@onesy/utils
Version:
21 lines (20 loc) • 766 B
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const sha256_1 = __importDefault(require("crypto-js/sha256"));
const serialize_1 = __importDefault(require("./serialize"));
const optionsDefault = {
serialize: true,
withPrefix: true
};
const hash = (value_, options_ = {}) => {
const options = Object.assign(Object.assign({}, optionsDefault), options_);
let value = value_;
if (options.serialize)
value = (0, serialize_1.default)(value);
value = (0, sha256_1.default)(value).toString();
return options.withPrefix ? `0x${value}` : value;
};
exports.default = hash;
;