@iden3/js-merkletree
Version:
javascript sparse merkle tree library
27 lines (26 loc) • 1.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.nodeValue = exports.leafKey = void 0;
// LeafKey computes the key of a leaf node given the hIndex and hValue of the
// entry of the leaf.
const hash_1 = require("../hash/hash");
const constants_1 = require("../../constants");
const bigint_1 = require("./bigint");
const leafKey = async (k, v) => {
return (0, hash_1.hashElemsKey)(BigInt(1), [k.bigInt(), v.bigInt()]);
};
exports.leafKey = leafKey;
const nodeValue = (type, a, b) => {
const bytes = new Uint8Array(constants_1.NODE_VALUE_BYTE_ARR_LENGTH);
const kBytes = (0, bigint_1.bigIntToUINT8Array)(a.bigInt());
const vBytes = (0, bigint_1.bigIntToUINT8Array)(b.bigInt());
bytes[0] = type;
for (let idx = 1; idx < 33; idx += 1) {
bytes[idx] = kBytes[idx - 1];
}
for (let idx = 33; idx <= constants_1.NODE_VALUE_BYTE_ARR_LENGTH; idx += 1) {
bytes[idx] = vBytes[idx - 33];
}
return bytes;
};
exports.nodeValue = nodeValue;