First Version SMT

This commit is contained in:
Jordi Baylina
2018-12-11 17:25:21 +01:00
parent 2d43178c8d
commit 38fc4b7396
15 changed files with 495 additions and 122321 deletions

31
src/smt_memdb.js Normal file
View 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;