mirror of
https://github.com/tornadocash/fixed-merkle-tree.git
synced 2024-11-22 17:50:22 +01:00
downgrade syntax for node 12
This commit is contained in:
parent
6663aec38c
commit
3aff8f4515
@ -25,7 +25,7 @@ class MerkleTree {
|
|||||||
this.levels = levels
|
this.levels = levels
|
||||||
this.capacity = 2 << levels
|
this.capacity = 2 << levels
|
||||||
this.zeroElement = zeroElement
|
this.zeroElement = zeroElement
|
||||||
this._hash = hashFunction ?? defaultHash
|
this._hash = hashFunction || defaultHash
|
||||||
|
|
||||||
this._zeros = []
|
this._zeros = []
|
||||||
this._layers = []
|
this._layers = []
|
||||||
@ -43,7 +43,9 @@ class MerkleTree {
|
|||||||
for (let i = 0; i < Math.ceil(this._layers[level - 1].length / 2); i++) {
|
for (let i = 0; i < Math.ceil(this._layers[level - 1].length / 2); i++) {
|
||||||
this._layers[level][i] = this._hash(
|
this._layers[level][i] = this._hash(
|
||||||
this._layers[level - 1][i * 2],
|
this._layers[level - 1][i * 2],
|
||||||
this._layers[level - 1]?.[i * 2 + 1] ?? this._zeros[level - 1],
|
i * 2 + 1 < this._layers[level - 1].length ?
|
||||||
|
this._layers[level - 1][i * 2 + 1] :
|
||||||
|
this._zeros[level - 1],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -54,7 +56,7 @@ class MerkleTree {
|
|||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
root() {
|
root() {
|
||||||
return this._layers[this.levels]?.[0] ?? this._zeros[this.levels]
|
return this._layers[this.levels].length > 0 ? this._layers[this.levels][0] : this._zeros[this.levels]
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -94,7 +96,9 @@ class MerkleTree {
|
|||||||
index >>= 1
|
index >>= 1
|
||||||
this._layers[level][index] = this._hash(
|
this._layers[level][index] = this._hash(
|
||||||
this._layers[level - 1][index * 2],
|
this._layers[level - 1][index * 2],
|
||||||
this._layers[level - 1]?.[index * 2 + 1] ?? this._zeros[level - 1],
|
index * 2 + 1 < this._layers[level - 1].length ?
|
||||||
|
this._layers[level - 1][index * 2 + 1] :
|
||||||
|
this._zeros[level - 1],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,7 +116,9 @@ class MerkleTree {
|
|||||||
const pathIndex = []
|
const pathIndex = []
|
||||||
for (let level = 0; level < this.levels; level++) {
|
for (let level = 0; level < this.levels; level++) {
|
||||||
pathIndex[level] = index % 2
|
pathIndex[level] = index % 2
|
||||||
pathElements[level] = this._layers[level]?.[index ^ 1] ?? this._zeros[level]
|
pathElements[level] = (index ^ 1) < this._layers[level].length ?
|
||||||
|
this._layers[level][index ^ 1] :
|
||||||
|
this._zeros[level]
|
||||||
index >>= 1
|
index >>= 1
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
Loading…
Reference in New Issue
Block a user