web3x
Version:
Typescript port of web3.js
31 lines (28 loc) • 2.17 kB
JavaScript
;
/*
This file is part of web3x.
web3x is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
web3x is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with web3x. If not, see <http://www.gnu.org/licenses/>.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const _1 = require(".");
const hash_1 = tslib_1.__importDefault(require("../eth-lib/hash"));
function hashMessage(data) {
const message = _1.isHexStrict(data) ? _1.hexToBytes(data) : data;
const messageBuffer = Buffer.from(message);
const preamble = '\x19Ethereum Signed Message:\n' + message.length;
const preambleBuffer = Buffer.from(preamble);
const ethMessage = Buffer.concat([preambleBuffer, messageBuffer]);
return hash_1.default.keccak256s(ethMessage);
}
exports.hashMessage = hashMessage;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaGFzaC1tZXNzYWdlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3V0aWxzL2hhc2gtbWVzc2FnZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Ozs7Ozs7Ozs7Ozs7OztFQWVFOzs7QUFFRix3QkFBNEM7QUFDNUMsbUVBQW1DO0FBRW5DLFNBQWdCLFdBQVcsQ0FBQyxJQUFJO0lBQzlCLE1BQU0sT0FBTyxHQUFHLGNBQVcsQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDLENBQUMsYUFBVSxDQUFDLElBQUksQ0FBQyxDQUFDLENBQUMsQ0FBQyxJQUFJLENBQUM7SUFDNUQsTUFBTSxhQUFhLEdBQUcsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsQ0FBQztJQUMzQyxNQUFNLFFBQVEsR0FBRyxnQ0FBZ0MsR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDO0lBQ25FLE1BQU0sY0FBYyxHQUFHLE1BQU0sQ0FBQyxJQUFJLENBQUMsUUFBUSxDQUFDLENBQUM7SUFDN0MsTUFBTSxVQUFVLEdBQUcsTUFBTSxDQUFDLE1BQU0sQ0FBQyxDQUFDLGNBQWMsRUFBRSxhQUFhLENBQUMsQ0FBQyxDQUFDO0lBQ2xFLE9BQU8sY0FBSSxDQUFDLFVBQVUsQ0FBQyxVQUFVLENBQUMsQ0FBQztBQUNyQyxDQUFDO0FBUEQsa0NBT0MifQ==