@0xcert/merkle 中文文档教程
二叉默克尔树基本功能的实现。
这个模块像这样处理二叉树(v = 值,n = 节点,r = 随机数):
n0
|
---------
| |
n1 n2
| |
|-----| |
v0 r0 |
---------
| |
n3 n4
| |
|-----| |
v1 r1 r2
用户定义一个值数组,其中这些值被散列到 imprint
中,这是一个 Merkle 根树哈希。 用户可以通过提供包含 values
和 nodes
配方的证据文件将所选值公开给第三方。 此文件包含足够的信息供第三方重新创建印记。
import { sha } from '@0xcert/utils';
import { Merkle } from '@0xcert/merkle';
const merkle = new Merkle({
hasher: (v, p, k) => sha(256, v),
noncer: (p) => Math.random().toString(36).substring(7),
});
const values = ['A', 'B', 'C', 'D', 'E'];
const expose = [2, 3];
const fullRecipe = await merkle.notarize(values);
const minRecipe = await merkle.disclose(fullRecipe, expose);
const imprint = await merkle.imprint(minRecipe);
0xcert Framework 是一个免费的开源 JavaScript 库,它提供用于构建强大的去中心化应用程序的工具。 请参阅官方文档了解更多详情。
该模块是 0xcert Framework 的组成部分之一。 它是用 TypeScript 编写的,并且得到积极维护。 源代码可在 GitHub 上找到,您还可以在其中找到我们的 问题跟踪器。
Implementation of basic functions of a binary Merkle tree.
This module handles binary trees like this (v = value, n = node, r = nonce):
n0
|
---------
| |
n1 n2
| |
|-----| |
v0 r0 |
---------
| |
n3 n4
| |
|-----| |
v1 r1 r2
A user defines an array of values where these values are hashed into an imprint
, which is a Merkle root tree hash. A user can expose selected values to a third-party by providing the evidence file which includes a recipe of values
and nodes
. This file holds enough information for a third-party to recreate the imprint.
import { sha } from '@0xcert/utils';
import { Merkle } from '@0xcert/merkle';
const merkle = new Merkle({
hasher: (v, p, k) => sha(256, v),
noncer: (p) => Math.random().toString(36).substring(7),
});
const values = ['A', 'B', 'C', 'D', 'E'];
const expose = [2, 3];
const fullRecipe = await merkle.notarize(values);
const minRecipe = await merkle.disclose(fullRecipe, expose);
const imprint = await merkle.imprint(minRecipe);
The 0xcert Framework is a free and open-source JavaScript library that provides tools for building powerful decentralized applications. Please refer to the official documentation for more details.
This module is one of the bricks of the 0xcert Framework. It's written with TypeScript and it's actively maintained. The source code is available on GitHub where you can also find our issue tracker.