zkjson 0.6.3 → 0.7.0
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.js +149 -0
- package/cjs/collection.js +196 -0
- package/cjs/db.js +731 -0
- package/cjs/doc.js +132 -0
- package/cjs/encoder-v1_5.js +1731 -0
- package/cjs/encoder.js +668 -0
- package/cjs/index.js +64 -0
- package/cjs/json.js +54 -0
- package/cjs/nft.js +165 -0
- package/cjs/parse.js +256 -0
- package/cjs/uint.js +580 -0
- package/{circomlibjs.js → esm/circomlibjs.js} +27 -35
- package/{collection.js → esm/collection.js} +4 -6
- package/{contracts → esm/contracts}/ZKIPFS.sol +3 -3
- package/esm/contracts/verifiers/verifier_ipfs.sol +667 -0
- package/{db.js → esm/db.js} +8 -10
- package/{doc.js → esm/doc.js} +7 -7
- package/{encoder-v1_5.js → esm/encoder-v1_5.js} +3 -3
- package/{encoder.js → esm/encoder.js} +2 -2
- package/esm/index.js +7 -0
- package/{json.js → esm/json.js} +2 -2
- package/{nft.js → esm/nft.js} +8 -10
- package/esm/package.json +3 -0
- package/{parse.js → esm/parse.js} +4 -4
- package/{uint.js → esm/uint.js} +1 -1
- package/package.json +21 -5
- package/contracts/verifiers/verifier_ipfs.sol +0 -464
- package/index.js +0 -6
- /package/{contracts → esm/contracts}/NORollup.sol +0 -0
- /package/{contracts → esm/contracts}/OPRollup.sol +0 -0
- /package/{contracts → esm/contracts}/ZKJson.sol +0 -0
- /package/{contracts → esm/contracts}/ZKQuery.sol +0 -0
- /package/{contracts → esm/contracts}/ZKRollup.sol +0 -0
- /package/{contracts → esm/contracts}/apps/SimpleJSON.sol +0 -0
- /package/{contracts → esm/contracts}/apps/SimpleOPRU.sol +0 -0
- /package/{contracts → esm/contracts}/apps/SimpleRU.sol +0 -0
- /package/{contracts → esm/contracts}/apps/Token.sol +0 -0
- /package/{contracts → esm/contracts}/apps/ZKArweave.sol +0 -0
- /package/{contracts → esm/contracts}/apps/ZKBridge.sol +0 -0
- /package/{contracts → esm/contracts}/apps/ZKNFT.sol +0 -0
- /package/{contracts → esm/contracts}/verifiers/verifier_db.sol +0 -0
- /package/{contracts → esm/contracts}/verifiers/verifier_json.sol +0 -0
- /package/{contracts → esm/contracts}/verifiers/verifier_rollup.sol +0 -0
package/cjs/db.js
ADDED
@@ -0,0 +1,731 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports["default"] = void 0;
|
7
|
+
var _circomlibjs = require("./circomlibjs.js");
|
8
|
+
var _snarkjs = require("snarkjs");
|
9
|
+
var _ramda = require("ramda");
|
10
|
+
var _encoder = require("./encoder.js");
|
11
|
+
var _collection = _interopRequireDefault(require("./collection.js"));
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
13
|
+
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); }
|
14
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
15
|
+
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."); }
|
16
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
17
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
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 _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 }; })(); }
|
22
|
+
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); }
|
23
|
+
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); }
|
24
|
+
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); }); }; }
|
25
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
26
|
+
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); } }
|
27
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
28
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
29
|
+
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); }
|
30
|
+
var DB = exports["default"] = /*#__PURE__*/function () {
|
31
|
+
function DB(_ref) {
|
32
|
+
var _ref$size_val = _ref.size_val,
|
33
|
+
size_val = _ref$size_val === void 0 ? 8 : _ref$size_val,
|
34
|
+
_ref$size_path = _ref.size_path,
|
35
|
+
size_path = _ref$size_path === void 0 ? 4 : _ref$size_path,
|
36
|
+
_ref$level = _ref.level,
|
37
|
+
level = _ref$level === void 0 ? 168 : _ref$level,
|
38
|
+
_ref$size_json = _ref.size_json,
|
39
|
+
size_json = _ref$size_json === void 0 ? 256 : _ref$size_json,
|
40
|
+
_ref$size_txs = _ref.size_txs,
|
41
|
+
size_txs = _ref$size_txs === void 0 ? 10 : _ref$size_txs,
|
42
|
+
_ref$level_col = _ref.level_col,
|
43
|
+
level_col = _ref$level_col === void 0 ? 8 : _ref$level_col,
|
44
|
+
wasm = _ref.wasm,
|
45
|
+
zkey = _ref.zkey,
|
46
|
+
wasmRU = _ref.wasmRU,
|
47
|
+
zkeyRU = _ref.zkeyRU;
|
48
|
+
_classCallCheck(this, DB);
|
49
|
+
this.wasm = wasm;
|
50
|
+
this.zkey = zkey;
|
51
|
+
this.wasmRU = wasmRU;
|
52
|
+
this.zkeyRU = zkeyRU;
|
53
|
+
this.level_col = level_col;
|
54
|
+
this.size_val = size_val;
|
55
|
+
this.size_path = size_path;
|
56
|
+
this.level = level;
|
57
|
+
this.size_json = size_json;
|
58
|
+
this.size_txs = size_txs;
|
59
|
+
this.count = 0;
|
60
|
+
this.ids = [];
|
61
|
+
}
|
62
|
+
return _createClass(DB, [{
|
63
|
+
key: "init",
|
64
|
+
value: function () {
|
65
|
+
var _init = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
66
|
+
return _regenerator().w(function (_context) {
|
67
|
+
while (1) switch (_context.n) {
|
68
|
+
case 0:
|
69
|
+
_context.n = 1;
|
70
|
+
return (0, _circomlibjs.newMemEmptyTrie)();
|
71
|
+
case 1:
|
72
|
+
this.tree = _context.v;
|
73
|
+
this.cols = [];
|
74
|
+
case 2:
|
75
|
+
return _context.a(2);
|
76
|
+
}
|
77
|
+
}, _callee, this);
|
78
|
+
}));
|
79
|
+
function init() {
|
80
|
+
return _init.apply(this, arguments);
|
81
|
+
}
|
82
|
+
return init;
|
83
|
+
}()
|
84
|
+
}, {
|
85
|
+
key: "parse",
|
86
|
+
value: function parse(res, tree, level) {
|
87
|
+
var isOld0 = res.isOld0 ? "1" : "0";
|
88
|
+
var oldRoot = tree.F.toObject(res.oldRoot).toString();
|
89
|
+
var newRoot = tree.F.toObject(res.newRoot).toString();
|
90
|
+
var oldKey = res.isOld0 ? "0" : tree.F.toObject(res.oldKey).toString();
|
91
|
+
var oldValue = res.isOld0 ? "0" : tree.F.toObject(res.oldValue).toString();
|
92
|
+
var siblings = res.siblings;
|
93
|
+
for (var i = 0; i < siblings.length; i++) siblings[i] = tree.F.toObject(siblings[i]);
|
94
|
+
while (siblings.length < level) siblings.push(0);
|
95
|
+
siblings = siblings.map(function (s) {
|
96
|
+
return s.toString();
|
97
|
+
});
|
98
|
+
return {
|
99
|
+
isOld0: isOld0,
|
100
|
+
oldRoot: oldRoot,
|
101
|
+
oldKey: oldKey,
|
102
|
+
oldValue: oldValue,
|
103
|
+
siblings: siblings,
|
104
|
+
newRoot: newRoot
|
105
|
+
};
|
106
|
+
}
|
107
|
+
}, {
|
108
|
+
key: "_getVal",
|
109
|
+
value: function _getVal(j, p) {
|
110
|
+
if (p.length === 0) {
|
111
|
+
return j;
|
112
|
+
} else {
|
113
|
+
var sp = p[0].split("[");
|
114
|
+
var _iterator = _createForOfIteratorHelper(sp),
|
115
|
+
_step;
|
116
|
+
try {
|
117
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
118
|
+
var v = _step.value;
|
119
|
+
if (/]$/.test(v)) {
|
120
|
+
j = j[v.replace(/]$/, "") * 1];
|
121
|
+
} else {
|
122
|
+
j = j[v];
|
123
|
+
}
|
124
|
+
}
|
125
|
+
} catch (err) {
|
126
|
+
_iterator.e(err);
|
127
|
+
} finally {
|
128
|
+
_iterator.f();
|
129
|
+
}
|
130
|
+
return this._getVal(j, p.slice(1));
|
131
|
+
}
|
132
|
+
}
|
133
|
+
}, {
|
134
|
+
key: "getVal",
|
135
|
+
value: function getVal(j, p) {
|
136
|
+
if (p === "") return j;
|
137
|
+
return this._getVal(j, p.split("."));
|
138
|
+
}
|
139
|
+
}, {
|
140
|
+
key: "genProof",
|
141
|
+
value: function () {
|
142
|
+
var _genProof = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref2) {
|
143
|
+
var json, col_id, path, id, query, inputs, _yield$groth16$fullPr, proof, publicSignals;
|
144
|
+
return _regenerator().w(function (_context2) {
|
145
|
+
while (1) switch (_context2.n) {
|
146
|
+
case 0:
|
147
|
+
json = _ref2.json, col_id = _ref2.col_id, path = _ref2.path, id = _ref2.id, query = _ref2.query;
|
148
|
+
_context2.n = 1;
|
149
|
+
return this.getInputs({
|
150
|
+
id: id,
|
151
|
+
col_id: col_id,
|
152
|
+
json: json,
|
153
|
+
path: path,
|
154
|
+
val: this.getVal(json, path),
|
155
|
+
query: query
|
156
|
+
});
|
157
|
+
case 1:
|
158
|
+
inputs = _context2.v;
|
159
|
+
_context2.n = 2;
|
160
|
+
return _snarkjs.groth16.fullProve(inputs, this.wasm, this.zkey);
|
161
|
+
case 2:
|
162
|
+
_yield$groth16$fullPr = _context2.v;
|
163
|
+
proof = _yield$groth16$fullPr.proof;
|
164
|
+
publicSignals = _yield$groth16$fullPr.publicSignals;
|
165
|
+
return _context2.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)));
|
166
|
+
}
|
167
|
+
}, _callee2, this);
|
168
|
+
}));
|
169
|
+
function genProof(_x) {
|
170
|
+
return _genProof.apply(this, arguments);
|
171
|
+
}
|
172
|
+
return genProof;
|
173
|
+
}()
|
174
|
+
}, {
|
175
|
+
key: "genRollupProof",
|
176
|
+
value: function () {
|
177
|
+
var _genRollupProof = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(txs) {
|
178
|
+
var inputs, _yield$groth16$fullPr2, proof, publicSignals;
|
179
|
+
return _regenerator().w(function (_context3) {
|
180
|
+
while (1) switch (_context3.n) {
|
181
|
+
case 0:
|
182
|
+
_context3.n = 1;
|
183
|
+
return this.getRollupInputs({
|
184
|
+
queries: txs
|
185
|
+
});
|
186
|
+
case 1:
|
187
|
+
inputs = _context3.v;
|
188
|
+
_context3.n = 2;
|
189
|
+
return _snarkjs.groth16.fullProve(inputs, this.wasmRU, this.zkeyRU);
|
190
|
+
case 2:
|
191
|
+
_yield$groth16$fullPr2 = _context3.v;
|
192
|
+
proof = _yield$groth16$fullPr2.proof;
|
193
|
+
publicSignals = _yield$groth16$fullPr2.publicSignals;
|
194
|
+
return _context3.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)));
|
195
|
+
}
|
196
|
+
}, _callee3, this);
|
197
|
+
}));
|
198
|
+
function genRollupProof(_x2) {
|
199
|
+
return _genRollupProof.apply(this, arguments);
|
200
|
+
}
|
201
|
+
return genRollupProof;
|
202
|
+
}()
|
203
|
+
}, {
|
204
|
+
key: "query",
|
205
|
+
value: function () {
|
206
|
+
var _query = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(col_id, id, path, json) {
|
207
|
+
var _this$zkdb, _this$zkdb2, _this$zkdb3, _this$zkdb4, _this$zkdb5, _this$zkdb6;
|
208
|
+
var val, inputs, sigs, params, type, _t, _t2;
|
209
|
+
return _regenerator().w(function (_context4) {
|
210
|
+
while (1) switch (_context4.n) {
|
211
|
+
case 0:
|
212
|
+
val = tar[path];
|
213
|
+
_context4.n = 1;
|
214
|
+
return this.genProof({
|
215
|
+
col_id: col_id,
|
216
|
+
id: id,
|
217
|
+
json: json,
|
218
|
+
path: path
|
219
|
+
});
|
220
|
+
case 1:
|
221
|
+
inputs = _context4.v;
|
222
|
+
sigs = inputs.slice(8);
|
223
|
+
params = [[sigs[12], sigs[13]].concat(_toConsumableArray(sigs.slice(1, 6))), inputs];
|
224
|
+
type = val === null ? 0 : typeof val === "string" ? 3 : typeof val === "boolean" ? 1 : typeof val === "number" ? Number.isInteger(val) ? 2 : 2.5 : 4;
|
225
|
+
_t = type;
|
226
|
+
_context4.n = _t === 0 ? 2 : _t === 1 ? 4 : _t === 2 ? 6 : _t === 2.5 ? 8 : _t === 3 ? 10 : _t === 4 ? 12 : 14;
|
227
|
+
break;
|
228
|
+
case 2:
|
229
|
+
_context4.n = 3;
|
230
|
+
return (_this$zkdb = this.zkdb).qNull.apply(_this$zkdb, params);
|
231
|
+
case 3:
|
232
|
+
return _context4.a(2, _context4.v);
|
233
|
+
case 4:
|
234
|
+
_context4.n = 5;
|
235
|
+
return (_this$zkdb2 = this.zkdb).qBool.apply(_this$zkdb2, params);
|
236
|
+
case 5:
|
237
|
+
return _context4.a(2, _context4.v);
|
238
|
+
case 6:
|
239
|
+
_context4.n = 7;
|
240
|
+
return (_this$zkdb3 = this.zkdb).qInt.apply(_this$zkdb3, params);
|
241
|
+
case 7:
|
242
|
+
_t2 = _context4.v.toString();
|
243
|
+
return _context4.a(2, _t2 * 1);
|
244
|
+
case 8:
|
245
|
+
_context4.n = 9;
|
246
|
+
return (_this$zkdb4 = this.zkdb).qFloat.apply(_this$zkdb4, params);
|
247
|
+
case 9:
|
248
|
+
return _context4.a(2, _context4.v.map(function (n) {
|
249
|
+
return n.toString() * 1;
|
250
|
+
}));
|
251
|
+
case 10:
|
252
|
+
_context4.n = 11;
|
253
|
+
return (_this$zkdb5 = this.zkdb).qString.apply(_this$zkdb5, params);
|
254
|
+
case 11:
|
255
|
+
return _context4.a(2, _context4.v);
|
256
|
+
case 12:
|
257
|
+
_context4.n = 13;
|
258
|
+
return (_this$zkdb6 = this.zkdb).qRaw.apply(_this$zkdb6, params);
|
259
|
+
case 13:
|
260
|
+
return _context4.a(2, _context4.v.map(function (n) {
|
261
|
+
return n.toString() * 1;
|
262
|
+
}));
|
263
|
+
case 14:
|
264
|
+
return _context4.a(2);
|
265
|
+
}
|
266
|
+
}, _callee4, this);
|
267
|
+
}));
|
268
|
+
function query(_x3, _x4, _x5, _x6) {
|
269
|
+
return _query.apply(this, arguments);
|
270
|
+
}
|
271
|
+
return query;
|
272
|
+
}()
|
273
|
+
}, {
|
274
|
+
key: "getRollupInputs",
|
275
|
+
value: function () {
|
276
|
+
var _getRollupInputs = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(_ref3) {
|
277
|
+
var queries, write, _json, oldRoot, newRoot, oldKey, oldValue, siblings, isOld0, oldRoot_db, newRoot_db, oldKey_db, oldValue_db, siblings_db, isOld0_db, newKey_db, newKey, _res, json, fnc, i, v, _yield$this$insert, update, tree, res2, res, icol, idb, _newKey, _newKey_db;
|
278
|
+
return _regenerator().w(function (_context5) {
|
279
|
+
while (1) switch (_context5.n) {
|
280
|
+
case 0:
|
281
|
+
queries = _ref3.queries;
|
282
|
+
oldRoot = [];
|
283
|
+
newRoot = [];
|
284
|
+
oldKey = [];
|
285
|
+
oldValue = [];
|
286
|
+
siblings = [];
|
287
|
+
isOld0 = [];
|
288
|
+
oldRoot_db = [];
|
289
|
+
newRoot_db = [];
|
290
|
+
oldKey_db = [];
|
291
|
+
oldValue_db = [];
|
292
|
+
siblings_db = [];
|
293
|
+
isOld0_db = [];
|
294
|
+
newKey_db = [];
|
295
|
+
newKey = [];
|
296
|
+
json = [];
|
297
|
+
fnc = [];
|
298
|
+
i = 0;
|
299
|
+
case 1:
|
300
|
+
if (!(i < this.size_txs)) {
|
301
|
+
_context5.n = 5;
|
302
|
+
break;
|
303
|
+
}
|
304
|
+
v = queries[i];
|
305
|
+
if (v) {
|
306
|
+
_context5.n = 2;
|
307
|
+
break;
|
308
|
+
}
|
309
|
+
json.push((0, _ramda.range)(0, this.size_json).map(function () {
|
310
|
+
return "0";
|
311
|
+
}));
|
312
|
+
fnc.push([0, 0]);
|
313
|
+
newRoot.push(newRoot[i - 1]);
|
314
|
+
oldRoot.push("0");
|
315
|
+
oldKey.push("0");
|
316
|
+
oldValue.push("0");
|
317
|
+
siblings.push((0, _ramda.range)(0, this.level).map(function () {
|
318
|
+
return "0";
|
319
|
+
}));
|
320
|
+
isOld0.push("0");
|
321
|
+
oldRoot_db.push(newRoot_db[i - 1]);
|
322
|
+
newRoot_db.push(newRoot_db[i - 1]);
|
323
|
+
oldKey_db.push("0");
|
324
|
+
oldValue_db.push("0");
|
325
|
+
siblings_db.push((0, _ramda.range)(0, this.level_col).map(function () {
|
326
|
+
return "0";
|
327
|
+
}));
|
328
|
+
isOld0_db.push("0");
|
329
|
+
newKey_db.push("0");
|
330
|
+
newKey.push("0");
|
331
|
+
return _context5.a(3, 4);
|
332
|
+
case 2:
|
333
|
+
_json = v[2];
|
334
|
+
_context5.n = 3;
|
335
|
+
return this.insert.apply(this, _toConsumableArray(v));
|
336
|
+
case 3:
|
337
|
+
_yield$this$insert = _context5.v;
|
338
|
+
update = _yield$this$insert.update;
|
339
|
+
tree = _yield$this$insert.tree;
|
340
|
+
res2 = _yield$this$insert.col;
|
341
|
+
res = _yield$this$insert.doc;
|
342
|
+
icol = this.parse(res, tree, this.level);
|
343
|
+
idb = this.parse(res2, this.tree, this.level_col);
|
344
|
+
_res = idb;
|
345
|
+
_newKey = (0, _encoder.toIndex)(v[1]);
|
346
|
+
json.push((0, _encoder.pad)((0, _encoder.toSignal)((0, _encoder.encode)(_json)), this.size_json));
|
347
|
+
_newKey_db = v[0].toString();
|
348
|
+
fnc.push(update ? [0, 1] : [1, 0]);
|
349
|
+
newRoot.push(idb.newRoot);
|
350
|
+
oldRoot.push(icol.oldRoot);
|
351
|
+
oldKey.push(icol.oldKey);
|
352
|
+
oldValue.push(icol.oldValue);
|
353
|
+
siblings.push(icol.siblings);
|
354
|
+
isOld0.push(icol.isOld0);
|
355
|
+
oldRoot_db.push(idb.oldRoot);
|
356
|
+
newRoot_db.push(idb.newRoot);
|
357
|
+
oldKey_db.push(idb.oldKey);
|
358
|
+
oldValue_db.push(idb.oldValue);
|
359
|
+
siblings_db.push(idb.siblings);
|
360
|
+
isOld0_db.push(idb.isOld0);
|
361
|
+
newKey_db.push(_newKey_db);
|
362
|
+
newKey.push(_newKey);
|
363
|
+
case 4:
|
364
|
+
i++;
|
365
|
+
_context5.n = 1;
|
366
|
+
break;
|
367
|
+
case 5:
|
368
|
+
return _context5.a(2, {
|
369
|
+
fnc: fnc,
|
370
|
+
oldRoot: oldRoot,
|
371
|
+
newRoot: newRoot,
|
372
|
+
oldKey: oldKey,
|
373
|
+
oldValue: oldValue,
|
374
|
+
siblings: siblings,
|
375
|
+
isOld0: isOld0,
|
376
|
+
oldRoot_db: oldRoot_db,
|
377
|
+
oldKey_db: oldKey_db,
|
378
|
+
oldValue_db: oldValue_db,
|
379
|
+
siblings_db: siblings_db,
|
380
|
+
isOld0_db: isOld0_db,
|
381
|
+
newKey_db: newKey_db,
|
382
|
+
newKey: newKey,
|
383
|
+
json: json
|
384
|
+
});
|
385
|
+
}
|
386
|
+
}, _callee5, this);
|
387
|
+
}));
|
388
|
+
function getRollupInputs(_x7) {
|
389
|
+
return _getRollupInputs.apply(this, arguments);
|
390
|
+
}
|
391
|
+
return getRollupInputs;
|
392
|
+
}()
|
393
|
+
}, {
|
394
|
+
key: "getQueryInputs",
|
395
|
+
value: function () {
|
396
|
+
var _getQueryInputs = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(_ref4) {
|
397
|
+
var id, col_id, json, _yield$this$insert2, update, tree, res2, res, icol, idb, newKey, newKey_db;
|
398
|
+
return _regenerator().w(function (_context6) {
|
399
|
+
while (1) switch (_context6.n) {
|
400
|
+
case 0:
|
401
|
+
id = _ref4.id, col_id = _ref4.col_id, json = _ref4.json;
|
402
|
+
_context6.n = 1;
|
403
|
+
return this.insert(col_id, id, json);
|
404
|
+
case 1:
|
405
|
+
_yield$this$insert2 = _context6.v;
|
406
|
+
update = _yield$this$insert2.update;
|
407
|
+
tree = _yield$this$insert2.tree;
|
408
|
+
res2 = _yield$this$insert2.col;
|
409
|
+
res = _yield$this$insert2.doc;
|
410
|
+
icol = this.parse(res, tree, this.level);
|
411
|
+
idb = this.parse(res2, this.tree, this.level_col);
|
412
|
+
newKey = (0, _encoder.toIndex)(id);
|
413
|
+
newKey_db = col_id.toString();
|
414
|
+
return _context6.a(2, {
|
415
|
+
fnc: update ? [0, 1] : [1, 0],
|
416
|
+
oldRoot: icol.oldRoot,
|
417
|
+
oldKey: icol.oldKey,
|
418
|
+
oldValue: icol.oldValue,
|
419
|
+
siblings: icol.siblings,
|
420
|
+
isOld0: icol.isOld0,
|
421
|
+
oldRoot_db: idb.oldRoot,
|
422
|
+
oldKey_db: idb.oldKey,
|
423
|
+
oldValue_db: idb.oldValue,
|
424
|
+
siblings_db: idb.siblings,
|
425
|
+
isOld0_db: idb.isOld0,
|
426
|
+
newRoot: idb.newRoot,
|
427
|
+
newKey_db: newKey_db,
|
428
|
+
newKey: newKey,
|
429
|
+
json: (0, _encoder.pad)((0, _encoder.toSignal)((0, _encoder.encode)(json)), this.size_json)
|
430
|
+
});
|
431
|
+
}
|
432
|
+
}, _callee6, this);
|
433
|
+
}));
|
434
|
+
function getQueryInputs(_x8) {
|
435
|
+
return _getQueryInputs.apply(this, arguments);
|
436
|
+
}
|
437
|
+
return getQueryInputs;
|
438
|
+
}()
|
439
|
+
}, {
|
440
|
+
key: "getInputs",
|
441
|
+
value: function () {
|
442
|
+
var _getInputs = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(_ref5) {
|
443
|
+
var id, col_id, json, path, val, query, col_root, col_res, col_siblings, i, col_key, col, col_inputs;
|
444
|
+
return _regenerator().w(function (_context7) {
|
445
|
+
while (1) switch (_context7.n) {
|
446
|
+
case 0:
|
447
|
+
id = _ref5.id, col_id = _ref5.col_id, json = _ref5.json, path = _ref5.path, val = _ref5.val, query = _ref5.query;
|
448
|
+
col_root = this.tree.F.toObject(this.tree.root).toString();
|
449
|
+
_context7.n = 1;
|
450
|
+
return this.getCol(col_id);
|
451
|
+
case 1:
|
452
|
+
col_res = _context7.v;
|
453
|
+
col_siblings = col_res.siblings;
|
454
|
+
for (i = 0; i < col_siblings.length; i++) col_siblings[i] = this.tree.F.toObject(col_siblings[i]);
|
455
|
+
while (col_siblings.length < this.level_col) col_siblings.push(0);
|
456
|
+
col_siblings = col_siblings.map(function (s) {
|
457
|
+
return s.toString();
|
458
|
+
});
|
459
|
+
col_key = col_id;
|
460
|
+
col = this.getColTree(col_id);
|
461
|
+
_context7.n = 2;
|
462
|
+
return col.getInputs({
|
463
|
+
id: id,
|
464
|
+
json: json,
|
465
|
+
path: path,
|
466
|
+
val: val,
|
467
|
+
query: query
|
468
|
+
});
|
469
|
+
case 2:
|
470
|
+
col_inputs = _context7.v;
|
471
|
+
return _context7.a(2, {
|
472
|
+
path: col_inputs.path,
|
473
|
+
val: col_inputs.val,
|
474
|
+
json: col_inputs.json,
|
475
|
+
root: col_inputs.root,
|
476
|
+
siblings: col_inputs.siblings,
|
477
|
+
key: (0, _encoder.toIndex)(id),
|
478
|
+
col_key: col_key,
|
479
|
+
col_siblings: col_siblings,
|
480
|
+
col_root: col_root
|
481
|
+
});
|
482
|
+
}
|
483
|
+
}, _callee7, this);
|
484
|
+
}));
|
485
|
+
function getInputs(_x9) {
|
486
|
+
return _getInputs.apply(this, arguments);
|
487
|
+
}
|
488
|
+
return getInputs;
|
489
|
+
}()
|
490
|
+
}, {
|
491
|
+
key: "getID",
|
492
|
+
value: function getID(num) {
|
493
|
+
if (!(0, _ramda.isNil)(num)) {
|
494
|
+
if ((0, _ramda.indexOf)(num)(this.ids) !== -1) {
|
495
|
+
throw Error("id exists");
|
496
|
+
}
|
497
|
+
return num;
|
498
|
+
} else {
|
499
|
+
while ((0, _ramda.indexOf)(this.count)(this.ids) !== -1) {
|
500
|
+
this.count++;
|
501
|
+
}
|
502
|
+
return this.count++;
|
503
|
+
}
|
504
|
+
}
|
505
|
+
}, {
|
506
|
+
key: "addCollection",
|
507
|
+
value: function () {
|
508
|
+
var _addCollection = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(num) {
|
509
|
+
var id, col, _col, root;
|
510
|
+
return _regenerator().w(function (_context8) {
|
511
|
+
while (1) switch (_context8.n) {
|
512
|
+
case 0:
|
513
|
+
if (!(!(0, _ramda.isNil)(num) && (!(0, _ramda.is)(Number, num) || Math.round(num) !== num))) {
|
514
|
+
_context8.n = 1;
|
515
|
+
break;
|
516
|
+
}
|
517
|
+
throw Error("id is not an integer");
|
518
|
+
case 1:
|
519
|
+
id = this.getID(num);
|
520
|
+
_context8.n = 2;
|
521
|
+
return this.tree.find(id);
|
522
|
+
case 2:
|
523
|
+
col = _context8.v;
|
524
|
+
if (!col.found) {
|
525
|
+
_context8.n = 3;
|
526
|
+
break;
|
527
|
+
}
|
528
|
+
throw Error("collection exists");
|
529
|
+
case 3:
|
530
|
+
_col = new _collection["default"]({
|
531
|
+
size_val: this.size_val,
|
532
|
+
size_path: this.size_path,
|
533
|
+
level: this.level,
|
534
|
+
size_json: this.size_json
|
535
|
+
});
|
536
|
+
_context8.n = 4;
|
537
|
+
return _col.init();
|
538
|
+
case 4:
|
539
|
+
this.cols[id] = _col;
|
540
|
+
root = _col.tree.F.toObject(_col.tree.root).toString();
|
541
|
+
_context8.n = 5;
|
542
|
+
return this.tree.insert(id, [root]);
|
543
|
+
case 5:
|
544
|
+
return _context8.a(2, id);
|
545
|
+
}
|
546
|
+
}, _callee8, this);
|
547
|
+
}));
|
548
|
+
function addCollection(_x0) {
|
549
|
+
return _addCollection.apply(this, arguments);
|
550
|
+
}
|
551
|
+
return addCollection;
|
552
|
+
}()
|
553
|
+
}, {
|
554
|
+
key: "getColTree",
|
555
|
+
value: function getColTree(col) {
|
556
|
+
var _col = this.cols[col];
|
557
|
+
if (!_col) throw Error("collection doesn't exist");
|
558
|
+
return _col;
|
559
|
+
}
|
560
|
+
}, {
|
561
|
+
key: "insert",
|
562
|
+
value: function () {
|
563
|
+
var _insert = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(col, _key, _val) {
|
564
|
+
var _col, update, res_doc, res_col;
|
565
|
+
return _regenerator().w(function (_context9) {
|
566
|
+
while (1) switch (_context9.n) {
|
567
|
+
case 0:
|
568
|
+
_col = this.getColTree(col);
|
569
|
+
update = false;
|
570
|
+
_context9.n = 1;
|
571
|
+
return _col.get(_key);
|
572
|
+
case 1:
|
573
|
+
if (!_context9.v.found) {
|
574
|
+
_context9.n = 3;
|
575
|
+
break;
|
576
|
+
}
|
577
|
+
update = true;
|
578
|
+
_context9.n = 2;
|
579
|
+
return _col.update(_key, _val);
|
580
|
+
case 2:
|
581
|
+
res_doc = _context9.v;
|
582
|
+
_context9.n = 5;
|
583
|
+
break;
|
584
|
+
case 3:
|
585
|
+
_context9.n = 4;
|
586
|
+
return _col.insert(_key, _val);
|
587
|
+
case 4:
|
588
|
+
res_doc = _context9.v;
|
589
|
+
case 5:
|
590
|
+
_context9.n = 6;
|
591
|
+
return this.updateDB(_col, col);
|
592
|
+
case 6:
|
593
|
+
res_col = _context9.v;
|
594
|
+
return _context9.a(2, {
|
595
|
+
update: update,
|
596
|
+
doc: res_doc,
|
597
|
+
col: res_col,
|
598
|
+
tree: _col.tree
|
599
|
+
});
|
600
|
+
}
|
601
|
+
}, _callee9, this);
|
602
|
+
}));
|
603
|
+
function insert(_x1, _x10, _x11) {
|
604
|
+
return _insert.apply(this, arguments);
|
605
|
+
}
|
606
|
+
return insert;
|
607
|
+
}()
|
608
|
+
}, {
|
609
|
+
key: "updateDB",
|
610
|
+
value: function () {
|
611
|
+
var _updateDB = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(_col, col) {
|
612
|
+
var root, colD;
|
613
|
+
return _regenerator().w(function (_context0) {
|
614
|
+
while (1) switch (_context0.n) {
|
615
|
+
case 0:
|
616
|
+
root = _col.tree.F.toObject(_col.tree.root).toString();
|
617
|
+
colD = col;
|
618
|
+
_context0.n = 1;
|
619
|
+
return this.tree.update(colD, [root]);
|
620
|
+
case 1:
|
621
|
+
return _context0.a(2, _context0.v);
|
622
|
+
}
|
623
|
+
}, _callee0, this);
|
624
|
+
}));
|
625
|
+
function updateDB(_x12, _x13) {
|
626
|
+
return _updateDB.apply(this, arguments);
|
627
|
+
}
|
628
|
+
return updateDB;
|
629
|
+
}()
|
630
|
+
}, {
|
631
|
+
key: "update",
|
632
|
+
value: function () {
|
633
|
+
var _update = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(col, _key, _val) {
|
634
|
+
var _col, res_doc, res_col;
|
635
|
+
return _regenerator().w(function (_context1) {
|
636
|
+
while (1) switch (_context1.n) {
|
637
|
+
case 0:
|
638
|
+
_col = this.getColTree(col);
|
639
|
+
_context1.n = 1;
|
640
|
+
return _col.update(_key, _val);
|
641
|
+
case 1:
|
642
|
+
res_doc = _context1.v;
|
643
|
+
_context1.n = 2;
|
644
|
+
return this.updateDB(_col, col);
|
645
|
+
case 2:
|
646
|
+
res_col = _context1.v;
|
647
|
+
return _context1.a(2, {
|
648
|
+
doc: res_doc,
|
649
|
+
col: res_col,
|
650
|
+
tree: _col.tree
|
651
|
+
});
|
652
|
+
}
|
653
|
+
}, _callee1, this);
|
654
|
+
}));
|
655
|
+
function update(_x14, _x15, _x16) {
|
656
|
+
return _update.apply(this, arguments);
|
657
|
+
}
|
658
|
+
return update;
|
659
|
+
}()
|
660
|
+
}, {
|
661
|
+
key: "delete",
|
662
|
+
value: function () {
|
663
|
+
var _delete2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(col, _key) {
|
664
|
+
var _col, res_doc, res_col;
|
665
|
+
return _regenerator().w(function (_context10) {
|
666
|
+
while (1) switch (_context10.n) {
|
667
|
+
case 0:
|
668
|
+
_col = this.getColTree(col);
|
669
|
+
_context10.n = 1;
|
670
|
+
return _col["delete"](_key);
|
671
|
+
case 1:
|
672
|
+
res_doc = _context10.v;
|
673
|
+
_context10.n = 2;
|
674
|
+
return this.updateDB(_col, col);
|
675
|
+
case 2:
|
676
|
+
res_col = _context10.v;
|
677
|
+
return _context10.a(2, {
|
678
|
+
doc: res_doc,
|
679
|
+
col: res_col,
|
680
|
+
tree: _col.tree
|
681
|
+
});
|
682
|
+
}
|
683
|
+
}, _callee10, this);
|
684
|
+
}));
|
685
|
+
function _delete(_x17, _x18) {
|
686
|
+
return _delete2.apply(this, arguments);
|
687
|
+
}
|
688
|
+
return _delete;
|
689
|
+
}()
|
690
|
+
}, {
|
691
|
+
key: "get",
|
692
|
+
value: function () {
|
693
|
+
var _get = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11(col, _key) {
|
694
|
+
var _col;
|
695
|
+
return _regenerator().w(function (_context11) {
|
696
|
+
while (1) switch (_context11.n) {
|
697
|
+
case 0:
|
698
|
+
_col = this.getColTree(col);
|
699
|
+
_context11.n = 1;
|
700
|
+
return _col.get(_key);
|
701
|
+
case 1:
|
702
|
+
return _context11.a(2, _context11.v);
|
703
|
+
}
|
704
|
+
}, _callee11, this);
|
705
|
+
}));
|
706
|
+
function get(_x19, _x20) {
|
707
|
+
return _get.apply(this, arguments);
|
708
|
+
}
|
709
|
+
return get;
|
710
|
+
}()
|
711
|
+
}, {
|
712
|
+
key: "getCol",
|
713
|
+
value: function () {
|
714
|
+
var _getCol = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12(col) {
|
715
|
+
return _regenerator().w(function (_context12) {
|
716
|
+
while (1) switch (_context12.n) {
|
717
|
+
case 0:
|
718
|
+
_context12.n = 1;
|
719
|
+
return this.tree.find(col);
|
720
|
+
case 1:
|
721
|
+
return _context12.a(2, _context12.v);
|
722
|
+
}
|
723
|
+
}, _callee12, this);
|
724
|
+
}));
|
725
|
+
function getCol(_x21) {
|
726
|
+
return _getCol.apply(this, arguments);
|
727
|
+
}
|
728
|
+
return getCol;
|
729
|
+
}()
|
730
|
+
}]);
|
731
|
+
}();
|