zkjson 0.8.4 → 0.8.6
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/.babelrc-cjs +5 -0
- package/.babelrc-esm +5 -0
- package/README.md +32 -0
- package/make.js +17 -0
- package/package.json +8 -5
- package/cjs/circomlibjs/SMT.js +0 -481
- package/cjs/circomlibjs/SMTMemDb.js +0 -233
- package/cjs/circomlibjs/buildPoseidon.js +0 -164
- package/cjs/circomlibjs/buildPoseidonWasm.js +0 -124
- package/cjs/circomlibjs/getHashes.js +0 -220
- package/cjs/circomlibjs/poseidonConstants$1.js +0 -1
- package/cjs/circomlibjs.js +0 -149
- package/cjs/collection.js +0 -196
- package/cjs/collection_tree.js +0 -183
- package/cjs/db.js +0 -745
- package/cjs/db_tree.js +0 -560
- package/cjs/doc.js +0 -132
- package/cjs/doc_tree.js +0 -84
- package/cjs/encoder-v1_5.js +0 -1731
- package/cjs/encoder.js +0 -668
- package/cjs/index.js +0 -88
- package/cjs/json.js +0 -54
- package/cjs/newMemEmptyTrie.js +0 -45
- package/cjs/nft.js +0 -164
- package/cjs/parse.js +0 -256
- package/cjs/prover.js +0 -84
- package/cjs/uint.js +0 -580
- package/esm/package.json +0 -3
- /package/{esm → src}/circomlibjs/SMT.js +0 -0
- /package/{esm → src}/circomlibjs/SMTMemDb.js +0 -0
- /package/{esm → src}/circomlibjs/buildPoseidon.js +0 -0
- /package/{esm → src}/circomlibjs/buildPoseidonWasm.js +0 -0
- /package/{esm → src}/circomlibjs/getHashes.js +0 -0
- /package/{esm → src}/circomlibjs/poseidonConstants$1.js +0 -0
- /package/{esm → src}/circomlibjs.js +0 -0
- /package/{esm → src}/collection.js +0 -0
- /package/{esm → src}/collection_tree.js +0 -0
- /package/{esm → src}/contracts/NORollup.sol +0 -0
- /package/{esm → src}/contracts/OPRollup.sol +0 -0
- /package/{esm → src}/contracts/ZKIPFS.sol +0 -0
- /package/{esm → src}/contracts/ZKJson.sol +0 -0
- /package/{esm → src}/contracts/ZKQuery.sol +0 -0
- /package/{esm → src}/contracts/ZKRollup.sol +0 -0
- /package/{esm → src}/contracts/apps/SimpleJSON.sol +0 -0
- /package/{esm → src}/contracts/apps/SimpleOPRU.sol +0 -0
- /package/{esm → src}/contracts/apps/SimpleRU.sol +0 -0
- /package/{esm → src}/contracts/apps/Token.sol +0 -0
- /package/{esm → src}/contracts/apps/ZKArweave.sol +0 -0
- /package/{esm → src}/contracts/apps/ZKBridge.sol +0 -0
- /package/{esm → src}/contracts/apps/ZKNFT.sol +0 -0
- /package/{esm → src}/contracts/verifiers/verifier_db.sol +0 -0
- /package/{esm → src}/contracts/verifiers/verifier_ipfs.sol +0 -0
- /package/{esm → src}/contracts/verifiers/verifier_json.sol +0 -0
- /package/{esm → src}/contracts/verifiers/verifier_rollup.sol +0 -0
- /package/{esm → src}/db.js +0 -0
- /package/{esm → src}/db_tree.js +0 -0
- /package/{esm → src}/doc.js +0 -0
- /package/{esm → src}/doc_tree.js +0 -0
- /package/{esm → src}/encoder-v1_5.js +0 -0
- /package/{esm → src}/encoder.js +0 -0
- /package/{esm → src}/index.js +0 -0
- /package/{esm → src}/json.js +0 -0
- /package/{esm → src}/newMemEmptyTrie.js +0 -0
- /package/{esm → src}/nft.js +0 -0
- /package/{esm → src}/parse.js +0 -0
- /package/{esm → src}/prover.js +0 -0
- /package/{esm → src}/uint.js +0 -0
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
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); }
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports["default"] = getHashes;
|
|
8
|
-
var ffjavascript = _interopRequireWildcard(require("ffjavascript"));
|
|
9
|
-
var _poseidonConstants$ = _interopRequireDefault(require("./poseidonConstants$1.js"));
|
|
10
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
11
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
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 }; })(); }
|
|
13
|
-
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); }
|
|
14
|
-
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); }
|
|
15
|
-
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); }); }; }
|
|
16
|
-
function buildPoseidonWasm(module) {
|
|
17
|
-
var F = new ffjavascript.F1Field(ffjavascript.Scalar.e("21888242871839275222246405745257275088548364400416034343698204186575808495617"));
|
|
18
|
-
var N_ROUNDS_P = [56, 57, 56, 60, 60, 63, 64, 63, 60, 66, 60, 65, 70, 60, 64, 68];
|
|
19
|
-
var NSizes = _poseidonConstants$["default"].C.length;
|
|
20
|
-
var buffIdx = new Uint8Array(NSizes * 5 * 4);
|
|
21
|
-
var buffIdx32 = new Uint32Array(buffIdx.buffer);
|
|
22
|
-
for (var i = 0; i < NSizes; i++) {
|
|
23
|
-
buffIdx32[i * 5] = N_ROUNDS_P[i];
|
|
24
|
-
var buffC = new Uint8Array(32 * _poseidonConstants$["default"].C[i].length);
|
|
25
|
-
for (var j = 0; j < _poseidonConstants$["default"].C[i].length; j++) {
|
|
26
|
-
F.toRprLEM(buffC, j * 32, F.e(_poseidonConstants$["default"].C[i][j]));
|
|
27
|
-
}
|
|
28
|
-
buffIdx32[i * 5 + 1] = module.alloc(buffC);
|
|
29
|
-
var buffS = new Uint8Array(32 * _poseidonConstants$["default"].S[i].length);
|
|
30
|
-
for (var _j = 0; _j < _poseidonConstants$["default"].S[i].length; _j++) {
|
|
31
|
-
F.toRprLEM(buffS, _j * 32, F.e(_poseidonConstants$["default"].S[i][_j]));
|
|
32
|
-
}
|
|
33
|
-
buffIdx32[i * 5 + 2] = module.alloc(buffS);
|
|
34
|
-
var N = _poseidonConstants$["default"].M[i].length;
|
|
35
|
-
var buffM = new Uint8Array(32 * N * N);
|
|
36
|
-
for (var _j2 = 0; _j2 < N; _j2++) {
|
|
37
|
-
for (var k = 0; k < N; k++) {
|
|
38
|
-
F.toRprLEM(buffM, (_j2 * N + k) * 32, F.e(_poseidonConstants$["default"].M[i][k][_j2]));
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
buffIdx32[i * 5 + 3] = module.alloc(buffM);
|
|
42
|
-
var buffP = new Uint8Array(32 * N * N);
|
|
43
|
-
for (var _j3 = 0; _j3 < N; _j3++) {
|
|
44
|
-
for (var _k = 0; _k < N; _k++) {
|
|
45
|
-
F.toRprLEM(buffP, (_j3 * N + _k) * 32, F.e(_poseidonConstants$["default"].P[i][_k][_j3]));
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
buffIdx32[i * 5 + 4] = module.alloc(buffP);
|
|
49
|
-
}
|
|
50
|
-
var pConstants = module.alloc(buffIdx);
|
|
51
|
-
var pState = module.alloc(32 * ((NSizes + 1) * 32));
|
|
52
|
-
function buildAddConstant() {
|
|
53
|
-
var f = module.addFunction("poseidon_addConstant");
|
|
54
|
-
f.addParam("t", "i32");
|
|
55
|
-
f.addParam("pC", "i32");
|
|
56
|
-
f.setReturnType("i32");
|
|
57
|
-
f.addLocal("i", "i32");
|
|
58
|
-
f.addLocal("pState", "i32");
|
|
59
|
-
var c = f.getCodeBuilder();
|
|
60
|
-
f.addCode(c.setLocal("pState", c.i32_const(pState)), c.setLocal("i", c.i32_const(0)), c.block(c.loop(c.br_if(1, c.i32_eq(c.getLocal("i"), c.getLocal("t"))), c.call("frm_add", c.getLocal("pC"), c.getLocal("pState"), c.getLocal("pState")), c.setLocal("pC", c.i32_add(c.getLocal("pC"), c.i32_const(32))), c.setLocal("pState", c.i32_add(c.getLocal("pState"), c.i32_const(32))), c.setLocal("i", c.i32_add(c.getLocal("i"), c.i32_const(1))), c.br(0))), c.ret(c.getLocal("pC")));
|
|
61
|
-
}
|
|
62
|
-
function buildPower5() {
|
|
63
|
-
var f = module.addFunction("poseidon_power5");
|
|
64
|
-
f.addParam("p", "i32");
|
|
65
|
-
var c = f.getCodeBuilder();
|
|
66
|
-
var AUX = c.i32_const(module.alloc(32));
|
|
67
|
-
f.addCode(c.call("frm_square", c.getLocal("p"), AUX), c.call("frm_square", AUX, AUX), c.call("frm_mul", c.getLocal("p"), AUX, c.getLocal("p")));
|
|
68
|
-
}
|
|
69
|
-
function buildPower5all() {
|
|
70
|
-
var f = module.addFunction("poseidon_power5all");
|
|
71
|
-
f.addParam("t", "i32");
|
|
72
|
-
f.addLocal("i", "i32");
|
|
73
|
-
f.addLocal("pState", "i32");
|
|
74
|
-
var c = f.getCodeBuilder();
|
|
75
|
-
f.addCode(c.setLocal("pState", c.i32_const(pState)), c.setLocal("i", c.i32_const(0)), c.block(c.loop(c.br_if(1, c.i32_eq(c.getLocal("i"), c.getLocal("t"))), c.call("poseidon_power5", c.getLocal("pState")), c.setLocal("pState", c.i32_add(c.getLocal("pState"), c.i32_const(32))), c.setLocal("i", c.i32_add(c.getLocal("i"), c.i32_const(1))), c.br(0))));
|
|
76
|
-
}
|
|
77
|
-
function buildApplyMatrix() {
|
|
78
|
-
var f = module.addFunction("poseidon_applyMatrix");
|
|
79
|
-
f.addParam("t", "i32");
|
|
80
|
-
f.addParam("pM", "i32");
|
|
81
|
-
f.addLocal("i", "i32");
|
|
82
|
-
f.addLocal("j", "i32");
|
|
83
|
-
f.addLocal("pState", "i32");
|
|
84
|
-
f.addLocal("pStateAux", "i32");
|
|
85
|
-
var c = f.getCodeBuilder();
|
|
86
|
-
var pStateAux = module.alloc(32 * ((NSizes + 1) * 32));
|
|
87
|
-
var pAux = module.alloc(32);
|
|
88
|
-
f.addCode(c.setLocal("pStateAux", c.i32_const(pStateAux)), c.setLocal("i", c.i32_const(0)), c.block(c.loop(c.br_if(1, c.i32_eq(c.getLocal("i"), c.getLocal("t"))), c.call("frm_zero", c.getLocal("pStateAux")), c.setLocal("pState", c.i32_const(pState)), c.setLocal("j", c.i32_const(0)), c.block(c.loop(c.br_if(1, c.i32_eq(c.getLocal("j"), c.getLocal("t"))), c.call("frm_mul", c.getLocal("pState"), c.getLocal("pM"), c.i32_const(pAux)), c.call("frm_add", c.i32_const(pAux), c.getLocal("pStateAux"), c.getLocal("pStateAux")), c.setLocal("pM", c.i32_add(c.getLocal("pM"), c.i32_const(32))), c.setLocal("pState", c.i32_add(c.getLocal("pState"), c.i32_const(32))), c.setLocal("j", c.i32_add(c.getLocal("j"), c.i32_const(1))), c.br(0))), c.setLocal("pStateAux", c.i32_add(c.getLocal("pStateAux"), c.i32_const(32))), c.setLocal("i", c.i32_add(c.getLocal("i"), c.i32_const(1))), c.br(0))), c.setLocal("pStateAux", c.i32_const(pStateAux)), c.setLocal("pState", c.i32_const(pState)), c.setLocal("i", c.i32_const(0)), c.block(c.loop(c.br_if(1, c.i32_eq(c.getLocal("i"), c.getLocal("t"))), c.call("frm_copy", c.getLocal("pStateAux"), c.getLocal("pState")), c.setLocal("pState", c.i32_add(c.getLocal("pState"), c.i32_const(32))), c.setLocal("pStateAux", c.i32_add(c.getLocal("pStateAux"), c.i32_const(32))), c.setLocal("i", c.i32_add(c.getLocal("i"), c.i32_const(1))), c.br(0))));
|
|
89
|
-
}
|
|
90
|
-
function buildApplySMatrix() {
|
|
91
|
-
var f = module.addFunction("poseidon_applySMatrix");
|
|
92
|
-
f.addParam("t", "i32");
|
|
93
|
-
f.addParam("pS", "i32");
|
|
94
|
-
f.setReturnType("i32");
|
|
95
|
-
f.addLocal("i", "i32");
|
|
96
|
-
f.addLocal("pState", "i32");
|
|
97
|
-
var c = f.getCodeBuilder();
|
|
98
|
-
var pS0 = module.alloc(32);
|
|
99
|
-
var pAux = module.alloc(32);
|
|
100
|
-
f.addCode(c.call("frm_zero", c.i32_const(pS0)), c.setLocal("pState", c.i32_const(pState)), c.setLocal("i", c.i32_const(0)), c.block(c.loop(c.br_if(1, c.i32_eq(c.getLocal("i"), c.getLocal("t"))), c.call("frm_mul", c.getLocal("pState"), c.getLocal("pS"), c.i32_const(pAux)), c.call("frm_add", c.i32_const(pS0), c.i32_const(pAux), c.i32_const(pS0)), c.setLocal("pS", c.i32_add(c.getLocal("pS"), c.i32_const(32))), c.setLocal("pState", c.i32_add(c.getLocal("pState"), c.i32_const(32))), c.setLocal("i", c.i32_add(c.getLocal("i"), c.i32_const(1))), c.br(0))), c.setLocal("pState", c.i32_const(pState + 32)), c.setLocal("i", c.i32_const(1)), c.block(c.loop(c.br_if(1, c.i32_eq(c.getLocal("i"), c.getLocal("t"))), c.call("frm_mul", c.i32_const(pState), c.getLocal("pS"), c.i32_const(pAux)), c.call("frm_add", c.getLocal("pState"), c.i32_const(pAux), c.getLocal("pState")), c.setLocal("pS", c.i32_add(c.getLocal("pS"), c.i32_const(32))), c.setLocal("pState", c.i32_add(c.getLocal("pState"), c.i32_const(32))), c.setLocal("i", c.i32_add(c.getLocal("i"), c.i32_const(1))), c.br(0))), c.call("frm_copy", c.i32_const(pS0), c.i32_const(pState)), c.ret(c.getLocal("pS")));
|
|
101
|
-
}
|
|
102
|
-
function buildPoseidon() {
|
|
103
|
-
var f = module.addFunction("poseidon");
|
|
104
|
-
f.addParam("pInitState", "i32");
|
|
105
|
-
f.addParam("pIn", "i32");
|
|
106
|
-
f.addParam("n", "i32");
|
|
107
|
-
f.addParam("pOut", "i32");
|
|
108
|
-
f.addParam("nOut", "i32");
|
|
109
|
-
f.addLocal("pC", "i32");
|
|
110
|
-
f.addLocal("pS", "i32");
|
|
111
|
-
f.addLocal("pM", "i32");
|
|
112
|
-
f.addLocal("pP", "i32");
|
|
113
|
-
f.addLocal("t", "i32");
|
|
114
|
-
f.addLocal("i", "i32");
|
|
115
|
-
f.addLocal("nRoundsP", "i32");
|
|
116
|
-
f.addLocal("pAux", "i32");
|
|
117
|
-
var c = f.getCodeBuilder();
|
|
118
|
-
f.addCode(c.setLocal("t", c.i32_add(c.getLocal("n"), c.i32_const(1))), c.setLocal("pAux", c.i32_add(c.i32_const(pConstants), c.i32_mul(c.i32_sub(c.getLocal("n"), c.i32_const(1)), c.i32_const(20)))), c.setLocal("nRoundsP", c.i32_load(c.getLocal("pAux"))), c.setLocal("pC", c.i32_load(c.i32_add(c.getLocal("pAux"), c.i32_const(4)))), c.setLocal("pS", c.i32_load(c.i32_add(c.getLocal("pAux"), c.i32_const(8)))), c.setLocal("pM", c.i32_load(c.i32_add(c.getLocal("pAux"), c.i32_const(12)))), c.setLocal("pP", c.i32_load(c.i32_add(c.getLocal("pAux"), c.i32_const(16)))),
|
|
119
|
-
// Initialize state
|
|
120
|
-
c.call("frm_zero", c.i32_const(pState)), c.call("frm_copy", c.getLocal("pInitState"), c.i32_const(pState)), c.setLocal("i", c.i32_const(1)), c.block(c.loop(c.call("frm_copy", c.i32_add(c.getLocal("pIn"), c.i32_mul(c.i32_sub(c.getLocal("i"), c.i32_const(1)), c.i32_const(32))), c.i32_add(c.i32_const(pState), c.i32_mul(c.getLocal("i"), c.i32_const(32)))), c.br_if(1, c.i32_eq(c.getLocal("i"), c.getLocal("n"))), c.setLocal("i", c.i32_add(c.getLocal("i"), c.i32_const(1))), c.br(0))),
|
|
121
|
-
// Initialize state
|
|
122
|
-
c.setLocal("pC", c.call("poseidon_addConstant", c.getLocal("t"), c.getLocal("pC"))),
|
|
123
|
-
// First full rounds
|
|
124
|
-
c.setLocal("i", c.i32_const(0)), c.block(c.loop(c.br_if(1, c.i32_eq(c.getLocal("i"), c.i32_const(3))), c.call("poseidon_power5all", c.getLocal("t")), c.setLocal("pC", c.call("poseidon_addConstant", c.getLocal("t"), c.getLocal("pC"))), c.call("poseidon_applyMatrix", c.getLocal("t"), c.getLocal("pM")), c.setLocal("i", c.i32_add(c.getLocal("i"), c.i32_const(1))), c.br(0))), c.call("poseidon_power5all", c.getLocal("t")), c.setLocal("pC", c.call("poseidon_addConstant", c.getLocal("t"), c.getLocal("pC"))), c.call("poseidon_applyMatrix", c.getLocal("t"), c.getLocal("pP")), c.setLocal("i", c.i32_const(0)), c.block(c.loop(c.br_if(1, c.i32_eq(c.getLocal("i"), c.getLocal("nRoundsP"))), c.call("poseidon_power5", c.i32_const(pState)), c.call("frm_add", c.i32_const(pState), c.getLocal("pC"), c.i32_const(pState)), c.setLocal("pC", c.i32_add(c.getLocal("pC"), c.i32_const(32))), c.setLocal("pS", c.call("poseidon_applySMatrix", c.getLocal("t"), c.getLocal("pS"))), c.setLocal("i", c.i32_add(c.getLocal("i"), c.i32_const(1))), c.br(0))), c.setLocal("i", c.i32_const(0)), c.block(c.loop(c.br_if(1, c.i32_eq(c.getLocal("i"), c.i32_const(3))), c.call("poseidon_power5all", c.getLocal("t")), c.setLocal("pC", c.call("poseidon_addConstant", c.getLocal("t"), c.getLocal("pC"))), c.call("poseidon_applyMatrix", c.getLocal("t"), c.getLocal("pM")), c.setLocal("i", c.i32_add(c.getLocal("i"), c.i32_const(1))), c.br(0))), c.call("poseidon_power5all", c.getLocal("t")), c.call("poseidon_applyMatrix", c.getLocal("t"), c.getLocal("pM")), c.setLocal("i", c.i32_const(0)), c.block(c.loop(c.br_if(1, c.i32_eq(c.getLocal("i"), c.getLocal("nOut"))), c.call("frm_copy", c.i32_add(c.i32_const(pState), c.i32_mul(c.getLocal("i"), c.i32_const(32))), c.i32_add(c.getLocal("pOut"), c.i32_mul(c.getLocal("i"), c.i32_const(32)))), c.setLocal("i", c.i32_add(c.getLocal("i"), c.i32_const(1))), c.br(0))));
|
|
125
|
-
}
|
|
126
|
-
buildAddConstant();
|
|
127
|
-
buildPower5();
|
|
128
|
-
buildPower5all();
|
|
129
|
-
buildApplyMatrix();
|
|
130
|
-
buildApplySMatrix();
|
|
131
|
-
buildPoseidon();
|
|
132
|
-
module.exportFunction("poseidon");
|
|
133
|
-
}
|
|
134
|
-
function buildPoseidon$2() {
|
|
135
|
-
return _buildPoseidon$.apply(this, arguments);
|
|
136
|
-
}
|
|
137
|
-
function _buildPoseidon$() {
|
|
138
|
-
_buildPoseidon$ = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
139
|
-
var bn128, F, pState, pIn, pOut, poseidon;
|
|
140
|
-
return _regenerator().w(function (_context) {
|
|
141
|
-
while (1) switch (_context.n) {
|
|
142
|
-
case 0:
|
|
143
|
-
_context.n = 1;
|
|
144
|
-
return ffjavascript.getCurveFromName("bn128", true, buildPoseidonWasm);
|
|
145
|
-
case 1:
|
|
146
|
-
bn128 = _context.v;
|
|
147
|
-
F = bn128.Fr;
|
|
148
|
-
pState = bn128.tm.alloc(32);
|
|
149
|
-
pIn = bn128.tm.alloc(32 * 16);
|
|
150
|
-
pOut = bn128.tm.alloc(32 * 17);
|
|
151
|
-
poseidon = function poseidon(arr, state, nOut) {
|
|
152
|
-
var buff;
|
|
153
|
-
var n;
|
|
154
|
-
if (Array.isArray(arr)) {
|
|
155
|
-
n = arr.length;
|
|
156
|
-
buff = new Uint8Array(n * 32);
|
|
157
|
-
for (var i = 0; i < n; i++) buff.set(F.e(arr[i]), i * 32);
|
|
158
|
-
} else {
|
|
159
|
-
buff = arr;
|
|
160
|
-
n = buff.byteLength / 32;
|
|
161
|
-
if (n * 32 != buff.byteLength) throw new Error("Invalid iput buff size");
|
|
162
|
-
}
|
|
163
|
-
bn128.tm.setBuff(pIn, buff);
|
|
164
|
-
if (n < 1 || n > 16) throw new Error("Invalid poseidon size");
|
|
165
|
-
if (typeof state == "undefined") {
|
|
166
|
-
state = F.zero;
|
|
167
|
-
} else {
|
|
168
|
-
state = F.e(state);
|
|
169
|
-
}
|
|
170
|
-
bn128.tm.setBuff(pState, state);
|
|
171
|
-
nOut = nOut || 1;
|
|
172
|
-
bn128.tm.instance.exports.poseidon(pState, pIn, n, pOut, nOut);
|
|
173
|
-
if (nOut == 1) {
|
|
174
|
-
return bn128.tm.getBuff(pOut, 32);
|
|
175
|
-
} else {
|
|
176
|
-
var out = [];
|
|
177
|
-
for (var _i = 0; _i < nOut; _i++) {
|
|
178
|
-
out.push(bn128.tm.getBuff(pOut + _i * 32, 32));
|
|
179
|
-
}
|
|
180
|
-
return out;
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
poseidon.F = F;
|
|
184
|
-
return _context.a(2, poseidon);
|
|
185
|
-
}
|
|
186
|
-
}, _callee);
|
|
187
|
-
}));
|
|
188
|
-
return _buildPoseidon$.apply(this, arguments);
|
|
189
|
-
}
|
|
190
|
-
function getHashes() {
|
|
191
|
-
return _getHashes.apply(this, arguments);
|
|
192
|
-
}
|
|
193
|
-
function _getHashes() {
|
|
194
|
-
_getHashes = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
|
|
195
|
-
var bn128, poseidon;
|
|
196
|
-
return _regenerator().w(function (_context2) {
|
|
197
|
-
while (1) switch (_context2.n) {
|
|
198
|
-
case 0:
|
|
199
|
-
_context2.n = 1;
|
|
200
|
-
return ffjavascript.getCurveFromName("bn128", true);
|
|
201
|
-
case 1:
|
|
202
|
-
bn128 = _context2.v;
|
|
203
|
-
_context2.n = 2;
|
|
204
|
-
return buildPoseidon$2();
|
|
205
|
-
case 2:
|
|
206
|
-
poseidon = _context2.v;
|
|
207
|
-
return _context2.a(2, {
|
|
208
|
-
hash0: function hash0(left, right) {
|
|
209
|
-
return poseidon([left, right]);
|
|
210
|
-
},
|
|
211
|
-
hash1: function hash1(key, value) {
|
|
212
|
-
return poseidon([key, value, bn128.Fr.one]);
|
|
213
|
-
},
|
|
214
|
-
F: bn128.Fr
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
}, _callee2);
|
|
218
|
-
}));
|
|
219
|
-
return _getHashes.apply(this, arguments);
|
|
220
|
-
}
|