mirror of
https://github.com/tornadocash/fixed-merkle-tree.git
synced 2024-11-22 01:37:09 +01:00
rename proof() -> path()
This commit is contained in:
parent
1f86cc10c1
commit
9c5a9cd65f
@ -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:
|
||||
{
|
||||
|
@ -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": {
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user