zkjson 0.8.1 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/circomlibjs/SMTMemDb.js +105 -45
- package/cjs/collection_tree.js +57 -22
- package/cjs/db_tree.js +74 -17
- package/cjs/doc_tree.js +84 -0
- package/cjs/index.js +8 -0
- package/cjs/newMemEmptyTrie.js +4 -1
- package/cjs/prover.js +84 -0
- package/esm/circomlibjs/SMTMemDb.js +7 -6
- package/esm/collection_tree.js +38 -16
- package/esm/db_tree.js +30 -12
- package/esm/doc_tree.js +41 -0
- package/esm/index.js +2 -1
- package/esm/newMemEmptyTrie.js +1 -0
- package/esm/prover.js +41 -0
- package/package.json +1 -1
@@ -20,23 +20,52 @@ var SMTMemDb = exports["default"] = /*#__PURE__*/function () {
|
|
20
20
|
this.kv = kv;
|
21
21
|
this.nodes = {};
|
22
22
|
this.root = F.zero;
|
23
|
-
if (this.kv) {
|
24
|
-
var root = this.kv.get("root");
|
25
|
-
if (root) this.root = root;else this.kv.put("root", this.root);
|
26
|
-
}
|
27
23
|
this.F = F;
|
28
24
|
}
|
29
25
|
return _createClass(SMTMemDb, [{
|
30
|
-
key: "
|
26
|
+
key: "init",
|
31
27
|
value: function () {
|
32
|
-
var
|
28
|
+
var _init = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
29
|
+
var root;
|
33
30
|
return _regenerator().w(function (_context) {
|
34
31
|
while (1) switch (_context.n) {
|
35
32
|
case 0:
|
36
|
-
|
33
|
+
if (!this.kv) {
|
34
|
+
_context.n = 2;
|
35
|
+
break;
|
36
|
+
}
|
37
|
+
root = this.kv.get("root");
|
38
|
+
if (!root) {
|
39
|
+
_context.n = 1;
|
40
|
+
break;
|
41
|
+
}
|
42
|
+
this.root = root;
|
43
|
+
_context.n = 2;
|
44
|
+
break;
|
45
|
+
case 1:
|
46
|
+
_context.n = 2;
|
47
|
+
return this.kv.put("root", this.root);
|
48
|
+
case 2:
|
49
|
+
return _context.a(2);
|
37
50
|
}
|
38
51
|
}, _callee, this);
|
39
52
|
}));
|
53
|
+
function init() {
|
54
|
+
return _init.apply(this, arguments);
|
55
|
+
}
|
56
|
+
return init;
|
57
|
+
}()
|
58
|
+
}, {
|
59
|
+
key: "getRoot",
|
60
|
+
value: function () {
|
61
|
+
var _getRoot = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
|
62
|
+
return _regenerator().w(function (_context2) {
|
63
|
+
while (1) switch (_context2.n) {
|
64
|
+
case 0:
|
65
|
+
return _context2.a(2, this.root);
|
66
|
+
}
|
67
|
+
}, _callee2, this);
|
68
|
+
}));
|
40
69
|
function getRoot() {
|
41
70
|
return _getRoot.apply(this, arguments);
|
42
71
|
}
|
@@ -60,19 +89,19 @@ var SMTMemDb = exports["default"] = /*#__PURE__*/function () {
|
|
60
89
|
}, {
|
61
90
|
key: "get",
|
62
91
|
value: function () {
|
63
|
-
var _get = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
92
|
+
var _get = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(key) {
|
64
93
|
var keyS, node;
|
65
|
-
return _regenerator().w(function (
|
66
|
-
while (1) switch (
|
94
|
+
return _regenerator().w(function (_context3) {
|
95
|
+
while (1) switch (_context3.n) {
|
67
96
|
case 0:
|
68
97
|
keyS = this._key2str(key);
|
69
98
|
if (!this.nodes[keyS]) {
|
70
99
|
node = this.kv.get("node_".concat(keyS));
|
71
100
|
if (node) this.nodes[keyS] = node;
|
72
101
|
}
|
73
|
-
return
|
102
|
+
return _context3.a(2, this.nodes[keyS]);
|
74
103
|
}
|
75
|
-
},
|
104
|
+
}, _callee3, this);
|
76
105
|
}));
|
77
106
|
function get(_x) {
|
78
107
|
return _get.apply(this, arguments);
|
@@ -82,21 +111,21 @@ var SMTMemDb = exports["default"] = /*#__PURE__*/function () {
|
|
82
111
|
}, {
|
83
112
|
key: "multiGet",
|
84
113
|
value: function () {
|
85
|
-
var _multiGet = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
114
|
+
var _multiGet = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(keys) {
|
86
115
|
var promises, i;
|
87
|
-
return _regenerator().w(function (
|
88
|
-
while (1) switch (
|
116
|
+
return _regenerator().w(function (_context4) {
|
117
|
+
while (1) switch (_context4.n) {
|
89
118
|
case 0:
|
90
119
|
promises = [];
|
91
120
|
for (i = 0; i < keys.length; i++) {
|
92
121
|
promises.push(this.get(keys[i]));
|
93
122
|
}
|
94
|
-
|
123
|
+
_context4.n = 1;
|
95
124
|
return Promise.all(promises);
|
96
125
|
case 1:
|
97
|
-
return
|
126
|
+
return _context4.a(2, _context4.v);
|
98
127
|
}
|
99
|
-
},
|
128
|
+
}, _callee4, this);
|
100
129
|
}));
|
101
130
|
function multiGet(_x2) {
|
102
131
|
return _multiGet.apply(this, arguments);
|
@@ -106,16 +135,21 @@ var SMTMemDb = exports["default"] = /*#__PURE__*/function () {
|
|
106
135
|
}, {
|
107
136
|
key: "setRoot",
|
108
137
|
value: function () {
|
109
|
-
var _setRoot = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
110
|
-
return _regenerator().w(function (
|
111
|
-
while (1) switch (
|
138
|
+
var _setRoot = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(rt) {
|
139
|
+
return _regenerator().w(function (_context5) {
|
140
|
+
while (1) switch (_context5.n) {
|
112
141
|
case 0:
|
113
142
|
this.root = rt;
|
114
|
-
if (this.kv)
|
143
|
+
if (!this.kv) {
|
144
|
+
_context5.n = 1;
|
145
|
+
break;
|
146
|
+
}
|
147
|
+
_context5.n = 1;
|
148
|
+
return this.kv.put("root", this.root);
|
115
149
|
case 1:
|
116
|
-
return
|
150
|
+
return _context5.a(2);
|
117
151
|
}
|
118
|
-
},
|
152
|
+
}, _callee5, this);
|
119
153
|
}));
|
120
154
|
function setRoot(_x3) {
|
121
155
|
return _setRoot.apply(this, arguments);
|
@@ -125,21 +159,34 @@ var SMTMemDb = exports["default"] = /*#__PURE__*/function () {
|
|
125
159
|
}, {
|
126
160
|
key: "multiIns",
|
127
161
|
value: function () {
|
128
|
-
var _multiIns = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
162
|
+
var _multiIns = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(inserts) {
|
129
163
|
var i, keyS;
|
130
|
-
return _regenerator().w(function (
|
131
|
-
while (1) switch (
|
164
|
+
return _regenerator().w(function (_context6) {
|
165
|
+
while (1) switch (_context6.n) {
|
132
166
|
case 0:
|
133
|
-
|
134
|
-
keyS = this._key2str(inserts[i][0]);
|
135
|
-
this._normalize(inserts[i][1]);
|
136
|
-
this.nodes[keyS] = inserts[i][1];
|
137
|
-
if (this.kv) this.kv.put("node_".concat(keyS), this.nodes[keyS]);
|
138
|
-
}
|
167
|
+
i = 0;
|
139
168
|
case 1:
|
140
|
-
|
169
|
+
if (!(i < inserts.length)) {
|
170
|
+
_context6.n = 3;
|
171
|
+
break;
|
172
|
+
}
|
173
|
+
keyS = this._key2str(inserts[i][0]);
|
174
|
+
this._normalize(inserts[i][1]);
|
175
|
+
this.nodes[keyS] = inserts[i][1];
|
176
|
+
if (!this.kv) {
|
177
|
+
_context6.n = 2;
|
178
|
+
break;
|
179
|
+
}
|
180
|
+
_context6.n = 2;
|
181
|
+
return this.kv.put("node_".concat(keyS), this.nodes[keyS]);
|
182
|
+
case 2:
|
183
|
+
i++;
|
184
|
+
_context6.n = 1;
|
185
|
+
break;
|
186
|
+
case 3:
|
187
|
+
return _context6.a(2);
|
141
188
|
}
|
142
|
-
},
|
189
|
+
}, _callee6, this);
|
143
190
|
}));
|
144
191
|
function multiIns(_x4) {
|
145
192
|
return _multiIns.apply(this, arguments);
|
@@ -149,20 +196,33 @@ var SMTMemDb = exports["default"] = /*#__PURE__*/function () {
|
|
149
196
|
}, {
|
150
197
|
key: "multiDel",
|
151
198
|
value: function () {
|
152
|
-
var _multiDel = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
199
|
+
var _multiDel = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(dels) {
|
153
200
|
var i, keyS;
|
154
|
-
return _regenerator().w(function (
|
155
|
-
while (1) switch (
|
201
|
+
return _regenerator().w(function (_context7) {
|
202
|
+
while (1) switch (_context7.n) {
|
156
203
|
case 0:
|
157
|
-
|
158
|
-
keyS = this._key2str(dels[i]);
|
159
|
-
delete this.nodes[keyS];
|
160
|
-
if (this.kv) this.kv.del("node_".concat(keyS));
|
161
|
-
}
|
204
|
+
i = 0;
|
162
205
|
case 1:
|
163
|
-
|
206
|
+
if (!(i < dels.length)) {
|
207
|
+
_context7.n = 3;
|
208
|
+
break;
|
209
|
+
}
|
210
|
+
keyS = this._key2str(dels[i]);
|
211
|
+
delete this.nodes[keyS];
|
212
|
+
if (!this.kv) {
|
213
|
+
_context7.n = 2;
|
214
|
+
break;
|
215
|
+
}
|
216
|
+
_context7.n = 2;
|
217
|
+
return this.kv.del("node_".concat(keyS));
|
218
|
+
case 2:
|
219
|
+
i++;
|
220
|
+
_context7.n = 1;
|
221
|
+
break;
|
222
|
+
case 3:
|
223
|
+
return _context7.a(2);
|
164
224
|
}
|
165
|
-
},
|
225
|
+
}, _callee7, this);
|
166
226
|
}));
|
167
227
|
function multiDel(_x5) {
|
168
228
|
return _multiDel.apply(this, arguments);
|
package/cjs/collection_tree.js
CHANGED
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
exports["default"] = void 0;
|
7
7
|
var _newMemEmptyTrie = _interopRequireDefault(require("./newMemEmptyTrie.js"));
|
8
8
|
var _encoder = require("./encoder.js");
|
9
|
+
var _doc_tree = _interopRequireDefault(require("./doc_tree.js"));
|
9
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
10
11
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
11
12
|
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
@@ -19,21 +20,23 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
19
20
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
20
21
|
var CollectionTree = exports["default"] = /*#__PURE__*/function () {
|
21
22
|
function CollectionTree(_ref) {
|
22
|
-
var _ref$
|
23
|
+
var _ref$size_json = _ref.size_json,
|
24
|
+
size_json = _ref$size_json === void 0 ? 256 : _ref$size_json,
|
25
|
+
_ref$size_val = _ref.size_val,
|
23
26
|
size_val = _ref$size_val === void 0 ? 256 : _ref$size_val,
|
24
27
|
_ref$size_path = _ref.size_path,
|
25
28
|
size_path = _ref$size_path === void 0 ? 32 : _ref$size_path,
|
26
|
-
_ref$size_json = _ref.size_json,
|
27
|
-
size_json = _ref$size_json === void 0 ? 256 : _ref$size_json,
|
28
29
|
_ref$level = _ref.level,
|
29
30
|
level = _ref$level === void 0 ? 184 : _ref$level,
|
30
31
|
kv = _ref.kv;
|
31
32
|
_classCallCheck(this, CollectionTree);
|
32
33
|
this.kv = kv;
|
33
|
-
this.size_val = size_val;
|
34
|
-
this.size_path = size_path;
|
35
|
-
this.size_json = size_json;
|
36
34
|
this.level = level;
|
35
|
+
this.doc = new _doc_tree["default"]({
|
36
|
+
size_val: this.size_val = size_val,
|
37
|
+
size_path: this.size_path = size_path,
|
38
|
+
size_json: this.size_json = size_json
|
39
|
+
});
|
37
40
|
}
|
38
41
|
return _createClass(CollectionTree, [{
|
39
42
|
key: "init",
|
@@ -60,15 +63,11 @@ var CollectionTree = exports["default"] = /*#__PURE__*/function () {
|
|
60
63
|
key: "insert",
|
61
64
|
value: function () {
|
62
65
|
var _insert = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_key, _val) {
|
63
|
-
var doc, id, val;
|
64
66
|
return _regenerator().w(function (_context2) {
|
65
67
|
while (1) switch (_context2.n) {
|
66
68
|
case 0:
|
67
|
-
doc = (0, _encoder.encode)(_val);
|
68
|
-
id = (0, _encoder.toIndex)(_key);
|
69
|
-
val = (0, _encoder.pad)((0, _encoder.toSignal)(doc), this.size_json);
|
70
69
|
_context2.n = 1;
|
71
|
-
return this.tree.insert(
|
70
|
+
return this.tree.insert((0, _encoder.toIndex)(_key), (0, _encoder.pad)((0, _encoder.toSignal)((0, _encoder.encode)(_val)), this.size_json));
|
72
71
|
case 1:
|
73
72
|
return _context2.a(2, _context2.v);
|
74
73
|
}
|
@@ -83,15 +82,11 @@ var CollectionTree = exports["default"] = /*#__PURE__*/function () {
|
|
83
82
|
key: "update",
|
84
83
|
value: function () {
|
85
84
|
var _update = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(_key, _val) {
|
86
|
-
var doc, id, val;
|
87
85
|
return _regenerator().w(function (_context3) {
|
88
86
|
while (1) switch (_context3.n) {
|
89
87
|
case 0:
|
90
|
-
doc = (0, _encoder.encode)(_val);
|
91
|
-
id = (0, _encoder.toIndex)(_key);
|
92
|
-
val = (0, _encoder.pad)((0, _encoder.toSignal)(doc), this.size_json);
|
93
88
|
_context3.n = 1;
|
94
|
-
return this.tree.update(
|
89
|
+
return this.tree.update((0, _encoder.toIndex)(_key), (0, _encoder.pad)((0, _encoder.toSignal)((0, _encoder.encode)(_val)), this.size_json));
|
95
90
|
case 1:
|
96
91
|
return _context3.a(2, _context3.v);
|
97
92
|
}
|
@@ -106,13 +101,11 @@ var CollectionTree = exports["default"] = /*#__PURE__*/function () {
|
|
106
101
|
key: "delete",
|
107
102
|
value: function () {
|
108
103
|
var _delete2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(_key) {
|
109
|
-
var id;
|
110
104
|
return _regenerator().w(function (_context4) {
|
111
105
|
while (1) switch (_context4.n) {
|
112
106
|
case 0:
|
113
|
-
id = (0, _encoder.toIndex)(_key);
|
114
107
|
_context4.n = 1;
|
115
|
-
return this.tree["delete"](
|
108
|
+
return this.tree["delete"]((0, _encoder.toIndex)(_key));
|
116
109
|
case 1:
|
117
110
|
return _context4.a(2, _context4.v);
|
118
111
|
}
|
@@ -127,13 +120,11 @@ var CollectionTree = exports["default"] = /*#__PURE__*/function () {
|
|
127
120
|
key: "get",
|
128
121
|
value: function () {
|
129
122
|
var _get = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(_key) {
|
130
|
-
var id;
|
131
123
|
return _regenerator().w(function (_context5) {
|
132
124
|
while (1) switch (_context5.n) {
|
133
125
|
case 0:
|
134
|
-
id = (0, _encoder.toIndex)(_key);
|
135
126
|
_context5.n = 1;
|
136
|
-
return this.tree.find(
|
127
|
+
return this.tree.find((0, _encoder.toIndex)(_key));
|
137
128
|
case 1:
|
138
129
|
return _context5.a(2, _context5.v);
|
139
130
|
}
|
@@ -144,5 +135,49 @@ var CollectionTree = exports["default"] = /*#__PURE__*/function () {
|
|
144
135
|
}
|
145
136
|
return get;
|
146
137
|
}()
|
138
|
+
}, {
|
139
|
+
key: "getInputs",
|
140
|
+
value: function () {
|
141
|
+
var _getInputs = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(_ref2) {
|
142
|
+
var id, json, path, val, query, doc_inputs, res, siblings, i;
|
143
|
+
return _regenerator().w(function (_context6) {
|
144
|
+
while (1) switch (_context6.n) {
|
145
|
+
case 0:
|
146
|
+
id = _ref2.id, json = _ref2.json, path = _ref2.path, val = _ref2.val, query = _ref2.query;
|
147
|
+
_context6.n = 1;
|
148
|
+
return this.doc.getInputs({
|
149
|
+
json: json,
|
150
|
+
path: path,
|
151
|
+
val: val,
|
152
|
+
query: query
|
153
|
+
});
|
154
|
+
case 1:
|
155
|
+
doc_inputs = _context6.v;
|
156
|
+
_context6.n = 2;
|
157
|
+
return this.get(id);
|
158
|
+
case 2:
|
159
|
+
res = _context6.v;
|
160
|
+
siblings = res.siblings;
|
161
|
+
for (i = 0; i < siblings.length; i++) siblings[i] = this.tree.F.toObject(siblings[i]);
|
162
|
+
while (siblings.length < this.level) siblings.push(0);
|
163
|
+
siblings = siblings.map(function (s) {
|
164
|
+
return s.toString();
|
165
|
+
});
|
166
|
+
return _context6.a(2, {
|
167
|
+
json: doc_inputs.json,
|
168
|
+
path: doc_inputs.path,
|
169
|
+
val: doc_inputs.val,
|
170
|
+
root: this.tree.F.toObject(this.tree.root).toString(),
|
171
|
+
siblings: siblings,
|
172
|
+
key: (0, _encoder.toIndex)(id)
|
173
|
+
});
|
174
|
+
}
|
175
|
+
}, _callee6, this);
|
176
|
+
}));
|
177
|
+
function getInputs(_x7) {
|
178
|
+
return _getInputs.apply(this, arguments);
|
179
|
+
}
|
180
|
+
return getInputs;
|
181
|
+
}()
|
147
182
|
}]);
|
148
183
|
}();
|
package/cjs/db_tree.js
CHANGED
@@ -7,6 +7,7 @@ exports["default"] = void 0;
|
|
7
7
|
var _newMemEmptyTrie = _interopRequireDefault(require("./newMemEmptyTrie.js"));
|
8
8
|
var _ramda = require("ramda");
|
9
9
|
var _collection_tree = _interopRequireDefault(require("./collection_tree.js"));
|
10
|
+
var _encoder = require("./encoder.js");
|
10
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
11
12
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
12
13
|
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
@@ -25,32 +26,26 @@ var to64 = function to64(hash) {
|
|
25
26
|
var buf = Buffer.from(hex, "hex");
|
26
27
|
return buf.toString("base64");
|
27
28
|
};
|
28
|
-
var from64 = function from64(b64) {
|
29
|
-
var buf = Buffer.from(b64, "base64");
|
30
|
-
var hex = buf.toString("hex");
|
31
|
-
var n = BigInt("0x" + hex);
|
32
|
-
return n.toString();
|
33
|
-
};
|
34
29
|
var DBTree = exports["default"] = /*#__PURE__*/function () {
|
35
30
|
function DBTree(_ref) {
|
36
|
-
var _ref$
|
31
|
+
var _ref$size_json = _ref.size_json,
|
32
|
+
size_json = _ref$size_json === void 0 ? 256 : _ref$size_json,
|
33
|
+
_ref$level_col = _ref.level_col,
|
34
|
+
level_col = _ref$level_col === void 0 ? 24 : _ref$level_col,
|
35
|
+
_ref$size_val = _ref.size_val,
|
37
36
|
size_val = _ref$size_val === void 0 ? 256 : _ref$size_val,
|
38
37
|
_ref$size_path = _ref.size_path,
|
39
38
|
size_path = _ref$size_path === void 0 ? 32 : _ref$size_path,
|
40
39
|
_ref$level = _ref.level,
|
41
40
|
level = _ref$level === void 0 ? 184 : _ref$level,
|
42
|
-
_ref$size_json = _ref.size_json,
|
43
|
-
size_json = _ref$size_json === void 0 ? 256 : _ref$size_json,
|
44
|
-
_ref$level_col = _ref.level_col,
|
45
|
-
level_col = _ref$level_col === void 0 ? 24 : _ref$level_col,
|
46
41
|
kv = _ref.kv;
|
47
42
|
_classCallCheck(this, DBTree);
|
48
43
|
this.kv = kv;
|
44
|
+
this.level = level;
|
49
45
|
this.level_col = level_col;
|
46
|
+
this.size_json = size_json;
|
50
47
|
this.size_val = size_val;
|
51
48
|
this.size_path = size_path;
|
52
|
-
this.level = level;
|
53
|
-
this.size_json = size_json;
|
54
49
|
this.count = 0;
|
55
50
|
this.ids = {};
|
56
51
|
this.cols = [];
|
@@ -215,10 +210,18 @@ var DBTree = exports["default"] = /*#__PURE__*/function () {
|
|
215
210
|
_context4.n = 9;
|
216
211
|
return this.tree.insert(id, [root]);
|
217
212
|
case 9:
|
218
|
-
if (id === this.count) {
|
219
|
-
|
220
|
-
|
213
|
+
if (!(id === this.count)) {
|
214
|
+
_context4.n = 10;
|
215
|
+
break;
|
216
|
+
}
|
217
|
+
this.count++;
|
218
|
+
if (!this.kvi) {
|
219
|
+
_context4.n = 10;
|
220
|
+
break;
|
221
221
|
}
|
222
|
+
_context4.n = 10;
|
223
|
+
return this.kvi.put("count", this.count);
|
224
|
+
case 10:
|
222
225
|
return _context4.a(2, id);
|
223
226
|
}
|
224
227
|
}, _callee4, this);
|
@@ -267,10 +270,10 @@ var DBTree = exports["default"] = /*#__PURE__*/function () {
|
|
267
270
|
while (1) switch (_context6.n) {
|
268
271
|
case 0:
|
269
272
|
col = new _collection_tree["default"]({
|
273
|
+
size_json: this.size_json,
|
270
274
|
size_val: this.size_val,
|
271
275
|
size_path: this.size_path,
|
272
276
|
level: this.level,
|
273
|
-
size_json: this.size_json,
|
274
277
|
kv: (_this$kv2 = this.kv) === null || _this$kv2 === void 0 ? void 0 : _this$kv2.call(this, "dir_".concat(id))
|
275
278
|
});
|
276
279
|
_context6.n = 1;
|
@@ -499,5 +502,59 @@ var DBTree = exports["default"] = /*#__PURE__*/function () {
|
|
499
502
|
}
|
500
503
|
return getCol;
|
501
504
|
}()
|
505
|
+
}, {
|
506
|
+
key: "getInputs",
|
507
|
+
value: function () {
|
508
|
+
var _getInputs = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12(_ref2) {
|
509
|
+
var id, col_id, json, path, val, query, col_root, col_res, col_siblings, i, col_key, col, col_inputs;
|
510
|
+
return _regenerator().w(function (_context12) {
|
511
|
+
while (1) switch (_context12.n) {
|
512
|
+
case 0:
|
513
|
+
id = _ref2.id, col_id = _ref2.col_id, json = _ref2.json, path = _ref2.path, val = _ref2.val, query = _ref2.query;
|
514
|
+
col_root = this.tree.F.toObject(this.tree.root).toString();
|
515
|
+
_context12.n = 1;
|
516
|
+
return this.getCol(col_id);
|
517
|
+
case 1:
|
518
|
+
col_res = _context12.v;
|
519
|
+
col_siblings = col_res.siblings;
|
520
|
+
for (i = 0; i < col_siblings.length; i++) col_siblings[i] = this.tree.F.toObject(col_siblings[i]);
|
521
|
+
while (col_siblings.length < this.level_col) col_siblings.push(0);
|
522
|
+
col_siblings = col_siblings.map(function (s) {
|
523
|
+
return s.toString();
|
524
|
+
});
|
525
|
+
col_key = col_id;
|
526
|
+
_context12.n = 2;
|
527
|
+
return this.getColTree(col_id);
|
528
|
+
case 2:
|
529
|
+
col = _context12.v;
|
530
|
+
_context12.n = 3;
|
531
|
+
return col.getInputs({
|
532
|
+
id: id,
|
533
|
+
json: json,
|
534
|
+
path: path,
|
535
|
+
val: val,
|
536
|
+
query: query
|
537
|
+
});
|
538
|
+
case 3:
|
539
|
+
col_inputs = _context12.v;
|
540
|
+
return _context12.a(2, {
|
541
|
+
path: col_inputs.path,
|
542
|
+
val: col_inputs.val,
|
543
|
+
json: col_inputs.json,
|
544
|
+
root: col_inputs.root,
|
545
|
+
siblings: col_inputs.siblings,
|
546
|
+
key: (0, _encoder.toIndex)(id),
|
547
|
+
col_key: col_key,
|
548
|
+
col_siblings: col_siblings,
|
549
|
+
col_root: col_root
|
550
|
+
});
|
551
|
+
}
|
552
|
+
}, _callee12, this);
|
553
|
+
}));
|
554
|
+
function getInputs(_x18) {
|
555
|
+
return _getInputs.apply(this, arguments);
|
556
|
+
}
|
557
|
+
return getInputs;
|
558
|
+
}()
|
502
559
|
}]);
|
503
560
|
}();
|
package/cjs/doc_tree.js
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports["default"] = void 0;
|
7
|
+
var _ramda = require("ramda");
|
8
|
+
var _encoder = require("./encoder.js");
|
9
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
10
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
11
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
12
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
13
|
+
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
14
|
+
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { if (r) i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n;else { var o = function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); }; o("next", 0), o("throw", 1), o("return", 2); } }, _regeneratorDefine2(e, r, n, t); }
|
15
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
16
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
17
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
18
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
19
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
20
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
21
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
22
|
+
var DocTree = exports["default"] = /*#__PURE__*/function () {
|
23
|
+
function DocTree(_ref) {
|
24
|
+
var _ref$size_val = _ref.size_val,
|
25
|
+
size_val = _ref$size_val === void 0 ? 256 : _ref$size_val,
|
26
|
+
_ref$size_path = _ref.size_path,
|
27
|
+
size_path = _ref$size_path === void 0 ? 32 : _ref$size_path,
|
28
|
+
_ref$size_json = _ref.size_json,
|
29
|
+
size_json = _ref$size_json === void 0 ? 256 : _ref$size_json;
|
30
|
+
_classCallCheck(this, DocTree);
|
31
|
+
this.size_val = size_val;
|
32
|
+
this.size_path = size_path;
|
33
|
+
this.size_json = size_json;
|
34
|
+
}
|
35
|
+
return _createClass(DocTree, [{
|
36
|
+
key: "getInputs",
|
37
|
+
value: function () {
|
38
|
+
var _getInputs = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref2) {
|
39
|
+
var query, json, path;
|
40
|
+
return _regenerator().w(function (_context) {
|
41
|
+
while (1) switch (_context.n) {
|
42
|
+
case 0:
|
43
|
+
query = _ref2.query, json = _ref2.json, path = _ref2.path;
|
44
|
+
return _context.a(2, {
|
45
|
+
json: (0, _encoder.pad)((0, _encoder.toSignal)((0, _encoder.encode)(json)), this.size_json),
|
46
|
+
path: (0, _encoder.pad)((0, _encoder.toSignal)((0, _encoder.encodePath)(path)), this.size_path),
|
47
|
+
val: (0, _ramda.isNil)(query) ? (0, _encoder.pad)((0, _encoder.toSignal)((0, _encoder.encodeVal)(this.getVal(json, path))), this.size_val) : (0, _encoder.pad)((0, _encoder.toSignal)((0, _encoder.encodeQuery)(query)), this.size_val)
|
48
|
+
});
|
49
|
+
}
|
50
|
+
}, _callee, this);
|
51
|
+
}));
|
52
|
+
function getInputs(_x) {
|
53
|
+
return _getInputs.apply(this, arguments);
|
54
|
+
}
|
55
|
+
return getInputs;
|
56
|
+
}()
|
57
|
+
}, {
|
58
|
+
key: "_getVal",
|
59
|
+
value: function _getVal(j, p) {
|
60
|
+
if (p.length === 0) return j;else {
|
61
|
+
var sp = p[0].split("[");
|
62
|
+
var _iterator = _createForOfIteratorHelper(sp),
|
63
|
+
_step;
|
64
|
+
try {
|
65
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
66
|
+
var v = _step.value;
|
67
|
+
if (/]$/.test(v)) j = j[v.replace(/]$/, "") * 1];else j = j[v];
|
68
|
+
}
|
69
|
+
} catch (err) {
|
70
|
+
_iterator.e(err);
|
71
|
+
} finally {
|
72
|
+
_iterator.f();
|
73
|
+
}
|
74
|
+
return this._getVal(j, p.slice(1));
|
75
|
+
}
|
76
|
+
}
|
77
|
+
}, {
|
78
|
+
key: "getVal",
|
79
|
+
value: function getVal(j, p) {
|
80
|
+
if (p === "") return j;
|
81
|
+
return this._getVal(j, p.split("."));
|
82
|
+
}
|
83
|
+
}]);
|
84
|
+
}();
|
package/cjs/index.js
CHANGED
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
var _exportNames = {
|
7
7
|
DBTree: true,
|
8
|
+
Prover: true,
|
8
9
|
CollectionTree: true,
|
9
10
|
DB: true,
|
10
11
|
Doc: true,
|
@@ -47,7 +48,14 @@ Object.defineProperty(exports, "NFT", {
|
|
47
48
|
return _nft["default"];
|
48
49
|
}
|
49
50
|
});
|
51
|
+
Object.defineProperty(exports, "Prover", {
|
52
|
+
enumerable: true,
|
53
|
+
get: function get() {
|
54
|
+
return _prover["default"];
|
55
|
+
}
|
56
|
+
});
|
50
57
|
var _db_tree = _interopRequireDefault(require("./db_tree.js"));
|
58
|
+
var _prover = _interopRequireDefault(require("./prover.js"));
|
51
59
|
var _collection_tree = _interopRequireDefault(require("./collection_tree.js"));
|
52
60
|
var _db = _interopRequireDefault(require("./db.js"));
|
53
61
|
var _doc = _interopRequireDefault(require("./doc.js"));
|
package/cjs/newMemEmptyTrie.js
CHANGED
@@ -30,8 +30,11 @@ function _newMemEmptyTrie() {
|
|
30
30
|
F = _yield$getHashes.F;
|
31
31
|
db = new _SMTMemDb["default"](F, kv);
|
32
32
|
_context.n = 2;
|
33
|
-
return db.
|
33
|
+
return db.init();
|
34
34
|
case 2:
|
35
|
+
_context.n = 3;
|
36
|
+
return db.getRoot();
|
37
|
+
case 3:
|
35
38
|
rt = _context.v;
|
36
39
|
smt = new _SMT["default"](db, rt, hash0, hash1, F);
|
37
40
|
return _context.a(2, smt);
|
package/cjs/prover.js
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports["default"] = void 0;
|
7
|
+
var _snarkjs = require("snarkjs");
|
8
|
+
var _encoder = require("./encoder.js");
|
9
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
10
|
+
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
11
|
+
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { if (r) i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n;else { var o = function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); }; o("next", 0), o("throw", 1), o("return", 2); } }, _regeneratorDefine2(e, r, n, t); }
|
12
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
13
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
14
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
15
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
16
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
17
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
18
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
19
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
20
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
21
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
22
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
23
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
24
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
25
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
26
|
+
var Prover = exports["default"] = /*#__PURE__*/function () {
|
27
|
+
function Prover(_ref) {
|
28
|
+
var wasm = _ref.wasm,
|
29
|
+
zkey = _ref.zkey;
|
30
|
+
_classCallCheck(this, Prover);
|
31
|
+
this.wasm = wasm;
|
32
|
+
this.zkey = zkey;
|
33
|
+
}
|
34
|
+
return _createClass(Prover, [{
|
35
|
+
key: "_getVal",
|
36
|
+
value: function _getVal(j, p) {
|
37
|
+
if (p.length === 0) return j;else {
|
38
|
+
var sp = p[0].split("[");
|
39
|
+
var _iterator = _createForOfIteratorHelper(sp),
|
40
|
+
_step;
|
41
|
+
try {
|
42
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
43
|
+
var v = _step.value;
|
44
|
+
if (/]$/.test(v)) j = j[v.replace(/]$/, "") * 1];else j = j[v];
|
45
|
+
}
|
46
|
+
} catch (err) {
|
47
|
+
_iterator.e(err);
|
48
|
+
} finally {
|
49
|
+
_iterator.f();
|
50
|
+
}
|
51
|
+
return this._getVal(j, p.slice(1));
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}, {
|
55
|
+
key: "getVal",
|
56
|
+
value: function getVal(j, p) {
|
57
|
+
if (p === "") return j;
|
58
|
+
return this._getVal(j, p.split("."));
|
59
|
+
}
|
60
|
+
}, {
|
61
|
+
key: "genProof",
|
62
|
+
value: function () {
|
63
|
+
var _genProof = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(inputs) {
|
64
|
+
var _yield$groth16$fullPr, proof, publicSignals;
|
65
|
+
return _regenerator().w(function (_context) {
|
66
|
+
while (1) switch (_context.n) {
|
67
|
+
case 0:
|
68
|
+
_context.n = 1;
|
69
|
+
return _snarkjs.groth16.fullProve(inputs, this.wasm, this.zkey);
|
70
|
+
case 1:
|
71
|
+
_yield$groth16$fullPr = _context.v;
|
72
|
+
proof = _yield$groth16$fullPr.proof;
|
73
|
+
publicSignals = _yield$groth16$fullPr.publicSignals;
|
74
|
+
return _context.a(2, [].concat(_toConsumableArray(proof.pi_a.slice(0, 2)), _toConsumableArray(proof.pi_b[0].slice(0, 2).reverse()), _toConsumableArray(proof.pi_b[1].slice(0, 2).reverse()), _toConsumableArray(proof.pi_c.slice(0, 2)), _toConsumableArray(publicSignals)));
|
75
|
+
}
|
76
|
+
}, _callee, this);
|
77
|
+
}));
|
78
|
+
function genProof(_x) {
|
79
|
+
return _genProof.apply(this, arguments);
|
80
|
+
}
|
81
|
+
return genProof;
|
82
|
+
}()
|
83
|
+
}]);
|
84
|
+
}();
|
@@ -3,14 +3,15 @@ export default class SMTMemDb {
|
|
3
3
|
this.kv = kv
|
4
4
|
this.nodes = {}
|
5
5
|
this.root = F.zero
|
6
|
+
this.F = F
|
7
|
+
}
|
8
|
+
async init() {
|
6
9
|
if (this.kv) {
|
7
10
|
const root = this.kv.get("root")
|
8
11
|
if (root) this.root = root
|
9
|
-
else this.kv.put("root", this.root)
|
12
|
+
else await this.kv.put("root", this.root)
|
10
13
|
}
|
11
|
-
this.F = F
|
12
14
|
}
|
13
|
-
|
14
15
|
async getRoot() {
|
15
16
|
return this.root
|
16
17
|
}
|
@@ -47,7 +48,7 @@ export default class SMTMemDb {
|
|
47
48
|
|
48
49
|
async setRoot(rt) {
|
49
50
|
this.root = rt
|
50
|
-
if (this.kv) this.kv.put("root", this.root)
|
51
|
+
if (this.kv) await this.kv.put("root", this.root)
|
51
52
|
}
|
52
53
|
|
53
54
|
async multiIns(inserts) {
|
@@ -55,7 +56,7 @@ export default class SMTMemDb {
|
|
55
56
|
const keyS = this._key2str(inserts[i][0])
|
56
57
|
this._normalize(inserts[i][1])
|
57
58
|
this.nodes[keyS] = inserts[i][1]
|
58
|
-
if (this.kv) this.kv.put(`node_${keyS}`, this.nodes[keyS])
|
59
|
+
if (this.kv) await this.kv.put(`node_${keyS}`, this.nodes[keyS])
|
59
60
|
}
|
60
61
|
}
|
61
62
|
|
@@ -63,7 +64,7 @@ export default class SMTMemDb {
|
|
63
64
|
for (let i = 0; i < dels.length; i++) {
|
64
65
|
const keyS = this._key2str(dels[i])
|
65
66
|
delete this.nodes[keyS]
|
66
|
-
if (this.kv) this.kv.del(`node_${keyS}`)
|
67
|
+
if (this.kv) await this.kv.del(`node_${keyS}`)
|
67
68
|
}
|
68
69
|
}
|
69
70
|
}
|
package/esm/collection_tree.js
CHANGED
@@ -1,43 +1,65 @@
|
|
1
1
|
import newMemEmptyTrie from "./newMemEmptyTrie.js"
|
2
2
|
import { pad, toSignal, encode, toIndex } from "./encoder.js"
|
3
|
+
import Doc from "./doc_tree.js"
|
3
4
|
|
4
5
|
export default class CollectionTree {
|
5
6
|
constructor({
|
7
|
+
size_json = 256,
|
6
8
|
size_val = 256,
|
7
9
|
size_path = 32,
|
8
|
-
size_json = 256,
|
9
10
|
level = 184,
|
10
11
|
kv,
|
11
12
|
}) {
|
12
13
|
this.kv = kv
|
13
|
-
this.size_val = size_val
|
14
|
-
this.size_path = size_path
|
15
|
-
this.size_json = size_json
|
16
14
|
this.level = level
|
15
|
+
this.doc = new Doc({
|
16
|
+
size_val: (this.size_val = size_val),
|
17
|
+
size_path: (this.size_path = size_path),
|
18
|
+
size_json: (this.size_json = size_json),
|
19
|
+
})
|
17
20
|
}
|
21
|
+
|
18
22
|
async init() {
|
19
23
|
this.tree = await newMemEmptyTrie(this.kv)
|
20
24
|
}
|
25
|
+
|
21
26
|
async insert(_key, _val) {
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
27
|
+
return await this.tree.insert(
|
28
|
+
toIndex(_key),
|
29
|
+
pad(toSignal(encode(_val)), this.size_json),
|
30
|
+
)
|
26
31
|
}
|
32
|
+
|
27
33
|
async update(_key, _val) {
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
34
|
+
return await this.tree.update(
|
35
|
+
toIndex(_key),
|
36
|
+
pad(toSignal(encode(_val)), this.size_json),
|
37
|
+
)
|
32
38
|
}
|
33
39
|
|
34
40
|
async delete(_key) {
|
35
|
-
|
36
|
-
return await this.tree.delete(id)
|
41
|
+
return await this.tree.delete(toIndex(_key))
|
37
42
|
}
|
38
43
|
|
39
44
|
async get(_key) {
|
40
|
-
|
41
|
-
|
45
|
+
return await this.tree.find(toIndex(_key))
|
46
|
+
}
|
47
|
+
|
48
|
+
async getInputs({ id, json, path, val, query }) {
|
49
|
+
const doc_inputs = await this.doc.getInputs({ json, path, val, query })
|
50
|
+
const res = await this.get(id)
|
51
|
+
let siblings = res.siblings
|
52
|
+
for (let i = 0; i < siblings.length; i++)
|
53
|
+
siblings[i] = this.tree.F.toObject(siblings[i])
|
54
|
+
while (siblings.length < this.level) siblings.push(0)
|
55
|
+
siblings = siblings.map(s => s.toString())
|
56
|
+
return {
|
57
|
+
json: doc_inputs.json,
|
58
|
+
path: doc_inputs.path,
|
59
|
+
val: doc_inputs.val,
|
60
|
+
root: this.tree.F.toObject(this.tree.root).toString(),
|
61
|
+
siblings,
|
62
|
+
key: toIndex(id),
|
63
|
+
}
|
42
64
|
}
|
43
65
|
}
|
package/esm/db_tree.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import newMemEmptyTrie from "./newMemEmptyTrie.js"
|
2
2
|
import { is, indexOf, isNil } from "ramda"
|
3
3
|
import Collection from "./collection_tree.js"
|
4
|
+
import { toIndex } from "./encoder.js"
|
4
5
|
|
5
6
|
const to64 = hash => {
|
6
7
|
const n = BigInt(hash)
|
@@ -9,28 +10,22 @@ const to64 = hash => {
|
|
9
10
|
const buf = Buffer.from(hex, "hex")
|
10
11
|
return buf.toString("base64")
|
11
12
|
}
|
12
|
-
const from64 = b64 => {
|
13
|
-
const buf = Buffer.from(b64, "base64")
|
14
|
-
const hex = buf.toString("hex")
|
15
|
-
const n = BigInt("0x" + hex)
|
16
|
-
return n.toString()
|
17
|
-
}
|
18
13
|
|
19
14
|
export default class DBTree {
|
20
15
|
constructor({
|
16
|
+
size_json = 256,
|
17
|
+
level_col = 24,
|
21
18
|
size_val = 256,
|
22
19
|
size_path = 32,
|
23
20
|
level = 184,
|
24
|
-
size_json = 256,
|
25
|
-
level_col = 24,
|
26
21
|
kv,
|
27
22
|
}) {
|
28
23
|
this.kv = kv
|
24
|
+
this.level = level
|
29
25
|
this.level_col = level_col
|
26
|
+
this.size_json = size_json
|
30
27
|
this.size_val = size_val
|
31
28
|
this.size_path = size_path
|
32
|
-
this.level = level
|
33
|
-
this.size_json = size_json
|
34
29
|
this.count = 0
|
35
30
|
this.ids = {}
|
36
31
|
this.cols = []
|
@@ -81,7 +76,7 @@ export default class DBTree {
|
|
81
76
|
await this.tree.insert(id, [root])
|
82
77
|
if (id === this.count) {
|
83
78
|
this.count++
|
84
|
-
if (this.kvi) this.kvi.put("count", this.count)
|
79
|
+
if (this.kvi) await this.kvi.put("count", this.count)
|
85
80
|
}
|
86
81
|
return id
|
87
82
|
}
|
@@ -93,10 +88,10 @@ export default class DBTree {
|
|
93
88
|
}
|
94
89
|
async loadCol(id) {
|
95
90
|
const col = new Collection({
|
91
|
+
size_json: this.size_json,
|
96
92
|
size_val: this.size_val,
|
97
93
|
size_path: this.size_path,
|
98
94
|
level: this.level,
|
99
|
-
size_json: this.size_json,
|
100
95
|
kv: this.kv?.(`dir_${id}`),
|
101
96
|
})
|
102
97
|
await col.init()
|
@@ -148,4 +143,27 @@ export default class DBTree {
|
|
148
143
|
async getCol(col) {
|
149
144
|
return await this.tree.find(col)
|
150
145
|
}
|
146
|
+
async getInputs({ id, col_id, json, path, val, query }) {
|
147
|
+
const col_root = this.tree.F.toObject(this.tree.root).toString()
|
148
|
+
const col_res = await this.getCol(col_id)
|
149
|
+
let col_siblings = col_res.siblings
|
150
|
+
for (let i = 0; i < col_siblings.length; i++)
|
151
|
+
col_siblings[i] = this.tree.F.toObject(col_siblings[i])
|
152
|
+
while (col_siblings.length < this.level_col) col_siblings.push(0)
|
153
|
+
col_siblings = col_siblings.map(s => s.toString())
|
154
|
+
const col_key = col_id
|
155
|
+
const col = await this.getColTree(col_id)
|
156
|
+
const col_inputs = await col.getInputs({ id, json, path, val, query })
|
157
|
+
return {
|
158
|
+
path: col_inputs.path,
|
159
|
+
val: col_inputs.val,
|
160
|
+
json: col_inputs.json,
|
161
|
+
root: col_inputs.root,
|
162
|
+
siblings: col_inputs.siblings,
|
163
|
+
key: toIndex(id),
|
164
|
+
col_key,
|
165
|
+
col_siblings,
|
166
|
+
col_root,
|
167
|
+
}
|
168
|
+
}
|
151
169
|
}
|
package/esm/doc_tree.js
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
import { isNil } from "ramda"
|
2
|
+
import {
|
3
|
+
encodeQuery,
|
4
|
+
pad,
|
5
|
+
toSignal,
|
6
|
+
encode,
|
7
|
+
encodePath,
|
8
|
+
encodeVal,
|
9
|
+
} from "./encoder.js"
|
10
|
+
|
11
|
+
export default class DocTree {
|
12
|
+
constructor({ size_val = 256, size_path = 32, size_json = 256 }) {
|
13
|
+
this.size_val = size_val
|
14
|
+
this.size_path = size_path
|
15
|
+
this.size_json = size_json
|
16
|
+
}
|
17
|
+
async getInputs({ query, json, path }) {
|
18
|
+
return {
|
19
|
+
json: pad(toSignal(encode(json)), this.size_json),
|
20
|
+
path: pad(toSignal(encodePath(path)), this.size_path),
|
21
|
+
val: isNil(query)
|
22
|
+
? pad(toSignal(encodeVal(this.getVal(json, path))), this.size_val)
|
23
|
+
: pad(toSignal(encodeQuery(query)), this.size_val),
|
24
|
+
}
|
25
|
+
}
|
26
|
+
_getVal(j, p) {
|
27
|
+
if (p.length === 0) return j
|
28
|
+
else {
|
29
|
+
const sp = p[0].split("[")
|
30
|
+
for (let v of sp) {
|
31
|
+
if (/]$/.test(v)) j = j[v.replace(/]$/, "") * 1]
|
32
|
+
else j = j[v]
|
33
|
+
}
|
34
|
+
return this._getVal(j, p.slice(1))
|
35
|
+
}
|
36
|
+
}
|
37
|
+
getVal(j, p) {
|
38
|
+
if (p === "") return j
|
39
|
+
return this._getVal(j, p.split("."))
|
40
|
+
}
|
41
|
+
}
|
package/esm/index.js
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
import DBTree from "./db_tree.js"
|
2
|
+
import Prover from "./prover.js"
|
2
3
|
import CollectionTree from "./collection_tree.js"
|
3
4
|
import DB from "./db.js"
|
4
5
|
import Doc from "./doc.js"
|
5
6
|
import Collection from "./collection.js"
|
6
7
|
import NFT from "./nft.js"
|
7
|
-
export { DB, Collection, Doc, NFT, DBTree, CollectionTree }
|
8
|
+
export { DB, Collection, Doc, NFT, DBTree, CollectionTree, Prover }
|
8
9
|
export * from "./encoder.js"
|
9
10
|
export * from "./parse.js"
|
package/esm/newMemEmptyTrie.js
CHANGED
@@ -5,6 +5,7 @@ import getHashes from "./circomlibjs/getHashes.js"
|
|
5
5
|
export default async function newMemEmptyTrie(kv) {
|
6
6
|
const { hash0, hash1, F } = await getHashes()
|
7
7
|
const db = new SMTMemDb(F, kv)
|
8
|
+
await db.init()
|
8
9
|
const rt = await db.getRoot()
|
9
10
|
const smt = new SMT(db, rt, hash0, hash1, F)
|
10
11
|
return smt
|
package/esm/prover.js
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
import { groth16 } from "snarkjs"
|
2
|
+
import { toIndex } from "./encoder.js"
|
3
|
+
|
4
|
+
export default class Prover {
|
5
|
+
constructor({ wasm, zkey }) {
|
6
|
+
this.wasm = wasm
|
7
|
+
this.zkey = zkey
|
8
|
+
}
|
9
|
+
|
10
|
+
_getVal(j, p) {
|
11
|
+
if (p.length === 0) return j
|
12
|
+
else {
|
13
|
+
const sp = p[0].split("[")
|
14
|
+
for (let v of sp) {
|
15
|
+
if (/]$/.test(v)) j = j[v.replace(/]$/, "") * 1]
|
16
|
+
else j = j[v]
|
17
|
+
}
|
18
|
+
return this._getVal(j, p.slice(1))
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
getVal(j, p) {
|
23
|
+
if (p === "") return j
|
24
|
+
return this._getVal(j, p.split("."))
|
25
|
+
}
|
26
|
+
|
27
|
+
async genProof(inputs) {
|
28
|
+
const { proof, publicSignals } = await groth16.fullProve(
|
29
|
+
inputs,
|
30
|
+
this.wasm,
|
31
|
+
this.zkey,
|
32
|
+
)
|
33
|
+
return [
|
34
|
+
...proof.pi_a.slice(0, 2),
|
35
|
+
...proof.pi_b[0].slice(0, 2).reverse(),
|
36
|
+
...proof.pi_b[1].slice(0, 2).reverse(),
|
37
|
+
...proof.pi_c.slice(0, 2),
|
38
|
+
...publicSignals,
|
39
|
+
]
|
40
|
+
}
|
41
|
+
}
|