MerkleTree.js – 梅克尔树.js区块链毕设代写

区块链毕设代写本文提供国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,MerkleTree.js – 梅克尔树.js区块链毕设代写 是一篇很好的国外资料


MerkleTree.js - 梅克尔树.js

MerkleTree.js

Construct Merkle Trees and verify proofs in JavaScript.

MerkleTree.js - 梅克尔树.js MerkleTree.js - 梅克尔树.js MerkleTree.js - 梅克尔树.js MerkleTree.js - 梅克尔树.js MerkleTree.js - 梅克尔树.js

Contents

  • Install
  • Getting started
  • Diagrams
  • Documentation
  • Test
  • FAQ
  • Notes
  • Resources
  • Contributing
  • License

Install

From NPM:

npm install merkletreejs

CDN

Available on jsDelivr CDN:

<script src="https://cdn.jsdelivr.net/npm/merkletreejs@latest/merkletree.js"></script>

Getting started

Construct tree, generate proof, and verify proof:

const { MerkleTree } = require('merkletreejs') const SHA256 = require('crypto-js/sha256')  const leaves = ['a', 'b', 'c'].map(x => SHA256(x)) const tree = new MerkleTree(leaves, SHA256) const root = tree.getRoot().toString('hex') const leaf = SHA256('a') const proof = tree.getProof(leaf) console.log(tree.verify(proof, leaf, root)) // true   const badLeaves = ['a', 'x', 'c'].map(x => SHA256(x)) const badTree = new MerkleTree(badLeaves, SHA256) const badLeaf = SHA256('x') const badProof = tree.getProof(badLeaf) console.log(tree.verify(badProof, leaf, root)) // false

Print tree to console:

MerkleTree.print(tree)

Output

└─ 311d2e46f49b15fff8b746b74ad57f2cc9e0d9939fda94387141a2d3fdf187ae    ├─ 176f0f307632fdd5831875eb709e2f68d770b102262998b214ddeb3f04164ae1    │  ├─ 3ac225168df54212a25c1c01fd35bebfea408fdac2e31ddd6f80a4bbf9a5f1cb    │  └─ b5553de315e0edf504d9150af82dafa5c4667fa618ed0a6f19c69b41166c5510    └─ 0b42b6393c1f53060fe3ddbfcd7aadcca894465a5a438f69c87d790b2299b9b2       └─ 0b42b6393c1f53060fe3ddbfcd7aadcca894465a5a438f69c87d790b2299b9b2

Diagrams

▾ Visualization of Merkle Tree

MerkleTree.js - 梅克尔树.js

▾ Visualization of Merkle Tree Proof

MerkleTree.js - 梅克尔树.js

▾ Visualization of Invalid Merkle Tree Proofs

MerkleTree.js - 梅克尔树.js

▾ Visualization of Bitcoin Merkle Tree

MerkleTree.js - 梅克尔树.js

Documentation

Class: MerkleTree

Class reprensenting a Merkle Tree

namespace MerkleTree

Hierarchy

  • MerkleTree

Index

Constructors

  • constructor

Methods

  • getDepth
  • getHexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexMultiProof
  • getHexProof
  • getHexRoot
  • getLayers
  • getLayersAsObject
  • getLayersFlat
  • getLeaves
  • getMultiProof
  • getProof
  • getProofFlags
  • getProofIndices
  • getRoot
  • print
  • toString
  • verify
  • verifyMultiProof
  • bufferify
  • getMultiProof
  • isHexString
  • print

Constructors

constructor

+ new MerkleTree(leaves: any[], hashAlgorithm: any, options: Options): MerkleTree

desc Constructs a Merkle Tree. All nodes and leaves are stored as Buffers. Lonely leaf nodes are promoted to the next level up without being hashed again.

example

const MerkleTree = require('merkletreejs') const crypto = require('crypto')  function sha256(data) {  // returns Buffer  return crypto.createHash('sha256').update(data).digest() }  const leaves = ['a', 'b', 'c'].map(x => keccak(x))  const tree = new MerkleTree(leaves, sha256)

Parameters:

Name Type Default Description
leaves any[] Array of hashed leaves. Each leaf must be a Buffer.
hashAlgorithm any SHA256 Algorithm used for hashing leaves and nodes
options Options {} Additional options

Returns: MerkleTree

Methods

getDepth

getDepth(): number

getDepth

desc Returns the tree depth (number of layers)

example

const depth = tree.getDepth()

Returns: number


getHexLayers

getHexLayers(): string[]

getHexLayers

desc Returns multi-dimensional array of all layers of Merkle Tree, including leaves and root as hex strings.

example

const layers = tree.getHexLayers()

Returns: string[]


getHexLayersFlat

getHexLayersFlat(): string[]

getHexLayersFlat

desc Returns single flat array of all layers of Merkle Tree, including leaves and root as hex string.

example

const layers = tree.getHexLayersFlat()

Returns: string[]


getHexLeaves

getHexLeaves(): string[]

getHexLeaves

desc Returns array of leaves of Merkle Tree as hex strings.

example

const leaves = tree.getHexLeaves()

Returns: string[]


getHexMultiProof

getHexMultiProof(tree: Buffer[], indices: number[]): string[]

getHexMultiProof

desc Returns the multiproof for given tree indices as hex strings.

example

const indices = [2, 5, 6] const proof = tree.getHexMultiProof(indices)

Parameters:

Name Type Description
tree Buffer[]
indices number[] Tree indices.

Returns: string[]

  • Multiproofs as hex strings.

getHexProof

getHexProof(leaf: Buffer, index?: number): string[]

getHexProof

desc Returns the proof for a target leaf as hex strings.

example

const proof = tree.getHexProof(leaves[2])

Parameters:

Name Type Description
leaf Buffer Target leaf
index? number

Returns: string[]

  • Proof array as hex strings.

getHexRoot

getHexRoot(): string

getHexRoot

desc Returns the Merkle root hash as a hex string.

example

const root = tree.getHexRoot()

Returns: string


getLayers

getLayers(): Buffer[]

getLayers

desc Returns multi-dimensional array of all layers of Merkle Tree, including leaves and root.

example

const layers = tree.getLayers()

Returns: Buffer[]


getLayersAsObject

getLayersAsObject(): any

getLayersAsObject

desc Returns the layers as nested objects instead of an array.

example

const layersObj = tree.getLayersAsObject()

Returns: any


getLayersFlat

getLayersFlat(): Buffer[]

getLayersFlat

desc Returns single flat array of all layers of Merkle Tree, including leaves and root.

example

const layers = tree.getLayersFlat()

Returns: Buffer[]


getLeaves

getLeaves(values?: any[]): Buffer[]

getLeaves

desc Returns array of leaves of Merkle Tree.

example

const leaves = tree.getLeaves()

Parameters:

Name Type
values? any[]

Returns: Buffer[]


getMultiProof

getMultiProof(tree?: any[], indices?: any[]): Buffer[]

getMultiProof

desc Returns the multiproof for given tree indices.

example

const indices = [2, 5, 6] const proof = tree.getMultiProof(indices)

Parameters:

Name Type Description
tree? any[]
indices? any[] Tree indices.

Returns: Buffer[]

  • Multiproofs

getProof

getProof(leaf: Buffer, index?: number): any[]

getProof

desc Returns the proof for a target leaf.

example

const proof = tree.getProof(leaves[2])

example

const leaves = ['a', 'b', 'a'].map(x => keccak(x)) const tree = new MerkleTree(leaves, keccak) const proof = tree.getProof(leaves[2], 2)

Parameters:

Name Type Description
leaf Buffer Target leaf
index? number

Returns: any[]

  • Array of objects containing a position property of type string with values of ‘left’ or ‘right’ and a data property of type Buffer.

getProofFlags

getProofFlags(leaves: Buffer[], proofs: Buffer[]): boolean[]

getProofFlags

desc Returns list of booleans where proofs should be used instead of hashing. Proof flags are used in the Solidity multiproof verifiers.

example

const indices = [2, 5, 6] const proof = tree.getMultiProof(indices) const proofFlags = tree.getProofFlags(leaves, proof)

Parameters:

Name Type
leaves Buffer[]
proofs Buffer[]

Returns: boolean[]

  • Boolean flags

getProofIndices

getProofIndices(treeIndices: number[], depth: number): number[]

getProofIndices

desc Returns the proof indices for given tree indices.

example

const proofIndices = tree.getProofIndices([2,5,6], 4) console.log(proofIndices) // [ 23, 20, 19, 8, 3 ]

Parameters:

Name Type Description
treeIndices number[] Tree indices
depth number Tree depth; number of layers.

Returns: number[]

  • Proof indices

getRoot

getRoot(): Buffer

getRoot

desc Returns the Merkle root hash as a Buffer.

example

const root = tree.getRoot()

Returns: Buffer


print

print(): void

print

desc Prints out a visual representation of the merkle tree.

example

tree.print()

Returns: void


toString

toString(): string

toString

desc Returns a visual representation of the merkle tree as a string.

example

console.log(tree.toString())

Returns: string


verify

verify(proof: any[], targetNode: Buffer, root: Buffer): boolean

verify

desc Returns true if the proof path (array of hashes) can connect the target node to the Merkle root.

example

const root = tree.getRoot() const proof = tree.getProof(leaves[2]) const verified = tree.verify(proof, leaves[2], root)

Parameters:

Name Type Description
proof any[] Array of proof objects that should connect target node to Merkle root.
targetNode Buffer Target node Buffer
root Buffer Merkle root Buffer

Returns: boolean


verifyMultiProof

verifyMultiProof(root: Buffer, indices: number[], leaves: Buffer[], depth: number, proof: Buffer[]): boolean

verifyMultiProof

desc Returns true if the multiproofs can connect the leaves to the Merkle root.

example

const root = tree.getRoot() const treeFlat = tree.getLayersFlat() const depth = tree.getDepth() const indices = [2, 5, 6] const proofLeaves = indices.map(i => leaves[i]) const proof = tree.getMultiProof(treeFlat, indices) const verified = tree.verifyMultiProof(root, indices, proofLeaves, depth, proof)

Parameters:

Name Type Description
root Buffer Merkle tree root
indices number[] Leave indices
leaves Buffer[] Leaf values at indices.
depth number Tree depth
proof Buffer[] Multiproofs given indices

Returns: boolean


Static bufferify

bufferify(value: any): Buffer

bufferify

desc Returns a buffer type for the given value.

example

const buf = MerkleTree.bufferify('0x1234')

Parameters:

Name Type
value any

Returns: Buffer


Static getMultiProof

getMultiProof(tree: Buffer[], indices: number[]): Buffer[]

getMultiProof

desc Returns the multiproof for given tree indices.

example

const flatTree = tree.getLayersFlat() const indices = [2, 5, 6] const proof = MerkleTree.getMultiProof(flatTree, indices)

Parameters:

Name Type Description
tree Buffer[] Tree as a flat array.
indices number[] Tree indices.

Returns: Buffer[]

  • Multiproofs

Static isHexString

isHexString(v: string): boolean

isHexString

desc Returns true if value is a hex string.

example

console.log(MerkleTree.isHexString('0x1234'))

Parameters:

Name Type
v string

Returns: boolean


Static print

print(tree: any): void

print

desc Prints out a visual representation of the given merkle tree.

example

MerkleTree.print(tree)

Parameters:

Name Type Description
tree any Merkle tree instance.

Returns: void

Interface: Options

Hierarchy

  • Options

Index

Properties

  • duplicateOdd
  • hashLeaves
  • isBitcoinTree
  • sort
  • sortLeaves
  • sortPairs

Properties

Optional duplicateOdd

duplicateOdd? : boolean

If set to true, an odd node will be duplicated and combined to make a pair to generate the layer hash.


Optional hashLeaves

hashLeaves? : boolean

If set to true, the leaves will hashed using the set hashing algorithms.


Optional isBitcoinTree

isBitcoinTree? : boolean

If set to true, constructs the Merkle Tree using the Bitcoin Merkle Tree implementation. Enable it when you need to replicate Bitcoin constructed Merkle Trees. In Bitcoin Merkle Trees, single nodes are combined with themselves, and each output hash is hashed again.


Optional sort

sort? : boolean

If set to true, the leaves and hashing pairs will be sorted.


Optional sortLeaves

sortLeaves? : boolean

If set to true, the leaves will be sorted.


Optional sortPairs

sortPairs? : boolean

If set to true, the hashing pairs will be sorted.

Test

npm test

FAQ

  • Q: How do you verify merkle proofs in Solidity?

    • A: Check out the example repo merkletreejs-solidity on how to generate merkle proofs with this library and verify them in Solidity.
  • Q: How do you verify merkle multiproofs in Solidity?

    • A: Check out the example repo merkletreejs-multiproof-solidity on how to generate merkle multiproofs with this library and verify them in Solidity.

Notes

As is, this implemenation is vulnerable to a second pre-image attack. Use a difference hashing algorithm function for leaves and nodes, so that H(x) != H'(x).

Also, as is, this implementation is vulnerable to a forgery attack for an unbalanced tree, where the last leaf node can be duplicated to create an artificial balanced tree, resulting in the same Merkle root hash. Do not accept unbalanced tree to prevent this.

More info here.

Resources

  • Bitcoin mining the hard way: the algorithms, protocols, and bytes

  • Bitcoin Talk – Merkle Trees

  • How Log Proofs Work

  • Raiden Merkle Tree Implemenation

  • Why aren’t Solidity sha3 hashes not matching what other sha3 libraries produce?

  • What is the purpose of using different hash functions for the leaves and internals of a hash tree?

  • Why is the full Merkle path needed to verify a transaction?

  • Where is Double hashing performed in Bitcoin?

  • Compact Merkle Multiproofs

  • Eth 2.0 specs – Merkle Multiproofs

Contributing

Pull requests are welcome!

For contributions please create a new branch and submit a pull request for review.

License

MIT


内容

建设者

用JavaScript构造Merkle树并验证证明。

MerkleTree.js - 梅克尔树.js MerkleTree.js - 梅克尔树.js MerkleTree.js - 梅克尔树.js MerkleTree.js - 梅克尔树.js MerkleTree.js - 梅克尔树.js

建设者

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • Resources
  • Contributing
  • License

建设者

<MerkleTree.js><MerkleTree.js><MerkleTree.js><MerkleTree.js><MerkleTree.js><MerkleTree.js>MerkleTree.js - 梅克尔树.js

来自NPM:

可在jsdeliver CDN上获得:

构造树,生成证据,并验证证明:

将树打印到控制台:

输出

▾Merkle树的可视化BTCMerkle树。所有节点和叶都存储为缓冲区。孤叶节点被提升到上一级,而不会再次被哈希化。

示例

参数:

返回:MerkleTree

▸getDepth():number

getDepth

desc返回树的深度(层数)

示例

返回:number

▸getHexLayers():string[]

getHexLayers

desc返回梅克尔树,包括叶和根作为十六进制字符串。

示例

返回:string[]

▸getHexLayerFlat():string[]

GetHexLayerFlat

desc返回Merkle树所有层的单个平面数组,包括叶和根作为十六进制字符串。

示例

返回:string[]

▸getHexLeaves():string[]

getHexLeaves

desc以十六进制字符串的形式返回Merkle树的叶子数组。

示例

返回:string[]

▸getHexMultiProof(tree:Buffer[],index:number[]):string[]

getHexMultiProof

desc以十六进制字符串的形式返回给定树索引的多屋顶。

示例

参数:

返回:string[]

▸getHexProof(leaf:Buffer,index?:number):string[]

getHexProof

desc以十六进制字符串的形式返回目标叶的证明。

示例

参数:

返回:string[]

▸getHexRoot():string

getHexRoot

desc以十六进制字符串的形式返回Merkle根哈希。

示例

返回:string

▸getLayers():Buffer[]

getLayers

desc返回Merkle树所有层的多维数组,包括叶和根。

示例

返回:Buffer[]

▸getLayersSobject():any

GetLayerSobject

desc将层作为嵌套对象而不是数组返回。

示例

返回:any

▸getLayerFlat():Buffer[]

GetLayerFlat

desc返回Merkle树所有层的单个平面数组,包括叶和根。

示例

返回:Buffer[]

▸getLeaves(值?:any[]):Buffer[]

getLeaves

desc返回Merkle树的叶子数组。

示例

参数:

返回:Buffer[]

▸getMultiProof(tree?:任何[],索引?:any[]):Buffer[]

getMultiProof

desc返回给定树索引的多屋顶。

示例

参数:

返回:Buffer[]

▸getProof(leaf:Buffer,index?:number):any[]

getProof

desc返回目标叶的证明。

示例

示例

参数:

返回:any[]

▸getProofFlags(leaves:Buffer[],proof:Buffer[]):boolean[]

getProofFlags

desc返回布尔值列表,其中应使用证明而不是散列。在Solidity多重验证程序中使用了证明标志。

示例

参数:

返回:boolean[]

▸getProofIndices(treeIndices:number[],depth:number):number[]

getProofIndexes

desc返回给定树索引的验证索引。

示例

参数:

返回:number[]

▸getRoot():Buffer

getRoot

desc返回Merkle根哈希作为缓冲区。

示例

返回:Buffer

▸print():void

print

desc打印merkle树的可视化表示。

示例

返回:void

▸toString():string

toString

desc将merkle树的可视化表示形式返回为字符串。

示例

返回:string

▸verify(proof:any[],targetNode:Buffer,root:Buffer):boolean

verify

desc如果证明路径(哈希数组)可以将目标节点连接到Merkle根,则返回true。

示例

参数:

返回:boolean

▸verifyMultiProof(root:Buffer,index:number[],leaves:Buffer[],depth:number,proof:Buffer[]):boolean

verifyMultiProof

desc返回true,如果多屋顶可以将叶连接到Merkle根。

示例

参数:

返回:boolean

▸bufferify(值:any):Buffer

bufferify

desc返回给定值的缓冲区类型。

示例

参数:

返回:Buffer

▸getMultiProof(tree:Buffer[],index:number[]):Buffer[]

getMultiProof

desc返回给定树索引的多顶点。

示例

参数:

返回:Buffer[]

▸isHexString(v:string):布尔值

isHexString

desc如果值是十六进制字符串,则返回true。

示例

参数:

返回:boolean

▸print(tree:any):void

print

desc打印给定merkle树的可视化表示。

示例

参数:

返回:void

•duplicateOdd?:boolean

如果设置为true,则将复制并组合一个奇数节点以生成层哈希。

•哈希叶?:boolean

如果设置为true,则将使用set hashing算法对叶进行哈希处理。

•isBitcoinTree?:boolean如果设置为true,则使用BTCMerkle树实现构造Merkle树。当您需要复制BTC构建的Merkle树时启用它。在BTCMerkle树中,单个节点与其自身结合,然后对每个输出哈希进行再次哈希处理。

•排序?:boolean

如果设置为true,则叶和哈希对将被排序。

•分类存储?:boolean

如果设置为true,将对树叶进行排序。

•分拣?:boolean

如果设置为true,将对哈希对进行排序。

Q:如何验证merkle证明的可靠性?

Q:如何验证merkle多屋顶的坚固性?

实际上,此实现容易受到第二次图像前攻击。对叶子和节点使用差分散列算法函数,使H(x)!=H’(x)。

同样,这种实现方式容易受到针对不平衡树的伪造攻击,其中可以复制最后一个叶节点来创建人工平衡树,从而产生相同的Merkle根散列。不要接受不平衡树来防止这种情况。

更多信息请点击此处。

BTC挖掘的艰难之路:算法、协议和字节数?

对哈希树的叶和内部使用不同的哈希函数的目的是什么?

为什么需要完整的Merkle路径来验证事务?

BTC中的双哈希在哪里执行?

Compact Merkle多屋顶

Eth 2.0规范-Merkle Multi车顶

欢迎请求拉取!

对于供款,请创建一个新的分支机构并提交请求以供审核。

麻省理工学院梅克尔树.js

内容

安装方法

建设者

建设者

建设者

方法的方法

getHexLayers

getHexLayers的getHexLayersFlat

GetHexMultip顶

GetLayersAsO3>

GetLayersO3 rsflat

在这个项目上,这个项目的两个主要项目分别是:h3>

getmultipop

在这个项目上,

getproverflags

GetRootGetroot

打印打印打印

toString

验证

verifyMultiProof

静态Bufferifyfh3>

静态静态静态静态静态的

静态ISh3>静态ISh3>静态ISh3>

静态h3>静态打印接口:选项

资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • npm install merkletreejs

    方法的方法

    来自NPM:

    <script src="https://cdn.jsdelivr.net/npm/merkletreejs@latest/merkletree.js"></script>

    getHexLayers

    getHexLayers的getHexLayersFlat

    GetHexMultip顶

    GetLayersAsO3>

    GetLayersO3 rsflat

    在这个项目上,这个项目的两个主要项目分别是:h3>

    getmultipop

    在这个项目上,

    getproverflags

    GetRootGetroot

    打印打印打印

    toString

    验证

    verifyMultiProof

    静态Bufferifyfh3>

    静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • 可在jsdeliver CDN上获得:

    const { MerkleTree } = require('merkletreejs') const SHA256 = require('crypto-js/sha256')  const leaves = ['a', 'b', 'c'].map(x => SHA256(x)) const tree = new MerkleTree(leaves, SHA256) const root = tree.getRoot().toString('hex') const leaf = SHA256('a') const proof = tree.getProof(leaf) console.log(tree.verify(proof, leaf, root)) // true   const badLeaves = ['a', 'x', 'c'].map(x => SHA256(x)) const badTree = new MerkleTree(badLeaves, SHA256) const badLeaf = SHA256('x') const badProof = tree.getProof(badLeaf) console.log(tree.verify(badProof, leaf, root)) // false

    构造树,生成证据,并验证证明:

    MerkleTree.print(tree)

    将树打印到控制台:

    └─ 311d2e46f49b15fff8b746b74ad57f2cc9e0d9939fda94387141a2d3fdf187ae    ├─ 176f0f307632fdd5831875eb709e2f68d770b102262998b214ddeb3f04164ae1    │  ├─ 3ac225168df54212a25c1c01fd35bebfea408fdac2e31ddd6f80a4bbf9a5f1cb    │  └─ b5553de315e0edf504d9150af82dafa5c4667fa618ed0a6f19c69b41166c5510    └─ 0b42b6393c1f53060fe3ddbfcd7aadcca894465a5a438f69c87d790b2299b9b2       └─ 0b42b6393c1f53060fe3ddbfcd7aadcca894465a5a438f69c87d790b2299b9b2

    getHexLayers

    输出

    ▾Merkle树的可视化BTCMerkle树。所有节点和叶都存储为缓冲区。孤叶节点被提升到上一级,而不会再次被哈希化。

    示例

    参数:

    返回:MerkleTree

    ▸getDepth():number

    getDepth

    desc返回树的深度(层数)

    getHexLayers的getHexLayersFlat

    GetHexMultip顶

    GetLayersAsO3>

    GetLayersO3 rsflat

    在这个项目上,这个项目的两个主要项目分别是:h3>

    getmultipop

    在这个项目上,

    getproverflags

    GetRootGetroot

    打印打印打印

    toString

    验证

    verifyMultiProof

    静态Bufferifyfh3>

    静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • 示例

    返回:number

    GetHexMultip顶

    • MerkleTree

    GetLayersAsO3>

    GetLayersO3 rsflat

    在这个项目上,这个项目的两个主要项目分别是:h3>

    getmultipop

    在这个项目上,

    getproverflags

    GetRootGetroot

    打印打印打印

    toString

    验证

    verifyMultiProof

    静态Bufferifyfh3>

    静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • GetLayersAsO3>

    GetLayersO3 rsflat

    在这个项目上,这个项目的两个主要项目分别是:h3>

    getmultipop

    在这个项目上,

    getproverflags

    GetRootGetroot

    打印打印打印

    toString

    验证

    verifyMultiProof

    静态Bufferifyfh3>

    静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
    • constructor

    GetLayersAsO3>

    GetLayersO3 rsflat

    在这个项目上,这个项目的两个主要项目分别是:h3>

    getmultipop

    在这个项目上,

    getproverflags

    GetRootGetroot

    打印打印打印

    toString

    验证

    verifyMultiProof

    静态Bufferifyfh3>

    静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
    • getDepth
    • getHexLayers
    • getHexLayersFlat
    • getHexLeaves
    • getHexMultiProof
    • getHexProof
    • getHexRoot
    • getLayers
    • getLayersAsObject
    • getLayersFlat
    • getLeaves
    • getMultiProof
    • getProof
    • getProofFlags
    • getProofIndices
    • getRoot
    • print
    • toString
    • verify
    • verifyMultiProof
    • bufferify
    • getMultiProof
    • isHexString
    • print

    GetLayersAsO3>

    GetLayersO3 rsflat

    在这个项目上,这个项目的两个主要项目分别是:h3>

    getmultipop

    在这个项目上,

    getproverflags

    GetRootGetroot

    打印打印打印

    toString

    验证

    verifyMultiProof

    静态Bufferifyfh3>

    静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • GetLayersAsO3>

    GetLayersO3 rsflat

    在这个项目上,这个项目的两个主要项目分别是:h3>

    getmultipop

    在这个项目上,

    getproverflags

    GetRootGetroot

    打印打印打印

    toString

    验证

    verifyMultiProof

    静态Bufferifyfh3>

    静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • ▸getHexLayers():string[]

    getHexLayers

    desc返回梅克尔树,包括叶和根作为十六进制字符串。

    const MerkleTree = require('merkletreejs') const crypto = require('crypto')  function sha256(data) {  // returns Buffer  return crypto.createHash('sha256').update(data).digest() }  const leaves = ['a', 'b', 'c'].map(x => keccak(x))  const tree = new MerkleTree(leaves, sha256)

    示例

    Name Type Default Description
    leaves any[] Array of hashed leaves. Each leaf must be a Buffer.
    hashAlgorithm any SHA256 Algorithm used for hashing leaves and nodes
    options Options {} Additional options

    返回:string[]

    GetLayersAsO3>

    GetLayersO3 rsflat

    在这个项目上,这个项目的两个主要项目分别是:h3>

    getmultipop

    在这个项目上,

    getproverflags

    GetRootGetroot

    打印打印打印

    toString

    验证

    verifyMultiProof

    静态Bufferifyfh3>

    静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • GetLayersAsO3>

    GetLayersO3 rsflat

    在这个项目上,这个项目的两个主要项目分别是:h3>

    getmultipop

    在这个项目上,

    getproverflags

    GetRootGetroot

    打印打印打印

    toString

    验证

    verifyMultiProof

    静态Bufferifyfh3>

    静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • ▸getHexLayerFlat():string[]

    GetHexLayerFlat

    desc返回Merkle树所有层的单个平面数组,包括叶和根作为十六进制字符串。

    示例

    const depth = tree.getDepth()

    返回:string[]


    GetLayersAsO3>

    GetLayersO3 rsflat

    在这个项目上,这个项目的两个主要项目分别是:h3>

    getmultipop

    在这个项目上,

    getproverflags

    GetRootGetroot

    打印打印打印

    toString

    验证

    verifyMultiProof

    静态Bufferifyfh3>

    静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • ▸getHexLeaves():string[]

    getHexLeaves

    desc以十六进制字符串的形式返回Merkle树的叶子数组。

    示例

    const layers = tree.getHexLayers()

    返回:string[]


    GetLayersAsO3>

    GetLayersO3 rsflat

    在这个项目上,这个项目的两个主要项目分别是:h3>

    getmultipop

    在这个项目上,

    getproverflags

    GetRootGetroot

    打印打印打印

    toString

    验证

    verifyMultiProof

    静态Bufferifyfh3>

    静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • ▸getHexMultiProof(tree:Buffer[],index:number[]):string[]

    getHexMultiProof

    desc以十六进制字符串的形式返回给定树索引的多屋顶。

    示例

    const layers = tree.getHexLayersFlat()

    参数:


    GetLayersAsO3>

    GetLayersO3 rsflat

    在这个项目上,这个项目的两个主要项目分别是:h3>

    getmultipop

    在这个项目上,

    getproverflags

    GetRootGetroot

    打印打印打印

    toString

    验证

    verifyMultiProof

    静态Bufferifyfh3>

    静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • 返回:string[]

    ▸getHexProof(leaf:Buffer,index?:number):string[]

    getHexProof

    desc以十六进制字符串的形式返回目标叶的证明。

    const leaves = tree.getHexLeaves()

    示例


    GetLayersAsO3>

    GetLayersO3 rsflat

    在这个项目上,这个项目的两个主要项目分别是:h3>

    getmultipop

    在这个项目上,

    getproverflags

    GetRootGetroot

    打印打印打印

    toString

    验证

    verifyMultiProof

    静态Bufferifyfh3>

    静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • 参数:

    返回:string[]

    ▸getHexRoot():string

    getHexRoot

    const indices = [2, 5, 6] const proof = tree.getHexMultiProof(indices)

    desc以十六进制字符串的形式返回Merkle根哈希。

    Name Type Description
    tree Buffer[]
    indices number[] Tree indices.

    示例

    • Multiproofs as hex strings.

    GetLayersAsO3>

    GetLayersO3 rsflat

    在这个项目上,这个项目的两个主要项目分别是:h3>

    getmultipop

    在这个项目上,

    getproverflags

    GetRootGetroot

    打印打印打印

    toString

    验证

    verifyMultiProof

    静态Bufferifyfh3>

    静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • 返回:string

    ▸getLayers():Buffer[]

    getLayers

    desc返回Merkle树所有层的多维数组,包括叶和根。

    const proof = tree.getHexProof(leaves[2])

    示例

    Name Type Description
    leaf Buffer Target leaf
    index? number

    返回:Buffer[]

    • Proof array as hex strings.

    GetLayersAsO3>

    GetLayersO3 rsflat

    在这个项目上,这个项目的两个主要项目分别是:h3>

    getmultipop

    在这个项目上,

    getproverflags

    GetRootGetroot

    打印打印打印

    toString

    验证

    verifyMultiProof

    静态Bufferifyfh3>

    静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • ▸getLayersSobject():any

    GetLayerSobject

    desc将层作为嵌套对象而不是数组返回。

    示例

    const root = tree.getHexRoot()

    返回:any


    GetLayersAsO3>

    GetLayersO3 rsflat

    在这个项目上,这个项目的两个主要项目分别是:h3>

    getmultipop

    在这个项目上,

    getproverflags

    GetRootGetroot

    打印打印打印

    toString

    验证

    verifyMultiProof

    静态Bufferifyfh3>

    静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • ▸getLayerFlat():Buffer[]

    GetLayerFlat

    desc返回Merkle树所有层的单个平面数组,包括叶和根。

    示例

    const layers = tree.getLayers()

    返回:Buffer[]


    GetLayersAsO3>

    GetLayersO3 rsflat

    在这个项目上,这个项目的两个主要项目分别是:h3>

    getmultipop

    在这个项目上,

    getproverflags

    GetRootGetroot

    打印打印打印

    toString

    验证

    verifyMultiProof

    静态Bufferifyfh3>

    静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • ▸getLeaves(值?:any[]):Buffer[]

    getLeaves

    desc返回Merkle树的叶子数组。

    示例

    const layersObj = tree.getLayersAsObject()

    参数:


    GetLayersO3 rsflat

    返回:Buffer[]

    ▸getMultiProof(tree?:任何[],索引?:any[]):Buffer[]

    getMultiProof

    desc返回给定树索引的多屋顶。

    const layers = tree.getLayersFlat()

    示例


    在这个项目上,这个项目的两个主要项目分别是:h3>

    getmultipop

    在这个项目上,

    getproverflags

    GetRootGetroot

    打印打印打印

    toString

    验证

    verifyMultiProof

    静态Bufferifyfh3>

    静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • 参数:

    返回:Buffer[]

    ▸getProof(leaf:Buffer,index?:number):any[]

    getProof

    const leaves = tree.getLeaves()

    desc返回目标叶的证明。

    Name Type
    values? any[]

    示例


    getmultipop

    在这个项目上,

    getproverflags

    GetRootGetroot

    打印打印打印

    toString

    验证

    verifyMultiProof

    静态Bufferifyfh3>

    静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • 示例

    参数:

    返回:any[]

    ▸getProofFlags(leaves:Buffer[],proof:Buffer[]):boolean[]

    const indices = [2, 5, 6] const proof = tree.getMultiProof(indices)

    getProofFlags

    Name Type Description
    tree? any[]
    indices? any[] Tree indices.

    desc返回布尔值列表,其中应使用证明而不是散列。在Solidity多重验证程序中使用了证明标志。

    • Multiproofs

    getmultipop

    示例

    参数:

    返回:boolean[]

    ▸getProofIndices(treeIndices:number[],depth:number):number[]

    const proof = tree.getProof(leaves[2])

    getProofIndexes

    const leaves = ['a', 'b', 'a'].map(x => keccak(x)) const tree = new MerkleTree(leaves, keccak) const proof = tree.getProof(leaves[2], 2)

    desc返回给定树索引的验证索引。

    Name Type Description
    leaf Buffer Target leaf
    index? number

    示例

    • Array of objects containing a position property of type string with values of ‘left’ or ‘right’ and a data property of type Buffer.

    在这个项目上,

    getproverflags

    GetRootGetroot

    打印打印打印

    toString

    验证

    verifyMultiProof

    静态Bufferifyfh3>

    静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • 参数:

    返回:number[]

    ▸getRoot():Buffer

    getRoot

    const indices = [2, 5, 6] const proof = tree.getMultiProof(indices) const proofFlags = tree.getProofFlags(leaves, proof)

    desc返回Merkle根哈希作为缓冲区。

    Name Type
    leaves Buffer[]
    proofs Buffer[]

    示例

    • Boolean flags

    getproverflags

    GetRootGetroot

    打印打印打印

    toString

    验证

    verifyMultiProof

    静态Bufferifyfh3>

    静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • 返回:Buffer

    ▸print():void

    print

    desc打印merkle树的可视化表示。

    const proofIndices = tree.getProofIndices([2,5,6], 4) console.log(proofIndices) // [ 23, 20, 19, 8, 3 ]

    示例

    Name Type Description
    treeIndices number[] Tree indices
    depth number Tree depth; number of layers.

    返回:void

    • Proof indices

    getproverflags

    GetRootGetroot

    打印打印打印

    toString

    验证

    verifyMultiProof

    静态Bufferifyfh3>

    静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • ▸toString():string

    toString

    desc将merkle树的可视化表示形式返回为字符串。

    示例

    const root = tree.getRoot()

    返回:string


    GetRootGetroot

    打印打印打印

    toString

    验证

    verifyMultiProof

    静态Bufferifyfh3>

    静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • ▸verify(proof:any[],targetNode:Buffer,root:Buffer):boolean

    verify

    desc如果证明路径(哈希数组)可以将目标节点连接到Merkle根,则返回true。

    示例

    tree.print()

    参数:


    GetRootGetroot

    打印打印打印

    toString

    验证

    verifyMultiProof

    静态Bufferifyfh3>

    静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • 返回:boolean

    ▸verifyMultiProof(root:Buffer,index:number[],leaves:Buffer[],depth:number,proof:Buffer[]):boolean

    verifyMultiProof

    desc返回true,如果多屋顶可以将叶连接到Merkle根。

    console.log(tree.toString())

    示例


    GetRootGetroot

    打印打印打印

    toString

    验证

    verifyMultiProof

    静态Bufferifyfh3>

    静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • 参数:

    返回:boolean

    ▸bufferify(值:any):Buffer

    bufferify

    const root = tree.getRoot() const proof = tree.getProof(leaves[2]) const verified = tree.verify(proof, leaves[2], root)

    desc返回给定值的缓冲区类型。

    Name Type Description
    proof any[] Array of proof objects that should connect target node to Merkle root.
    targetNode Buffer Target node Buffer
    root Buffer Merkle root Buffer

    示例


    GetRootGetroot

    打印打印打印

    toString

    验证

    verifyMultiProof

    静态Bufferifyfh3>

    静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • 参数:

    返回:Buffer

    ▸getMultiProof(tree:Buffer[],index:number[]):Buffer[]

    getMultiProof

    const root = tree.getRoot() const treeFlat = tree.getLayersFlat() const depth = tree.getDepth() const indices = [2, 5, 6] const proofLeaves = indices.map(i => leaves[i]) const proof = tree.getMultiProof(treeFlat, indices) const verified = tree.verifyMultiProof(root, indices, proofLeaves, depth, proof)

    desc返回给定树索引的多顶点。

    Name Type Description
    root Buffer Merkle tree root
    indices number[] Leave indices
    leaves Buffer[] Leaf values at indices.
    depth number Tree depth
    proof Buffer[] Multiproofs given indices

    示例


    GetRootGetroot

    参数:

    返回:Buffer[]

    ▸isHexString(v:string):布尔值

    isHexString

    const buf = MerkleTree.bufferify('0x1234')

    desc如果值是十六进制字符串,则返回true。

    Name Type
    value any

    示例


    打印打印打印

    参数:

    返回:boolean

    ▸print(tree:any):void

    print

    const flatTree = tree.getLayersFlat() const indices = [2, 5, 6] const proof = MerkleTree.getMultiProof(flatTree, indices)

    desc打印给定merkle树的可视化表示。

    Name Type Description
    tree Buffer[] Tree as a flat array.
    indices number[] Tree indices.

    示例

    • Multiproofs

    toString

    参数:

    返回:void

    •duplicateOdd?:boolean

    如果设置为true,则将复制并组合一个奇数节点以生成层哈希。

    console.log(MerkleTree.isHexString('0x1234'))

    •哈希叶?:boolean

    Name Type
    v string

    如果设置为true,则将使用set hashing算法对叶进行哈希处理。


    验证

    verifyMultiProof

    静态Bufferifyfh3>

    静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • •isBitcoinTree?:boolean如果设置为true,则使用BTCMerkle树实现构造Merkle树。当您需要复制BTC构建的Merkle树时启用它。在BTCMerkle树中,单个节点与其自身结合,然后对每个输出哈希进行再次哈希处理。

    •排序?:boolean

    如果设置为true,则叶和哈希对将被排序。

    •分类存储?:boolean

    MerkleTree.print(tree)

    如果设置为true,将对树叶进行排序。

    Name Type Description
    tree any Merkle tree instance.

    •分拣?:boolean

    验证

    verifyMultiProof

    • Options

    静态Bufferifyfh3>

    静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • 静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
    • duplicateOdd
    • hashLeaves
    • isBitcoinTree
    • sort
    • sortLeaves
    • sortPairs

    静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • 如果设置为true,将对哈希对进行排序。

    Q:如何验证merkle证明的可靠性?


    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • Q:如何验证merkle多屋顶的坚固性?

    实际上,此实现容易受到第二次图像前攻击。对叶子和节点使用差分散列算法函数,使H(x)!=H’(x)。


    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • 同样,这种实现方式容易受到针对不平衡树的伪造攻击,其中可以复制最后一个叶节点来创建人工平衡树,从而产生相同的Merkle根散列。不要接受不平衡树来防止这种情况。

    更多信息请点击此处。


    Optional sort

    BTC挖掘的艰难之路:算法、协议和字节数?

    对哈希树的叶和内部使用不同的哈希函数的目的是什么?


    Optional sortLeaves

    为什么需要完整的Merkle路径来验证事务?

    BTC中的双哈希在哪里执行?


    Optional sortPairs

    Compact Merkle多屋顶

    Eth 2.0规范-Merkle Multi车顶

    Test

    npm test

    FAQ

    • 欢迎请求拉取!

      • A: Check out the example repo merkletreejs-solidity on how to generate merkle proofs with this library and verify them in Solidity.
    • 对于供款,请创建一个新的分支机构并提交请求以供审核。

      • A: Check out the example repo merkletreejs-multiproof-solidity on how to generate merkle multiproofs with this library and verify them in Solidity.

    Notes

    麻省理工学院梅克尔树.js

    内容

    安装方法

    建设者

    建设者

    建设者

    方法的方法

    getHexLayers

    getHexLayers的getHexLayersFlat

    GetHexMultip顶

    GetLayersAsO3>

    GetLayersO3 rsflat

    在这个项目上,这个项目的两个主要项目分别是:h3>

    getmultipop

    在这个项目上,

    getproverflags

    GetRootGetroot

    打印打印打印

    toString

    验证

    verifyMultiProof

    静态Bufferifyfh3>

    静态静态静态静态静态的

    静态ISh3>静态ISh3>静态ISh3>

    静态h3>静态打印接口:选项

    资源

  • 获取HexLayers
  • getHexLayersFlat
  • getHexLeaves
  • getHexProof
  • getHexRoot
  • GetLayersSobject
  • GetLayersSobject
  • Also, as is, this implementation is vulnerable to a forgery attack for an unbalanced tree, where the last leaf node can be duplicated to create an artificial balanced tree, resulting in the same Merkle root hash. Do not accept unbalanced tree to prevent this.

    More info here.

    Resources

    • Bitcoin mining the hard way: the algorithms, protocols, and bytes

    • Bitcoin Talk – Merkle Trees

    • How Log Proofs Work

    • Raiden Merkle Tree Implemenation

    • Why aren’t Solidity sha3 hashes not matching what other sha3 libraries produce?

    • What is the purpose of using different hash functions for the leaves and internals of a hash tree?

    • Why is the full Merkle path needed to verify a transaction?

    • Where is Double hashing performed in Bitcoin?

    • Compact Merkle Multiproofs

    • Eth 2.0 specs – Merkle Multiproofs

    Contributing

    Pull requests are welcome!

    For contributions please create a new branch and submit a pull request for review.

    License

    MIT

  • 部分转自网络,侵权联系删除区块链源码网

    www.interchains.cc

    https://www.interchains.cc/16414.html

    区块链毕设网(www.interchains.cc)全网最靠谱的原创区块链毕设代做网站 部分资料来自网络,侵权联系删除! 最全最大的区块链源码站 !
    区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » MerkleTree.js – 梅克尔树.js区块链毕设代写

    提供最优质的资源集合

    立即查看 了解详情