Support for non-bitcoin tree proofs
This commit is contained in:
parent
5da9e2dd48
commit
8da6f51d55
62
index.js
62
index.js
|
@ -151,25 +151,55 @@ class MerkleTree {
|
|||
return []
|
||||
}
|
||||
|
||||
for (let i = 0; i < this.layers.length - 1; i++) {
|
||||
const layer = this.layers[i]
|
||||
const isRightNode = index % 2
|
||||
const pairIndex = (isRightNode ? index - 1 : index)
|
||||
if (this.isBitcoinTree) {
|
||||
|
||||
if (pairIndex < layer.length) {
|
||||
proof.push({
|
||||
position: isRightNode ? 'left': 'right',
|
||||
data: layer[pairIndex]
|
||||
})
|
||||
// Proof Generation for Bitcoin Trees
|
||||
|
||||
for (let i = 0; i < this.layers.length - 1; i++) {
|
||||
const layer = this.layers[i]
|
||||
const isRightNode = index % 2
|
||||
const pairIndex = (isRightNode ? index - 1 : index)
|
||||
|
||||
if (pairIndex < layer.length) {
|
||||
proof.push({
|
||||
position: isRightNode ? 'left': 'right',
|
||||
data: layer[pairIndex]
|
||||
})
|
||||
}
|
||||
|
||||
// set index to parent index
|
||||
index = (index / 2)|0
|
||||
|
||||
}
|
||||
|
||||
return proof
|
||||
|
||||
} else {
|
||||
|
||||
// Proof Generation for Non-Bitcoin Trees
|
||||
|
||||
for (let i = 0; i < this.layers.length; i++) {
|
||||
const layer = this.layers[i]
|
||||
const isRightNode = index % 2
|
||||
const pairIndex = (isRightNode ? index - 1 : index + 1)
|
||||
|
||||
if (pairIndex < layer.length) {
|
||||
proof.push({
|
||||
position: isRightNode ? 'left': 'right',
|
||||
data: layer[pairIndex]
|
||||
})
|
||||
}
|
||||
|
||||
// set index to parent index
|
||||
index = (index / 2)|0
|
||||
|
||||
}
|
||||
|
||||
return proof
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// set index to parent index
|
||||
index = (index / 2)|0
|
||||
}
|
||||
|
||||
return proof
|
||||
}
|
||||
|
||||
/**
|
||||
* verify
|
||||
* @desc Returns true if the proof path (array of hashes) can connect the target node
|
||||
|
|
Loading…
Reference in New Issue