@ethereumjs/mpt
Version:
Implementation of the modified merkle patricia tree as specified in Ethereum's yellow paper.
43 lines • 883 B
JavaScript
/**
* Prepends hex prefix to an array of nibbles.
* @param key - Array of nibbles
* @returns returns buffer of encoded data
**/
export function addHexPrefix(key, terminator) {
// odd
if (key.length % 2) {
key.unshift(1);
}
else {
// even
key.unshift(0);
key.unshift(0);
}
if (terminator) {
key[0] += 2;
}
return key;
}
/**
* Removes hex prefix of an array of nibbles.
* @param val - Array of nibbles
* @private
*/
export function removeHexPrefix(val) {
if (val[0] % 2) {
val = val.slice(1);
}
else {
val = val.slice(2);
}
return val;
}
/**
* Returns true if hex-prefixed path is for a terminating (leaf) node.
* @param key - a hex-prefixed array of nibbles
* @private
*/
export function isTerminator(key) {
return key[0] > 1;
}
//# sourceMappingURL=hex.js.map