UNPKG

@parity/api

Version:

The Parity Promise-based API library for interfacing with Ethereum over RPC

26 lines (25 loc) 848 B
"use strict"; // Copyright 2015-2019 Parity Technologies (UK) Ltd. // This file is part of Parity. // // SPDX-License-Identifier: MIT Object.defineProperty(exports, "__esModule", { value: true }); var js_sha3_1 = require("js-sha3"); var format_1 = require("./format"); var types_1 = require("./types"); /** * * @param value - The value to hash * @param options - Set the encoding in the options, encoding can be `'hex'` * or `'raw'`. */ exports.sha3 = function (value, options) { var forceHex = options && options.encoding === 'hex'; if (forceHex || (!options && types_1.isHex(value))) { var bytes = format_1.hexToBytes(value); return exports.sha3(bytes); } var hash = js_sha3_1.keccak_256(value); return "0x" + hash; }; exports.sha3Text = function (val) { return exports.sha3(val, { encoding: 'raw' }); };