1 Commits
0.4.0 ... 0.3.4

Author SHA1 Message Date
9cf202ce36 Update dependencies & fix package name to self-hosted registry 2023-09-18 01:31:37 -07:00
4 changed files with 5 additions and 50 deletions

8
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "@tornado/fixed-merkle-tree",
"version": "0.4.0",
"name": "fixed-merkle-tree",
"version": "0.3.4",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@tornado/fixed-merkle-tree",
"version": "0.4.0",
"name": "fixed-merkle-tree",
"version": "0.3.4",
"license": "ISC",
"dependencies": {
"@tornado/circomlib": "^0.0.21",

View File

@@ -1,6 +1,6 @@
{
"name": "@tornado/fixed-merkle-tree",
"version": "0.4.0",
"version": "0.3.4",
"description": "Fixed depth merkle tree implementation with sequential inserts",
"main": "src/merkleTree.js",
"repository": {

View File

@@ -152,36 +152,6 @@ class MerkleTree {
elements() {
return this._layers[0].slice()
}
/**
* Serialize entire tree state including intermediate layers into a plain object
* Deserializing it back will not require to recompute any hashes
* Elements are not converted to a plain type, this is responsibility of the caller
*/
serialize() {
return {
levels: this.levels,
capacity: this.capacity,
zeroElement: this.zeroElement,
_zeros: this._zeros,
_layers: this._layers,
}
}
/**
* Deserialize data into a MerkleTree instance
* Make sure to provide the same hashFunction as was used in the source tree,
* otherwise the tree state will be invalid
*
* @param data
* @param hashFunction
* @returns {MerkleTree}
*/
static deserialize(data, hashFunction) {
const instance = Object.assign(Object.create(this.prototype), data)
instance._hash = hashFunction || defaultHash
return instance
}
}
module.exports = MerkleTree

View File

@@ -202,19 +202,4 @@ describe('MerkleTree', () => {
])
})
})
describe('#serialize', () => {
it('should work', () => {
const src = new MerkleTree(10, [1, 2, 3])
const data = src.serialize()
const dst = MerkleTree.deserialize(data)
src.root().should.equal(dst.root())
src.insert(10)
dst.insert(10)
src.root().should.equal(dst.root())
})
})
})