merkletreejs
Advanced tools
Comparing version 0.0.14 to 0.0.15
@@ -42,5 +42,4 @@ const reverse = require('buffer-reverse') | ||
createHashes(nodes) { | ||
while (nodes.length > 1) { | ||
while (nodes.length !== 1) { | ||
const layerIndex = this.layers.length | ||
@@ -122,3 +121,3 @@ | ||
getRoot() { | ||
return this.layers[this.layers.length-1][0] | ||
return this.layers[this.layers.length-1][0] || Buffer.from([]) | ||
} | ||
@@ -125,0 +124,0 @@ |
{ | ||
"name": "merkletreejs", | ||
"version": "0.0.14", | ||
"version": "0.0.15", | ||
"description": "Construct Merkle Trees and verify proofs", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -225,1 +225,27 @@ const test = require('tape') | ||
}) | ||
test('sha256 - no leaves', t => { | ||
t.plan(1) | ||
const leaves = [] | ||
const tree = new MerkleTree(leaves, sha256) | ||
const root = '' | ||
t.equal(tree.getRoot().toString('hex'), root) | ||
}) | ||
test('sha256 - 1,000,000 leaves', t => { | ||
t.plan(1) | ||
let values = [] | ||
for (let i = 0; i < 1e6; i++) { | ||
values.push(`${i}`) | ||
} | ||
const leaves = values.map(x => sha256(x)) | ||
const tree = new MerkleTree(leaves, sha256) | ||
const root = '101dd357df60384d254330fe118e3046871767c2748ebd62ce031c117df483da' | ||
t.equal(tree.getRoot().toString('hex'), root) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
256038
449