mirror of
https://github.com/tornadocash/fixed-merkle-tree.git
synced 2024-11-24 10:54:15 +01:00
update Readme
This commit is contained in:
parent
a29aa84450
commit
0efd9caee8
77
README.md
77
README.md
@ -5,27 +5,72 @@ This is a fixed depth merkle tree implementation with sequential inserts
|
||||
## Usage
|
||||
|
||||
```javascript
|
||||
const MerkleTree = require('MerkleTree')
|
||||
import { MerkleTree, PartialMerkleTree } from 'fixed-merkle-tree'
|
||||
|
||||
const tree = new MerkleTree(10, [1, 2, 3, 4, 5])
|
||||
tree.insert(6)
|
||||
tree.update(3, 42)
|
||||
const path = tree.path(tree.indexOf(2))
|
||||
const path = tree.proof(3)
|
||||
console.log(path)
|
||||
|
||||
// output:
|
||||
// output
|
||||
{
|
||||
pathIndex: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
pathElements: [
|
||||
'42',
|
||||
'19814528709687996974327303300007262407299502847885145507292406548098437687919',
|
||||
'11545490348087423460235196042660837039811055736960842865648632633825765931887',
|
||||
'14506027710748750947258687001455876266559341618222612722926156490737302846427',
|
||||
'4766583705360062980279572762279781527342845808161105063909171241304075622345',
|
||||
'16640205414190175414380077665118269450294358858897019640557533278896634808665',
|
||||
'13024477302430254842915163302704885770955784224100349847438808884122720088412',
|
||||
'11345696205391376769769683860277269518617256738724086786512014734609753488820',
|
||||
'17235543131546745471991808272245772046758360534180976603221801364506032471936',
|
||||
'155962837046691114236524362966874066300454611955781275944230309195800494087'
|
||||
]
|
||||
42,
|
||||
'4027992409016347597424110157229339967488',
|
||||
'2008015086710634950773855228781840564224',
|
||||
'938972308169430750202858820582946897920',
|
||||
'3743880566844110745576746962917825445888',
|
||||
'2074434463882483178614385966084599578624',
|
||||
'2808856778596740691845240322870189490176',
|
||||
'4986731814143931240516913804278285467648',
|
||||
'1918547053077726613961101558405545328640',
|
||||
'5444383861051812288142814494928935059456'
|
||||
],
|
||||
pathIndices:
|
||||
[
|
||||
0, 1, 0, 0, 0,
|
||||
0, 0, 0, 0, 0
|
||||
],
|
||||
pathPositions:
|
||||
[
|
||||
3, 0, 1, 0, 0,
|
||||
0, 0, 0, 0, 0
|
||||
],
|
||||
pathRoot:
|
||||
'3917789723822252567979048877718291611648'
|
||||
}
|
||||
|
||||
const treeEdge = tree.getTreeEdge(2)
|
||||
const partialTree = new PartialMerkleTree(10, treeEdge, tree.elements.slice(treeEdge.edgeIndex))
|
||||
console.log(partialTree.elements)
|
||||
// output
|
||||
[<2 empty items >, 3, 42, 5, 6]
|
||||
|
||||
const proofPath = partialTree.proof(3)
|
||||
console.log(proofPath)
|
||||
// output
|
||||
{
|
||||
pathElements: [
|
||||
42,
|
||||
'4027992409016347597424110157229339967488',
|
||||
'2008015086710634950773855228781840564224',
|
||||
'938972308169430750202858820582946897920',
|
||||
'3743880566844110745576746962917825445888',
|
||||
'2074434463882483178614385966084599578624',
|
||||
'2808856778596740691845240322870189490176',
|
||||
'4986731814143931240516913804278285467648',
|
||||
'1918547053077726613961101558405545328640',
|
||||
'5444383861051812288142814494928935059456'
|
||||
],
|
||||
pathIndices: [
|
||||
0, 1, 0, 0, 0,
|
||||
0, 0, 0, 0, 0
|
||||
],
|
||||
pathPositions: [
|
||||
3, 0, 1, 0, 0,
|
||||
0, 0, 0, 0, 0
|
||||
],
|
||||
pathRoot: '3917789723822252567979048877718291611648'
|
||||
}
|
||||
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user