From 9c5a9cd65f76bd01ef7d675a961ded9e424c1a5a Mon Sep 17 00:00:00 2001 From: poma Date: Fri, 31 Jul 2020 17:19:20 +0300 Subject: [PATCH] rename proof() -> path() --- README.md | 4 ++-- package.json | 2 +- src/merkleTree.js | 6 +++--- test/merkleTree.test.js | 14 +++++++------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 7195811..d7ace82 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,8 @@ const MerkleTree = require('MerkleTree') const tree = new MerkleTree(10, [1, 2, 3, 4, 5]) tree.insert(6) tree.update(3, 42) -const proof = tree.proof(tree.indexOf(2)) -console.log(proof) +const path = tree.path(tree.indexOf(2)) +console.log(path) // output: { diff --git a/package.json b/package.json index e82e280..de68355 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fixed-merkle-tree", - "version": "0.2.1", + "version": "0.3.0", "description": "Fixed depth merkle tree implementation with sequential inserts", "main": "src/merkleTree.js", "scripts": { diff --git a/src/merkleTree.js b/src/merkleTree.js index 9aaf508..7922c31 100644 --- a/src/merkleTree.js +++ b/src/merkleTree.js @@ -105,11 +105,11 @@ class MerkleTree { } /** - * Get merkle proof for a leaf - * @param index Leaf index to generate proof for + * Get merkle path to a leaf + * @param index Leaf index to generate path for * @returns {{pathElements: Object[], pathIndex: number[]}} An object containing adjacent elements and left-right index */ - proof(index) { + path(index) { if (index < 0 || index >= this._layers[0].length) { throw new Error('Index out of bounds: ' + index) } diff --git a/test/merkleTree.test.js b/test/merkleTree.test.js index 63ec932..59c2191 100644 --- a/test/merkleTree.test.js +++ b/test/merkleTree.test.js @@ -85,12 +85,12 @@ describe('MerkleTree', () => { }) }) - describe('#proof', () => { + describe('#path', () => { it('should work for even index', () => { const tree = new MerkleTree(10, [1, 2, 3, 4, 5]) - const proof = tree.proof(2) - proof.pathIndices.should.be.deep.equal([0, 1, 0, 0, 0, 0, 0, 0, 0, 0]) - proof.pathElements.should.be.deep.equal([ + const path = tree.path(2) + path.pathIndices.should.be.deep.equal([0, 1, 0, 0, 0, 0, 0, 0, 0, 0]) + path.pathElements.should.be.deep.equal([ 4, '19814528709687996974327303300007262407299502847885145507292406548098437687919', '21305827034995891902714687670641862055126514524916463201449278400604999416145', @@ -106,9 +106,9 @@ describe('MerkleTree', () => { it('should work for odd index', () => { const tree = new MerkleTree(10, [1, 2, 3, 4, 5]) - const proof = tree.proof(3) - proof.pathIndices.should.be.deep.equal([1, 1, 0, 0, 0, 0, 0, 0, 0, 0]) - proof.pathElements.should.be.deep.equal([ + const path = tree.path(3) + path.pathIndices.should.be.deep.equal([1, 1, 0, 0, 0, 0, 0, 0, 0, 0]) + path.pathElements.should.be.deep.equal([ 3, '19814528709687996974327303300007262407299502847885145507292406548098437687919', '21305827034995891902714687670641862055126514524916463201449278400604999416145',