ethers.js/packages/hash/lib/message.js

19 lines
752 B
JavaScript
Raw Normal View History

2020-10-19 06:19:16 +03:00
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
2021-03-08 02:24:04 +03:00
exports.hashMessage = exports.messagePrefix = void 0;
2020-10-19 06:19:16 +03:00
var bytes_1 = require("@ethersproject/bytes");
var keccak256_1 = require("@ethersproject/keccak256");
var strings_1 = require("@ethersproject/strings");
exports.messagePrefix = "\x19Ethereum Signed Message:\n";
function hashMessage(message) {
if (typeof (message) === "string") {
2021-10-16 09:29:27 +03:00
message = (0, strings_1.toUtf8Bytes)(message);
2020-10-19 06:19:16 +03:00
}
2021-10-16 09:29:27 +03:00
return (0, keccak256_1.keccak256)((0, bytes_1.concat)([
(0, strings_1.toUtf8Bytes)(exports.messagePrefix),
(0, strings_1.toUtf8Bytes)(String(message.length)),
2020-10-19 06:19:16 +03:00
message
]));
}
exports.hashMessage = hashMessage;
//# sourceMappingURL=message.js.map