mirror of
https://github.com/arnaucube/circomlib.git
synced 2026-02-07 11:16:45 +01:00
First Version SMT
This commit is contained in:
31
src/smt_memdb.js
Normal file
31
src/smt_memdb.js
Normal file
@@ -0,0 +1,31 @@
|
||||
const bigInt = require("snarkjs").bigInt;
|
||||
|
||||
class SMTMemDb {
|
||||
constructor() {
|
||||
this.nodes = {};
|
||||
this.root = bigInt(0);
|
||||
}
|
||||
|
||||
async getRoot() {
|
||||
return this.root;
|
||||
}
|
||||
|
||||
async get(key) {
|
||||
const res = [];
|
||||
const keyS = bigInt(key).leInt2Buff(32).toString("hex");
|
||||
for (let i=0; i<this.nodes[keyS].length; i++) {
|
||||
res.push(bigInt(this.nodes[keyS][i]));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
async save(root, inserts) {
|
||||
for (let i=0; i<inserts.length; i++) {
|
||||
const keyS = bigInt(inserts[i][0]).leInt2Buff(32).toString("hex");
|
||||
this.nodes[keyS] = inserts[i][1];
|
||||
}
|
||||
this.root = root;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SMTMemDb;
|
||||
Reference in New Issue
Block a user