-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
29 lines (26 loc) · 1.01 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import MemDown from "memdown";
import { BaseTrie as Trie } from "merkle-patricia-tree";
// const db = level("./testdb");
const db = MemDown();
const trie = new Trie(db);
async function test() {
await trie.put(Buffer.from("test"), Buffer.from("one"), function (err) {
if (err) return console.log("put error", err);
console.log("put success");
});
await trie.put(Buffer.from("test"), Buffer.from("one"), function (err) {
if (err) return console.log("put error", err);
console.log("put success");
});
await trie.put(Buffer.from("test2"), Buffer.from("two"), function (err) {
if (err) return console.log("put error", err);
console.log("put success");
});
const value1 = await trie.get(Buffer.from("test"));
console.log(value1.toString()); // one
// this will proove that test3 is not a hash in tree
const proof = await Trie.createProof(trie, Buffer.from("test3"));
const value = await Trie.verifyProof(trie.root, Buffer.from("test3"), proof);
console.log(value.toString()); //
}
test();