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

19 lines
727 B
JavaScript
Raw Permalink Normal View History

2020-10-18 23:19:16 -04:00
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
2021-03-07 18:24:04 -05:00
exports.hashMessage = exports.messagePrefix = void 0;
2020-10-18 23:19:16 -04: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") {
message = strings_1.toUtf8Bytes(message);
}
return keccak256_1.keccak256(bytes_1.concat([
strings_1.toUtf8Bytes(exports.messagePrefix),
strings_1.toUtf8Bytes(String(message.length)),
message
]));
}
exports.hashMessage = hashMessage;
//# sourceMappingURL=message.js.map