Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c89146c3e5 | |||
|
|
29021a8028 | ||
|
|
4a63b3b7fb | ||
|
|
acc7e53b01 | ||
|
|
823545596e | ||
|
|
4f6ff9b777 |
1
.npmrc
Normal file
1
.npmrc
Normal file
@@ -0,0 +1 @@
|
||||
@tornado:registry=https://git.tornado.ws/api/packages/tornado-packages/npm/
|
||||
7
.prettierrc
Normal file
7
.prettierrc
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"semi": false,
|
||||
"arrowParens": "always",
|
||||
"singleQuote": true,
|
||||
"printWidth": 110,
|
||||
"trailingComma": "all"
|
||||
}
|
||||
4967
package-lock.json
generated
4967
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1,9 @@
|
||||
{
|
||||
"name": "fixed-merkle-tree",
|
||||
"version": "0.4.0",
|
||||
"name": "@tornado/fixed-merkle-tree",
|
||||
"version": "0.5.1",
|
||||
"description": "Fixed depth merkle tree implementation with sequential inserts",
|
||||
"main": "src/merkleTree.js",
|
||||
"repository": "https://git.tornado.ws/tornado-packages/fixed-merkle-tree.git",
|
||||
"scripts": {
|
||||
"test": "mocha",
|
||||
"lint": "eslint ."
|
||||
@@ -18,8 +19,8 @@
|
||||
"src/*"
|
||||
],
|
||||
"dependencies": {
|
||||
"snarkjs": "git+https://github.com/tornadocash/snarkjs.git#869181cfaf7526fe8972073d31655493a04326d5",
|
||||
"circomlib": "git+https://github.com/tornadocash/circomlib.git#5beb6aee94923052faeecea40135d45b6ce6172c"
|
||||
"@tornado/circomlib": "0.0.21",
|
||||
"@tornado/snarkjs": "0.1.20"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-eslint": "^10.1.0",
|
||||
|
||||
@@ -24,7 +24,7 @@ class MerkleTree {
|
||||
*/
|
||||
constructor(levels, elements = [], { hashFunction, zeroElement = DEFAULT_ZERO } = {}) {
|
||||
this.levels = levels
|
||||
this.capacity = 1 << levels
|
||||
this.capacity = 2 ** levels
|
||||
this.zeroElement = zeroElement
|
||||
this._hash = hashFunction || defaultHash
|
||||
if (elements.length > this.capacity) {
|
||||
@@ -47,9 +47,9 @@ class MerkleTree {
|
||||
for (let i = 0; i < Math.ceil(this._layers[level - 1].length / 2); i++) {
|
||||
this._layers[level][i] = this._hash(
|
||||
this._layers[level - 1][i * 2],
|
||||
i * 2 + 1 < this._layers[level - 1].length ?
|
||||
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],
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -100,9 +100,9 @@ class MerkleTree {
|
||||
index >>= 1
|
||||
this._layers[level][index] = this._hash(
|
||||
this._layers[level - 1][index * 2],
|
||||
index * 2 + 1 < this._layers[level - 1].length ?
|
||||
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],
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -120,9 +120,8 @@ class MerkleTree {
|
||||
const pathIndices = []
|
||||
for (let level = 0; level < this.levels; level++) {
|
||||
pathIndices[level] = index % 2
|
||||
pathElements[level] = (index ^ 1) < this._layers[level].length ?
|
||||
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
|
||||
}
|
||||
return {
|
||||
@@ -161,8 +160,6 @@ class MerkleTree {
|
||||
serialize() {
|
||||
return {
|
||||
levels: this.levels,
|
||||
capacity: this.capacity,
|
||||
zeroElement: this.zeroElement,
|
||||
_zeros: this._zeros,
|
||||
_layers: this._layers,
|
||||
}
|
||||
@@ -180,6 +177,8 @@ class MerkleTree {
|
||||
static deserialize(data, hashFunction) {
|
||||
const instance = Object.assign(Object.create(this.prototype), data)
|
||||
instance._hash = hashFunction || defaultHash
|
||||
instance.capacity = 2 ** instance.levels
|
||||
instance.zeroElement = instance._zeros[0]
|
||||
return instance
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
const { mimcsponge } = require('circomlib')
|
||||
const { bigInt } = require('snarkjs')
|
||||
const { mimcsponge } = require('@tornado/circomlib')
|
||||
const { bigInt } = require('@tornado/snarkjs')
|
||||
module.exports = (left, right) => mimcsponge.multiHash([bigInt(left), bigInt(right)]).toString()
|
||||
|
||||
Reference in New Issue
Block a user