circomlib/src/smt_memdb.js
src/smt_memdb.jsRaw
1const bigInt = require("snarkjs").bigInt;
2
3class SMTMemDb {
4 constructor() {
5 this.nodes = {};
6 this.root = bigInt(0);
7 }
8
9 async getRoot() {
10 return this.root;
11 }
12
13 async get(key) {
14 const res = [];
15 const keyS = bigInt(key).leInt2Buff(32).toString("hex");
16 for (let i=0; i<this.nodes[keyS].length; i++) {
17 res.push(bigInt(this.nodes[keyS][i]));
18 }
19 return res;
20 }
21
22 async save(root, inserts) {
23 for (let i=0; i<inserts.length; i++) {
24 const keyS = bigInt(inserts[i][0]).leInt2Buff(32).toString("hex");
25 this.nodes[keyS] = inserts[i][1];
26 }
27 this.root = root;
28 }
29}
30
31module.exports = SMTMemDb;