@airgap/coinlib-core
Version:
The @airgap/coinlib-core is a protocol agnostic library to prepare, sign and broadcast cryptocurrency transactions.
23 lines • 1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.blake2bAsBytes = exports.blake2bAsHex = void 0;
var blake2b = require("../dependencies/src/blake2b-6268e6dd678661e0acc4359e9171b97eb1ebf8ac");
var hex_1 = require("./hex");
function blake2bAsHex(data, bitLength, config) {
if (config === void 0) { config = { withPrefix: false }; }
var hash = blake2bAsBytes(data, bitLength, { key: config.key });
var hex = Buffer.from(hash).toString('hex');
return config.withPrefix ? (0, hex_1.addHexPrefix)(hex) : hex;
}
exports.blake2bAsHex = blake2bAsHex;
function blake2bAsBytes(data, bitLength, config) {
if (config === void 0) { config = {}; }
var byteLength = Math.ceil(bitLength / 8);
var hashU8a = new Uint8Array(byteLength);
var hash = blake2b(byteLength, config.key);
hash.update((0, hex_1.hexToBytes)(data));
hash.digest(hashU8a);
return hashU8a;
}
exports.blake2bAsBytes = blake2bAsBytes;
//# sourceMappingURL=blake2b.js.map