@onesy/utils
Version:
19 lines (17 loc) • 516 B
JavaScript
import SHA256 from 'crypto-js/sha256';
import serialize from './serialize';
const optionsDefault = {
serialize: true,
withPrefix: true
};
const hash = function (value_) {
let options_ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
const options = { ...optionsDefault,
...options_
};
let value = value_;
if (options.serialize) value = serialize(value);
value = SHA256(value).toString();
return options.withPrefix ? "0x".concat(value) : value;
};
export default hash;