Fix unexpected breaking change

This commit is contained in:
Miguel Mota 2022-11-14 10:42:19 -08:00
parent 9b880c9165
commit fdb3cc8b75
No known key found for this signature in database
GPG Key ID: 67EC1161588A00F9
2 changed files with 17 additions and 1 deletions

View File

@ -531,7 +531,13 @@ export class MerkleTree extends Base {
const proof = []
if (!Number.isInteger(index)) {
index = this._bufferIndexOf(this.leaves, leaf, this.sortLeaves)
index = -1
for (let i = 0; i < this.leaves.length; i++) {
if (Buffer.compare(leaf, this.leaves[i]) === 0) {
index = i
}
}
}
if (index <= -1) {

View File

@ -1291,3 +1291,13 @@ test('complete option with incompatible options', t => {
)
})
test('simple bad proof', t => {
t.plan(2)
const leaves = ['d', 'e', 'f']
const tree = new MerkleTree(leaves)
const proof = tree.getHexProof(leaves[0])
t.equal(proof.length, 1)
t.equal(proof[0], '0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855')
})