diff --git a/.gitignore b/.gitignore index aea8ef9b..5d561b6a 100644 --- a/.gitignore +++ b/.gitignore @@ -68,3 +68,5 @@ tmp .DS_Store stats.html + +sophia_smart_contract_tests/contracts diff --git a/build/browser.esm.js b/build/browser.esm.js index a7c592d4..b2efa01b 100644 --- a/build/browser.esm.js +++ b/build/browser.esm.js @@ -3886,10 +3886,10 @@ class WitnessCalculatorCircom2 { You should have received a copy of the GNU General Public License along with snarkJS. If not, see . */ -const { unstringifyBigInts: unstringifyBigInts$b} = utils; +const { unstringifyBigInts: unstringifyBigInts$c} = utils; async function wtnsCalculate(_input, wasmFileName, wtnsFileName, options) { - const input = unstringifyBigInts$b(_input); + const input = unstringifyBigInts$c(_input); const fdWasm = await readExisting(wasmFileName); const wasm = await fdWasm.read(fdWasm.totalSize); @@ -3931,10 +3931,10 @@ async function wtnsCalculate(_input, wasmFileName, wtnsFileName, options) { You should have received a copy of the GNU General Public License along with snarkJS. If not, see . */ -const {unstringifyBigInts: unstringifyBigInts$a} = utils; +const {unstringifyBigInts: unstringifyBigInts$b} = utils; async function groth16FullProve(_input, wasmFile, zkeyFileName, logger) { - const input = unstringifyBigInts$a(_input); + const input = unstringifyBigInts$b(_input); const wtns= { type: "mem" @@ -3961,7 +3961,7 @@ async function groth16FullProve(_input, wasmFile, zkeyFileName, logger) { You should have received a copy of the GNU General Public License along with snarkjs. If not, see . */ -const {unstringifyBigInts: unstringifyBigInts$9} = utils; +const {unstringifyBigInts: unstringifyBigInts$a} = utils; async function groth16Verify(_vk_verifier, _publicSignals, _proof, logger) { /* @@ -3971,9 +3971,9 @@ async function groth16Verify(_vk_verifier, _publicSignals, _proof, logger) { } */ - const vk_verifier = unstringifyBigInts$9(_vk_verifier); - const proof = unstringifyBigInts$9(_proof); - const publicSignals = unstringifyBigInts$9(_publicSignals); + const vk_verifier = unstringifyBigInts$a(_vk_verifier); + const proof = unstringifyBigInts$a(_proof); + const publicSignals = unstringifyBigInts$a(_publicSignals); const curve = await getCurveFromName(vk_verifier.curve); @@ -4062,7 +4062,7 @@ function publicInputsAreValid$1(curve, publicInputs) { You should have received a copy of the GNU General Public License along with snarkJS. If not, see . */ -const { unstringifyBigInts: unstringifyBigInts$8} = utils; +const { unstringifyBigInts: unstringifyBigInts$9} = utils; function p256$2(n) { let nstr = n.toString(16); @@ -4072,8 +4072,8 @@ function p256$2(n) { } async function groth16ExportSolidityCallData(_proof, _pub) { - const proof = unstringifyBigInts$8(_proof); - const pub = unstringifyBigInts$8(_pub); + const proof = unstringifyBigInts$9(_proof); + const pub = unstringifyBigInts$9(_pub); let inputs = ""; for (let i=0; i. +*/ +const { unstringifyBigInts: unstringifyBigInts$8 } = utils; + +function cli_n(n) { + let nstr = n.toString(16); + return `0x${nstr}`; +} + +function sdk_n(n) { + let nstr = n.toString(10); + return `${nstr}n`; +} + +async function groth16ExportSophiaCalldata(_proof, _pub, type) { + const proof = unstringifyBigInts$8(_proof); + const pub = unstringifyBigInts$8(_pub); + + + let S; + + if (type == "cli") { + let inputs = ""; + for (let i=0; i. */ -const {unstringifyBigInts: unstringifyBigInts$b, stringifyBigInts: stringifyBigInts$4} = ffjavascript.utils; +const {unstringifyBigInts: unstringifyBigInts$c, stringifyBigInts: stringifyBigInts$4} = ffjavascript.utils; async function fflonkExportSolidityVerifier(vk, templates, logger) { if (logger) logger.info("FFLONK EXPORT SOLIDITY VERIFIER STARTED"); @@ -5562,7 +5577,7 @@ async function fflonkExportSolidityVerifier(vk, templates, logger) { return ejs__default["default"].render(template, vk); function fromVkey(str) { - const val = unstringifyBigInts$b(str); + const val = unstringifyBigInts$c(str); return curve.Fr.fromObject(val); } @@ -6062,10 +6077,10 @@ async function joinABC(curve, zkey, a, b, c, logger) { You should have received a copy of the GNU General Public License along with snarkJS. If not, see . */ -const { unstringifyBigInts: unstringifyBigInts$a} = ffjavascript.utils; +const { unstringifyBigInts: unstringifyBigInts$b} = ffjavascript.utils; async function wtnsCalculate$1(_input, wasmFileName, wtnsFileName, options) { - const input = unstringifyBigInts$a(_input); + const input = unstringifyBigInts$b(_input); const fdWasm = await fastFile__namespace.readExisting(wasmFileName); const wasm = await fdWasm.read(fdWasm.totalSize); @@ -6107,10 +6122,10 @@ async function wtnsCalculate$1(_input, wasmFileName, wtnsFileName, options) { You should have received a copy of the GNU General Public License along with snarkJS. If not, see . */ -const {unstringifyBigInts: unstringifyBigInts$9} = ffjavascript.utils; +const {unstringifyBigInts: unstringifyBigInts$a} = ffjavascript.utils; async function groth16FullProve$1(_input, wasmFile, zkeyFileName, logger) { - const input = unstringifyBigInts$9(_input); + const input = unstringifyBigInts$a(_input); const wtns= { type: "mem" @@ -6137,7 +6152,7 @@ async function groth16FullProve$1(_input, wasmFile, zkeyFileName, logger) { You should have received a copy of the GNU General Public License along with snarkjs. If not, see . */ -const {unstringifyBigInts: unstringifyBigInts$8} = ffjavascript.utils; +const {unstringifyBigInts: unstringifyBigInts$9} = ffjavascript.utils; async function groth16Verify$1(_vk_verifier, _publicSignals, _proof, logger) { /* @@ -6147,9 +6162,9 @@ async function groth16Verify$1(_vk_verifier, _publicSignals, _proof, logger) { } */ - const vk_verifier = unstringifyBigInts$8(_vk_verifier); - const proof = unstringifyBigInts$8(_proof); - const publicSignals = unstringifyBigInts$8(_publicSignals); + const vk_verifier = unstringifyBigInts$9(_vk_verifier); + const proof = unstringifyBigInts$9(_proof); + const publicSignals = unstringifyBigInts$9(_publicSignals); const curve = await getCurveFromName(vk_verifier.curve); @@ -6238,7 +6253,7 @@ function publicInputsAreValid$1(curve, publicInputs) { You should have received a copy of the GNU General Public License along with snarkJS. If not, see . */ -const { unstringifyBigInts: unstringifyBigInts$7} = ffjavascript.utils; +const { unstringifyBigInts: unstringifyBigInts$8} = ffjavascript.utils; function p256$2(n) { let nstr = n.toString(16); @@ -6248,8 +6263,8 @@ function p256$2(n) { } async function groth16ExportSolidityCallData(_proof, _pub) { - const proof = unstringifyBigInts$7(_proof); - const pub = unstringifyBigInts$7(_pub); + const proof = unstringifyBigInts$8(_proof); + const pub = unstringifyBigInts$8(_pub); let inputs = ""; for (let i=0; i. +*/ +const { unstringifyBigInts: unstringifyBigInts$7 } = ffjavascript.utils; + +function cli_n(n) { + let nstr = n.toString(16); + return `0x${nstr}`; +} + +function sdk_n(n) { + let nstr = n.toString(10); + return `${nstr}n`; +} + +async function groth16ExportSophiaCalldata(_proof, _pub, type) { + const proof = unstringifyBigInts$7(_proof); + const pub = unstringifyBigInts$7(_pub); + + + let S; + + if (type == "cli") { + let inputs = ""; + for (let i=0; i async function zkeyExportSolidityCalldata(params, options) { @@ -13131,6 +13282,40 @@ async function zkeyExportSolidityCalldata(params, options) { return 0; } +// sophia gencall +async function zkeyExportSophiaCalldata(params, options) { + let publicName; + let proofName; + + if (params.length < 1) { + publicName = "public.json"; + } else { + publicName = params[0]; + } + + if (params.length < 2) { + proofName = "proof.json"; + } else { + proofName = params[1]; + } + + let type = "sdk"; + if (options.cli) type = "cli"; + + const pub = JSON.parse(fs__default["default"].readFileSync(publicName, "utf8")); + const proof = JSON.parse(fs__default["default"].readFileSync(proofName, "utf8")); + + let res; + if (proof.protocol == "groth16") { + res = await groth16ExportSophiaCalldata(proof, pub, type); + } else { + throw new Error("Invalid Protocol"); + } + console.log(res); + + return 0; +} + // powersoftau new [powersoftau_0000.ptau]", async function powersOfTauNew(params, options) { let curveName; diff --git a/build/main.cjs b/build/main.cjs index deeb7fb5..d964980e 100644 --- a/build/main.cjs +++ b/build/main.cjs @@ -1245,10 +1245,10 @@ async function joinABC(curve, zkey, a, b, c, logger) { You should have received a copy of the GNU General Public License along with snarkJS. If not, see . */ -const { unstringifyBigInts: unstringifyBigInts$b} = ffjavascript.utils; +const { unstringifyBigInts: unstringifyBigInts$c} = ffjavascript.utils; async function wtnsCalculate(_input, wasmFileName, wtnsFileName, options) { - const input = unstringifyBigInts$b(_input); + const input = unstringifyBigInts$c(_input); const fdWasm = await fastFile__namespace.readExisting(wasmFileName); const wasm = await fdWasm.read(fdWasm.totalSize); @@ -1290,10 +1290,10 @@ async function wtnsCalculate(_input, wasmFileName, wtnsFileName, options) { You should have received a copy of the GNU General Public License along with snarkJS. If not, see . */ -const {unstringifyBigInts: unstringifyBigInts$a} = ffjavascript.utils; +const {unstringifyBigInts: unstringifyBigInts$b} = ffjavascript.utils; async function groth16FullProve(_input, wasmFile, zkeyFileName, logger) { - const input = unstringifyBigInts$a(_input); + const input = unstringifyBigInts$b(_input); const wtns= { type: "mem" @@ -1320,7 +1320,7 @@ async function groth16FullProve(_input, wasmFile, zkeyFileName, logger) { You should have received a copy of the GNU General Public License along with snarkjs. If not, see . */ -const {unstringifyBigInts: unstringifyBigInts$9} = ffjavascript.utils; +const {unstringifyBigInts: unstringifyBigInts$a} = ffjavascript.utils; async function groth16Verify(_vk_verifier, _publicSignals, _proof, logger) { /* @@ -1330,9 +1330,9 @@ async function groth16Verify(_vk_verifier, _publicSignals, _proof, logger) { } */ - const vk_verifier = unstringifyBigInts$9(_vk_verifier); - const proof = unstringifyBigInts$9(_proof); - const publicSignals = unstringifyBigInts$9(_publicSignals); + const vk_verifier = unstringifyBigInts$a(_vk_verifier); + const proof = unstringifyBigInts$a(_proof); + const publicSignals = unstringifyBigInts$a(_publicSignals); const curve = await getCurveFromName(vk_verifier.curve); @@ -1421,7 +1421,7 @@ function publicInputsAreValid$1(curve, publicInputs) { You should have received a copy of the GNU General Public License along with snarkJS. If not, see . */ -const { unstringifyBigInts: unstringifyBigInts$8} = ffjavascript.utils; +const { unstringifyBigInts: unstringifyBigInts$9} = ffjavascript.utils; function p256$2(n) { let nstr = n.toString(16); @@ -1431,8 +1431,8 @@ function p256$2(n) { } async function groth16ExportSolidityCallData(_proof, _pub) { - const proof = unstringifyBigInts$8(_proof); - const pub = unstringifyBigInts$8(_pub); + const proof = unstringifyBigInts$9(_proof); + const pub = unstringifyBigInts$9(_pub); let inputs = ""; for (let i=0; i. +*/ +const { unstringifyBigInts: unstringifyBigInts$8 } = ffjavascript.utils; + +function cli_n(n) { + let nstr = n.toString(16); + return `0x${nstr}`; +} + +function sdk_n(n) { + let nstr = n.toString(10); + return `${nstr}n`; +} + +async function groth16ExportSophiaCalldata(_proof, _pub, type) { + const proof = unstringifyBigInts$8(_proof); + const pub = unstringifyBigInts$8(_pub); + + + let S; + + if (type == "cli") { + let inputs = ""; + for (let i=0; i { - res[k] = unstringifyBigInts$c(o[k]); + res[k] = unstringifyBigInts$d(o[k]); }); return res; } else { @@ -12689,7 +12689,7 @@ var snarkjs = (function (exports) { log2: log2$4, stringifyBigInts: stringifyBigInts$5, stringifyFElements: stringifyFElements, - unstringifyBigInts: unstringifyBigInts$c, + unstringifyBigInts: unstringifyBigInts$d, unstringifyFElements: unstringifyFElements }); @@ -33846,10 +33846,10 @@ var snarkjs = (function (exports) { You should have received a copy of the GNU General Public License along with snarkJS. If not, see . */ - const { unstringifyBigInts: unstringifyBigInts$b} = utils$7; + const { unstringifyBigInts: unstringifyBigInts$c} = utils$7; async function wtnsCalculate(_input, wasmFileName, wtnsFileName, options) { - const input = unstringifyBigInts$b(_input); + const input = unstringifyBigInts$c(_input); const fdWasm = await readExisting(wasmFileName); const wasm = await fdWasm.read(fdWasm.totalSize); @@ -33891,10 +33891,10 @@ var snarkjs = (function (exports) { You should have received a copy of the GNU General Public License along with snarkJS. If not, see . */ - const {unstringifyBigInts: unstringifyBigInts$a} = utils$7; + const {unstringifyBigInts: unstringifyBigInts$b} = utils$7; async function groth16FullProve(_input, wasmFile, zkeyFileName, logger) { - const input = unstringifyBigInts$a(_input); + const input = unstringifyBigInts$b(_input); const wtns= { type: "mem" @@ -33921,7 +33921,7 @@ var snarkjs = (function (exports) { You should have received a copy of the GNU General Public License along with snarkjs. If not, see . */ - const {unstringifyBigInts: unstringifyBigInts$9} = utils$7; + const {unstringifyBigInts: unstringifyBigInts$a} = utils$7; async function groth16Verify(_vk_verifier, _publicSignals, _proof, logger) { /* @@ -33931,9 +33931,9 @@ var snarkjs = (function (exports) { } */ - const vk_verifier = unstringifyBigInts$9(_vk_verifier); - const proof = unstringifyBigInts$9(_proof); - const publicSignals = unstringifyBigInts$9(_publicSignals); + const vk_verifier = unstringifyBigInts$a(_vk_verifier); + const proof = unstringifyBigInts$a(_proof); + const publicSignals = unstringifyBigInts$a(_publicSignals); const curve = await getCurveFromName(vk_verifier.curve); @@ -34022,7 +34022,7 @@ var snarkjs = (function (exports) { You should have received a copy of the GNU General Public License along with snarkJS. If not, see . */ - const { unstringifyBigInts: unstringifyBigInts$8} = utils$7; + const { unstringifyBigInts: unstringifyBigInts$9} = utils$7; function p256$2(n) { let nstr = n.toString(16); @@ -34032,8 +34032,8 @@ var snarkjs = (function (exports) { } async function groth16ExportSolidityCallData(_proof, _pub) { - const proof = unstringifyBigInts$8(_proof); - const pub = unstringifyBigInts$8(_pub); + const proof = unstringifyBigInts$9(_proof); + const pub = unstringifyBigInts$9(_pub); let inputs = ""; for (let i=0; i. + */ + const { unstringifyBigInts: unstringifyBigInts$8 } = utils$7; + + function cli_n(n) { + let nstr = n.toString(16); + return `0x${nstr}`; + } + + function sdk_n(n) { + let nstr = n.toString(10); + return `${nstr}n`; + } + + async function groth16ExportSophiaCalldata(_proof, _pub, type) { + const proof = unstringifyBigInts$8(_proof); + const pub = unstringifyBigInts$8(_pub); + + + let S; + + if (type == "cli") { + let inputs = ""; + for (let i=0; i>BigInt(a)}const r=c,d=s;function u(t){return(BigInt(t)&BigInt(1))==BigInt(1)}function _(t){let a=BigInt(t);const e=[];for(;a;)a&BigInt(1)?e.push(1):e.push(0),a>>=BigInt(1);return e}function g(t){if(t>BigInt(Number.MAX_SAFE_INTEGER))throw new Error("Number too big");return Number(t)}function f(t,a){return BigInt(t)+BigInt(a)}function h(t,a){return BigInt(t)-BigInt(a)}function p(t){return-BigInt(t)}function m(t,a){return BigInt(t)*BigInt(a)}function L(t,a){return BigInt(t)**BigInt(a)}function b(t,a){return BigInt(t)/BigInt(a)}function w(t,a){return BigInt(t)%BigInt(a)}function y(t,a){return BigInt(t)==BigInt(a)}function A(t,a){return BigInt(t)>BigInt(a)}function C(t,a){return BigInt(t)>=BigInt(a)}function F(t,a){return BigInt(t)&BigInt(a)}function x(t,a,e,o){const i="0000000"+e.toString(16),n=new Uint32Array(t.buffer,t.byteOffset+a,o/4),l=1+(4*(i.length-7)-1>>5);for(let t=0;t>5);for(let t=0;tn[n.length-a-1]=t.toString(16).padStart(8,"0"))),e(n.join(""),16)}function E(t,a,o){o=o||t.byteLength,a=a||0;const i=new DataView(t.buffer,t.byteOffset+a,o),n=new Array(o/4);for(let t=0;t=0?BigInt(t):-BigInt(t)},add:f,band:F,bitLength:i,bits:_,bor:function(t,a){return BigInt(t)|BigInt(a)},bxor:function(t,a){return BigInt(t)^BigInt(a)},div:b,e:o,eq:y,exp:function(t,a){return BigInt(t)**BigInt(a)},fromArray:function(t,a){let e=BigInt(0);a=BigInt(a);for(let o=0;o>=BigInt(1)}return e},neg:p,neq:function(t,a){return BigInt(t)!=BigInt(a)},one:q,pow:L,shiftLeft:c,shiftRight:s,shl:r,shr:d,square:function(t){return BigInt(t)*BigInt(t)},sub:h,toArray:function(t,a){const e=[];let o=BigInt(t);for(a=BigInt(a);o;)e.unshift(Number(o%a)),o/=a;return e},toLEBuff:S,toNumber:g,toRprBE:I,toRprLE:x,toString:v,zero:P});function G(t,a,e){if(l(e))return t.one;const o=_(e);if(0==o.length)return t.one;let i=a;for(let e=o.length-2;e>=0;e--)i=t.square(i),o[e]&&(i=t.mul(i,a));return i}function z(t){if(t.m%2==1)if(y(w(t.p,4),1))if(y(w(t.p,8),1))if(y(w(t.p,16),1))!function(t){t.sqrt_q=L(t.p,t.m),t.sqrt_s=0,t.sqrt_t=h(t.sqrt_q,1);for(;!u(t.sqrt_t);)t.sqrt_s=t.sqrt_s+1,t.sqrt_t=b(t.sqrt_t,2);let a=t.one;for(;t.eq(a,t.one);){const e=t.random();t.sqrt_z=t.pow(e,t.sqrt_t),a=t.pow(t.sqrt_z,2**(t.sqrt_s-1))}t.sqrt_tm1d2=b(h(t.sqrt_t,1),2),t.sqrt=function(t){const a=this;if(a.isZero(t))return a.zero;let e=a.pow(t,a.sqrt_tm1d2);const o=a.pow(a.mul(a.square(e),t),2**(a.sqrt_s-1));if(a.eq(o,a.negone))return null;let i=a.sqrt_s,n=a.mul(t,e),l=a.mul(n,e),c=a.sqrt_z;for(;!a.eq(l,a.one);){let t=a.square(l),o=1;for(;!a.eq(t,a.one);)t=a.square(t),o++;e=c;for(let t=0;t>>0,t[i]=(t[i]^t[a])>>>0,t[i]=(t[i]<<16|t[i]>>>16&65535)>>>0,t[o]=t[o]+t[i]>>>0,t[e]=(t[e]^t[o])>>>0,t[e]=(t[e]<<12|t[e]>>>20&4095)>>>0,t[a]=t[a]+t[e]>>>0,t[i]=(t[i]^t[a])>>>0,t[i]=(t[i]<<8|t[i]>>>24&255)>>>0,t[o]=t[o]+t[i]>>>0,t[e]=(t[e]^t[o])>>>0,t[e]=(t[e]<<7|t[e]>>>25&127)>>>0}class M{constructor(t){t=t||[0,0,0,0,0,0,0,0],this.state=[1634760805,857760878,2036477234,1797285236,t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],0,0,0,0],this.idx=16,this.buff=new Array(16)}nextU32(){return 16==this.idx&&this.update(),this.buff[this.idx++]}nextU64(){return f(m(this.nextU32(),4294967296),this.nextU32())}nextBool(){return 1==(1&this.nextU32())}update(){for(let t=0;t<16;t++)this.buff[t]=this.state[t];for(let a=0;a<10;a++)T(t=this.buff,0,4,8,12),T(t,1,5,9,13),T(t,2,6,10,14),T(t,3,7,11,15),T(t,0,5,10,15),T(t,1,6,11,12),T(t,2,7,8,13),T(t,3,4,9,14);var t;for(let t=0;t<16;t++)this.buff[t]=this.buff[t]+this.state[t]>>>0;this.idx=0,this.state[12]=this.state[12]+1>>>0,0==this.state[12]&&(this.state[13]=this.state[13]+1>>>0,0==this.state[13]&&(this.state[14]=this.state[14]+1>>>0,0==this.state[14]&&(this.state[15]=this.state[15]+1>>>0)))}}function U(t){let a=new Uint8Array(t);if(void 0!==globalThis.crypto)globalThis.crypto.getRandomValues(a);else for(let e=0;e>>0;return a}let Q=null;function k(){return Q||(Q=new M(function(){const t=U(32),a=new Uint32Array(t.buffer),e=[];for(let t=0;t<8;t++)e.push(a[t]);return e}()),Q)}class R{constructor(t,a,e){this.F=a,this.G=t,this.opMulGF=e;let o=a.sqrt_t||a.t,i=a.sqrt_s||a.s,n=a.one;for(;a.eq(a.pow(n,a.half),a.one);)n=a.add(n,a.one);this.w=new Array(i+1),this.wi=new Array(i+1),this.w[i]=this.F.pow(n,o),this.wi[i]=this.F.inv(this.w[i]);let l=i-1;for(;l>=0;)this.w[l]=this.F.square(this.w[l+1]),this.wi[l]=this.F.square(this.wi[l+1]),l--;this.roots=[],this._setRoots(Math.min(i,15))}_setRoots(t){for(let a=t;a>=0&&!this.roots[a];a--){let t=this.F.one;const e=1<>1,c=D(t,a,e-1,o,2*i),s=D(t,a,e-1,o+i,2*i),r=new Array(n);for(let a=0;a>this.one,this.bitLength=i(this.p),this.mask=(this.one<>this.one;this.nqr=this.two;let e=this.pow(this.nqr,a);for(;!this.eq(e,this.negone);)this.nqr=this.nqr+this.one,e=this.pow(this.nqr,a);for(this.s=0,this.t=this.negone;(this.t&this.one)==this.zero;)this.s=this.s+1,this.t=this.t>>this.one;this.nqr_to_t=this.pow(this.nqr,this.t),z(this),this.FFT=new R(this,this,this.mul.bind(this)),this.fft=this.FFT.fft.bind(this.FFT),this.ifft=this.FFT.ifft.bind(this.FFT),this.w=this.FFT.w,this.wi=this.FFT.wi,this.shift=this.square(this.nqr),this.k=this.exp(this.nqr,2**this.s)}e(t,a){let e;if(a?16==a&&(e=BigInt("0x"+t)):e=BigInt(t),e<0){let t=-e;return t>=this.p&&(t%=this.p),this.p-t}return e>=this.p?e%this.p:e}add(t,a){const e=t+a;return e>=this.p?e-this.p:e}sub(t,a){return t>=a?t-a:this.p-a+t}neg(t){return t?this.p-t:t}mul(t,a){return t*a%this.p}mulScalar(t,a){return t*this.e(a)%this.p}square(t){return t*t%this.p}eq(t,a){return t==a}neq(t,a){return t!=a}lt(t,a){return(t>this.half?t-this.p:t)<(a>this.half?a-this.p:a)}gt(t,a){return(t>this.half?t-this.p:t)>(a>this.half?a-this.p:a)}leq(t,a){return(t>this.half?t-this.p:t)<=(a>this.half?a-this.p:a)}geq(t,a){return(t>this.half?t-this.p:t)>=(a>this.half?a-this.p:a)}div(t,a){return this.mul(t,this.inv(a))}idiv(t,a){if(!a)throw new Error("Division by zero");return t/a}inv(t){if(!t)throw new Error("Division by zero");let a=this.zero,e=this.p,o=this.one,i=t%this.p;for(;i;){let t=e/i;[a,o]=[o,a-t*o],[e,i]=[i,e-t*i]}return a=this.p?e-this.p:e}bor(t,a){const e=(t|a)&this.mask;return e>=this.p?e-this.p:e}bxor(t,a){const e=(t^a)&this.mask;return e>=this.p?e-this.p:e}bnot(t){const a=t^this.mask;return a>=this.p?a-this.p:a}shl(t,a){if(Number(a)=this.p?e-this.p:e}{const e=this.p-a;return Number(e)>e:this.zero}}shr(t,a){if(Number(a)>a;{const e=this.p-a;if(Number(e)=this.p?a-this.p:a}return 0}}land(t,a){return t&&a?this.one:this.zero}lor(t,a){return t||a?this.one:this.zero}lnot(t){return t?this.zero:this.one}sqrt_old(t){if(t==this.zero)return this.zero;if(this.pow(t,this.negone>>this.one)!=this.one)return null;let a=this.s,e=this.nqr_to_t,o=this.pow(t,this.t),i=this.pow(t,this.add(this.t,this.one)>>this.one);for(;o!=this.one;){let t=this.square(o),n=1;for(;t!=this.one;)n++,t=this.square(t);let l=e;for(let t=0;tthis.p>>this.one&&(i=this.neg(i)),i}normalize(t,a){if((t=BigInt(t,a))<0){let a=-t;return a>=this.p&&(a%=this.p),this.p-a}return t>=this.p?t%this.p:t}random(){const t=2*this.bitLength/8;let a=this.zero;for(let e=0;ethis.half&&10==a){e="-"+(this.p-t).toString(a)}else e=t.toString(a);return e}isZero(t){return t==this.zero}fromRng(t){let a;do{a=this.zero;for(let e=0;e=this.p);return a=a*this.Ri%this.p,a}fft(t){return this.FFT.fft(t)}ifft(t){return this.FFT.ifft(t)}toRprLE(t,a,e){x(t,a,e,8*this.n64)}toRprBE(t,a,e){I(t,a,e,8*this.n64)}toRprBEM(t,a,e){return this.toRprBE(t,a,this.mul(this.R,e))}toRprLEM(t,a,e){return this.toRprLE(t,a,this.mul(this.R,e))}fromRprLE(t,a){return B(t,a,this.n8)}fromRprBE(t,a){return E(t,a,this.n8)}fromRprLEM(t,a){return this.mul(this.fromRprLE(t,a),this.Ri)}fromRprBEM(t,a){return this.mul(this.fromRprBE(t,a),this.Ri)}toObject(t){return t}}function j(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var V={bigInt2BytesLE:function(t,a){const e=Array(a);let o=BigInt(t);for(let t=0;t>=8n;return e},bigInt2U32LE:function(t,a){const e=Array(a);let o=BigInt(t);for(let t=0;t>=32n;return e},isOcamNum:function(t){return!!Array.isArray(t)&&(3==t.length&&("number"==typeof t[0]&&("number"==typeof t[1]&&!!Array.isArray(t[2]))))}},K=function(t,a,e,o,i,n,l){const c=t.addFunction(a);c.addParam("base","i32"),c.addParam("scalar","i32"),c.addParam("scalarLength","i32"),c.addParam("r","i32"),c.addLocal("i","i32"),c.addLocal("b","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(e));c.addCode(s.if(s.i32_eqz(s.getLocal("scalarLength")),[...s.call(l,s.getLocal("r")),...s.ret([])])),c.addCode(s.call(n,s.getLocal("base"),r)),c.addCode(s.call(l,s.getLocal("r"))),c.addCode(s.setLocal("i",s.getLocal("scalarLength"))),c.addCode(s.block(s.loop(s.setLocal("i",s.i32_sub(s.getLocal("i"),s.i32_const(1))),s.setLocal("b",s.i32_load8_u(s.i32_add(s.getLocal("scalar"),s.getLocal("i")))),...function(){const t=[];for(let a=0;a<8;a++)t.push(...s.call(i,s.getLocal("r"),s.getLocal("r")),...s.if(s.i32_ge_u(s.getLocal("b"),s.i32_const(128>>a)),[...s.setLocal("b",s.i32_sub(s.getLocal("b"),s.i32_const(128>>a))),...s.call(o,s.getLocal("r"),r,s.getLocal("r"))]));return t}(),s.br_if(1,s.i32_eqz(s.getLocal("i"))),s.br(0))))},H=function(t,a){const e=8*t.modules[a].n64,o=t.addFunction(a+"_batchInverse");o.addParam("pIn","i32"),o.addParam("inStep","i32"),o.addParam("n","i32"),o.addParam("pOut","i32"),o.addParam("outStep","i32"),o.addLocal("itAux","i32"),o.addLocal("itIn","i32"),o.addLocal("itOut","i32"),o.addLocal("i","i32");const i=o.getCodeBuilder(),n=i.i32_const(t.alloc(e));o.addCode(i.setLocal("itAux",i.i32_load(i.i32_const(0))),i.i32_store(i.i32_const(0),i.i32_add(i.getLocal("itAux"),i.i32_mul(i.i32_add(i.getLocal("n"),i.i32_const(1)),i.i32_const(e))))),o.addCode(i.call(a+"_one",i.getLocal("itAux")),i.setLocal("itIn",i.getLocal("pIn")),i.setLocal("itAux",i.i32_add(i.getLocal("itAux"),i.i32_const(e))),i.setLocal("i",i.i32_const(0)),i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("i"),i.getLocal("n"))),i.if(i.call(a+"_isZero",i.getLocal("itIn")),i.call(a+"_copy",i.i32_sub(i.getLocal("itAux"),i.i32_const(e)),i.getLocal("itAux")),i.call(a+"_mul",i.getLocal("itIn"),i.i32_sub(i.getLocal("itAux"),i.i32_const(e)),i.getLocal("itAux"))),i.setLocal("itIn",i.i32_add(i.getLocal("itIn"),i.getLocal("inStep"))),i.setLocal("itAux",i.i32_add(i.getLocal("itAux"),i.i32_const(e))),i.setLocal("i",i.i32_add(i.getLocal("i"),i.i32_const(1))),i.br(0))),i.setLocal("itIn",i.i32_sub(i.getLocal("itIn"),i.getLocal("inStep"))),i.setLocal("itAux",i.i32_sub(i.getLocal("itAux"),i.i32_const(e))),i.setLocal("itOut",i.i32_add(i.getLocal("pOut"),i.i32_mul(i.i32_sub(i.getLocal("n"),i.i32_const(1)),i.getLocal("outStep")))),i.call(a+"_inverse",i.getLocal("itAux"),i.getLocal("itAux")),i.block(i.loop(i.br_if(1,i.i32_eqz(i.getLocal("i"))),i.if(i.call(a+"_isZero",i.getLocal("itIn")),[...i.call(a+"_copy",i.getLocal("itAux"),i.i32_sub(i.getLocal("itAux"),i.i32_const(e))),...i.call(a+"_zero",i.getLocal("itOut"))],[...i.call(a+"_copy",i.i32_sub(i.getLocal("itAux"),i.i32_const(e)),n),...i.call(a+"_mul",i.getLocal("itAux"),i.getLocal("itIn"),i.i32_sub(i.getLocal("itAux"),i.i32_const(e))),...i.call(a+"_mul",i.getLocal("itAux"),n,i.getLocal("itOut"))]),i.setLocal("itIn",i.i32_sub(i.getLocal("itIn"),i.getLocal("inStep"))),i.setLocal("itOut",i.i32_sub(i.getLocal("itOut"),i.getLocal("outStep"))),i.setLocal("itAux",i.i32_sub(i.getLocal("itAux"),i.i32_const(e))),i.setLocal("i",i.i32_sub(i.getLocal("i"),i.i32_const(1))),i.br(0)))),o.addCode(i.i32_store(i.i32_const(0),i.getLocal("itAux")))};var Z=function(t,a,e,o,i,n){void 0===n&&(n=oa?1:-1}function X(t){return t*t}function tt(t){return t%2n!==0n}function at(t){return t%2n===0n}function et(t){return t<0n}function ot(t){return t>0n}function it(t){return et(t)?t.toString(2).length-1:t.toString(2).length}function nt(t){return t<0n?-t:t}function lt(t){return 1n===nt(t)}function ct(t,a){for(var e,o,i,n=0n,l=1n,c=a,s=nt(t);0n!==s;)e=c/s,o=n,i=c,n=l,c=s,l=o-e*l,s=i-e*s;if(!lt(c))throw new Error(t.toString()+" and "+a.toString()+" are not co-prime");return-1===J(n,0n)&&(n+=a),et(t)?-n:n}function st(t,a,e){if(0n===e)throw new Error("Cannot take modPow with modulus 0");var o=1n,i=t%e;for(et(a)&&(a*=-1n,i=ct(i,e));ot(a);){if(0n===i)return 0n;tt(a)&&(o=o*i%e),a/=2n,i=X(i)%e}return o}function rt(t,a){return 0n!==a&&(!!lt(a)||(0===function(t,a){return(t=t>=0n?t:-t)===(a=a>=0n?a:-a)?0:t>a?1:-1}(a,2n)?at(t):t%a===0n))}function dt(t,a){for(var e,o,i,n=function(t){return t-1n}(t),l=n,c=0;at(l);)l/=2n,c++;t:for(o=0;o>1&&o>1,t>>1)))),a.addCode(e.setLocal(s,e.i64_add(e.getLocal(s),e.i64_shr_u(e.getLocal(c),e.i64_const(32)))))),t>0&&(a.addCode(e.setLocal(c,e.i64_add(e.i64_and(e.getLocal(c),e.i64_const(4294967295)),e.i64_and(e.getLocal(r),e.i64_const(4294967295))))),a.addCode(e.setLocal(s,e.i64_add(e.i64_add(e.getLocal(s),e.i64_shr_u(e.getLocal(c),e.i64_const(32))),e.getLocal(d))))),a.addCode(e.i64_store32(e.getLocal("r"),4*t,e.getLocal(c))),a.addCode(e.setLocal(r,e.getLocal(s)),e.setLocal(d,e.i64_shr_u(e.getLocal(r),e.i64_const(32))))}a.addCode(e.i64_store32(e.getLocal("r"),4*i*2-4,e.getLocal(r)))}(),function(){const a=t.addFunction(o+"_squareOld");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(o+"_mul",e.getLocal("x"),e.getLocal("x"),e.getLocal("r")))}(),function(){!function(){const a=t.addFunction(o+"__mul1");a.addParam("px","i32"),a.addParam("y","i64"),a.addParam("pr","i32"),a.addLocal("c","i64");const e=a.getCodeBuilder();a.addCode(e.setLocal("c",e.i64_mul(e.i64_load32_u(e.getLocal("px"),0,0),e.getLocal("y")))),a.addCode(e.i64_store32(e.getLocal("pr"),0,0,e.getLocal("c")));for(let t=1;t>1n,p=t.alloc(c,_t.bigInt2BytesLE(h,c)),m=h+1n,L=t.alloc(c,_t.bigInt2BytesLE(m,c));t.modules[s]={pq:d,pR2:u,n64:n,q:i,pOne:_,pZero:g,pePlusOne:L};let b=2n;if(wt(i))for(;bt(b,h,i)!==f;)b+=1n;let w=0,y=f;for(;!yt(y)&&0n!==y;)w++,y>>=1n;const A=t.alloc(c,_t.bigInt2BytesLE(y,c)),C=bt(b,y,i),F=t.alloc(_t.bigInt2BytesLE((C<>1n,I=t.alloc(c,_t.bigInt2BytesLE(x,c));return t.exportFunction(r+"_copy",s+"_copy"),t.exportFunction(r+"_zero",s+"_zero"),t.exportFunction(r+"_isZero",s+"_isZero"),t.exportFunction(r+"_eq",s+"_eq"),function(){const a=t.addFunction(s+"_isOne");a.addParam("x","i32"),a.setReturnType("i32");const e=a.getCodeBuilder();a.addCode(e.ret(e.call(r+"_eq",e.getLocal("x"),e.i32_const(_))))}(),function(){const a=t.addFunction(s+"_add");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.if(e.call(r+"_add",e.getLocal("x"),e.getLocal("y"),e.getLocal("r")),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))),e.if(e.call(r+"_gte",e.getLocal("r"),e.i32_const(d)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))))))}(),function(){const a=t.addFunction(s+"_sub");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.if(e.call(r+"_sub",e.getLocal("x"),e.getLocal("y"),e.getLocal("r")),e.drop(e.call(r+"_add",e.getLocal("r"),e.i32_const(d),e.getLocal("r")))))}(),function(){const a=t.addFunction(s+"_neg");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_sub",e.i32_const(g),e.getLocal("x"),e.getLocal("r")))}(),function(){const a=t.alloc(l*l*8),e=t.addFunction(s+"_mReduct");e.addParam("t","i32"),e.addParam("r","i32"),e.addLocal("np32","i64"),e.addLocal("c","i64"),e.addLocal("m","i64");const o=e.getCodeBuilder(),n=Number(0x100000000n-Lt(i,0x100000000n));e.addCode(o.setLocal("np32",o.i64_const(n)));for(let t=0;t=l&&a.addCode(e.i64_store32(e.getLocal("r"),4*(t-l),e.getLocal(f))),[f,h]=[h,f],a.addCode(e.setLocal(h,e.i64_shr_u(e.getLocal(f),e.i64_const(32))))}a.addCode(e.i64_store32(e.getLocal("r"),4*l-4,e.getLocal(f))),a.addCode(e.if(e.i32_wrap_i64(e.getLocal(h)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))),e.if(e.call(r+"_gte",e.getLocal("r"),e.i32_const(d)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))))))}(),function(){const a=t.addFunction(s+"_square");a.addParam("x","i32"),a.addParam("r","i32"),a.addLocal("c0","i64"),a.addLocal("c1","i64"),a.addLocal("c0_old","i64"),a.addLocal("c1_old","i64"),a.addLocal("np32","i64");for(let t=0;t>1&&o>1,t>>1)))),a.addCode(e.setLocal(f,e.i64_add(e.getLocal(f),e.i64_shr_u(e.getLocal(g),e.i64_const(32)))))),t>0&&(a.addCode(e.setLocal(g,e.i64_add(e.i64_and(e.getLocal(g),e.i64_const(4294967295)),e.i64_and(e.getLocal(h),e.i64_const(4294967295))))),a.addCode(e.setLocal(f,e.i64_add(e.i64_add(e.getLocal(f),e.i64_shr_u(e.getLocal(g),e.i64_const(32))),e.getLocal(p)))));for(let o=Math.max(1,t-l+1);o<=t&&o=l&&a.addCode(e.i64_store32(e.getLocal("r"),4*(t-l),e.getLocal(g))),a.addCode(e.setLocal(h,e.getLocal(f)),e.setLocal(p,e.i64_shr_u(e.getLocal(h),e.i64_const(32))))}a.addCode(e.i64_store32(e.getLocal("r"),4*l-4,e.getLocal(h))),a.addCode(e.if(e.i32_wrap_i64(e.getLocal(p)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))),e.if(e.call(r+"_gte",e.getLocal("r"),e.i32_const(d)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))))))}(),function(){const a=t.addFunction(s+"_squareOld");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_mul",e.getLocal("x"),e.getLocal("x"),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_toMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_mul",e.getLocal("x"),e.i32_const(u),e.getLocal("r")))}(),function(){const a=t.alloc(2*c),e=t.addFunction(s+"_fromMontgomery");e.addParam("x","i32"),e.addParam("r","i32");const o=e.getCodeBuilder();e.addCode(o.call(r+"_copy",o.getLocal("x"),o.i32_const(a))),e.addCode(o.call(r+"_zero",o.i32_const(a+c))),e.addCode(o.call(s+"_mReduct",o.i32_const(a),o.getLocal("r")))}(),function(){const a=t.addFunction(s+"_isNegative");a.addParam("x","i32"),a.setReturnType("i32");const e=a.getCodeBuilder(),o=e.i32_const(t.alloc(c));a.addCode(e.call(s+"_fromMontgomery",e.getLocal("x"),o),e.call(r+"_gte",o,e.i32_const(L)))}(),function(){const a=t.addFunction(s+"_sign");a.addParam("x","i32"),a.setReturnType("i32");const e=a.getCodeBuilder(),o=e.i32_const(t.alloc(c));a.addCode(e.if(e.call(r+"_isZero",e.getLocal("x")),e.ret(e.i32_const(0))),e.call(s+"_fromMontgomery",e.getLocal("x"),o),e.if(e.call(r+"_gte",o,e.i32_const(L)),e.ret(e.i32_const(-1))),e.ret(e.i32_const(1)))}(),function(){const a=t.addFunction(s+"_inverse");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_fromMontgomery",e.getLocal("x"),e.getLocal("r"))),a.addCode(e.call(r+"_inverseMod",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))),a.addCode(e.call(s+"_toMontgomery",e.getLocal("r"),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_one");a.addParam("pr","i32");const e=a.getCodeBuilder();a.addCode(e.call(r+"_copy",e.i32_const(_),e.getLocal("pr")))}(),function(){const a=t.addFunction(s+"_load");a.addParam("scalar","i32"),a.addParam("scalarLen","i32"),a.addParam("r","i32"),a.addLocal("p","i32"),a.addLocal("l","i32"),a.addLocal("i","i32"),a.addLocal("j","i32");const e=a.getCodeBuilder(),o=e.i32_const(t.alloc(c)),i=t.alloc(c),n=e.i32_const(i);a.addCode(e.call(r+"_zero",e.getLocal("r")),e.setLocal("i",e.i32_const(c)),e.setLocal("p",e.getLocal("scalar")),e.block(e.loop(e.br_if(1,e.i32_gt_u(e.getLocal("i"),e.getLocal("scalarLen"))),e.if(e.i32_eq(e.getLocal("i"),e.i32_const(c)),e.call(s+"_one",o),e.call(s+"_mul",o,e.i32_const(u),o)),e.call(s+"_mul",e.getLocal("p"),o,n),e.call(s+"_add",e.getLocal("r"),n,e.getLocal("r")),e.setLocal("p",e.i32_add(e.getLocal("p"),e.i32_const(c))),e.setLocal("i",e.i32_add(e.getLocal("i"),e.i32_const(c))),e.br(0))),e.setLocal("l",e.i32_rem_u(e.getLocal("scalarLen"),e.i32_const(c))),e.if(e.i32_eqz(e.getLocal("l")),e.ret([])),e.call(r+"_zero",n),e.setLocal("j",e.i32_const(0)),e.block(e.loop(e.br_if(1,e.i32_eq(e.getLocal("j"),e.getLocal("l"))),e.i32_store8(e.getLocal("j"),i,e.i32_load8_u(e.getLocal("p"))),e.setLocal("p",e.i32_add(e.getLocal("p"),e.i32_const(1))),e.setLocal("j",e.i32_add(e.getLocal("j"),e.i32_const(1))),e.br(0))),e.if(e.i32_eq(e.getLocal("i"),e.i32_const(c)),e.call(s+"_one",o),e.call(s+"_mul",o,e.i32_const(u),o)),e.call(s+"_mul",n,o,n),e.call(s+"_add",e.getLocal("r"),n,e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_timesScalar");a.addParam("x","i32"),a.addParam("scalar","i32"),a.addParam("scalarLen","i32"),a.addParam("r","i32");const e=a.getCodeBuilder(),o=e.i32_const(t.alloc(c));a.addCode(e.call(s+"_load",e.getLocal("scalar"),e.getLocal("scalarLen"),o),e.call(s+"_toMontgomery",o,o),e.call(s+"_mul",e.getLocal("x"),o,e.getLocal("r")))}(),ft(t,s),ht(t,s+"_batchToMontgomery",s+"_toMontgomery",c,c),ht(t,s+"_batchFromMontgomery",s+"_fromMontgomery",c,c),ht(t,s+"_batchNeg",s+"_neg",c,c),pt(t,s+"_batchAdd",s+"_add",c,c),pt(t,s+"_batchSub",s+"_sub",c,c),pt(t,s+"_batchMul",s+"_mul",c,c),t.exportFunction(s+"_add"),t.exportFunction(s+"_sub"),t.exportFunction(s+"_neg"),t.exportFunction(s+"_isNegative"),t.exportFunction(s+"_isOne"),t.exportFunction(s+"_sign"),t.exportFunction(s+"_mReduct"),t.exportFunction(s+"_mul"),t.exportFunction(s+"_square"),t.exportFunction(s+"_squareOld"),t.exportFunction(s+"_fromMontgomery"),t.exportFunction(s+"_toMontgomery"),t.exportFunction(s+"_inverse"),t.exportFunction(s+"_one"),t.exportFunction(s+"_load"),t.exportFunction(s+"_timesScalar"),gt(t,s+"_exp",c,s+"_mul",s+"_square",r+"_copy",s+"_one"),t.exportFunction(s+"_exp"),t.exportFunction(s+"_batchInverse"),wt(i)&&(!function(){const a=t.addFunction(s+"_sqrt");a.addParam("n","i32"),a.addParam("r","i32"),a.addLocal("m","i32"),a.addLocal("i","i32"),a.addLocal("j","i32");const e=a.getCodeBuilder(),o=e.i32_const(_),i=e.i32_const(t.alloc(c)),n=e.i32_const(t.alloc(c)),l=e.i32_const(t.alloc(c)),r=e.i32_const(t.alloc(c)),d=e.i32_const(t.alloc(c));a.addCode(e.if(e.call(s+"_isZero",e.getLocal("n")),e.ret(e.call(s+"_zero",e.getLocal("r")))),e.setLocal("m",e.i32_const(w)),e.call(s+"_copy",e.i32_const(F),i),e.call(s+"_exp",e.getLocal("n"),e.i32_const(A),e.i32_const(c),n),e.call(s+"_exp",e.getLocal("n"),e.i32_const(I),e.i32_const(c),l),e.block(e.loop(e.br_if(1,e.call(s+"_eq",n,o)),e.call(s+"_square",n,r),e.setLocal("i",e.i32_const(1)),e.block(e.loop(e.br_if(1,e.call(s+"_eq",r,o)),e.call(s+"_square",r,r),e.setLocal("i",e.i32_add(e.getLocal("i"),e.i32_const(1))),e.br(0))),e.call(s+"_copy",i,d),e.setLocal("j",e.i32_sub(e.i32_sub(e.getLocal("m"),e.getLocal("i")),e.i32_const(1))),e.block(e.loop(e.br_if(1,e.i32_eqz(e.getLocal("j"))),e.call(s+"_square",d,d),e.setLocal("j",e.i32_sub(e.getLocal("j"),e.i32_const(1))),e.br(0))),e.setLocal("m",e.getLocal("i")),e.call(s+"_square",d,i),e.call(s+"_mul",n,i,n),e.call(s+"_mul",l,d,l),e.br(0))),e.if(e.call(s+"_isNegative",l),e.call(s+"_neg",l,e.getLocal("r")),e.call(s+"_copy",l,e.getLocal("r"))))}(),function(){const a=t.addFunction(s+"_isSquare");a.addParam("n","i32"),a.setReturnType("i32");const e=a.getCodeBuilder(),o=e.i32_const(_),i=e.i32_const(t.alloc(c));a.addCode(e.if(e.call(s+"_isZero",e.getLocal("n")),e.ret(e.i32_const(1))),e.call(s+"_exp",e.getLocal("n"),e.i32_const(p),e.i32_const(c),i),e.call(s+"_eq",i,o))}(),t.exportFunction(s+"_sqrt"),t.exportFunction(s+"_isSquare")),t.exportFunction(s+"_batchToMontgomery"),t.exportFunction(s+"_batchFromMontgomery"),s};const Ft=Ct,{bitLength:xt}=Y;var It=function(t,a,e,o,i){const n=BigInt(a),l=Math.floor((xt(n-1n)-1)/64)+1,c=8*l,s=e||"f1";if(t.modules[s])return s;t.modules[s]={n64:l};const r=i||"int",d=Ft(t,n,o,r),u=t.modules[d].pR2,_=t.modules[d].pq,g=t.modules[d].pePlusOne;return function(){const a=t.alloc(c),e=t.addFunction(s+"_mul");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32");const o=e.getCodeBuilder();e.addCode(o.call(d+"_mul",o.getLocal("x"),o.getLocal("y"),o.i32_const(a))),e.addCode(o.call(d+"_mul",o.i32_const(a),o.i32_const(u),o.getLocal("r")))}(),function(){const a=t.addFunction(s+"_square");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_mul",e.getLocal("x"),e.getLocal("x"),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_inverse");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(r+"_inverseMod",e.getLocal("x"),e.i32_const(_),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_isNegative");a.addParam("x","i32"),a.setReturnType("i32");const e=a.getCodeBuilder();a.addCode(e.call(r+"_gte",e.getLocal("x"),e.i32_const(g)))}(),t.exportFunction(d+"_add",s+"_add"),t.exportFunction(d+"_sub",s+"_sub"),t.exportFunction(d+"_neg",s+"_neg"),t.exportFunction(s+"_mul"),t.exportFunction(s+"_square"),t.exportFunction(s+"_inverse"),t.exportFunction(s+"_isNegative"),t.exportFunction(d+"_copy",s+"_copy"),t.exportFunction(d+"_zero",s+"_zero"),t.exportFunction(d+"_one",s+"_one"),t.exportFunction(d+"_isZero",s+"_isZero"),t.exportFunction(d+"_eq",s+"_eq"),s};const Bt=K,Et=H,vt=V;var St=function(t,a,e,o){if(t.modules[e])return e;const i=8*t.modules[o].n64,n=t.modules[o].q;return t.modules[e]={n64:2*t.modules[o].n64},function(){const a=t.addFunction(e+"_isZero");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.i32_and(n.call(o+"_isZero",l),n.call(o+"_isZero",c)))}(),function(){const a=t.addFunction(e+"_isOne");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.ret(n.i32_and(n.call(o+"_isOne",l),n.call(o+"_isZero",c))))}(),function(){const a=t.addFunction(e+"_zero");a.addParam("x","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.call(o+"_zero",l),n.call(o+"_zero",c))}(),function(){const a=t.addFunction(e+"_one");a.addParam("x","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.call(o+"_one",l),n.call(o+"_zero",c))}(),function(){const a=t.addFunction(e+"_copy");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_copy",l,s),n.call(o+"_copy",c,r))}(),function(){const n=t.addFunction(e+"_mul");n.addParam("x","i32"),n.addParam("y","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.getLocal("y"),d=l.i32_add(l.getLocal("y"),l.i32_const(i)),u=l.getLocal("r"),_=l.i32_add(l.getLocal("r"),l.i32_const(i)),g=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i)),h=l.i32_const(t.alloc(i)),p=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_mul",c,r,g),l.call(o+"_mul",s,d,f),l.call(o+"_add",c,s,h),l.call(o+"_add",r,d,p),l.call(o+"_mul",h,p,h),l.call(a,f,u),l.call(o+"_add",g,u,u),l.call(o+"_add",g,f,_),l.call(o+"_sub",h,_,_))}(),function(){const a=t.addFunction(e+"_mul1");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("y"),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_mul",l,s,r),n.call(o+"_mul",c,s,d))}(),function(){const n=t.addFunction(e+"_square");n.addParam("x","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.getLocal("r"),d=l.i32_add(l.getLocal("r"),l.i32_const(i)),u=l.i32_const(t.alloc(i)),_=l.i32_const(t.alloc(i)),g=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_mul",c,s,u),l.call(o+"_add",c,s,_),l.call(a,s,g),l.call(o+"_add",c,g,g),l.call(a,u,f),l.call(o+"_add",f,u,f),l.call(o+"_mul",_,g,r),l.call(o+"_sub",r,f,r),l.call(o+"_add",u,u,d))}(),function(){const a=t.addFunction(e+"_add");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("y"),r=n.i32_add(n.getLocal("y"),n.i32_const(i)),d=n.getLocal("r"),u=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_add",l,s,d),n.call(o+"_add",c,r,u))}(),function(){const a=t.addFunction(e+"_sub");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("y"),r=n.i32_add(n.getLocal("y"),n.i32_const(i)),d=n.getLocal("r"),u=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_sub",l,s,d),n.call(o+"_sub",c,r,u))}(),function(){const a=t.addFunction(e+"_neg");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_neg",l,s),n.call(o+"_neg",c,r))}(),function(){const a=t.addFunction(e+"_conjugate");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_copy",l,s),n.call(o+"_neg",c,r))}(),function(){const a=t.addFunction(e+"_toMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_toMontgomery",l,s),n.call(o+"_toMontgomery",c,r))}(),function(){const a=t.addFunction(e+"_fromMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_fromMontgomery",l,s),n.call(o+"_fromMontgomery",c,r))}(),function(){const a=t.addFunction(e+"_eq");a.addParam("x","i32"),a.addParam("y","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("y"),r=n.i32_add(n.getLocal("y"),n.i32_const(i));a.addCode(n.i32_and(n.call(o+"_eq",l,s),n.call(o+"_eq",c,r)))}(),function(){const n=t.addFunction(e+"_inverse");n.addParam("x","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.getLocal("r"),d=l.i32_add(l.getLocal("r"),l.i32_const(i)),u=l.i32_const(t.alloc(i)),_=l.i32_const(t.alloc(i)),g=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_square",c,u),l.call(o+"_square",s,_),l.call(a,_,g),l.call(o+"_sub",u,g,g),l.call(o+"_inverse",g,f),l.call(o+"_mul",c,f,r),l.call(o+"_mul",s,f,d),l.call(o+"_neg",d,d))}(),function(){const a=t.addFunction(e+"_timesScalar");a.addParam("x","i32"),a.addParam("scalar","i32"),a.addParam("scalarLen","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_timesScalar",l,n.getLocal("scalar"),n.getLocal("scalarLen"),s),n.call(o+"_timesScalar",c,n.getLocal("scalar"),n.getLocal("scalarLen"),r))}(),function(){const a=t.addFunction(e+"_sign");a.addParam("x","i32"),a.addLocal("s","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.setLocal("s",n.call(o+"_sign",c)),n.if(n.getLocal("s"),n.ret(n.getLocal("s"))),n.ret(n.call(o+"_sign",l)))}(),function(){const a=t.addFunction(e+"_isNegative");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.if(n.call(o+"_isZero",c),n.ret(n.call(o+"_isNegative",l))),n.ret(n.call(o+"_isNegative",c)))}(),t.exportFunction(e+"_isZero"),t.exportFunction(e+"_isOne"),t.exportFunction(e+"_zero"),t.exportFunction(e+"_one"),t.exportFunction(e+"_copy"),t.exportFunction(e+"_mul"),t.exportFunction(e+"_mul1"),t.exportFunction(e+"_square"),t.exportFunction(e+"_add"),t.exportFunction(e+"_sub"),t.exportFunction(e+"_neg"),t.exportFunction(e+"_sign"),t.exportFunction(e+"_conjugate"),t.exportFunction(e+"_fromMontgomery"),t.exportFunction(e+"_toMontgomery"),t.exportFunction(e+"_eq"),t.exportFunction(e+"_inverse"),Et(t,e),Bt(t,e+"_exp",2*i,e+"_mul",e+"_square",e+"_copy",e+"_one"),function(){const a=t.addFunction(e+"_sqrt");a.addParam("a","i32"),a.addParam("pr","i32");const l=a.getCodeBuilder(),c=l.i32_const(t.alloc(vt.bigInt2BytesLE((BigInt(n||0)-3n)/4n,i))),s=l.i32_const(t.alloc(vt.bigInt2BytesLE((BigInt(n||0)-1n)/2n,i))),r=l.getLocal("a"),d=l.i32_const(t.alloc(2*i)),u=l.i32_const(t.alloc(2*i)),_=l.i32_const(t.alloc(2*i)),g=t.alloc(2*i),f=l.i32_const(g),h=l.i32_const(g),p=l.i32_const(g+i),m=l.i32_const(t.alloc(2*i)),L=l.i32_const(t.alloc(2*i));a.addCode(l.call(e+"_one",f),l.call(e+"_neg",f,f),l.call(e+"_exp",r,c,l.i32_const(i),d),l.call(e+"_square",d,u),l.call(e+"_mul",r,u,u),l.call(e+"_conjugate",u,_),l.call(e+"_mul",_,u,_),l.if(l.call(e+"_eq",_,f),l.unreachable()),l.call(e+"_mul",d,r,m),l.if(l.call(e+"_eq",u,f),[...l.call(o+"_zero",h),...l.call(o+"_one",p),...l.call(e+"_mul",f,m,l.getLocal("pr"))],[...l.call(e+"_one",L),...l.call(e+"_add",L,u,L),...l.call(e+"_exp",L,s,l.i32_const(i),L),...l.call(e+"_mul",L,m,l.getLocal("pr"))]))}(),function(){const a=t.addFunction(e+"_isSquare");a.addParam("a","i32"),a.setReturnType("i32");const o=a.getCodeBuilder(),l=o.i32_const(t.alloc(vt.bigInt2BytesLE((BigInt(n||0)-3n)/4n,i))),c=o.getLocal("a"),s=o.i32_const(t.alloc(2*i)),r=o.i32_const(t.alloc(2*i)),d=o.i32_const(t.alloc(2*i)),u=t.alloc(2*i),_=o.i32_const(u);a.addCode(o.call(e+"_one",_),o.call(e+"_neg",_,_),o.call(e+"_exp",c,l,o.i32_const(i),s),o.call(e+"_square",s,r),o.call(e+"_mul",c,r,r),o.call(e+"_conjugate",r,d),o.call(e+"_mul",d,r,d),o.if(o.call(e+"_eq",d,_),o.ret(o.i32_const(0))),o.ret(o.i32_const(1)))}(),t.exportFunction(e+"_exp"),t.exportFunction(e+"_timesScalar"),t.exportFunction(e+"_batchInverse"),t.exportFunction(e+"_sqrt"),t.exportFunction(e+"_isSquare"),t.exportFunction(e+"_isNegative"),e};const Pt=K,qt=H;var Ot=function(t,a,e,o){if(t.modules[e])return e;const i=8*t.modules[o].n64;return t.modules[e]={n64:3*t.modules[o].n64},function(){const a=t.addFunction(e+"_isZero");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.i32_and(n.i32_and(n.call(o+"_isZero",l),n.call(o+"_isZero",c)),n.call(o+"_isZero",s)))}(),function(){const a=t.addFunction(e+"_isOne");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.ret(n.i32_and(n.i32_and(n.call(o+"_isOne",l),n.call(o+"_isZero",c)),n.call(o+"_isZero",s))))}(),function(){const a=t.addFunction(e+"_zero");a.addParam("x","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.call(o+"_zero",l),n.call(o+"_zero",c),n.call(o+"_zero",s))}(),function(){const a=t.addFunction(e+"_one");a.addParam("x","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.call(o+"_one",l),n.call(o+"_zero",c),n.call(o+"_zero",s))}(),function(){const a=t.addFunction(e+"_copy");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_copy",l,r),n.call(o+"_copy",c,d),n.call(o+"_copy",s,u))}(),function(){const n=t.addFunction(e+"_mul");n.addParam("x","i32"),n.addParam("y","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.i32_add(l.getLocal("x"),l.i32_const(2*i)),d=l.getLocal("y"),u=l.i32_add(l.getLocal("y"),l.i32_const(i)),_=l.i32_add(l.getLocal("y"),l.i32_const(2*i)),g=l.getLocal("r"),f=l.i32_add(l.getLocal("r"),l.i32_const(i)),h=l.i32_add(l.getLocal("r"),l.i32_const(2*i)),p=l.i32_const(t.alloc(i)),m=l.i32_const(t.alloc(i)),L=l.i32_const(t.alloc(i)),b=l.i32_const(t.alloc(i)),w=l.i32_const(t.alloc(i)),y=l.i32_const(t.alloc(i)),A=l.i32_const(t.alloc(i)),C=l.i32_const(t.alloc(i)),F=l.i32_const(t.alloc(i)),x=l.i32_const(t.alloc(i)),I=l.i32_const(t.alloc(i)),B=l.i32_const(t.alloc(i)),E=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_mul",c,d,p),l.call(o+"_mul",s,u,m),l.call(o+"_mul",r,_,L),l.call(o+"_add",c,s,b),l.call(o+"_add",d,u,w),l.call(o+"_add",c,r,y),l.call(o+"_add",d,_,A),l.call(o+"_add",s,r,C),l.call(o+"_add",u,_,F),l.call(o+"_add",p,m,x),l.call(o+"_add",p,L,I),l.call(o+"_add",m,L,B),l.call(o+"_mul",C,F,g),l.call(o+"_sub",g,B,g),l.call(a,g,g),l.call(o+"_add",p,g,g),l.call(o+"_mul",b,w,f),l.call(o+"_sub",f,x,f),l.call(a,L,E),l.call(o+"_add",f,E,f),l.call(o+"_mul",y,A,h),l.call(o+"_sub",h,I,h),l.call(o+"_add",h,m,h))}(),function(){const n=t.addFunction(e+"_square");n.addParam("x","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.i32_add(l.getLocal("x"),l.i32_const(2*i)),d=l.getLocal("r"),u=l.i32_add(l.getLocal("r"),l.i32_const(i)),_=l.i32_add(l.getLocal("r"),l.i32_const(2*i)),g=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i)),h=l.i32_const(t.alloc(i)),p=l.i32_const(t.alloc(i)),m=l.i32_const(t.alloc(i)),L=l.i32_const(t.alloc(i)),b=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_square",c,g),l.call(o+"_mul",c,s,f),l.call(o+"_add",f,f,h),l.call(o+"_sub",c,s,p),l.call(o+"_add",p,r,p),l.call(o+"_square",p,p),l.call(o+"_mul",s,r,m),l.call(o+"_add",m,m,L),l.call(o+"_square",r,b),l.call(a,L,d),l.call(o+"_add",g,d,d),l.call(a,b,u),l.call(o+"_add",h,u,u),l.call(o+"_add",g,b,_),l.call(o+"_sub",L,_,_),l.call(o+"_add",p,_,_),l.call(o+"_add",h,_,_))}(),function(){const a=t.addFunction(e+"_add");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("y"),d=n.i32_add(n.getLocal("y"),n.i32_const(i)),u=n.i32_add(n.getLocal("y"),n.i32_const(2*i)),_=n.getLocal("r"),g=n.i32_add(n.getLocal("r"),n.i32_const(i)),f=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_add",l,r,_),n.call(o+"_add",c,d,g),n.call(o+"_add",s,u,f))}(),function(){const a=t.addFunction(e+"_sub");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("y"),d=n.i32_add(n.getLocal("y"),n.i32_const(i)),u=n.i32_add(n.getLocal("y"),n.i32_const(2*i)),_=n.getLocal("r"),g=n.i32_add(n.getLocal("r"),n.i32_const(i)),f=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_sub",l,r,_),n.call(o+"_sub",c,d,g),n.call(o+"_sub",s,u,f))}(),function(){const a=t.addFunction(e+"_neg");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_neg",l,r),n.call(o+"_neg",c,d),n.call(o+"_neg",s,u))}(),function(){const a=t.addFunction(e+"_sign");a.addParam("x","i32"),a.addLocal("s","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.setLocal("s",n.call(o+"_sign",s)),n.if(n.getLocal("s"),n.ret(n.getLocal("s"))),n.setLocal("s",n.call(o+"_sign",c)),n.if(n.getLocal("s"),n.ret(n.getLocal("s"))),n.ret(n.call(o+"_sign",l)))}(),function(){const a=t.addFunction(e+"_toMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_toMontgomery",l,r),n.call(o+"_toMontgomery",c,d),n.call(o+"_toMontgomery",s,u))}(),function(){const a=t.addFunction(e+"_fromMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_fromMontgomery",l,r),n.call(o+"_fromMontgomery",c,d),n.call(o+"_fromMontgomery",s,u))}(),function(){const a=t.addFunction(e+"_eq");a.addParam("x","i32"),a.addParam("y","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("y"),d=n.i32_add(n.getLocal("y"),n.i32_const(i)),u=n.i32_add(n.getLocal("y"),n.i32_const(2*i));a.addCode(n.i32_and(n.i32_and(n.call(o+"_eq",l,r),n.call(o+"_eq",c,d)),n.call(o+"_eq",s,u)))}(),function(){const n=t.addFunction(e+"_inverse");n.addParam("x","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.i32_add(l.getLocal("x"),l.i32_const(2*i)),d=l.getLocal("r"),u=l.i32_add(l.getLocal("r"),l.i32_const(i)),_=l.i32_add(l.getLocal("r"),l.i32_const(2*i)),g=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i)),h=l.i32_const(t.alloc(i)),p=l.i32_const(t.alloc(i)),m=l.i32_const(t.alloc(i)),L=l.i32_const(t.alloc(i)),b=l.i32_const(t.alloc(i)),w=l.i32_const(t.alloc(i)),y=l.i32_const(t.alloc(i)),A=l.i32_const(t.alloc(i)),C=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_square",c,g),l.call(o+"_square",s,f),l.call(o+"_square",r,h),l.call(o+"_mul",c,s,p),l.call(o+"_mul",c,r,m),l.call(o+"_mul",s,r,L),l.call(a,L,b),l.call(o+"_sub",g,b,b),l.call(a,h,w),l.call(o+"_sub",w,p,w),l.call(o+"_sub",f,m,y),l.call(o+"_mul",r,w,A),l.call(o+"_mul",s,y,C),l.call(o+"_add",A,C,A),l.call(a,A,A),l.call(o+"_mul",c,b,C),l.call(o+"_add",C,A,A),l.call(o+"_inverse",A,A),l.call(o+"_mul",A,b,d),l.call(o+"_mul",A,w,u),l.call(o+"_mul",A,y,_))}(),function(){const a=t.addFunction(e+"_timesScalar");a.addParam("x","i32"),a.addParam("scalar","i32"),a.addParam("scalarLen","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_timesScalar",l,n.getLocal("scalar"),n.getLocal("scalarLen"),r),n.call(o+"_timesScalar",c,n.getLocal("scalar"),n.getLocal("scalarLen"),d),n.call(o+"_timesScalar",s,n.getLocal("scalar"),n.getLocal("scalarLen"),u))}(),function(){const a=t.addFunction(e+"_isNegative");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.if(n.call(o+"_isZero",s),n.if(n.call(o+"_isZero",c),n.ret(n.call(o+"_isNegative",l)),n.ret(n.call(o+"_isNegative",c)))),n.ret(n.call(o+"_isNegative",s)))}(),t.exportFunction(e+"_isZero"),t.exportFunction(e+"_isOne"),t.exportFunction(e+"_zero"),t.exportFunction(e+"_one"),t.exportFunction(e+"_copy"),t.exportFunction(e+"_mul"),t.exportFunction(e+"_square"),t.exportFunction(e+"_add"),t.exportFunction(e+"_sub"),t.exportFunction(e+"_neg"),t.exportFunction(e+"_sign"),t.exportFunction(e+"_fromMontgomery"),t.exportFunction(e+"_toMontgomery"),t.exportFunction(e+"_eq"),t.exportFunction(e+"_inverse"),qt(t,e),Pt(t,e+"_exp",3*i,e+"_mul",e+"_square",e+"_copy",e+"_one"),t.exportFunction(e+"_exp"),t.exportFunction(e+"_timesScalar"),t.exportFunction(e+"_batchInverse"),t.exportFunction(e+"_isNegative"),e};const Gt=function(t,a,e,o,i,n,l,c){const s=t.addFunction(a);s.addParam("base","i32"),s.addParam("scalar","i32"),s.addParam("scalarLength","i32"),s.addParam("r","i32"),s.addLocal("old0","i32"),s.addLocal("nbits","i32"),s.addLocal("i","i32"),s.addLocal("last","i32"),s.addLocal("cur","i32"),s.addLocal("carry","i32"),s.addLocal("p","i32");const r=s.getCodeBuilder(),d=r.i32_const(t.alloc(e));function u(t){return r.i32_and(r.i32_shr_u(r.i32_load(r.i32_add(r.getLocal("scalar"),r.i32_and(r.i32_shr_u(t,r.i32_const(3)),r.i32_const(4294967292)))),r.i32_and(t,r.i32_const(31))),r.i32_const(1))}function _(t){return[...r.i32_store8(r.getLocal("p"),r.i32_const(t)),...r.setLocal("p",r.i32_add(r.getLocal("p"),r.i32_const(1)))]}s.addCode(r.if(r.i32_eqz(r.getLocal("scalarLength")),[...r.call(c,r.getLocal("r")),...r.ret([])]),r.setLocal("nbits",r.i32_shl(r.getLocal("scalarLength"),r.i32_const(3))),r.setLocal("old0",r.i32_load(r.i32_const(0))),r.setLocal("p",r.getLocal("old0")),r.i32_store(r.i32_const(0),r.i32_and(r.i32_add(r.i32_add(r.getLocal("old0"),r.i32_const(32)),r.getLocal("nbits")),r.i32_const(4294967288))),r.setLocal("i",r.i32_const(1)),r.setLocal("last",u(r.i32_const(0))),r.setLocal("carry",r.i32_const(0)),r.block(r.loop(r.br_if(1,r.i32_eq(r.getLocal("i"),r.getLocal("nbits"))),r.setLocal("cur",u(r.getLocal("i"))),r.if(r.getLocal("last"),r.if(r.getLocal("cur"),r.if(r.getLocal("carry"),[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(1)),..._(1)],[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(1)),..._(255)]),r.if(r.getLocal("carry"),[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(1)),..._(255)],[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(0)),..._(1)])),r.if(r.getLocal("cur"),r.if(r.getLocal("carry"),[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(1)),..._(0)],[...r.setLocal("last",r.i32_const(1)),...r.setLocal("carry",r.i32_const(0)),..._(0)]),r.if(r.getLocal("carry"),[...r.setLocal("last",r.i32_const(1)),...r.setLocal("carry",r.i32_const(0)),..._(0)],[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(0)),..._(0)]))),r.setLocal("i",r.i32_add(r.getLocal("i"),r.i32_const(1))),r.br(0))),r.if(r.getLocal("last"),r.if(r.getLocal("carry"),[..._(255),..._(0),..._(1)],[..._(1)]),r.if(r.getLocal("carry"),[..._(0),..._(1)])),r.setLocal("p",r.i32_sub(r.getLocal("p"),r.i32_const(1))),r.call(l,r.getLocal("base"),d),r.call(c,r.getLocal("r")),r.block(r.loop(r.call(i,r.getLocal("r"),r.getLocal("r")),r.setLocal("cur",r.i32_load8_u(r.getLocal("p"))),r.if(r.getLocal("cur"),r.if(r.i32_eq(r.getLocal("cur"),r.i32_const(1)),r.call(o,r.getLocal("r"),d,r.getLocal("r")),r.call(n,r.getLocal("r"),d,r.getLocal("r")))),r.br_if(1,r.i32_eq(r.getLocal("old0"),r.getLocal("p"))),r.setLocal("p",r.i32_sub(r.getLocal("p"),r.i32_const(1))),r.br(0))),r.i32_store(r.i32_const(0),r.getLocal("old0")))},zt=Z,Tt=function(t,a,e,o,i){const n=8*t.modules[a].n64;function l(){const o=t.addFunction(e);o.addParam("pBases","i32"),o.addParam("pScalars","i32"),o.addParam("scalarSize","i32"),o.addParam("n","i32"),o.addParam("pr","i32"),o.addLocal("chunkSize","i32"),o.addLocal("nChunks","i32"),o.addLocal("itScalar","i32"),o.addLocal("endScalar","i32"),o.addLocal("itBase","i32"),o.addLocal("itBit","i32"),o.addLocal("i","i32"),o.addLocal("j","i32"),o.addLocal("nTable","i32"),o.addLocal("pTable","i32"),o.addLocal("idx","i32"),o.addLocal("pIdxTable","i32");const i=o.getCodeBuilder(),l=i.i32_const(t.alloc(n)),c=t.alloc([17,17,17,17,17,17,17,17,17,17,16,16,15,14,13,13,12,11,10,9,8,7,7,6,5,4,3,2,1,1,1,1]);o.addCode(i.call(a+"_zero",i.getLocal("pr")),i.if(i.i32_eqz(i.getLocal("n")),i.ret([])),i.setLocal("chunkSize",i.i32_load8_u(i.i32_clz(i.getLocal("n")),c)),i.setLocal("nChunks",i.i32_add(i.i32_div_u(i.i32_sub(i.i32_shl(i.getLocal("scalarSize"),i.i32_const(3)),i.i32_const(1)),i.getLocal("chunkSize")),i.i32_const(1))),i.setLocal("itBit",i.i32_mul(i.i32_sub(i.getLocal("nChunks"),i.i32_const(1)),i.getLocal("chunkSize"))),i.block(i.loop(i.br_if(1,i.i32_lt_s(i.getLocal("itBit"),i.i32_const(0))),i.if(i.i32_eqz(i.call(a+"_isZero",i.getLocal("pr"))),[...i.setLocal("j",i.i32_const(0)),...i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("j"),i.getLocal("chunkSize"))),i.call(a+"_double",i.getLocal("pr"),i.getLocal("pr")),i.setLocal("j",i.i32_add(i.getLocal("j"),i.i32_const(1))),i.br(0)))]),i.call(e+"_chunk",i.getLocal("pBases"),i.getLocal("pScalars"),i.getLocal("scalarSize"),i.getLocal("n"),i.getLocal("itBit"),i.getLocal("chunkSize"),l),i.call(a+"_add",i.getLocal("pr"),l,i.getLocal("pr")),i.setLocal("itBit",i.i32_sub(i.getLocal("itBit"),i.getLocal("chunkSize"))),i.br(0))))}!function(){const a=t.addFunction(e+"_getChunk");a.addParam("pScalar","i32"),a.addParam("scalarSize","i32"),a.addParam("startBit","i32"),a.addParam("chunkSize","i32"),a.addLocal("bitsToEnd","i32"),a.addLocal("mask","i32"),a.setReturnType("i32");const o=a.getCodeBuilder();a.addCode(o.setLocal("bitsToEnd",o.i32_sub(o.i32_mul(o.getLocal("scalarSize"),o.i32_const(8)),o.getLocal("startBit"))),o.if(o.i32_gt_s(o.getLocal("chunkSize"),o.getLocal("bitsToEnd")),o.setLocal("mask",o.i32_sub(o.i32_shl(o.i32_const(1),o.getLocal("bitsToEnd")),o.i32_const(1))),o.setLocal("mask",o.i32_sub(o.i32_shl(o.i32_const(1),o.getLocal("chunkSize")),o.i32_const(1)))),o.i32_and(o.i32_shr_u(o.i32_load(o.i32_add(o.getLocal("pScalar"),o.i32_shr_u(o.getLocal("startBit"),o.i32_const(3))),0,0),o.i32_and(o.getLocal("startBit"),o.i32_const(7))),o.getLocal("mask")))}(),function(){const o=t.addFunction(e+"_reduceTable");o.addParam("pTable","i32"),o.addParam("p","i32"),o.addLocal("half","i32"),o.addLocal("it1","i32"),o.addLocal("it2","i32"),o.addLocal("pAcc","i32");const i=o.getCodeBuilder();o.addCode(i.if(i.i32_eq(i.getLocal("p"),i.i32_const(1)),i.ret([])),i.setLocal("half",i.i32_shl(i.i32_const(1),i.i32_sub(i.getLocal("p"),i.i32_const(1)))),i.setLocal("it1",i.getLocal("pTable")),i.setLocal("it2",i.i32_add(i.getLocal("pTable"),i.i32_mul(i.getLocal("half"),i.i32_const(n)))),i.setLocal("pAcc",i.i32_sub(i.getLocal("it2"),i.i32_const(n))),i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("it1"),i.getLocal("pAcc"))),i.call(a+"_add",i.getLocal("it1"),i.getLocal("it2"),i.getLocal("it1")),i.call(a+"_add",i.getLocal("pAcc"),i.getLocal("it2"),i.getLocal("pAcc")),i.setLocal("it1",i.i32_add(i.getLocal("it1"),i.i32_const(n))),i.setLocal("it2",i.i32_add(i.getLocal("it2"),i.i32_const(n))),i.br(0))),i.call(e+"_reduceTable",i.getLocal("pTable"),i.i32_sub(i.getLocal("p"),i.i32_const(1))),i.setLocal("p",i.i32_sub(i.getLocal("p"),i.i32_const(1))),i.block(i.loop(i.br_if(1,i.i32_eqz(i.getLocal("p"))),i.call(a+"_double",i.getLocal("pAcc"),i.getLocal("pAcc")),i.setLocal("p",i.i32_sub(i.getLocal("p"),i.i32_const(1))),i.br(0))),i.call(a+"_add",i.getLocal("pTable"),i.getLocal("pAcc"),i.getLocal("pTable")))}(),function(){const l=t.addFunction(e+"_chunk");l.addParam("pBases","i32"),l.addParam("pScalars","i32"),l.addParam("scalarSize","i32"),l.addParam("n","i32"),l.addParam("startBit","i32"),l.addParam("chunkSize","i32"),l.addParam("pr","i32"),l.addLocal("nChunks","i32"),l.addLocal("itScalar","i32"),l.addLocal("endScalar","i32"),l.addLocal("itBase","i32"),l.addLocal("i","i32"),l.addLocal("j","i32"),l.addLocal("nTable","i32"),l.addLocal("pTable","i32"),l.addLocal("idx","i32"),l.addLocal("pIdxTable","i32");const c=l.getCodeBuilder();l.addCode(c.if(c.i32_eqz(c.getLocal("n")),[...c.call(a+"_zero",c.getLocal("pr")),...c.ret([])]),c.setLocal("nTable",c.i32_shl(c.i32_const(1),c.getLocal("chunkSize"))),c.setLocal("pTable",c.i32_load(c.i32_const(0))),c.i32_store(c.i32_const(0),c.i32_add(c.getLocal("pTable"),c.i32_mul(c.getLocal("nTable"),c.i32_const(n)))),c.setLocal("j",c.i32_const(0)),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("j"),c.getLocal("nTable"))),c.call(a+"_zero",c.i32_add(c.getLocal("pTable"),c.i32_mul(c.getLocal("j"),c.i32_const(n)))),c.setLocal("j",c.i32_add(c.getLocal("j"),c.i32_const(1))),c.br(0))),c.setLocal("itBase",c.getLocal("pBases")),c.setLocal("itScalar",c.getLocal("pScalars")),c.setLocal("endScalar",c.i32_add(c.getLocal("pScalars"),c.i32_mul(c.getLocal("n"),c.getLocal("scalarSize")))),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("itScalar"),c.getLocal("endScalar"))),c.setLocal("idx",c.call(e+"_getChunk",c.getLocal("itScalar"),c.getLocal("scalarSize"),c.getLocal("startBit"),c.getLocal("chunkSize"))),c.if(c.getLocal("idx"),[...c.setLocal("pIdxTable",c.i32_add(c.getLocal("pTable"),c.i32_mul(c.i32_sub(c.getLocal("idx"),c.i32_const(1)),c.i32_const(n)))),...c.call(o,c.getLocal("pIdxTable"),c.getLocal("itBase"),c.getLocal("pIdxTable"))]),c.setLocal("itScalar",c.i32_add(c.getLocal("itScalar"),c.getLocal("scalarSize"))),c.setLocal("itBase",c.i32_add(c.getLocal("itBase"),c.i32_const(i))),c.br(0))),c.call(e+"_reduceTable",c.getLocal("pTable"),c.getLocal("chunkSize")),c.call(a+"_copy",c.getLocal("pTable"),c.getLocal("pr")),c.i32_store(c.i32_const(0),c.getLocal("pTable")))}(),l(),t.exportFunction(e),t.exportFunction(e+"_chunk")};var Mt=function(t,a,e,o){const i=t.modules[e].n64,n=8*i;if(t.modules[a])return a;return t.modules[a]={n64:3*i},function(){const o=t.addFunction(a+"_isZeroAffine");o.addParam("p1","i32"),o.setReturnType("i32");const i=o.getCodeBuilder();o.addCode(i.i32_and(i.call(e+"_isZero",i.getLocal("p1")),i.call(e+"_isZero",i.i32_add(i.getLocal("p1"),i.i32_const(n)))))}(),function(){const o=t.addFunction(a+"_isZero");o.addParam("p1","i32"),o.setReturnType("i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_isZero",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))))}(),function(){const o=t.addFunction(a+"_zeroAffine");o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_zero",i.getLocal("pr"))),o.addCode(i.call(e+"_zero",i.i32_add(i.getLocal("pr"),i.i32_const(n))))}(),function(){const o=t.addFunction(a+"_zero");o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_zero",i.getLocal("pr"))),o.addCode(i.call(e+"_one",i.i32_add(i.getLocal("pr"),i.i32_const(n)))),o.addCode(i.call(e+"_zero",i.i32_add(i.getLocal("pr"),i.i32_const(2*n))))}(),function(){const e=t.addFunction(a+"_copyAffine");e.addParam("ps","i32"),e.addParam("pd","i32");const o=e.getCodeBuilder();for(let t=0;t<2*i;t++)e.addCode(o.i64_store(o.getLocal("pd"),8*t,o.i64_load(o.getLocal("ps"),8*t)))}(),function(){const e=t.addFunction(a+"_copy");e.addParam("ps","i32"),e.addParam("pd","i32");const o=e.getCodeBuilder();for(let t=0;t<3*i;t++)e.addCode(o.i64_store(o.getLocal("pd"),8*t,o.i64_load(o.getLocal("ps"),8*t)))}(),function(){const o=t.addFunction(a+"_toJacobian");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.getLocal("pr"),r=i.i32_add(i.getLocal("pr"),i.i32_const(n)),d=i.i32_add(i.getLocal("pr"),i.i32_const(2*n));o.addCode(i.if(i.call(a+"_isZeroAffine",i.getLocal("p1")),i.call(a+"_zero",i.getLocal("pr")),[...i.call(e+"_one",d),...i.call(e+"_copy",c,r),...i.call(e+"_copy",l,s)]))}(),function(){const o=t.addFunction(a+"_eqAffine");o.addParam("p1","i32"),o.addParam("p2","i32"),o.setReturnType("i32"),o.addLocal("z1","i32");const i=o.getCodeBuilder();o.addCode(i.ret(i.i32_and(i.call(e+"_eq",i.getLocal("p1"),i.getLocal("p2")),i.call(e+"_eq",i.i32_add(i.getLocal("p1"),i.i32_const(n)),i.i32_add(i.getLocal("p2"),i.i32_const(n))))))}(),function(){const o=t.addFunction(a+"_eqMixed");o.addParam("p1","i32"),o.addParam("p2","i32"),o.setReturnType("i32"),o.addLocal("z1","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n));o.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))));const s=i.getLocal("z1"),r=i.getLocal("p2"),d=i.i32_add(i.getLocal("p2"),i.i32_const(n)),u=i.i32_const(t.alloc(n)),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),i.ret(i.call(a+"_isZeroAffine",i.getLocal("p2")))),i.if(i.call(a+"_isZeroAffine",i.getLocal("p2")),i.ret(i.i32_const(0))),i.if(i.call(e+"_isOne",s),i.ret(i.call(a+"_eqAffine",i.getLocal("p1"),i.getLocal("p2")))),i.call(e+"_square",s,u),i.call(e+"_mul",r,u,_),i.call(e+"_mul",s,u,g),i.call(e+"_mul",d,g,f),i.if(i.call(e+"_eq",l,_),i.if(i.call(e+"_eq",c,f),i.ret(i.i32_const(1)))),i.ret(i.i32_const(0)))}(),function(){const o=t.addFunction(a+"_eq");o.addParam("p1","i32"),o.addParam("p2","i32"),o.setReturnType("i32"),o.addLocal("z1","i32"),o.addLocal("z2","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n));o.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))));const s=i.getLocal("z1"),r=i.getLocal("p2"),d=i.i32_add(i.getLocal("p2"),i.i32_const(n));o.addCode(i.setLocal("z2",i.i32_add(i.getLocal("p2"),i.i32_const(2*n))));const u=i.getLocal("z2"),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n)),m=i.i32_const(t.alloc(n)),L=i.i32_const(t.alloc(n)),b=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),i.ret(i.call(a+"_isZero",i.getLocal("p2")))),i.if(i.call(a+"_isZero",i.getLocal("p2")),i.ret(i.i32_const(0))),i.if(i.call(e+"_isOne",s),i.ret(i.call(a+"_eqMixed",i.getLocal("p2"),i.getLocal("p1")))),i.if(i.call(e+"_isOne",u),i.ret(i.call(a+"_eqMixed",i.getLocal("p1"),i.getLocal("p2")))),i.call(e+"_square",s,_),i.call(e+"_square",u,g),i.call(e+"_mul",l,g,f),i.call(e+"_mul",r,_,h),i.call(e+"_mul",s,_,p),i.call(e+"_mul",u,g,m),i.call(e+"_mul",c,m,L),i.call(e+"_mul",d,p,b),i.if(i.call(e+"_eq",f,h),i.if(i.call(e+"_eq",L,b),i.ret(i.i32_const(1)))),i.ret(i.i32_const(0)))}(),function(){const o=t.addFunction(a+"_doubleAffine");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.getLocal("pr"),r=i.i32_add(i.getLocal("pr"),i.i32_const(n)),d=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),u=i.i32_const(t.alloc(n)),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZeroAffine",i.getLocal("p1")),[...i.call(a+"_toJacobian",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])]),i.call(e+"_square",l,u),i.call(e+"_square",c,_),i.call(e+"_square",_,g),i.call(e+"_add",l,_,f),i.call(e+"_square",f,f),i.call(e+"_sub",f,u,f),i.call(e+"_sub",f,g,f),i.call(e+"_add",f,f,f),i.call(e+"_add",u,u,h),i.call(e+"_add",h,u,h),i.call(e+"_add",c,c,d),i.call(e+"_square",h,s),i.call(e+"_sub",s,f,s),i.call(e+"_sub",s,f,s),i.call(e+"_add",g,g,p),i.call(e+"_add",p,p,p),i.call(e+"_add",p,p,p),i.call(e+"_sub",f,s,r),i.call(e+"_mul",r,h,r),i.call(e+"_sub",r,p,r))}(),function(){const o=t.addFunction(a+"_double");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.i32_add(i.getLocal("p1"),i.i32_const(2*n)),r=i.getLocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(n)),u=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n)),m=i.i32_const(t.alloc(n)),L=i.i32_const(t.alloc(n)),b=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),[...i.call(a+"_copy",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])]),i.if(i.call(e+"_isOne",s),[...i.ret(i.call(a+"_doubleAffine",i.getLocal("p1"),i.getLocal("pr"))),...i.ret([])]),i.call(e+"_square",l,_),i.call(e+"_square",c,g),i.call(e+"_square",g,f),i.call(e+"_add",l,g,h),i.call(e+"_square",h,h),i.call(e+"_sub",h,_,h),i.call(e+"_sub",h,f,h),i.call(e+"_add",h,h,h),i.call(e+"_add",_,_,p),i.call(e+"_add",p,_,p),i.call(e+"_square",p,m),i.call(e+"_mul",c,s,L),i.call(e+"_add",h,h,r),i.call(e+"_sub",m,r,r),i.call(e+"_add",f,f,b),i.call(e+"_add",b,b,b),i.call(e+"_add",b,b,b),i.call(e+"_sub",h,r,d),i.call(e+"_mul",d,p,d),i.call(e+"_sub",d,b,d),i.call(e+"_add",L,L,u))}(),function(){const o=t.addFunction(a+"_addAffine");o.addParam("p1","i32"),o.addParam("p2","i32"),o.addParam("pr","i32"),o.addLocal("z1","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n));o.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))));const s=i.getLocal("p2"),r=i.i32_add(i.getLocal("p2"),i.i32_const(n)),d=i.getLocal("pr"),u=i.i32_add(i.getLocal("pr"),i.i32_const(n)),_=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n)),m=i.i32_const(t.alloc(n)),L=i.i32_const(t.alloc(n)),b=i.i32_const(t.alloc(n)),w=i.i32_const(t.alloc(n)),y=i.i32_const(t.alloc(n)),A=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZeroAffine",i.getLocal("p1")),[...i.call(a+"_copyAffine",i.getLocal("p2"),i.getLocal("pr")),...i.call(e+"_one",i.i32_add(i.getLocal("pr"),i.i32_const(2*n))),...i.ret([])]),i.if(i.call(a+"_isZeroAffine",i.getLocal("p2")),[...i.call(a+"_copyAffine",i.getLocal("p1"),i.getLocal("pr")),...i.call(e+"_one",i.i32_add(i.getLocal("pr"),i.i32_const(2*n))),...i.ret([])]),i.if(i.call(e+"_eq",l,s),i.if(i.call(e+"_eq",c,r),[...i.call(a+"_doubleAffine",i.getLocal("p2"),i.getLocal("pr")),...i.ret([])])),i.call(e+"_sub",s,l,g),i.call(e+"_sub",r,c,h),i.call(e+"_square",g,f),i.call(e+"_add",f,f,p),i.call(e+"_add",p,p,p),i.call(e+"_mul",g,p,m),i.call(e+"_add",h,h,L),i.call(e+"_mul",l,p,w),i.call(e+"_square",L,b),i.call(e+"_add",w,w,y),i.call(e+"_sub",b,m,d),i.call(e+"_sub",d,y,d),i.call(e+"_mul",c,m,A),i.call(e+"_add",A,A,A),i.call(e+"_sub",w,d,u),i.call(e+"_mul",u,L,u),i.call(e+"_sub",u,A,u),i.call(e+"_add",g,g,_))}(),function(){const o=t.addFunction(a+"_addMixed");o.addParam("p1","i32"),o.addParam("p2","i32"),o.addParam("pr","i32"),o.addLocal("z1","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n));o.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))));const s=i.getLocal("z1"),r=i.getLocal("p2"),d=i.i32_add(i.getLocal("p2"),i.i32_const(n)),u=i.getLocal("pr"),_=i.i32_add(i.getLocal("pr"),i.i32_const(n)),g=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),f=i.i32_const(t.alloc(n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n)),m=i.i32_const(t.alloc(n)),L=i.i32_const(t.alloc(n)),b=i.i32_const(t.alloc(n)),w=i.i32_const(t.alloc(n)),y=i.i32_const(t.alloc(n)),A=i.i32_const(t.alloc(n)),C=i.i32_const(t.alloc(n)),F=i.i32_const(t.alloc(n)),x=i.i32_const(t.alloc(n)),I=i.i32_const(t.alloc(n)),B=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),[...i.call(a+"_copyAffine",i.getLocal("p2"),i.getLocal("pr")),...i.call(e+"_one",i.i32_add(i.getLocal("pr"),i.i32_const(2*n))),...i.ret([])]),i.if(i.call(a+"_isZeroAffine",i.getLocal("p2")),[...i.call(a+"_copy",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])]),i.if(i.call(e+"_isOne",s),[...i.call(a+"_addAffine",l,r,u),...i.ret([])]),i.call(e+"_square",s,f),i.call(e+"_mul",r,f,h),i.call(e+"_mul",s,f,p),i.call(e+"_mul",d,p,m),i.if(i.call(e+"_eq",l,h),i.if(i.call(e+"_eq",c,m),[...i.call(a+"_doubleAffine",i.getLocal("p2"),i.getLocal("pr")),...i.ret([])])),i.call(e+"_sub",h,l,L),i.call(e+"_sub",m,c,w),i.call(e+"_square",L,b),i.call(e+"_add",b,b,y),i.call(e+"_add",y,y,y),i.call(e+"_mul",L,y,A),i.call(e+"_add",w,w,C),i.call(e+"_mul",l,y,x),i.call(e+"_square",C,F),i.call(e+"_add",x,x,I),i.call(e+"_sub",F,A,u),i.call(e+"_sub",u,I,u),i.call(e+"_mul",c,A,B),i.call(e+"_add",B,B,B),i.call(e+"_sub",x,u,_),i.call(e+"_mul",_,C,_),i.call(e+"_sub",_,B,_),i.call(e+"_add",s,L,g),i.call(e+"_square",g,g),i.call(e+"_sub",g,f,g),i.call(e+"_sub",g,b,g))}(),function(){const o=t.addFunction(a+"_add");o.addParam("p1","i32"),o.addParam("p2","i32"),o.addParam("pr","i32"),o.addLocal("z1","i32"),o.addLocal("z2","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n));o.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))));const s=i.getLocal("z1"),r=i.getLocal("p2"),d=i.i32_add(i.getLocal("p2"),i.i32_const(n));o.addCode(i.setLocal("z2",i.i32_add(i.getLocal("p2"),i.i32_const(2*n))));const u=i.getLocal("z2"),_=i.getLocal("pr"),g=i.i32_add(i.getLocal("pr"),i.i32_const(n)),f=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n)),m=i.i32_const(t.alloc(n)),L=i.i32_const(t.alloc(n)),b=i.i32_const(t.alloc(n)),w=i.i32_const(t.alloc(n)),y=i.i32_const(t.alloc(n)),A=i.i32_const(t.alloc(n)),C=i.i32_const(t.alloc(n)),F=i.i32_const(t.alloc(n)),x=i.i32_const(t.alloc(n)),I=i.i32_const(t.alloc(n)),B=i.i32_const(t.alloc(n)),E=i.i32_const(t.alloc(n)),v=i.i32_const(t.alloc(n)),S=i.i32_const(t.alloc(n)),P=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),[...i.call(a+"_copy",i.getLocal("p2"),i.getLocal("pr")),...i.ret([])]),i.if(i.call(a+"_isZero",i.getLocal("p2")),[...i.call(a+"_copy",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])]),i.if(i.call(e+"_isOne",s),[...i.call(a+"_addMixed",r,l,_),...i.ret([])]),i.if(i.call(e+"_isOne",u),[...i.call(a+"_addMixed",l,r,_),...i.ret([])]),i.call(e+"_square",s,h),i.call(e+"_square",u,p),i.call(e+"_mul",l,p,m),i.call(e+"_mul",r,h,L),i.call(e+"_mul",s,h,b),i.call(e+"_mul",u,p,w),i.call(e+"_mul",c,w,y),i.call(e+"_mul",d,b,A),i.if(i.call(e+"_eq",m,L),i.if(i.call(e+"_eq",y,A),[...i.call(a+"_double",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])])),i.call(e+"_sub",L,m,C),i.call(e+"_sub",A,y,F),i.call(e+"_add",C,C,x),i.call(e+"_square",x,x),i.call(e+"_mul",C,x,I),i.call(e+"_add",F,F,B),i.call(e+"_mul",m,x,v),i.call(e+"_square",B,E),i.call(e+"_add",v,v,S),i.call(e+"_sub",E,I,_),i.call(e+"_sub",_,S,_),i.call(e+"_mul",y,I,P),i.call(e+"_add",P,P,P),i.call(e+"_sub",v,_,g),i.call(e+"_mul",g,B,g),i.call(e+"_sub",g,P,g),i.call(e+"_add",s,u,f),i.call(e+"_square",f,f),i.call(e+"_sub",f,h,f),i.call(e+"_sub",f,p,f),i.call(e+"_mul",f,C,f))}(),function(){const o=t.addFunction(a+"_negAffine");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.getLocal("pr"),r=i.i32_add(i.getLocal("pr"),i.i32_const(n));o.addCode(i.call(e+"_copy",l,s),i.call(e+"_neg",c,r))}(),function(){const o=t.addFunction(a+"_neg");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.i32_add(i.getLocal("p1"),i.i32_const(2*n)),r=i.getLocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(n)),u=i.i32_add(i.getLocal("pr"),i.i32_const(2*n));o.addCode(i.call(e+"_copy",l,r),i.call(e+"_neg",c,d),i.call(e+"_copy",s,u))}(),function(){const e=t.addFunction(a+"_subAffine");e.addParam("p1","i32"),e.addParam("p2","i32"),e.addParam("pr","i32");const o=e.getCodeBuilder(),i=o.i32_const(t.alloc(3*n));e.addCode(o.call(a+"_negAffine",o.getLocal("p2"),i),o.call(a+"_addAffine",o.getLocal("p1"),i,o.getLocal("pr")))}(),function(){const e=t.addFunction(a+"_subMixed");e.addParam("p1","i32"),e.addParam("p2","i32"),e.addParam("pr","i32");const o=e.getCodeBuilder(),i=o.i32_const(t.alloc(3*n));e.addCode(o.call(a+"_negAffine",o.getLocal("p2"),i),o.call(a+"_addMixed",o.getLocal("p1"),i,o.getLocal("pr")))}(),function(){const e=t.addFunction(a+"_sub");e.addParam("p1","i32"),e.addParam("p2","i32"),e.addParam("pr","i32");const o=e.getCodeBuilder(),i=o.i32_const(t.alloc(3*n));e.addCode(o.call(a+"_neg",o.getLocal("p2"),i),o.call(a+"_add",o.getLocal("p1"),i,o.getLocal("pr")))}(),function(){const o=t.addFunction(a+"_fromMontgomeryAffine");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_fromMontgomery",i.getLocal("p1"),i.getLocal("pr")));for(let t=1;t<2;t++)o.addCode(i.call(e+"_fromMontgomery",i.i32_add(i.getLocal("p1"),i.i32_const(t*n)),i.i32_add(i.getLocal("pr"),i.i32_const(t*n))))}(),function(){const o=t.addFunction(a+"_fromMontgomery");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_fromMontgomery",i.getLocal("p1"),i.getLocal("pr")));for(let t=1;t<3;t++)o.addCode(i.call(e+"_fromMontgomery",i.i32_add(i.getLocal("p1"),i.i32_const(t*n)),i.i32_add(i.getLocal("pr"),i.i32_const(t*n))))}(),function(){const o=t.addFunction(a+"_toMontgomeryAffine");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_toMontgomery",i.getLocal("p1"),i.getLocal("pr")));for(let t=1;t<2;t++)o.addCode(i.call(e+"_toMontgomery",i.i32_add(i.getLocal("p1"),i.i32_const(t*n)),i.i32_add(i.getLocal("pr"),i.i32_const(t*n))))}(),function(){const o=t.addFunction(a+"_toMontgomery");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_toMontgomery",i.getLocal("p1"),i.getLocal("pr")));for(let t=1;t<3;t++)o.addCode(i.call(e+"_toMontgomery",i.i32_add(i.getLocal("p1"),i.i32_const(t*n)),i.i32_add(i.getLocal("pr"),i.i32_const(t*n))))}(),function(){const o=t.addFunction(a+"_toAffine");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.i32_add(i.getLocal("p1"),i.i32_const(2*n)),r=i.getLocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(n)),u=i.i32_const(t.alloc(n)),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),[...i.call(e+"_zero",r),...i.call(e+"_zero",d)],[...i.call(e+"_inverse",s,u),...i.call(e+"_square",u,_),...i.call(e+"_mul",u,_,g),...i.call(e+"_mul",l,_,r),...i.call(e+"_mul",c,g,d)]))}(),function(){const i=t.addFunction(a+"_inCurveAffine");i.addParam("pIn","i32"),i.setReturnType("i32");const l=i.getCodeBuilder(),c=l.getLocal("pIn"),s=l.i32_add(l.getLocal("pIn"),l.i32_const(n)),r=l.i32_const(t.alloc(n)),d=l.i32_const(t.alloc(n));i.addCode(l.call(e+"_square",s,r),l.call(e+"_square",c,d),l.call(e+"_mul",c,d,d),l.call(e+"_add",d,l.i32_const(o),d),l.ret(l.call(e+"_eq",r,d)))}(),function(){const e=t.addFunction(a+"_inCurve");e.addParam("pIn","i32"),e.setReturnType("i32");const o=e.getCodeBuilder(),i=o.i32_const(t.alloc(2*n));e.addCode(o.call(a+"_toAffine",o.getLocal("pIn"),i),o.ret(o.call(a+"_inCurveAffine",i)))}(),function(){const o=t.addFunction(a+"_batchToAffine");o.addParam("pIn","i32"),o.addParam("n","i32"),o.addParam("pOut","i32"),o.addLocal("pAux","i32"),o.addLocal("itIn","i32"),o.addLocal("itAux","i32"),o.addLocal("itOut","i32"),o.addLocal("i","i32");const i=o.getCodeBuilder(),l=i.i32_const(t.alloc(n));o.addCode(i.setLocal("pAux",i.i32_load(i.i32_const(0))),i.i32_store(i.i32_const(0),i.i32_add(i.getLocal("pAux"),i.i32_mul(i.getLocal("n"),i.i32_const(n)))),i.call(e+"_batchInverse",i.i32_add(i.getLocal("pIn"),i.i32_const(2*n)),i.i32_const(3*n),i.getLocal("n"),i.getLocal("pAux"),i.i32_const(n)),i.setLocal("itIn",i.getLocal("pIn")),i.setLocal("itAux",i.getLocal("pAux")),i.setLocal("itOut",i.getLocal("pOut")),i.setLocal("i",i.i32_const(0)),i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("i"),i.getLocal("n"))),i.if(i.call(e+"_isZero",i.getLocal("itAux")),[...i.call(e+"_zero",i.getLocal("itOut")),...i.call(e+"_zero",i.i32_add(i.getLocal("itOut"),i.i32_const(n)))],[...i.call(e+"_mul",i.getLocal("itAux"),i.i32_add(i.getLocal("itIn"),i.i32_const(n)),l),...i.call(e+"_square",i.getLocal("itAux"),i.getLocal("itAux")),...i.call(e+"_mul",i.getLocal("itAux"),i.getLocal("itIn"),i.getLocal("itOut")),...i.call(e+"_mul",i.getLocal("itAux"),l,i.i32_add(i.getLocal("itOut"),i.i32_const(n)))]),i.setLocal("itIn",i.i32_add(i.getLocal("itIn"),i.i32_const(3*n))),i.setLocal("itOut",i.i32_add(i.getLocal("itOut"),i.i32_const(2*n))),i.setLocal("itAux",i.i32_add(i.getLocal("itAux"),i.i32_const(n))),i.setLocal("i",i.i32_add(i.getLocal("i"),i.i32_const(1))),i.br(0))),i.i32_store(i.i32_const(0),i.getLocal("pAux")))}(),function(){const o=t.addFunction(a+"_normalize");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.i32_add(i.getLocal("p1"),i.i32_const(2*n)),r=i.getLocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(n)),u=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),i.call(a+"_zero",i.getLocal("pr")),[...i.call(e+"_inverse",s,_),...i.call(e+"_square",_,g),...i.call(e+"_mul",_,g,f),...i.call(e+"_mul",l,g,r),...i.call(e+"_mul",c,f,d),...i.call(e+"_one",u)]))}(),function(){const e=t.addFunction(a+"__reverseBytes");e.addParam("pIn","i32"),e.addParam("n","i32"),e.addParam("pOut","i32"),e.addLocal("itOut","i32"),e.addLocal("itIn","i32");const o=e.getCodeBuilder();e.addCode(o.setLocal("itOut",o.i32_sub(o.i32_add(o.getLocal("pOut"),o.getLocal("n")),o.i32_const(1))),o.setLocal("itIn",o.getLocal("pIn")),o.block(o.loop(o.br_if(1,o.i32_lt_s(o.getLocal("itOut"),o.getLocal("pOut"))),o.i32_store8(o.getLocal("itOut"),o.i32_load8_u(o.getLocal("itIn"))),o.setLocal("itOut",o.i32_sub(o.getLocal("itOut"),o.i32_const(1))),o.setLocal("itIn",o.i32_add(o.getLocal("itIn"),o.i32_const(1))),o.br(0))))}(),function(){const e=t.addFunction(a+"_LEMtoU");e.addParam("pIn","i32"),e.addParam("pOut","i32");const o=e.getCodeBuilder(),i=t.alloc(2*n),l=o.i32_const(i),c=o.i32_const(i),s=o.i32_const(i+n);e.addCode(o.if(o.call(a+"_isZeroAffine",o.getLocal("pIn")),[...o.call(a+"_zeroAffine",o.getLocal("pOut")),...o.ret([])]),o.call(a+"_fromMontgomeryAffine",o.getLocal("pIn"),l),o.call(a+"__reverseBytes",c,o.i32_const(n),o.getLocal("pOut")),o.call(a+"__reverseBytes",s,o.i32_const(n),o.i32_add(o.getLocal("pOut"),o.i32_const(n))))}(),function(){const o=t.addFunction(a+"_LEMtoC");o.addParam("pIn","i32"),o.addParam("pOut","i32");const i=o.getCodeBuilder(),l=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZeroAffine",i.getLocal("pIn")),[...i.call(e+"_zero",i.getLocal("pOut")),...i.i32_store8(i.getLocal("pOut"),i.i32_const(64)),...i.ret([])]),i.call(e+"_fromMontgomery",i.getLocal("pIn"),l),i.call(a+"__reverseBytes",l,i.i32_const(n),i.getLocal("pOut")),i.if(i.i32_eq(i.call(e+"_sign",i.i32_add(i.getLocal("pIn"),i.i32_const(n))),i.i32_const(-1)),i.i32_store8(i.getLocal("pOut"),i.i32_or(i.i32_load8_u(i.getLocal("pOut")),i.i32_const(128)))))}(),function(){const e=t.addFunction(a+"_UtoLEM");e.addParam("pIn","i32"),e.addParam("pOut","i32");const o=e.getCodeBuilder(),i=t.alloc(2*n),l=o.i32_const(i),c=o.i32_const(i),s=o.i32_const(i+n);e.addCode(o.if(o.i32_and(o.i32_load8_u(o.getLocal("pIn")),o.i32_const(64)),[...o.call(a+"_zeroAffine",o.getLocal("pOut")),...o.ret([])]),o.call(a+"__reverseBytes",o.getLocal("pIn"),o.i32_const(n),c),o.call(a+"__reverseBytes",o.i32_add(o.getLocal("pIn"),o.i32_const(n)),o.i32_const(n),s),o.call(a+"_toMontgomeryAffine",l,o.getLocal("pOut")))}(),function(){const i=t.addFunction(a+"_CtoLEM");i.addParam("pIn","i32"),i.addParam("pOut","i32"),i.addLocal("firstByte","i32"),i.addLocal("greatest","i32");const l=i.getCodeBuilder(),c=t.alloc(2*n),s=l.i32_const(c),r=l.i32_const(c+n);i.addCode(l.setLocal("firstByte",l.i32_load8_u(l.getLocal("pIn"))),l.if(l.i32_and(l.getLocal("firstByte"),l.i32_const(64)),[...l.call(a+"_zeroAffine",l.getLocal("pOut")),...l.ret([])]),l.setLocal("greatest",l.i32_and(l.getLocal("firstByte"),l.i32_const(128))),l.call(e+"_copy",l.getLocal("pIn"),r),l.i32_store8(r,l.i32_and(l.getLocal("firstByte"),l.i32_const(63))),l.call(a+"__reverseBytes",r,l.i32_const(n),s),l.call(e+"_toMontgomery",s,l.getLocal("pOut")),l.call(e+"_square",l.getLocal("pOut"),r),l.call(e+"_mul",l.getLocal("pOut"),r,r),l.call(e+"_add",r,l.i32_const(o),r),l.call(e+"_sqrt",r,r),l.call(e+"_neg",r,s),l.if(l.i32_eq(l.call(e+"_sign",r),l.i32_const(-1)),l.if(l.getLocal("greatest"),l.call(e+"_copy",r,l.i32_add(l.getLocal("pOut"),l.i32_const(n))),l.call(e+"_neg",r,l.i32_add(l.getLocal("pOut"),l.i32_const(n)))),l.if(l.getLocal("greatest"),l.call(e+"_neg",r,l.i32_add(l.getLocal("pOut"),l.i32_const(n))),l.call(e+"_copy",r,l.i32_add(l.getLocal("pOut"),l.i32_const(n))))))}(),zt(t,a+"_batchLEMtoU",a+"_LEMtoU",2*n,2*n),zt(t,a+"_batchLEMtoC",a+"_LEMtoC",2*n,n),zt(t,a+"_batchUtoLEM",a+"_UtoLEM",2*n,2*n),zt(t,a+"_batchCtoLEM",a+"_CtoLEM",n,2*n,!0),zt(t,a+"_batchToJacobian",a+"_toJacobian",2*n,3*n,!0),Tt(t,a,a+"_multiexp",a+"_add",3*n),Tt(t,a,a+"_multiexpAffine",a+"_addMixed",2*n),Gt(t,a+"_timesScalar",3*n,a+"_add",a+"_double",a+"_sub",a+"_copy",a+"_zero"),Gt(t,a+"_timesScalarAffine",2*n,a+"_addMixed",a+"_double",a+"_subMixed",a+"_copyAffine",a+"_zero"),t.exportFunction(a+"_isZero"),t.exportFunction(a+"_isZeroAffine"),t.exportFunction(a+"_eq"),t.exportFunction(a+"_eqMixed"),t.exportFunction(a+"_eqAffine"),t.exportFunction(a+"_copy"),t.exportFunction(a+"_copyAffine"),t.exportFunction(a+"_zero"),t.exportFunction(a+"_zeroAffine"),t.exportFunction(a+"_double"),t.exportFunction(a+"_doubleAffine"),t.exportFunction(a+"_add"),t.exportFunction(a+"_addMixed"),t.exportFunction(a+"_addAffine"),t.exportFunction(a+"_neg"),t.exportFunction(a+"_negAffine"),t.exportFunction(a+"_sub"),t.exportFunction(a+"_subMixed"),t.exportFunction(a+"_subAffine"),t.exportFunction(a+"_fromMontgomery"),t.exportFunction(a+"_fromMontgomeryAffine"),t.exportFunction(a+"_toMontgomery"),t.exportFunction(a+"_toMontgomeryAffine"),t.exportFunction(a+"_timesScalar"),t.exportFunction(a+"_timesScalarAffine"),t.exportFunction(a+"_normalize"),t.exportFunction(a+"_LEMtoU"),t.exportFunction(a+"_LEMtoC"),t.exportFunction(a+"_UtoLEM"),t.exportFunction(a+"_CtoLEM"),t.exportFunction(a+"_batchLEMtoU"),t.exportFunction(a+"_batchLEMtoC"),t.exportFunction(a+"_batchUtoLEM"),t.exportFunction(a+"_batchCtoLEM"),t.exportFunction(a+"_toAffine"),t.exportFunction(a+"_toJacobian"),t.exportFunction(a+"_batchToAffine"),t.exportFunction(a+"_batchToJacobian"),t.exportFunction(a+"_inCurve"),t.exportFunction(a+"_inCurveAffine"),a};const{isOdd:Ut,modInv:Qt,modPow:kt}=Y,Rt=V;var Nt=function(t,a,e,o,i){const n=8*t.modules[o].n64,l=8*t.modules[e].n64,c=t.modules[o].q;let s=c-1n,r=0;for(;!Ut(s);)r++,s>>=1n;let d=2n;for(;1n===kt(d,c>>1n,c);)d+=1n;const u=new Array(r+1);u[r]=kt(d,s,c);let _=r-1;for(;_>=0;)u[_]=kt(u[_+1],2n,c),_--;const g=[],f=(1n<>e);return a}const x=Array(256);for(let t=0;t<256;t++)x[t]=F(t);const I=t.alloc(x);function B(){const e=t.addFunction(a+"_fft");e.addParam("px","i32"),e.addParam("n","i32"),e.addLocal("bits","i32");const i=e.getCodeBuilder(),l=i.i32_const(t.alloc(n));e.addCode(i.setLocal("bits",i.call(a+"__log2",i.getLocal("n"))),i.call(o+"_one",l),i.call(a+"_rawfft",i.getLocal("px"),i.getLocal("bits"),i.i32_const(0),l))}!function(){const e=t.addFunction(a+"__rev");e.addParam("x","i32"),e.addParam("bits","i32"),e.setReturnType("i32");const o=e.getCodeBuilder();e.addCode(o.i32_rotl(o.i32_add(o.i32_add(o.i32_shl(o.i32_load8_u(o.i32_and(o.getLocal("x"),o.i32_const(255)),I,0),o.i32_const(24)),o.i32_shl(o.i32_load8_u(o.i32_and(o.i32_shr_u(o.getLocal("x"),o.i32_const(8)),o.i32_const(255)),I,0),o.i32_const(16))),o.i32_add(o.i32_shl(o.i32_load8_u(o.i32_and(o.i32_shr_u(o.getLocal("x"),o.i32_const(16)),o.i32_const(255)),I,0),o.i32_const(8)),o.i32_load8_u(o.i32_and(o.i32_shr_u(o.getLocal("x"),o.i32_const(24)),o.i32_const(255)),I,0))),o.getLocal("bits")))}(),function(){const o=t.addFunction(a+"__reversePermutation");o.addParam("px","i32"),o.addParam("bits","i32"),o.addLocal("n","i32"),o.addLocal("i","i32"),o.addLocal("ri","i32"),o.addLocal("idx1","i32"),o.addLocal("idx2","i32");const i=o.getCodeBuilder(),n=i.i32_const(t.alloc(l));o.addCode(i.setLocal("n",i.i32_shl(i.i32_const(1),i.getLocal("bits"))),i.setLocal("i",i.i32_const(0)),i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("i"),i.getLocal("n"))),i.setLocal("idx1",i.i32_add(i.getLocal("px"),i.i32_mul(i.getLocal("i"),i.i32_const(l)))),i.setLocal("ri",i.call(a+"__rev",i.getLocal("i"),i.getLocal("bits"))),i.setLocal("idx2",i.i32_add(i.getLocal("px"),i.i32_mul(i.getLocal("ri"),i.i32_const(l)))),i.if(i.i32_lt_u(i.getLocal("i"),i.getLocal("ri")),[...i.call(e+"_copy",i.getLocal("idx1"),n),...i.call(e+"_copy",i.getLocal("idx2"),i.getLocal("idx1")),...i.call(e+"_copy",n,i.getLocal("idx2"))]),i.setLocal("i",i.i32_add(i.getLocal("i"),i.i32_const(1))),i.br(0))))}(),function(){const n=t.addFunction(a+"__fftFinal");n.addParam("px","i32"),n.addParam("bits","i32"),n.addParam("reverse","i32"),n.addParam("mulFactor","i32"),n.addLocal("n","i32"),n.addLocal("ndiv2","i32"),n.addLocal("pInv2","i32"),n.addLocal("i","i32"),n.addLocal("mask","i32"),n.addLocal("idx1","i32"),n.addLocal("idx2","i32");const c=n.getCodeBuilder(),s=c.i32_const(t.alloc(l));n.addCode(c.if(c.i32_and(c.i32_eqz(c.getLocal("reverse")),c.call(o+"_isOne",c.getLocal("mulFactor"))),c.ret([])),c.setLocal("n",c.i32_shl(c.i32_const(1),c.getLocal("bits"))),c.setLocal("mask",c.i32_sub(c.getLocal("n"),c.i32_const(1))),c.setLocal("i",c.i32_const(1)),c.setLocal("ndiv2",c.i32_shr_u(c.getLocal("n"),c.i32_const(1))),c.block(c.loop(c.br_if(1,c.i32_ge_u(c.getLocal("i"),c.getLocal("ndiv2"))),c.setLocal("idx1",c.i32_add(c.getLocal("px"),c.i32_mul(c.getLocal("i"),c.i32_const(l)))),c.setLocal("idx2",c.i32_add(c.getLocal("px"),c.i32_mul(c.i32_sub(c.getLocal("n"),c.getLocal("i")),c.i32_const(l)))),c.if(c.getLocal("reverse"),c.if(c.call(o+"_isOne",c.getLocal("mulFactor")),[...c.call(e+"_copy",c.getLocal("idx1"),s),...c.call(e+"_copy",c.getLocal("idx2"),c.getLocal("idx1")),...c.call(e+"_copy",s,c.getLocal("idx2"))],[...c.call(e+"_copy",c.getLocal("idx1"),s),...c.call(i,c.getLocal("idx2"),c.getLocal("mulFactor"),c.getLocal("idx1")),...c.call(i,s,c.getLocal("mulFactor"),c.getLocal("idx2"))]),c.if(c.call(o+"_isOne",c.getLocal("mulFactor")),[],[...c.call(i,c.getLocal("idx1"),c.getLocal("mulFactor"),c.getLocal("idx1")),...c.call(i,c.getLocal("idx2"),c.getLocal("mulFactor"),c.getLocal("idx2"))])),c.setLocal("i",c.i32_add(c.getLocal("i"),c.i32_const(1))),c.br(0))),c.if(c.call(o+"_isOne",c.getLocal("mulFactor")),[],[...c.call(i,c.getLocal("px"),c.getLocal("mulFactor"),c.getLocal("px")),...c.setLocal("idx2",c.i32_add(c.getLocal("px"),c.i32_mul(c.getLocal("ndiv2"),c.i32_const(l)))),...c.call(i,c.getLocal("idx2"),c.getLocal("mulFactor"),c.getLocal("idx2"))]))}(),function(){const c=t.addFunction(a+"_rawfft");c.addParam("px","i32"),c.addParam("bits","i32"),c.addParam("reverse","i32"),c.addParam("mulFactor","i32"),c.addLocal("s","i32"),c.addLocal("k","i32"),c.addLocal("j","i32"),c.addLocal("m","i32"),c.addLocal("mdiv2","i32"),c.addLocal("n","i32"),c.addLocal("pwm","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l)),u=s.i32_const(t.alloc(l));c.addCode(s.call(a+"__reversePermutation",s.getLocal("px"),s.getLocal("bits")),s.setLocal("n",s.i32_shl(s.i32_const(1),s.getLocal("bits"))),s.setLocal("s",s.i32_const(1)),s.block(s.loop(s.br_if(1,s.i32_gt_u(s.getLocal("s"),s.getLocal("bits"))),s.setLocal("m",s.i32_shl(s.i32_const(1),s.getLocal("s"))),s.setLocal("pwm",s.i32_add(s.i32_const(h),s.i32_mul(s.getLocal("s"),s.i32_const(n)))),s.setLocal("k",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_ge_u(s.getLocal("k"),s.getLocal("n"))),s.call(o+"_one",r),s.setLocal("mdiv2",s.i32_shr_u(s.getLocal("m"),s.i32_const(1))),s.setLocal("j",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_ge_u(s.getLocal("j"),s.getLocal("mdiv2"))),s.setLocal("idx1",s.i32_add(s.getLocal("px"),s.i32_mul(s.i32_add(s.getLocal("k"),s.getLocal("j")),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("idx1"),s.i32_mul(s.getLocal("mdiv2"),s.i32_const(l)))),s.call(i,s.getLocal("idx2"),r,d),s.call(e+"_copy",s.getLocal("idx1"),u),s.call(e+"_add",u,d,s.getLocal("idx1")),s.call(e+"_sub",u,d,s.getLocal("idx2")),s.call(o+"_mul",r,s.getLocal("pwm"),r),s.setLocal("j",s.i32_add(s.getLocal("j"),s.i32_const(1))),s.br(0))),s.setLocal("k",s.i32_add(s.getLocal("k"),s.getLocal("m"))),s.br(0))),s.setLocal("s",s.i32_add(s.getLocal("s"),s.i32_const(1))),s.br(0))),s.call(a+"__fftFinal",s.getLocal("px"),s.getLocal("bits"),s.getLocal("reverse"),s.getLocal("mulFactor")))}(),function(){const e=t.addFunction(a+"__log2");e.addParam("n","i32"),e.setReturnType("i32"),e.addLocal("bits","i32"),e.addLocal("aux","i32");const o=e.getCodeBuilder();e.addCode(o.setLocal("aux",o.i32_shr_u(o.getLocal("n"),o.i32_const(1)))),e.addCode(o.setLocal("bits",o.i32_const(0))),e.addCode(o.block(o.loop(o.br_if(1,o.i32_eqz(o.getLocal("aux"))),o.setLocal("aux",o.i32_shr_u(o.getLocal("aux"),o.i32_const(1))),o.setLocal("bits",o.i32_add(o.getLocal("bits"),o.i32_const(1))),o.br(0)))),e.addCode(o.if(o.i32_ne(o.getLocal("n"),o.i32_shl(o.i32_const(1),o.getLocal("bits"))),o.unreachable())),e.addCode(o.if(o.i32_gt_u(o.getLocal("bits"),o.i32_const(r)),o.unreachable())),e.addCode(o.getLocal("bits"))}(),B(),function(){const e=t.addFunction(a+"_ifft");e.addParam("px","i32"),e.addParam("n","i32"),e.addLocal("bits","i32"),e.addLocal("pInv2","i32");const o=e.getCodeBuilder();e.addCode(o.setLocal("bits",o.call(a+"__log2",o.getLocal("n"))),o.setLocal("pInv2",o.i32_add(o.i32_const(L),o.i32_mul(o.getLocal("bits"),o.i32_const(n)))),o.call(a+"_rawfft",o.getLocal("px"),o.getLocal("bits"),o.i32_const(1),o.getLocal("pInv2")))}(),function(){const c=t.addFunction(a+"_fftJoin");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l)),u=s.i32_const(t.alloc(l));c.addCode(s.call(o+"_copy",s.getLocal("first"),r),s.setLocal("i",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("n"))),s.setLocal("idx1",s.i32_add(s.getLocal("pBuff1"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("pBuff2"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.call(i,s.getLocal("idx2"),r,d),s.call(e+"_copy",s.getLocal("idx1"),u),s.call(e+"_add",u,d,s.getLocal("idx1")),s.call(e+"_sub",u,d,s.getLocal("idx2")),s.call(o+"_mul",r,s.getLocal("inc"),r),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),function(){const c=t.addFunction(a+"_fftJoinExt");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addParam("totalBits","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("pShiftToM","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l));c.addCode(s.setLocal("pShiftToM",s.i32_add(s.i32_const(A),s.i32_mul(s.getLocal("totalBits"),s.i32_const(n)))),s.call(o+"_copy",s.getLocal("first"),r),s.setLocal("i",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("n"))),s.setLocal("idx1",s.i32_add(s.getLocal("pBuff1"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("pBuff2"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.call(e+"_add",s.getLocal("idx1"),s.getLocal("idx2"),d),s.call(i,s.getLocal("idx2"),s.getLocal("pShiftToM"),s.getLocal("idx2")),s.call(e+"_add",s.getLocal("idx1"),s.getLocal("idx2"),s.getLocal("idx2")),s.call(i,s.getLocal("idx2"),r,s.getLocal("idx2")),s.call(e+"_copy",d,s.getLocal("idx1")),s.call(o+"_mul",r,s.getLocal("inc"),r),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),function(){const c=t.addFunction(a+"_fftJoinExtInv");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addParam("totalBits","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("pShiftToM","i32"),c.addLocal("pSConst","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l));c.addCode(s.setLocal("pShiftToM",s.i32_add(s.i32_const(A),s.i32_mul(s.getLocal("totalBits"),s.i32_const(n)))),s.setLocal("pSConst",s.i32_add(s.i32_const(C),s.i32_mul(s.getLocal("totalBits"),s.i32_const(n)))),s.call(o+"_copy",s.getLocal("first"),r),s.setLocal("i",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("n"))),s.setLocal("idx1",s.i32_add(s.getLocal("pBuff1"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("pBuff2"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.call(i,s.getLocal("idx2"),r,d),s.call(e+"_sub",s.getLocal("idx1"),d,s.getLocal("idx2")),s.call(i,s.getLocal("idx2"),s.getLocal("pSConst"),s.getLocal("idx2")),s.call(i,s.getLocal("idx1"),s.getLocal("pShiftToM"),s.getLocal("idx1")),s.call(e+"_sub",d,s.getLocal("idx1"),s.getLocal("idx1")),s.call(i,s.getLocal("idx1"),s.getLocal("pSConst"),s.getLocal("idx1")),s.call(o+"_mul",r,s.getLocal("inc"),r),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),function(){const c=t.addFunction(a+"_fftMix");c.addParam("pBuff","i32"),c.addParam("n","i32"),c.addParam("exp","i32"),c.addLocal("nGroups","i32"),c.addLocal("nPerGroup","i32"),c.addLocal("nPerGroupDiv2","i32"),c.addLocal("pairOffset","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("j","i32"),c.addLocal("pwm","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l)),u=s.i32_const(t.alloc(l));c.addCode(s.setLocal("nPerGroup",s.i32_shl(s.i32_const(1),s.getLocal("exp"))),s.setLocal("nPerGroupDiv2",s.i32_shr_u(s.getLocal("nPerGroup"),s.i32_const(1))),s.setLocal("nGroups",s.i32_shr_u(s.getLocal("n"),s.getLocal("exp"))),s.setLocal("pairOffset",s.i32_mul(s.getLocal("nPerGroupDiv2"),s.i32_const(l))),s.setLocal("pwm",s.i32_add(s.i32_const(h),s.i32_mul(s.getLocal("exp"),s.i32_const(n)))),s.setLocal("i",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("nGroups"))),s.call(o+"_one",r),s.setLocal("j",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("j"),s.getLocal("nPerGroupDiv2"))),s.setLocal("idx1",s.i32_add(s.getLocal("pBuff"),s.i32_mul(s.i32_add(s.i32_mul(s.getLocal("i"),s.getLocal("nPerGroup")),s.getLocal("j")),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("idx1"),s.getLocal("pairOffset"))),s.call(i,s.getLocal("idx2"),r,d),s.call(e+"_copy",s.getLocal("idx1"),u),s.call(e+"_add",u,d,s.getLocal("idx1")),s.call(e+"_sub",u,d,s.getLocal("idx2")),s.call(o+"_mul",r,s.getLocal("pwm"),r),s.setLocal("j",s.i32_add(s.getLocal("j"),s.i32_const(1))),s.br(0))),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),function(){const o=t.addFunction(a+"_fftFinal");o.addParam("pBuff","i32"),o.addParam("n","i32"),o.addParam("factor","i32"),o.addLocal("idx1","i32"),o.addLocal("idx2","i32"),o.addLocal("i","i32"),o.addLocal("ndiv2","i32");const n=o.getCodeBuilder(),c=n.i32_const(t.alloc(l));o.addCode(n.setLocal("ndiv2",n.i32_shr_u(n.getLocal("n"),n.i32_const(1))),n.if(n.i32_and(n.getLocal("n"),n.i32_const(1)),n.call(i,n.i32_add(n.getLocal("pBuff"),n.i32_mul(n.getLocal("ndiv2"),n.i32_const(l))),n.getLocal("factor"),n.i32_add(n.getLocal("pBuff"),n.i32_mul(n.getLocal("ndiv2"),n.i32_const(l))))),n.setLocal("i",n.i32_const(0)),n.block(n.loop(n.br_if(1,n.i32_ge_u(n.getLocal("i"),n.getLocal("ndiv2"))),n.setLocal("idx1",n.i32_add(n.getLocal("pBuff"),n.i32_mul(n.getLocal("i"),n.i32_const(l)))),n.setLocal("idx2",n.i32_add(n.getLocal("pBuff"),n.i32_mul(n.i32_sub(n.i32_sub(n.getLocal("n"),n.i32_const(1)),n.getLocal("i")),n.i32_const(l)))),n.call(i,n.getLocal("idx2"),n.getLocal("factor"),c),n.call(i,n.getLocal("idx1"),n.getLocal("factor"),n.getLocal("idx2")),n.call(e+"_copy",c,n.getLocal("idx1")),n.setLocal("i",n.i32_add(n.getLocal("i"),n.i32_const(1))),n.br(0))))}(),function(){const c=t.addFunction(a+"_prepareLagrangeEvaluation");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addParam("totalBits","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("pShiftToM","i32"),c.addLocal("pSConst","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l));c.addCode(s.setLocal("pShiftToM",s.i32_add(s.i32_const(A),s.i32_mul(s.getLocal("totalBits"),s.i32_const(n)))),s.setLocal("pSConst",s.i32_add(s.i32_const(C),s.i32_mul(s.getLocal("totalBits"),s.i32_const(n)))),s.call(o+"_copy",s.getLocal("first"),r),s.setLocal("i",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("n"))),s.setLocal("idx1",s.i32_add(s.getLocal("pBuff1"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("pBuff2"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.call(i,s.getLocal("idx1"),s.getLocal("pShiftToM"),d),s.call(e+"_sub",s.getLocal("idx2"),d,d),s.call(e+"_sub",s.getLocal("idx1"),s.getLocal("idx2"),s.getLocal("idx2")),s.call(i,d,s.getLocal("pSConst"),s.getLocal("idx1")),s.call(i,s.getLocal("idx2"),r,s.getLocal("idx2")),s.call(o+"_mul",r,s.getLocal("inc"),r),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),t.exportFunction(a+"_fft"),t.exportFunction(a+"_ifft"),t.exportFunction(a+"_rawfft"),t.exportFunction(a+"_fftJoin"),t.exportFunction(a+"_fftJoinExt"),t.exportFunction(a+"_fftJoinExtInv"),t.exportFunction(a+"_fftMix"),t.exportFunction(a+"_fftFinal"),t.exportFunction(a+"_prepareLagrangeEvaluation")},Dt=function(t,a,e){const o=8*t.modules[e].n64;return function(){const i=t.addFunction(a+"_zero");i.addParam("px","i32"),i.addParam("n","i32"),i.addLocal("lastp","i32"),i.addLocal("p","i32");const n=i.getCodeBuilder();i.addCode(n.setLocal("p",n.getLocal("px")),n.setLocal("lastp",n.i32_add(n.getLocal("px"),n.i32_mul(n.getLocal("n"),n.i32_const(o)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("p"),n.getLocal("lastp"))),n.call(e+"_zero",n.getLocal("p")),n.setLocal("p",n.i32_add(n.getLocal("p"),n.i32_const(o))),n.br(0))))}(),function(){const i=t.addFunction(a+"_constructLC");i.addParam("ppolynomials","i32"),i.addParam("psignals","i32"),i.addParam("nSignals","i32"),i.addParam("pres","i32"),i.addLocal("i","i32"),i.addLocal("j","i32"),i.addLocal("pp","i32"),i.addLocal("ps","i32"),i.addLocal("pd","i32"),i.addLocal("ncoefs","i32");const n=i.getCodeBuilder(),l=n.i32_const(t.alloc(o));i.addCode(n.setLocal("i",n.i32_const(0)),n.setLocal("pp",n.getLocal("ppolynomials")),n.setLocal("ps",n.getLocal("psignals")),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("i"),n.getLocal("nSignals"))),n.setLocal("ncoefs",n.i32_load(n.getLocal("pp"))),n.setLocal("pp",n.i32_add(n.getLocal("pp"),n.i32_const(4))),n.setLocal("j",n.i32_const(0)),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("j"),n.getLocal("ncoefs"))),n.setLocal("pd",n.i32_add(n.getLocal("pres"),n.i32_mul(n.i32_load(n.getLocal("pp")),n.i32_const(o)))),n.setLocal("pp",n.i32_add(n.getLocal("pp"),n.i32_const(4))),n.call(e+"_mul",n.getLocal("ps"),n.getLocal("pp"),l),n.call(e+"_add",l,n.getLocal("pd"),n.getLocal("pd")),n.setLocal("pp",n.i32_add(n.getLocal("pp"),n.i32_const(o))),n.setLocal("j",n.i32_add(n.getLocal("j"),n.i32_const(1))),n.br(0))),n.setLocal("ps",n.i32_add(n.getLocal("ps"),n.i32_const(o))),n.setLocal("i",n.i32_add(n.getLocal("i"),n.i32_const(1))),n.br(0))))}(),t.exportFunction(a+"_zero"),t.exportFunction(a+"_constructLC"),a},$t=function(t,a,e){const o=8*t.modules[e].n64;return function(){const i=t.addFunction(a+"_buildABC");i.addParam("pCoefs","i32"),i.addParam("nCoefs","i32"),i.addParam("pWitness","i32"),i.addParam("pA","i32"),i.addParam("pB","i32"),i.addParam("pC","i32"),i.addParam("offsetOut","i32"),i.addParam("nOut","i32"),i.addParam("offsetWitness","i32"),i.addParam("nWitness","i32"),i.addLocal("it","i32"),i.addLocal("ita","i32"),i.addLocal("itb","i32"),i.addLocal("last","i32"),i.addLocal("m","i32"),i.addLocal("c","i32"),i.addLocal("s","i32"),i.addLocal("pOut","i32");const n=i.getCodeBuilder(),l=n.i32_const(t.alloc(o));i.addCode(n.setLocal("ita",n.getLocal("pA")),n.setLocal("itb",n.getLocal("pB")),n.setLocal("last",n.i32_add(n.getLocal("pA"),n.i32_mul(n.getLocal("nOut"),n.i32_const(o)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(e+"_zero",n.getLocal("ita")),n.call(e+"_zero",n.getLocal("itb")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(o))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(o))),n.br(0))),n.setLocal("it",n.getLocal("pCoefs")),n.setLocal("last",n.i32_add(n.getLocal("pCoefs"),n.i32_mul(n.getLocal("nCoefs"),n.i32_const(o+12)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("it"),n.getLocal("last"))),n.setLocal("s",n.i32_load(n.getLocal("it"),8)),n.if(n.i32_or(n.i32_lt_u(n.getLocal("s"),n.getLocal("offsetWitness")),n.i32_ge_u(n.getLocal("s"),n.i32_add(n.getLocal("offsetWitness"),n.getLocal("nWitness")))),[...n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(o+12))),...n.br(1)]),n.setLocal("m",n.i32_load(n.getLocal("it"))),n.if(n.i32_eq(n.getLocal("m"),n.i32_const(0)),n.setLocal("pOut",n.getLocal("pA")),n.if(n.i32_eq(n.getLocal("m"),n.i32_const(1)),n.setLocal("pOut",n.getLocal("pB")),[...n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(o+12))),...n.br(1)])),n.setLocal("c",n.i32_load(n.getLocal("it"),4)),n.if(n.i32_or(n.i32_lt_u(n.getLocal("c"),n.getLocal("offsetOut")),n.i32_ge_u(n.getLocal("c"),n.i32_add(n.getLocal("offsetOut"),n.getLocal("nOut")))),[...n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(o+12))),...n.br(1)]),n.setLocal("pOut",n.i32_add(n.getLocal("pOut"),n.i32_mul(n.i32_sub(n.getLocal("c"),n.getLocal("offsetOut")),n.i32_const(o)))),n.call(e+"_mul",n.i32_add(n.getLocal("pWitness"),n.i32_mul(n.i32_sub(n.getLocal("s"),n.getLocal("offsetWitness")),n.i32_const(o))),n.i32_add(n.getLocal("it"),n.i32_const(12)),l),n.call(e+"_add",n.getLocal("pOut"),l,n.getLocal("pOut")),n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(o+12))),n.br(0))),n.setLocal("ita",n.getLocal("pA")),n.setLocal("itb",n.getLocal("pB")),n.setLocal("it",n.getLocal("pC")),n.setLocal("last",n.i32_add(n.getLocal("pA"),n.i32_mul(n.getLocal("nOut"),n.i32_const(o)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(e+"_mul",n.getLocal("ita"),n.getLocal("itb"),n.getLocal("it")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(o))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(o))),n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(o))),n.br(0))))}(),function(){const i=t.addFunction(a+"_joinABC");i.addParam("pA","i32"),i.addParam("pB","i32"),i.addParam("pC","i32"),i.addParam("n","i32"),i.addParam("pP","i32"),i.addLocal("ita","i32"),i.addLocal("itb","i32"),i.addLocal("itc","i32"),i.addLocal("itp","i32"),i.addLocal("last","i32");const n=i.getCodeBuilder(),l=n.i32_const(t.alloc(o));i.addCode(n.setLocal("ita",n.getLocal("pA")),n.setLocal("itb",n.getLocal("pB")),n.setLocal("itc",n.getLocal("pC")),n.setLocal("itp",n.getLocal("pP")),n.setLocal("last",n.i32_add(n.getLocal("pA"),n.i32_mul(n.getLocal("n"),n.i32_const(o)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(e+"_mul",n.getLocal("ita"),n.getLocal("itb"),l),n.call(e+"_sub",l,n.getLocal("itc"),n.getLocal("itp")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(o))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(o))),n.setLocal("itc",n.i32_add(n.getLocal("itc"),n.i32_const(o))),n.setLocal("itp",n.i32_add(n.getLocal("itp"),n.i32_const(o))),n.br(0))))}(),function(){const i=t.addFunction(a+"_batchAdd");i.addParam("pa","i32"),i.addParam("pb","i32"),i.addParam("n","i32"),i.addParam("pr","i32"),i.addLocal("ita","i32"),i.addLocal("itb","i32"),i.addLocal("itr","i32"),i.addLocal("last","i32");const n=i.getCodeBuilder();i.addCode(n.setLocal("ita",n.getLocal("pa")),n.setLocal("itb",n.getLocal("pb")),n.setLocal("itr",n.getLocal("pr")),n.setLocal("last",n.i32_add(n.getLocal("pa"),n.i32_mul(n.getLocal("n"),n.i32_const(o)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(e+"_add",n.getLocal("ita"),n.getLocal("itb"),n.getLocal("itr")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(o))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(o))),n.setLocal("itr",n.i32_add(n.getLocal("itr"),n.i32_const(o))),n.br(0))))}(),t.exportFunction(a+"_buildABC"),t.exportFunction(a+"_joinABC"),t.exportFunction(a+"_batchAdd"),a},jt=function(t,a,e,o,i,n,l,c){const s=t.addFunction(a);s.addParam("pIn","i32"),s.addParam("n","i32"),s.addParam("pFirst","i32"),s.addParam("pInc","i32"),s.addParam("pOut","i32"),s.addLocal("pOldFree","i32"),s.addLocal("i","i32"),s.addLocal("pFrom","i32"),s.addLocal("pTo","i32");const r=s.getCodeBuilder(),d=r.i32_const(t.alloc(l));s.addCode(r.setLocal("pFrom",r.getLocal("pIn")),r.setLocal("pTo",r.getLocal("pOut"))),s.addCode(r.call(o+"_copy",r.getLocal("pFirst"),d)),s.addCode(r.setLocal("i",r.i32_const(0)),r.block(r.loop(r.br_if(1,r.i32_eq(r.getLocal("i"),r.getLocal("n"))),r.call(c,r.getLocal("pFrom"),d,r.getLocal("pTo")),r.setLocal("pFrom",r.i32_add(r.getLocal("pFrom"),r.i32_const(i))),r.setLocal("pTo",r.i32_add(r.getLocal("pTo"),r.i32_const(n))),r.call(o+"_mul",d,r.getLocal("pInc"),d),r.setLocal("i",r.i32_add(r.getLocal("i"),r.i32_const(1))),r.br(0)))),t.exportFunction(a)};const Vt=V,Kt=Ct,Ht=It,Zt=St,Wt=Ot,Yt=Mt,Jt=Nt,Xt=Dt,ta=$t,aa=jt,{bitLength:ea,modInv:oa,isOdd:ia,isNegative:na}=Y;const la=V,ca=Ct,sa=It,ra=St,da=Ot,ua=Mt,_a=Nt,ga=Dt,fa=$t,ha=jt,{bitLength:pa,isOdd:ma,isNegative:La}=Y;var ba=function(t,a){const e=a||"bn128";if(t.modules[e])return e;const o=21888242871839275222246405745257275088696311157297823662689037894645226208583n,i=21888242871839275222246405745257275088548364400416034343698204186575808495617n,n=Math.floor((ea(o-1n)-1)/64)+1,l=8*n,c=l,s=l,r=2*s,d=12*s,u=t.alloc(Vt.bigInt2BytesLE(i,c)),_=Kt(t,o,"f1m");Ht(t,i,"fr","frm");const g=t.alloc(Vt.bigInt2BytesLE(b(3n),s)),f=Yt(t,"g1m","f1m",g);Jt(t,"frm","frm","frm","frm_mul"),Xt(t,"pol","frm"),ta(t,"qap","frm");const h=Zt(t,"f1m_neg","f2m","f1m"),p=t.alloc([...Vt.bigInt2BytesLE(b(19485874751759354771024239261021720505790618469301721065564631296452457478373n),s),...Vt.bigInt2BytesLE(b(266929791119991161246907387137283842545076965332900288569378510910307636690n),s)]),m=Yt(t,"g2m","f2m",p);function L(a,e){const o=t.addFunction(a);o.addParam("pG","i32"),o.addParam("pFr","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),n=i.i32_const(t.alloc(l));o.addCode(i.call("frm_fromMontgomery",i.getLocal("pFr"),n),i.call(e,i.getLocal("pG"),n,i.i32_const(l),i.getLocal("pr"))),t.exportFunction(a)}function b(t){return BigInt(t)*(1n<0n;)ia(a)?e.push(1):e.push(0),a>>=1n;return e}(29793968203157093288n),T=t.alloc(z),M=3*r,U=z.length-1,Q=z.reduce(((t,a)=>t+(0!=a?1:0)),0),k=6*l,R=3*l*2+(Q+U+1)*M;t.modules[e]={n64:n,pG1gen:y,pG1zero:C,pG1b:g,pG2gen:x,pG2zero:B,pG2b:p,pq:t.modules.f1m.pq,pr:u,pOneT:E,prePSize:k,preQSize:R,r:i.toString(),q:o.toString()};const N=4965661367192848881n;function D(a){const i=[[[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n]],[[1n,0n],[8376118865763821496583973867626364092589906065868298776909617916018768340080n,16469823323077808223889137241176536799009286646108169935659301613961712198316n],[21888242871839275220042445260109153167277707414472061641714758635765020556617n,0n],[11697423496358154304825782922584725312912383441159505038794027105778954184319n,303847389135065887422783454877609941456349188919719272345083954437860409601n],[21888242871839275220042445260109153167277707414472061641714758635765020556616n,0n],[3321304630594332808241809054958361220322477375291206261884409189760185844239n,5722266937896532885780051958958348231143373700109372999374820235121374419868n],[21888242871839275222246405745257275088696311157297823662689037894645226208582n,0n],[13512124006075453725662431877630910996106405091429524885779419978626457868503n,5418419548761466998357268504080738289687024511189653727029736280683514010267n],[2203960485148121921418603742825762020974279258880205651966n,0n],[10190819375481120917420622822672549775783927716138318623895010788866272024264n,21584395482704209334823622290379665147239961968378104390343953940207365798982n],[2203960485148121921418603742825762020974279258880205651967n,0n],[18566938241244942414004596690298913868373833782006617400804628704885040364344n,16165975933942742336466353786298926857552937457188450663314217659523851788715n]]],n=[[[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n]],[[1n,0n],[21575463638280843010398324269430826099269044274347216827212613867836435027261n,10307601595873709700152284273816112264069230130616436755625194854815875713954n],[21888242871839275220042445260109153167277707414472061641714758635765020556616n,0n],[3772000881919853776433695186713858239009073593817195771773381919316419345261n,2236595495967245188281701248203181795121068902605861227855261137820944008926n],[2203960485148121921418603742825762020974279258880205651966n,0n],[18429021223477853657660792034369865839114504446431234726392080002137598044644n,9344045779998320333812420223237981029506012124075525679208581902008406485703n]],[[1n,0n],[2581911344467009335267311115468803099551665605076196740867805258568234346338n,19937756971775647987995932169929341994314640652964949448313374472400716661030n],[2203960485148121921418603742825762020974279258880205651966n,0n],[5324479202449903542726783395506214481928257762400643279780343368557297135718n,16208900380737693084919495127334387981393726419856888799917914180988844123039n],[21888242871839275220042445260109153167277707414472061641714758635765020556616n,0n],[13981852324922362344252311234282257507216387789820983642040889267519694726527n,7629828391165209371577384193250820201684255241773809077146787135900891633097n]]],l=t.addFunction(e+"__frobeniusMap"+a);l.addParam("x","i32"),l.addParam("r","i32");const c=l.getCodeBuilder();for(let e=0;e<6;e++){const o=0==e?c.getLocal("x"):c.i32_add(c.getLocal("x"),c.i32_const(e*r)),u=o,g=c.i32_add(c.getLocal("x"),c.i32_const(e*r+s)),f=0==e?c.getLocal("r"):c.i32_add(c.getLocal("r"),c.i32_const(e*r)),p=f,m=c.i32_add(c.getLocal("r"),c.i32_const(e*r+s)),L=d(i[Math.floor(e/3)][a%12],n[e%3][a%6]),w=t.alloc([...Vt.bigInt2BytesLE(b(L[0]),32),...Vt.bigInt2BytesLE(b(L[1]),32)]);a%2==1?l.addCode(c.call(_+"_copy",u,p),c.call(_+"_neg",g,m),c.call(h+"_mul",f,c.i32_const(w),f)):l.addCode(c.call(h+"_mul",o,c.i32_const(w),f))}function d(t,a){const e=BigInt(t[0]),i=BigInt(t[1]),n=BigInt(a[0]),l=BigInt(a[1]),c=[(e*n-i*l)%o,(e*l+i*n)%o];return na(c[0])&&(c[0]=c[0]+o),c}}function $(a,o){const i=function(t){let a=t;const e=[];for(;a>0n;){if(ia(a)){const t=2-Number(a%4n);e.push(t),a-=BigInt(t)}else e.push(0);a>>=1n}return e}(a).map((t=>-1==t?255:t)),n=t.alloc(i),l=t.addFunction(e+"__cyclotomicExp_"+o);l.addParam("x","i32"),l.addParam("r","i32"),l.addLocal("bit","i32"),l.addLocal("i","i32");const c=l.getCodeBuilder(),s=c.getLocal("x"),r=c.getLocal("r"),u=c.i32_const(t.alloc(d));l.addCode(c.call(G+"_conjugate",s,u),c.call(G+"_one",r),c.if(c.teeLocal("bit",c.i32_load8_s(c.i32_const(i.length-1),n)),c.if(c.i32_eq(c.getLocal("bit"),c.i32_const(1)),c.call(G+"_mul",r,s,r),c.call(G+"_mul",r,u,r))),c.setLocal("i",c.i32_const(i.length-2)),c.block(c.loop(c.call(e+"__cyclotomicSquare",r,r),c.if(c.teeLocal("bit",c.i32_load8_s(c.getLocal("i"),n)),c.if(c.i32_eq(c.getLocal("bit"),c.i32_const(1)),c.call(G+"_mul",r,s,r),c.call(G+"_mul",r,u,r))),c.br_if(1,c.i32_eqz(c.getLocal("i"))),c.setLocal("i",c.i32_sub(c.getLocal("i"),c.i32_const(1))),c.br(0))))}function j(){!function(){const a=t.addFunction(e+"__cyclotomicSquare");a.addParam("x","i32"),a.addParam("r","i32");const o=a.getCodeBuilder(),i=o.getLocal("x"),n=o.i32_add(o.getLocal("x"),o.i32_const(r)),l=o.i32_add(o.getLocal("x"),o.i32_const(2*r)),c=o.i32_add(o.getLocal("x"),o.i32_const(3*r)),s=o.i32_add(o.getLocal("x"),o.i32_const(4*r)),d=o.i32_add(o.getLocal("x"),o.i32_const(5*r)),u=o.getLocal("r"),_=o.i32_add(o.getLocal("r"),o.i32_const(r)),g=o.i32_add(o.getLocal("r"),o.i32_const(2*r)),f=o.i32_add(o.getLocal("r"),o.i32_const(3*r)),p=o.i32_add(o.getLocal("r"),o.i32_const(4*r)),m=o.i32_add(o.getLocal("r"),o.i32_const(5*r)),L=o.i32_const(t.alloc(r)),b=o.i32_const(t.alloc(r)),w=o.i32_const(t.alloc(r)),y=o.i32_const(t.alloc(r)),A=o.i32_const(t.alloc(r)),C=o.i32_const(t.alloc(r)),F=o.i32_const(t.alloc(r)),x=o.i32_const(t.alloc(r));a.addCode(o.call(h+"_mul",i,s,F),o.call(h+"_mul",s,o.i32_const(v),L),o.call(h+"_add",i,L,L),o.call(h+"_add",i,s,x),o.call(h+"_mul",x,L,L),o.call(h+"_mul",o.i32_const(v),F,x),o.call(h+"_add",F,x,x),o.call(h+"_sub",L,x,L),o.call(h+"_add",F,F,b),o.call(h+"_mul",c,l,F),o.call(h+"_mul",l,o.i32_const(v),w),o.call(h+"_add",c,w,w),o.call(h+"_add",c,l,x),o.call(h+"_mul",x,w,w),o.call(h+"_mul",o.i32_const(v),F,x),o.call(h+"_add",F,x,x),o.call(h+"_sub",w,x,w),o.call(h+"_add",F,F,y),o.call(h+"_mul",n,d,F),o.call(h+"_mul",d,o.i32_const(v),A),o.call(h+"_add",n,A,A),o.call(h+"_add",n,d,x),o.call(h+"_mul",x,A,A),o.call(h+"_mul",o.i32_const(v),F,x),o.call(h+"_add",F,x,x),o.call(h+"_sub",A,x,A),o.call(h+"_add",F,F,C),o.call(h+"_sub",L,i,u),o.call(h+"_add",u,u,u),o.call(h+"_add",L,u,u),o.call(h+"_add",b,s,p),o.call(h+"_add",p,p,p),o.call(h+"_add",b,p,p),o.call(h+"_mul",C,o.i32_const(P),x),o.call(h+"_add",x,c,f),o.call(h+"_add",f,f,f),o.call(h+"_add",x,f,f),o.call(h+"_sub",A,l,g),o.call(h+"_add",g,g,g),o.call(h+"_add",A,g,g),o.call(h+"_sub",w,n,_),o.call(h+"_add",_,_,_),o.call(h+"_add",w,_,_),o.call(h+"_add",y,d,m),o.call(h+"_add",m,m,m),o.call(h+"_add",y,m,m))}(),$(N,"w0");const a=t.addFunction(e+"__finalExponentiationLastChunk");a.addParam("x","i32"),a.addParam("r","i32");const o=a.getCodeBuilder(),i=o.getLocal("x"),n=o.getLocal("r"),l=o.i32_const(t.alloc(d)),c=o.i32_const(t.alloc(d)),s=o.i32_const(t.alloc(d)),u=o.i32_const(t.alloc(d)),_=o.i32_const(t.alloc(d)),g=o.i32_const(t.alloc(d)),f=o.i32_const(t.alloc(d)),p=o.i32_const(t.alloc(d)),m=o.i32_const(t.alloc(d)),L=o.i32_const(t.alloc(d)),b=o.i32_const(t.alloc(d)),w=o.i32_const(t.alloc(d)),y=o.i32_const(t.alloc(d)),A=o.i32_const(t.alloc(d)),C=o.i32_const(t.alloc(d)),F=o.i32_const(t.alloc(d)),x=o.i32_const(t.alloc(d)),I=o.i32_const(t.alloc(d)),B=o.i32_const(t.alloc(d)),E=o.i32_const(t.alloc(d)),S=o.i32_const(t.alloc(d));a.addCode(o.call(e+"__cyclotomicExp_w0",i,l),o.call(G+"_conjugate",l,l),o.call(e+"__cyclotomicSquare",l,c),o.call(e+"__cyclotomicSquare",c,s),o.call(G+"_mul",s,c,u),o.call(e+"__cyclotomicExp_w0",u,_),o.call(G+"_conjugate",_,_),o.call(e+"__cyclotomicSquare",_,g),o.call(e+"__cyclotomicExp_w0",g,f),o.call(G+"_conjugate",f,f),o.call(G+"_conjugate",u,p),o.call(G+"_conjugate",f,m),o.call(G+"_mul",m,_,L),o.call(G+"_mul",L,p,b),o.call(G+"_mul",b,c,w),o.call(G+"_mul",b,_,y),o.call(G+"_mul",y,i,A),o.call(e+"__frobeniusMap1",w,C),o.call(G+"_mul",C,A,F),o.call(e+"__frobeniusMap2",b,x),o.call(G+"_mul",x,F,I),o.call(G+"_conjugate",i,B),o.call(G+"_mul",B,w,E),o.call(e+"__frobeniusMap3",E,S),o.call(G+"_mul",S,I,n))}const V=t.alloc(k),K=t.alloc(R);function H(a){const o=t.addFunction(e+"_pairingEq"+a);for(let t=0;t0n;)ma(a)?e.push(1):e.push(0),a>>=1n;return e}(0xd201000000010000n),z=t.alloc(G),T=3*s,M=G.length-1,U=G.reduce(((t,a)=>t+(0!=a?1:0)),0),Q=6*l,k=3*l*2+(U+M+1)*T,R=15132376222941642752n;function N(a){const e=[[[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n]],[[1n,0n],[3850754370037169011952147076051364057158807420970682438676050522613628423219637725072182697113062777891589506424760n,151655185184498381465642749684540099398075398968325446656007613510403227271200139370504932015952886146304766135027n],[793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620351n,0n],[2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530n,1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257n],[793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350n,0n],[3125332594171059424908108096204648978570118281977575435832422631601824034463382777937621250592425535493320683825557n,877076961050607968509681729531255177986764537961432449499635504522207616027455086505066378536590128544573588734230n],[4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559786n,0n],[151655185184498381465642749684540099398075398968325446656007613510403227271200139370504932015952886146304766135027n,3850754370037169011952147076051364057158807420970682438676050522613628423219637725072182697113062777891589506424760n],[4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436n,0n],[1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257n,2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530n],[4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437n,0n],[877076961050607968509681729531255177986764537961432449499635504522207616027455086505066378536590128544573588734230n,3125332594171059424908108096204648978570118281977575435832422631601824034463382777937621250592425535493320683825557n]]],i=[[[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n]],[[1n,0n],[0n,4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436n],[793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350n,0n],[0n,1n],[4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436n,0n],[0n,793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350n]],[[1n,0n],[4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437n,0n],[4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436n,0n],[4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559786n,0n],[793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350n,0n],[793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620351n,0n]]],n=t.addFunction(O+"_frobeniusMap"+a);n.addParam("x","i32"),n.addParam("r","i32");const r=n.getCodeBuilder();for(let o=0;o<6;o++){const u=0==o?r.getLocal("x"):r.i32_add(r.getLocal("x"),r.i32_const(o*s)),_=u,g=r.i32_add(r.getLocal("x"),r.i32_const(o*s+c)),h=0==o?r.getLocal("r"):r.i32_add(r.getLocal("r"),r.i32_const(o*s)),p=h,L=r.i32_add(r.getLocal("r"),r.i32_const(o*s+c)),b=d(e[Math.floor(o/3)][a%12],i[o%3][a%6]),w=t.alloc([...la.bigInt2BytesLE(y(b[0]),l),...la.bigInt2BytesLE(y(b[1]),l)]);a%2==1?n.addCode(r.call(f+"_copy",_,p),r.call(f+"_neg",g,L),r.call(m+"_mul",h,r.i32_const(w),h)):n.addCode(r.call(m+"_mul",u,r.i32_const(w),h))}function d(t,a){const e=t[0],i=t[1],n=a[0],l=a[1],c=[(e*n-i*l)%o,(e*l+i*n)%o];return La(c[0])&&(c[0]=c[0]+o),c}}function D(a,o,i){const n=function(t){let a=t;const e=[];for(;a>0n;){if(ma(a)){const t=2-Number(a%4n);e.push(t),a-=BigInt(t)}else e.push(0);a>>=1n}return e}(a).map((t=>-1==t?255:t)),l=t.alloc(n),c=t.addFunction(e+"__cyclotomicExp_"+i);c.addParam("x","i32"),c.addParam("r","i32"),c.addLocal("bit","i32"),c.addLocal("i","i32");const s=c.getCodeBuilder(),d=s.getLocal("x"),u=s.getLocal("r"),_=s.i32_const(t.alloc(r));c.addCode(s.call(O+"_conjugate",d,_),s.call(O+"_one",u),s.if(s.teeLocal("bit",s.i32_load8_s(s.i32_const(n.length-1),l)),s.if(s.i32_eq(s.getLocal("bit"),s.i32_const(1)),s.call(O+"_mul",u,d,u),s.call(O+"_mul",u,_,u))),s.setLocal("i",s.i32_const(n.length-2)),s.block(s.loop(s.call(e+"__cyclotomicSquare",u,u),s.if(s.teeLocal("bit",s.i32_load8_s(s.getLocal("i"),l)),s.if(s.i32_eq(s.getLocal("bit"),s.i32_const(1)),s.call(O+"_mul",u,d,u),s.call(O+"_mul",u,_,u))),s.br_if(1,s.i32_eqz(s.getLocal("i"))),s.setLocal("i",s.i32_sub(s.getLocal("i"),s.i32_const(1))),s.br(0)))),o&&c.addCode(s.call(O+"_conjugate",u,u))}t.modules[e]={n64q:n,n64r:d,n8q:l,n8r:u,pG1gen:C,pG1zero:x,pG1b:h,pG2gen:B,pG2zero:v,pG2b:L,pq:t.modules.f1m.pq,pr:g,pOneT:S,r:i,q:o,prePSize:Q,preQSize:k},function(){const a=t.addFunction(q+"_mul1");a.addParam("pA","i32"),a.addParam("pC1","i32"),a.addParam("pR","i32");const e=a.getCodeBuilder(),o=e.getLocal("pA"),i=e.i32_add(e.getLocal("pA"),e.i32_const(2*c)),n=e.i32_add(e.getLocal("pA"),e.i32_const(4*c)),l=e.getLocal("pC1"),s=e.getLocal("pR"),r=e.i32_add(e.getLocal("pR"),e.i32_const(2*c)),d=e.i32_add(e.getLocal("pR"),e.i32_const(4*c)),u=e.i32_const(t.alloc(2*c)),_=e.i32_const(t.alloc(2*c));a.addCode(e.call(m+"_add",o,i,u),e.call(m+"_add",i,n,_),e.call(m+"_mul",i,l,d),e.call(m+"_mul",_,l,s),e.call(m+"_sub",s,d,s),e.call(m+"_mulNR",s,s),e.call(m+"_mul",u,l,r),e.call(m+"_sub",r,d,r))}(),function(){const a=t.addFunction(q+"_mul01");a.addParam("pA","i32"),a.addParam("pC0","i32"),a.addParam("pC1","i32"),a.addParam("pR","i32");const e=a.getCodeBuilder(),o=e.getLocal("pA"),i=e.i32_add(e.getLocal("pA"),e.i32_const(2*c)),n=e.i32_add(e.getLocal("pA"),e.i32_const(4*c)),l=e.getLocal("pC0"),s=e.getLocal("pC1"),r=e.getLocal("pR"),d=e.i32_add(e.getLocal("pR"),e.i32_const(2*c)),u=e.i32_add(e.getLocal("pR"),e.i32_const(4*c)),_=e.i32_const(t.alloc(2*c)),g=e.i32_const(t.alloc(2*c)),f=e.i32_const(t.alloc(2*c)),h=e.i32_const(t.alloc(2*c));a.addCode(e.call(m+"_mul",o,l,_),e.call(m+"_mul",i,s,g),e.call(m+"_add",o,i,f),e.call(m+"_add",o,n,h),e.call(m+"_add",i,n,r),e.call(m+"_mul",r,s,r),e.call(m+"_sub",r,g,r),e.call(m+"_mulNR",r,r),e.call(m+"_add",r,_,r),e.call(m+"_add",l,s,d),e.call(m+"_mul",d,f,d),e.call(m+"_sub",d,_,d),e.call(m+"_sub",d,g,d),e.call(m+"_mul",h,l,u),e.call(m+"_sub",u,_,u),e.call(m+"_add",u,g,u))}(),function(){const a=t.addFunction(O+"_mul014");a.addParam("pA","i32"),a.addParam("pC0","i32"),a.addParam("pC1","i32"),a.addParam("pC4","i32"),a.addParam("pR","i32");const e=a.getCodeBuilder(),o=e.getLocal("pA"),i=e.i32_add(e.getLocal("pA"),e.i32_const(6*c)),n=e.getLocal("pC0"),l=e.getLocal("pC1"),s=e.getLocal("pC4"),r=e.i32_const(t.alloc(6*c)),d=e.i32_const(t.alloc(6*c)),u=e.i32_const(t.alloc(2*c)),_=e.getLocal("pR"),g=e.i32_add(e.getLocal("pR"),e.i32_const(6*c));a.addCode(e.call(q+"_mul01",o,n,l,r),e.call(q+"_mul1",i,s,d),e.call(m+"_add",l,s,u),e.call(q+"_add",i,o,g),e.call(q+"_mul01",g,n,u,g),e.call(q+"_sub",g,r,g),e.call(q+"_sub",g,d,g),e.call(q+"_copy",d,_),e.call(q+"_mulNR",_,_),e.call(q+"_add",_,r,_))}(),function(){const a=t.addFunction(e+"_ell");a.addParam("pP","i32"),a.addParam("pCoefs","i32"),a.addParam("pF","i32");const o=a.getCodeBuilder(),i=o.getLocal("pP"),n=o.i32_add(o.getLocal("pP"),o.i32_const(l)),s=o.getLocal("pF"),r=o.getLocal("pCoefs"),d=o.i32_add(o.getLocal("pCoefs"),o.i32_const(c)),u=o.i32_add(o.getLocal("pCoefs"),o.i32_const(2*c)),_=o.i32_add(o.getLocal("pCoefs"),o.i32_const(3*c)),g=o.i32_add(o.getLocal("pCoefs"),o.i32_const(4*c)),h=t.alloc(2*c),p=o.i32_const(h),m=o.i32_const(h),L=o.i32_const(h+c),b=t.alloc(2*c),w=o.i32_const(b),y=o.i32_const(b),A=o.i32_const(b+c);a.addCode(o.call(f+"_mul",r,n,m),o.call(f+"_mul",d,n,L),o.call(f+"_mul",u,i,y),o.call(f+"_mul",_,i,A),o.call(O+"_mul014",s,g,w,p,s))}();const $=t.alloc(Q),j=t.alloc(k);function V(a){const o=t.addFunction(e+"_pairingEq"+a);for(let t=0;t>=BigInt(32)):l+2<=a?(n.setUint16(l,Number(e&BigInt(65535)),!0),l+=2,e>>=BigInt(16)):(n.setUint8(l,Number(e&BigInt(255)),!0),l+=1,e>>=BigInt(8));if(e)throw new Error("Number does not fit in this length");return o}const Aa=[];for(let t=0;t<256;t++)Aa[t]=Ca(t,8);function Ca(t,a){let e=0,o=t;for(let t=0;t>=1;return e}function Fa(t,a){return(Aa[t>>>24]|Aa[t>>>16&255]<<8|Aa[t>>>8&255]<<16|Aa[255&t]<<24)>>>32-a}function xa(t){return(0!=(4294901760&t)?(t&=4294901760,16):0)|(0!=(4278255360&t)?(t&=4278255360,8):0)|(0!=(4042322160&t)?(t&=4042322160,4):0)|(0!=(3435973836&t)?(t&=3435973836,2):0)|0!=(2863311530&t)}function Ia(t,a){const e=t.byteLength/a,o=xa(e);if(e!=1<e){const o=t.slice(i*a,(i+1)*a);t.set(t.slice(e*a,(e+1)*a),i*a),t.set(o,e*a)}}}function Ba(t,a){const e=new Uint8Array(a*t.length);for(let o=0;o0;)e>=4?(e-=4,a+=BigInt(i.getUint32(e))<=2?(e-=2,a+=BigInt(i.getUint16(e))<0;)n-4>=0?(n-=4,i.setUint32(n,Number(e&BigInt(4294967295))),e>>=BigInt(32)):n-2>=0?(n-=2,i.setUint16(n,Number(e&BigInt(65535))),e>>=BigInt(16)):(n-=1,i.setUint8(n,Number(e&BigInt(255))),e>>=BigInt(8));if(e)throw new Error("Number does not fit in this length");return o},bitReverse:Fa,buffReverseBits:Ia,buffer2array:Ea,leBuff2int:function(t){let a=BigInt(0),e=0;const o=new DataView(t.buffer,t.byteOffset,t.byteLength);for(;e{e[o]=t(a[o])})),e}return a},stringifyFElements:function t(a,e){if("bigint"==typeof e||void 0!==e.eq)return e.toString(10);if(e instanceof Uint8Array)return a.toString(a.e(e));if(Array.isArray(e))return e.map(t.bind(this,a));if("object"==typeof e){const o={};return Object.keys(e).forEach((i=>{o[i]=t(a,e[i])})),o}return e},unstringifyBigInts:function t(a){if("string"==typeof a&&/^[0-9]+$/.test(a))return BigInt(a);if("string"==typeof a&&/^0x[0-9a-fA-F]+$/.test(a))return BigInt(a);if(Array.isArray(a))return a.map(t);if("object"==typeof a){if(null===a)return null;const e={};return Object.keys(a).forEach((o=>{e[o]=t(a[o])})),e}return a},unstringifyFElements:function t(a,e){if("string"==typeof e&&/^[0-9]+$/.test(e))return a.e(e);if("string"==typeof e&&/^0x[0-9a-fA-F]+$/.test(e))return a.e(e);if(Array.isArray(e))return e.map(t.bind(this,a));if("object"==typeof e){if(null===e)return null;const o={};return Object.keys(e).forEach((i=>{o[i]=t(a,e[i])})),o}return e}});const Sa=1<<30;class Pa{constructor(t){this.buffers=[],this.byteLength=t;for(let a=0;a0;){const t=l+c>Sa?Sa-l:c,a=new Uint8Array(this.buffers[n].buffer,this.buffers[n].byteOffset+l,t);if(t==e)return a.slice();i||(i=e<=Sa?new Uint8Array(e):new Pa(e)),i.set(a,e-c),c-=t,n++,l=0}return i}set(t,a){void 0===a&&(a=0);const e=t.byteLength;if(0==e)return;const o=Math.floor(a/Sa);if(o==Math.floor((a+e-1)/Sa))return t instanceof Pa&&1==t.buffers.length?this.buffers[o].set(t.buffers[0],a%Sa):this.buffers[o].set(t,a%Sa);let i=o,n=a%Sa,l=e;for(;l>0;){const a=n+l>Sa?Sa-n:l,o=t.slice(e-l,e-l+a);new Uint8Array(this.buffers[i].buffer,this.buffers[i].byteOffset+n,a).set(o),l-=a,i++,n=0}}}function qa(t,a,e,o){return async function(i){const n=Math.floor(i.byteLength/e);if(n*e!==i.byteLength)throw new Error("Invalid buffer size");const l=Math.floor(n/t.concurrency),c=[];for(let s=0;s=0;t--)this.w[t]=this.square(this.w[t+1]);if(!this.eq(this.w[0],this.one))throw new Error("Error calculating roots of unity");this.batchToMontgomery=qa(t,a+"_batchToMontgomery",this.n8,this.n8),this.batchFromMontgomery=qa(t,a+"_batchFromMontgomery",this.n8,this.n8)}op2(t,a,e){return this.tm.setBuff(this.pOp1,a),this.tm.setBuff(this.pOp2,e),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op2Bool(t,a,e){return this.tm.setBuff(this.pOp1,a),this.tm.setBuff(this.pOp2,e),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2)}op1(t,a){return this.tm.setBuff(this.pOp1,a),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op1Bool(t,a){return this.tm.setBuff(this.pOp1,a),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3)}add(t,a){return this.op2("_add",t,a)}eq(t,a){return this.op2Bool("_eq",t,a)}isZero(t){return this.op1Bool("_isZero",t)}sub(t,a){return this.op2("_sub",t,a)}neg(t){return this.op1("_neg",t)}inv(t){return this.op1("_inverse",t)}toMontgomery(t){return this.op1("_toMontgomery",t)}fromMontgomery(t){return this.op1("_fromMontgomery",t)}mul(t,a){return this.op2("_mul",t,a)}div(t,a){return this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,a),this.tm.instance.exports[this.prefix+"_inverse"](this.pOp2,this.pOp2),this.tm.instance.exports[this.prefix+"_mul"](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}square(t){return this.op1("_square",t)}isSquare(t){return this.op1Bool("_isSquare",t)}sqrt(t){return this.op1("_sqrt",t)}exp(t,a){return a instanceof Uint8Array||(a=S(o(a))),this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,a),this.tm.instance.exports[this.prefix+"_exp"](this.pOp1,this.pOp2,a.byteLength,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}isNegative(t){return this.op1Bool("_isNegative",t)}e(t,a){if(t instanceof Uint8Array)return t;let e=o(t,a);n(e)?(e=p(e),A(e,this.p)&&(e=w(e,this.p)),e=h(this.p,e)):A(e,this.p)&&(e=w(e,this.p));const i=ya(e,this.n8);return this.toMontgomery(i)}toString(t,a){return v(B(this.fromMontgomery(t),0),a)}fromRng(t){let a;const e=new Uint8Array(this.n8);do{a=P;for(let e=0;e{this.reject=a,this.resolve=t}))}}var ka;const Ra="data:application/javascript;base64,"+(ka='(function thread(self) {\n const MAXMEM = 32767;\n let instance;\n let memory;\n\n if (self) {\n self.onmessage = function(e) {\n let data;\n if (e.data) {\n data = e.data;\n } else {\n data = e;\n }\n\n if (data[0].cmd == "INIT") {\n init(data[0]).then(function() {\n self.postMessage(data.result);\n });\n } else if (data[0].cmd == "TERMINATE") {\n self.close();\n } else {\n const res = runTask(data);\n self.postMessage(res);\n }\n };\n }\n\n async function init(data) {\n const code = new Uint8Array(data.code);\n const wasmModule = await WebAssembly.compile(code);\n memory = new WebAssembly.Memory({initial:data.init, maximum: MAXMEM});\n\n instance = await WebAssembly.instantiate(wasmModule, {\n env: {\n "memory": memory\n }\n });\n }\n\n\n\n function alloc(length) {\n const u32 = new Uint32Array(memory.buffer, 0, 1);\n while (u32[0] & 3) u32[0]++; // Return always aligned pointers\n const res = u32[0];\n u32[0] += length;\n if (u32[0] + length > memory.buffer.byteLength) {\n const currentPages = memory.buffer.byteLength / 0x10000;\n let requiredPages = Math.floor((u32[0] + length) / 0x10000)+1;\n if (requiredPages>MAXMEM) requiredPages=MAXMEM;\n memory.grow(requiredPages-currentPages);\n }\n return res;\n }\n\n function allocBuffer(buffer) {\n const p = alloc(buffer.byteLength);\n setBuffer(p, buffer);\n return p;\n }\n\n function getBuffer(pointer, length) {\n const u8 = new Uint8Array(memory.buffer);\n return new Uint8Array(u8.buffer, u8.byteOffset + pointer, length);\n }\n\n function setBuffer(pointer, buffer) {\n const u8 = new Uint8Array(memory.buffer);\n u8.set(new Uint8Array(buffer), pointer);\n }\n\n function runTask(task) {\n if (task[0].cmd == "INIT") {\n return init(task[0]);\n }\n const ctx = {\n vars: [],\n out: []\n };\n const u32a = new Uint32Array(memory.buffer, 0, 1);\n const oldAlloc = u32a[0];\n for (let i=0; io.buffer.byteLength){const i=o.buffer.byteLength/65536;let n=Math.floor((e[0]+t)/65536)+1;n>a&&(n=a),o.grow(n-i)}return i}function l(t){const a=n(t.byteLength);return s(a,t),a}function c(t,a){const e=new Uint8Array(o.buffer);return new Uint8Array(e.buffer,e.byteOffset+t,a)}function s(t,a){new Uint8Array(o.buffer).set(new Uint8Array(a),t)}function r(t){if("INIT"==t[0].cmd)return i(t[0]);const a={vars:[],out:[]},r=new Uint32Array(o.buffer,0,1)[0];for(let o=0;o64&&(a=64),e.concurrency=a;for(let t=0;t0;t++)if(0==this.working[t]){const a=this.actionQueue.shift();this.postAction(t,a.data,a.transfers,a.deferred)}}queueAction(t,a){const e=new Qa;if(this.singleThread){const a=this.taskManager(t);e.resolve(a)}else this.actionQueue.push({data:t,transfers:a,deferred:e}),this.processWorks();return e.promise}resetMemory(){this.u32[0]=this.initalPFree}allocBuff(t){const a=this.alloc(t.byteLength);return this.setBuff(a,t),a}getBuff(t,a){return this.u8.slice(t,t+a)}setBuff(t,a){this.u8.set(new Uint8Array(a),t)}alloc(t){for(;3&this.u32[0];)this.u32[0]++;const a=this.u32[0];return this.u32[0]+=t,a}async terminate(){for(let t=0;tsetTimeout(a,t))))}}function $a(t,a){const e=t[a],o=t.Fr,i=t.tm;t[a].batchApplyKey=async function(t,n,l,c,s){let r,d,u,_,g;if(c=c||"affine",s=s||"affine","G1"==a)"jacobian"==c?(u=3*e.F.n8,r="g1m_batchApplyKey"):(u=2*e.F.n8,r="g1m_batchApplyKeyMixed"),_=3*e.F.n8,"jacobian"==s?g=3*e.F.n8:(d="g1m_batchToAffine",g=2*e.F.n8);else if("G2"==a)"jacobian"==c?(u=3*e.F.n8,r="g2m_batchApplyKey"):(u=2*e.F.n8,r="g2m_batchApplyKeyMixed"),_=3*e.F.n8,"jacobian"==s?g=3*e.F.n8:(d="g2m_batchToAffine",g=2*e.F.n8);else{if("Fr"!=a)throw new Error("Invalid group: "+a);r="frm_batchApplyKey",u=e.n8,_=e.n8,g=e.n8}const f=Math.floor(t.byteLength/u),h=Math.floor(f/i.concurrency),p=[];l=o.e(l);let m=o.e(n);for(let a=0;a=0;t--){if(!e.isZero(h))for(let t=0;tr&&(h=r),h<1024&&(h=1024);const p=[];for(let a=0;a(c&&c.debug(`Multiexp end: ${s}: ${a}/${u}`),t))))}const m=await Promise.all(p);let L=e.zero;for(let t=m.length-1;t>=0;t--)L=e.add(L,m[t]);return L}e.multiExp=async function(t,a,e,o){return await n(t,a,"jacobian",e,o)},e.multiExpAffine=async function(t,a,e,o){return await n(t,a,"affine",e,o)}}function Ka(t,a){const e=t[a],o=t.Fr,i=e.tm;async function n(t,c,s,r,d,u){s=s||"affine",r=r||"affine";let _,g,f,h,p,m,L,b;"G1"==a?("affine"==s?(_=2*e.F.n8,h="g1m_batchToJacobian"):_=3*e.F.n8,g=3*e.F.n8,c&&(b="g1m_fftFinal"),L="g1m_fftJoin",m="g1m_fftMix","affine"==r?(f=2*e.F.n8,p="g1m_batchToAffine"):f=3*e.F.n8):"G2"==a?("affine"==s?(_=2*e.F.n8,h="g2m_batchToJacobian"):_=3*e.F.n8,g=3*e.F.n8,c&&(b="g2m_fftFinal"),L="g2m_fftJoin",m="g2m_fftMix","affine"==r?(f=2*e.F.n8,p="g2m_batchToAffine"):f=3*e.F.n8):"Fr"==a&&(_=e.n8,g=e.n8,f=e.n8,c&&(b="frm_fftFinal"),m="frm_fftMix",L="frm_fftJoin");let w=!1;Array.isArray(t)?(t=Ba(t,_),w=!0):t=t.slice(0,t.byteLength);const y=t.byteLength/_,A=xa(y);if(1<1<<28?new Pa(2*u[0].byteLength):new Uint8Array(2*u[0].byteLength);return _.set(u[0]),_.set(u[1],u[0].byteLength),_}(t,s,r,d,u):await async function(t,a,e,i,c){let s,r;s=t.slice(0,t.byteLength/2),r=t.slice(t.byteLength/2,t.byteLength);const d=[];[s,r]=await l(s,r,"fftJoinExt",o.one,o.shift,a,"jacobian",i,c),d.push(n(s,!1,"jacobian",e,i,c)),d.push(n(r,!1,"jacobian",e,i,c));const u=await Promise.all(d);let _;_=u[0].byteLength>1<<28?new Pa(2*u[0].byteLength):new Uint8Array(2*u[0].byteLength);return _.set(u[0]),_.set(u[1],u[0].byteLength),_}(t,s,r,d,u),w?Ea(a,f):a}let C,F,x;c&&(C=o.inv(o.e(y))),Ia(t,_);let I=Math.min(16384,y),B=y/I;for(;B=16;)B*=2,I/=2;const E=xa(I),v=[];for(let a=0;a(d&&d.debug(`${u}: fft ${A} mix end: ${a}/${B}`),t))))}x=await Promise.all(v);for(let t=0;t(d&&d.debug(`${u}: fft ${A} join ${t}/${A} ${l+1}/${a} ${c}/${e/2}`),o))))}const l=await Promise.all(n);for(let t=0;t0;a--)F.set(x[a],t),t+=I*f,delete x[a];F.set(x[0].slice(0,(I-1)*f),t),delete x[0]}else for(let t=0;t65536&&(w=65536);const y=[];for(let a=0;a(u&&u.debug(`${_}: fftJoinExt End: ${a}/${b}`),t))))}const A=await Promise.all(y);let C,F;b*p>1<<28?(C=new Pa(b*p),F=new Pa(b*p)):(C=new Uint8Array(b*p),F=new Uint8Array(b*p));let x=0;for(let t=0;to.s+1)throw s&&s.error("lagrangeEvaluations input too big"),new Error("lagrangeEvaluations input too big");let g=t.slice(0,t.byteLength/2),f=t.slice(t.byteLength/2,t.byteLength);const h=o.exp(o.shift,u/2),p=o.inv(o.sub(o.one,h));[g,f]=await l(g,f,"prepareLagrangeEvaluation",p,o.shiftInv,i,"jacobian",s,r+" prep");const m=[];let L;return m.push(n(g,!0,"jacobian",c,s,r+" t0")),m.push(n(f,!0,"jacobian",c,s,r+" t1")),[g,f]=await Promise.all(m),L=g.byteLength>1<<28?new Pa(2*g.byteLength):new Uint8Array(2*g.byteLength),L.set(g),L.set(f,g.byteLength),L},e.fftMix=async function(t){const n=3*e.F.n8;let l,c;if("G1"==a)l="g1m_fftMix",c="g1m_fftJoin";else if("G2"==a)l="g2m_fftMix",c="g2m_fftJoin";else{if("Fr"!=a)throw new Error("Invalid group");l="frm_fftMix",c="frm_fftJoin"}const s=Math.floor(t.byteLength/n),r=xa(s);let d=1<=0;t--)g.set(_[t][0],f),f+=_[t][0].byteLength;return g}}async function Ha(t){const a=await Na(t.wasm,t.singleThread),e={};return e.q=o(t.wasm.q.toString()),e.r=o(t.wasm.r.toString()),e.name=t.name,e.tm=a,e.prePSize=t.wasm.prePSize,e.preQSize=t.wasm.preQSize,e.Fr=new Oa(a,"frm",t.n8r,t.r),e.F1=new Oa(a,"f1m",t.n8q,t.q),e.F2=new Ga(a,"f2m",e.F1),e.G1=new Ta(a,"g1m",e.F1,t.wasm.pG1gen,t.wasm.pG1b,t.cofactorG1),e.G2=new Ta(a,"g2m",e.F2,t.wasm.pG2gen,t.wasm.pG2b,t.cofactorG2),e.F6=new za(a,"f6m",e.F2),e.F12=new Ga(a,"ftm",e.F6),e.Gt=e.F12,$a(e,"G1"),$a(e,"G2"),$a(e,"Fr"),Va(e,"G1"),Va(e,"G2"),Ka(e,"G1"),Ka(e,"G2"),Ka(e,"Fr"),function(t){const a=t.tm;t.pairing=function(e,o){a.startSyncOp();const i=a.allocBuff(t.G1.toJacobian(e)),n=a.allocBuff(t.G2.toJacobian(o)),l=a.alloc(t.Gt.n8);a.instance.exports[t.name+"_pairing"](i,n,l);const c=a.getBuff(l,t.Gt.n8);return a.endSyncOp(),c},t.pairingEq=async function(){let e,o;arguments.length%2==1?(e=arguments[arguments.length-1],o=(arguments.length-1)/2):(e=t.Gt.one,o=arguments.length/2);const i=[];for(let e=0;e>8n&0xFFn)),a.push(Number(e>>16n&0xFFn)),a.push(Number(e>>24n&0xFFn)),a}function Xa(t){const a=function(t){for(var a=[],e=0;e>6,128|63&o):o<55296||o>=57344?a.push(224|o>>12,128|o>>6&63,128|63&o):(e++,o=65536+((1023&o)<<10|1023&t.charCodeAt(e)),a.push(240|o>>18,128|o>>12&63,128|o>>6&63,128|63&o))}return a}(t);return[...ie(a.length),...a]}function te(t){const a=[];let e=Za(t);if(Wa(e))throw new Error("Number cannot be negative");for(;!Ya(e);)a.push(Number(0x7Fn&e)),e>>=7n;0==a.length&&a.push(0);for(let t=0;t0xFFFFFFFFn)throw new Error("Number too big");if(a>0x7FFFFFFFn&&(a-=0x100000000n),a<-2147483648n)throw new Error("Number too small");return ae(a)}function oe(t){let a=Za(t);if(a>0xFFFFFFFFFFFFFFFFn)throw new Error("Number too big");if(a>0x7FFFFFFFFFFFFFFFn&&(a-=0x10000000000000000n),a<-9223372036854775808n)throw new Error("Number too small");return ae(a)}function ie(t){let a=Za(t);if(a>0xFFFFFFFFn)throw new Error("Number too big");return te(a)}function ne(t){return Array.from(t,(function(t){return("0"+(255&t).toString(16)).slice(-2)})).join("")}class le{constructor(t){this.func=t,this.functionName=t.functionName,this.module=t.module}setLocal(t,a){const e=this.func.localIdxByName[t];if(void 0===e)throw new Error(`Local Variable not defined: Function: ${this.functionName} local: ${t} `);return[...a,33,...ie(e)]}teeLocal(t,a){const e=this.func.localIdxByName[t];if(void 0===e)throw new Error(`Local Variable not defined: Function: ${this.functionName} local: ${t} `);return[...a,34,...ie(e)]}getLocal(t){const a=this.func.localIdxByName[t];if(void 0===a)throw new Error(`Local Variable not defined: Function: ${this.functionName} local: ${t} `);return[32,...ie(a)]}i64_load8_s(t,a,e){return[...t,48,void 0===e?0:e,...ie(a||0)]}i64_load8_u(t,a,e){return[...t,49,void 0===e?0:e,...ie(a||0)]}i64_load16_s(t,a,e){return[...t,50,void 0===e?1:e,...ie(a||0)]}i64_load16_u(t,a,e){return[...t,51,void 0===e?1:e,...ie(a||0)]}i64_load32_s(t,a,e){return[...t,52,void 0===e?2:e,...ie(a||0)]}i64_load32_u(t,a,e){return[...t,53,void 0===e?2:e,...ie(a||0)]}i64_load(t,a,e){return[...t,41,void 0===e?3:e,...ie(a||0)]}i64_store(t,a,e,o){let i,n,l;return Array.isArray(a)?(i=0,n=3,l=a):Array.isArray(e)?(i=a,n=3,l=e):Array.isArray(o)&&(i=a,n=e,l=o),[...t,...l,55,n,...ie(i)]}i64_store32(t,a,e,o){let i,n,l;return Array.isArray(a)?(i=0,n=2,l=a):Array.isArray(e)?(i=a,n=2,l=e):Array.isArray(o)&&(i=a,n=e,l=o),[...t,...l,62,n,...ie(i)]}i64_store16(t,a,e,o){let i,n,l;return Array.isArray(a)?(i=0,n=1,l=a):Array.isArray(e)?(i=a,n=1,l=e):Array.isArray(o)&&(i=a,n=e,l=o),[...t,...l,61,n,...ie(i)]}i64_store8(t,a,e,o){let i,n,l;return Array.isArray(a)?(i=0,n=0,l=a):Array.isArray(e)?(i=a,n=0,l=e):Array.isArray(o)&&(i=a,n=e,l=o),[...t,...l,60,n,...ie(i)]}i32_load8_s(t,a,e){return[...t,44,void 0===e?0:e,...ie(a||0)]}i32_load8_u(t,a,e){return[...t,45,void 0===e?0:e,...ie(a||0)]}i32_load16_s(t,a,e){return[...t,46,void 0===e?1:e,...ie(a||0)]}i32_load16_u(t,a,e){return[...t,47,void 0===e?1:e,...ie(a||0)]}i32_load(t,a,e){return[...t,40,void 0===e?2:e,...ie(a||0)]}i32_store(t,a,e,o){let i,n,l;return Array.isArray(a)?(i=0,n=2,l=a):Array.isArray(e)?(i=a,n=2,l=e):Array.isArray(o)&&(i=a,n=e,l=o),[...t,...l,54,n,...ie(i)]}i32_store16(t,a,e,o){let i,n,l;return Array.isArray(a)?(i=0,n=1,l=a):Array.isArray(e)?(i=a,n=1,l=e):Array.isArray(o)&&(i=a,n=e,l=o),[...t,...l,59,n,...ie(i)]}i32_store8(t,a,e,o){let i,n,l;return Array.isArray(a)?(i=0,n=0,l=a):Array.isArray(e)?(i=a,n=0,l=e):Array.isArray(o)&&(i=a,n=e,l=o),[...t,...l,58,n,...ie(i)]}call(t,...a){const e=this.module.functionIdxByName[t];if(void 0===e)throw new Error(`Function not defined: Function: ${t}`);return[...[].concat(...a),16,...ie(e)]}call_indirect(t,...a){return[...[].concat(...a),...t,17,0,0]}if(t,a,e){return e?[...t,4,64,...a,5,...e,11]:[...t,4,64,...a,11]}block(t){return[2,64,...t,11]}loop(...t){return[3,64,...[].concat(...t),11]}br_if(t,a){return[...a,13,...ie(t)]}br(t){return[12,...ie(t)]}ret(t){return[...t,15]}drop(t){return[...t,26]}i64_const(t){return[66,...oe(t)]}i32_const(t){return[65,...ee(t)]}i64_eqz(t){return[...t,80]}i64_eq(t,a){return[...t,...a,81]}i64_ne(t,a){return[...t,...a,82]}i64_lt_s(t,a){return[...t,...a,83]}i64_lt_u(t,a){return[...t,...a,84]}i64_gt_s(t,a){return[...t,...a,85]}i64_gt_u(t,a){return[...t,...a,86]}i64_le_s(t,a){return[...t,...a,87]}i64_le_u(t,a){return[...t,...a,88]}i64_ge_s(t,a){return[...t,...a,89]}i64_ge_u(t,a){return[...t,...a,90]}i64_add(t,a){return[...t,...a,124]}i64_sub(t,a){return[...t,...a,125]}i64_mul(t,a){return[...t,...a,126]}i64_div_s(t,a){return[...t,...a,127]}i64_div_u(t,a){return[...t,...a,128]}i64_rem_s(t,a){return[...t,...a,129]}i64_rem_u(t,a){return[...t,...a,130]}i64_and(t,a){return[...t,...a,131]}i64_or(t,a){return[...t,...a,132]}i64_xor(t,a){return[...t,...a,133]}i64_shl(t,a){return[...t,...a,134]}i64_shr_s(t,a){return[...t,...a,135]}i64_shr_u(t,a){return[...t,...a,136]}i64_extend_i32_s(t){return[...t,172]}i64_extend_i32_u(t){return[...t,173]}i64_clz(t){return[...t,121]}i64_ctz(t){return[...t,122]}i32_eqz(t){return[...t,69]}i32_eq(t,a){return[...t,...a,70]}i32_ne(t,a){return[...t,...a,71]}i32_lt_s(t,a){return[...t,...a,72]}i32_lt_u(t,a){return[...t,...a,73]}i32_gt_s(t,a){return[...t,...a,74]}i32_gt_u(t,a){return[...t,...a,75]}i32_le_s(t,a){return[...t,...a,76]}i32_le_u(t,a){return[...t,...a,77]}i32_ge_s(t,a){return[...t,...a,78]}i32_ge_u(t,a){return[...t,...a,79]}i32_add(t,a){return[...t,...a,106]}i32_sub(t,a){return[...t,...a,107]}i32_mul(t,a){return[...t,...a,108]}i32_div_s(t,a){return[...t,...a,109]}i32_div_u(t,a){return[...t,...a,110]}i32_rem_s(t,a){return[...t,...a,111]}i32_rem_u(t,a){return[...t,...a,112]}i32_and(t,a){return[...t,...a,113]}i32_or(t,a){return[...t,...a,114]}i32_xor(t,a){return[...t,...a,115]}i32_shl(t,a){return[...t,...a,116]}i32_shr_s(t,a){return[...t,...a,117]}i32_shr_u(t,a){return[...t,...a,118]}i32_rotl(t,a){return[...t,...a,119]}i32_rotr(t,a){return[...t,...a,120]}i32_wrap_i64(t){return[...t,167]}i32_clz(t){return[...t,103]}i32_ctz(t){return[...t,104]}unreachable(){return[0]}current_memory(){return[63,0]}comment(){return[]}}const ce={i32:127,i64:126,f32:125,f64:124,anyfunc:112,func:96,emptyblock:64};class se{constructor(t,a,e,o,i){if("import"==e)this.fnType="import",this.moduleName=o,this.fieldName=i;else{if("internal"!=e)throw new Error("Invalid function fnType: "+e);this.fnType="internal"}this.module=t,this.fnName=a,this.params=[],this.locals=[],this.localIdxByName={},this.code=[],this.returnType=null,this.nextLocal=0}addParam(t,a){if(this.localIdxByName[t])throw new Error(`param already exists. Function: ${this.fnName}, Param: ${t} `);const e=this.nextLocal++;this.localIdxByName[t]=e,this.params.push({type:a})}addLocal(t,a,e){const o=e||1;if(this.localIdxByName[t])throw new Error(`local already exists. Function: ${this.fnName}, Param: ${t} `);const i=this.nextLocal++;this.localIdxByName[t]=i,this.locals.push({type:a,length:o})}setReturnType(t){if(this.returnType)throw new Error(`returnType already defined. Function: ${this.fnName}`);this.returnType=t}getSignature(){return[96,...[...ie(this.params.length),...this.params.map((t=>ce[t.type]))],...this.returnType?[1,ce[this.returnType]]:[0]]}getBody(){const t=this.locals.map((t=>[...ie(t.length),ce[t.type]])),a=[...ie(this.locals.length),...[].concat(...t),...this.code,11];return[...ie(a.length),...a]}addCode(...t){this.code.push(...[].concat(...t))}getCodeBuilder(){return new le(this)}}class re{constructor(){this.functions=[],this.functionIdxByName={},this.nImportFunctions=0,this.nInternalFunctions=0,this.memory={pagesSize:1,moduleName:"env",fieldName:"memory"},this.free=8,this.datas=[],this.modules={},this.exports=[],this.functionsTable=[]}build(){return this._setSignatures(),new Uint8Array([...Ja(1836278016),...Ja(1),...this._buildType(),...this._buildImport(),...this._buildFunctionDeclarations(),...this._buildFunctionsTable(),...this._buildExports(),...this._buildElements(),...this._buildCode(),...this._buildData()])}addFunction(t){if(void 0!==this.functionIdxByName[t])throw new Error(`Function already defined: ${t}`);const a=this.functions.length;return this.functionIdxByName[t]=a,this.functions.push(new se(this,t,"internal")),this.nInternalFunctions++,this.functions[a]}addIimportFunction(t,a,e){if(void 0!==this.functionIdxByName[t])throw new Error(`Function already defined: ${t}`);if(this.functions.length>0&&"internal"==this.functions[this.functions.length-1].type)throw new Error(`Import functions must be declared before internal: ${t}`);let o=e||t;const i=this.functions.length;return this.functionIdxByName[t]=i,this.functions.push(new se(this,t,"import",a,o)),this.nImportFunctions++,this.functions[i]}setMemory(t,a,e){this.memory={pagesSize:t,moduleName:a||"env",fieldName:e||"memory"}}exportFunction(t,a){const e=a||t;if(void 0===this.functionIdxByName[t])throw new Error(`Function not defined: ${t}`);const o=this.functionIdxByName[t];e!=t&&(this.functionIdxByName[e]=o),this.exports.push({exportName:e,idx:o})}addFunctionToTable(t){const a=this.functionIdxByName[t];this.functionsTable.push(a)}addData(t,a){this.datas.push({offset:t,bytes:a})}alloc(t,a){let e,o;(Array.isArray(t)||ArrayBuffer.isView(t))&&void 0===a?(e=t.length,o=t):(e=t,o=a),e=1+(e-1>>3)<<3;const i=this.free;return this.free+=e,o&&this.addData(i,o),i}allocString(t){const a=(new globalThis.TextEncoder).encode(t);return this.alloc([...a,0])}_setSignatures(){this.signatures=[];const t={};if(this.functionsTable.length>0){const a=this.functions[this.functionsTable[0]].getSignature();t["s_"+ne(a)]=0,this.signatures.push(a)}for(let a=0;a{a.pendingLoads.push({page:t,resolve:e,reject:o})}));return a.__statusPage("After Load request: ",t),e}__statusPage(t,a){const e=[],o=this;if(!o.logHistory)return;e.push("=="+t+" "+a);let i="";for(let t=0;t "+a.history[t][e][o])}_triggerLoad(){const t=this;if(t.reading)return;if(0==t.pendingLoads.length)return;const a=Object.keys(t.pages),e=[];for(let o=0;o0&&(void 0!==t.pages[t.pendingLoads[0].page]||o>0||e.length>0);){const a=t.pendingLoads.shift();if(void 0!==t.pages[a.page]){t.pages[a.page].pendingOps++;const o=e.indexOf(a.page);o>=0&&e.splice(o,1),t.pages[a.page].loading?t.pages[a.page].loading.push(a):a.resolve(),t.__statusPage("After Load (cached): ",a.page)}else{if(o)o--;else{const a=e.shift();t.__statusPage("Before Unload: ",a),t.avBuffs.unshift(t.pages[a]),delete t.pages[a],t.__statusPage("After Unload: ",a)}a.page>=t.totalPages?(t.pages[a.page]=n(),a.resolve(),t.__statusPage("After Load (new): ",a.page)):(t.reading=!0,t.pages[a.page]=n(),t.pages[a.page].loading=[a],i.push(t.fd.read(t.pages[a.page].buff,0,t.pageSize,a.page*t.pageSize).then((e=>{t.pages[a.page].size=e.bytesRead;const o=t.pages[a.page].loading;delete t.pages[a.page].loading;for(let t=0;t{a.reject(t)}))),t.__statusPage("After Load (loading): ",a.page))}}function n(){if(t.avBuffs.length>0){const a=t.avBuffs.shift();return a.dirty=!1,a.pendingOps=1,a.size=0,a}return{dirty:!1,buff:new Uint8Array(t.pageSize),pendingOps:1,size:0}}Promise.all(i).then((()=>{t.reading=!1,t.pendingLoads.length>0&&setImmediate(t._triggerLoad.bind(t)),t._tryClose()}))}_triggerWrite(){const t=this;if(t.writing)return;const a=Object.keys(t.pages),e=[];for(let o=0;o{i.writing=!1}),(a=>{console.log("ERROR Writing: "+a),t.error=a,t._tryClose()}))))}t.writing&&Promise.all(e).then((()=>{t.writing=!1,setImmediate(t._triggerWrite.bind(t)),t._tryClose(),t.pendingLoads.length>0&&setImmediate(t._triggerLoad.bind(t))}))}_getDirtyPage(){for(let t in this.pages)if(this.pages[t].dirty)return t;return-1}async write(t,a){if(0==t.byteLength)return;const e=this;if(void 0===a&&(a=e.pos),e.pos=a+t.byteLength,e.totalSize0;){await n[l-o];const a=c+s>e.pageSize?e.pageSize-c:s,i=t.slice(t.byteLength-s,t.byteLength-s+a);new Uint8Array(e.pages[l].buff.buffer,c,a).set(i),e.pages[l].dirty=!0,e.pages[l].pendingOps--,e.pages[l].size=Math.max(c+a,e.pages[l].size),l>=e.totalPages&&(e.totalPages=l+1),s-=a,l++,c=0,e.writing||setImmediate(e._triggerWrite.bind(e))}}async read(t,a){let e=new Uint8Array(t);return await this.readToBuffer(e,0,t,a),e}async readToBuffer(t,a,e,o){if(0==e)return;const i=this;if(e>i.pageSize*i.maxPagesLoaded*.8){const t=Math.floor(1.1*e);this.maxPagesLoaded=Math.floor(t/i.pageSize)+1}if(void 0===o&&(o=i.pos),i.pos=o+e,i.pendingClose)throw new Error("Reading a closing file");const n=Math.floor(o/i.pageSize),l=Math.floor((o+e-1)/i.pageSize),c=[];for(let t=n;t<=l;t++)c.push(i._loadPage(t));i._triggerLoad();let s=n,r=o%i.pageSize,d=o+e>i.totalSize?e-(o+e-i.totalSize):e;for(;d>0;){await c[s-n],i.__statusPage("After Await (read): ",s);const o=r+d>i.pageSize?i.pageSize-r:d,l=new Uint8Array(i.pages[s].buff.buffer,i.pages[s].buff.byteOffset+r,o);t.set(l,a+e-d),i.pages[s].pendingOps--,i.__statusPage("After Op done: ",s),d-=o,s++,r=0,i.pendingLoads.length>0&&setImmediate(i._triggerLoad.bind(i))}this.pos=o+e}_tryClose(){const t=this;if(!t.pendingClose)return;t.error&&t.pendingCloseReject(t.error);t._getDirtyPage()>=0||t.writing||t.reading||t.pendingLoads.length>0||t.pendingClose()}close(){const t=this;if(t.pendingClose)throw new Error("Closing the file twice");return new Promise(((a,e)=>{t.pendingClose=a,t.pendingCloseReject=e,t._tryClose()})).then((()=>{t.fd.close()}),(a=>{throw t.fd.close(),a}))}async discard(){await this.close(),await fe.promises.unlink(this.fileName)}async writeULE32(t,a){const e=new Uint8Array(4);new DataView(e.buffer).setUint32(0,t,!0),await this.write(e,a)}async writeUBE32(t,a){const e=new Uint8Array(4);new DataView(e.buffer).setUint32(0,t,!1),await this.write(e,a)}async writeULE64(t,a){const e=new Uint8Array(8),o=new DataView(e.buffer);o.setUint32(0,4294967295&t,!0),o.setUint32(4,Math.floor(t/4294967296),!0),await this.write(e,a)}async readULE32(t){const a=await this.read(4,t);return new Uint32Array(a.buffer)[0]}async readUBE32(t){const a=await this.read(4,t);return new DataView(a.buffer).getUint32(0,!1)}async readULE64(t){const a=await this.read(8,t),e=new Uint32Array(a.buffer);return 4294967296*e[1]+e[0]}async readString(t){const a=this;if(a.pendingClose)throw new Error("Reading a closing file");let e=void 0===t?a.pos:t,o=Math.floor(e/a.pageSize),i=!1,n="";for(;!i;){let t=a._loadPage(o);a._triggerLoad(),await t,a.__statusPage("After Await (read): ",o);let l=e%a.pageSize;const c=new Uint8Array(a.pages[o].buff.buffer,a.pages[o].buff.byteOffset+l,a.pageSize-l);let s=c.findIndex((t=>0===t));i=-1!==s,i?(n+=(new TextDecoder).decode(c.slice(0,s)),a.pos=o*this.pageSize+l+s+1):(n+=(new TextDecoder).decode(c),a.pos=o*this.pageSize+l+c.length),a.pages[o].pendingOps--,a.__statusPage("After Op done: ",o),e=a.pos,o++,a.pendingLoads.length>0&&setImmediate(a._triggerLoad.bind(a))}return n}}const me=new Uint8Array(4),Le=new DataView(me.buffer),be=new Uint8Array(8),we=new DataView(be.buffer);class ye{constructor(){this.pageSize=16384}_resizeIfNeeded(t){if(t>this.allocSize){const a=Math.max(this.allocSize+(1<<20),Math.floor(1.1*this.allocSize),t),e=new Uint8Array(a);e.set(this.o.data),this.o.data=e,this.allocSize=a}}async write(t,a){if(void 0===a&&(a=this.pos),this.readOnly)throw new Error("Writing a read only file");this._resizeIfNeeded(a+t.byteLength),this.o.data.set(t.slice(),a),a+t.byteLength>this.totalSize&&(this.totalSize=a+t.byteLength),this.pos=a+t.byteLength}async readToBuffer(t,a,e,o){if(void 0===o&&(o=this.pos),this.readOnly&&o+e>this.totalSize)throw new Error("Reading out of bounds");this._resizeIfNeeded(o+e);const i=new Uint8Array(this.o.data.buffer,this.o.data.byteOffset+o,e);t.set(i,a),this.pos=o+e}async read(t,a){const e=new Uint8Array(t);return await this.readToBuffer(e,0,t,a),e}close(){this.o.data.byteLength!=this.totalSize&&(this.o.data=this.o.data.slice(0,this.totalSize))}async discard(){}async writeULE32(t,a){Le.setUint32(0,t,!0),await this.write(me,a)}async writeUBE32(t,a){Le.setUint32(0,t,!1),await this.write(me,a)}async writeULE64(t,a){we.setUint32(0,4294967295&t,!0),we.setUint32(4,Math.floor(t/4294967296),!0),await this.write(be,a)}async readULE32(t){const a=await this.read(4,t);return new Uint32Array(a.buffer)[0]}async readUBE32(t){const a=await this.read(4,t);return new DataView(a.buffer).getUint32(0,!1)}async readULE64(t){const a=await this.read(8,t),e=new Uint32Array(a.buffer);return 4294967296*e[1]+e[0]}async readString(t){const a=this;let e=void 0===t?a.pos:t;if(e>this.totalSize){if(this.readOnly)throw new Error("Reading out of bounds");this._resizeIfNeeded(t)}const o=new Uint8Array(a.o.data.buffer,e,this.totalSize-e);let i=o.findIndex((t=>0===t)),n="";return-1!==i?(n=(new TextDecoder).decode(o.slice(0,i)),a.pos=e+i+1):a.pos=e,n}}const Ae=1<<22;const Ce=new Uint8Array(4),Fe=new DataView(Ce.buffer),xe=new Uint8Array(8),Ie=new DataView(xe.buffer);class Be{constructor(){this.pageSize=16384}_resizeIfNeeded(t){if(t<=this.totalSize)return;if(this.readOnly)throw new Error("Reading out of file bounds");const a=Math.floor((t-1)/Ae)+1;for(let e=Math.max(this.o.data.length-1,0);e0;){const a=i+n>Ae?Ae-i:n,l=t.slice(t.byteLength-n,t.byteLength-n+a);new Uint8Array(e.o.data[o].buffer,i,a).set(l),n-=a,o++,i=0}this.pos=a+t.byteLength}async readToBuffer(t,a,e,o){const i=this;if(void 0===o&&(o=i.pos),this.readOnly&&o+e>this.totalSize)throw new Error("Reading out of bounds");this._resizeIfNeeded(o+e);let n=Math.floor(o/Ae),l=o%Ae,c=e;for(;c>0;){const o=l+c>Ae?Ae-l:c,s=new Uint8Array(i.o.data[n].buffer,l,o);t.set(s,a+e-c),c-=o,n++,l=0}this.pos=o+e}async read(t,a){const e=new Uint8Array(t);return await this.readToBuffer(e,0,t,a),e}close(){}async discard(){}async writeULE32(t,a){Fe.setUint32(0,t,!0),await this.write(Ce,a)}async writeUBE32(t,a){Fe.setUint32(0,t,!1),await this.write(Ce,a)}async writeULE64(t,a){Ie.setUint32(0,4294967295&t,!0),Ie.setUint32(4,Math.floor(t/4294967296),!0),await this.write(xe,a)}async readULE32(t){const a=await this.read(4,t);return new Uint32Array(a.buffer)[0]}async readUBE32(t){const a=await this.read(4,t);return new DataView(a.buffer).getUint32(0,!1)}async readULE64(t){const a=await this.read(8,t),e=new Uint32Array(a.buffer);return 4294967296*e[1]+e[0]}async readString(t){const a=this;let e=void 0===t?a.pos:t;if(e>this.totalSize){if(this.readOnly)throw new Error("Reading out of bounds");this._resizeIfNeeded(t)}let o=!1,i="";for(;!o;){let t=Math.floor(e/Ae),n=e%Ae;if(void 0===a.o.data[t])throw new Error("ERROR");let l=Math.min(2048,a.o.data[t].length-n);const c=new Uint8Array(a.o.data[t].buffer,n,l);let s=c.findIndex((t=>0===t));o=-1!==s,o?(i+=(new TextDecoder).decode(c.slice(0,s)),a.pos=t*Ae+n+s+1):(i+=(new TextDecoder).decode(c),a.pos=t*Ae+n+c.length),e=a.pos}return i}}const Ee=1024,ve=512,Se=2,Pe=0,qe=65536,Oe=8192;async function Ge(t,a,e){if("string"==typeof t&&(t={type:"file",fileName:t,cacheSize:a||qe,pageSize:e||Oe}),"file"==t.type)return await he(t.fileName,Ee|ve|Se,t.cacheSize,t.pageSize);if("mem"==t.type)return function(t){const a=t.initialSize||1<<20,e=new ye;return e.o=t,e.o.data=new Uint8Array(a),e.allocSize=a,e.totalSize=0,e.readOnly=!1,e.pos=0,e}(t);if("bigMem"==t.type)return function(t){const a=t.initialSize||0,e=new Be;e.o=t;const o=a?Math.floor((a-1)/Ae)+1:0;e.o.data=[];for(let t=0;te)throw new Error("Version not supported");const s=await n.readULE32();let r=[];for(let t=0;t1)throw new Error(t.fileName+": Section Duplicated "+e);t.pos=a[e][0].p,t.readingSection=a[e][0]}async function Re(t,a){if(void 0===t.readingSection)throw new Error("Not reading a section");if(!a&&t.pos-t.readingSection.p!=t.readingSection.size)throw new Error("Invalid section size reading");delete t.readingSection}async function Ne(t,a,e,o){const i=new Uint8Array(e);_e.toRprLE(i,0,a,e),await t.write(i,o)}async function De(t,a,e){const o=await t.read(a,e);return _e.fromRprLE(o,0,a)}async function $e(t,a,e,o,i){void 0===i&&(i=a[o][0].size);const n=t.pageSize;await ke(t,a,o),await Ue(e,o);for(let a=0;aa[e][0].size)throw new Error("Reading out of the range of the section");let n;return n=i<1<<30?new Uint8Array(i):new Pa(i),await t.readToBuffer(n,0,i,a[e][0].p+o),n}async function Ve(t,a,e,o,i){const n=16*t.pageSize;if(await ke(t,a,i),await ke(e,o,i),a[i][0].size!=o[i][0].size)return!1;const l=a[i][0].size;for(let a=0;a=0)a=await de();else{if(!(["BLS12381"].indexOf(e)>=0))throw new Error(`Curve not supported: ${t}`);a=await ue()}return a}var Xe="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},to={exports:{}},ao=function t(a,e){if(!a){var o=new eo(e);throw Error.captureStackTrace&&Error.captureStackTrace(o,t),o}};class eo extends Error{}eo.prototype.name="AssertionError";var oo={exports:{}};function io(t){return t.length}var no={byteLength:io,toString:function(t){const a=t.byteLength;let e="";for(let o=0;o1&&61===t.charCodeAt(a-1)&&a--,3*a>>>2}co[45]=62,co[95]=63;var ro={byteLength:so,toString:function(t){const a=t.byteLength;let e="";for(let o=0;o>2]+lo[(3&t[o])<<4|t[o+1]>>4]+lo[(15&t[o+1])<<2|t[o+2]>>6]+lo[63&t[o+2]];return a%3==2?e=e.substring(0,e.length-1)+"=":a%3==1&&(e=e.substring(0,e.length-2)+"=="),e},write:function(t,a,e=0,o=so(a)){const i=Math.min(o,t.byteLength-e);for(let e=0,o=0;o>4,t[o++]=(15&n)<<4|l>>2,t[o++]=(3&l)<<6|63&c}return i}};function uo(t){return t.length>>>1}var _o={byteLength:uo,toString:function(t){const a=t.byteLength;t=new DataView(t.buffer,t.byteOffset,a);let e="",o=0;for(let i=a-a%4;o=48&&t<=57?t-48:t>=65&&t<=70?t-65+10:t>=97&&t<=102?t-97+10:void 0}function fo(t){let a=0;for(let e=0,o=t.length;e=55296&&i<=56319&&e+1=56320&&o<=57343){a+=4,e++;continue}}a+=i<=127?1:i<=2047?2:3}return a}let ho,po;if("undefined"!=typeof TextDecoder){const t=new TextDecoder;ho=function(a){return t.decode(a)}}else ho=function(t){const a=t.byteLength;let e="",o=0;for(;o0){let a=0;for(;a>o,o-=6;o>=0;)t[l++]=128|e>>o&63,o-=6;n+=e>=65536?2:1}return i};var mo={byteLength:fo,toString:ho,write:po};function Lo(t){return 2*t.length}var bo,wo,yo={byteLength:Lo,toString:function(t){const a=t.byteLength;let e="";for(let o=0;o>8,l=i%256;t[e+2*o]=l,t[e+2*o+1]=n}return i}};!function(t,a){const e=no,o=ro,i=_o,n=mo,l=yo,c=255===new Uint8Array(Uint16Array.of(255).buffer)[0];function s(t){switch(t){case"ascii":return e;case"base64":return o;case"hex":return i;case"utf8":case"utf-8":case void 0:return n;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return l;default:throw new Error(`Unknown encoding: ${t}`)}}function r(t){return t instanceof Uint8Array}function d(t,a,e){return"string"==typeof t?function(t,a){const e=s(a),o=new Uint8Array(e.byteLength(t));return e.write(o,t,0,o.byteLength),o}(t,a):Array.isArray(t)?function(t){const a=new Uint8Array(t.length);return a.set(t),a}(t):ArrayBuffer.isView(t)?function(t){const a=new Uint8Array(t.byteLength);return a.set(t),a}(t):function(t,a,e){return new Uint8Array(t,a,e)}(t,a,e)}function u(t,a,e,o,i){if(0===t.byteLength)return-1;if("string"==typeof e?(o=e,e=0):void 0===e?e=i?0:t.length-1:e<0&&(e+=t.byteLength),e>=t.byteLength){if(i)return-1;e=t.byteLength-1}else if(e<0){if(!i)return-1;e=0}if("string"==typeof a)a=d(a,o);else if("number"==typeof a)return a&=255,i?t.indexOf(a,e):t.lastIndexOf(a,e);if(0===a.byteLength)return-1;if(i){let o=-1;for(let i=e;it.byteLength&&(e=t.byteLength-a.byteLength);for(let o=e;o>=0;o--){let e=!0;for(let i=0;ii)return 1}return t.byteLength>a.byteLength?1:t.byteLengtht+a.byteLength),0));const e=new Uint8Array(a);let o=0;for(const a of t){if(o+a.byteLength>e.byteLength){const t=a.subarray(0,e.byteLength-o);return e.set(t,o),e}e.set(a,o),o+=a.byteLength}return e},copy:function(t,a,e=0,o=0,i=t.byteLength){if(i>0&&i=t.byteLength)throw new RangeError("sourceStart is out of range");if(i<0)throw new RangeError("sourceEnd is out of range");e>=a.byteLength&&(e=a.byteLength),i>t.byteLength&&(i=t.byteLength),a.byteLength-e=i||o<=e?"":(e<0&&(e=0),o>i&&(o=i),(0!==e||o{for(var t=new Uint8Array(128),a=0;a<64;a++)t[a<26?a+65:a<52?a+71:a<62?a-4:4*a-205]=a;return a=>{for(var e=a.length,o=new Uint8Array(3*(e-("="==a[e-1])-("="==a[e-2]))/4|0),i=0,n=0;i>4,o[n++]=c<<4|s>>2,o[n++]=s<<6|r}return o}})(),a=((t,a)=>function(){return a||(0,t[Object.keys(t)[0]])((a={exports:{}}).exports,a),a.exports})({"wasm-binary:./blake2b.wat"(a,e){e.exports=t("AGFzbQEAAAABEANgAn9/AGADf39/AGABfwADBQQAAQICBQUBAQroBwdNBQZtZW1vcnkCAAxibGFrZTJiX2luaXQAAA5ibGFrZTJiX3VwZGF0ZQABDWJsYWtlMmJfZmluYWwAAhBibGFrZTJiX2NvbXByZXNzAAMKvz8EwAIAIABCADcDACAAQgA3AwggAEIANwMQIABCADcDGCAAQgA3AyAgAEIANwMoIABCADcDMCAAQgA3AzggAEIANwNAIABCADcDSCAAQgA3A1AgAEIANwNYIABCADcDYCAAQgA3A2ggAEIANwNwIABCADcDeCAAQoiS853/zPmE6gBBACkDAIU3A4ABIABCu86qptjQ67O7f0EIKQMAhTcDiAEgAEKr8NP0r+68tzxBECkDAIU3A5ABIABC8e30+KWn/aelf0EYKQMAhTcDmAEgAELRhZrv+s+Uh9EAQSApAwCFNwOgASAAQp/Y+dnCkdqCm39BKCkDAIU3A6gBIABC6/qG2r+19sEfQTApAwCFNwOwASAAQvnC+JuRo7Pw2wBBOCkDAIU3A7gBIABCADcDwAEgAEIANwPIASAAQgA3A9ABC20BA38gAEHAAWohAyAAQcgBaiEEIAQpAwCnIQUCQANAIAEgAkYNASAFQYABRgRAIAMgAykDACAFrXw3AwBBACEFIAAQAwsgACAFaiABLQAAOgAAIAVBAWohBSABQQFqIQEMAAsLIAQgBa03AwALYQEDfyAAQcABaiEBIABByAFqIQIgASABKQMAIAIpAwB8NwMAIABCfzcD0AEgAikDAKchAwJAA0AgA0GAAUYNASAAIANqQQA6AAAgA0EBaiEDDAALCyACIAOtNwMAIAAQAwuqOwIgfgl/IABBgAFqISEgAEGIAWohIiAAQZABaiEjIABBmAFqISQgAEGgAWohJSAAQagBaiEmIABBsAFqIScgAEG4AWohKCAhKQMAIQEgIikDACECICMpAwAhAyAkKQMAIQQgJSkDACEFICYpAwAhBiAnKQMAIQcgKCkDACEIQoiS853/zPmE6gAhCUK7zqqm2NDrs7t/IQpCq/DT9K/uvLc8IQtC8e30+KWn/aelfyEMQtGFmu/6z5SH0QAhDUKf2PnZwpHagpt/IQ5C6/qG2r+19sEfIQ9C+cL4m5Gjs/DbACEQIAApAwAhESAAKQMIIRIgACkDECETIAApAxghFCAAKQMgIRUgACkDKCEWIAApAzAhFyAAKQM4IRggACkDQCEZIAApA0ghGiAAKQNQIRsgACkDWCEcIAApA2AhHSAAKQNoIR4gACkDcCEfIAApA3ghICANIAApA8ABhSENIA8gACkD0AGFIQ8gASAFIBF8fCEBIA0gAYVCIIohDSAJIA18IQkgBSAJhUIYiiEFIAEgBSASfHwhASANIAGFQhCKIQ0gCSANfCEJIAUgCYVCP4ohBSACIAYgE3x8IQIgDiAChUIgiiEOIAogDnwhCiAGIAqFQhiKIQYgAiAGIBR8fCECIA4gAoVCEIohDiAKIA58IQogBiAKhUI/iiEGIAMgByAVfHwhAyAPIAOFQiCKIQ8gCyAPfCELIAcgC4VCGIohByADIAcgFnx8IQMgDyADhUIQiiEPIAsgD3whCyAHIAuFQj+KIQcgBCAIIBd8fCEEIBAgBIVCIIohECAMIBB8IQwgCCAMhUIYiiEIIAQgCCAYfHwhBCAQIASFQhCKIRAgDCAQfCEMIAggDIVCP4ohCCABIAYgGXx8IQEgECABhUIgiiEQIAsgEHwhCyAGIAuFQhiKIQYgASAGIBp8fCEBIBAgAYVCEIohECALIBB8IQsgBiALhUI/iiEGIAIgByAbfHwhAiANIAKFQiCKIQ0gDCANfCEMIAcgDIVCGIohByACIAcgHHx8IQIgDSAChUIQiiENIAwgDXwhDCAHIAyFQj+KIQcgAyAIIB18fCEDIA4gA4VCIIohDiAJIA58IQkgCCAJhUIYiiEIIAMgCCAefHwhAyAOIAOFQhCKIQ4gCSAOfCEJIAggCYVCP4ohCCAEIAUgH3x8IQQgDyAEhUIgiiEPIAogD3whCiAFIAqFQhiKIQUgBCAFICB8fCEEIA8gBIVCEIohDyAKIA98IQogBSAKhUI/iiEFIAEgBSAffHwhASANIAGFQiCKIQ0gCSANfCEJIAUgCYVCGIohBSABIAUgG3x8IQEgDSABhUIQiiENIAkgDXwhCSAFIAmFQj+KIQUgAiAGIBV8fCECIA4gAoVCIIohDiAKIA58IQogBiAKhUIYiiEGIAIgBiAZfHwhAiAOIAKFQhCKIQ4gCiAOfCEKIAYgCoVCP4ohBiADIAcgGnx8IQMgDyADhUIgiiEPIAsgD3whCyAHIAuFQhiKIQcgAyAHICB8fCEDIA8gA4VCEIohDyALIA98IQsgByALhUI/iiEHIAQgCCAefHwhBCAQIASFQiCKIRAgDCAQfCEMIAggDIVCGIohCCAEIAggF3x8IQQgECAEhUIQiiEQIAwgEHwhDCAIIAyFQj+KIQggASAGIBJ8fCEBIBAgAYVCIIohECALIBB8IQsgBiALhUIYiiEGIAEgBiAdfHwhASAQIAGFQhCKIRAgCyAQfCELIAYgC4VCP4ohBiACIAcgEXx8IQIgDSAChUIgiiENIAwgDXwhDCAHIAyFQhiKIQcgAiAHIBN8fCECIA0gAoVCEIohDSAMIA18IQwgByAMhUI/iiEHIAMgCCAcfHwhAyAOIAOFQiCKIQ4gCSAOfCEJIAggCYVCGIohCCADIAggGHx8IQMgDiADhUIQiiEOIAkgDnwhCSAIIAmFQj+KIQggBCAFIBZ8fCEEIA8gBIVCIIohDyAKIA98IQogBSAKhUIYiiEFIAQgBSAUfHwhBCAPIASFQhCKIQ8gCiAPfCEKIAUgCoVCP4ohBSABIAUgHHx8IQEgDSABhUIgiiENIAkgDXwhCSAFIAmFQhiKIQUgASAFIBl8fCEBIA0gAYVCEIohDSAJIA18IQkgBSAJhUI/iiEFIAIgBiAdfHwhAiAOIAKFQiCKIQ4gCiAOfCEKIAYgCoVCGIohBiACIAYgEXx8IQIgDiAChUIQiiEOIAogDnwhCiAGIAqFQj+KIQYgAyAHIBZ8fCEDIA8gA4VCIIohDyALIA98IQsgByALhUIYiiEHIAMgByATfHwhAyAPIAOFQhCKIQ8gCyAPfCELIAcgC4VCP4ohByAEIAggIHx8IQQgECAEhUIgiiEQIAwgEHwhDCAIIAyFQhiKIQggBCAIIB58fCEEIBAgBIVCEIohECAMIBB8IQwgCCAMhUI/iiEIIAEgBiAbfHwhASAQIAGFQiCKIRAgCyAQfCELIAYgC4VCGIohBiABIAYgH3x8IQEgECABhUIQiiEQIAsgEHwhCyAGIAuFQj+KIQYgAiAHIBR8fCECIA0gAoVCIIohDSAMIA18IQwgByAMhUIYiiEHIAIgByAXfHwhAiANIAKFQhCKIQ0gDCANfCEMIAcgDIVCP4ohByADIAggGHx8IQMgDiADhUIgiiEOIAkgDnwhCSAIIAmFQhiKIQggAyAIIBJ8fCEDIA4gA4VCEIohDiAJIA58IQkgCCAJhUI/iiEIIAQgBSAafHwhBCAPIASFQiCKIQ8gCiAPfCEKIAUgCoVCGIohBSAEIAUgFXx8IQQgDyAEhUIQiiEPIAogD3whCiAFIAqFQj+KIQUgASAFIBh8fCEBIA0gAYVCIIohDSAJIA18IQkgBSAJhUIYiiEFIAEgBSAafHwhASANIAGFQhCKIQ0gCSANfCEJIAUgCYVCP4ohBSACIAYgFHx8IQIgDiAChUIgiiEOIAogDnwhCiAGIAqFQhiKIQYgAiAGIBJ8fCECIA4gAoVCEIohDiAKIA58IQogBiAKhUI/iiEGIAMgByAefHwhAyAPIAOFQiCKIQ8gCyAPfCELIAcgC4VCGIohByADIAcgHXx8IQMgDyADhUIQiiEPIAsgD3whCyAHIAuFQj+KIQcgBCAIIBx8fCEEIBAgBIVCIIohECAMIBB8IQwgCCAMhUIYiiEIIAQgCCAffHwhBCAQIASFQhCKIRAgDCAQfCEMIAggDIVCP4ohCCABIAYgE3x8IQEgECABhUIgiiEQIAsgEHwhCyAGIAuFQhiKIQYgASAGIBd8fCEBIBAgAYVCEIohECALIBB8IQsgBiALhUI/iiEGIAIgByAWfHwhAiANIAKFQiCKIQ0gDCANfCEMIAcgDIVCGIohByACIAcgG3x8IQIgDSAChUIQiiENIAwgDXwhDCAHIAyFQj+KIQcgAyAIIBV8fCEDIA4gA4VCIIohDiAJIA58IQkgCCAJhUIYiiEIIAMgCCARfHwhAyAOIAOFQhCKIQ4gCSAOfCEJIAggCYVCP4ohCCAEIAUgIHx8IQQgDyAEhUIgiiEPIAogD3whCiAFIAqFQhiKIQUgBCAFIBl8fCEEIA8gBIVCEIohDyAKIA98IQogBSAKhUI/iiEFIAEgBSAafHwhASANIAGFQiCKIQ0gCSANfCEJIAUgCYVCGIohBSABIAUgEXx8IQEgDSABhUIQiiENIAkgDXwhCSAFIAmFQj+KIQUgAiAGIBZ8fCECIA4gAoVCIIohDiAKIA58IQogBiAKhUIYiiEGIAIgBiAYfHwhAiAOIAKFQhCKIQ4gCiAOfCEKIAYgCoVCP4ohBiADIAcgE3x8IQMgDyADhUIgiiEPIAsgD3whCyAHIAuFQhiKIQcgAyAHIBV8fCEDIA8gA4VCEIohDyALIA98IQsgByALhUI/iiEHIAQgCCAbfHwhBCAQIASFQiCKIRAgDCAQfCEMIAggDIVCGIohCCAEIAggIHx8IQQgECAEhUIQiiEQIAwgEHwhDCAIIAyFQj+KIQggASAGIB98fCEBIBAgAYVCIIohECALIBB8IQsgBiALhUIYiiEGIAEgBiASfHwhASAQIAGFQhCKIRAgCyAQfCELIAYgC4VCP4ohBiACIAcgHHx8IQIgDSAChUIgiiENIAwgDXwhDCAHIAyFQhiKIQcgAiAHIB18fCECIA0gAoVCEIohDSAMIA18IQwgByAMhUI/iiEHIAMgCCAXfHwhAyAOIAOFQiCKIQ4gCSAOfCEJIAggCYVCGIohCCADIAggGXx8IQMgDiADhUIQiiEOIAkgDnwhCSAIIAmFQj+KIQggBCAFIBR8fCEEIA8gBIVCIIohDyAKIA98IQogBSAKhUIYiiEFIAQgBSAefHwhBCAPIASFQhCKIQ8gCiAPfCEKIAUgCoVCP4ohBSABIAUgE3x8IQEgDSABhUIgiiENIAkgDXwhCSAFIAmFQhiKIQUgASAFIB18fCEBIA0gAYVCEIohDSAJIA18IQkgBSAJhUI/iiEFIAIgBiAXfHwhAiAOIAKFQiCKIQ4gCiAOfCEKIAYgCoVCGIohBiACIAYgG3x8IQIgDiAChUIQiiEOIAogDnwhCiAGIAqFQj+KIQYgAyAHIBF8fCEDIA8gA4VCIIohDyALIA98IQsgByALhUIYiiEHIAMgByAcfHwhAyAPIAOFQhCKIQ8gCyAPfCELIAcgC4VCP4ohByAEIAggGXx8IQQgECAEhUIgiiEQIAwgEHwhDCAIIAyFQhiKIQggBCAIIBR8fCEEIBAgBIVCEIohECAMIBB8IQwgCCAMhUI/iiEIIAEgBiAVfHwhASAQIAGFQiCKIRAgCyAQfCELIAYgC4VCGIohBiABIAYgHnx8IQEgECABhUIQiiEQIAsgEHwhCyAGIAuFQj+KIQYgAiAHIBh8fCECIA0gAoVCIIohDSAMIA18IQwgByAMhUIYiiEHIAIgByAWfHwhAiANIAKFQhCKIQ0gDCANfCEMIAcgDIVCP4ohByADIAggIHx8IQMgDiADhUIgiiEOIAkgDnwhCSAIIAmFQhiKIQggAyAIIB98fCEDIA4gA4VCEIohDiAJIA58IQkgCCAJhUI/iiEIIAQgBSASfHwhBCAPIASFQiCKIQ8gCiAPfCEKIAUgCoVCGIohBSAEIAUgGnx8IQQgDyAEhUIQiiEPIAogD3whCiAFIAqFQj+KIQUgASAFIB18fCEBIA0gAYVCIIohDSAJIA18IQkgBSAJhUIYiiEFIAEgBSAWfHwhASANIAGFQhCKIQ0gCSANfCEJIAUgCYVCP4ohBSACIAYgEnx8IQIgDiAChUIgiiEOIAogDnwhCiAGIAqFQhiKIQYgAiAGICB8fCECIA4gAoVCEIohDiAKIA58IQogBiAKhUI/iiEGIAMgByAffHwhAyAPIAOFQiCKIQ8gCyAPfCELIAcgC4VCGIohByADIAcgHnx8IQMgDyADhUIQiiEPIAsgD3whCyAHIAuFQj+KIQcgBCAIIBV8fCEEIBAgBIVCIIohECAMIBB8IQwgCCAMhUIYiiEIIAQgCCAbfHwhBCAQIASFQhCKIRAgDCAQfCEMIAggDIVCP4ohCCABIAYgEXx8IQEgECABhUIgiiEQIAsgEHwhCyAGIAuFQhiKIQYgASAGIBh8fCEBIBAgAYVCEIohECALIBB8IQsgBiALhUI/iiEGIAIgByAXfHwhAiANIAKFQiCKIQ0gDCANfCEMIAcgDIVCGIohByACIAcgFHx8IQIgDSAChUIQiiENIAwgDXwhDCAHIAyFQj+KIQcgAyAIIBp8fCEDIA4gA4VCIIohDiAJIA58IQkgCCAJhUIYiiEIIAMgCCATfHwhAyAOIAOFQhCKIQ4gCSAOfCEJIAggCYVCP4ohCCAEIAUgGXx8IQQgDyAEhUIgiiEPIAogD3whCiAFIAqFQhiKIQUgBCAFIBx8fCEEIA8gBIVCEIohDyAKIA98IQogBSAKhUI/iiEFIAEgBSAefHwhASANIAGFQiCKIQ0gCSANfCEJIAUgCYVCGIohBSABIAUgHHx8IQEgDSABhUIQiiENIAkgDXwhCSAFIAmFQj+KIQUgAiAGIBh8fCECIA4gAoVCIIohDiAKIA58IQogBiAKhUIYiiEGIAIgBiAffHwhAiAOIAKFQhCKIQ4gCiAOfCEKIAYgCoVCP4ohBiADIAcgHXx8IQMgDyADhUIgiiEPIAsgD3whCyAHIAuFQhiKIQcgAyAHIBJ8fCEDIA8gA4VCEIohDyALIA98IQsgByALhUI/iiEHIAQgCCAUfHwhBCAQIASFQiCKIRAgDCAQfCEMIAggDIVCGIohCCAEIAggGnx8IQQgECAEhUIQiiEQIAwgEHwhDCAIIAyFQj+KIQggASAGIBZ8fCEBIBAgAYVCIIohECALIBB8IQsgBiALhUIYiiEGIAEgBiARfHwhASAQIAGFQhCKIRAgCyAQfCELIAYgC4VCP4ohBiACIAcgIHx8IQIgDSAChUIgiiENIAwgDXwhDCAHIAyFQhiKIQcgAiAHIBV8fCECIA0gAoVCEIohDSAMIA18IQwgByAMhUI/iiEHIAMgCCAZfHwhAyAOIAOFQiCKIQ4gCSAOfCEJIAggCYVCGIohCCADIAggF3x8IQMgDiADhUIQiiEOIAkgDnwhCSAIIAmFQj+KIQggBCAFIBN8fCEEIA8gBIVCIIohDyAKIA98IQogBSAKhUIYiiEFIAQgBSAbfHwhBCAPIASFQhCKIQ8gCiAPfCEKIAUgCoVCP4ohBSABIAUgF3x8IQEgDSABhUIgiiENIAkgDXwhCSAFIAmFQhiKIQUgASAFICB8fCEBIA0gAYVCEIohDSAJIA18IQkgBSAJhUI/iiEFIAIgBiAffHwhAiAOIAKFQiCKIQ4gCiAOfCEKIAYgCoVCGIohBiACIAYgGnx8IQIgDiAChUIQiiEOIAogDnwhCiAGIAqFQj+KIQYgAyAHIBx8fCEDIA8gA4VCIIohDyALIA98IQsgByALhUIYiiEHIAMgByAUfHwhAyAPIAOFQhCKIQ8gCyAPfCELIAcgC4VCP4ohByAEIAggEXx8IQQgECAEhUIgiiEQIAwgEHwhDCAIIAyFQhiKIQggBCAIIBl8fCEEIBAgBIVCEIohECAMIBB8IQwgCCAMhUI/iiEIIAEgBiAdfHwhASAQIAGFQiCKIRAgCyAQfCELIAYgC4VCGIohBiABIAYgE3x8IQEgECABhUIQiiEQIAsgEHwhCyAGIAuFQj+KIQYgAiAHIB58fCECIA0gAoVCIIohDSAMIA18IQwgByAMhUIYiiEHIAIgByAYfHwhAiANIAKFQhCKIQ0gDCANfCEMIAcgDIVCP4ohByADIAggEnx8IQMgDiADhUIgiiEOIAkgDnwhCSAIIAmFQhiKIQggAyAIIBV8fCEDIA4gA4VCEIohDiAJIA58IQkgCCAJhUI/iiEIIAQgBSAbfHwhBCAPIASFQiCKIQ8gCiAPfCEKIAUgCoVCGIohBSAEIAUgFnx8IQQgDyAEhUIQiiEPIAogD3whCiAFIAqFQj+KIQUgASAFIBt8fCEBIA0gAYVCIIohDSAJIA18IQkgBSAJhUIYiiEFIAEgBSATfHwhASANIAGFQhCKIQ0gCSANfCEJIAUgCYVCP4ohBSACIAYgGXx8IQIgDiAChUIgiiEOIAogDnwhCiAGIAqFQhiKIQYgAiAGIBV8fCECIA4gAoVCEIohDiAKIA58IQogBiAKhUI/iiEGIAMgByAYfHwhAyAPIAOFQiCKIQ8gCyAPfCELIAcgC4VCGIohByADIAcgF3x8IQMgDyADhUIQiiEPIAsgD3whCyAHIAuFQj+KIQcgBCAIIBJ8fCEEIBAgBIVCIIohECAMIBB8IQwgCCAMhUIYiiEIIAQgCCAWfHwhBCAQIASFQhCKIRAgDCAQfCEMIAggDIVCP4ohCCABIAYgIHx8IQEgECABhUIgiiEQIAsgEHwhCyAGIAuFQhiKIQYgASAGIBx8fCEBIBAgAYVCEIohECALIBB8IQsgBiALhUI/iiEGIAIgByAafHwhAiANIAKFQiCKIQ0gDCANfCEMIAcgDIVCGIohByACIAcgH3x8IQIgDSAChUIQiiENIAwgDXwhDCAHIAyFQj+KIQcgAyAIIBR8fCEDIA4gA4VCIIohDiAJIA58IQkgCCAJhUIYiiEIIAMgCCAdfHwhAyAOIAOFQhCKIQ4gCSAOfCEJIAggCYVCP4ohCCAEIAUgHnx8IQQgDyAEhUIgiiEPIAogD3whCiAFIAqFQhiKIQUgBCAFIBF8fCEEIA8gBIVCEIohDyAKIA98IQogBSAKhUI/iiEFIAEgBSARfHwhASANIAGFQiCKIQ0gCSANfCEJIAUgCYVCGIohBSABIAUgEnx8IQEgDSABhUIQiiENIAkgDXwhCSAFIAmFQj+KIQUgAiAGIBN8fCECIA4gAoVCIIohDiAKIA58IQogBiAKhUIYiiEGIAIgBiAUfHwhAiAOIAKFQhCKIQ4gCiAOfCEKIAYgCoVCP4ohBiADIAcgFXx8IQMgDyADhUIgiiEPIAsgD3whCyAHIAuFQhiKIQcgAyAHIBZ8fCEDIA8gA4VCEIohDyALIA98IQsgByALhUI/iiEHIAQgCCAXfHwhBCAQIASFQiCKIRAgDCAQfCEMIAggDIVCGIohCCAEIAggGHx8IQQgECAEhUIQiiEQIAwgEHwhDCAIIAyFQj+KIQggASAGIBl8fCEBIBAgAYVCIIohECALIBB8IQsgBiALhUIYiiEGIAEgBiAafHwhASAQIAGFQhCKIRAgCyAQfCELIAYgC4VCP4ohBiACIAcgG3x8IQIgDSAChUIgiiENIAwgDXwhDCAHIAyFQhiKIQcgAiAHIBx8fCECIA0gAoVCEIohDSAMIA18IQwgByAMhUI/iiEHIAMgCCAdfHwhAyAOIAOFQiCKIQ4gCSAOfCEJIAggCYVCGIohCCADIAggHnx8IQMgDiADhUIQiiEOIAkgDnwhCSAIIAmFQj+KIQggBCAFIB98fCEEIA8gBIVCIIohDyAKIA98IQogBSAKhUIYiiEFIAQgBSAgfHwhBCAPIASFQhCKIQ8gCiAPfCEKIAUgCoVCP4ohBSABIAUgH3x8IQEgDSABhUIgiiENIAkgDXwhCSAFIAmFQhiKIQUgASAFIBt8fCEBIA0gAYVCEIohDSAJIA18IQkgBSAJhUI/iiEFIAIgBiAVfHwhAiAOIAKFQiCKIQ4gCiAOfCEKIAYgCoVCGIohBiACIAYgGXx8IQIgDiAChUIQiiEOIAogDnwhCiAGIAqFQj+KIQYgAyAHIBp8fCEDIA8gA4VCIIohDyALIA98IQsgByALhUIYiiEHIAMgByAgfHwhAyAPIAOFQhCKIQ8gCyAPfCELIAcgC4VCP4ohByAEIAggHnx8IQQgECAEhUIgiiEQIAwgEHwhDCAIIAyFQhiKIQggBCAIIBd8fCEEIBAgBIVCEIohECAMIBB8IQwgCCAMhUI/iiEIIAEgBiASfHwhASAQIAGFQiCKIRAgCyAQfCELIAYgC4VCGIohBiABIAYgHXx8IQEgECABhUIQiiEQIAsgEHwhCyAGIAuFQj+KIQYgAiAHIBF8fCECIA0gAoVCIIohDSAMIA18IQwgByAMhUIYiiEHIAIgByATfHwhAiANIAKFQhCKIQ0gDCANfCEMIAcgDIVCP4ohByADIAggHHx8IQMgDiADhUIgiiEOIAkgDnwhCSAIIAmFQhiKIQggAyAIIBh8fCEDIA4gA4VCEIohDiAJIA58IQkgCCAJhUI/iiEIIAQgBSAWfHwhBCAPIASFQiCKIQ8gCiAPfCEKIAUgCoVCGIohBSAEIAUgFHx8IQQgDyAEhUIQiiEPIAogD3whCiAFIAqFQj+KIQUgISAhKQMAIAEgCYWFNwMAICIgIikDACACIAqFhTcDACAjICMpAwAgAyALhYU3AwAgJCAkKQMAIAQgDIWFNwMAICUgJSkDACAFIA2FhTcDACAmICYpAwAgBiAOhYU3AwAgJyAnKQMAIAcgD4WFNwMAICggKCkDACAIIBCFhTcDAAs=")}}),e=a(),o=WebAssembly.compile(e);return bo=async t=>(await WebAssembly.instantiate(await o,t)).exports}()().then((t=>{Fo=t})),Io=64,Bo=[];to.exports=Go;var Eo=to.exports.BYTES_MIN=16,vo=to.exports.BYTES_MAX=64;to.exports.BYTES=32;var So=to.exports.KEYBYTES_MIN=16,Po=to.exports.KEYBYTES_MAX=64;to.exports.KEYBYTES=32;var qo=to.exports.SALTBYTES=16,Oo=to.exports.PERSONALBYTES=16;function Go(t,a,e,o,i){if(!(this instanceof Go))return new Go(t,a,e,o,i);if(!Fo)throw new Error("WASM not loaded. Wait for Blake2b.ready(cb)");t||(t=32),!0!==i&&(Ao(t>=Eo,"digestLength must be at least "+Eo+", was given "+t),Ao(t<=vo,"digestLength must be at most "+vo+", was given "+t),null!=a&&(Ao(a instanceof Uint8Array,"key must be Uint8Array or Buffer"),Ao(a.length>=So,"key must be at least "+So+", was given "+a.length),Ao(a.length<=Po,"key must be at least "+Po+", was given "+a.length)),null!=e&&(Ao(e instanceof Uint8Array,"salt must be Uint8Array or Buffer"),Ao(e.length===qo,"salt must be exactly "+qo+", was given "+e.length)),null!=o&&(Ao(o instanceof Uint8Array,"personal must be Uint8Array or Buffer"),Ao(o.length===Oo,"personal must be exactly "+Oo+", was given "+o.length))),Bo.length||(Bo.push(Io),Io+=216),this.digestLength=t,this.finalized=!1,this.pointer=Bo.pop(),this._memory=new Uint8Array(Fo.memory.buffer),this._memory.fill(0,0,64),this._memory[0]=this.digestLength,this._memory[1]=a?a.length:0,this._memory[2]=1,this._memory[3]=1,e&&this._memory.set(e,32),o&&this._memory.set(o,48),this.pointer+216>this._memory.length&&this._realloc(this.pointer+216),Fo.blake2b_init(this.pointer,this.digestLength),a&&(this.update(a),this._memory.fill(0,Io,Io+a.length),this._memory[this.pointer+200]=128)}function zo(){}function To(t){return(0!=(4294901760&t)?(t&=4294901760,16):0)|(0!=(4278255360&t)?(t&=4278255360,8):0)|(0!=(4042322160&t)?(t&=4042322160,4):0)|(0!=(3435973836&t)?(t&=3435973836,2):0)|0!=(2863311530&t)}function Mo(t,a){const e=new DataView(t.buffer,t.byteOffset,t.byteLength);let o="";for(let t=0;t<4;t++){t>0&&(o+="\n"),o+="\t\t";for(let a=0;a<4;a++)a>0&&(o+=" "),o+=e.getUint32(16*t+4*a).toString(16).padStart(8,"0")}return a&&(o=a+"\n"+o),o}function Uo(t,a){if(t.byteLength!=a.byteLength)return!1;for(var e=new Int8Array(t),o=new Int8Array(a),i=0;i!=t.byteLength;i++)if(e[i]!=o[i])return!1;return!0}function Qo(t){const a=t.getPartialHash(),e=to.exports(64);return e.setPartialHash(a),e}async function ko(t,a,e,o,i){if(t.G1.isZero(a))return!1;if(t.G1.isZero(e))return!1;if(t.G2.isZero(o))return!1;if(t.G2.isZero(i))return!1;return await t.pairingEq(a,i,t.G1.neg(e),o)}function Ro(t){let a=new Uint8Array(t);return globalThis.crypto.getRandomValues(a),a}async function No(t){{const a=await globalThis.crypto.subtle.digest("SHA-256",t.buffer);return new Uint8Array(a)}}function Do(t,a){return new DataView(t.buffer).getUint32(a,!1)}async function $o(t){for(;!t;)t=await window.prompt("Enter a random text. (Entropy): ","");const a=to.exports(64);a.update(Ro(64));const e=new TextEncoder;a.update(e.encode(t));const o=a.digest(),i=[];for(let t=0;t<8;t++)i[t]=Do(o,4*t);return new M(i)}async function jo(t,a){let e,o;a<32?(e=1<>>0,o=1):(e=4294967296,o=1<>>0);let i=t;for(let t=0;t{e[o]=Ho(t,a[o])})),e}return"bigint"==typeof a||void 0!==a.eq?a.toString(10):a}Go.prototype._realloc=function(t){Fo.memory.grow(Math.max(0,Math.ceil(Math.abs(t-this._memory.length)/65536))),this._memory=new Uint8Array(Fo.memory.buffer)},Go.prototype.update=function(t){return Ao(!1===this.finalized,"Hash instance finalized"),Ao(t instanceof Uint8Array,"input must be Uint8Array or Buffer"),Io+t.length>this._memory.length&&this._realloc(Io+t.length),this._memory.set(t,Io),Fo.blake2b_update(this.pointer,Io,Io+t.length),this},Go.prototype.digest=function(t){if(Ao(!1===this.finalized,"Hash instance finalized"),this.finalized=!0,Bo.push(this.pointer),Fo.blake2b_final(this.pointer),!t||"binary"===t)return this._memory.slice(this.pointer+128,this.pointer+128+this.digestLength);if("string"==typeof t)return Co.toString(this._memory,t,this.pointer+128,this.pointer+128+this.digestLength);Ao(t instanceof Uint8Array&&t.length>=this.digestLength,"input must be Uint8Array or Buffer");for(var a=0;at()),t):t(new Error("WebAssembly not supported"))},Go.prototype.ready=Go.ready,Go.prototype.getPartialHash=function(){return this._memory.slice(this.pointer,this.pointer+216)},Go.prototype.setPartialHash=function(t){this._memory.set(t,this.pointer)};const Zo=1,Wo=2,Yo=10,Jo=2,Xo=3,ti=4,ai=5,ei=6,oi=7,ii=8,ni=9,li=10,ci=11,si=12,ri=13,di=14,ui=15,_i=16,gi=17;async function fi(t,a){await Ue(t,1),await t.writeULE32(1),await Qe(t);const e=await Ye(a.q);await Ue(t,2);const o=e.q,i=8*(Math.floor((_e.bitLength(o)-1)/64)+1),n=e.r,l=8*(Math.floor((_e.bitLength(n)-1)/64)+1);await t.writeULE32(i),await Ne(t,o,i),await t.writeULE32(l),await Ne(t,n,l),await t.writeULE32(a.nVars),await t.writeULE32(a.nPublic),await t.writeULE32(a.domainSize),await hi(t,e,a.vk_alpha_1),await hi(t,e,a.vk_beta_1),await pi(t,e,a.vk_beta_2),await pi(t,e,a.vk_gamma_2),await hi(t,e,a.vk_delta_1),await pi(t,e,a.vk_delta_2),await Qe(t)}async function hi(t,a,e){const o=new Uint8Array(2*a.G1.F.n8);a.G1.toRprLEM(o,0,e),await t.write(o)}async function pi(t,a,e){const o=new Uint8Array(2*a.G2.F.n8);a.G2.toRprLEM(o,0,e),await t.write(o)}async function mi(t,a,e){const o=await t.read(2*a.G1.F.n8),i=a.G1.fromRprLEM(o,0);return e?a.G1.toObject(i):i}async function Li(t,a,e){const o=await t.read(2*a.G2.F.n8),i=a.G2.fromRprLEM(o,0);return e?a.G2.toObject(i):i}async function bi(t,a,e){await ke(t,a,1);const o=await t.readULE32();if(await Re(t),o===Zo)return await async function(t,a,e){const o={protocol:"groth16"};await ke(t,a,2);const i=await t.readULE32();o.n8q=i,o.q=await De(t,i);const n=await t.readULE32();return o.n8r=n,o.r=await De(t,n),o.curve=await Ye(o.q),o.nVars=await t.readULE32(),o.nPublic=await t.readULE32(),o.domainSize=await t.readULE32(),o.power=To(o.domainSize),o.vk_alpha_1=await mi(t,o.curve,e),o.vk_beta_1=await mi(t,o.curve,e),o.vk_beta_2=await Li(t,o.curve,e),o.vk_gamma_2=await Li(t,o.curve,e),o.vk_delta_1=await mi(t,o.curve,e),o.vk_delta_2=await Li(t,o.curve,e),await Re(t),o}(t,a,e);if(o===Wo)return await async function(t,a,e){const o={protocol:"plonk"};await ke(t,a,2);const i=await t.readULE32();o.n8q=i,o.q=await De(t,i);const n=await t.readULE32();return o.n8r=n,o.r=await De(t,n),o.curve=await Ye(o.q),o.nVars=await t.readULE32(),o.nPublic=await t.readULE32(),o.domainSize=await t.readULE32(),o.power=To(o.domainSize),o.nAdditions=await t.readULE32(),o.nConstraints=await t.readULE32(),o.k1=await t.read(n),o.k2=await t.read(n),o.Qm=await mi(t,o.curve,e),o.Ql=await mi(t,o.curve,e),o.Qr=await mi(t,o.curve,e),o.Qo=await mi(t,o.curve,e),o.Qc=await mi(t,o.curve,e),o.S1=await mi(t,o.curve,e),o.S2=await mi(t,o.curve,e),o.S3=await mi(t,o.curve,e),o.X_2=await Li(t,o.curve,e),await Re(t),o}(t,a,e);if(o===Yo)return await async function(t,a,e){const o={protocol:"fflonk"};o.protocolId=Yo,await ke(t,a,Jo);const i=await t.readULE32();o.n8q=i,o.q=await De(t,i),o.curve=await Ye(o.q);const n=await t.readULE32();return o.n8r=n,o.r=await De(t,n),o.nVars=await t.readULE32(),o.nPublic=await t.readULE32(),o.domainSize=await t.readULE32(),o.power=To(o.domainSize),o.nAdditions=await t.readULE32(),o.nConstraints=await t.readULE32(),o.k1=await t.read(n),o.k2=await t.read(n),o.w3=await t.read(n),o.w4=await t.read(n),o.w8=await t.read(n),o.wr=await t.read(n),o.X_2=await Li(t,o.curve,e),o.C0=await mi(t,o.curve,e),await Re(t),o}(t,a,e);throw new Error("Protocol not supported: ")}async function wi(t,a,e){const o={delta:{}};o.deltaAfter=await mi(t,a,e),o.delta.g1_s=await mi(t,a,e),o.delta.g1_sx=await mi(t,a,e),o.delta.g2_spx=await Li(t,a,e),o.transcript=await t.read(64),o.type=await t.readULE32();const i=await t.readULE32(),n=t.pos;let l=0;for(;t.pos-n0){const a=new Uint8Array(o);await t.writeULE32(a.byteLength),await t.write(a)}else await t.writeULE32(0)}async function Ci(t,a,e){await Ue(t,10),await t.write(e.csHash),await t.writeULE32(e.contributions.length);for(let o=0;o0;)e.unshift(0),n--;return e}const qi=[0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4];function Oi(t,a){return a&&10!=a?16==a?"0x"==t.slice(0,2)?BigInt(t):BigInt("0x"+t):void 0:BigInt(t)}const Gi=Oi;function zi(t){const a=t.toString(16);return 4*(a.length-1)+qi[parseInt(a[0],16)]}function Ti(t){return!t}function Mi(t,a){return BigInt(t)<>BigInt(a)}const Qi=Mi,ki=Ui;function Ri(t){return(BigInt(t)&BigInt(1))==BigInt(1)}function Ni(t){let a=BigInt(t);const e=[];for(;a;)a&BigInt(1)?e.push(1):e.push(0),a>>=BigInt(1);return e}function Di(t){if(t>BigInt(Number.MAX_SAFE_INTEGER))throw new Error("Number too big");return Number(t)}function $i(t,a){return BigInt(t)-BigInt(a)}function ji(t,a){return BigInt(t)**BigInt(a)}function Vi(t,a){return BigInt(t)/BigInt(a)}function Ki(t,a){return BigInt(t)%BigInt(a)}function Hi(t,a){return BigInt(t)==BigInt(a)}function Zi(t,a){return BigInt(t)&BigInt(a)}function Wi(t,a,e,o){const i="0000000"+e.toString(16),n=new Uint32Array(t.buffer,t.byteOffset+a,o/4),l=1+(4*(i.length-7)-1>>5);for(let t=0;t>5);for(let t=0;ti[i.length-a-1]=t.toString(16).padStart(8,"0"))),Oi(i.join(""),16)}function Xi(t,a,e){e=e||t.byteLength,a=a||0;const o=new DataView(t.buffer,t.byteOffset+a,e),i=new Array(e/4);for(let t=0;t>=BigInt(1)}return e},bits:Ni,toNumber:Di,toArray:function(t,a){const e=[];let o=BigInt(t);for(a=BigInt(a);o;)e.unshift(Number(o%a)),o/=a;return e},add:function(t,a){return BigInt(t)+BigInt(a)},sub:$i,neg:function(t){return-BigInt(t)},mul:function(t,a){return BigInt(t)*BigInt(a)},square:function(t){return BigInt(t)*BigInt(t)},pow:ji,exp:function(t,a){return BigInt(t)**BigInt(a)},abs:function(t){return BigInt(t)>=0?BigInt(t):-BigInt(t)},div:Vi,mod:Ki,eq:Hi,neq:function(t,a){return BigInt(t)!=BigInt(a)},lt:function(t,a){return BigInt(t)BigInt(a)},leq:function(t,a){return BigInt(t)<=BigInt(a)},geq:function(t,a){return BigInt(t)>=BigInt(a)},band:Zi,bor:function(t,a){return BigInt(t)|BigInt(a)},bxor:function(t,a){return BigInt(t)^BigInt(a)},land:function(t,a){return BigInt(t)&&BigInt(a)},lor:function(t,a){return BigInt(t)||BigInt(a)},lnot:function(t){return!BigInt(t)},toRprLE:Wi,toRprBE:Yi,fromRprLE:Ji,fromRprBE:Xi,toString:function(t,a){return t.toString(a)},toLEBuff:function(t){const a=new Uint8Array(Math.floor((zi(t)-1)/8)+1);return Wi(a,0,t,a.byteLength),a},zero:tn,one:an});function on(t,a,e){if(Ti(e))return t.one;const o=Ni(e);if(0==o.length)return t.one;let i=a;for(let e=o.length-2;e>=0;e--)i=t.square(i),o[e]&&(i=t.mul(i,a));return i}function nn(t){if(t.m%2==1)if(Hi(Ki(t.p,4),1))if(Hi(Ki(t.p,8),1))if(Hi(Ki(t.p,16),1))!function(t){t.sqrt_q=ji(t.p,t.m),t.sqrt_s=0,t.sqrt_t=$i(t.sqrt_q,1);for(;!Ri(t.sqrt_t);)t.sqrt_s=t.sqrt_s+1,t.sqrt_t=Vi(t.sqrt_t,2);let a=t.one;for(;t.eq(a,t.one);){const e=t.random();t.sqrt_z=t.pow(e,t.sqrt_t),a=t.pow(t.sqrt_z,2**(t.sqrt_s-1))}t.sqrt_tm1d2=Vi($i(t.sqrt_t,1),2),t.sqrt=function(t){const a=this;if(a.isZero(t))return a.zero;let e=a.pow(t,a.sqrt_tm1d2);const o=a.pow(a.mul(a.square(e),t),2**(a.sqrt_s-1));if(a.eq(o,a.negone))return null;let i=a.sqrt_s,n=a.mul(t,e),l=a.mul(n,e),c=a.sqrt_z;for(;!a.eq(l,a.one);){let t=a.square(l),o=1;for(;!a.eq(t,a.one);)t=a.square(t),o++;e=c;for(let t=0;t>>0;return a}class cn{constructor(t,a,e){this.F=a,this.G=t,this.opMulGF=e;let o=a.sqrt_t||a.t,i=a.sqrt_s||a.s,n=a.one;for(;a.eq(a.pow(n,a.half),a.one);)n=a.add(n,a.one);this.w=new Array(i+1),this.wi=new Array(i+1),this.w[i]=this.F.pow(n,o),this.wi[i]=this.F.inv(this.w[i]);let l=i-1;for(;l>=0;)this.w[l]=this.F.square(this.w[l+1]),this.wi[l]=this.F.square(this.wi[l+1]),l--;this.roots=[],this._setRoots(Math.min(i,15))}_setRoots(t){for(let a=t;a>=0&&!this.roots[a];a--){let t=this.F.one;const e=1<>1,c=rn(t,a,e-1,o,2*i),s=rn(t,a,e-1,o+i,2*i),r=new Array(n);for(let a=0;a>this.one,this.bitLength=zi(this.p),this.mask=(this.one<>this.one;this.nqr=this.two;let e=this.pow(this.nqr,a);for(;!this.eq(e,this.negone);)this.nqr=this.nqr+this.one,e=this.pow(this.nqr,a);for(this.s=0,this.t=this.negone;(this.t&this.one)==this.zero;)this.s=this.s+1,this.t=this.t>>this.one;this.nqr_to_t=this.pow(this.nqr,this.t),nn(this),this.FFT=new cn(this,this,this.mul.bind(this)),this.fft=this.FFT.fft.bind(this.FFT),this.ifft=this.FFT.ifft.bind(this.FFT),this.w=this.FFT.w,this.wi=this.FFT.wi,this.shift=this.square(this.nqr),this.k=this.exp(this.nqr,2**this.s)}e(t,a){let e;if(a?16==a&&(e=BigInt("0x"+t)):e=BigInt(t),e<0){let t=-e;return t>=this.p&&(t%=this.p),this.p-t}return e>=this.p?e%this.p:e}add(t,a){const e=t+a;return e>=this.p?e-this.p:e}sub(t,a){return t>=a?t-a:this.p-a+t}neg(t){return t?this.p-t:t}mul(t,a){return t*a%this.p}mulScalar(t,a){return t*this.e(a)%this.p}square(t){return t*t%this.p}eq(t,a){return t==a}neq(t,a){return t!=a}lt(t,a){return(t>this.half?t-this.p:t)<(a>this.half?a-this.p:a)}gt(t,a){return(t>this.half?t-this.p:t)>(a>this.half?a-this.p:a)}leq(t,a){return(t>this.half?t-this.p:t)<=(a>this.half?a-this.p:a)}geq(t,a){return(t>this.half?t-this.p:t)>=(a>this.half?a-this.p:a)}div(t,a){return this.mul(t,this.inv(a))}idiv(t,a){if(!a)throw new Error("Division by zero");return t/a}inv(t){if(!t)throw new Error("Division by zero");let a=this.zero,e=this.p,o=this.one,i=t%this.p;for(;i;){let t=e/i;[a,o]=[o,a-t*o],[e,i]=[i,e-t*i]}return a=this.p?e-this.p:e}bor(t,a){const e=(t|a)&this.mask;return e>=this.p?e-this.p:e}bxor(t,a){const e=(t^a)&this.mask;return e>=this.p?e-this.p:e}bnot(t){const a=t^this.mask;return a>=this.p?a-this.p:a}shl(t,a){if(Number(a)=this.p?e-this.p:e}{const e=this.p-a;return Number(e)>e:this.zero}}shr(t,a){if(Number(a)>a;{const e=this.p-a;if(Number(e)=this.p?a-this.p:a}return 0}}land(t,a){return t&&a?this.one:this.zero}lor(t,a){return t||a?this.one:this.zero}lnot(t){return t?this.zero:this.one}sqrt_old(t){if(t==this.zero)return this.zero;if(this.pow(t,this.negone>>this.one)!=this.one)return null;let a=this.s,e=this.nqr_to_t,o=this.pow(t,this.t),i=this.pow(t,this.add(this.t,this.one)>>this.one);for(;o!=this.one;){let t=this.square(o),n=1;for(;t!=this.one;)n++,t=this.square(t);let l=e;for(let t=0;tthis.p>>this.one&&(i=this.neg(i)),i}normalize(t,a){if((t=BigInt(t,a))<0){let a=-t;return a>=this.p&&(a%=this.p),this.p-a}return t>=this.p?t%this.p:t}random(){const t=2*this.bitLength/8;let a=this.zero;for(let e=0;ethis.half&&10==a){e="-"+(this.p-t).toString(a)}else e=t.toString(a);return e}isZero(t){return t==this.zero}fromRng(t){let a;do{a=this.zero;for(let e=0;e=this.p);return a=a*this.Ri%this.p,a}fft(t){return this.FFT.fft(t)}ifft(t){return this.FFT.ifft(t)}toRprLE(t,a,e){Wi(t,a,e,8*this.n64)}toRprBE(t,a,e){Yi(t,a,e,8*this.n64)}toRprBEM(t,a,e){return this.toRprBE(t,a,this.mul(this.R,e))}toRprLEM(t,a,e){return this.toRprLE(t,a,this.mul(this.R,e))}fromRprLE(t,a){return Ji(t,a,this.n8)}fromRprBE(t,a){return Xi(t,a,this.n8)}fromRprLEM(t,a){return this.mul(this.fromRprLE(t,a),this.Ri)}fromRprBEM(t,a){return this.mul(this.fromRprBE(t,a),this.Ri)}toObject(t){return t}}var un={bigInt2BytesLE:function(t,a){const e=Array(a);let o=BigInt(t);for(let t=0;t>=8n;return e},bigInt2U32LE:function(t,a){const e=Array(a);let o=BigInt(t);for(let t=0;t>=32n;return e},isOcamNum:function(t){return!!Array.isArray(t)&&(3==t.length&&("number"==typeof t[0]&&("number"==typeof t[1]&&!!Array.isArray(t[2]))))}},_n=function(t,a,e,o,i,n,l){const c=t.addFunction(a);c.addParam("base","i32"),c.addParam("scalar","i32"),c.addParam("scalarLength","i32"),c.addParam("r","i32"),c.addLocal("i","i32"),c.addLocal("b","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(e));c.addCode(s.if(s.i32_eqz(s.getLocal("scalarLength")),[...s.call(l,s.getLocal("r")),...s.ret([])])),c.addCode(s.call(n,s.getLocal("base"),r)),c.addCode(s.call(l,s.getLocal("r"))),c.addCode(s.setLocal("i",s.getLocal("scalarLength"))),c.addCode(s.block(s.loop(s.setLocal("i",s.i32_sub(s.getLocal("i"),s.i32_const(1))),s.setLocal("b",s.i32_load8_u(s.i32_add(s.getLocal("scalar"),s.getLocal("i")))),...function(){const t=[];for(let a=0;a<8;a++)t.push(...s.call(i,s.getLocal("r"),s.getLocal("r")),...s.if(s.i32_ge_u(s.getLocal("b"),s.i32_const(128>>a)),[...s.setLocal("b",s.i32_sub(s.getLocal("b"),s.i32_const(128>>a))),...s.call(o,s.getLocal("r"),r,s.getLocal("r"))]));return t}(),s.br_if(1,s.i32_eqz(s.getLocal("i"))),s.br(0))))},gn=function(t,a){const e=8*t.modules[a].n64,o=t.addFunction(a+"_batchInverse");o.addParam("pIn","i32"),o.addParam("inStep","i32"),o.addParam("n","i32"),o.addParam("pOut","i32"),o.addParam("outStep","i32"),o.addLocal("itAux","i32"),o.addLocal("itIn","i32"),o.addLocal("itOut","i32"),o.addLocal("i","i32");const i=o.getCodeBuilder(),n=i.i32_const(t.alloc(e));o.addCode(i.setLocal("itAux",i.i32_load(i.i32_const(0))),i.i32_store(i.i32_const(0),i.i32_add(i.getLocal("itAux"),i.i32_mul(i.i32_add(i.getLocal("n"),i.i32_const(1)),i.i32_const(e))))),o.addCode(i.call(a+"_one",i.getLocal("itAux")),i.setLocal("itIn",i.getLocal("pIn")),i.setLocal("itAux",i.i32_add(i.getLocal("itAux"),i.i32_const(e))),i.setLocal("i",i.i32_const(0)),i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("i"),i.getLocal("n"))),i.if(i.call(a+"_isZero",i.getLocal("itIn")),i.call(a+"_copy",i.i32_sub(i.getLocal("itAux"),i.i32_const(e)),i.getLocal("itAux")),i.call(a+"_mul",i.getLocal("itIn"),i.i32_sub(i.getLocal("itAux"),i.i32_const(e)),i.getLocal("itAux"))),i.setLocal("itIn",i.i32_add(i.getLocal("itIn"),i.getLocal("inStep"))),i.setLocal("itAux",i.i32_add(i.getLocal("itAux"),i.i32_const(e))),i.setLocal("i",i.i32_add(i.getLocal("i"),i.i32_const(1))),i.br(0))),i.setLocal("itIn",i.i32_sub(i.getLocal("itIn"),i.getLocal("inStep"))),i.setLocal("itAux",i.i32_sub(i.getLocal("itAux"),i.i32_const(e))),i.setLocal("itOut",i.i32_add(i.getLocal("pOut"),i.i32_mul(i.i32_sub(i.getLocal("n"),i.i32_const(1)),i.getLocal("outStep")))),i.call(a+"_inverse",i.getLocal("itAux"),i.getLocal("itAux")),i.block(i.loop(i.br_if(1,i.i32_eqz(i.getLocal("i"))),i.if(i.call(a+"_isZero",i.getLocal("itIn")),[...i.call(a+"_copy",i.getLocal("itAux"),i.i32_sub(i.getLocal("itAux"),i.i32_const(e))),...i.call(a+"_zero",i.getLocal("itOut"))],[...i.call(a+"_copy",i.i32_sub(i.getLocal("itAux"),i.i32_const(e)),n),...i.call(a+"_mul",i.getLocal("itAux"),i.getLocal("itIn"),i.i32_sub(i.getLocal("itAux"),i.i32_const(e))),...i.call(a+"_mul",i.getLocal("itAux"),n,i.getLocal("itOut"))]),i.setLocal("itIn",i.i32_sub(i.getLocal("itIn"),i.getLocal("inStep"))),i.setLocal("itOut",i.i32_sub(i.getLocal("itOut"),i.getLocal("outStep"))),i.setLocal("itAux",i.i32_sub(i.getLocal("itAux"),i.i32_const(e))),i.setLocal("i",i.i32_sub(i.getLocal("i"),i.i32_const(1))),i.br(0)))),o.addCode(i.i32_store(i.i32_const(0),i.getLocal("itAux")))};var fn=function(t,a,e,o,i,n){void 0===n&&(n=oa?1:-1}function Ln(t){return t*t}function bn(t){return t%2n!==0n}function wn(t){return t%2n===0n}function yn(t){return t<0n}function An(t){return t>0n}function Cn(t){return yn(t)?t.toString(2).length-1:t.toString(2).length}function Fn(t){return t<0n?-t:t}function xn(t){return 1n===Fn(t)}function In(t,a){for(var e,o,i,n=0n,l=1n,c=a,s=Fn(t);0n!==s;)e=c/s,o=n,i=c,n=l,c=s,l=o-e*l,s=i-e*s;if(!xn(c))throw new Error(t.toString()+" and "+a.toString()+" are not co-prime");return-1===mn(n,0n)&&(n+=a),yn(t)?-n:n}function Bn(t,a,e){if(0n===e)throw new Error("Cannot take modPow with modulus 0");var o=1n,i=t%e;for(yn(a)&&(a*=-1n,i=In(i,e));An(a);){if(0n===i)return 0n;bn(a)&&(o=o*i%e),a/=2n,i=Ln(i)%e}return o}function En(t,a){return 0n!==a&&(!!xn(a)||(0===function(t,a){return(t=t>=0n?t:-t)===(a=a>=0n?a:-a)?0:t>a?1:-1}(a,2n)?wn(t):t%a===0n))}function vn(t,a){for(var e,o,i,n=function(t){return t-1n}(t),l=n,c=0;wn(l);)l/=2n,c++;t:for(o=0;o>1&&o>1,t>>1)))),a.addCode(e.setLocal(s,e.i64_add(e.getLocal(s),e.i64_shr_u(e.getLocal(c),e.i64_const(32)))))),t>0&&(a.addCode(e.setLocal(c,e.i64_add(e.i64_and(e.getLocal(c),e.i64_const(4294967295)),e.i64_and(e.getLocal(r),e.i64_const(4294967295))))),a.addCode(e.setLocal(s,e.i64_add(e.i64_add(e.getLocal(s),e.i64_shr_u(e.getLocal(c),e.i64_const(32))),e.getLocal(d))))),a.addCode(e.i64_store32(e.getLocal("r"),4*t,e.getLocal(c))),a.addCode(e.setLocal(r,e.getLocal(s)),e.setLocal(d,e.i64_shr_u(e.getLocal(r),e.i64_const(32))))}a.addCode(e.i64_store32(e.getLocal("r"),4*i*2-4,e.getLocal(r)))}(),function(){const a=t.addFunction(o+"_squareOld");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(o+"_mul",e.getLocal("x"),e.getLocal("x"),e.getLocal("r")))}(),function(){!function(){const a=t.addFunction(o+"__mul1");a.addParam("px","i32"),a.addParam("y","i64"),a.addParam("pr","i32"),a.addLocal("c","i64");const e=a.getCodeBuilder();a.addCode(e.setLocal("c",e.i64_mul(e.i64_load32_u(e.getLocal("px"),0,0),e.getLocal("y")))),a.addCode(e.i64_store32(e.getLocal("pr"),0,0,e.getLocal("c")));for(let t=1;t>1n,p=t.alloc(c,Pn.bigInt2BytesLE(h,c)),m=h+1n,L=t.alloc(c,Pn.bigInt2BytesLE(m,c));t.modules[s]={pq:d,pR2:u,n64:n,q:i,pOne:_,pZero:g,pePlusOne:L};let b=2n;if(Qn(i))for(;Un(b,h,i)!==f;)b+=1n;let w=0,y=f;for(;!kn(y)&&0n!==y;)w++,y>>=1n;const A=t.alloc(c,Pn.bigInt2BytesLE(y,c)),C=Un(b,y,i),F=t.alloc(Pn.bigInt2BytesLE((C<>1n,I=t.alloc(c,Pn.bigInt2BytesLE(x,c));return t.exportFunction(r+"_copy",s+"_copy"),t.exportFunction(r+"_zero",s+"_zero"),t.exportFunction(r+"_isZero",s+"_isZero"),t.exportFunction(r+"_eq",s+"_eq"),function(){const a=t.addFunction(s+"_isOne");a.addParam("x","i32"),a.setReturnType("i32");const e=a.getCodeBuilder();a.addCode(e.ret(e.call(r+"_eq",e.getLocal("x"),e.i32_const(_))))}(),function(){const a=t.addFunction(s+"_add");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.if(e.call(r+"_add",e.getLocal("x"),e.getLocal("y"),e.getLocal("r")),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))),e.if(e.call(r+"_gte",e.getLocal("r"),e.i32_const(d)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))))))}(),function(){const a=t.addFunction(s+"_sub");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.if(e.call(r+"_sub",e.getLocal("x"),e.getLocal("y"),e.getLocal("r")),e.drop(e.call(r+"_add",e.getLocal("r"),e.i32_const(d),e.getLocal("r")))))}(),function(){const a=t.addFunction(s+"_neg");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_sub",e.i32_const(g),e.getLocal("x"),e.getLocal("r")))}(),function(){const a=t.alloc(l*l*8),e=t.addFunction(s+"_mReduct");e.addParam("t","i32"),e.addParam("r","i32"),e.addLocal("np32","i64"),e.addLocal("c","i64"),e.addLocal("m","i64");const o=e.getCodeBuilder(),n=Number(0x100000000n-Mn(i,0x100000000n));e.addCode(o.setLocal("np32",o.i64_const(n)));for(let t=0;t=l&&a.addCode(e.i64_store32(e.getLocal("r"),4*(t-l),e.getLocal(f))),[f,h]=[h,f],a.addCode(e.setLocal(h,e.i64_shr_u(e.getLocal(f),e.i64_const(32))))}a.addCode(e.i64_store32(e.getLocal("r"),4*l-4,e.getLocal(f))),a.addCode(e.if(e.i32_wrap_i64(e.getLocal(h)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))),e.if(e.call(r+"_gte",e.getLocal("r"),e.i32_const(d)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))))))}(),function(){const a=t.addFunction(s+"_square");a.addParam("x","i32"),a.addParam("r","i32"),a.addLocal("c0","i64"),a.addLocal("c1","i64"),a.addLocal("c0_old","i64"),a.addLocal("c1_old","i64"),a.addLocal("np32","i64");for(let t=0;t>1&&o>1,t>>1)))),a.addCode(e.setLocal(f,e.i64_add(e.getLocal(f),e.i64_shr_u(e.getLocal(g),e.i64_const(32)))))),t>0&&(a.addCode(e.setLocal(g,e.i64_add(e.i64_and(e.getLocal(g),e.i64_const(4294967295)),e.i64_and(e.getLocal(h),e.i64_const(4294967295))))),a.addCode(e.setLocal(f,e.i64_add(e.i64_add(e.getLocal(f),e.i64_shr_u(e.getLocal(g),e.i64_const(32))),e.getLocal(p)))));for(let o=Math.max(1,t-l+1);o<=t&&o=l&&a.addCode(e.i64_store32(e.getLocal("r"),4*(t-l),e.getLocal(g))),a.addCode(e.setLocal(h,e.getLocal(f)),e.setLocal(p,e.i64_shr_u(e.getLocal(h),e.i64_const(32))))}a.addCode(e.i64_store32(e.getLocal("r"),4*l-4,e.getLocal(h))),a.addCode(e.if(e.i32_wrap_i64(e.getLocal(p)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))),e.if(e.call(r+"_gte",e.getLocal("r"),e.i32_const(d)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))))))}(),function(){const a=t.addFunction(s+"_squareOld");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_mul",e.getLocal("x"),e.getLocal("x"),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_toMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_mul",e.getLocal("x"),e.i32_const(u),e.getLocal("r")))}(),function(){const a=t.alloc(2*c),e=t.addFunction(s+"_fromMontgomery");e.addParam("x","i32"),e.addParam("r","i32");const o=e.getCodeBuilder();e.addCode(o.call(r+"_copy",o.getLocal("x"),o.i32_const(a))),e.addCode(o.call(r+"_zero",o.i32_const(a+c))),e.addCode(o.call(s+"_mReduct",o.i32_const(a),o.getLocal("r")))}(),function(){const a=t.addFunction(s+"_isNegative");a.addParam("x","i32"),a.setReturnType("i32");const e=a.getCodeBuilder(),o=e.i32_const(t.alloc(c));a.addCode(e.call(s+"_fromMontgomery",e.getLocal("x"),o),e.call(r+"_gte",o,e.i32_const(L)))}(),function(){const a=t.addFunction(s+"_sign");a.addParam("x","i32"),a.setReturnType("i32");const e=a.getCodeBuilder(),o=e.i32_const(t.alloc(c));a.addCode(e.if(e.call(r+"_isZero",e.getLocal("x")),e.ret(e.i32_const(0))),e.call(s+"_fromMontgomery",e.getLocal("x"),o),e.if(e.call(r+"_gte",o,e.i32_const(L)),e.ret(e.i32_const(-1))),e.ret(e.i32_const(1)))}(),function(){const a=t.addFunction(s+"_inverse");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_fromMontgomery",e.getLocal("x"),e.getLocal("r"))),a.addCode(e.call(r+"_inverseMod",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))),a.addCode(e.call(s+"_toMontgomery",e.getLocal("r"),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_one");a.addParam("pr","i32");const e=a.getCodeBuilder();a.addCode(e.call(r+"_copy",e.i32_const(_),e.getLocal("pr")))}(),function(){const a=t.addFunction(s+"_load");a.addParam("scalar","i32"),a.addParam("scalarLen","i32"),a.addParam("r","i32"),a.addLocal("p","i32"),a.addLocal("l","i32"),a.addLocal("i","i32"),a.addLocal("j","i32");const e=a.getCodeBuilder(),o=e.i32_const(t.alloc(c)),i=t.alloc(c),n=e.i32_const(i);a.addCode(e.call(r+"_zero",e.getLocal("r")),e.setLocal("i",e.i32_const(c)),e.setLocal("p",e.getLocal("scalar")),e.block(e.loop(e.br_if(1,e.i32_gt_u(e.getLocal("i"),e.getLocal("scalarLen"))),e.if(e.i32_eq(e.getLocal("i"),e.i32_const(c)),e.call(s+"_one",o),e.call(s+"_mul",o,e.i32_const(u),o)),e.call(s+"_mul",e.getLocal("p"),o,n),e.call(s+"_add",e.getLocal("r"),n,e.getLocal("r")),e.setLocal("p",e.i32_add(e.getLocal("p"),e.i32_const(c))),e.setLocal("i",e.i32_add(e.getLocal("i"),e.i32_const(c))),e.br(0))),e.setLocal("l",e.i32_rem_u(e.getLocal("scalarLen"),e.i32_const(c))),e.if(e.i32_eqz(e.getLocal("l")),e.ret([])),e.call(r+"_zero",n),e.setLocal("j",e.i32_const(0)),e.block(e.loop(e.br_if(1,e.i32_eq(e.getLocal("j"),e.getLocal("l"))),e.i32_store8(e.getLocal("j"),i,e.i32_load8_u(e.getLocal("p"))),e.setLocal("p",e.i32_add(e.getLocal("p"),e.i32_const(1))),e.setLocal("j",e.i32_add(e.getLocal("j"),e.i32_const(1))),e.br(0))),e.if(e.i32_eq(e.getLocal("i"),e.i32_const(c)),e.call(s+"_one",o),e.call(s+"_mul",o,e.i32_const(u),o)),e.call(s+"_mul",n,o,n),e.call(s+"_add",e.getLocal("r"),n,e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_timesScalar");a.addParam("x","i32"),a.addParam("scalar","i32"),a.addParam("scalarLen","i32"),a.addParam("r","i32");const e=a.getCodeBuilder(),o=e.i32_const(t.alloc(c));a.addCode(e.call(s+"_load",e.getLocal("scalar"),e.getLocal("scalarLen"),o),e.call(s+"_toMontgomery",o,o),e.call(s+"_mul",e.getLocal("x"),o,e.getLocal("r")))}(),On(t,s),Gn(t,s+"_batchToMontgomery",s+"_toMontgomery",c,c),Gn(t,s+"_batchFromMontgomery",s+"_fromMontgomery",c,c),Gn(t,s+"_batchNeg",s+"_neg",c,c),zn(t,s+"_batchAdd",s+"_add",c,c),zn(t,s+"_batchSub",s+"_sub",c,c),zn(t,s+"_batchMul",s+"_mul",c,c),t.exportFunction(s+"_add"),t.exportFunction(s+"_sub"),t.exportFunction(s+"_neg"),t.exportFunction(s+"_isNegative"),t.exportFunction(s+"_isOne"),t.exportFunction(s+"_sign"),t.exportFunction(s+"_mReduct"),t.exportFunction(s+"_mul"),t.exportFunction(s+"_square"),t.exportFunction(s+"_squareOld"),t.exportFunction(s+"_fromMontgomery"),t.exportFunction(s+"_toMontgomery"),t.exportFunction(s+"_inverse"),t.exportFunction(s+"_one"),t.exportFunction(s+"_load"),t.exportFunction(s+"_timesScalar"),qn(t,s+"_exp",c,s+"_mul",s+"_square",r+"_copy",s+"_one"),t.exportFunction(s+"_exp"),t.exportFunction(s+"_batchInverse"),Qn(i)&&(!function(){const a=t.addFunction(s+"_sqrt");a.addParam("n","i32"),a.addParam("r","i32"),a.addLocal("m","i32"),a.addLocal("i","i32"),a.addLocal("j","i32");const e=a.getCodeBuilder(),o=e.i32_const(_),i=e.i32_const(t.alloc(c)),n=e.i32_const(t.alloc(c)),l=e.i32_const(t.alloc(c)),r=e.i32_const(t.alloc(c)),d=e.i32_const(t.alloc(c));a.addCode(e.if(e.call(s+"_isZero",e.getLocal("n")),e.ret(e.call(s+"_zero",e.getLocal("r")))),e.setLocal("m",e.i32_const(w)),e.call(s+"_copy",e.i32_const(F),i),e.call(s+"_exp",e.getLocal("n"),e.i32_const(A),e.i32_const(c),n),e.call(s+"_exp",e.getLocal("n"),e.i32_const(I),e.i32_const(c),l),e.block(e.loop(e.br_if(1,e.call(s+"_eq",n,o)),e.call(s+"_square",n,r),e.setLocal("i",e.i32_const(1)),e.block(e.loop(e.br_if(1,e.call(s+"_eq",r,o)),e.call(s+"_square",r,r),e.setLocal("i",e.i32_add(e.getLocal("i"),e.i32_const(1))),e.br(0))),e.call(s+"_copy",i,d),e.setLocal("j",e.i32_sub(e.i32_sub(e.getLocal("m"),e.getLocal("i")),e.i32_const(1))),e.block(e.loop(e.br_if(1,e.i32_eqz(e.getLocal("j"))),e.call(s+"_square",d,d),e.setLocal("j",e.i32_sub(e.getLocal("j"),e.i32_const(1))),e.br(0))),e.setLocal("m",e.getLocal("i")),e.call(s+"_square",d,i),e.call(s+"_mul",n,i,n),e.call(s+"_mul",l,d,l),e.br(0))),e.if(e.call(s+"_isNegative",l),e.call(s+"_neg",l,e.getLocal("r")),e.call(s+"_copy",l,e.getLocal("r"))))}(),function(){const a=t.addFunction(s+"_isSquare");a.addParam("n","i32"),a.setReturnType("i32");const e=a.getCodeBuilder(),o=e.i32_const(_),i=e.i32_const(t.alloc(c));a.addCode(e.if(e.call(s+"_isZero",e.getLocal("n")),e.ret(e.i32_const(1))),e.call(s+"_exp",e.getLocal("n"),e.i32_const(p),e.i32_const(c),i),e.call(s+"_eq",i,o))}(),t.exportFunction(s+"_sqrt"),t.exportFunction(s+"_isSquare")),t.exportFunction(s+"_batchToMontgomery"),t.exportFunction(s+"_batchFromMontgomery"),s};const Dn=Nn,{bitLength:$n}=pn;var jn=function(t,a,e,o,i){const n=BigInt(a),l=Math.floor(($n(n-1n)-1)/64)+1,c=8*l,s=e||"f1";if(t.modules[s])return s;t.modules[s]={n64:l};const r=i||"int",d=Dn(t,n,o,r),u=t.modules[d].pR2,_=t.modules[d].pq,g=t.modules[d].pePlusOne;return function(){const a=t.alloc(c),e=t.addFunction(s+"_mul");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32");const o=e.getCodeBuilder();e.addCode(o.call(d+"_mul",o.getLocal("x"),o.getLocal("y"),o.i32_const(a))),e.addCode(o.call(d+"_mul",o.i32_const(a),o.i32_const(u),o.getLocal("r")))}(),function(){const a=t.addFunction(s+"_square");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_mul",e.getLocal("x"),e.getLocal("x"),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_inverse");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(r+"_inverseMod",e.getLocal("x"),e.i32_const(_),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_isNegative");a.addParam("x","i32"),a.setReturnType("i32");const e=a.getCodeBuilder();a.addCode(e.call(r+"_gte",e.getLocal("x"),e.i32_const(g)))}(),t.exportFunction(d+"_add",s+"_add"),t.exportFunction(d+"_sub",s+"_sub"),t.exportFunction(d+"_neg",s+"_neg"),t.exportFunction(s+"_mul"),t.exportFunction(s+"_square"),t.exportFunction(s+"_inverse"),t.exportFunction(s+"_isNegative"),t.exportFunction(d+"_copy",s+"_copy"),t.exportFunction(d+"_zero",s+"_zero"),t.exportFunction(d+"_one",s+"_one"),t.exportFunction(d+"_isZero",s+"_isZero"),t.exportFunction(d+"_eq",s+"_eq"),s};const Vn=_n,Kn=gn,Hn=un;var Zn=function(t,a,e,o){if(t.modules[e])return e;const i=8*t.modules[o].n64,n=t.modules[o].q;return t.modules[e]={n64:2*t.modules[o].n64},function(){const a=t.addFunction(e+"_isZero");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.i32_and(n.call(o+"_isZero",l),n.call(o+"_isZero",c)))}(),function(){const a=t.addFunction(e+"_isOne");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.ret(n.i32_and(n.call(o+"_isOne",l),n.call(o+"_isZero",c))))}(),function(){const a=t.addFunction(e+"_zero");a.addParam("x","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.call(o+"_zero",l),n.call(o+"_zero",c))}(),function(){const a=t.addFunction(e+"_one");a.addParam("x","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.call(o+"_one",l),n.call(o+"_zero",c))}(),function(){const a=t.addFunction(e+"_copy");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_copy",l,s),n.call(o+"_copy",c,r))}(),function(){const n=t.addFunction(e+"_mul");n.addParam("x","i32"),n.addParam("y","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.getLocal("y"),d=l.i32_add(l.getLocal("y"),l.i32_const(i)),u=l.getLocal("r"),_=l.i32_add(l.getLocal("r"),l.i32_const(i)),g=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i)),h=l.i32_const(t.alloc(i)),p=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_mul",c,r,g),l.call(o+"_mul",s,d,f),l.call(o+"_add",c,s,h),l.call(o+"_add",r,d,p),l.call(o+"_mul",h,p,h),l.call(a,f,u),l.call(o+"_add",g,u,u),l.call(o+"_add",g,f,_),l.call(o+"_sub",h,_,_))}(),function(){const a=t.addFunction(e+"_mul1");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("y"),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_mul",l,s,r),n.call(o+"_mul",c,s,d))}(),function(){const n=t.addFunction(e+"_square");n.addParam("x","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.getLocal("r"),d=l.i32_add(l.getLocal("r"),l.i32_const(i)),u=l.i32_const(t.alloc(i)),_=l.i32_const(t.alloc(i)),g=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_mul",c,s,u),l.call(o+"_add",c,s,_),l.call(a,s,g),l.call(o+"_add",c,g,g),l.call(a,u,f),l.call(o+"_add",f,u,f),l.call(o+"_mul",_,g,r),l.call(o+"_sub",r,f,r),l.call(o+"_add",u,u,d))}(),function(){const a=t.addFunction(e+"_add");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("y"),r=n.i32_add(n.getLocal("y"),n.i32_const(i)),d=n.getLocal("r"),u=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_add",l,s,d),n.call(o+"_add",c,r,u))}(),function(){const a=t.addFunction(e+"_sub");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("y"),r=n.i32_add(n.getLocal("y"),n.i32_const(i)),d=n.getLocal("r"),u=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_sub",l,s,d),n.call(o+"_sub",c,r,u))}(),function(){const a=t.addFunction(e+"_neg");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_neg",l,s),n.call(o+"_neg",c,r))}(),function(){const a=t.addFunction(e+"_conjugate");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_copy",l,s),n.call(o+"_neg",c,r))}(),function(){const a=t.addFunction(e+"_toMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_toMontgomery",l,s),n.call(o+"_toMontgomery",c,r))}(),function(){const a=t.addFunction(e+"_fromMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_fromMontgomery",l,s),n.call(o+"_fromMontgomery",c,r))}(),function(){const a=t.addFunction(e+"_eq");a.addParam("x","i32"),a.addParam("y","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("y"),r=n.i32_add(n.getLocal("y"),n.i32_const(i));a.addCode(n.i32_and(n.call(o+"_eq",l,s),n.call(o+"_eq",c,r)))}(),function(){const n=t.addFunction(e+"_inverse");n.addParam("x","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.getLocal("r"),d=l.i32_add(l.getLocal("r"),l.i32_const(i)),u=l.i32_const(t.alloc(i)),_=l.i32_const(t.alloc(i)),g=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_square",c,u),l.call(o+"_square",s,_),l.call(a,_,g),l.call(o+"_sub",u,g,g),l.call(o+"_inverse",g,f),l.call(o+"_mul",c,f,r),l.call(o+"_mul",s,f,d),l.call(o+"_neg",d,d))}(),function(){const a=t.addFunction(e+"_timesScalar");a.addParam("x","i32"),a.addParam("scalar","i32"),a.addParam("scalarLen","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_timesScalar",l,n.getLocal("scalar"),n.getLocal("scalarLen"),s),n.call(o+"_timesScalar",c,n.getLocal("scalar"),n.getLocal("scalarLen"),r))}(),function(){const a=t.addFunction(e+"_sign");a.addParam("x","i32"),a.addLocal("s","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.setLocal("s",n.call(o+"_sign",c)),n.if(n.getLocal("s"),n.ret(n.getLocal("s"))),n.ret(n.call(o+"_sign",l)))}(),function(){const a=t.addFunction(e+"_isNegative");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.if(n.call(o+"_isZero",c),n.ret(n.call(o+"_isNegative",l))),n.ret(n.call(o+"_isNegative",c)))}(),t.exportFunction(e+"_isZero"),t.exportFunction(e+"_isOne"),t.exportFunction(e+"_zero"),t.exportFunction(e+"_one"),t.exportFunction(e+"_copy"),t.exportFunction(e+"_mul"),t.exportFunction(e+"_mul1"),t.exportFunction(e+"_square"),t.exportFunction(e+"_add"),t.exportFunction(e+"_sub"),t.exportFunction(e+"_neg"),t.exportFunction(e+"_sign"),t.exportFunction(e+"_conjugate"),t.exportFunction(e+"_fromMontgomery"),t.exportFunction(e+"_toMontgomery"),t.exportFunction(e+"_eq"),t.exportFunction(e+"_inverse"),Kn(t,e),Vn(t,e+"_exp",2*i,e+"_mul",e+"_square",e+"_copy",e+"_one"),function(){const a=t.addFunction(e+"_sqrt");a.addParam("a","i32"),a.addParam("pr","i32");const l=a.getCodeBuilder(),c=l.i32_const(t.alloc(Hn.bigInt2BytesLE((BigInt(n||0)-3n)/4n,i))),s=l.i32_const(t.alloc(Hn.bigInt2BytesLE((BigInt(n||0)-1n)/2n,i))),r=l.getLocal("a"),d=l.i32_const(t.alloc(2*i)),u=l.i32_const(t.alloc(2*i)),_=l.i32_const(t.alloc(2*i)),g=t.alloc(2*i),f=l.i32_const(g),h=l.i32_const(g),p=l.i32_const(g+i),m=l.i32_const(t.alloc(2*i)),L=l.i32_const(t.alloc(2*i));a.addCode(l.call(e+"_one",f),l.call(e+"_neg",f,f),l.call(e+"_exp",r,c,l.i32_const(i),d),l.call(e+"_square",d,u),l.call(e+"_mul",r,u,u),l.call(e+"_conjugate",u,_),l.call(e+"_mul",_,u,_),l.if(l.call(e+"_eq",_,f),l.unreachable()),l.call(e+"_mul",d,r,m),l.if(l.call(e+"_eq",u,f),[...l.call(o+"_zero",h),...l.call(o+"_one",p),...l.call(e+"_mul",f,m,l.getLocal("pr"))],[...l.call(e+"_one",L),...l.call(e+"_add",L,u,L),...l.call(e+"_exp",L,s,l.i32_const(i),L),...l.call(e+"_mul",L,m,l.getLocal("pr"))]))}(),function(){const a=t.addFunction(e+"_isSquare");a.addParam("a","i32"),a.setReturnType("i32");const o=a.getCodeBuilder(),l=o.i32_const(t.alloc(Hn.bigInt2BytesLE((BigInt(n||0)-3n)/4n,i))),c=o.getLocal("a"),s=o.i32_const(t.alloc(2*i)),r=o.i32_const(t.alloc(2*i)),d=o.i32_const(t.alloc(2*i)),u=t.alloc(2*i),_=o.i32_const(u);a.addCode(o.call(e+"_one",_),o.call(e+"_neg",_,_),o.call(e+"_exp",c,l,o.i32_const(i),s),o.call(e+"_square",s,r),o.call(e+"_mul",c,r,r),o.call(e+"_conjugate",r,d),o.call(e+"_mul",d,r,d),o.if(o.call(e+"_eq",d,_),o.ret(o.i32_const(0))),o.ret(o.i32_const(1)))}(),t.exportFunction(e+"_exp"),t.exportFunction(e+"_timesScalar"),t.exportFunction(e+"_batchInverse"),t.exportFunction(e+"_sqrt"),t.exportFunction(e+"_isSquare"),t.exportFunction(e+"_isNegative"),e};const Wn=_n,Yn=gn;var Jn=function(t,a,e,o){if(t.modules[e])return e;const i=8*t.modules[o].n64;return t.modules[e]={n64:3*t.modules[o].n64},function(){const a=t.addFunction(e+"_isZero");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.i32_and(n.i32_and(n.call(o+"_isZero",l),n.call(o+"_isZero",c)),n.call(o+"_isZero",s)))}(),function(){const a=t.addFunction(e+"_isOne");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.ret(n.i32_and(n.i32_and(n.call(o+"_isOne",l),n.call(o+"_isZero",c)),n.call(o+"_isZero",s))))}(),function(){const a=t.addFunction(e+"_zero");a.addParam("x","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.call(o+"_zero",l),n.call(o+"_zero",c),n.call(o+"_zero",s))}(),function(){const a=t.addFunction(e+"_one");a.addParam("x","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.call(o+"_one",l),n.call(o+"_zero",c),n.call(o+"_zero",s))}(),function(){const a=t.addFunction(e+"_copy");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_copy",l,r),n.call(o+"_copy",c,d),n.call(o+"_copy",s,u))}(),function(){const n=t.addFunction(e+"_mul");n.addParam("x","i32"),n.addParam("y","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.i32_add(l.getLocal("x"),l.i32_const(2*i)),d=l.getLocal("y"),u=l.i32_add(l.getLocal("y"),l.i32_const(i)),_=l.i32_add(l.getLocal("y"),l.i32_const(2*i)),g=l.getLocal("r"),f=l.i32_add(l.getLocal("r"),l.i32_const(i)),h=l.i32_add(l.getLocal("r"),l.i32_const(2*i)),p=l.i32_const(t.alloc(i)),m=l.i32_const(t.alloc(i)),L=l.i32_const(t.alloc(i)),b=l.i32_const(t.alloc(i)),w=l.i32_const(t.alloc(i)),y=l.i32_const(t.alloc(i)),A=l.i32_const(t.alloc(i)),C=l.i32_const(t.alloc(i)),F=l.i32_const(t.alloc(i)),x=l.i32_const(t.alloc(i)),I=l.i32_const(t.alloc(i)),B=l.i32_const(t.alloc(i)),E=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_mul",c,d,p),l.call(o+"_mul",s,u,m),l.call(o+"_mul",r,_,L),l.call(o+"_add",c,s,b),l.call(o+"_add",d,u,w),l.call(o+"_add",c,r,y),l.call(o+"_add",d,_,A),l.call(o+"_add",s,r,C),l.call(o+"_add",u,_,F),l.call(o+"_add",p,m,x),l.call(o+"_add",p,L,I),l.call(o+"_add",m,L,B),l.call(o+"_mul",C,F,g),l.call(o+"_sub",g,B,g),l.call(a,g,g),l.call(o+"_add",p,g,g),l.call(o+"_mul",b,w,f),l.call(o+"_sub",f,x,f),l.call(a,L,E),l.call(o+"_add",f,E,f),l.call(o+"_mul",y,A,h),l.call(o+"_sub",h,I,h),l.call(o+"_add",h,m,h))}(),function(){const n=t.addFunction(e+"_square");n.addParam("x","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.i32_add(l.getLocal("x"),l.i32_const(2*i)),d=l.getLocal("r"),u=l.i32_add(l.getLocal("r"),l.i32_const(i)),_=l.i32_add(l.getLocal("r"),l.i32_const(2*i)),g=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i)),h=l.i32_const(t.alloc(i)),p=l.i32_const(t.alloc(i)),m=l.i32_const(t.alloc(i)),L=l.i32_const(t.alloc(i)),b=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_square",c,g),l.call(o+"_mul",c,s,f),l.call(o+"_add",f,f,h),l.call(o+"_sub",c,s,p),l.call(o+"_add",p,r,p),l.call(o+"_square",p,p),l.call(o+"_mul",s,r,m),l.call(o+"_add",m,m,L),l.call(o+"_square",r,b),l.call(a,L,d),l.call(o+"_add",g,d,d),l.call(a,b,u),l.call(o+"_add",h,u,u),l.call(o+"_add",g,b,_),l.call(o+"_sub",L,_,_),l.call(o+"_add",p,_,_),l.call(o+"_add",h,_,_))}(),function(){const a=t.addFunction(e+"_add");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("y"),d=n.i32_add(n.getLocal("y"),n.i32_const(i)),u=n.i32_add(n.getLocal("y"),n.i32_const(2*i)),_=n.getLocal("r"),g=n.i32_add(n.getLocal("r"),n.i32_const(i)),f=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_add",l,r,_),n.call(o+"_add",c,d,g),n.call(o+"_add",s,u,f))}(),function(){const a=t.addFunction(e+"_sub");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("y"),d=n.i32_add(n.getLocal("y"),n.i32_const(i)),u=n.i32_add(n.getLocal("y"),n.i32_const(2*i)),_=n.getLocal("r"),g=n.i32_add(n.getLocal("r"),n.i32_const(i)),f=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_sub",l,r,_),n.call(o+"_sub",c,d,g),n.call(o+"_sub",s,u,f))}(),function(){const a=t.addFunction(e+"_neg");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_neg",l,r),n.call(o+"_neg",c,d),n.call(o+"_neg",s,u))}(),function(){const a=t.addFunction(e+"_sign");a.addParam("x","i32"),a.addLocal("s","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.setLocal("s",n.call(o+"_sign",s)),n.if(n.getLocal("s"),n.ret(n.getLocal("s"))),n.setLocal("s",n.call(o+"_sign",c)),n.if(n.getLocal("s"),n.ret(n.getLocal("s"))),n.ret(n.call(o+"_sign",l)))}(),function(){const a=t.addFunction(e+"_toMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_toMontgomery",l,r),n.call(o+"_toMontgomery",c,d),n.call(o+"_toMontgomery",s,u))}(),function(){const a=t.addFunction(e+"_fromMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_fromMontgomery",l,r),n.call(o+"_fromMontgomery",c,d),n.call(o+"_fromMontgomery",s,u))}(),function(){const a=t.addFunction(e+"_eq");a.addParam("x","i32"),a.addParam("y","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("y"),d=n.i32_add(n.getLocal("y"),n.i32_const(i)),u=n.i32_add(n.getLocal("y"),n.i32_const(2*i));a.addCode(n.i32_and(n.i32_and(n.call(o+"_eq",l,r),n.call(o+"_eq",c,d)),n.call(o+"_eq",s,u)))}(),function(){const n=t.addFunction(e+"_inverse");n.addParam("x","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.i32_add(l.getLocal("x"),l.i32_const(2*i)),d=l.getLocal("r"),u=l.i32_add(l.getLocal("r"),l.i32_const(i)),_=l.i32_add(l.getLocal("r"),l.i32_const(2*i)),g=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i)),h=l.i32_const(t.alloc(i)),p=l.i32_const(t.alloc(i)),m=l.i32_const(t.alloc(i)),L=l.i32_const(t.alloc(i)),b=l.i32_const(t.alloc(i)),w=l.i32_const(t.alloc(i)),y=l.i32_const(t.alloc(i)),A=l.i32_const(t.alloc(i)),C=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_square",c,g),l.call(o+"_square",s,f),l.call(o+"_square",r,h),l.call(o+"_mul",c,s,p),l.call(o+"_mul",c,r,m),l.call(o+"_mul",s,r,L),l.call(a,L,b),l.call(o+"_sub",g,b,b),l.call(a,h,w),l.call(o+"_sub",w,p,w),l.call(o+"_sub",f,m,y),l.call(o+"_mul",r,w,A),l.call(o+"_mul",s,y,C),l.call(o+"_add",A,C,A),l.call(a,A,A),l.call(o+"_mul",c,b,C),l.call(o+"_add",C,A,A),l.call(o+"_inverse",A,A),l.call(o+"_mul",A,b,d),l.call(o+"_mul",A,w,u),l.call(o+"_mul",A,y,_))}(),function(){const a=t.addFunction(e+"_timesScalar");a.addParam("x","i32"),a.addParam("scalar","i32"),a.addParam("scalarLen","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_timesScalar",l,n.getLocal("scalar"),n.getLocal("scalarLen"),r),n.call(o+"_timesScalar",c,n.getLocal("scalar"),n.getLocal("scalarLen"),d),n.call(o+"_timesScalar",s,n.getLocal("scalar"),n.getLocal("scalarLen"),u))}(),function(){const a=t.addFunction(e+"_isNegative");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.if(n.call(o+"_isZero",s),n.if(n.call(o+"_isZero",c),n.ret(n.call(o+"_isNegative",l)),n.ret(n.call(o+"_isNegative",c)))),n.ret(n.call(o+"_isNegative",s)))}(),t.exportFunction(e+"_isZero"),t.exportFunction(e+"_isOne"),t.exportFunction(e+"_zero"),t.exportFunction(e+"_one"),t.exportFunction(e+"_copy"),t.exportFunction(e+"_mul"),t.exportFunction(e+"_square"),t.exportFunction(e+"_add"),t.exportFunction(e+"_sub"),t.exportFunction(e+"_neg"),t.exportFunction(e+"_sign"),t.exportFunction(e+"_fromMontgomery"),t.exportFunction(e+"_toMontgomery"),t.exportFunction(e+"_eq"),t.exportFunction(e+"_inverse"),Yn(t,e),Wn(t,e+"_exp",3*i,e+"_mul",e+"_square",e+"_copy",e+"_one"),t.exportFunction(e+"_exp"),t.exportFunction(e+"_timesScalar"),t.exportFunction(e+"_batchInverse"),t.exportFunction(e+"_isNegative"),e};const Xn=function(t,a,e,o,i,n,l,c){const s=t.addFunction(a);s.addParam("base","i32"),s.addParam("scalar","i32"),s.addParam("scalarLength","i32"),s.addParam("r","i32"),s.addLocal("old0","i32"),s.addLocal("nbits","i32"),s.addLocal("i","i32"),s.addLocal("last","i32"),s.addLocal("cur","i32"),s.addLocal("carry","i32"),s.addLocal("p","i32");const r=s.getCodeBuilder(),d=r.i32_const(t.alloc(e));function u(t){return r.i32_and(r.i32_shr_u(r.i32_load(r.i32_add(r.getLocal("scalar"),r.i32_and(r.i32_shr_u(t,r.i32_const(3)),r.i32_const(4294967292)))),r.i32_and(t,r.i32_const(31))),r.i32_const(1))}function _(t){return[...r.i32_store8(r.getLocal("p"),r.i32_const(t)),...r.setLocal("p",r.i32_add(r.getLocal("p"),r.i32_const(1)))]}s.addCode(r.if(r.i32_eqz(r.getLocal("scalarLength")),[...r.call(c,r.getLocal("r")),...r.ret([])]),r.setLocal("nbits",r.i32_shl(r.getLocal("scalarLength"),r.i32_const(3))),r.setLocal("old0",r.i32_load(r.i32_const(0))),r.setLocal("p",r.getLocal("old0")),r.i32_store(r.i32_const(0),r.i32_and(r.i32_add(r.i32_add(r.getLocal("old0"),r.i32_const(32)),r.getLocal("nbits")),r.i32_const(4294967288))),r.setLocal("i",r.i32_const(1)),r.setLocal("last",u(r.i32_const(0))),r.setLocal("carry",r.i32_const(0)),r.block(r.loop(r.br_if(1,r.i32_eq(r.getLocal("i"),r.getLocal("nbits"))),r.setLocal("cur",u(r.getLocal("i"))),r.if(r.getLocal("last"),r.if(r.getLocal("cur"),r.if(r.getLocal("carry"),[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(1)),..._(1)],[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(1)),..._(255)]),r.if(r.getLocal("carry"),[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(1)),..._(255)],[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(0)),..._(1)])),r.if(r.getLocal("cur"),r.if(r.getLocal("carry"),[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(1)),..._(0)],[...r.setLocal("last",r.i32_const(1)),...r.setLocal("carry",r.i32_const(0)),..._(0)]),r.if(r.getLocal("carry"),[...r.setLocal("last",r.i32_const(1)),...r.setLocal("carry",r.i32_const(0)),..._(0)],[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(0)),..._(0)]))),r.setLocal("i",r.i32_add(r.getLocal("i"),r.i32_const(1))),r.br(0))),r.if(r.getLocal("last"),r.if(r.getLocal("carry"),[..._(255),..._(0),..._(1)],[..._(1)]),r.if(r.getLocal("carry"),[..._(0),..._(1)])),r.setLocal("p",r.i32_sub(r.getLocal("p"),r.i32_const(1))),r.call(l,r.getLocal("base"),d),r.call(c,r.getLocal("r")),r.block(r.loop(r.call(i,r.getLocal("r"),r.getLocal("r")),r.setLocal("cur",r.i32_load8_u(r.getLocal("p"))),r.if(r.getLocal("cur"),r.if(r.i32_eq(r.getLocal("cur"),r.i32_const(1)),r.call(o,r.getLocal("r"),d,r.getLocal("r")),r.call(n,r.getLocal("r"),d,r.getLocal("r")))),r.br_if(1,r.i32_eq(r.getLocal("old0"),r.getLocal("p"))),r.setLocal("p",r.i32_sub(r.getLocal("p"),r.i32_const(1))),r.br(0))),r.i32_store(r.i32_const(0),r.getLocal("old0")))},tl=fn,al=function(t,a,e,o,i){const n=8*t.modules[a].n64;function l(){const o=t.addFunction(e);o.addParam("pBases","i32"),o.addParam("pScalars","i32"),o.addParam("scalarSize","i32"),o.addParam("n","i32"),o.addParam("pr","i32"),o.addLocal("chunkSize","i32"),o.addLocal("nChunks","i32"),o.addLocal("itScalar","i32"),o.addLocal("endScalar","i32"),o.addLocal("itBase","i32"),o.addLocal("itBit","i32"),o.addLocal("i","i32"),o.addLocal("j","i32"),o.addLocal("nTable","i32"),o.addLocal("pTable","i32"),o.addLocal("idx","i32"),o.addLocal("pIdxTable","i32");const i=o.getCodeBuilder(),l=i.i32_const(t.alloc(n)),c=t.alloc([17,17,17,17,17,17,17,17,17,17,16,16,15,14,13,13,12,11,10,9,8,7,7,6,5,4,3,2,1,1,1,1]);o.addCode(i.call(a+"_zero",i.getLocal("pr")),i.if(i.i32_eqz(i.getLocal("n")),i.ret([])),i.setLocal("chunkSize",i.i32_load8_u(i.i32_clz(i.getLocal("n")),c)),i.setLocal("nChunks",i.i32_add(i.i32_div_u(i.i32_sub(i.i32_shl(i.getLocal("scalarSize"),i.i32_const(3)),i.i32_const(1)),i.getLocal("chunkSize")),i.i32_const(1))),i.setLocal("itBit",i.i32_mul(i.i32_sub(i.getLocal("nChunks"),i.i32_const(1)),i.getLocal("chunkSize"))),i.block(i.loop(i.br_if(1,i.i32_lt_s(i.getLocal("itBit"),i.i32_const(0))),i.if(i.i32_eqz(i.call(a+"_isZero",i.getLocal("pr"))),[...i.setLocal("j",i.i32_const(0)),...i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("j"),i.getLocal("chunkSize"))),i.call(a+"_double",i.getLocal("pr"),i.getLocal("pr")),i.setLocal("j",i.i32_add(i.getLocal("j"),i.i32_const(1))),i.br(0)))]),i.call(e+"_chunk",i.getLocal("pBases"),i.getLocal("pScalars"),i.getLocal("scalarSize"),i.getLocal("n"),i.getLocal("itBit"),i.getLocal("chunkSize"),l),i.call(a+"_add",i.getLocal("pr"),l,i.getLocal("pr")),i.setLocal("itBit",i.i32_sub(i.getLocal("itBit"),i.getLocal("chunkSize"))),i.br(0))))}!function(){const a=t.addFunction(e+"_getChunk");a.addParam("pScalar","i32"),a.addParam("scalarSize","i32"),a.addParam("startBit","i32"),a.addParam("chunkSize","i32"),a.addLocal("bitsToEnd","i32"),a.addLocal("mask","i32"),a.setReturnType("i32");const o=a.getCodeBuilder();a.addCode(o.setLocal("bitsToEnd",o.i32_sub(o.i32_mul(o.getLocal("scalarSize"),o.i32_const(8)),o.getLocal("startBit"))),o.if(o.i32_gt_s(o.getLocal("chunkSize"),o.getLocal("bitsToEnd")),o.setLocal("mask",o.i32_sub(o.i32_shl(o.i32_const(1),o.getLocal("bitsToEnd")),o.i32_const(1))),o.setLocal("mask",o.i32_sub(o.i32_shl(o.i32_const(1),o.getLocal("chunkSize")),o.i32_const(1)))),o.i32_and(o.i32_shr_u(o.i32_load(o.i32_add(o.getLocal("pScalar"),o.i32_shr_u(o.getLocal("startBit"),o.i32_const(3))),0,0),o.i32_and(o.getLocal("startBit"),o.i32_const(7))),o.getLocal("mask")))}(),function(){const o=t.addFunction(e+"_reduceTable");o.addParam("pTable","i32"),o.addParam("p","i32"),o.addLocal("half","i32"),o.addLocal("it1","i32"),o.addLocal("it2","i32"),o.addLocal("pAcc","i32");const i=o.getCodeBuilder();o.addCode(i.if(i.i32_eq(i.getLocal("p"),i.i32_const(1)),i.ret([])),i.setLocal("half",i.i32_shl(i.i32_const(1),i.i32_sub(i.getLocal("p"),i.i32_const(1)))),i.setLocal("it1",i.getLocal("pTable")),i.setLocal("it2",i.i32_add(i.getLocal("pTable"),i.i32_mul(i.getLocal("half"),i.i32_const(n)))),i.setLocal("pAcc",i.i32_sub(i.getLocal("it2"),i.i32_const(n))),i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("it1"),i.getLocal("pAcc"))),i.call(a+"_add",i.getLocal("it1"),i.getLocal("it2"),i.getLocal("it1")),i.call(a+"_add",i.getLocal("pAcc"),i.getLocal("it2"),i.getLocal("pAcc")),i.setLocal("it1",i.i32_add(i.getLocal("it1"),i.i32_const(n))),i.setLocal("it2",i.i32_add(i.getLocal("it2"),i.i32_const(n))),i.br(0))),i.call(e+"_reduceTable",i.getLocal("pTable"),i.i32_sub(i.getLocal("p"),i.i32_const(1))),i.setLocal("p",i.i32_sub(i.getLocal("p"),i.i32_const(1))),i.block(i.loop(i.br_if(1,i.i32_eqz(i.getLocal("p"))),i.call(a+"_double",i.getLocal("pAcc"),i.getLocal("pAcc")),i.setLocal("p",i.i32_sub(i.getLocal("p"),i.i32_const(1))),i.br(0))),i.call(a+"_add",i.getLocal("pTable"),i.getLocal("pAcc"),i.getLocal("pTable")))}(),function(){const l=t.addFunction(e+"_chunk");l.addParam("pBases","i32"),l.addParam("pScalars","i32"),l.addParam("scalarSize","i32"),l.addParam("n","i32"),l.addParam("startBit","i32"),l.addParam("chunkSize","i32"),l.addParam("pr","i32"),l.addLocal("nChunks","i32"),l.addLocal("itScalar","i32"),l.addLocal("endScalar","i32"),l.addLocal("itBase","i32"),l.addLocal("i","i32"),l.addLocal("j","i32"),l.addLocal("nTable","i32"),l.addLocal("pTable","i32"),l.addLocal("idx","i32"),l.addLocal("pIdxTable","i32");const c=l.getCodeBuilder();l.addCode(c.if(c.i32_eqz(c.getLocal("n")),[...c.call(a+"_zero",c.getLocal("pr")),...c.ret([])]),c.setLocal("nTable",c.i32_shl(c.i32_const(1),c.getLocal("chunkSize"))),c.setLocal("pTable",c.i32_load(c.i32_const(0))),c.i32_store(c.i32_const(0),c.i32_add(c.getLocal("pTable"),c.i32_mul(c.getLocal("nTable"),c.i32_const(n)))),c.setLocal("j",c.i32_const(0)),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("j"),c.getLocal("nTable"))),c.call(a+"_zero",c.i32_add(c.getLocal("pTable"),c.i32_mul(c.getLocal("j"),c.i32_const(n)))),c.setLocal("j",c.i32_add(c.getLocal("j"),c.i32_const(1))),c.br(0))),c.setLocal("itBase",c.getLocal("pBases")),c.setLocal("itScalar",c.getLocal("pScalars")),c.setLocal("endScalar",c.i32_add(c.getLocal("pScalars"),c.i32_mul(c.getLocal("n"),c.getLocal("scalarSize")))),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("itScalar"),c.getLocal("endScalar"))),c.setLocal("idx",c.call(e+"_getChunk",c.getLocal("itScalar"),c.getLocal("scalarSize"),c.getLocal("startBit"),c.getLocal("chunkSize"))),c.if(c.getLocal("idx"),[...c.setLocal("pIdxTable",c.i32_add(c.getLocal("pTable"),c.i32_mul(c.i32_sub(c.getLocal("idx"),c.i32_const(1)),c.i32_const(n)))),...c.call(o,c.getLocal("pIdxTable"),c.getLocal("itBase"),c.getLocal("pIdxTable"))]),c.setLocal("itScalar",c.i32_add(c.getLocal("itScalar"),c.getLocal("scalarSize"))),c.setLocal("itBase",c.i32_add(c.getLocal("itBase"),c.i32_const(i))),c.br(0))),c.call(e+"_reduceTable",c.getLocal("pTable"),c.getLocal("chunkSize")),c.call(a+"_copy",c.getLocal("pTable"),c.getLocal("pr")),c.i32_store(c.i32_const(0),c.getLocal("pTable")))}(),l(),t.exportFunction(e),t.exportFunction(e+"_chunk")};var el=function(t,a,e,o){const i=t.modules[e].n64,n=8*i;if(t.modules[a])return a;return t.modules[a]={n64:3*i},function(){const o=t.addFunction(a+"_isZeroAffine");o.addParam("p1","i32"),o.setReturnType("i32");const i=o.getCodeBuilder();o.addCode(i.i32_and(i.call(e+"_isZero",i.getLocal("p1")),i.call(e+"_isZero",i.i32_add(i.getLocal("p1"),i.i32_const(n)))))}(),function(){const o=t.addFunction(a+"_isZero");o.addParam("p1","i32"),o.setReturnType("i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_isZero",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))))}(),function(){const o=t.addFunction(a+"_zeroAffine");o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_zero",i.getLocal("pr"))),o.addCode(i.call(e+"_zero",i.i32_add(i.getLocal("pr"),i.i32_const(n))))}(),function(){const o=t.addFunction(a+"_zero");o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_zero",i.getLocal("pr"))),o.addCode(i.call(e+"_one",i.i32_add(i.getLocal("pr"),i.i32_const(n)))),o.addCode(i.call(e+"_zero",i.i32_add(i.getLocal("pr"),i.i32_const(2*n))))}(),function(){const e=t.addFunction(a+"_copyAffine");e.addParam("ps","i32"),e.addParam("pd","i32");const o=e.getCodeBuilder();for(let t=0;t<2*i;t++)e.addCode(o.i64_store(o.getLocal("pd"),8*t,o.i64_load(o.getLocal("ps"),8*t)))}(),function(){const e=t.addFunction(a+"_copy");e.addParam("ps","i32"),e.addParam("pd","i32");const o=e.getCodeBuilder();for(let t=0;t<3*i;t++)e.addCode(o.i64_store(o.getLocal("pd"),8*t,o.i64_load(o.getLocal("ps"),8*t)))}(),function(){const o=t.addFunction(a+"_toJacobian");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.getLocal("pr"),r=i.i32_add(i.getLocal("pr"),i.i32_const(n)),d=i.i32_add(i.getLocal("pr"),i.i32_const(2*n));o.addCode(i.if(i.call(a+"_isZeroAffine",i.getLocal("p1")),i.call(a+"_zero",i.getLocal("pr")),[...i.call(e+"_one",d),...i.call(e+"_copy",c,r),...i.call(e+"_copy",l,s)]))}(),function(){const o=t.addFunction(a+"_eqAffine");o.addParam("p1","i32"),o.addParam("p2","i32"),o.setReturnType("i32"),o.addLocal("z1","i32");const i=o.getCodeBuilder();o.addCode(i.ret(i.i32_and(i.call(e+"_eq",i.getLocal("p1"),i.getLocal("p2")),i.call(e+"_eq",i.i32_add(i.getLocal("p1"),i.i32_const(n)),i.i32_add(i.getLocal("p2"),i.i32_const(n))))))}(),function(){const o=t.addFunction(a+"_eqMixed");o.addParam("p1","i32"),o.addParam("p2","i32"),o.setReturnType("i32"),o.addLocal("z1","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n));o.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))));const s=i.getLocal("z1"),r=i.getLocal("p2"),d=i.i32_add(i.getLocal("p2"),i.i32_const(n)),u=i.i32_const(t.alloc(n)),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),i.ret(i.call(a+"_isZeroAffine",i.getLocal("p2")))),i.if(i.call(a+"_isZeroAffine",i.getLocal("p2")),i.ret(i.i32_const(0))),i.if(i.call(e+"_isOne",s),i.ret(i.call(a+"_eqAffine",i.getLocal("p1"),i.getLocal("p2")))),i.call(e+"_square",s,u),i.call(e+"_mul",r,u,_),i.call(e+"_mul",s,u,g),i.call(e+"_mul",d,g,f),i.if(i.call(e+"_eq",l,_),i.if(i.call(e+"_eq",c,f),i.ret(i.i32_const(1)))),i.ret(i.i32_const(0)))}(),function(){const o=t.addFunction(a+"_eq");o.addParam("p1","i32"),o.addParam("p2","i32"),o.setReturnType("i32"),o.addLocal("z1","i32"),o.addLocal("z2","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n));o.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))));const s=i.getLocal("z1"),r=i.getLocal("p2"),d=i.i32_add(i.getLocal("p2"),i.i32_const(n));o.addCode(i.setLocal("z2",i.i32_add(i.getLocal("p2"),i.i32_const(2*n))));const u=i.getLocal("z2"),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n)),m=i.i32_const(t.alloc(n)),L=i.i32_const(t.alloc(n)),b=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),i.ret(i.call(a+"_isZero",i.getLocal("p2")))),i.if(i.call(a+"_isZero",i.getLocal("p2")),i.ret(i.i32_const(0))),i.if(i.call(e+"_isOne",s),i.ret(i.call(a+"_eqMixed",i.getLocal("p2"),i.getLocal("p1")))),i.if(i.call(e+"_isOne",u),i.ret(i.call(a+"_eqMixed",i.getLocal("p1"),i.getLocal("p2")))),i.call(e+"_square",s,_),i.call(e+"_square",u,g),i.call(e+"_mul",l,g,f),i.call(e+"_mul",r,_,h),i.call(e+"_mul",s,_,p),i.call(e+"_mul",u,g,m),i.call(e+"_mul",c,m,L),i.call(e+"_mul",d,p,b),i.if(i.call(e+"_eq",f,h),i.if(i.call(e+"_eq",L,b),i.ret(i.i32_const(1)))),i.ret(i.i32_const(0)))}(),function(){const o=t.addFunction(a+"_doubleAffine");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.getLocal("pr"),r=i.i32_add(i.getLocal("pr"),i.i32_const(n)),d=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),u=i.i32_const(t.alloc(n)),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZeroAffine",i.getLocal("p1")),[...i.call(a+"_toJacobian",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])]),i.call(e+"_square",l,u),i.call(e+"_square",c,_),i.call(e+"_square",_,g),i.call(e+"_add",l,_,f),i.call(e+"_square",f,f),i.call(e+"_sub",f,u,f),i.call(e+"_sub",f,g,f),i.call(e+"_add",f,f,f),i.call(e+"_add",u,u,h),i.call(e+"_add",h,u,h),i.call(e+"_add",c,c,d),i.call(e+"_square",h,s),i.call(e+"_sub",s,f,s),i.call(e+"_sub",s,f,s),i.call(e+"_add",g,g,p),i.call(e+"_add",p,p,p),i.call(e+"_add",p,p,p),i.call(e+"_sub",f,s,r),i.call(e+"_mul",r,h,r),i.call(e+"_sub",r,p,r))}(),function(){const o=t.addFunction(a+"_double");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.i32_add(i.getLocal("p1"),i.i32_const(2*n)),r=i.getLocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(n)),u=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n)),m=i.i32_const(t.alloc(n)),L=i.i32_const(t.alloc(n)),b=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),[...i.call(a+"_copy",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])]),i.if(i.call(e+"_isOne",s),[...i.ret(i.call(a+"_doubleAffine",i.getLocal("p1"),i.getLocal("pr"))),...i.ret([])]),i.call(e+"_square",l,_),i.call(e+"_square",c,g),i.call(e+"_square",g,f),i.call(e+"_add",l,g,h),i.call(e+"_square",h,h),i.call(e+"_sub",h,_,h),i.call(e+"_sub",h,f,h),i.call(e+"_add",h,h,h),i.call(e+"_add",_,_,p),i.call(e+"_add",p,_,p),i.call(e+"_square",p,m),i.call(e+"_mul",c,s,L),i.call(e+"_add",h,h,r),i.call(e+"_sub",m,r,r),i.call(e+"_add",f,f,b),i.call(e+"_add",b,b,b),i.call(e+"_add",b,b,b),i.call(e+"_sub",h,r,d),i.call(e+"_mul",d,p,d),i.call(e+"_sub",d,b,d),i.call(e+"_add",L,L,u))}(),function(){const o=t.addFunction(a+"_addAffine");o.addParam("p1","i32"),o.addParam("p2","i32"),o.addParam("pr","i32"),o.addLocal("z1","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n));o.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))));const s=i.getLocal("p2"),r=i.i32_add(i.getLocal("p2"),i.i32_const(n)),d=i.getLocal("pr"),u=i.i32_add(i.getLocal("pr"),i.i32_const(n)),_=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n)),m=i.i32_const(t.alloc(n)),L=i.i32_const(t.alloc(n)),b=i.i32_const(t.alloc(n)),w=i.i32_const(t.alloc(n)),y=i.i32_const(t.alloc(n)),A=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZeroAffine",i.getLocal("p1")),[...i.call(a+"_copyAffine",i.getLocal("p2"),i.getLocal("pr")),...i.call(e+"_one",i.i32_add(i.getLocal("pr"),i.i32_const(2*n))),...i.ret([])]),i.if(i.call(a+"_isZeroAffine",i.getLocal("p2")),[...i.call(a+"_copyAffine",i.getLocal("p1"),i.getLocal("pr")),...i.call(e+"_one",i.i32_add(i.getLocal("pr"),i.i32_const(2*n))),...i.ret([])]),i.if(i.call(e+"_eq",l,s),i.if(i.call(e+"_eq",c,r),[...i.call(a+"_doubleAffine",i.getLocal("p2"),i.getLocal("pr")),...i.ret([])])),i.call(e+"_sub",s,l,g),i.call(e+"_sub",r,c,h),i.call(e+"_square",g,f),i.call(e+"_add",f,f,p),i.call(e+"_add",p,p,p),i.call(e+"_mul",g,p,m),i.call(e+"_add",h,h,L),i.call(e+"_mul",l,p,w),i.call(e+"_square",L,b),i.call(e+"_add",w,w,y),i.call(e+"_sub",b,m,d),i.call(e+"_sub",d,y,d),i.call(e+"_mul",c,m,A),i.call(e+"_add",A,A,A),i.call(e+"_sub",w,d,u),i.call(e+"_mul",u,L,u),i.call(e+"_sub",u,A,u),i.call(e+"_add",g,g,_))}(),function(){const o=t.addFunction(a+"_addMixed");o.addParam("p1","i32"),o.addParam("p2","i32"),o.addParam("pr","i32"),o.addLocal("z1","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n));o.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))));const s=i.getLocal("z1"),r=i.getLocal("p2"),d=i.i32_add(i.getLocal("p2"),i.i32_const(n)),u=i.getLocal("pr"),_=i.i32_add(i.getLocal("pr"),i.i32_const(n)),g=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),f=i.i32_const(t.alloc(n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n)),m=i.i32_const(t.alloc(n)),L=i.i32_const(t.alloc(n)),b=i.i32_const(t.alloc(n)),w=i.i32_const(t.alloc(n)),y=i.i32_const(t.alloc(n)),A=i.i32_const(t.alloc(n)),C=i.i32_const(t.alloc(n)),F=i.i32_const(t.alloc(n)),x=i.i32_const(t.alloc(n)),I=i.i32_const(t.alloc(n)),B=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),[...i.call(a+"_copyAffine",i.getLocal("p2"),i.getLocal("pr")),...i.call(e+"_one",i.i32_add(i.getLocal("pr"),i.i32_const(2*n))),...i.ret([])]),i.if(i.call(a+"_isZeroAffine",i.getLocal("p2")),[...i.call(a+"_copy",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])]),i.if(i.call(e+"_isOne",s),[...i.call(a+"_addAffine",l,r,u),...i.ret([])]),i.call(e+"_square",s,f),i.call(e+"_mul",r,f,h),i.call(e+"_mul",s,f,p),i.call(e+"_mul",d,p,m),i.if(i.call(e+"_eq",l,h),i.if(i.call(e+"_eq",c,m),[...i.call(a+"_doubleAffine",i.getLocal("p2"),i.getLocal("pr")),...i.ret([])])),i.call(e+"_sub",h,l,L),i.call(e+"_sub",m,c,w),i.call(e+"_square",L,b),i.call(e+"_add",b,b,y),i.call(e+"_add",y,y,y),i.call(e+"_mul",L,y,A),i.call(e+"_add",w,w,C),i.call(e+"_mul",l,y,x),i.call(e+"_square",C,F),i.call(e+"_add",x,x,I),i.call(e+"_sub",F,A,u),i.call(e+"_sub",u,I,u),i.call(e+"_mul",c,A,B),i.call(e+"_add",B,B,B),i.call(e+"_sub",x,u,_),i.call(e+"_mul",_,C,_),i.call(e+"_sub",_,B,_),i.call(e+"_add",s,L,g),i.call(e+"_square",g,g),i.call(e+"_sub",g,f,g),i.call(e+"_sub",g,b,g))}(),function(){const o=t.addFunction(a+"_add");o.addParam("p1","i32"),o.addParam("p2","i32"),o.addParam("pr","i32"),o.addLocal("z1","i32"),o.addLocal("z2","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n));o.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))));const s=i.getLocal("z1"),r=i.getLocal("p2"),d=i.i32_add(i.getLocal("p2"),i.i32_const(n));o.addCode(i.setLocal("z2",i.i32_add(i.getLocal("p2"),i.i32_const(2*n))));const u=i.getLocal("z2"),_=i.getLocal("pr"),g=i.i32_add(i.getLocal("pr"),i.i32_const(n)),f=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n)),m=i.i32_const(t.alloc(n)),L=i.i32_const(t.alloc(n)),b=i.i32_const(t.alloc(n)),w=i.i32_const(t.alloc(n)),y=i.i32_const(t.alloc(n)),A=i.i32_const(t.alloc(n)),C=i.i32_const(t.alloc(n)),F=i.i32_const(t.alloc(n)),x=i.i32_const(t.alloc(n)),I=i.i32_const(t.alloc(n)),B=i.i32_const(t.alloc(n)),E=i.i32_const(t.alloc(n)),v=i.i32_const(t.alloc(n)),S=i.i32_const(t.alloc(n)),P=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),[...i.call(a+"_copy",i.getLocal("p2"),i.getLocal("pr")),...i.ret([])]),i.if(i.call(a+"_isZero",i.getLocal("p2")),[...i.call(a+"_copy",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])]),i.if(i.call(e+"_isOne",s),[...i.call(a+"_addMixed",r,l,_),...i.ret([])]),i.if(i.call(e+"_isOne",u),[...i.call(a+"_addMixed",l,r,_),...i.ret([])]),i.call(e+"_square",s,h),i.call(e+"_square",u,p),i.call(e+"_mul",l,p,m),i.call(e+"_mul",r,h,L),i.call(e+"_mul",s,h,b),i.call(e+"_mul",u,p,w),i.call(e+"_mul",c,w,y),i.call(e+"_mul",d,b,A),i.if(i.call(e+"_eq",m,L),i.if(i.call(e+"_eq",y,A),[...i.call(a+"_double",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])])),i.call(e+"_sub",L,m,C),i.call(e+"_sub",A,y,F),i.call(e+"_add",C,C,x),i.call(e+"_square",x,x),i.call(e+"_mul",C,x,I),i.call(e+"_add",F,F,B),i.call(e+"_mul",m,x,v),i.call(e+"_square",B,E),i.call(e+"_add",v,v,S),i.call(e+"_sub",E,I,_),i.call(e+"_sub",_,S,_),i.call(e+"_mul",y,I,P),i.call(e+"_add",P,P,P),i.call(e+"_sub",v,_,g),i.call(e+"_mul",g,B,g),i.call(e+"_sub",g,P,g),i.call(e+"_add",s,u,f),i.call(e+"_square",f,f),i.call(e+"_sub",f,h,f),i.call(e+"_sub",f,p,f),i.call(e+"_mul",f,C,f))}(),function(){const o=t.addFunction(a+"_negAffine");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.getLocal("pr"),r=i.i32_add(i.getLocal("pr"),i.i32_const(n));o.addCode(i.call(e+"_copy",l,s),i.call(e+"_neg",c,r))}(),function(){const o=t.addFunction(a+"_neg");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.i32_add(i.getLocal("p1"),i.i32_const(2*n)),r=i.getLocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(n)),u=i.i32_add(i.getLocal("pr"),i.i32_const(2*n));o.addCode(i.call(e+"_copy",l,r),i.call(e+"_neg",c,d),i.call(e+"_copy",s,u))}(),function(){const e=t.addFunction(a+"_subAffine");e.addParam("p1","i32"),e.addParam("p2","i32"),e.addParam("pr","i32");const o=e.getCodeBuilder(),i=o.i32_const(t.alloc(3*n));e.addCode(o.call(a+"_negAffine",o.getLocal("p2"),i),o.call(a+"_addAffine",o.getLocal("p1"),i,o.getLocal("pr")))}(),function(){const e=t.addFunction(a+"_subMixed");e.addParam("p1","i32"),e.addParam("p2","i32"),e.addParam("pr","i32");const o=e.getCodeBuilder(),i=o.i32_const(t.alloc(3*n));e.addCode(o.call(a+"_negAffine",o.getLocal("p2"),i),o.call(a+"_addMixed",o.getLocal("p1"),i,o.getLocal("pr")))}(),function(){const e=t.addFunction(a+"_sub");e.addParam("p1","i32"),e.addParam("p2","i32"),e.addParam("pr","i32");const o=e.getCodeBuilder(),i=o.i32_const(t.alloc(3*n));e.addCode(o.call(a+"_neg",o.getLocal("p2"),i),o.call(a+"_add",o.getLocal("p1"),i,o.getLocal("pr")))}(),function(){const o=t.addFunction(a+"_fromMontgomeryAffine");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_fromMontgomery",i.getLocal("p1"),i.getLocal("pr")));for(let t=1;t<2;t++)o.addCode(i.call(e+"_fromMontgomery",i.i32_add(i.getLocal("p1"),i.i32_const(t*n)),i.i32_add(i.getLocal("pr"),i.i32_const(t*n))))}(),function(){const o=t.addFunction(a+"_fromMontgomery");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_fromMontgomery",i.getLocal("p1"),i.getLocal("pr")));for(let t=1;t<3;t++)o.addCode(i.call(e+"_fromMontgomery",i.i32_add(i.getLocal("p1"),i.i32_const(t*n)),i.i32_add(i.getLocal("pr"),i.i32_const(t*n))))}(),function(){const o=t.addFunction(a+"_toMontgomeryAffine");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_toMontgomery",i.getLocal("p1"),i.getLocal("pr")));for(let t=1;t<2;t++)o.addCode(i.call(e+"_toMontgomery",i.i32_add(i.getLocal("p1"),i.i32_const(t*n)),i.i32_add(i.getLocal("pr"),i.i32_const(t*n))))}(),function(){const o=t.addFunction(a+"_toMontgomery");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_toMontgomery",i.getLocal("p1"),i.getLocal("pr")));for(let t=1;t<3;t++)o.addCode(i.call(e+"_toMontgomery",i.i32_add(i.getLocal("p1"),i.i32_const(t*n)),i.i32_add(i.getLocal("pr"),i.i32_const(t*n))))}(),function(){const o=t.addFunction(a+"_toAffine");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.i32_add(i.getLocal("p1"),i.i32_const(2*n)),r=i.getLocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(n)),u=i.i32_const(t.alloc(n)),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),[...i.call(e+"_zero",r),...i.call(e+"_zero",d)],[...i.call(e+"_inverse",s,u),...i.call(e+"_square",u,_),...i.call(e+"_mul",u,_,g),...i.call(e+"_mul",l,_,r),...i.call(e+"_mul",c,g,d)]))}(),function(){const i=t.addFunction(a+"_inCurveAffine");i.addParam("pIn","i32"),i.setReturnType("i32");const l=i.getCodeBuilder(),c=l.getLocal("pIn"),s=l.i32_add(l.getLocal("pIn"),l.i32_const(n)),r=l.i32_const(t.alloc(n)),d=l.i32_const(t.alloc(n));i.addCode(l.call(e+"_square",s,r),l.call(e+"_square",c,d),l.call(e+"_mul",c,d,d),l.call(e+"_add",d,l.i32_const(o),d),l.ret(l.call(e+"_eq",r,d)))}(),function(){const e=t.addFunction(a+"_inCurve");e.addParam("pIn","i32"),e.setReturnType("i32");const o=e.getCodeBuilder(),i=o.i32_const(t.alloc(2*n));e.addCode(o.call(a+"_toAffine",o.getLocal("pIn"),i),o.ret(o.call(a+"_inCurveAffine",i)))}(),function(){const o=t.addFunction(a+"_batchToAffine");o.addParam("pIn","i32"),o.addParam("n","i32"),o.addParam("pOut","i32"),o.addLocal("pAux","i32"),o.addLocal("itIn","i32"),o.addLocal("itAux","i32"),o.addLocal("itOut","i32"),o.addLocal("i","i32");const i=o.getCodeBuilder(),l=i.i32_const(t.alloc(n));o.addCode(i.setLocal("pAux",i.i32_load(i.i32_const(0))),i.i32_store(i.i32_const(0),i.i32_add(i.getLocal("pAux"),i.i32_mul(i.getLocal("n"),i.i32_const(n)))),i.call(e+"_batchInverse",i.i32_add(i.getLocal("pIn"),i.i32_const(2*n)),i.i32_const(3*n),i.getLocal("n"),i.getLocal("pAux"),i.i32_const(n)),i.setLocal("itIn",i.getLocal("pIn")),i.setLocal("itAux",i.getLocal("pAux")),i.setLocal("itOut",i.getLocal("pOut")),i.setLocal("i",i.i32_const(0)),i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("i"),i.getLocal("n"))),i.if(i.call(e+"_isZero",i.getLocal("itAux")),[...i.call(e+"_zero",i.getLocal("itOut")),...i.call(e+"_zero",i.i32_add(i.getLocal("itOut"),i.i32_const(n)))],[...i.call(e+"_mul",i.getLocal("itAux"),i.i32_add(i.getLocal("itIn"),i.i32_const(n)),l),...i.call(e+"_square",i.getLocal("itAux"),i.getLocal("itAux")),...i.call(e+"_mul",i.getLocal("itAux"),i.getLocal("itIn"),i.getLocal("itOut")),...i.call(e+"_mul",i.getLocal("itAux"),l,i.i32_add(i.getLocal("itOut"),i.i32_const(n)))]),i.setLocal("itIn",i.i32_add(i.getLocal("itIn"),i.i32_const(3*n))),i.setLocal("itOut",i.i32_add(i.getLocal("itOut"),i.i32_const(2*n))),i.setLocal("itAux",i.i32_add(i.getLocal("itAux"),i.i32_const(n))),i.setLocal("i",i.i32_add(i.getLocal("i"),i.i32_const(1))),i.br(0))),i.i32_store(i.i32_const(0),i.getLocal("pAux")))}(),function(){const o=t.addFunction(a+"_normalize");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.i32_add(i.getLocal("p1"),i.i32_const(2*n)),r=i.getLocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(n)),u=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),i.call(a+"_zero",i.getLocal("pr")),[...i.call(e+"_inverse",s,_),...i.call(e+"_square",_,g),...i.call(e+"_mul",_,g,f),...i.call(e+"_mul",l,g,r),...i.call(e+"_mul",c,f,d),...i.call(e+"_one",u)]))}(),function(){const e=t.addFunction(a+"__reverseBytes");e.addParam("pIn","i32"),e.addParam("n","i32"),e.addParam("pOut","i32"),e.addLocal("itOut","i32"),e.addLocal("itIn","i32");const o=e.getCodeBuilder();e.addCode(o.setLocal("itOut",o.i32_sub(o.i32_add(o.getLocal("pOut"),o.getLocal("n")),o.i32_const(1))),o.setLocal("itIn",o.getLocal("pIn")),o.block(o.loop(o.br_if(1,o.i32_lt_s(o.getLocal("itOut"),o.getLocal("pOut"))),o.i32_store8(o.getLocal("itOut"),o.i32_load8_u(o.getLocal("itIn"))),o.setLocal("itOut",o.i32_sub(o.getLocal("itOut"),o.i32_const(1))),o.setLocal("itIn",o.i32_add(o.getLocal("itIn"),o.i32_const(1))),o.br(0))))}(),function(){const e=t.addFunction(a+"_LEMtoU");e.addParam("pIn","i32"),e.addParam("pOut","i32");const o=e.getCodeBuilder(),i=t.alloc(2*n),l=o.i32_const(i),c=o.i32_const(i),s=o.i32_const(i+n);e.addCode(o.if(o.call(a+"_isZeroAffine",o.getLocal("pIn")),[...o.call(a+"_zeroAffine",o.getLocal("pOut")),...o.ret([])]),o.call(a+"_fromMontgomeryAffine",o.getLocal("pIn"),l),o.call(a+"__reverseBytes",c,o.i32_const(n),o.getLocal("pOut")),o.call(a+"__reverseBytes",s,o.i32_const(n),o.i32_add(o.getLocal("pOut"),o.i32_const(n))))}(),function(){const o=t.addFunction(a+"_LEMtoC");o.addParam("pIn","i32"),o.addParam("pOut","i32");const i=o.getCodeBuilder(),l=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZeroAffine",i.getLocal("pIn")),[...i.call(e+"_zero",i.getLocal("pOut")),...i.i32_store8(i.getLocal("pOut"),i.i32_const(64)),...i.ret([])]),i.call(e+"_fromMontgomery",i.getLocal("pIn"),l),i.call(a+"__reverseBytes",l,i.i32_const(n),i.getLocal("pOut")),i.if(i.i32_eq(i.call(e+"_sign",i.i32_add(i.getLocal("pIn"),i.i32_const(n))),i.i32_const(-1)),i.i32_store8(i.getLocal("pOut"),i.i32_or(i.i32_load8_u(i.getLocal("pOut")),i.i32_const(128)))))}(),function(){const e=t.addFunction(a+"_UtoLEM");e.addParam("pIn","i32"),e.addParam("pOut","i32");const o=e.getCodeBuilder(),i=t.alloc(2*n),l=o.i32_const(i),c=o.i32_const(i),s=o.i32_const(i+n);e.addCode(o.if(o.i32_and(o.i32_load8_u(o.getLocal("pIn")),o.i32_const(64)),[...o.call(a+"_zeroAffine",o.getLocal("pOut")),...o.ret([])]),o.call(a+"__reverseBytes",o.getLocal("pIn"),o.i32_const(n),c),o.call(a+"__reverseBytes",o.i32_add(o.getLocal("pIn"),o.i32_const(n)),o.i32_const(n),s),o.call(a+"_toMontgomeryAffine",l,o.getLocal("pOut")))}(),function(){const i=t.addFunction(a+"_CtoLEM");i.addParam("pIn","i32"),i.addParam("pOut","i32"),i.addLocal("firstByte","i32"),i.addLocal("greatest","i32");const l=i.getCodeBuilder(),c=t.alloc(2*n),s=l.i32_const(c),r=l.i32_const(c+n);i.addCode(l.setLocal("firstByte",l.i32_load8_u(l.getLocal("pIn"))),l.if(l.i32_and(l.getLocal("firstByte"),l.i32_const(64)),[...l.call(a+"_zeroAffine",l.getLocal("pOut")),...l.ret([])]),l.setLocal("greatest",l.i32_and(l.getLocal("firstByte"),l.i32_const(128))),l.call(e+"_copy",l.getLocal("pIn"),r),l.i32_store8(r,l.i32_and(l.getLocal("firstByte"),l.i32_const(63))),l.call(a+"__reverseBytes",r,l.i32_const(n),s),l.call(e+"_toMontgomery",s,l.getLocal("pOut")),l.call(e+"_square",l.getLocal("pOut"),r),l.call(e+"_mul",l.getLocal("pOut"),r,r),l.call(e+"_add",r,l.i32_const(o),r),l.call(e+"_sqrt",r,r),l.call(e+"_neg",r,s),l.if(l.i32_eq(l.call(e+"_sign",r),l.i32_const(-1)),l.if(l.getLocal("greatest"),l.call(e+"_copy",r,l.i32_add(l.getLocal("pOut"),l.i32_const(n))),l.call(e+"_neg",r,l.i32_add(l.getLocal("pOut"),l.i32_const(n)))),l.if(l.getLocal("greatest"),l.call(e+"_neg",r,l.i32_add(l.getLocal("pOut"),l.i32_const(n))),l.call(e+"_copy",r,l.i32_add(l.getLocal("pOut"),l.i32_const(n))))))}(),tl(t,a+"_batchLEMtoU",a+"_LEMtoU",2*n,2*n),tl(t,a+"_batchLEMtoC",a+"_LEMtoC",2*n,n),tl(t,a+"_batchUtoLEM",a+"_UtoLEM",2*n,2*n),tl(t,a+"_batchCtoLEM",a+"_CtoLEM",n,2*n,!0),tl(t,a+"_batchToJacobian",a+"_toJacobian",2*n,3*n,!0),al(t,a,a+"_multiexp",a+"_add",3*n),al(t,a,a+"_multiexpAffine",a+"_addMixed",2*n),Xn(t,a+"_timesScalar",3*n,a+"_add",a+"_double",a+"_sub",a+"_copy",a+"_zero"),Xn(t,a+"_timesScalarAffine",2*n,a+"_addMixed",a+"_double",a+"_subMixed",a+"_copyAffine",a+"_zero"),t.exportFunction(a+"_isZero"),t.exportFunction(a+"_isZeroAffine"),t.exportFunction(a+"_eq"),t.exportFunction(a+"_eqMixed"),t.exportFunction(a+"_eqAffine"),t.exportFunction(a+"_copy"),t.exportFunction(a+"_copyAffine"),t.exportFunction(a+"_zero"),t.exportFunction(a+"_zeroAffine"),t.exportFunction(a+"_double"),t.exportFunction(a+"_doubleAffine"),t.exportFunction(a+"_add"),t.exportFunction(a+"_addMixed"),t.exportFunction(a+"_addAffine"),t.exportFunction(a+"_neg"),t.exportFunction(a+"_negAffine"),t.exportFunction(a+"_sub"),t.exportFunction(a+"_subMixed"),t.exportFunction(a+"_subAffine"),t.exportFunction(a+"_fromMontgomery"),t.exportFunction(a+"_fromMontgomeryAffine"),t.exportFunction(a+"_toMontgomery"),t.exportFunction(a+"_toMontgomeryAffine"),t.exportFunction(a+"_timesScalar"),t.exportFunction(a+"_timesScalarAffine"),t.exportFunction(a+"_normalize"),t.exportFunction(a+"_LEMtoU"),t.exportFunction(a+"_LEMtoC"),t.exportFunction(a+"_UtoLEM"),t.exportFunction(a+"_CtoLEM"),t.exportFunction(a+"_batchLEMtoU"),t.exportFunction(a+"_batchLEMtoC"),t.exportFunction(a+"_batchUtoLEM"),t.exportFunction(a+"_batchCtoLEM"),t.exportFunction(a+"_toAffine"),t.exportFunction(a+"_toJacobian"),t.exportFunction(a+"_batchToAffine"),t.exportFunction(a+"_batchToJacobian"),t.exportFunction(a+"_inCurve"),t.exportFunction(a+"_inCurveAffine"),a};const{isOdd:ol,modInv:il,modPow:nl}=pn,ll=un;var cl=function(t,a,e,o,i){const n=8*t.modules[o].n64,l=8*t.modules[e].n64,c=t.modules[o].q;let s=c-1n,r=0;for(;!ol(s);)r++,s>>=1n;let d=2n;for(;1n===nl(d,c>>1n,c);)d+=1n;const u=new Array(r+1);u[r]=nl(d,s,c);let _=r-1;for(;_>=0;)u[_]=nl(u[_+1],2n,c),_--;const g=[],f=(1n<>e);return a}const x=Array(256);for(let t=0;t<256;t++)x[t]=F(t);const I=t.alloc(x);function B(){const e=t.addFunction(a+"_fft");e.addParam("px","i32"),e.addParam("n","i32"),e.addLocal("bits","i32");const i=e.getCodeBuilder(),l=i.i32_const(t.alloc(n));e.addCode(i.setLocal("bits",i.call(a+"__log2",i.getLocal("n"))),i.call(o+"_one",l),i.call(a+"_rawfft",i.getLocal("px"),i.getLocal("bits"),i.i32_const(0),l))}!function(){const e=t.addFunction(a+"__rev");e.addParam("x","i32"),e.addParam("bits","i32"),e.setReturnType("i32");const o=e.getCodeBuilder();e.addCode(o.i32_rotl(o.i32_add(o.i32_add(o.i32_shl(o.i32_load8_u(o.i32_and(o.getLocal("x"),o.i32_const(255)),I,0),o.i32_const(24)),o.i32_shl(o.i32_load8_u(o.i32_and(o.i32_shr_u(o.getLocal("x"),o.i32_const(8)),o.i32_const(255)),I,0),o.i32_const(16))),o.i32_add(o.i32_shl(o.i32_load8_u(o.i32_and(o.i32_shr_u(o.getLocal("x"),o.i32_const(16)),o.i32_const(255)),I,0),o.i32_const(8)),o.i32_load8_u(o.i32_and(o.i32_shr_u(o.getLocal("x"),o.i32_const(24)),o.i32_const(255)),I,0))),o.getLocal("bits")))}(),function(){const o=t.addFunction(a+"__reversePermutation");o.addParam("px","i32"),o.addParam("bits","i32"),o.addLocal("n","i32"),o.addLocal("i","i32"),o.addLocal("ri","i32"),o.addLocal("idx1","i32"),o.addLocal("idx2","i32");const i=o.getCodeBuilder(),n=i.i32_const(t.alloc(l));o.addCode(i.setLocal("n",i.i32_shl(i.i32_const(1),i.getLocal("bits"))),i.setLocal("i",i.i32_const(0)),i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("i"),i.getLocal("n"))),i.setLocal("idx1",i.i32_add(i.getLocal("px"),i.i32_mul(i.getLocal("i"),i.i32_const(l)))),i.setLocal("ri",i.call(a+"__rev",i.getLocal("i"),i.getLocal("bits"))),i.setLocal("idx2",i.i32_add(i.getLocal("px"),i.i32_mul(i.getLocal("ri"),i.i32_const(l)))),i.if(i.i32_lt_u(i.getLocal("i"),i.getLocal("ri")),[...i.call(e+"_copy",i.getLocal("idx1"),n),...i.call(e+"_copy",i.getLocal("idx2"),i.getLocal("idx1")),...i.call(e+"_copy",n,i.getLocal("idx2"))]),i.setLocal("i",i.i32_add(i.getLocal("i"),i.i32_const(1))),i.br(0))))}(),function(){const n=t.addFunction(a+"__fftFinal");n.addParam("px","i32"),n.addParam("bits","i32"),n.addParam("reverse","i32"),n.addParam("mulFactor","i32"),n.addLocal("n","i32"),n.addLocal("ndiv2","i32"),n.addLocal("pInv2","i32"),n.addLocal("i","i32"),n.addLocal("mask","i32"),n.addLocal("idx1","i32"),n.addLocal("idx2","i32");const c=n.getCodeBuilder(),s=c.i32_const(t.alloc(l));n.addCode(c.if(c.i32_and(c.i32_eqz(c.getLocal("reverse")),c.call(o+"_isOne",c.getLocal("mulFactor"))),c.ret([])),c.setLocal("n",c.i32_shl(c.i32_const(1),c.getLocal("bits"))),c.setLocal("mask",c.i32_sub(c.getLocal("n"),c.i32_const(1))),c.setLocal("i",c.i32_const(1)),c.setLocal("ndiv2",c.i32_shr_u(c.getLocal("n"),c.i32_const(1))),c.block(c.loop(c.br_if(1,c.i32_ge_u(c.getLocal("i"),c.getLocal("ndiv2"))),c.setLocal("idx1",c.i32_add(c.getLocal("px"),c.i32_mul(c.getLocal("i"),c.i32_const(l)))),c.setLocal("idx2",c.i32_add(c.getLocal("px"),c.i32_mul(c.i32_sub(c.getLocal("n"),c.getLocal("i")),c.i32_const(l)))),c.if(c.getLocal("reverse"),c.if(c.call(o+"_isOne",c.getLocal("mulFactor")),[...c.call(e+"_copy",c.getLocal("idx1"),s),...c.call(e+"_copy",c.getLocal("idx2"),c.getLocal("idx1")),...c.call(e+"_copy",s,c.getLocal("idx2"))],[...c.call(e+"_copy",c.getLocal("idx1"),s),...c.call(i,c.getLocal("idx2"),c.getLocal("mulFactor"),c.getLocal("idx1")),...c.call(i,s,c.getLocal("mulFactor"),c.getLocal("idx2"))]),c.if(c.call(o+"_isOne",c.getLocal("mulFactor")),[],[...c.call(i,c.getLocal("idx1"),c.getLocal("mulFactor"),c.getLocal("idx1")),...c.call(i,c.getLocal("idx2"),c.getLocal("mulFactor"),c.getLocal("idx2"))])),c.setLocal("i",c.i32_add(c.getLocal("i"),c.i32_const(1))),c.br(0))),c.if(c.call(o+"_isOne",c.getLocal("mulFactor")),[],[...c.call(i,c.getLocal("px"),c.getLocal("mulFactor"),c.getLocal("px")),...c.setLocal("idx2",c.i32_add(c.getLocal("px"),c.i32_mul(c.getLocal("ndiv2"),c.i32_const(l)))),...c.call(i,c.getLocal("idx2"),c.getLocal("mulFactor"),c.getLocal("idx2"))]))}(),function(){const c=t.addFunction(a+"_rawfft");c.addParam("px","i32"),c.addParam("bits","i32"),c.addParam("reverse","i32"),c.addParam("mulFactor","i32"),c.addLocal("s","i32"),c.addLocal("k","i32"),c.addLocal("j","i32"),c.addLocal("m","i32"),c.addLocal("mdiv2","i32"),c.addLocal("n","i32"),c.addLocal("pwm","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l)),u=s.i32_const(t.alloc(l));c.addCode(s.call(a+"__reversePermutation",s.getLocal("px"),s.getLocal("bits")),s.setLocal("n",s.i32_shl(s.i32_const(1),s.getLocal("bits"))),s.setLocal("s",s.i32_const(1)),s.block(s.loop(s.br_if(1,s.i32_gt_u(s.getLocal("s"),s.getLocal("bits"))),s.setLocal("m",s.i32_shl(s.i32_const(1),s.getLocal("s"))),s.setLocal("pwm",s.i32_add(s.i32_const(h),s.i32_mul(s.getLocal("s"),s.i32_const(n)))),s.setLocal("k",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_ge_u(s.getLocal("k"),s.getLocal("n"))),s.call(o+"_one",r),s.setLocal("mdiv2",s.i32_shr_u(s.getLocal("m"),s.i32_const(1))),s.setLocal("j",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_ge_u(s.getLocal("j"),s.getLocal("mdiv2"))),s.setLocal("idx1",s.i32_add(s.getLocal("px"),s.i32_mul(s.i32_add(s.getLocal("k"),s.getLocal("j")),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("idx1"),s.i32_mul(s.getLocal("mdiv2"),s.i32_const(l)))),s.call(i,s.getLocal("idx2"),r,d),s.call(e+"_copy",s.getLocal("idx1"),u),s.call(e+"_add",u,d,s.getLocal("idx1")),s.call(e+"_sub",u,d,s.getLocal("idx2")),s.call(o+"_mul",r,s.getLocal("pwm"),r),s.setLocal("j",s.i32_add(s.getLocal("j"),s.i32_const(1))),s.br(0))),s.setLocal("k",s.i32_add(s.getLocal("k"),s.getLocal("m"))),s.br(0))),s.setLocal("s",s.i32_add(s.getLocal("s"),s.i32_const(1))),s.br(0))),s.call(a+"__fftFinal",s.getLocal("px"),s.getLocal("bits"),s.getLocal("reverse"),s.getLocal("mulFactor")))}(),function(){const e=t.addFunction(a+"__log2");e.addParam("n","i32"),e.setReturnType("i32"),e.addLocal("bits","i32"),e.addLocal("aux","i32");const o=e.getCodeBuilder();e.addCode(o.setLocal("aux",o.i32_shr_u(o.getLocal("n"),o.i32_const(1)))),e.addCode(o.setLocal("bits",o.i32_const(0))),e.addCode(o.block(o.loop(o.br_if(1,o.i32_eqz(o.getLocal("aux"))),o.setLocal("aux",o.i32_shr_u(o.getLocal("aux"),o.i32_const(1))),o.setLocal("bits",o.i32_add(o.getLocal("bits"),o.i32_const(1))),o.br(0)))),e.addCode(o.if(o.i32_ne(o.getLocal("n"),o.i32_shl(o.i32_const(1),o.getLocal("bits"))),o.unreachable())),e.addCode(o.if(o.i32_gt_u(o.getLocal("bits"),o.i32_const(r)),o.unreachable())),e.addCode(o.getLocal("bits"))}(),B(),function(){const e=t.addFunction(a+"_ifft");e.addParam("px","i32"),e.addParam("n","i32"),e.addLocal("bits","i32"),e.addLocal("pInv2","i32");const o=e.getCodeBuilder();e.addCode(o.setLocal("bits",o.call(a+"__log2",o.getLocal("n"))),o.setLocal("pInv2",o.i32_add(o.i32_const(L),o.i32_mul(o.getLocal("bits"),o.i32_const(n)))),o.call(a+"_rawfft",o.getLocal("px"),o.getLocal("bits"),o.i32_const(1),o.getLocal("pInv2")))}(),function(){const c=t.addFunction(a+"_fftJoin");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l)),u=s.i32_const(t.alloc(l));c.addCode(s.call(o+"_copy",s.getLocal("first"),r),s.setLocal("i",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("n"))),s.setLocal("idx1",s.i32_add(s.getLocal("pBuff1"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("pBuff2"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.call(i,s.getLocal("idx2"),r,d),s.call(e+"_copy",s.getLocal("idx1"),u),s.call(e+"_add",u,d,s.getLocal("idx1")),s.call(e+"_sub",u,d,s.getLocal("idx2")),s.call(o+"_mul",r,s.getLocal("inc"),r),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),function(){const c=t.addFunction(a+"_fftJoinExt");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addParam("totalBits","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("pShiftToM","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l));c.addCode(s.setLocal("pShiftToM",s.i32_add(s.i32_const(A),s.i32_mul(s.getLocal("totalBits"),s.i32_const(n)))),s.call(o+"_copy",s.getLocal("first"),r),s.setLocal("i",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("n"))),s.setLocal("idx1",s.i32_add(s.getLocal("pBuff1"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("pBuff2"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.call(e+"_add",s.getLocal("idx1"),s.getLocal("idx2"),d),s.call(i,s.getLocal("idx2"),s.getLocal("pShiftToM"),s.getLocal("idx2")),s.call(e+"_add",s.getLocal("idx1"),s.getLocal("idx2"),s.getLocal("idx2")),s.call(i,s.getLocal("idx2"),r,s.getLocal("idx2")),s.call(e+"_copy",d,s.getLocal("idx1")),s.call(o+"_mul",r,s.getLocal("inc"),r),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),function(){const c=t.addFunction(a+"_fftJoinExtInv");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addParam("totalBits","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("pShiftToM","i32"),c.addLocal("pSConst","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l));c.addCode(s.setLocal("pShiftToM",s.i32_add(s.i32_const(A),s.i32_mul(s.getLocal("totalBits"),s.i32_const(n)))),s.setLocal("pSConst",s.i32_add(s.i32_const(C),s.i32_mul(s.getLocal("totalBits"),s.i32_const(n)))),s.call(o+"_copy",s.getLocal("first"),r),s.setLocal("i",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("n"))),s.setLocal("idx1",s.i32_add(s.getLocal("pBuff1"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("pBuff2"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.call(i,s.getLocal("idx2"),r,d),s.call(e+"_sub",s.getLocal("idx1"),d,s.getLocal("idx2")),s.call(i,s.getLocal("idx2"),s.getLocal("pSConst"),s.getLocal("idx2")),s.call(i,s.getLocal("idx1"),s.getLocal("pShiftToM"),s.getLocal("idx1")),s.call(e+"_sub",d,s.getLocal("idx1"),s.getLocal("idx1")),s.call(i,s.getLocal("idx1"),s.getLocal("pSConst"),s.getLocal("idx1")),s.call(o+"_mul",r,s.getLocal("inc"),r),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),function(){const c=t.addFunction(a+"_fftMix");c.addParam("pBuff","i32"),c.addParam("n","i32"),c.addParam("exp","i32"),c.addLocal("nGroups","i32"),c.addLocal("nPerGroup","i32"),c.addLocal("nPerGroupDiv2","i32"),c.addLocal("pairOffset","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("j","i32"),c.addLocal("pwm","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l)),u=s.i32_const(t.alloc(l));c.addCode(s.setLocal("nPerGroup",s.i32_shl(s.i32_const(1),s.getLocal("exp"))),s.setLocal("nPerGroupDiv2",s.i32_shr_u(s.getLocal("nPerGroup"),s.i32_const(1))),s.setLocal("nGroups",s.i32_shr_u(s.getLocal("n"),s.getLocal("exp"))),s.setLocal("pairOffset",s.i32_mul(s.getLocal("nPerGroupDiv2"),s.i32_const(l))),s.setLocal("pwm",s.i32_add(s.i32_const(h),s.i32_mul(s.getLocal("exp"),s.i32_const(n)))),s.setLocal("i",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("nGroups"))),s.call(o+"_one",r),s.setLocal("j",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("j"),s.getLocal("nPerGroupDiv2"))),s.setLocal("idx1",s.i32_add(s.getLocal("pBuff"),s.i32_mul(s.i32_add(s.i32_mul(s.getLocal("i"),s.getLocal("nPerGroup")),s.getLocal("j")),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("idx1"),s.getLocal("pairOffset"))),s.call(i,s.getLocal("idx2"),r,d),s.call(e+"_copy",s.getLocal("idx1"),u),s.call(e+"_add",u,d,s.getLocal("idx1")),s.call(e+"_sub",u,d,s.getLocal("idx2")),s.call(o+"_mul",r,s.getLocal("pwm"),r),s.setLocal("j",s.i32_add(s.getLocal("j"),s.i32_const(1))),s.br(0))),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),function(){const o=t.addFunction(a+"_fftFinal");o.addParam("pBuff","i32"),o.addParam("n","i32"),o.addParam("factor","i32"),o.addLocal("idx1","i32"),o.addLocal("idx2","i32"),o.addLocal("i","i32"),o.addLocal("ndiv2","i32");const n=o.getCodeBuilder(),c=n.i32_const(t.alloc(l));o.addCode(n.setLocal("ndiv2",n.i32_shr_u(n.getLocal("n"),n.i32_const(1))),n.if(n.i32_and(n.getLocal("n"),n.i32_const(1)),n.call(i,n.i32_add(n.getLocal("pBuff"),n.i32_mul(n.getLocal("ndiv2"),n.i32_const(l))),n.getLocal("factor"),n.i32_add(n.getLocal("pBuff"),n.i32_mul(n.getLocal("ndiv2"),n.i32_const(l))))),n.setLocal("i",n.i32_const(0)),n.block(n.loop(n.br_if(1,n.i32_ge_u(n.getLocal("i"),n.getLocal("ndiv2"))),n.setLocal("idx1",n.i32_add(n.getLocal("pBuff"),n.i32_mul(n.getLocal("i"),n.i32_const(l)))),n.setLocal("idx2",n.i32_add(n.getLocal("pBuff"),n.i32_mul(n.i32_sub(n.i32_sub(n.getLocal("n"),n.i32_const(1)),n.getLocal("i")),n.i32_const(l)))),n.call(i,n.getLocal("idx2"),n.getLocal("factor"),c),n.call(i,n.getLocal("idx1"),n.getLocal("factor"),n.getLocal("idx2")),n.call(e+"_copy",c,n.getLocal("idx1")),n.setLocal("i",n.i32_add(n.getLocal("i"),n.i32_const(1))),n.br(0))))}(),function(){const c=t.addFunction(a+"_prepareLagrangeEvaluation");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addParam("totalBits","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("pShiftToM","i32"),c.addLocal("pSConst","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l));c.addCode(s.setLocal("pShiftToM",s.i32_add(s.i32_const(A),s.i32_mul(s.getLocal("totalBits"),s.i32_const(n)))),s.setLocal("pSConst",s.i32_add(s.i32_const(C),s.i32_mul(s.getLocal("totalBits"),s.i32_const(n)))),s.call(o+"_copy",s.getLocal("first"),r),s.setLocal("i",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("n"))),s.setLocal("idx1",s.i32_add(s.getLocal("pBuff1"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("pBuff2"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.call(i,s.getLocal("idx1"),s.getLocal("pShiftToM"),d),s.call(e+"_sub",s.getLocal("idx2"),d,d),s.call(e+"_sub",s.getLocal("idx1"),s.getLocal("idx2"),s.getLocal("idx2")),s.call(i,d,s.getLocal("pSConst"),s.getLocal("idx1")),s.call(i,s.getLocal("idx2"),r,s.getLocal("idx2")),s.call(o+"_mul",r,s.getLocal("inc"),r),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),t.exportFunction(a+"_fft"),t.exportFunction(a+"_ifft"),t.exportFunction(a+"_rawfft"),t.exportFunction(a+"_fftJoin"),t.exportFunction(a+"_fftJoinExt"),t.exportFunction(a+"_fftJoinExtInv"),t.exportFunction(a+"_fftMix"),t.exportFunction(a+"_fftFinal"),t.exportFunction(a+"_prepareLagrangeEvaluation")},sl=function(t,a,e){const o=8*t.modules[e].n64;return function(){const i=t.addFunction(a+"_zero");i.addParam("px","i32"),i.addParam("n","i32"),i.addLocal("lastp","i32"),i.addLocal("p","i32");const n=i.getCodeBuilder();i.addCode(n.setLocal("p",n.getLocal("px")),n.setLocal("lastp",n.i32_add(n.getLocal("px"),n.i32_mul(n.getLocal("n"),n.i32_const(o)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("p"),n.getLocal("lastp"))),n.call(e+"_zero",n.getLocal("p")),n.setLocal("p",n.i32_add(n.getLocal("p"),n.i32_const(o))),n.br(0))))}(),function(){const i=t.addFunction(a+"_constructLC");i.addParam("ppolynomials","i32"),i.addParam("psignals","i32"),i.addParam("nSignals","i32"),i.addParam("pres","i32"),i.addLocal("i","i32"),i.addLocal("j","i32"),i.addLocal("pp","i32"),i.addLocal("ps","i32"),i.addLocal("pd","i32"),i.addLocal("ncoefs","i32");const n=i.getCodeBuilder(),l=n.i32_const(t.alloc(o));i.addCode(n.setLocal("i",n.i32_const(0)),n.setLocal("pp",n.getLocal("ppolynomials")),n.setLocal("ps",n.getLocal("psignals")),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("i"),n.getLocal("nSignals"))),n.setLocal("ncoefs",n.i32_load(n.getLocal("pp"))),n.setLocal("pp",n.i32_add(n.getLocal("pp"),n.i32_const(4))),n.setLocal("j",n.i32_const(0)),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("j"),n.getLocal("ncoefs"))),n.setLocal("pd",n.i32_add(n.getLocal("pres"),n.i32_mul(n.i32_load(n.getLocal("pp")),n.i32_const(o)))),n.setLocal("pp",n.i32_add(n.getLocal("pp"),n.i32_const(4))),n.call(e+"_mul",n.getLocal("ps"),n.getLocal("pp"),l),n.call(e+"_add",l,n.getLocal("pd"),n.getLocal("pd")),n.setLocal("pp",n.i32_add(n.getLocal("pp"),n.i32_const(o))),n.setLocal("j",n.i32_add(n.getLocal("j"),n.i32_const(1))),n.br(0))),n.setLocal("ps",n.i32_add(n.getLocal("ps"),n.i32_const(o))),n.setLocal("i",n.i32_add(n.getLocal("i"),n.i32_const(1))),n.br(0))))}(),t.exportFunction(a+"_zero"),t.exportFunction(a+"_constructLC"),a},rl=function(t,a,e){const o=8*t.modules[e].n64;return function(){const i=t.addFunction(a+"_buildABC");i.addParam("pCoefs","i32"),i.addParam("nCoefs","i32"),i.addParam("pWitness","i32"),i.addParam("pA","i32"),i.addParam("pB","i32"),i.addParam("pC","i32"),i.addParam("offsetOut","i32"),i.addParam("nOut","i32"),i.addParam("offsetWitness","i32"),i.addParam("nWitness","i32"),i.addLocal("it","i32"),i.addLocal("ita","i32"),i.addLocal("itb","i32"),i.addLocal("last","i32"),i.addLocal("m","i32"),i.addLocal("c","i32"),i.addLocal("s","i32"),i.addLocal("pOut","i32");const n=i.getCodeBuilder(),l=n.i32_const(t.alloc(o));i.addCode(n.setLocal("ita",n.getLocal("pA")),n.setLocal("itb",n.getLocal("pB")),n.setLocal("last",n.i32_add(n.getLocal("pA"),n.i32_mul(n.getLocal("nOut"),n.i32_const(o)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(e+"_zero",n.getLocal("ita")),n.call(e+"_zero",n.getLocal("itb")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(o))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(o))),n.br(0))),n.setLocal("it",n.getLocal("pCoefs")),n.setLocal("last",n.i32_add(n.getLocal("pCoefs"),n.i32_mul(n.getLocal("nCoefs"),n.i32_const(o+12)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("it"),n.getLocal("last"))),n.setLocal("s",n.i32_load(n.getLocal("it"),8)),n.if(n.i32_or(n.i32_lt_u(n.getLocal("s"),n.getLocal("offsetWitness")),n.i32_ge_u(n.getLocal("s"),n.i32_add(n.getLocal("offsetWitness"),n.getLocal("nWitness")))),[...n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(o+12))),...n.br(1)]),n.setLocal("m",n.i32_load(n.getLocal("it"))),n.if(n.i32_eq(n.getLocal("m"),n.i32_const(0)),n.setLocal("pOut",n.getLocal("pA")),n.if(n.i32_eq(n.getLocal("m"),n.i32_const(1)),n.setLocal("pOut",n.getLocal("pB")),[...n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(o+12))),...n.br(1)])),n.setLocal("c",n.i32_load(n.getLocal("it"),4)),n.if(n.i32_or(n.i32_lt_u(n.getLocal("c"),n.getLocal("offsetOut")),n.i32_ge_u(n.getLocal("c"),n.i32_add(n.getLocal("offsetOut"),n.getLocal("nOut")))),[...n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(o+12))),...n.br(1)]),n.setLocal("pOut",n.i32_add(n.getLocal("pOut"),n.i32_mul(n.i32_sub(n.getLocal("c"),n.getLocal("offsetOut")),n.i32_const(o)))),n.call(e+"_mul",n.i32_add(n.getLocal("pWitness"),n.i32_mul(n.i32_sub(n.getLocal("s"),n.getLocal("offsetWitness")),n.i32_const(o))),n.i32_add(n.getLocal("it"),n.i32_const(12)),l),n.call(e+"_add",n.getLocal("pOut"),l,n.getLocal("pOut")),n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(o+12))),n.br(0))),n.setLocal("ita",n.getLocal("pA")),n.setLocal("itb",n.getLocal("pB")),n.setLocal("it",n.getLocal("pC")),n.setLocal("last",n.i32_add(n.getLocal("pA"),n.i32_mul(n.getLocal("nOut"),n.i32_const(o)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(e+"_mul",n.getLocal("ita"),n.getLocal("itb"),n.getLocal("it")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(o))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(o))),n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(o))),n.br(0))))}(),function(){const i=t.addFunction(a+"_joinABC");i.addParam("pA","i32"),i.addParam("pB","i32"),i.addParam("pC","i32"),i.addParam("n","i32"),i.addParam("pP","i32"),i.addLocal("ita","i32"),i.addLocal("itb","i32"),i.addLocal("itc","i32"),i.addLocal("itp","i32"),i.addLocal("last","i32");const n=i.getCodeBuilder(),l=n.i32_const(t.alloc(o));i.addCode(n.setLocal("ita",n.getLocal("pA")),n.setLocal("itb",n.getLocal("pB")),n.setLocal("itc",n.getLocal("pC")),n.setLocal("itp",n.getLocal("pP")),n.setLocal("last",n.i32_add(n.getLocal("pA"),n.i32_mul(n.getLocal("n"),n.i32_const(o)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(e+"_mul",n.getLocal("ita"),n.getLocal("itb"),l),n.call(e+"_sub",l,n.getLocal("itc"),n.getLocal("itp")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(o))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(o))),n.setLocal("itc",n.i32_add(n.getLocal("itc"),n.i32_const(o))),n.setLocal("itp",n.i32_add(n.getLocal("itp"),n.i32_const(o))),n.br(0))))}(),function(){const i=t.addFunction(a+"_batchAdd");i.addParam("pa","i32"),i.addParam("pb","i32"),i.addParam("n","i32"),i.addParam("pr","i32"),i.addLocal("ita","i32"),i.addLocal("itb","i32"),i.addLocal("itr","i32"),i.addLocal("last","i32");const n=i.getCodeBuilder();i.addCode(n.setLocal("ita",n.getLocal("pa")),n.setLocal("itb",n.getLocal("pb")),n.setLocal("itr",n.getLocal("pr")),n.setLocal("last",n.i32_add(n.getLocal("pa"),n.i32_mul(n.getLocal("n"),n.i32_const(o)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(e+"_add",n.getLocal("ita"),n.getLocal("itb"),n.getLocal("itr")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(o))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(o))),n.setLocal("itr",n.i32_add(n.getLocal("itr"),n.i32_const(o))),n.br(0))))}(),t.exportFunction(a+"_buildABC"),t.exportFunction(a+"_joinABC"),t.exportFunction(a+"_batchAdd"),a},dl=function(t,a,e,o,i,n,l,c){const s=t.addFunction(a);s.addParam("pIn","i32"),s.addParam("n","i32"),s.addParam("pFirst","i32"),s.addParam("pInc","i32"),s.addParam("pOut","i32"),s.addLocal("pOldFree","i32"),s.addLocal("i","i32"),s.addLocal("pFrom","i32"),s.addLocal("pTo","i32");const r=s.getCodeBuilder(),d=r.i32_const(t.alloc(l));s.addCode(r.setLocal("pFrom",r.getLocal("pIn")),r.setLocal("pTo",r.getLocal("pOut"))),s.addCode(r.call(o+"_copy",r.getLocal("pFirst"),d)),s.addCode(r.setLocal("i",r.i32_const(0)),r.block(r.loop(r.br_if(1,r.i32_eq(r.getLocal("i"),r.getLocal("n"))),r.call(c,r.getLocal("pFrom"),d,r.getLocal("pTo")),r.setLocal("pFrom",r.i32_add(r.getLocal("pFrom"),r.i32_const(i))),r.setLocal("pTo",r.i32_add(r.getLocal("pTo"),r.i32_const(n))),r.call(o+"_mul",d,r.getLocal("pInc"),d),r.setLocal("i",r.i32_add(r.getLocal("i"),r.i32_const(1))),r.br(0)))),t.exportFunction(a)};const ul=un,_l=Nn,gl=jn,fl=Zn,hl=Jn,pl=el,ml=cl,Ll=sl,bl=rl,wl=dl,{bitLength:yl,modInv:Al,isOdd:Cl,isNegative:Fl}=pn;const xl=un,Il=Nn,Bl=jn,El=Zn,vl=Jn,Sl=el,Pl=cl,ql=sl,Ol=rl,Gl=dl,{bitLength:zl,isOdd:Tl,isNegative:Ml}=pn;var Ul=function(t,a){const e=a||"bn128";if(t.modules[e])return e;const o=21888242871839275222246405745257275088696311157297823662689037894645226208583n,i=21888242871839275222246405745257275088548364400416034343698204186575808495617n,n=Math.floor((yl(o-1n)-1)/64)+1,l=8*n,c=l,s=l,r=2*s,d=12*s,u=t.alloc(ul.bigInt2BytesLE(i,c)),_=_l(t,o,"f1m");gl(t,i,"fr","frm");const g=t.alloc(ul.bigInt2BytesLE(b(3n),s)),f=pl(t,"g1m","f1m",g);ml(t,"frm","frm","frm","frm_mul"),Ll(t,"pol","frm"),bl(t,"qap","frm");const h=fl(t,"f1m_neg","f2m","f1m"),p=t.alloc([...ul.bigInt2BytesLE(b(19485874751759354771024239261021720505790618469301721065564631296452457478373n),s),...ul.bigInt2BytesLE(b(266929791119991161246907387137283842545076965332900288569378510910307636690n),s)]),m=pl(t,"g2m","f2m",p);function L(a,e){const o=t.addFunction(a);o.addParam("pG","i32"),o.addParam("pFr","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),n=i.i32_const(t.alloc(l));o.addCode(i.call("frm_fromMontgomery",i.getLocal("pFr"),n),i.call(e,i.getLocal("pG"),n,i.i32_const(l),i.getLocal("pr"))),t.exportFunction(a)}function b(t){return BigInt(t)*(1n<0n;)Cl(a)?e.push(1):e.push(0),a>>=1n;return e}(29793968203157093288n),T=t.alloc(z),M=3*r,U=z.length-1,Q=z.reduce(((t,a)=>t+(0!=a?1:0)),0),k=6*l,R=3*l*2+(Q+U+1)*M;t.modules[e]={n64:n,pG1gen:y,pG1zero:C,pG1b:g,pG2gen:x,pG2zero:B,pG2b:p,pq:t.modules.f1m.pq,pr:u,pOneT:E,prePSize:k,preQSize:R,r:i.toString(),q:o.toString()};const N=4965661367192848881n;function D(a){const i=[[[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n]],[[1n,0n],[8376118865763821496583973867626364092589906065868298776909617916018768340080n,16469823323077808223889137241176536799009286646108169935659301613961712198316n],[21888242871839275220042445260109153167277707414472061641714758635765020556617n,0n],[11697423496358154304825782922584725312912383441159505038794027105778954184319n,303847389135065887422783454877609941456349188919719272345083954437860409601n],[21888242871839275220042445260109153167277707414472061641714758635765020556616n,0n],[3321304630594332808241809054958361220322477375291206261884409189760185844239n,5722266937896532885780051958958348231143373700109372999374820235121374419868n],[21888242871839275222246405745257275088696311157297823662689037894645226208582n,0n],[13512124006075453725662431877630910996106405091429524885779419978626457868503n,5418419548761466998357268504080738289687024511189653727029736280683514010267n],[2203960485148121921418603742825762020974279258880205651966n,0n],[10190819375481120917420622822672549775783927716138318623895010788866272024264n,21584395482704209334823622290379665147239961968378104390343953940207365798982n],[2203960485148121921418603742825762020974279258880205651967n,0n],[18566938241244942414004596690298913868373833782006617400804628704885040364344n,16165975933942742336466353786298926857552937457188450663314217659523851788715n]]],n=[[[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n]],[[1n,0n],[21575463638280843010398324269430826099269044274347216827212613867836435027261n,10307601595873709700152284273816112264069230130616436755625194854815875713954n],[21888242871839275220042445260109153167277707414472061641714758635765020556616n,0n],[3772000881919853776433695186713858239009073593817195771773381919316419345261n,2236595495967245188281701248203181795121068902605861227855261137820944008926n],[2203960485148121921418603742825762020974279258880205651966n,0n],[18429021223477853657660792034369865839114504446431234726392080002137598044644n,9344045779998320333812420223237981029506012124075525679208581902008406485703n]],[[1n,0n],[2581911344467009335267311115468803099551665605076196740867805258568234346338n,19937756971775647987995932169929341994314640652964949448313374472400716661030n],[2203960485148121921418603742825762020974279258880205651966n,0n],[5324479202449903542726783395506214481928257762400643279780343368557297135718n,16208900380737693084919495127334387981393726419856888799917914180988844123039n],[21888242871839275220042445260109153167277707414472061641714758635765020556616n,0n],[13981852324922362344252311234282257507216387789820983642040889267519694726527n,7629828391165209371577384193250820201684255241773809077146787135900891633097n]]],l=t.addFunction(e+"__frobeniusMap"+a);l.addParam("x","i32"),l.addParam("r","i32");const c=l.getCodeBuilder();for(let e=0;e<6;e++){const o=0==e?c.getLocal("x"):c.i32_add(c.getLocal("x"),c.i32_const(e*r)),u=o,g=c.i32_add(c.getLocal("x"),c.i32_const(e*r+s)),f=0==e?c.getLocal("r"):c.i32_add(c.getLocal("r"),c.i32_const(e*r)),p=f,m=c.i32_add(c.getLocal("r"),c.i32_const(e*r+s)),L=d(i[Math.floor(e/3)][a%12],n[e%3][a%6]),w=t.alloc([...ul.bigInt2BytesLE(b(L[0]),32),...ul.bigInt2BytesLE(b(L[1]),32)]);a%2==1?l.addCode(c.call(_+"_copy",u,p),c.call(_+"_neg",g,m),c.call(h+"_mul",f,c.i32_const(w),f)):l.addCode(c.call(h+"_mul",o,c.i32_const(w),f))}function d(t,a){const e=BigInt(t[0]),i=BigInt(t[1]),n=BigInt(a[0]),l=BigInt(a[1]),c=[(e*n-i*l)%o,(e*l+i*n)%o];return Fl(c[0])&&(c[0]=c[0]+o),c}}function $(a,o){const i=function(t){let a=t;const e=[];for(;a>0n;){if(Cl(a)){const t=2-Number(a%4n);e.push(t),a-=BigInt(t)}else e.push(0);a>>=1n}return e}(a).map((t=>-1==t?255:t)),n=t.alloc(i),l=t.addFunction(e+"__cyclotomicExp_"+o);l.addParam("x","i32"),l.addParam("r","i32"),l.addLocal("bit","i32"),l.addLocal("i","i32");const c=l.getCodeBuilder(),s=c.getLocal("x"),r=c.getLocal("r"),u=c.i32_const(t.alloc(d));l.addCode(c.call(G+"_conjugate",s,u),c.call(G+"_one",r),c.if(c.teeLocal("bit",c.i32_load8_s(c.i32_const(i.length-1),n)),c.if(c.i32_eq(c.getLocal("bit"),c.i32_const(1)),c.call(G+"_mul",r,s,r),c.call(G+"_mul",r,u,r))),c.setLocal("i",c.i32_const(i.length-2)),c.block(c.loop(c.call(e+"__cyclotomicSquare",r,r),c.if(c.teeLocal("bit",c.i32_load8_s(c.getLocal("i"),n)),c.if(c.i32_eq(c.getLocal("bit"),c.i32_const(1)),c.call(G+"_mul",r,s,r),c.call(G+"_mul",r,u,r))),c.br_if(1,c.i32_eqz(c.getLocal("i"))),c.setLocal("i",c.i32_sub(c.getLocal("i"),c.i32_const(1))),c.br(0))))}function j(){!function(){const a=t.addFunction(e+"__cyclotomicSquare");a.addParam("x","i32"),a.addParam("r","i32");const o=a.getCodeBuilder(),i=o.getLocal("x"),n=o.i32_add(o.getLocal("x"),o.i32_const(r)),l=o.i32_add(o.getLocal("x"),o.i32_const(2*r)),c=o.i32_add(o.getLocal("x"),o.i32_const(3*r)),s=o.i32_add(o.getLocal("x"),o.i32_const(4*r)),d=o.i32_add(o.getLocal("x"),o.i32_const(5*r)),u=o.getLocal("r"),_=o.i32_add(o.getLocal("r"),o.i32_const(r)),g=o.i32_add(o.getLocal("r"),o.i32_const(2*r)),f=o.i32_add(o.getLocal("r"),o.i32_const(3*r)),p=o.i32_add(o.getLocal("r"),o.i32_const(4*r)),m=o.i32_add(o.getLocal("r"),o.i32_const(5*r)),L=o.i32_const(t.alloc(r)),b=o.i32_const(t.alloc(r)),w=o.i32_const(t.alloc(r)),y=o.i32_const(t.alloc(r)),A=o.i32_const(t.alloc(r)),C=o.i32_const(t.alloc(r)),F=o.i32_const(t.alloc(r)),x=o.i32_const(t.alloc(r));a.addCode(o.call(h+"_mul",i,s,F),o.call(h+"_mul",s,o.i32_const(v),L),o.call(h+"_add",i,L,L),o.call(h+"_add",i,s,x),o.call(h+"_mul",x,L,L),o.call(h+"_mul",o.i32_const(v),F,x),o.call(h+"_add",F,x,x),o.call(h+"_sub",L,x,L),o.call(h+"_add",F,F,b),o.call(h+"_mul",c,l,F),o.call(h+"_mul",l,o.i32_const(v),w),o.call(h+"_add",c,w,w),o.call(h+"_add",c,l,x),o.call(h+"_mul",x,w,w),o.call(h+"_mul",o.i32_const(v),F,x),o.call(h+"_add",F,x,x),o.call(h+"_sub",w,x,w),o.call(h+"_add",F,F,y),o.call(h+"_mul",n,d,F),o.call(h+"_mul",d,o.i32_const(v),A),o.call(h+"_add",n,A,A),o.call(h+"_add",n,d,x),o.call(h+"_mul",x,A,A),o.call(h+"_mul",o.i32_const(v),F,x),o.call(h+"_add",F,x,x),o.call(h+"_sub",A,x,A),o.call(h+"_add",F,F,C),o.call(h+"_sub",L,i,u),o.call(h+"_add",u,u,u),o.call(h+"_add",L,u,u),o.call(h+"_add",b,s,p),o.call(h+"_add",p,p,p),o.call(h+"_add",b,p,p),o.call(h+"_mul",C,o.i32_const(P),x),o.call(h+"_add",x,c,f),o.call(h+"_add",f,f,f),o.call(h+"_add",x,f,f),o.call(h+"_sub",A,l,g),o.call(h+"_add",g,g,g),o.call(h+"_add",A,g,g),o.call(h+"_sub",w,n,_),o.call(h+"_add",_,_,_),o.call(h+"_add",w,_,_),o.call(h+"_add",y,d,m),o.call(h+"_add",m,m,m),o.call(h+"_add",y,m,m))}(),$(N,"w0");const a=t.addFunction(e+"__finalExponentiationLastChunk");a.addParam("x","i32"),a.addParam("r","i32");const o=a.getCodeBuilder(),i=o.getLocal("x"),n=o.getLocal("r"),l=o.i32_const(t.alloc(d)),c=o.i32_const(t.alloc(d)),s=o.i32_const(t.alloc(d)),u=o.i32_const(t.alloc(d)),_=o.i32_const(t.alloc(d)),g=o.i32_const(t.alloc(d)),f=o.i32_const(t.alloc(d)),p=o.i32_const(t.alloc(d)),m=o.i32_const(t.alloc(d)),L=o.i32_const(t.alloc(d)),b=o.i32_const(t.alloc(d)),w=o.i32_const(t.alloc(d)),y=o.i32_const(t.alloc(d)),A=o.i32_const(t.alloc(d)),C=o.i32_const(t.alloc(d)),F=o.i32_const(t.alloc(d)),x=o.i32_const(t.alloc(d)),I=o.i32_const(t.alloc(d)),B=o.i32_const(t.alloc(d)),E=o.i32_const(t.alloc(d)),S=o.i32_const(t.alloc(d));a.addCode(o.call(e+"__cyclotomicExp_w0",i,l),o.call(G+"_conjugate",l,l),o.call(e+"__cyclotomicSquare",l,c),o.call(e+"__cyclotomicSquare",c,s),o.call(G+"_mul",s,c,u),o.call(e+"__cyclotomicExp_w0",u,_),o.call(G+"_conjugate",_,_),o.call(e+"__cyclotomicSquare",_,g),o.call(e+"__cyclotomicExp_w0",g,f),o.call(G+"_conjugate",f,f),o.call(G+"_conjugate",u,p),o.call(G+"_conjugate",f,m),o.call(G+"_mul",m,_,L),o.call(G+"_mul",L,p,b),o.call(G+"_mul",b,c,w),o.call(G+"_mul",b,_,y),o.call(G+"_mul",y,i,A),o.call(e+"__frobeniusMap1",w,C),o.call(G+"_mul",C,A,F),o.call(e+"__frobeniusMap2",b,x),o.call(G+"_mul",x,F,I),o.call(G+"_conjugate",i,B),o.call(G+"_mul",B,w,E),o.call(e+"__frobeniusMap3",E,S),o.call(G+"_mul",S,I,n))}const V=t.alloc(k),K=t.alloc(R);function H(a){const o=t.addFunction(e+"_pairingEq"+a);for(let t=0;t0n;)Tl(a)?e.push(1):e.push(0),a>>=1n;return e}(0xd201000000010000n),z=t.alloc(G),T=3*s,M=G.length-1,U=G.reduce(((t,a)=>t+(0!=a?1:0)),0),Q=6*l,k=3*l*2+(U+M+1)*T,R=15132376222941642752n;function N(a){const e=[[[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n]],[[1n,0n],[3850754370037169011952147076051364057158807420970682438676050522613628423219637725072182697113062777891589506424760n,151655185184498381465642749684540099398075398968325446656007613510403227271200139370504932015952886146304766135027n],[793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620351n,0n],[2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530n,1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257n],[793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350n,0n],[3125332594171059424908108096204648978570118281977575435832422631601824034463382777937621250592425535493320683825557n,877076961050607968509681729531255177986764537961432449499635504522207616027455086505066378536590128544573588734230n],[4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559786n,0n],[151655185184498381465642749684540099398075398968325446656007613510403227271200139370504932015952886146304766135027n,3850754370037169011952147076051364057158807420970682438676050522613628423219637725072182697113062777891589506424760n],[4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436n,0n],[1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257n,2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530n],[4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437n,0n],[877076961050607968509681729531255177986764537961432449499635504522207616027455086505066378536590128544573588734230n,3125332594171059424908108096204648978570118281977575435832422631601824034463382777937621250592425535493320683825557n]]],i=[[[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n]],[[1n,0n],[0n,4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436n],[793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350n,0n],[0n,1n],[4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436n,0n],[0n,793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350n]],[[1n,0n],[4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437n,0n],[4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436n,0n],[4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559786n,0n],[793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350n,0n],[793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620351n,0n]]],n=t.addFunction(O+"_frobeniusMap"+a);n.addParam("x","i32"),n.addParam("r","i32");const r=n.getCodeBuilder();for(let o=0;o<6;o++){const u=0==o?r.getLocal("x"):r.i32_add(r.getLocal("x"),r.i32_const(o*s)),_=u,g=r.i32_add(r.getLocal("x"),r.i32_const(o*s+c)),h=0==o?r.getLocal("r"):r.i32_add(r.getLocal("r"),r.i32_const(o*s)),p=h,L=r.i32_add(r.getLocal("r"),r.i32_const(o*s+c)),b=d(e[Math.floor(o/3)][a%12],i[o%3][a%6]),w=t.alloc([...xl.bigInt2BytesLE(y(b[0]),l),...xl.bigInt2BytesLE(y(b[1]),l)]);a%2==1?n.addCode(r.call(f+"_copy",_,p),r.call(f+"_neg",g,L),r.call(m+"_mul",h,r.i32_const(w),h)):n.addCode(r.call(m+"_mul",u,r.i32_const(w),h))}function d(t,a){const e=t[0],i=t[1],n=a[0],l=a[1],c=[(e*n-i*l)%o,(e*l+i*n)%o];return Ml(c[0])&&(c[0]=c[0]+o),c}}function D(a,o,i){const n=function(t){let a=t;const e=[];for(;a>0n;){if(Tl(a)){const t=2-Number(a%4n);e.push(t),a-=BigInt(t)}else e.push(0);a>>=1n}return e}(a).map((t=>-1==t?255:t)),l=t.alloc(n),c=t.addFunction(e+"__cyclotomicExp_"+i);c.addParam("x","i32"),c.addParam("r","i32"),c.addLocal("bit","i32"),c.addLocal("i","i32");const s=c.getCodeBuilder(),d=s.getLocal("x"),u=s.getLocal("r"),_=s.i32_const(t.alloc(r));c.addCode(s.call(O+"_conjugate",d,_),s.call(O+"_one",u),s.if(s.teeLocal("bit",s.i32_load8_s(s.i32_const(n.length-1),l)),s.if(s.i32_eq(s.getLocal("bit"),s.i32_const(1)),s.call(O+"_mul",u,d,u),s.call(O+"_mul",u,_,u))),s.setLocal("i",s.i32_const(n.length-2)),s.block(s.loop(s.call(e+"__cyclotomicSquare",u,u),s.if(s.teeLocal("bit",s.i32_load8_s(s.getLocal("i"),l)),s.if(s.i32_eq(s.getLocal("bit"),s.i32_const(1)),s.call(O+"_mul",u,d,u),s.call(O+"_mul",u,_,u))),s.br_if(1,s.i32_eqz(s.getLocal("i"))),s.setLocal("i",s.i32_sub(s.getLocal("i"),s.i32_const(1))),s.br(0)))),o&&c.addCode(s.call(O+"_conjugate",u,u))}t.modules[e]={n64q:n,n64r:d,n8q:l,n8r:u,pG1gen:C,pG1zero:x,pG1b:h,pG2gen:B,pG2zero:v,pG2b:L,pq:t.modules.f1m.pq,pr:g,pOneT:S,r:i,q:o,prePSize:Q,preQSize:k},function(){const a=t.addFunction(q+"_mul1");a.addParam("pA","i32"),a.addParam("pC1","i32"),a.addParam("pR","i32");const e=a.getCodeBuilder(),o=e.getLocal("pA"),i=e.i32_add(e.getLocal("pA"),e.i32_const(2*c)),n=e.i32_add(e.getLocal("pA"),e.i32_const(4*c)),l=e.getLocal("pC1"),s=e.getLocal("pR"),r=e.i32_add(e.getLocal("pR"),e.i32_const(2*c)),d=e.i32_add(e.getLocal("pR"),e.i32_const(4*c)),u=e.i32_const(t.alloc(2*c)),_=e.i32_const(t.alloc(2*c));a.addCode(e.call(m+"_add",o,i,u),e.call(m+"_add",i,n,_),e.call(m+"_mul",i,l,d),e.call(m+"_mul",_,l,s),e.call(m+"_sub",s,d,s),e.call(m+"_mulNR",s,s),e.call(m+"_mul",u,l,r),e.call(m+"_sub",r,d,r))}(),function(){const a=t.addFunction(q+"_mul01");a.addParam("pA","i32"),a.addParam("pC0","i32"),a.addParam("pC1","i32"),a.addParam("pR","i32");const e=a.getCodeBuilder(),o=e.getLocal("pA"),i=e.i32_add(e.getLocal("pA"),e.i32_const(2*c)),n=e.i32_add(e.getLocal("pA"),e.i32_const(4*c)),l=e.getLocal("pC0"),s=e.getLocal("pC1"),r=e.getLocal("pR"),d=e.i32_add(e.getLocal("pR"),e.i32_const(2*c)),u=e.i32_add(e.getLocal("pR"),e.i32_const(4*c)),_=e.i32_const(t.alloc(2*c)),g=e.i32_const(t.alloc(2*c)),f=e.i32_const(t.alloc(2*c)),h=e.i32_const(t.alloc(2*c));a.addCode(e.call(m+"_mul",o,l,_),e.call(m+"_mul",i,s,g),e.call(m+"_add",o,i,f),e.call(m+"_add",o,n,h),e.call(m+"_add",i,n,r),e.call(m+"_mul",r,s,r),e.call(m+"_sub",r,g,r),e.call(m+"_mulNR",r,r),e.call(m+"_add",r,_,r),e.call(m+"_add",l,s,d),e.call(m+"_mul",d,f,d),e.call(m+"_sub",d,_,d),e.call(m+"_sub",d,g,d),e.call(m+"_mul",h,l,u),e.call(m+"_sub",u,_,u),e.call(m+"_add",u,g,u))}(),function(){const a=t.addFunction(O+"_mul014");a.addParam("pA","i32"),a.addParam("pC0","i32"),a.addParam("pC1","i32"),a.addParam("pC4","i32"),a.addParam("pR","i32");const e=a.getCodeBuilder(),o=e.getLocal("pA"),i=e.i32_add(e.getLocal("pA"),e.i32_const(6*c)),n=e.getLocal("pC0"),l=e.getLocal("pC1"),s=e.getLocal("pC4"),r=e.i32_const(t.alloc(6*c)),d=e.i32_const(t.alloc(6*c)),u=e.i32_const(t.alloc(2*c)),_=e.getLocal("pR"),g=e.i32_add(e.getLocal("pR"),e.i32_const(6*c));a.addCode(e.call(q+"_mul01",o,n,l,r),e.call(q+"_mul1",i,s,d),e.call(m+"_add",l,s,u),e.call(q+"_add",i,o,g),e.call(q+"_mul01",g,n,u,g),e.call(q+"_sub",g,r,g),e.call(q+"_sub",g,d,g),e.call(q+"_copy",d,_),e.call(q+"_mulNR",_,_),e.call(q+"_add",_,r,_))}(),function(){const a=t.addFunction(e+"_ell");a.addParam("pP","i32"),a.addParam("pCoefs","i32"),a.addParam("pF","i32");const o=a.getCodeBuilder(),i=o.getLocal("pP"),n=o.i32_add(o.getLocal("pP"),o.i32_const(l)),s=o.getLocal("pF"),r=o.getLocal("pCoefs"),d=o.i32_add(o.getLocal("pCoefs"),o.i32_const(c)),u=o.i32_add(o.getLocal("pCoefs"),o.i32_const(2*c)),_=o.i32_add(o.getLocal("pCoefs"),o.i32_const(3*c)),g=o.i32_add(o.getLocal("pCoefs"),o.i32_const(4*c)),h=t.alloc(2*c),p=o.i32_const(h),m=o.i32_const(h),L=o.i32_const(h+c),b=t.alloc(2*c),w=o.i32_const(b),y=o.i32_const(b),A=o.i32_const(b+c);a.addCode(o.call(f+"_mul",r,n,m),o.call(f+"_mul",d,n,L),o.call(f+"_mul",u,i,y),o.call(f+"_mul",_,i,A),o.call(O+"_mul014",s,g,w,p,s))}();const $=t.alloc(Q),j=t.alloc(k);function V(a){const o=t.addFunction(e+"_pairingEq"+a);for(let t=0;t>8n&0xFFn)),a.push(Number(e>>16n&0xFFn)),a.push(Number(e>>24n&0xFFn)),a}function Vl(t){const a=function(t){for(var a=[],e=0;e>6,128|63&o):o<55296||o>=57344?a.push(224|o>>12,128|o>>6&63,128|63&o):(e++,o=65536+((1023&o)<<10|1023&t.charCodeAt(e)),a.push(240|o>>18,128|o>>12&63,128|o>>6&63,128|63&o))}return a}(t);return[...Yl(a.length),...a]}function Kl(t){const a=[];let e=Nl(t);if(Dl(e))throw new Error("Number cannot be negative");for(;!$l(e);)a.push(Number(0x7Fn&e)),e>>=7n;0==a.length&&a.push(0);for(let t=0;t0xFFFFFFFFn)throw new Error("Number too big");if(a>0x7FFFFFFFn&&(a-=0x100000000n),a<-2147483648n)throw new Error("Number too small");return Hl(a)}function Wl(t){let a=Nl(t);if(a>0xFFFFFFFFFFFFFFFFn)throw new Error("Number too big");if(a>0x7FFFFFFFFFFFFFFFn&&(a-=0x10000000000000000n),a<-9223372036854775808n)throw new Error("Number too small");return Hl(a)}function Yl(t){let a=Nl(t);if(a>0xFFFFFFFFn)throw new Error("Number too big");return Kl(a)}function Jl(t){return Array.from(t,(function(t){return("0"+(255&t).toString(16)).slice(-2)})).join("")}!function(t){globalThis.btoa(t)}("("+function(t){const a=32767;let e,o;async function i(t){const i=new Uint8Array(t.code),n=await WebAssembly.compile(i);o=new WebAssembly.Memory({initial:t.init,maximum:a}),e=await WebAssembly.instantiate(n,{env:{memory:o}})}function n(t){const e=new Uint32Array(o.buffer,0,1);for(;3&e[0];)e[0]++;const i=e[0];if(e[0]+=t,e[0]+t>o.buffer.byteLength){const i=o.buffer.byteLength/65536;let n=Math.floor((e[0]+t)/65536)+1;n>a&&(n=a),o.grow(n-i)}return i}function l(t){const a=n(t.byteLength);return s(a,t),a}function c(t,a){const e=new Uint8Array(o.buffer);return new Uint8Array(e.buffer,e.byteOffset+t,a)}function s(t,a){new Uint8Array(o.buffer).set(new Uint8Array(a),t)}function r(t){if("INIT"==t[0].cmd)return i(t[0]);const a={vars:[],out:[]},r=new Uint32Array(o.buffer,0,1)[0];for(let o=0;otc[t.type]))],...this.returnType?[1,tc[this.returnType]]:[0]]}getBody(){const t=this.locals.map((t=>[...Yl(t.length),tc[t.type]])),a=[...Yl(this.locals.length),...[].concat(...t),...this.code,11];return[...Yl(a.length),...a]}addCode(...t){this.code.push(...[].concat(...t))}getCodeBuilder(){return new Xl(this)}}class ec{constructor(){this.functions=[],this.functionIdxByName={},this.nImportFunctions=0,this.nInternalFunctions=0,this.memory={pagesSize:1,moduleName:"env",fieldName:"memory"},this.free=8,this.datas=[],this.modules={},this.exports=[],this.functionsTable=[]}build(){return this._setSignatures(),new Uint8Array([...jl(1836278016),...jl(1),...this._buildType(),...this._buildImport(),...this._buildFunctionDeclarations(),...this._buildFunctionsTable(),...this._buildExports(),...this._buildElements(),...this._buildCode(),...this._buildData()])}addFunction(t){if(void 0!==this.functionIdxByName[t])throw new Error(`Function already defined: ${t}`);const a=this.functions.length;return this.functionIdxByName[t]=a,this.functions.push(new ac(this,t,"internal")),this.nInternalFunctions++,this.functions[a]}addIimportFunction(t,a,e){if(void 0!==this.functionIdxByName[t])throw new Error(`Function already defined: ${t}`);if(this.functions.length>0&&"internal"==this.functions[this.functions.length-1].type)throw new Error(`Import functions must be declared before internal: ${t}`);let o=e||t;const i=this.functions.length;return this.functionIdxByName[t]=i,this.functions.push(new ac(this,t,"import",a,o)),this.nImportFunctions++,this.functions[i]}setMemory(t,a,e){this.memory={pagesSize:t,moduleName:a||"env",fieldName:e||"memory"}}exportFunction(t,a){const e=a||t;if(void 0===this.functionIdxByName[t])throw new Error(`Function not defined: ${t}`);const o=this.functionIdxByName[t];e!=t&&(this.functionIdxByName[e]=o),this.exports.push({exportName:e,idx:o})}addFunctionToTable(t){const a=this.functionIdxByName[t];this.functionsTable.push(a)}addData(t,a){this.datas.push({offset:t,bytes:a})}alloc(t,a){let e,o;(Array.isArray(t)||ArrayBuffer.isView(t))&&void 0===a?(e=t.length,o=t):(e=t,o=a),e=1+(e-1>>3)<<3;const i=this.free;return this.free+=e,o&&this.addData(i,o),i}allocString(t){const a=(new globalThis.TextEncoder).encode(t);return this.alloc([...a,0])}_setSignatures(){this.signatures=[];const t={};if(this.functionsTable.length>0){const a=this.functions[this.functionsTable[0]].getSignature();t["s_"+Jl(a)]=0,this.signatures.push(a)}for(let a=0;a=2&&(d>=1||u>=7)){""!==s&&(s+=" ");const t=oc.fromArray(a,4294967296).toString();s+=t}else console.log(oc.fromArray(a,4294967296))},error:function(t,e,o,i,n,c){let s;throw s=7==t?h(e)+" "+l.getFr(i).toString()+" != "+l.getFr(n).toString()+" "+h(c):9==t?h(e)+" "+l.getFr(i).toString()+" "+h(n):5==t&&a.sym?h(e)+" "+a.sym.labelIdx2Name[n]:h(e)+" "+o+" "+i+" "+n+" "+c,console.log("ERROR: ",t,s),new Error(s)},log:function(t){console.log(l.getFr(t).toString())},logGetSignal:function(t,e){a.logGetSignal&&a.logGetSignal(t,l.getFr(e))},logSetSignal:function(t,e){a.logSetSignal&&a.logSetSignal(t,l.getFr(e))},logStartComponent:function(t){a.logStartComponent&&a.logStartComponent(t)},logFinishComponent:function(t){a.logFinishComponent&&a.logFinishComponent(t)}}});"function"==typeof _.exports.getVersion&&(r=_.exports.getVersion()),"function"==typeof _.exports.getMinorVersion&&(d=_.exports.getMinorVersion()),"function"==typeof _.exports.getPatchVersion&&(u=_.exports.getPatchVersion());const g=a&&(a.sanityCheck||a.logGetSignal||a.logSetSignal||a.logStartComponent||a.logFinishComponent);return l=2===r?new lc(_,g):new nc(e,_,g),l;function f(){for(var t="",a=_.exports.getMessageChar();0!=a;)t+=String.fromCharCode(a),a=_.exports.getMessageChar();return t}function h(t){const a=new Uint8Array(e.buffer),o=[];for(let e=0;a[t+e]>0;e++)o.push(a[t+e]);return String.fromCharCode.apply(null,o)}}class nc{constructor(t,a,e){this.memory=t,this.i32=new Uint32Array(t.buffer),this.instance=a,this.n32=(this.instance.exports.getFrLen()>>2)-2;const o=this.instance.exports.getPRawPrime(),i=new Array(this.n32);for(let t=0;t>2)+t];this.prime=oc.fromArray(i,4294967296),this.Fr=new dn(this.prime),this.mask32=oc.fromString("FFFFFFFF",16),this.NVars=this.instance.exports.getNVars(),this.n64=Math.floor((this.Fr.bitLength-1)/64)+1,this.R=this.Fr.e(oc.shiftLeft(1,64*this.n64)),this.RInv=this.Fr.inv(this.R),this.sanityCheck=e}circom_version(){return 1}async _doCalculateWitness(t,a){this.instance.exports.init(this.sanityCheck||a?1:0);const e=this.allocInt(),o=this.allocFr();Object.keys(t).forEach((a=>{const i=Si(a),n=parseInt(i.slice(0,8),16),l=parseInt(i.slice(8,16),16);try{this.instance.exports.getSignalOffset32(e,0,n,l)}catch(t){throw new Error(`Signal ${a} is not an input of the circuit.`)}const c=this.getInt(e),s=vi(t[a]);for(let t=0;t>2]}setInt(t,a){this.i32[t>>2]=a}getFr(t){const a=this,e=t>>2;if(2147483648&a.i32[e+1]){const t=new Array(a.n32);for(let o=0;o>2]=i,void(e.i32[1+(t>>2)]=0)}e.i32[t>>2]=0,e.i32[1+(t>>2)]=2147483648;const n=oc.toArray(a,4294967296);for(let a=0;a>2)+a]=o>=0?n[o]:0}}}class lc{constructor(t,a){this.instance=t,this.version=this.instance.exports.getVersion(),this.n32=this.instance.exports.getFieldNumLen32(),this.instance.exports.getRawPrime();const e=new Array(this.n32);for(let t=0;t{const e=Si(a),i=parseInt(e.slice(0,8),16),n=parseInt(e.slice(8,16),16),l=vi(t[a]);for(let t=0;t1)throw new Error(t.fileName+": File has more than one header");t.pos=a[1][0].p;const e=await t.readULE32(),o=await t.read(e),i=_e.fromRprLE(o),n=await Ye(i);if(8*n.F1.n64!=e)throw new Error(t.fileName+": Invalid size");const l=await t.readULE32(),c=await t.readULE32();if(t.pos-a[1][0].p!=a[1][0].size)throw new Error("Invalid PTau header size");return{curve:n,power:l,ceremonyPower:c}}function wc(t,a,e,o){const i={tau:{},alpha:{},beta:{}};return i.tau.g1_s=n(),i.tau.g1_sx=n(),i.alpha.g1_s=n(),i.alpha.g1_sx=n(),i.beta.g1_s=n(),i.beta.g1_sx=n(),i.tau.g2_spx=l(),i.alpha.g2_spx=l(),i.beta.g2_spx=l(),i;function n(){let i;return i=o?e.G1.fromRprLEM(t,a):e.G1.fromRprUncompressed(t,a),a+=2*e.G1.F.n8,i}function l(){let i;return i=o?e.G2.fromRprLEM(t,a):e.G2.fromRprUncompressed(t,a),a+=2*e.G2.F.n8,i}}function yc(t,a,e,o,i){async function n(o){i?e.G1.toRprLEM(t,a,o):e.G1.toRprUncompressed(t,a,o),a+=2*e.F1.n8}async function l(o){i?e.G2.toRprLEM(t,a,o):e.G2.toRprUncompressed(t,a,o),a+=2*e.F2.n8}return n(o.tau.g1_s),n(o.tau.g1_sx),n(o.alpha.g1_s),n(o.alpha.g1_sx),n(o.beta.g1_s),n(o.beta.g1_sx),l(o.tau.g2_spx),l(o.alpha.g2_spx),l(o.beta.g2_spx),t}async function Ac(t,a){const e={};e.tauG1=await s(),e.tauG2=await r(),e.alphaG1=await s(),e.betaG1=await s(),e.betaG2=await r(),e.key=await async function(t,a,e){return wc(await t.read(2*a.F1.n8*6+2*a.F2.n8*3),0,a,e)}(t,a,!0),e.partialHash=await t.read(216),e.nextChallenge=await t.read(64),e.type=await t.readULE32();const o=new Uint8Array(2*a.G1.F.n8*6+2*a.G2.F.n8*3);yc(o,0,a,e.key,!1);const i=to.exports(64);i.setPartialHash(e.partialHash),i.update(o),e.responseHash=i.digest();const n=await t.readULE32(),l=t.pos;let c=0;for(;t.pos-l1)throw new Error(t.fileName+": File has more than one contributions section");t.pos=e[7][0].p;const o=await t.readULE32(),i=[];for(let e=0;e0){const a=new Uint8Array(n);await t.writeULE32(a.byteLength),await t.write(a)}else await t.writeULE32(0);async function l(e){a.G1.toRprLEM(o,0,e),await t.write(o)}async function c(e){a.G2.toRprLEM(i,0,e),await t.write(i)}}async function xc(t,a,e){await t.writeULE32(7);const o=t.pos;await t.writeULE64(0),await t.writeULE32(e.length);for(let o=0;o0?u[u.length-1].nextChallenge:Ic(r,d,n);const b=await Me(e,"ptau",1,i?7:2);await Lc(b,r,d);const w=await m.read(64);if(Uo(l,L)&&(L=w,u[u.length-1].nextChallenge=L),!Uo(w,L))throw new Error("Wrong contribution. this contribution is not based on the previus hash");const y=new to.exports(64);y.update(w);const A=[];let C;C=await I(m,b,"G1",2,2**d*2-1,[1],"tauG1"),_.tauG1=C[0],C=await I(m,b,"G2",3,2**d,[1],"tauG2"),_.tauG2=C[0],C=await I(m,b,"G1",4,2**d,[0],"alphaG1"),_.alphaG1=C[0],C=await I(m,b,"G1",5,2**d,[0],"betaG1"),_.betaG1=C[0],C=await I(m,b,"G2",6,1,[0],"betaG2"),_.betaG2=C[0],_.partialHash=y.getPartialHash();const F=await m.read(2*r.F1.n8*6+2*r.F2.n8*3);_.key=wc(F,0,r,!1),y.update(new Uint8Array(F));const x=y.digest();if(n&&n.info(Mo(x,"Contribution Response Hash imported: ")),i){const t=new to.exports(64);t.update(x),await B(t,b,"G1",2,2**d*2-1,"tauG1",n),await B(t,b,"G2",3,2**d,"tauG2",n),await B(t,b,"G1",4,2**d,"alphaTauG1",n),await B(t,b,"G1",5,2**d,"betaTauG1",n),await B(t,b,"G2",6,1,"betaG2",n),_.nextChallenge=t.digest(),n&&n.info(Mo(_.nextChallenge,"Next Challenge Hash: "))}else _.nextChallenge=l;return u.push(_),await xc(b,r,u),await m.close(),await b.close(),await c.close(),_.nextChallenge;async function I(t,a,e,o,l,c,s){return i?await async function(t,a,e,o,i,l,c){const s=r[e],d=s.F.n8,u=2*s.F.n8,_=[];await Ue(a,o);const g=Math.floor((1<<24)/u);A[o]=a.pos;for(let e=0;e=e&&a=a&&i1?s[s.length-2]:r;const u=s[s.length-1];if(a&&a.debug("Validating contribution #"+s[s.length-1].id),!await vc(n,u,d,a))return!1;const _=to.exports(64);_.update(u.responseHash),a&&a.debug("Verifying powers in tau*G1 section");const g=await w(2,"G1","tauG1",2**l*2-1,[0,1],a);if(e=await Ec(n,g.R1,g.R2,n.G2.g,u.tauG2),!0!==e)return a&&a.error("tauG1 section. Powers do not match"),!1;if(!n.G1.eq(n.G1.g,g.singularPoints[0]))return a&&a.error("First element of tau*G1 section must be the generator"),!1;if(!n.G1.eq(u.tauG1,g.singularPoints[1]))return a&&a.error("Second element of tau*G1 section does not match the one in the contribution section"),!1;a&&a.debug("Verifying powers in tau*G2 section");const f=await w(3,"G2","tauG2",2**l,[0,1],a);if(e=await Ec(n,n.G1.g,u.tauG1,f.R1,f.R2),!0!==e)return a&&a.error("tauG2 section. Powers do not match"),!1;if(!n.G2.eq(n.G2.g,f.singularPoints[0]))return a&&a.error("First element of tau*G2 section must be the generator"),!1;if(!n.G2.eq(u.tauG2,f.singularPoints[1]))return a&&a.error("Second element of tau*G2 section does not match the one in the contribution section"),!1;a&&a.debug("Verifying powers in alpha*tau*G1 section");const h=await w(4,"G1","alphatauG1",2**l,[0],a);if(e=await Ec(n,h.R1,h.R2,n.G2.g,u.tauG2),!0!==e)return a&&a.error("alphaTauG1 section. Powers do not match"),!1;if(!n.G1.eq(u.alphaG1,h.singularPoints[0]))return a&&a.error("First element of alpha*tau*G1 section (alpha*G1) does not match the one in the contribution section"),!1;a&&a.debug("Verifying powers in beta*tau*G1 section");const p=await w(5,"G1","betatauG1",2**l,[0],a);if(e=await Ec(n,p.R1,p.R2,n.G2.g,u.tauG2),!0!==e)return a&&a.error("betaTauG1 section. Powers do not match"),!1;if(!n.G1.eq(u.betaG1,p.singularPoints[0]))return a&&a.error("First element of beta*tau*G1 section (beta*G1) does not match the one in the contribution section"),!1;const m=await async function(t){const a=n.G2,e=2*a.F.n8,l=new Uint8Array(e);if(!i[6])throw t.error("File has no BetaG2 section"),new Error("File has no BetaG2 section");if(i[6].length>1)throw t.error("File has no BetaG2 section"),new Error("File has more than one GetaG2 section");o.pos=i[6][0].p;const c=await o.read(e),s=a.fromRprLEM(c);return a.toRprUncompressed(l,0,s),_.update(l),s}(a);if(!n.G2.eq(u.betaG2,m))return a&&a.error("betaG2 element in betaG2 section does not match the one in the contribution section"),!1;const L=_.digest();if(l==c&&!Uo(L,u.nextChallenge))return a&&a.error("Hash of the values does not match the next challenge of the last contributor in the contributions section"),!1;a&&a.info(Mo(L,"Next challenge hash: ")),b(u,d);for(let t=s.length-2;t>=0;t--){const e=s[t],o=t>0?s[t-1]:r;if(!await vc(n,e,o,a))return!1;b(e,o)}if(a&&a.info("-----------------------------------------------------"),i[12]&&i[13]&&i[14]&&i[15]){let t;if(t=await y("G1",2,12,"tauG1",a),!t)return!1;if(t=await y("G2",3,13,"tauG2",a),!t)return!1;if(t=await y("G1",4,14,"alphaTauG1",a),!t)return!1;if(t=await y("G1",5,15,"betaTauG1",a),!t)return!1}else a&&a.warn('this file does not contain phase2 precalculated values. Please run: \n snarkjs "powersoftau preparephase2" to prepare this file to be used in the phase2 ceremony.');return await o.close(),a&&a.info("Powers of Tau Ok!"),!0;function b(t,e){if(!a)return;a.info("-----------------------------------------------------"),a.info(`Contribution #${t.id}: ${t.name||""}`),a.info(Mo(t.nextChallenge,"Next Challenge: "));const o=new Uint8Array(2*n.G1.F.n8*6+2*n.G2.F.n8*3);yc(o,0,n,t.key,!1);const i=to.exports(64);i.setPartialHash(t.partialHash),i.update(o);const l=i.digest();a.info(Mo(l,"Response Hash:")),a.info(Mo(e.nextChallenge,"Response Hash:")),1==t.type&&(a.info(`Beacon generator: ${Ko(t.beaconHash)}`),a.info(`Beacon iterations Exp: ${t.numIterationsExp}`))}async function w(t,a,e,l,c,s){const r=n[a],d=2*r.F.n8;await ke(o,i,t);const u=[];let g=r.zero,f=r.zero,h=r.zero;for(let t=0;t0){const t=r.fromRprLEM(i,0),a=Do(Ro(4),0);g=r.add(g,r.timesScalar(h,a)),f=r.add(f,r.timesScalar(t,a))}const m=await r.multiExpAffine(i.slice(0,(a-1)*d),p),L=await r.multiExpAffine(i.slice(d),p);g=r.add(g,m),f=r.add(f,L),h=r.fromRprLEM(i,(a-1)*d);for(let e=0;e=t&&o1;)r/=2,d+=1;if(2**d!=s)throw new Error("Invalid file size");i&&i.debug("Power to tau size: "+d);const u=await $o(o),_=await Ge(e),g=to.exports(64);for(let t=0;t{i.debug(a+".g1_s: "+t.G1.toString(p[a].g1_s,16)),i.debug(a+".g1_sx: "+t.G1.toString(p[a].g1_sx,16)),i.debug(a+".g2_sp: "+t.G2.toString(p[a].g2_sp,16)),i.debug(a+".g2_spx: "+t.G2.toString(p[a].g2_spx,16)),i.debug("")}));const m=to.exports(64);await _.write(h),m.update(h),await Pc(n,_,m,t,"G1",2**d*2-1,t.Fr.one,p.tau.prvKey,"COMPRESSED","tauG1",i),await Pc(n,_,m,t,"G2",2**d,t.Fr.one,p.tau.prvKey,"COMPRESSED","tauG2",i),await Pc(n,_,m,t,"G1",2**d,p.alpha.prvKey,p.tau.prvKey,"COMPRESSED","alphaTauG1",i),await Pc(n,_,m,t,"G1",2**d,p.beta.prvKey,p.tau.prvKey,"COMPRESSED","betaTauG1",i),await Pc(n,_,m,t,"G2",1,p.beta.prvKey,p.tau.prvKey,"COMPRESSED","betaTauG2",i);const L=new Uint8Array(2*t.F1.n8*6+2*t.F2.n8*3);yc(L,0,t,p,!1),await _.write(L),m.update(L);const b=m.digest();i&&i.info(Mo(b,"Contribution Response Hash: ")),await _.close(),await n.close()},beacon:async function(t,a,e,o,i,n){const l=Vo(o);if(0==l.byteLength||2*l.byteLength!=o.length)return n&&n.error("Invalid Beacon Hash. (It must be a valid hexadecimal sequence)"),!1;if(l.length>=256)return n&&n.error("Maximum lenght of beacon hash is 255 bytes"),!1;if((i=parseInt(i))<10||i>63)return n&&n.error("Invalid numIterationsExp. (Must be between 10 and 63)"),!1;await to.exports.ready();const{fd:c,sections:s}=await Te(t,"ptau",1),{curve:r,power:d,ceremonyPower:u}=await bc(c,s);if(d!=u)return n&&n.error("This file has been reduced. You cannot contribute into a reduced file."),!1;s[12]&&n&&n.warn("Contributing into a file that has phase2 calculated. You will have to prepare phase2 again.");const _=await Cc(c,r,s),g={name:e,type:1,numIterationsExp:i,beaconHash:l};let f;f=_.length>0?_[_.length-1].nextChallenge:Ic(r,d,n),g.key=await Bc(r,f,l,i);const h=new to.exports(64);h.update(f);const p=await Me(a,"ptau",1,7);await Lc(p,r,d);const m=[];let L;L=await A(2,"G1",2**d*2-1,r.Fr.e(1),g.key.tau.prvKey,"tauG1",n),g.tauG1=L[1],L=await A(3,"G2",2**d,r.Fr.e(1),g.key.tau.prvKey,"tauG2",n),g.tauG2=L[1],L=await A(4,"G1",2**d,g.key.alpha.prvKey,g.key.tau.prvKey,"alphaTauG1",n),g.alphaG1=L[0],L=await A(5,"G1",2**d,g.key.beta.prvKey,g.key.tau.prvKey,"betaTauG1",n),g.betaG1=L[0],L=await A(6,"G2",1,g.key.beta.prvKey,g.key.tau.prvKey,"betaTauG2",n),g.betaG2=L[0],g.partialHash=h.getPartialHash();const b=new Uint8Array(2*r.F1.n8*6+2*r.F2.n8*3);yc(b,0,r,g.key,!1),h.update(new Uint8Array(b));const w=h.digest();n&&n.info(Mo(w,"Contribution Response Hash imported: "));const y=new to.exports(64);return y.update(w),await C(p,"G1",2,2**d*2-1,"tauG1",n),await C(p,"G2",3,2**d,"tauG2",n),await C(p,"G1",4,2**d,"alphaTauG1",n),await C(p,"G1",5,2**d,"betaTauG1",n),await C(p,"G2",6,1,"betaG2",n),g.nextChallenge=y.digest(),n&&n.info(Mo(g.nextChallenge,"Next Challenge Hash: ")),_.push(g),await xc(p,r,_),await c.close(),await p.close(),w;async function A(t,a,e,o,i,n,l){const d=[];c.pos=s[t][0].p,await Ue(p,t),m[t]=p.pos;const u=r[a],_=2*u.F.n8,g=Math.floor((1<<20)/_);let f=o;for(let t=0;t0?d[d.length-1].nextChallenge:Ic(c,s,i),u.key=mc(c,_,g);const f=new to.exports(64);f.update(_);const h=await Me(a,"ptau",1,7);await Lc(h,c,s);const p=[];let m;m=await y(2,"G1",2**s*2-1,c.Fr.e(1),u.key.tau.prvKey,"tauG1"),u.tauG1=m[1],m=await y(3,"G2",2**s,c.Fr.e(1),u.key.tau.prvKey,"tauG2"),u.tauG2=m[1],m=await y(4,"G1",2**s,u.key.alpha.prvKey,u.key.tau.prvKey,"alphaTauG1"),u.alphaG1=m[0],m=await y(5,"G1",2**s,u.key.beta.prvKey,u.key.tau.prvKey,"betaTauG1"),u.betaG1=m[0],m=await y(6,"G2",1,u.key.beta.prvKey,u.key.tau.prvKey,"betaTauG2"),u.betaG2=m[0],u.partialHash=f.getPartialHash();const L=new Uint8Array(2*c.F1.n8*6+2*c.F2.n8*3);yc(L,0,c,u.key,!1),f.update(new Uint8Array(L));const b=f.digest();i&&i.info(Mo(b,"Contribution Response Hash imported: "));const w=new to.exports(64);return w.update(b),await A(h,"G1",2,2**s*2-1,"tauG1"),await A(h,"G2",3,2**s,"tauG2"),await A(h,"G1",4,2**s,"alphaTauG1"),await A(h,"G1",5,2**s,"betaTauG1"),await A(h,"G2",6,1,"betaG2"),u.nextChallenge=w.digest(),i&&i.info(Mo(u.nextChallenge,"Next Challenge Hash: ")),d.push(u),await xc(h,c,d),await n.close(),await h.close(),b;async function y(t,a,e,o,s,r){const d=[];n.pos=l[t][0].p,await Ue(h,t),p[t]=h.pos;const u=c[a],_=2*u.F.n8,g=Math.floor((1<<20)/_);let m=o;for(let t=0;t>BigInt(a)}function Qc(t){return(BigInt(t)&BigInt(1))==BigInt(1)}function kc(t){if(t>BigInt(Number.MAX_SAFE_INTEGER))throw new Error("Number too big");return Number(t)}function Rc(t,a){return BigInt(t)+BigInt(a)}function Nc(t,a){return BigInt(t)-BigInt(a)}function Dc(t,a){return BigInt(t)**BigInt(a)}function $c(t,a){return BigInt(t)/BigInt(a)}function jc(t,a){return BigInt(t)%BigInt(a)}function Vc(t,a){return BigInt(t)==BigInt(a)}function Kc(t,a){return BigInt(t)>BigInt(a)}function Hc(t,a){return BigInt(t)&BigInt(a)}function Zc(t,a,e,o){const i="0000000"+e.toString(16),n=new Uint32Array(t.buffer,t.byteOffset+a,o/4),l=1+(4*(i.length-7)-1>>5);for(let t=0;ti[i.length-a-1]=t.toString(16).padStart(8,"0"))),Gc(i.join(""),16)}function Yc(t,a){return t.toString(a)}function Jc(t){const a=new Uint8Array(Math.floor((Tc(t)-1)/8)+1);return Zc(a,0,t,a.byteLength),a}const Xc=zc(0),ts=zc(1);function as(t,a,e){if(!e)return t.one;const o=function(t){let a=BigInt(t);const e=[];for(;a;)a&BigInt(1)?e.push(1):e.push(0),a>>=BigInt(1);return e}(e);if(0==o.length)return t.one;let i=a;for(let e=o.length-2;e>=0;e--)i=t.square(i),o[e]&&(i=t.mul(i,a));return i}function es(t){if(t.m%2==1)if(Vc(jc(t.p,4),1))if(Vc(jc(t.p,8),1))if(Vc(jc(t.p,16),1))!function(t){t.sqrt_q=Dc(t.p,t.m),t.sqrt_s=0,t.sqrt_t=Nc(t.sqrt_q,1);for(;!Qc(t.sqrt_t);)t.sqrt_s=t.sqrt_s+1,t.sqrt_t=$c(t.sqrt_t,2);let a=t.one;for(;t.eq(a,t.one);){const e=t.random();t.sqrt_z=t.pow(e,t.sqrt_t),a=t.pow(t.sqrt_z,2**(t.sqrt_s-1))}t.sqrt_tm1d2=$c(Nc(t.sqrt_t,1),2),t.sqrt=function(t){const a=this;if(a.isZero(t))return a.zero;let e=a.pow(t,a.sqrt_tm1d2);const o=a.pow(a.mul(a.square(e),t),2**(a.sqrt_s-1));if(a.eq(o,a.negone))return null;let i=a.sqrt_s,n=a.mul(t,e),l=a.mul(n,e),c=a.sqrt_z;for(;!a.eq(l,a.one);){let t=a.square(l),o=1;for(;!a.eq(t,a.one);)t=a.square(t),o++;e=c;for(let t=0;t>>0,t[i]=(t[i]^t[a])>>>0,t[i]=(t[i]<<16|t[i]>>>16&65535)>>>0,t[o]=t[o]+t[i]>>>0,t[e]=(t[e]^t[o])>>>0,t[e]=(t[e]<<12|t[e]>>>20&4095)>>>0,t[a]=t[a]+t[e]>>>0,t[i]=(t[i]^t[a])>>>0,t[i]=(t[i]<<8|t[i]>>>24&255)>>>0,t[o]=t[o]+t[i]>>>0,t[e]=(t[e]^t[o])>>>0,t[e]=(t[e]<<7|t[e]>>>25&127)>>>0}class is{constructor(t){t=t||[0,0,0,0,0,0,0,0],this.state=[1634760805,857760878,2036477234,1797285236,t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],0,0,0,0],this.idx=16,this.buff=new Array(16)}nextU32(){return 16==this.idx&&this.update(),this.buff[this.idx++]}nextU64(){return Rc((t=this.nextU32(),a=4294967296,BigInt(t)*BigInt(a)),this.nextU32());var t,a}nextBool(){return 1==(1&this.nextU32())}update(){for(let t=0;t<16;t++)this.buff[t]=this.state[t];for(let a=0;a<10;a++)os(t=this.buff,0,4,8,12),os(t,1,5,9,13),os(t,2,6,10,14),os(t,3,7,11,15),os(t,0,5,10,15),os(t,1,6,11,12),os(t,2,7,8,13),os(t,3,4,9,14);var t;for(let t=0;t<16;t++)this.buff[t]=this.buff[t]+this.state[t]>>>0;this.idx=0,this.state[12]=this.state[12]+1>>>0,0==this.state[12]&&(this.state[13]=this.state[13]+1>>>0,0==this.state[13]&&(this.state[14]=this.state[14]+1>>>0,0==this.state[14]&&(this.state[15]=this.state[15]+1>>>0)))}}function ns(t){let a=new Uint8Array(t);if(void 0!==globalThis.crypto)globalThis.crypto.getRandomValues(a);else for(let e=0;e>>0;return a}let ls=null;function cs(){return ls||(ls=new is(function(){const t=ns(32),a=new Uint32Array(t.buffer),e=[];for(let t=0;t<8;t++)e.push(a[t]);return e}()),ls)}class ss{constructor(t,a,e){this.F=a,this.G=t,this.opMulGF=e;let o=a.sqrt_t||a.t,i=a.sqrt_s||a.s,n=a.one;for(;a.eq(a.pow(n,a.half),a.one);)n=a.add(n,a.one);this.w=new Array(i+1),this.wi=new Array(i+1),this.w[i]=this.F.pow(n,o),this.wi[i]=this.F.inv(this.w[i]);let l=i-1;for(;l>=0;)this.w[l]=this.F.square(this.w[l+1]),this.wi[l]=this.F.square(this.wi[l+1]),l--;this.roots=[],this._setRoots(Math.min(i,15))}_setRoots(t){for(let a=t;a>=0&&!this.roots[a];a--){let t=this.F.one;const e=1<>1,c=ds(t,a,e-1,o,2*i),s=ds(t,a,e-1,o+i,2*i),r=new Array(n);for(let a=0;a>this.one,this.bitLength=Tc(this.p),this.mask=(this.one<>this.one;this.nqr=this.two;let e=this.pow(this.nqr,a);for(;!this.eq(e,this.negone);)this.nqr=this.nqr+this.one,e=this.pow(this.nqr,a);for(this.s=0,this.t=this.negone;(this.t&this.one)==this.zero;)this.s=this.s+1,this.t=this.t>>this.one;this.nqr_to_t=this.pow(this.nqr,this.t),es(this),this.FFT=new ss(this,this,this.mul.bind(this)),this.fft=this.FFT.fft.bind(this.FFT),this.ifft=this.FFT.ifft.bind(this.FFT),this.w=this.FFT.w,this.wi=this.FFT.wi,this.shift=this.square(this.nqr),this.k=this.exp(this.nqr,2**this.s)}e(t,a){let e;if(a?16==a&&(e=BigInt("0x"+t)):e=BigInt(t),e<0){let t=-e;return t>=this.p&&(t%=this.p),this.p-t}return e>=this.p?e%this.p:e}add(t,a){const e=t+a;return e>=this.p?e-this.p:e}sub(t,a){return t>=a?t-a:this.p-a+t}neg(t){return t?this.p-t:t}mul(t,a){return t*a%this.p}mulScalar(t,a){return t*this.e(a)%this.p}square(t){return t*t%this.p}eq(t,a){return t==a}neq(t,a){return t!=a}lt(t,a){return(t>this.half?t-this.p:t)<(a>this.half?a-this.p:a)}gt(t,a){return(t>this.half?t-this.p:t)>(a>this.half?a-this.p:a)}leq(t,a){return(t>this.half?t-this.p:t)<=(a>this.half?a-this.p:a)}geq(t,a){return(t>this.half?t-this.p:t)>=(a>this.half?a-this.p:a)}div(t,a){return this.mul(t,this.inv(a))}idiv(t,a){if(!a)throw new Error("Division by zero");return t/a}inv(t){if(!t)throw new Error("Division by zero");let a=this.zero,e=this.p,o=this.one,i=t%this.p;for(;i;){let t=e/i;[a,o]=[o,a-t*o],[e,i]=[i,e-t*i]}return a=this.p?e-this.p:e}bor(t,a){const e=(t|a)&this.mask;return e>=this.p?e-this.p:e}bxor(t,a){const e=(t^a)&this.mask;return e>=this.p?e-this.p:e}bnot(t){const a=t^this.mask;return a>=this.p?a-this.p:a}shl(t,a){if(Number(a)=this.p?e-this.p:e}{const e=this.p-a;return Number(e)>e:this.zero}}shr(t,a){if(Number(a)>a;{const e=this.p-a;if(Number(e)=this.p?a-this.p:a}return 0}}land(t,a){return t&&a?this.one:this.zero}lor(t,a){return t||a?this.one:this.zero}lnot(t){return t?this.zero:this.one}sqrt_old(t){if(t==this.zero)return this.zero;if(this.pow(t,this.negone>>this.one)!=this.one)return null;let a=this.s,e=this.nqr_to_t,o=this.pow(t,this.t),i=this.pow(t,this.add(this.t,this.one)>>this.one);for(;o!=this.one;){let t=this.square(o),n=1;for(;t!=this.one;)n++,t=this.square(t);let l=e;for(let t=0;tthis.p>>this.one&&(i=this.neg(i)),i}normalize(t,a){if((t=BigInt(t,a))<0){let a=-t;return a>=this.p&&(a%=this.p),this.p-a}return t>=this.p?t%this.p:t}random(){const t=2*this.bitLength/8;let a=this.zero;for(let e=0;ethis.half&&10==a){e="-"+(this.p-t).toString(a)}else e=t.toString(a);return e}isZero(t){return t==this.zero}fromRng(t){let a;do{a=this.zero;for(let e=0;e=this.p);return a=a*this.Ri%this.p,a}fft(t){return this.FFT.fft(t)}ifft(t){return this.FFT.ifft(t)}toRprLE(t,a,e){Zc(t,a,e,8*this.n64)}toRprBE(t,a,e){!function(t,a,e,o){const i="0000000"+e.toString(16),n=new DataView(t.buffer,t.byteOffset+a,o),l=1+(4*(i.length-7)-1>>5);for(let t=0;t>=1;return e}function fs(t,a){return(_s[t>>>24]|_s[t>>>16&255]<<8|_s[t>>>8&255]<<16|_s[255&t]<<24)>>>32-a}function hs(t){return(0!=(4294901760&t)?(t&=4294901760,16):0)|(0!=(4278255360&t)?(t&=4278255360,8):0)|(0!=(4042322160&t)?(t&=4042322160,4):0)|(0!=(3435973836&t)?(t&=3435973836,2):0)|0!=(2863311530&t)}function ps(t,a){const e=new Uint8Array(a*t.length);for(let o=0;o0;){const t=l+c>Ls?Ls-l:c,a=new Uint8Array(this.buffers[n].buffer,this.buffers[n].byteOffset+l,t);if(t==e)return a.slice();i||(i=e<=Ls?new Uint8Array(e):new bs(e)),i.set(a,e-c),c-=t,n++,l=0}return i}set(t,a){void 0===a&&(a=0);const e=t.byteLength;if(0==e)return;const o=Math.floor(a/Ls);if(o==Math.floor((a+e-1)/Ls))return t instanceof bs&&1==t.buffers.length?this.buffers[o].set(t.buffers[0],a%Ls):this.buffers[o].set(t,a%Ls);let i=o,n=a%Ls,l=e;for(;l>0;){const a=n+l>Ls?Ls-n:l,o=t.slice(e-l,e-l+a);new Uint8Array(this.buffers[i].buffer,this.buffers[i].byteOffset+n,a).set(o),l-=a,i++,n=0}}}function ws(t,a,e,o){return async function(i){const n=Math.floor(i.byteLength/e);if(n*e!==i.byteLength)throw new Error("Invalid buffer size");const l=Math.floor(n/t.concurrency),c=[];for(let s=0;s=0;t--)this.w[t]=this.square(this.w[t+1]);if(!this.eq(this.w[0],this.one))throw new Error("Error calculating roots of unity");this.batchToMontgomery=ws(t,a+"_batchToMontgomery",this.n8,this.n8),this.batchFromMontgomery=ws(t,a+"_batchFromMontgomery",this.n8,this.n8)}op2(t,a,e){return this.tm.setBuff(this.pOp1,a),this.tm.setBuff(this.pOp2,e),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op2Bool(t,a,e){return this.tm.setBuff(this.pOp1,a),this.tm.setBuff(this.pOp2,e),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2)}op1(t,a){return this.tm.setBuff(this.pOp1,a),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op1Bool(t,a){return this.tm.setBuff(this.pOp1,a),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3)}add(t,a){return this.op2("_add",t,a)}eq(t,a){return this.op2Bool("_eq",t,a)}isZero(t){return this.op1Bool("_isZero",t)}sub(t,a){return this.op2("_sub",t,a)}neg(t){return this.op1("_neg",t)}inv(t){return this.op1("_inverse",t)}toMontgomery(t){return this.op1("_toMontgomery",t)}fromMontgomery(t){return this.op1("_fromMontgomery",t)}mul(t,a){return this.op2("_mul",t,a)}div(t,a){return this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,a),this.tm.instance.exports[this.prefix+"_inverse"](this.pOp2,this.pOp2),this.tm.instance.exports[this.prefix+"_mul"](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}square(t){return this.op1("_square",t)}isSquare(t){return this.op1Bool("_isSquare",t)}sqrt(t){return this.op1("_sqrt",t)}exp(t,a){return a instanceof Uint8Array||(a=Jc(zc(a))),this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,a),this.tm.instance.exports[this.prefix+"_exp"](this.pOp1,this.pOp2,a.byteLength,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}isNegative(t){return this.op1Bool("_isNegative",t)}e(t,a){if(t instanceof Uint8Array)return t;let e=zc(t,a);!function(t){return BigInt(t)>=BigInt(32)):n+2<=a?(i.setUint16(n,Number(e&BigInt(65535)),!0),n+=2,e>>=BigInt(16)):(i.setUint8(n,Number(e&BigInt(255)),!0),n+=1,e>>=BigInt(8));if(e)throw new Error("Number does not fit in this length");return o}(e,this.n8);return this.toMontgomery(o)}toString(t,a){return Yc(Wc(this.fromMontgomery(t),0),a)}fromRng(t){let a;const e=new Uint8Array(this.n8);do{a=Xc;for(let e=0;e=BigInt(i));var o,i;return Zc(e,0,a,this.n8),e}random(){return this.fromRng(cs())}toObject(t){return Wc(this.fromMontgomery(t),0)}fromObject(t){const a=new Uint8Array(this.n8);return Zc(a,0,t,this.n8),this.toMontgomery(a)}toRprLE(t,a,e){t.set(this.fromMontgomery(e),a)}toRprBE(t,a,e){const o=this.fromMontgomery(e);for(let t=0;to.buffer.byteLength){const i=o.buffer.byteLength/65536;let n=Math.floor((e[0]+t)/65536)+1;n>a&&(n=a),o.grow(n-i)}return i}function l(t){const a=n(t.byteLength);return s(a,t),a}function c(t,a){const e=new Uint8Array(o.buffer);return new Uint8Array(e.buffer,e.byteOffset+t,a)}function s(t,a){new Uint8Array(o.buffer).set(new Uint8Array(a),t)}function r(t){if("INIT"==t[0].cmd)return i(t[0]);const a={vars:[],out:[]},r=new Uint32Array(o.buffer,0,1)[0];for(let o=0;o{this.reject=a,this.resolve=t}))}}const Es=function(t){return globalThis.btoa(t)}("("+xs.toString()+")(self)"),vs="data:application/javascript;base64,"+Es;class Ss{constructor(){this.actionQueue=[],this.oldPFree=0}startSyncOp(){if(0!=this.oldPFree)throw new Error("Sync operation in progress");this.oldPFree=this.u32[0]}endSyncOp(){if(0==this.oldPFree)throw new Error("No sync operation in progress");this.u32[0]=this.oldPFree,this.oldPFree=0}postAction(t,a,e,o){if(this.working[t])throw new Error("Posting a job t a working worker");return this.working[t]=!0,this.pendingDeferreds[t]=o||new Bs,this.workers[t].postMessage(a,e),this.pendingDeferreds[t].promise}processWorks(){for(let t=0;t0;t++)if(0==this.working[t]){const a=this.actionQueue.shift();this.postAction(t,a.data,a.transfers,a.deferred)}}queueAction(t,a){const e=new Bs;if(this.singleThread){const a=this.taskManager(t);e.resolve(a)}else this.actionQueue.push({data:t,transfers:a,deferred:e}),this.processWorks();return e.promise}resetMemory(){this.u32[0]=this.initalPFree}allocBuff(t){const a=this.alloc(t.byteLength);return this.setBuff(a,t),a}getBuff(t,a){return this.u8.slice(t,t+a)}setBuff(t,a){this.u8.set(new Uint8Array(a),t)}alloc(t){for(;3&this.u32[0];)this.u32[0]++;const a=this.u32[0];return this.u32[0]+=t,a}async terminate(){for(let t=0;tsetTimeout(a,t))))}}function Ps(t,a){const e=t[a],o=t.Fr,i=t.tm;t[a].batchApplyKey=async function(t,n,l,c,s){let r,d,u,_,g;if(c=c||"affine",s=s||"affine","G1"==a)"jacobian"==c?(u=3*e.F.n8,r="g1m_batchApplyKey"):(u=2*e.F.n8,r="g1m_batchApplyKeyMixed"),_=3*e.F.n8,"jacobian"==s?g=3*e.F.n8:(d="g1m_batchToAffine",g=2*e.F.n8);else if("G2"==a)"jacobian"==c?(u=3*e.F.n8,r="g2m_batchApplyKey"):(u=2*e.F.n8,r="g2m_batchApplyKeyMixed"),_=3*e.F.n8,"jacobian"==s?g=3*e.F.n8:(d="g2m_batchToAffine",g=2*e.F.n8);else{if("Fr"!=a)throw new Error("Invalid group: "+a);r="frm_batchApplyKey",u=e.n8,_=e.n8,g=e.n8}const f=Math.floor(t.byteLength/u),h=Math.floor(f/i.concurrency),p=[];l=o.e(l);let m=o.e(n);for(let a=0;a=0;t--){if(!e.isZero(h))for(let t=0;tr&&(h=r),h<1024&&(h=1024);const p=[];for(let a=0;a(c&&c.debug(`Multiexp end: ${s}: ${a}/${u}`),t))))}const m=await Promise.all(p);let L=e.zero;for(let t=m.length-1;t>=0;t--)L=e.add(L,m[t]);return L}e.multiExp=async function(t,a,e,o){return await n(t,a,"jacobian",e,o)},e.multiExpAffine=async function(t,a,e,o){return await n(t,a,"affine",e,o)}}function Gs(t,a){const e=t[a],o=t.Fr,i=e.tm;async function n(t,c,s,r,d,u){s=s||"affine",r=r||"affine";let _,g,f,h,p,m,L,b;"G1"==a?("affine"==s?(_=2*e.F.n8,h="g1m_batchToJacobian"):_=3*e.F.n8,g=3*e.F.n8,c&&(b="g1m_fftFinal"),L="g1m_fftJoin",m="g1m_fftMix","affine"==r?(f=2*e.F.n8,p="g1m_batchToAffine"):f=3*e.F.n8):"G2"==a?("affine"==s?(_=2*e.F.n8,h="g2m_batchToJacobian"):_=3*e.F.n8,g=3*e.F.n8,c&&(b="g2m_fftFinal"),L="g2m_fftJoin",m="g2m_fftMix","affine"==r?(f=2*e.F.n8,p="g2m_batchToAffine"):f=3*e.F.n8):"Fr"==a&&(_=e.n8,g=e.n8,f=e.n8,c&&(b="frm_fftFinal"),m="frm_fftMix",L="frm_fftJoin");let w=!1;Array.isArray(t)?(t=ps(t,_),w=!0):t=t.slice(0,t.byteLength);const y=t.byteLength/_,A=hs(y);if(1<1<<28?new bs(2*u[0].byteLength):new Uint8Array(2*u[0].byteLength);return _.set(u[0]),_.set(u[1],u[0].byteLength),_}(t,s,r,d,u):await async function(t,a,e,i,c){let s,r;s=t.slice(0,t.byteLength/2),r=t.slice(t.byteLength/2,t.byteLength);const d=[];[s,r]=await l(s,r,"fftJoinExt",o.one,o.shift,a,"jacobian",i,c),d.push(n(s,!1,"jacobian",e,i,c)),d.push(n(r,!1,"jacobian",e,i,c));const u=await Promise.all(d);let _;_=u[0].byteLength>1<<28?new bs(2*u[0].byteLength):new Uint8Array(2*u[0].byteLength);return _.set(u[0]),_.set(u[1],u[0].byteLength),_}(t,s,r,d,u),w?ms(a,f):a}let C,F,x;c&&(C=o.inv(o.e(y))),function(t,a){const e=t.byteLength/a,o=hs(e);if(e!=1<e){const o=t.slice(i*a,(i+1)*a);t.set(t.slice(e*a,(e+1)*a),i*a),t.set(o,e*a)}}}(t,_);let I=Math.min(16384,y),B=y/I;for(;B=16;)B*=2,I/=2;const E=hs(I),v=[];for(let a=0;a(d&&d.debug(`${u}: fft ${A} mix end: ${a}/${B}`),t))))}x=await Promise.all(v);for(let t=0;t(d&&d.debug(`${u}: fft ${A} join ${t}/${A} ${l+1}/${a} ${c}/${e/2}`),o))))}const l=await Promise.all(n);for(let t=0;t0;a--)F.set(x[a],t),t+=I*f,delete x[a];F.set(x[0].slice(0,(I-1)*f),t),delete x[0]}else for(let t=0;t65536&&(w=65536);const y=[];for(let a=0;a(u&&u.debug(`${_}: fftJoinExt End: ${a}/${b}`),t))))}const A=await Promise.all(y);let C,F;b*p>1<<28?(C=new bs(b*p),F=new bs(b*p)):(C=new Uint8Array(b*p),F=new Uint8Array(b*p));let x=0;for(let t=0;to.s+1)throw s&&s.error("lagrangeEvaluations input too big"),new Error("lagrangeEvaluations input too big");let g=t.slice(0,t.byteLength/2),f=t.slice(t.byteLength/2,t.byteLength);const h=o.exp(o.shift,u/2),p=o.inv(o.sub(o.one,h));[g,f]=await l(g,f,"prepareLagrangeEvaluation",p,o.shiftInv,i,"jacobian",s,r+" prep");const m=[];let L;return m.push(n(g,!0,"jacobian",c,s,r+" t0")),m.push(n(f,!0,"jacobian",c,s,r+" t1")),[g,f]=await Promise.all(m),L=g.byteLength>1<<28?new bs(2*g.byteLength):new Uint8Array(2*g.byteLength),L.set(g),L.set(f,g.byteLength),L},e.fftMix=async function(t){const n=3*e.F.n8;let l,c;if("G1"==a)l="g1m_fftMix",c="g1m_fftJoin";else if("G2"==a)l="g2m_fftMix",c="g2m_fftJoin";else{if("Fr"!=a)throw new Error("Invalid group");l="frm_fftMix",c="frm_fftJoin"}const s=Math.floor(t.byteLength/n),r=hs(s);let d=1<=0;t--)g.set(_[t][0],f),f+=_[t][0].byteLength;return g}}async function zs(t){const a=await async function(t,a){const e=new Ss;e.memory=new WebAssembly.Memory({initial:Is}),e.u8=new Uint8Array(e.memory.buffer),e.u32=new Uint32Array(e.memory.buffer);const o=await WebAssembly.compile(t.code);if(e.instance=await WebAssembly.instantiate(o,{env:{memory:e.memory}}),e.singleThread=a,e.initalPFree=e.u32[0],e.pq=t.pq,e.pr=t.pr,e.pG1gen=t.pG1gen,e.pG1zero=t.pG1zero,e.pG2gen=t.pG2gen,e.pG2zero=t.pG2zero,e.pOneT=t.pOneT,a)e.code=t.code,e.taskManager=xs(),await e.taskManager([{cmd:"INIT",init:Is,code:e.code.slice()}]),e.concurrency=1;else{let a;e.workers=[],e.pendingDeferreds=[],e.working=[],a="object"==typeof navigator&&navigator.hardwareConcurrency?navigator.hardwareConcurrency:kl.cpus().length,0==a&&(a=2),a>64&&(a=64),e.concurrency=a;for(let t=0;t=this.length&&(this.length=t+1),!0}getKeys(){const t=new Ns;for(let a=0;a1<<20?new Ns:[];for(let t=0;t1<<20?new Ns:[];for(let t=0;t1<<20?new Ns:[];for(let t=0;t{let o="";return Object.keys(e).forEach((i=>{let n=a.varIdx2Name[i];"one"==n&&(n="1");let l=t.curve.Fr.toString(e[i]);"1"==l&&(l=""),"-1"==l&&(l="-"),""!=o&&"-"!=l[0]&&(l="+"+l),""!=o&&(l=" "+l),o=o+l+n})),o},n=`[ ${i(o[0])} ] * [ ${i(o[1])} ] - [ ${i(o[2])} ] = 0`;e&&e.info(n)}},info:async function(t,a){const e=await Ks(t);return _e.eq(e.prime,Zs)?a&&a.info("Curve: bn-128"):_e.eq(e.prime,Hs)?a&&a.info("Curve: bls12-381"):a&&a.info(`Unknown Curve. Prime: ${_e.toString(e.prime)}`),a&&a.info(`# of Wires: ${e.nVars}`),a&&a.info(`# of Constraints: ${e.nConstraints}`),a&&a.info(`# of Private Inputs: ${e.nPrvInputs}`),a&&a.info(`# of Public Inputs: ${e.nPubInputs}`),a&&a.info(`# of Labels: ${e.nLabels}`),a&&a.info(`# of Outputs: ${e.nOutputs}`),e},exportJson:async function(t,a){const e=await Ks(t,!0,!0,!0,a),o=e.curve.Fr;return delete e.curve,delete e.F,Ho(o,e)}});async function Ys(t){const a={labelIdx2Name:["one"],varIdx2Name:["one"],componentIdx2Name:[]},e=await ze(t),o=await e.read(e.totalSize),i=new TextDecoder("utf-8").decode(o).split("\n");for(let t=0;t Reading r1cs file");const{fd:o,sections:i}=await Te(t,"r1cs",1),n=await Vs(o,i,{loadConstraints:!1,loadCustomGates:!1});e&&e.info("> Reading witness file");const{fd:l,sections:c}=await Te(a,"wtns",2),s=await Ii(l,c);if(!_e.eq(n.prime,s.q))throw new Error("Curve of the witness does not match the curve of the proving key");const r=await je(l,c,2);await l.close();const d=(await async function(t){let a;if(_e.eq(t,He))a=await de();else{if(!_e.eq(t,Ke))throw new Error(`Curve not supported: ${_e.toString(t)}`);a=await ue()}return a}(n.prime)).Fr,u=d.n8,_=await je(o,i,2);e&&(e.info("----------------------------"),e.info(" WITNESS CHECK"),e.info(` Curve: ${n.curve.name}`),e.info(` Vars (wires): ${n.nVars}`),e.info(` Ouputs: ${n.nOutputs}`),e.info(` Public Inputs: ${n.nPubInputs}`),e.info(` Private Inputs: ${n.nPrvInputs}`),e.info(` Labels: ${n.nLabels}`),e.info(` Constraints: ${n.nConstraints}`),e.info(` Custom Gates: ${n.useCustomGates}`),e.info("----------------------------")),e&&e.info("> Checking witness correctness");let g=0,f=!0;for(let t=0;t{const o=function(t){return d.fromRprLE(r.slice(t*u,t*u+u))}(e),i=t[e];a=d.add(a,d.mul(o,i))})),a}function p(){const t={},a=_.slice(g,g+4);g+=4;const e=new DataView(a.buffer).getUint32(0,!0),o=_.slice(g,g+(4+n.n8)*e);g+=(4+n.n8)*e;const i=new DataView(o.buffer);for(let a=0;a=this.length&&(this.length=t+1),!0}getKeys(){const t=new or;for(let a=0;as)return o&&o.error(`circuit too big for this power of tau ceremony. ${u.nConstraints}*2 > 2**${s}`),-1;if(!l[12])return o&&o.error("Powers of tau is not prepared."),-1;const p=u.nOutputs+u.nPubInputs,m=2**h;await Ue(_,1),await _.writeULE32(1),await Qe(_),await Ue(_,2);const L=c.q,b=8*(Math.floor((_e.bitLength(L)-1)/64)+1),w=c.r,y=8*(Math.floor((_e.bitLength(w)-1)/64)+1),A=_e.mod(_e.shl(1,8*y),w),C=c.Fr.e(_e.mod(_e.mul(A,A),w));let F,x,I;await _.writeULE32(b),await Ne(_,L,b),await _.writeULE32(y),await Ne(_,w,y),await _.writeULE32(u.nVars),await _.writeULE32(p),await _.writeULE32(m),F=await n.read(g,l[4][0].p),await _.write(F),F=await c.G1.batchLEMtoU(F),i.update(F),x=await n.read(g,l[5][0].p),await _.write(x),x=await c.G1.batchLEMtoU(x),i.update(x),I=await n.read(f,l[6][0].p),await _.write(I),I=await c.G2.batchLEMtoU(I),i.update(I);const B=new Uint8Array(g);c.G1.toRprLEM(B,0,c.G1.g);const E=new Uint8Array(f);c.G2.toRprLEM(E,0,c.G2.g);const v=new Uint8Array(g);c.G1.toRprUncompressed(v,0,c.G1.g);const S=new Uint8Array(f);c.G2.toRprUncompressed(S,0,c.G2.g),await _.write(E),await _.write(B),await _.write(E),i.update(S),i.update(v),i.update(S),await Qe(_),o&&o.info("Reading r1cs");let P=await je(r,d,2);const q=new or(u.nVars),O=new or(u.nVars),G=new or(u.nVars),z=new or(u.nVars-p-1),T=new Array(p+1);o&&o.info("Reading tauG1");let M=await je(n,l,12,(m-1)*g,m*g);o&&o.info("Reading tauG2");let U=await je(n,l,13,(m-1)*f,m*f);o&&o.info("Reading alphatauG1");let Q=await je(n,l,14,(m-1)*g,m*g);o&&o.info("Reading betatauG1");let k=await je(n,l,15,(m-1)*g,m*g);await async function(){const t=new Uint8Array(12+c.Fr.n8),a=new DataView(t.buffer),e=new Uint8Array(c.Fr.n8);c.Fr.toRprLE(e,0,c.Fr.e(1));let i=0;function n(){const t=P.slice(i,i+4);i+=4;return new DataView(t.buffer).getUint32(0,!0)}const l=new or;for(let t=0;t=0?c.Fr.fromRprLE(P.slice(o[3],o[3]+c.Fr.n8),0):c.Fr.fromRprLE(e,0);const n=c.Fr.mul(i,C);c.Fr.toRprLE(t,12,n),s.set(t,d),d+=t.length}await _.write(s),await Qe(_)}(),await N(3,"G1",T,"IC"),await async function(){await Ue(_,9);const t=new Pa(m*g);if(h(o&&o.debug(`Writing points end ${n}: ${d}/${e.length}`),t)))),r+=i,t++}const d=await Promise.all(s);for(let t=0;t32768?(g=new Pa(h*n),f=new Pa(h*c.Fr.n8)):(g=new Uint8Array(h*n),f=new Uint8Array(h*c.Fr.n8));let p=0,m=0;const L=[M,U,Q,k],b=new Uint8Array(c.Fr.n8);c.Fr.toRprLE(b,0,c.Fr.e(1));let w=0;for(let t=0;t=0?f.set(P.slice(a[t][i][2],a[t][i][2]+c.Fr.n8),w*c.Fr.n8):f.set(b,w*c.Fr.n8),w++;if(a.length>1){const t=[];t.push({cmd:"ALLOCSET",var:0,buff:g}),t.push({cmd:"ALLOCSET",var:1,buff:f}),t.push({cmd:"ALLOC",var:2,len:a.length*l}),p=0,m=0;let e=0;for(let o=0;o=0;t--){const a=d.contributions[t];o&&o.info("-------------------------"),o&&o.info(Mo(a.contributionHash,`contribution #${t+1} ${a.name?a.name:""}:`)),1==a.type&&(o&&o.info(`Beacon generator: ${Ko(a.beaconHash)}`),o&&o.info(`Beacon iterations Exp: ${a.numIterationsExp}`))}return o&&o.info("-------------------------"),o&&o.info("ZKey Ok!"),!0;async function L(t,a){const e=2*s.G1.F.n8,o=t.byteLength/e,i=s.tm.concurrency,n=Math.floor(o/i),l=[];for(let e=0;e Detected protocol: "+i.protocol),"groth16"===i.protocol)n=await async function(t,a,e){const o=await Ye(t.q),i=2*o.G1.F.n8,n=await o.pairing(t.vk_alpha_1,t.vk_beta_2);let l={protocol:t.protocol,curve:o.name,nPublic:t.nPublic,vk_alpha_1:o.G1.toObject(t.vk_alpha_1),vk_beta_2:o.G2.toObject(t.vk_beta_2),vk_gamma_2:o.G2.toObject(t.vk_gamma_2),vk_delta_2:o.G2.toObject(t.vk_delta_2),vk_alphabeta_12:o.Gt.toObject(n)};await ke(a,e,3),l.IC=[];for(let e=0;e<=t.nPublic;e++){const t=await a.read(i),e=o.G1.toObject(t);l.IC.push(e)}return await Re(a),l=cr(l),l}(i,e,o);else if("plonk"===i.protocol)n=await async function(t){const a=await Ye(t.q);let e={protocol:t.protocol,curve:a.name,nPublic:t.nPublic,power:t.power,k1:a.Fr.toObject(t.k1),k2:a.Fr.toObject(t.k2),Qm:a.G1.toObject(t.Qm),Ql:a.G1.toObject(t.Ql),Qr:a.G1.toObject(t.Qr),Qo:a.G1.toObject(t.Qo),Qc:a.G1.toObject(t.Qc),S1:a.G1.toObject(t.S1),S2:a.G1.toObject(t.S2),S3:a.G1.toObject(t.S3),X_2:a.G2.toObject(t.X_2),w:a.Fr.toObject(a.Fr.w[t.power])};return e=cr(e),e}(i);else{if(!i.protocolId||i.protocolId!==Yo)throw new Error("zkey file protocol unrecognized");n=await async function(t,a){const e=await Ye(t.q);let o={protocol:t.protocol,curve:e.name,nPublic:t.nPublic,power:t.power,k1:e.Fr.toObject(t.k1),k2:e.Fr.toObject(t.k2),w:e.Fr.toObject(e.Fr.w[t.power]),w3:e.Fr.toObject(t.w3),w4:e.Fr.toObject(t.w4),w8:e.Fr.toObject(t.w8),wr:e.Fr.toObject(t.wr),X_2:e.G2.toObject(t.X_2),C0:e.G1.toObject(t.C0)};return cr(o)}(i)}return await e.close(),a&&a.info("EXPORT VERIFICATION KEY FINISHED"),n}var rr={};const{unstringifyBigInts:dr,stringifyBigInts:ur}=ge;async function _r(t,a,e){e&&e.info("FFLONK EXPORT SOLIDITY VERIFIER STARTED");const o=await Je(t.curve);let i=r(t.w3);t.w3_2=d(o.Fr.square(i));let n=r(t.w4);t.w4_2=d(o.Fr.square(n)),t.w4_3=d(o.Fr.mul(o.Fr.square(n),n));let l=r(t.w8),c=o.Fr.one;for(let a=1;a<8;a++)c=o.Fr.mul(c,l),t["w8_"+a]=d(c);let s=a[t.protocol];return e&&e.info("FFLONK EXPORT SOLIDITY VERIFIER FINISHED"),rr.render(s,t);function r(t){const a=dr(t);return o.Fr.fromObject(a)}function d(t){const a=o.Fr.toObject(t);return ur(a)}}var gr=Object.freeze({__proto__:null,newZKey:ir,exportBellman:async function(t,a,e){const{fd:o,sections:i}=await Te(t,"zkey",2),n=await bi(o,i);if("groth16"!=n.protocol)throw new Error("zkey file is not groth16");const l=await Ye(n.q),c=2*l.G1.F.n8,s=2*l.G2.F.n8,r=await yi(o,l,i),d=await Ge(a);let u;await L(n.vk_alpha_1),await L(n.vk_beta_1),await b(n.vk_beta_2),await b(n.vk_gamma_2),await L(n.vk_delta_1),await b(n.vk_delta_2),u=await je(o,i,3),u=await l.G1.batchLEMtoU(u),await w("G1",u);const _=await je(o,i,9);let g,f,h,p,m;g=await l.G1.fft(_,"affine","jacobian",e),g=await l.G1.batchApplyKey(g,l.Fr.neg(l.Fr.e(2)),l.Fr.w[n.power+1],"jacobian","affine",e),g=g.slice(0,g.byteLength-c),g=await l.G1.batchLEMtoU(g),await w("G1",g),f=await je(o,i,8),f=await l.G1.batchLEMtoU(f),await w("G1",f),h=await je(o,i,5),h=await l.G1.batchLEMtoU(h),await w("G1",h),p=await je(o,i,6),p=await l.G1.batchLEMtoU(p),await w("G1",p),m=await je(o,i,7),m=await l.G2.batchLEMtoU(m),await w("G2",m),await d.write(r.csHash),await async function(t){const a=new Uint8Array(4);new DataView(a.buffer,a.byteOffset,a.byteLength).setUint32(0,t,!1),await d.write(a)}(r.contributions.length);for(let t=0;t_.contributions.length)return i&&i.error("The impoerted file does not include new contributions"),!1;for(let t=0;t=256)return n&&n.error("Maximum lenght of beacon hash is 255 bytes"),!1;if((i=parseInt(i))<10||i>63)return n&&n.error("Invalid numIterationsExp. (Must be between 10 and 63)"),!1;const{fd:c,sections:s}=await Te(t,"zkey",2),r=await bi(c,s);if("groth16"!=r.protocol)throw new Error("zkey file is not groth16");const d=await Ye(r.q),u=await yi(c,d,s),_=await Me(a,"zkey",1,10),g=await jo(l,i),f=to.exports(64);f.update(u.csHash);for(let t=0;t{const o=this.curve.G1.toObject(this.polynomials[e]);t?a.polynomials[e]=o:a[e]=o})),Object.keys(this.evaluations).forEach((e=>{const o=this.curve.Fr.toObject(this.evaluations[e]);t?a.evaluations[e]=o:a[e]=o})),a}fromObjectProof(t){this.resetProof(),Object.keys(t.polynomials).forEach((a=>{this.polynomials[a]=this.curve.G1.fromObject(t.polynomials[a])})),Object.keys(t.evaluations).forEach((a=>{this.evaluations[a]=this.curve.Fr.fromObject(t.evaluations[a])}))}}var hr,pr={exports:{}}; +var snarkjs=function(t){"use strict";const a=[0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4];function e(t,a){return a&&10!=a?16==a?"0x"==t.slice(0,2)?BigInt(t):BigInt("0x"+t):void 0:BigInt(t)}const o=e;function i(t){const e=t.toString(16);return 4*(e.length-1)+a[parseInt(e[0],16)]}function n(t){return BigInt(t)>BigInt(a)}const r=c,d=s;function u(t){return(BigInt(t)&BigInt(1))==BigInt(1)}function _(t){let a=BigInt(t);const e=[];for(;a;)a&BigInt(1)?e.push(1):e.push(0),a>>=BigInt(1);return e}function g(t){if(t>BigInt(Number.MAX_SAFE_INTEGER))throw new Error("Number too big");return Number(t)}function f(t,a){return BigInt(t)+BigInt(a)}function h(t,a){return BigInt(t)-BigInt(a)}function p(t){return-BigInt(t)}function m(t,a){return BigInt(t)*BigInt(a)}function L(t,a){return BigInt(t)**BigInt(a)}function b(t,a){return BigInt(t)/BigInt(a)}function w(t,a){return BigInt(t)%BigInt(a)}function y(t,a){return BigInt(t)==BigInt(a)}function A(t,a){return BigInt(t)>BigInt(a)}function C(t,a){return BigInt(t)>=BigInt(a)}function F(t,a){return BigInt(t)&BigInt(a)}function x(t,a,e,o){const i="0000000"+e.toString(16),n=new Uint32Array(t.buffer,t.byteOffset+a,o/4),l=1+(4*(i.length-7)-1>>5);for(let t=0;t>5);for(let t=0;tn[n.length-a-1]=t.toString(16).padStart(8,"0"))),e(n.join(""),16)}function E(t,a,o){o=o||t.byteLength,a=a||0;const i=new DataView(t.buffer,t.byteOffset+a,o),n=new Array(o/4);for(let t=0;t=0?BigInt(t):-BigInt(t)},add:f,band:F,bitLength:i,bits:_,bor:function(t,a){return BigInt(t)|BigInt(a)},bxor:function(t,a){return BigInt(t)^BigInt(a)},div:b,e:o,eq:y,exp:function(t,a){return BigInt(t)**BigInt(a)},fromArray:function(t,a){let e=BigInt(0);a=BigInt(a);for(let o=0;o>=BigInt(1)}return e},neg:p,neq:function(t,a){return BigInt(t)!=BigInt(a)},one:q,pow:L,shiftLeft:c,shiftRight:s,shl:r,shr:d,square:function(t){return BigInt(t)*BigInt(t)},sub:h,toArray:function(t,a){const e=[];let o=BigInt(t);for(a=BigInt(a);o;)e.unshift(Number(o%a)),o/=a;return e},toLEBuff:S,toNumber:g,toRprBE:I,toRprLE:x,toString:v,zero:P});function G(t,a,e){if(l(e))return t.one;const o=_(e);if(0==o.length)return t.one;let i=a;for(let e=o.length-2;e>=0;e--)i=t.square(i),o[e]&&(i=t.mul(i,a));return i}function z(t){if(t.m%2==1)if(y(w(t.p,4),1))if(y(w(t.p,8),1))if(y(w(t.p,16),1))!function(t){t.sqrt_q=L(t.p,t.m),t.sqrt_s=0,t.sqrt_t=h(t.sqrt_q,1);for(;!u(t.sqrt_t);)t.sqrt_s=t.sqrt_s+1,t.sqrt_t=b(t.sqrt_t,2);let a=t.one;for(;t.eq(a,t.one);){const e=t.random();t.sqrt_z=t.pow(e,t.sqrt_t),a=t.pow(t.sqrt_z,2**(t.sqrt_s-1))}t.sqrt_tm1d2=b(h(t.sqrt_t,1),2),t.sqrt=function(t){const a=this;if(a.isZero(t))return a.zero;let e=a.pow(t,a.sqrt_tm1d2);const o=a.pow(a.mul(a.square(e),t),2**(a.sqrt_s-1));if(a.eq(o,a.negone))return null;let i=a.sqrt_s,n=a.mul(t,e),l=a.mul(n,e),c=a.sqrt_z;for(;!a.eq(l,a.one);){let t=a.square(l),o=1;for(;!a.eq(t,a.one);)t=a.square(t),o++;e=c;for(let t=0;t>>0,t[i]=(t[i]^t[a])>>>0,t[i]=(t[i]<<16|t[i]>>>16&65535)>>>0,t[o]=t[o]+t[i]>>>0,t[e]=(t[e]^t[o])>>>0,t[e]=(t[e]<<12|t[e]>>>20&4095)>>>0,t[a]=t[a]+t[e]>>>0,t[i]=(t[i]^t[a])>>>0,t[i]=(t[i]<<8|t[i]>>>24&255)>>>0,t[o]=t[o]+t[i]>>>0,t[e]=(t[e]^t[o])>>>0,t[e]=(t[e]<<7|t[e]>>>25&127)>>>0}class M{constructor(t){t=t||[0,0,0,0,0,0,0,0],this.state=[1634760805,857760878,2036477234,1797285236,t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],0,0,0,0],this.idx=16,this.buff=new Array(16)}nextU32(){return 16==this.idx&&this.update(),this.buff[this.idx++]}nextU64(){return f(m(this.nextU32(),4294967296),this.nextU32())}nextBool(){return 1==(1&this.nextU32())}update(){for(let t=0;t<16;t++)this.buff[t]=this.state[t];for(let a=0;a<10;a++)T(t=this.buff,0,4,8,12),T(t,1,5,9,13),T(t,2,6,10,14),T(t,3,7,11,15),T(t,0,5,10,15),T(t,1,6,11,12),T(t,2,7,8,13),T(t,3,4,9,14);var t;for(let t=0;t<16;t++)this.buff[t]=this.buff[t]+this.state[t]>>>0;this.idx=0,this.state[12]=this.state[12]+1>>>0,0==this.state[12]&&(this.state[13]=this.state[13]+1>>>0,0==this.state[13]&&(this.state[14]=this.state[14]+1>>>0,0==this.state[14]&&(this.state[15]=this.state[15]+1>>>0)))}}function U(t){let a=new Uint8Array(t);if(void 0!==globalThis.crypto)globalThis.crypto.getRandomValues(a);else for(let e=0;e>>0;return a}let Q=null;function k(){return Q||(Q=new M(function(){const t=U(32),a=new Uint32Array(t.buffer),e=[];for(let t=0;t<8;t++)e.push(a[t]);return e}()),Q)}class R{constructor(t,a,e){this.F=a,this.G=t,this.opMulGF=e;let o=a.sqrt_t||a.t,i=a.sqrt_s||a.s,n=a.one;for(;a.eq(a.pow(n,a.half),a.one);)n=a.add(n,a.one);this.w=new Array(i+1),this.wi=new Array(i+1),this.w[i]=this.F.pow(n,o),this.wi[i]=this.F.inv(this.w[i]);let l=i-1;for(;l>=0;)this.w[l]=this.F.square(this.w[l+1]),this.wi[l]=this.F.square(this.wi[l+1]),l--;this.roots=[],this._setRoots(Math.min(i,15))}_setRoots(t){for(let a=t;a>=0&&!this.roots[a];a--){let t=this.F.one;const e=1<>1,c=$(t,a,e-1,o,2*i),s=$(t,a,e-1,o+i,2*i),r=new Array(n);for(let a=0;a>this.one,this.bitLength=i(this.p),this.mask=(this.one<>this.one;this.nqr=this.two;let e=this.pow(this.nqr,a);for(;!this.eq(e,this.negone);)this.nqr=this.nqr+this.one,e=this.pow(this.nqr,a);for(this.s=0,this.t=this.negone;(this.t&this.one)==this.zero;)this.s=this.s+1,this.t=this.t>>this.one;this.nqr_to_t=this.pow(this.nqr,this.t),z(this),this.FFT=new R(this,this,this.mul.bind(this)),this.fft=this.FFT.fft.bind(this.FFT),this.ifft=this.FFT.ifft.bind(this.FFT),this.w=this.FFT.w,this.wi=this.FFT.wi,this.shift=this.square(this.nqr),this.k=this.exp(this.nqr,2**this.s)}e(t,a){let e;if(a?16==a&&(e=BigInt("0x"+t)):e=BigInt(t),e<0){let t=-e;return t>=this.p&&(t%=this.p),this.p-t}return e>=this.p?e%this.p:e}add(t,a){const e=t+a;return e>=this.p?e-this.p:e}sub(t,a){return t>=a?t-a:this.p-a+t}neg(t){return t?this.p-t:t}mul(t,a){return t*a%this.p}mulScalar(t,a){return t*this.e(a)%this.p}square(t){return t*t%this.p}eq(t,a){return t==a}neq(t,a){return t!=a}lt(t,a){return(t>this.half?t-this.p:t)<(a>this.half?a-this.p:a)}gt(t,a){return(t>this.half?t-this.p:t)>(a>this.half?a-this.p:a)}leq(t,a){return(t>this.half?t-this.p:t)<=(a>this.half?a-this.p:a)}geq(t,a){return(t>this.half?t-this.p:t)>=(a>this.half?a-this.p:a)}div(t,a){return this.mul(t,this.inv(a))}idiv(t,a){if(!a)throw new Error("Division by zero");return t/a}inv(t){if(!t)throw new Error("Division by zero");let a=this.zero,e=this.p,o=this.one,i=t%this.p;for(;i;){let t=e/i;[a,o]=[o,a-t*o],[e,i]=[i,e-t*i]}return a=this.p?e-this.p:e}bor(t,a){const e=(t|a)&this.mask;return e>=this.p?e-this.p:e}bxor(t,a){const e=(t^a)&this.mask;return e>=this.p?e-this.p:e}bnot(t){const a=t^this.mask;return a>=this.p?a-this.p:a}shl(t,a){if(Number(a)=this.p?e-this.p:e}{const e=this.p-a;return Number(e)>e:this.zero}}shr(t,a){if(Number(a)>a;{const e=this.p-a;if(Number(e)=this.p?a-this.p:a}return 0}}land(t,a){return t&&a?this.one:this.zero}lor(t,a){return t||a?this.one:this.zero}lnot(t){return t?this.zero:this.one}sqrt_old(t){if(t==this.zero)return this.zero;if(this.pow(t,this.negone>>this.one)!=this.one)return null;let a=this.s,e=this.nqr_to_t,o=this.pow(t,this.t),i=this.pow(t,this.add(this.t,this.one)>>this.one);for(;o!=this.one;){let t=this.square(o),n=1;for(;t!=this.one;)n++,t=this.square(t);let l=e;for(let t=0;tthis.p>>this.one&&(i=this.neg(i)),i}normalize(t,a){if((t=BigInt(t,a))<0){let a=-t;return a>=this.p&&(a%=this.p),this.p-a}return t>=this.p?t%this.p:t}random(){const t=2*this.bitLength/8;let a=this.zero;for(let e=0;ethis.half&&10==a){e="-"+(this.p-t).toString(a)}else e=t.toString(a);return e}isZero(t){return t==this.zero}fromRng(t){let a;do{a=this.zero;for(let e=0;e=this.p);return a=a*this.Ri%this.p,a}fft(t){return this.FFT.fft(t)}ifft(t){return this.FFT.ifft(t)}toRprLE(t,a,e){x(t,a,e,8*this.n64)}toRprBE(t,a,e){I(t,a,e,8*this.n64)}toRprBEM(t,a,e){return this.toRprBE(t,a,this.mul(this.R,e))}toRprLEM(t,a,e){return this.toRprLE(t,a,this.mul(this.R,e))}fromRprLE(t,a){return B(t,a,this.n8)}fromRprBE(t,a){return E(t,a,this.n8)}fromRprLEM(t,a){return this.mul(this.fromRprLE(t,a),this.Ri)}fromRprBEM(t,a){return this.mul(this.fromRprBE(t,a),this.Ri)}toObject(t){return t}}function j(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var V={bigInt2BytesLE:function(t,a){const e=Array(a);let o=BigInt(t);for(let t=0;t>=8n;return e},bigInt2U32LE:function(t,a){const e=Array(a);let o=BigInt(t);for(let t=0;t>=32n;return e},isOcamNum:function(t){return!!Array.isArray(t)&&(3==t.length&&("number"==typeof t[0]&&("number"==typeof t[1]&&!!Array.isArray(t[2]))))}},K=function(t,a,e,o,i,n,l){const c=t.addFunction(a);c.addParam("base","i32"),c.addParam("scalar","i32"),c.addParam("scalarLength","i32"),c.addParam("r","i32"),c.addLocal("i","i32"),c.addLocal("b","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(e));c.addCode(s.if(s.i32_eqz(s.getLocal("scalarLength")),[...s.call(l,s.getLocal("r")),...s.ret([])])),c.addCode(s.call(n,s.getLocal("base"),r)),c.addCode(s.call(l,s.getLocal("r"))),c.addCode(s.setLocal("i",s.getLocal("scalarLength"))),c.addCode(s.block(s.loop(s.setLocal("i",s.i32_sub(s.getLocal("i"),s.i32_const(1))),s.setLocal("b",s.i32_load8_u(s.i32_add(s.getLocal("scalar"),s.getLocal("i")))),...function(){const t=[];for(let a=0;a<8;a++)t.push(...s.call(i,s.getLocal("r"),s.getLocal("r")),...s.if(s.i32_ge_u(s.getLocal("b"),s.i32_const(128>>a)),[...s.setLocal("b",s.i32_sub(s.getLocal("b"),s.i32_const(128>>a))),...s.call(o,s.getLocal("r"),r,s.getLocal("r"))]));return t}(),s.br_if(1,s.i32_eqz(s.getLocal("i"))),s.br(0))))},H=function(t,a){const e=8*t.modules[a].n64,o=t.addFunction(a+"_batchInverse");o.addParam("pIn","i32"),o.addParam("inStep","i32"),o.addParam("n","i32"),o.addParam("pOut","i32"),o.addParam("outStep","i32"),o.addLocal("itAux","i32"),o.addLocal("itIn","i32"),o.addLocal("itOut","i32"),o.addLocal("i","i32");const i=o.getCodeBuilder(),n=i.i32_const(t.alloc(e));o.addCode(i.setLocal("itAux",i.i32_load(i.i32_const(0))),i.i32_store(i.i32_const(0),i.i32_add(i.getLocal("itAux"),i.i32_mul(i.i32_add(i.getLocal("n"),i.i32_const(1)),i.i32_const(e))))),o.addCode(i.call(a+"_one",i.getLocal("itAux")),i.setLocal("itIn",i.getLocal("pIn")),i.setLocal("itAux",i.i32_add(i.getLocal("itAux"),i.i32_const(e))),i.setLocal("i",i.i32_const(0)),i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("i"),i.getLocal("n"))),i.if(i.call(a+"_isZero",i.getLocal("itIn")),i.call(a+"_copy",i.i32_sub(i.getLocal("itAux"),i.i32_const(e)),i.getLocal("itAux")),i.call(a+"_mul",i.getLocal("itIn"),i.i32_sub(i.getLocal("itAux"),i.i32_const(e)),i.getLocal("itAux"))),i.setLocal("itIn",i.i32_add(i.getLocal("itIn"),i.getLocal("inStep"))),i.setLocal("itAux",i.i32_add(i.getLocal("itAux"),i.i32_const(e))),i.setLocal("i",i.i32_add(i.getLocal("i"),i.i32_const(1))),i.br(0))),i.setLocal("itIn",i.i32_sub(i.getLocal("itIn"),i.getLocal("inStep"))),i.setLocal("itAux",i.i32_sub(i.getLocal("itAux"),i.i32_const(e))),i.setLocal("itOut",i.i32_add(i.getLocal("pOut"),i.i32_mul(i.i32_sub(i.getLocal("n"),i.i32_const(1)),i.getLocal("outStep")))),i.call(a+"_inverse",i.getLocal("itAux"),i.getLocal("itAux")),i.block(i.loop(i.br_if(1,i.i32_eqz(i.getLocal("i"))),i.if(i.call(a+"_isZero",i.getLocal("itIn")),[...i.call(a+"_copy",i.getLocal("itAux"),i.i32_sub(i.getLocal("itAux"),i.i32_const(e))),...i.call(a+"_zero",i.getLocal("itOut"))],[...i.call(a+"_copy",i.i32_sub(i.getLocal("itAux"),i.i32_const(e)),n),...i.call(a+"_mul",i.getLocal("itAux"),i.getLocal("itIn"),i.i32_sub(i.getLocal("itAux"),i.i32_const(e))),...i.call(a+"_mul",i.getLocal("itAux"),n,i.getLocal("itOut"))]),i.setLocal("itIn",i.i32_sub(i.getLocal("itIn"),i.getLocal("inStep"))),i.setLocal("itOut",i.i32_sub(i.getLocal("itOut"),i.getLocal("outStep"))),i.setLocal("itAux",i.i32_sub(i.getLocal("itAux"),i.i32_const(e))),i.setLocal("i",i.i32_sub(i.getLocal("i"),i.i32_const(1))),i.br(0)))),o.addCode(i.i32_store(i.i32_const(0),i.getLocal("itAux")))};var Z=function(t,a,e,o,i,n){void 0===n&&(n=oa?1:-1}function X(t){return t*t}function tt(t){return t%2n!==0n}function at(t){return t%2n===0n}function et(t){return t<0n}function ot(t){return t>0n}function it(t){return et(t)?t.toString(2).length-1:t.toString(2).length}function nt(t){return t<0n?-t:t}function lt(t){return 1n===nt(t)}function ct(t,a){for(var e,o,i,n=0n,l=1n,c=a,s=nt(t);0n!==s;)e=c/s,o=n,i=c,n=l,c=s,l=o-e*l,s=i-e*s;if(!lt(c))throw new Error(t.toString()+" and "+a.toString()+" are not co-prime");return-1===J(n,0n)&&(n+=a),et(t)?-n:n}function st(t,a,e){if(0n===e)throw new Error("Cannot take modPow with modulus 0");var o=1n,i=t%e;for(et(a)&&(a*=-1n,i=ct(i,e));ot(a);){if(0n===i)return 0n;tt(a)&&(o=o*i%e),a/=2n,i=X(i)%e}return o}function rt(t,a){return 0n!==a&&(!!lt(a)||(0===function(t,a){return(t=t>=0n?t:-t)===(a=a>=0n?a:-a)?0:t>a?1:-1}(a,2n)?at(t):t%a===0n))}function dt(t,a){for(var e,o,i,n=function(t){return t-1n}(t),l=n,c=0;at(l);)l/=2n,c++;t:for(o=0;o>1&&o>1,t>>1)))),a.addCode(e.setLocal(s,e.i64_add(e.getLocal(s),e.i64_shr_u(e.getLocal(c),e.i64_const(32)))))),t>0&&(a.addCode(e.setLocal(c,e.i64_add(e.i64_and(e.getLocal(c),e.i64_const(4294967295)),e.i64_and(e.getLocal(r),e.i64_const(4294967295))))),a.addCode(e.setLocal(s,e.i64_add(e.i64_add(e.getLocal(s),e.i64_shr_u(e.getLocal(c),e.i64_const(32))),e.getLocal(d))))),a.addCode(e.i64_store32(e.getLocal("r"),4*t,e.getLocal(c))),a.addCode(e.setLocal(r,e.getLocal(s)),e.setLocal(d,e.i64_shr_u(e.getLocal(r),e.i64_const(32))))}a.addCode(e.i64_store32(e.getLocal("r"),4*i*2-4,e.getLocal(r)))}(),function(){const a=t.addFunction(o+"_squareOld");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(o+"_mul",e.getLocal("x"),e.getLocal("x"),e.getLocal("r")))}(),function(){!function(){const a=t.addFunction(o+"__mul1");a.addParam("px","i32"),a.addParam("y","i64"),a.addParam("pr","i32"),a.addLocal("c","i64");const e=a.getCodeBuilder();a.addCode(e.setLocal("c",e.i64_mul(e.i64_load32_u(e.getLocal("px"),0,0),e.getLocal("y")))),a.addCode(e.i64_store32(e.getLocal("pr"),0,0,e.getLocal("c")));for(let t=1;t>1n,p=t.alloc(c,_t.bigInt2BytesLE(h,c)),m=h+1n,L=t.alloc(c,_t.bigInt2BytesLE(m,c));t.modules[s]={pq:d,pR2:u,n64:n,q:i,pOne:_,pZero:g,pePlusOne:L};let b=2n;if(wt(i))for(;bt(b,h,i)!==f;)b+=1n;let w=0,y=f;for(;!yt(y)&&0n!==y;)w++,y>>=1n;const A=t.alloc(c,_t.bigInt2BytesLE(y,c)),C=bt(b,y,i),F=t.alloc(_t.bigInt2BytesLE((C<>1n,I=t.alloc(c,_t.bigInt2BytesLE(x,c));return t.exportFunction(r+"_copy",s+"_copy"),t.exportFunction(r+"_zero",s+"_zero"),t.exportFunction(r+"_isZero",s+"_isZero"),t.exportFunction(r+"_eq",s+"_eq"),function(){const a=t.addFunction(s+"_isOne");a.addParam("x","i32"),a.setReturnType("i32");const e=a.getCodeBuilder();a.addCode(e.ret(e.call(r+"_eq",e.getLocal("x"),e.i32_const(_))))}(),function(){const a=t.addFunction(s+"_add");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.if(e.call(r+"_add",e.getLocal("x"),e.getLocal("y"),e.getLocal("r")),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))),e.if(e.call(r+"_gte",e.getLocal("r"),e.i32_const(d)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))))))}(),function(){const a=t.addFunction(s+"_sub");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.if(e.call(r+"_sub",e.getLocal("x"),e.getLocal("y"),e.getLocal("r")),e.drop(e.call(r+"_add",e.getLocal("r"),e.i32_const(d),e.getLocal("r")))))}(),function(){const a=t.addFunction(s+"_neg");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_sub",e.i32_const(g),e.getLocal("x"),e.getLocal("r")))}(),function(){const a=t.alloc(l*l*8),e=t.addFunction(s+"_mReduct");e.addParam("t","i32"),e.addParam("r","i32"),e.addLocal("np32","i64"),e.addLocal("c","i64"),e.addLocal("m","i64");const o=e.getCodeBuilder(),n=Number(0x100000000n-Lt(i,0x100000000n));e.addCode(o.setLocal("np32",o.i64_const(n)));for(let t=0;t=l&&a.addCode(e.i64_store32(e.getLocal("r"),4*(t-l),e.getLocal(f))),[f,h]=[h,f],a.addCode(e.setLocal(h,e.i64_shr_u(e.getLocal(f),e.i64_const(32))))}a.addCode(e.i64_store32(e.getLocal("r"),4*l-4,e.getLocal(f))),a.addCode(e.if(e.i32_wrap_i64(e.getLocal(h)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))),e.if(e.call(r+"_gte",e.getLocal("r"),e.i32_const(d)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))))))}(),function(){const a=t.addFunction(s+"_square");a.addParam("x","i32"),a.addParam("r","i32"),a.addLocal("c0","i64"),a.addLocal("c1","i64"),a.addLocal("c0_old","i64"),a.addLocal("c1_old","i64"),a.addLocal("np32","i64");for(let t=0;t>1&&o>1,t>>1)))),a.addCode(e.setLocal(f,e.i64_add(e.getLocal(f),e.i64_shr_u(e.getLocal(g),e.i64_const(32)))))),t>0&&(a.addCode(e.setLocal(g,e.i64_add(e.i64_and(e.getLocal(g),e.i64_const(4294967295)),e.i64_and(e.getLocal(h),e.i64_const(4294967295))))),a.addCode(e.setLocal(f,e.i64_add(e.i64_add(e.getLocal(f),e.i64_shr_u(e.getLocal(g),e.i64_const(32))),e.getLocal(p)))));for(let o=Math.max(1,t-l+1);o<=t&&o=l&&a.addCode(e.i64_store32(e.getLocal("r"),4*(t-l),e.getLocal(g))),a.addCode(e.setLocal(h,e.getLocal(f)),e.setLocal(p,e.i64_shr_u(e.getLocal(h),e.i64_const(32))))}a.addCode(e.i64_store32(e.getLocal("r"),4*l-4,e.getLocal(h))),a.addCode(e.if(e.i32_wrap_i64(e.getLocal(p)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))),e.if(e.call(r+"_gte",e.getLocal("r"),e.i32_const(d)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))))))}(),function(){const a=t.addFunction(s+"_squareOld");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_mul",e.getLocal("x"),e.getLocal("x"),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_toMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_mul",e.getLocal("x"),e.i32_const(u),e.getLocal("r")))}(),function(){const a=t.alloc(2*c),e=t.addFunction(s+"_fromMontgomery");e.addParam("x","i32"),e.addParam("r","i32");const o=e.getCodeBuilder();e.addCode(o.call(r+"_copy",o.getLocal("x"),o.i32_const(a))),e.addCode(o.call(r+"_zero",o.i32_const(a+c))),e.addCode(o.call(s+"_mReduct",o.i32_const(a),o.getLocal("r")))}(),function(){const a=t.addFunction(s+"_isNegative");a.addParam("x","i32"),a.setReturnType("i32");const e=a.getCodeBuilder(),o=e.i32_const(t.alloc(c));a.addCode(e.call(s+"_fromMontgomery",e.getLocal("x"),o),e.call(r+"_gte",o,e.i32_const(L)))}(),function(){const a=t.addFunction(s+"_sign");a.addParam("x","i32"),a.setReturnType("i32");const e=a.getCodeBuilder(),o=e.i32_const(t.alloc(c));a.addCode(e.if(e.call(r+"_isZero",e.getLocal("x")),e.ret(e.i32_const(0))),e.call(s+"_fromMontgomery",e.getLocal("x"),o),e.if(e.call(r+"_gte",o,e.i32_const(L)),e.ret(e.i32_const(-1))),e.ret(e.i32_const(1)))}(),function(){const a=t.addFunction(s+"_inverse");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_fromMontgomery",e.getLocal("x"),e.getLocal("r"))),a.addCode(e.call(r+"_inverseMod",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))),a.addCode(e.call(s+"_toMontgomery",e.getLocal("r"),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_one");a.addParam("pr","i32");const e=a.getCodeBuilder();a.addCode(e.call(r+"_copy",e.i32_const(_),e.getLocal("pr")))}(),function(){const a=t.addFunction(s+"_load");a.addParam("scalar","i32"),a.addParam("scalarLen","i32"),a.addParam("r","i32"),a.addLocal("p","i32"),a.addLocal("l","i32"),a.addLocal("i","i32"),a.addLocal("j","i32");const e=a.getCodeBuilder(),o=e.i32_const(t.alloc(c)),i=t.alloc(c),n=e.i32_const(i);a.addCode(e.call(r+"_zero",e.getLocal("r")),e.setLocal("i",e.i32_const(c)),e.setLocal("p",e.getLocal("scalar")),e.block(e.loop(e.br_if(1,e.i32_gt_u(e.getLocal("i"),e.getLocal("scalarLen"))),e.if(e.i32_eq(e.getLocal("i"),e.i32_const(c)),e.call(s+"_one",o),e.call(s+"_mul",o,e.i32_const(u),o)),e.call(s+"_mul",e.getLocal("p"),o,n),e.call(s+"_add",e.getLocal("r"),n,e.getLocal("r")),e.setLocal("p",e.i32_add(e.getLocal("p"),e.i32_const(c))),e.setLocal("i",e.i32_add(e.getLocal("i"),e.i32_const(c))),e.br(0))),e.setLocal("l",e.i32_rem_u(e.getLocal("scalarLen"),e.i32_const(c))),e.if(e.i32_eqz(e.getLocal("l")),e.ret([])),e.call(r+"_zero",n),e.setLocal("j",e.i32_const(0)),e.block(e.loop(e.br_if(1,e.i32_eq(e.getLocal("j"),e.getLocal("l"))),e.i32_store8(e.getLocal("j"),i,e.i32_load8_u(e.getLocal("p"))),e.setLocal("p",e.i32_add(e.getLocal("p"),e.i32_const(1))),e.setLocal("j",e.i32_add(e.getLocal("j"),e.i32_const(1))),e.br(0))),e.if(e.i32_eq(e.getLocal("i"),e.i32_const(c)),e.call(s+"_one",o),e.call(s+"_mul",o,e.i32_const(u),o)),e.call(s+"_mul",n,o,n),e.call(s+"_add",e.getLocal("r"),n,e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_timesScalar");a.addParam("x","i32"),a.addParam("scalar","i32"),a.addParam("scalarLen","i32"),a.addParam("r","i32");const e=a.getCodeBuilder(),o=e.i32_const(t.alloc(c));a.addCode(e.call(s+"_load",e.getLocal("scalar"),e.getLocal("scalarLen"),o),e.call(s+"_toMontgomery",o,o),e.call(s+"_mul",e.getLocal("x"),o,e.getLocal("r")))}(),ft(t,s),ht(t,s+"_batchToMontgomery",s+"_toMontgomery",c,c),ht(t,s+"_batchFromMontgomery",s+"_fromMontgomery",c,c),ht(t,s+"_batchNeg",s+"_neg",c,c),pt(t,s+"_batchAdd",s+"_add",c,c),pt(t,s+"_batchSub",s+"_sub",c,c),pt(t,s+"_batchMul",s+"_mul",c,c),t.exportFunction(s+"_add"),t.exportFunction(s+"_sub"),t.exportFunction(s+"_neg"),t.exportFunction(s+"_isNegative"),t.exportFunction(s+"_isOne"),t.exportFunction(s+"_sign"),t.exportFunction(s+"_mReduct"),t.exportFunction(s+"_mul"),t.exportFunction(s+"_square"),t.exportFunction(s+"_squareOld"),t.exportFunction(s+"_fromMontgomery"),t.exportFunction(s+"_toMontgomery"),t.exportFunction(s+"_inverse"),t.exportFunction(s+"_one"),t.exportFunction(s+"_load"),t.exportFunction(s+"_timesScalar"),gt(t,s+"_exp",c,s+"_mul",s+"_square",r+"_copy",s+"_one"),t.exportFunction(s+"_exp"),t.exportFunction(s+"_batchInverse"),wt(i)&&(!function(){const a=t.addFunction(s+"_sqrt");a.addParam("n","i32"),a.addParam("r","i32"),a.addLocal("m","i32"),a.addLocal("i","i32"),a.addLocal("j","i32");const e=a.getCodeBuilder(),o=e.i32_const(_),i=e.i32_const(t.alloc(c)),n=e.i32_const(t.alloc(c)),l=e.i32_const(t.alloc(c)),r=e.i32_const(t.alloc(c)),d=e.i32_const(t.alloc(c));a.addCode(e.if(e.call(s+"_isZero",e.getLocal("n")),e.ret(e.call(s+"_zero",e.getLocal("r")))),e.setLocal("m",e.i32_const(w)),e.call(s+"_copy",e.i32_const(F),i),e.call(s+"_exp",e.getLocal("n"),e.i32_const(A),e.i32_const(c),n),e.call(s+"_exp",e.getLocal("n"),e.i32_const(I),e.i32_const(c),l),e.block(e.loop(e.br_if(1,e.call(s+"_eq",n,o)),e.call(s+"_square",n,r),e.setLocal("i",e.i32_const(1)),e.block(e.loop(e.br_if(1,e.call(s+"_eq",r,o)),e.call(s+"_square",r,r),e.setLocal("i",e.i32_add(e.getLocal("i"),e.i32_const(1))),e.br(0))),e.call(s+"_copy",i,d),e.setLocal("j",e.i32_sub(e.i32_sub(e.getLocal("m"),e.getLocal("i")),e.i32_const(1))),e.block(e.loop(e.br_if(1,e.i32_eqz(e.getLocal("j"))),e.call(s+"_square",d,d),e.setLocal("j",e.i32_sub(e.getLocal("j"),e.i32_const(1))),e.br(0))),e.setLocal("m",e.getLocal("i")),e.call(s+"_square",d,i),e.call(s+"_mul",n,i,n),e.call(s+"_mul",l,d,l),e.br(0))),e.if(e.call(s+"_isNegative",l),e.call(s+"_neg",l,e.getLocal("r")),e.call(s+"_copy",l,e.getLocal("r"))))}(),function(){const a=t.addFunction(s+"_isSquare");a.addParam("n","i32"),a.setReturnType("i32");const e=a.getCodeBuilder(),o=e.i32_const(_),i=e.i32_const(t.alloc(c));a.addCode(e.if(e.call(s+"_isZero",e.getLocal("n")),e.ret(e.i32_const(1))),e.call(s+"_exp",e.getLocal("n"),e.i32_const(p),e.i32_const(c),i),e.call(s+"_eq",i,o))}(),t.exportFunction(s+"_sqrt"),t.exportFunction(s+"_isSquare")),t.exportFunction(s+"_batchToMontgomery"),t.exportFunction(s+"_batchFromMontgomery"),s};const Ft=Ct,{bitLength:xt}=Y;var It=function(t,a,e,o,i){const n=BigInt(a),l=Math.floor((xt(n-1n)-1)/64)+1,c=8*l,s=e||"f1";if(t.modules[s])return s;t.modules[s]={n64:l};const r=i||"int",d=Ft(t,n,o,r),u=t.modules[d].pR2,_=t.modules[d].pq,g=t.modules[d].pePlusOne;return function(){const a=t.alloc(c),e=t.addFunction(s+"_mul");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32");const o=e.getCodeBuilder();e.addCode(o.call(d+"_mul",o.getLocal("x"),o.getLocal("y"),o.i32_const(a))),e.addCode(o.call(d+"_mul",o.i32_const(a),o.i32_const(u),o.getLocal("r")))}(),function(){const a=t.addFunction(s+"_square");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_mul",e.getLocal("x"),e.getLocal("x"),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_inverse");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(r+"_inverseMod",e.getLocal("x"),e.i32_const(_),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_isNegative");a.addParam("x","i32"),a.setReturnType("i32");const e=a.getCodeBuilder();a.addCode(e.call(r+"_gte",e.getLocal("x"),e.i32_const(g)))}(),t.exportFunction(d+"_add",s+"_add"),t.exportFunction(d+"_sub",s+"_sub"),t.exportFunction(d+"_neg",s+"_neg"),t.exportFunction(s+"_mul"),t.exportFunction(s+"_square"),t.exportFunction(s+"_inverse"),t.exportFunction(s+"_isNegative"),t.exportFunction(d+"_copy",s+"_copy"),t.exportFunction(d+"_zero",s+"_zero"),t.exportFunction(d+"_one",s+"_one"),t.exportFunction(d+"_isZero",s+"_isZero"),t.exportFunction(d+"_eq",s+"_eq"),s};const Bt=K,Et=H,vt=V;var St=function(t,a,e,o){if(t.modules[e])return e;const i=8*t.modules[o].n64,n=t.modules[o].q;return t.modules[e]={n64:2*t.modules[o].n64},function(){const a=t.addFunction(e+"_isZero");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.i32_and(n.call(o+"_isZero",l),n.call(o+"_isZero",c)))}(),function(){const a=t.addFunction(e+"_isOne");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.ret(n.i32_and(n.call(o+"_isOne",l),n.call(o+"_isZero",c))))}(),function(){const a=t.addFunction(e+"_zero");a.addParam("x","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.call(o+"_zero",l),n.call(o+"_zero",c))}(),function(){const a=t.addFunction(e+"_one");a.addParam("x","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.call(o+"_one",l),n.call(o+"_zero",c))}(),function(){const a=t.addFunction(e+"_copy");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_copy",l,s),n.call(o+"_copy",c,r))}(),function(){const n=t.addFunction(e+"_mul");n.addParam("x","i32"),n.addParam("y","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.getLocal("y"),d=l.i32_add(l.getLocal("y"),l.i32_const(i)),u=l.getLocal("r"),_=l.i32_add(l.getLocal("r"),l.i32_const(i)),g=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i)),h=l.i32_const(t.alloc(i)),p=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_mul",c,r,g),l.call(o+"_mul",s,d,f),l.call(o+"_add",c,s,h),l.call(o+"_add",r,d,p),l.call(o+"_mul",h,p,h),l.call(a,f,u),l.call(o+"_add",g,u,u),l.call(o+"_add",g,f,_),l.call(o+"_sub",h,_,_))}(),function(){const a=t.addFunction(e+"_mul1");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("y"),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_mul",l,s,r),n.call(o+"_mul",c,s,d))}(),function(){const n=t.addFunction(e+"_square");n.addParam("x","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.getLocal("r"),d=l.i32_add(l.getLocal("r"),l.i32_const(i)),u=l.i32_const(t.alloc(i)),_=l.i32_const(t.alloc(i)),g=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_mul",c,s,u),l.call(o+"_add",c,s,_),l.call(a,s,g),l.call(o+"_add",c,g,g),l.call(a,u,f),l.call(o+"_add",f,u,f),l.call(o+"_mul",_,g,r),l.call(o+"_sub",r,f,r),l.call(o+"_add",u,u,d))}(),function(){const a=t.addFunction(e+"_add");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("y"),r=n.i32_add(n.getLocal("y"),n.i32_const(i)),d=n.getLocal("r"),u=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_add",l,s,d),n.call(o+"_add",c,r,u))}(),function(){const a=t.addFunction(e+"_sub");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("y"),r=n.i32_add(n.getLocal("y"),n.i32_const(i)),d=n.getLocal("r"),u=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_sub",l,s,d),n.call(o+"_sub",c,r,u))}(),function(){const a=t.addFunction(e+"_neg");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_neg",l,s),n.call(o+"_neg",c,r))}(),function(){const a=t.addFunction(e+"_conjugate");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_copy",l,s),n.call(o+"_neg",c,r))}(),function(){const a=t.addFunction(e+"_toMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_toMontgomery",l,s),n.call(o+"_toMontgomery",c,r))}(),function(){const a=t.addFunction(e+"_fromMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_fromMontgomery",l,s),n.call(o+"_fromMontgomery",c,r))}(),function(){const a=t.addFunction(e+"_eq");a.addParam("x","i32"),a.addParam("y","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("y"),r=n.i32_add(n.getLocal("y"),n.i32_const(i));a.addCode(n.i32_and(n.call(o+"_eq",l,s),n.call(o+"_eq",c,r)))}(),function(){const n=t.addFunction(e+"_inverse");n.addParam("x","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.getLocal("r"),d=l.i32_add(l.getLocal("r"),l.i32_const(i)),u=l.i32_const(t.alloc(i)),_=l.i32_const(t.alloc(i)),g=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_square",c,u),l.call(o+"_square",s,_),l.call(a,_,g),l.call(o+"_sub",u,g,g),l.call(o+"_inverse",g,f),l.call(o+"_mul",c,f,r),l.call(o+"_mul",s,f,d),l.call(o+"_neg",d,d))}(),function(){const a=t.addFunction(e+"_timesScalar");a.addParam("x","i32"),a.addParam("scalar","i32"),a.addParam("scalarLen","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_timesScalar",l,n.getLocal("scalar"),n.getLocal("scalarLen"),s),n.call(o+"_timesScalar",c,n.getLocal("scalar"),n.getLocal("scalarLen"),r))}(),function(){const a=t.addFunction(e+"_sign");a.addParam("x","i32"),a.addLocal("s","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.setLocal("s",n.call(o+"_sign",c)),n.if(n.getLocal("s"),n.ret(n.getLocal("s"))),n.ret(n.call(o+"_sign",l)))}(),function(){const a=t.addFunction(e+"_isNegative");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.if(n.call(o+"_isZero",c),n.ret(n.call(o+"_isNegative",l))),n.ret(n.call(o+"_isNegative",c)))}(),t.exportFunction(e+"_isZero"),t.exportFunction(e+"_isOne"),t.exportFunction(e+"_zero"),t.exportFunction(e+"_one"),t.exportFunction(e+"_copy"),t.exportFunction(e+"_mul"),t.exportFunction(e+"_mul1"),t.exportFunction(e+"_square"),t.exportFunction(e+"_add"),t.exportFunction(e+"_sub"),t.exportFunction(e+"_neg"),t.exportFunction(e+"_sign"),t.exportFunction(e+"_conjugate"),t.exportFunction(e+"_fromMontgomery"),t.exportFunction(e+"_toMontgomery"),t.exportFunction(e+"_eq"),t.exportFunction(e+"_inverse"),Et(t,e),Bt(t,e+"_exp",2*i,e+"_mul",e+"_square",e+"_copy",e+"_one"),function(){const a=t.addFunction(e+"_sqrt");a.addParam("a","i32"),a.addParam("pr","i32");const l=a.getCodeBuilder(),c=l.i32_const(t.alloc(vt.bigInt2BytesLE((BigInt(n||0)-3n)/4n,i))),s=l.i32_const(t.alloc(vt.bigInt2BytesLE((BigInt(n||0)-1n)/2n,i))),r=l.getLocal("a"),d=l.i32_const(t.alloc(2*i)),u=l.i32_const(t.alloc(2*i)),_=l.i32_const(t.alloc(2*i)),g=t.alloc(2*i),f=l.i32_const(g),h=l.i32_const(g),p=l.i32_const(g+i),m=l.i32_const(t.alloc(2*i)),L=l.i32_const(t.alloc(2*i));a.addCode(l.call(e+"_one",f),l.call(e+"_neg",f,f),l.call(e+"_exp",r,c,l.i32_const(i),d),l.call(e+"_square",d,u),l.call(e+"_mul",r,u,u),l.call(e+"_conjugate",u,_),l.call(e+"_mul",_,u,_),l.if(l.call(e+"_eq",_,f),l.unreachable()),l.call(e+"_mul",d,r,m),l.if(l.call(e+"_eq",u,f),[...l.call(o+"_zero",h),...l.call(o+"_one",p),...l.call(e+"_mul",f,m,l.getLocal("pr"))],[...l.call(e+"_one",L),...l.call(e+"_add",L,u,L),...l.call(e+"_exp",L,s,l.i32_const(i),L),...l.call(e+"_mul",L,m,l.getLocal("pr"))]))}(),function(){const a=t.addFunction(e+"_isSquare");a.addParam("a","i32"),a.setReturnType("i32");const o=a.getCodeBuilder(),l=o.i32_const(t.alloc(vt.bigInt2BytesLE((BigInt(n||0)-3n)/4n,i))),c=o.getLocal("a"),s=o.i32_const(t.alloc(2*i)),r=o.i32_const(t.alloc(2*i)),d=o.i32_const(t.alloc(2*i)),u=t.alloc(2*i),_=o.i32_const(u);a.addCode(o.call(e+"_one",_),o.call(e+"_neg",_,_),o.call(e+"_exp",c,l,o.i32_const(i),s),o.call(e+"_square",s,r),o.call(e+"_mul",c,r,r),o.call(e+"_conjugate",r,d),o.call(e+"_mul",d,r,d),o.if(o.call(e+"_eq",d,_),o.ret(o.i32_const(0))),o.ret(o.i32_const(1)))}(),t.exportFunction(e+"_exp"),t.exportFunction(e+"_timesScalar"),t.exportFunction(e+"_batchInverse"),t.exportFunction(e+"_sqrt"),t.exportFunction(e+"_isSquare"),t.exportFunction(e+"_isNegative"),e};const Pt=K,qt=H;var Ot=function(t,a,e,o){if(t.modules[e])return e;const i=8*t.modules[o].n64;return t.modules[e]={n64:3*t.modules[o].n64},function(){const a=t.addFunction(e+"_isZero");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.i32_and(n.i32_and(n.call(o+"_isZero",l),n.call(o+"_isZero",c)),n.call(o+"_isZero",s)))}(),function(){const a=t.addFunction(e+"_isOne");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.ret(n.i32_and(n.i32_and(n.call(o+"_isOne",l),n.call(o+"_isZero",c)),n.call(o+"_isZero",s))))}(),function(){const a=t.addFunction(e+"_zero");a.addParam("x","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.call(o+"_zero",l),n.call(o+"_zero",c),n.call(o+"_zero",s))}(),function(){const a=t.addFunction(e+"_one");a.addParam("x","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.call(o+"_one",l),n.call(o+"_zero",c),n.call(o+"_zero",s))}(),function(){const a=t.addFunction(e+"_copy");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_copy",l,r),n.call(o+"_copy",c,d),n.call(o+"_copy",s,u))}(),function(){const n=t.addFunction(e+"_mul");n.addParam("x","i32"),n.addParam("y","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.i32_add(l.getLocal("x"),l.i32_const(2*i)),d=l.getLocal("y"),u=l.i32_add(l.getLocal("y"),l.i32_const(i)),_=l.i32_add(l.getLocal("y"),l.i32_const(2*i)),g=l.getLocal("r"),f=l.i32_add(l.getLocal("r"),l.i32_const(i)),h=l.i32_add(l.getLocal("r"),l.i32_const(2*i)),p=l.i32_const(t.alloc(i)),m=l.i32_const(t.alloc(i)),L=l.i32_const(t.alloc(i)),b=l.i32_const(t.alloc(i)),w=l.i32_const(t.alloc(i)),y=l.i32_const(t.alloc(i)),A=l.i32_const(t.alloc(i)),C=l.i32_const(t.alloc(i)),F=l.i32_const(t.alloc(i)),x=l.i32_const(t.alloc(i)),I=l.i32_const(t.alloc(i)),B=l.i32_const(t.alloc(i)),E=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_mul",c,d,p),l.call(o+"_mul",s,u,m),l.call(o+"_mul",r,_,L),l.call(o+"_add",c,s,b),l.call(o+"_add",d,u,w),l.call(o+"_add",c,r,y),l.call(o+"_add",d,_,A),l.call(o+"_add",s,r,C),l.call(o+"_add",u,_,F),l.call(o+"_add",p,m,x),l.call(o+"_add",p,L,I),l.call(o+"_add",m,L,B),l.call(o+"_mul",C,F,g),l.call(o+"_sub",g,B,g),l.call(a,g,g),l.call(o+"_add",p,g,g),l.call(o+"_mul",b,w,f),l.call(o+"_sub",f,x,f),l.call(a,L,E),l.call(o+"_add",f,E,f),l.call(o+"_mul",y,A,h),l.call(o+"_sub",h,I,h),l.call(o+"_add",h,m,h))}(),function(){const n=t.addFunction(e+"_square");n.addParam("x","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.i32_add(l.getLocal("x"),l.i32_const(2*i)),d=l.getLocal("r"),u=l.i32_add(l.getLocal("r"),l.i32_const(i)),_=l.i32_add(l.getLocal("r"),l.i32_const(2*i)),g=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i)),h=l.i32_const(t.alloc(i)),p=l.i32_const(t.alloc(i)),m=l.i32_const(t.alloc(i)),L=l.i32_const(t.alloc(i)),b=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_square",c,g),l.call(o+"_mul",c,s,f),l.call(o+"_add",f,f,h),l.call(o+"_sub",c,s,p),l.call(o+"_add",p,r,p),l.call(o+"_square",p,p),l.call(o+"_mul",s,r,m),l.call(o+"_add",m,m,L),l.call(o+"_square",r,b),l.call(a,L,d),l.call(o+"_add",g,d,d),l.call(a,b,u),l.call(o+"_add",h,u,u),l.call(o+"_add",g,b,_),l.call(o+"_sub",L,_,_),l.call(o+"_add",p,_,_),l.call(o+"_add",h,_,_))}(),function(){const a=t.addFunction(e+"_add");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("y"),d=n.i32_add(n.getLocal("y"),n.i32_const(i)),u=n.i32_add(n.getLocal("y"),n.i32_const(2*i)),_=n.getLocal("r"),g=n.i32_add(n.getLocal("r"),n.i32_const(i)),f=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_add",l,r,_),n.call(o+"_add",c,d,g),n.call(o+"_add",s,u,f))}(),function(){const a=t.addFunction(e+"_sub");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("y"),d=n.i32_add(n.getLocal("y"),n.i32_const(i)),u=n.i32_add(n.getLocal("y"),n.i32_const(2*i)),_=n.getLocal("r"),g=n.i32_add(n.getLocal("r"),n.i32_const(i)),f=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_sub",l,r,_),n.call(o+"_sub",c,d,g),n.call(o+"_sub",s,u,f))}(),function(){const a=t.addFunction(e+"_neg");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_neg",l,r),n.call(o+"_neg",c,d),n.call(o+"_neg",s,u))}(),function(){const a=t.addFunction(e+"_sign");a.addParam("x","i32"),a.addLocal("s","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.setLocal("s",n.call(o+"_sign",s)),n.if(n.getLocal("s"),n.ret(n.getLocal("s"))),n.setLocal("s",n.call(o+"_sign",c)),n.if(n.getLocal("s"),n.ret(n.getLocal("s"))),n.ret(n.call(o+"_sign",l)))}(),function(){const a=t.addFunction(e+"_toMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_toMontgomery",l,r),n.call(o+"_toMontgomery",c,d),n.call(o+"_toMontgomery",s,u))}(),function(){const a=t.addFunction(e+"_fromMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_fromMontgomery",l,r),n.call(o+"_fromMontgomery",c,d),n.call(o+"_fromMontgomery",s,u))}(),function(){const a=t.addFunction(e+"_eq");a.addParam("x","i32"),a.addParam("y","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("y"),d=n.i32_add(n.getLocal("y"),n.i32_const(i)),u=n.i32_add(n.getLocal("y"),n.i32_const(2*i));a.addCode(n.i32_and(n.i32_and(n.call(o+"_eq",l,r),n.call(o+"_eq",c,d)),n.call(o+"_eq",s,u)))}(),function(){const n=t.addFunction(e+"_inverse");n.addParam("x","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.i32_add(l.getLocal("x"),l.i32_const(2*i)),d=l.getLocal("r"),u=l.i32_add(l.getLocal("r"),l.i32_const(i)),_=l.i32_add(l.getLocal("r"),l.i32_const(2*i)),g=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i)),h=l.i32_const(t.alloc(i)),p=l.i32_const(t.alloc(i)),m=l.i32_const(t.alloc(i)),L=l.i32_const(t.alloc(i)),b=l.i32_const(t.alloc(i)),w=l.i32_const(t.alloc(i)),y=l.i32_const(t.alloc(i)),A=l.i32_const(t.alloc(i)),C=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_square",c,g),l.call(o+"_square",s,f),l.call(o+"_square",r,h),l.call(o+"_mul",c,s,p),l.call(o+"_mul",c,r,m),l.call(o+"_mul",s,r,L),l.call(a,L,b),l.call(o+"_sub",g,b,b),l.call(a,h,w),l.call(o+"_sub",w,p,w),l.call(o+"_sub",f,m,y),l.call(o+"_mul",r,w,A),l.call(o+"_mul",s,y,C),l.call(o+"_add",A,C,A),l.call(a,A,A),l.call(o+"_mul",c,b,C),l.call(o+"_add",C,A,A),l.call(o+"_inverse",A,A),l.call(o+"_mul",A,b,d),l.call(o+"_mul",A,w,u),l.call(o+"_mul",A,y,_))}(),function(){const a=t.addFunction(e+"_timesScalar");a.addParam("x","i32"),a.addParam("scalar","i32"),a.addParam("scalarLen","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_timesScalar",l,n.getLocal("scalar"),n.getLocal("scalarLen"),r),n.call(o+"_timesScalar",c,n.getLocal("scalar"),n.getLocal("scalarLen"),d),n.call(o+"_timesScalar",s,n.getLocal("scalar"),n.getLocal("scalarLen"),u))}(),function(){const a=t.addFunction(e+"_isNegative");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.if(n.call(o+"_isZero",s),n.if(n.call(o+"_isZero",c),n.ret(n.call(o+"_isNegative",l)),n.ret(n.call(o+"_isNegative",c)))),n.ret(n.call(o+"_isNegative",s)))}(),t.exportFunction(e+"_isZero"),t.exportFunction(e+"_isOne"),t.exportFunction(e+"_zero"),t.exportFunction(e+"_one"),t.exportFunction(e+"_copy"),t.exportFunction(e+"_mul"),t.exportFunction(e+"_square"),t.exportFunction(e+"_add"),t.exportFunction(e+"_sub"),t.exportFunction(e+"_neg"),t.exportFunction(e+"_sign"),t.exportFunction(e+"_fromMontgomery"),t.exportFunction(e+"_toMontgomery"),t.exportFunction(e+"_eq"),t.exportFunction(e+"_inverse"),qt(t,e),Pt(t,e+"_exp",3*i,e+"_mul",e+"_square",e+"_copy",e+"_one"),t.exportFunction(e+"_exp"),t.exportFunction(e+"_timesScalar"),t.exportFunction(e+"_batchInverse"),t.exportFunction(e+"_isNegative"),e};const Gt=function(t,a,e,o,i,n,l,c){const s=t.addFunction(a);s.addParam("base","i32"),s.addParam("scalar","i32"),s.addParam("scalarLength","i32"),s.addParam("r","i32"),s.addLocal("old0","i32"),s.addLocal("nbits","i32"),s.addLocal("i","i32"),s.addLocal("last","i32"),s.addLocal("cur","i32"),s.addLocal("carry","i32"),s.addLocal("p","i32");const r=s.getCodeBuilder(),d=r.i32_const(t.alloc(e));function u(t){return r.i32_and(r.i32_shr_u(r.i32_load(r.i32_add(r.getLocal("scalar"),r.i32_and(r.i32_shr_u(t,r.i32_const(3)),r.i32_const(4294967292)))),r.i32_and(t,r.i32_const(31))),r.i32_const(1))}function _(t){return[...r.i32_store8(r.getLocal("p"),r.i32_const(t)),...r.setLocal("p",r.i32_add(r.getLocal("p"),r.i32_const(1)))]}s.addCode(r.if(r.i32_eqz(r.getLocal("scalarLength")),[...r.call(c,r.getLocal("r")),...r.ret([])]),r.setLocal("nbits",r.i32_shl(r.getLocal("scalarLength"),r.i32_const(3))),r.setLocal("old0",r.i32_load(r.i32_const(0))),r.setLocal("p",r.getLocal("old0")),r.i32_store(r.i32_const(0),r.i32_and(r.i32_add(r.i32_add(r.getLocal("old0"),r.i32_const(32)),r.getLocal("nbits")),r.i32_const(4294967288))),r.setLocal("i",r.i32_const(1)),r.setLocal("last",u(r.i32_const(0))),r.setLocal("carry",r.i32_const(0)),r.block(r.loop(r.br_if(1,r.i32_eq(r.getLocal("i"),r.getLocal("nbits"))),r.setLocal("cur",u(r.getLocal("i"))),r.if(r.getLocal("last"),r.if(r.getLocal("cur"),r.if(r.getLocal("carry"),[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(1)),..._(1)],[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(1)),..._(255)]),r.if(r.getLocal("carry"),[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(1)),..._(255)],[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(0)),..._(1)])),r.if(r.getLocal("cur"),r.if(r.getLocal("carry"),[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(1)),..._(0)],[...r.setLocal("last",r.i32_const(1)),...r.setLocal("carry",r.i32_const(0)),..._(0)]),r.if(r.getLocal("carry"),[...r.setLocal("last",r.i32_const(1)),...r.setLocal("carry",r.i32_const(0)),..._(0)],[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(0)),..._(0)]))),r.setLocal("i",r.i32_add(r.getLocal("i"),r.i32_const(1))),r.br(0))),r.if(r.getLocal("last"),r.if(r.getLocal("carry"),[..._(255),..._(0),..._(1)],[..._(1)]),r.if(r.getLocal("carry"),[..._(0),..._(1)])),r.setLocal("p",r.i32_sub(r.getLocal("p"),r.i32_const(1))),r.call(l,r.getLocal("base"),d),r.call(c,r.getLocal("r")),r.block(r.loop(r.call(i,r.getLocal("r"),r.getLocal("r")),r.setLocal("cur",r.i32_load8_u(r.getLocal("p"))),r.if(r.getLocal("cur"),r.if(r.i32_eq(r.getLocal("cur"),r.i32_const(1)),r.call(o,r.getLocal("r"),d,r.getLocal("r")),r.call(n,r.getLocal("r"),d,r.getLocal("r")))),r.br_if(1,r.i32_eq(r.getLocal("old0"),r.getLocal("p"))),r.setLocal("p",r.i32_sub(r.getLocal("p"),r.i32_const(1))),r.br(0))),r.i32_store(r.i32_const(0),r.getLocal("old0")))},zt=Z,Tt=function(t,a,e,o,i){const n=8*t.modules[a].n64;function l(){const o=t.addFunction(e);o.addParam("pBases","i32"),o.addParam("pScalars","i32"),o.addParam("scalarSize","i32"),o.addParam("n","i32"),o.addParam("pr","i32"),o.addLocal("chunkSize","i32"),o.addLocal("nChunks","i32"),o.addLocal("itScalar","i32"),o.addLocal("endScalar","i32"),o.addLocal("itBase","i32"),o.addLocal("itBit","i32"),o.addLocal("i","i32"),o.addLocal("j","i32"),o.addLocal("nTable","i32"),o.addLocal("pTable","i32"),o.addLocal("idx","i32"),o.addLocal("pIdxTable","i32");const i=o.getCodeBuilder(),l=i.i32_const(t.alloc(n)),c=t.alloc([17,17,17,17,17,17,17,17,17,17,16,16,15,14,13,13,12,11,10,9,8,7,7,6,5,4,3,2,1,1,1,1]);o.addCode(i.call(a+"_zero",i.getLocal("pr")),i.if(i.i32_eqz(i.getLocal("n")),i.ret([])),i.setLocal("chunkSize",i.i32_load8_u(i.i32_clz(i.getLocal("n")),c)),i.setLocal("nChunks",i.i32_add(i.i32_div_u(i.i32_sub(i.i32_shl(i.getLocal("scalarSize"),i.i32_const(3)),i.i32_const(1)),i.getLocal("chunkSize")),i.i32_const(1))),i.setLocal("itBit",i.i32_mul(i.i32_sub(i.getLocal("nChunks"),i.i32_const(1)),i.getLocal("chunkSize"))),i.block(i.loop(i.br_if(1,i.i32_lt_s(i.getLocal("itBit"),i.i32_const(0))),i.if(i.i32_eqz(i.call(a+"_isZero",i.getLocal("pr"))),[...i.setLocal("j",i.i32_const(0)),...i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("j"),i.getLocal("chunkSize"))),i.call(a+"_double",i.getLocal("pr"),i.getLocal("pr")),i.setLocal("j",i.i32_add(i.getLocal("j"),i.i32_const(1))),i.br(0)))]),i.call(e+"_chunk",i.getLocal("pBases"),i.getLocal("pScalars"),i.getLocal("scalarSize"),i.getLocal("n"),i.getLocal("itBit"),i.getLocal("chunkSize"),l),i.call(a+"_add",i.getLocal("pr"),l,i.getLocal("pr")),i.setLocal("itBit",i.i32_sub(i.getLocal("itBit"),i.getLocal("chunkSize"))),i.br(0))))}!function(){const a=t.addFunction(e+"_getChunk");a.addParam("pScalar","i32"),a.addParam("scalarSize","i32"),a.addParam("startBit","i32"),a.addParam("chunkSize","i32"),a.addLocal("bitsToEnd","i32"),a.addLocal("mask","i32"),a.setReturnType("i32");const o=a.getCodeBuilder();a.addCode(o.setLocal("bitsToEnd",o.i32_sub(o.i32_mul(o.getLocal("scalarSize"),o.i32_const(8)),o.getLocal("startBit"))),o.if(o.i32_gt_s(o.getLocal("chunkSize"),o.getLocal("bitsToEnd")),o.setLocal("mask",o.i32_sub(o.i32_shl(o.i32_const(1),o.getLocal("bitsToEnd")),o.i32_const(1))),o.setLocal("mask",o.i32_sub(o.i32_shl(o.i32_const(1),o.getLocal("chunkSize")),o.i32_const(1)))),o.i32_and(o.i32_shr_u(o.i32_load(o.i32_add(o.getLocal("pScalar"),o.i32_shr_u(o.getLocal("startBit"),o.i32_const(3))),0,0),o.i32_and(o.getLocal("startBit"),o.i32_const(7))),o.getLocal("mask")))}(),function(){const o=t.addFunction(e+"_reduceTable");o.addParam("pTable","i32"),o.addParam("p","i32"),o.addLocal("half","i32"),o.addLocal("it1","i32"),o.addLocal("it2","i32"),o.addLocal("pAcc","i32");const i=o.getCodeBuilder();o.addCode(i.if(i.i32_eq(i.getLocal("p"),i.i32_const(1)),i.ret([])),i.setLocal("half",i.i32_shl(i.i32_const(1),i.i32_sub(i.getLocal("p"),i.i32_const(1)))),i.setLocal("it1",i.getLocal("pTable")),i.setLocal("it2",i.i32_add(i.getLocal("pTable"),i.i32_mul(i.getLocal("half"),i.i32_const(n)))),i.setLocal("pAcc",i.i32_sub(i.getLocal("it2"),i.i32_const(n))),i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("it1"),i.getLocal("pAcc"))),i.call(a+"_add",i.getLocal("it1"),i.getLocal("it2"),i.getLocal("it1")),i.call(a+"_add",i.getLocal("pAcc"),i.getLocal("it2"),i.getLocal("pAcc")),i.setLocal("it1",i.i32_add(i.getLocal("it1"),i.i32_const(n))),i.setLocal("it2",i.i32_add(i.getLocal("it2"),i.i32_const(n))),i.br(0))),i.call(e+"_reduceTable",i.getLocal("pTable"),i.i32_sub(i.getLocal("p"),i.i32_const(1))),i.setLocal("p",i.i32_sub(i.getLocal("p"),i.i32_const(1))),i.block(i.loop(i.br_if(1,i.i32_eqz(i.getLocal("p"))),i.call(a+"_double",i.getLocal("pAcc"),i.getLocal("pAcc")),i.setLocal("p",i.i32_sub(i.getLocal("p"),i.i32_const(1))),i.br(0))),i.call(a+"_add",i.getLocal("pTable"),i.getLocal("pAcc"),i.getLocal("pTable")))}(),function(){const l=t.addFunction(e+"_chunk");l.addParam("pBases","i32"),l.addParam("pScalars","i32"),l.addParam("scalarSize","i32"),l.addParam("n","i32"),l.addParam("startBit","i32"),l.addParam("chunkSize","i32"),l.addParam("pr","i32"),l.addLocal("nChunks","i32"),l.addLocal("itScalar","i32"),l.addLocal("endScalar","i32"),l.addLocal("itBase","i32"),l.addLocal("i","i32"),l.addLocal("j","i32"),l.addLocal("nTable","i32"),l.addLocal("pTable","i32"),l.addLocal("idx","i32"),l.addLocal("pIdxTable","i32");const c=l.getCodeBuilder();l.addCode(c.if(c.i32_eqz(c.getLocal("n")),[...c.call(a+"_zero",c.getLocal("pr")),...c.ret([])]),c.setLocal("nTable",c.i32_shl(c.i32_const(1),c.getLocal("chunkSize"))),c.setLocal("pTable",c.i32_load(c.i32_const(0))),c.i32_store(c.i32_const(0),c.i32_add(c.getLocal("pTable"),c.i32_mul(c.getLocal("nTable"),c.i32_const(n)))),c.setLocal("j",c.i32_const(0)),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("j"),c.getLocal("nTable"))),c.call(a+"_zero",c.i32_add(c.getLocal("pTable"),c.i32_mul(c.getLocal("j"),c.i32_const(n)))),c.setLocal("j",c.i32_add(c.getLocal("j"),c.i32_const(1))),c.br(0))),c.setLocal("itBase",c.getLocal("pBases")),c.setLocal("itScalar",c.getLocal("pScalars")),c.setLocal("endScalar",c.i32_add(c.getLocal("pScalars"),c.i32_mul(c.getLocal("n"),c.getLocal("scalarSize")))),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("itScalar"),c.getLocal("endScalar"))),c.setLocal("idx",c.call(e+"_getChunk",c.getLocal("itScalar"),c.getLocal("scalarSize"),c.getLocal("startBit"),c.getLocal("chunkSize"))),c.if(c.getLocal("idx"),[...c.setLocal("pIdxTable",c.i32_add(c.getLocal("pTable"),c.i32_mul(c.i32_sub(c.getLocal("idx"),c.i32_const(1)),c.i32_const(n)))),...c.call(o,c.getLocal("pIdxTable"),c.getLocal("itBase"),c.getLocal("pIdxTable"))]),c.setLocal("itScalar",c.i32_add(c.getLocal("itScalar"),c.getLocal("scalarSize"))),c.setLocal("itBase",c.i32_add(c.getLocal("itBase"),c.i32_const(i))),c.br(0))),c.call(e+"_reduceTable",c.getLocal("pTable"),c.getLocal("chunkSize")),c.call(a+"_copy",c.getLocal("pTable"),c.getLocal("pr")),c.i32_store(c.i32_const(0),c.getLocal("pTable")))}(),l(),t.exportFunction(e),t.exportFunction(e+"_chunk")};var Mt=function(t,a,e,o){const i=t.modules[e].n64,n=8*i;if(t.modules[a])return a;return t.modules[a]={n64:3*i},function(){const o=t.addFunction(a+"_isZeroAffine");o.addParam("p1","i32"),o.setReturnType("i32");const i=o.getCodeBuilder();o.addCode(i.i32_and(i.call(e+"_isZero",i.getLocal("p1")),i.call(e+"_isZero",i.i32_add(i.getLocal("p1"),i.i32_const(n)))))}(),function(){const o=t.addFunction(a+"_isZero");o.addParam("p1","i32"),o.setReturnType("i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_isZero",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))))}(),function(){const o=t.addFunction(a+"_zeroAffine");o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_zero",i.getLocal("pr"))),o.addCode(i.call(e+"_zero",i.i32_add(i.getLocal("pr"),i.i32_const(n))))}(),function(){const o=t.addFunction(a+"_zero");o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_zero",i.getLocal("pr"))),o.addCode(i.call(e+"_one",i.i32_add(i.getLocal("pr"),i.i32_const(n)))),o.addCode(i.call(e+"_zero",i.i32_add(i.getLocal("pr"),i.i32_const(2*n))))}(),function(){const e=t.addFunction(a+"_copyAffine");e.addParam("ps","i32"),e.addParam("pd","i32");const o=e.getCodeBuilder();for(let t=0;t<2*i;t++)e.addCode(o.i64_store(o.getLocal("pd"),8*t,o.i64_load(o.getLocal("ps"),8*t)))}(),function(){const e=t.addFunction(a+"_copy");e.addParam("ps","i32"),e.addParam("pd","i32");const o=e.getCodeBuilder();for(let t=0;t<3*i;t++)e.addCode(o.i64_store(o.getLocal("pd"),8*t,o.i64_load(o.getLocal("ps"),8*t)))}(),function(){const o=t.addFunction(a+"_toJacobian");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.getLocal("pr"),r=i.i32_add(i.getLocal("pr"),i.i32_const(n)),d=i.i32_add(i.getLocal("pr"),i.i32_const(2*n));o.addCode(i.if(i.call(a+"_isZeroAffine",i.getLocal("p1")),i.call(a+"_zero",i.getLocal("pr")),[...i.call(e+"_one",d),...i.call(e+"_copy",c,r),...i.call(e+"_copy",l,s)]))}(),function(){const o=t.addFunction(a+"_eqAffine");o.addParam("p1","i32"),o.addParam("p2","i32"),o.setReturnType("i32"),o.addLocal("z1","i32");const i=o.getCodeBuilder();o.addCode(i.ret(i.i32_and(i.call(e+"_eq",i.getLocal("p1"),i.getLocal("p2")),i.call(e+"_eq",i.i32_add(i.getLocal("p1"),i.i32_const(n)),i.i32_add(i.getLocal("p2"),i.i32_const(n))))))}(),function(){const o=t.addFunction(a+"_eqMixed");o.addParam("p1","i32"),o.addParam("p2","i32"),o.setReturnType("i32"),o.addLocal("z1","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n));o.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))));const s=i.getLocal("z1"),r=i.getLocal("p2"),d=i.i32_add(i.getLocal("p2"),i.i32_const(n)),u=i.i32_const(t.alloc(n)),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),i.ret(i.call(a+"_isZeroAffine",i.getLocal("p2")))),i.if(i.call(a+"_isZeroAffine",i.getLocal("p2")),i.ret(i.i32_const(0))),i.if(i.call(e+"_isOne",s),i.ret(i.call(a+"_eqAffine",i.getLocal("p1"),i.getLocal("p2")))),i.call(e+"_square",s,u),i.call(e+"_mul",r,u,_),i.call(e+"_mul",s,u,g),i.call(e+"_mul",d,g,f),i.if(i.call(e+"_eq",l,_),i.if(i.call(e+"_eq",c,f),i.ret(i.i32_const(1)))),i.ret(i.i32_const(0)))}(),function(){const o=t.addFunction(a+"_eq");o.addParam("p1","i32"),o.addParam("p2","i32"),o.setReturnType("i32"),o.addLocal("z1","i32"),o.addLocal("z2","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n));o.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))));const s=i.getLocal("z1"),r=i.getLocal("p2"),d=i.i32_add(i.getLocal("p2"),i.i32_const(n));o.addCode(i.setLocal("z2",i.i32_add(i.getLocal("p2"),i.i32_const(2*n))));const u=i.getLocal("z2"),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n)),m=i.i32_const(t.alloc(n)),L=i.i32_const(t.alloc(n)),b=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),i.ret(i.call(a+"_isZero",i.getLocal("p2")))),i.if(i.call(a+"_isZero",i.getLocal("p2")),i.ret(i.i32_const(0))),i.if(i.call(e+"_isOne",s),i.ret(i.call(a+"_eqMixed",i.getLocal("p2"),i.getLocal("p1")))),i.if(i.call(e+"_isOne",u),i.ret(i.call(a+"_eqMixed",i.getLocal("p1"),i.getLocal("p2")))),i.call(e+"_square",s,_),i.call(e+"_square",u,g),i.call(e+"_mul",l,g,f),i.call(e+"_mul",r,_,h),i.call(e+"_mul",s,_,p),i.call(e+"_mul",u,g,m),i.call(e+"_mul",c,m,L),i.call(e+"_mul",d,p,b),i.if(i.call(e+"_eq",f,h),i.if(i.call(e+"_eq",L,b),i.ret(i.i32_const(1)))),i.ret(i.i32_const(0)))}(),function(){const o=t.addFunction(a+"_doubleAffine");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.getLocal("pr"),r=i.i32_add(i.getLocal("pr"),i.i32_const(n)),d=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),u=i.i32_const(t.alloc(n)),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZeroAffine",i.getLocal("p1")),[...i.call(a+"_toJacobian",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])]),i.call(e+"_square",l,u),i.call(e+"_square",c,_),i.call(e+"_square",_,g),i.call(e+"_add",l,_,f),i.call(e+"_square",f,f),i.call(e+"_sub",f,u,f),i.call(e+"_sub",f,g,f),i.call(e+"_add",f,f,f),i.call(e+"_add",u,u,h),i.call(e+"_add",h,u,h),i.call(e+"_add",c,c,d),i.call(e+"_square",h,s),i.call(e+"_sub",s,f,s),i.call(e+"_sub",s,f,s),i.call(e+"_add",g,g,p),i.call(e+"_add",p,p,p),i.call(e+"_add",p,p,p),i.call(e+"_sub",f,s,r),i.call(e+"_mul",r,h,r),i.call(e+"_sub",r,p,r))}(),function(){const o=t.addFunction(a+"_double");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.i32_add(i.getLocal("p1"),i.i32_const(2*n)),r=i.getLocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(n)),u=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n)),m=i.i32_const(t.alloc(n)),L=i.i32_const(t.alloc(n)),b=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),[...i.call(a+"_copy",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])]),i.if(i.call(e+"_isOne",s),[...i.ret(i.call(a+"_doubleAffine",i.getLocal("p1"),i.getLocal("pr"))),...i.ret([])]),i.call(e+"_square",l,_),i.call(e+"_square",c,g),i.call(e+"_square",g,f),i.call(e+"_add",l,g,h),i.call(e+"_square",h,h),i.call(e+"_sub",h,_,h),i.call(e+"_sub",h,f,h),i.call(e+"_add",h,h,h),i.call(e+"_add",_,_,p),i.call(e+"_add",p,_,p),i.call(e+"_square",p,m),i.call(e+"_mul",c,s,L),i.call(e+"_add",h,h,r),i.call(e+"_sub",m,r,r),i.call(e+"_add",f,f,b),i.call(e+"_add",b,b,b),i.call(e+"_add",b,b,b),i.call(e+"_sub",h,r,d),i.call(e+"_mul",d,p,d),i.call(e+"_sub",d,b,d),i.call(e+"_add",L,L,u))}(),function(){const o=t.addFunction(a+"_addAffine");o.addParam("p1","i32"),o.addParam("p2","i32"),o.addParam("pr","i32"),o.addLocal("z1","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n));o.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))));const s=i.getLocal("p2"),r=i.i32_add(i.getLocal("p2"),i.i32_const(n)),d=i.getLocal("pr"),u=i.i32_add(i.getLocal("pr"),i.i32_const(n)),_=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n)),m=i.i32_const(t.alloc(n)),L=i.i32_const(t.alloc(n)),b=i.i32_const(t.alloc(n)),w=i.i32_const(t.alloc(n)),y=i.i32_const(t.alloc(n)),A=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZeroAffine",i.getLocal("p1")),[...i.call(a+"_copyAffine",i.getLocal("p2"),i.getLocal("pr")),...i.call(e+"_one",i.i32_add(i.getLocal("pr"),i.i32_const(2*n))),...i.ret([])]),i.if(i.call(a+"_isZeroAffine",i.getLocal("p2")),[...i.call(a+"_copyAffine",i.getLocal("p1"),i.getLocal("pr")),...i.call(e+"_one",i.i32_add(i.getLocal("pr"),i.i32_const(2*n))),...i.ret([])]),i.if(i.call(e+"_eq",l,s),i.if(i.call(e+"_eq",c,r),[...i.call(a+"_doubleAffine",i.getLocal("p2"),i.getLocal("pr")),...i.ret([])])),i.call(e+"_sub",s,l,g),i.call(e+"_sub",r,c,h),i.call(e+"_square",g,f),i.call(e+"_add",f,f,p),i.call(e+"_add",p,p,p),i.call(e+"_mul",g,p,m),i.call(e+"_add",h,h,L),i.call(e+"_mul",l,p,w),i.call(e+"_square",L,b),i.call(e+"_add",w,w,y),i.call(e+"_sub",b,m,d),i.call(e+"_sub",d,y,d),i.call(e+"_mul",c,m,A),i.call(e+"_add",A,A,A),i.call(e+"_sub",w,d,u),i.call(e+"_mul",u,L,u),i.call(e+"_sub",u,A,u),i.call(e+"_add",g,g,_))}(),function(){const o=t.addFunction(a+"_addMixed");o.addParam("p1","i32"),o.addParam("p2","i32"),o.addParam("pr","i32"),o.addLocal("z1","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n));o.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))));const s=i.getLocal("z1"),r=i.getLocal("p2"),d=i.i32_add(i.getLocal("p2"),i.i32_const(n)),u=i.getLocal("pr"),_=i.i32_add(i.getLocal("pr"),i.i32_const(n)),g=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),f=i.i32_const(t.alloc(n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n)),m=i.i32_const(t.alloc(n)),L=i.i32_const(t.alloc(n)),b=i.i32_const(t.alloc(n)),w=i.i32_const(t.alloc(n)),y=i.i32_const(t.alloc(n)),A=i.i32_const(t.alloc(n)),C=i.i32_const(t.alloc(n)),F=i.i32_const(t.alloc(n)),x=i.i32_const(t.alloc(n)),I=i.i32_const(t.alloc(n)),B=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),[...i.call(a+"_copyAffine",i.getLocal("p2"),i.getLocal("pr")),...i.call(e+"_one",i.i32_add(i.getLocal("pr"),i.i32_const(2*n))),...i.ret([])]),i.if(i.call(a+"_isZeroAffine",i.getLocal("p2")),[...i.call(a+"_copy",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])]),i.if(i.call(e+"_isOne",s),[...i.call(a+"_addAffine",l,r,u),...i.ret([])]),i.call(e+"_square",s,f),i.call(e+"_mul",r,f,h),i.call(e+"_mul",s,f,p),i.call(e+"_mul",d,p,m),i.if(i.call(e+"_eq",l,h),i.if(i.call(e+"_eq",c,m),[...i.call(a+"_doubleAffine",i.getLocal("p2"),i.getLocal("pr")),...i.ret([])])),i.call(e+"_sub",h,l,L),i.call(e+"_sub",m,c,w),i.call(e+"_square",L,b),i.call(e+"_add",b,b,y),i.call(e+"_add",y,y,y),i.call(e+"_mul",L,y,A),i.call(e+"_add",w,w,C),i.call(e+"_mul",l,y,x),i.call(e+"_square",C,F),i.call(e+"_add",x,x,I),i.call(e+"_sub",F,A,u),i.call(e+"_sub",u,I,u),i.call(e+"_mul",c,A,B),i.call(e+"_add",B,B,B),i.call(e+"_sub",x,u,_),i.call(e+"_mul",_,C,_),i.call(e+"_sub",_,B,_),i.call(e+"_add",s,L,g),i.call(e+"_square",g,g),i.call(e+"_sub",g,f,g),i.call(e+"_sub",g,b,g))}(),function(){const o=t.addFunction(a+"_add");o.addParam("p1","i32"),o.addParam("p2","i32"),o.addParam("pr","i32"),o.addLocal("z1","i32"),o.addLocal("z2","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n));o.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))));const s=i.getLocal("z1"),r=i.getLocal("p2"),d=i.i32_add(i.getLocal("p2"),i.i32_const(n));o.addCode(i.setLocal("z2",i.i32_add(i.getLocal("p2"),i.i32_const(2*n))));const u=i.getLocal("z2"),_=i.getLocal("pr"),g=i.i32_add(i.getLocal("pr"),i.i32_const(n)),f=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n)),m=i.i32_const(t.alloc(n)),L=i.i32_const(t.alloc(n)),b=i.i32_const(t.alloc(n)),w=i.i32_const(t.alloc(n)),y=i.i32_const(t.alloc(n)),A=i.i32_const(t.alloc(n)),C=i.i32_const(t.alloc(n)),F=i.i32_const(t.alloc(n)),x=i.i32_const(t.alloc(n)),I=i.i32_const(t.alloc(n)),B=i.i32_const(t.alloc(n)),E=i.i32_const(t.alloc(n)),v=i.i32_const(t.alloc(n)),S=i.i32_const(t.alloc(n)),P=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),[...i.call(a+"_copy",i.getLocal("p2"),i.getLocal("pr")),...i.ret([])]),i.if(i.call(a+"_isZero",i.getLocal("p2")),[...i.call(a+"_copy",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])]),i.if(i.call(e+"_isOne",s),[...i.call(a+"_addMixed",r,l,_),...i.ret([])]),i.if(i.call(e+"_isOne",u),[...i.call(a+"_addMixed",l,r,_),...i.ret([])]),i.call(e+"_square",s,h),i.call(e+"_square",u,p),i.call(e+"_mul",l,p,m),i.call(e+"_mul",r,h,L),i.call(e+"_mul",s,h,b),i.call(e+"_mul",u,p,w),i.call(e+"_mul",c,w,y),i.call(e+"_mul",d,b,A),i.if(i.call(e+"_eq",m,L),i.if(i.call(e+"_eq",y,A),[...i.call(a+"_double",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])])),i.call(e+"_sub",L,m,C),i.call(e+"_sub",A,y,F),i.call(e+"_add",C,C,x),i.call(e+"_square",x,x),i.call(e+"_mul",C,x,I),i.call(e+"_add",F,F,B),i.call(e+"_mul",m,x,v),i.call(e+"_square",B,E),i.call(e+"_add",v,v,S),i.call(e+"_sub",E,I,_),i.call(e+"_sub",_,S,_),i.call(e+"_mul",y,I,P),i.call(e+"_add",P,P,P),i.call(e+"_sub",v,_,g),i.call(e+"_mul",g,B,g),i.call(e+"_sub",g,P,g),i.call(e+"_add",s,u,f),i.call(e+"_square",f,f),i.call(e+"_sub",f,h,f),i.call(e+"_sub",f,p,f),i.call(e+"_mul",f,C,f))}(),function(){const o=t.addFunction(a+"_negAffine");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.getLocal("pr"),r=i.i32_add(i.getLocal("pr"),i.i32_const(n));o.addCode(i.call(e+"_copy",l,s),i.call(e+"_neg",c,r))}(),function(){const o=t.addFunction(a+"_neg");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.i32_add(i.getLocal("p1"),i.i32_const(2*n)),r=i.getLocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(n)),u=i.i32_add(i.getLocal("pr"),i.i32_const(2*n));o.addCode(i.call(e+"_copy",l,r),i.call(e+"_neg",c,d),i.call(e+"_copy",s,u))}(),function(){const e=t.addFunction(a+"_subAffine");e.addParam("p1","i32"),e.addParam("p2","i32"),e.addParam("pr","i32");const o=e.getCodeBuilder(),i=o.i32_const(t.alloc(3*n));e.addCode(o.call(a+"_negAffine",o.getLocal("p2"),i),o.call(a+"_addAffine",o.getLocal("p1"),i,o.getLocal("pr")))}(),function(){const e=t.addFunction(a+"_subMixed");e.addParam("p1","i32"),e.addParam("p2","i32"),e.addParam("pr","i32");const o=e.getCodeBuilder(),i=o.i32_const(t.alloc(3*n));e.addCode(o.call(a+"_negAffine",o.getLocal("p2"),i),o.call(a+"_addMixed",o.getLocal("p1"),i,o.getLocal("pr")))}(),function(){const e=t.addFunction(a+"_sub");e.addParam("p1","i32"),e.addParam("p2","i32"),e.addParam("pr","i32");const o=e.getCodeBuilder(),i=o.i32_const(t.alloc(3*n));e.addCode(o.call(a+"_neg",o.getLocal("p2"),i),o.call(a+"_add",o.getLocal("p1"),i,o.getLocal("pr")))}(),function(){const o=t.addFunction(a+"_fromMontgomeryAffine");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_fromMontgomery",i.getLocal("p1"),i.getLocal("pr")));for(let t=1;t<2;t++)o.addCode(i.call(e+"_fromMontgomery",i.i32_add(i.getLocal("p1"),i.i32_const(t*n)),i.i32_add(i.getLocal("pr"),i.i32_const(t*n))))}(),function(){const o=t.addFunction(a+"_fromMontgomery");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_fromMontgomery",i.getLocal("p1"),i.getLocal("pr")));for(let t=1;t<3;t++)o.addCode(i.call(e+"_fromMontgomery",i.i32_add(i.getLocal("p1"),i.i32_const(t*n)),i.i32_add(i.getLocal("pr"),i.i32_const(t*n))))}(),function(){const o=t.addFunction(a+"_toMontgomeryAffine");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_toMontgomery",i.getLocal("p1"),i.getLocal("pr")));for(let t=1;t<2;t++)o.addCode(i.call(e+"_toMontgomery",i.i32_add(i.getLocal("p1"),i.i32_const(t*n)),i.i32_add(i.getLocal("pr"),i.i32_const(t*n))))}(),function(){const o=t.addFunction(a+"_toMontgomery");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_toMontgomery",i.getLocal("p1"),i.getLocal("pr")));for(let t=1;t<3;t++)o.addCode(i.call(e+"_toMontgomery",i.i32_add(i.getLocal("p1"),i.i32_const(t*n)),i.i32_add(i.getLocal("pr"),i.i32_const(t*n))))}(),function(){const o=t.addFunction(a+"_toAffine");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.i32_add(i.getLocal("p1"),i.i32_const(2*n)),r=i.getLocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(n)),u=i.i32_const(t.alloc(n)),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),[...i.call(e+"_zero",r),...i.call(e+"_zero",d)],[...i.call(e+"_inverse",s,u),...i.call(e+"_square",u,_),...i.call(e+"_mul",u,_,g),...i.call(e+"_mul",l,_,r),...i.call(e+"_mul",c,g,d)]))}(),function(){const i=t.addFunction(a+"_inCurveAffine");i.addParam("pIn","i32"),i.setReturnType("i32");const l=i.getCodeBuilder(),c=l.getLocal("pIn"),s=l.i32_add(l.getLocal("pIn"),l.i32_const(n)),r=l.i32_const(t.alloc(n)),d=l.i32_const(t.alloc(n));i.addCode(l.call(e+"_square",s,r),l.call(e+"_square",c,d),l.call(e+"_mul",c,d,d),l.call(e+"_add",d,l.i32_const(o),d),l.ret(l.call(e+"_eq",r,d)))}(),function(){const e=t.addFunction(a+"_inCurve");e.addParam("pIn","i32"),e.setReturnType("i32");const o=e.getCodeBuilder(),i=o.i32_const(t.alloc(2*n));e.addCode(o.call(a+"_toAffine",o.getLocal("pIn"),i),o.ret(o.call(a+"_inCurveAffine",i)))}(),function(){const o=t.addFunction(a+"_batchToAffine");o.addParam("pIn","i32"),o.addParam("n","i32"),o.addParam("pOut","i32"),o.addLocal("pAux","i32"),o.addLocal("itIn","i32"),o.addLocal("itAux","i32"),o.addLocal("itOut","i32"),o.addLocal("i","i32");const i=o.getCodeBuilder(),l=i.i32_const(t.alloc(n));o.addCode(i.setLocal("pAux",i.i32_load(i.i32_const(0))),i.i32_store(i.i32_const(0),i.i32_add(i.getLocal("pAux"),i.i32_mul(i.getLocal("n"),i.i32_const(n)))),i.call(e+"_batchInverse",i.i32_add(i.getLocal("pIn"),i.i32_const(2*n)),i.i32_const(3*n),i.getLocal("n"),i.getLocal("pAux"),i.i32_const(n)),i.setLocal("itIn",i.getLocal("pIn")),i.setLocal("itAux",i.getLocal("pAux")),i.setLocal("itOut",i.getLocal("pOut")),i.setLocal("i",i.i32_const(0)),i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("i"),i.getLocal("n"))),i.if(i.call(e+"_isZero",i.getLocal("itAux")),[...i.call(e+"_zero",i.getLocal("itOut")),...i.call(e+"_zero",i.i32_add(i.getLocal("itOut"),i.i32_const(n)))],[...i.call(e+"_mul",i.getLocal("itAux"),i.i32_add(i.getLocal("itIn"),i.i32_const(n)),l),...i.call(e+"_square",i.getLocal("itAux"),i.getLocal("itAux")),...i.call(e+"_mul",i.getLocal("itAux"),i.getLocal("itIn"),i.getLocal("itOut")),...i.call(e+"_mul",i.getLocal("itAux"),l,i.i32_add(i.getLocal("itOut"),i.i32_const(n)))]),i.setLocal("itIn",i.i32_add(i.getLocal("itIn"),i.i32_const(3*n))),i.setLocal("itOut",i.i32_add(i.getLocal("itOut"),i.i32_const(2*n))),i.setLocal("itAux",i.i32_add(i.getLocal("itAux"),i.i32_const(n))),i.setLocal("i",i.i32_add(i.getLocal("i"),i.i32_const(1))),i.br(0))),i.i32_store(i.i32_const(0),i.getLocal("pAux")))}(),function(){const o=t.addFunction(a+"_normalize");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.i32_add(i.getLocal("p1"),i.i32_const(2*n)),r=i.getLocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(n)),u=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),i.call(a+"_zero",i.getLocal("pr")),[...i.call(e+"_inverse",s,_),...i.call(e+"_square",_,g),...i.call(e+"_mul",_,g,f),...i.call(e+"_mul",l,g,r),...i.call(e+"_mul",c,f,d),...i.call(e+"_one",u)]))}(),function(){const e=t.addFunction(a+"__reverseBytes");e.addParam("pIn","i32"),e.addParam("n","i32"),e.addParam("pOut","i32"),e.addLocal("itOut","i32"),e.addLocal("itIn","i32");const o=e.getCodeBuilder();e.addCode(o.setLocal("itOut",o.i32_sub(o.i32_add(o.getLocal("pOut"),o.getLocal("n")),o.i32_const(1))),o.setLocal("itIn",o.getLocal("pIn")),o.block(o.loop(o.br_if(1,o.i32_lt_s(o.getLocal("itOut"),o.getLocal("pOut"))),o.i32_store8(o.getLocal("itOut"),o.i32_load8_u(o.getLocal("itIn"))),o.setLocal("itOut",o.i32_sub(o.getLocal("itOut"),o.i32_const(1))),o.setLocal("itIn",o.i32_add(o.getLocal("itIn"),o.i32_const(1))),o.br(0))))}(),function(){const e=t.addFunction(a+"_LEMtoU");e.addParam("pIn","i32"),e.addParam("pOut","i32");const o=e.getCodeBuilder(),i=t.alloc(2*n),l=o.i32_const(i),c=o.i32_const(i),s=o.i32_const(i+n);e.addCode(o.if(o.call(a+"_isZeroAffine",o.getLocal("pIn")),[...o.call(a+"_zeroAffine",o.getLocal("pOut")),...o.ret([])]),o.call(a+"_fromMontgomeryAffine",o.getLocal("pIn"),l),o.call(a+"__reverseBytes",c,o.i32_const(n),o.getLocal("pOut")),o.call(a+"__reverseBytes",s,o.i32_const(n),o.i32_add(o.getLocal("pOut"),o.i32_const(n))))}(),function(){const o=t.addFunction(a+"_LEMtoC");o.addParam("pIn","i32"),o.addParam("pOut","i32");const i=o.getCodeBuilder(),l=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZeroAffine",i.getLocal("pIn")),[...i.call(e+"_zero",i.getLocal("pOut")),...i.i32_store8(i.getLocal("pOut"),i.i32_const(64)),...i.ret([])]),i.call(e+"_fromMontgomery",i.getLocal("pIn"),l),i.call(a+"__reverseBytes",l,i.i32_const(n),i.getLocal("pOut")),i.if(i.i32_eq(i.call(e+"_sign",i.i32_add(i.getLocal("pIn"),i.i32_const(n))),i.i32_const(-1)),i.i32_store8(i.getLocal("pOut"),i.i32_or(i.i32_load8_u(i.getLocal("pOut")),i.i32_const(128)))))}(),function(){const e=t.addFunction(a+"_UtoLEM");e.addParam("pIn","i32"),e.addParam("pOut","i32");const o=e.getCodeBuilder(),i=t.alloc(2*n),l=o.i32_const(i),c=o.i32_const(i),s=o.i32_const(i+n);e.addCode(o.if(o.i32_and(o.i32_load8_u(o.getLocal("pIn")),o.i32_const(64)),[...o.call(a+"_zeroAffine",o.getLocal("pOut")),...o.ret([])]),o.call(a+"__reverseBytes",o.getLocal("pIn"),o.i32_const(n),c),o.call(a+"__reverseBytes",o.i32_add(o.getLocal("pIn"),o.i32_const(n)),o.i32_const(n),s),o.call(a+"_toMontgomeryAffine",l,o.getLocal("pOut")))}(),function(){const i=t.addFunction(a+"_CtoLEM");i.addParam("pIn","i32"),i.addParam("pOut","i32"),i.addLocal("firstByte","i32"),i.addLocal("greatest","i32");const l=i.getCodeBuilder(),c=t.alloc(2*n),s=l.i32_const(c),r=l.i32_const(c+n);i.addCode(l.setLocal("firstByte",l.i32_load8_u(l.getLocal("pIn"))),l.if(l.i32_and(l.getLocal("firstByte"),l.i32_const(64)),[...l.call(a+"_zeroAffine",l.getLocal("pOut")),...l.ret([])]),l.setLocal("greatest",l.i32_and(l.getLocal("firstByte"),l.i32_const(128))),l.call(e+"_copy",l.getLocal("pIn"),r),l.i32_store8(r,l.i32_and(l.getLocal("firstByte"),l.i32_const(63))),l.call(a+"__reverseBytes",r,l.i32_const(n),s),l.call(e+"_toMontgomery",s,l.getLocal("pOut")),l.call(e+"_square",l.getLocal("pOut"),r),l.call(e+"_mul",l.getLocal("pOut"),r,r),l.call(e+"_add",r,l.i32_const(o),r),l.call(e+"_sqrt",r,r),l.call(e+"_neg",r,s),l.if(l.i32_eq(l.call(e+"_sign",r),l.i32_const(-1)),l.if(l.getLocal("greatest"),l.call(e+"_copy",r,l.i32_add(l.getLocal("pOut"),l.i32_const(n))),l.call(e+"_neg",r,l.i32_add(l.getLocal("pOut"),l.i32_const(n)))),l.if(l.getLocal("greatest"),l.call(e+"_neg",r,l.i32_add(l.getLocal("pOut"),l.i32_const(n))),l.call(e+"_copy",r,l.i32_add(l.getLocal("pOut"),l.i32_const(n))))))}(),zt(t,a+"_batchLEMtoU",a+"_LEMtoU",2*n,2*n),zt(t,a+"_batchLEMtoC",a+"_LEMtoC",2*n,n),zt(t,a+"_batchUtoLEM",a+"_UtoLEM",2*n,2*n),zt(t,a+"_batchCtoLEM",a+"_CtoLEM",n,2*n,!0),zt(t,a+"_batchToJacobian",a+"_toJacobian",2*n,3*n,!0),Tt(t,a,a+"_multiexp",a+"_add",3*n),Tt(t,a,a+"_multiexpAffine",a+"_addMixed",2*n),Gt(t,a+"_timesScalar",3*n,a+"_add",a+"_double",a+"_sub",a+"_copy",a+"_zero"),Gt(t,a+"_timesScalarAffine",2*n,a+"_addMixed",a+"_double",a+"_subMixed",a+"_copyAffine",a+"_zero"),t.exportFunction(a+"_isZero"),t.exportFunction(a+"_isZeroAffine"),t.exportFunction(a+"_eq"),t.exportFunction(a+"_eqMixed"),t.exportFunction(a+"_eqAffine"),t.exportFunction(a+"_copy"),t.exportFunction(a+"_copyAffine"),t.exportFunction(a+"_zero"),t.exportFunction(a+"_zeroAffine"),t.exportFunction(a+"_double"),t.exportFunction(a+"_doubleAffine"),t.exportFunction(a+"_add"),t.exportFunction(a+"_addMixed"),t.exportFunction(a+"_addAffine"),t.exportFunction(a+"_neg"),t.exportFunction(a+"_negAffine"),t.exportFunction(a+"_sub"),t.exportFunction(a+"_subMixed"),t.exportFunction(a+"_subAffine"),t.exportFunction(a+"_fromMontgomery"),t.exportFunction(a+"_fromMontgomeryAffine"),t.exportFunction(a+"_toMontgomery"),t.exportFunction(a+"_toMontgomeryAffine"),t.exportFunction(a+"_timesScalar"),t.exportFunction(a+"_timesScalarAffine"),t.exportFunction(a+"_normalize"),t.exportFunction(a+"_LEMtoU"),t.exportFunction(a+"_LEMtoC"),t.exportFunction(a+"_UtoLEM"),t.exportFunction(a+"_CtoLEM"),t.exportFunction(a+"_batchLEMtoU"),t.exportFunction(a+"_batchLEMtoC"),t.exportFunction(a+"_batchUtoLEM"),t.exportFunction(a+"_batchCtoLEM"),t.exportFunction(a+"_toAffine"),t.exportFunction(a+"_toJacobian"),t.exportFunction(a+"_batchToAffine"),t.exportFunction(a+"_batchToJacobian"),t.exportFunction(a+"_inCurve"),t.exportFunction(a+"_inCurveAffine"),a};const{isOdd:Ut,modInv:Qt,modPow:kt}=Y,Rt=V;var Nt=function(t,a,e,o,i){const n=8*t.modules[o].n64,l=8*t.modules[e].n64,c=t.modules[o].q;let s=c-1n,r=0;for(;!Ut(s);)r++,s>>=1n;let d=2n;for(;1n===kt(d,c>>1n,c);)d+=1n;const u=new Array(r+1);u[r]=kt(d,s,c);let _=r-1;for(;_>=0;)u[_]=kt(u[_+1],2n,c),_--;const g=[],f=(1n<>e);return a}const x=Array(256);for(let t=0;t<256;t++)x[t]=F(t);const I=t.alloc(x);function B(){const e=t.addFunction(a+"_fft");e.addParam("px","i32"),e.addParam("n","i32"),e.addLocal("bits","i32");const i=e.getCodeBuilder(),l=i.i32_const(t.alloc(n));e.addCode(i.setLocal("bits",i.call(a+"__log2",i.getLocal("n"))),i.call(o+"_one",l),i.call(a+"_rawfft",i.getLocal("px"),i.getLocal("bits"),i.i32_const(0),l))}!function(){const e=t.addFunction(a+"__rev");e.addParam("x","i32"),e.addParam("bits","i32"),e.setReturnType("i32");const o=e.getCodeBuilder();e.addCode(o.i32_rotl(o.i32_add(o.i32_add(o.i32_shl(o.i32_load8_u(o.i32_and(o.getLocal("x"),o.i32_const(255)),I,0),o.i32_const(24)),o.i32_shl(o.i32_load8_u(o.i32_and(o.i32_shr_u(o.getLocal("x"),o.i32_const(8)),o.i32_const(255)),I,0),o.i32_const(16))),o.i32_add(o.i32_shl(o.i32_load8_u(o.i32_and(o.i32_shr_u(o.getLocal("x"),o.i32_const(16)),o.i32_const(255)),I,0),o.i32_const(8)),o.i32_load8_u(o.i32_and(o.i32_shr_u(o.getLocal("x"),o.i32_const(24)),o.i32_const(255)),I,0))),o.getLocal("bits")))}(),function(){const o=t.addFunction(a+"__reversePermutation");o.addParam("px","i32"),o.addParam("bits","i32"),o.addLocal("n","i32"),o.addLocal("i","i32"),o.addLocal("ri","i32"),o.addLocal("idx1","i32"),o.addLocal("idx2","i32");const i=o.getCodeBuilder(),n=i.i32_const(t.alloc(l));o.addCode(i.setLocal("n",i.i32_shl(i.i32_const(1),i.getLocal("bits"))),i.setLocal("i",i.i32_const(0)),i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("i"),i.getLocal("n"))),i.setLocal("idx1",i.i32_add(i.getLocal("px"),i.i32_mul(i.getLocal("i"),i.i32_const(l)))),i.setLocal("ri",i.call(a+"__rev",i.getLocal("i"),i.getLocal("bits"))),i.setLocal("idx2",i.i32_add(i.getLocal("px"),i.i32_mul(i.getLocal("ri"),i.i32_const(l)))),i.if(i.i32_lt_u(i.getLocal("i"),i.getLocal("ri")),[...i.call(e+"_copy",i.getLocal("idx1"),n),...i.call(e+"_copy",i.getLocal("idx2"),i.getLocal("idx1")),...i.call(e+"_copy",n,i.getLocal("idx2"))]),i.setLocal("i",i.i32_add(i.getLocal("i"),i.i32_const(1))),i.br(0))))}(),function(){const n=t.addFunction(a+"__fftFinal");n.addParam("px","i32"),n.addParam("bits","i32"),n.addParam("reverse","i32"),n.addParam("mulFactor","i32"),n.addLocal("n","i32"),n.addLocal("ndiv2","i32"),n.addLocal("pInv2","i32"),n.addLocal("i","i32"),n.addLocal("mask","i32"),n.addLocal("idx1","i32"),n.addLocal("idx2","i32");const c=n.getCodeBuilder(),s=c.i32_const(t.alloc(l));n.addCode(c.if(c.i32_and(c.i32_eqz(c.getLocal("reverse")),c.call(o+"_isOne",c.getLocal("mulFactor"))),c.ret([])),c.setLocal("n",c.i32_shl(c.i32_const(1),c.getLocal("bits"))),c.setLocal("mask",c.i32_sub(c.getLocal("n"),c.i32_const(1))),c.setLocal("i",c.i32_const(1)),c.setLocal("ndiv2",c.i32_shr_u(c.getLocal("n"),c.i32_const(1))),c.block(c.loop(c.br_if(1,c.i32_ge_u(c.getLocal("i"),c.getLocal("ndiv2"))),c.setLocal("idx1",c.i32_add(c.getLocal("px"),c.i32_mul(c.getLocal("i"),c.i32_const(l)))),c.setLocal("idx2",c.i32_add(c.getLocal("px"),c.i32_mul(c.i32_sub(c.getLocal("n"),c.getLocal("i")),c.i32_const(l)))),c.if(c.getLocal("reverse"),c.if(c.call(o+"_isOne",c.getLocal("mulFactor")),[...c.call(e+"_copy",c.getLocal("idx1"),s),...c.call(e+"_copy",c.getLocal("idx2"),c.getLocal("idx1")),...c.call(e+"_copy",s,c.getLocal("idx2"))],[...c.call(e+"_copy",c.getLocal("idx1"),s),...c.call(i,c.getLocal("idx2"),c.getLocal("mulFactor"),c.getLocal("idx1")),...c.call(i,s,c.getLocal("mulFactor"),c.getLocal("idx2"))]),c.if(c.call(o+"_isOne",c.getLocal("mulFactor")),[],[...c.call(i,c.getLocal("idx1"),c.getLocal("mulFactor"),c.getLocal("idx1")),...c.call(i,c.getLocal("idx2"),c.getLocal("mulFactor"),c.getLocal("idx2"))])),c.setLocal("i",c.i32_add(c.getLocal("i"),c.i32_const(1))),c.br(0))),c.if(c.call(o+"_isOne",c.getLocal("mulFactor")),[],[...c.call(i,c.getLocal("px"),c.getLocal("mulFactor"),c.getLocal("px")),...c.setLocal("idx2",c.i32_add(c.getLocal("px"),c.i32_mul(c.getLocal("ndiv2"),c.i32_const(l)))),...c.call(i,c.getLocal("idx2"),c.getLocal("mulFactor"),c.getLocal("idx2"))]))}(),function(){const c=t.addFunction(a+"_rawfft");c.addParam("px","i32"),c.addParam("bits","i32"),c.addParam("reverse","i32"),c.addParam("mulFactor","i32"),c.addLocal("s","i32"),c.addLocal("k","i32"),c.addLocal("j","i32"),c.addLocal("m","i32"),c.addLocal("mdiv2","i32"),c.addLocal("n","i32"),c.addLocal("pwm","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l)),u=s.i32_const(t.alloc(l));c.addCode(s.call(a+"__reversePermutation",s.getLocal("px"),s.getLocal("bits")),s.setLocal("n",s.i32_shl(s.i32_const(1),s.getLocal("bits"))),s.setLocal("s",s.i32_const(1)),s.block(s.loop(s.br_if(1,s.i32_gt_u(s.getLocal("s"),s.getLocal("bits"))),s.setLocal("m",s.i32_shl(s.i32_const(1),s.getLocal("s"))),s.setLocal("pwm",s.i32_add(s.i32_const(h),s.i32_mul(s.getLocal("s"),s.i32_const(n)))),s.setLocal("k",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_ge_u(s.getLocal("k"),s.getLocal("n"))),s.call(o+"_one",r),s.setLocal("mdiv2",s.i32_shr_u(s.getLocal("m"),s.i32_const(1))),s.setLocal("j",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_ge_u(s.getLocal("j"),s.getLocal("mdiv2"))),s.setLocal("idx1",s.i32_add(s.getLocal("px"),s.i32_mul(s.i32_add(s.getLocal("k"),s.getLocal("j")),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("idx1"),s.i32_mul(s.getLocal("mdiv2"),s.i32_const(l)))),s.call(i,s.getLocal("idx2"),r,d),s.call(e+"_copy",s.getLocal("idx1"),u),s.call(e+"_add",u,d,s.getLocal("idx1")),s.call(e+"_sub",u,d,s.getLocal("idx2")),s.call(o+"_mul",r,s.getLocal("pwm"),r),s.setLocal("j",s.i32_add(s.getLocal("j"),s.i32_const(1))),s.br(0))),s.setLocal("k",s.i32_add(s.getLocal("k"),s.getLocal("m"))),s.br(0))),s.setLocal("s",s.i32_add(s.getLocal("s"),s.i32_const(1))),s.br(0))),s.call(a+"__fftFinal",s.getLocal("px"),s.getLocal("bits"),s.getLocal("reverse"),s.getLocal("mulFactor")))}(),function(){const e=t.addFunction(a+"__log2");e.addParam("n","i32"),e.setReturnType("i32"),e.addLocal("bits","i32"),e.addLocal("aux","i32");const o=e.getCodeBuilder();e.addCode(o.setLocal("aux",o.i32_shr_u(o.getLocal("n"),o.i32_const(1)))),e.addCode(o.setLocal("bits",o.i32_const(0))),e.addCode(o.block(o.loop(o.br_if(1,o.i32_eqz(o.getLocal("aux"))),o.setLocal("aux",o.i32_shr_u(o.getLocal("aux"),o.i32_const(1))),o.setLocal("bits",o.i32_add(o.getLocal("bits"),o.i32_const(1))),o.br(0)))),e.addCode(o.if(o.i32_ne(o.getLocal("n"),o.i32_shl(o.i32_const(1),o.getLocal("bits"))),o.unreachable())),e.addCode(o.if(o.i32_gt_u(o.getLocal("bits"),o.i32_const(r)),o.unreachable())),e.addCode(o.getLocal("bits"))}(),B(),function(){const e=t.addFunction(a+"_ifft");e.addParam("px","i32"),e.addParam("n","i32"),e.addLocal("bits","i32"),e.addLocal("pInv2","i32");const o=e.getCodeBuilder();e.addCode(o.setLocal("bits",o.call(a+"__log2",o.getLocal("n"))),o.setLocal("pInv2",o.i32_add(o.i32_const(L),o.i32_mul(o.getLocal("bits"),o.i32_const(n)))),o.call(a+"_rawfft",o.getLocal("px"),o.getLocal("bits"),o.i32_const(1),o.getLocal("pInv2")))}(),function(){const c=t.addFunction(a+"_fftJoin");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l)),u=s.i32_const(t.alloc(l));c.addCode(s.call(o+"_copy",s.getLocal("first"),r),s.setLocal("i",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("n"))),s.setLocal("idx1",s.i32_add(s.getLocal("pBuff1"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("pBuff2"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.call(i,s.getLocal("idx2"),r,d),s.call(e+"_copy",s.getLocal("idx1"),u),s.call(e+"_add",u,d,s.getLocal("idx1")),s.call(e+"_sub",u,d,s.getLocal("idx2")),s.call(o+"_mul",r,s.getLocal("inc"),r),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),function(){const c=t.addFunction(a+"_fftJoinExt");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addParam("totalBits","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("pShiftToM","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l));c.addCode(s.setLocal("pShiftToM",s.i32_add(s.i32_const(A),s.i32_mul(s.getLocal("totalBits"),s.i32_const(n)))),s.call(o+"_copy",s.getLocal("first"),r),s.setLocal("i",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("n"))),s.setLocal("idx1",s.i32_add(s.getLocal("pBuff1"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("pBuff2"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.call(e+"_add",s.getLocal("idx1"),s.getLocal("idx2"),d),s.call(i,s.getLocal("idx2"),s.getLocal("pShiftToM"),s.getLocal("idx2")),s.call(e+"_add",s.getLocal("idx1"),s.getLocal("idx2"),s.getLocal("idx2")),s.call(i,s.getLocal("idx2"),r,s.getLocal("idx2")),s.call(e+"_copy",d,s.getLocal("idx1")),s.call(o+"_mul",r,s.getLocal("inc"),r),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),function(){const c=t.addFunction(a+"_fftJoinExtInv");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addParam("totalBits","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("pShiftToM","i32"),c.addLocal("pSConst","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l));c.addCode(s.setLocal("pShiftToM",s.i32_add(s.i32_const(A),s.i32_mul(s.getLocal("totalBits"),s.i32_const(n)))),s.setLocal("pSConst",s.i32_add(s.i32_const(C),s.i32_mul(s.getLocal("totalBits"),s.i32_const(n)))),s.call(o+"_copy",s.getLocal("first"),r),s.setLocal("i",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("n"))),s.setLocal("idx1",s.i32_add(s.getLocal("pBuff1"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("pBuff2"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.call(i,s.getLocal("idx2"),r,d),s.call(e+"_sub",s.getLocal("idx1"),d,s.getLocal("idx2")),s.call(i,s.getLocal("idx2"),s.getLocal("pSConst"),s.getLocal("idx2")),s.call(i,s.getLocal("idx1"),s.getLocal("pShiftToM"),s.getLocal("idx1")),s.call(e+"_sub",d,s.getLocal("idx1"),s.getLocal("idx1")),s.call(i,s.getLocal("idx1"),s.getLocal("pSConst"),s.getLocal("idx1")),s.call(o+"_mul",r,s.getLocal("inc"),r),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),function(){const c=t.addFunction(a+"_fftMix");c.addParam("pBuff","i32"),c.addParam("n","i32"),c.addParam("exp","i32"),c.addLocal("nGroups","i32"),c.addLocal("nPerGroup","i32"),c.addLocal("nPerGroupDiv2","i32"),c.addLocal("pairOffset","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("j","i32"),c.addLocal("pwm","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l)),u=s.i32_const(t.alloc(l));c.addCode(s.setLocal("nPerGroup",s.i32_shl(s.i32_const(1),s.getLocal("exp"))),s.setLocal("nPerGroupDiv2",s.i32_shr_u(s.getLocal("nPerGroup"),s.i32_const(1))),s.setLocal("nGroups",s.i32_shr_u(s.getLocal("n"),s.getLocal("exp"))),s.setLocal("pairOffset",s.i32_mul(s.getLocal("nPerGroupDiv2"),s.i32_const(l))),s.setLocal("pwm",s.i32_add(s.i32_const(h),s.i32_mul(s.getLocal("exp"),s.i32_const(n)))),s.setLocal("i",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("nGroups"))),s.call(o+"_one",r),s.setLocal("j",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("j"),s.getLocal("nPerGroupDiv2"))),s.setLocal("idx1",s.i32_add(s.getLocal("pBuff"),s.i32_mul(s.i32_add(s.i32_mul(s.getLocal("i"),s.getLocal("nPerGroup")),s.getLocal("j")),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("idx1"),s.getLocal("pairOffset"))),s.call(i,s.getLocal("idx2"),r,d),s.call(e+"_copy",s.getLocal("idx1"),u),s.call(e+"_add",u,d,s.getLocal("idx1")),s.call(e+"_sub",u,d,s.getLocal("idx2")),s.call(o+"_mul",r,s.getLocal("pwm"),r),s.setLocal("j",s.i32_add(s.getLocal("j"),s.i32_const(1))),s.br(0))),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),function(){const o=t.addFunction(a+"_fftFinal");o.addParam("pBuff","i32"),o.addParam("n","i32"),o.addParam("factor","i32"),o.addLocal("idx1","i32"),o.addLocal("idx2","i32"),o.addLocal("i","i32"),o.addLocal("ndiv2","i32");const n=o.getCodeBuilder(),c=n.i32_const(t.alloc(l));o.addCode(n.setLocal("ndiv2",n.i32_shr_u(n.getLocal("n"),n.i32_const(1))),n.if(n.i32_and(n.getLocal("n"),n.i32_const(1)),n.call(i,n.i32_add(n.getLocal("pBuff"),n.i32_mul(n.getLocal("ndiv2"),n.i32_const(l))),n.getLocal("factor"),n.i32_add(n.getLocal("pBuff"),n.i32_mul(n.getLocal("ndiv2"),n.i32_const(l))))),n.setLocal("i",n.i32_const(0)),n.block(n.loop(n.br_if(1,n.i32_ge_u(n.getLocal("i"),n.getLocal("ndiv2"))),n.setLocal("idx1",n.i32_add(n.getLocal("pBuff"),n.i32_mul(n.getLocal("i"),n.i32_const(l)))),n.setLocal("idx2",n.i32_add(n.getLocal("pBuff"),n.i32_mul(n.i32_sub(n.i32_sub(n.getLocal("n"),n.i32_const(1)),n.getLocal("i")),n.i32_const(l)))),n.call(i,n.getLocal("idx2"),n.getLocal("factor"),c),n.call(i,n.getLocal("idx1"),n.getLocal("factor"),n.getLocal("idx2")),n.call(e+"_copy",c,n.getLocal("idx1")),n.setLocal("i",n.i32_add(n.getLocal("i"),n.i32_const(1))),n.br(0))))}(),function(){const c=t.addFunction(a+"_prepareLagrangeEvaluation");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addParam("totalBits","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("pShiftToM","i32"),c.addLocal("pSConst","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l));c.addCode(s.setLocal("pShiftToM",s.i32_add(s.i32_const(A),s.i32_mul(s.getLocal("totalBits"),s.i32_const(n)))),s.setLocal("pSConst",s.i32_add(s.i32_const(C),s.i32_mul(s.getLocal("totalBits"),s.i32_const(n)))),s.call(o+"_copy",s.getLocal("first"),r),s.setLocal("i",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("n"))),s.setLocal("idx1",s.i32_add(s.getLocal("pBuff1"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("pBuff2"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.call(i,s.getLocal("idx1"),s.getLocal("pShiftToM"),d),s.call(e+"_sub",s.getLocal("idx2"),d,d),s.call(e+"_sub",s.getLocal("idx1"),s.getLocal("idx2"),s.getLocal("idx2")),s.call(i,d,s.getLocal("pSConst"),s.getLocal("idx1")),s.call(i,s.getLocal("idx2"),r,s.getLocal("idx2")),s.call(o+"_mul",r,s.getLocal("inc"),r),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),t.exportFunction(a+"_fft"),t.exportFunction(a+"_ifft"),t.exportFunction(a+"_rawfft"),t.exportFunction(a+"_fftJoin"),t.exportFunction(a+"_fftJoinExt"),t.exportFunction(a+"_fftJoinExtInv"),t.exportFunction(a+"_fftMix"),t.exportFunction(a+"_fftFinal"),t.exportFunction(a+"_prepareLagrangeEvaluation")},$t=function(t,a,e){const o=8*t.modules[e].n64;return function(){const i=t.addFunction(a+"_zero");i.addParam("px","i32"),i.addParam("n","i32"),i.addLocal("lastp","i32"),i.addLocal("p","i32");const n=i.getCodeBuilder();i.addCode(n.setLocal("p",n.getLocal("px")),n.setLocal("lastp",n.i32_add(n.getLocal("px"),n.i32_mul(n.getLocal("n"),n.i32_const(o)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("p"),n.getLocal("lastp"))),n.call(e+"_zero",n.getLocal("p")),n.setLocal("p",n.i32_add(n.getLocal("p"),n.i32_const(o))),n.br(0))))}(),function(){const i=t.addFunction(a+"_constructLC");i.addParam("ppolynomials","i32"),i.addParam("psignals","i32"),i.addParam("nSignals","i32"),i.addParam("pres","i32"),i.addLocal("i","i32"),i.addLocal("j","i32"),i.addLocal("pp","i32"),i.addLocal("ps","i32"),i.addLocal("pd","i32"),i.addLocal("ncoefs","i32");const n=i.getCodeBuilder(),l=n.i32_const(t.alloc(o));i.addCode(n.setLocal("i",n.i32_const(0)),n.setLocal("pp",n.getLocal("ppolynomials")),n.setLocal("ps",n.getLocal("psignals")),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("i"),n.getLocal("nSignals"))),n.setLocal("ncoefs",n.i32_load(n.getLocal("pp"))),n.setLocal("pp",n.i32_add(n.getLocal("pp"),n.i32_const(4))),n.setLocal("j",n.i32_const(0)),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("j"),n.getLocal("ncoefs"))),n.setLocal("pd",n.i32_add(n.getLocal("pres"),n.i32_mul(n.i32_load(n.getLocal("pp")),n.i32_const(o)))),n.setLocal("pp",n.i32_add(n.getLocal("pp"),n.i32_const(4))),n.call(e+"_mul",n.getLocal("ps"),n.getLocal("pp"),l),n.call(e+"_add",l,n.getLocal("pd"),n.getLocal("pd")),n.setLocal("pp",n.i32_add(n.getLocal("pp"),n.i32_const(o))),n.setLocal("j",n.i32_add(n.getLocal("j"),n.i32_const(1))),n.br(0))),n.setLocal("ps",n.i32_add(n.getLocal("ps"),n.i32_const(o))),n.setLocal("i",n.i32_add(n.getLocal("i"),n.i32_const(1))),n.br(0))))}(),t.exportFunction(a+"_zero"),t.exportFunction(a+"_constructLC"),a},Dt=function(t,a,e){const o=8*t.modules[e].n64;return function(){const i=t.addFunction(a+"_buildABC");i.addParam("pCoefs","i32"),i.addParam("nCoefs","i32"),i.addParam("pWitness","i32"),i.addParam("pA","i32"),i.addParam("pB","i32"),i.addParam("pC","i32"),i.addParam("offsetOut","i32"),i.addParam("nOut","i32"),i.addParam("offsetWitness","i32"),i.addParam("nWitness","i32"),i.addLocal("it","i32"),i.addLocal("ita","i32"),i.addLocal("itb","i32"),i.addLocal("last","i32"),i.addLocal("m","i32"),i.addLocal("c","i32"),i.addLocal("s","i32"),i.addLocal("pOut","i32");const n=i.getCodeBuilder(),l=n.i32_const(t.alloc(o));i.addCode(n.setLocal("ita",n.getLocal("pA")),n.setLocal("itb",n.getLocal("pB")),n.setLocal("last",n.i32_add(n.getLocal("pA"),n.i32_mul(n.getLocal("nOut"),n.i32_const(o)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(e+"_zero",n.getLocal("ita")),n.call(e+"_zero",n.getLocal("itb")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(o))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(o))),n.br(0))),n.setLocal("it",n.getLocal("pCoefs")),n.setLocal("last",n.i32_add(n.getLocal("pCoefs"),n.i32_mul(n.getLocal("nCoefs"),n.i32_const(o+12)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("it"),n.getLocal("last"))),n.setLocal("s",n.i32_load(n.getLocal("it"),8)),n.if(n.i32_or(n.i32_lt_u(n.getLocal("s"),n.getLocal("offsetWitness")),n.i32_ge_u(n.getLocal("s"),n.i32_add(n.getLocal("offsetWitness"),n.getLocal("nWitness")))),[...n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(o+12))),...n.br(1)]),n.setLocal("m",n.i32_load(n.getLocal("it"))),n.if(n.i32_eq(n.getLocal("m"),n.i32_const(0)),n.setLocal("pOut",n.getLocal("pA")),n.if(n.i32_eq(n.getLocal("m"),n.i32_const(1)),n.setLocal("pOut",n.getLocal("pB")),[...n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(o+12))),...n.br(1)])),n.setLocal("c",n.i32_load(n.getLocal("it"),4)),n.if(n.i32_or(n.i32_lt_u(n.getLocal("c"),n.getLocal("offsetOut")),n.i32_ge_u(n.getLocal("c"),n.i32_add(n.getLocal("offsetOut"),n.getLocal("nOut")))),[...n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(o+12))),...n.br(1)]),n.setLocal("pOut",n.i32_add(n.getLocal("pOut"),n.i32_mul(n.i32_sub(n.getLocal("c"),n.getLocal("offsetOut")),n.i32_const(o)))),n.call(e+"_mul",n.i32_add(n.getLocal("pWitness"),n.i32_mul(n.i32_sub(n.getLocal("s"),n.getLocal("offsetWitness")),n.i32_const(o))),n.i32_add(n.getLocal("it"),n.i32_const(12)),l),n.call(e+"_add",n.getLocal("pOut"),l,n.getLocal("pOut")),n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(o+12))),n.br(0))),n.setLocal("ita",n.getLocal("pA")),n.setLocal("itb",n.getLocal("pB")),n.setLocal("it",n.getLocal("pC")),n.setLocal("last",n.i32_add(n.getLocal("pA"),n.i32_mul(n.getLocal("nOut"),n.i32_const(o)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(e+"_mul",n.getLocal("ita"),n.getLocal("itb"),n.getLocal("it")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(o))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(o))),n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(o))),n.br(0))))}(),function(){const i=t.addFunction(a+"_joinABC");i.addParam("pA","i32"),i.addParam("pB","i32"),i.addParam("pC","i32"),i.addParam("n","i32"),i.addParam("pP","i32"),i.addLocal("ita","i32"),i.addLocal("itb","i32"),i.addLocal("itc","i32"),i.addLocal("itp","i32"),i.addLocal("last","i32");const n=i.getCodeBuilder(),l=n.i32_const(t.alloc(o));i.addCode(n.setLocal("ita",n.getLocal("pA")),n.setLocal("itb",n.getLocal("pB")),n.setLocal("itc",n.getLocal("pC")),n.setLocal("itp",n.getLocal("pP")),n.setLocal("last",n.i32_add(n.getLocal("pA"),n.i32_mul(n.getLocal("n"),n.i32_const(o)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(e+"_mul",n.getLocal("ita"),n.getLocal("itb"),l),n.call(e+"_sub",l,n.getLocal("itc"),n.getLocal("itp")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(o))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(o))),n.setLocal("itc",n.i32_add(n.getLocal("itc"),n.i32_const(o))),n.setLocal("itp",n.i32_add(n.getLocal("itp"),n.i32_const(o))),n.br(0))))}(),function(){const i=t.addFunction(a+"_batchAdd");i.addParam("pa","i32"),i.addParam("pb","i32"),i.addParam("n","i32"),i.addParam("pr","i32"),i.addLocal("ita","i32"),i.addLocal("itb","i32"),i.addLocal("itr","i32"),i.addLocal("last","i32");const n=i.getCodeBuilder();i.addCode(n.setLocal("ita",n.getLocal("pa")),n.setLocal("itb",n.getLocal("pb")),n.setLocal("itr",n.getLocal("pr")),n.setLocal("last",n.i32_add(n.getLocal("pa"),n.i32_mul(n.getLocal("n"),n.i32_const(o)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(e+"_add",n.getLocal("ita"),n.getLocal("itb"),n.getLocal("itr")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(o))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(o))),n.setLocal("itr",n.i32_add(n.getLocal("itr"),n.i32_const(o))),n.br(0))))}(),t.exportFunction(a+"_buildABC"),t.exportFunction(a+"_joinABC"),t.exportFunction(a+"_batchAdd"),a},jt=function(t,a,e,o,i,n,l,c){const s=t.addFunction(a);s.addParam("pIn","i32"),s.addParam("n","i32"),s.addParam("pFirst","i32"),s.addParam("pInc","i32"),s.addParam("pOut","i32"),s.addLocal("pOldFree","i32"),s.addLocal("i","i32"),s.addLocal("pFrom","i32"),s.addLocal("pTo","i32");const r=s.getCodeBuilder(),d=r.i32_const(t.alloc(l));s.addCode(r.setLocal("pFrom",r.getLocal("pIn")),r.setLocal("pTo",r.getLocal("pOut"))),s.addCode(r.call(o+"_copy",r.getLocal("pFirst"),d)),s.addCode(r.setLocal("i",r.i32_const(0)),r.block(r.loop(r.br_if(1,r.i32_eq(r.getLocal("i"),r.getLocal("n"))),r.call(c,r.getLocal("pFrom"),d,r.getLocal("pTo")),r.setLocal("pFrom",r.i32_add(r.getLocal("pFrom"),r.i32_const(i))),r.setLocal("pTo",r.i32_add(r.getLocal("pTo"),r.i32_const(n))),r.call(o+"_mul",d,r.getLocal("pInc"),d),r.setLocal("i",r.i32_add(r.getLocal("i"),r.i32_const(1))),r.br(0)))),t.exportFunction(a)};const Vt=V,Kt=Ct,Ht=It,Zt=St,Wt=Ot,Yt=Mt,Jt=Nt,Xt=$t,ta=Dt,aa=jt,{bitLength:ea,modInv:oa,isOdd:ia,isNegative:na}=Y;const la=V,ca=Ct,sa=It,ra=St,da=Ot,ua=Mt,_a=Nt,ga=$t,fa=Dt,ha=jt,{bitLength:pa,isOdd:ma,isNegative:La}=Y;var ba=function(t,a){const e=a||"bn128";if(t.modules[e])return e;const o=21888242871839275222246405745257275088696311157297823662689037894645226208583n,i=21888242871839275222246405745257275088548364400416034343698204186575808495617n,n=Math.floor((ea(o-1n)-1)/64)+1,l=8*n,c=l,s=l,r=2*s,d=12*s,u=t.alloc(Vt.bigInt2BytesLE(i,c)),_=Kt(t,o,"f1m");Ht(t,i,"fr","frm");const g=t.alloc(Vt.bigInt2BytesLE(b(3n),s)),f=Yt(t,"g1m","f1m",g);Jt(t,"frm","frm","frm","frm_mul"),Xt(t,"pol","frm"),ta(t,"qap","frm");const h=Zt(t,"f1m_neg","f2m","f1m"),p=t.alloc([...Vt.bigInt2BytesLE(b(19485874751759354771024239261021720505790618469301721065564631296452457478373n),s),...Vt.bigInt2BytesLE(b(266929791119991161246907387137283842545076965332900288569378510910307636690n),s)]),m=Yt(t,"g2m","f2m",p);function L(a,e){const o=t.addFunction(a);o.addParam("pG","i32"),o.addParam("pFr","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),n=i.i32_const(t.alloc(l));o.addCode(i.call("frm_fromMontgomery",i.getLocal("pFr"),n),i.call(e,i.getLocal("pG"),n,i.i32_const(l),i.getLocal("pr"))),t.exportFunction(a)}function b(t){return BigInt(t)*(1n<0n;)ia(a)?e.push(1):e.push(0),a>>=1n;return e}(29793968203157093288n),T=t.alloc(z),M=3*r,U=z.length-1,Q=z.reduce(((t,a)=>t+(0!=a?1:0)),0),k=6*l,R=3*l*2+(Q+U+1)*M;t.modules[e]={n64:n,pG1gen:y,pG1zero:C,pG1b:g,pG2gen:x,pG2zero:B,pG2b:p,pq:t.modules.f1m.pq,pr:u,pOneT:E,prePSize:k,preQSize:R,r:i.toString(),q:o.toString()};const N=4965661367192848881n;function $(a){const i=[[[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n]],[[1n,0n],[8376118865763821496583973867626364092589906065868298776909617916018768340080n,16469823323077808223889137241176536799009286646108169935659301613961712198316n],[21888242871839275220042445260109153167277707414472061641714758635765020556617n,0n],[11697423496358154304825782922584725312912383441159505038794027105778954184319n,303847389135065887422783454877609941456349188919719272345083954437860409601n],[21888242871839275220042445260109153167277707414472061641714758635765020556616n,0n],[3321304630594332808241809054958361220322477375291206261884409189760185844239n,5722266937896532885780051958958348231143373700109372999374820235121374419868n],[21888242871839275222246405745257275088696311157297823662689037894645226208582n,0n],[13512124006075453725662431877630910996106405091429524885779419978626457868503n,5418419548761466998357268504080738289687024511189653727029736280683514010267n],[2203960485148121921418603742825762020974279258880205651966n,0n],[10190819375481120917420622822672549775783927716138318623895010788866272024264n,21584395482704209334823622290379665147239961968378104390343953940207365798982n],[2203960485148121921418603742825762020974279258880205651967n,0n],[18566938241244942414004596690298913868373833782006617400804628704885040364344n,16165975933942742336466353786298926857552937457188450663314217659523851788715n]]],n=[[[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n]],[[1n,0n],[21575463638280843010398324269430826099269044274347216827212613867836435027261n,10307601595873709700152284273816112264069230130616436755625194854815875713954n],[21888242871839275220042445260109153167277707414472061641714758635765020556616n,0n],[3772000881919853776433695186713858239009073593817195771773381919316419345261n,2236595495967245188281701248203181795121068902605861227855261137820944008926n],[2203960485148121921418603742825762020974279258880205651966n,0n],[18429021223477853657660792034369865839114504446431234726392080002137598044644n,9344045779998320333812420223237981029506012124075525679208581902008406485703n]],[[1n,0n],[2581911344467009335267311115468803099551665605076196740867805258568234346338n,19937756971775647987995932169929341994314640652964949448313374472400716661030n],[2203960485148121921418603742825762020974279258880205651966n,0n],[5324479202449903542726783395506214481928257762400643279780343368557297135718n,16208900380737693084919495127334387981393726419856888799917914180988844123039n],[21888242871839275220042445260109153167277707414472061641714758635765020556616n,0n],[13981852324922362344252311234282257507216387789820983642040889267519694726527n,7629828391165209371577384193250820201684255241773809077146787135900891633097n]]],l=t.addFunction(e+"__frobeniusMap"+a);l.addParam("x","i32"),l.addParam("r","i32");const c=l.getCodeBuilder();for(let e=0;e<6;e++){const o=0==e?c.getLocal("x"):c.i32_add(c.getLocal("x"),c.i32_const(e*r)),u=o,g=c.i32_add(c.getLocal("x"),c.i32_const(e*r+s)),f=0==e?c.getLocal("r"):c.i32_add(c.getLocal("r"),c.i32_const(e*r)),p=f,m=c.i32_add(c.getLocal("r"),c.i32_const(e*r+s)),L=d(i[Math.floor(e/3)][a%12],n[e%3][a%6]),w=t.alloc([...Vt.bigInt2BytesLE(b(L[0]),32),...Vt.bigInt2BytesLE(b(L[1]),32)]);a%2==1?l.addCode(c.call(_+"_copy",u,p),c.call(_+"_neg",g,m),c.call(h+"_mul",f,c.i32_const(w),f)):l.addCode(c.call(h+"_mul",o,c.i32_const(w),f))}function d(t,a){const e=BigInt(t[0]),i=BigInt(t[1]),n=BigInt(a[0]),l=BigInt(a[1]),c=[(e*n-i*l)%o,(e*l+i*n)%o];return na(c[0])&&(c[0]=c[0]+o),c}}function D(a,o){const i=function(t){let a=t;const e=[];for(;a>0n;){if(ia(a)){const t=2-Number(a%4n);e.push(t),a-=BigInt(t)}else e.push(0);a>>=1n}return e}(a).map((t=>-1==t?255:t)),n=t.alloc(i),l=t.addFunction(e+"__cyclotomicExp_"+o);l.addParam("x","i32"),l.addParam("r","i32"),l.addLocal("bit","i32"),l.addLocal("i","i32");const c=l.getCodeBuilder(),s=c.getLocal("x"),r=c.getLocal("r"),u=c.i32_const(t.alloc(d));l.addCode(c.call(G+"_conjugate",s,u),c.call(G+"_one",r),c.if(c.teeLocal("bit",c.i32_load8_s(c.i32_const(i.length-1),n)),c.if(c.i32_eq(c.getLocal("bit"),c.i32_const(1)),c.call(G+"_mul",r,s,r),c.call(G+"_mul",r,u,r))),c.setLocal("i",c.i32_const(i.length-2)),c.block(c.loop(c.call(e+"__cyclotomicSquare",r,r),c.if(c.teeLocal("bit",c.i32_load8_s(c.getLocal("i"),n)),c.if(c.i32_eq(c.getLocal("bit"),c.i32_const(1)),c.call(G+"_mul",r,s,r),c.call(G+"_mul",r,u,r))),c.br_if(1,c.i32_eqz(c.getLocal("i"))),c.setLocal("i",c.i32_sub(c.getLocal("i"),c.i32_const(1))),c.br(0))))}function j(){!function(){const a=t.addFunction(e+"__cyclotomicSquare");a.addParam("x","i32"),a.addParam("r","i32");const o=a.getCodeBuilder(),i=o.getLocal("x"),n=o.i32_add(o.getLocal("x"),o.i32_const(r)),l=o.i32_add(o.getLocal("x"),o.i32_const(2*r)),c=o.i32_add(o.getLocal("x"),o.i32_const(3*r)),s=o.i32_add(o.getLocal("x"),o.i32_const(4*r)),d=o.i32_add(o.getLocal("x"),o.i32_const(5*r)),u=o.getLocal("r"),_=o.i32_add(o.getLocal("r"),o.i32_const(r)),g=o.i32_add(o.getLocal("r"),o.i32_const(2*r)),f=o.i32_add(o.getLocal("r"),o.i32_const(3*r)),p=o.i32_add(o.getLocal("r"),o.i32_const(4*r)),m=o.i32_add(o.getLocal("r"),o.i32_const(5*r)),L=o.i32_const(t.alloc(r)),b=o.i32_const(t.alloc(r)),w=o.i32_const(t.alloc(r)),y=o.i32_const(t.alloc(r)),A=o.i32_const(t.alloc(r)),C=o.i32_const(t.alloc(r)),F=o.i32_const(t.alloc(r)),x=o.i32_const(t.alloc(r));a.addCode(o.call(h+"_mul",i,s,F),o.call(h+"_mul",s,o.i32_const(v),L),o.call(h+"_add",i,L,L),o.call(h+"_add",i,s,x),o.call(h+"_mul",x,L,L),o.call(h+"_mul",o.i32_const(v),F,x),o.call(h+"_add",F,x,x),o.call(h+"_sub",L,x,L),o.call(h+"_add",F,F,b),o.call(h+"_mul",c,l,F),o.call(h+"_mul",l,o.i32_const(v),w),o.call(h+"_add",c,w,w),o.call(h+"_add",c,l,x),o.call(h+"_mul",x,w,w),o.call(h+"_mul",o.i32_const(v),F,x),o.call(h+"_add",F,x,x),o.call(h+"_sub",w,x,w),o.call(h+"_add",F,F,y),o.call(h+"_mul",n,d,F),o.call(h+"_mul",d,o.i32_const(v),A),o.call(h+"_add",n,A,A),o.call(h+"_add",n,d,x),o.call(h+"_mul",x,A,A),o.call(h+"_mul",o.i32_const(v),F,x),o.call(h+"_add",F,x,x),o.call(h+"_sub",A,x,A),o.call(h+"_add",F,F,C),o.call(h+"_sub",L,i,u),o.call(h+"_add",u,u,u),o.call(h+"_add",L,u,u),o.call(h+"_add",b,s,p),o.call(h+"_add",p,p,p),o.call(h+"_add",b,p,p),o.call(h+"_mul",C,o.i32_const(P),x),o.call(h+"_add",x,c,f),o.call(h+"_add",f,f,f),o.call(h+"_add",x,f,f),o.call(h+"_sub",A,l,g),o.call(h+"_add",g,g,g),o.call(h+"_add",A,g,g),o.call(h+"_sub",w,n,_),o.call(h+"_add",_,_,_),o.call(h+"_add",w,_,_),o.call(h+"_add",y,d,m),o.call(h+"_add",m,m,m),o.call(h+"_add",y,m,m))}(),D(N,"w0");const a=t.addFunction(e+"__finalExponentiationLastChunk");a.addParam("x","i32"),a.addParam("r","i32");const o=a.getCodeBuilder(),i=o.getLocal("x"),n=o.getLocal("r"),l=o.i32_const(t.alloc(d)),c=o.i32_const(t.alloc(d)),s=o.i32_const(t.alloc(d)),u=o.i32_const(t.alloc(d)),_=o.i32_const(t.alloc(d)),g=o.i32_const(t.alloc(d)),f=o.i32_const(t.alloc(d)),p=o.i32_const(t.alloc(d)),m=o.i32_const(t.alloc(d)),L=o.i32_const(t.alloc(d)),b=o.i32_const(t.alloc(d)),w=o.i32_const(t.alloc(d)),y=o.i32_const(t.alloc(d)),A=o.i32_const(t.alloc(d)),C=o.i32_const(t.alloc(d)),F=o.i32_const(t.alloc(d)),x=o.i32_const(t.alloc(d)),I=o.i32_const(t.alloc(d)),B=o.i32_const(t.alloc(d)),E=o.i32_const(t.alloc(d)),S=o.i32_const(t.alloc(d));a.addCode(o.call(e+"__cyclotomicExp_w0",i,l),o.call(G+"_conjugate",l,l),o.call(e+"__cyclotomicSquare",l,c),o.call(e+"__cyclotomicSquare",c,s),o.call(G+"_mul",s,c,u),o.call(e+"__cyclotomicExp_w0",u,_),o.call(G+"_conjugate",_,_),o.call(e+"__cyclotomicSquare",_,g),o.call(e+"__cyclotomicExp_w0",g,f),o.call(G+"_conjugate",f,f),o.call(G+"_conjugate",u,p),o.call(G+"_conjugate",f,m),o.call(G+"_mul",m,_,L),o.call(G+"_mul",L,p,b),o.call(G+"_mul",b,c,w),o.call(G+"_mul",b,_,y),o.call(G+"_mul",y,i,A),o.call(e+"__frobeniusMap1",w,C),o.call(G+"_mul",C,A,F),o.call(e+"__frobeniusMap2",b,x),o.call(G+"_mul",x,F,I),o.call(G+"_conjugate",i,B),o.call(G+"_mul",B,w,E),o.call(e+"__frobeniusMap3",E,S),o.call(G+"_mul",S,I,n))}const V=t.alloc(k),K=t.alloc(R);function H(a){const o=t.addFunction(e+"_pairingEq"+a);for(let t=0;t0n;)ma(a)?e.push(1):e.push(0),a>>=1n;return e}(0xd201000000010000n),z=t.alloc(G),T=3*s,M=G.length-1,U=G.reduce(((t,a)=>t+(0!=a?1:0)),0),Q=6*l,k=3*l*2+(U+M+1)*T,R=15132376222941642752n;function N(a){const e=[[[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n]],[[1n,0n],[3850754370037169011952147076051364057158807420970682438676050522613628423219637725072182697113062777891589506424760n,151655185184498381465642749684540099398075398968325446656007613510403227271200139370504932015952886146304766135027n],[793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620351n,0n],[2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530n,1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257n],[793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350n,0n],[3125332594171059424908108096204648978570118281977575435832422631601824034463382777937621250592425535493320683825557n,877076961050607968509681729531255177986764537961432449499635504522207616027455086505066378536590128544573588734230n],[4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559786n,0n],[151655185184498381465642749684540099398075398968325446656007613510403227271200139370504932015952886146304766135027n,3850754370037169011952147076051364057158807420970682438676050522613628423219637725072182697113062777891589506424760n],[4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436n,0n],[1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257n,2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530n],[4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437n,0n],[877076961050607968509681729531255177986764537961432449499635504522207616027455086505066378536590128544573588734230n,3125332594171059424908108096204648978570118281977575435832422631601824034463382777937621250592425535493320683825557n]]],i=[[[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n]],[[1n,0n],[0n,4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436n],[793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350n,0n],[0n,1n],[4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436n,0n],[0n,793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350n]],[[1n,0n],[4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437n,0n],[4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436n,0n],[4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559786n,0n],[793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350n,0n],[793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620351n,0n]]],n=t.addFunction(O+"_frobeniusMap"+a);n.addParam("x","i32"),n.addParam("r","i32");const r=n.getCodeBuilder();for(let o=0;o<6;o++){const u=0==o?r.getLocal("x"):r.i32_add(r.getLocal("x"),r.i32_const(o*s)),_=u,g=r.i32_add(r.getLocal("x"),r.i32_const(o*s+c)),h=0==o?r.getLocal("r"):r.i32_add(r.getLocal("r"),r.i32_const(o*s)),p=h,L=r.i32_add(r.getLocal("r"),r.i32_const(o*s+c)),b=d(e[Math.floor(o/3)][a%12],i[o%3][a%6]),w=t.alloc([...la.bigInt2BytesLE(y(b[0]),l),...la.bigInt2BytesLE(y(b[1]),l)]);a%2==1?n.addCode(r.call(f+"_copy",_,p),r.call(f+"_neg",g,L),r.call(m+"_mul",h,r.i32_const(w),h)):n.addCode(r.call(m+"_mul",u,r.i32_const(w),h))}function d(t,a){const e=t[0],i=t[1],n=a[0],l=a[1],c=[(e*n-i*l)%o,(e*l+i*n)%o];return La(c[0])&&(c[0]=c[0]+o),c}}function $(a,o,i){const n=function(t){let a=t;const e=[];for(;a>0n;){if(ma(a)){const t=2-Number(a%4n);e.push(t),a-=BigInt(t)}else e.push(0);a>>=1n}return e}(a).map((t=>-1==t?255:t)),l=t.alloc(n),c=t.addFunction(e+"__cyclotomicExp_"+i);c.addParam("x","i32"),c.addParam("r","i32"),c.addLocal("bit","i32"),c.addLocal("i","i32");const s=c.getCodeBuilder(),d=s.getLocal("x"),u=s.getLocal("r"),_=s.i32_const(t.alloc(r));c.addCode(s.call(O+"_conjugate",d,_),s.call(O+"_one",u),s.if(s.teeLocal("bit",s.i32_load8_s(s.i32_const(n.length-1),l)),s.if(s.i32_eq(s.getLocal("bit"),s.i32_const(1)),s.call(O+"_mul",u,d,u),s.call(O+"_mul",u,_,u))),s.setLocal("i",s.i32_const(n.length-2)),s.block(s.loop(s.call(e+"__cyclotomicSquare",u,u),s.if(s.teeLocal("bit",s.i32_load8_s(s.getLocal("i"),l)),s.if(s.i32_eq(s.getLocal("bit"),s.i32_const(1)),s.call(O+"_mul",u,d,u),s.call(O+"_mul",u,_,u))),s.br_if(1,s.i32_eqz(s.getLocal("i"))),s.setLocal("i",s.i32_sub(s.getLocal("i"),s.i32_const(1))),s.br(0)))),o&&c.addCode(s.call(O+"_conjugate",u,u))}t.modules[e]={n64q:n,n64r:d,n8q:l,n8r:u,pG1gen:C,pG1zero:x,pG1b:h,pG2gen:B,pG2zero:v,pG2b:L,pq:t.modules.f1m.pq,pr:g,pOneT:S,r:i,q:o,prePSize:Q,preQSize:k},function(){const a=t.addFunction(q+"_mul1");a.addParam("pA","i32"),a.addParam("pC1","i32"),a.addParam("pR","i32");const e=a.getCodeBuilder(),o=e.getLocal("pA"),i=e.i32_add(e.getLocal("pA"),e.i32_const(2*c)),n=e.i32_add(e.getLocal("pA"),e.i32_const(4*c)),l=e.getLocal("pC1"),s=e.getLocal("pR"),r=e.i32_add(e.getLocal("pR"),e.i32_const(2*c)),d=e.i32_add(e.getLocal("pR"),e.i32_const(4*c)),u=e.i32_const(t.alloc(2*c)),_=e.i32_const(t.alloc(2*c));a.addCode(e.call(m+"_add",o,i,u),e.call(m+"_add",i,n,_),e.call(m+"_mul",i,l,d),e.call(m+"_mul",_,l,s),e.call(m+"_sub",s,d,s),e.call(m+"_mulNR",s,s),e.call(m+"_mul",u,l,r),e.call(m+"_sub",r,d,r))}(),function(){const a=t.addFunction(q+"_mul01");a.addParam("pA","i32"),a.addParam("pC0","i32"),a.addParam("pC1","i32"),a.addParam("pR","i32");const e=a.getCodeBuilder(),o=e.getLocal("pA"),i=e.i32_add(e.getLocal("pA"),e.i32_const(2*c)),n=e.i32_add(e.getLocal("pA"),e.i32_const(4*c)),l=e.getLocal("pC0"),s=e.getLocal("pC1"),r=e.getLocal("pR"),d=e.i32_add(e.getLocal("pR"),e.i32_const(2*c)),u=e.i32_add(e.getLocal("pR"),e.i32_const(4*c)),_=e.i32_const(t.alloc(2*c)),g=e.i32_const(t.alloc(2*c)),f=e.i32_const(t.alloc(2*c)),h=e.i32_const(t.alloc(2*c));a.addCode(e.call(m+"_mul",o,l,_),e.call(m+"_mul",i,s,g),e.call(m+"_add",o,i,f),e.call(m+"_add",o,n,h),e.call(m+"_add",i,n,r),e.call(m+"_mul",r,s,r),e.call(m+"_sub",r,g,r),e.call(m+"_mulNR",r,r),e.call(m+"_add",r,_,r),e.call(m+"_add",l,s,d),e.call(m+"_mul",d,f,d),e.call(m+"_sub",d,_,d),e.call(m+"_sub",d,g,d),e.call(m+"_mul",h,l,u),e.call(m+"_sub",u,_,u),e.call(m+"_add",u,g,u))}(),function(){const a=t.addFunction(O+"_mul014");a.addParam("pA","i32"),a.addParam("pC0","i32"),a.addParam("pC1","i32"),a.addParam("pC4","i32"),a.addParam("pR","i32");const e=a.getCodeBuilder(),o=e.getLocal("pA"),i=e.i32_add(e.getLocal("pA"),e.i32_const(6*c)),n=e.getLocal("pC0"),l=e.getLocal("pC1"),s=e.getLocal("pC4"),r=e.i32_const(t.alloc(6*c)),d=e.i32_const(t.alloc(6*c)),u=e.i32_const(t.alloc(2*c)),_=e.getLocal("pR"),g=e.i32_add(e.getLocal("pR"),e.i32_const(6*c));a.addCode(e.call(q+"_mul01",o,n,l,r),e.call(q+"_mul1",i,s,d),e.call(m+"_add",l,s,u),e.call(q+"_add",i,o,g),e.call(q+"_mul01",g,n,u,g),e.call(q+"_sub",g,r,g),e.call(q+"_sub",g,d,g),e.call(q+"_copy",d,_),e.call(q+"_mulNR",_,_),e.call(q+"_add",_,r,_))}(),function(){const a=t.addFunction(e+"_ell");a.addParam("pP","i32"),a.addParam("pCoefs","i32"),a.addParam("pF","i32");const o=a.getCodeBuilder(),i=o.getLocal("pP"),n=o.i32_add(o.getLocal("pP"),o.i32_const(l)),s=o.getLocal("pF"),r=o.getLocal("pCoefs"),d=o.i32_add(o.getLocal("pCoefs"),o.i32_const(c)),u=o.i32_add(o.getLocal("pCoefs"),o.i32_const(2*c)),_=o.i32_add(o.getLocal("pCoefs"),o.i32_const(3*c)),g=o.i32_add(o.getLocal("pCoefs"),o.i32_const(4*c)),h=t.alloc(2*c),p=o.i32_const(h),m=o.i32_const(h),L=o.i32_const(h+c),b=t.alloc(2*c),w=o.i32_const(b),y=o.i32_const(b),A=o.i32_const(b+c);a.addCode(o.call(f+"_mul",r,n,m),o.call(f+"_mul",d,n,L),o.call(f+"_mul",u,i,y),o.call(f+"_mul",_,i,A),o.call(O+"_mul014",s,g,w,p,s))}();const D=t.alloc(Q),j=t.alloc(k);function V(a){const o=t.addFunction(e+"_pairingEq"+a);for(let t=0;t>=BigInt(32)):l+2<=a?(n.setUint16(l,Number(e&BigInt(65535)),!0),l+=2,e>>=BigInt(16)):(n.setUint8(l,Number(e&BigInt(255)),!0),l+=1,e>>=BigInt(8));if(e)throw new Error("Number does not fit in this length");return o}const Aa=[];for(let t=0;t<256;t++)Aa[t]=Ca(t,8);function Ca(t,a){let e=0,o=t;for(let t=0;t>=1;return e}function Fa(t,a){return(Aa[t>>>24]|Aa[t>>>16&255]<<8|Aa[t>>>8&255]<<16|Aa[255&t]<<24)>>>32-a}function xa(t){return(0!=(4294901760&t)?(t&=4294901760,16):0)|(0!=(4278255360&t)?(t&=4278255360,8):0)|(0!=(4042322160&t)?(t&=4042322160,4):0)|(0!=(3435973836&t)?(t&=3435973836,2):0)|0!=(2863311530&t)}function Ia(t,a){const e=t.byteLength/a,o=xa(e);if(e!=1<e){const o=t.slice(i*a,(i+1)*a);t.set(t.slice(e*a,(e+1)*a),i*a),t.set(o,e*a)}}}function Ba(t,a){const e=new Uint8Array(a*t.length);for(let o=0;o0;)e>=4?(e-=4,a+=BigInt(i.getUint32(e))<=2?(e-=2,a+=BigInt(i.getUint16(e))<0;)n-4>=0?(n-=4,i.setUint32(n,Number(e&BigInt(4294967295))),e>>=BigInt(32)):n-2>=0?(n-=2,i.setUint16(n,Number(e&BigInt(65535))),e>>=BigInt(16)):(n-=1,i.setUint8(n,Number(e&BigInt(255))),e>>=BigInt(8));if(e)throw new Error("Number does not fit in this length");return o},bitReverse:Fa,buffReverseBits:Ia,buffer2array:Ea,leBuff2int:function(t){let a=BigInt(0),e=0;const o=new DataView(t.buffer,t.byteOffset,t.byteLength);for(;e{e[o]=t(a[o])})),e}return a},stringifyFElements:function t(a,e){if("bigint"==typeof e||void 0!==e.eq)return e.toString(10);if(e instanceof Uint8Array)return a.toString(a.e(e));if(Array.isArray(e))return e.map(t.bind(this,a));if("object"==typeof e){const o={};return Object.keys(e).forEach((i=>{o[i]=t(a,e[i])})),o}return e},unstringifyBigInts:function t(a){if("string"==typeof a&&/^[0-9]+$/.test(a))return BigInt(a);if("string"==typeof a&&/^0x[0-9a-fA-F]+$/.test(a))return BigInt(a);if(Array.isArray(a))return a.map(t);if("object"==typeof a){if(null===a)return null;const e={};return Object.keys(a).forEach((o=>{e[o]=t(a[o])})),e}return a},unstringifyFElements:function t(a,e){if("string"==typeof e&&/^[0-9]+$/.test(e))return a.e(e);if("string"==typeof e&&/^0x[0-9a-fA-F]+$/.test(e))return a.e(e);if(Array.isArray(e))return e.map(t.bind(this,a));if("object"==typeof e){if(null===e)return null;const o={};return Object.keys(e).forEach((i=>{o[i]=t(a,e[i])})),o}return e}});const Sa=1<<30;class Pa{constructor(t){this.buffers=[],this.byteLength=t;for(let a=0;a0;){const t=l+c>Sa?Sa-l:c,a=new Uint8Array(this.buffers[n].buffer,this.buffers[n].byteOffset+l,t);if(t==e)return a.slice();i||(i=e<=Sa?new Uint8Array(e):new Pa(e)),i.set(a,e-c),c-=t,n++,l=0}return i}set(t,a){void 0===a&&(a=0);const e=t.byteLength;if(0==e)return;const o=Math.floor(a/Sa);if(o==Math.floor((a+e-1)/Sa))return t instanceof Pa&&1==t.buffers.length?this.buffers[o].set(t.buffers[0],a%Sa):this.buffers[o].set(t,a%Sa);let i=o,n=a%Sa,l=e;for(;l>0;){const a=n+l>Sa?Sa-n:l,o=t.slice(e-l,e-l+a);new Uint8Array(this.buffers[i].buffer,this.buffers[i].byteOffset+n,a).set(o),l-=a,i++,n=0}}}function qa(t,a,e,o){return async function(i){const n=Math.floor(i.byteLength/e);if(n*e!==i.byteLength)throw new Error("Invalid buffer size");const l=Math.floor(n/t.concurrency),c=[];for(let s=0;s=0;t--)this.w[t]=this.square(this.w[t+1]);if(!this.eq(this.w[0],this.one))throw new Error("Error calculating roots of unity");this.batchToMontgomery=qa(t,a+"_batchToMontgomery",this.n8,this.n8),this.batchFromMontgomery=qa(t,a+"_batchFromMontgomery",this.n8,this.n8)}op2(t,a,e){return this.tm.setBuff(this.pOp1,a),this.tm.setBuff(this.pOp2,e),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op2Bool(t,a,e){return this.tm.setBuff(this.pOp1,a),this.tm.setBuff(this.pOp2,e),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2)}op1(t,a){return this.tm.setBuff(this.pOp1,a),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op1Bool(t,a){return this.tm.setBuff(this.pOp1,a),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3)}add(t,a){return this.op2("_add",t,a)}eq(t,a){return this.op2Bool("_eq",t,a)}isZero(t){return this.op1Bool("_isZero",t)}sub(t,a){return this.op2("_sub",t,a)}neg(t){return this.op1("_neg",t)}inv(t){return this.op1("_inverse",t)}toMontgomery(t){return this.op1("_toMontgomery",t)}fromMontgomery(t){return this.op1("_fromMontgomery",t)}mul(t,a){return this.op2("_mul",t,a)}div(t,a){return this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,a),this.tm.instance.exports[this.prefix+"_inverse"](this.pOp2,this.pOp2),this.tm.instance.exports[this.prefix+"_mul"](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}square(t){return this.op1("_square",t)}isSquare(t){return this.op1Bool("_isSquare",t)}sqrt(t){return this.op1("_sqrt",t)}exp(t,a){return a instanceof Uint8Array||(a=S(o(a))),this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,a),this.tm.instance.exports[this.prefix+"_exp"](this.pOp1,this.pOp2,a.byteLength,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}isNegative(t){return this.op1Bool("_isNegative",t)}e(t,a){if(t instanceof Uint8Array)return t;let e=o(t,a);n(e)?(e=p(e),A(e,this.p)&&(e=w(e,this.p)),e=h(this.p,e)):A(e,this.p)&&(e=w(e,this.p));const i=ya(e,this.n8);return this.toMontgomery(i)}toString(t,a){return v(B(this.fromMontgomery(t),0),a)}fromRng(t){let a;const e=new Uint8Array(this.n8);do{a=P;for(let e=0;e{this.reject=a,this.resolve=t}))}}var ka;const Ra="data:application/javascript;base64,"+(ka='(function thread(self) {\n const MAXMEM = 32767;\n let instance;\n let memory;\n\n if (self) {\n self.onmessage = function(e) {\n let data;\n if (e.data) {\n data = e.data;\n } else {\n data = e;\n }\n\n if (data[0].cmd == "INIT") {\n init(data[0]).then(function() {\n self.postMessage(data.result);\n });\n } else if (data[0].cmd == "TERMINATE") {\n self.close();\n } else {\n const res = runTask(data);\n self.postMessage(res);\n }\n };\n }\n\n async function init(data) {\n const code = new Uint8Array(data.code);\n const wasmModule = await WebAssembly.compile(code);\n memory = new WebAssembly.Memory({initial:data.init, maximum: MAXMEM});\n\n instance = await WebAssembly.instantiate(wasmModule, {\n env: {\n "memory": memory\n }\n });\n }\n\n\n\n function alloc(length) {\n const u32 = new Uint32Array(memory.buffer, 0, 1);\n while (u32[0] & 3) u32[0]++; // Return always aligned pointers\n const res = u32[0];\n u32[0] += length;\n if (u32[0] + length > memory.buffer.byteLength) {\n const currentPages = memory.buffer.byteLength / 0x10000;\n let requiredPages = Math.floor((u32[0] + length) / 0x10000)+1;\n if (requiredPages>MAXMEM) requiredPages=MAXMEM;\n memory.grow(requiredPages-currentPages);\n }\n return res;\n }\n\n function allocBuffer(buffer) {\n const p = alloc(buffer.byteLength);\n setBuffer(p, buffer);\n return p;\n }\n\n function getBuffer(pointer, length) {\n const u8 = new Uint8Array(memory.buffer);\n return new Uint8Array(u8.buffer, u8.byteOffset + pointer, length);\n }\n\n function setBuffer(pointer, buffer) {\n const u8 = new Uint8Array(memory.buffer);\n u8.set(new Uint8Array(buffer), pointer);\n }\n\n function runTask(task) {\n if (task[0].cmd == "INIT") {\n return init(task[0]);\n }\n const ctx = {\n vars: [],\n out: []\n };\n const u32a = new Uint32Array(memory.buffer, 0, 1);\n const oldAlloc = u32a[0];\n for (let i=0; io.buffer.byteLength){const i=o.buffer.byteLength/65536;let n=Math.floor((e[0]+t)/65536)+1;n>a&&(n=a),o.grow(n-i)}return i}function l(t){const a=n(t.byteLength);return s(a,t),a}function c(t,a){const e=new Uint8Array(o.buffer);return new Uint8Array(e.buffer,e.byteOffset+t,a)}function s(t,a){new Uint8Array(o.buffer).set(new Uint8Array(a),t)}function r(t){if("INIT"==t[0].cmd)return i(t[0]);const a={vars:[],out:[]},r=new Uint32Array(o.buffer,0,1)[0];for(let o=0;o64&&(a=64),e.concurrency=a;for(let t=0;t0;t++)if(0==this.working[t]){const a=this.actionQueue.shift();this.postAction(t,a.data,a.transfers,a.deferred)}}queueAction(t,a){const e=new Qa;if(this.singleThread){const a=this.taskManager(t);e.resolve(a)}else this.actionQueue.push({data:t,transfers:a,deferred:e}),this.processWorks();return e.promise}resetMemory(){this.u32[0]=this.initalPFree}allocBuff(t){const a=this.alloc(t.byteLength);return this.setBuff(a,t),a}getBuff(t,a){return this.u8.slice(t,t+a)}setBuff(t,a){this.u8.set(new Uint8Array(a),t)}alloc(t){for(;3&this.u32[0];)this.u32[0]++;const a=this.u32[0];return this.u32[0]+=t,a}async terminate(){for(let t=0;tsetTimeout(a,t))))}}function Da(t,a){const e=t[a],o=t.Fr,i=t.tm;t[a].batchApplyKey=async function(t,n,l,c,s){let r,d,u,_,g;if(c=c||"affine",s=s||"affine","G1"==a)"jacobian"==c?(u=3*e.F.n8,r="g1m_batchApplyKey"):(u=2*e.F.n8,r="g1m_batchApplyKeyMixed"),_=3*e.F.n8,"jacobian"==s?g=3*e.F.n8:(d="g1m_batchToAffine",g=2*e.F.n8);else if("G2"==a)"jacobian"==c?(u=3*e.F.n8,r="g2m_batchApplyKey"):(u=2*e.F.n8,r="g2m_batchApplyKeyMixed"),_=3*e.F.n8,"jacobian"==s?g=3*e.F.n8:(d="g2m_batchToAffine",g=2*e.F.n8);else{if("Fr"!=a)throw new Error("Invalid group: "+a);r="frm_batchApplyKey",u=e.n8,_=e.n8,g=e.n8}const f=Math.floor(t.byteLength/u),h=Math.floor(f/i.concurrency),p=[];l=o.e(l);let m=o.e(n);for(let a=0;a=0;t--){if(!e.isZero(h))for(let t=0;tr&&(h=r),h<1024&&(h=1024);const p=[];for(let a=0;a(c&&c.debug(`Multiexp end: ${s}: ${a}/${u}`),t))))}const m=await Promise.all(p);let L=e.zero;for(let t=m.length-1;t>=0;t--)L=e.add(L,m[t]);return L}e.multiExp=async function(t,a,e,o){return await n(t,a,"jacobian",e,o)},e.multiExpAffine=async function(t,a,e,o){return await n(t,a,"affine",e,o)}}function Ka(t,a){const e=t[a],o=t.Fr,i=e.tm;async function n(t,c,s,r,d,u){s=s||"affine",r=r||"affine";let _,g,f,h,p,m,L,b;"G1"==a?("affine"==s?(_=2*e.F.n8,h="g1m_batchToJacobian"):_=3*e.F.n8,g=3*e.F.n8,c&&(b="g1m_fftFinal"),L="g1m_fftJoin",m="g1m_fftMix","affine"==r?(f=2*e.F.n8,p="g1m_batchToAffine"):f=3*e.F.n8):"G2"==a?("affine"==s?(_=2*e.F.n8,h="g2m_batchToJacobian"):_=3*e.F.n8,g=3*e.F.n8,c&&(b="g2m_fftFinal"),L="g2m_fftJoin",m="g2m_fftMix","affine"==r?(f=2*e.F.n8,p="g2m_batchToAffine"):f=3*e.F.n8):"Fr"==a&&(_=e.n8,g=e.n8,f=e.n8,c&&(b="frm_fftFinal"),m="frm_fftMix",L="frm_fftJoin");let w=!1;Array.isArray(t)?(t=Ba(t,_),w=!0):t=t.slice(0,t.byteLength);const y=t.byteLength/_,A=xa(y);if(1<1<<28?new Pa(2*u[0].byteLength):new Uint8Array(2*u[0].byteLength);return _.set(u[0]),_.set(u[1],u[0].byteLength),_}(t,s,r,d,u):await async function(t,a,e,i,c){let s,r;s=t.slice(0,t.byteLength/2),r=t.slice(t.byteLength/2,t.byteLength);const d=[];[s,r]=await l(s,r,"fftJoinExt",o.one,o.shift,a,"jacobian",i,c),d.push(n(s,!1,"jacobian",e,i,c)),d.push(n(r,!1,"jacobian",e,i,c));const u=await Promise.all(d);let _;_=u[0].byteLength>1<<28?new Pa(2*u[0].byteLength):new Uint8Array(2*u[0].byteLength);return _.set(u[0]),_.set(u[1],u[0].byteLength),_}(t,s,r,d,u),w?Ea(a,f):a}let C,F,x;c&&(C=o.inv(o.e(y))),Ia(t,_);let I=Math.min(16384,y),B=y/I;for(;B=16;)B*=2,I/=2;const E=xa(I),v=[];for(let a=0;a(d&&d.debug(`${u}: fft ${A} mix end: ${a}/${B}`),t))))}x=await Promise.all(v);for(let t=0;t(d&&d.debug(`${u}: fft ${A} join ${t}/${A} ${l+1}/${a} ${c}/${e/2}`),o))))}const l=await Promise.all(n);for(let t=0;t0;a--)F.set(x[a],t),t+=I*f,delete x[a];F.set(x[0].slice(0,(I-1)*f),t),delete x[0]}else for(let t=0;t65536&&(w=65536);const y=[];for(let a=0;a(u&&u.debug(`${_}: fftJoinExt End: ${a}/${b}`),t))))}const A=await Promise.all(y);let C,F;b*p>1<<28?(C=new Pa(b*p),F=new Pa(b*p)):(C=new Uint8Array(b*p),F=new Uint8Array(b*p));let x=0;for(let t=0;to.s+1)throw s&&s.error("lagrangeEvaluations input too big"),new Error("lagrangeEvaluations input too big");let g=t.slice(0,t.byteLength/2),f=t.slice(t.byteLength/2,t.byteLength);const h=o.exp(o.shift,u/2),p=o.inv(o.sub(o.one,h));[g,f]=await l(g,f,"prepareLagrangeEvaluation",p,o.shiftInv,i,"jacobian",s,r+" prep");const m=[];let L;return m.push(n(g,!0,"jacobian",c,s,r+" t0")),m.push(n(f,!0,"jacobian",c,s,r+" t1")),[g,f]=await Promise.all(m),L=g.byteLength>1<<28?new Pa(2*g.byteLength):new Uint8Array(2*g.byteLength),L.set(g),L.set(f,g.byteLength),L},e.fftMix=async function(t){const n=3*e.F.n8;let l,c;if("G1"==a)l="g1m_fftMix",c="g1m_fftJoin";else if("G2"==a)l="g2m_fftMix",c="g2m_fftJoin";else{if("Fr"!=a)throw new Error("Invalid group");l="frm_fftMix",c="frm_fftJoin"}const s=Math.floor(t.byteLength/n),r=xa(s);let d=1<=0;t--)g.set(_[t][0],f),f+=_[t][0].byteLength;return g}}async function Ha(t){const a=await Na(t.wasm,t.singleThread),e={};return e.q=o(t.wasm.q.toString()),e.r=o(t.wasm.r.toString()),e.name=t.name,e.tm=a,e.prePSize=t.wasm.prePSize,e.preQSize=t.wasm.preQSize,e.Fr=new Oa(a,"frm",t.n8r,t.r),e.F1=new Oa(a,"f1m",t.n8q,t.q),e.F2=new Ga(a,"f2m",e.F1),e.G1=new Ta(a,"g1m",e.F1,t.wasm.pG1gen,t.wasm.pG1b,t.cofactorG1),e.G2=new Ta(a,"g2m",e.F2,t.wasm.pG2gen,t.wasm.pG2b,t.cofactorG2),e.F6=new za(a,"f6m",e.F2),e.F12=new Ga(a,"ftm",e.F6),e.Gt=e.F12,Da(e,"G1"),Da(e,"G2"),Da(e,"Fr"),Va(e,"G1"),Va(e,"G2"),Ka(e,"G1"),Ka(e,"G2"),Ka(e,"Fr"),function(t){const a=t.tm;t.pairing=function(e,o){a.startSyncOp();const i=a.allocBuff(t.G1.toJacobian(e)),n=a.allocBuff(t.G2.toJacobian(o)),l=a.alloc(t.Gt.n8);a.instance.exports[t.name+"_pairing"](i,n,l);const c=a.getBuff(l,t.Gt.n8);return a.endSyncOp(),c},t.pairingEq=async function(){let e,o;arguments.length%2==1?(e=arguments[arguments.length-1],o=(arguments.length-1)/2):(e=t.Gt.one,o=arguments.length/2);const i=[];for(let e=0;e>8n&0xFFn)),a.push(Number(e>>16n&0xFFn)),a.push(Number(e>>24n&0xFFn)),a}function Xa(t){const a=function(t){for(var a=[],e=0;e>6,128|63&o):o<55296||o>=57344?a.push(224|o>>12,128|o>>6&63,128|63&o):(e++,o=65536+((1023&o)<<10|1023&t.charCodeAt(e)),a.push(240|o>>18,128|o>>12&63,128|o>>6&63,128|63&o))}return a}(t);return[...ie(a.length),...a]}function te(t){const a=[];let e=Za(t);if(Wa(e))throw new Error("Number cannot be negative");for(;!Ya(e);)a.push(Number(0x7Fn&e)),e>>=7n;0==a.length&&a.push(0);for(let t=0;t0xFFFFFFFFn)throw new Error("Number too big");if(a>0x7FFFFFFFn&&(a-=0x100000000n),a<-2147483648n)throw new Error("Number too small");return ae(a)}function oe(t){let a=Za(t);if(a>0xFFFFFFFFFFFFFFFFn)throw new Error("Number too big");if(a>0x7FFFFFFFFFFFFFFFn&&(a-=0x10000000000000000n),a<-9223372036854775808n)throw new Error("Number too small");return ae(a)}function ie(t){let a=Za(t);if(a>0xFFFFFFFFn)throw new Error("Number too big");return te(a)}function ne(t){return Array.from(t,(function(t){return("0"+(255&t).toString(16)).slice(-2)})).join("")}class le{constructor(t){this.func=t,this.functionName=t.functionName,this.module=t.module}setLocal(t,a){const e=this.func.localIdxByName[t];if(void 0===e)throw new Error(`Local Variable not defined: Function: ${this.functionName} local: ${t} `);return[...a,33,...ie(e)]}teeLocal(t,a){const e=this.func.localIdxByName[t];if(void 0===e)throw new Error(`Local Variable not defined: Function: ${this.functionName} local: ${t} `);return[...a,34,...ie(e)]}getLocal(t){const a=this.func.localIdxByName[t];if(void 0===a)throw new Error(`Local Variable not defined: Function: ${this.functionName} local: ${t} `);return[32,...ie(a)]}i64_load8_s(t,a,e){return[...t,48,void 0===e?0:e,...ie(a||0)]}i64_load8_u(t,a,e){return[...t,49,void 0===e?0:e,...ie(a||0)]}i64_load16_s(t,a,e){return[...t,50,void 0===e?1:e,...ie(a||0)]}i64_load16_u(t,a,e){return[...t,51,void 0===e?1:e,...ie(a||0)]}i64_load32_s(t,a,e){return[...t,52,void 0===e?2:e,...ie(a||0)]}i64_load32_u(t,a,e){return[...t,53,void 0===e?2:e,...ie(a||0)]}i64_load(t,a,e){return[...t,41,void 0===e?3:e,...ie(a||0)]}i64_store(t,a,e,o){let i,n,l;return Array.isArray(a)?(i=0,n=3,l=a):Array.isArray(e)?(i=a,n=3,l=e):Array.isArray(o)&&(i=a,n=e,l=o),[...t,...l,55,n,...ie(i)]}i64_store32(t,a,e,o){let i,n,l;return Array.isArray(a)?(i=0,n=2,l=a):Array.isArray(e)?(i=a,n=2,l=e):Array.isArray(o)&&(i=a,n=e,l=o),[...t,...l,62,n,...ie(i)]}i64_store16(t,a,e,o){let i,n,l;return Array.isArray(a)?(i=0,n=1,l=a):Array.isArray(e)?(i=a,n=1,l=e):Array.isArray(o)&&(i=a,n=e,l=o),[...t,...l,61,n,...ie(i)]}i64_store8(t,a,e,o){let i,n,l;return Array.isArray(a)?(i=0,n=0,l=a):Array.isArray(e)?(i=a,n=0,l=e):Array.isArray(o)&&(i=a,n=e,l=o),[...t,...l,60,n,...ie(i)]}i32_load8_s(t,a,e){return[...t,44,void 0===e?0:e,...ie(a||0)]}i32_load8_u(t,a,e){return[...t,45,void 0===e?0:e,...ie(a||0)]}i32_load16_s(t,a,e){return[...t,46,void 0===e?1:e,...ie(a||0)]}i32_load16_u(t,a,e){return[...t,47,void 0===e?1:e,...ie(a||0)]}i32_load(t,a,e){return[...t,40,void 0===e?2:e,...ie(a||0)]}i32_store(t,a,e,o){let i,n,l;return Array.isArray(a)?(i=0,n=2,l=a):Array.isArray(e)?(i=a,n=2,l=e):Array.isArray(o)&&(i=a,n=e,l=o),[...t,...l,54,n,...ie(i)]}i32_store16(t,a,e,o){let i,n,l;return Array.isArray(a)?(i=0,n=1,l=a):Array.isArray(e)?(i=a,n=1,l=e):Array.isArray(o)&&(i=a,n=e,l=o),[...t,...l,59,n,...ie(i)]}i32_store8(t,a,e,o){let i,n,l;return Array.isArray(a)?(i=0,n=0,l=a):Array.isArray(e)?(i=a,n=0,l=e):Array.isArray(o)&&(i=a,n=e,l=o),[...t,...l,58,n,...ie(i)]}call(t,...a){const e=this.module.functionIdxByName[t];if(void 0===e)throw new Error(`Function not defined: Function: ${t}`);return[...[].concat(...a),16,...ie(e)]}call_indirect(t,...a){return[...[].concat(...a),...t,17,0,0]}if(t,a,e){return e?[...t,4,64,...a,5,...e,11]:[...t,4,64,...a,11]}block(t){return[2,64,...t,11]}loop(...t){return[3,64,...[].concat(...t),11]}br_if(t,a){return[...a,13,...ie(t)]}br(t){return[12,...ie(t)]}ret(t){return[...t,15]}drop(t){return[...t,26]}i64_const(t){return[66,...oe(t)]}i32_const(t){return[65,...ee(t)]}i64_eqz(t){return[...t,80]}i64_eq(t,a){return[...t,...a,81]}i64_ne(t,a){return[...t,...a,82]}i64_lt_s(t,a){return[...t,...a,83]}i64_lt_u(t,a){return[...t,...a,84]}i64_gt_s(t,a){return[...t,...a,85]}i64_gt_u(t,a){return[...t,...a,86]}i64_le_s(t,a){return[...t,...a,87]}i64_le_u(t,a){return[...t,...a,88]}i64_ge_s(t,a){return[...t,...a,89]}i64_ge_u(t,a){return[...t,...a,90]}i64_add(t,a){return[...t,...a,124]}i64_sub(t,a){return[...t,...a,125]}i64_mul(t,a){return[...t,...a,126]}i64_div_s(t,a){return[...t,...a,127]}i64_div_u(t,a){return[...t,...a,128]}i64_rem_s(t,a){return[...t,...a,129]}i64_rem_u(t,a){return[...t,...a,130]}i64_and(t,a){return[...t,...a,131]}i64_or(t,a){return[...t,...a,132]}i64_xor(t,a){return[...t,...a,133]}i64_shl(t,a){return[...t,...a,134]}i64_shr_s(t,a){return[...t,...a,135]}i64_shr_u(t,a){return[...t,...a,136]}i64_extend_i32_s(t){return[...t,172]}i64_extend_i32_u(t){return[...t,173]}i64_clz(t){return[...t,121]}i64_ctz(t){return[...t,122]}i32_eqz(t){return[...t,69]}i32_eq(t,a){return[...t,...a,70]}i32_ne(t,a){return[...t,...a,71]}i32_lt_s(t,a){return[...t,...a,72]}i32_lt_u(t,a){return[...t,...a,73]}i32_gt_s(t,a){return[...t,...a,74]}i32_gt_u(t,a){return[...t,...a,75]}i32_le_s(t,a){return[...t,...a,76]}i32_le_u(t,a){return[...t,...a,77]}i32_ge_s(t,a){return[...t,...a,78]}i32_ge_u(t,a){return[...t,...a,79]}i32_add(t,a){return[...t,...a,106]}i32_sub(t,a){return[...t,...a,107]}i32_mul(t,a){return[...t,...a,108]}i32_div_s(t,a){return[...t,...a,109]}i32_div_u(t,a){return[...t,...a,110]}i32_rem_s(t,a){return[...t,...a,111]}i32_rem_u(t,a){return[...t,...a,112]}i32_and(t,a){return[...t,...a,113]}i32_or(t,a){return[...t,...a,114]}i32_xor(t,a){return[...t,...a,115]}i32_shl(t,a){return[...t,...a,116]}i32_shr_s(t,a){return[...t,...a,117]}i32_shr_u(t,a){return[...t,...a,118]}i32_rotl(t,a){return[...t,...a,119]}i32_rotr(t,a){return[...t,...a,120]}i32_wrap_i64(t){return[...t,167]}i32_clz(t){return[...t,103]}i32_ctz(t){return[...t,104]}unreachable(){return[0]}current_memory(){return[63,0]}comment(){return[]}}const ce={i32:127,i64:126,f32:125,f64:124,anyfunc:112,func:96,emptyblock:64};class se{constructor(t,a,e,o,i){if("import"==e)this.fnType="import",this.moduleName=o,this.fieldName=i;else{if("internal"!=e)throw new Error("Invalid function fnType: "+e);this.fnType="internal"}this.module=t,this.fnName=a,this.params=[],this.locals=[],this.localIdxByName={},this.code=[],this.returnType=null,this.nextLocal=0}addParam(t,a){if(this.localIdxByName[t])throw new Error(`param already exists. Function: ${this.fnName}, Param: ${t} `);const e=this.nextLocal++;this.localIdxByName[t]=e,this.params.push({type:a})}addLocal(t,a,e){const o=e||1;if(this.localIdxByName[t])throw new Error(`local already exists. Function: ${this.fnName}, Param: ${t} `);const i=this.nextLocal++;this.localIdxByName[t]=i,this.locals.push({type:a,length:o})}setReturnType(t){if(this.returnType)throw new Error(`returnType already defined. Function: ${this.fnName}`);this.returnType=t}getSignature(){return[96,...[...ie(this.params.length),...this.params.map((t=>ce[t.type]))],...this.returnType?[1,ce[this.returnType]]:[0]]}getBody(){const t=this.locals.map((t=>[...ie(t.length),ce[t.type]])),a=[...ie(this.locals.length),...[].concat(...t),...this.code,11];return[...ie(a.length),...a]}addCode(...t){this.code.push(...[].concat(...t))}getCodeBuilder(){return new le(this)}}class re{constructor(){this.functions=[],this.functionIdxByName={},this.nImportFunctions=0,this.nInternalFunctions=0,this.memory={pagesSize:1,moduleName:"env",fieldName:"memory"},this.free=8,this.datas=[],this.modules={},this.exports=[],this.functionsTable=[]}build(){return this._setSignatures(),new Uint8Array([...Ja(1836278016),...Ja(1),...this._buildType(),...this._buildImport(),...this._buildFunctionDeclarations(),...this._buildFunctionsTable(),...this._buildExports(),...this._buildElements(),...this._buildCode(),...this._buildData()])}addFunction(t){if(void 0!==this.functionIdxByName[t])throw new Error(`Function already defined: ${t}`);const a=this.functions.length;return this.functionIdxByName[t]=a,this.functions.push(new se(this,t,"internal")),this.nInternalFunctions++,this.functions[a]}addIimportFunction(t,a,e){if(void 0!==this.functionIdxByName[t])throw new Error(`Function already defined: ${t}`);if(this.functions.length>0&&"internal"==this.functions[this.functions.length-1].type)throw new Error(`Import functions must be declared before internal: ${t}`);let o=e||t;const i=this.functions.length;return this.functionIdxByName[t]=i,this.functions.push(new se(this,t,"import",a,o)),this.nImportFunctions++,this.functions[i]}setMemory(t,a,e){this.memory={pagesSize:t,moduleName:a||"env",fieldName:e||"memory"}}exportFunction(t,a){const e=a||t;if(void 0===this.functionIdxByName[t])throw new Error(`Function not defined: ${t}`);const o=this.functionIdxByName[t];e!=t&&(this.functionIdxByName[e]=o),this.exports.push({exportName:e,idx:o})}addFunctionToTable(t){const a=this.functionIdxByName[t];this.functionsTable.push(a)}addData(t,a){this.datas.push({offset:t,bytes:a})}alloc(t,a){let e,o;(Array.isArray(t)||ArrayBuffer.isView(t))&&void 0===a?(e=t.length,o=t):(e=t,o=a),e=1+(e-1>>3)<<3;const i=this.free;return this.free+=e,o&&this.addData(i,o),i}allocString(t){const a=(new globalThis.TextEncoder).encode(t);return this.alloc([...a,0])}_setSignatures(){this.signatures=[];const t={};if(this.functionsTable.length>0){const a=this.functions[this.functionsTable[0]].getSignature();t["s_"+ne(a)]=0,this.signatures.push(a)}for(let a=0;a{a.pendingLoads.push({page:t,resolve:e,reject:o})}));return a.__statusPage("After Load request: ",t),e}__statusPage(t,a){const e=[],o=this;if(!o.logHistory)return;e.push("=="+t+" "+a);let i="";for(let t=0;t "+a.history[t][e][o])}_triggerLoad(){const t=this;if(t.reading)return;if(0==t.pendingLoads.length)return;const a=Object.keys(t.pages),e=[];for(let o=0;o0&&(void 0!==t.pages[t.pendingLoads[0].page]||o>0||e.length>0);){const a=t.pendingLoads.shift();if(void 0!==t.pages[a.page]){t.pages[a.page].pendingOps++;const o=e.indexOf(a.page);o>=0&&e.splice(o,1),t.pages[a.page].loading?t.pages[a.page].loading.push(a):a.resolve(),t.__statusPage("After Load (cached): ",a.page)}else{if(o)o--;else{const a=e.shift();t.__statusPage("Before Unload: ",a),t.avBuffs.unshift(t.pages[a]),delete t.pages[a],t.__statusPage("After Unload: ",a)}a.page>=t.totalPages?(t.pages[a.page]=n(),a.resolve(),t.__statusPage("After Load (new): ",a.page)):(t.reading=!0,t.pages[a.page]=n(),t.pages[a.page].loading=[a],i.push(t.fd.read(t.pages[a.page].buff,0,t.pageSize,a.page*t.pageSize).then((e=>{t.pages[a.page].size=e.bytesRead;const o=t.pages[a.page].loading;delete t.pages[a.page].loading;for(let t=0;t{a.reject(t)}))),t.__statusPage("After Load (loading): ",a.page))}}function n(){if(t.avBuffs.length>0){const a=t.avBuffs.shift();return a.dirty=!1,a.pendingOps=1,a.size=0,a}return{dirty:!1,buff:new Uint8Array(t.pageSize),pendingOps:1,size:0}}Promise.all(i).then((()=>{t.reading=!1,t.pendingLoads.length>0&&setImmediate(t._triggerLoad.bind(t)),t._tryClose()}))}_triggerWrite(){const t=this;if(t.writing)return;const a=Object.keys(t.pages),e=[];for(let o=0;o{i.writing=!1}),(a=>{console.log("ERROR Writing: "+a),t.error=a,t._tryClose()}))))}t.writing&&Promise.all(e).then((()=>{t.writing=!1,setImmediate(t._triggerWrite.bind(t)),t._tryClose(),t.pendingLoads.length>0&&setImmediate(t._triggerLoad.bind(t))}))}_getDirtyPage(){for(let t in this.pages)if(this.pages[t].dirty)return t;return-1}async write(t,a){if(0==t.byteLength)return;const e=this;if(void 0===a&&(a=e.pos),e.pos=a+t.byteLength,e.totalSize0;){await n[l-o];const a=c+s>e.pageSize?e.pageSize-c:s,i=t.slice(t.byteLength-s,t.byteLength-s+a);new Uint8Array(e.pages[l].buff.buffer,c,a).set(i),e.pages[l].dirty=!0,e.pages[l].pendingOps--,e.pages[l].size=Math.max(c+a,e.pages[l].size),l>=e.totalPages&&(e.totalPages=l+1),s-=a,l++,c=0,e.writing||setImmediate(e._triggerWrite.bind(e))}}async read(t,a){let e=new Uint8Array(t);return await this.readToBuffer(e,0,t,a),e}async readToBuffer(t,a,e,o){if(0==e)return;const i=this;if(e>i.pageSize*i.maxPagesLoaded*.8){const t=Math.floor(1.1*e);this.maxPagesLoaded=Math.floor(t/i.pageSize)+1}if(void 0===o&&(o=i.pos),i.pos=o+e,i.pendingClose)throw new Error("Reading a closing file");const n=Math.floor(o/i.pageSize),l=Math.floor((o+e-1)/i.pageSize),c=[];for(let t=n;t<=l;t++)c.push(i._loadPage(t));i._triggerLoad();let s=n,r=o%i.pageSize,d=o+e>i.totalSize?e-(o+e-i.totalSize):e;for(;d>0;){await c[s-n],i.__statusPage("After Await (read): ",s);const o=r+d>i.pageSize?i.pageSize-r:d,l=new Uint8Array(i.pages[s].buff.buffer,i.pages[s].buff.byteOffset+r,o);t.set(l,a+e-d),i.pages[s].pendingOps--,i.__statusPage("After Op done: ",s),d-=o,s++,r=0,i.pendingLoads.length>0&&setImmediate(i._triggerLoad.bind(i))}this.pos=o+e}_tryClose(){const t=this;if(!t.pendingClose)return;t.error&&t.pendingCloseReject(t.error);t._getDirtyPage()>=0||t.writing||t.reading||t.pendingLoads.length>0||t.pendingClose()}close(){const t=this;if(t.pendingClose)throw new Error("Closing the file twice");return new Promise(((a,e)=>{t.pendingClose=a,t.pendingCloseReject=e,t._tryClose()})).then((()=>{t.fd.close()}),(a=>{throw t.fd.close(),a}))}async discard(){await this.close(),await fe.promises.unlink(this.fileName)}async writeULE32(t,a){const e=new Uint8Array(4);new DataView(e.buffer).setUint32(0,t,!0),await this.write(e,a)}async writeUBE32(t,a){const e=new Uint8Array(4);new DataView(e.buffer).setUint32(0,t,!1),await this.write(e,a)}async writeULE64(t,a){const e=new Uint8Array(8),o=new DataView(e.buffer);o.setUint32(0,4294967295&t,!0),o.setUint32(4,Math.floor(t/4294967296),!0),await this.write(e,a)}async readULE32(t){const a=await this.read(4,t);return new Uint32Array(a.buffer)[0]}async readUBE32(t){const a=await this.read(4,t);return new DataView(a.buffer).getUint32(0,!1)}async readULE64(t){const a=await this.read(8,t),e=new Uint32Array(a.buffer);return 4294967296*e[1]+e[0]}async readString(t){const a=this;if(a.pendingClose)throw new Error("Reading a closing file");let e=void 0===t?a.pos:t,o=Math.floor(e/a.pageSize),i=!1,n="";for(;!i;){let t=a._loadPage(o);a._triggerLoad(),await t,a.__statusPage("After Await (read): ",o);let l=e%a.pageSize;const c=new Uint8Array(a.pages[o].buff.buffer,a.pages[o].buff.byteOffset+l,a.pageSize-l);let s=c.findIndex((t=>0===t));i=-1!==s,i?(n+=(new TextDecoder).decode(c.slice(0,s)),a.pos=o*this.pageSize+l+s+1):(n+=(new TextDecoder).decode(c),a.pos=o*this.pageSize+l+c.length),a.pages[o].pendingOps--,a.__statusPage("After Op done: ",o),e=a.pos,o++,a.pendingLoads.length>0&&setImmediate(a._triggerLoad.bind(a))}return n}}const me=new Uint8Array(4),Le=new DataView(me.buffer),be=new Uint8Array(8),we=new DataView(be.buffer);class ye{constructor(){this.pageSize=16384}_resizeIfNeeded(t){if(t>this.allocSize){const a=Math.max(this.allocSize+(1<<20),Math.floor(1.1*this.allocSize),t),e=new Uint8Array(a);e.set(this.o.data),this.o.data=e,this.allocSize=a}}async write(t,a){if(void 0===a&&(a=this.pos),this.readOnly)throw new Error("Writing a read only file");this._resizeIfNeeded(a+t.byteLength),this.o.data.set(t.slice(),a),a+t.byteLength>this.totalSize&&(this.totalSize=a+t.byteLength),this.pos=a+t.byteLength}async readToBuffer(t,a,e,o){if(void 0===o&&(o=this.pos),this.readOnly&&o+e>this.totalSize)throw new Error("Reading out of bounds");this._resizeIfNeeded(o+e);const i=new Uint8Array(this.o.data.buffer,this.o.data.byteOffset+o,e);t.set(i,a),this.pos=o+e}async read(t,a){const e=new Uint8Array(t);return await this.readToBuffer(e,0,t,a),e}close(){this.o.data.byteLength!=this.totalSize&&(this.o.data=this.o.data.slice(0,this.totalSize))}async discard(){}async writeULE32(t,a){Le.setUint32(0,t,!0),await this.write(me,a)}async writeUBE32(t,a){Le.setUint32(0,t,!1),await this.write(me,a)}async writeULE64(t,a){we.setUint32(0,4294967295&t,!0),we.setUint32(4,Math.floor(t/4294967296),!0),await this.write(be,a)}async readULE32(t){const a=await this.read(4,t);return new Uint32Array(a.buffer)[0]}async readUBE32(t){const a=await this.read(4,t);return new DataView(a.buffer).getUint32(0,!1)}async readULE64(t){const a=await this.read(8,t),e=new Uint32Array(a.buffer);return 4294967296*e[1]+e[0]}async readString(t){const a=this;let e=void 0===t?a.pos:t;if(e>this.totalSize){if(this.readOnly)throw new Error("Reading out of bounds");this._resizeIfNeeded(t)}const o=new Uint8Array(a.o.data.buffer,e,this.totalSize-e);let i=o.findIndex((t=>0===t)),n="";return-1!==i?(n=(new TextDecoder).decode(o.slice(0,i)),a.pos=e+i+1):a.pos=e,n}}const Ae=1<<22;const Ce=new Uint8Array(4),Fe=new DataView(Ce.buffer),xe=new Uint8Array(8),Ie=new DataView(xe.buffer);class Be{constructor(){this.pageSize=16384}_resizeIfNeeded(t){if(t<=this.totalSize)return;if(this.readOnly)throw new Error("Reading out of file bounds");const a=Math.floor((t-1)/Ae)+1;for(let e=Math.max(this.o.data.length-1,0);e0;){const a=i+n>Ae?Ae-i:n,l=t.slice(t.byteLength-n,t.byteLength-n+a);new Uint8Array(e.o.data[o].buffer,i,a).set(l),n-=a,o++,i=0}this.pos=a+t.byteLength}async readToBuffer(t,a,e,o){const i=this;if(void 0===o&&(o=i.pos),this.readOnly&&o+e>this.totalSize)throw new Error("Reading out of bounds");this._resizeIfNeeded(o+e);let n=Math.floor(o/Ae),l=o%Ae,c=e;for(;c>0;){const o=l+c>Ae?Ae-l:c,s=new Uint8Array(i.o.data[n].buffer,l,o);t.set(s,a+e-c),c-=o,n++,l=0}this.pos=o+e}async read(t,a){const e=new Uint8Array(t);return await this.readToBuffer(e,0,t,a),e}close(){}async discard(){}async writeULE32(t,a){Fe.setUint32(0,t,!0),await this.write(Ce,a)}async writeUBE32(t,a){Fe.setUint32(0,t,!1),await this.write(Ce,a)}async writeULE64(t,a){Ie.setUint32(0,4294967295&t,!0),Ie.setUint32(4,Math.floor(t/4294967296),!0),await this.write(xe,a)}async readULE32(t){const a=await this.read(4,t);return new Uint32Array(a.buffer)[0]}async readUBE32(t){const a=await this.read(4,t);return new DataView(a.buffer).getUint32(0,!1)}async readULE64(t){const a=await this.read(8,t),e=new Uint32Array(a.buffer);return 4294967296*e[1]+e[0]}async readString(t){const a=this;let e=void 0===t?a.pos:t;if(e>this.totalSize){if(this.readOnly)throw new Error("Reading out of bounds");this._resizeIfNeeded(t)}let o=!1,i="";for(;!o;){let t=Math.floor(e/Ae),n=e%Ae;if(void 0===a.o.data[t])throw new Error("ERROR");let l=Math.min(2048,a.o.data[t].length-n);const c=new Uint8Array(a.o.data[t].buffer,n,l);let s=c.findIndex((t=>0===t));o=-1!==s,o?(i+=(new TextDecoder).decode(c.slice(0,s)),a.pos=t*Ae+n+s+1):(i+=(new TextDecoder).decode(c),a.pos=t*Ae+n+c.length),e=a.pos}return i}}const Ee=1024,ve=512,Se=2,Pe=0,qe=65536,Oe=8192;async function Ge(t,a,e){if("string"==typeof t&&(t={type:"file",fileName:t,cacheSize:a||qe,pageSize:e||Oe}),"file"==t.type)return await he(t.fileName,Ee|ve|Se,t.cacheSize,t.pageSize);if("mem"==t.type)return function(t){const a=t.initialSize||1<<20,e=new ye;return e.o=t,e.o.data=new Uint8Array(a),e.allocSize=a,e.totalSize=0,e.readOnly=!1,e.pos=0,e}(t);if("bigMem"==t.type)return function(t){const a=t.initialSize||0,e=new Be;e.o=t;const o=a?Math.floor((a-1)/Ae)+1:0;e.o.data=[];for(let t=0;te)throw new Error("Version not supported");const s=await n.readULE32();let r=[];for(let t=0;t1)throw new Error(t.fileName+": Section Duplicated "+e);t.pos=a[e][0].p,t.readingSection=a[e][0]}async function Re(t,a){if(void 0===t.readingSection)throw new Error("Not reading a section");if(!a&&t.pos-t.readingSection.p!=t.readingSection.size)throw new Error("Invalid section size reading");delete t.readingSection}async function Ne(t,a,e,o){const i=new Uint8Array(e);_e.toRprLE(i,0,a,e),await t.write(i,o)}async function $e(t,a,e){const o=await t.read(a,e);return _e.fromRprLE(o,0,a)}async function De(t,a,e,o,i){void 0===i&&(i=a[o][0].size);const n=t.pageSize;await ke(t,a,o),await Ue(e,o);for(let a=0;aa[e][0].size)throw new Error("Reading out of the range of the section");let n;return n=i<1<<30?new Uint8Array(i):new Pa(i),await t.readToBuffer(n,0,i,a[e][0].p+o),n}async function Ve(t,a,e,o,i){const n=16*t.pageSize;if(await ke(t,a,i),await ke(e,o,i),a[i][0].size!=o[i][0].size)return!1;const l=a[i][0].size;for(let a=0;a=0)a=await de();else{if(!(["BLS12381"].indexOf(e)>=0))throw new Error(`Curve not supported: ${t}`);a=await ue()}return a}var Xe="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},to={exports:{}},ao=function t(a,e){if(!a){var o=new eo(e);throw Error.captureStackTrace&&Error.captureStackTrace(o,t),o}};class eo extends Error{}eo.prototype.name="AssertionError";var oo={exports:{}};function io(t){return t.length}var no={byteLength:io,toString:function(t){const a=t.byteLength;let e="";for(let o=0;o1&&61===t.charCodeAt(a-1)&&a--,3*a>>>2}co[45]=62,co[95]=63;var ro={byteLength:so,toString:function(t){const a=t.byteLength;let e="";for(let o=0;o>2]+lo[(3&t[o])<<4|t[o+1]>>4]+lo[(15&t[o+1])<<2|t[o+2]>>6]+lo[63&t[o+2]];return a%3==2?e=e.substring(0,e.length-1)+"=":a%3==1&&(e=e.substring(0,e.length-2)+"=="),e},write:function(t,a,e=0,o=so(a)){const i=Math.min(o,t.byteLength-e);for(let e=0,o=0;o>4,t[o++]=(15&n)<<4|l>>2,t[o++]=(3&l)<<6|63&c}return i}};function uo(t){return t.length>>>1}var _o={byteLength:uo,toString:function(t){const a=t.byteLength;t=new DataView(t.buffer,t.byteOffset,a);let e="",o=0;for(let i=a-a%4;o=48&&t<=57?t-48:t>=65&&t<=70?t-65+10:t>=97&&t<=102?t-97+10:void 0}function fo(t){let a=0;for(let e=0,o=t.length;e=55296&&i<=56319&&e+1=56320&&o<=57343){a+=4,e++;continue}}a+=i<=127?1:i<=2047?2:3}return a}let ho,po;if("undefined"!=typeof TextDecoder){const t=new TextDecoder;ho=function(a){return t.decode(a)}}else ho=function(t){const a=t.byteLength;let e="",o=0;for(;o0){let a=0;for(;a>o,o-=6;o>=0;)t[l++]=128|e>>o&63,o-=6;n+=e>=65536?2:1}return i};var mo={byteLength:fo,toString:ho,write:po};function Lo(t){return 2*t.length}var bo,wo,yo={byteLength:Lo,toString:function(t){const a=t.byteLength;let e="";for(let o=0;o>8,l=i%256;t[e+2*o]=l,t[e+2*o+1]=n}return i}};!function(t,a){const e=no,o=ro,i=_o,n=mo,l=yo,c=255===new Uint8Array(Uint16Array.of(255).buffer)[0];function s(t){switch(t){case"ascii":return e;case"base64":return o;case"hex":return i;case"utf8":case"utf-8":case void 0:return n;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return l;default:throw new Error(`Unknown encoding: ${t}`)}}function r(t){return t instanceof Uint8Array}function d(t,a,e){return"string"==typeof t?function(t,a){const e=s(a),o=new Uint8Array(e.byteLength(t));return e.write(o,t,0,o.byteLength),o}(t,a):Array.isArray(t)?function(t){const a=new Uint8Array(t.length);return a.set(t),a}(t):ArrayBuffer.isView(t)?function(t){const a=new Uint8Array(t.byteLength);return a.set(t),a}(t):function(t,a,e){return new Uint8Array(t,a,e)}(t,a,e)}function u(t,a,e,o,i){if(0===t.byteLength)return-1;if("string"==typeof e?(o=e,e=0):void 0===e?e=i?0:t.length-1:e<0&&(e+=t.byteLength),e>=t.byteLength){if(i)return-1;e=t.byteLength-1}else if(e<0){if(!i)return-1;e=0}if("string"==typeof a)a=d(a,o);else if("number"==typeof a)return a&=255,i?t.indexOf(a,e):t.lastIndexOf(a,e);if(0===a.byteLength)return-1;if(i){let o=-1;for(let i=e;it.byteLength&&(e=t.byteLength-a.byteLength);for(let o=e;o>=0;o--){let e=!0;for(let i=0;ii)return 1}return t.byteLength>a.byteLength?1:t.byteLengtht+a.byteLength),0));const e=new Uint8Array(a);let o=0;for(const a of t){if(o+a.byteLength>e.byteLength){const t=a.subarray(0,e.byteLength-o);return e.set(t,o),e}e.set(a,o),o+=a.byteLength}return e},copy:function(t,a,e=0,o=0,i=t.byteLength){if(i>0&&i=t.byteLength)throw new RangeError("sourceStart is out of range");if(i<0)throw new RangeError("sourceEnd is out of range");e>=a.byteLength&&(e=a.byteLength),i>t.byteLength&&(i=t.byteLength),a.byteLength-e=i||o<=e?"":(e<0&&(e=0),o>i&&(o=i),(0!==e||o{for(var t=new Uint8Array(128),a=0;a<64;a++)t[a<26?a+65:a<52?a+71:a<62?a-4:4*a-205]=a;return a=>{for(var e=a.length,o=new Uint8Array(3*(e-("="==a[e-1])-("="==a[e-2]))/4|0),i=0,n=0;i>4,o[n++]=c<<4|s>>2,o[n++]=s<<6|r}return o}})(),a=((t,a)=>function(){return a||(0,t[Object.keys(t)[0]])((a={exports:{}}).exports,a),a.exports})({"wasm-binary:./blake2b.wat"(a,e){e.exports=t("AGFzbQEAAAABEANgAn9/AGADf39/AGABfwADBQQAAQICBQUBAQroBwdNBQZtZW1vcnkCAAxibGFrZTJiX2luaXQAAA5ibGFrZTJiX3VwZGF0ZQABDWJsYWtlMmJfZmluYWwAAhBibGFrZTJiX2NvbXByZXNzAAMKvz8EwAIAIABCADcDACAAQgA3AwggAEIANwMQIABCADcDGCAAQgA3AyAgAEIANwMoIABCADcDMCAAQgA3AzggAEIANwNAIABCADcDSCAAQgA3A1AgAEIANwNYIABCADcDYCAAQgA3A2ggAEIANwNwIABCADcDeCAAQoiS853/zPmE6gBBACkDAIU3A4ABIABCu86qptjQ67O7f0EIKQMAhTcDiAEgAEKr8NP0r+68tzxBECkDAIU3A5ABIABC8e30+KWn/aelf0EYKQMAhTcDmAEgAELRhZrv+s+Uh9EAQSApAwCFNwOgASAAQp/Y+dnCkdqCm39BKCkDAIU3A6gBIABC6/qG2r+19sEfQTApAwCFNwOwASAAQvnC+JuRo7Pw2wBBOCkDAIU3A7gBIABCADcDwAEgAEIANwPIASAAQgA3A9ABC20BA38gAEHAAWohAyAAQcgBaiEEIAQpAwCnIQUCQANAIAEgAkYNASAFQYABRgRAIAMgAykDACAFrXw3AwBBACEFIAAQAwsgACAFaiABLQAAOgAAIAVBAWohBSABQQFqIQEMAAsLIAQgBa03AwALYQEDfyAAQcABaiEBIABByAFqIQIgASABKQMAIAIpAwB8NwMAIABCfzcD0AEgAikDAKchAwJAA0AgA0GAAUYNASAAIANqQQA6AAAgA0EBaiEDDAALCyACIAOtNwMAIAAQAwuqOwIgfgl/IABBgAFqISEgAEGIAWohIiAAQZABaiEjIABBmAFqISQgAEGgAWohJSAAQagBaiEmIABBsAFqIScgAEG4AWohKCAhKQMAIQEgIikDACECICMpAwAhAyAkKQMAIQQgJSkDACEFICYpAwAhBiAnKQMAIQcgKCkDACEIQoiS853/zPmE6gAhCUK7zqqm2NDrs7t/IQpCq/DT9K/uvLc8IQtC8e30+KWn/aelfyEMQtGFmu/6z5SH0QAhDUKf2PnZwpHagpt/IQ5C6/qG2r+19sEfIQ9C+cL4m5Gjs/DbACEQIAApAwAhESAAKQMIIRIgACkDECETIAApAxghFCAAKQMgIRUgACkDKCEWIAApAzAhFyAAKQM4IRggACkDQCEZIAApA0ghGiAAKQNQIRsgACkDWCEcIAApA2AhHSAAKQNoIR4gACkDcCEfIAApA3ghICANIAApA8ABhSENIA8gACkD0AGFIQ8gASAFIBF8fCEBIA0gAYVCIIohDSAJIA18IQkgBSAJhUIYiiEFIAEgBSASfHwhASANIAGFQhCKIQ0gCSANfCEJIAUgCYVCP4ohBSACIAYgE3x8IQIgDiAChUIgiiEOIAogDnwhCiAGIAqFQhiKIQYgAiAGIBR8fCECIA4gAoVCEIohDiAKIA58IQogBiAKhUI/iiEGIAMgByAVfHwhAyAPIAOFQiCKIQ8gCyAPfCELIAcgC4VCGIohByADIAcgFnx8IQMgDyADhUIQiiEPIAsgD3whCyAHIAuFQj+KIQcgBCAIIBd8fCEEIBAgBIVCIIohECAMIBB8IQwgCCAMhUIYiiEIIAQgCCAYfHwhBCAQIASFQhCKIRAgDCAQfCEMIAggDIVCP4ohCCABIAYgGXx8IQEgECABhUIgiiEQIAsgEHwhCyAGIAuFQhiKIQYgASAGIBp8fCEBIBAgAYVCEIohECALIBB8IQsgBiALhUI/iiEGIAIgByAbfHwhAiANIAKFQiCKIQ0gDCANfCEMIAcgDIVCGIohByACIAcgHHx8IQIgDSAChUIQiiENIAwgDXwhDCAHIAyFQj+KIQcgAyAIIB18fCEDIA4gA4VCIIohDiAJIA58IQkgCCAJhUIYiiEIIAMgCCAefHwhAyAOIAOFQhCKIQ4gCSAOfCEJIAggCYVCP4ohCCAEIAUgH3x8IQQgDyAEhUIgiiEPIAogD3whCiAFIAqFQhiKIQUgBCAFICB8fCEEIA8gBIVCEIohDyAKIA98IQogBSAKhUI/iiEFIAEgBSAffHwhASANIAGFQiCKIQ0gCSANfCEJIAUgCYVCGIohBSABIAUgG3x8IQEgDSABhUIQiiENIAkgDXwhCSAFIAmFQj+KIQUgAiAGIBV8fCECIA4gAoVCIIohDiAKIA58IQogBiAKhUIYiiEGIAIgBiAZfHwhAiAOIAKFQhCKIQ4gCiAOfCEKIAYgCoVCP4ohBiADIAcgGnx8IQMgDyADhUIgiiEPIAsgD3whCyAHIAuFQhiKIQcgAyAHICB8fCEDIA8gA4VCEIohDyALIA98IQsgByALhUI/iiEHIAQgCCAefHwhBCAQIASFQiCKIRAgDCAQfCEMIAggDIVCGIohCCAEIAggF3x8IQQgECAEhUIQiiEQIAwgEHwhDCAIIAyFQj+KIQggASAGIBJ8fCEBIBAgAYVCIIohECALIBB8IQsgBiALhUIYiiEGIAEgBiAdfHwhASAQIAGFQhCKIRAgCyAQfCELIAYgC4VCP4ohBiACIAcgEXx8IQIgDSAChUIgiiENIAwgDXwhDCAHIAyFQhiKIQcgAiAHIBN8fCECIA0gAoVCEIohDSAMIA18IQwgByAMhUI/iiEHIAMgCCAcfHwhAyAOIAOFQiCKIQ4gCSAOfCEJIAggCYVCGIohCCADIAggGHx8IQMgDiADhUIQiiEOIAkgDnwhCSAIIAmFQj+KIQggBCAFIBZ8fCEEIA8gBIVCIIohDyAKIA98IQogBSAKhUIYiiEFIAQgBSAUfHwhBCAPIASFQhCKIQ8gCiAPfCEKIAUgCoVCP4ohBSABIAUgHHx8IQEgDSABhUIgiiENIAkgDXwhCSAFIAmFQhiKIQUgASAFIBl8fCEBIA0gAYVCEIohDSAJIA18IQkgBSAJhUI/iiEFIAIgBiAdfHwhAiAOIAKFQiCKIQ4gCiAOfCEKIAYgCoVCGIohBiACIAYgEXx8IQIgDiAChUIQiiEOIAogDnwhCiAGIAqFQj+KIQYgAyAHIBZ8fCEDIA8gA4VCIIohDyALIA98IQsgByALhUIYiiEHIAMgByATfHwhAyAPIAOFQhCKIQ8gCyAPfCELIAcgC4VCP4ohByAEIAggIHx8IQQgECAEhUIgiiEQIAwgEHwhDCAIIAyFQhiKIQggBCAIIB58fCEEIBAgBIVCEIohECAMIBB8IQwgCCAMhUI/iiEIIAEgBiAbfHwhASAQIAGFQiCKIRAgCyAQfCELIAYgC4VCGIohBiABIAYgH3x8IQEgECABhUIQiiEQIAsgEHwhCyAGIAuFQj+KIQYgAiAHIBR8fCECIA0gAoVCIIohDSAMIA18IQwgByAMhUIYiiEHIAIgByAXfHwhAiANIAKFQhCKIQ0gDCANfCEMIAcgDIVCP4ohByADIAggGHx8IQMgDiADhUIgiiEOIAkgDnwhCSAIIAmFQhiKIQggAyAIIBJ8fCEDIA4gA4VCEIohDiAJIA58IQkgCCAJhUI/iiEIIAQgBSAafHwhBCAPIASFQiCKIQ8gCiAPfCEKIAUgCoVCGIohBSAEIAUgFXx8IQQgDyAEhUIQiiEPIAogD3whCiAFIAqFQj+KIQUgASAFIBh8fCEBIA0gAYVCIIohDSAJIA18IQkgBSAJhUIYiiEFIAEgBSAafHwhASANIAGFQhCKIQ0gCSANfCEJIAUgCYVCP4ohBSACIAYgFHx8IQIgDiAChUIgiiEOIAogDnwhCiAGIAqFQhiKIQYgAiAGIBJ8fCECIA4gAoVCEIohDiAKIA58IQogBiAKhUI/iiEGIAMgByAefHwhAyAPIAOFQiCKIQ8gCyAPfCELIAcgC4VCGIohByADIAcgHXx8IQMgDyADhUIQiiEPIAsgD3whCyAHIAuFQj+KIQcgBCAIIBx8fCEEIBAgBIVCIIohECAMIBB8IQwgCCAMhUIYiiEIIAQgCCAffHwhBCAQIASFQhCKIRAgDCAQfCEMIAggDIVCP4ohCCABIAYgE3x8IQEgECABhUIgiiEQIAsgEHwhCyAGIAuFQhiKIQYgASAGIBd8fCEBIBAgAYVCEIohECALIBB8IQsgBiALhUI/iiEGIAIgByAWfHwhAiANIAKFQiCKIQ0gDCANfCEMIAcgDIVCGIohByACIAcgG3x8IQIgDSAChUIQiiENIAwgDXwhDCAHIAyFQj+KIQcgAyAIIBV8fCEDIA4gA4VCIIohDiAJIA58IQkgCCAJhUIYiiEIIAMgCCARfHwhAyAOIAOFQhCKIQ4gCSAOfCEJIAggCYVCP4ohCCAEIAUgIHx8IQQgDyAEhUIgiiEPIAogD3whCiAFIAqFQhiKIQUgBCAFIBl8fCEEIA8gBIVCEIohDyAKIA98IQogBSAKhUI/iiEFIAEgBSAafHwhASANIAGFQiCKIQ0gCSANfCEJIAUgCYVCGIohBSABIAUgEXx8IQEgDSABhUIQiiENIAkgDXwhCSAFIAmFQj+KIQUgAiAGIBZ8fCECIA4gAoVCIIohDiAKIA58IQogBiAKhUIYiiEGIAIgBiAYfHwhAiAOIAKFQhCKIQ4gCiAOfCEKIAYgCoVCP4ohBiADIAcgE3x8IQMgDyADhUIgiiEPIAsgD3whCyAHIAuFQhiKIQcgAyAHIBV8fCEDIA8gA4VCEIohDyALIA98IQsgByALhUI/iiEHIAQgCCAbfHwhBCAQIASFQiCKIRAgDCAQfCEMIAggDIVCGIohCCAEIAggIHx8IQQgECAEhUIQiiEQIAwgEHwhDCAIIAyFQj+KIQggASAGIB98fCEBIBAgAYVCIIohECALIBB8IQsgBiALhUIYiiEGIAEgBiASfHwhASAQIAGFQhCKIRAgCyAQfCELIAYgC4VCP4ohBiACIAcgHHx8IQIgDSAChUIgiiENIAwgDXwhDCAHIAyFQhiKIQcgAiAHIB18fCECIA0gAoVCEIohDSAMIA18IQwgByAMhUI/iiEHIAMgCCAXfHwhAyAOIAOFQiCKIQ4gCSAOfCEJIAggCYVCGIohCCADIAggGXx8IQMgDiADhUIQiiEOIAkgDnwhCSAIIAmFQj+KIQggBCAFIBR8fCEEIA8gBIVCIIohDyAKIA98IQogBSAKhUIYiiEFIAQgBSAefHwhBCAPIASFQhCKIQ8gCiAPfCEKIAUgCoVCP4ohBSABIAUgE3x8IQEgDSABhUIgiiENIAkgDXwhCSAFIAmFQhiKIQUgASAFIB18fCEBIA0gAYVCEIohDSAJIA18IQkgBSAJhUI/iiEFIAIgBiAXfHwhAiAOIAKFQiCKIQ4gCiAOfCEKIAYgCoVCGIohBiACIAYgG3x8IQIgDiAChUIQiiEOIAogDnwhCiAGIAqFQj+KIQYgAyAHIBF8fCEDIA8gA4VCIIohDyALIA98IQsgByALhUIYiiEHIAMgByAcfHwhAyAPIAOFQhCKIQ8gCyAPfCELIAcgC4VCP4ohByAEIAggGXx8IQQgECAEhUIgiiEQIAwgEHwhDCAIIAyFQhiKIQggBCAIIBR8fCEEIBAgBIVCEIohECAMIBB8IQwgCCAMhUI/iiEIIAEgBiAVfHwhASAQIAGFQiCKIRAgCyAQfCELIAYgC4VCGIohBiABIAYgHnx8IQEgECABhUIQiiEQIAsgEHwhCyAGIAuFQj+KIQYgAiAHIBh8fCECIA0gAoVCIIohDSAMIA18IQwgByAMhUIYiiEHIAIgByAWfHwhAiANIAKFQhCKIQ0gDCANfCEMIAcgDIVCP4ohByADIAggIHx8IQMgDiADhUIgiiEOIAkgDnwhCSAIIAmFQhiKIQggAyAIIB98fCEDIA4gA4VCEIohDiAJIA58IQkgCCAJhUI/iiEIIAQgBSASfHwhBCAPIASFQiCKIQ8gCiAPfCEKIAUgCoVCGIohBSAEIAUgGnx8IQQgDyAEhUIQiiEPIAogD3whCiAFIAqFQj+KIQUgASAFIB18fCEBIA0gAYVCIIohDSAJIA18IQkgBSAJhUIYiiEFIAEgBSAWfHwhASANIAGFQhCKIQ0gCSANfCEJIAUgCYVCP4ohBSACIAYgEnx8IQIgDiAChUIgiiEOIAogDnwhCiAGIAqFQhiKIQYgAiAGICB8fCECIA4gAoVCEIohDiAKIA58IQogBiAKhUI/iiEGIAMgByAffHwhAyAPIAOFQiCKIQ8gCyAPfCELIAcgC4VCGIohByADIAcgHnx8IQMgDyADhUIQiiEPIAsgD3whCyAHIAuFQj+KIQcgBCAIIBV8fCEEIBAgBIVCIIohECAMIBB8IQwgCCAMhUIYiiEIIAQgCCAbfHwhBCAQIASFQhCKIRAgDCAQfCEMIAggDIVCP4ohCCABIAYgEXx8IQEgECABhUIgiiEQIAsgEHwhCyAGIAuFQhiKIQYgASAGIBh8fCEBIBAgAYVCEIohECALIBB8IQsgBiALhUI/iiEGIAIgByAXfHwhAiANIAKFQiCKIQ0gDCANfCEMIAcgDIVCGIohByACIAcgFHx8IQIgDSAChUIQiiENIAwgDXwhDCAHIAyFQj+KIQcgAyAIIBp8fCEDIA4gA4VCIIohDiAJIA58IQkgCCAJhUIYiiEIIAMgCCATfHwhAyAOIAOFQhCKIQ4gCSAOfCEJIAggCYVCP4ohCCAEIAUgGXx8IQQgDyAEhUIgiiEPIAogD3whCiAFIAqFQhiKIQUgBCAFIBx8fCEEIA8gBIVCEIohDyAKIA98IQogBSAKhUI/iiEFIAEgBSAefHwhASANIAGFQiCKIQ0gCSANfCEJIAUgCYVCGIohBSABIAUgHHx8IQEgDSABhUIQiiENIAkgDXwhCSAFIAmFQj+KIQUgAiAGIBh8fCECIA4gAoVCIIohDiAKIA58IQogBiAKhUIYiiEGIAIgBiAffHwhAiAOIAKFQhCKIQ4gCiAOfCEKIAYgCoVCP4ohBiADIAcgHXx8IQMgDyADhUIgiiEPIAsgD3whCyAHIAuFQhiKIQcgAyAHIBJ8fCEDIA8gA4VCEIohDyALIA98IQsgByALhUI/iiEHIAQgCCAUfHwhBCAQIASFQiCKIRAgDCAQfCEMIAggDIVCGIohCCAEIAggGnx8IQQgECAEhUIQiiEQIAwgEHwhDCAIIAyFQj+KIQggASAGIBZ8fCEBIBAgAYVCIIohECALIBB8IQsgBiALhUIYiiEGIAEgBiARfHwhASAQIAGFQhCKIRAgCyAQfCELIAYgC4VCP4ohBiACIAcgIHx8IQIgDSAChUIgiiENIAwgDXwhDCAHIAyFQhiKIQcgAiAHIBV8fCECIA0gAoVCEIohDSAMIA18IQwgByAMhUI/iiEHIAMgCCAZfHwhAyAOIAOFQiCKIQ4gCSAOfCEJIAggCYVCGIohCCADIAggF3x8IQMgDiADhUIQiiEOIAkgDnwhCSAIIAmFQj+KIQggBCAFIBN8fCEEIA8gBIVCIIohDyAKIA98IQogBSAKhUIYiiEFIAQgBSAbfHwhBCAPIASFQhCKIQ8gCiAPfCEKIAUgCoVCP4ohBSABIAUgF3x8IQEgDSABhUIgiiENIAkgDXwhCSAFIAmFQhiKIQUgASAFICB8fCEBIA0gAYVCEIohDSAJIA18IQkgBSAJhUI/iiEFIAIgBiAffHwhAiAOIAKFQiCKIQ4gCiAOfCEKIAYgCoVCGIohBiACIAYgGnx8IQIgDiAChUIQiiEOIAogDnwhCiAGIAqFQj+KIQYgAyAHIBx8fCEDIA8gA4VCIIohDyALIA98IQsgByALhUIYiiEHIAMgByAUfHwhAyAPIAOFQhCKIQ8gCyAPfCELIAcgC4VCP4ohByAEIAggEXx8IQQgECAEhUIgiiEQIAwgEHwhDCAIIAyFQhiKIQggBCAIIBl8fCEEIBAgBIVCEIohECAMIBB8IQwgCCAMhUI/iiEIIAEgBiAdfHwhASAQIAGFQiCKIRAgCyAQfCELIAYgC4VCGIohBiABIAYgE3x8IQEgECABhUIQiiEQIAsgEHwhCyAGIAuFQj+KIQYgAiAHIB58fCECIA0gAoVCIIohDSAMIA18IQwgByAMhUIYiiEHIAIgByAYfHwhAiANIAKFQhCKIQ0gDCANfCEMIAcgDIVCP4ohByADIAggEnx8IQMgDiADhUIgiiEOIAkgDnwhCSAIIAmFQhiKIQggAyAIIBV8fCEDIA4gA4VCEIohDiAJIA58IQkgCCAJhUI/iiEIIAQgBSAbfHwhBCAPIASFQiCKIQ8gCiAPfCEKIAUgCoVCGIohBSAEIAUgFnx8IQQgDyAEhUIQiiEPIAogD3whCiAFIAqFQj+KIQUgASAFIBt8fCEBIA0gAYVCIIohDSAJIA18IQkgBSAJhUIYiiEFIAEgBSATfHwhASANIAGFQhCKIQ0gCSANfCEJIAUgCYVCP4ohBSACIAYgGXx8IQIgDiAChUIgiiEOIAogDnwhCiAGIAqFQhiKIQYgAiAGIBV8fCECIA4gAoVCEIohDiAKIA58IQogBiAKhUI/iiEGIAMgByAYfHwhAyAPIAOFQiCKIQ8gCyAPfCELIAcgC4VCGIohByADIAcgF3x8IQMgDyADhUIQiiEPIAsgD3whCyAHIAuFQj+KIQcgBCAIIBJ8fCEEIBAgBIVCIIohECAMIBB8IQwgCCAMhUIYiiEIIAQgCCAWfHwhBCAQIASFQhCKIRAgDCAQfCEMIAggDIVCP4ohCCABIAYgIHx8IQEgECABhUIgiiEQIAsgEHwhCyAGIAuFQhiKIQYgASAGIBx8fCEBIBAgAYVCEIohECALIBB8IQsgBiALhUI/iiEGIAIgByAafHwhAiANIAKFQiCKIQ0gDCANfCEMIAcgDIVCGIohByACIAcgH3x8IQIgDSAChUIQiiENIAwgDXwhDCAHIAyFQj+KIQcgAyAIIBR8fCEDIA4gA4VCIIohDiAJIA58IQkgCCAJhUIYiiEIIAMgCCAdfHwhAyAOIAOFQhCKIQ4gCSAOfCEJIAggCYVCP4ohCCAEIAUgHnx8IQQgDyAEhUIgiiEPIAogD3whCiAFIAqFQhiKIQUgBCAFIBF8fCEEIA8gBIVCEIohDyAKIA98IQogBSAKhUI/iiEFIAEgBSARfHwhASANIAGFQiCKIQ0gCSANfCEJIAUgCYVCGIohBSABIAUgEnx8IQEgDSABhUIQiiENIAkgDXwhCSAFIAmFQj+KIQUgAiAGIBN8fCECIA4gAoVCIIohDiAKIA58IQogBiAKhUIYiiEGIAIgBiAUfHwhAiAOIAKFQhCKIQ4gCiAOfCEKIAYgCoVCP4ohBiADIAcgFXx8IQMgDyADhUIgiiEPIAsgD3whCyAHIAuFQhiKIQcgAyAHIBZ8fCEDIA8gA4VCEIohDyALIA98IQsgByALhUI/iiEHIAQgCCAXfHwhBCAQIASFQiCKIRAgDCAQfCEMIAggDIVCGIohCCAEIAggGHx8IQQgECAEhUIQiiEQIAwgEHwhDCAIIAyFQj+KIQggASAGIBl8fCEBIBAgAYVCIIohECALIBB8IQsgBiALhUIYiiEGIAEgBiAafHwhASAQIAGFQhCKIRAgCyAQfCELIAYgC4VCP4ohBiACIAcgG3x8IQIgDSAChUIgiiENIAwgDXwhDCAHIAyFQhiKIQcgAiAHIBx8fCECIA0gAoVCEIohDSAMIA18IQwgByAMhUI/iiEHIAMgCCAdfHwhAyAOIAOFQiCKIQ4gCSAOfCEJIAggCYVCGIohCCADIAggHnx8IQMgDiADhUIQiiEOIAkgDnwhCSAIIAmFQj+KIQggBCAFIB98fCEEIA8gBIVCIIohDyAKIA98IQogBSAKhUIYiiEFIAQgBSAgfHwhBCAPIASFQhCKIQ8gCiAPfCEKIAUgCoVCP4ohBSABIAUgH3x8IQEgDSABhUIgiiENIAkgDXwhCSAFIAmFQhiKIQUgASAFIBt8fCEBIA0gAYVCEIohDSAJIA18IQkgBSAJhUI/iiEFIAIgBiAVfHwhAiAOIAKFQiCKIQ4gCiAOfCEKIAYgCoVCGIohBiACIAYgGXx8IQIgDiAChUIQiiEOIAogDnwhCiAGIAqFQj+KIQYgAyAHIBp8fCEDIA8gA4VCIIohDyALIA98IQsgByALhUIYiiEHIAMgByAgfHwhAyAPIAOFQhCKIQ8gCyAPfCELIAcgC4VCP4ohByAEIAggHnx8IQQgECAEhUIgiiEQIAwgEHwhDCAIIAyFQhiKIQggBCAIIBd8fCEEIBAgBIVCEIohECAMIBB8IQwgCCAMhUI/iiEIIAEgBiASfHwhASAQIAGFQiCKIRAgCyAQfCELIAYgC4VCGIohBiABIAYgHXx8IQEgECABhUIQiiEQIAsgEHwhCyAGIAuFQj+KIQYgAiAHIBF8fCECIA0gAoVCIIohDSAMIA18IQwgByAMhUIYiiEHIAIgByATfHwhAiANIAKFQhCKIQ0gDCANfCEMIAcgDIVCP4ohByADIAggHHx8IQMgDiADhUIgiiEOIAkgDnwhCSAIIAmFQhiKIQggAyAIIBh8fCEDIA4gA4VCEIohDiAJIA58IQkgCCAJhUI/iiEIIAQgBSAWfHwhBCAPIASFQiCKIQ8gCiAPfCEKIAUgCoVCGIohBSAEIAUgFHx8IQQgDyAEhUIQiiEPIAogD3whCiAFIAqFQj+KIQUgISAhKQMAIAEgCYWFNwMAICIgIikDACACIAqFhTcDACAjICMpAwAgAyALhYU3AwAgJCAkKQMAIAQgDIWFNwMAICUgJSkDACAFIA2FhTcDACAmICYpAwAgBiAOhYU3AwAgJyAnKQMAIAcgD4WFNwMAICggKCkDACAIIBCFhTcDAAs=")}}),e=a(),o=WebAssembly.compile(e);return bo=async t=>(await WebAssembly.instantiate(await o,t)).exports}()().then((t=>{Fo=t})),Io=64,Bo=[];to.exports=Go;var Eo=to.exports.BYTES_MIN=16,vo=to.exports.BYTES_MAX=64;to.exports.BYTES=32;var So=to.exports.KEYBYTES_MIN=16,Po=to.exports.KEYBYTES_MAX=64;to.exports.KEYBYTES=32;var qo=to.exports.SALTBYTES=16,Oo=to.exports.PERSONALBYTES=16;function Go(t,a,e,o,i){if(!(this instanceof Go))return new Go(t,a,e,o,i);if(!Fo)throw new Error("WASM not loaded. Wait for Blake2b.ready(cb)");t||(t=32),!0!==i&&(Ao(t>=Eo,"digestLength must be at least "+Eo+", was given "+t),Ao(t<=vo,"digestLength must be at most "+vo+", was given "+t),null!=a&&(Ao(a instanceof Uint8Array,"key must be Uint8Array or Buffer"),Ao(a.length>=So,"key must be at least "+So+", was given "+a.length),Ao(a.length<=Po,"key must be at least "+Po+", was given "+a.length)),null!=e&&(Ao(e instanceof Uint8Array,"salt must be Uint8Array or Buffer"),Ao(e.length===qo,"salt must be exactly "+qo+", was given "+e.length)),null!=o&&(Ao(o instanceof Uint8Array,"personal must be Uint8Array or Buffer"),Ao(o.length===Oo,"personal must be exactly "+Oo+", was given "+o.length))),Bo.length||(Bo.push(Io),Io+=216),this.digestLength=t,this.finalized=!1,this.pointer=Bo.pop(),this._memory=new Uint8Array(Fo.memory.buffer),this._memory.fill(0,0,64),this._memory[0]=this.digestLength,this._memory[1]=a?a.length:0,this._memory[2]=1,this._memory[3]=1,e&&this._memory.set(e,32),o&&this._memory.set(o,48),this.pointer+216>this._memory.length&&this._realloc(this.pointer+216),Fo.blake2b_init(this.pointer,this.digestLength),a&&(this.update(a),this._memory.fill(0,Io,Io+a.length),this._memory[this.pointer+200]=128)}function zo(){}function To(t){return(0!=(4294901760&t)?(t&=4294901760,16):0)|(0!=(4278255360&t)?(t&=4278255360,8):0)|(0!=(4042322160&t)?(t&=4042322160,4):0)|(0!=(3435973836&t)?(t&=3435973836,2):0)|0!=(2863311530&t)}function Mo(t,a){const e=new DataView(t.buffer,t.byteOffset,t.byteLength);let o="";for(let t=0;t<4;t++){t>0&&(o+="\n"),o+="\t\t";for(let a=0;a<4;a++)a>0&&(o+=" "),o+=e.getUint32(16*t+4*a).toString(16).padStart(8,"0")}return a&&(o=a+"\n"+o),o}function Uo(t,a){if(t.byteLength!=a.byteLength)return!1;for(var e=new Int8Array(t),o=new Int8Array(a),i=0;i!=t.byteLength;i++)if(e[i]!=o[i])return!1;return!0}function Qo(t){const a=t.getPartialHash(),e=to.exports(64);return e.setPartialHash(a),e}async function ko(t,a,e,o,i){if(t.G1.isZero(a))return!1;if(t.G1.isZero(e))return!1;if(t.G2.isZero(o))return!1;if(t.G2.isZero(i))return!1;return await t.pairingEq(a,i,t.G1.neg(e),o)}function Ro(t){let a=new Uint8Array(t);return globalThis.crypto.getRandomValues(a),a}async function No(t){{const a=await globalThis.crypto.subtle.digest("SHA-256",t.buffer);return new Uint8Array(a)}}function $o(t,a){return new DataView(t.buffer).getUint32(a,!1)}async function Do(t){for(;!t;)t=await window.prompt("Enter a random text. (Entropy): ","");const a=to.exports(64);a.update(Ro(64));const e=new TextEncoder;a.update(e.encode(t));const o=a.digest(),i=[];for(let t=0;t<8;t++)i[t]=$o(o,4*t);return new M(i)}async function jo(t,a){let e,o;a<32?(e=1<>>0,o=1):(e=4294967296,o=1<>>0);let i=t;for(let t=0;t{e[o]=Ho(t,a[o])})),e}return"bigint"==typeof a||void 0!==a.eq?a.toString(10):a}Go.prototype._realloc=function(t){Fo.memory.grow(Math.max(0,Math.ceil(Math.abs(t-this._memory.length)/65536))),this._memory=new Uint8Array(Fo.memory.buffer)},Go.prototype.update=function(t){return Ao(!1===this.finalized,"Hash instance finalized"),Ao(t instanceof Uint8Array,"input must be Uint8Array or Buffer"),Io+t.length>this._memory.length&&this._realloc(Io+t.length),this._memory.set(t,Io),Fo.blake2b_update(this.pointer,Io,Io+t.length),this},Go.prototype.digest=function(t){if(Ao(!1===this.finalized,"Hash instance finalized"),this.finalized=!0,Bo.push(this.pointer),Fo.blake2b_final(this.pointer),!t||"binary"===t)return this._memory.slice(this.pointer+128,this.pointer+128+this.digestLength);if("string"==typeof t)return Co.toString(this._memory,t,this.pointer+128,this.pointer+128+this.digestLength);Ao(t instanceof Uint8Array&&t.length>=this.digestLength,"input must be Uint8Array or Buffer");for(var a=0;at()),t):t(new Error("WebAssembly not supported"))},Go.prototype.ready=Go.ready,Go.prototype.getPartialHash=function(){return this._memory.slice(this.pointer,this.pointer+216)},Go.prototype.setPartialHash=function(t){this._memory.set(t,this.pointer)};const Zo=1,Wo=2,Yo=10,Jo=2,Xo=3,ti=4,ai=5,ei=6,oi=7,ii=8,ni=9,li=10,ci=11,si=12,ri=13,di=14,ui=15,_i=16,gi=17;async function fi(t,a){await Ue(t,1),await t.writeULE32(1),await Qe(t);const e=await Ye(a.q);await Ue(t,2);const o=e.q,i=8*(Math.floor((_e.bitLength(o)-1)/64)+1),n=e.r,l=8*(Math.floor((_e.bitLength(n)-1)/64)+1);await t.writeULE32(i),await Ne(t,o,i),await t.writeULE32(l),await Ne(t,n,l),await t.writeULE32(a.nVars),await t.writeULE32(a.nPublic),await t.writeULE32(a.domainSize),await hi(t,e,a.vk_alpha_1),await hi(t,e,a.vk_beta_1),await pi(t,e,a.vk_beta_2),await pi(t,e,a.vk_gamma_2),await hi(t,e,a.vk_delta_1),await pi(t,e,a.vk_delta_2),await Qe(t)}async function hi(t,a,e){const o=new Uint8Array(2*a.G1.F.n8);a.G1.toRprLEM(o,0,e),await t.write(o)}async function pi(t,a,e){const o=new Uint8Array(2*a.G2.F.n8);a.G2.toRprLEM(o,0,e),await t.write(o)}async function mi(t,a,e){const o=await t.read(2*a.G1.F.n8),i=a.G1.fromRprLEM(o,0);return e?a.G1.toObject(i):i}async function Li(t,a,e){const o=await t.read(2*a.G2.F.n8),i=a.G2.fromRprLEM(o,0);return e?a.G2.toObject(i):i}async function bi(t,a,e){await ke(t,a,1);const o=await t.readULE32();if(await Re(t),o===Zo)return await async function(t,a,e){const o={protocol:"groth16"};await ke(t,a,2);const i=await t.readULE32();o.n8q=i,o.q=await $e(t,i);const n=await t.readULE32();return o.n8r=n,o.r=await $e(t,n),o.curve=await Ye(o.q),o.nVars=await t.readULE32(),o.nPublic=await t.readULE32(),o.domainSize=await t.readULE32(),o.power=To(o.domainSize),o.vk_alpha_1=await mi(t,o.curve,e),o.vk_beta_1=await mi(t,o.curve,e),o.vk_beta_2=await Li(t,o.curve,e),o.vk_gamma_2=await Li(t,o.curve,e),o.vk_delta_1=await mi(t,o.curve,e),o.vk_delta_2=await Li(t,o.curve,e),await Re(t),o}(t,a,e);if(o===Wo)return await async function(t,a,e){const o={protocol:"plonk"};await ke(t,a,2);const i=await t.readULE32();o.n8q=i,o.q=await $e(t,i);const n=await t.readULE32();return o.n8r=n,o.r=await $e(t,n),o.curve=await Ye(o.q),o.nVars=await t.readULE32(),o.nPublic=await t.readULE32(),o.domainSize=await t.readULE32(),o.power=To(o.domainSize),o.nAdditions=await t.readULE32(),o.nConstraints=await t.readULE32(),o.k1=await t.read(n),o.k2=await t.read(n),o.Qm=await mi(t,o.curve,e),o.Ql=await mi(t,o.curve,e),o.Qr=await mi(t,o.curve,e),o.Qo=await mi(t,o.curve,e),o.Qc=await mi(t,o.curve,e),o.S1=await mi(t,o.curve,e),o.S2=await mi(t,o.curve,e),o.S3=await mi(t,o.curve,e),o.X_2=await Li(t,o.curve,e),await Re(t),o}(t,a,e);if(o===Yo)return await async function(t,a,e){const o={protocol:"fflonk"};o.protocolId=Yo,await ke(t,a,Jo);const i=await t.readULE32();o.n8q=i,o.q=await $e(t,i),o.curve=await Ye(o.q);const n=await t.readULE32();return o.n8r=n,o.r=await $e(t,n),o.nVars=await t.readULE32(),o.nPublic=await t.readULE32(),o.domainSize=await t.readULE32(),o.power=To(o.domainSize),o.nAdditions=await t.readULE32(),o.nConstraints=await t.readULE32(),o.k1=await t.read(n),o.k2=await t.read(n),o.w3=await t.read(n),o.w4=await t.read(n),o.w8=await t.read(n),o.wr=await t.read(n),o.X_2=await Li(t,o.curve,e),o.C0=await mi(t,o.curve,e),await Re(t),o}(t,a,e);throw new Error("Protocol not supported: ")}async function wi(t,a,e){const o={delta:{}};o.deltaAfter=await mi(t,a,e),o.delta.g1_s=await mi(t,a,e),o.delta.g1_sx=await mi(t,a,e),o.delta.g2_spx=await Li(t,a,e),o.transcript=await t.read(64),o.type=await t.readULE32();const i=await t.readULE32(),n=t.pos;let l=0;for(;t.pos-n0){const a=new Uint8Array(o);await t.writeULE32(a.byteLength),await t.write(a)}else await t.writeULE32(0)}async function Ci(t,a,e){await Ue(t,10),await t.write(e.csHash),await t.writeULE32(e.contributions.length);for(let o=0;o0;)e.unshift(0),n--;return e}const qi=[0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4];function Oi(t,a){return a&&10!=a?16==a?"0x"==t.slice(0,2)?BigInt(t):BigInt("0x"+t):void 0:BigInt(t)}const Gi=Oi;function zi(t){const a=t.toString(16);return 4*(a.length-1)+qi[parseInt(a[0],16)]}function Ti(t){return!t}function Mi(t,a){return BigInt(t)<>BigInt(a)}const Qi=Mi,ki=Ui;function Ri(t){return(BigInt(t)&BigInt(1))==BigInt(1)}function Ni(t){let a=BigInt(t);const e=[];for(;a;)a&BigInt(1)?e.push(1):e.push(0),a>>=BigInt(1);return e}function $i(t){if(t>BigInt(Number.MAX_SAFE_INTEGER))throw new Error("Number too big");return Number(t)}function Di(t,a){return BigInt(t)-BigInt(a)}function ji(t,a){return BigInt(t)**BigInt(a)}function Vi(t,a){return BigInt(t)/BigInt(a)}function Ki(t,a){return BigInt(t)%BigInt(a)}function Hi(t,a){return BigInt(t)==BigInt(a)}function Zi(t,a){return BigInt(t)&BigInt(a)}function Wi(t,a,e,o){const i="0000000"+e.toString(16),n=new Uint32Array(t.buffer,t.byteOffset+a,o/4),l=1+(4*(i.length-7)-1>>5);for(let t=0;t>5);for(let t=0;ti[i.length-a-1]=t.toString(16).padStart(8,"0"))),Oi(i.join(""),16)}function Xi(t,a,e){e=e||t.byteLength,a=a||0;const o=new DataView(t.buffer,t.byteOffset+a,e),i=new Array(e/4);for(let t=0;t>=BigInt(1)}return e},bits:Ni,toNumber:$i,toArray:function(t,a){const e=[];let o=BigInt(t);for(a=BigInt(a);o;)e.unshift(Number(o%a)),o/=a;return e},add:function(t,a){return BigInt(t)+BigInt(a)},sub:Di,neg:function(t){return-BigInt(t)},mul:function(t,a){return BigInt(t)*BigInt(a)},square:function(t){return BigInt(t)*BigInt(t)},pow:ji,exp:function(t,a){return BigInt(t)**BigInt(a)},abs:function(t){return BigInt(t)>=0?BigInt(t):-BigInt(t)},div:Vi,mod:Ki,eq:Hi,neq:function(t,a){return BigInt(t)!=BigInt(a)},lt:function(t,a){return BigInt(t)BigInt(a)},leq:function(t,a){return BigInt(t)<=BigInt(a)},geq:function(t,a){return BigInt(t)>=BigInt(a)},band:Zi,bor:function(t,a){return BigInt(t)|BigInt(a)},bxor:function(t,a){return BigInt(t)^BigInt(a)},land:function(t,a){return BigInt(t)&&BigInt(a)},lor:function(t,a){return BigInt(t)||BigInt(a)},lnot:function(t){return!BigInt(t)},toRprLE:Wi,toRprBE:Yi,fromRprLE:Ji,fromRprBE:Xi,toString:function(t,a){return t.toString(a)},toLEBuff:function(t){const a=new Uint8Array(Math.floor((zi(t)-1)/8)+1);return Wi(a,0,t,a.byteLength),a},zero:tn,one:an});function on(t,a,e){if(Ti(e))return t.one;const o=Ni(e);if(0==o.length)return t.one;let i=a;for(let e=o.length-2;e>=0;e--)i=t.square(i),o[e]&&(i=t.mul(i,a));return i}function nn(t){if(t.m%2==1)if(Hi(Ki(t.p,4),1))if(Hi(Ki(t.p,8),1))if(Hi(Ki(t.p,16),1))!function(t){t.sqrt_q=ji(t.p,t.m),t.sqrt_s=0,t.sqrt_t=Di(t.sqrt_q,1);for(;!Ri(t.sqrt_t);)t.sqrt_s=t.sqrt_s+1,t.sqrt_t=Vi(t.sqrt_t,2);let a=t.one;for(;t.eq(a,t.one);){const e=t.random();t.sqrt_z=t.pow(e,t.sqrt_t),a=t.pow(t.sqrt_z,2**(t.sqrt_s-1))}t.sqrt_tm1d2=Vi(Di(t.sqrt_t,1),2),t.sqrt=function(t){const a=this;if(a.isZero(t))return a.zero;let e=a.pow(t,a.sqrt_tm1d2);const o=a.pow(a.mul(a.square(e),t),2**(a.sqrt_s-1));if(a.eq(o,a.negone))return null;let i=a.sqrt_s,n=a.mul(t,e),l=a.mul(n,e),c=a.sqrt_z;for(;!a.eq(l,a.one);){let t=a.square(l),o=1;for(;!a.eq(t,a.one);)t=a.square(t),o++;e=c;for(let t=0;t>>0;return a}class cn{constructor(t,a,e){this.F=a,this.G=t,this.opMulGF=e;let o=a.sqrt_t||a.t,i=a.sqrt_s||a.s,n=a.one;for(;a.eq(a.pow(n,a.half),a.one);)n=a.add(n,a.one);this.w=new Array(i+1),this.wi=new Array(i+1),this.w[i]=this.F.pow(n,o),this.wi[i]=this.F.inv(this.w[i]);let l=i-1;for(;l>=0;)this.w[l]=this.F.square(this.w[l+1]),this.wi[l]=this.F.square(this.wi[l+1]),l--;this.roots=[],this._setRoots(Math.min(i,15))}_setRoots(t){for(let a=t;a>=0&&!this.roots[a];a--){let t=this.F.one;const e=1<>1,c=rn(t,a,e-1,o,2*i),s=rn(t,a,e-1,o+i,2*i),r=new Array(n);for(let a=0;a>this.one,this.bitLength=zi(this.p),this.mask=(this.one<>this.one;this.nqr=this.two;let e=this.pow(this.nqr,a);for(;!this.eq(e,this.negone);)this.nqr=this.nqr+this.one,e=this.pow(this.nqr,a);for(this.s=0,this.t=this.negone;(this.t&this.one)==this.zero;)this.s=this.s+1,this.t=this.t>>this.one;this.nqr_to_t=this.pow(this.nqr,this.t),nn(this),this.FFT=new cn(this,this,this.mul.bind(this)),this.fft=this.FFT.fft.bind(this.FFT),this.ifft=this.FFT.ifft.bind(this.FFT),this.w=this.FFT.w,this.wi=this.FFT.wi,this.shift=this.square(this.nqr),this.k=this.exp(this.nqr,2**this.s)}e(t,a){let e;if(a?16==a&&(e=BigInt("0x"+t)):e=BigInt(t),e<0){let t=-e;return t>=this.p&&(t%=this.p),this.p-t}return e>=this.p?e%this.p:e}add(t,a){const e=t+a;return e>=this.p?e-this.p:e}sub(t,a){return t>=a?t-a:this.p-a+t}neg(t){return t?this.p-t:t}mul(t,a){return t*a%this.p}mulScalar(t,a){return t*this.e(a)%this.p}square(t){return t*t%this.p}eq(t,a){return t==a}neq(t,a){return t!=a}lt(t,a){return(t>this.half?t-this.p:t)<(a>this.half?a-this.p:a)}gt(t,a){return(t>this.half?t-this.p:t)>(a>this.half?a-this.p:a)}leq(t,a){return(t>this.half?t-this.p:t)<=(a>this.half?a-this.p:a)}geq(t,a){return(t>this.half?t-this.p:t)>=(a>this.half?a-this.p:a)}div(t,a){return this.mul(t,this.inv(a))}idiv(t,a){if(!a)throw new Error("Division by zero");return t/a}inv(t){if(!t)throw new Error("Division by zero");let a=this.zero,e=this.p,o=this.one,i=t%this.p;for(;i;){let t=e/i;[a,o]=[o,a-t*o],[e,i]=[i,e-t*i]}return a=this.p?e-this.p:e}bor(t,a){const e=(t|a)&this.mask;return e>=this.p?e-this.p:e}bxor(t,a){const e=(t^a)&this.mask;return e>=this.p?e-this.p:e}bnot(t){const a=t^this.mask;return a>=this.p?a-this.p:a}shl(t,a){if(Number(a)=this.p?e-this.p:e}{const e=this.p-a;return Number(e)>e:this.zero}}shr(t,a){if(Number(a)>a;{const e=this.p-a;if(Number(e)=this.p?a-this.p:a}return 0}}land(t,a){return t&&a?this.one:this.zero}lor(t,a){return t||a?this.one:this.zero}lnot(t){return t?this.zero:this.one}sqrt_old(t){if(t==this.zero)return this.zero;if(this.pow(t,this.negone>>this.one)!=this.one)return null;let a=this.s,e=this.nqr_to_t,o=this.pow(t,this.t),i=this.pow(t,this.add(this.t,this.one)>>this.one);for(;o!=this.one;){let t=this.square(o),n=1;for(;t!=this.one;)n++,t=this.square(t);let l=e;for(let t=0;tthis.p>>this.one&&(i=this.neg(i)),i}normalize(t,a){if((t=BigInt(t,a))<0){let a=-t;return a>=this.p&&(a%=this.p),this.p-a}return t>=this.p?t%this.p:t}random(){const t=2*this.bitLength/8;let a=this.zero;for(let e=0;ethis.half&&10==a){e="-"+(this.p-t).toString(a)}else e=t.toString(a);return e}isZero(t){return t==this.zero}fromRng(t){let a;do{a=this.zero;for(let e=0;e=this.p);return a=a*this.Ri%this.p,a}fft(t){return this.FFT.fft(t)}ifft(t){return this.FFT.ifft(t)}toRprLE(t,a,e){Wi(t,a,e,8*this.n64)}toRprBE(t,a,e){Yi(t,a,e,8*this.n64)}toRprBEM(t,a,e){return this.toRprBE(t,a,this.mul(this.R,e))}toRprLEM(t,a,e){return this.toRprLE(t,a,this.mul(this.R,e))}fromRprLE(t,a){return Ji(t,a,this.n8)}fromRprBE(t,a){return Xi(t,a,this.n8)}fromRprLEM(t,a){return this.mul(this.fromRprLE(t,a),this.Ri)}fromRprBEM(t,a){return this.mul(this.fromRprBE(t,a),this.Ri)}toObject(t){return t}}var un={bigInt2BytesLE:function(t,a){const e=Array(a);let o=BigInt(t);for(let t=0;t>=8n;return e},bigInt2U32LE:function(t,a){const e=Array(a);let o=BigInt(t);for(let t=0;t>=32n;return e},isOcamNum:function(t){return!!Array.isArray(t)&&(3==t.length&&("number"==typeof t[0]&&("number"==typeof t[1]&&!!Array.isArray(t[2]))))}},_n=function(t,a,e,o,i,n,l){const c=t.addFunction(a);c.addParam("base","i32"),c.addParam("scalar","i32"),c.addParam("scalarLength","i32"),c.addParam("r","i32"),c.addLocal("i","i32"),c.addLocal("b","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(e));c.addCode(s.if(s.i32_eqz(s.getLocal("scalarLength")),[...s.call(l,s.getLocal("r")),...s.ret([])])),c.addCode(s.call(n,s.getLocal("base"),r)),c.addCode(s.call(l,s.getLocal("r"))),c.addCode(s.setLocal("i",s.getLocal("scalarLength"))),c.addCode(s.block(s.loop(s.setLocal("i",s.i32_sub(s.getLocal("i"),s.i32_const(1))),s.setLocal("b",s.i32_load8_u(s.i32_add(s.getLocal("scalar"),s.getLocal("i")))),...function(){const t=[];for(let a=0;a<8;a++)t.push(...s.call(i,s.getLocal("r"),s.getLocal("r")),...s.if(s.i32_ge_u(s.getLocal("b"),s.i32_const(128>>a)),[...s.setLocal("b",s.i32_sub(s.getLocal("b"),s.i32_const(128>>a))),...s.call(o,s.getLocal("r"),r,s.getLocal("r"))]));return t}(),s.br_if(1,s.i32_eqz(s.getLocal("i"))),s.br(0))))},gn=function(t,a){const e=8*t.modules[a].n64,o=t.addFunction(a+"_batchInverse");o.addParam("pIn","i32"),o.addParam("inStep","i32"),o.addParam("n","i32"),o.addParam("pOut","i32"),o.addParam("outStep","i32"),o.addLocal("itAux","i32"),o.addLocal("itIn","i32"),o.addLocal("itOut","i32"),o.addLocal("i","i32");const i=o.getCodeBuilder(),n=i.i32_const(t.alloc(e));o.addCode(i.setLocal("itAux",i.i32_load(i.i32_const(0))),i.i32_store(i.i32_const(0),i.i32_add(i.getLocal("itAux"),i.i32_mul(i.i32_add(i.getLocal("n"),i.i32_const(1)),i.i32_const(e))))),o.addCode(i.call(a+"_one",i.getLocal("itAux")),i.setLocal("itIn",i.getLocal("pIn")),i.setLocal("itAux",i.i32_add(i.getLocal("itAux"),i.i32_const(e))),i.setLocal("i",i.i32_const(0)),i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("i"),i.getLocal("n"))),i.if(i.call(a+"_isZero",i.getLocal("itIn")),i.call(a+"_copy",i.i32_sub(i.getLocal("itAux"),i.i32_const(e)),i.getLocal("itAux")),i.call(a+"_mul",i.getLocal("itIn"),i.i32_sub(i.getLocal("itAux"),i.i32_const(e)),i.getLocal("itAux"))),i.setLocal("itIn",i.i32_add(i.getLocal("itIn"),i.getLocal("inStep"))),i.setLocal("itAux",i.i32_add(i.getLocal("itAux"),i.i32_const(e))),i.setLocal("i",i.i32_add(i.getLocal("i"),i.i32_const(1))),i.br(0))),i.setLocal("itIn",i.i32_sub(i.getLocal("itIn"),i.getLocal("inStep"))),i.setLocal("itAux",i.i32_sub(i.getLocal("itAux"),i.i32_const(e))),i.setLocal("itOut",i.i32_add(i.getLocal("pOut"),i.i32_mul(i.i32_sub(i.getLocal("n"),i.i32_const(1)),i.getLocal("outStep")))),i.call(a+"_inverse",i.getLocal("itAux"),i.getLocal("itAux")),i.block(i.loop(i.br_if(1,i.i32_eqz(i.getLocal("i"))),i.if(i.call(a+"_isZero",i.getLocal("itIn")),[...i.call(a+"_copy",i.getLocal("itAux"),i.i32_sub(i.getLocal("itAux"),i.i32_const(e))),...i.call(a+"_zero",i.getLocal("itOut"))],[...i.call(a+"_copy",i.i32_sub(i.getLocal("itAux"),i.i32_const(e)),n),...i.call(a+"_mul",i.getLocal("itAux"),i.getLocal("itIn"),i.i32_sub(i.getLocal("itAux"),i.i32_const(e))),...i.call(a+"_mul",i.getLocal("itAux"),n,i.getLocal("itOut"))]),i.setLocal("itIn",i.i32_sub(i.getLocal("itIn"),i.getLocal("inStep"))),i.setLocal("itOut",i.i32_sub(i.getLocal("itOut"),i.getLocal("outStep"))),i.setLocal("itAux",i.i32_sub(i.getLocal("itAux"),i.i32_const(e))),i.setLocal("i",i.i32_sub(i.getLocal("i"),i.i32_const(1))),i.br(0)))),o.addCode(i.i32_store(i.i32_const(0),i.getLocal("itAux")))};var fn=function(t,a,e,o,i,n){void 0===n&&(n=oa?1:-1}function Ln(t){return t*t}function bn(t){return t%2n!==0n}function wn(t){return t%2n===0n}function yn(t){return t<0n}function An(t){return t>0n}function Cn(t){return yn(t)?t.toString(2).length-1:t.toString(2).length}function Fn(t){return t<0n?-t:t}function xn(t){return 1n===Fn(t)}function In(t,a){for(var e,o,i,n=0n,l=1n,c=a,s=Fn(t);0n!==s;)e=c/s,o=n,i=c,n=l,c=s,l=o-e*l,s=i-e*s;if(!xn(c))throw new Error(t.toString()+" and "+a.toString()+" are not co-prime");return-1===mn(n,0n)&&(n+=a),yn(t)?-n:n}function Bn(t,a,e){if(0n===e)throw new Error("Cannot take modPow with modulus 0");var o=1n,i=t%e;for(yn(a)&&(a*=-1n,i=In(i,e));An(a);){if(0n===i)return 0n;bn(a)&&(o=o*i%e),a/=2n,i=Ln(i)%e}return o}function En(t,a){return 0n!==a&&(!!xn(a)||(0===function(t,a){return(t=t>=0n?t:-t)===(a=a>=0n?a:-a)?0:t>a?1:-1}(a,2n)?wn(t):t%a===0n))}function vn(t,a){for(var e,o,i,n=function(t){return t-1n}(t),l=n,c=0;wn(l);)l/=2n,c++;t:for(o=0;o>1&&o>1,t>>1)))),a.addCode(e.setLocal(s,e.i64_add(e.getLocal(s),e.i64_shr_u(e.getLocal(c),e.i64_const(32)))))),t>0&&(a.addCode(e.setLocal(c,e.i64_add(e.i64_and(e.getLocal(c),e.i64_const(4294967295)),e.i64_and(e.getLocal(r),e.i64_const(4294967295))))),a.addCode(e.setLocal(s,e.i64_add(e.i64_add(e.getLocal(s),e.i64_shr_u(e.getLocal(c),e.i64_const(32))),e.getLocal(d))))),a.addCode(e.i64_store32(e.getLocal("r"),4*t,e.getLocal(c))),a.addCode(e.setLocal(r,e.getLocal(s)),e.setLocal(d,e.i64_shr_u(e.getLocal(r),e.i64_const(32))))}a.addCode(e.i64_store32(e.getLocal("r"),4*i*2-4,e.getLocal(r)))}(),function(){const a=t.addFunction(o+"_squareOld");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(o+"_mul",e.getLocal("x"),e.getLocal("x"),e.getLocal("r")))}(),function(){!function(){const a=t.addFunction(o+"__mul1");a.addParam("px","i32"),a.addParam("y","i64"),a.addParam("pr","i32"),a.addLocal("c","i64");const e=a.getCodeBuilder();a.addCode(e.setLocal("c",e.i64_mul(e.i64_load32_u(e.getLocal("px"),0,0),e.getLocal("y")))),a.addCode(e.i64_store32(e.getLocal("pr"),0,0,e.getLocal("c")));for(let t=1;t>1n,p=t.alloc(c,Pn.bigInt2BytesLE(h,c)),m=h+1n,L=t.alloc(c,Pn.bigInt2BytesLE(m,c));t.modules[s]={pq:d,pR2:u,n64:n,q:i,pOne:_,pZero:g,pePlusOne:L};let b=2n;if(Qn(i))for(;Un(b,h,i)!==f;)b+=1n;let w=0,y=f;for(;!kn(y)&&0n!==y;)w++,y>>=1n;const A=t.alloc(c,Pn.bigInt2BytesLE(y,c)),C=Un(b,y,i),F=t.alloc(Pn.bigInt2BytesLE((C<>1n,I=t.alloc(c,Pn.bigInt2BytesLE(x,c));return t.exportFunction(r+"_copy",s+"_copy"),t.exportFunction(r+"_zero",s+"_zero"),t.exportFunction(r+"_isZero",s+"_isZero"),t.exportFunction(r+"_eq",s+"_eq"),function(){const a=t.addFunction(s+"_isOne");a.addParam("x","i32"),a.setReturnType("i32");const e=a.getCodeBuilder();a.addCode(e.ret(e.call(r+"_eq",e.getLocal("x"),e.i32_const(_))))}(),function(){const a=t.addFunction(s+"_add");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.if(e.call(r+"_add",e.getLocal("x"),e.getLocal("y"),e.getLocal("r")),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))),e.if(e.call(r+"_gte",e.getLocal("r"),e.i32_const(d)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))))))}(),function(){const a=t.addFunction(s+"_sub");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.if(e.call(r+"_sub",e.getLocal("x"),e.getLocal("y"),e.getLocal("r")),e.drop(e.call(r+"_add",e.getLocal("r"),e.i32_const(d),e.getLocal("r")))))}(),function(){const a=t.addFunction(s+"_neg");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_sub",e.i32_const(g),e.getLocal("x"),e.getLocal("r")))}(),function(){const a=t.alloc(l*l*8),e=t.addFunction(s+"_mReduct");e.addParam("t","i32"),e.addParam("r","i32"),e.addLocal("np32","i64"),e.addLocal("c","i64"),e.addLocal("m","i64");const o=e.getCodeBuilder(),n=Number(0x100000000n-Mn(i,0x100000000n));e.addCode(o.setLocal("np32",o.i64_const(n)));for(let t=0;t=l&&a.addCode(e.i64_store32(e.getLocal("r"),4*(t-l),e.getLocal(f))),[f,h]=[h,f],a.addCode(e.setLocal(h,e.i64_shr_u(e.getLocal(f),e.i64_const(32))))}a.addCode(e.i64_store32(e.getLocal("r"),4*l-4,e.getLocal(f))),a.addCode(e.if(e.i32_wrap_i64(e.getLocal(h)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))),e.if(e.call(r+"_gte",e.getLocal("r"),e.i32_const(d)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))))))}(),function(){const a=t.addFunction(s+"_square");a.addParam("x","i32"),a.addParam("r","i32"),a.addLocal("c0","i64"),a.addLocal("c1","i64"),a.addLocal("c0_old","i64"),a.addLocal("c1_old","i64"),a.addLocal("np32","i64");for(let t=0;t>1&&o>1,t>>1)))),a.addCode(e.setLocal(f,e.i64_add(e.getLocal(f),e.i64_shr_u(e.getLocal(g),e.i64_const(32)))))),t>0&&(a.addCode(e.setLocal(g,e.i64_add(e.i64_and(e.getLocal(g),e.i64_const(4294967295)),e.i64_and(e.getLocal(h),e.i64_const(4294967295))))),a.addCode(e.setLocal(f,e.i64_add(e.i64_add(e.getLocal(f),e.i64_shr_u(e.getLocal(g),e.i64_const(32))),e.getLocal(p)))));for(let o=Math.max(1,t-l+1);o<=t&&o=l&&a.addCode(e.i64_store32(e.getLocal("r"),4*(t-l),e.getLocal(g))),a.addCode(e.setLocal(h,e.getLocal(f)),e.setLocal(p,e.i64_shr_u(e.getLocal(h),e.i64_const(32))))}a.addCode(e.i64_store32(e.getLocal("r"),4*l-4,e.getLocal(h))),a.addCode(e.if(e.i32_wrap_i64(e.getLocal(p)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))),e.if(e.call(r+"_gte",e.getLocal("r"),e.i32_const(d)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))))))}(),function(){const a=t.addFunction(s+"_squareOld");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_mul",e.getLocal("x"),e.getLocal("x"),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_toMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_mul",e.getLocal("x"),e.i32_const(u),e.getLocal("r")))}(),function(){const a=t.alloc(2*c),e=t.addFunction(s+"_fromMontgomery");e.addParam("x","i32"),e.addParam("r","i32");const o=e.getCodeBuilder();e.addCode(o.call(r+"_copy",o.getLocal("x"),o.i32_const(a))),e.addCode(o.call(r+"_zero",o.i32_const(a+c))),e.addCode(o.call(s+"_mReduct",o.i32_const(a),o.getLocal("r")))}(),function(){const a=t.addFunction(s+"_isNegative");a.addParam("x","i32"),a.setReturnType("i32");const e=a.getCodeBuilder(),o=e.i32_const(t.alloc(c));a.addCode(e.call(s+"_fromMontgomery",e.getLocal("x"),o),e.call(r+"_gte",o,e.i32_const(L)))}(),function(){const a=t.addFunction(s+"_sign");a.addParam("x","i32"),a.setReturnType("i32");const e=a.getCodeBuilder(),o=e.i32_const(t.alloc(c));a.addCode(e.if(e.call(r+"_isZero",e.getLocal("x")),e.ret(e.i32_const(0))),e.call(s+"_fromMontgomery",e.getLocal("x"),o),e.if(e.call(r+"_gte",o,e.i32_const(L)),e.ret(e.i32_const(-1))),e.ret(e.i32_const(1)))}(),function(){const a=t.addFunction(s+"_inverse");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_fromMontgomery",e.getLocal("x"),e.getLocal("r"))),a.addCode(e.call(r+"_inverseMod",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))),a.addCode(e.call(s+"_toMontgomery",e.getLocal("r"),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_one");a.addParam("pr","i32");const e=a.getCodeBuilder();a.addCode(e.call(r+"_copy",e.i32_const(_),e.getLocal("pr")))}(),function(){const a=t.addFunction(s+"_load");a.addParam("scalar","i32"),a.addParam("scalarLen","i32"),a.addParam("r","i32"),a.addLocal("p","i32"),a.addLocal("l","i32"),a.addLocal("i","i32"),a.addLocal("j","i32");const e=a.getCodeBuilder(),o=e.i32_const(t.alloc(c)),i=t.alloc(c),n=e.i32_const(i);a.addCode(e.call(r+"_zero",e.getLocal("r")),e.setLocal("i",e.i32_const(c)),e.setLocal("p",e.getLocal("scalar")),e.block(e.loop(e.br_if(1,e.i32_gt_u(e.getLocal("i"),e.getLocal("scalarLen"))),e.if(e.i32_eq(e.getLocal("i"),e.i32_const(c)),e.call(s+"_one",o),e.call(s+"_mul",o,e.i32_const(u),o)),e.call(s+"_mul",e.getLocal("p"),o,n),e.call(s+"_add",e.getLocal("r"),n,e.getLocal("r")),e.setLocal("p",e.i32_add(e.getLocal("p"),e.i32_const(c))),e.setLocal("i",e.i32_add(e.getLocal("i"),e.i32_const(c))),e.br(0))),e.setLocal("l",e.i32_rem_u(e.getLocal("scalarLen"),e.i32_const(c))),e.if(e.i32_eqz(e.getLocal("l")),e.ret([])),e.call(r+"_zero",n),e.setLocal("j",e.i32_const(0)),e.block(e.loop(e.br_if(1,e.i32_eq(e.getLocal("j"),e.getLocal("l"))),e.i32_store8(e.getLocal("j"),i,e.i32_load8_u(e.getLocal("p"))),e.setLocal("p",e.i32_add(e.getLocal("p"),e.i32_const(1))),e.setLocal("j",e.i32_add(e.getLocal("j"),e.i32_const(1))),e.br(0))),e.if(e.i32_eq(e.getLocal("i"),e.i32_const(c)),e.call(s+"_one",o),e.call(s+"_mul",o,e.i32_const(u),o)),e.call(s+"_mul",n,o,n),e.call(s+"_add",e.getLocal("r"),n,e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_timesScalar");a.addParam("x","i32"),a.addParam("scalar","i32"),a.addParam("scalarLen","i32"),a.addParam("r","i32");const e=a.getCodeBuilder(),o=e.i32_const(t.alloc(c));a.addCode(e.call(s+"_load",e.getLocal("scalar"),e.getLocal("scalarLen"),o),e.call(s+"_toMontgomery",o,o),e.call(s+"_mul",e.getLocal("x"),o,e.getLocal("r")))}(),On(t,s),Gn(t,s+"_batchToMontgomery",s+"_toMontgomery",c,c),Gn(t,s+"_batchFromMontgomery",s+"_fromMontgomery",c,c),Gn(t,s+"_batchNeg",s+"_neg",c,c),zn(t,s+"_batchAdd",s+"_add",c,c),zn(t,s+"_batchSub",s+"_sub",c,c),zn(t,s+"_batchMul",s+"_mul",c,c),t.exportFunction(s+"_add"),t.exportFunction(s+"_sub"),t.exportFunction(s+"_neg"),t.exportFunction(s+"_isNegative"),t.exportFunction(s+"_isOne"),t.exportFunction(s+"_sign"),t.exportFunction(s+"_mReduct"),t.exportFunction(s+"_mul"),t.exportFunction(s+"_square"),t.exportFunction(s+"_squareOld"),t.exportFunction(s+"_fromMontgomery"),t.exportFunction(s+"_toMontgomery"),t.exportFunction(s+"_inverse"),t.exportFunction(s+"_one"),t.exportFunction(s+"_load"),t.exportFunction(s+"_timesScalar"),qn(t,s+"_exp",c,s+"_mul",s+"_square",r+"_copy",s+"_one"),t.exportFunction(s+"_exp"),t.exportFunction(s+"_batchInverse"),Qn(i)&&(!function(){const a=t.addFunction(s+"_sqrt");a.addParam("n","i32"),a.addParam("r","i32"),a.addLocal("m","i32"),a.addLocal("i","i32"),a.addLocal("j","i32");const e=a.getCodeBuilder(),o=e.i32_const(_),i=e.i32_const(t.alloc(c)),n=e.i32_const(t.alloc(c)),l=e.i32_const(t.alloc(c)),r=e.i32_const(t.alloc(c)),d=e.i32_const(t.alloc(c));a.addCode(e.if(e.call(s+"_isZero",e.getLocal("n")),e.ret(e.call(s+"_zero",e.getLocal("r")))),e.setLocal("m",e.i32_const(w)),e.call(s+"_copy",e.i32_const(F),i),e.call(s+"_exp",e.getLocal("n"),e.i32_const(A),e.i32_const(c),n),e.call(s+"_exp",e.getLocal("n"),e.i32_const(I),e.i32_const(c),l),e.block(e.loop(e.br_if(1,e.call(s+"_eq",n,o)),e.call(s+"_square",n,r),e.setLocal("i",e.i32_const(1)),e.block(e.loop(e.br_if(1,e.call(s+"_eq",r,o)),e.call(s+"_square",r,r),e.setLocal("i",e.i32_add(e.getLocal("i"),e.i32_const(1))),e.br(0))),e.call(s+"_copy",i,d),e.setLocal("j",e.i32_sub(e.i32_sub(e.getLocal("m"),e.getLocal("i")),e.i32_const(1))),e.block(e.loop(e.br_if(1,e.i32_eqz(e.getLocal("j"))),e.call(s+"_square",d,d),e.setLocal("j",e.i32_sub(e.getLocal("j"),e.i32_const(1))),e.br(0))),e.setLocal("m",e.getLocal("i")),e.call(s+"_square",d,i),e.call(s+"_mul",n,i,n),e.call(s+"_mul",l,d,l),e.br(0))),e.if(e.call(s+"_isNegative",l),e.call(s+"_neg",l,e.getLocal("r")),e.call(s+"_copy",l,e.getLocal("r"))))}(),function(){const a=t.addFunction(s+"_isSquare");a.addParam("n","i32"),a.setReturnType("i32");const e=a.getCodeBuilder(),o=e.i32_const(_),i=e.i32_const(t.alloc(c));a.addCode(e.if(e.call(s+"_isZero",e.getLocal("n")),e.ret(e.i32_const(1))),e.call(s+"_exp",e.getLocal("n"),e.i32_const(p),e.i32_const(c),i),e.call(s+"_eq",i,o))}(),t.exportFunction(s+"_sqrt"),t.exportFunction(s+"_isSquare")),t.exportFunction(s+"_batchToMontgomery"),t.exportFunction(s+"_batchFromMontgomery"),s};const $n=Nn,{bitLength:Dn}=pn;var jn=function(t,a,e,o,i){const n=BigInt(a),l=Math.floor((Dn(n-1n)-1)/64)+1,c=8*l,s=e||"f1";if(t.modules[s])return s;t.modules[s]={n64:l};const r=i||"int",d=$n(t,n,o,r),u=t.modules[d].pR2,_=t.modules[d].pq,g=t.modules[d].pePlusOne;return function(){const a=t.alloc(c),e=t.addFunction(s+"_mul");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32");const o=e.getCodeBuilder();e.addCode(o.call(d+"_mul",o.getLocal("x"),o.getLocal("y"),o.i32_const(a))),e.addCode(o.call(d+"_mul",o.i32_const(a),o.i32_const(u),o.getLocal("r")))}(),function(){const a=t.addFunction(s+"_square");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_mul",e.getLocal("x"),e.getLocal("x"),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_inverse");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(r+"_inverseMod",e.getLocal("x"),e.i32_const(_),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_isNegative");a.addParam("x","i32"),a.setReturnType("i32");const e=a.getCodeBuilder();a.addCode(e.call(r+"_gte",e.getLocal("x"),e.i32_const(g)))}(),t.exportFunction(d+"_add",s+"_add"),t.exportFunction(d+"_sub",s+"_sub"),t.exportFunction(d+"_neg",s+"_neg"),t.exportFunction(s+"_mul"),t.exportFunction(s+"_square"),t.exportFunction(s+"_inverse"),t.exportFunction(s+"_isNegative"),t.exportFunction(d+"_copy",s+"_copy"),t.exportFunction(d+"_zero",s+"_zero"),t.exportFunction(d+"_one",s+"_one"),t.exportFunction(d+"_isZero",s+"_isZero"),t.exportFunction(d+"_eq",s+"_eq"),s};const Vn=_n,Kn=gn,Hn=un;var Zn=function(t,a,e,o){if(t.modules[e])return e;const i=8*t.modules[o].n64,n=t.modules[o].q;return t.modules[e]={n64:2*t.modules[o].n64},function(){const a=t.addFunction(e+"_isZero");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.i32_and(n.call(o+"_isZero",l),n.call(o+"_isZero",c)))}(),function(){const a=t.addFunction(e+"_isOne");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.ret(n.i32_and(n.call(o+"_isOne",l),n.call(o+"_isZero",c))))}(),function(){const a=t.addFunction(e+"_zero");a.addParam("x","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.call(o+"_zero",l),n.call(o+"_zero",c))}(),function(){const a=t.addFunction(e+"_one");a.addParam("x","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.call(o+"_one",l),n.call(o+"_zero",c))}(),function(){const a=t.addFunction(e+"_copy");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_copy",l,s),n.call(o+"_copy",c,r))}(),function(){const n=t.addFunction(e+"_mul");n.addParam("x","i32"),n.addParam("y","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.getLocal("y"),d=l.i32_add(l.getLocal("y"),l.i32_const(i)),u=l.getLocal("r"),_=l.i32_add(l.getLocal("r"),l.i32_const(i)),g=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i)),h=l.i32_const(t.alloc(i)),p=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_mul",c,r,g),l.call(o+"_mul",s,d,f),l.call(o+"_add",c,s,h),l.call(o+"_add",r,d,p),l.call(o+"_mul",h,p,h),l.call(a,f,u),l.call(o+"_add",g,u,u),l.call(o+"_add",g,f,_),l.call(o+"_sub",h,_,_))}(),function(){const a=t.addFunction(e+"_mul1");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("y"),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_mul",l,s,r),n.call(o+"_mul",c,s,d))}(),function(){const n=t.addFunction(e+"_square");n.addParam("x","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.getLocal("r"),d=l.i32_add(l.getLocal("r"),l.i32_const(i)),u=l.i32_const(t.alloc(i)),_=l.i32_const(t.alloc(i)),g=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_mul",c,s,u),l.call(o+"_add",c,s,_),l.call(a,s,g),l.call(o+"_add",c,g,g),l.call(a,u,f),l.call(o+"_add",f,u,f),l.call(o+"_mul",_,g,r),l.call(o+"_sub",r,f,r),l.call(o+"_add",u,u,d))}(),function(){const a=t.addFunction(e+"_add");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("y"),r=n.i32_add(n.getLocal("y"),n.i32_const(i)),d=n.getLocal("r"),u=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_add",l,s,d),n.call(o+"_add",c,r,u))}(),function(){const a=t.addFunction(e+"_sub");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("y"),r=n.i32_add(n.getLocal("y"),n.i32_const(i)),d=n.getLocal("r"),u=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_sub",l,s,d),n.call(o+"_sub",c,r,u))}(),function(){const a=t.addFunction(e+"_neg");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_neg",l,s),n.call(o+"_neg",c,r))}(),function(){const a=t.addFunction(e+"_conjugate");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_copy",l,s),n.call(o+"_neg",c,r))}(),function(){const a=t.addFunction(e+"_toMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_toMontgomery",l,s),n.call(o+"_toMontgomery",c,r))}(),function(){const a=t.addFunction(e+"_fromMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_fromMontgomery",l,s),n.call(o+"_fromMontgomery",c,r))}(),function(){const a=t.addFunction(e+"_eq");a.addParam("x","i32"),a.addParam("y","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("y"),r=n.i32_add(n.getLocal("y"),n.i32_const(i));a.addCode(n.i32_and(n.call(o+"_eq",l,s),n.call(o+"_eq",c,r)))}(),function(){const n=t.addFunction(e+"_inverse");n.addParam("x","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.getLocal("r"),d=l.i32_add(l.getLocal("r"),l.i32_const(i)),u=l.i32_const(t.alloc(i)),_=l.i32_const(t.alloc(i)),g=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_square",c,u),l.call(o+"_square",s,_),l.call(a,_,g),l.call(o+"_sub",u,g,g),l.call(o+"_inverse",g,f),l.call(o+"_mul",c,f,r),l.call(o+"_mul",s,f,d),l.call(o+"_neg",d,d))}(),function(){const a=t.addFunction(e+"_timesScalar");a.addParam("x","i32"),a.addParam("scalar","i32"),a.addParam("scalarLen","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.getLocal("r"),r=n.i32_add(n.getLocal("r"),n.i32_const(i));a.addCode(n.call(o+"_timesScalar",l,n.getLocal("scalar"),n.getLocal("scalarLen"),s),n.call(o+"_timesScalar",c,n.getLocal("scalar"),n.getLocal("scalarLen"),r))}(),function(){const a=t.addFunction(e+"_sign");a.addParam("x","i32"),a.addLocal("s","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.setLocal("s",n.call(o+"_sign",c)),n.if(n.getLocal("s"),n.ret(n.getLocal("s"))),n.ret(n.call(o+"_sign",l)))}(),function(){const a=t.addFunction(e+"_isNegative");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i));a.addCode(n.if(n.call(o+"_isZero",c),n.ret(n.call(o+"_isNegative",l))),n.ret(n.call(o+"_isNegative",c)))}(),t.exportFunction(e+"_isZero"),t.exportFunction(e+"_isOne"),t.exportFunction(e+"_zero"),t.exportFunction(e+"_one"),t.exportFunction(e+"_copy"),t.exportFunction(e+"_mul"),t.exportFunction(e+"_mul1"),t.exportFunction(e+"_square"),t.exportFunction(e+"_add"),t.exportFunction(e+"_sub"),t.exportFunction(e+"_neg"),t.exportFunction(e+"_sign"),t.exportFunction(e+"_conjugate"),t.exportFunction(e+"_fromMontgomery"),t.exportFunction(e+"_toMontgomery"),t.exportFunction(e+"_eq"),t.exportFunction(e+"_inverse"),Kn(t,e),Vn(t,e+"_exp",2*i,e+"_mul",e+"_square",e+"_copy",e+"_one"),function(){const a=t.addFunction(e+"_sqrt");a.addParam("a","i32"),a.addParam("pr","i32");const l=a.getCodeBuilder(),c=l.i32_const(t.alloc(Hn.bigInt2BytesLE((BigInt(n||0)-3n)/4n,i))),s=l.i32_const(t.alloc(Hn.bigInt2BytesLE((BigInt(n||0)-1n)/2n,i))),r=l.getLocal("a"),d=l.i32_const(t.alloc(2*i)),u=l.i32_const(t.alloc(2*i)),_=l.i32_const(t.alloc(2*i)),g=t.alloc(2*i),f=l.i32_const(g),h=l.i32_const(g),p=l.i32_const(g+i),m=l.i32_const(t.alloc(2*i)),L=l.i32_const(t.alloc(2*i));a.addCode(l.call(e+"_one",f),l.call(e+"_neg",f,f),l.call(e+"_exp",r,c,l.i32_const(i),d),l.call(e+"_square",d,u),l.call(e+"_mul",r,u,u),l.call(e+"_conjugate",u,_),l.call(e+"_mul",_,u,_),l.if(l.call(e+"_eq",_,f),l.unreachable()),l.call(e+"_mul",d,r,m),l.if(l.call(e+"_eq",u,f),[...l.call(o+"_zero",h),...l.call(o+"_one",p),...l.call(e+"_mul",f,m,l.getLocal("pr"))],[...l.call(e+"_one",L),...l.call(e+"_add",L,u,L),...l.call(e+"_exp",L,s,l.i32_const(i),L),...l.call(e+"_mul",L,m,l.getLocal("pr"))]))}(),function(){const a=t.addFunction(e+"_isSquare");a.addParam("a","i32"),a.setReturnType("i32");const o=a.getCodeBuilder(),l=o.i32_const(t.alloc(Hn.bigInt2BytesLE((BigInt(n||0)-3n)/4n,i))),c=o.getLocal("a"),s=o.i32_const(t.alloc(2*i)),r=o.i32_const(t.alloc(2*i)),d=o.i32_const(t.alloc(2*i)),u=t.alloc(2*i),_=o.i32_const(u);a.addCode(o.call(e+"_one",_),o.call(e+"_neg",_,_),o.call(e+"_exp",c,l,o.i32_const(i),s),o.call(e+"_square",s,r),o.call(e+"_mul",c,r,r),o.call(e+"_conjugate",r,d),o.call(e+"_mul",d,r,d),o.if(o.call(e+"_eq",d,_),o.ret(o.i32_const(0))),o.ret(o.i32_const(1)))}(),t.exportFunction(e+"_exp"),t.exportFunction(e+"_timesScalar"),t.exportFunction(e+"_batchInverse"),t.exportFunction(e+"_sqrt"),t.exportFunction(e+"_isSquare"),t.exportFunction(e+"_isNegative"),e};const Wn=_n,Yn=gn;var Jn=function(t,a,e,o){if(t.modules[e])return e;const i=8*t.modules[o].n64;return t.modules[e]={n64:3*t.modules[o].n64},function(){const a=t.addFunction(e+"_isZero");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.i32_and(n.i32_and(n.call(o+"_isZero",l),n.call(o+"_isZero",c)),n.call(o+"_isZero",s)))}(),function(){const a=t.addFunction(e+"_isOne");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.ret(n.i32_and(n.i32_and(n.call(o+"_isOne",l),n.call(o+"_isZero",c)),n.call(o+"_isZero",s))))}(),function(){const a=t.addFunction(e+"_zero");a.addParam("x","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.call(o+"_zero",l),n.call(o+"_zero",c),n.call(o+"_zero",s))}(),function(){const a=t.addFunction(e+"_one");a.addParam("x","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.call(o+"_one",l),n.call(o+"_zero",c),n.call(o+"_zero",s))}(),function(){const a=t.addFunction(e+"_copy");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_copy",l,r),n.call(o+"_copy",c,d),n.call(o+"_copy",s,u))}(),function(){const n=t.addFunction(e+"_mul");n.addParam("x","i32"),n.addParam("y","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.i32_add(l.getLocal("x"),l.i32_const(2*i)),d=l.getLocal("y"),u=l.i32_add(l.getLocal("y"),l.i32_const(i)),_=l.i32_add(l.getLocal("y"),l.i32_const(2*i)),g=l.getLocal("r"),f=l.i32_add(l.getLocal("r"),l.i32_const(i)),h=l.i32_add(l.getLocal("r"),l.i32_const(2*i)),p=l.i32_const(t.alloc(i)),m=l.i32_const(t.alloc(i)),L=l.i32_const(t.alloc(i)),b=l.i32_const(t.alloc(i)),w=l.i32_const(t.alloc(i)),y=l.i32_const(t.alloc(i)),A=l.i32_const(t.alloc(i)),C=l.i32_const(t.alloc(i)),F=l.i32_const(t.alloc(i)),x=l.i32_const(t.alloc(i)),I=l.i32_const(t.alloc(i)),B=l.i32_const(t.alloc(i)),E=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_mul",c,d,p),l.call(o+"_mul",s,u,m),l.call(o+"_mul",r,_,L),l.call(o+"_add",c,s,b),l.call(o+"_add",d,u,w),l.call(o+"_add",c,r,y),l.call(o+"_add",d,_,A),l.call(o+"_add",s,r,C),l.call(o+"_add",u,_,F),l.call(o+"_add",p,m,x),l.call(o+"_add",p,L,I),l.call(o+"_add",m,L,B),l.call(o+"_mul",C,F,g),l.call(o+"_sub",g,B,g),l.call(a,g,g),l.call(o+"_add",p,g,g),l.call(o+"_mul",b,w,f),l.call(o+"_sub",f,x,f),l.call(a,L,E),l.call(o+"_add",f,E,f),l.call(o+"_mul",y,A,h),l.call(o+"_sub",h,I,h),l.call(o+"_add",h,m,h))}(),function(){const n=t.addFunction(e+"_square");n.addParam("x","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.i32_add(l.getLocal("x"),l.i32_const(2*i)),d=l.getLocal("r"),u=l.i32_add(l.getLocal("r"),l.i32_const(i)),_=l.i32_add(l.getLocal("r"),l.i32_const(2*i)),g=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i)),h=l.i32_const(t.alloc(i)),p=l.i32_const(t.alloc(i)),m=l.i32_const(t.alloc(i)),L=l.i32_const(t.alloc(i)),b=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_square",c,g),l.call(o+"_mul",c,s,f),l.call(o+"_add",f,f,h),l.call(o+"_sub",c,s,p),l.call(o+"_add",p,r,p),l.call(o+"_square",p,p),l.call(o+"_mul",s,r,m),l.call(o+"_add",m,m,L),l.call(o+"_square",r,b),l.call(a,L,d),l.call(o+"_add",g,d,d),l.call(a,b,u),l.call(o+"_add",h,u,u),l.call(o+"_add",g,b,_),l.call(o+"_sub",L,_,_),l.call(o+"_add",p,_,_),l.call(o+"_add",h,_,_))}(),function(){const a=t.addFunction(e+"_add");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("y"),d=n.i32_add(n.getLocal("y"),n.i32_const(i)),u=n.i32_add(n.getLocal("y"),n.i32_const(2*i)),_=n.getLocal("r"),g=n.i32_add(n.getLocal("r"),n.i32_const(i)),f=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_add",l,r,_),n.call(o+"_add",c,d,g),n.call(o+"_add",s,u,f))}(),function(){const a=t.addFunction(e+"_sub");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("y"),d=n.i32_add(n.getLocal("y"),n.i32_const(i)),u=n.i32_add(n.getLocal("y"),n.i32_const(2*i)),_=n.getLocal("r"),g=n.i32_add(n.getLocal("r"),n.i32_const(i)),f=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_sub",l,r,_),n.call(o+"_sub",c,d,g),n.call(o+"_sub",s,u,f))}(),function(){const a=t.addFunction(e+"_neg");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_neg",l,r),n.call(o+"_neg",c,d),n.call(o+"_neg",s,u))}(),function(){const a=t.addFunction(e+"_sign");a.addParam("x","i32"),a.addLocal("s","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.setLocal("s",n.call(o+"_sign",s)),n.if(n.getLocal("s"),n.ret(n.getLocal("s"))),n.setLocal("s",n.call(o+"_sign",c)),n.if(n.getLocal("s"),n.ret(n.getLocal("s"))),n.ret(n.call(o+"_sign",l)))}(),function(){const a=t.addFunction(e+"_toMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_toMontgomery",l,r),n.call(o+"_toMontgomery",c,d),n.call(o+"_toMontgomery",s,u))}(),function(){const a=t.addFunction(e+"_fromMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_fromMontgomery",l,r),n.call(o+"_fromMontgomery",c,d),n.call(o+"_fromMontgomery",s,u))}(),function(){const a=t.addFunction(e+"_eq");a.addParam("x","i32"),a.addParam("y","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("y"),d=n.i32_add(n.getLocal("y"),n.i32_const(i)),u=n.i32_add(n.getLocal("y"),n.i32_const(2*i));a.addCode(n.i32_and(n.i32_and(n.call(o+"_eq",l,r),n.call(o+"_eq",c,d)),n.call(o+"_eq",s,u)))}(),function(){const n=t.addFunction(e+"_inverse");n.addParam("x","i32"),n.addParam("r","i32");const l=n.getCodeBuilder(),c=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.i32_add(l.getLocal("x"),l.i32_const(2*i)),d=l.getLocal("r"),u=l.i32_add(l.getLocal("r"),l.i32_const(i)),_=l.i32_add(l.getLocal("r"),l.i32_const(2*i)),g=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i)),h=l.i32_const(t.alloc(i)),p=l.i32_const(t.alloc(i)),m=l.i32_const(t.alloc(i)),L=l.i32_const(t.alloc(i)),b=l.i32_const(t.alloc(i)),w=l.i32_const(t.alloc(i)),y=l.i32_const(t.alloc(i)),A=l.i32_const(t.alloc(i)),C=l.i32_const(t.alloc(i));n.addCode(l.call(o+"_square",c,g),l.call(o+"_square",s,f),l.call(o+"_square",r,h),l.call(o+"_mul",c,s,p),l.call(o+"_mul",c,r,m),l.call(o+"_mul",s,r,L),l.call(a,L,b),l.call(o+"_sub",g,b,b),l.call(a,h,w),l.call(o+"_sub",w,p,w),l.call(o+"_sub",f,m,y),l.call(o+"_mul",r,w,A),l.call(o+"_mul",s,y,C),l.call(o+"_add",A,C,A),l.call(a,A,A),l.call(o+"_mul",c,b,C),l.call(o+"_add",C,A,A),l.call(o+"_inverse",A,A),l.call(o+"_mul",A,b,d),l.call(o+"_mul",A,w,u),l.call(o+"_mul",A,y,_))}(),function(){const a=t.addFunction(e+"_timesScalar");a.addParam("x","i32"),a.addParam("scalar","i32"),a.addParam("scalarLen","i32"),a.addParam("r","i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i)),r=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(i)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*i));a.addCode(n.call(o+"_timesScalar",l,n.getLocal("scalar"),n.getLocal("scalarLen"),r),n.call(o+"_timesScalar",c,n.getLocal("scalar"),n.getLocal("scalarLen"),d),n.call(o+"_timesScalar",s,n.getLocal("scalar"),n.getLocal("scalarLen"),u))}(),function(){const a=t.addFunction(e+"_isNegative");a.addParam("x","i32"),a.setReturnType("i32");const n=a.getCodeBuilder(),l=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(i)),s=n.i32_add(n.getLocal("x"),n.i32_const(2*i));a.addCode(n.if(n.call(o+"_isZero",s),n.if(n.call(o+"_isZero",c),n.ret(n.call(o+"_isNegative",l)),n.ret(n.call(o+"_isNegative",c)))),n.ret(n.call(o+"_isNegative",s)))}(),t.exportFunction(e+"_isZero"),t.exportFunction(e+"_isOne"),t.exportFunction(e+"_zero"),t.exportFunction(e+"_one"),t.exportFunction(e+"_copy"),t.exportFunction(e+"_mul"),t.exportFunction(e+"_square"),t.exportFunction(e+"_add"),t.exportFunction(e+"_sub"),t.exportFunction(e+"_neg"),t.exportFunction(e+"_sign"),t.exportFunction(e+"_fromMontgomery"),t.exportFunction(e+"_toMontgomery"),t.exportFunction(e+"_eq"),t.exportFunction(e+"_inverse"),Yn(t,e),Wn(t,e+"_exp",3*i,e+"_mul",e+"_square",e+"_copy",e+"_one"),t.exportFunction(e+"_exp"),t.exportFunction(e+"_timesScalar"),t.exportFunction(e+"_batchInverse"),t.exportFunction(e+"_isNegative"),e};const Xn=function(t,a,e,o,i,n,l,c){const s=t.addFunction(a);s.addParam("base","i32"),s.addParam("scalar","i32"),s.addParam("scalarLength","i32"),s.addParam("r","i32"),s.addLocal("old0","i32"),s.addLocal("nbits","i32"),s.addLocal("i","i32"),s.addLocal("last","i32"),s.addLocal("cur","i32"),s.addLocal("carry","i32"),s.addLocal("p","i32");const r=s.getCodeBuilder(),d=r.i32_const(t.alloc(e));function u(t){return r.i32_and(r.i32_shr_u(r.i32_load(r.i32_add(r.getLocal("scalar"),r.i32_and(r.i32_shr_u(t,r.i32_const(3)),r.i32_const(4294967292)))),r.i32_and(t,r.i32_const(31))),r.i32_const(1))}function _(t){return[...r.i32_store8(r.getLocal("p"),r.i32_const(t)),...r.setLocal("p",r.i32_add(r.getLocal("p"),r.i32_const(1)))]}s.addCode(r.if(r.i32_eqz(r.getLocal("scalarLength")),[...r.call(c,r.getLocal("r")),...r.ret([])]),r.setLocal("nbits",r.i32_shl(r.getLocal("scalarLength"),r.i32_const(3))),r.setLocal("old0",r.i32_load(r.i32_const(0))),r.setLocal("p",r.getLocal("old0")),r.i32_store(r.i32_const(0),r.i32_and(r.i32_add(r.i32_add(r.getLocal("old0"),r.i32_const(32)),r.getLocal("nbits")),r.i32_const(4294967288))),r.setLocal("i",r.i32_const(1)),r.setLocal("last",u(r.i32_const(0))),r.setLocal("carry",r.i32_const(0)),r.block(r.loop(r.br_if(1,r.i32_eq(r.getLocal("i"),r.getLocal("nbits"))),r.setLocal("cur",u(r.getLocal("i"))),r.if(r.getLocal("last"),r.if(r.getLocal("cur"),r.if(r.getLocal("carry"),[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(1)),..._(1)],[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(1)),..._(255)]),r.if(r.getLocal("carry"),[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(1)),..._(255)],[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(0)),..._(1)])),r.if(r.getLocal("cur"),r.if(r.getLocal("carry"),[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(1)),..._(0)],[...r.setLocal("last",r.i32_const(1)),...r.setLocal("carry",r.i32_const(0)),..._(0)]),r.if(r.getLocal("carry"),[...r.setLocal("last",r.i32_const(1)),...r.setLocal("carry",r.i32_const(0)),..._(0)],[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(0)),..._(0)]))),r.setLocal("i",r.i32_add(r.getLocal("i"),r.i32_const(1))),r.br(0))),r.if(r.getLocal("last"),r.if(r.getLocal("carry"),[..._(255),..._(0),..._(1)],[..._(1)]),r.if(r.getLocal("carry"),[..._(0),..._(1)])),r.setLocal("p",r.i32_sub(r.getLocal("p"),r.i32_const(1))),r.call(l,r.getLocal("base"),d),r.call(c,r.getLocal("r")),r.block(r.loop(r.call(i,r.getLocal("r"),r.getLocal("r")),r.setLocal("cur",r.i32_load8_u(r.getLocal("p"))),r.if(r.getLocal("cur"),r.if(r.i32_eq(r.getLocal("cur"),r.i32_const(1)),r.call(o,r.getLocal("r"),d,r.getLocal("r")),r.call(n,r.getLocal("r"),d,r.getLocal("r")))),r.br_if(1,r.i32_eq(r.getLocal("old0"),r.getLocal("p"))),r.setLocal("p",r.i32_sub(r.getLocal("p"),r.i32_const(1))),r.br(0))),r.i32_store(r.i32_const(0),r.getLocal("old0")))},tl=fn,al=function(t,a,e,o,i){const n=8*t.modules[a].n64;function l(){const o=t.addFunction(e);o.addParam("pBases","i32"),o.addParam("pScalars","i32"),o.addParam("scalarSize","i32"),o.addParam("n","i32"),o.addParam("pr","i32"),o.addLocal("chunkSize","i32"),o.addLocal("nChunks","i32"),o.addLocal("itScalar","i32"),o.addLocal("endScalar","i32"),o.addLocal("itBase","i32"),o.addLocal("itBit","i32"),o.addLocal("i","i32"),o.addLocal("j","i32"),o.addLocal("nTable","i32"),o.addLocal("pTable","i32"),o.addLocal("idx","i32"),o.addLocal("pIdxTable","i32");const i=o.getCodeBuilder(),l=i.i32_const(t.alloc(n)),c=t.alloc([17,17,17,17,17,17,17,17,17,17,16,16,15,14,13,13,12,11,10,9,8,7,7,6,5,4,3,2,1,1,1,1]);o.addCode(i.call(a+"_zero",i.getLocal("pr")),i.if(i.i32_eqz(i.getLocal("n")),i.ret([])),i.setLocal("chunkSize",i.i32_load8_u(i.i32_clz(i.getLocal("n")),c)),i.setLocal("nChunks",i.i32_add(i.i32_div_u(i.i32_sub(i.i32_shl(i.getLocal("scalarSize"),i.i32_const(3)),i.i32_const(1)),i.getLocal("chunkSize")),i.i32_const(1))),i.setLocal("itBit",i.i32_mul(i.i32_sub(i.getLocal("nChunks"),i.i32_const(1)),i.getLocal("chunkSize"))),i.block(i.loop(i.br_if(1,i.i32_lt_s(i.getLocal("itBit"),i.i32_const(0))),i.if(i.i32_eqz(i.call(a+"_isZero",i.getLocal("pr"))),[...i.setLocal("j",i.i32_const(0)),...i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("j"),i.getLocal("chunkSize"))),i.call(a+"_double",i.getLocal("pr"),i.getLocal("pr")),i.setLocal("j",i.i32_add(i.getLocal("j"),i.i32_const(1))),i.br(0)))]),i.call(e+"_chunk",i.getLocal("pBases"),i.getLocal("pScalars"),i.getLocal("scalarSize"),i.getLocal("n"),i.getLocal("itBit"),i.getLocal("chunkSize"),l),i.call(a+"_add",i.getLocal("pr"),l,i.getLocal("pr")),i.setLocal("itBit",i.i32_sub(i.getLocal("itBit"),i.getLocal("chunkSize"))),i.br(0))))}!function(){const a=t.addFunction(e+"_getChunk");a.addParam("pScalar","i32"),a.addParam("scalarSize","i32"),a.addParam("startBit","i32"),a.addParam("chunkSize","i32"),a.addLocal("bitsToEnd","i32"),a.addLocal("mask","i32"),a.setReturnType("i32");const o=a.getCodeBuilder();a.addCode(o.setLocal("bitsToEnd",o.i32_sub(o.i32_mul(o.getLocal("scalarSize"),o.i32_const(8)),o.getLocal("startBit"))),o.if(o.i32_gt_s(o.getLocal("chunkSize"),o.getLocal("bitsToEnd")),o.setLocal("mask",o.i32_sub(o.i32_shl(o.i32_const(1),o.getLocal("bitsToEnd")),o.i32_const(1))),o.setLocal("mask",o.i32_sub(o.i32_shl(o.i32_const(1),o.getLocal("chunkSize")),o.i32_const(1)))),o.i32_and(o.i32_shr_u(o.i32_load(o.i32_add(o.getLocal("pScalar"),o.i32_shr_u(o.getLocal("startBit"),o.i32_const(3))),0,0),o.i32_and(o.getLocal("startBit"),o.i32_const(7))),o.getLocal("mask")))}(),function(){const o=t.addFunction(e+"_reduceTable");o.addParam("pTable","i32"),o.addParam("p","i32"),o.addLocal("half","i32"),o.addLocal("it1","i32"),o.addLocal("it2","i32"),o.addLocal("pAcc","i32");const i=o.getCodeBuilder();o.addCode(i.if(i.i32_eq(i.getLocal("p"),i.i32_const(1)),i.ret([])),i.setLocal("half",i.i32_shl(i.i32_const(1),i.i32_sub(i.getLocal("p"),i.i32_const(1)))),i.setLocal("it1",i.getLocal("pTable")),i.setLocal("it2",i.i32_add(i.getLocal("pTable"),i.i32_mul(i.getLocal("half"),i.i32_const(n)))),i.setLocal("pAcc",i.i32_sub(i.getLocal("it2"),i.i32_const(n))),i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("it1"),i.getLocal("pAcc"))),i.call(a+"_add",i.getLocal("it1"),i.getLocal("it2"),i.getLocal("it1")),i.call(a+"_add",i.getLocal("pAcc"),i.getLocal("it2"),i.getLocal("pAcc")),i.setLocal("it1",i.i32_add(i.getLocal("it1"),i.i32_const(n))),i.setLocal("it2",i.i32_add(i.getLocal("it2"),i.i32_const(n))),i.br(0))),i.call(e+"_reduceTable",i.getLocal("pTable"),i.i32_sub(i.getLocal("p"),i.i32_const(1))),i.setLocal("p",i.i32_sub(i.getLocal("p"),i.i32_const(1))),i.block(i.loop(i.br_if(1,i.i32_eqz(i.getLocal("p"))),i.call(a+"_double",i.getLocal("pAcc"),i.getLocal("pAcc")),i.setLocal("p",i.i32_sub(i.getLocal("p"),i.i32_const(1))),i.br(0))),i.call(a+"_add",i.getLocal("pTable"),i.getLocal("pAcc"),i.getLocal("pTable")))}(),function(){const l=t.addFunction(e+"_chunk");l.addParam("pBases","i32"),l.addParam("pScalars","i32"),l.addParam("scalarSize","i32"),l.addParam("n","i32"),l.addParam("startBit","i32"),l.addParam("chunkSize","i32"),l.addParam("pr","i32"),l.addLocal("nChunks","i32"),l.addLocal("itScalar","i32"),l.addLocal("endScalar","i32"),l.addLocal("itBase","i32"),l.addLocal("i","i32"),l.addLocal("j","i32"),l.addLocal("nTable","i32"),l.addLocal("pTable","i32"),l.addLocal("idx","i32"),l.addLocal("pIdxTable","i32");const c=l.getCodeBuilder();l.addCode(c.if(c.i32_eqz(c.getLocal("n")),[...c.call(a+"_zero",c.getLocal("pr")),...c.ret([])]),c.setLocal("nTable",c.i32_shl(c.i32_const(1),c.getLocal("chunkSize"))),c.setLocal("pTable",c.i32_load(c.i32_const(0))),c.i32_store(c.i32_const(0),c.i32_add(c.getLocal("pTable"),c.i32_mul(c.getLocal("nTable"),c.i32_const(n)))),c.setLocal("j",c.i32_const(0)),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("j"),c.getLocal("nTable"))),c.call(a+"_zero",c.i32_add(c.getLocal("pTable"),c.i32_mul(c.getLocal("j"),c.i32_const(n)))),c.setLocal("j",c.i32_add(c.getLocal("j"),c.i32_const(1))),c.br(0))),c.setLocal("itBase",c.getLocal("pBases")),c.setLocal("itScalar",c.getLocal("pScalars")),c.setLocal("endScalar",c.i32_add(c.getLocal("pScalars"),c.i32_mul(c.getLocal("n"),c.getLocal("scalarSize")))),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("itScalar"),c.getLocal("endScalar"))),c.setLocal("idx",c.call(e+"_getChunk",c.getLocal("itScalar"),c.getLocal("scalarSize"),c.getLocal("startBit"),c.getLocal("chunkSize"))),c.if(c.getLocal("idx"),[...c.setLocal("pIdxTable",c.i32_add(c.getLocal("pTable"),c.i32_mul(c.i32_sub(c.getLocal("idx"),c.i32_const(1)),c.i32_const(n)))),...c.call(o,c.getLocal("pIdxTable"),c.getLocal("itBase"),c.getLocal("pIdxTable"))]),c.setLocal("itScalar",c.i32_add(c.getLocal("itScalar"),c.getLocal("scalarSize"))),c.setLocal("itBase",c.i32_add(c.getLocal("itBase"),c.i32_const(i))),c.br(0))),c.call(e+"_reduceTable",c.getLocal("pTable"),c.getLocal("chunkSize")),c.call(a+"_copy",c.getLocal("pTable"),c.getLocal("pr")),c.i32_store(c.i32_const(0),c.getLocal("pTable")))}(),l(),t.exportFunction(e),t.exportFunction(e+"_chunk")};var el=function(t,a,e,o){const i=t.modules[e].n64,n=8*i;if(t.modules[a])return a;return t.modules[a]={n64:3*i},function(){const o=t.addFunction(a+"_isZeroAffine");o.addParam("p1","i32"),o.setReturnType("i32");const i=o.getCodeBuilder();o.addCode(i.i32_and(i.call(e+"_isZero",i.getLocal("p1")),i.call(e+"_isZero",i.i32_add(i.getLocal("p1"),i.i32_const(n)))))}(),function(){const o=t.addFunction(a+"_isZero");o.addParam("p1","i32"),o.setReturnType("i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_isZero",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))))}(),function(){const o=t.addFunction(a+"_zeroAffine");o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_zero",i.getLocal("pr"))),o.addCode(i.call(e+"_zero",i.i32_add(i.getLocal("pr"),i.i32_const(n))))}(),function(){const o=t.addFunction(a+"_zero");o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_zero",i.getLocal("pr"))),o.addCode(i.call(e+"_one",i.i32_add(i.getLocal("pr"),i.i32_const(n)))),o.addCode(i.call(e+"_zero",i.i32_add(i.getLocal("pr"),i.i32_const(2*n))))}(),function(){const e=t.addFunction(a+"_copyAffine");e.addParam("ps","i32"),e.addParam("pd","i32");const o=e.getCodeBuilder();for(let t=0;t<2*i;t++)e.addCode(o.i64_store(o.getLocal("pd"),8*t,o.i64_load(o.getLocal("ps"),8*t)))}(),function(){const e=t.addFunction(a+"_copy");e.addParam("ps","i32"),e.addParam("pd","i32");const o=e.getCodeBuilder();for(let t=0;t<3*i;t++)e.addCode(o.i64_store(o.getLocal("pd"),8*t,o.i64_load(o.getLocal("ps"),8*t)))}(),function(){const o=t.addFunction(a+"_toJacobian");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.getLocal("pr"),r=i.i32_add(i.getLocal("pr"),i.i32_const(n)),d=i.i32_add(i.getLocal("pr"),i.i32_const(2*n));o.addCode(i.if(i.call(a+"_isZeroAffine",i.getLocal("p1")),i.call(a+"_zero",i.getLocal("pr")),[...i.call(e+"_one",d),...i.call(e+"_copy",c,r),...i.call(e+"_copy",l,s)]))}(),function(){const o=t.addFunction(a+"_eqAffine");o.addParam("p1","i32"),o.addParam("p2","i32"),o.setReturnType("i32"),o.addLocal("z1","i32");const i=o.getCodeBuilder();o.addCode(i.ret(i.i32_and(i.call(e+"_eq",i.getLocal("p1"),i.getLocal("p2")),i.call(e+"_eq",i.i32_add(i.getLocal("p1"),i.i32_const(n)),i.i32_add(i.getLocal("p2"),i.i32_const(n))))))}(),function(){const o=t.addFunction(a+"_eqMixed");o.addParam("p1","i32"),o.addParam("p2","i32"),o.setReturnType("i32"),o.addLocal("z1","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n));o.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))));const s=i.getLocal("z1"),r=i.getLocal("p2"),d=i.i32_add(i.getLocal("p2"),i.i32_const(n)),u=i.i32_const(t.alloc(n)),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),i.ret(i.call(a+"_isZeroAffine",i.getLocal("p2")))),i.if(i.call(a+"_isZeroAffine",i.getLocal("p2")),i.ret(i.i32_const(0))),i.if(i.call(e+"_isOne",s),i.ret(i.call(a+"_eqAffine",i.getLocal("p1"),i.getLocal("p2")))),i.call(e+"_square",s,u),i.call(e+"_mul",r,u,_),i.call(e+"_mul",s,u,g),i.call(e+"_mul",d,g,f),i.if(i.call(e+"_eq",l,_),i.if(i.call(e+"_eq",c,f),i.ret(i.i32_const(1)))),i.ret(i.i32_const(0)))}(),function(){const o=t.addFunction(a+"_eq");o.addParam("p1","i32"),o.addParam("p2","i32"),o.setReturnType("i32"),o.addLocal("z1","i32"),o.addLocal("z2","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n));o.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))));const s=i.getLocal("z1"),r=i.getLocal("p2"),d=i.i32_add(i.getLocal("p2"),i.i32_const(n));o.addCode(i.setLocal("z2",i.i32_add(i.getLocal("p2"),i.i32_const(2*n))));const u=i.getLocal("z2"),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n)),m=i.i32_const(t.alloc(n)),L=i.i32_const(t.alloc(n)),b=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),i.ret(i.call(a+"_isZero",i.getLocal("p2")))),i.if(i.call(a+"_isZero",i.getLocal("p2")),i.ret(i.i32_const(0))),i.if(i.call(e+"_isOne",s),i.ret(i.call(a+"_eqMixed",i.getLocal("p2"),i.getLocal("p1")))),i.if(i.call(e+"_isOne",u),i.ret(i.call(a+"_eqMixed",i.getLocal("p1"),i.getLocal("p2")))),i.call(e+"_square",s,_),i.call(e+"_square",u,g),i.call(e+"_mul",l,g,f),i.call(e+"_mul",r,_,h),i.call(e+"_mul",s,_,p),i.call(e+"_mul",u,g,m),i.call(e+"_mul",c,m,L),i.call(e+"_mul",d,p,b),i.if(i.call(e+"_eq",f,h),i.if(i.call(e+"_eq",L,b),i.ret(i.i32_const(1)))),i.ret(i.i32_const(0)))}(),function(){const o=t.addFunction(a+"_doubleAffine");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.getLocal("pr"),r=i.i32_add(i.getLocal("pr"),i.i32_const(n)),d=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),u=i.i32_const(t.alloc(n)),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZeroAffine",i.getLocal("p1")),[...i.call(a+"_toJacobian",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])]),i.call(e+"_square",l,u),i.call(e+"_square",c,_),i.call(e+"_square",_,g),i.call(e+"_add",l,_,f),i.call(e+"_square",f,f),i.call(e+"_sub",f,u,f),i.call(e+"_sub",f,g,f),i.call(e+"_add",f,f,f),i.call(e+"_add",u,u,h),i.call(e+"_add",h,u,h),i.call(e+"_add",c,c,d),i.call(e+"_square",h,s),i.call(e+"_sub",s,f,s),i.call(e+"_sub",s,f,s),i.call(e+"_add",g,g,p),i.call(e+"_add",p,p,p),i.call(e+"_add",p,p,p),i.call(e+"_sub",f,s,r),i.call(e+"_mul",r,h,r),i.call(e+"_sub",r,p,r))}(),function(){const o=t.addFunction(a+"_double");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.i32_add(i.getLocal("p1"),i.i32_const(2*n)),r=i.getLocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(n)),u=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n)),m=i.i32_const(t.alloc(n)),L=i.i32_const(t.alloc(n)),b=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),[...i.call(a+"_copy",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])]),i.if(i.call(e+"_isOne",s),[...i.ret(i.call(a+"_doubleAffine",i.getLocal("p1"),i.getLocal("pr"))),...i.ret([])]),i.call(e+"_square",l,_),i.call(e+"_square",c,g),i.call(e+"_square",g,f),i.call(e+"_add",l,g,h),i.call(e+"_square",h,h),i.call(e+"_sub",h,_,h),i.call(e+"_sub",h,f,h),i.call(e+"_add",h,h,h),i.call(e+"_add",_,_,p),i.call(e+"_add",p,_,p),i.call(e+"_square",p,m),i.call(e+"_mul",c,s,L),i.call(e+"_add",h,h,r),i.call(e+"_sub",m,r,r),i.call(e+"_add",f,f,b),i.call(e+"_add",b,b,b),i.call(e+"_add",b,b,b),i.call(e+"_sub",h,r,d),i.call(e+"_mul",d,p,d),i.call(e+"_sub",d,b,d),i.call(e+"_add",L,L,u))}(),function(){const o=t.addFunction(a+"_addAffine");o.addParam("p1","i32"),o.addParam("p2","i32"),o.addParam("pr","i32"),o.addLocal("z1","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n));o.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))));const s=i.getLocal("p2"),r=i.i32_add(i.getLocal("p2"),i.i32_const(n)),d=i.getLocal("pr"),u=i.i32_add(i.getLocal("pr"),i.i32_const(n)),_=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n)),m=i.i32_const(t.alloc(n)),L=i.i32_const(t.alloc(n)),b=i.i32_const(t.alloc(n)),w=i.i32_const(t.alloc(n)),y=i.i32_const(t.alloc(n)),A=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZeroAffine",i.getLocal("p1")),[...i.call(a+"_copyAffine",i.getLocal("p2"),i.getLocal("pr")),...i.call(e+"_one",i.i32_add(i.getLocal("pr"),i.i32_const(2*n))),...i.ret([])]),i.if(i.call(a+"_isZeroAffine",i.getLocal("p2")),[...i.call(a+"_copyAffine",i.getLocal("p1"),i.getLocal("pr")),...i.call(e+"_one",i.i32_add(i.getLocal("pr"),i.i32_const(2*n))),...i.ret([])]),i.if(i.call(e+"_eq",l,s),i.if(i.call(e+"_eq",c,r),[...i.call(a+"_doubleAffine",i.getLocal("p2"),i.getLocal("pr")),...i.ret([])])),i.call(e+"_sub",s,l,g),i.call(e+"_sub",r,c,h),i.call(e+"_square",g,f),i.call(e+"_add",f,f,p),i.call(e+"_add",p,p,p),i.call(e+"_mul",g,p,m),i.call(e+"_add",h,h,L),i.call(e+"_mul",l,p,w),i.call(e+"_square",L,b),i.call(e+"_add",w,w,y),i.call(e+"_sub",b,m,d),i.call(e+"_sub",d,y,d),i.call(e+"_mul",c,m,A),i.call(e+"_add",A,A,A),i.call(e+"_sub",w,d,u),i.call(e+"_mul",u,L,u),i.call(e+"_sub",u,A,u),i.call(e+"_add",g,g,_))}(),function(){const o=t.addFunction(a+"_addMixed");o.addParam("p1","i32"),o.addParam("p2","i32"),o.addParam("pr","i32"),o.addLocal("z1","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n));o.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))));const s=i.getLocal("z1"),r=i.getLocal("p2"),d=i.i32_add(i.getLocal("p2"),i.i32_const(n)),u=i.getLocal("pr"),_=i.i32_add(i.getLocal("pr"),i.i32_const(n)),g=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),f=i.i32_const(t.alloc(n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n)),m=i.i32_const(t.alloc(n)),L=i.i32_const(t.alloc(n)),b=i.i32_const(t.alloc(n)),w=i.i32_const(t.alloc(n)),y=i.i32_const(t.alloc(n)),A=i.i32_const(t.alloc(n)),C=i.i32_const(t.alloc(n)),F=i.i32_const(t.alloc(n)),x=i.i32_const(t.alloc(n)),I=i.i32_const(t.alloc(n)),B=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),[...i.call(a+"_copyAffine",i.getLocal("p2"),i.getLocal("pr")),...i.call(e+"_one",i.i32_add(i.getLocal("pr"),i.i32_const(2*n))),...i.ret([])]),i.if(i.call(a+"_isZeroAffine",i.getLocal("p2")),[...i.call(a+"_copy",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])]),i.if(i.call(e+"_isOne",s),[...i.call(a+"_addAffine",l,r,u),...i.ret([])]),i.call(e+"_square",s,f),i.call(e+"_mul",r,f,h),i.call(e+"_mul",s,f,p),i.call(e+"_mul",d,p,m),i.if(i.call(e+"_eq",l,h),i.if(i.call(e+"_eq",c,m),[...i.call(a+"_doubleAffine",i.getLocal("p2"),i.getLocal("pr")),...i.ret([])])),i.call(e+"_sub",h,l,L),i.call(e+"_sub",m,c,w),i.call(e+"_square",L,b),i.call(e+"_add",b,b,y),i.call(e+"_add",y,y,y),i.call(e+"_mul",L,y,A),i.call(e+"_add",w,w,C),i.call(e+"_mul",l,y,x),i.call(e+"_square",C,F),i.call(e+"_add",x,x,I),i.call(e+"_sub",F,A,u),i.call(e+"_sub",u,I,u),i.call(e+"_mul",c,A,B),i.call(e+"_add",B,B,B),i.call(e+"_sub",x,u,_),i.call(e+"_mul",_,C,_),i.call(e+"_sub",_,B,_),i.call(e+"_add",s,L,g),i.call(e+"_square",g,g),i.call(e+"_sub",g,f,g),i.call(e+"_sub",g,b,g))}(),function(){const o=t.addFunction(a+"_add");o.addParam("p1","i32"),o.addParam("p2","i32"),o.addParam("pr","i32"),o.addLocal("z1","i32"),o.addLocal("z2","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n));o.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*n))));const s=i.getLocal("z1"),r=i.getLocal("p2"),d=i.i32_add(i.getLocal("p2"),i.i32_const(n));o.addCode(i.setLocal("z2",i.i32_add(i.getLocal("p2"),i.i32_const(2*n))));const u=i.getLocal("z2"),_=i.getLocal("pr"),g=i.i32_add(i.getLocal("pr"),i.i32_const(n)),f=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),h=i.i32_const(t.alloc(n)),p=i.i32_const(t.alloc(n)),m=i.i32_const(t.alloc(n)),L=i.i32_const(t.alloc(n)),b=i.i32_const(t.alloc(n)),w=i.i32_const(t.alloc(n)),y=i.i32_const(t.alloc(n)),A=i.i32_const(t.alloc(n)),C=i.i32_const(t.alloc(n)),F=i.i32_const(t.alloc(n)),x=i.i32_const(t.alloc(n)),I=i.i32_const(t.alloc(n)),B=i.i32_const(t.alloc(n)),E=i.i32_const(t.alloc(n)),v=i.i32_const(t.alloc(n)),S=i.i32_const(t.alloc(n)),P=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),[...i.call(a+"_copy",i.getLocal("p2"),i.getLocal("pr")),...i.ret([])]),i.if(i.call(a+"_isZero",i.getLocal("p2")),[...i.call(a+"_copy",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])]),i.if(i.call(e+"_isOne",s),[...i.call(a+"_addMixed",r,l,_),...i.ret([])]),i.if(i.call(e+"_isOne",u),[...i.call(a+"_addMixed",l,r,_),...i.ret([])]),i.call(e+"_square",s,h),i.call(e+"_square",u,p),i.call(e+"_mul",l,p,m),i.call(e+"_mul",r,h,L),i.call(e+"_mul",s,h,b),i.call(e+"_mul",u,p,w),i.call(e+"_mul",c,w,y),i.call(e+"_mul",d,b,A),i.if(i.call(e+"_eq",m,L),i.if(i.call(e+"_eq",y,A),[...i.call(a+"_double",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])])),i.call(e+"_sub",L,m,C),i.call(e+"_sub",A,y,F),i.call(e+"_add",C,C,x),i.call(e+"_square",x,x),i.call(e+"_mul",C,x,I),i.call(e+"_add",F,F,B),i.call(e+"_mul",m,x,v),i.call(e+"_square",B,E),i.call(e+"_add",v,v,S),i.call(e+"_sub",E,I,_),i.call(e+"_sub",_,S,_),i.call(e+"_mul",y,I,P),i.call(e+"_add",P,P,P),i.call(e+"_sub",v,_,g),i.call(e+"_mul",g,B,g),i.call(e+"_sub",g,P,g),i.call(e+"_add",s,u,f),i.call(e+"_square",f,f),i.call(e+"_sub",f,h,f),i.call(e+"_sub",f,p,f),i.call(e+"_mul",f,C,f))}(),function(){const o=t.addFunction(a+"_negAffine");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.getLocal("pr"),r=i.i32_add(i.getLocal("pr"),i.i32_const(n));o.addCode(i.call(e+"_copy",l,s),i.call(e+"_neg",c,r))}(),function(){const o=t.addFunction(a+"_neg");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.i32_add(i.getLocal("p1"),i.i32_const(2*n)),r=i.getLocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(n)),u=i.i32_add(i.getLocal("pr"),i.i32_const(2*n));o.addCode(i.call(e+"_copy",l,r),i.call(e+"_neg",c,d),i.call(e+"_copy",s,u))}(),function(){const e=t.addFunction(a+"_subAffine");e.addParam("p1","i32"),e.addParam("p2","i32"),e.addParam("pr","i32");const o=e.getCodeBuilder(),i=o.i32_const(t.alloc(3*n));e.addCode(o.call(a+"_negAffine",o.getLocal("p2"),i),o.call(a+"_addAffine",o.getLocal("p1"),i,o.getLocal("pr")))}(),function(){const e=t.addFunction(a+"_subMixed");e.addParam("p1","i32"),e.addParam("p2","i32"),e.addParam("pr","i32");const o=e.getCodeBuilder(),i=o.i32_const(t.alloc(3*n));e.addCode(o.call(a+"_negAffine",o.getLocal("p2"),i),o.call(a+"_addMixed",o.getLocal("p1"),i,o.getLocal("pr")))}(),function(){const e=t.addFunction(a+"_sub");e.addParam("p1","i32"),e.addParam("p2","i32"),e.addParam("pr","i32");const o=e.getCodeBuilder(),i=o.i32_const(t.alloc(3*n));e.addCode(o.call(a+"_neg",o.getLocal("p2"),i),o.call(a+"_add",o.getLocal("p1"),i,o.getLocal("pr")))}(),function(){const o=t.addFunction(a+"_fromMontgomeryAffine");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_fromMontgomery",i.getLocal("p1"),i.getLocal("pr")));for(let t=1;t<2;t++)o.addCode(i.call(e+"_fromMontgomery",i.i32_add(i.getLocal("p1"),i.i32_const(t*n)),i.i32_add(i.getLocal("pr"),i.i32_const(t*n))))}(),function(){const o=t.addFunction(a+"_fromMontgomery");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_fromMontgomery",i.getLocal("p1"),i.getLocal("pr")));for(let t=1;t<3;t++)o.addCode(i.call(e+"_fromMontgomery",i.i32_add(i.getLocal("p1"),i.i32_const(t*n)),i.i32_add(i.getLocal("pr"),i.i32_const(t*n))))}(),function(){const o=t.addFunction(a+"_toMontgomeryAffine");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_toMontgomery",i.getLocal("p1"),i.getLocal("pr")));for(let t=1;t<2;t++)o.addCode(i.call(e+"_toMontgomery",i.i32_add(i.getLocal("p1"),i.i32_const(t*n)),i.i32_add(i.getLocal("pr"),i.i32_const(t*n))))}(),function(){const o=t.addFunction(a+"_toMontgomery");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.call(e+"_toMontgomery",i.getLocal("p1"),i.getLocal("pr")));for(let t=1;t<3;t++)o.addCode(i.call(e+"_toMontgomery",i.i32_add(i.getLocal("p1"),i.i32_const(t*n)),i.i32_add(i.getLocal("pr"),i.i32_const(t*n))))}(),function(){const o=t.addFunction(a+"_toAffine");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.i32_add(i.getLocal("p1"),i.i32_const(2*n)),r=i.getLocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(n)),u=i.i32_const(t.alloc(n)),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),[...i.call(e+"_zero",r),...i.call(e+"_zero",d)],[...i.call(e+"_inverse",s,u),...i.call(e+"_square",u,_),...i.call(e+"_mul",u,_,g),...i.call(e+"_mul",l,_,r),...i.call(e+"_mul",c,g,d)]))}(),function(){const i=t.addFunction(a+"_inCurveAffine");i.addParam("pIn","i32"),i.setReturnType("i32");const l=i.getCodeBuilder(),c=l.getLocal("pIn"),s=l.i32_add(l.getLocal("pIn"),l.i32_const(n)),r=l.i32_const(t.alloc(n)),d=l.i32_const(t.alloc(n));i.addCode(l.call(e+"_square",s,r),l.call(e+"_square",c,d),l.call(e+"_mul",c,d,d),l.call(e+"_add",d,l.i32_const(o),d),l.ret(l.call(e+"_eq",r,d)))}(),function(){const e=t.addFunction(a+"_inCurve");e.addParam("pIn","i32"),e.setReturnType("i32");const o=e.getCodeBuilder(),i=o.i32_const(t.alloc(2*n));e.addCode(o.call(a+"_toAffine",o.getLocal("pIn"),i),o.ret(o.call(a+"_inCurveAffine",i)))}(),function(){const o=t.addFunction(a+"_batchToAffine");o.addParam("pIn","i32"),o.addParam("n","i32"),o.addParam("pOut","i32"),o.addLocal("pAux","i32"),o.addLocal("itIn","i32"),o.addLocal("itAux","i32"),o.addLocal("itOut","i32"),o.addLocal("i","i32");const i=o.getCodeBuilder(),l=i.i32_const(t.alloc(n));o.addCode(i.setLocal("pAux",i.i32_load(i.i32_const(0))),i.i32_store(i.i32_const(0),i.i32_add(i.getLocal("pAux"),i.i32_mul(i.getLocal("n"),i.i32_const(n)))),i.call(e+"_batchInverse",i.i32_add(i.getLocal("pIn"),i.i32_const(2*n)),i.i32_const(3*n),i.getLocal("n"),i.getLocal("pAux"),i.i32_const(n)),i.setLocal("itIn",i.getLocal("pIn")),i.setLocal("itAux",i.getLocal("pAux")),i.setLocal("itOut",i.getLocal("pOut")),i.setLocal("i",i.i32_const(0)),i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("i"),i.getLocal("n"))),i.if(i.call(e+"_isZero",i.getLocal("itAux")),[...i.call(e+"_zero",i.getLocal("itOut")),...i.call(e+"_zero",i.i32_add(i.getLocal("itOut"),i.i32_const(n)))],[...i.call(e+"_mul",i.getLocal("itAux"),i.i32_add(i.getLocal("itIn"),i.i32_const(n)),l),...i.call(e+"_square",i.getLocal("itAux"),i.getLocal("itAux")),...i.call(e+"_mul",i.getLocal("itAux"),i.getLocal("itIn"),i.getLocal("itOut")),...i.call(e+"_mul",i.getLocal("itAux"),l,i.i32_add(i.getLocal("itOut"),i.i32_const(n)))]),i.setLocal("itIn",i.i32_add(i.getLocal("itIn"),i.i32_const(3*n))),i.setLocal("itOut",i.i32_add(i.getLocal("itOut"),i.i32_const(2*n))),i.setLocal("itAux",i.i32_add(i.getLocal("itAux"),i.i32_const(n))),i.setLocal("i",i.i32_add(i.getLocal("i"),i.i32_const(1))),i.br(0))),i.i32_store(i.i32_const(0),i.getLocal("pAux")))}(),function(){const o=t.addFunction(a+"_normalize");o.addParam("p1","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),l=i.getLocal("p1"),c=i.i32_add(i.getLocal("p1"),i.i32_const(n)),s=i.i32_add(i.getLocal("p1"),i.i32_const(2*n)),r=i.getLocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(n)),u=i.i32_add(i.getLocal("pr"),i.i32_const(2*n)),_=i.i32_const(t.alloc(n)),g=i.i32_const(t.alloc(n)),f=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),i.call(a+"_zero",i.getLocal("pr")),[...i.call(e+"_inverse",s,_),...i.call(e+"_square",_,g),...i.call(e+"_mul",_,g,f),...i.call(e+"_mul",l,g,r),...i.call(e+"_mul",c,f,d),...i.call(e+"_one",u)]))}(),function(){const e=t.addFunction(a+"__reverseBytes");e.addParam("pIn","i32"),e.addParam("n","i32"),e.addParam("pOut","i32"),e.addLocal("itOut","i32"),e.addLocal("itIn","i32");const o=e.getCodeBuilder();e.addCode(o.setLocal("itOut",o.i32_sub(o.i32_add(o.getLocal("pOut"),o.getLocal("n")),o.i32_const(1))),o.setLocal("itIn",o.getLocal("pIn")),o.block(o.loop(o.br_if(1,o.i32_lt_s(o.getLocal("itOut"),o.getLocal("pOut"))),o.i32_store8(o.getLocal("itOut"),o.i32_load8_u(o.getLocal("itIn"))),o.setLocal("itOut",o.i32_sub(o.getLocal("itOut"),o.i32_const(1))),o.setLocal("itIn",o.i32_add(o.getLocal("itIn"),o.i32_const(1))),o.br(0))))}(),function(){const e=t.addFunction(a+"_LEMtoU");e.addParam("pIn","i32"),e.addParam("pOut","i32");const o=e.getCodeBuilder(),i=t.alloc(2*n),l=o.i32_const(i),c=o.i32_const(i),s=o.i32_const(i+n);e.addCode(o.if(o.call(a+"_isZeroAffine",o.getLocal("pIn")),[...o.call(a+"_zeroAffine",o.getLocal("pOut")),...o.ret([])]),o.call(a+"_fromMontgomeryAffine",o.getLocal("pIn"),l),o.call(a+"__reverseBytes",c,o.i32_const(n),o.getLocal("pOut")),o.call(a+"__reverseBytes",s,o.i32_const(n),o.i32_add(o.getLocal("pOut"),o.i32_const(n))))}(),function(){const o=t.addFunction(a+"_LEMtoC");o.addParam("pIn","i32"),o.addParam("pOut","i32");const i=o.getCodeBuilder(),l=i.i32_const(t.alloc(n));o.addCode(i.if(i.call(a+"_isZeroAffine",i.getLocal("pIn")),[...i.call(e+"_zero",i.getLocal("pOut")),...i.i32_store8(i.getLocal("pOut"),i.i32_const(64)),...i.ret([])]),i.call(e+"_fromMontgomery",i.getLocal("pIn"),l),i.call(a+"__reverseBytes",l,i.i32_const(n),i.getLocal("pOut")),i.if(i.i32_eq(i.call(e+"_sign",i.i32_add(i.getLocal("pIn"),i.i32_const(n))),i.i32_const(-1)),i.i32_store8(i.getLocal("pOut"),i.i32_or(i.i32_load8_u(i.getLocal("pOut")),i.i32_const(128)))))}(),function(){const e=t.addFunction(a+"_UtoLEM");e.addParam("pIn","i32"),e.addParam("pOut","i32");const o=e.getCodeBuilder(),i=t.alloc(2*n),l=o.i32_const(i),c=o.i32_const(i),s=o.i32_const(i+n);e.addCode(o.if(o.i32_and(o.i32_load8_u(o.getLocal("pIn")),o.i32_const(64)),[...o.call(a+"_zeroAffine",o.getLocal("pOut")),...o.ret([])]),o.call(a+"__reverseBytes",o.getLocal("pIn"),o.i32_const(n),c),o.call(a+"__reverseBytes",o.i32_add(o.getLocal("pIn"),o.i32_const(n)),o.i32_const(n),s),o.call(a+"_toMontgomeryAffine",l,o.getLocal("pOut")))}(),function(){const i=t.addFunction(a+"_CtoLEM");i.addParam("pIn","i32"),i.addParam("pOut","i32"),i.addLocal("firstByte","i32"),i.addLocal("greatest","i32");const l=i.getCodeBuilder(),c=t.alloc(2*n),s=l.i32_const(c),r=l.i32_const(c+n);i.addCode(l.setLocal("firstByte",l.i32_load8_u(l.getLocal("pIn"))),l.if(l.i32_and(l.getLocal("firstByte"),l.i32_const(64)),[...l.call(a+"_zeroAffine",l.getLocal("pOut")),...l.ret([])]),l.setLocal("greatest",l.i32_and(l.getLocal("firstByte"),l.i32_const(128))),l.call(e+"_copy",l.getLocal("pIn"),r),l.i32_store8(r,l.i32_and(l.getLocal("firstByte"),l.i32_const(63))),l.call(a+"__reverseBytes",r,l.i32_const(n),s),l.call(e+"_toMontgomery",s,l.getLocal("pOut")),l.call(e+"_square",l.getLocal("pOut"),r),l.call(e+"_mul",l.getLocal("pOut"),r,r),l.call(e+"_add",r,l.i32_const(o),r),l.call(e+"_sqrt",r,r),l.call(e+"_neg",r,s),l.if(l.i32_eq(l.call(e+"_sign",r),l.i32_const(-1)),l.if(l.getLocal("greatest"),l.call(e+"_copy",r,l.i32_add(l.getLocal("pOut"),l.i32_const(n))),l.call(e+"_neg",r,l.i32_add(l.getLocal("pOut"),l.i32_const(n)))),l.if(l.getLocal("greatest"),l.call(e+"_neg",r,l.i32_add(l.getLocal("pOut"),l.i32_const(n))),l.call(e+"_copy",r,l.i32_add(l.getLocal("pOut"),l.i32_const(n))))))}(),tl(t,a+"_batchLEMtoU",a+"_LEMtoU",2*n,2*n),tl(t,a+"_batchLEMtoC",a+"_LEMtoC",2*n,n),tl(t,a+"_batchUtoLEM",a+"_UtoLEM",2*n,2*n),tl(t,a+"_batchCtoLEM",a+"_CtoLEM",n,2*n,!0),tl(t,a+"_batchToJacobian",a+"_toJacobian",2*n,3*n,!0),al(t,a,a+"_multiexp",a+"_add",3*n),al(t,a,a+"_multiexpAffine",a+"_addMixed",2*n),Xn(t,a+"_timesScalar",3*n,a+"_add",a+"_double",a+"_sub",a+"_copy",a+"_zero"),Xn(t,a+"_timesScalarAffine",2*n,a+"_addMixed",a+"_double",a+"_subMixed",a+"_copyAffine",a+"_zero"),t.exportFunction(a+"_isZero"),t.exportFunction(a+"_isZeroAffine"),t.exportFunction(a+"_eq"),t.exportFunction(a+"_eqMixed"),t.exportFunction(a+"_eqAffine"),t.exportFunction(a+"_copy"),t.exportFunction(a+"_copyAffine"),t.exportFunction(a+"_zero"),t.exportFunction(a+"_zeroAffine"),t.exportFunction(a+"_double"),t.exportFunction(a+"_doubleAffine"),t.exportFunction(a+"_add"),t.exportFunction(a+"_addMixed"),t.exportFunction(a+"_addAffine"),t.exportFunction(a+"_neg"),t.exportFunction(a+"_negAffine"),t.exportFunction(a+"_sub"),t.exportFunction(a+"_subMixed"),t.exportFunction(a+"_subAffine"),t.exportFunction(a+"_fromMontgomery"),t.exportFunction(a+"_fromMontgomeryAffine"),t.exportFunction(a+"_toMontgomery"),t.exportFunction(a+"_toMontgomeryAffine"),t.exportFunction(a+"_timesScalar"),t.exportFunction(a+"_timesScalarAffine"),t.exportFunction(a+"_normalize"),t.exportFunction(a+"_LEMtoU"),t.exportFunction(a+"_LEMtoC"),t.exportFunction(a+"_UtoLEM"),t.exportFunction(a+"_CtoLEM"),t.exportFunction(a+"_batchLEMtoU"),t.exportFunction(a+"_batchLEMtoC"),t.exportFunction(a+"_batchUtoLEM"),t.exportFunction(a+"_batchCtoLEM"),t.exportFunction(a+"_toAffine"),t.exportFunction(a+"_toJacobian"),t.exportFunction(a+"_batchToAffine"),t.exportFunction(a+"_batchToJacobian"),t.exportFunction(a+"_inCurve"),t.exportFunction(a+"_inCurveAffine"),a};const{isOdd:ol,modInv:il,modPow:nl}=pn,ll=un;var cl=function(t,a,e,o,i){const n=8*t.modules[o].n64,l=8*t.modules[e].n64,c=t.modules[o].q;let s=c-1n,r=0;for(;!ol(s);)r++,s>>=1n;let d=2n;for(;1n===nl(d,c>>1n,c);)d+=1n;const u=new Array(r+1);u[r]=nl(d,s,c);let _=r-1;for(;_>=0;)u[_]=nl(u[_+1],2n,c),_--;const g=[],f=(1n<>e);return a}const x=Array(256);for(let t=0;t<256;t++)x[t]=F(t);const I=t.alloc(x);function B(){const e=t.addFunction(a+"_fft");e.addParam("px","i32"),e.addParam("n","i32"),e.addLocal("bits","i32");const i=e.getCodeBuilder(),l=i.i32_const(t.alloc(n));e.addCode(i.setLocal("bits",i.call(a+"__log2",i.getLocal("n"))),i.call(o+"_one",l),i.call(a+"_rawfft",i.getLocal("px"),i.getLocal("bits"),i.i32_const(0),l))}!function(){const e=t.addFunction(a+"__rev");e.addParam("x","i32"),e.addParam("bits","i32"),e.setReturnType("i32");const o=e.getCodeBuilder();e.addCode(o.i32_rotl(o.i32_add(o.i32_add(o.i32_shl(o.i32_load8_u(o.i32_and(o.getLocal("x"),o.i32_const(255)),I,0),o.i32_const(24)),o.i32_shl(o.i32_load8_u(o.i32_and(o.i32_shr_u(o.getLocal("x"),o.i32_const(8)),o.i32_const(255)),I,0),o.i32_const(16))),o.i32_add(o.i32_shl(o.i32_load8_u(o.i32_and(o.i32_shr_u(o.getLocal("x"),o.i32_const(16)),o.i32_const(255)),I,0),o.i32_const(8)),o.i32_load8_u(o.i32_and(o.i32_shr_u(o.getLocal("x"),o.i32_const(24)),o.i32_const(255)),I,0))),o.getLocal("bits")))}(),function(){const o=t.addFunction(a+"__reversePermutation");o.addParam("px","i32"),o.addParam("bits","i32"),o.addLocal("n","i32"),o.addLocal("i","i32"),o.addLocal("ri","i32"),o.addLocal("idx1","i32"),o.addLocal("idx2","i32");const i=o.getCodeBuilder(),n=i.i32_const(t.alloc(l));o.addCode(i.setLocal("n",i.i32_shl(i.i32_const(1),i.getLocal("bits"))),i.setLocal("i",i.i32_const(0)),i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("i"),i.getLocal("n"))),i.setLocal("idx1",i.i32_add(i.getLocal("px"),i.i32_mul(i.getLocal("i"),i.i32_const(l)))),i.setLocal("ri",i.call(a+"__rev",i.getLocal("i"),i.getLocal("bits"))),i.setLocal("idx2",i.i32_add(i.getLocal("px"),i.i32_mul(i.getLocal("ri"),i.i32_const(l)))),i.if(i.i32_lt_u(i.getLocal("i"),i.getLocal("ri")),[...i.call(e+"_copy",i.getLocal("idx1"),n),...i.call(e+"_copy",i.getLocal("idx2"),i.getLocal("idx1")),...i.call(e+"_copy",n,i.getLocal("idx2"))]),i.setLocal("i",i.i32_add(i.getLocal("i"),i.i32_const(1))),i.br(0))))}(),function(){const n=t.addFunction(a+"__fftFinal");n.addParam("px","i32"),n.addParam("bits","i32"),n.addParam("reverse","i32"),n.addParam("mulFactor","i32"),n.addLocal("n","i32"),n.addLocal("ndiv2","i32"),n.addLocal("pInv2","i32"),n.addLocal("i","i32"),n.addLocal("mask","i32"),n.addLocal("idx1","i32"),n.addLocal("idx2","i32");const c=n.getCodeBuilder(),s=c.i32_const(t.alloc(l));n.addCode(c.if(c.i32_and(c.i32_eqz(c.getLocal("reverse")),c.call(o+"_isOne",c.getLocal("mulFactor"))),c.ret([])),c.setLocal("n",c.i32_shl(c.i32_const(1),c.getLocal("bits"))),c.setLocal("mask",c.i32_sub(c.getLocal("n"),c.i32_const(1))),c.setLocal("i",c.i32_const(1)),c.setLocal("ndiv2",c.i32_shr_u(c.getLocal("n"),c.i32_const(1))),c.block(c.loop(c.br_if(1,c.i32_ge_u(c.getLocal("i"),c.getLocal("ndiv2"))),c.setLocal("idx1",c.i32_add(c.getLocal("px"),c.i32_mul(c.getLocal("i"),c.i32_const(l)))),c.setLocal("idx2",c.i32_add(c.getLocal("px"),c.i32_mul(c.i32_sub(c.getLocal("n"),c.getLocal("i")),c.i32_const(l)))),c.if(c.getLocal("reverse"),c.if(c.call(o+"_isOne",c.getLocal("mulFactor")),[...c.call(e+"_copy",c.getLocal("idx1"),s),...c.call(e+"_copy",c.getLocal("idx2"),c.getLocal("idx1")),...c.call(e+"_copy",s,c.getLocal("idx2"))],[...c.call(e+"_copy",c.getLocal("idx1"),s),...c.call(i,c.getLocal("idx2"),c.getLocal("mulFactor"),c.getLocal("idx1")),...c.call(i,s,c.getLocal("mulFactor"),c.getLocal("idx2"))]),c.if(c.call(o+"_isOne",c.getLocal("mulFactor")),[],[...c.call(i,c.getLocal("idx1"),c.getLocal("mulFactor"),c.getLocal("idx1")),...c.call(i,c.getLocal("idx2"),c.getLocal("mulFactor"),c.getLocal("idx2"))])),c.setLocal("i",c.i32_add(c.getLocal("i"),c.i32_const(1))),c.br(0))),c.if(c.call(o+"_isOne",c.getLocal("mulFactor")),[],[...c.call(i,c.getLocal("px"),c.getLocal("mulFactor"),c.getLocal("px")),...c.setLocal("idx2",c.i32_add(c.getLocal("px"),c.i32_mul(c.getLocal("ndiv2"),c.i32_const(l)))),...c.call(i,c.getLocal("idx2"),c.getLocal("mulFactor"),c.getLocal("idx2"))]))}(),function(){const c=t.addFunction(a+"_rawfft");c.addParam("px","i32"),c.addParam("bits","i32"),c.addParam("reverse","i32"),c.addParam("mulFactor","i32"),c.addLocal("s","i32"),c.addLocal("k","i32"),c.addLocal("j","i32"),c.addLocal("m","i32"),c.addLocal("mdiv2","i32"),c.addLocal("n","i32"),c.addLocal("pwm","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l)),u=s.i32_const(t.alloc(l));c.addCode(s.call(a+"__reversePermutation",s.getLocal("px"),s.getLocal("bits")),s.setLocal("n",s.i32_shl(s.i32_const(1),s.getLocal("bits"))),s.setLocal("s",s.i32_const(1)),s.block(s.loop(s.br_if(1,s.i32_gt_u(s.getLocal("s"),s.getLocal("bits"))),s.setLocal("m",s.i32_shl(s.i32_const(1),s.getLocal("s"))),s.setLocal("pwm",s.i32_add(s.i32_const(h),s.i32_mul(s.getLocal("s"),s.i32_const(n)))),s.setLocal("k",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_ge_u(s.getLocal("k"),s.getLocal("n"))),s.call(o+"_one",r),s.setLocal("mdiv2",s.i32_shr_u(s.getLocal("m"),s.i32_const(1))),s.setLocal("j",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_ge_u(s.getLocal("j"),s.getLocal("mdiv2"))),s.setLocal("idx1",s.i32_add(s.getLocal("px"),s.i32_mul(s.i32_add(s.getLocal("k"),s.getLocal("j")),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("idx1"),s.i32_mul(s.getLocal("mdiv2"),s.i32_const(l)))),s.call(i,s.getLocal("idx2"),r,d),s.call(e+"_copy",s.getLocal("idx1"),u),s.call(e+"_add",u,d,s.getLocal("idx1")),s.call(e+"_sub",u,d,s.getLocal("idx2")),s.call(o+"_mul",r,s.getLocal("pwm"),r),s.setLocal("j",s.i32_add(s.getLocal("j"),s.i32_const(1))),s.br(0))),s.setLocal("k",s.i32_add(s.getLocal("k"),s.getLocal("m"))),s.br(0))),s.setLocal("s",s.i32_add(s.getLocal("s"),s.i32_const(1))),s.br(0))),s.call(a+"__fftFinal",s.getLocal("px"),s.getLocal("bits"),s.getLocal("reverse"),s.getLocal("mulFactor")))}(),function(){const e=t.addFunction(a+"__log2");e.addParam("n","i32"),e.setReturnType("i32"),e.addLocal("bits","i32"),e.addLocal("aux","i32");const o=e.getCodeBuilder();e.addCode(o.setLocal("aux",o.i32_shr_u(o.getLocal("n"),o.i32_const(1)))),e.addCode(o.setLocal("bits",o.i32_const(0))),e.addCode(o.block(o.loop(o.br_if(1,o.i32_eqz(o.getLocal("aux"))),o.setLocal("aux",o.i32_shr_u(o.getLocal("aux"),o.i32_const(1))),o.setLocal("bits",o.i32_add(o.getLocal("bits"),o.i32_const(1))),o.br(0)))),e.addCode(o.if(o.i32_ne(o.getLocal("n"),o.i32_shl(o.i32_const(1),o.getLocal("bits"))),o.unreachable())),e.addCode(o.if(o.i32_gt_u(o.getLocal("bits"),o.i32_const(r)),o.unreachable())),e.addCode(o.getLocal("bits"))}(),B(),function(){const e=t.addFunction(a+"_ifft");e.addParam("px","i32"),e.addParam("n","i32"),e.addLocal("bits","i32"),e.addLocal("pInv2","i32");const o=e.getCodeBuilder();e.addCode(o.setLocal("bits",o.call(a+"__log2",o.getLocal("n"))),o.setLocal("pInv2",o.i32_add(o.i32_const(L),o.i32_mul(o.getLocal("bits"),o.i32_const(n)))),o.call(a+"_rawfft",o.getLocal("px"),o.getLocal("bits"),o.i32_const(1),o.getLocal("pInv2")))}(),function(){const c=t.addFunction(a+"_fftJoin");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l)),u=s.i32_const(t.alloc(l));c.addCode(s.call(o+"_copy",s.getLocal("first"),r),s.setLocal("i",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("n"))),s.setLocal("idx1",s.i32_add(s.getLocal("pBuff1"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("pBuff2"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.call(i,s.getLocal("idx2"),r,d),s.call(e+"_copy",s.getLocal("idx1"),u),s.call(e+"_add",u,d,s.getLocal("idx1")),s.call(e+"_sub",u,d,s.getLocal("idx2")),s.call(o+"_mul",r,s.getLocal("inc"),r),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),function(){const c=t.addFunction(a+"_fftJoinExt");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addParam("totalBits","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("pShiftToM","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l));c.addCode(s.setLocal("pShiftToM",s.i32_add(s.i32_const(A),s.i32_mul(s.getLocal("totalBits"),s.i32_const(n)))),s.call(o+"_copy",s.getLocal("first"),r),s.setLocal("i",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("n"))),s.setLocal("idx1",s.i32_add(s.getLocal("pBuff1"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("pBuff2"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.call(e+"_add",s.getLocal("idx1"),s.getLocal("idx2"),d),s.call(i,s.getLocal("idx2"),s.getLocal("pShiftToM"),s.getLocal("idx2")),s.call(e+"_add",s.getLocal("idx1"),s.getLocal("idx2"),s.getLocal("idx2")),s.call(i,s.getLocal("idx2"),r,s.getLocal("idx2")),s.call(e+"_copy",d,s.getLocal("idx1")),s.call(o+"_mul",r,s.getLocal("inc"),r),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),function(){const c=t.addFunction(a+"_fftJoinExtInv");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addParam("totalBits","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("pShiftToM","i32"),c.addLocal("pSConst","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l));c.addCode(s.setLocal("pShiftToM",s.i32_add(s.i32_const(A),s.i32_mul(s.getLocal("totalBits"),s.i32_const(n)))),s.setLocal("pSConst",s.i32_add(s.i32_const(C),s.i32_mul(s.getLocal("totalBits"),s.i32_const(n)))),s.call(o+"_copy",s.getLocal("first"),r),s.setLocal("i",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("n"))),s.setLocal("idx1",s.i32_add(s.getLocal("pBuff1"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("pBuff2"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.call(i,s.getLocal("idx2"),r,d),s.call(e+"_sub",s.getLocal("idx1"),d,s.getLocal("idx2")),s.call(i,s.getLocal("idx2"),s.getLocal("pSConst"),s.getLocal("idx2")),s.call(i,s.getLocal("idx1"),s.getLocal("pShiftToM"),s.getLocal("idx1")),s.call(e+"_sub",d,s.getLocal("idx1"),s.getLocal("idx1")),s.call(i,s.getLocal("idx1"),s.getLocal("pSConst"),s.getLocal("idx1")),s.call(o+"_mul",r,s.getLocal("inc"),r),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),function(){const c=t.addFunction(a+"_fftMix");c.addParam("pBuff","i32"),c.addParam("n","i32"),c.addParam("exp","i32"),c.addLocal("nGroups","i32"),c.addLocal("nPerGroup","i32"),c.addLocal("nPerGroupDiv2","i32"),c.addLocal("pairOffset","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("j","i32"),c.addLocal("pwm","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l)),u=s.i32_const(t.alloc(l));c.addCode(s.setLocal("nPerGroup",s.i32_shl(s.i32_const(1),s.getLocal("exp"))),s.setLocal("nPerGroupDiv2",s.i32_shr_u(s.getLocal("nPerGroup"),s.i32_const(1))),s.setLocal("nGroups",s.i32_shr_u(s.getLocal("n"),s.getLocal("exp"))),s.setLocal("pairOffset",s.i32_mul(s.getLocal("nPerGroupDiv2"),s.i32_const(l))),s.setLocal("pwm",s.i32_add(s.i32_const(h),s.i32_mul(s.getLocal("exp"),s.i32_const(n)))),s.setLocal("i",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("nGroups"))),s.call(o+"_one",r),s.setLocal("j",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("j"),s.getLocal("nPerGroupDiv2"))),s.setLocal("idx1",s.i32_add(s.getLocal("pBuff"),s.i32_mul(s.i32_add(s.i32_mul(s.getLocal("i"),s.getLocal("nPerGroup")),s.getLocal("j")),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("idx1"),s.getLocal("pairOffset"))),s.call(i,s.getLocal("idx2"),r,d),s.call(e+"_copy",s.getLocal("idx1"),u),s.call(e+"_add",u,d,s.getLocal("idx1")),s.call(e+"_sub",u,d,s.getLocal("idx2")),s.call(o+"_mul",r,s.getLocal("pwm"),r),s.setLocal("j",s.i32_add(s.getLocal("j"),s.i32_const(1))),s.br(0))),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),function(){const o=t.addFunction(a+"_fftFinal");o.addParam("pBuff","i32"),o.addParam("n","i32"),o.addParam("factor","i32"),o.addLocal("idx1","i32"),o.addLocal("idx2","i32"),o.addLocal("i","i32"),o.addLocal("ndiv2","i32");const n=o.getCodeBuilder(),c=n.i32_const(t.alloc(l));o.addCode(n.setLocal("ndiv2",n.i32_shr_u(n.getLocal("n"),n.i32_const(1))),n.if(n.i32_and(n.getLocal("n"),n.i32_const(1)),n.call(i,n.i32_add(n.getLocal("pBuff"),n.i32_mul(n.getLocal("ndiv2"),n.i32_const(l))),n.getLocal("factor"),n.i32_add(n.getLocal("pBuff"),n.i32_mul(n.getLocal("ndiv2"),n.i32_const(l))))),n.setLocal("i",n.i32_const(0)),n.block(n.loop(n.br_if(1,n.i32_ge_u(n.getLocal("i"),n.getLocal("ndiv2"))),n.setLocal("idx1",n.i32_add(n.getLocal("pBuff"),n.i32_mul(n.getLocal("i"),n.i32_const(l)))),n.setLocal("idx2",n.i32_add(n.getLocal("pBuff"),n.i32_mul(n.i32_sub(n.i32_sub(n.getLocal("n"),n.i32_const(1)),n.getLocal("i")),n.i32_const(l)))),n.call(i,n.getLocal("idx2"),n.getLocal("factor"),c),n.call(i,n.getLocal("idx1"),n.getLocal("factor"),n.getLocal("idx2")),n.call(e+"_copy",c,n.getLocal("idx1")),n.setLocal("i",n.i32_add(n.getLocal("i"),n.i32_const(1))),n.br(0))))}(),function(){const c=t.addFunction(a+"_prepareLagrangeEvaluation");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addParam("totalBits","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("pShiftToM","i32"),c.addLocal("pSConst","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(n)),d=s.i32_const(t.alloc(l));c.addCode(s.setLocal("pShiftToM",s.i32_add(s.i32_const(A),s.i32_mul(s.getLocal("totalBits"),s.i32_const(n)))),s.setLocal("pSConst",s.i32_add(s.i32_const(C),s.i32_mul(s.getLocal("totalBits"),s.i32_const(n)))),s.call(o+"_copy",s.getLocal("first"),r),s.setLocal("i",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("n"))),s.setLocal("idx1",s.i32_add(s.getLocal("pBuff1"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("pBuff2"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.call(i,s.getLocal("idx1"),s.getLocal("pShiftToM"),d),s.call(e+"_sub",s.getLocal("idx2"),d,d),s.call(e+"_sub",s.getLocal("idx1"),s.getLocal("idx2"),s.getLocal("idx2")),s.call(i,d,s.getLocal("pSConst"),s.getLocal("idx1")),s.call(i,s.getLocal("idx2"),r,s.getLocal("idx2")),s.call(o+"_mul",r,s.getLocal("inc"),r),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),t.exportFunction(a+"_fft"),t.exportFunction(a+"_ifft"),t.exportFunction(a+"_rawfft"),t.exportFunction(a+"_fftJoin"),t.exportFunction(a+"_fftJoinExt"),t.exportFunction(a+"_fftJoinExtInv"),t.exportFunction(a+"_fftMix"),t.exportFunction(a+"_fftFinal"),t.exportFunction(a+"_prepareLagrangeEvaluation")},sl=function(t,a,e){const o=8*t.modules[e].n64;return function(){const i=t.addFunction(a+"_zero");i.addParam("px","i32"),i.addParam("n","i32"),i.addLocal("lastp","i32"),i.addLocal("p","i32");const n=i.getCodeBuilder();i.addCode(n.setLocal("p",n.getLocal("px")),n.setLocal("lastp",n.i32_add(n.getLocal("px"),n.i32_mul(n.getLocal("n"),n.i32_const(o)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("p"),n.getLocal("lastp"))),n.call(e+"_zero",n.getLocal("p")),n.setLocal("p",n.i32_add(n.getLocal("p"),n.i32_const(o))),n.br(0))))}(),function(){const i=t.addFunction(a+"_constructLC");i.addParam("ppolynomials","i32"),i.addParam("psignals","i32"),i.addParam("nSignals","i32"),i.addParam("pres","i32"),i.addLocal("i","i32"),i.addLocal("j","i32"),i.addLocal("pp","i32"),i.addLocal("ps","i32"),i.addLocal("pd","i32"),i.addLocal("ncoefs","i32");const n=i.getCodeBuilder(),l=n.i32_const(t.alloc(o));i.addCode(n.setLocal("i",n.i32_const(0)),n.setLocal("pp",n.getLocal("ppolynomials")),n.setLocal("ps",n.getLocal("psignals")),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("i"),n.getLocal("nSignals"))),n.setLocal("ncoefs",n.i32_load(n.getLocal("pp"))),n.setLocal("pp",n.i32_add(n.getLocal("pp"),n.i32_const(4))),n.setLocal("j",n.i32_const(0)),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("j"),n.getLocal("ncoefs"))),n.setLocal("pd",n.i32_add(n.getLocal("pres"),n.i32_mul(n.i32_load(n.getLocal("pp")),n.i32_const(o)))),n.setLocal("pp",n.i32_add(n.getLocal("pp"),n.i32_const(4))),n.call(e+"_mul",n.getLocal("ps"),n.getLocal("pp"),l),n.call(e+"_add",l,n.getLocal("pd"),n.getLocal("pd")),n.setLocal("pp",n.i32_add(n.getLocal("pp"),n.i32_const(o))),n.setLocal("j",n.i32_add(n.getLocal("j"),n.i32_const(1))),n.br(0))),n.setLocal("ps",n.i32_add(n.getLocal("ps"),n.i32_const(o))),n.setLocal("i",n.i32_add(n.getLocal("i"),n.i32_const(1))),n.br(0))))}(),t.exportFunction(a+"_zero"),t.exportFunction(a+"_constructLC"),a},rl=function(t,a,e){const o=8*t.modules[e].n64;return function(){const i=t.addFunction(a+"_buildABC");i.addParam("pCoefs","i32"),i.addParam("nCoefs","i32"),i.addParam("pWitness","i32"),i.addParam("pA","i32"),i.addParam("pB","i32"),i.addParam("pC","i32"),i.addParam("offsetOut","i32"),i.addParam("nOut","i32"),i.addParam("offsetWitness","i32"),i.addParam("nWitness","i32"),i.addLocal("it","i32"),i.addLocal("ita","i32"),i.addLocal("itb","i32"),i.addLocal("last","i32"),i.addLocal("m","i32"),i.addLocal("c","i32"),i.addLocal("s","i32"),i.addLocal("pOut","i32");const n=i.getCodeBuilder(),l=n.i32_const(t.alloc(o));i.addCode(n.setLocal("ita",n.getLocal("pA")),n.setLocal("itb",n.getLocal("pB")),n.setLocal("last",n.i32_add(n.getLocal("pA"),n.i32_mul(n.getLocal("nOut"),n.i32_const(o)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(e+"_zero",n.getLocal("ita")),n.call(e+"_zero",n.getLocal("itb")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(o))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(o))),n.br(0))),n.setLocal("it",n.getLocal("pCoefs")),n.setLocal("last",n.i32_add(n.getLocal("pCoefs"),n.i32_mul(n.getLocal("nCoefs"),n.i32_const(o+12)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("it"),n.getLocal("last"))),n.setLocal("s",n.i32_load(n.getLocal("it"),8)),n.if(n.i32_or(n.i32_lt_u(n.getLocal("s"),n.getLocal("offsetWitness")),n.i32_ge_u(n.getLocal("s"),n.i32_add(n.getLocal("offsetWitness"),n.getLocal("nWitness")))),[...n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(o+12))),...n.br(1)]),n.setLocal("m",n.i32_load(n.getLocal("it"))),n.if(n.i32_eq(n.getLocal("m"),n.i32_const(0)),n.setLocal("pOut",n.getLocal("pA")),n.if(n.i32_eq(n.getLocal("m"),n.i32_const(1)),n.setLocal("pOut",n.getLocal("pB")),[...n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(o+12))),...n.br(1)])),n.setLocal("c",n.i32_load(n.getLocal("it"),4)),n.if(n.i32_or(n.i32_lt_u(n.getLocal("c"),n.getLocal("offsetOut")),n.i32_ge_u(n.getLocal("c"),n.i32_add(n.getLocal("offsetOut"),n.getLocal("nOut")))),[...n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(o+12))),...n.br(1)]),n.setLocal("pOut",n.i32_add(n.getLocal("pOut"),n.i32_mul(n.i32_sub(n.getLocal("c"),n.getLocal("offsetOut")),n.i32_const(o)))),n.call(e+"_mul",n.i32_add(n.getLocal("pWitness"),n.i32_mul(n.i32_sub(n.getLocal("s"),n.getLocal("offsetWitness")),n.i32_const(o))),n.i32_add(n.getLocal("it"),n.i32_const(12)),l),n.call(e+"_add",n.getLocal("pOut"),l,n.getLocal("pOut")),n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(o+12))),n.br(0))),n.setLocal("ita",n.getLocal("pA")),n.setLocal("itb",n.getLocal("pB")),n.setLocal("it",n.getLocal("pC")),n.setLocal("last",n.i32_add(n.getLocal("pA"),n.i32_mul(n.getLocal("nOut"),n.i32_const(o)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(e+"_mul",n.getLocal("ita"),n.getLocal("itb"),n.getLocal("it")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(o))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(o))),n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(o))),n.br(0))))}(),function(){const i=t.addFunction(a+"_joinABC");i.addParam("pA","i32"),i.addParam("pB","i32"),i.addParam("pC","i32"),i.addParam("n","i32"),i.addParam("pP","i32"),i.addLocal("ita","i32"),i.addLocal("itb","i32"),i.addLocal("itc","i32"),i.addLocal("itp","i32"),i.addLocal("last","i32");const n=i.getCodeBuilder(),l=n.i32_const(t.alloc(o));i.addCode(n.setLocal("ita",n.getLocal("pA")),n.setLocal("itb",n.getLocal("pB")),n.setLocal("itc",n.getLocal("pC")),n.setLocal("itp",n.getLocal("pP")),n.setLocal("last",n.i32_add(n.getLocal("pA"),n.i32_mul(n.getLocal("n"),n.i32_const(o)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(e+"_mul",n.getLocal("ita"),n.getLocal("itb"),l),n.call(e+"_sub",l,n.getLocal("itc"),n.getLocal("itp")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(o))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(o))),n.setLocal("itc",n.i32_add(n.getLocal("itc"),n.i32_const(o))),n.setLocal("itp",n.i32_add(n.getLocal("itp"),n.i32_const(o))),n.br(0))))}(),function(){const i=t.addFunction(a+"_batchAdd");i.addParam("pa","i32"),i.addParam("pb","i32"),i.addParam("n","i32"),i.addParam("pr","i32"),i.addLocal("ita","i32"),i.addLocal("itb","i32"),i.addLocal("itr","i32"),i.addLocal("last","i32");const n=i.getCodeBuilder();i.addCode(n.setLocal("ita",n.getLocal("pa")),n.setLocal("itb",n.getLocal("pb")),n.setLocal("itr",n.getLocal("pr")),n.setLocal("last",n.i32_add(n.getLocal("pa"),n.i32_mul(n.getLocal("n"),n.i32_const(o)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(e+"_add",n.getLocal("ita"),n.getLocal("itb"),n.getLocal("itr")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(o))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(o))),n.setLocal("itr",n.i32_add(n.getLocal("itr"),n.i32_const(o))),n.br(0))))}(),t.exportFunction(a+"_buildABC"),t.exportFunction(a+"_joinABC"),t.exportFunction(a+"_batchAdd"),a},dl=function(t,a,e,o,i,n,l,c){const s=t.addFunction(a);s.addParam("pIn","i32"),s.addParam("n","i32"),s.addParam("pFirst","i32"),s.addParam("pInc","i32"),s.addParam("pOut","i32"),s.addLocal("pOldFree","i32"),s.addLocal("i","i32"),s.addLocal("pFrom","i32"),s.addLocal("pTo","i32");const r=s.getCodeBuilder(),d=r.i32_const(t.alloc(l));s.addCode(r.setLocal("pFrom",r.getLocal("pIn")),r.setLocal("pTo",r.getLocal("pOut"))),s.addCode(r.call(o+"_copy",r.getLocal("pFirst"),d)),s.addCode(r.setLocal("i",r.i32_const(0)),r.block(r.loop(r.br_if(1,r.i32_eq(r.getLocal("i"),r.getLocal("n"))),r.call(c,r.getLocal("pFrom"),d,r.getLocal("pTo")),r.setLocal("pFrom",r.i32_add(r.getLocal("pFrom"),r.i32_const(i))),r.setLocal("pTo",r.i32_add(r.getLocal("pTo"),r.i32_const(n))),r.call(o+"_mul",d,r.getLocal("pInc"),d),r.setLocal("i",r.i32_add(r.getLocal("i"),r.i32_const(1))),r.br(0)))),t.exportFunction(a)};const ul=un,_l=Nn,gl=jn,fl=Zn,hl=Jn,pl=el,ml=cl,Ll=sl,bl=rl,wl=dl,{bitLength:yl,modInv:Al,isOdd:Cl,isNegative:Fl}=pn;const xl=un,Il=Nn,Bl=jn,El=Zn,vl=Jn,Sl=el,Pl=cl,ql=sl,Ol=rl,Gl=dl,{bitLength:zl,isOdd:Tl,isNegative:Ml}=pn;var Ul=function(t,a){const e=a||"bn128";if(t.modules[e])return e;const o=21888242871839275222246405745257275088696311157297823662689037894645226208583n,i=21888242871839275222246405745257275088548364400416034343698204186575808495617n,n=Math.floor((yl(o-1n)-1)/64)+1,l=8*n,c=l,s=l,r=2*s,d=12*s,u=t.alloc(ul.bigInt2BytesLE(i,c)),_=_l(t,o,"f1m");gl(t,i,"fr","frm");const g=t.alloc(ul.bigInt2BytesLE(b(3n),s)),f=pl(t,"g1m","f1m",g);ml(t,"frm","frm","frm","frm_mul"),Ll(t,"pol","frm"),bl(t,"qap","frm");const h=fl(t,"f1m_neg","f2m","f1m"),p=t.alloc([...ul.bigInt2BytesLE(b(19485874751759354771024239261021720505790618469301721065564631296452457478373n),s),...ul.bigInt2BytesLE(b(266929791119991161246907387137283842545076965332900288569378510910307636690n),s)]),m=pl(t,"g2m","f2m",p);function L(a,e){const o=t.addFunction(a);o.addParam("pG","i32"),o.addParam("pFr","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder(),n=i.i32_const(t.alloc(l));o.addCode(i.call("frm_fromMontgomery",i.getLocal("pFr"),n),i.call(e,i.getLocal("pG"),n,i.i32_const(l),i.getLocal("pr"))),t.exportFunction(a)}function b(t){return BigInt(t)*(1n<0n;)Cl(a)?e.push(1):e.push(0),a>>=1n;return e}(29793968203157093288n),T=t.alloc(z),M=3*r,U=z.length-1,Q=z.reduce(((t,a)=>t+(0!=a?1:0)),0),k=6*l,R=3*l*2+(Q+U+1)*M;t.modules[e]={n64:n,pG1gen:y,pG1zero:C,pG1b:g,pG2gen:x,pG2zero:B,pG2b:p,pq:t.modules.f1m.pq,pr:u,pOneT:E,prePSize:k,preQSize:R,r:i.toString(),q:o.toString()};const N=4965661367192848881n;function $(a){const i=[[[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n]],[[1n,0n],[8376118865763821496583973867626364092589906065868298776909617916018768340080n,16469823323077808223889137241176536799009286646108169935659301613961712198316n],[21888242871839275220042445260109153167277707414472061641714758635765020556617n,0n],[11697423496358154304825782922584725312912383441159505038794027105778954184319n,303847389135065887422783454877609941456349188919719272345083954437860409601n],[21888242871839275220042445260109153167277707414472061641714758635765020556616n,0n],[3321304630594332808241809054958361220322477375291206261884409189760185844239n,5722266937896532885780051958958348231143373700109372999374820235121374419868n],[21888242871839275222246405745257275088696311157297823662689037894645226208582n,0n],[13512124006075453725662431877630910996106405091429524885779419978626457868503n,5418419548761466998357268504080738289687024511189653727029736280683514010267n],[2203960485148121921418603742825762020974279258880205651966n,0n],[10190819375481120917420622822672549775783927716138318623895010788866272024264n,21584395482704209334823622290379665147239961968378104390343953940207365798982n],[2203960485148121921418603742825762020974279258880205651967n,0n],[18566938241244942414004596690298913868373833782006617400804628704885040364344n,16165975933942742336466353786298926857552937457188450663314217659523851788715n]]],n=[[[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n]],[[1n,0n],[21575463638280843010398324269430826099269044274347216827212613867836435027261n,10307601595873709700152284273816112264069230130616436755625194854815875713954n],[21888242871839275220042445260109153167277707414472061641714758635765020556616n,0n],[3772000881919853776433695186713858239009073593817195771773381919316419345261n,2236595495967245188281701248203181795121068902605861227855261137820944008926n],[2203960485148121921418603742825762020974279258880205651966n,0n],[18429021223477853657660792034369865839114504446431234726392080002137598044644n,9344045779998320333812420223237981029506012124075525679208581902008406485703n]],[[1n,0n],[2581911344467009335267311115468803099551665605076196740867805258568234346338n,19937756971775647987995932169929341994314640652964949448313374472400716661030n],[2203960485148121921418603742825762020974279258880205651966n,0n],[5324479202449903542726783395506214481928257762400643279780343368557297135718n,16208900380737693084919495127334387981393726419856888799917914180988844123039n],[21888242871839275220042445260109153167277707414472061641714758635765020556616n,0n],[13981852324922362344252311234282257507216387789820983642040889267519694726527n,7629828391165209371577384193250820201684255241773809077146787135900891633097n]]],l=t.addFunction(e+"__frobeniusMap"+a);l.addParam("x","i32"),l.addParam("r","i32");const c=l.getCodeBuilder();for(let e=0;e<6;e++){const o=0==e?c.getLocal("x"):c.i32_add(c.getLocal("x"),c.i32_const(e*r)),u=o,g=c.i32_add(c.getLocal("x"),c.i32_const(e*r+s)),f=0==e?c.getLocal("r"):c.i32_add(c.getLocal("r"),c.i32_const(e*r)),p=f,m=c.i32_add(c.getLocal("r"),c.i32_const(e*r+s)),L=d(i[Math.floor(e/3)][a%12],n[e%3][a%6]),w=t.alloc([...ul.bigInt2BytesLE(b(L[0]),32),...ul.bigInt2BytesLE(b(L[1]),32)]);a%2==1?l.addCode(c.call(_+"_copy",u,p),c.call(_+"_neg",g,m),c.call(h+"_mul",f,c.i32_const(w),f)):l.addCode(c.call(h+"_mul",o,c.i32_const(w),f))}function d(t,a){const e=BigInt(t[0]),i=BigInt(t[1]),n=BigInt(a[0]),l=BigInt(a[1]),c=[(e*n-i*l)%o,(e*l+i*n)%o];return Fl(c[0])&&(c[0]=c[0]+o),c}}function D(a,o){const i=function(t){let a=t;const e=[];for(;a>0n;){if(Cl(a)){const t=2-Number(a%4n);e.push(t),a-=BigInt(t)}else e.push(0);a>>=1n}return e}(a).map((t=>-1==t?255:t)),n=t.alloc(i),l=t.addFunction(e+"__cyclotomicExp_"+o);l.addParam("x","i32"),l.addParam("r","i32"),l.addLocal("bit","i32"),l.addLocal("i","i32");const c=l.getCodeBuilder(),s=c.getLocal("x"),r=c.getLocal("r"),u=c.i32_const(t.alloc(d));l.addCode(c.call(G+"_conjugate",s,u),c.call(G+"_one",r),c.if(c.teeLocal("bit",c.i32_load8_s(c.i32_const(i.length-1),n)),c.if(c.i32_eq(c.getLocal("bit"),c.i32_const(1)),c.call(G+"_mul",r,s,r),c.call(G+"_mul",r,u,r))),c.setLocal("i",c.i32_const(i.length-2)),c.block(c.loop(c.call(e+"__cyclotomicSquare",r,r),c.if(c.teeLocal("bit",c.i32_load8_s(c.getLocal("i"),n)),c.if(c.i32_eq(c.getLocal("bit"),c.i32_const(1)),c.call(G+"_mul",r,s,r),c.call(G+"_mul",r,u,r))),c.br_if(1,c.i32_eqz(c.getLocal("i"))),c.setLocal("i",c.i32_sub(c.getLocal("i"),c.i32_const(1))),c.br(0))))}function j(){!function(){const a=t.addFunction(e+"__cyclotomicSquare");a.addParam("x","i32"),a.addParam("r","i32");const o=a.getCodeBuilder(),i=o.getLocal("x"),n=o.i32_add(o.getLocal("x"),o.i32_const(r)),l=o.i32_add(o.getLocal("x"),o.i32_const(2*r)),c=o.i32_add(o.getLocal("x"),o.i32_const(3*r)),s=o.i32_add(o.getLocal("x"),o.i32_const(4*r)),d=o.i32_add(o.getLocal("x"),o.i32_const(5*r)),u=o.getLocal("r"),_=o.i32_add(o.getLocal("r"),o.i32_const(r)),g=o.i32_add(o.getLocal("r"),o.i32_const(2*r)),f=o.i32_add(o.getLocal("r"),o.i32_const(3*r)),p=o.i32_add(o.getLocal("r"),o.i32_const(4*r)),m=o.i32_add(o.getLocal("r"),o.i32_const(5*r)),L=o.i32_const(t.alloc(r)),b=o.i32_const(t.alloc(r)),w=o.i32_const(t.alloc(r)),y=o.i32_const(t.alloc(r)),A=o.i32_const(t.alloc(r)),C=o.i32_const(t.alloc(r)),F=o.i32_const(t.alloc(r)),x=o.i32_const(t.alloc(r));a.addCode(o.call(h+"_mul",i,s,F),o.call(h+"_mul",s,o.i32_const(v),L),o.call(h+"_add",i,L,L),o.call(h+"_add",i,s,x),o.call(h+"_mul",x,L,L),o.call(h+"_mul",o.i32_const(v),F,x),o.call(h+"_add",F,x,x),o.call(h+"_sub",L,x,L),o.call(h+"_add",F,F,b),o.call(h+"_mul",c,l,F),o.call(h+"_mul",l,o.i32_const(v),w),o.call(h+"_add",c,w,w),o.call(h+"_add",c,l,x),o.call(h+"_mul",x,w,w),o.call(h+"_mul",o.i32_const(v),F,x),o.call(h+"_add",F,x,x),o.call(h+"_sub",w,x,w),o.call(h+"_add",F,F,y),o.call(h+"_mul",n,d,F),o.call(h+"_mul",d,o.i32_const(v),A),o.call(h+"_add",n,A,A),o.call(h+"_add",n,d,x),o.call(h+"_mul",x,A,A),o.call(h+"_mul",o.i32_const(v),F,x),o.call(h+"_add",F,x,x),o.call(h+"_sub",A,x,A),o.call(h+"_add",F,F,C),o.call(h+"_sub",L,i,u),o.call(h+"_add",u,u,u),o.call(h+"_add",L,u,u),o.call(h+"_add",b,s,p),o.call(h+"_add",p,p,p),o.call(h+"_add",b,p,p),o.call(h+"_mul",C,o.i32_const(P),x),o.call(h+"_add",x,c,f),o.call(h+"_add",f,f,f),o.call(h+"_add",x,f,f),o.call(h+"_sub",A,l,g),o.call(h+"_add",g,g,g),o.call(h+"_add",A,g,g),o.call(h+"_sub",w,n,_),o.call(h+"_add",_,_,_),o.call(h+"_add",w,_,_),o.call(h+"_add",y,d,m),o.call(h+"_add",m,m,m),o.call(h+"_add",y,m,m))}(),D(N,"w0");const a=t.addFunction(e+"__finalExponentiationLastChunk");a.addParam("x","i32"),a.addParam("r","i32");const o=a.getCodeBuilder(),i=o.getLocal("x"),n=o.getLocal("r"),l=o.i32_const(t.alloc(d)),c=o.i32_const(t.alloc(d)),s=o.i32_const(t.alloc(d)),u=o.i32_const(t.alloc(d)),_=o.i32_const(t.alloc(d)),g=o.i32_const(t.alloc(d)),f=o.i32_const(t.alloc(d)),p=o.i32_const(t.alloc(d)),m=o.i32_const(t.alloc(d)),L=o.i32_const(t.alloc(d)),b=o.i32_const(t.alloc(d)),w=o.i32_const(t.alloc(d)),y=o.i32_const(t.alloc(d)),A=o.i32_const(t.alloc(d)),C=o.i32_const(t.alloc(d)),F=o.i32_const(t.alloc(d)),x=o.i32_const(t.alloc(d)),I=o.i32_const(t.alloc(d)),B=o.i32_const(t.alloc(d)),E=o.i32_const(t.alloc(d)),S=o.i32_const(t.alloc(d));a.addCode(o.call(e+"__cyclotomicExp_w0",i,l),o.call(G+"_conjugate",l,l),o.call(e+"__cyclotomicSquare",l,c),o.call(e+"__cyclotomicSquare",c,s),o.call(G+"_mul",s,c,u),o.call(e+"__cyclotomicExp_w0",u,_),o.call(G+"_conjugate",_,_),o.call(e+"__cyclotomicSquare",_,g),o.call(e+"__cyclotomicExp_w0",g,f),o.call(G+"_conjugate",f,f),o.call(G+"_conjugate",u,p),o.call(G+"_conjugate",f,m),o.call(G+"_mul",m,_,L),o.call(G+"_mul",L,p,b),o.call(G+"_mul",b,c,w),o.call(G+"_mul",b,_,y),o.call(G+"_mul",y,i,A),o.call(e+"__frobeniusMap1",w,C),o.call(G+"_mul",C,A,F),o.call(e+"__frobeniusMap2",b,x),o.call(G+"_mul",x,F,I),o.call(G+"_conjugate",i,B),o.call(G+"_mul",B,w,E),o.call(e+"__frobeniusMap3",E,S),o.call(G+"_mul",S,I,n))}const V=t.alloc(k),K=t.alloc(R);function H(a){const o=t.addFunction(e+"_pairingEq"+a);for(let t=0;t0n;)Tl(a)?e.push(1):e.push(0),a>>=1n;return e}(0xd201000000010000n),z=t.alloc(G),T=3*s,M=G.length-1,U=G.reduce(((t,a)=>t+(0!=a?1:0)),0),Q=6*l,k=3*l*2+(U+M+1)*T,R=15132376222941642752n;function N(a){const e=[[[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n]],[[1n,0n],[3850754370037169011952147076051364057158807420970682438676050522613628423219637725072182697113062777891589506424760n,151655185184498381465642749684540099398075398968325446656007613510403227271200139370504932015952886146304766135027n],[793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620351n,0n],[2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530n,1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257n],[793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350n,0n],[3125332594171059424908108096204648978570118281977575435832422631601824034463382777937621250592425535493320683825557n,877076961050607968509681729531255177986764537961432449499635504522207616027455086505066378536590128544573588734230n],[4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559786n,0n],[151655185184498381465642749684540099398075398968325446656007613510403227271200139370504932015952886146304766135027n,3850754370037169011952147076051364057158807420970682438676050522613628423219637725072182697113062777891589506424760n],[4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436n,0n],[1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257n,2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530n],[4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437n,0n],[877076961050607968509681729531255177986764537961432449499635504522207616027455086505066378536590128544573588734230n,3125332594171059424908108096204648978570118281977575435832422631601824034463382777937621250592425535493320683825557n]]],i=[[[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n]],[[1n,0n],[0n,4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436n],[793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350n,0n],[0n,1n],[4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436n,0n],[0n,793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350n]],[[1n,0n],[4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437n,0n],[4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436n,0n],[4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559786n,0n],[793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350n,0n],[793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620351n,0n]]],n=t.addFunction(O+"_frobeniusMap"+a);n.addParam("x","i32"),n.addParam("r","i32");const r=n.getCodeBuilder();for(let o=0;o<6;o++){const u=0==o?r.getLocal("x"):r.i32_add(r.getLocal("x"),r.i32_const(o*s)),_=u,g=r.i32_add(r.getLocal("x"),r.i32_const(o*s+c)),h=0==o?r.getLocal("r"):r.i32_add(r.getLocal("r"),r.i32_const(o*s)),p=h,L=r.i32_add(r.getLocal("r"),r.i32_const(o*s+c)),b=d(e[Math.floor(o/3)][a%12],i[o%3][a%6]),w=t.alloc([...xl.bigInt2BytesLE(y(b[0]),l),...xl.bigInt2BytesLE(y(b[1]),l)]);a%2==1?n.addCode(r.call(f+"_copy",_,p),r.call(f+"_neg",g,L),r.call(m+"_mul",h,r.i32_const(w),h)):n.addCode(r.call(m+"_mul",u,r.i32_const(w),h))}function d(t,a){const e=t[0],i=t[1],n=a[0],l=a[1],c=[(e*n-i*l)%o,(e*l+i*n)%o];return Ml(c[0])&&(c[0]=c[0]+o),c}}function $(a,o,i){const n=function(t){let a=t;const e=[];for(;a>0n;){if(Tl(a)){const t=2-Number(a%4n);e.push(t),a-=BigInt(t)}else e.push(0);a>>=1n}return e}(a).map((t=>-1==t?255:t)),l=t.alloc(n),c=t.addFunction(e+"__cyclotomicExp_"+i);c.addParam("x","i32"),c.addParam("r","i32"),c.addLocal("bit","i32"),c.addLocal("i","i32");const s=c.getCodeBuilder(),d=s.getLocal("x"),u=s.getLocal("r"),_=s.i32_const(t.alloc(r));c.addCode(s.call(O+"_conjugate",d,_),s.call(O+"_one",u),s.if(s.teeLocal("bit",s.i32_load8_s(s.i32_const(n.length-1),l)),s.if(s.i32_eq(s.getLocal("bit"),s.i32_const(1)),s.call(O+"_mul",u,d,u),s.call(O+"_mul",u,_,u))),s.setLocal("i",s.i32_const(n.length-2)),s.block(s.loop(s.call(e+"__cyclotomicSquare",u,u),s.if(s.teeLocal("bit",s.i32_load8_s(s.getLocal("i"),l)),s.if(s.i32_eq(s.getLocal("bit"),s.i32_const(1)),s.call(O+"_mul",u,d,u),s.call(O+"_mul",u,_,u))),s.br_if(1,s.i32_eqz(s.getLocal("i"))),s.setLocal("i",s.i32_sub(s.getLocal("i"),s.i32_const(1))),s.br(0)))),o&&c.addCode(s.call(O+"_conjugate",u,u))}t.modules[e]={n64q:n,n64r:d,n8q:l,n8r:u,pG1gen:C,pG1zero:x,pG1b:h,pG2gen:B,pG2zero:v,pG2b:L,pq:t.modules.f1m.pq,pr:g,pOneT:S,r:i,q:o,prePSize:Q,preQSize:k},function(){const a=t.addFunction(q+"_mul1");a.addParam("pA","i32"),a.addParam("pC1","i32"),a.addParam("pR","i32");const e=a.getCodeBuilder(),o=e.getLocal("pA"),i=e.i32_add(e.getLocal("pA"),e.i32_const(2*c)),n=e.i32_add(e.getLocal("pA"),e.i32_const(4*c)),l=e.getLocal("pC1"),s=e.getLocal("pR"),r=e.i32_add(e.getLocal("pR"),e.i32_const(2*c)),d=e.i32_add(e.getLocal("pR"),e.i32_const(4*c)),u=e.i32_const(t.alloc(2*c)),_=e.i32_const(t.alloc(2*c));a.addCode(e.call(m+"_add",o,i,u),e.call(m+"_add",i,n,_),e.call(m+"_mul",i,l,d),e.call(m+"_mul",_,l,s),e.call(m+"_sub",s,d,s),e.call(m+"_mulNR",s,s),e.call(m+"_mul",u,l,r),e.call(m+"_sub",r,d,r))}(),function(){const a=t.addFunction(q+"_mul01");a.addParam("pA","i32"),a.addParam("pC0","i32"),a.addParam("pC1","i32"),a.addParam("pR","i32");const e=a.getCodeBuilder(),o=e.getLocal("pA"),i=e.i32_add(e.getLocal("pA"),e.i32_const(2*c)),n=e.i32_add(e.getLocal("pA"),e.i32_const(4*c)),l=e.getLocal("pC0"),s=e.getLocal("pC1"),r=e.getLocal("pR"),d=e.i32_add(e.getLocal("pR"),e.i32_const(2*c)),u=e.i32_add(e.getLocal("pR"),e.i32_const(4*c)),_=e.i32_const(t.alloc(2*c)),g=e.i32_const(t.alloc(2*c)),f=e.i32_const(t.alloc(2*c)),h=e.i32_const(t.alloc(2*c));a.addCode(e.call(m+"_mul",o,l,_),e.call(m+"_mul",i,s,g),e.call(m+"_add",o,i,f),e.call(m+"_add",o,n,h),e.call(m+"_add",i,n,r),e.call(m+"_mul",r,s,r),e.call(m+"_sub",r,g,r),e.call(m+"_mulNR",r,r),e.call(m+"_add",r,_,r),e.call(m+"_add",l,s,d),e.call(m+"_mul",d,f,d),e.call(m+"_sub",d,_,d),e.call(m+"_sub",d,g,d),e.call(m+"_mul",h,l,u),e.call(m+"_sub",u,_,u),e.call(m+"_add",u,g,u))}(),function(){const a=t.addFunction(O+"_mul014");a.addParam("pA","i32"),a.addParam("pC0","i32"),a.addParam("pC1","i32"),a.addParam("pC4","i32"),a.addParam("pR","i32");const e=a.getCodeBuilder(),o=e.getLocal("pA"),i=e.i32_add(e.getLocal("pA"),e.i32_const(6*c)),n=e.getLocal("pC0"),l=e.getLocal("pC1"),s=e.getLocal("pC4"),r=e.i32_const(t.alloc(6*c)),d=e.i32_const(t.alloc(6*c)),u=e.i32_const(t.alloc(2*c)),_=e.getLocal("pR"),g=e.i32_add(e.getLocal("pR"),e.i32_const(6*c));a.addCode(e.call(q+"_mul01",o,n,l,r),e.call(q+"_mul1",i,s,d),e.call(m+"_add",l,s,u),e.call(q+"_add",i,o,g),e.call(q+"_mul01",g,n,u,g),e.call(q+"_sub",g,r,g),e.call(q+"_sub",g,d,g),e.call(q+"_copy",d,_),e.call(q+"_mulNR",_,_),e.call(q+"_add",_,r,_))}(),function(){const a=t.addFunction(e+"_ell");a.addParam("pP","i32"),a.addParam("pCoefs","i32"),a.addParam("pF","i32");const o=a.getCodeBuilder(),i=o.getLocal("pP"),n=o.i32_add(o.getLocal("pP"),o.i32_const(l)),s=o.getLocal("pF"),r=o.getLocal("pCoefs"),d=o.i32_add(o.getLocal("pCoefs"),o.i32_const(c)),u=o.i32_add(o.getLocal("pCoefs"),o.i32_const(2*c)),_=o.i32_add(o.getLocal("pCoefs"),o.i32_const(3*c)),g=o.i32_add(o.getLocal("pCoefs"),o.i32_const(4*c)),h=t.alloc(2*c),p=o.i32_const(h),m=o.i32_const(h),L=o.i32_const(h+c),b=t.alloc(2*c),w=o.i32_const(b),y=o.i32_const(b),A=o.i32_const(b+c);a.addCode(o.call(f+"_mul",r,n,m),o.call(f+"_mul",d,n,L),o.call(f+"_mul",u,i,y),o.call(f+"_mul",_,i,A),o.call(O+"_mul014",s,g,w,p,s))}();const D=t.alloc(Q),j=t.alloc(k);function V(a){const o=t.addFunction(e+"_pairingEq"+a);for(let t=0;t>8n&0xFFn)),a.push(Number(e>>16n&0xFFn)),a.push(Number(e>>24n&0xFFn)),a}function Vl(t){const a=function(t){for(var a=[],e=0;e>6,128|63&o):o<55296||o>=57344?a.push(224|o>>12,128|o>>6&63,128|63&o):(e++,o=65536+((1023&o)<<10|1023&t.charCodeAt(e)),a.push(240|o>>18,128|o>>12&63,128|o>>6&63,128|63&o))}return a}(t);return[...Yl(a.length),...a]}function Kl(t){const a=[];let e=Nl(t);if($l(e))throw new Error("Number cannot be negative");for(;!Dl(e);)a.push(Number(0x7Fn&e)),e>>=7n;0==a.length&&a.push(0);for(let t=0;t0xFFFFFFFFn)throw new Error("Number too big");if(a>0x7FFFFFFFn&&(a-=0x100000000n),a<-2147483648n)throw new Error("Number too small");return Hl(a)}function Wl(t){let a=Nl(t);if(a>0xFFFFFFFFFFFFFFFFn)throw new Error("Number too big");if(a>0x7FFFFFFFFFFFFFFFn&&(a-=0x10000000000000000n),a<-9223372036854775808n)throw new Error("Number too small");return Hl(a)}function Yl(t){let a=Nl(t);if(a>0xFFFFFFFFn)throw new Error("Number too big");return Kl(a)}function Jl(t){return Array.from(t,(function(t){return("0"+(255&t).toString(16)).slice(-2)})).join("")}!function(t){globalThis.btoa(t)}("("+function(t){const a=32767;let e,o;async function i(t){const i=new Uint8Array(t.code),n=await WebAssembly.compile(i);o=new WebAssembly.Memory({initial:t.init,maximum:a}),e=await WebAssembly.instantiate(n,{env:{memory:o}})}function n(t){const e=new Uint32Array(o.buffer,0,1);for(;3&e[0];)e[0]++;const i=e[0];if(e[0]+=t,e[0]+t>o.buffer.byteLength){const i=o.buffer.byteLength/65536;let n=Math.floor((e[0]+t)/65536)+1;n>a&&(n=a),o.grow(n-i)}return i}function l(t){const a=n(t.byteLength);return s(a,t),a}function c(t,a){const e=new Uint8Array(o.buffer);return new Uint8Array(e.buffer,e.byteOffset+t,a)}function s(t,a){new Uint8Array(o.buffer).set(new Uint8Array(a),t)}function r(t){if("INIT"==t[0].cmd)return i(t[0]);const a={vars:[],out:[]},r=new Uint32Array(o.buffer,0,1)[0];for(let o=0;otc[t.type]))],...this.returnType?[1,tc[this.returnType]]:[0]]}getBody(){const t=this.locals.map((t=>[...Yl(t.length),tc[t.type]])),a=[...Yl(this.locals.length),...[].concat(...t),...this.code,11];return[...Yl(a.length),...a]}addCode(...t){this.code.push(...[].concat(...t))}getCodeBuilder(){return new Xl(this)}}class ec{constructor(){this.functions=[],this.functionIdxByName={},this.nImportFunctions=0,this.nInternalFunctions=0,this.memory={pagesSize:1,moduleName:"env",fieldName:"memory"},this.free=8,this.datas=[],this.modules={},this.exports=[],this.functionsTable=[]}build(){return this._setSignatures(),new Uint8Array([...jl(1836278016),...jl(1),...this._buildType(),...this._buildImport(),...this._buildFunctionDeclarations(),...this._buildFunctionsTable(),...this._buildExports(),...this._buildElements(),...this._buildCode(),...this._buildData()])}addFunction(t){if(void 0!==this.functionIdxByName[t])throw new Error(`Function already defined: ${t}`);const a=this.functions.length;return this.functionIdxByName[t]=a,this.functions.push(new ac(this,t,"internal")),this.nInternalFunctions++,this.functions[a]}addIimportFunction(t,a,e){if(void 0!==this.functionIdxByName[t])throw new Error(`Function already defined: ${t}`);if(this.functions.length>0&&"internal"==this.functions[this.functions.length-1].type)throw new Error(`Import functions must be declared before internal: ${t}`);let o=e||t;const i=this.functions.length;return this.functionIdxByName[t]=i,this.functions.push(new ac(this,t,"import",a,o)),this.nImportFunctions++,this.functions[i]}setMemory(t,a,e){this.memory={pagesSize:t,moduleName:a||"env",fieldName:e||"memory"}}exportFunction(t,a){const e=a||t;if(void 0===this.functionIdxByName[t])throw new Error(`Function not defined: ${t}`);const o=this.functionIdxByName[t];e!=t&&(this.functionIdxByName[e]=o),this.exports.push({exportName:e,idx:o})}addFunctionToTable(t){const a=this.functionIdxByName[t];this.functionsTable.push(a)}addData(t,a){this.datas.push({offset:t,bytes:a})}alloc(t,a){let e,o;(Array.isArray(t)||ArrayBuffer.isView(t))&&void 0===a?(e=t.length,o=t):(e=t,o=a),e=1+(e-1>>3)<<3;const i=this.free;return this.free+=e,o&&this.addData(i,o),i}allocString(t){const a=(new globalThis.TextEncoder).encode(t);return this.alloc([...a,0])}_setSignatures(){this.signatures=[];const t={};if(this.functionsTable.length>0){const a=this.functions[this.functionsTable[0]].getSignature();t["s_"+Jl(a)]=0,this.signatures.push(a)}for(let a=0;a=2&&(d>=1||u>=7)){""!==s&&(s+=" ");const t=oc.fromArray(a,4294967296).toString();s+=t}else console.log(oc.fromArray(a,4294967296))},error:function(t,e,o,i,n,c){let s;throw s=7==t?h(e)+" "+l.getFr(i).toString()+" != "+l.getFr(n).toString()+" "+h(c):9==t?h(e)+" "+l.getFr(i).toString()+" "+h(n):5==t&&a.sym?h(e)+" "+a.sym.labelIdx2Name[n]:h(e)+" "+o+" "+i+" "+n+" "+c,console.log("ERROR: ",t,s),new Error(s)},log:function(t){console.log(l.getFr(t).toString())},logGetSignal:function(t,e){a.logGetSignal&&a.logGetSignal(t,l.getFr(e))},logSetSignal:function(t,e){a.logSetSignal&&a.logSetSignal(t,l.getFr(e))},logStartComponent:function(t){a.logStartComponent&&a.logStartComponent(t)},logFinishComponent:function(t){a.logFinishComponent&&a.logFinishComponent(t)}}});"function"==typeof _.exports.getVersion&&(r=_.exports.getVersion()),"function"==typeof _.exports.getMinorVersion&&(d=_.exports.getMinorVersion()),"function"==typeof _.exports.getPatchVersion&&(u=_.exports.getPatchVersion());const g=a&&(a.sanityCheck||a.logGetSignal||a.logSetSignal||a.logStartComponent||a.logFinishComponent);return l=2===r?new lc(_,g):new nc(e,_,g),l;function f(){for(var t="",a=_.exports.getMessageChar();0!=a;)t+=String.fromCharCode(a),a=_.exports.getMessageChar();return t}function h(t){const a=new Uint8Array(e.buffer),o=[];for(let e=0;a[t+e]>0;e++)o.push(a[t+e]);return String.fromCharCode.apply(null,o)}}class nc{constructor(t,a,e){this.memory=t,this.i32=new Uint32Array(t.buffer),this.instance=a,this.n32=(this.instance.exports.getFrLen()>>2)-2;const o=this.instance.exports.getPRawPrime(),i=new Array(this.n32);for(let t=0;t>2)+t];this.prime=oc.fromArray(i,4294967296),this.Fr=new dn(this.prime),this.mask32=oc.fromString("FFFFFFFF",16),this.NVars=this.instance.exports.getNVars(),this.n64=Math.floor((this.Fr.bitLength-1)/64)+1,this.R=this.Fr.e(oc.shiftLeft(1,64*this.n64)),this.RInv=this.Fr.inv(this.R),this.sanityCheck=e}circom_version(){return 1}async _doCalculateWitness(t,a){this.instance.exports.init(this.sanityCheck||a?1:0);const e=this.allocInt(),o=this.allocFr();Object.keys(t).forEach((a=>{const i=Si(a),n=parseInt(i.slice(0,8),16),l=parseInt(i.slice(8,16),16);try{this.instance.exports.getSignalOffset32(e,0,n,l)}catch(t){throw new Error(`Signal ${a} is not an input of the circuit.`)}const c=this.getInt(e),s=vi(t[a]);for(let t=0;t>2]}setInt(t,a){this.i32[t>>2]=a}getFr(t){const a=this,e=t>>2;if(2147483648&a.i32[e+1]){const t=new Array(a.n32);for(let o=0;o>2]=i,void(e.i32[1+(t>>2)]=0)}e.i32[t>>2]=0,e.i32[1+(t>>2)]=2147483648;const n=oc.toArray(a,4294967296);for(let a=0;a>2)+a]=o>=0?n[o]:0}}}class lc{constructor(t,a){this.instance=t,this.version=this.instance.exports.getVersion(),this.n32=this.instance.exports.getFieldNumLen32(),this.instance.exports.getRawPrime();const e=new Array(this.n32);for(let t=0;t{const e=Si(a),i=parseInt(e.slice(0,8),16),n=parseInt(e.slice(8,16),16),l=vi(t[a]);for(let t=0;t1)throw new Error(t.fileName+": File has more than one header");t.pos=a[1][0].p;const e=await t.readULE32(),o=await t.read(e),i=_e.fromRprLE(o),n=await Ye(i);if(8*n.F1.n64!=e)throw new Error(t.fileName+": Invalid size");const l=await t.readULE32(),c=await t.readULE32();if(t.pos-a[1][0].p!=a[1][0].size)throw new Error("Invalid PTau header size");return{curve:n,power:l,ceremonyPower:c}}function Cc(t,a,e,o){const i={tau:{},alpha:{},beta:{}};return i.tau.g1_s=n(),i.tau.g1_sx=n(),i.alpha.g1_s=n(),i.alpha.g1_sx=n(),i.beta.g1_s=n(),i.beta.g1_sx=n(),i.tau.g2_spx=l(),i.alpha.g2_spx=l(),i.beta.g2_spx=l(),i;function n(){let i;return i=o?e.G1.fromRprLEM(t,a):e.G1.fromRprUncompressed(t,a),a+=2*e.G1.F.n8,i}function l(){let i;return i=o?e.G2.fromRprLEM(t,a):e.G2.fromRprUncompressed(t,a),a+=2*e.G2.F.n8,i}}function Fc(t,a,e,o,i){async function n(o){i?e.G1.toRprLEM(t,a,o):e.G1.toRprUncompressed(t,a,o),a+=2*e.F1.n8}async function l(o){i?e.G2.toRprLEM(t,a,o):e.G2.toRprUncompressed(t,a,o),a+=2*e.F2.n8}return n(o.tau.g1_s),n(o.tau.g1_sx),n(o.alpha.g1_s),n(o.alpha.g1_sx),n(o.beta.g1_s),n(o.beta.g1_sx),l(o.tau.g2_spx),l(o.alpha.g2_spx),l(o.beta.g2_spx),t}async function xc(t,a){const e={};e.tauG1=await s(),e.tauG2=await r(),e.alphaG1=await s(),e.betaG1=await s(),e.betaG2=await r(),e.key=await async function(t,a,e){return Cc(await t.read(2*a.F1.n8*6+2*a.F2.n8*3),0,a,e)}(t,a,!0),e.partialHash=await t.read(216),e.nextChallenge=await t.read(64),e.type=await t.readULE32();const o=new Uint8Array(2*a.G1.F.n8*6+2*a.G2.F.n8*3);Fc(o,0,a,e.key,!1);const i=to.exports(64);i.setPartialHash(e.partialHash),i.update(o),e.responseHash=i.digest();const n=await t.readULE32(),l=t.pos;let c=0;for(;t.pos-l1)throw new Error(t.fileName+": File has more than one contributions section");t.pos=e[7][0].p;const o=await t.readULE32(),i=[];for(let e=0;e0){const a=new Uint8Array(n);await t.writeULE32(a.byteLength),await t.write(a)}else await t.writeULE32(0);async function l(e){a.G1.toRprLEM(o,0,e),await t.write(o)}async function c(e){a.G2.toRprLEM(i,0,e),await t.write(i)}}async function Ec(t,a,e){await t.writeULE32(7);const o=t.pos;await t.writeULE64(0),await t.writeULE32(e.length);for(let o=0;o0?u[u.length-1].nextChallenge:vc(r,d,n);const b=await Me(e,"ptau",1,i?7:2);await yc(b,r,d);const w=await m.read(64);if(Uo(l,L)&&(L=w,u[u.length-1].nextChallenge=L),!Uo(w,L))throw new Error("Wrong contribution. this contribution is not based on the previus hash");const y=new to.exports(64);y.update(w);const A=[];let C;C=await I(m,b,"G1",2,2**d*2-1,[1],"tauG1"),_.tauG1=C[0],C=await I(m,b,"G2",3,2**d,[1],"tauG2"),_.tauG2=C[0],C=await I(m,b,"G1",4,2**d,[0],"alphaG1"),_.alphaG1=C[0],C=await I(m,b,"G1",5,2**d,[0],"betaG1"),_.betaG1=C[0],C=await I(m,b,"G2",6,1,[0],"betaG2"),_.betaG2=C[0],_.partialHash=y.getPartialHash();const F=await m.read(2*r.F1.n8*6+2*r.F2.n8*3);_.key=Cc(F,0,r,!1),y.update(new Uint8Array(F));const x=y.digest();if(n&&n.info(Mo(x,"Contribution Response Hash imported: ")),i){const t=new to.exports(64);t.update(x),await B(t,b,"G1",2,2**d*2-1,"tauG1",n),await B(t,b,"G2",3,2**d,"tauG2",n),await B(t,b,"G1",4,2**d,"alphaTauG1",n),await B(t,b,"G1",5,2**d,"betaTauG1",n),await B(t,b,"G2",6,1,"betaG2",n),_.nextChallenge=t.digest(),n&&n.info(Mo(_.nextChallenge,"Next Challenge Hash: "))}else _.nextChallenge=l;return u.push(_),await Ec(b,r,u),await m.close(),await b.close(),await c.close(),_.nextChallenge;async function I(t,a,e,o,l,c,s){return i?await async function(t,a,e,o,i,l,c){const s=r[e],d=s.F.n8,u=2*s.F.n8,_=[];await Ue(a,o);const g=Math.floor((1<<24)/u);A[o]=a.pos;for(let e=0;e=e&&a=a&&i1?s[s.length-2]:r;const u=s[s.length-1];if(a&&a.debug("Validating contribution #"+s[s.length-1].id),!await qc(n,u,d,a))return!1;const _=to.exports(64);_.update(u.responseHash),a&&a.debug("Verifying powers in tau*G1 section");const g=await w(2,"G1","tauG1",2**l*2-1,[0,1],a);if(e=await Pc(n,g.R1,g.R2,n.G2.g,u.tauG2),!0!==e)return a&&a.error("tauG1 section. Powers do not match"),!1;if(!n.G1.eq(n.G1.g,g.singularPoints[0]))return a&&a.error("First element of tau*G1 section must be the generator"),!1;if(!n.G1.eq(u.tauG1,g.singularPoints[1]))return a&&a.error("Second element of tau*G1 section does not match the one in the contribution section"),!1;a&&a.debug("Verifying powers in tau*G2 section");const f=await w(3,"G2","tauG2",2**l,[0,1],a);if(e=await Pc(n,n.G1.g,u.tauG1,f.R1,f.R2),!0!==e)return a&&a.error("tauG2 section. Powers do not match"),!1;if(!n.G2.eq(n.G2.g,f.singularPoints[0]))return a&&a.error("First element of tau*G2 section must be the generator"),!1;if(!n.G2.eq(u.tauG2,f.singularPoints[1]))return a&&a.error("Second element of tau*G2 section does not match the one in the contribution section"),!1;a&&a.debug("Verifying powers in alpha*tau*G1 section");const h=await w(4,"G1","alphatauG1",2**l,[0],a);if(e=await Pc(n,h.R1,h.R2,n.G2.g,u.tauG2),!0!==e)return a&&a.error("alphaTauG1 section. Powers do not match"),!1;if(!n.G1.eq(u.alphaG1,h.singularPoints[0]))return a&&a.error("First element of alpha*tau*G1 section (alpha*G1) does not match the one in the contribution section"),!1;a&&a.debug("Verifying powers in beta*tau*G1 section");const p=await w(5,"G1","betatauG1",2**l,[0],a);if(e=await Pc(n,p.R1,p.R2,n.G2.g,u.tauG2),!0!==e)return a&&a.error("betaTauG1 section. Powers do not match"),!1;if(!n.G1.eq(u.betaG1,p.singularPoints[0]))return a&&a.error("First element of beta*tau*G1 section (beta*G1) does not match the one in the contribution section"),!1;const m=await async function(t){const a=n.G2,e=2*a.F.n8,l=new Uint8Array(e);if(!i[6])throw t.error("File has no BetaG2 section"),new Error("File has no BetaG2 section");if(i[6].length>1)throw t.error("File has no BetaG2 section"),new Error("File has more than one GetaG2 section");o.pos=i[6][0].p;const c=await o.read(e),s=a.fromRprLEM(c);return a.toRprUncompressed(l,0,s),_.update(l),s}(a);if(!n.G2.eq(u.betaG2,m))return a&&a.error("betaG2 element in betaG2 section does not match the one in the contribution section"),!1;const L=_.digest();if(l==c&&!Uo(L,u.nextChallenge))return a&&a.error("Hash of the values does not match the next challenge of the last contributor in the contributions section"),!1;a&&a.info(Mo(L,"Next challenge hash: ")),b(u,d);for(let t=s.length-2;t>=0;t--){const e=s[t],o=t>0?s[t-1]:r;if(!await qc(n,e,o,a))return!1;b(e,o)}if(a&&a.info("-----------------------------------------------------"),i[12]&&i[13]&&i[14]&&i[15]){let t;if(t=await y("G1",2,12,"tauG1",a),!t)return!1;if(t=await y("G2",3,13,"tauG2",a),!t)return!1;if(t=await y("G1",4,14,"alphaTauG1",a),!t)return!1;if(t=await y("G1",5,15,"betaTauG1",a),!t)return!1}else a&&a.warn('this file does not contain phase2 precalculated values. Please run: \n snarkjs "powersoftau preparephase2" to prepare this file to be used in the phase2 ceremony.');return await o.close(),a&&a.info("Powers of Tau Ok!"),!0;function b(t,e){if(!a)return;a.info("-----------------------------------------------------"),a.info(`Contribution #${t.id}: ${t.name||""}`),a.info(Mo(t.nextChallenge,"Next Challenge: "));const o=new Uint8Array(2*n.G1.F.n8*6+2*n.G2.F.n8*3);Fc(o,0,n,t.key,!1);const i=to.exports(64);i.setPartialHash(t.partialHash),i.update(o);const l=i.digest();a.info(Mo(l,"Response Hash:")),a.info(Mo(e.nextChallenge,"Response Hash:")),1==t.type&&(a.info(`Beacon generator: ${Ko(t.beaconHash)}`),a.info(`Beacon iterations Exp: ${t.numIterationsExp}`))}async function w(t,a,e,l,c,s){const r=n[a],d=2*r.F.n8;await ke(o,i,t);const u=[];let g=r.zero,f=r.zero,h=r.zero;for(let t=0;t0){const t=r.fromRprLEM(i,0),a=$o(Ro(4),0);g=r.add(g,r.timesScalar(h,a)),f=r.add(f,r.timesScalar(t,a))}const m=await r.multiExpAffine(i.slice(0,(a-1)*d),p),L=await r.multiExpAffine(i.slice(d),p);g=r.add(g,m),f=r.add(f,L),h=r.fromRprLEM(i,(a-1)*d);for(let e=0;e=t&&o1;)r/=2,d+=1;if(2**d!=s)throw new Error("Invalid file size");i&&i.debug("Power to tau size: "+d);const u=await Do(o),_=await Ge(e),g=to.exports(64);for(let t=0;t{i.debug(a+".g1_s: "+t.G1.toString(p[a].g1_s,16)),i.debug(a+".g1_sx: "+t.G1.toString(p[a].g1_sx,16)),i.debug(a+".g2_sp: "+t.G2.toString(p[a].g2_sp,16)),i.debug(a+".g2_spx: "+t.G2.toString(p[a].g2_spx,16)),i.debug("")}));const m=to.exports(64);await _.write(h),m.update(h),await Gc(n,_,m,t,"G1",2**d*2-1,t.Fr.one,p.tau.prvKey,"COMPRESSED","tauG1",i),await Gc(n,_,m,t,"G2",2**d,t.Fr.one,p.tau.prvKey,"COMPRESSED","tauG2",i),await Gc(n,_,m,t,"G1",2**d,p.alpha.prvKey,p.tau.prvKey,"COMPRESSED","alphaTauG1",i),await Gc(n,_,m,t,"G1",2**d,p.beta.prvKey,p.tau.prvKey,"COMPRESSED","betaTauG1",i),await Gc(n,_,m,t,"G2",1,p.beta.prvKey,p.tau.prvKey,"COMPRESSED","betaTauG2",i);const L=new Uint8Array(2*t.F1.n8*6+2*t.F2.n8*3);Fc(L,0,t,p,!1),await _.write(L),m.update(L);const b=m.digest();i&&i.info(Mo(b,"Contribution Response Hash: ")),await _.close(),await n.close()},beacon:async function(t,a,e,o,i,n){const l=Vo(o);if(0==l.byteLength||2*l.byteLength!=o.length)return n&&n.error("Invalid Beacon Hash. (It must be a valid hexadecimal sequence)"),!1;if(l.length>=256)return n&&n.error("Maximum lenght of beacon hash is 255 bytes"),!1;if((i=parseInt(i))<10||i>63)return n&&n.error("Invalid numIterationsExp. (Must be between 10 and 63)"),!1;await to.exports.ready();const{fd:c,sections:s}=await Te(t,"ptau",1),{curve:r,power:d,ceremonyPower:u}=await Ac(c,s);if(d!=u)return n&&n.error("This file has been reduced. You cannot contribute into a reduced file."),!1;s[12]&&n&&n.warn("Contributing into a file that has phase2 calculated. You will have to prepare phase2 again.");const _=await Ic(c,r,s),g={name:e,type:1,numIterationsExp:i,beaconHash:l};let f;f=_.length>0?_[_.length-1].nextChallenge:vc(r,d,n),g.key=await Sc(r,f,l,i);const h=new to.exports(64);h.update(f);const p=await Me(a,"ptau",1,7);await yc(p,r,d);const m=[];let L;L=await A(2,"G1",2**d*2-1,r.Fr.e(1),g.key.tau.prvKey,"tauG1",n),g.tauG1=L[1],L=await A(3,"G2",2**d,r.Fr.e(1),g.key.tau.prvKey,"tauG2",n),g.tauG2=L[1],L=await A(4,"G1",2**d,g.key.alpha.prvKey,g.key.tau.prvKey,"alphaTauG1",n),g.alphaG1=L[0],L=await A(5,"G1",2**d,g.key.beta.prvKey,g.key.tau.prvKey,"betaTauG1",n),g.betaG1=L[0],L=await A(6,"G2",1,g.key.beta.prvKey,g.key.tau.prvKey,"betaTauG2",n),g.betaG2=L[0],g.partialHash=h.getPartialHash();const b=new Uint8Array(2*r.F1.n8*6+2*r.F2.n8*3);Fc(b,0,r,g.key,!1),h.update(new Uint8Array(b));const w=h.digest();n&&n.info(Mo(w,"Contribution Response Hash imported: "));const y=new to.exports(64);return y.update(w),await C(p,"G1",2,2**d*2-1,"tauG1",n),await C(p,"G2",3,2**d,"tauG2",n),await C(p,"G1",4,2**d,"alphaTauG1",n),await C(p,"G1",5,2**d,"betaTauG1",n),await C(p,"G2",6,1,"betaG2",n),g.nextChallenge=y.digest(),n&&n.info(Mo(g.nextChallenge,"Next Challenge Hash: ")),_.push(g),await Ec(p,r,_),await c.close(),await p.close(),w;async function A(t,a,e,o,i,n,l){const d=[];c.pos=s[t][0].p,await Ue(p,t),m[t]=p.pos;const u=r[a],_=2*u.F.n8,g=Math.floor((1<<20)/_);let f=o;for(let t=0;t0?d[d.length-1].nextChallenge:vc(c,s,i),u.key=wc(c,_,g);const f=new to.exports(64);f.update(_);const h=await Me(a,"ptau",1,7);await yc(h,c,s);const p=[];let m;m=await y(2,"G1",2**s*2-1,c.Fr.e(1),u.key.tau.prvKey,"tauG1"),u.tauG1=m[1],m=await y(3,"G2",2**s,c.Fr.e(1),u.key.tau.prvKey,"tauG2"),u.tauG2=m[1],m=await y(4,"G1",2**s,u.key.alpha.prvKey,u.key.tau.prvKey,"alphaTauG1"),u.alphaG1=m[0],m=await y(5,"G1",2**s,u.key.beta.prvKey,u.key.tau.prvKey,"betaTauG1"),u.betaG1=m[0],m=await y(6,"G2",1,u.key.beta.prvKey,u.key.tau.prvKey,"betaTauG2"),u.betaG2=m[0],u.partialHash=f.getPartialHash();const L=new Uint8Array(2*c.F1.n8*6+2*c.F2.n8*3);Fc(L,0,c,u.key,!1),f.update(new Uint8Array(L));const b=f.digest();i&&i.info(Mo(b,"Contribution Response Hash imported: "));const w=new to.exports(64);return w.update(b),await A(h,"G1",2,2**s*2-1,"tauG1"),await A(h,"G2",3,2**s,"tauG2"),await A(h,"G1",4,2**s,"alphaTauG1"),await A(h,"G1",5,2**s,"betaTauG1"),await A(h,"G2",6,1,"betaG2"),u.nextChallenge=w.digest(),i&&i.info(Mo(u.nextChallenge,"Next Challenge Hash: ")),d.push(u),await Ec(h,c,d),await n.close(),await h.close(),b;async function y(t,a,e,o,s,r){const d=[];n.pos=l[t][0].p,await Ue(h,t),p[t]=h.pos;const u=c[a],_=2*u.F.n8,g=Math.floor((1<<20)/_);let m=o;for(let t=0;t>BigInt(a)}function Nc(t){return(BigInt(t)&BigInt(1))==BigInt(1)}function $c(t){if(t>BigInt(Number.MAX_SAFE_INTEGER))throw new Error("Number too big");return Number(t)}function Dc(t,a){return BigInt(t)+BigInt(a)}function jc(t,a){return BigInt(t)-BigInt(a)}function Vc(t,a){return BigInt(t)**BigInt(a)}function Kc(t,a){return BigInt(t)/BigInt(a)}function Hc(t,a){return BigInt(t)%BigInt(a)}function Zc(t,a){return BigInt(t)==BigInt(a)}function Wc(t,a){return BigInt(t)>BigInt(a)}function Yc(t,a){return BigInt(t)&BigInt(a)}function Jc(t,a,e,o){const i="0000000"+e.toString(16),n=new Uint32Array(t.buffer,t.byteOffset+a,o/4),l=1+(4*(i.length-7)-1>>5);for(let t=0;ti[i.length-a-1]=t.toString(16).padStart(8,"0"))),Mc(i.join(""),16)}function ts(t,a){return t.toString(a)}function as(t){const a=new Uint8Array(Math.floor((Qc(t)-1)/8)+1);return Jc(a,0,t,a.byteLength),a}const es=Uc(0),os=Uc(1);function is(t,a,e){if(!e)return t.one;const o=function(t){let a=BigInt(t);const e=[];for(;a;)a&BigInt(1)?e.push(1):e.push(0),a>>=BigInt(1);return e}(e);if(0==o.length)return t.one;let i=a;for(let e=o.length-2;e>=0;e--)i=t.square(i),o[e]&&(i=t.mul(i,a));return i}function ns(t){if(t.m%2==1)if(Zc(Hc(t.p,4),1))if(Zc(Hc(t.p,8),1))if(Zc(Hc(t.p,16),1))!function(t){t.sqrt_q=Vc(t.p,t.m),t.sqrt_s=0,t.sqrt_t=jc(t.sqrt_q,1);for(;!Nc(t.sqrt_t);)t.sqrt_s=t.sqrt_s+1,t.sqrt_t=Kc(t.sqrt_t,2);let a=t.one;for(;t.eq(a,t.one);){const e=t.random();t.sqrt_z=t.pow(e,t.sqrt_t),a=t.pow(t.sqrt_z,2**(t.sqrt_s-1))}t.sqrt_tm1d2=Kc(jc(t.sqrt_t,1),2),t.sqrt=function(t){const a=this;if(a.isZero(t))return a.zero;let e=a.pow(t,a.sqrt_tm1d2);const o=a.pow(a.mul(a.square(e),t),2**(a.sqrt_s-1));if(a.eq(o,a.negone))return null;let i=a.sqrt_s,n=a.mul(t,e),l=a.mul(n,e),c=a.sqrt_z;for(;!a.eq(l,a.one);){let t=a.square(l),o=1;for(;!a.eq(t,a.one);)t=a.square(t),o++;e=c;for(let t=0;t>>0,t[i]=(t[i]^t[a])>>>0,t[i]=(t[i]<<16|t[i]>>>16&65535)>>>0,t[o]=t[o]+t[i]>>>0,t[e]=(t[e]^t[o])>>>0,t[e]=(t[e]<<12|t[e]>>>20&4095)>>>0,t[a]=t[a]+t[e]>>>0,t[i]=(t[i]^t[a])>>>0,t[i]=(t[i]<<8|t[i]>>>24&255)>>>0,t[o]=t[o]+t[i]>>>0,t[e]=(t[e]^t[o])>>>0,t[e]=(t[e]<<7|t[e]>>>25&127)>>>0}class cs{constructor(t){t=t||[0,0,0,0,0,0,0,0],this.state=[1634760805,857760878,2036477234,1797285236,t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],0,0,0,0],this.idx=16,this.buff=new Array(16)}nextU32(){return 16==this.idx&&this.update(),this.buff[this.idx++]}nextU64(){return Dc((t=this.nextU32(),a=4294967296,BigInt(t)*BigInt(a)),this.nextU32());var t,a}nextBool(){return 1==(1&this.nextU32())}update(){for(let t=0;t<16;t++)this.buff[t]=this.state[t];for(let a=0;a<10;a++)ls(t=this.buff,0,4,8,12),ls(t,1,5,9,13),ls(t,2,6,10,14),ls(t,3,7,11,15),ls(t,0,5,10,15),ls(t,1,6,11,12),ls(t,2,7,8,13),ls(t,3,4,9,14);var t;for(let t=0;t<16;t++)this.buff[t]=this.buff[t]+this.state[t]>>>0;this.idx=0,this.state[12]=this.state[12]+1>>>0,0==this.state[12]&&(this.state[13]=this.state[13]+1>>>0,0==this.state[13]&&(this.state[14]=this.state[14]+1>>>0,0==this.state[14]&&(this.state[15]=this.state[15]+1>>>0)))}}function ss(t){let a=new Uint8Array(t);if(void 0!==globalThis.crypto)globalThis.crypto.getRandomValues(a);else for(let e=0;e>>0;return a}let rs=null;function ds(){return rs||(rs=new cs(function(){const t=ss(32),a=new Uint32Array(t.buffer),e=[];for(let t=0;t<8;t++)e.push(a[t]);return e}()),rs)}class us{constructor(t,a,e){this.F=a,this.G=t,this.opMulGF=e;let o=a.sqrt_t||a.t,i=a.sqrt_s||a.s,n=a.one;for(;a.eq(a.pow(n,a.half),a.one);)n=a.add(n,a.one);this.w=new Array(i+1),this.wi=new Array(i+1),this.w[i]=this.F.pow(n,o),this.wi[i]=this.F.inv(this.w[i]);let l=i-1;for(;l>=0;)this.w[l]=this.F.square(this.w[l+1]),this.wi[l]=this.F.square(this.wi[l+1]),l--;this.roots=[],this._setRoots(Math.min(i,15))}_setRoots(t){for(let a=t;a>=0&&!this.roots[a];a--){let t=this.F.one;const e=1<>1,c=gs(t,a,e-1,o,2*i),s=gs(t,a,e-1,o+i,2*i),r=new Array(n);for(let a=0;a>this.one,this.bitLength=Qc(this.p),this.mask=(this.one<>this.one;this.nqr=this.two;let e=this.pow(this.nqr,a);for(;!this.eq(e,this.negone);)this.nqr=this.nqr+this.one,e=this.pow(this.nqr,a);for(this.s=0,this.t=this.negone;(this.t&this.one)==this.zero;)this.s=this.s+1,this.t=this.t>>this.one;this.nqr_to_t=this.pow(this.nqr,this.t),ns(this),this.FFT=new us(this,this,this.mul.bind(this)),this.fft=this.FFT.fft.bind(this.FFT),this.ifft=this.FFT.ifft.bind(this.FFT),this.w=this.FFT.w,this.wi=this.FFT.wi,this.shift=this.square(this.nqr),this.k=this.exp(this.nqr,2**this.s)}e(t,a){let e;if(a?16==a&&(e=BigInt("0x"+t)):e=BigInt(t),e<0){let t=-e;return t>=this.p&&(t%=this.p),this.p-t}return e>=this.p?e%this.p:e}add(t,a){const e=t+a;return e>=this.p?e-this.p:e}sub(t,a){return t>=a?t-a:this.p-a+t}neg(t){return t?this.p-t:t}mul(t,a){return t*a%this.p}mulScalar(t,a){return t*this.e(a)%this.p}square(t){return t*t%this.p}eq(t,a){return t==a}neq(t,a){return t!=a}lt(t,a){return(t>this.half?t-this.p:t)<(a>this.half?a-this.p:a)}gt(t,a){return(t>this.half?t-this.p:t)>(a>this.half?a-this.p:a)}leq(t,a){return(t>this.half?t-this.p:t)<=(a>this.half?a-this.p:a)}geq(t,a){return(t>this.half?t-this.p:t)>=(a>this.half?a-this.p:a)}div(t,a){return this.mul(t,this.inv(a))}idiv(t,a){if(!a)throw new Error("Division by zero");return t/a}inv(t){if(!t)throw new Error("Division by zero");let a=this.zero,e=this.p,o=this.one,i=t%this.p;for(;i;){let t=e/i;[a,o]=[o,a-t*o],[e,i]=[i,e-t*i]}return a=this.p?e-this.p:e}bor(t,a){const e=(t|a)&this.mask;return e>=this.p?e-this.p:e}bxor(t,a){const e=(t^a)&this.mask;return e>=this.p?e-this.p:e}bnot(t){const a=t^this.mask;return a>=this.p?a-this.p:a}shl(t,a){if(Number(a)=this.p?e-this.p:e}{const e=this.p-a;return Number(e)>e:this.zero}}shr(t,a){if(Number(a)>a;{const e=this.p-a;if(Number(e)=this.p?a-this.p:a}return 0}}land(t,a){return t&&a?this.one:this.zero}lor(t,a){return t||a?this.one:this.zero}lnot(t){return t?this.zero:this.one}sqrt_old(t){if(t==this.zero)return this.zero;if(this.pow(t,this.negone>>this.one)!=this.one)return null;let a=this.s,e=this.nqr_to_t,o=this.pow(t,this.t),i=this.pow(t,this.add(this.t,this.one)>>this.one);for(;o!=this.one;){let t=this.square(o),n=1;for(;t!=this.one;)n++,t=this.square(t);let l=e;for(let t=0;tthis.p>>this.one&&(i=this.neg(i)),i}normalize(t,a){if((t=BigInt(t,a))<0){let a=-t;return a>=this.p&&(a%=this.p),this.p-a}return t>=this.p?t%this.p:t}random(){const t=2*this.bitLength/8;let a=this.zero;for(let e=0;ethis.half&&10==a){e="-"+(this.p-t).toString(a)}else e=t.toString(a);return e}isZero(t){return t==this.zero}fromRng(t){let a;do{a=this.zero;for(let e=0;e=this.p);return a=a*this.Ri%this.p,a}fft(t){return this.FFT.fft(t)}ifft(t){return this.FFT.ifft(t)}toRprLE(t,a,e){Jc(t,a,e,8*this.n64)}toRprBE(t,a,e){!function(t,a,e,o){const i="0000000"+e.toString(16),n=new DataView(t.buffer,t.byteOffset+a,o),l=1+(4*(i.length-7)-1>>5);for(let t=0;t>=1;return e}function ms(t,a){return(hs[t>>>24]|hs[t>>>16&255]<<8|hs[t>>>8&255]<<16|hs[255&t]<<24)>>>32-a}function Ls(t){return(0!=(4294901760&t)?(t&=4294901760,16):0)|(0!=(4278255360&t)?(t&=4278255360,8):0)|(0!=(4042322160&t)?(t&=4042322160,4):0)|(0!=(3435973836&t)?(t&=3435973836,2):0)|0!=(2863311530&t)}function bs(t,a){const e=new Uint8Array(a*t.length);for(let o=0;o0;){const t=l+c>ys?ys-l:c,a=new Uint8Array(this.buffers[n].buffer,this.buffers[n].byteOffset+l,t);if(t==e)return a.slice();i||(i=e<=ys?new Uint8Array(e):new As(e)),i.set(a,e-c),c-=t,n++,l=0}return i}set(t,a){void 0===a&&(a=0);const e=t.byteLength;if(0==e)return;const o=Math.floor(a/ys);if(o==Math.floor((a+e-1)/ys))return t instanceof As&&1==t.buffers.length?this.buffers[o].set(t.buffers[0],a%ys):this.buffers[o].set(t,a%ys);let i=o,n=a%ys,l=e;for(;l>0;){const a=n+l>ys?ys-n:l,o=t.slice(e-l,e-l+a);new Uint8Array(this.buffers[i].buffer,this.buffers[i].byteOffset+n,a).set(o),l-=a,i++,n=0}}}function Cs(t,a,e,o){return async function(i){const n=Math.floor(i.byteLength/e);if(n*e!==i.byteLength)throw new Error("Invalid buffer size");const l=Math.floor(n/t.concurrency),c=[];for(let s=0;s=0;t--)this.w[t]=this.square(this.w[t+1]);if(!this.eq(this.w[0],this.one))throw new Error("Error calculating roots of unity");this.batchToMontgomery=Cs(t,a+"_batchToMontgomery",this.n8,this.n8),this.batchFromMontgomery=Cs(t,a+"_batchFromMontgomery",this.n8,this.n8)}op2(t,a,e){return this.tm.setBuff(this.pOp1,a),this.tm.setBuff(this.pOp2,e),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op2Bool(t,a,e){return this.tm.setBuff(this.pOp1,a),this.tm.setBuff(this.pOp2,e),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2)}op1(t,a){return this.tm.setBuff(this.pOp1,a),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op1Bool(t,a){return this.tm.setBuff(this.pOp1,a),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3)}add(t,a){return this.op2("_add",t,a)}eq(t,a){return this.op2Bool("_eq",t,a)}isZero(t){return this.op1Bool("_isZero",t)}sub(t,a){return this.op2("_sub",t,a)}neg(t){return this.op1("_neg",t)}inv(t){return this.op1("_inverse",t)}toMontgomery(t){return this.op1("_toMontgomery",t)}fromMontgomery(t){return this.op1("_fromMontgomery",t)}mul(t,a){return this.op2("_mul",t,a)}div(t,a){return this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,a),this.tm.instance.exports[this.prefix+"_inverse"](this.pOp2,this.pOp2),this.tm.instance.exports[this.prefix+"_mul"](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}square(t){return this.op1("_square",t)}isSquare(t){return this.op1Bool("_isSquare",t)}sqrt(t){return this.op1("_sqrt",t)}exp(t,a){return a instanceof Uint8Array||(a=as(Uc(a))),this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,a),this.tm.instance.exports[this.prefix+"_exp"](this.pOp1,this.pOp2,a.byteLength,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}isNegative(t){return this.op1Bool("_isNegative",t)}e(t,a){if(t instanceof Uint8Array)return t;let e=Uc(t,a);!function(t){return BigInt(t)>=BigInt(32)):n+2<=a?(i.setUint16(n,Number(e&BigInt(65535)),!0),n+=2,e>>=BigInt(16)):(i.setUint8(n,Number(e&BigInt(255)),!0),n+=1,e>>=BigInt(8));if(e)throw new Error("Number does not fit in this length");return o}(e,this.n8);return this.toMontgomery(o)}toString(t,a){return ts(Xc(this.fromMontgomery(t),0),a)}fromRng(t){let a;const e=new Uint8Array(this.n8);do{a=es;for(let e=0;e=BigInt(i));var o,i;return Jc(e,0,a,this.n8),e}random(){return this.fromRng(ds())}toObject(t){return Xc(this.fromMontgomery(t),0)}fromObject(t){const a=new Uint8Array(this.n8);return Jc(a,0,t,this.n8),this.toMontgomery(a)}toRprLE(t,a,e){t.set(this.fromMontgomery(e),a)}toRprBE(t,a,e){const o=this.fromMontgomery(e);for(let t=0;to.buffer.byteLength){const i=o.buffer.byteLength/65536;let n=Math.floor((e[0]+t)/65536)+1;n>a&&(n=a),o.grow(n-i)}return i}function l(t){const a=n(t.byteLength);return s(a,t),a}function c(t,a){const e=new Uint8Array(o.buffer);return new Uint8Array(e.buffer,e.byteOffset+t,a)}function s(t,a){new Uint8Array(o.buffer).set(new Uint8Array(a),t)}function r(t){if("INIT"==t[0].cmd)return i(t[0]);const a={vars:[],out:[]},r=new Uint32Array(o.buffer,0,1)[0];for(let o=0;o{this.reject=a,this.resolve=t}))}}const Ps=function(t){return globalThis.btoa(t)}("("+Es.toString()+")(self)"),qs="data:application/javascript;base64,"+Ps;class Os{constructor(){this.actionQueue=[],this.oldPFree=0}startSyncOp(){if(0!=this.oldPFree)throw new Error("Sync operation in progress");this.oldPFree=this.u32[0]}endSyncOp(){if(0==this.oldPFree)throw new Error("No sync operation in progress");this.u32[0]=this.oldPFree,this.oldPFree=0}postAction(t,a,e,o){if(this.working[t])throw new Error("Posting a job t a working worker");return this.working[t]=!0,this.pendingDeferreds[t]=o||new Ss,this.workers[t].postMessage(a,e),this.pendingDeferreds[t].promise}processWorks(){for(let t=0;t0;t++)if(0==this.working[t]){const a=this.actionQueue.shift();this.postAction(t,a.data,a.transfers,a.deferred)}}queueAction(t,a){const e=new Ss;if(this.singleThread){const a=this.taskManager(t);e.resolve(a)}else this.actionQueue.push({data:t,transfers:a,deferred:e}),this.processWorks();return e.promise}resetMemory(){this.u32[0]=this.initalPFree}allocBuff(t){const a=this.alloc(t.byteLength);return this.setBuff(a,t),a}getBuff(t,a){return this.u8.slice(t,t+a)}setBuff(t,a){this.u8.set(new Uint8Array(a),t)}alloc(t){for(;3&this.u32[0];)this.u32[0]++;const a=this.u32[0];return this.u32[0]+=t,a}async terminate(){for(let t=0;tsetTimeout(a,t))))}}function Gs(t,a){const e=t[a],o=t.Fr,i=t.tm;t[a].batchApplyKey=async function(t,n,l,c,s){let r,d,u,_,g;if(c=c||"affine",s=s||"affine","G1"==a)"jacobian"==c?(u=3*e.F.n8,r="g1m_batchApplyKey"):(u=2*e.F.n8,r="g1m_batchApplyKeyMixed"),_=3*e.F.n8,"jacobian"==s?g=3*e.F.n8:(d="g1m_batchToAffine",g=2*e.F.n8);else if("G2"==a)"jacobian"==c?(u=3*e.F.n8,r="g2m_batchApplyKey"):(u=2*e.F.n8,r="g2m_batchApplyKeyMixed"),_=3*e.F.n8,"jacobian"==s?g=3*e.F.n8:(d="g2m_batchToAffine",g=2*e.F.n8);else{if("Fr"!=a)throw new Error("Invalid group: "+a);r="frm_batchApplyKey",u=e.n8,_=e.n8,g=e.n8}const f=Math.floor(t.byteLength/u),h=Math.floor(f/i.concurrency),p=[];l=o.e(l);let m=o.e(n);for(let a=0;a=0;t--){if(!e.isZero(h))for(let t=0;tr&&(h=r),h<1024&&(h=1024);const p=[];for(let a=0;a(c&&c.debug(`Multiexp end: ${s}: ${a}/${u}`),t))))}const m=await Promise.all(p);let L=e.zero;for(let t=m.length-1;t>=0;t--)L=e.add(L,m[t]);return L}e.multiExp=async function(t,a,e,o){return await n(t,a,"jacobian",e,o)},e.multiExpAffine=async function(t,a,e,o){return await n(t,a,"affine",e,o)}}function Ms(t,a){const e=t[a],o=t.Fr,i=e.tm;async function n(t,c,s,r,d,u){s=s||"affine",r=r||"affine";let _,g,f,h,p,m,L,b;"G1"==a?("affine"==s?(_=2*e.F.n8,h="g1m_batchToJacobian"):_=3*e.F.n8,g=3*e.F.n8,c&&(b="g1m_fftFinal"),L="g1m_fftJoin",m="g1m_fftMix","affine"==r?(f=2*e.F.n8,p="g1m_batchToAffine"):f=3*e.F.n8):"G2"==a?("affine"==s?(_=2*e.F.n8,h="g2m_batchToJacobian"):_=3*e.F.n8,g=3*e.F.n8,c&&(b="g2m_fftFinal"),L="g2m_fftJoin",m="g2m_fftMix","affine"==r?(f=2*e.F.n8,p="g2m_batchToAffine"):f=3*e.F.n8):"Fr"==a&&(_=e.n8,g=e.n8,f=e.n8,c&&(b="frm_fftFinal"),m="frm_fftMix",L="frm_fftJoin");let w=!1;Array.isArray(t)?(t=bs(t,_),w=!0):t=t.slice(0,t.byteLength);const y=t.byteLength/_,A=Ls(y);if(1<1<<28?new As(2*u[0].byteLength):new Uint8Array(2*u[0].byteLength);return _.set(u[0]),_.set(u[1],u[0].byteLength),_}(t,s,r,d,u):await async function(t,a,e,i,c){let s,r;s=t.slice(0,t.byteLength/2),r=t.slice(t.byteLength/2,t.byteLength);const d=[];[s,r]=await l(s,r,"fftJoinExt",o.one,o.shift,a,"jacobian",i,c),d.push(n(s,!1,"jacobian",e,i,c)),d.push(n(r,!1,"jacobian",e,i,c));const u=await Promise.all(d);let _;_=u[0].byteLength>1<<28?new As(2*u[0].byteLength):new Uint8Array(2*u[0].byteLength);return _.set(u[0]),_.set(u[1],u[0].byteLength),_}(t,s,r,d,u),w?ws(a,f):a}let C,F,x;c&&(C=o.inv(o.e(y))),function(t,a){const e=t.byteLength/a,o=Ls(e);if(e!=1<e){const o=t.slice(i*a,(i+1)*a);t.set(t.slice(e*a,(e+1)*a),i*a),t.set(o,e*a)}}}(t,_);let I=Math.min(16384,y),B=y/I;for(;B=16;)B*=2,I/=2;const E=Ls(I),v=[];for(let a=0;a(d&&d.debug(`${u}: fft ${A} mix end: ${a}/${B}`),t))))}x=await Promise.all(v);for(let t=0;t(d&&d.debug(`${u}: fft ${A} join ${t}/${A} ${l+1}/${a} ${c}/${e/2}`),o))))}const l=await Promise.all(n);for(let t=0;t0;a--)F.set(x[a],t),t+=I*f,delete x[a];F.set(x[0].slice(0,(I-1)*f),t),delete x[0]}else for(let t=0;t65536&&(w=65536);const y=[];for(let a=0;a(u&&u.debug(`${_}: fftJoinExt End: ${a}/${b}`),t))))}const A=await Promise.all(y);let C,F;b*p>1<<28?(C=new As(b*p),F=new As(b*p)):(C=new Uint8Array(b*p),F=new Uint8Array(b*p));let x=0;for(let t=0;to.s+1)throw s&&s.error("lagrangeEvaluations input too big"),new Error("lagrangeEvaluations input too big");let g=t.slice(0,t.byteLength/2),f=t.slice(t.byteLength/2,t.byteLength);const h=o.exp(o.shift,u/2),p=o.inv(o.sub(o.one,h));[g,f]=await l(g,f,"prepareLagrangeEvaluation",p,o.shiftInv,i,"jacobian",s,r+" prep");const m=[];let L;return m.push(n(g,!0,"jacobian",c,s,r+" t0")),m.push(n(f,!0,"jacobian",c,s,r+" t1")),[g,f]=await Promise.all(m),L=g.byteLength>1<<28?new As(2*g.byteLength):new Uint8Array(2*g.byteLength),L.set(g),L.set(f,g.byteLength),L},e.fftMix=async function(t){const n=3*e.F.n8;let l,c;if("G1"==a)l="g1m_fftMix",c="g1m_fftJoin";else if("G2"==a)l="g2m_fftMix",c="g2m_fftJoin";else{if("Fr"!=a)throw new Error("Invalid group");l="frm_fftMix",c="frm_fftJoin"}const s=Math.floor(t.byteLength/n),r=Ls(s);let d=1<=0;t--)g.set(_[t][0],f),f+=_[t][0].byteLength;return g}}async function Us(t){const a=await async function(t,a){const e=new Os;e.memory=new WebAssembly.Memory({initial:vs}),e.u8=new Uint8Array(e.memory.buffer),e.u32=new Uint32Array(e.memory.buffer);const o=await WebAssembly.compile(t.code);if(e.instance=await WebAssembly.instantiate(o,{env:{memory:e.memory}}),e.singleThread=a,e.initalPFree=e.u32[0],e.pq=t.pq,e.pr=t.pr,e.pG1gen=t.pG1gen,e.pG1zero=t.pG1zero,e.pG2gen=t.pG2gen,e.pG2zero=t.pG2zero,e.pOneT=t.pOneT,a)e.code=t.code,e.taskManager=Es(),await e.taskManager([{cmd:"INIT",init:vs,code:e.code.slice()}]),e.concurrency=1;else{let a;e.workers=[],e.pendingDeferreds=[],e.working=[],a="object"==typeof navigator&&navigator.hardwareConcurrency?navigator.hardwareConcurrency:kl.cpus().length,0==a&&(a=2),a>64&&(a=64),e.concurrency=a;for(let t=0;t=this.length&&(this.length=t+1),!0}getKeys(){const t=new js;for(let a=0;a1<<20?new js:[];for(let t=0;t1<<20?new js:[];for(let t=0;t1<<20?new js:[];for(let t=0;t{let o="";return Object.keys(e).forEach((i=>{let n=a.varIdx2Name[i];"one"==n&&(n="1");let l=t.curve.Fr.toString(e[i]);"1"==l&&(l=""),"-1"==l&&(l="-"),""!=o&&"-"!=l[0]&&(l="+"+l),""!=o&&(l=" "+l),o=o+l+n})),o},n=`[ ${i(o[0])} ] * [ ${i(o[1])} ] - [ ${i(o[2])} ] = 0`;e&&e.info(n)}},info:async function(t,a){const e=await Ws(t);return _e.eq(e.prime,Js)?a&&a.info("Curve: bn-128"):_e.eq(e.prime,Ys)?a&&a.info("Curve: bls12-381"):a&&a.info(`Unknown Curve. Prime: ${_e.toString(e.prime)}`),a&&a.info(`# of Wires: ${e.nVars}`),a&&a.info(`# of Constraints: ${e.nConstraints}`),a&&a.info(`# of Private Inputs: ${e.nPrvInputs}`),a&&a.info(`# of Public Inputs: ${e.nPubInputs}`),a&&a.info(`# of Labels: ${e.nLabels}`),a&&a.info(`# of Outputs: ${e.nOutputs}`),e},exportJson:async function(t,a){const e=await Ws(t,!0,!0,!0,a),o=e.curve.Fr;return delete e.curve,delete e.F,Ho(o,e)}});async function tr(t){const a={labelIdx2Name:["one"],varIdx2Name:["one"],componentIdx2Name:[]},e=await ze(t),o=await e.read(e.totalSize),i=new TextDecoder("utf-8").decode(o).split("\n");for(let t=0;t Reading r1cs file");const{fd:o,sections:i}=await Te(t,"r1cs",1),n=await Zs(o,i,{loadConstraints:!1,loadCustomGates:!1});e&&e.info("> Reading witness file");const{fd:l,sections:c}=await Te(a,"wtns",2),s=await Ii(l,c);if(!_e.eq(n.prime,s.q))throw new Error("Curve of the witness does not match the curve of the proving key");const r=await je(l,c,2);await l.close();const d=(await async function(t){let a;if(_e.eq(t,He))a=await de();else{if(!_e.eq(t,Ke))throw new Error(`Curve not supported: ${_e.toString(t)}`);a=await ue()}return a}(n.prime)).Fr,u=d.n8,_=await je(o,i,2);e&&(e.info("----------------------------"),e.info(" WITNESS CHECK"),e.info(` Curve: ${n.curve.name}`),e.info(` Vars (wires): ${n.nVars}`),e.info(` Ouputs: ${n.nOutputs}`),e.info(` Public Inputs: ${n.nPubInputs}`),e.info(` Private Inputs: ${n.nPrvInputs}`),e.info(` Labels: ${n.nLabels}`),e.info(` Constraints: ${n.nConstraints}`),e.info(` Custom Gates: ${n.useCustomGates}`),e.info("----------------------------")),e&&e.info("> Checking witness correctness");let g=0,f=!0;for(let t=0;t{const o=function(t){return d.fromRprLE(r.slice(t*u,t*u+u))}(e),i=t[e];a=d.add(a,d.mul(o,i))})),a}function p(){const t={},a=_.slice(g,g+4);g+=4;const e=new DataView(a.buffer).getUint32(0,!0),o=_.slice(g,g+(4+n.n8)*e);g+=(4+n.n8)*e;const i=new DataView(o.buffer);for(let a=0;a=this.length&&(this.length=t+1),!0}getKeys(){const t=new lr;for(let a=0;as)return o&&o.error(`circuit too big for this power of tau ceremony. ${u.nConstraints}*2 > 2**${s}`),-1;if(!l[12])return o&&o.error("Powers of tau is not prepared."),-1;const p=u.nOutputs+u.nPubInputs,m=2**h;await Ue(_,1),await _.writeULE32(1),await Qe(_),await Ue(_,2);const L=c.q,b=8*(Math.floor((_e.bitLength(L)-1)/64)+1),w=c.r,y=8*(Math.floor((_e.bitLength(w)-1)/64)+1),A=_e.mod(_e.shl(1,8*y),w),C=c.Fr.e(_e.mod(_e.mul(A,A),w));let F,x,I;await _.writeULE32(b),await Ne(_,L,b),await _.writeULE32(y),await Ne(_,w,y),await _.writeULE32(u.nVars),await _.writeULE32(p),await _.writeULE32(m),F=await n.read(g,l[4][0].p),await _.write(F),F=await c.G1.batchLEMtoU(F),i.update(F),x=await n.read(g,l[5][0].p),await _.write(x),x=await c.G1.batchLEMtoU(x),i.update(x),I=await n.read(f,l[6][0].p),await _.write(I),I=await c.G2.batchLEMtoU(I),i.update(I);const B=new Uint8Array(g);c.G1.toRprLEM(B,0,c.G1.g);const E=new Uint8Array(f);c.G2.toRprLEM(E,0,c.G2.g);const v=new Uint8Array(g);c.G1.toRprUncompressed(v,0,c.G1.g);const S=new Uint8Array(f);c.G2.toRprUncompressed(S,0,c.G2.g),await _.write(E),await _.write(B),await _.write(E),i.update(S),i.update(v),i.update(S),await Qe(_),o&&o.info("Reading r1cs");let P=await je(r,d,2);const q=new lr(u.nVars),O=new lr(u.nVars),G=new lr(u.nVars),z=new lr(u.nVars-p-1),T=new Array(p+1);o&&o.info("Reading tauG1");let M=await je(n,l,12,(m-1)*g,m*g);o&&o.info("Reading tauG2");let U=await je(n,l,13,(m-1)*f,m*f);o&&o.info("Reading alphatauG1");let Q=await je(n,l,14,(m-1)*g,m*g);o&&o.info("Reading betatauG1");let k=await je(n,l,15,(m-1)*g,m*g);await async function(){const t=new Uint8Array(12+c.Fr.n8),a=new DataView(t.buffer),e=new Uint8Array(c.Fr.n8);c.Fr.toRprLE(e,0,c.Fr.e(1));let i=0;function n(){const t=P.slice(i,i+4);i+=4;return new DataView(t.buffer).getUint32(0,!0)}const l=new lr;for(let t=0;t=0?c.Fr.fromRprLE(P.slice(o[3],o[3]+c.Fr.n8),0):c.Fr.fromRprLE(e,0);const n=c.Fr.mul(i,C);c.Fr.toRprLE(t,12,n),s.set(t,d),d+=t.length}await _.write(s),await Qe(_)}(),await N(3,"G1",T,"IC"),await async function(){await Ue(_,9);const t=new Pa(m*g);if(h(o&&o.debug(`Writing points end ${n}: ${d}/${e.length}`),t)))),r+=i,t++}const d=await Promise.all(s);for(let t=0;t32768?(g=new Pa(h*n),f=new Pa(h*c.Fr.n8)):(g=new Uint8Array(h*n),f=new Uint8Array(h*c.Fr.n8));let p=0,m=0;const L=[M,U,Q,k],b=new Uint8Array(c.Fr.n8);c.Fr.toRprLE(b,0,c.Fr.e(1));let w=0;for(let t=0;t=0?f.set(P.slice(a[t][i][2],a[t][i][2]+c.Fr.n8),w*c.Fr.n8):f.set(b,w*c.Fr.n8),w++;if(a.length>1){const t=[];t.push({cmd:"ALLOCSET",var:0,buff:g}),t.push({cmd:"ALLOCSET",var:1,buff:f}),t.push({cmd:"ALLOC",var:2,len:a.length*l}),p=0,m=0;let e=0;for(let o=0;o=0;t--){const a=d.contributions[t];o&&o.info("-------------------------"),o&&o.info(Mo(a.contributionHash,`contribution #${t+1} ${a.name?a.name:""}:`)),1==a.type&&(o&&o.info(`Beacon generator: ${Ko(a.beaconHash)}`),o&&o.info(`Beacon iterations Exp: ${a.numIterationsExp}`))}return o&&o.info("-------------------------"),o&&o.info("ZKey Ok!"),!0;async function L(t,a){const e=2*s.G1.F.n8,o=t.byteLength/e,i=s.tm.concurrency,n=Math.floor(o/i),l=[];for(let e=0;e Detected protocol: "+i.protocol),"groth16"===i.protocol)n=await async function(t,a,e){const o=await Ye(t.q),i=2*o.G1.F.n8,n=await o.pairing(t.vk_alpha_1,t.vk_beta_2);let l={protocol:t.protocol,curve:o.name,nPublic:t.nPublic,vk_alpha_1:o.G1.toObject(t.vk_alpha_1),vk_beta_2:o.G2.toObject(t.vk_beta_2),vk_gamma_2:o.G2.toObject(t.vk_gamma_2),vk_delta_2:o.G2.toObject(t.vk_delta_2),vk_alphabeta_12:o.Gt.toObject(n)};await ke(a,e,3),l.IC=[];for(let e=0;e<=t.nPublic;e++){const t=await a.read(i),e=o.G1.toObject(t);l.IC.push(e)}return await Re(a),l=dr(l),l}(i,e,o);else if("plonk"===i.protocol)n=await async function(t){const a=await Ye(t.q);let e={protocol:t.protocol,curve:a.name,nPublic:t.nPublic,power:t.power,k1:a.Fr.toObject(t.k1),k2:a.Fr.toObject(t.k2),Qm:a.G1.toObject(t.Qm),Ql:a.G1.toObject(t.Ql),Qr:a.G1.toObject(t.Qr),Qo:a.G1.toObject(t.Qo),Qc:a.G1.toObject(t.Qc),S1:a.G1.toObject(t.S1),S2:a.G1.toObject(t.S2),S3:a.G1.toObject(t.S3),X_2:a.G2.toObject(t.X_2),w:a.Fr.toObject(a.Fr.w[t.power])};return e=dr(e),e}(i);else{if(!i.protocolId||i.protocolId!==Yo)throw new Error("zkey file protocol unrecognized");n=await async function(t,a){const e=await Ye(t.q);let o={protocol:t.protocol,curve:e.name,nPublic:t.nPublic,power:t.power,k1:e.Fr.toObject(t.k1),k2:e.Fr.toObject(t.k2),w:e.Fr.toObject(e.Fr.w[t.power]),w3:e.Fr.toObject(t.w3),w4:e.Fr.toObject(t.w4),w8:e.Fr.toObject(t.w8),wr:e.Fr.toObject(t.wr),X_2:e.G2.toObject(t.X_2),C0:e.G1.toObject(t.C0)};return dr(o)}(i)}return await e.close(),a&&a.info("EXPORT VERIFICATION KEY FINISHED"),n}var _r={};const{unstringifyBigInts:gr,stringifyBigInts:fr}=ge;async function hr(t,a,e){e&&e.info("FFLONK EXPORT SOLIDITY VERIFIER STARTED");const o=await Je(t.curve);let i=r(t.w3);t.w3_2=d(o.Fr.square(i));let n=r(t.w4);t.w4_2=d(o.Fr.square(n)),t.w4_3=d(o.Fr.mul(o.Fr.square(n),n));let l=r(t.w8),c=o.Fr.one;for(let a=1;a<8;a++)c=o.Fr.mul(c,l),t["w8_"+a]=d(c);let s=a[t.protocol];return e&&e.info("FFLONK EXPORT SOLIDITY VERIFIER FINISHED"),_r.render(s,t);function r(t){const a=gr(t);return o.Fr.fromObject(a)}function d(t){const a=o.Fr.toObject(t);return fr(a)}}var pr=Object.freeze({__proto__:null,newZKey:cr,exportBellman:async function(t,a,e){const{fd:o,sections:i}=await Te(t,"zkey",2),n=await bi(o,i);if("groth16"!=n.protocol)throw new Error("zkey file is not groth16");const l=await Ye(n.q),c=2*l.G1.F.n8,s=2*l.G2.F.n8,r=await yi(o,l,i),d=await Ge(a);let u;await L(n.vk_alpha_1),await L(n.vk_beta_1),await b(n.vk_beta_2),await b(n.vk_gamma_2),await L(n.vk_delta_1),await b(n.vk_delta_2),u=await je(o,i,3),u=await l.G1.batchLEMtoU(u),await w("G1",u);const _=await je(o,i,9);let g,f,h,p,m;g=await l.G1.fft(_,"affine","jacobian",e),g=await l.G1.batchApplyKey(g,l.Fr.neg(l.Fr.e(2)),l.Fr.w[n.power+1],"jacobian","affine",e),g=g.slice(0,g.byteLength-c),g=await l.G1.batchLEMtoU(g),await w("G1",g),f=await je(o,i,8),f=await l.G1.batchLEMtoU(f),await w("G1",f),h=await je(o,i,5),h=await l.G1.batchLEMtoU(h),await w("G1",h),p=await je(o,i,6),p=await l.G1.batchLEMtoU(p),await w("G1",p),m=await je(o,i,7),m=await l.G2.batchLEMtoU(m),await w("G2",m),await d.write(r.csHash),await async function(t){const a=new Uint8Array(4);new DataView(a.buffer,a.byteOffset,a.byteLength).setUint32(0,t,!1),await d.write(a)}(r.contributions.length);for(let t=0;t_.contributions.length)return i&&i.error("The impoerted file does not include new contributions"),!1;for(let t=0;t=256)return n&&n.error("Maximum lenght of beacon hash is 255 bytes"),!1;if((i=parseInt(i))<10||i>63)return n&&n.error("Invalid numIterationsExp. (Must be between 10 and 63)"),!1;const{fd:c,sections:s}=await Te(t,"zkey",2),r=await bi(c,s);if("groth16"!=r.protocol)throw new Error("zkey file is not groth16");const d=await Ye(r.q),u=await yi(c,d,s),_=await Me(a,"zkey",1,10),g=await jo(l,i),f=to.exports(64);f.update(u.csHash);for(let t=0;t{const o=this.curve.G1.toObject(this.polynomials[e]);t?a.polynomials[e]=o:a[e]=o})),Object.keys(this.evaluations).forEach((e=>{const o=this.curve.Fr.toObject(this.evaluations[e]);t?a.evaluations[e]=o:a[e]=o})),a}fromObjectProof(t){this.resetProof(),Object.keys(t.polynomials).forEach((a=>{this.polynomials[a]=this.curve.G1.fromObject(t.polynomials[a])})),Object.keys(t.evaluations).forEach((a=>{this.evaluations[a]=this.curve.Fr.fromObject(t.evaluations[a])}))}}var Lr,br={exports:{}}; /** * [js-sha3]{@link https://github.com/emn178/js-sha3} * @@ -6,4 +6,4 @@ var snarkjs=function(t){"use strict";const a=[0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4];f * @author Chen, Yi-Cyuan [emn178@gmail.com] * @copyright Chen, Yi-Cyuan 2015-2018 * @license MIT - */hr=pr,function(){var t="input is invalid type",a="object"==typeof window,e=a?window:{};e.JS_SHA3_NO_WINDOW&&(a=!1);var o=!a&&"object"==typeof self;!e.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node?e=Xe:o&&(e=self);var i=!e.JS_SHA3_NO_COMMON_JS&&hr.exports,n=!e.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,l="0123456789abcdef".split(""),c=[4,1024,262144,67108864],s=[0,8,16,24],r=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],d=[224,256,384,512],u=[128,256],_=["hex","buffer","arrayBuffer","array","digest"],g={128:168,256:136};!e.JS_SHA3_NO_NODE_JS&&Array.isArray||(Array.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)}),!n||!e.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView||(ArrayBuffer.isView=function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer});for(var f=function(t,a,e){return function(o){return new v(t,a,t).update(o)[e]()}},h=function(t,a,e){return function(o,i){return new v(t,a,i).update(o)[e]()}},p=function(t,a,e){return function(a,o,i,n){return y["cshake"+t].update(a,o,i,n)[e]()}},m=function(t,a,e){return function(a,o,i,n){return y["kmac"+t].update(a,o,i,n)[e]()}},L=function(t,a,e,o){for(var i=0;i<_.length;++i){var n=_[i];t[n]=a(e,o,n)}return t},b=function(t,a){var e=f(t,a,"hex");return e.create=function(){return new v(t,a,t)},e.update=function(t){return e.create().update(t)},L(e,f,t,a)},w=[{name:"keccak",padding:[1,256,65536,16777216],bits:d,createMethod:b},{name:"sha3",padding:[6,1536,393216,100663296],bits:d,createMethod:b},{name:"shake",padding:[31,7936,2031616,520093696],bits:u,createMethod:function(t,a){var e=h(t,a,"hex");return e.create=function(e){return new v(t,a,e)},e.update=function(t,a){return e.create(a).update(t)},L(e,h,t,a)}},{name:"cshake",padding:c,bits:u,createMethod:function(t,a){var e=g[t],o=p(t,0,"hex");return o.create=function(o,i,n){return i||n?new v(t,a,o).bytepad([i,n],e):y["shake"+t].create(o)},o.update=function(t,a,e,i){return o.create(a,e,i).update(t)},L(o,p,t,a)}},{name:"kmac",padding:c,bits:u,createMethod:function(t,a){var e=g[t],o=m(t,0,"hex");return o.create=function(o,i,n){return new S(t,a,i).bytepad(["KMAC",n],e).bytepad([o],e)},o.update=function(t,a,e,i){return o.create(t,e,i).update(a)},L(o,m,t,a)}}],y={},A=[],C=0;C>5,this.byteCount=this.blockCount<<2,this.outputBlocks=e>>5,this.extraBytes=(31&e)>>3;for(var o=0;o<50;++o)this.s[o]=0}function S(t,a,e){v.call(this,t,a,e)}v.prototype.update=function(a){if(this.finalized)throw new Error("finalize already called");var e,o=typeof a;if("string"!==o){if("object"!==o)throw new Error(t);if(null===a)throw new Error(t);if(n&&a.constructor===ArrayBuffer)a=new Uint8Array(a);else if(!(Array.isArray(a)||n&&ArrayBuffer.isView(a)))throw new Error(t);e=!0}for(var i,l,c=this.blocks,r=this.byteCount,d=a.length,u=this.blockCount,_=0,g=this.s;_>2]|=a[_]<>2]|=l<>2]|=(192|l>>6)<>2]|=(128|63&l)<=57344?(c[i>>2]|=(224|l>>12)<>2]|=(128|l>>6&63)<>2]|=(128|63&l)<>2]|=(240|l>>18)<>2]|=(128|l>>12&63)<>2]|=(128|l>>6&63)<>2]|=(128|63&l)<=r){for(this.start=i-r,this.block=c[u],i=0;i>=8);e>0;)i.unshift(e),e=255&(t>>=8),++o;return a?i.push(o):i.unshift(o),this.update(i),i.length},v.prototype.encodeString=function(a){var e,o=typeof a;if("string"!==o){if("object"!==o)throw new Error(t);if(null===a)throw new Error(t);if(n&&a.constructor===ArrayBuffer)a=new Uint8Array(a);else if(!(Array.isArray(a)||n&&ArrayBuffer.isView(a)))throw new Error(t);e=!0}var i=0,l=a.length;if(e)i=l;else for(var c=0;c=57344?i+=3:(s=65536+((1023&s)<<10|1023&a.charCodeAt(++c)),i+=4)}return i+=this.encode(8*i),this.update(a),i},v.prototype.bytepad=function(t,a){for(var e=this.encode(a),o=0;o>2]|=this.padding[3&a],this.lastByteIndex===this.byteCount)for(t[0]=t[e],a=1;a>4&15]+l[15&t]+l[t>>12&15]+l[t>>8&15]+l[t>>20&15]+l[t>>16&15]+l[t>>28&15]+l[t>>24&15];c%a==0&&(P(e),n=0)}return i&&(t=e[n],s+=l[t>>4&15]+l[15&t],i>1&&(s+=l[t>>12&15]+l[t>>8&15]),i>2&&(s+=l[t>>20&15]+l[t>>16&15])),s},v.prototype.arrayBuffer=function(){this.finalize();var t,a=this.blockCount,e=this.s,o=this.outputBlocks,i=this.extraBytes,n=0,l=0,c=this.outputBits>>3;t=i?new ArrayBuffer(o+1<<2):new ArrayBuffer(c);for(var s=new Uint32Array(t);l>8&255,s[t+2]=a>>16&255,s[t+3]=a>>24&255;c%e==0&&P(o)}return n&&(t=c<<2,a=o[l],s[t]=255&a,n>1&&(s[t+1]=a>>8&255),n>2&&(s[t+2]=a>>16&255)),s},S.prototype=new v,S.prototype.finalize=function(){return this.encode(this.outputBits,!0),v.prototype.finalize.call(this)};var P=function(t){var a,e,o,i,n,l,c,s,d,u,_,g,f,h,p,m,L,b,w,y,A,C,F,x,I,B,E,v,S,P,q,O,G,z,T,M,U,Q,k,R,N,D,$,j,V,K,H,Z,W,Y,J,X,tt,at,et,ot,it,nt,lt,ct,st,rt,dt;for(o=0;o<48;o+=2)i=t[0]^t[10]^t[20]^t[30]^t[40],n=t[1]^t[11]^t[21]^t[31]^t[41],l=t[2]^t[12]^t[22]^t[32]^t[42],c=t[3]^t[13]^t[23]^t[33]^t[43],s=t[4]^t[14]^t[24]^t[34]^t[44],d=t[5]^t[15]^t[25]^t[35]^t[45],u=t[6]^t[16]^t[26]^t[36]^t[46],_=t[7]^t[17]^t[27]^t[37]^t[47],a=(g=t[8]^t[18]^t[28]^t[38]^t[48])^(l<<1|c>>>31),e=(f=t[9]^t[19]^t[29]^t[39]^t[49])^(c<<1|l>>>31),t[0]^=a,t[1]^=e,t[10]^=a,t[11]^=e,t[20]^=a,t[21]^=e,t[30]^=a,t[31]^=e,t[40]^=a,t[41]^=e,a=i^(s<<1|d>>>31),e=n^(d<<1|s>>>31),t[2]^=a,t[3]^=e,t[12]^=a,t[13]^=e,t[22]^=a,t[23]^=e,t[32]^=a,t[33]^=e,t[42]^=a,t[43]^=e,a=l^(u<<1|_>>>31),e=c^(_<<1|u>>>31),t[4]^=a,t[5]^=e,t[14]^=a,t[15]^=e,t[24]^=a,t[25]^=e,t[34]^=a,t[35]^=e,t[44]^=a,t[45]^=e,a=s^(g<<1|f>>>31),e=d^(f<<1|g>>>31),t[6]^=a,t[7]^=e,t[16]^=a,t[17]^=e,t[26]^=a,t[27]^=e,t[36]^=a,t[37]^=e,t[46]^=a,t[47]^=e,a=u^(i<<1|n>>>31),e=_^(n<<1|i>>>31),t[8]^=a,t[9]^=e,t[18]^=a,t[19]^=e,t[28]^=a,t[29]^=e,t[38]^=a,t[39]^=e,t[48]^=a,t[49]^=e,h=t[0],p=t[1],K=t[11]<<4|t[10]>>>28,H=t[10]<<4|t[11]>>>28,v=t[20]<<3|t[21]>>>29,S=t[21]<<3|t[20]>>>29,ct=t[31]<<9|t[30]>>>23,st=t[30]<<9|t[31]>>>23,D=t[40]<<18|t[41]>>>14,$=t[41]<<18|t[40]>>>14,z=t[2]<<1|t[3]>>>31,T=t[3]<<1|t[2]>>>31,m=t[13]<<12|t[12]>>>20,L=t[12]<<12|t[13]>>>20,Z=t[22]<<10|t[23]>>>22,W=t[23]<<10|t[22]>>>22,P=t[33]<<13|t[32]>>>19,q=t[32]<<13|t[33]>>>19,rt=t[42]<<2|t[43]>>>30,dt=t[43]<<2|t[42]>>>30,at=t[5]<<30|t[4]>>>2,et=t[4]<<30|t[5]>>>2,M=t[14]<<6|t[15]>>>26,U=t[15]<<6|t[14]>>>26,b=t[25]<<11|t[24]>>>21,w=t[24]<<11|t[25]>>>21,Y=t[34]<<15|t[35]>>>17,J=t[35]<<15|t[34]>>>17,O=t[45]<<29|t[44]>>>3,G=t[44]<<29|t[45]>>>3,x=t[6]<<28|t[7]>>>4,I=t[7]<<28|t[6]>>>4,ot=t[17]<<23|t[16]>>>9,it=t[16]<<23|t[17]>>>9,Q=t[26]<<25|t[27]>>>7,k=t[27]<<25|t[26]>>>7,y=t[36]<<21|t[37]>>>11,A=t[37]<<21|t[36]>>>11,X=t[47]<<24|t[46]>>>8,tt=t[46]<<24|t[47]>>>8,j=t[8]<<27|t[9]>>>5,V=t[9]<<27|t[8]>>>5,B=t[18]<<20|t[19]>>>12,E=t[19]<<20|t[18]>>>12,nt=t[29]<<7|t[28]>>>25,lt=t[28]<<7|t[29]>>>25,R=t[38]<<8|t[39]>>>24,N=t[39]<<8|t[38]>>>24,C=t[48]<<14|t[49]>>>18,F=t[49]<<14|t[48]>>>18,t[0]=h^~m&b,t[1]=p^~L&w,t[10]=x^~B&v,t[11]=I^~E&S,t[20]=z^~M&Q,t[21]=T^~U&k,t[30]=j^~K&Z,t[31]=V^~H&W,t[40]=at^~ot&nt,t[41]=et^~it<,t[2]=m^~b&y,t[3]=L^~w&A,t[12]=B^~v&P,t[13]=E^~S&q,t[22]=M^~Q&R,t[23]=U^~k&N,t[32]=K^~Z&Y,t[33]=H^~W&J,t[42]=ot^~nt&ct,t[43]=it^~lt&st,t[4]=b^~y&C,t[5]=w^~A&F,t[14]=v^~P&O,t[15]=S^~q&G,t[24]=Q^~R&D,t[25]=k^~N&$,t[34]=Z^~Y&X,t[35]=W^~J&tt,t[44]=nt^~ct&rt,t[45]=lt^~st&dt,t[6]=y^~C&h,t[7]=A^~F&p,t[16]=P^~O&x,t[17]=q^~G&I,t[26]=R^~D&z,t[27]=N^~$&T,t[36]=Y^~X&j,t[37]=J^~tt&V,t[46]=ct^~rt&at,t[47]=st^~dt&et,t[8]=C^~h&m,t[9]=F^~p&L,t[18]=O^~x&B,t[19]=G^~I&E,t[28]=D^~z&M,t[29]=$^~T&U,t[38]=X^~j&K,t[39]=tt^~V&H,t[48]=rt^~at&ot,t[49]=dt^~et&it,t[0]^=r[o],t[1]^=r[o+1]};if(i)hr.exports=y;else for(C=0;C0===e.type?t++:a++));let e=new Uint8Array(a*this.Fr.n8+t*this.G1.F.n8*2),o=0;for(let t=0;t32768?new Pa(t.length*o.n8):new Uint8Array(t.length*o.n8);for(let a=0;a32768?new Pa(o*i.n8):new Uint8Array(o*i.n8);return n.set(t.coef.slice(),0),new Or(n,a,e)}isEqual(t){const a=this.degree();if(a!==t.degree())return!1;for(let e=0;e32768?new Pa((this.length()+t.length)*this.Fr.n8):new Uint8Array((this.length()+t.length)*this.Fr.n8);a.set(this.coef,0);for(let e=0;ethis.coef.byteLength?this.Fr.zero:this.coef.slice(a,a+this.Fr.n8)}setCoef(t,a){if(t>this.length()-1)throw new Error("Coef index is not available");this.coef.set(a,t*this.Fr.n8)}static async to4T(t,a,e,o){e=e||[];let i=await o.ifft(t);const n=4*a>32768?new Pa(4*a*o.n8):new Uint8Array(4*a*o.n8);n.set(i,0);const l=await o.fft(n);if(0===e.length)return[i,l];const c=a+e.length>32768?new Pa((a+e.length)*o.n8):new Uint8Array((a+e.length)*o.n8);c.set(i,0);for(let t=0;t0;t--){const a=t*this.Fr.n8;if(!this.Fr.eq(this.Fr.zero,this.coef.slice(a,a+this.Fr.n8)))return t}return 0}evaluate(t){let a=this.Fr.zero;for(let e=this.degree()+1;e>0;e--){let o=e*this.Fr.n8;const i=this.coef.slice(o-this.Fr.n8,o);a=this.Fr.add(i,this.Fr.mul(a,t))}return a}fastEvaluate(t){const a=this.Fr;let e=this.degree()+1,o=parseInt(e/3),i=e-3*o,n=[],l=[];l[0]=a.one;for(let e=0;e<3;e++){n[e]=a.zero;for(let c=2===e?o+i:o;c>0;c--)n[e]=a.add(this.getCoef(e*o+c-1),a.mul(n[e],t)),0===e&&(l[0]=a.mul(l[0],t))}for(let t=1;t<3;t++)n[0]=a.add(n[0],a.mul(l[t-1],n[t])),l[t]=a.mul(l[t-1],l[0]);return n[0]}add(t,a){let e=!1;t.length()>this.length()&&(e=!0);const o=this.length(),i=t.length();for(let n=0;nthis.length()&&(e=!0);const o=this.length(),i=t.length();for(let n=0;n32768?new Pa(e*a.n8):new Uint8Array(e*a.n8);let i=new Or(o,this.curve,this.logger);i.coef.set(this.coef.slice(0,(e-1)*a.n8),32),this.mulScalar(a.neg(t)),i.add(this),this.coef=i.coef}byXNSubValue(t,a){const e=this.Fr,o=!(this.length()-t-1>=this.degree())?this.length()+t:this.length(),i=o>32768?new Pa(o*e.n8):new Uint8Array(o*e.n8);let n=new Or(i,this.curve,this.logger);n.coef.set(this.coef.slice(0,32*(this.degree()+1)),32*t),this.mulScalar(a),n.add(this),this.coef=n.coef}divBy(t){const a=this.Fr,e=this.degree(),o=t.degree();let i=new Or(this.coef,this.curve,this.logger);this.coef=this.length()>32768?new Pa(this.length()*a.n8):new Uint8Array(this.length()*a.n8);for(let n=e-o;n>=0;n--){this.setCoef(n,a.div(i.getCoef(n+o),t.getCoef(o)));for(let e=0;e<=o;e++)i.setCoef(n+e,a.sub(i.getCoef(n+e),a.mul(this.getCoef(n),t.getCoef(e))))}return i}divByMonic(t,a){const e=this.Fr;let o=this.degree(),i=this.length()>32768?new Pa(this.length()*e.n8):new Uint8Array(this.length()*e.n8),n=new Or(i,this.curve,this.logger),l=[];for(let a=0;a=0&&!(s<0);s-=c){let o=i;l[o]=e.add(this.getCoef(s+t),e.mul(l[o],a)),n.setCoef(s,l[o])}this.coef=n.coef}divByVanishing(t,a){if(this.degree()32768?new Pa(this.length()*e.n8):new Uint8Array(this.length()*e.n8);for(let i=this.length()-1;i>=t;i--){let n=o.getCoef(i);e.eq(e.zero,n)||(o.setCoef(i,e.zero),o.setCoef(i-t,e.add(o.getCoef(i-t),e.mul(a,n))),this.setCoef(i-t,e.add(this.getCoef(i-t),n)))}return o}divByVanishing2(t,a){if(this.degree()32768?new Pa(this.length()*e.n8):new Uint8Array(this.length()*e.n8);let i=this.length()-t,n=Math.floor(i/3),l=i-2*n;console.log(i),console.log(n+" "+l);for(let i=0;i<3;i++){console.log("> Thread "+i);for(let c=0===i?l:n;c>0;c--){let s=c-1;0!==i&&(s+=(i-1)*n+l);let r=s+t,d=o.getCoef(r);e.eq(e.zero,d)||(o.setCoef(r,e.zero),o.setCoef(s,e.add(o.getCoef(s),e.mul(a,d))),this.setCoef(s,e.add(this.getCoef(s),d)),console.log(s+" <-- "+r))}}return this.print(),o}fastDivByVanishing(t){const a=this.Fr;for(let e=0;e32768?new Pa(this.length()*a.n8):new Uint8Array(this.length()*a.n8),this.curve,this.logger),u=this.coef;this.coef=d.coef,d.coef=u;for(let t=0;t0;t--){let e=t-1,i=e*s+r;f[e]=[];for(let l=0;l32768?new Pa(this.length()*this.Fr.n8):new Uint8Array(this.length()*this.Fr.n8);a.set(this.Fr.zero,(this.length()-1)*this.Fr.n8),a.set(this.coef.slice((this.length()-1)*this.Fr.n8,this.length()*this.Fr.n8),(this.length()-2)*this.Fr.n8);for(let e=this.length()-3;e>=0;e--){let o=e*this.Fr.n8;a.set(this.Fr.add(this.coef.slice(o+this.Fr.n8,o+2*this.Fr.n8),this.Fr.mul(t,a.slice(o+this.Fr.n8,o+2*this.Fr.n8))),e*this.Fr.n8)}if(!this.Fr.eq(this.coef.slice(0,this.Fr.n8),this.Fr.mul(this.Fr.neg(t),a.slice(0,this.Fr.n8))))throw new Error("Polynomial does not divide");this.coef=a}divZh(t,a=4){for(let a=0;at*(a-1)-a&&!this.Fr.isZero(i))throw new Error("Polynomial is not divisible")}return this}divByZerofier(t,a){let e=this.Fr;const o=e.inv(a),i=e.neg(o);let n=e.eq(e.one,i),l=e.eq(e.negone,i);if(!n)for(let a=0;athis.length()-t-1&&!this.Fr.isZero(s))throw new Error("Polynomial is not divisible")}return this}byX(){const t=this.length()+1>32768?new Pa(this.coef.byteLength+this.Fr.n8):new Uint8Array(this.coef.byteLength+this.Fr.n8);t.set(this.Fr.zero,0),t.set(this.coef,this.Fr.n8),this.coef=t}static async expX(t,a,e=!1){const o=t.Fr;if(a<1)throw new Error("Compute a new polynomial to a zero or negative number is not allowed");if(1===a)return await Or.fromEvaluations(t.coef,curve,t.logger);const i=e?t.degree():t.length()-1,n=i*a+1>32768?new Pa((i*a+1)*o.n8):new Uint8Array((i*a+1)*o.n8);n.set(t.getCoef(0),0);for(let e=1;e<=i;e++){const i=e*o.n8,l=t.getCoef(e);n.set(l,i*a)}return new Or(n,t.curve,t.logger)}split(t,a,e){if(t<1)throw new Error(`Polynomials can't be split in ${t} parts`);if(1===t)return[this];if(0!==e.length&&e.length32768?new Pa(l):new Uint8Array(l);i[a]=new Or(c,this.curve,this.logger);const s=a*o,r=n?this.coef.byteLength:(a+1)*o;if(i[a].coef.set(this.coef.slice(s,r),0),n||i[a].coef.set(e[a],o),0!==a){const t=this.Fr.sub(i[a].coef.slice(0,this.Fr.n8),e[a-1]);i[a].coef.set(t,0)}n&&i[a].truncate()}return i}truncate(){const t=this.degree();if(t+132768?new Pa((t+1)*this.Fr.n8):new Uint8Array((t+1)*this.Fr.n8);a.set(this.coef.slice(0,(t+1)*this.Fr.n8),0),this.coef=a}}static lagrangePolynomialInterpolation(t,a,e){const o=e.Fr;let i=n(0);for(let a=1;a32768?new Pa(t.length*o.n8):new Uint8Array(t.length*o.n8);n=new Or(i,e),n.setCoef(0,o.neg(t[a])),n.setCoef(1,o.one)}else n.byXSubValue(t[a]);let l=n.evaluate(t[i]);l=o.inv(l);const c=o.mul(a[i],l);return n.mulScalar(c),n}}static zerofierPolynomial(t,a){const e=a.Fr;let o=t.length+1>32768?new Pa((t.length+1)*e.n8):new Uint8Array((t.length+1)*e.n8),i=new Or(o,a);i.setCoef(0,e.neg(t[0])),i.setCoef(1,e.one);for(let a=1;a=0;e--){const o=this.getCoef(e);t.eq(t.zero,o)||(t.isNegative(o)?a+=" - ":e!==this.degree()&&(a+=" + "),a+=t.toString(o),e>0&&(a+=e>1?"x^"+e:"x"))}console.log(a)}async multiExponentiation(t,a){const e=this.coef.byteLength/this.Fr.n8,o=t.slice(0,e*this.G1.F.n8*2),i=await this.Fr.batchFromMontgomery(this.coef);let n=await this.G1.multiExpAffine(o,i,this.logger,a);return n=this.G1.toAffine(n),n}}class Gr{constructor(t,a,e){this.eval=t,this.curve=a,this.Fr=a.Fr,this.logger=e}static async fromPolynomial(t,a,e,o){const i=new Pa(t.length()*a*e.Fr.n8);i.set(t.coef,0);const n=await e.Fr.fft(i);return new Gr(n,e,o)}getEvaluation(t){const a=t*this.Fr.n8;if(a+this.Fr.n8>this.eval.byteLength)throw new Error("Evaluations.getEvaluation() out of bounds");return this.eval.slice(a,a+this.Fr.n8)}length(){let t=this.eval.byteLength/this.Fr.n8;if(t!==Math.floor(this.eval.byteLength/this.Fr.n8))throw new Error("Polynomial evaluations buffer has incorrect size");return 0===t&&this.logger.warn("Polynomial has length zero"),t}}const{stringifyBigInts:zr}=ge;async function Tr(t,a,e){const{fd:o,sections:i}=await Te(a,"wtns",2);e&&e.debug("> Reading witness file");const n=await Ii(o,i);e&&e.debug("> Reading zkey file");const{fd:l,sections:c}=await Te(t,"zkey",2),s=await bi(l,c);if("plonk"!=s.protocol)throw new Error("zkey file is not plonk");if(!_e.eq(s.r,n.q))throw new Error("Curve of the witness does not match the curve of the proving key");if(n.nWitness!=s.nVars-s.nAdditions)throw new Error(`Invalid witness length. Circuit: ${s.nVars}, witness: ${n.nWitness}, ${s.nAdditions}`);const r=s.curve,d=r.Fr,u=r.Fr.n8,_=s.domainSize*u;e&&(e.debug("----------------------------"),e.debug(" PLONK PROVE SETTINGS"),e.debug(` Curve: ${r.name}`),e.debug(` Circuit power: ${s.power}`),e.debug(` Domain size: ${s.domainSize}`),e.debug(` Vars: ${s.nVars}`),e.debug(` Public vars: ${s.nPublic}`),e.debug(` Constraints: ${s.nConstraints}`),e.debug(` Additions: ${s.nAdditions}`),e.debug("----------------------------")),e&&e.debug("> Reading witness file data");const g=await je(o,i,2);g.set(d.zero,0);const f=new Pa(u*s.nAdditions);let h={},p={},m={},L={},b=new fr(r,e);const w=new br(r);e&&e.debug(`> Reading Section ${yr}. Additions`),await async function(){e&&e.debug("··· Computing additions");const t=await je(l,c,yr),a=8+2*u;for(let o=0;o Reading Section ${Sr}. Sigma1, Sigma2 & Sigma 3`),e&&e.debug("··· Reading Sigma polynomials "),p.Sigma1=new Or(new Pa(_),r,e),p.Sigma2=new Or(new Pa(_),r,e),p.Sigma3=new Or(new Pa(_),r,e),await l.readToBuffer(p.Sigma1.coef,0,_,c[Sr][0].p),await l.readToBuffer(p.Sigma2.coef,0,_,c[Sr][0].p+5*_),await l.readToBuffer(p.Sigma3.coef,0,_,c[Sr][0].p+10*_),e&&e.debug("··· Reading Sigma evaluations"),m.Sigma1=new Gr(new Pa(4*_),r,e),m.Sigma2=new Gr(new Pa(4*_),r,e),m.Sigma3=new Gr(new Pa(4*_),r,e),await l.readToBuffer(m.Sigma1.eval,0,4*_,c[Sr][0].p+_),await l.readToBuffer(m.Sigma2.eval,0,4*_,c[Sr][0].p+6*_),await l.readToBuffer(m.Sigma3.eval,0,4*_,c[Sr][0].p+11*_),e&&e.debug(`> Reading Section ${qr}. Powers of Tau`);const y=await je(l,c,qr);let A=[];for(let t=1;t<=s.nPublic;t++){const a=g.slice(t*d.n8,t*d.n8+d.n8);A.push(_e.fromRprLE(a))}e&&e.debug(""),e&&e.debug("> ROUND 1"),await async function(){L.b=[];for(let t=1;t<=11;t++)L.b[t]=r.Fr.random();e&&e.debug("> Computing A, B, C wire polynomials");await async function(){e&&e.debug("··· Reading data from zkey file");h.A=new Pa(_),h.B=new Pa(_),h.C=new Pa(_);const t=await je(l,c,Ar),a=await je(l,c,Cr),o=await je(l,c,Fr);for(let e=0;e=s.domainSize+2)throw new Error("A Polynomial is not well calculated");if(p.B.degree()>=s.domainSize+2)throw new Error("B Polynomial is not well calculated");if(p.C.degree()>=s.domainSize+2)throw new Error("C Polynomial is not well calculated")}(),e&&e.debug("> Computing A, B, C MSM");let t=await p.A.multiExponentiation(y,"A"),a=await p.B.multiExponentiation(y,"B"),o=await p.C.multiExponentiation(y,"C");return b.addPolynomial("A",t),b.addPolynomial("B",a),b.addPolynomial("C",o),0}(),e&&e.debug("> ROUND 2"),await async function(){e&&e.debug("> Computing challenges beta and gamma");w.reset(),w.addPolCommitment(s.Qm),w.addPolCommitment(s.Ql),w.addPolCommitment(s.Qr),w.addPolCommitment(s.Qo),w.addPolCommitment(s.Qc),w.addPolCommitment(s.S1),w.addPolCommitment(s.S2),w.addPolCommitment(s.S3);for(let t=0;t Computing Z polynomial");await async function(){e&&e.debug("··· Computing Z evaluations");let t=new Pa(_),a=new Pa(_);t.set(d.one,0),a.set(d.one,0);let o=d.one;for(let e=0;e=s.domainSize+3)throw new Error("Z Polynomial is not well calculated");delete h.Z}(),e&&e.debug("> Computing Z MSM");let t=await p.Z.multiExponentiation(y,"Z");b.addPolynomial("Z",t)}(),e&&e.debug("> ROUND 3"),await async function(){e&&e.debug("> Computing challenge alpha");w.reset(),w.addScalar(L.beta),w.addScalar(L.gamma),w.addPolCommitment(b.getPolynomial("Z")),L.alpha=w.getChallenge(),L.alpha2=d.square(L.alpha),e&&e.debug("··· challenges.alpha: "+d.toString(L.alpha,16));e&&e.debug("> Computing T polynomial");await async function(){e&&e.debug(`··· Reading sections ${Ir}, ${Br}, ${xr}, ${Er}, ${vr}. Q selectors`);m.QL=new Gr(new Pa(4*_),r,e),m.QR=new Gr(new Pa(4*_),r,e),m.QM=new Gr(new Pa(4*_),r,e),m.QO=new Gr(new Pa(4*_),r,e),m.QC=new Gr(new Pa(4*_),r,e),await l.readToBuffer(m.QL.eval,0,4*_,c[Ir][0].p+_),await l.readToBuffer(m.QR.eval,0,4*_,c[Br][0].p+_),await l.readToBuffer(m.QM.eval,0,4*_,c[xr][0].p+_),await l.readToBuffer(m.QO.eval,0,4*_,c[Er][0].p+_),await l.readToBuffer(m.QC.eval,0,4*_,c[vr][0].p+_),m.Lagrange=new Gr(new Pa(4*_*s.nPublic),r,e);for(let t=0;t=3*s.domainSize+6)throw new Error("T Polynomial is not well calculated");e&&e.debug("··· Computing T1, T2, T3 polynomials");p.T1=new Or(new Pa((s.domainSize+1)*u),r,e),p.T2=new Or(new Pa((s.domainSize+1)*u),r,e),p.T3=new Or(new Pa((s.domainSize+6)*u),r,e),p.T1.coef.set(p.T.coef.slice(0,_),0),p.T2.coef.set(p.T.coef.slice(_,2*_),0),p.T3.coef.set(p.T.coef.slice(2*_,3*_+6*u),0),p.T1.setCoef(s.domainSize,L.b[10]);const a=d.sub(p.T2.getCoef(0),L.b[10]);p.T2.setCoef(0,a),p.T2.setCoef(s.domainSize,L.b[11]);const o=d.sub(p.T3.getCoef(0),L.b[11]);p.T3.setCoef(0,o)}(),e&&e.debug("> Computing T MSM");let t=await p.T1.multiExponentiation(y,"T1"),a=await p.T2.multiExponentiation(y,"T2"),o=await p.T3.multiExponentiation(y,"T3");b.addPolynomial("T1",t),b.addPolynomial("T2",a),b.addPolynomial("T3",o)}(),e&&e.debug("> ROUND 4"),await async function(){e&&e.debug("> Computing challenge xi");w.reset(),w.addScalar(L.alpha),w.addPolCommitment(b.getPolynomial("T1")),w.addPolCommitment(b.getPolynomial("T2")),w.addPolCommitment(b.getPolynomial("T3")),L.xi=w.getChallenge(),L.xiw=d.mul(L.xi,d.w[s.power]),e&&e.debug("··· challenges.xi: "+d.toString(L.xi,16));b.addEvaluation("eval_a",p.A.evaluate(L.xi)),b.addEvaluation("eval_b",p.B.evaluate(L.xi)),b.addEvaluation("eval_c",p.C.evaluate(L.xi)),b.addEvaluation("eval_s1",p.Sigma1.evaluate(L.xi)),b.addEvaluation("eval_s2",p.Sigma2.evaluate(L.xi)),b.addEvaluation("eval_zw",p.Z.evaluate(L.xiw))}(),e&&e.debug("> ROUND 5"),await async function(){e&&e.debug("> Computing challenge v");w.reset(),w.addScalar(L.xi),w.addScalar(b.getEvaluation("eval_a")),w.addScalar(b.getEvaluation("eval_b")),w.addScalar(b.getEvaluation("eval_c")),w.addScalar(b.getEvaluation("eval_s1")),w.addScalar(b.getEvaluation("eval_s2")),w.addScalar(b.getEvaluation("eval_zw")),L.v=[],L.v[1]=w.getChallenge(),e&&e.debug("··· challenges.v: "+d.toString(L.v[1],16));for(let t=2;t<6;t++)L.v[t]=d.mul(L.v[t-1],L.v[1]);e&&e.debug("> Computing linearisation polynomial R(X)");await async function(){const t=r.Fr;p.QL=new Or(new Pa(_),r,e),p.QR=new Or(new Pa(_),r,e),p.QM=new Or(new Pa(_),r,e),p.QO=new Or(new Pa(_),r,e),p.QC=new Or(new Pa(_),r,e),await l.readToBuffer(p.QL.coef,0,_,c[Ir][0].p),await l.readToBuffer(p.QR.coef,0,_,c[Br][0].p),await l.readToBuffer(p.QM.coef,0,_,c[xr][0].p),await l.readToBuffer(p.QO.coef,0,_,c[Er][0].p),await l.readToBuffer(p.QC.coef,0,_,c[vr][0].p),L.xin=L.xi;for(let a=0;a Computing opening proof polynomial Wxi(X) polynomial");p.Wxi=new Or(new Pa(_+6*u),r,e),p.Wxi.add(p.R),p.Wxi.add(p.A,L.v[1]),p.Wxi.add(p.B,L.v[2]),p.Wxi.add(p.C,L.v[3]),p.Wxi.add(p.Sigma1,L.v[4]),p.Wxi.add(p.Sigma2,L.v[5]),p.Wxi.subScalar(d.mul(L.v[1],b.evaluations.eval_a)),p.Wxi.subScalar(d.mul(L.v[2],b.evaluations.eval_b)),p.Wxi.subScalar(d.mul(L.v[3],b.evaluations.eval_c)),p.Wxi.subScalar(d.mul(L.v[4],b.evaluations.eval_s1)),p.Wxi.subScalar(d.mul(L.v[5],b.evaluations.eval_s2)),void p.Wxi.divByZerofier(1,L.xi),e&&e.debug("> Computing opening proof polynomial Wxiw(X) polynomial");(async function(){p.Wxiw=Or.fromPolynomial(p.Z,r,e),p.Wxiw.subScalar(b.evaluations.eval_zw),p.Wxiw.divByZerofier(1,L.xiw)})(),e&&e.debug("> Computing Wxi, Wxiw MSM");let t=await p.Wxi.multiExponentiation(y,"Wxi"),a=await p.Wxiw.multiExponentiation(y,"Wxiw");b.addPolynomial("Wxi",t),b.addPolynomial("Wxiw",a)}(),await l.close(),await o.close();let C=b.toObjectProof(!1);return C.protocol="plonk",C.curve=r.name,e&&e.debug("PLONK PROVER FINISHED"),{proof:zr(C),publicSignals:zr(A)};function F(t,a){const e=t.slice(a,a+4);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(0,!0)}function x(t){return te;){const a=i.shift(),e=i.shift(),o=a[0],n=e[0],l=L++,c=t.zero,s=t.neg(a[1]),r=t.neg(e[1]),d=t.one,u=t.zero;p.push([o,n,l,c,s,r,d,u]),m.push([o,n,a[1],e[1]]),i.push([l,t.one])}for(let t=0;t0?o.toString():e!=t.zero?"k":"0"}function s(a,e,s){const r=c(a),d=c(e);if("0"===r||"0"===d)o(s),l(s);else if("k"===r){l(i(e,a[0],s))}else if("k"===d){l(i(a,e[0],s))}else!function(a,e,o){const i=n(a,1),l=n(e,1),c=n(o,1),s=i.s[0],r=l.s[0],d=c.s[0],u=t.mul(i.coefs[0],l.coefs[0]),_=t.mul(i.coefs[0],l.k),g=t.mul(i.k,l.coefs[0]),f=t.neg(c.coefs[0]),h=t.sub(t.mul(i.k,l.k),c.k);p.push([s,r,d,u,_,g,f,h])}(a,e,s)}for(let a=1;a<=b;a++){const e=a,o=0,i=0,n=t.zero,l=t.one,c=t.zero,s=t.zero,r=t.zero;p.push([e,o,i,n,l,c,s,r])}for(let t=0;tc)return o&&o.error(`circuit too big for this power of tau ceremony. ${p.length} > 2**${c}`),-1;if(!n[12])return o&&o.error("Powers of tau is not prepared."),-1;const C=new Pa(A*u),F=n[12][0].p+(2**y-1)*u;await i.readToBuffer(C,0,A*u,F);const[x,I]=function(){let t=f.two;for(;e(t,[],y);)f.add(t,f.one);let a=f.add(t,f.one);for(;e(a,[t],y);)f.add(a,f.one);return[t,a];function e(t,a,e){const o=2**e;let i=f.one;for(let n=0;n0?2:this.Fr.isZero(a)?0:1}normalizeLinearCombination(t){const a=Object.keys(t);for(let e=0;ei;){const o=l.shift(),i=l.shift(),n=t.nVars++,c=this.fnGetAdditionConstraint(o[0],i[0],n,this.Fr.neg(o[1]),this.Fr.neg(i[1]),this.Fr.zero,this.Fr.one,this.Fr.zero);a.push(c),e.push([o[0],i[0],o[1],i[1]]),l.push([n,this.Fr.one])}for(let t=0;tthis.n-1)throw new Error("CPolynomial:addPolynomial, cannot add a polynomial to a position greater than n-1");this.polynomials[t]=a}degree(){let t=this.polynomials.map(((t,a)=>void 0===t?0:t.degree()*this.n+a));return Math.max(...t)}getPolynomial(){let t=this.polynomials.map((t=>void 0===t?0:t.degree()));const a=this.degree(),e=2**(To(a-1)+1),o=this.Fr.n8;let i=new Or(new Pa(e*o),this.curve,this.logger);for(let e=0;e Reading witness file");const{fd:o,sections:i}=await Te(a,"wtns",2),n=await Ii(o,i);e&&e.info("> Reading zkey file");const{fd:l,sections:c}=await Te(t,"zkey",2),s=await bi(l,c);if(s.protocolId!==Yo)throw new Error("zkey file is not fflonk");if(!_e.eq(s.r,n.q))throw new Error("Curve of the witness does not match the curve of the proving key");if(n.nWitness!==s.nVars-s.nAdditions)throw new Error(`Invalid witness length. Circuit: ${s.nVars}, witness: ${n.nWitness}, ${s.nAdditions}`);const r=s.curve,d=r.Fr,u=r.Fr.n8,_=2*r.G1.F.n8,g=s.domainSize*u;e&&(e.info("----------------------------"),e.info(" FFLONK PROVE SETTINGS"),e.info(` Curve: ${r.name}`),e.info(` Circuit power: ${s.power}`),e.info(` Domain size: ${s.domainSize}`),e.info(` Vars: ${s.nVars}`),e.info(` Public vars: ${s.nPublic}`),e.info(` Constraints: ${s.nConstraints}`),e.info(` Additions: ${s.nAdditions}`),e.info("----------------------------")),e&&e.info("> Reading witness file data");const f=await je(o,i,2);await o.close(),f.set(d.zero,0);const h=new Pa(s.nAdditions*u);let p={},m={},L={},b={},w={},y={},A=new fr(r,e);e&&e.info(`> Reading Section ${Xo}. Additions`),await async function(){e&&e.info("··· Computing additions");const t=await je(l,c,Xo),a=8+2*u;for(let o=0;o Reading Sections ${si},${ri},${di}. Sigma1, Sigma2 & Sigma 3`),e&&e.info("··· Reading Sigma polynomials "),m.Sigma1=new Or(new Pa(g),r,e),m.Sigma2=new Or(new Pa(g),r,e),m.Sigma3=new Or(new Pa(g),r,e),await l.readToBuffer(m.Sigma1.coef,0,g,c[si][0].p),await l.readToBuffer(m.Sigma2.coef,0,g,c[ri][0].p),await l.readToBuffer(m.Sigma3.coef,0,g,c[di][0].p),e&&e.info("··· Reading Sigma evaluations"),L.Sigma1=new Gr(new Pa(4*g),r,e),L.Sigma2=new Gr(new Pa(4*g),r,e),L.Sigma3=new Gr(new Pa(4*g),r,e),await l.readToBuffer(L.Sigma1.eval,0,4*g,c[si][0].p+g),await l.readToBuffer(L.Sigma2.eval,0,4*g,c[ri][0].p+g),await l.readToBuffer(L.Sigma3.eval,0,4*g,c[di][0].p+g),e&&e.info(`> Reading Section ${_i}. Powers of Tau`);const C=new Pa(16*s.domainSize*_);await l.readToBuffer(C,0,(9*s.domainSize+18)*_,c[_i][0].p),globalThis.gc&&globalThis.gc(),e&&e.info(""),e&&e.info("> ROUND 1"),await async function(){w.b=[];for(let t=1;t<=9;t++)w.b[t]=d.random();e&&e.info("> Computing A, B, C wire polynomials");await async function(){e&&e.info("··· Reading data from zkey file");p.A=new Pa(g),p.B=new Pa(g),p.C=new Pa(g);const t=await je(l,c,ti),a=await je(l,c,ai),o=await je(l,c,ei);for(let e=0;e=s.domainSize)throw new Error("A Polynomial is not well calculated");if(m.B.degree()>=s.domainSize)throw new Error("B Polynomial is not well calculated");if(m.C.degree()>=s.domainSize)throw new Error("C Polynomial is not well calculated")}(),e&&e.info("> Computing T0 polynomial");await async function(){e&&e.info(`··· Reading sections ${oi}, ${ii}, ${ni}, ${li}, ${ci}. Q selectors`);L.QL=new Gr(new Pa(4*g),r,e),L.QR=new Gr(new Pa(4*g),r,e),L.QM=new Gr(new Pa(4*g),r,e),L.QO=new Gr(new Pa(4*g),r,e),L.QC=new Gr(new Pa(4*g),r,e),await l.readToBuffer(L.QL.eval,0,4*g,c[oi][0].p+g),await l.readToBuffer(L.QR.eval,0,4*g,c[ii][0].p+g),await l.readToBuffer(L.QM.eval,0,4*g,c[ni][0].p+g),await l.readToBuffer(L.QO.eval,0,4*g,c[li][0].p+g),await l.readToBuffer(L.QC.eval,0,4*g,c[ci][0].p+g);const t=await je(l,c,ui);L.lagrange1=new Gr(t,r,e),p.T0=new Pa(4*g),e&&e.info("··· Computing T0 evaluations");for(let t=0;t<4*s.domainSize;t++){e&&0!==t&&t%1e5==0&&e.info(` T0 evaluation ${t}/${4*s.domainSize}`);const a=L.A.getEvaluation(t),o=L.B.getEvaluation(t),i=L.C.getEvaluation(t),n=L.QL.getEvaluation(t),l=L.QR.getEvaluation(t),c=L.QM.getEvaluation(t),r=L.QO.getEvaluation(t),_=L.QC.getEvaluation(t);let g=d.zero;for(let a=0;a=2*s.domainSize-2)throw new Error(`T0 Polynomial is not well calculated (degree is ${m.T0.degree()} and must be less than ${2*s.domainSize+2}`);delete p.T0}(),e&&e.info("> Computing C1 polynomial");await async function(){let t=new Vr(4,r,e);if(t.addPolynomial(0,m.A),t.addPolynomial(1,m.B),t.addPolynomial(2,m.C),t.addPolynomial(3,m.T0),m.C1=t.getPolynomial(),m.C1.degree()>=8*s.domainSize-8)throw new Error("C1 Polynomial is not well calculated")}(),e&&e.info("> Computing C1 multi exponentiation");let t=await m.C1.multiExponentiation(C,"C1");return A.addPolynomial("C1",t),0}(),delete m.T0,delete L.QL,delete L.QR,delete L.QM,delete L.QO,delete L.QC,globalThis.gc&&globalThis.gc(),e&&e.info("> ROUND 2"),await async function(){e&&e.info("> Computing challenges beta and gamma");const t=new br(r);t.addPolCommitment(s.C0);for(let a=0;a Computing Z polynomial");await async function(){e&&e.info("··· Computing Z evaluations");let t=new Pa(g),a=new Pa(g);t.set(d.one,0),a.set(d.one,0);let o=d.one;for(let i=0;i=s.domainSize+3)throw new Error("Z Polynomial is not well calculated");delete p.Z}(),e&&e.info("> Computing T1 polynomial");await async function(){e&&e.info("··· Computing T1 evaluations");p.T1=new Pa(2*g),p.T1z=new Pa(2*g);let t=d.one;for(let a=0;a<2*s.domainSize;a++){e&&0!==a&&a%1e5==0&&e.info(` T1 evaluation ${a}/${4*s.domainSize}`);const o=d.square(t),i=L.Z.getEvaluation(2*a),n=d.add(d.add(d.mul(w.b[7],o),d.mul(w.b[8],t)),w.b[9]),l=L.lagrange1.getEvaluation(s.domainSize+2*a);let c=d.mul(d.sub(i,d.one),l),r=d.mul(n,l);p.T1.set(c,a*u),p.T1z.set(r,a*u),t=d.mul(t,d.w[s.power+1])}e&&e.info("··· Computing T1 ifft");m.T1=await Or.fromEvaluations(p.T1,r,e),m.T1.divByZerofier(s.domainSize,d.one),e&&e.info("··· Computing T1z ifft");if(m.T1z=await Or.fromEvaluations(p.T1z,r,e),m.T1.add(m.T1z),m.T1.degree()>=s.domainSize+2)throw new Error("T1 Polynomial is not well calculated");delete p.T1,delete p.T1z,delete m.T1z}(),e&&e.info("> Computing T2 polynomial");await async function(){e&&e.info("··· Computing T2 evaluations");p.T2=new Pa(4*g),p.T2z=new Pa(4*g);let t=d.one;for(let a=0;a<4*s.domainSize;a++){e&&0!==a&&a%1e5==0&&e.info(` T2 evaluation ${a}/${4*s.domainSize}`);const o=d.square(t),i=d.mul(t,d.w[s.power]),n=d.square(i),l=L.A.getEvaluation(a),c=L.B.getEvaluation(a),r=L.C.getEvaluation(a),_=L.Z.getEvaluation(a),g=L.Z.getEvaluation((4*s.domainSize+4+a)%(4*s.domainSize)),f=d.add(d.add(d.mul(w.b[7],o),d.mul(w.b[8],t)),w.b[9]),h=d.add(d.add(d.mul(w.b[7],n),d.mul(w.b[8],i)),w.b[9]),m=L.Sigma1.getEvaluation(a),b=L.Sigma2.getEvaluation(a),y=L.Sigma3.getEvaluation(a),A=d.mul(w.beta,t);let C=d.add(l,A);C=d.add(C,w.gamma);let F=d.add(c,d.mul(A,s.k1));F=d.add(F,w.gamma);let x=d.add(r,d.mul(A,s.k2));x=d.add(x,w.gamma);let I=d.mul(d.mul(d.mul(C,F),x),_),B=d.mul(d.mul(d.mul(C,F),x),f),E=d.add(l,d.mul(w.beta,m));E=d.add(E,w.gamma);let v=d.add(c,d.mul(w.beta,b));v=d.add(v,w.gamma);let S=d.add(r,d.mul(w.beta,y));S=d.add(S,w.gamma);let P=d.mul(d.mul(d.mul(E,v),S),g),q=d.mul(d.mul(d.mul(E,v),S),h),O=d.sub(I,P),G=d.sub(B,q);p.T2.set(O,a*u),p.T2z.set(G,a*u),t=d.mul(t,d.w[s.power+2])}e&&e.info("··· Computing T2 ifft");m.T2=await Or.fromEvaluations(p.T2,r,e),e&&e.info("··· Computing T2 / ZH");m.T2.divByZerofier(s.domainSize,d.one),e&&e.info("··· Computing T2z ifft");if(m.T2z=await Or.fromEvaluations(p.T2z,r,e),m.T2.add(m.T2z),m.T2.degree()>=3*s.domainSize)throw new Error("T2 Polynomial is not well calculated");delete p.T2,delete p.T2z,delete m.T2z}(),e&&e.info("> Computing C2 polynomial");await async function(){let t=new Vr(3,r,e);if(t.addPolynomial(0,m.Z),t.addPolynomial(1,m.T1),t.addPolynomial(2,m.T2),m.C2=t.getPolynomial(),m.C2.degree()>=9*s.domainSize)throw new Error("C2 Polynomial is not well calculated")}(),e&&e.info("> Computing C2 multi exponentiation");let a=await m.C2.multiExponentiation(C,"C2");return A.addPolynomial("C2",a),0}(),delete p.A,delete p.B,delete p.C,delete L.A,delete L.B,delete L.C,delete L.Sigma1,delete L.Sigma2,delete L.Sigma3,delete L.lagrange1,delete L.Z,globalThis.gc&&globalThis.gc(),e&&e.info("> ROUND 3"),await async function(){e&&e.info("> Computing challenge xi");const t=new br(r);t.addScalar(w.gamma),t.addPolCommitment(A.getPolynomial("C2")),w.xiSeed=t.getChallenge();const a=d.square(w.xiSeed);y.w8=[],y.w8[0]=d.one;for(let t=1;t<8;t++)y.w8[t]=d.mul(y.w8[t-1],s.w8);y.w4=[],y.w4[0]=d.one;for(let t=1;t<4;t++)y.w4[t]=d.mul(y.w4[t-1],s.w4);y.w3=[],y.w3[0]=d.one,y.w3[1]=s.w3,y.w3[2]=d.square(s.w3),y.S0={},y.S0.h0w8=[],y.S0.h0w8[0]=d.mul(a,w.xiSeed);for(let t=1;t<8;t++)y.S0.h0w8[t]=d.mul(y.S0.h0w8[0],y.w8[t]);y.S1={},y.S1.h1w4=[],y.S1.h1w4[0]=d.square(y.S0.h0w8[0]);for(let t=1;t<4;t++)y.S1.h1w4[t]=d.mul(y.S1.h1w4[0],y.w4[t]);y.S2={},y.S2.h2w3=[],y.S2.h2w3[0]=d.mul(y.S1.h1w4[0],a),y.S2.h2w3[1]=d.mul(y.S2.h2w3[0],y.w3[1]),y.S2.h2w3[2]=d.mul(y.S2.h2w3[0],y.w3[2]),y.S2.h3w3=[],y.S2.h3w3[0]=d.mul(y.S2.h2w3[0],s.wr),y.S2.h3w3[1]=d.mul(y.S2.h3w3[0],y.w3[1]),y.S2.h3w3[2]=d.mul(y.S2.h3w3[0],y.w3[2]),w.xi=d.mul(d.square(y.S2.h2w3[0]),y.S2.h2w3[0]),e&&e.info("··· challenges.xi: "+d.toString(w.xi));m.QL=new Or(new Pa(g),r,e),m.QR=new Or(new Pa(g),r,e),m.QM=new Or(new Pa(g),r,e),m.QO=new Or(new Pa(g),r,e),m.QC=new Or(new Pa(g),r,e),await l.readToBuffer(m.QL.coef,0,g,c[oi][0].p),await l.readToBuffer(m.QR.coef,0,g,c[ii][0].p),await l.readToBuffer(m.QM.coef,0,g,c[ni][0].p),await l.readToBuffer(m.QO.coef,0,g,c[li][0].p),await l.readToBuffer(m.QC.coef,0,g,c[ci][0].p),e&&e.info("··· Computing evaluations");A.addEvaluation("ql",m.QL.evaluate(w.xi)),A.addEvaluation("qr",m.QR.evaluate(w.xi)),A.addEvaluation("qm",m.QM.evaluate(w.xi)),A.addEvaluation("qo",m.QO.evaluate(w.xi)),A.addEvaluation("qc",m.QC.evaluate(w.xi)),A.addEvaluation("s1",m.Sigma1.evaluate(w.xi)),A.addEvaluation("s2",m.Sigma2.evaluate(w.xi)),A.addEvaluation("s3",m.Sigma3.evaluate(w.xi)),A.addEvaluation("a",m.A.evaluate(w.xi)),A.addEvaluation("b",m.B.evaluate(w.xi)),A.addEvaluation("c",m.C.evaluate(w.xi)),A.addEvaluation("z",m.Z.evaluate(w.xi)),w.xiw=d.mul(w.xi,d.w[s.power]),A.addEvaluation("zw",m.Z.evaluate(w.xiw)),A.addEvaluation("t1w",m.T1.evaluate(w.xiw)),A.addEvaluation("t2w",m.T2.evaluate(w.xiw))}(),delete m.A,delete m.B,delete m.C,delete m.Z,delete m.T1,delete m.T2,delete m.Sigma1,delete m.Sigma2,delete m.Sigma3,delete m.QL,delete m.QR,delete m.QM,delete m.QC,delete m.QO,globalThis.gc&&globalThis.gc(),e&&e.info("> ROUND 4"),await async function(){e&&e.info("> Computing challenge alpha");const t=new br(r);t.addScalar(w.xiSeed),t.addScalar(A.getEvaluation("ql")),t.addScalar(A.getEvaluation("qr")),t.addScalar(A.getEvaluation("qm")),t.addScalar(A.getEvaluation("qo")),t.addScalar(A.getEvaluation("qc")),t.addScalar(A.getEvaluation("s1")),t.addScalar(A.getEvaluation("s2")),t.addScalar(A.getEvaluation("s3")),t.addScalar(A.getEvaluation("a")),t.addScalar(A.getEvaluation("b")),t.addScalar(A.getEvaluation("c")),t.addScalar(A.getEvaluation("z")),t.addScalar(A.getEvaluation("zw")),t.addScalar(A.getEvaluation("t1w")),t.addScalar(A.getEvaluation("t2w")),w.alpha=t.getChallenge(),e&&e.info("··· challenges.alpha: "+d.toString(w.alpha));e&&e.info("> Reading C0 polynomial");m.C0=new Or(new Pa(8*g),r,e),await l.readToBuffer(m.C0.coef,0,8*g,c[gi][0].p),e&&e.info("> Computing R0 polynomial");(function(){if(m.R0=Or.lagrangePolynomialInterpolation([y.S0.h0w8[0],y.S0.h0w8[1],y.S0.h0w8[2],y.S0.h0w8[3],y.S0.h0w8[4],y.S0.h0w8[5],y.S0.h0w8[6],y.S0.h0w8[7]],[m.C0.evaluate(y.S0.h0w8[0]),m.C0.evaluate(y.S0.h0w8[1]),m.C0.evaluate(y.S0.h0w8[2]),m.C0.evaluate(y.S0.h0w8[3]),m.C0.evaluate(y.S0.h0w8[4]),m.C0.evaluate(y.S0.h0w8[5]),m.C0.evaluate(y.S0.h0w8[6]),m.C0.evaluate(y.S0.h0w8[7])],r),m.R0.degree()>7)throw new Error("R0 Polynomial is not well calculated")})(),e&&e.info("> Computing R1 polynomial");(function(){if(m.R1=Or.lagrangePolynomialInterpolation([y.S1.h1w4[0],y.S1.h1w4[1],y.S1.h1w4[2],y.S1.h1w4[3]],[m.C1.evaluate(y.S1.h1w4[0]),m.C1.evaluate(y.S1.h1w4[1]),m.C1.evaluate(y.S1.h1w4[2]),m.C1.evaluate(y.S1.h1w4[3])],r),m.R1.degree()>3)throw new Error("R1 Polynomial is not well calculated")})(),e&&e.info("> Computing R2 polynomial");(function(){if(m.R2=Or.lagrangePolynomialInterpolation([y.S2.h2w3[0],y.S2.h2w3[1],y.S2.h2w3[2],y.S2.h3w3[0],y.S2.h3w3[1],y.S2.h3w3[2]],[m.C2.evaluate(y.S2.h2w3[0]),m.C2.evaluate(y.S2.h2w3[1]),m.C2.evaluate(y.S2.h2w3[2]),m.C2.evaluate(y.S2.h3w3[0]),m.C2.evaluate(y.S2.h3w3[1]),m.C2.evaluate(y.S2.h3w3[2])],r),m.R2.degree()>5)throw new Error("R2 Polynomial is not well calculated")})(),e&&e.info("> Computing F polynomial");await async function(){e&&e.info("··· Computing F polynomial");m.F=Or.fromPolynomial(m.C0,r,e),m.F.sub(m.R0),m.F.divByZerofier(8,w.xi);let t=Or.fromPolynomial(m.C1,r,e);t.sub(m.R1),t.mulScalar(w.alpha),t.divByZerofier(4,w.xi);let a=Or.fromPolynomial(m.C2,r,e);if(a.sub(m.R2),a.mulScalar(d.square(w.alpha)),a.divByZerofier(3,w.xi),a.divByZerofier(3,w.xiw),m.F.add(t),m.F.add(a),m.F.degree()>=9*s.domainSize-6)throw new Error("F Polynomial is not well calculated")}(),e&&e.info("> Computing W1 multi exponentiation");let a=await m.F.multiExponentiation(C,"W1");return A.addPolynomial("W1",a),0}(),globalThis.gc&&globalThis.gc(),e&&e.info("> ROUND 5"),await async function(){e&&e.info("> Computing challenge y");const t=new br(r);t.addScalar(w.alpha),t.addPolCommitment(A.getPolynomial("W1")),w.y=t.getChallenge(),e&&e.info("··· challenges.y: "+d.toString(w.y));e&&e.info("> Computing L polynomial");await async function(){e&&e.info("··· Computing L polynomial");const t=m.R0.evaluate(w.y),a=m.R1.evaluate(w.y),o=m.R2.evaluate(w.y);let i=d.sub(w.y,y.S0.h0w8[0]);for(let t=1;t<8;t++)i=d.mul(i,d.sub(w.y,y.S0.h0w8[t]));let n=d.sub(w.y,y.S1.h1w4[0]);for(let t=1;t<4;t++)n=d.mul(n,d.sub(w.y,y.S1.h1w4[t]));let l=d.sub(w.y,y.S2.h2w3[0]);for(let t=1;t<3;t++)l=d.mul(l,d.sub(w.y,y.S2.h2w3[t]));for(let t=0;t<3;t++)l=d.mul(l,d.sub(w.y,y.S2.h3w3[t]));let c=d.mul(n,l),u=d.mul(w.alpha,d.mul(i,l)),_=d.mul(d.square(w.alpha),d.mul(i,n));b.denH1=n,b.denH2=l,m.L=Or.fromPolynomial(m.C0,r,e),m.L.subScalar(t),m.L.mulScalar(c);let g=Or.fromPolynomial(m.C1,r,e);g.subScalar(a),g.mulScalar(u);let f=Or.fromPolynomial(m.C2,r,e);f.subScalar(o),f.mulScalar(_),m.L.add(g),m.L.add(f),e&&e.info("> Computing ZT polynomial");await async function(){m.ZT=Or.zerofierPolynomial([y.S0.h0w8[0],y.S0.h0w8[1],y.S0.h0w8[2],y.S0.h0w8[3],y.S0.h0w8[4],y.S0.h0w8[5],y.S0.h0w8[6],y.S0.h0w8[7],y.S1.h1w4[0],y.S1.h1w4[1],y.S1.h1w4[2],y.S1.h1w4[3],y.S2.h2w3[0],y.S2.h2w3[1],y.S2.h2w3[2],y.S2.h3w3[0],y.S2.h3w3[1],y.S2.h3w3[2]],r)}();const h=m.ZT.evaluate(w.y);if(m.F.mulScalar(h),m.L.sub(m.F),m.L.degree()>=9*s.domainSize)throw new Error("L Polynomial is not well calculated");delete p.L}(),e&&e.info("> Computing ZTS2 polynomial");await async function(){m.ZTS2=Or.zerofierPolynomial([y.S1.h1w4[0],y.S1.h1w4[1],y.S1.h1w4[2],y.S1.h1w4[3],y.S2.h2w3[0],y.S2.h2w3[1],y.S2.h2w3[2],y.S2.h3w3[0],y.S2.h3w3[1],y.S2.h3w3[2]],r)}();let a=m.ZTS2.evaluate(w.y);a=d.inv(a),m.L.mulScalar(a);const o=Or.fromCoefficientsArray([d.neg(w.y),d.one],r);e&&e.info("> Computing W' = L / ZTS2 polynomial");const i=m.L.divBy(o);if(i.degree()>0)throw new Error(`Degree of L(X)/(ZTS2(y)(X-y)) remainder is ${i.degree()} and should be 0`);if(m.L.degree()>=9*s.domainSize-1)throw new Error("Degree of L(X)/(ZTS2(y)(X-y)) is not correct");e&&e.info("> Computing W' multi exponentiation");let n=await m.L.multiExponentiation(C,"W2");return A.addPolynomial("W2",n),0}(),delete m.C0,delete m.C1,delete m.C2,delete m.R1,delete m.R2,delete m.F,delete m.L,delete m.ZT,delete m.ZTS2,await l.close(),globalThis.gc&&globalThis.gc(),A.addEvaluation("inv",function(){let t=w.xi;for(let a=0;a Reading PTau file");const{fd:i,sections:n}=await Te(a,"ptau",1);if(!n[12])throw new Error("Powers of Tau is not well prepared. Section 12 missing.");o&&o.info("> Getting curve from PTau settings");const{curve:l}=await bc(i,n);o&&o.info("> Reading r1cs file");const{fd:c,sections:s}=await Te(t,"r1cs",1),r=await Vs(c,s,{loadConstraints:!1,loadCustomGates:!0});if(r.prime!==l.r)throw new Error("r1cs curve does not match powers of tau ceremony curve");const d=l.Fr,u=l.Fr.n8,_=2*l.G1.F.n8,g=2*l.G2.F.n8;let f,h={},p={},m={nVars:r.nVars,nPublic:r.nOutputs+r.nPubInputs};const L=new or;let b=new or;if(o&&o.info("> Processing FFlonk constraints"),await async function(t,a,e){for(let a=0;a computing k1 and k2");const[w,y]=function(){let t=d.two;for(;e(t,[],m.cirPower);)d.add(t,d.one);let a=d.add(t,d.one);for(;e(a,[t],m.cirPower);)d.add(a,d.one);return[t,a];function e(t,a,e){const o=2**e;let i=d.one;for(let n=0;n computing w3");const A=function(){let t=d.e(31624),a=_e.div(3648040478639879203707734290876212514758060733402672390616367364429301415936n,_e.e(3));return d.exp(t,a)}();o&&o.info("> computing w4");const C=d.w[2];o&&o.info("> computing w8");const F=d.w[3];o&&o.info("> computing wr");const x=function(t,a){const e=a.e(467799165886069610036046866799264026481344299079011762026774533774345988080n);return a.exp(e,2**(28-t))}(m.cirPower,l.Fr);return await async function(){o&&o.info("> Writing the zkey file");const t=await Me(e,"zkey",1,17,1<<22,1<<24);o&&o.info("··· Writing Section 1. Zkey Header");await async function(t){await Ue(t,1),await t.writeULE32(Yo),await Qe(t)}(t),o&&o.info(`··· Writing Section ${Xo}. Additions`);await async function(t){await Ue(t,Xo);const a=new Uint8Array(8+2*u),e=new DataView(a.buffer);for(let i=0;i=8*m.domainSize)throw new Error("C0 Polynomial is not well calculated");await Ue(t,gi),await t.write(h.C0.coef),await Qe(t)}(t),globalThis.gc&&globalThis.gc();o&&o.info(`··· Writing Section ${Jo}. FFlonk Header`);await async function(t){await Ue(t,Jo);const a=l.q,e=8*(Math.floor((_e.bitLength(a)-1)/64)+1);await t.writeULE32(e),await Ne(t,a,e);const o=l.r,c=8*(Math.floor((_e.bitLength(o)-1)/64)+1);let s;await t.writeULE32(c),await Ne(t,o,c),await t.writeULE32(m.nVars),await t.writeULE32(m.nPublic),await t.writeULE32(m.domainSize),await t.writeULE32(b.length),await t.writeULE32(L.length),await t.write(w),await t.write(y),await t.write(A),await t.write(C),await t.write(F),await t.write(x),s=await i.read(g,n[3][0].p+g),await t.write(s);let r=await h.C0.multiExponentiation(f,"C0");await t.write(r),await Qe(t)}(t),globalThis.gc&&globalThis.gc();o&&o.info("> Writing the zkey file finished");await t.close()}(),await c.close(),await i.close(),o&&o.info("FFLONK SETUP FINISHED"),0;async function I(t,a,e,i){await Ue(t,a);for(let a=0;a Checking commitments belong to G1"),!function(t,a,e){const o=t.G1;return o.isValid(a.polynomials.C1)&&o.isValid(a.polynomials.C2)&&o.isValid(a.polynomials.W1)&&o.isValid(a.polynomials.W2)&&o.isValid(e.C0)}(i,l,n))return o&&o.error("Proof commitments are not valid"),!1;if(o&&o.info("> Checking evaluations belong to F"),!function(t,a){return Jr(t,a.evaluations.ql)&&Jr(t,a.evaluations.qr)&&Jr(t,a.evaluations.qm)&&Jr(t,a.evaluations.qo)&&Jr(t,a.evaluations.qc)&&Jr(t,a.evaluations.s1)&&Jr(t,a.evaluations.s2)&&Jr(t,a.evaluations.s3)&&Jr(t,a.evaluations.a)&&Jr(t,a.evaluations.b)&&Jr(t,a.evaluations.c)&&Jr(t,a.evaluations.z)&&Jr(t,a.evaluations.zw)&&Jr(t,a.evaluations.t1w)&&Jr(t,a.evaluations.t2w)}(i,l))return o&&o.error("Proof evaluations are not valid."),!1;if(o&&o.info("> Checking public inputs belong to F"),!function(t,a){for(let e=0;e Computing challenges");const{challenges:r,roots:d}=function(t,a,e,o,i){const n=t.Fr,l={},c={},s=new br(t);s.addPolCommitment(e.C0);for(let t=0;t Computing Zero polynomial evaluation Z_H(xi)"),r.zh=s.sub(r.xiN,s.one),r.invzh=s.inv(r.zh),o&&o.info("> Computing Lagrange evaluations");const u=await async function(t,a,e){const o=t.Fr,i=Math.max(1,e.nPublic),n=new Pa(i*o.n8);let l=new Pa(i*o.n8),c=o.one;for(let t=0;t Computing polynomial identities PI(X)");const _=function(t,a,e){const o=t.Fr;let i=o.zero;for(let t=0;t Computing r0(y)");const g=function(t,a,e,o,i){const n=o.Fr,l=Xr(e.S0.h0w8,a.y,a.xi,o);i&&i.info("··· Computing r0(y)");let c=n.zero;for(let a=0;a<8;a++){let o=[];o[1]=e.S0.h0w8[a];for(let t=2;t<8;t++)o[t]=n.mul(o[t-1],e.S0.h0w8[a]);let i=n.add(t.evaluations.ql,n.mul(t.evaluations.qr,o[1]));i=n.add(i,n.mul(t.evaluations.qo,o[2])),i=n.add(i,n.mul(t.evaluations.qm,o[3])),i=n.add(i,n.mul(t.evaluations.qc,o[4])),i=n.add(i,n.mul(t.evaluations.s1,o[5])),i=n.add(i,n.mul(t.evaluations.s2,o[6])),i=n.add(i,n.mul(t.evaluations.s3,o[7])),c=n.add(c,n.mul(i,l[a]))}return c}(l,r,d,i,o);o&&o.info("> Computing r1(y)");const f=function(t,a,e,o,i,n){const l=i.Fr,c=Xr(e.S1.h1w4,a.y,a.xi,i);n&&n.info("··· Computing T0(xi)");let s=l.mul(t.evaluations.ql,t.evaluations.a);s=l.add(s,l.mul(t.evaluations.qr,t.evaluations.b)),s=l.add(s,l.mul(t.evaluations.qm,l.mul(t.evaluations.a,t.evaluations.b))),s=l.add(s,l.mul(t.evaluations.qo,t.evaluations.c)),s=l.add(s,t.evaluations.qc),s=l.add(s,o),s=l.mul(s,a.invzh),n&&n.info("··· Computing C1(h_1ω_4^i) values");let r=l.zero;for(let a=0;a<4;a++){let o=t.evaluations.a;o=l.add(o,l.mul(e.S1.h1w4[a],t.evaluations.b));const i=l.square(e.S1.h1w4[a]);o=l.add(o,l.mul(i,t.evaluations.c)),o=l.add(o,l.mul(l.mul(i,e.S1.h1w4[a]),s)),r=l.add(r,l.mul(o,c[a]))}return r}(l,r,d,_,i,o);o&&o.info("> Computing r2(y)");const h=function(t,a,e,o,i,n,l){const c=n.Fr,s=function(t,a,e,o,i){const n=i.Fr,l=[],c=t[0].length,s=c*t.length,r=n.exp(a,s),d=n.mul(n.add(e,o),n.exp(a,c)),u=n.mul(e,o),_=n.add(n.sub(r,d),u);let g=n.mul(n.mul(n.e(c),t[0][0]),n.sub(e,o));for(let e=0;e Computing F");const p=function(t,a,e,o,i){const n=t.G1,l=t.Fr;let c=l.sub(o.y,i.S0.h0w8[0]);for(let t=1;t<8;t++)c=l.mul(c,l.sub(o.y,i.S0.h0w8[t]));o.temp=c;let s=l.sub(o.y,i.S1.h1w4[0]);for(let t=1;t<4;t++)s=l.mul(s,l.sub(o.y,i.S1.h1w4[t]));let r=l.sub(o.y,i.S2.h2w3[0]);for(let t=1;t<3;t++)r=l.mul(r,l.sub(o.y,i.S2.h2w3[t]));for(let t=0;t<3;t++)r=l.mul(r,l.sub(o.y,i.S2.h3w3[t]));o.quotient1=l.mul(o.alpha,l.div(c,s)),o.quotient2=l.mul(l.square(o.alpha),l.div(c,r));let d=n.timesFr(a.polynomials.C1,o.quotient1),u=n.timesFr(a.polynomials.C2,o.quotient2);return n.add(e.C0,n.add(d,u))}(i,l,n,r,d);o&&o.info("> Computing E");const m=function(t,a,e,o,i,n,l){const c=t.G1,s=t.Fr;let r=s.mul(n,e.quotient1),d=s.mul(l,e.quotient2);return c.timesFr(c.one,s.add(i,s.add(r,d)))}(i,0,r,0,g,f,h);o&&o.info("> Computing J");const L=function(t,a,e){const o=t.G1;return o.timesFr(a.polynomials.W1,e.temp)}(i,l,r);o&&o.info("> Validate all evaluations with a pairing");const b=await async function(t,a,e,o,i,n,l){const c=t.G1;let s=c.timesFr(a.polynomials.W2,e.y);s=c.add(c.sub(c.sub(i,n),l),s);const r=t.G2.one,d=a.polynomials.W2,u=o.X_2;return await t.pairingEq(c.neg(s),r,d,u)}(i,l,r,n,p,m,L);return o&&(b?o.info("PROOF VERIFIED SUCCESSFULLY"):o.warn("Invalid Proof")),o&&o.info("FFLONK VERIFIER FINISHED"),b},exportSolidityVerifier:_r,exportSolidityCallData:async function(t,a){const e=td(a),o=td(t),i=await Je(e.curve);i.G1,i.Fr;let n="";for(let t=0;t>5,this.byteCount=this.blockCount<<2,this.outputBlocks=e>>5,this.extraBytes=(31&e)>>3;for(var o=0;o<50;++o)this.s[o]=0}function S(t,a,e){v.call(this,t,a,e)}v.prototype.update=function(a){if(this.finalized)throw new Error("finalize already called");var e,o=typeof a;if("string"!==o){if("object"!==o)throw new Error(t);if(null===a)throw new Error(t);if(n&&a.constructor===ArrayBuffer)a=new Uint8Array(a);else if(!(Array.isArray(a)||n&&ArrayBuffer.isView(a)))throw new Error(t);e=!0}for(var i,l,c=this.blocks,r=this.byteCount,d=a.length,u=this.blockCount,_=0,g=this.s;_>2]|=a[_]<>2]|=l<>2]|=(192|l>>6)<>2]|=(128|63&l)<=57344?(c[i>>2]|=(224|l>>12)<>2]|=(128|l>>6&63)<>2]|=(128|63&l)<>2]|=(240|l>>18)<>2]|=(128|l>>12&63)<>2]|=(128|l>>6&63)<>2]|=(128|63&l)<=r){for(this.start=i-r,this.block=c[u],i=0;i>=8);e>0;)i.unshift(e),e=255&(t>>=8),++o;return a?i.push(o):i.unshift(o),this.update(i),i.length},v.prototype.encodeString=function(a){var e,o=typeof a;if("string"!==o){if("object"!==o)throw new Error(t);if(null===a)throw new Error(t);if(n&&a.constructor===ArrayBuffer)a=new Uint8Array(a);else if(!(Array.isArray(a)||n&&ArrayBuffer.isView(a)))throw new Error(t);e=!0}var i=0,l=a.length;if(e)i=l;else for(var c=0;c=57344?i+=3:(s=65536+((1023&s)<<10|1023&a.charCodeAt(++c)),i+=4)}return i+=this.encode(8*i),this.update(a),i},v.prototype.bytepad=function(t,a){for(var e=this.encode(a),o=0;o>2]|=this.padding[3&a],this.lastByteIndex===this.byteCount)for(t[0]=t[e],a=1;a>4&15]+l[15&t]+l[t>>12&15]+l[t>>8&15]+l[t>>20&15]+l[t>>16&15]+l[t>>28&15]+l[t>>24&15];c%a==0&&(P(e),n=0)}return i&&(t=e[n],s+=l[t>>4&15]+l[15&t],i>1&&(s+=l[t>>12&15]+l[t>>8&15]),i>2&&(s+=l[t>>20&15]+l[t>>16&15])),s},v.prototype.arrayBuffer=function(){this.finalize();var t,a=this.blockCount,e=this.s,o=this.outputBlocks,i=this.extraBytes,n=0,l=0,c=this.outputBits>>3;t=i?new ArrayBuffer(o+1<<2):new ArrayBuffer(c);for(var s=new Uint32Array(t);l>8&255,s[t+2]=a>>16&255,s[t+3]=a>>24&255;c%e==0&&P(o)}return n&&(t=c<<2,a=o[l],s[t]=255&a,n>1&&(s[t+1]=a>>8&255),n>2&&(s[t+2]=a>>16&255)),s},S.prototype=new v,S.prototype.finalize=function(){return this.encode(this.outputBits,!0),v.prototype.finalize.call(this)};var P=function(t){var a,e,o,i,n,l,c,s,d,u,_,g,f,h,p,m,L,b,w,y,A,C,F,x,I,B,E,v,S,P,q,O,G,z,T,M,U,Q,k,R,N,$,D,j,V,K,H,Z,W,Y,J,X,tt,at,et,ot,it,nt,lt,ct,st,rt,dt;for(o=0;o<48;o+=2)i=t[0]^t[10]^t[20]^t[30]^t[40],n=t[1]^t[11]^t[21]^t[31]^t[41],l=t[2]^t[12]^t[22]^t[32]^t[42],c=t[3]^t[13]^t[23]^t[33]^t[43],s=t[4]^t[14]^t[24]^t[34]^t[44],d=t[5]^t[15]^t[25]^t[35]^t[45],u=t[6]^t[16]^t[26]^t[36]^t[46],_=t[7]^t[17]^t[27]^t[37]^t[47],a=(g=t[8]^t[18]^t[28]^t[38]^t[48])^(l<<1|c>>>31),e=(f=t[9]^t[19]^t[29]^t[39]^t[49])^(c<<1|l>>>31),t[0]^=a,t[1]^=e,t[10]^=a,t[11]^=e,t[20]^=a,t[21]^=e,t[30]^=a,t[31]^=e,t[40]^=a,t[41]^=e,a=i^(s<<1|d>>>31),e=n^(d<<1|s>>>31),t[2]^=a,t[3]^=e,t[12]^=a,t[13]^=e,t[22]^=a,t[23]^=e,t[32]^=a,t[33]^=e,t[42]^=a,t[43]^=e,a=l^(u<<1|_>>>31),e=c^(_<<1|u>>>31),t[4]^=a,t[5]^=e,t[14]^=a,t[15]^=e,t[24]^=a,t[25]^=e,t[34]^=a,t[35]^=e,t[44]^=a,t[45]^=e,a=s^(g<<1|f>>>31),e=d^(f<<1|g>>>31),t[6]^=a,t[7]^=e,t[16]^=a,t[17]^=e,t[26]^=a,t[27]^=e,t[36]^=a,t[37]^=e,t[46]^=a,t[47]^=e,a=u^(i<<1|n>>>31),e=_^(n<<1|i>>>31),t[8]^=a,t[9]^=e,t[18]^=a,t[19]^=e,t[28]^=a,t[29]^=e,t[38]^=a,t[39]^=e,t[48]^=a,t[49]^=e,h=t[0],p=t[1],K=t[11]<<4|t[10]>>>28,H=t[10]<<4|t[11]>>>28,v=t[20]<<3|t[21]>>>29,S=t[21]<<3|t[20]>>>29,ct=t[31]<<9|t[30]>>>23,st=t[30]<<9|t[31]>>>23,$=t[40]<<18|t[41]>>>14,D=t[41]<<18|t[40]>>>14,z=t[2]<<1|t[3]>>>31,T=t[3]<<1|t[2]>>>31,m=t[13]<<12|t[12]>>>20,L=t[12]<<12|t[13]>>>20,Z=t[22]<<10|t[23]>>>22,W=t[23]<<10|t[22]>>>22,P=t[33]<<13|t[32]>>>19,q=t[32]<<13|t[33]>>>19,rt=t[42]<<2|t[43]>>>30,dt=t[43]<<2|t[42]>>>30,at=t[5]<<30|t[4]>>>2,et=t[4]<<30|t[5]>>>2,M=t[14]<<6|t[15]>>>26,U=t[15]<<6|t[14]>>>26,b=t[25]<<11|t[24]>>>21,w=t[24]<<11|t[25]>>>21,Y=t[34]<<15|t[35]>>>17,J=t[35]<<15|t[34]>>>17,O=t[45]<<29|t[44]>>>3,G=t[44]<<29|t[45]>>>3,x=t[6]<<28|t[7]>>>4,I=t[7]<<28|t[6]>>>4,ot=t[17]<<23|t[16]>>>9,it=t[16]<<23|t[17]>>>9,Q=t[26]<<25|t[27]>>>7,k=t[27]<<25|t[26]>>>7,y=t[36]<<21|t[37]>>>11,A=t[37]<<21|t[36]>>>11,X=t[47]<<24|t[46]>>>8,tt=t[46]<<24|t[47]>>>8,j=t[8]<<27|t[9]>>>5,V=t[9]<<27|t[8]>>>5,B=t[18]<<20|t[19]>>>12,E=t[19]<<20|t[18]>>>12,nt=t[29]<<7|t[28]>>>25,lt=t[28]<<7|t[29]>>>25,R=t[38]<<8|t[39]>>>24,N=t[39]<<8|t[38]>>>24,C=t[48]<<14|t[49]>>>18,F=t[49]<<14|t[48]>>>18,t[0]=h^~m&b,t[1]=p^~L&w,t[10]=x^~B&v,t[11]=I^~E&S,t[20]=z^~M&Q,t[21]=T^~U&k,t[30]=j^~K&Z,t[31]=V^~H&W,t[40]=at^~ot&nt,t[41]=et^~it<,t[2]=m^~b&y,t[3]=L^~w&A,t[12]=B^~v&P,t[13]=E^~S&q,t[22]=M^~Q&R,t[23]=U^~k&N,t[32]=K^~Z&Y,t[33]=H^~W&J,t[42]=ot^~nt&ct,t[43]=it^~lt&st,t[4]=b^~y&C,t[5]=w^~A&F,t[14]=v^~P&O,t[15]=S^~q&G,t[24]=Q^~R&$,t[25]=k^~N&D,t[34]=Z^~Y&X,t[35]=W^~J&tt,t[44]=nt^~ct&rt,t[45]=lt^~st&dt,t[6]=y^~C&h,t[7]=A^~F&p,t[16]=P^~O&x,t[17]=q^~G&I,t[26]=R^~$&z,t[27]=N^~D&T,t[36]=Y^~X&j,t[37]=J^~tt&V,t[46]=ct^~rt&at,t[47]=st^~dt&et,t[8]=C^~h&m,t[9]=F^~p&L,t[18]=O^~x&B,t[19]=G^~I&E,t[28]=$^~z&M,t[29]=D^~T&U,t[38]=X^~j&K,t[39]=tt^~V&H,t[48]=rt^~at&ot,t[49]=dt^~et&it,t[0]^=r[o],t[1]^=r[o+1]};if(i)Lr.exports=y;else for(C=0;C0===e.type?t++:a++));let e=new Uint8Array(a*this.Fr.n8+t*this.G1.F.n8*2),o=0;for(let t=0;t32768?new Pa(t.length*o.n8):new Uint8Array(t.length*o.n8);for(let a=0;a32768?new Pa(o*i.n8):new Uint8Array(o*i.n8);return n.set(t.coef.slice(),0),new Tr(n,a,e)}isEqual(t){const a=this.degree();if(a!==t.degree())return!1;for(let e=0;e32768?new Pa((this.length()+t.length)*this.Fr.n8):new Uint8Array((this.length()+t.length)*this.Fr.n8);a.set(this.coef,0);for(let e=0;ethis.coef.byteLength?this.Fr.zero:this.coef.slice(a,a+this.Fr.n8)}setCoef(t,a){if(t>this.length()-1)throw new Error("Coef index is not available");this.coef.set(a,t*this.Fr.n8)}static async to4T(t,a,e,o){e=e||[];let i=await o.ifft(t);const n=4*a>32768?new Pa(4*a*o.n8):new Uint8Array(4*a*o.n8);n.set(i,0);const l=await o.fft(n);if(0===e.length)return[i,l];const c=a+e.length>32768?new Pa((a+e.length)*o.n8):new Uint8Array((a+e.length)*o.n8);c.set(i,0);for(let t=0;t0;t--){const a=t*this.Fr.n8;if(!this.Fr.eq(this.Fr.zero,this.coef.slice(a,a+this.Fr.n8)))return t}return 0}evaluate(t){let a=this.Fr.zero;for(let e=this.degree()+1;e>0;e--){let o=e*this.Fr.n8;const i=this.coef.slice(o-this.Fr.n8,o);a=this.Fr.add(i,this.Fr.mul(a,t))}return a}fastEvaluate(t){const a=this.Fr;let e=this.degree()+1,o=parseInt(e/3),i=e-3*o,n=[],l=[];l[0]=a.one;for(let e=0;e<3;e++){n[e]=a.zero;for(let c=2===e?o+i:o;c>0;c--)n[e]=a.add(this.getCoef(e*o+c-1),a.mul(n[e],t)),0===e&&(l[0]=a.mul(l[0],t))}for(let t=1;t<3;t++)n[0]=a.add(n[0],a.mul(l[t-1],n[t])),l[t]=a.mul(l[t-1],l[0]);return n[0]}add(t,a){let e=!1;t.length()>this.length()&&(e=!0);const o=this.length(),i=t.length();for(let n=0;nthis.length()&&(e=!0);const o=this.length(),i=t.length();for(let n=0;n32768?new Pa(e*a.n8):new Uint8Array(e*a.n8);let i=new Tr(o,this.curve,this.logger);i.coef.set(this.coef.slice(0,(e-1)*a.n8),32),this.mulScalar(a.neg(t)),i.add(this),this.coef=i.coef}byXNSubValue(t,a){const e=this.Fr,o=!(this.length()-t-1>=this.degree())?this.length()+t:this.length(),i=o>32768?new Pa(o*e.n8):new Uint8Array(o*e.n8);let n=new Tr(i,this.curve,this.logger);n.coef.set(this.coef.slice(0,32*(this.degree()+1)),32*t),this.mulScalar(a),n.add(this),this.coef=n.coef}divBy(t){const a=this.Fr,e=this.degree(),o=t.degree();let i=new Tr(this.coef,this.curve,this.logger);this.coef=this.length()>32768?new Pa(this.length()*a.n8):new Uint8Array(this.length()*a.n8);for(let n=e-o;n>=0;n--){this.setCoef(n,a.div(i.getCoef(n+o),t.getCoef(o)));for(let e=0;e<=o;e++)i.setCoef(n+e,a.sub(i.getCoef(n+e),a.mul(this.getCoef(n),t.getCoef(e))))}return i}divByMonic(t,a){const e=this.Fr;let o=this.degree(),i=this.length()>32768?new Pa(this.length()*e.n8):new Uint8Array(this.length()*e.n8),n=new Tr(i,this.curve,this.logger),l=[];for(let a=0;a=0&&!(s<0);s-=c){let o=i;l[o]=e.add(this.getCoef(s+t),e.mul(l[o],a)),n.setCoef(s,l[o])}this.coef=n.coef}divByVanishing(t,a){if(this.degree()32768?new Pa(this.length()*e.n8):new Uint8Array(this.length()*e.n8);for(let i=this.length()-1;i>=t;i--){let n=o.getCoef(i);e.eq(e.zero,n)||(o.setCoef(i,e.zero),o.setCoef(i-t,e.add(o.getCoef(i-t),e.mul(a,n))),this.setCoef(i-t,e.add(this.getCoef(i-t),n)))}return o}divByVanishing2(t,a){if(this.degree()32768?new Pa(this.length()*e.n8):new Uint8Array(this.length()*e.n8);let i=this.length()-t,n=Math.floor(i/3),l=i-2*n;console.log(i),console.log(n+" "+l);for(let i=0;i<3;i++){console.log("> Thread "+i);for(let c=0===i?l:n;c>0;c--){let s=c-1;0!==i&&(s+=(i-1)*n+l);let r=s+t,d=o.getCoef(r);e.eq(e.zero,d)||(o.setCoef(r,e.zero),o.setCoef(s,e.add(o.getCoef(s),e.mul(a,d))),this.setCoef(s,e.add(this.getCoef(s),d)),console.log(s+" <-- "+r))}}return this.print(),o}fastDivByVanishing(t){const a=this.Fr;for(let e=0;e32768?new Pa(this.length()*a.n8):new Uint8Array(this.length()*a.n8),this.curve,this.logger),u=this.coef;this.coef=d.coef,d.coef=u;for(let t=0;t0;t--){let e=t-1,i=e*s+r;f[e]=[];for(let l=0;l32768?new Pa(this.length()*this.Fr.n8):new Uint8Array(this.length()*this.Fr.n8);a.set(this.Fr.zero,(this.length()-1)*this.Fr.n8),a.set(this.coef.slice((this.length()-1)*this.Fr.n8,this.length()*this.Fr.n8),(this.length()-2)*this.Fr.n8);for(let e=this.length()-3;e>=0;e--){let o=e*this.Fr.n8;a.set(this.Fr.add(this.coef.slice(o+this.Fr.n8,o+2*this.Fr.n8),this.Fr.mul(t,a.slice(o+this.Fr.n8,o+2*this.Fr.n8))),e*this.Fr.n8)}if(!this.Fr.eq(this.coef.slice(0,this.Fr.n8),this.Fr.mul(this.Fr.neg(t),a.slice(0,this.Fr.n8))))throw new Error("Polynomial does not divide");this.coef=a}divZh(t,a=4){for(let a=0;at*(a-1)-a&&!this.Fr.isZero(i))throw new Error("Polynomial is not divisible")}return this}divByZerofier(t,a){let e=this.Fr;const o=e.inv(a),i=e.neg(o);let n=e.eq(e.one,i),l=e.eq(e.negone,i);if(!n)for(let a=0;athis.length()-t-1&&!this.Fr.isZero(s))throw new Error("Polynomial is not divisible")}return this}byX(){const t=this.length()+1>32768?new Pa(this.coef.byteLength+this.Fr.n8):new Uint8Array(this.coef.byteLength+this.Fr.n8);t.set(this.Fr.zero,0),t.set(this.coef,this.Fr.n8),this.coef=t}static async expX(t,a,e=!1){const o=t.Fr;if(a<1)throw new Error("Compute a new polynomial to a zero or negative number is not allowed");if(1===a)return await Tr.fromEvaluations(t.coef,curve,t.logger);const i=e?t.degree():t.length()-1,n=i*a+1>32768?new Pa((i*a+1)*o.n8):new Uint8Array((i*a+1)*o.n8);n.set(t.getCoef(0),0);for(let e=1;e<=i;e++){const i=e*o.n8,l=t.getCoef(e);n.set(l,i*a)}return new Tr(n,t.curve,t.logger)}split(t,a,e){if(t<1)throw new Error(`Polynomials can't be split in ${t} parts`);if(1===t)return[this];if(0!==e.length&&e.length32768?new Pa(l):new Uint8Array(l);i[a]=new Tr(c,this.curve,this.logger);const s=a*o,r=n?this.coef.byteLength:(a+1)*o;if(i[a].coef.set(this.coef.slice(s,r),0),n||i[a].coef.set(e[a],o),0!==a){const t=this.Fr.sub(i[a].coef.slice(0,this.Fr.n8),e[a-1]);i[a].coef.set(t,0)}n&&i[a].truncate()}return i}truncate(){const t=this.degree();if(t+132768?new Pa((t+1)*this.Fr.n8):new Uint8Array((t+1)*this.Fr.n8);a.set(this.coef.slice(0,(t+1)*this.Fr.n8),0),this.coef=a}}static lagrangePolynomialInterpolation(t,a,e){const o=e.Fr;let i=n(0);for(let a=1;a32768?new Pa(t.length*o.n8):new Uint8Array(t.length*o.n8);n=new Tr(i,e),n.setCoef(0,o.neg(t[a])),n.setCoef(1,o.one)}else n.byXSubValue(t[a]);let l=n.evaluate(t[i]);l=o.inv(l);const c=o.mul(a[i],l);return n.mulScalar(c),n}}static zerofierPolynomial(t,a){const e=a.Fr;let o=t.length+1>32768?new Pa((t.length+1)*e.n8):new Uint8Array((t.length+1)*e.n8),i=new Tr(o,a);i.setCoef(0,e.neg(t[0])),i.setCoef(1,e.one);for(let a=1;a=0;e--){const o=this.getCoef(e);t.eq(t.zero,o)||(t.isNegative(o)?a+=" - ":e!==this.degree()&&(a+=" + "),a+=t.toString(o),e>0&&(a+=e>1?"x^"+e:"x"))}console.log(a)}async multiExponentiation(t,a){const e=this.coef.byteLength/this.Fr.n8,o=t.slice(0,e*this.G1.F.n8*2),i=await this.Fr.batchFromMontgomery(this.coef);let n=await this.G1.multiExpAffine(o,i,this.logger,a);return n=this.G1.toAffine(n),n}}class Mr{constructor(t,a,e){this.eval=t,this.curve=a,this.Fr=a.Fr,this.logger=e}static async fromPolynomial(t,a,e,o){const i=new Pa(t.length()*a*e.Fr.n8);i.set(t.coef,0);const n=await e.Fr.fft(i);return new Mr(n,e,o)}getEvaluation(t){const a=t*this.Fr.n8;if(a+this.Fr.n8>this.eval.byteLength)throw new Error("Evaluations.getEvaluation() out of bounds");return this.eval.slice(a,a+this.Fr.n8)}length(){let t=this.eval.byteLength/this.Fr.n8;if(t!==Math.floor(this.eval.byteLength/this.Fr.n8))throw new Error("Polynomial evaluations buffer has incorrect size");return 0===t&&this.logger.warn("Polynomial has length zero"),t}}const{stringifyBigInts:Ur}=ge;async function Qr(t,a,e){const{fd:o,sections:i}=await Te(a,"wtns",2);e&&e.debug("> Reading witness file");const n=await Ii(o,i);e&&e.debug("> Reading zkey file");const{fd:l,sections:c}=await Te(t,"zkey",2),s=await bi(l,c);if("plonk"!=s.protocol)throw new Error("zkey file is not plonk");if(!_e.eq(s.r,n.q))throw new Error("Curve of the witness does not match the curve of the proving key");if(n.nWitness!=s.nVars-s.nAdditions)throw new Error(`Invalid witness length. Circuit: ${s.nVars}, witness: ${n.nWitness}, ${s.nAdditions}`);const r=s.curve,d=r.Fr,u=r.Fr.n8,_=s.domainSize*u;e&&(e.debug("----------------------------"),e.debug(" PLONK PROVE SETTINGS"),e.debug(` Curve: ${r.name}`),e.debug(` Circuit power: ${s.power}`),e.debug(` Domain size: ${s.domainSize}`),e.debug(` Vars: ${s.nVars}`),e.debug(` Public vars: ${s.nPublic}`),e.debug(` Constraints: ${s.nConstraints}`),e.debug(` Additions: ${s.nAdditions}`),e.debug("----------------------------")),e&&e.debug("> Reading witness file data");const g=await je(o,i,2);g.set(d.zero,0);const f=new Pa(u*s.nAdditions);let h={},p={},m={},L={},b=new mr(r,e);const w=new Ar(r);e&&e.debug(`> Reading Section ${Fr}. Additions`),await async function(){e&&e.debug("··· Computing additions");const t=await je(l,c,Fr),a=8+2*u;for(let o=0;o Reading Section ${Or}. Sigma1, Sigma2 & Sigma 3`),e&&e.debug("··· Reading Sigma polynomials "),p.Sigma1=new Tr(new Pa(_),r,e),p.Sigma2=new Tr(new Pa(_),r,e),p.Sigma3=new Tr(new Pa(_),r,e),await l.readToBuffer(p.Sigma1.coef,0,_,c[Or][0].p),await l.readToBuffer(p.Sigma2.coef,0,_,c[Or][0].p+5*_),await l.readToBuffer(p.Sigma3.coef,0,_,c[Or][0].p+10*_),e&&e.debug("··· Reading Sigma evaluations"),m.Sigma1=new Mr(new Pa(4*_),r,e),m.Sigma2=new Mr(new Pa(4*_),r,e),m.Sigma3=new Mr(new Pa(4*_),r,e),await l.readToBuffer(m.Sigma1.eval,0,4*_,c[Or][0].p+_),await l.readToBuffer(m.Sigma2.eval,0,4*_,c[Or][0].p+6*_),await l.readToBuffer(m.Sigma3.eval,0,4*_,c[Or][0].p+11*_),e&&e.debug(`> Reading Section ${zr}. Powers of Tau`);const y=await je(l,c,zr);let A=[];for(let t=1;t<=s.nPublic;t++){const a=g.slice(t*d.n8,t*d.n8+d.n8);A.push(_e.fromRprLE(a))}e&&e.debug(""),e&&e.debug("> ROUND 1"),await async function(){L.b=[];for(let t=1;t<=11;t++)L.b[t]=r.Fr.random();e&&e.debug("> Computing A, B, C wire polynomials");await async function(){e&&e.debug("··· Reading data from zkey file");h.A=new Pa(_),h.B=new Pa(_),h.C=new Pa(_);const t=await je(l,c,xr),a=await je(l,c,Ir),o=await je(l,c,Br);for(let e=0;e=s.domainSize+2)throw new Error("A Polynomial is not well calculated");if(p.B.degree()>=s.domainSize+2)throw new Error("B Polynomial is not well calculated");if(p.C.degree()>=s.domainSize+2)throw new Error("C Polynomial is not well calculated")}(),e&&e.debug("> Computing A, B, C MSM");let t=await p.A.multiExponentiation(y,"A"),a=await p.B.multiExponentiation(y,"B"),o=await p.C.multiExponentiation(y,"C");return b.addPolynomial("A",t),b.addPolynomial("B",a),b.addPolynomial("C",o),0}(),e&&e.debug("> ROUND 2"),await async function(){e&&e.debug("> Computing challenges beta and gamma");w.reset(),w.addPolCommitment(s.Qm),w.addPolCommitment(s.Ql),w.addPolCommitment(s.Qr),w.addPolCommitment(s.Qo),w.addPolCommitment(s.Qc),w.addPolCommitment(s.S1),w.addPolCommitment(s.S2),w.addPolCommitment(s.S3);for(let t=0;t Computing Z polynomial");await async function(){e&&e.debug("··· Computing Z evaluations");let t=new Pa(_),a=new Pa(_);t.set(d.one,0),a.set(d.one,0);let o=d.one;for(let e=0;e=s.domainSize+3)throw new Error("Z Polynomial is not well calculated");delete h.Z}(),e&&e.debug("> Computing Z MSM");let t=await p.Z.multiExponentiation(y,"Z");b.addPolynomial("Z",t)}(),e&&e.debug("> ROUND 3"),await async function(){e&&e.debug("> Computing challenge alpha");w.reset(),w.addScalar(L.beta),w.addScalar(L.gamma),w.addPolCommitment(b.getPolynomial("Z")),L.alpha=w.getChallenge(),L.alpha2=d.square(L.alpha),e&&e.debug("··· challenges.alpha: "+d.toString(L.alpha,16));e&&e.debug("> Computing T polynomial");await async function(){e&&e.debug(`··· Reading sections ${vr}, ${Sr}, ${Er}, ${Pr}, ${qr}. Q selectors`);m.QL=new Mr(new Pa(4*_),r,e),m.QR=new Mr(new Pa(4*_),r,e),m.QM=new Mr(new Pa(4*_),r,e),m.QO=new Mr(new Pa(4*_),r,e),m.QC=new Mr(new Pa(4*_),r,e),await l.readToBuffer(m.QL.eval,0,4*_,c[vr][0].p+_),await l.readToBuffer(m.QR.eval,0,4*_,c[Sr][0].p+_),await l.readToBuffer(m.QM.eval,0,4*_,c[Er][0].p+_),await l.readToBuffer(m.QO.eval,0,4*_,c[Pr][0].p+_),await l.readToBuffer(m.QC.eval,0,4*_,c[qr][0].p+_),m.Lagrange=new Mr(new Pa(4*_*s.nPublic),r,e);for(let t=0;t=3*s.domainSize+6)throw new Error("T Polynomial is not well calculated");e&&e.debug("··· Computing T1, T2, T3 polynomials");p.T1=new Tr(new Pa((s.domainSize+1)*u),r,e),p.T2=new Tr(new Pa((s.domainSize+1)*u),r,e),p.T3=new Tr(new Pa((s.domainSize+6)*u),r,e),p.T1.coef.set(p.T.coef.slice(0,_),0),p.T2.coef.set(p.T.coef.slice(_,2*_),0),p.T3.coef.set(p.T.coef.slice(2*_,3*_+6*u),0),p.T1.setCoef(s.domainSize,L.b[10]);const a=d.sub(p.T2.getCoef(0),L.b[10]);p.T2.setCoef(0,a),p.T2.setCoef(s.domainSize,L.b[11]);const o=d.sub(p.T3.getCoef(0),L.b[11]);p.T3.setCoef(0,o)}(),e&&e.debug("> Computing T MSM");let t=await p.T1.multiExponentiation(y,"T1"),a=await p.T2.multiExponentiation(y,"T2"),o=await p.T3.multiExponentiation(y,"T3");b.addPolynomial("T1",t),b.addPolynomial("T2",a),b.addPolynomial("T3",o)}(),e&&e.debug("> ROUND 4"),await async function(){e&&e.debug("> Computing challenge xi");w.reset(),w.addScalar(L.alpha),w.addPolCommitment(b.getPolynomial("T1")),w.addPolCommitment(b.getPolynomial("T2")),w.addPolCommitment(b.getPolynomial("T3")),L.xi=w.getChallenge(),L.xiw=d.mul(L.xi,d.w[s.power]),e&&e.debug("··· challenges.xi: "+d.toString(L.xi,16));b.addEvaluation("eval_a",p.A.evaluate(L.xi)),b.addEvaluation("eval_b",p.B.evaluate(L.xi)),b.addEvaluation("eval_c",p.C.evaluate(L.xi)),b.addEvaluation("eval_s1",p.Sigma1.evaluate(L.xi)),b.addEvaluation("eval_s2",p.Sigma2.evaluate(L.xi)),b.addEvaluation("eval_zw",p.Z.evaluate(L.xiw))}(),e&&e.debug("> ROUND 5"),await async function(){e&&e.debug("> Computing challenge v");w.reset(),w.addScalar(L.xi),w.addScalar(b.getEvaluation("eval_a")),w.addScalar(b.getEvaluation("eval_b")),w.addScalar(b.getEvaluation("eval_c")),w.addScalar(b.getEvaluation("eval_s1")),w.addScalar(b.getEvaluation("eval_s2")),w.addScalar(b.getEvaluation("eval_zw")),L.v=[],L.v[1]=w.getChallenge(),e&&e.debug("··· challenges.v: "+d.toString(L.v[1],16));for(let t=2;t<6;t++)L.v[t]=d.mul(L.v[t-1],L.v[1]);e&&e.debug("> Computing linearisation polynomial R(X)");await async function(){const t=r.Fr;p.QL=new Tr(new Pa(_),r,e),p.QR=new Tr(new Pa(_),r,e),p.QM=new Tr(new Pa(_),r,e),p.QO=new Tr(new Pa(_),r,e),p.QC=new Tr(new Pa(_),r,e),await l.readToBuffer(p.QL.coef,0,_,c[vr][0].p),await l.readToBuffer(p.QR.coef,0,_,c[Sr][0].p),await l.readToBuffer(p.QM.coef,0,_,c[Er][0].p),await l.readToBuffer(p.QO.coef,0,_,c[Pr][0].p),await l.readToBuffer(p.QC.coef,0,_,c[qr][0].p),L.xin=L.xi;for(let a=0;a Computing opening proof polynomial Wxi(X) polynomial");p.Wxi=new Tr(new Pa(_+6*u),r,e),p.Wxi.add(p.R),p.Wxi.add(p.A,L.v[1]),p.Wxi.add(p.B,L.v[2]),p.Wxi.add(p.C,L.v[3]),p.Wxi.add(p.Sigma1,L.v[4]),p.Wxi.add(p.Sigma2,L.v[5]),p.Wxi.subScalar(d.mul(L.v[1],b.evaluations.eval_a)),p.Wxi.subScalar(d.mul(L.v[2],b.evaluations.eval_b)),p.Wxi.subScalar(d.mul(L.v[3],b.evaluations.eval_c)),p.Wxi.subScalar(d.mul(L.v[4],b.evaluations.eval_s1)),p.Wxi.subScalar(d.mul(L.v[5],b.evaluations.eval_s2)),void p.Wxi.divByZerofier(1,L.xi),e&&e.debug("> Computing opening proof polynomial Wxiw(X) polynomial");(async function(){p.Wxiw=Tr.fromPolynomial(p.Z,r,e),p.Wxiw.subScalar(b.evaluations.eval_zw),p.Wxiw.divByZerofier(1,L.xiw)})(),e&&e.debug("> Computing Wxi, Wxiw MSM");let t=await p.Wxi.multiExponentiation(y,"Wxi"),a=await p.Wxiw.multiExponentiation(y,"Wxiw");b.addPolynomial("Wxi",t),b.addPolynomial("Wxiw",a)}(),await l.close(),await o.close();let C=b.toObjectProof(!1);return C.protocol="plonk",C.curve=r.name,e&&e.debug("PLONK PROVER FINISHED"),{proof:Ur(C),publicSignals:Ur(A)};function F(t,a){const e=t.slice(a,a+4);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(0,!0)}function x(t){return te;){const a=i.shift(),e=i.shift(),o=a[0],n=e[0],l=L++,c=t.zero,s=t.neg(a[1]),r=t.neg(e[1]),d=t.one,u=t.zero;p.push([o,n,l,c,s,r,d,u]),m.push([o,n,a[1],e[1]]),i.push([l,t.one])}for(let t=0;t0?o.toString():e!=t.zero?"k":"0"}function s(a,e,s){const r=c(a),d=c(e);if("0"===r||"0"===d)o(s),l(s);else if("k"===r){l(i(e,a[0],s))}else if("k"===d){l(i(a,e[0],s))}else!function(a,e,o){const i=n(a,1),l=n(e,1),c=n(o,1),s=i.s[0],r=l.s[0],d=c.s[0],u=t.mul(i.coefs[0],l.coefs[0]),_=t.mul(i.coefs[0],l.k),g=t.mul(i.k,l.coefs[0]),f=t.neg(c.coefs[0]),h=t.sub(t.mul(i.k,l.k),c.k);p.push([s,r,d,u,_,g,f,h])}(a,e,s)}for(let a=1;a<=b;a++){const e=a,o=0,i=0,n=t.zero,l=t.one,c=t.zero,s=t.zero,r=t.zero;p.push([e,o,i,n,l,c,s,r])}for(let t=0;tc)return o&&o.error(`circuit too big for this power of tau ceremony. ${p.length} > 2**${c}`),-1;if(!n[12])return o&&o.error("Powers of tau is not prepared."),-1;const C=new Pa(A*u),F=n[12][0].p+(2**y-1)*u;await i.readToBuffer(C,0,A*u,F);const[x,I]=function(){let t=f.two;for(;e(t,[],y);)f.add(t,f.one);let a=f.add(t,f.one);for(;e(a,[t],y);)f.add(a,f.one);return[t,a];function e(t,a,e){const o=2**e;let i=f.one;for(let n=0;n0?2:this.Fr.isZero(a)?0:1}normalizeLinearCombination(t){const a=Object.keys(t);for(let e=0;ei;){const o=l.shift(),i=l.shift(),n=t.nVars++,c=this.fnGetAdditionConstraint(o[0],i[0],n,this.Fr.neg(o[1]),this.Fr.neg(i[1]),this.Fr.zero,this.Fr.one,this.Fr.zero);a.push(c),e.push([o[0],i[0],o[1],i[1]]),l.push([n,this.Fr.one])}for(let t=0;tthis.n-1)throw new Error("CPolynomial:addPolynomial, cannot add a polynomial to a position greater than n-1");this.polynomials[t]=a}degree(){let t=this.polynomials.map(((t,a)=>void 0===t?0:t.degree()*this.n+a));return Math.max(...t)}getPolynomial(){let t=this.polynomials.map((t=>void 0===t?0:t.degree()));const a=this.degree(),e=2**(To(a-1)+1),o=this.Fr.n8;let i=new Tr(new Pa(e*o),this.curve,this.logger);for(let e=0;e Reading witness file");const{fd:o,sections:i}=await Te(a,"wtns",2),n=await Ii(o,i);e&&e.info("> Reading zkey file");const{fd:l,sections:c}=await Te(t,"zkey",2),s=await bi(l,c);if(s.protocolId!==Yo)throw new Error("zkey file is not fflonk");if(!_e.eq(s.r,n.q))throw new Error("Curve of the witness does not match the curve of the proving key");if(n.nWitness!==s.nVars-s.nAdditions)throw new Error(`Invalid witness length. Circuit: ${s.nVars}, witness: ${n.nWitness}, ${s.nAdditions}`);const r=s.curve,d=r.Fr,u=r.Fr.n8,_=2*r.G1.F.n8,g=s.domainSize*u;e&&(e.info("----------------------------"),e.info(" FFLONK PROVE SETTINGS"),e.info(` Curve: ${r.name}`),e.info(` Circuit power: ${s.power}`),e.info(` Domain size: ${s.domainSize}`),e.info(` Vars: ${s.nVars}`),e.info(` Public vars: ${s.nPublic}`),e.info(` Constraints: ${s.nConstraints}`),e.info(` Additions: ${s.nAdditions}`),e.info("----------------------------")),e&&e.info("> Reading witness file data");const f=await je(o,i,2);await o.close(),f.set(d.zero,0);const h=new Pa(s.nAdditions*u);let p={},m={},L={},b={},w={},y={},A=new mr(r,e);e&&e.info(`> Reading Section ${Xo}. Additions`),await async function(){e&&e.info("··· Computing additions");const t=await je(l,c,Xo),a=8+2*u;for(let o=0;o Reading Sections ${si},${ri},${di}. Sigma1, Sigma2 & Sigma 3`),e&&e.info("··· Reading Sigma polynomials "),m.Sigma1=new Tr(new Pa(g),r,e),m.Sigma2=new Tr(new Pa(g),r,e),m.Sigma3=new Tr(new Pa(g),r,e),await l.readToBuffer(m.Sigma1.coef,0,g,c[si][0].p),await l.readToBuffer(m.Sigma2.coef,0,g,c[ri][0].p),await l.readToBuffer(m.Sigma3.coef,0,g,c[di][0].p),e&&e.info("··· Reading Sigma evaluations"),L.Sigma1=new Mr(new Pa(4*g),r,e),L.Sigma2=new Mr(new Pa(4*g),r,e),L.Sigma3=new Mr(new Pa(4*g),r,e),await l.readToBuffer(L.Sigma1.eval,0,4*g,c[si][0].p+g),await l.readToBuffer(L.Sigma2.eval,0,4*g,c[ri][0].p+g),await l.readToBuffer(L.Sigma3.eval,0,4*g,c[di][0].p+g),e&&e.info(`> Reading Section ${_i}. Powers of Tau`);const C=new Pa(16*s.domainSize*_);await l.readToBuffer(C,0,(9*s.domainSize+18)*_,c[_i][0].p),globalThis.gc&&globalThis.gc(),e&&e.info(""),e&&e.info("> ROUND 1"),await async function(){w.b=[];for(let t=1;t<=9;t++)w.b[t]=d.random();e&&e.info("> Computing A, B, C wire polynomials");await async function(){e&&e.info("··· Reading data from zkey file");p.A=new Pa(g),p.B=new Pa(g),p.C=new Pa(g);const t=await je(l,c,ti),a=await je(l,c,ai),o=await je(l,c,ei);for(let e=0;e=s.domainSize)throw new Error("A Polynomial is not well calculated");if(m.B.degree()>=s.domainSize)throw new Error("B Polynomial is not well calculated");if(m.C.degree()>=s.domainSize)throw new Error("C Polynomial is not well calculated")}(),e&&e.info("> Computing T0 polynomial");await async function(){e&&e.info(`··· Reading sections ${oi}, ${ii}, ${ni}, ${li}, ${ci}. Q selectors`);L.QL=new Mr(new Pa(4*g),r,e),L.QR=new Mr(new Pa(4*g),r,e),L.QM=new Mr(new Pa(4*g),r,e),L.QO=new Mr(new Pa(4*g),r,e),L.QC=new Mr(new Pa(4*g),r,e),await l.readToBuffer(L.QL.eval,0,4*g,c[oi][0].p+g),await l.readToBuffer(L.QR.eval,0,4*g,c[ii][0].p+g),await l.readToBuffer(L.QM.eval,0,4*g,c[ni][0].p+g),await l.readToBuffer(L.QO.eval,0,4*g,c[li][0].p+g),await l.readToBuffer(L.QC.eval,0,4*g,c[ci][0].p+g);const t=await je(l,c,ui);L.lagrange1=new Mr(t,r,e),p.T0=new Pa(4*g),e&&e.info("··· Computing T0 evaluations");for(let t=0;t<4*s.domainSize;t++){e&&0!==t&&t%1e5==0&&e.info(` T0 evaluation ${t}/${4*s.domainSize}`);const a=L.A.getEvaluation(t),o=L.B.getEvaluation(t),i=L.C.getEvaluation(t),n=L.QL.getEvaluation(t),l=L.QR.getEvaluation(t),c=L.QM.getEvaluation(t),r=L.QO.getEvaluation(t),_=L.QC.getEvaluation(t);let g=d.zero;for(let a=0;a=2*s.domainSize-2)throw new Error(`T0 Polynomial is not well calculated (degree is ${m.T0.degree()} and must be less than ${2*s.domainSize+2}`);delete p.T0}(),e&&e.info("> Computing C1 polynomial");await async function(){let t=new Zr(4,r,e);if(t.addPolynomial(0,m.A),t.addPolynomial(1,m.B),t.addPolynomial(2,m.C),t.addPolynomial(3,m.T0),m.C1=t.getPolynomial(),m.C1.degree()>=8*s.domainSize-8)throw new Error("C1 Polynomial is not well calculated")}(),e&&e.info("> Computing C1 multi exponentiation");let t=await m.C1.multiExponentiation(C,"C1");return A.addPolynomial("C1",t),0}(),delete m.T0,delete L.QL,delete L.QR,delete L.QM,delete L.QO,delete L.QC,globalThis.gc&&globalThis.gc(),e&&e.info("> ROUND 2"),await async function(){e&&e.info("> Computing challenges beta and gamma");const t=new Ar(r);t.addPolCommitment(s.C0);for(let a=0;a Computing Z polynomial");await async function(){e&&e.info("··· Computing Z evaluations");let t=new Pa(g),a=new Pa(g);t.set(d.one,0),a.set(d.one,0);let o=d.one;for(let i=0;i=s.domainSize+3)throw new Error("Z Polynomial is not well calculated");delete p.Z}(),e&&e.info("> Computing T1 polynomial");await async function(){e&&e.info("··· Computing T1 evaluations");p.T1=new Pa(2*g),p.T1z=new Pa(2*g);let t=d.one;for(let a=0;a<2*s.domainSize;a++){e&&0!==a&&a%1e5==0&&e.info(` T1 evaluation ${a}/${4*s.domainSize}`);const o=d.square(t),i=L.Z.getEvaluation(2*a),n=d.add(d.add(d.mul(w.b[7],o),d.mul(w.b[8],t)),w.b[9]),l=L.lagrange1.getEvaluation(s.domainSize+2*a);let c=d.mul(d.sub(i,d.one),l),r=d.mul(n,l);p.T1.set(c,a*u),p.T1z.set(r,a*u),t=d.mul(t,d.w[s.power+1])}e&&e.info("··· Computing T1 ifft");m.T1=await Tr.fromEvaluations(p.T1,r,e),m.T1.divByZerofier(s.domainSize,d.one),e&&e.info("··· Computing T1z ifft");if(m.T1z=await Tr.fromEvaluations(p.T1z,r,e),m.T1.add(m.T1z),m.T1.degree()>=s.domainSize+2)throw new Error("T1 Polynomial is not well calculated");delete p.T1,delete p.T1z,delete m.T1z}(),e&&e.info("> Computing T2 polynomial");await async function(){e&&e.info("··· Computing T2 evaluations");p.T2=new Pa(4*g),p.T2z=new Pa(4*g);let t=d.one;for(let a=0;a<4*s.domainSize;a++){e&&0!==a&&a%1e5==0&&e.info(` T2 evaluation ${a}/${4*s.domainSize}`);const o=d.square(t),i=d.mul(t,d.w[s.power]),n=d.square(i),l=L.A.getEvaluation(a),c=L.B.getEvaluation(a),r=L.C.getEvaluation(a),_=L.Z.getEvaluation(a),g=L.Z.getEvaluation((4*s.domainSize+4+a)%(4*s.domainSize)),f=d.add(d.add(d.mul(w.b[7],o),d.mul(w.b[8],t)),w.b[9]),h=d.add(d.add(d.mul(w.b[7],n),d.mul(w.b[8],i)),w.b[9]),m=L.Sigma1.getEvaluation(a),b=L.Sigma2.getEvaluation(a),y=L.Sigma3.getEvaluation(a),A=d.mul(w.beta,t);let C=d.add(l,A);C=d.add(C,w.gamma);let F=d.add(c,d.mul(A,s.k1));F=d.add(F,w.gamma);let x=d.add(r,d.mul(A,s.k2));x=d.add(x,w.gamma);let I=d.mul(d.mul(d.mul(C,F),x),_),B=d.mul(d.mul(d.mul(C,F),x),f),E=d.add(l,d.mul(w.beta,m));E=d.add(E,w.gamma);let v=d.add(c,d.mul(w.beta,b));v=d.add(v,w.gamma);let S=d.add(r,d.mul(w.beta,y));S=d.add(S,w.gamma);let P=d.mul(d.mul(d.mul(E,v),S),g),q=d.mul(d.mul(d.mul(E,v),S),h),O=d.sub(I,P),G=d.sub(B,q);p.T2.set(O,a*u),p.T2z.set(G,a*u),t=d.mul(t,d.w[s.power+2])}e&&e.info("··· Computing T2 ifft");m.T2=await Tr.fromEvaluations(p.T2,r,e),e&&e.info("··· Computing T2 / ZH");m.T2.divByZerofier(s.domainSize,d.one),e&&e.info("··· Computing T2z ifft");if(m.T2z=await Tr.fromEvaluations(p.T2z,r,e),m.T2.add(m.T2z),m.T2.degree()>=3*s.domainSize)throw new Error("T2 Polynomial is not well calculated");delete p.T2,delete p.T2z,delete m.T2z}(),e&&e.info("> Computing C2 polynomial");await async function(){let t=new Zr(3,r,e);if(t.addPolynomial(0,m.Z),t.addPolynomial(1,m.T1),t.addPolynomial(2,m.T2),m.C2=t.getPolynomial(),m.C2.degree()>=9*s.domainSize)throw new Error("C2 Polynomial is not well calculated")}(),e&&e.info("> Computing C2 multi exponentiation");let a=await m.C2.multiExponentiation(C,"C2");return A.addPolynomial("C2",a),0}(),delete p.A,delete p.B,delete p.C,delete L.A,delete L.B,delete L.C,delete L.Sigma1,delete L.Sigma2,delete L.Sigma3,delete L.lagrange1,delete L.Z,globalThis.gc&&globalThis.gc(),e&&e.info("> ROUND 3"),await async function(){e&&e.info("> Computing challenge xi");const t=new Ar(r);t.addScalar(w.gamma),t.addPolCommitment(A.getPolynomial("C2")),w.xiSeed=t.getChallenge();const a=d.square(w.xiSeed);y.w8=[],y.w8[0]=d.one;for(let t=1;t<8;t++)y.w8[t]=d.mul(y.w8[t-1],s.w8);y.w4=[],y.w4[0]=d.one;for(let t=1;t<4;t++)y.w4[t]=d.mul(y.w4[t-1],s.w4);y.w3=[],y.w3[0]=d.one,y.w3[1]=s.w3,y.w3[2]=d.square(s.w3),y.S0={},y.S0.h0w8=[],y.S0.h0w8[0]=d.mul(a,w.xiSeed);for(let t=1;t<8;t++)y.S0.h0w8[t]=d.mul(y.S0.h0w8[0],y.w8[t]);y.S1={},y.S1.h1w4=[],y.S1.h1w4[0]=d.square(y.S0.h0w8[0]);for(let t=1;t<4;t++)y.S1.h1w4[t]=d.mul(y.S1.h1w4[0],y.w4[t]);y.S2={},y.S2.h2w3=[],y.S2.h2w3[0]=d.mul(y.S1.h1w4[0],a),y.S2.h2w3[1]=d.mul(y.S2.h2w3[0],y.w3[1]),y.S2.h2w3[2]=d.mul(y.S2.h2w3[0],y.w3[2]),y.S2.h3w3=[],y.S2.h3w3[0]=d.mul(y.S2.h2w3[0],s.wr),y.S2.h3w3[1]=d.mul(y.S2.h3w3[0],y.w3[1]),y.S2.h3w3[2]=d.mul(y.S2.h3w3[0],y.w3[2]),w.xi=d.mul(d.square(y.S2.h2w3[0]),y.S2.h2w3[0]),e&&e.info("··· challenges.xi: "+d.toString(w.xi));m.QL=new Tr(new Pa(g),r,e),m.QR=new Tr(new Pa(g),r,e),m.QM=new Tr(new Pa(g),r,e),m.QO=new Tr(new Pa(g),r,e),m.QC=new Tr(new Pa(g),r,e),await l.readToBuffer(m.QL.coef,0,g,c[oi][0].p),await l.readToBuffer(m.QR.coef,0,g,c[ii][0].p),await l.readToBuffer(m.QM.coef,0,g,c[ni][0].p),await l.readToBuffer(m.QO.coef,0,g,c[li][0].p),await l.readToBuffer(m.QC.coef,0,g,c[ci][0].p),e&&e.info("··· Computing evaluations");A.addEvaluation("ql",m.QL.evaluate(w.xi)),A.addEvaluation("qr",m.QR.evaluate(w.xi)),A.addEvaluation("qm",m.QM.evaluate(w.xi)),A.addEvaluation("qo",m.QO.evaluate(w.xi)),A.addEvaluation("qc",m.QC.evaluate(w.xi)),A.addEvaluation("s1",m.Sigma1.evaluate(w.xi)),A.addEvaluation("s2",m.Sigma2.evaluate(w.xi)),A.addEvaluation("s3",m.Sigma3.evaluate(w.xi)),A.addEvaluation("a",m.A.evaluate(w.xi)),A.addEvaluation("b",m.B.evaluate(w.xi)),A.addEvaluation("c",m.C.evaluate(w.xi)),A.addEvaluation("z",m.Z.evaluate(w.xi)),w.xiw=d.mul(w.xi,d.w[s.power]),A.addEvaluation("zw",m.Z.evaluate(w.xiw)),A.addEvaluation("t1w",m.T1.evaluate(w.xiw)),A.addEvaluation("t2w",m.T2.evaluate(w.xiw))}(),delete m.A,delete m.B,delete m.C,delete m.Z,delete m.T1,delete m.T2,delete m.Sigma1,delete m.Sigma2,delete m.Sigma3,delete m.QL,delete m.QR,delete m.QM,delete m.QC,delete m.QO,globalThis.gc&&globalThis.gc(),e&&e.info("> ROUND 4"),await async function(){e&&e.info("> Computing challenge alpha");const t=new Ar(r);t.addScalar(w.xiSeed),t.addScalar(A.getEvaluation("ql")),t.addScalar(A.getEvaluation("qr")),t.addScalar(A.getEvaluation("qm")),t.addScalar(A.getEvaluation("qo")),t.addScalar(A.getEvaluation("qc")),t.addScalar(A.getEvaluation("s1")),t.addScalar(A.getEvaluation("s2")),t.addScalar(A.getEvaluation("s3")),t.addScalar(A.getEvaluation("a")),t.addScalar(A.getEvaluation("b")),t.addScalar(A.getEvaluation("c")),t.addScalar(A.getEvaluation("z")),t.addScalar(A.getEvaluation("zw")),t.addScalar(A.getEvaluation("t1w")),t.addScalar(A.getEvaluation("t2w")),w.alpha=t.getChallenge(),e&&e.info("··· challenges.alpha: "+d.toString(w.alpha));e&&e.info("> Reading C0 polynomial");m.C0=new Tr(new Pa(8*g),r,e),await l.readToBuffer(m.C0.coef,0,8*g,c[gi][0].p),e&&e.info("> Computing R0 polynomial");(function(){if(m.R0=Tr.lagrangePolynomialInterpolation([y.S0.h0w8[0],y.S0.h0w8[1],y.S0.h0w8[2],y.S0.h0w8[3],y.S0.h0w8[4],y.S0.h0w8[5],y.S0.h0w8[6],y.S0.h0w8[7]],[m.C0.evaluate(y.S0.h0w8[0]),m.C0.evaluate(y.S0.h0w8[1]),m.C0.evaluate(y.S0.h0w8[2]),m.C0.evaluate(y.S0.h0w8[3]),m.C0.evaluate(y.S0.h0w8[4]),m.C0.evaluate(y.S0.h0w8[5]),m.C0.evaluate(y.S0.h0w8[6]),m.C0.evaluate(y.S0.h0w8[7])],r),m.R0.degree()>7)throw new Error("R0 Polynomial is not well calculated")})(),e&&e.info("> Computing R1 polynomial");(function(){if(m.R1=Tr.lagrangePolynomialInterpolation([y.S1.h1w4[0],y.S1.h1w4[1],y.S1.h1w4[2],y.S1.h1w4[3]],[m.C1.evaluate(y.S1.h1w4[0]),m.C1.evaluate(y.S1.h1w4[1]),m.C1.evaluate(y.S1.h1w4[2]),m.C1.evaluate(y.S1.h1w4[3])],r),m.R1.degree()>3)throw new Error("R1 Polynomial is not well calculated")})(),e&&e.info("> Computing R2 polynomial");(function(){if(m.R2=Tr.lagrangePolynomialInterpolation([y.S2.h2w3[0],y.S2.h2w3[1],y.S2.h2w3[2],y.S2.h3w3[0],y.S2.h3w3[1],y.S2.h3w3[2]],[m.C2.evaluate(y.S2.h2w3[0]),m.C2.evaluate(y.S2.h2w3[1]),m.C2.evaluate(y.S2.h2w3[2]),m.C2.evaluate(y.S2.h3w3[0]),m.C2.evaluate(y.S2.h3w3[1]),m.C2.evaluate(y.S2.h3w3[2])],r),m.R2.degree()>5)throw new Error("R2 Polynomial is not well calculated")})(),e&&e.info("> Computing F polynomial");await async function(){e&&e.info("··· Computing F polynomial");m.F=Tr.fromPolynomial(m.C0,r,e),m.F.sub(m.R0),m.F.divByZerofier(8,w.xi);let t=Tr.fromPolynomial(m.C1,r,e);t.sub(m.R1),t.mulScalar(w.alpha),t.divByZerofier(4,w.xi);let a=Tr.fromPolynomial(m.C2,r,e);if(a.sub(m.R2),a.mulScalar(d.square(w.alpha)),a.divByZerofier(3,w.xi),a.divByZerofier(3,w.xiw),m.F.add(t),m.F.add(a),m.F.degree()>=9*s.domainSize-6)throw new Error("F Polynomial is not well calculated")}(),e&&e.info("> Computing W1 multi exponentiation");let a=await m.F.multiExponentiation(C,"W1");return A.addPolynomial("W1",a),0}(),globalThis.gc&&globalThis.gc(),e&&e.info("> ROUND 5"),await async function(){e&&e.info("> Computing challenge y");const t=new Ar(r);t.addScalar(w.alpha),t.addPolCommitment(A.getPolynomial("W1")),w.y=t.getChallenge(),e&&e.info("··· challenges.y: "+d.toString(w.y));e&&e.info("> Computing L polynomial");await async function(){e&&e.info("··· Computing L polynomial");const t=m.R0.evaluate(w.y),a=m.R1.evaluate(w.y),o=m.R2.evaluate(w.y);let i=d.sub(w.y,y.S0.h0w8[0]);for(let t=1;t<8;t++)i=d.mul(i,d.sub(w.y,y.S0.h0w8[t]));let n=d.sub(w.y,y.S1.h1w4[0]);for(let t=1;t<4;t++)n=d.mul(n,d.sub(w.y,y.S1.h1w4[t]));let l=d.sub(w.y,y.S2.h2w3[0]);for(let t=1;t<3;t++)l=d.mul(l,d.sub(w.y,y.S2.h2w3[t]));for(let t=0;t<3;t++)l=d.mul(l,d.sub(w.y,y.S2.h3w3[t]));let c=d.mul(n,l),u=d.mul(w.alpha,d.mul(i,l)),_=d.mul(d.square(w.alpha),d.mul(i,n));b.denH1=n,b.denH2=l,m.L=Tr.fromPolynomial(m.C0,r,e),m.L.subScalar(t),m.L.mulScalar(c);let g=Tr.fromPolynomial(m.C1,r,e);g.subScalar(a),g.mulScalar(u);let f=Tr.fromPolynomial(m.C2,r,e);f.subScalar(o),f.mulScalar(_),m.L.add(g),m.L.add(f),e&&e.info("> Computing ZT polynomial");await async function(){m.ZT=Tr.zerofierPolynomial([y.S0.h0w8[0],y.S0.h0w8[1],y.S0.h0w8[2],y.S0.h0w8[3],y.S0.h0w8[4],y.S0.h0w8[5],y.S0.h0w8[6],y.S0.h0w8[7],y.S1.h1w4[0],y.S1.h1w4[1],y.S1.h1w4[2],y.S1.h1w4[3],y.S2.h2w3[0],y.S2.h2w3[1],y.S2.h2w3[2],y.S2.h3w3[0],y.S2.h3w3[1],y.S2.h3w3[2]],r)}();const h=m.ZT.evaluate(w.y);if(m.F.mulScalar(h),m.L.sub(m.F),m.L.degree()>=9*s.domainSize)throw new Error("L Polynomial is not well calculated");delete p.L}(),e&&e.info("> Computing ZTS2 polynomial");await async function(){m.ZTS2=Tr.zerofierPolynomial([y.S1.h1w4[0],y.S1.h1w4[1],y.S1.h1w4[2],y.S1.h1w4[3],y.S2.h2w3[0],y.S2.h2w3[1],y.S2.h2w3[2],y.S2.h3w3[0],y.S2.h3w3[1],y.S2.h3w3[2]],r)}();let a=m.ZTS2.evaluate(w.y);a=d.inv(a),m.L.mulScalar(a);const o=Tr.fromCoefficientsArray([d.neg(w.y),d.one],r);e&&e.info("> Computing W' = L / ZTS2 polynomial");const i=m.L.divBy(o);if(i.degree()>0)throw new Error(`Degree of L(X)/(ZTS2(y)(X-y)) remainder is ${i.degree()} and should be 0`);if(m.L.degree()>=9*s.domainSize-1)throw new Error("Degree of L(X)/(ZTS2(y)(X-y)) is not correct");e&&e.info("> Computing W' multi exponentiation");let n=await m.L.multiExponentiation(C,"W2");return A.addPolynomial("W2",n),0}(),delete m.C0,delete m.C1,delete m.C2,delete m.R1,delete m.R2,delete m.F,delete m.L,delete m.ZT,delete m.ZTS2,await l.close(),globalThis.gc&&globalThis.gc(),A.addEvaluation("inv",function(){let t=w.xi;for(let a=0;a Reading PTau file");const{fd:i,sections:n}=await Te(a,"ptau",1);if(!n[12])throw new Error("Powers of Tau is not well prepared. Section 12 missing.");o&&o.info("> Getting curve from PTau settings");const{curve:l}=await Ac(i,n);o&&o.info("> Reading r1cs file");const{fd:c,sections:s}=await Te(t,"r1cs",1),r=await Zs(c,s,{loadConstraints:!1,loadCustomGates:!0});if(r.prime!==l.r)throw new Error("r1cs curve does not match powers of tau ceremony curve");const d=l.Fr,u=l.Fr.n8,_=2*l.G1.F.n8,g=2*l.G2.F.n8;let f,h={},p={},m={nVars:r.nVars,nPublic:r.nOutputs+r.nPubInputs};const L=new lr;let b=new lr;if(o&&o.info("> Processing FFlonk constraints"),await async function(t,a,e){for(let a=0;a computing k1 and k2");const[w,y]=function(){let t=d.two;for(;e(t,[],m.cirPower);)d.add(t,d.one);let a=d.add(t,d.one);for(;e(a,[t],m.cirPower);)d.add(a,d.one);return[t,a];function e(t,a,e){const o=2**e;let i=d.one;for(let n=0;n computing w3");const A=function(){let t=d.e(31624),a=_e.div(3648040478639879203707734290876212514758060733402672390616367364429301415936n,_e.e(3));return d.exp(t,a)}();o&&o.info("> computing w4");const C=d.w[2];o&&o.info("> computing w8");const F=d.w[3];o&&o.info("> computing wr");const x=function(t,a){const e=a.e(467799165886069610036046866799264026481344299079011762026774533774345988080n);return a.exp(e,2**(28-t))}(m.cirPower,l.Fr);return await async function(){o&&o.info("> Writing the zkey file");const t=await Me(e,"zkey",1,17,1<<22,1<<24);o&&o.info("··· Writing Section 1. Zkey Header");await async function(t){await Ue(t,1),await t.writeULE32(Yo),await Qe(t)}(t),o&&o.info(`··· Writing Section ${Xo}. Additions`);await async function(t){await Ue(t,Xo);const a=new Uint8Array(8+2*u),e=new DataView(a.buffer);for(let i=0;i=8*m.domainSize)throw new Error("C0 Polynomial is not well calculated");await Ue(t,gi),await t.write(h.C0.coef),await Qe(t)}(t),globalThis.gc&&globalThis.gc();o&&o.info(`··· Writing Section ${Jo}. FFlonk Header`);await async function(t){await Ue(t,Jo);const a=l.q,e=8*(Math.floor((_e.bitLength(a)-1)/64)+1);await t.writeULE32(e),await Ne(t,a,e);const o=l.r,c=8*(Math.floor((_e.bitLength(o)-1)/64)+1);let s;await t.writeULE32(c),await Ne(t,o,c),await t.writeULE32(m.nVars),await t.writeULE32(m.nPublic),await t.writeULE32(m.domainSize),await t.writeULE32(b.length),await t.writeULE32(L.length),await t.write(w),await t.write(y),await t.write(A),await t.write(C),await t.write(F),await t.write(x),s=await i.read(g,n[3][0].p+g),await t.write(s);let r=await h.C0.multiExponentiation(f,"C0");await t.write(r),await Qe(t)}(t),globalThis.gc&&globalThis.gc();o&&o.info("> Writing the zkey file finished");await t.close()}(),await c.close(),await i.close(),o&&o.info("FFLONK SETUP FINISHED"),0;async function I(t,a,e,i){await Ue(t,a);for(let a=0;a Checking commitments belong to G1"),!function(t,a,e){const o=t.G1;return o.isValid(a.polynomials.C1)&&o.isValid(a.polynomials.C2)&&o.isValid(a.polynomials.W1)&&o.isValid(a.polynomials.W2)&&o.isValid(e.C0)}(i,l,n))return o&&o.error("Proof commitments are not valid"),!1;if(o&&o.info("> Checking evaluations belong to F"),!function(t,a){return ad(t,a.evaluations.ql)&&ad(t,a.evaluations.qr)&&ad(t,a.evaluations.qm)&&ad(t,a.evaluations.qo)&&ad(t,a.evaluations.qc)&&ad(t,a.evaluations.s1)&&ad(t,a.evaluations.s2)&&ad(t,a.evaluations.s3)&&ad(t,a.evaluations.a)&&ad(t,a.evaluations.b)&&ad(t,a.evaluations.c)&&ad(t,a.evaluations.z)&&ad(t,a.evaluations.zw)&&ad(t,a.evaluations.t1w)&&ad(t,a.evaluations.t2w)}(i,l))return o&&o.error("Proof evaluations are not valid."),!1;if(o&&o.info("> Checking public inputs belong to F"),!function(t,a){for(let e=0;e Computing challenges");const{challenges:r,roots:d}=function(t,a,e,o,i){const n=t.Fr,l={},c={},s=new Ar(t);s.addPolCommitment(e.C0);for(let t=0;t Computing Zero polynomial evaluation Z_H(xi)"),r.zh=s.sub(r.xiN,s.one),r.invzh=s.inv(r.zh),o&&o.info("> Computing Lagrange evaluations");const u=await async function(t,a,e){const o=t.Fr,i=Math.max(1,e.nPublic),n=new Pa(i*o.n8);let l=new Pa(i*o.n8),c=o.one;for(let t=0;t Computing polynomial identities PI(X)");const _=function(t,a,e){const o=t.Fr;let i=o.zero;for(let t=0;t Computing r0(y)");const g=function(t,a,e,o,i){const n=o.Fr,l=ed(e.S0.h0w8,a.y,a.xi,o);i&&i.info("··· Computing r0(y)");let c=n.zero;for(let a=0;a<8;a++){let o=[];o[1]=e.S0.h0w8[a];for(let t=2;t<8;t++)o[t]=n.mul(o[t-1],e.S0.h0w8[a]);let i=n.add(t.evaluations.ql,n.mul(t.evaluations.qr,o[1]));i=n.add(i,n.mul(t.evaluations.qo,o[2])),i=n.add(i,n.mul(t.evaluations.qm,o[3])),i=n.add(i,n.mul(t.evaluations.qc,o[4])),i=n.add(i,n.mul(t.evaluations.s1,o[5])),i=n.add(i,n.mul(t.evaluations.s2,o[6])),i=n.add(i,n.mul(t.evaluations.s3,o[7])),c=n.add(c,n.mul(i,l[a]))}return c}(l,r,d,i,o);o&&o.info("> Computing r1(y)");const f=function(t,a,e,o,i,n){const l=i.Fr,c=ed(e.S1.h1w4,a.y,a.xi,i);n&&n.info("··· Computing T0(xi)");let s=l.mul(t.evaluations.ql,t.evaluations.a);s=l.add(s,l.mul(t.evaluations.qr,t.evaluations.b)),s=l.add(s,l.mul(t.evaluations.qm,l.mul(t.evaluations.a,t.evaluations.b))),s=l.add(s,l.mul(t.evaluations.qo,t.evaluations.c)),s=l.add(s,t.evaluations.qc),s=l.add(s,o),s=l.mul(s,a.invzh),n&&n.info("··· Computing C1(h_1ω_4^i) values");let r=l.zero;for(let a=0;a<4;a++){let o=t.evaluations.a;o=l.add(o,l.mul(e.S1.h1w4[a],t.evaluations.b));const i=l.square(e.S1.h1w4[a]);o=l.add(o,l.mul(i,t.evaluations.c)),o=l.add(o,l.mul(l.mul(i,e.S1.h1w4[a]),s)),r=l.add(r,l.mul(o,c[a]))}return r}(l,r,d,_,i,o);o&&o.info("> Computing r2(y)");const h=function(t,a,e,o,i,n,l){const c=n.Fr,s=function(t,a,e,o,i){const n=i.Fr,l=[],c=t[0].length,s=c*t.length,r=n.exp(a,s),d=n.mul(n.add(e,o),n.exp(a,c)),u=n.mul(e,o),_=n.add(n.sub(r,d),u);let g=n.mul(n.mul(n.e(c),t[0][0]),n.sub(e,o));for(let e=0;e Computing F");const p=function(t,a,e,o,i){const n=t.G1,l=t.Fr;let c=l.sub(o.y,i.S0.h0w8[0]);for(let t=1;t<8;t++)c=l.mul(c,l.sub(o.y,i.S0.h0w8[t]));o.temp=c;let s=l.sub(o.y,i.S1.h1w4[0]);for(let t=1;t<4;t++)s=l.mul(s,l.sub(o.y,i.S1.h1w4[t]));let r=l.sub(o.y,i.S2.h2w3[0]);for(let t=1;t<3;t++)r=l.mul(r,l.sub(o.y,i.S2.h2w3[t]));for(let t=0;t<3;t++)r=l.mul(r,l.sub(o.y,i.S2.h3w3[t]));o.quotient1=l.mul(o.alpha,l.div(c,s)),o.quotient2=l.mul(l.square(o.alpha),l.div(c,r));let d=n.timesFr(a.polynomials.C1,o.quotient1),u=n.timesFr(a.polynomials.C2,o.quotient2);return n.add(e.C0,n.add(d,u))}(i,l,n,r,d);o&&o.info("> Computing E");const m=function(t,a,e,o,i,n,l){const c=t.G1,s=t.Fr;let r=s.mul(n,e.quotient1),d=s.mul(l,e.quotient2);return c.timesFr(c.one,s.add(i,s.add(r,d)))}(i,0,r,0,g,f,h);o&&o.info("> Computing J");const L=function(t,a,e){const o=t.G1;return o.timesFr(a.polynomials.W1,e.temp)}(i,l,r);o&&o.info("> Validate all evaluations with a pairing");const b=await async function(t,a,e,o,i,n,l){const c=t.G1;let s=c.timesFr(a.polynomials.W2,e.y);s=c.add(c.sub(c.sub(i,n),l),s);const r=t.G2.one,d=a.polynomials.W2,u=o.X_2;return await t.pairingEq(c.neg(s),r,d,u)}(i,l,r,n,p,m,L);return o&&(b?o.info("PROOF VERIFIED SUCCESSFULLY"):o.warn("Invalid Proof")),o&&o.info("FFLONK VERIFIER FINISHED"),b},exportSolidityVerifier:hr,exportSolidityCallData:async function(t,a){const e=od(a),o=od(t),i=await Je(e.curve);i.G1,i.Fr;let n="";for(let t=0;t async function zkeyExportSolidityCalldata(params, options) { @@ -689,6 +736,40 @@ async function zkeyExportSolidityCalldata(params, options) { return 0; } +// sophia gencall +async function zkeyExportSophiaCalldata(params, options) { + let publicName; + let proofName; + + if (params.length < 1) { + publicName = "public.json"; + } else { + publicName = params[0]; + } + + if (params.length < 2) { + proofName = "proof.json"; + } else { + proofName = params[1]; + } + + let type = "sdk"; + if (options.cli) type = "cli"; + + const pub = JSON.parse(fs.readFileSync(publicName, "utf8")); + const proof = JSON.parse(fs.readFileSync(proofName, "utf8")); + + let res; + if (proof.protocol == "groth16") { + res = await groth16.exportSophiaCallData(proof, pub, type); + } else { + throw new Error("Invalid Protocol"); + } + console.log(res); + + return 0; +} + // powersoftau new [powersoftau_0000.ptau]", async function powersOfTauNew(params, options) { let curveName; diff --git a/sophia_smart_contract_tests/README.md b/sophia_smart_contract_tests/README.md new file mode 100644 index 00000000..b54da9c9 --- /dev/null +++ b/sophia_smart_contract_tests/README.md @@ -0,0 +1,9 @@ +## Tests for exported Sophia smart contract verifier + +### Requirements + +You need to have docker installed. + +### Running the tests + +Run the tests with `npm run all`, after installing all dependences with `npm install`. \ No newline at end of file diff --git a/sophia_smart_contract_tests/docker-compose.yml b/sophia_smart_contract_tests/docker-compose.yml new file mode 100644 index 00000000..c23d7f4f --- /dev/null +++ b/sophia_smart_contract_tests/docker-compose.yml @@ -0,0 +1,28 @@ +version: '3.6' +services: + + aeproject_node: + image: aeternity/aeternity:${NODE_TAG:-v6.11.0}-bundle + hostname: node + environment: + AETERNITY_CONFIG: /home/aeternity/aeternity.yaml + volumes: + - './docker/aeternity.yaml:/home/aeternity/aeternity.yaml' + - './docker/accounts.json:/home/aeternity/node/data/aecore/.genesis/accounts_test.json' + + aeproject_compiler: + image: aeternity/aesophia_http:${COMPILER_TAG:-v7.6.0} + hostname: compiler + ports: + - '3080:3080' + + aeproject_proxy: + image: nginx:latest + hostname: proxy + ports: + - '3001:3001' + volumes: + - './docker/nginx.conf:/etc/nginx/conf.d/default.conf' + depends_on: + - aeproject_compiler + - aeproject_node \ No newline at end of file diff --git a/sophia_smart_contract_tests/docker/accounts.json b/sophia_smart_contract_tests/docker/accounts.json new file mode 100644 index 00000000..6ce4cc51 --- /dev/null +++ b/sophia_smart_contract_tests/docker/accounts.json @@ -0,0 +1,13 @@ +{ + "ak_fUq2NesPXcYZ1CcqBcGC3StpdnQw3iVxMA3YSeCNAwfN4myQk": 100000000000000000000000000000000, + "ak_tWZrf8ehmY7CyB1JAoBmWJEeThwWnDpU4NadUdzxVSbzDgKjP": 100000000000000000000000000000000, + "ak_FHZrEbRmanKUe9ECPXVNTLLpRP2SeQCLCT6Vnvs9JuVu78J7V": 100000000000000000000000000000000, + "ak_RYkcTuYcyxQ6fWZsL2G3Kj3K5WCRUEXsi76bPUNkEsoHc52Wp": 100000000000000000000000000000000, + "ak_2VvB4fFu7BQHaSuW5EkQ7GCaM5qiA5BsFUHjJ7dYpAaBoeFCZi": 100000000000000000000000000000000, + "ak_286tvbfP6xe4GY9sEbuN2ftx1LpavQwFVcPor9H4GxBtq5fXws": 100000000000000000000000000000000, + "ak_f9bmi44rdvUGKDsTLp3vMCMLMvvqsMQVWyc3XDAYECmCXEbzy": 100000000000000000000000000000000, + "ak_23p6pT7bajYMJRbnJ5BsbFUuYGX2PBoZAiiYcsrRHZ1BUY2zSF": 100000000000000000000000000000000, + "ak_gLYH5tAexTCvvQA6NpXksrkPJKCkLnB9MTDFTVCBuHNDJ3uZv": 100000000000000000000000000000000, + "ak_zPoY7cSHy2wBKFsdWJGXM7LnSjVt6cn1TWBDdRBUMC7Tur2NQ": 100000000000000000000000000000000, + "ak_RdoCvwe7kxPu2VBv2gQAc1V81sGyTTuxFv36AcvNQYZN7qgut": 0 +} diff --git a/sophia_smart_contract_tests/docker/aeternity.yaml b/sophia_smart_contract_tests/docker/aeternity.yaml new file mode 100644 index 00000000..9415c377 --- /dev/null +++ b/sophia_smart_contract_tests/docker/aeternity.yaml @@ -0,0 +1,47 @@ +http: + external: + gas_limit: 60000000 + internal: + debug_endpoints: true + listen_address: 0.0.0.0 + endpoints: + dry-run: true + +system: + plugin_path: /home/aeternity/node/plugins + plugins: + - name: aeplugin_dev_mode + config: # keeping the old config style at first to stay backwards compatible + keyblock_interval: 0 + microblock_interval: 0 + auto_emit_microblocks: true + +dev_mode: + keyblock_interval: 0 + microblock_interval: 0 + auto_emit_microblocks: true + +fork_management: + network_id: ae_dev + +chain: + persist: true + consensus: + "0": + name: "on_demand" # keeping the old config style at first to stay backwards compatible + type: "on_demand" + +mining: + beneficiary: "ak_RdoCvwe7kxPu2VBv2gQAc1V81sGyTTuxFv36AcvNQYZN7qgut" + beneficiary_reward_delay: 2 + strictly_follow_top: true + +websocket: + channel: + port: 3014 + listen_address: 0.0.0.0 + +logging: + # Controls the overload protection in the logs. + hwm: 50 + level: debug diff --git a/sophia_smart_contract_tests/docker/nginx.conf b/sophia_smart_contract_tests/docker/nginx.conf new file mode 100644 index 00000000..4fd1188c --- /dev/null +++ b/sophia_smart_contract_tests/docker/nginx.conf @@ -0,0 +1,32 @@ +server { + listen 3001; + access_log off; + + location /v2/debug { + proxy_pass http://node:3113; + } + + location /v3/debug { + proxy_pass http://node:3113; + } + + location /channel { + proxy_pass http://node:3014; + } + + location /v2 { + proxy_pass http://node:3013; + } + + location /v3 { + proxy_pass http://node:3013; + } + + location /api { + proxy_pass http://node:3013; + } + + location / { + proxy_pass http://node:3313; + } +} diff --git a/sophia_smart_contract_tests/input/circuit2.r1cs b/sophia_smart_contract_tests/input/circuit2.r1cs new file mode 100644 index 00000000..9ce5664d Binary files /dev/null and b/sophia_smart_contract_tests/input/circuit2.r1cs differ diff --git a/sophia_smart_contract_tests/input/circuit3.r1cs b/sophia_smart_contract_tests/input/circuit3.r1cs new file mode 100644 index 00000000..361761e1 Binary files /dev/null and b/sophia_smart_contract_tests/input/circuit3.r1cs differ diff --git a/sophia_smart_contract_tests/input/pot11_bls12381_final.ptau b/sophia_smart_contract_tests/input/pot11_bls12381_final.ptau new file mode 100644 index 00000000..3f530374 Binary files /dev/null and b/sophia_smart_contract_tests/input/pot11_bls12381_final.ptau differ diff --git a/sophia_smart_contract_tests/input/witness2.wtns b/sophia_smart_contract_tests/input/witness2.wtns new file mode 100644 index 00000000..6153a2b2 Binary files /dev/null and b/sophia_smart_contract_tests/input/witness2.wtns differ diff --git a/sophia_smart_contract_tests/input/witness3.wtns b/sophia_smart_contract_tests/input/witness3.wtns new file mode 100644 index 00000000..8bbbdc31 Binary files /dev/null and b/sophia_smart_contract_tests/input/witness3.wtns differ diff --git a/sophia_smart_contract_tests/package-lock.json b/sophia_smart_contract_tests/package-lock.json new file mode 100644 index 00000000..cea8e095 --- /dev/null +++ b/sophia_smart_contract_tests/package-lock.json @@ -0,0 +1,2618 @@ +{ + "name": "aeproject-project", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "aeproject-project", + "version": "1.0.0", + "dependencies": { + "@aeternity/aepp-sdk": "^13.2.1" + }, + "devDependencies": { + "@aeternity/aeproject": "^4.8.2", + "chai": "^4.3.8", + "ffjavascript": "0.2.59", + "mocha": "^10.2.0", + "snarkjs": "file:.." + } + }, + "node_modules/@aeternity/aepp-calldata": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@aeternity/aepp-calldata/-/aepp-calldata-1.6.0.tgz", + "integrity": "sha512-usqmuGoxGPH2i1cUvSJKA38ixWBQQT8J+yqe3Zfm22QtdKC2+aD/6cepKq32rB05obJlKsnnyaNbo4fYU8y5Gg==", + "dependencies": { + "blakejs": "^1.2.1", + "bs58": "^5.0.0", + "rlp": "^3.0.0", + "safe-buffer": "^5.2.1", + "sha.js": "^2.4.11" + } + }, + "node_modules/@aeternity/aepp-sdk": { + "version": "13.2.2", + "resolved": "https://registry.npmjs.org/@aeternity/aepp-sdk/-/aepp-sdk-13.2.2.tgz", + "integrity": "sha512-hTpAV4E8I0Y/IfjizsHlpzPN3gW4Bkr08GVqmRcGUh5yi7MQA9N54kbTfl+kQlcp6AYC9WVk3fhNuoTUOzISig==", + "dependencies": { + "@aeternity/aepp-calldata": "^1.5.1", + "@aeternity/argon2": "^0.0.1", + "@aeternity/uuid": "^0.0.1", + "@azure/core-client": "1.6.0", + "@azure/core-rest-pipeline": "^1.11.0", + "@babel/runtime-corejs3": "^7.22.6", + "@ledgerhq/hw-transport": "^6.28.6", + "@types/aes-js": "^3.1.1", + "@types/json-bigint": "^1.0.1", + "@types/node": "~18.11.9", + "@types/sha.js": "^2.4.1", + "@types/uuid": "^9.0.2", + "@types/webextension-polyfill": "^0.10.1", + "@types/websocket": "^1.0.5", + "@types/ws": "^8.5.5", + "aes-js": "^3.1.2", + "bignumber.js": "^9.1.1", + "bip32-path": "^0.4.2", + "blakejs": "^1.2.1", + "bs58": "^5.0.0", + "buffer": "^6.0.3", + "canonicalize": "^2.0.0", + "events": "^3.3.0", + "isomorphic-ws": "^5.0.0", + "json-bigint": "^1.0.0", + "process": "^0.11.10", + "rlp": "^3.0.0", + "sha.js": "^2.4.11", + "tweetnacl": "^1.0.3", + "tweetnacl-auth": "^1.0.1", + "varuint-bitcoin": "^1.1.2", + "websocket": "^1.0.34", + "ws": "^8.13.0" + }, + "engines": { + "node": ">=14.19.0" + } + }, + "node_modules/@aeternity/aeproject": { + "version": "4.8.3", + "resolved": "https://registry.npmjs.org/@aeternity/aeproject/-/aeproject-4.8.3.tgz", + "integrity": "sha512-4fVwkERpemRcdqezQJYgYt00tn9ugYL1BN4HFPaBahs2j6ygK/AVxm/0gyVDgsRFl/Gl3UbM6z2zBuueAytysg==", + "dev": true, + "dependencies": { + "@aeternity/aepp-sdk": "^13.2.1", + "commander": "^11.0.0", + "promisify-child-process": "^4.1.2", + "prompts": "^2.4.2" + }, + "bin": { + "aeproject": ".build/esm/src/cli.js" + }, + "engines": { + "node": ">=16.0.0", + "npm": ">=8.0.0" + } + }, + "node_modules/@aeternity/argon2": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/@aeternity/argon2/-/argon2-0.0.1.tgz", + "integrity": "sha512-xC+znnq5sL3FiQcGWapFqKAZpJJBXnFhW8+pP7OE2xL7zH15X66jzdgqi1LHRKJM6UHxknqKQX/pqgUrpLruxw==", + "dependencies": { + "@aeternity/argon2-browser": "^0.1.2", + "argon2": "^0.28.7" + } + }, + "node_modules/@aeternity/argon2-browser": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/@aeternity/argon2-browser/-/argon2-browser-0.1.2.tgz", + "integrity": "sha512-nL3xZYf0JXVIm6HFyppXn9fgHjmSjYa1PBYXzD1/pLbECdikD+r3IuhIR3dAwn8nq9xShjHPr9ZnJUbbUvva4g==" + }, + "node_modules/@aeternity/argon2/node_modules/argon2": { + "version": "0.28.7", + "resolved": "https://registry.npmjs.org/argon2/-/argon2-0.28.7.tgz", + "integrity": "sha512-pvsScM3Fq7b+jolXkZHh8nRQx0uD/WeelnwYPMRpn4pAydoa1gqeL/KRdWAag4Hnu1TJNBTAfqyTjV+ZHwNnYA==", + "hasInstallScript": true, + "dependencies": { + "@mapbox/node-pre-gyp": "^1.0.9", + "@phc/format": "^1.0.0", + "node-addon-api": "^5.0.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aeternity/argon2/node_modules/node-addon-api": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-5.1.0.tgz", + "integrity": "sha512-eh0GgfEkpnoWDq+VY8OyvYhFEzBk6jIYbRKdIlyTiAXIVJ8PyBaKb0rp7oDtoddbdoHWhq8wwr+XZ81F1rpNdA==" + }, + "node_modules/@aeternity/uuid": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/@aeternity/uuid/-/uuid-0.0.1.tgz", + "integrity": "sha512-ecE01IM9ZJwN27v6rlB0fKZVk4j8vOlcBj1/VdtF+rb5Kfy65H+QyHL1laNM84vRdz484UvxwrG/SXHYeA3IkQ==", + "bin": { + "uuid": "dist/bin/uuid" + } + }, + "node_modules/@azure/abort-controller": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@azure/abort-controller/-/abort-controller-1.1.0.tgz", + "integrity": "sha512-TrRLIoSQVzfAJX9H1JeFjzAoDGcoK1IYX1UImfceTZpsyYfWr09Ss1aHW1y5TrrR3iq6RZLBwJ3E24uwPhwahw==", + "dependencies": { + "tslib": "^2.2.0" + }, + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/@azure/core-auth": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@azure/core-auth/-/core-auth-1.6.0.tgz", + "integrity": "sha512-3X9wzaaGgRaBCwhLQZDtFp5uLIXCPrGbwJNWPPugvL4xbIGgScv77YzzxToKGLAKvG9amDoofMoP+9hsH1vs1w==", + "dependencies": { + "@azure/abort-controller": "^2.0.0", + "@azure/core-util": "^1.1.0", + "tslib": "^2.2.0" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@azure/core-auth/node_modules/@azure/abort-controller": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@azure/abort-controller/-/abort-controller-2.0.0.tgz", + "integrity": "sha512-RP/mR/WJchR+g+nQFJGOec+nzeN/VvjlwbinccoqfhTsTHbb8X5+mLDp48kHT0ueyum0BNSwGm0kX0UZuIqTGg==", + "dependencies": { + "tslib": "^2.2.0" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@azure/core-client": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@azure/core-client/-/core-client-1.6.0.tgz", + "integrity": "sha512-YhSf4cb61ApSjItscp9XoaLq8KRnacPDAhmjAZSMnn/gs6FhFbZNfOBOErG2dDj7JRknVtCmJ5mLmfR2sLa11A==", + "dependencies": { + "@azure/abort-controller": "^1.0.0", + "@azure/core-auth": "^1.3.0", + "@azure/core-rest-pipeline": "^1.5.0", + "@azure/core-tracing": "^1.0.0", + "@azure/core-util": "^1.0.0", + "@azure/logger": "^1.0.0", + "tslib": "^2.2.0" + }, + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/@azure/core-rest-pipeline": { + "version": "1.14.0", + "resolved": "https://registry.npmjs.org/@azure/core-rest-pipeline/-/core-rest-pipeline-1.14.0.tgz", + "integrity": "sha512-Tp4M6NsjCmn9L5p7HsW98eSOS7A0ibl3e5ntZglozT0XuD/0y6i36iW829ZbBq0qihlGgfaeFpkLjZ418KDm1Q==", + "dependencies": { + "@azure/abort-controller": "^2.0.0", + "@azure/core-auth": "^1.4.0", + "@azure/core-tracing": "^1.0.1", + "@azure/core-util": "^1.3.0", + "@azure/logger": "^1.0.0", + "http-proxy-agent": "^5.0.0", + "https-proxy-agent": "^5.0.0", + "tslib": "^2.2.0" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@azure/core-rest-pipeline/node_modules/@azure/abort-controller": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@azure/abort-controller/-/abort-controller-2.0.0.tgz", + "integrity": "sha512-RP/mR/WJchR+g+nQFJGOec+nzeN/VvjlwbinccoqfhTsTHbb8X5+mLDp48kHT0ueyum0BNSwGm0kX0UZuIqTGg==", + "dependencies": { + "tslib": "^2.2.0" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@azure/core-tracing": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@azure/core-tracing/-/core-tracing-1.0.1.tgz", + "integrity": "sha512-I5CGMoLtX+pI17ZdiFJZgxMJApsK6jjfm85hpgp3oazCdq5Wxgh4wMr7ge/TTWW1B5WBuvIOI1fMU/FrOAMKrw==", + "dependencies": { + "tslib": "^2.2.0" + }, + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/@azure/core-util": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@azure/core-util/-/core-util-1.7.0.tgz", + "integrity": "sha512-Zq2i3QO6k9DA8vnm29mYM4G8IE9u1mhF1GUabVEqPNX8Lj833gdxQ2NAFxt2BZsfAL+e9cT8SyVN7dFVJ/Hf0g==", + "dependencies": { + "@azure/abort-controller": "^2.0.0", + "tslib": "^2.2.0" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@azure/core-util/node_modules/@azure/abort-controller": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@azure/abort-controller/-/abort-controller-2.0.0.tgz", + "integrity": "sha512-RP/mR/WJchR+g+nQFJGOec+nzeN/VvjlwbinccoqfhTsTHbb8X5+mLDp48kHT0ueyum0BNSwGm0kX0UZuIqTGg==", + "dependencies": { + "tslib": "^2.2.0" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@azure/logger": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@azure/logger/-/logger-1.0.4.tgz", + "integrity": "sha512-ustrPY8MryhloQj7OWGe+HrYx+aoiOxzbXTtgblbV3xwCqpzUK36phH3XNHQKj3EPonyFUuDTfR3qFhTEAuZEg==", + "dependencies": { + "tslib": "^2.2.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@babel/runtime-corejs3": { + "version": "7.23.9", + "resolved": "https://registry.npmjs.org/@babel/runtime-corejs3/-/runtime-corejs3-7.23.9.tgz", + "integrity": "sha512-oeOFTrYWdWXCvXGB5orvMTJ6gCZ9I6FBjR+M38iKNXCsPxr4xT0RTdg5uz1H7QP8pp74IzPtwritEr+JscqHXQ==", + "dependencies": { + "core-js-pure": "^3.30.2", + "regenerator-runtime": "^0.14.0" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@iden3/bigarray": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/@iden3/bigarray/-/bigarray-0.0.2.tgz", + "integrity": "sha512-Xzdyxqm1bOFF6pdIsiHLLl3HkSLjbhqJHVyqaTxXt3RqXBEnmsUmEW47H7VOi/ak7TdkRpNkxjyK5Zbkm+y52g==", + "dev": true + }, + "node_modules/@iden3/binfileutils": { + "version": "0.0.11", + "resolved": "https://registry.npmjs.org/@iden3/binfileutils/-/binfileutils-0.0.11.tgz", + "integrity": "sha512-LylnJoZ0CTdgErnKY8OxohvW4K+p6UHD3sxt+3P9AmMyBQjYR4IpoqoYZZ+9aMj89cmCQ21UvdhndAx04er3NA==", + "dev": true, + "dependencies": { + "fastfile": "0.0.20", + "ffjavascript": "^0.2.48" + } + }, + "node_modules/@ledgerhq/devices": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/@ledgerhq/devices/-/devices-8.2.0.tgz", + "integrity": "sha512-XROTW2gTmmuy+YPPDjdtKKTQ3mfxrPtKtV+a9QFbj8f5MnjVMV0Zpy1BIB4CyIMsVVi4z6+nI67auT7IlsM3SQ==", + "dependencies": { + "@ledgerhq/errors": "^6.16.1", + "@ledgerhq/logs": "^6.12.0", + "rxjs": "^7.8.1", + "semver": "^7.3.5" + } + }, + "node_modules/@ledgerhq/errors": { + "version": "6.16.1", + "resolved": "https://registry.npmjs.org/@ledgerhq/errors/-/errors-6.16.1.tgz", + "integrity": "sha512-4D4wKecGzQpIu7sx03Sg4uE1e8g1oZUndWgw9gw776H8h9ov9c5TxPaldTn2j6orPECAERViLf7LTO4L5pE2Cw==" + }, + "node_modules/@ledgerhq/hw-transport": { + "version": "6.30.3", + "resolved": "https://registry.npmjs.org/@ledgerhq/hw-transport/-/hw-transport-6.30.3.tgz", + "integrity": "sha512-eqtTCGy8wFCxl+hZSEpjVqn1EDjQhFCne/qUyY0aA36efhWUF6bCRAhkq1e5i7g2P6TbxcIM5P5PW67dILuqIQ==", + "dependencies": { + "@ledgerhq/devices": "^8.2.0", + "@ledgerhq/errors": "^6.16.1", + "@ledgerhq/logs": "^6.12.0", + "events": "^3.3.0" + } + }, + "node_modules/@ledgerhq/logs": { + "version": "6.12.0", + "resolved": "https://registry.npmjs.org/@ledgerhq/logs/-/logs-6.12.0.tgz", + "integrity": "sha512-ExDoj1QV5eC6TEbMdLUMMk9cfvNKhhv5gXol4SmULRVCx/3iyCPhJ74nsb3S0Vb+/f+XujBEj3vQn5+cwS0fNA==" + }, + "node_modules/@mapbox/node-pre-gyp": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.11.tgz", + "integrity": "sha512-Yhlar6v9WQgUp/He7BdgzOz8lqMQ8sU+jkCq7Wx8Myc5YFJLbEe7lgui/V7G1qB1DJykHSGwreceSaD60Y0PUQ==", + "dependencies": { + "detect-libc": "^2.0.0", + "https-proxy-agent": "^5.0.0", + "make-dir": "^3.1.0", + "node-fetch": "^2.6.7", + "nopt": "^5.0.0", + "npmlog": "^5.0.1", + "rimraf": "^3.0.2", + "semver": "^7.3.5", + "tar": "^6.1.11" + }, + "bin": { + "node-pre-gyp": "bin/node-pre-gyp" + } + }, + "node_modules/@phc/format": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@phc/format/-/format-1.0.0.tgz", + "integrity": "sha512-m7X9U6BG2+J+R1lSOdCiITLLrxm+cWlNI3HUFA92oLO77ObGNzaKdh8pMLqdZcshtkKuV84olNNXDfMc4FezBQ==", + "engines": { + "node": ">=10" + } + }, + "node_modules/@tootallnate/once": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-2.0.0.tgz", + "integrity": "sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A==", + "engines": { + "node": ">= 10" + } + }, + "node_modules/@types/aes-js": { + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/@types/aes-js/-/aes-js-3.1.4.tgz", + "integrity": "sha512-v3D66IptpUqh+pHKVNRxY8yvp2ESSZXe0rTzsGdzUhEwag7ljVfgCllkWv2YgiYXDhWFBrEywll4A5JToyTNFA==" + }, + "node_modules/@types/json-bigint": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@types/json-bigint/-/json-bigint-1.0.4.tgz", + "integrity": "sha512-ydHooXLbOmxBbubnA7Eh+RpBzuaIiQjh8WGJYQB50JFGFrdxW7JzVlyEV7fAXw0T2sqJ1ysTneJbiyNLqZRAag==" + }, + "node_modules/@types/node": { + "version": "18.11.19", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.19.tgz", + "integrity": "sha512-YUgMWAQBWLObABqrvx8qKO1enAvBUdjZOAWQ5grBAkp5LQv45jBvYKZ3oFS9iKRCQyFjqw6iuEa1vmFqtxYLZw==" + }, + "node_modules/@types/sha.js": { + "version": "2.4.4", + "resolved": "https://registry.npmjs.org/@types/sha.js/-/sha.js-2.4.4.tgz", + "integrity": "sha512-Qukd+D6S2Hm0wLVt2Vh+/eWBIoUt+wF8jWjBsG4F8EFQRwKtYvtXCPcNl2OEUQ1R+eTr3xuSaBYUyM3WD1x/Qw==", + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@types/uuid": { + "version": "9.0.8", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.8.tgz", + "integrity": "sha512-jg+97EGIcY9AGHJJRaaPVgetKDsrTgbRjQ5Msgjh/DQKEFl0DtyRr/VCOyD1T2R1MNeWPK/u7JoGhlDZnKBAfA==" + }, + "node_modules/@types/webextension-polyfill": { + "version": "0.10.7", + "resolved": "https://registry.npmjs.org/@types/webextension-polyfill/-/webextension-polyfill-0.10.7.tgz", + "integrity": "sha512-10ql7A0qzBmFB+F+qAke/nP1PIonS0TXZAOMVOxEUsm+lGSW6uwVcISFNa0I4Oyj0884TZVWGGMIWeXOVSNFHw==" + }, + "node_modules/@types/websocket": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/@types/websocket/-/websocket-1.0.10.tgz", + "integrity": "sha512-svjGZvPB7EzuYS94cI7a+qhwgGU1y89wUgjT6E2wVUfmAGIvRfT7obBvRtnhXCSsoMdlG4gBFGE7MfkIXZLoww==", + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@types/ws": { + "version": "8.5.10", + "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.10.tgz", + "integrity": "sha512-vmQSUcfalpIq0R9q7uTo2lXs6eGIpt9wtnLdMv9LVpIjCA/+ufZRozlVoVelIYixx1ugCBKDhn89vnsEGOCx9A==", + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/abbrev": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", + "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==" + }, + "node_modules/aes-js": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/aes-js/-/aes-js-3.1.2.tgz", + "integrity": "sha512-e5pEa2kBnBOgR4Y/p20pskXI74UEz7de8ZGVo58asOtvSVG5YAbJeELPZxOmt+Bnz3rX753YKhfIn4X4l1PPRQ==" + }, + "node_modules/agent-base": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", + "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", + "dependencies": { + "debug": "4" + }, + "engines": { + "node": ">= 6.0.0" + } + }, + "node_modules/ansi-colors": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz", + "integrity": "sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==", + "dev": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "engines": { + "node": ">=8" + } + }, + "node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/anymatch": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", + "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", + "dev": true, + "dependencies": { + "normalize-path": "^3.0.0", + "picomatch": "^2.0.4" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/aproba": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/aproba/-/aproba-2.0.0.tgz", + "integrity": "sha512-lYe4Gx7QT+MKGbDsA+Z+he/Wtef0BiwDOlK/XkBrdfsh9J/jPPXbX0tE9x9cl27Tmu5gg3QUbUrQYa/y+KOHPQ==" + }, + "node_modules/are-we-there-yet": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-2.0.0.tgz", + "integrity": "sha512-Ci/qENmwHnsYo9xKIcUJN5LeDKdJ6R1Z1j9V/J5wyq8nh/mYPEpIKJbBZXtZjG04HiK7zV/p6Vs9952MrMeUIw==", + "dependencies": { + "delegates": "^1.0.0", + "readable-stream": "^3.6.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "dev": true + }, + "node_modules/assertion-error": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", + "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", + "dev": true, + "engines": { + "node": "*" + } + }, + "node_modules/async": { + "version": "3.2.5", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.5.tgz", + "integrity": "sha512-baNZyqaaLhyLVKm/DlvdW051MSgO6b8eVfIezl9E5PqWxFgzLm/wQntEW4zOytVburDEr0JlALEpdOFwvErLsg==", + "dev": true + }, + "node_modules/b4a": { + "version": "1.6.6", + "resolved": "https://registry.npmjs.org/b4a/-/b4a-1.6.6.tgz", + "integrity": "sha512-5Tk1HLk6b6ctmjIkAcU/Ujv/1WqiDl0F0JdRCR80VsOcUlHcu7pWeWRlOqQLHfDEsVx9YH/aif5AG4ehoCtTmg==", + "dev": true + }, + "node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" + }, + "node_modules/base-x": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/base-x/-/base-x-4.0.0.tgz", + "integrity": "sha512-FuwxlW4H5kh37X/oW59pwTzzTKRzfrrQwhmyspRM7swOEZcHtDZSCt45U6oKgtuFE+WYPblePMVIPR4RZrh/hw==" + }, + "node_modules/base64-js": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, + "node_modules/bfj": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/bfj/-/bfj-7.1.0.tgz", + "integrity": "sha512-I6MMLkn+anzNdCUp9hMRyui1HaNEUCco50lxbvNS4+EyXg8lN3nJ48PjPWtbH8UVS9CuMoaKE9U2V3l29DaRQw==", + "dev": true, + "dependencies": { + "bluebird": "^3.7.2", + "check-types": "^11.2.3", + "hoopy": "^0.1.4", + "jsonpath": "^1.1.1", + "tryer": "^1.0.1" + }, + "engines": { + "node": ">= 8.0.0" + } + }, + "node_modules/bignumber.js": { + "version": "9.1.2", + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.1.2.tgz", + "integrity": "sha512-2/mKyZH9K85bzOEfhXDBFZTGd1CTs+5IHpeFQo9luiBG7hghdC851Pj2WAhb6E3R6b9tZj/XKhbg4fum+Kepug==", + "engines": { + "node": "*" + } + }, + "node_modules/binary-extensions": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", + "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/bip32-path": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/bip32-path/-/bip32-path-0.4.2.tgz", + "integrity": "sha512-ZBMCELjJfcNMkz5bDuJ1WrYvjlhEF5k6mQ8vUr4N7MbVRsXei7ZOg8VhhwMfNiW68NWmLkgkc6WvTickrLGprQ==" + }, + "node_modules/blake2b-wasm": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/blake2b-wasm/-/blake2b-wasm-2.4.0.tgz", + "integrity": "sha512-S1kwmW2ZhZFFFOghcx73+ZajEfKBqhP82JMssxtLVMxlaPea1p9uoLiUZ5WYyHn0KddwbLc+0vh4wR0KBNoT5w==", + "dev": true, + "dependencies": { + "b4a": "^1.0.1", + "nanoassert": "^2.0.0" + } + }, + "node_modules/blakejs": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/blakejs/-/blakejs-1.2.1.tgz", + "integrity": "sha512-QXUSXI3QVc/gJME0dBpXrag1kbzOqCjCX8/b54ntNyW6sjtoqxqRk3LTmXzaJoh71zMsDCjM+47jS7XiwN/+fQ==" + }, + "node_modules/bluebird": { + "version": "3.7.2", + "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", + "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==", + "dev": true + }, + "node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/braces": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "dev": true, + "dependencies": { + "fill-range": "^7.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/browser-stdout": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", + "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", + "dev": true + }, + "node_modules/bs58": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/bs58/-/bs58-5.0.0.tgz", + "integrity": "sha512-r+ihvQJvahgYT50JD05dyJNKlmmSlMoOGwn1lCcEzanPglg7TxYjioQUYehQ9mAR/+hOSd2jRc/Z2y5UxBymvQ==", + "dependencies": { + "base-x": "^4.0.0" + } + }, + "node_modules/buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, + "node_modules/bufferutil": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.0.8.tgz", + "integrity": "sha512-4T53u4PdgsXqKaIctwF8ifXlRTTmEPJ8iEPWFdGZvcf7sbwYo6FKFEX9eNNAnzFZ7EzJAQ3CJeOtCRA4rDp7Pw==", + "hasInstallScript": true, + "dependencies": { + "node-gyp-build": "^4.3.0" + }, + "engines": { + "node": ">=6.14.2" + } + }, + "node_modules/camelcase": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", + "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/canonicalize": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/canonicalize/-/canonicalize-2.0.0.tgz", + "integrity": "sha512-ulDEYPv7asdKvqahuAY35c1selLdzDwHqugK92hfkzvlDCwXRRelDkR+Er33md/PtnpqHemgkuDPanZ4fiYZ8w==" + }, + "node_modules/chai": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/chai/-/chai-4.4.1.tgz", + "integrity": "sha512-13sOfMv2+DWduEU+/xbun3LScLoqN17nBeTLUsmDfKdoiC1fr0n9PU4guu4AhRcOVFk/sW8LyZWHuhWtQZiF+g==", + "dev": true, + "dependencies": { + "assertion-error": "^1.1.0", + "check-error": "^1.0.3", + "deep-eql": "^4.1.3", + "get-func-name": "^2.0.2", + "loupe": "^2.3.6", + "pathval": "^1.1.1", + "type-detect": "^4.0.8" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/chalk/node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/check-error": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.3.tgz", + "integrity": "sha512-iKEoDYaRmd1mxM90a2OEfWhjsjPpYPuQ+lMYsoxB126+t8fw7ySEO48nmDg5COTjxDI65/Y2OWpeEHk3ZOe8zg==", + "dev": true, + "dependencies": { + "get-func-name": "^2.0.2" + }, + "engines": { + "node": "*" + } + }, + "node_modules/check-types": { + "version": "11.2.3", + "resolved": "https://registry.npmjs.org/check-types/-/check-types-11.2.3.tgz", + "integrity": "sha512-+67P1GkJRaxQD6PKK0Et9DhwQB+vGg3PM5+aavopCpZT1lj9jeqfvpgTLAWErNj8qApkkmXlu/Ug74kmhagkXg==", + "dev": true + }, + "node_modules/chokidar": { + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", + "integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==", + "dev": true, + "funding": [ + { + "type": "individual", + "url": "https://paulmillr.com/funding/" + } + ], + "dependencies": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + }, + "engines": { + "node": ">= 8.10.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + } + }, + "node_modules/chownr": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz", + "integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==", + "engines": { + "node": ">=10" + } + }, + "node_modules/circom_runtime": { + "version": "0.1.24", + "resolved": "https://registry.npmjs.org/circom_runtime/-/circom_runtime-0.1.24.tgz", + "integrity": "sha512-H7/7I2J/cBmRnZm9docOCGhfxzS61BEm4TMCWcrZGsWNBQhePNfQq88Oj2XpUfzmBTCd8pRvRb3Mvazt3TMrJw==", + "dev": true, + "dependencies": { + "ffjavascript": "0.2.60" + }, + "bin": { + "calcwit": "calcwit.js" + } + }, + "node_modules/circom_runtime/node_modules/ffjavascript": { + "version": "0.2.60", + "resolved": "https://registry.npmjs.org/ffjavascript/-/ffjavascript-0.2.60.tgz", + "integrity": "sha512-T/9bnEL5xAZRDbQoEMf+pM9nrhK+C3JyZNmqiWub26EQorW7Jt+jR54gpqDhceA4Nj0YctPQwYnl8xa52/A26A==", + "dev": true, + "dependencies": { + "wasmbuilder": "0.0.16", + "wasmcurves": "0.2.2", + "web-worker": "^1.2.0" + } + }, + "node_modules/cliui": { + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", + "integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==", + "dev": true, + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0", + "wrap-ansi": "^7.0.0" + } + }, + "node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "node_modules/color-support": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-support/-/color-support-1.1.3.tgz", + "integrity": "sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg==", + "bin": { + "color-support": "bin.js" + } + }, + "node_modules/commander": { + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-11.1.0.tgz", + "integrity": "sha512-yPVavfyCcRhmorC7rWlkHn15b4wDVgVmBA7kV4QVBsF7kv/9TKJAbAXVTxvTnwP8HHKjRCJDClKbciiYS7p0DQ==", + "dev": true, + "engines": { + "node": ">=16" + } + }, + "node_modules/concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" + }, + "node_modules/console-control-strings": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", + "integrity": "sha512-ty/fTekppD2fIwRvnZAVdeOiGd1c7YXEixbgJTNzqcxJWKQnjJ/V1bNEEE6hygpM3WjwHFUVK6HTjWSzV4a8sQ==" + }, + "node_modules/core-js-pure": { + "version": "3.36.0", + "resolved": "https://registry.npmjs.org/core-js-pure/-/core-js-pure-3.36.0.tgz", + "integrity": "sha512-cN28qmhRNgbMZZMc/RFu5w8pK9VJzpb2rJVR/lHuZJKwmXnoWOpXmMkxqBB514igkp1Hu8WGROsiOAzUcKdHOQ==", + "hasInstallScript": true, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/core-js" + } + }, + "node_modules/d": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/d/-/d-1.0.1.tgz", + "integrity": "sha512-m62ShEObQ39CfralilEQRjH6oAMtNCV1xJyEx5LpRYUVN+EviphDgUc/F3hnYbADmkiNs67Y+3ylmlG7Lnu+FA==", + "dependencies": { + "es5-ext": "^0.10.50", + "type": "^1.0.1" + } + }, + "node_modules/debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/decamelize": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-4.0.0.tgz", + "integrity": "sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/deep-eql": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-4.1.3.tgz", + "integrity": "sha512-WaEtAOpRA1MQ0eohqZjpGD8zdI0Ovsm8mmFhaDN8dvDZzyoUMcYDnf5Y6iu7HTXxf8JDS23qWa4a+hKCDyOPzw==", + "dev": true, + "dependencies": { + "type-detect": "^4.0.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/deep-is": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", + "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", + "dev": true + }, + "node_modules/delegates": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", + "integrity": "sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==" + }, + "node_modules/detect-libc": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.2.tgz", + "integrity": "sha512-UX6sGumvvqSaXgdKGUsgZWqcUyIXZ/vZTrlRT/iobiKhGL0zL4d3osHj3uqllWJK+i+sixDS/3COVEOFbupFyw==", + "engines": { + "node": ">=8" + } + }, + "node_modules/diff": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-5.0.0.tgz", + "integrity": "sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==", + "dev": true, + "engines": { + "node": ">=0.3.1" + } + }, + "node_modules/ejs": { + "version": "3.1.9", + "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.9.tgz", + "integrity": "sha512-rC+QVNMJWv+MtPgkt0y+0rVEIdbtxVADApW9JXrUVlzHetgcyczP/E7DJmWJ4fJCZF2cPcBk0laWO9ZHMG3DmQ==", + "dev": true, + "dependencies": { + "jake": "^10.8.5" + }, + "bin": { + "ejs": "bin/cli.js" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" + }, + "node_modules/es5-ext": { + "version": "0.10.62", + "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.62.tgz", + "integrity": "sha512-BHLqn0klhEpnOKSrzn/Xsz2UIW8j+cGmo9JLzr8BiUapV8hPL9+FliFqjwr9ngW7jWdnxv6eO+/LqyhJVqgrjA==", + "hasInstallScript": true, + "dependencies": { + "es6-iterator": "^2.0.3", + "es6-symbol": "^3.1.3", + "next-tick": "^1.1.0" + }, + "engines": { + "node": ">=0.10" + } + }, + "node_modules/es6-iterator": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.3.tgz", + "integrity": "sha512-zw4SRzoUkd+cl+ZoE15A9o1oQd920Bb0iOJMQkQhl3jNc03YqVjAhG7scf9C5KWRU/R13Orf588uCC6525o02g==", + "dependencies": { + "d": "1", + "es5-ext": "^0.10.35", + "es6-symbol": "^3.1.1" + } + }, + "node_modules/es6-symbol": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.3.tgz", + "integrity": "sha512-NJ6Yn3FuDinBaBRWl/q5X/s4koRHBrgKAu+yGI6JCBeiu3qrcbJhwT2GeR/EXVfylRk8dpQVJoLEFhK+Mu31NA==", + "dependencies": { + "d": "^1.0.1", + "ext": "^1.1.2" + } + }, + "node_modules/escalade": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.2.tgz", + "integrity": "sha512-ErCHMCae19vR8vQGe50xIsVomy19rg6gFu3+r3jkEO46suLMWBksvVyoGgQV+jOfl84ZSOSlmv6Gxa89PmTGmA==", + "dev": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/escodegen": { + "version": "1.14.3", + "resolved": "https://registry.npmjs.org/escodegen/-/escodegen-1.14.3.tgz", + "integrity": "sha512-qFcX0XJkdg+PB3xjZZG/wKSuT1PnQWx57+TVSjIMmILd2yC/6ByYElPwJnslDsuWuSAp4AwJGumarAAmJch5Kw==", + "dev": true, + "dependencies": { + "esprima": "^4.0.1", + "estraverse": "^4.2.0", + "esutils": "^2.0.2", + "optionator": "^0.8.1" + }, + "bin": { + "escodegen": "bin/escodegen.js", + "esgenerate": "bin/esgenerate.js" + }, + "engines": { + "node": ">=4.0" + }, + "optionalDependencies": { + "source-map": "~0.6.1" + } + }, + "node_modules/escodegen/node_modules/esprima": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", + "dev": true, + "bin": { + "esparse": "bin/esparse.js", + "esvalidate": "bin/esvalidate.js" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/esprima": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-1.2.2.tgz", + "integrity": "sha512-+JpPZam9w5DuJ3Q67SqsMGtiHKENSMRVoxvArfJZK01/BfLEObtZ6orJa/MtoGNR/rfMgp5837T41PAmTwAv/A==", + "dev": true, + "bin": { + "esparse": "bin/esparse.js", + "esvalidate": "bin/esvalidate.js" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/estraverse": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", + "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", + "dev": true, + "engines": { + "node": ">=4.0" + } + }, + "node_modules/esutils": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", + "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/events": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz", + "integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==", + "engines": { + "node": ">=0.8.x" + } + }, + "node_modules/ext": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/ext/-/ext-1.7.0.tgz", + "integrity": "sha512-6hxeJYaL110a9b5TEJSj0gojyHQAmA2ch5Os+ySCiA1QGdS697XWY1pzsrSjqA9LDEEgdB/KypIlR59RcLuHYw==", + "dependencies": { + "type": "^2.7.2" + } + }, + "node_modules/ext/node_modules/type": { + "version": "2.7.2", + "resolved": "https://registry.npmjs.org/type/-/type-2.7.2.tgz", + "integrity": "sha512-dzlvlNlt6AXU7EBSfpAscydQ7gXB+pPGsPnfJnZpiNJBDj7IaJzQlBZYGdEi4R9HmPdBv2XmWJ6YUtoTa7lmCw==" + }, + "node_modules/fast-levenshtein": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", + "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", + "dev": true + }, + "node_modules/fastfile": { + "version": "0.0.20", + "resolved": "https://registry.npmjs.org/fastfile/-/fastfile-0.0.20.tgz", + "integrity": "sha512-r5ZDbgImvVWCP0lA/cGNgQcZqR+aYdFx3u+CtJqUE510pBUVGMn4ulL/iRTI4tACTYsNJ736uzFxEBXesPAktA==", + "dev": true + }, + "node_modules/ffjavascript": { + "version": "0.2.59", + "resolved": "https://registry.npmjs.org/ffjavascript/-/ffjavascript-0.2.59.tgz", + "integrity": "sha512-QssOEUv+wilz9Sg7Zaj6KWAm7QceOAEsFuEBTltUsDo1cjn11rA/LGYvzFBPbzNfxRlZxwgJ7uxpCQcdDlrNfw==", + "dev": true, + "dependencies": { + "wasmbuilder": "0.0.16", + "wasmcurves": "0.2.1", + "web-worker": "^1.2.0" + } + }, + "node_modules/ffjavascript/node_modules/wasmcurves": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/wasmcurves/-/wasmcurves-0.2.1.tgz", + "integrity": "sha512-9ciO7bUE5bgpbOcdK7IO3enrSVIKHwrQmPibok4GLJWaCA7Wyqc9PRYnu5HbiFv9NDFNqVKPtU5R6Is5KujBLg==", + "dev": true, + "dependencies": { + "wasmbuilder": "0.0.16" + } + }, + "node_modules/filelist": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.4.tgz", + "integrity": "sha512-w1cEuf3S+DrLCQL7ET6kz+gmlJdbq9J7yXCSjK/OZCPA+qEN1WyF4ZAf0YYJa4/shHJra2t/d/r8SV4Ji+x+8Q==", + "dev": true, + "dependencies": { + "minimatch": "^5.0.1" + } + }, + "node_modules/fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "dev": true, + "dependencies": { + "to-regex-range": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/find-up": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", + "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", + "dev": true, + "dependencies": { + "locate-path": "^6.0.0", + "path-exists": "^4.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/flat": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/flat/-/flat-5.0.2.tgz", + "integrity": "sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==", + "dev": true, + "bin": { + "flat": "cli.js" + } + }, + "node_modules/fs-minipass": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz", + "integrity": "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==", + "dependencies": { + "minipass": "^3.0.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/fs-minipass/node_modules/minipass": { + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz", + "integrity": "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/gauge": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/gauge/-/gauge-3.0.2.tgz", + "integrity": "sha512-+5J6MS/5XksCuXq++uFRsnUd7Ovu1XenbeuIuNRJxYWjgQbPuFhT14lAvsWfqfAmnwluf1OwMjz39HjfLPci0Q==", + "dependencies": { + "aproba": "^1.0.3 || ^2.0.0", + "color-support": "^1.1.2", + "console-control-strings": "^1.0.0", + "has-unicode": "^2.0.1", + "object-assign": "^4.1.1", + "signal-exit": "^3.0.0", + "string-width": "^4.2.3", + "strip-ansi": "^6.0.1", + "wide-align": "^1.1.2" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/get-caller-file": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", + "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", + "dev": true, + "engines": { + "node": "6.* || 8.* || >= 10.*" + } + }, + "node_modules/get-func-name": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.2.tgz", + "integrity": "sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ==", + "dev": true, + "engines": { + "node": "*" + } + }, + "node_modules/glob": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", + "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", + "dev": true, + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^5.0.1", + "once": "^1.3.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/has-unicode": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", + "integrity": "sha512-8Rf9Y83NBReMnx0gFzA8JImQACstCYWUplepDa9xprwwtmgEZUF0h/i5xSA625zB/I37EtrswSST6OXxwaaIJQ==" + }, + "node_modules/he": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", + "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", + "dev": true, + "bin": { + "he": "bin/he" + } + }, + "node_modules/hoopy": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/hoopy/-/hoopy-0.1.4.tgz", + "integrity": "sha512-HRcs+2mr52W0K+x8RzcLzuPPmVIKMSv97RGHy0Ea9y/mpcaK+xTrjICA04KAHi4GRzxliNqNJEFYWHghy3rSfQ==", + "dev": true, + "engines": { + "node": ">= 6.0.0" + } + }, + "node_modules/http-proxy-agent": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-5.0.0.tgz", + "integrity": "sha512-n2hY8YdoRE1i7r6M0w9DIw5GgZN0G25P8zLCRQ8rjXtTU3vsNFBI/vWK/UIeE6g5MUUz6avwAPXmL6Fy9D/90w==", + "dependencies": { + "@tootallnate/once": "2", + "agent-base": "6", + "debug": "4" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/https-proxy-agent": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", + "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", + "dependencies": { + "agent-base": "6", + "debug": "4" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/ieee754": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, + "node_modules/inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", + "dependencies": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "node_modules/is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dev": true, + "dependencies": { + "binary-extensions": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "engines": { + "node": ">=8" + } + }, + "node_modules/is-glob": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", + "dev": true, + "dependencies": { + "is-extglob": "^2.1.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true, + "engines": { + "node": ">=0.12.0" + } + }, + "node_modules/is-plain-obj": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz", + "integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/is-typedarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", + "integrity": "sha512-cyA56iCMHAh5CdzjJIa4aohJyeO1YbwLi3Jc35MmRU6poroFjIGZzUzupGiRPOjgHg9TLu43xbpwXk523fMxKA==" + }, + "node_modules/is-unicode-supported": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz", + "integrity": "sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/isomorphic-ws": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/isomorphic-ws/-/isomorphic-ws-5.0.0.tgz", + "integrity": "sha512-muId7Zzn9ywDsyXgTIafTry2sV3nySZeUDe6YedVd1Hvuuep5AsIlqK+XefWpYTyJG5e503F2xIuT2lcU6rCSw==", + "peerDependencies": { + "ws": "*" + } + }, + "node_modules/jake": { + "version": "10.8.7", + "resolved": "https://registry.npmjs.org/jake/-/jake-10.8.7.tgz", + "integrity": "sha512-ZDi3aP+fG/LchyBzUM804VjddnwfSfsdeYkwt8NcbKRvo4rFkjhs456iLFn3k2ZUWvNe4i48WACDbza8fhq2+w==", + "dev": true, + "dependencies": { + "async": "^3.2.3", + "chalk": "^4.0.2", + "filelist": "^1.0.4", + "minimatch": "^3.1.2" + }, + "bin": { + "jake": "bin/cli.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/jake/node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/jake/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/js-sha3": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.8.0.tgz", + "integrity": "sha512-gF1cRrHhIzNfToc802P800N8PpXS+evLLXfsVpowqmAFR9uwbi89WvXg2QspOmXL8QL86J4T1EpFu+yUkwJY3Q==", + "dev": true + }, + "node_modules/js-yaml": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", + "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", + "dev": true, + "dependencies": { + "argparse": "^2.0.1" + }, + "bin": { + "js-yaml": "bin/js-yaml.js" + } + }, + "node_modules/json-bigint": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-bigint/-/json-bigint-1.0.0.tgz", + "integrity": "sha512-SiPv/8VpZuWbvLSMtTDU8hEfrZWg/mH/nV/b4o0CYbSxu1UIQPLdwKOCIyLQX+VIPO5vrLX3i8qtqFyhdPSUSQ==", + "dependencies": { + "bignumber.js": "^9.0.0" + } + }, + "node_modules/jsonpath": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/jsonpath/-/jsonpath-1.1.1.tgz", + "integrity": "sha512-l6Cg7jRpixfbgoWgkrl77dgEj8RPvND0wMH6TwQmi9Qs4TFfS9u5cUFnbeKTwj5ga5Y3BTGGNI28k117LJ009w==", + "dev": true, + "dependencies": { + "esprima": "1.2.2", + "static-eval": "2.0.2", + "underscore": "1.12.1" + } + }, + "node_modules/kleur": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz", + "integrity": "sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==", + "dev": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/levn": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz", + "integrity": "sha512-0OO4y2iOHix2W6ujICbKIaEQXvFQHue65vUG3pb5EUomzPI90z9hsA1VsO/dbIIpC53J8gxM9Q4Oho0jrCM/yA==", + "dev": true, + "dependencies": { + "prelude-ls": "~1.1.2", + "type-check": "~0.3.2" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/locate-path": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", + "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", + "dev": true, + "dependencies": { + "p-locate": "^5.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/log-symbols": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", + "integrity": "sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==", + "dev": true, + "dependencies": { + "chalk": "^4.1.0", + "is-unicode-supported": "^0.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/logplease": { + "version": "1.2.15", + "resolved": "https://registry.npmjs.org/logplease/-/logplease-1.2.15.tgz", + "integrity": "sha512-jLlHnlsPSJjpwUfcNyUxXCl33AYg2cHhIf9QhGL2T4iPT0XPB+xP1LRKFPgIg1M/sg9kAJvy94w9CzBNrfnstA==", + "dev": true + }, + "node_modules/loupe": { + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.7.tgz", + "integrity": "sha512-zSMINGVYkdpYSOBmLi0D1Uo7JU9nVdQKrHxC8eYlV+9YKK9WePqAlL7lSlorG/U2Fw1w0hTBmaa/jrQ3UbPHtA==", + "dev": true, + "dependencies": { + "get-func-name": "^2.0.1" + } + }, + "node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/make-dir": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", + "integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==", + "dependencies": { + "semver": "^6.0.0" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/make-dir/node_modules/semver": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", + "bin": { + "semver": "bin/semver.js" + } + }, + "node_modules/minimatch": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.0.1.tgz", + "integrity": "sha512-nLDxIFRyhDblz3qMuq+SoRZED4+miJ/G+tdDrjkkkRnjAsBexeGpgjLEQ0blJy7rHhR2b93rhQY4SvyWu9v03g==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/minipass": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-5.0.0.tgz", + "integrity": "sha512-3FnjYuehv9k6ovOEbyOswadCDPX1piCfhV8ncmYtHOjuPwylVWsghTLo7rabjC3Rx5xD4HDx8Wm1xnMF7S5qFQ==", + "engines": { + "node": ">=8" + } + }, + "node_modules/minizlib": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-2.1.2.tgz", + "integrity": "sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==", + "dependencies": { + "minipass": "^3.0.0", + "yallist": "^4.0.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/minizlib/node_modules/minipass": { + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz", + "integrity": "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/mkdirp": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", + "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", + "bin": { + "mkdirp": "bin/cmd.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/mocha": { + "version": "10.3.0", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-10.3.0.tgz", + "integrity": "sha512-uF2XJs+7xSLsrmIvn37i/wnc91nw7XjOQB8ccyx5aEgdnohr7n+rEiZP23WkCYHjilR6+EboEnbq/ZQDz4LSbg==", + "dev": true, + "dependencies": { + "ansi-colors": "4.1.1", + "browser-stdout": "1.3.1", + "chokidar": "3.5.3", + "debug": "4.3.4", + "diff": "5.0.0", + "escape-string-regexp": "4.0.0", + "find-up": "5.0.0", + "glob": "8.1.0", + "he": "1.2.0", + "js-yaml": "4.1.0", + "log-symbols": "4.1.0", + "minimatch": "5.0.1", + "ms": "2.1.3", + "serialize-javascript": "6.0.0", + "strip-json-comments": "3.1.1", + "supports-color": "8.1.1", + "workerpool": "6.2.1", + "yargs": "16.2.0", + "yargs-parser": "20.2.4", + "yargs-unparser": "2.0.0" + }, + "bin": { + "_mocha": "bin/_mocha", + "mocha": "bin/mocha.js" + }, + "engines": { + "node": ">= 14.0.0" + } + }, + "node_modules/mocha/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "dev": true + }, + "node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + }, + "node_modules/nanoassert": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/nanoassert/-/nanoassert-2.0.0.tgz", + "integrity": "sha512-7vO7n28+aYO4J+8w96AzhmU8G+Y/xpPDJz/se19ICsqj/momRbb9mh9ZUtkoJ5X3nTnPdhEJyc0qnM6yAsHBaA==", + "dev": true + }, + "node_modules/next-tick": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.1.0.tgz", + "integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==" + }, + "node_modules/node-fetch": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, + "node_modules/node-gyp-build": { + "version": "4.8.0", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.0.tgz", + "integrity": "sha512-u6fs2AEUljNho3EYTJNBfImO5QTo/J/1Etd+NVdCj7qWKUSN/bSLkZwhDv7I+w/MSC6qJ4cknepkAYykDdK8og==", + "bin": { + "node-gyp-build": "bin.js", + "node-gyp-build-optional": "optional.js", + "node-gyp-build-test": "build-test.js" + } + }, + "node_modules/nopt": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz", + "integrity": "sha512-Tbj67rffqceeLpcRXrT7vKAN8CwfPeIBgM7E6iBkmKLV7bEMwpGgYLGv0jACUsECaa/vuxP0IjEont6umdMgtQ==", + "dependencies": { + "abbrev": "1" + }, + "bin": { + "nopt": "bin/nopt.js" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/normalize-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/npmlog": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-5.0.1.tgz", + "integrity": "sha512-AqZtDUWOMKs1G/8lwylVjrdYgqA4d9nu8hc+0gzRxlDb1I10+FHBGMXs6aiQHFdCUUlqH99MUMuLfzWDNDtfxw==", + "dependencies": { + "are-we-there-yet": "^2.0.0", + "console-control-strings": "^1.1.0", + "gauge": "^3.0.0", + "set-blocking": "^2.0.0" + } + }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/optionator": { + "version": "0.8.3", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.3.tgz", + "integrity": "sha512-+IW9pACdk3XWmmTXG8m3upGUJst5XRGzxMRjXzAuJ1XnIFNvfhjjIuYkDvysnPQ7qzqVzLt78BCruntqRhWQbA==", + "dev": true, + "dependencies": { + "deep-is": "~0.1.3", + "fast-levenshtein": "~2.0.6", + "levn": "~0.3.0", + "prelude-ls": "~1.1.2", + "type-check": "~0.3.2", + "word-wrap": "~1.2.3" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/p-limit": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", + "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", + "dev": true, + "dependencies": { + "yocto-queue": "^0.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/p-locate": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", + "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", + "dev": true, + "dependencies": { + "p-limit": "^3.0.2" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/path-exists": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/pathval": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.1.tgz", + "integrity": "sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==", + "dev": true, + "engines": { + "node": "*" + } + }, + "node_modules/picomatch": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "dev": true, + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/prelude-ls": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", + "integrity": "sha512-ESF23V4SKG6lVSGZgYNpbsiaAkdab6ZgOxe52p7+Kid3W3u3bxR4Vfd/o21dmN7jSt0IwgZ4v5MUd26FEtXE9w==", + "dev": true, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/process": { + "version": "0.11.10", + "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", + "integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==", + "engines": { + "node": ">= 0.6.0" + } + }, + "node_modules/promisify-child-process": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/promisify-child-process/-/promisify-child-process-4.1.2.tgz", + "integrity": "sha512-APnkIgmaHNJpkAn7k+CrJSi9WMuff5ctYFbD0CO2XIPkM8yO7d/ShouU2clywbpHV/DUsyc4bpJCsNgddNtx4g==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/prompts": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.2.tgz", + "integrity": "sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==", + "dev": true, + "dependencies": { + "kleur": "^3.0.3", + "sisteransi": "^1.0.5" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/r1csfile": { + "version": "0.0.47", + "resolved": "https://registry.npmjs.org/r1csfile/-/r1csfile-0.0.47.tgz", + "integrity": "sha512-oI4mAwuh1WwuFg95eJDNDDL8hCaZkwnPuNZrQdLBWvDoRU7EG+L/MOHL7SwPW2Y+ZuYcTLpj3rBkgllBQZN/JA==", + "dev": true, + "dependencies": { + "@iden3/bigarray": "0.0.2", + "@iden3/binfileutils": "0.0.11", + "fastfile": "0.0.20", + "ffjavascript": "0.2.60" + } + }, + "node_modules/r1csfile/node_modules/ffjavascript": { + "version": "0.2.60", + "resolved": "https://registry.npmjs.org/ffjavascript/-/ffjavascript-0.2.60.tgz", + "integrity": "sha512-T/9bnEL5xAZRDbQoEMf+pM9nrhK+C3JyZNmqiWub26EQorW7Jt+jR54gpqDhceA4Nj0YctPQwYnl8xa52/A26A==", + "dev": true, + "dependencies": { + "wasmbuilder": "0.0.16", + "wasmcurves": "0.2.2", + "web-worker": "^1.2.0" + } + }, + "node_modules/randombytes": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", + "integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==", + "dev": true, + "dependencies": { + "safe-buffer": "^5.1.0" + } + }, + "node_modules/readable-stream": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/readdirp": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", + "dev": true, + "dependencies": { + "picomatch": "^2.2.1" + }, + "engines": { + "node": ">=8.10.0" + } + }, + "node_modules/regenerator-runtime": { + "version": "0.14.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz", + "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==" + }, + "node_modules/require-directory": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", + "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dependencies": { + "glob": "^7.1.3" + }, + "bin": { + "rimraf": "bin.js" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/rimraf/node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/rimraf/node_modules/glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/rimraf/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/rlp": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/rlp/-/rlp-3.0.0.tgz", + "integrity": "sha512-PD6U2PGk6Vq2spfgiWZdomLvRGDreBLxi5jv5M8EpRo3pU6VEm31KO+HFxE18Q3vgqfDrQ9pZA3FP95rkijNKw==", + "bin": { + "rlp": "bin/rlp" + } + }, + "node_modules/rxjs": { + "version": "7.8.1", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.1.tgz", + "integrity": "sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg==", + "dependencies": { + "tslib": "^2.1.0" + } + }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, + "node_modules/semver": { + "version": "7.6.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", + "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==", + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/serialize-javascript": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.0.tgz", + "integrity": "sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag==", + "dev": true, + "dependencies": { + "randombytes": "^2.1.0" + } + }, + "node_modules/set-blocking": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", + "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==" + }, + "node_modules/sha.js": { + "version": "2.4.11", + "resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz", + "integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==", + "dependencies": { + "inherits": "^2.0.1", + "safe-buffer": "^5.0.1" + }, + "bin": { + "sha.js": "bin.js" + } + }, + "node_modules/signal-exit": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", + "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==" + }, + "node_modules/sisteransi": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz", + "integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==", + "dev": true + }, + "node_modules/snarkjs": { + "version": "0.7.3", + "resolved": "file:..", + "dev": true, + "license": "GPL-3.0", + "dependencies": { + "@iden3/binfileutils": "0.0.11", + "bfj": "^7.0.2", + "blake2b-wasm": "^2.4.0", + "circom_runtime": "0.1.24", + "ejs": "^3.1.6", + "fastfile": "0.0.20", + "ffjavascript": "0.2.63", + "js-sha3": "^0.8.0", + "logplease": "^1.2.15", + "r1csfile": "0.0.47" + }, + "bin": { + "snarkjs": "build/cli.cjs" + } + }, + "node_modules/snarkjs/node_modules/ffjavascript": { + "version": "0.2.63", + "resolved": "https://registry.npmjs.org/ffjavascript/-/ffjavascript-0.2.63.tgz", + "integrity": "sha512-dBgdsfGks58b66JnUZeZpGxdMIDQ4QsD3VYlRJyFVrKQHb2kJy4R2gufx5oetrTxXPT+aEjg0dOvOLg1N0on4A==", + "dev": true, + "dependencies": { + "wasmbuilder": "0.0.16", + "wasmcurves": "0.2.2", + "web-worker": "1.2.0" + } + }, + "node_modules/source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true, + "optional": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/static-eval": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/static-eval/-/static-eval-2.0.2.tgz", + "integrity": "sha512-N/D219Hcr2bPjLxPiV+TQE++Tsmrady7TqAJugLy7Xk1EumfDWS/f5dtBbkRCGE7wKKXuYockQoj8Rm2/pVKyg==", + "dev": true, + "dependencies": { + "escodegen": "^1.8.1" + } + }, + "node_modules/string_decoder": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", + "dependencies": { + "safe-buffer": "~5.2.0" + } + }, + "node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-json-comments": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", + "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", + "dev": true, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/supports-color": { + "version": "8.1.1", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", + "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", + "dev": true, + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/supports-color?sponsor=1" + } + }, + "node_modules/tar": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/tar/-/tar-6.2.0.tgz", + "integrity": "sha512-/Wo7DcT0u5HUV486xg675HtjNd3BXZ6xDbzsCUZPt5iw8bTQ63bP0Raut3mvro9u+CUyq7YQd8Cx55fsZXxqLQ==", + "dependencies": { + "chownr": "^2.0.0", + "fs-minipass": "^2.0.0", + "minipass": "^5.0.0", + "minizlib": "^2.1.1", + "mkdirp": "^1.0.3", + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "dependencies": { + "is-number": "^7.0.0" + }, + "engines": { + "node": ">=8.0" + } + }, + "node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" + }, + "node_modules/tryer": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/tryer/-/tryer-1.0.1.tgz", + "integrity": "sha512-c3zayb8/kWWpycWYg87P71E1S1ZL6b6IJxfb5fvsUgsf0S2MVGaDhDXXjDMpdCpfWXqptc+4mXwmiy1ypXqRAA==", + "dev": true + }, + "node_modules/tslib": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==" + }, + "node_modules/tweetnacl": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", + "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==" + }, + "node_modules/tweetnacl-auth": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/tweetnacl-auth/-/tweetnacl-auth-1.0.1.tgz", + "integrity": "sha512-Qu2JonS5VUh5oJBnGsFohfel8O4gqN2QwdrsLjaZEZOU/25iIr3zU7jFOFbtOM5Wak5jiIViAqMvRvuxk9Lhmg==", + "dependencies": { + "tweetnacl": "1.x.x" + } + }, + "node_modules/type": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/type/-/type-1.2.0.tgz", + "integrity": "sha512-+5nt5AAniqsCnu2cEQQdpzCAh33kVx8n0VoFidKpB1dVVLAN/F+bgVOqOJqOnEnrhp222clB5p3vUlD+1QAnfg==" + }, + "node_modules/type-check": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", + "integrity": "sha512-ZCmOJdvOWDBYJlzAoFkC+Q0+bUyEOS1ltgp1MGU03fqHG+dbi9tBFU2Rd9QKiDZFAYrhPh2JUf7rZRIuHRKtOg==", + "dev": true, + "dependencies": { + "prelude-ls": "~1.1.2" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/type-detect": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", + "dev": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/typedarray-to-buffer": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz", + "integrity": "sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==", + "dependencies": { + "is-typedarray": "^1.0.0" + } + }, + "node_modules/underscore": { + "version": "1.12.1", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.12.1.tgz", + "integrity": "sha512-hEQt0+ZLDVUMhebKxL4x1BTtDY7bavVofhZ9KZ4aI26X9SRaE+Y3m83XUL1UP2jn8ynjndwCCpEHdUG+9pP1Tw==", + "dev": true + }, + "node_modules/utf-8-validate": { + "version": "5.0.10", + "resolved": "https://registry.npmjs.org/utf-8-validate/-/utf-8-validate-5.0.10.tgz", + "integrity": "sha512-Z6czzLq4u8fPOyx7TU6X3dvUZVvoJmxSQ+IcrlmagKhilxlhZgxPK6C5Jqbkw1IDUmFTM+cz9QDnnLTwDz/2gQ==", + "hasInstallScript": true, + "dependencies": { + "node-gyp-build": "^4.3.0" + }, + "engines": { + "node": ">=6.14.2" + } + }, + "node_modules/util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" + }, + "node_modules/varuint-bitcoin": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/varuint-bitcoin/-/varuint-bitcoin-1.1.2.tgz", + "integrity": "sha512-4EVb+w4rx+YfVM32HQX42AbbT7/1f5zwAYhIujKXKk8NQK+JfRVl3pqT3hjNn/L+RstigmGGKVwHA/P0wgITZw==", + "dependencies": { + "safe-buffer": "^5.1.1" + } + }, + "node_modules/wasmbuilder": { + "version": "0.0.16", + "resolved": "https://registry.npmjs.org/wasmbuilder/-/wasmbuilder-0.0.16.tgz", + "integrity": "sha512-Qx3lEFqaVvp1cEYW7Bfi+ebRJrOiwz2Ieu7ZG2l7YyeSJIok/reEQCQCuicj/Y32ITIJuGIM9xZQppGx5LrQdA==", + "dev": true + }, + "node_modules/wasmcurves": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/wasmcurves/-/wasmcurves-0.2.2.tgz", + "integrity": "sha512-JRY908NkmKjFl4ytnTu5ED6AwPD+8VJ9oc94kdq7h5bIwbj0L4TDJ69mG+2aLs2SoCmGfqIesMWTEJjtYsoQXQ==", + "dev": true, + "dependencies": { + "wasmbuilder": "0.0.16" + } + }, + "node_modules/web-worker": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/web-worker/-/web-worker-1.2.0.tgz", + "integrity": "sha512-PgF341avzqyx60neE9DD+XS26MMNMoUQRz9NOZwW32nPQrF6p77f1htcnjBSEV8BGMKZ16choqUG4hyI0Hx7mA==", + "dev": true + }, + "node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" + }, + "node_modules/websocket": { + "version": "1.0.34", + "resolved": "https://registry.npmjs.org/websocket/-/websocket-1.0.34.tgz", + "integrity": "sha512-PRDso2sGwF6kM75QykIesBijKSVceR6jL2G8NGYyq2XrItNC2P5/qL5XeR056GhA+Ly7JMFvJb9I312mJfmqnQ==", + "dependencies": { + "bufferutil": "^4.0.1", + "debug": "^2.2.0", + "es5-ext": "^0.10.50", + "typedarray-to-buffer": "^3.1.5", + "utf-8-validate": "^5.0.2", + "yaeti": "^0.0.6" + }, + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/websocket/node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/websocket/node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" + }, + "node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, + "node_modules/wide-align": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.5.tgz", + "integrity": "sha512-eDMORYaPNZ4sQIuuYPDHdQvf4gyCF9rEEV/yPxGfwPkRodwEgiMUUXTx/dex+Me0wxx53S+NgUHaP7y3MGlDmg==", + "dependencies": { + "string-width": "^1.0.2 || 2 || 3 || 4" + } + }, + "node_modules/word-wrap": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", + "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/workerpool": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.2.1.tgz", + "integrity": "sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw==", + "dev": true + }, + "node_modules/wrap-ansi": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" + }, + "node_modules/ws": { + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.16.0.tgz", + "integrity": "sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ==", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, + "node_modules/y18n": { + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", + "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", + "dev": true, + "engines": { + "node": ">=10" + } + }, + "node_modules/yaeti": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/yaeti/-/yaeti-0.0.6.tgz", + "integrity": "sha512-MvQa//+KcZCUkBTIC9blM+CU9J2GzuTytsOUwf2lidtvkx/6gnEp1QvJv34t9vdjhFmha/mUiNDbN0D0mJWdug==", + "engines": { + "node": ">=0.10.32" + } + }, + "node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + }, + "node_modules/yargs": { + "version": "16.2.0", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz", + "integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==", + "dev": true, + "dependencies": { + "cliui": "^7.0.2", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", + "require-directory": "^2.1.1", + "string-width": "^4.2.0", + "y18n": "^5.0.5", + "yargs-parser": "^20.2.2" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/yargs-parser": { + "version": "20.2.4", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.4.tgz", + "integrity": "sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA==", + "dev": true, + "engines": { + "node": ">=10" + } + }, + "node_modules/yargs-unparser": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/yargs-unparser/-/yargs-unparser-2.0.0.tgz", + "integrity": "sha512-7pRTIA9Qc1caZ0bZ6RYRGbHJthJWuakf+WmHK0rVeLkNrrGhfoabBNdue6kdINI6r4if7ocq9aD/n7xwKOdzOA==", + "dev": true, + "dependencies": { + "camelcase": "^6.0.0", + "decamelize": "^4.0.0", + "flat": "^5.0.2", + "is-plain-obj": "^2.1.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/yocto-queue": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", + "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + } + } +} diff --git a/sophia_smart_contract_tests/package.json b/sophia_smart_contract_tests/package.json new file mode 100644 index 00000000..43e92bab --- /dev/null +++ b/sophia_smart_contract_tests/package.json @@ -0,0 +1,22 @@ +{ + "name": "aeproject-project", + "version": "1.0.0", + "description": "This is the default package.json generated for your project", + "type": "module", + "scripts": { + "all": "npm run setup; npm test; npm run teardown", + "setup": "docker compose up -d", + "teardown": "docker compose down -v", + "test": "mocha ./test/**/*.js --exit" + }, + "dependencies": { + "@aeternity/aepp-sdk": "^13.2.1" + }, + "devDependencies": { + "@aeternity/aeproject": "^4.8.2", + "chai": "^4.3.8", + "ffjavascript": "0.2.59", + "mocha": "^10.2.0", + "snarkjs": "file:.." + } +} diff --git a/sophia_smart_contract_tests/test/sophia_contract_tests.js b/sophia_smart_contract_tests/test/sophia_contract_tests.js new file mode 100644 index 00000000..d00e02ee --- /dev/null +++ b/sophia_smart_contract_tests/test/sophia_contract_tests.js @@ -0,0 +1,85 @@ +import { createRequire } from "module"; +const require = createRequire(import.meta.url); +const { utils } = require('@aeternity/aeproject'); + +import path from "path"; +import fs from "fs"; +import { assert } from "chai"; +import { buildBls12381 } from "ffjavascript"; +import * as snarkjs from "snarkjs"; + +describe('SophiaContracts', function () { + this.timeout(20000); + + let aeSdk; + let contract; + + const ptauFilename = path.join("./input", "pot11_bls12381_final.ptau"); + + // Load template(s) + const templates = {}; + templates.groth16 = fs.readFileSync(path.join("../templates", "verifier_groth16.aes.ejs"), "utf8"); + + let verifierContract; + let curve; + + before(async () => { + aeSdk = utils.getSdk(); + + // create a snapshot of the blockchain state + await utils.createSnapshot(aeSdk); + + await utils.awaitKeyBlocks(aeSdk, 1); + + // create folder for contracts + await fs.promises.mkdir("contracts", {recursive: true}); + + // initialize curve + curve = await buildBls12381(); + }); + + // after each test roll back to initial state + afterEach(async () => { + await utils.rollbackSnapshot(aeSdk); + await curve.terminate(); + }); + + it("Groth16 smart contract with 2 inputs", async () => { + const res = await groth16Verify(path.join("./input", "circuit2.r1cs"), path.join("./input", "witness2.wtns")); + assert.equal(res.decodedResult, true); + }); + + it("Groth16 smart contract 3 inputs", async () => { + const res = await groth16Verify(path.join("./input", "circuit3.r1cs"), path.join("./input", "witness3.wtns")); + assert.equal(res.decodedResult, true); + }); + + async function groth16Verify(r1csFilename, wtnsFilename) { + const sophiaVerifierFilename = path.join("contracts", "groth16.aes"); + + const zkeyFilename = { type: "mem" }; + + await snarkjs.zKey.newZKey(r1csFilename, ptauFilename, zkeyFilename); + const { proof: proof, publicSignals: publicInputs } = await snarkjs.groth16.prove(zkeyFilename, wtnsFilename); + + const theProof = {a: [proof.pi_a[0], proof.pi_a[1]], + b: [[proof.pi_b[0][0], proof.pi_b[0][1]], [proof.pi_b[1][0], proof.pi_b[1][1]]], + c: [proof.pi_c[0], proof.pi_c[1]]}; + + + // Generate groth16 verifier solidity file from groth16 template + zkey + const verifierCode = await snarkjs.zKey.exportSophiaVerifier(zkeyFilename, templates); + fs.writeFileSync(sophiaVerifierFilename, verifierCode, "utf-8"); + + // a filesystem object must be passed to the compiler if the contract uses custom includes + const fileSystem = utils.getFilesystem(sophiaVerifierFilename); + + // initialize the contract instance + const sourceCode = utils.getContractContent(sophiaVerifierFilename); + contract = await aeSdk.initializeContract({ sourceCode, fileSystem }); + + await contract.$deploy([]); + + return await contract.verify(publicInputs, theProof); + } +}); diff --git a/src/groth16.js b/src/groth16.js index fa3c66f6..84dc2b46 100644 --- a/src/groth16.js +++ b/src/groth16.js @@ -21,3 +21,4 @@ export {default as fullProve} from "./groth16_fullprove.js"; export {default as prove} from "./groth16_prove.js"; export {default as verify} from "./groth16_verify.js"; export {default as exportSolidityCallData} from "./groth16_exportsoliditycalldata.js"; +export {default as exportSophiaCallData} from "./groth16_exportsophiacalldata.js"; diff --git a/src/groth16_exportsophiacalldata.js b/src/groth16_exportsophiacalldata.js new file mode 100644 index 00000000..1b46f417 --- /dev/null +++ b/src/groth16_exportsophiacalldata.js @@ -0,0 +1,89 @@ +/* + Copyright 2024 0KIMS association. + + This file is part of snarkJS. + + snarkJS is a free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + snarkJS is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public + License for more details. + + You should have received a copy of the GNU General Public License + along with snarkJS. If not, see . +*/ +import { utils } from "ffjavascript"; +const { unstringifyBigInts } = utils; + +function cli_n(n) { + let nstr = n.toString(16); + return `0x${nstr}`; +} + +function sdk_n(n) { + let nstr = n.toString(10); + return `${nstr}n`; +} + +export default async function groth16ExportSophiaCalldata(_proof, _pub, type) { + const proof = unstringifyBigInts(_proof); + const pub = unstringifyBigInts(_pub); + + + let S; + + if (type == "cli") { + let inputs = ""; + for (let i=0; i, + <%= vk_alpha_1[1] %>, + 1), + + beta = BLS12_381.mk_g2(<%= vk_beta_2[0][0] %>, + <%= vk_beta_2[0][1] %>, + <%= vk_beta_2[1][0] %>, + <%= vk_beta_2[1][1] %>, + 1, 0), + + gamma = BLS12_381.mk_g2(<%= vk_gamma_2[0][0] %>, + <%= vk_gamma_2[0][1] %>, + <%= vk_gamma_2[1][0] %>, + <%= vk_gamma_2[1][1] %>, + 1, 0), + + delta = BLS12_381.mk_g2(<%= vk_delta_2[0][0] %>, + <%= vk_delta_2[0][1] %>, + <%= vk_delta_2[1][0] %>, + <%= vk_delta_2[1][1] %>, + 1, 0), + + gamma_abc = +<% if (IC.length == 0) { %> + [] +<% } else { %> + [ BLS12_381.mk_g1(<%=IC[0][0]%>, + <%=IC[0][1]%>, + 1) +<% for (let i=1; i + , BLS12_381.mk_g1(<%=IC[i][0]%>, + <%=IC[i][1]%>, + 1) +<% } %> +<% } %> + ] + } \ No newline at end of file