2 Commits
0.6.1 ... 123

Author SHA1 Message Date
poma
c83a4a4dc0 efficient bulk insert 2021-09-15 19:55:13 +03:00
poma
2b6b5c481d minor refactor 2021-09-15 19:54:57 +03:00
6 changed files with 2172 additions and 2107 deletions

0
.npmrc
View File

1
.nvmrc
View File

@@ -1 +0,0 @@
v14.21.3

4256
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,8 +1,8 @@
{
"name": "@tornado/fixed-merkle-tree",
"version": "0.6.1",
"name": "fixed-merkle-tree",
"version": "0.6.0",
"description": "Fixed depth merkle tree implementation with sequential inserts",
"repository": "https://git.tornado.ws/tornado-packages/fixed-merkle-tree.git",
"repository": "https://github.com/tornadocash/fixed-merkle-tree.git",
"main": "src/merkleTree.js",
"scripts": {
"test": "mocha",
@@ -19,8 +19,8 @@
"src/*"
],
"dependencies": {
"@tornado/circomlib": "0.0.21",
"@tornado/snarkjs": "0.1.20"
"snarkjs": "git+https://github.com/tornadocash/snarkjs.git#869181cfaf7526fe8972073d31655493a04326d5",
"circomlib": "git+https://github.com/tornadocash/circomlib.git#5beb6aee94923052faeecea40135d45b6ce6172c"
},
"devDependencies": {
"babel-eslint": "^10.1.0",

View File

@@ -22,13 +22,13 @@ class MerkleTree {
* @param {hashFunction} [options.hashFunction] Function used to hash 2 leaves
* @param [options.zeroElement] Value for non-existent leaves
*/
constructor(levels, elements = [], { hashFunction, zeroElement = DEFAULT_ZERO } = {}) {
constructor(levels, elements = [], { hashFunction = defaultHash, zeroElement = DEFAULT_ZERO } = {}) {
this.levels = levels
this.capacity = 2 ** levels
if (elements.length > this.capacity) {
throw new Error('Tree is full')
}
this._hash = hashFunction || defaultHash
this._hash = hashFunction
this.zeroElement = zeroElement
this._zeros = []
this._zeros[0] = zeroElement
@@ -78,10 +78,6 @@ class MerkleTree {
* @param {Array} elements Elements to insert
*/
bulkInsert(elements) {
if (!elements.length) {
return
}
if (this._layers[0].length + elements.length > this.capacity) {
throw new Error('Tree is full')
}

View File

@@ -1,3 +1,3 @@
const { mimcsponge } = require('@tornado/circomlib')
const { bigInt } = require('@tornado/snarkjs')
const { mimcsponge } = require('circomlib')
const { bigInt } = require('snarkjs')
module.exports = (left, right) => mimcsponge.multiHash([bigInt(left), bigInt(right)]).toString()