forked from iden3/snarkjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnarkjs.min.js
9 lines (9 loc) · 394 KB
/
snarkjs.min.js
1
2
3
4
5
6
7
8
9
var snarkjs=function(t){"use strict";const e=[0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4];function a(t,e){return e&&10!=e?16==e?"0x"==t.slice(0,2)?BigInt(t):BigInt("0x"+t):void 0:BigInt(t)}const i=a;function o(t){const a=t.toString(16);return 4*(a.length-1)+e[parseInt(a[0],16)]}function n(t){return BigInt(t)<BigInt(0)}function c(t){return!t}function r(t,e){return BigInt(t)<<BigInt(e)}function l(t,e){return BigInt(t)>>BigInt(e)}const s=r,d=l;function u(t){return(BigInt(t)&BigInt(1))==BigInt(1)}function g(t){let e=BigInt(t);const a=[];for(;e;)e&BigInt(1)?a.push(1):a.push(0),e>>=BigInt(1);return a}function _(t){if(t>BigInt(Number.MAX_SAFE_INTEGER))throw new Error("Number too big");return Number(t)}function f(t,e){return BigInt(t)+BigInt(e)}function h(t,e){return BigInt(t)-BigInt(e)}function p(t){return-BigInt(t)}function m(t,e){return BigInt(t)*BigInt(e)}function L(t,e){return BigInt(t)**BigInt(e)}function w(t,e){return BigInt(t)/BigInt(e)}function A(t,e){return BigInt(t)%BigInt(e)}function b(t,e){return BigInt(t)==BigInt(e)}function y(t,e){return BigInt(t)>BigInt(e)}function I(t,e){return BigInt(t)>=BigInt(e)}function C(t,e){return BigInt(t)&BigInt(e)}function F(t,e,a,i){const o="0000000"+a.toString(16),n=new Uint32Array(t.buffer,e,i/4),c=1+(4*(o.length-7)-1>>5);for(let t=0;t<c;t++)n[t]=parseInt(o.substring(o.length-8*t-8,o.length-8*t),16);for(let t=c;t<n.length;t++)n[t]=0;for(let e=4*n.length;e<i;e++)t[e]=_(C(l(a,8*e),255))}function x(t,e,a,i){const o="0000000"+a.toString(16),n=new DataView(t.buffer,t.byteOffset+e,i),c=1+(4*(o.length-7)-1>>5);for(let t=0;t<c;t++)n.setUint32(i-4*t-4,parseInt(o.substring(o.length-8*t-8,o.length-8*t),16),!1);for(let t=0;t<i/4-c;t++)n[t]=0}function E(t,e,i){i=i||t.byteLength,e=e||0;const o=new Uint32Array(t.buffer,e,i/4),n=new Array(i/4);return o.forEach(((t,e)=>n[n.length-e-1]=t.toString(16).padStart(8,"0"))),a(n.join(""),16)}function B(t,e,i){i=i||t.byteLength,e=e||0;const o=new DataView(t.buffer,t.byteOffset+e,i),n=new Array(i/4);for(let t=0;t<i/4;t++)n[t]=o.getUint32(4*t,!1).toString(16).padStart(8,"0");return a(n.join(""),16)}function v(t,e){return t.toString(e)}function S(t){const e=new Uint8Array(Math.floor((o(t)-1)/8)+1);return F(e,0,t,e.byteLength),e}const G=i(0),P=i(1);var U=Object.freeze({__proto__:null,fromString:a,e:i,fromArray:function(t,e){let a=BigInt(0);e=BigInt(e);for(let i=0;i<t.length;i++)a=a*e+BigInt(t[i]);return a},bitLength:o,isNegative:n,isZero:c,shiftLeft:r,shiftRight:l,shl:s,shr:d,isOdd:u,naf:function(t){let e=BigInt(t);const a=[];for(;e;){if(e&BigInt(1)){const t=2-Number(e%BigInt(4));a.push(t),e-=BigInt(t)}else a.push(0);e>>=BigInt(1)}return a},bits:g,toNumber:_,toArray:function(t,e){const a=[];let i=BigInt(t);for(e=BigInt(e);i;)a.unshift(Number(i%e)),i/=e;return a},add:f,sub:h,neg:p,mul:m,square:function(t){return BigInt(t)*BigInt(t)},pow:L,exp:function(t,e){return BigInt(t)**BigInt(e)},abs:function(t){return BigInt(t)>=0?BigInt(t):-BigInt(t)},div:w,mod:A,eq:b,neq:function(t,e){return BigInt(t)!=BigInt(e)},lt:function(t,e){return BigInt(t)<BigInt(e)},gt:y,leq:function(t,e){return BigInt(t)<=BigInt(e)},geq:I,band:C,bor:function(t,e){return BigInt(t)|BigInt(e)},bxor:function(t,e){return BigInt(t)^BigInt(e)},land:function(t,e){return BigInt(t)&&BigInt(e)},lor:function(t,e){return BigInt(t)||BigInt(e)},lnot:function(t){return!BigInt(t)},toRprLE:F,toRprBE:x,fromRprLE:E,fromRprBE:B,toString:v,toLEBuff:S,zero:G,one:P});function O(t,e,a){if(c(a))return t.one;const i=g(a);if(0==i.length)return t.one;let o=e;for(let a=i.length-2;a>=0;a--)o=t.square(o),i[a]&&(o=t.mul(o,e));return o}function z(t){if(t.m%2==1)if(b(A(t.p,4),1))if(b(A(t.p,8),1))if(b(A(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=w(t.sqrt_t,2);let e=t.one;for(;t.eq(e,t.one);){const a=t.random();t.sqrt_z=t.pow(a,t.sqrt_t),e=t.pow(t.sqrt_z,2**(t.sqrt_s-1))}t.sqrt_tm1d2=w(h(t.sqrt_t,1),2),t.sqrt=function(t){const e=this;if(e.isZero(t))return e.zero;let a=e.pow(t,e.sqrt_tm1d2);const i=e.pow(e.mul(e.square(a),t),2**(e.sqrt_s-1));if(e.eq(i,e.negone))return null;let o=e.sqrt_s,n=e.mul(t,a),c=e.mul(n,a),r=e.sqrt_z;for(;!e.eq(c,e.one);){let t=e.square(c),i=1;for(;!e.eq(t,e.one);)t=e.square(t),i++;a=r;for(let t=0;t<o-i-1;t++)a=e.square(a);r=e.square(a),c=e.mul(c,r),n=e.mul(n,a),o=i}return e.geq(n,e.zero)?n:e.neg(n)}}(t);else{if(!b(A(t.p,16),9))throw new Error("Field withot sqrt");!function(t){t.sqrt=function(){throw new Error("Sqrt alg 4 not implemented")}}(t)}else{if(!b(A(t.p,8),5))throw new Error("Field withot sqrt");!function(t){t.sqrt=function(){throw new Error("Sqrt alg 3 not implemented")}}(t)}else b(A(t.p,4),3)&&function(t){t.sqrt_q=L(t.p,t.m),t.sqrt_e1=w(h(t.sqrt_q,3),4),t.sqrt=function(e){if(this.isZero(e))return this.zero;const a=this.pow(e,this.sqrt_e1),i=this.mul(this.square(a),e);if(this.eq(i,this.negone))return null;const o=this.mul(a,e);return t.geq(o,t.zero)?o:t.neg(o)}}(t);else{const e=A(L(t.p,t.m/2),4);1==e?function(t){t.sqrt=function(){throw new Error("Sqrt alg 10 not implemented")}}(t):3==e?function(t){t.sqrt_q=L(t.p,t.m/2),t.sqrt_e34=w(h(t.sqrt_q,3),4),t.sqrt_e12=w(h(t.sqrt_q,1),2),t.frobenius=function(e,a){return e%2==1?t.conjugate(a):a},t.sqrt=function(t){const e=this,a=e.pow(t,e.sqrt_e34),i=e.mul(e.square(a),t),o=e.mul(e.frobenius(1,i),i);if(e.eq(o,e.negone))return null;const n=e.mul(a,t);let c;if(e.eq(i,e.negone))c=e.mul(n,[e.F.zero,e.F.one]);else{const t=e.pow(e.add(e.one,i),e.sqrt_e12);c=e.mul(t,n)}return e.geq(c,e.zero)?c:e.neg(c)}}(t):function(t){t.sqrt=function(){throw new Error("Sqrt alg 8 not implemented")}}(t)}}function Q(t,e,a,i,o){t[e]=t[e]+t[a]>>>0,t[o]=(t[o]^t[e])>>>0,t[o]=(t[o]<<16|t[o]>>>16&65535)>>>0,t[i]=t[i]+t[o]>>>0,t[a]=(t[a]^t[i])>>>0,t[a]=(t[a]<<12|t[a]>>>20&4095)>>>0,t[e]=t[e]+t[a]>>>0,t[o]=(t[o]^t[e])>>>0,t[o]=(t[o]<<8|t[o]>>>24&255)>>>0,t[i]=t[i]+t[o]>>>0,t[a]=(t[a]^t[i])>>>0,t[a]=(t[a]<<7|t[a]>>>25&127)>>>0}class q{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 e=0;e<10;e++)Q(t=this.buff,0,4,8,12),Q(t,1,5,9,13),Q(t,2,6,10,14),Q(t,3,7,11,15),Q(t,0,5,10,15),Q(t,1,6,11,12),Q(t,2,7,8,13),Q(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)))}}var M={};function T(t){let e=new Uint8Array(t);if(void 0!==globalThis.crypto)globalThis.crypto.getRandomValues(e);else for(let a=0;a<t;a++)e[a]=4294967296*Math.random()>>>0;return e}let k=null;function R(){return k||(k=new q(function(){const t=T(32),e=new Uint32Array(t.buffer),a=[];for(let t=0;t<8;t++)a.push(e[t]);return a}()),k)}class D{constructor(t,e,a){this.F=e,this.G=t,this.opMulGF=a;let i=e.sqrt_t||e.t,o=e.sqrt_s||e.s,n=e.one;for(;e.eq(e.pow(n,e.half),e.one);)n=e.add(n,e.one);this.w=new Array(o+1),this.wi=new Array(o+1),this.w[o]=this.F.pow(n,i),this.wi[o]=this.F.inv(this.w[o]);let c=o-1;for(;c>=0;)this.w[c]=this.F.square(this.w[c+1]),this.wi[c]=this.F.square(this.wi[c+1]),c--;this.roots=[],this._setRoots(Math.min(o,15))}_setRoots(t){for(let e=t;e>=0&&!this.roots[e];e--){let t=this.F.one;const a=1<<e,i=new Array(a);for(let o=0;o<a;o++)i[o]=t,t=this.F.mul(t,this.w[e]);this.roots[e]=i}}fft(t){if(t.length<=1)return t;const e=N(t.length-1)+1;this._setRoots(e);const a=1<<e;if(t.length!=a)throw new Error("Size must be multiple of 2");return V(this,t,e,0,1)}ifft(t){if(t.length<=1)return t;const e=N(t.length-1)+1;this._setRoots(e);const a=1<<e;if(t.length!=a)throw new Error("Size must be multiple of 2");const i=V(this,t,e,0,1),o=this.F.inv(this.F.mulScalar(this.F.one,a)),n=new Array(a);for(let t=0;t<a;t++)n[t]=this.opMulGF(i[(a-t)%a],o);return n}}function N(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 V(t,e,a,i,o){const n=1<<a;if(1==n)return[e[i]];if(2==n)return[t.G.add(e[i],e[i+o]),t.G.sub(e[i],e[i+o])];const c=n>>1,r=V(t,e,a-1,i,2*o),l=V(t,e,a-1,i+o,2*o),s=new Array(n);for(let e=0;e<c;e++)s[e]=t.G.add(r[e],t.opMulGF(l[e],t.roots[a][e])),s[e+c]=t.G.sub(r[e],t.opMulGF(l[e],t.roots[a][e]));return s}class K{constructor(t){this.type="F1",this.one=BigInt(1),this.zero=BigInt(0),this.p=BigInt(t),this.m=1,this.negone=this.p-this.one,this.two=BigInt(2),this.half=this.p>>this.one,this.bitLength=o(this.p),this.mask=(this.one<<BigInt(this.bitLength))-this.one,this.n64=Math.floor((this.bitLength-1)/64)+1,this.n32=2*this.n64,this.n8=8*this.n64,this.R=this.e(this.one<<BigInt(64*this.n64)),this.Ri=this.inv(this.R);const e=this.negone>>this.one;this.nqr=this.two;let a=this.pow(this.nqr,e);for(;!this.eq(a,this.negone);)this.nqr=this.nqr+this.one,a=this.pow(this.nqr,e);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 D(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,e){let a;if(e?16==e&&(a=BigInt("0x"+t)):a=BigInt(t),a<0){let t=-a;return t>=this.p&&(t%=this.p),this.p-t}return a>=this.p?a%this.p:a}add(t,e){const a=t+e;return a>=this.p?a-this.p:a}sub(t,e){return t>=e?t-e:this.p-e+t}neg(t){return t?this.p-t:t}mul(t,e){return t*e%this.p}mulScalar(t,e){return t*this.e(e)%this.p}square(t){return t*t%this.p}eq(t,e){return t==e}neq(t,e){return t!=e}lt(t,e){return(t>this.half?t-this.p:t)<(e>this.half?e-this.p:e)}gt(t,e){return(t>this.half?t-this.p:t)>(e>this.half?e-this.p:e)}leq(t,e){return(t>this.half?t-this.p:t)<=(e>this.half?e-this.p:e)}geq(t,e){return(t>this.half?t-this.p:t)>=(e>this.half?e-this.p:e)}div(t,e){return this.mul(t,this.inv(e))}idiv(t,e){if(!e)throw new Error("Division by zero");return t/e}inv(t){if(!t)throw new Error("Division by zero");let e=this.zero,a=this.p,i=this.one,o=t%this.p;for(;o;){let t=a/o;[e,i]=[i,e-t*i],[a,o]=[o,a-t*o]}return e<this.zero&&(e+=this.p),e}mod(t,e){return t%e}pow(t,e){return O(this,t,e)}exp(t,e){return O(this,t,e)}band(t,e){const a=t&e&this.mask;return a>=this.p?a-this.p:a}bor(t,e){const a=(t|e)&this.mask;return a>=this.p?a-this.p:a}bxor(t,e){const a=(t^e)&this.mask;return a>=this.p?a-this.p:a}bnot(t){const e=t^this.mask;return e>=this.p?e-this.p:e}shl(t,e){if(Number(e)<this.bitLength){const a=t<<e&this.mask;return a>=this.p?a-this.p:a}{const a=this.p-e;return Number(a)<this.bitLength?t>>a:this.zero}}shr(t,e){if(Number(e)<this.bitLength)return t>>e;{const a=this.p-e;if(Number(a)<this.bitLength){const e=t<<a&this.mask;return e>=this.p?e-this.p:e}return 0}}land(t,e){return t&&e?this.one:this.zero}lor(t,e){return t||e?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 e=this.s,a=this.nqr_to_t,i=this.pow(t,this.t),o=this.pow(t,this.add(this.t,this.one)>>this.one);for(;i!=this.one;){let t=this.square(i),n=1;for(;t!=this.one;)n++,t=this.square(t);let c=a;for(let t=0;t<e-n-1;t++)c=this.square(c);e=n,a=this.square(c),i=this.mul(i,a),o=this.mul(o,c)}return o>this.p>>this.one&&(o=this.neg(o)),o}normalize(t,e){if((t=BigInt(t,e))<0){let e=-t;return e>=this.p&&(e%=this.p),this.p-e}return t>=this.p?t%this.p:t}random(){const t=2*this.bitLength/8;let e=this.zero;for(let a=0;a<t;a++)e=(e<<BigInt(8))+BigInt(T(1)[0]);return e%this.p}toString(t,e){let a;if(e=e||10,t>this.half&&10==e){a="-"+(this.p-t).toString(e)}else a=t.toString(e);return a}isZero(t){return t==this.zero}fromRng(t){let e;do{e=this.zero;for(let a=0;a<this.n64;a++)e+=t.nextU64()<<BigInt(64*a);e&=this.mask}while(e>=this.p);return e=e*this.Ri%this.p,e}fft(t){return this.FFT.fft(t)}ifft(t){return this.FFT.ifft(t)}toRprLE(t,e,a){F(t,e,a,8*this.n64)}toRprBE(t,e,a){x(t,e,a,8*this.n64)}toRprBEM(t,e,a){return this.toRprBE(t,e,this.mul(this.R,a))}toRprLEM(t,e,a){return this.toRprLE(t,e,this.mul(this.R,a))}fromRprLE(t,e){return E(t,e,this.n8)}fromRprBE(t,e){return B(t,e,this.n8)}fromRprLEM(t,e){return this.mul(this.fromRprLE(t,e),this.Ri)}fromRprBEM(t,e){return this.mul(this.fromRprBE(t,e),this.Ri)}toObject(t){return t}}var j="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},H={bigInt2BytesLE:function(t,e){const a=Array(e);let i=BigInt(t);for(let t=0;t<e;t++)a[t]=Number(0xFFn&i),i>>=8n;return a},bigInt2U32LE:function(t,e){const a=Array(e);let i=BigInt(t);for(let t=0;t<e;t++)a[t]=Number(0xFFFFFFFFn&i),i>>=32n;return a},isOcamNum:function(t){return!!Array.isArray(t)&&(3==t.length&&("number"==typeof t[0]&&("number"==typeof t[1]&&!!Array.isArray(t[2]))))}},$=function(t,e,a,i,o,n,c){const r=t.addFunction(e);r.addParam("base","i32"),r.addParam("scalar","i32"),r.addParam("scalarLength","i32"),r.addParam("r","i32"),r.addLocal("i","i32"),r.addLocal("b","i32");const l=r.getCodeBuilder(),s=l.i32_const(t.alloc(a));r.addCode(l.if(l.i32_eqz(l.getLocal("scalarLength")),[...l.call(c,l.getLocal("r")),...l.ret([])])),r.addCode(l.call(n,l.getLocal("base"),s)),r.addCode(l.call(c,l.getLocal("r"))),r.addCode(l.setLocal("i",l.getLocal("scalarLength"))),r.addCode(l.block(l.loop(l.setLocal("i",l.i32_sub(l.getLocal("i"),l.i32_const(1))),l.setLocal("b",l.i32_load8_u(l.i32_add(l.getLocal("scalar"),l.getLocal("i")))),...function(){const t=[];for(let e=0;e<8;e++)t.push(...l.call(o,l.getLocal("r"),l.getLocal("r")),...l.if(l.i32_ge_u(l.getLocal("b"),l.i32_const(128>>e)),[...l.setLocal("b",l.i32_sub(l.getLocal("b"),l.i32_const(128>>e))),...l.call(i,l.getLocal("r"),s,l.getLocal("r"))]));return t}(),l.br_if(1,l.i32_eqz(l.getLocal("i"))),l.br(0))))},Y=function(t,e){const a=8*t.modules[e].n64,i=t.addFunction(e+"_batchInverse");i.addParam("pIn","i32"),i.addParam("inStep","i32"),i.addParam("n","i32"),i.addParam("pOut","i32"),i.addParam("outStep","i32"),i.addLocal("itAux","i32"),i.addLocal("itIn","i32"),i.addLocal("itOut","i32"),i.addLocal("i","i32");const o=i.getCodeBuilder(),n=o.i32_const(t.alloc(a));i.addCode(o.setLocal("itAux",o.i32_load(o.i32_const(0))),o.i32_store(o.i32_const(0),o.i32_add(o.getLocal("itAux"),o.i32_mul(o.i32_add(o.getLocal("n"),o.i32_const(1)),o.i32_const(a))))),i.addCode(o.call(e+"_one",o.getLocal("itAux")),o.setLocal("itIn",o.getLocal("pIn")),o.setLocal("itAux",o.i32_add(o.getLocal("itAux"),o.i32_const(a))),o.setLocal("i",o.i32_const(0)),o.block(o.loop(o.br_if(1,o.i32_eq(o.getLocal("i"),o.getLocal("n"))),o.if(o.call(e+"_isZero",o.getLocal("itIn")),o.call(e+"_copy",o.i32_sub(o.getLocal("itAux"),o.i32_const(a)),o.getLocal("itAux")),o.call(e+"_mul",o.getLocal("itIn"),o.i32_sub(o.getLocal("itAux"),o.i32_const(a)),o.getLocal("itAux"))),o.setLocal("itIn",o.i32_add(o.getLocal("itIn"),o.getLocal("inStep"))),o.setLocal("itAux",o.i32_add(o.getLocal("itAux"),o.i32_const(a))),o.setLocal("i",o.i32_add(o.getLocal("i"),o.i32_const(1))),o.br(0))),o.setLocal("itIn",o.i32_sub(o.getLocal("itIn"),o.getLocal("inStep"))),o.setLocal("itAux",o.i32_sub(o.getLocal("itAux"),o.i32_const(a))),o.setLocal("itOut",o.i32_add(o.getLocal("pOut"),o.i32_mul(o.i32_sub(o.getLocal("n"),o.i32_const(1)),o.getLocal("outStep")))),o.call(e+"_inverse",o.getLocal("itAux"),o.getLocal("itAux")),o.block(o.loop(o.br_if(1,o.i32_eqz(o.getLocal("i"))),o.if(o.call(e+"_isZero",o.getLocal("itIn")),[...o.call(e+"_copy",o.getLocal("itAux"),o.i32_sub(o.getLocal("itAux"),o.i32_const(a))),...o.call(e+"_zero",o.getLocal("itOut"))],[...o.call(e+"_copy",o.i32_sub(o.getLocal("itAux"),o.i32_const(a)),n),...o.call(e+"_mul",o.getLocal("itAux"),o.getLocal("itIn"),o.i32_sub(o.getLocal("itAux"),o.i32_const(a))),...o.call(e+"_mul",o.getLocal("itAux"),n,o.getLocal("itOut"))]),o.setLocal("itIn",o.i32_sub(o.getLocal("itIn"),o.getLocal("inStep"))),o.setLocal("itOut",o.i32_sub(o.getLocal("itOut"),o.getLocal("outStep"))),o.setLocal("itAux",o.i32_sub(o.getLocal("itAux"),o.i32_const(a))),o.setLocal("i",o.i32_sub(o.getLocal("i"),o.i32_const(1))),o.br(0)))),i.addCode(o.i32_store(o.i32_const(0),o.getLocal("itAux")))};var W=function(t,e,a,i,o,n){void 0===n&&(n=i<o);const c=t.addFunction(e);c.addParam("pIn","i32"),c.addParam("n","i32"),c.addParam("pOut","i32"),c.addLocal("i","i32"),c.addLocal("itIn","i32"),c.addLocal("itOut","i32");const r=c.getCodeBuilder();n?c.addCode(r.setLocal("itIn",r.i32_add(r.getLocal("pIn"),r.i32_mul(r.i32_sub(r.getLocal("n"),r.i32_const(1)),r.i32_const(i)))),r.setLocal("itOut",r.i32_add(r.getLocal("pOut"),r.i32_mul(r.i32_sub(r.getLocal("n"),r.i32_const(1)),r.i32_const(o)))),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(a,r.getLocal("itIn"),r.getLocal("itOut")),r.setLocal("itIn",r.i32_sub(r.getLocal("itIn"),r.i32_const(i))),r.setLocal("itOut",r.i32_sub(r.getLocal("itOut"),r.i32_const(o))),r.setLocal("i",r.i32_add(r.getLocal("i"),r.i32_const(1))),r.br(0)))):c.addCode(r.setLocal("itIn",r.getLocal("pIn")),r.setLocal("itOut",r.getLocal("pOut")),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(a,r.getLocal("itIn"),r.getLocal("itOut")),r.setLocal("itIn",r.i32_add(r.getLocal("itIn"),r.i32_const(i))),r.setLocal("itOut",r.i32_add(r.getLocal("itOut"),r.i32_const(o))),r.setLocal("i",r.i32_add(r.getLocal("i"),r.i32_const(1))),r.br(0))))};var Z=function(t,e,a,i,o,n){void 0===n&&(n=i<o);const c=t.addFunction(e);c.addParam("pIn1","i32"),c.addParam("pIn2","i32"),c.addParam("n","i32"),c.addParam("pOut","i32"),c.addLocal("i","i32"),c.addLocal("itIn1","i32"),c.addLocal("itIn2","i32"),c.addLocal("itOut","i32");const r=c.getCodeBuilder();n?c.addCode(r.setLocal("itIn1",r.i32_add(r.getLocal("pIn1"),r.i32_mul(r.i32_sub(r.getLocal("n"),r.i32_const(1)),r.i32_const(i)))),r.setLocal("itIn2",r.i32_add(r.getLocal("pIn2"),r.i32_mul(r.i32_sub(r.getLocal("n"),r.i32_const(1)),r.i32_const(i)))),r.setLocal("itOut",r.i32_add(r.getLocal("pOut"),r.i32_mul(r.i32_sub(r.getLocal("n"),r.i32_const(1)),r.i32_const(o)))),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(a,r.getLocal("itIn1"),r.getLocal("itIn2"),r.getLocal("itOut")),r.setLocal("itIn1",r.i32_sub(r.getLocal("itIn1"),r.i32_const(i))),r.setLocal("itIn2",r.i32_sub(r.getLocal("itIn2"),r.i32_const(i))),r.setLocal("itOut",r.i32_sub(r.getLocal("itOut"),r.i32_const(o))),r.setLocal("i",r.i32_add(r.getLocal("i"),r.i32_const(1))),r.br(0)))):c.addCode(r.setLocal("itIn1",r.getLocal("pIn1")),r.setLocal("itIn2",r.getLocal("pIn2")),r.setLocal("itOut",r.getLocal("pOut")),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(a,r.getLocal("itIn1"),r.getLocal("itIn2"),r.getLocal("itOut")),r.setLocal("itIn1",r.i32_add(r.getLocal("itIn1"),r.i32_const(i))),r.setLocal("itIn2",r.i32_add(r.getLocal("itIn2"),r.i32_const(i))),r.setLocal("itOut",r.i32_add(r.getLocal("itOut"),r.i32_const(o))),r.setLocal("i",r.i32_add(r.getLocal("i"),r.i32_const(1))),r.br(0))))};var J={};function X(t,e){return t===e?0:t>e?1:-1}function tt(t){return t*t}function et(t){return t%2n!==0n}function at(t){return t%2n===0n}function it(t){return t<0n}function ot(t){return t>0n}function nt(t){return it(t)?t.toString(2).length-1:t.toString(2).length}function ct(t){return t<0n?-t:t}function rt(t){return 1n===ct(t)}function lt(t,e){for(var a,i,o,n=0n,c=1n,r=e,l=ct(t);0n!==l;)a=r/l,i=n,o=r,n=c,r=l,c=i-a*c,l=o-a*l;if(!rt(r))throw new Error(t.toString()+" and "+e.toString()+" are not co-prime");return-1===X(n,0n)&&(n+=e),it(t)?-n:n}function st(t,e,a){if(0n===a)throw new Error("Cannot take modPow with modulus 0");var i=1n,o=t%a;for(it(e)&&(e*=-1n,o=lt(o,a));ot(e);){if(0n===o)return 0n;et(e)&&(i=i*o%a),e/=2n,o=tt(o)%a}return i}function dt(t,e){return 0n!==e&&(!!rt(e)||(0===function(t,e){return(t=t>=0n?t:-t)===(e=e>=0n?e:-e)?0:t>e?1:-1}(e,2n)?at(t):t%e===0n))}function ut(t,e){for(var a,i,o,n=function(t){return t-1n}(t),c=n,r=0;at(c);)c/=2n,r++;t:for(i=0;i<e.length;i++)if(!(t<e[i]||rt(o=st(BigInt(e[i]),c,t))||o===n)){for(a=r-1;0!=a;a--){if(rt(o=tt(o)%t))return!1;if(o===n)continue t}return!1}return!0}J.bitLength=nt,J.isOdd=et,J.isNegative=it,J.abs=ct,J.isUnit=rt,J.compare=X,J.modInv=lt,J.modPow=st,J.isPrime=function(t){var e=function(t){var e=ct(t);return!rt(e)&&(2n===e||3n===e||5n===e||!(at(e)||dt(e,3n)||dt(e,5n))&&(e<49n||void 0))}(t);if(void 0!==e)return e;var a=ct(t),i=nt(a);if(i<=64)return ut(a,[2,3,5,7,11,13,17,19,23,29,31,37]);for(var o=Math.log(2)*Number(i),n=Math.ceil(o),c=[],r=0;r<n;r++)c.push(BigInt(r+2));return ut(a,c)},J.square=tt;const gt=function(t,e,a){const i=a||"int";if(t.modules[i])return i;t.modules[i]={};const o=2*e,n=8*e;return function(){const a=t.addFunction(i+"_copy");a.addParam("px","i32"),a.addParam("pr","i32");const o=a.getCodeBuilder();for(let t=0;t<e;t++)a.addCode(o.i64_store(o.getLocal("pr"),8*t,o.i64_load(o.getLocal("px"),8*t)))}(),function(){const a=t.addFunction(i+"_zero");a.addParam("pr","i32");const o=a.getCodeBuilder();for(let t=0;t<e;t++)a.addCode(o.i64_store(o.getLocal("pr"),8*t,o.i64_const(0)))}(),function(){const a=t.addFunction(i+"_isZero");a.addParam("px","i32"),a.setReturnType("i32");const o=a.getCodeBuilder();a.addCode(function t(e){return 0==e?o.ret(o.i64_eqz(o.i64_load(o.getLocal("px")))):o.if(o.i64_eqz(o.i64_load(o.getLocal("px"),8*e)),t(e-1),o.ret(o.i32_const(0)))}(e-1)),a.addCode(o.ret(o.i32_const(0)))}(),function(){const a=t.addFunction(i+"_one");a.addParam("pr","i32");const o=a.getCodeBuilder();a.addCode(o.i64_store(o.getLocal("pr"),0,o.i64_const(1)));for(let t=1;t<e;t++)a.addCode(o.i64_store(o.getLocal("pr"),8*t,o.i64_const(0)))}(),function(){const a=t.addFunction(i+"_eq");a.addParam("px","i32"),a.addParam("py","i32"),a.setReturnType("i32");const o=a.getCodeBuilder();a.addCode(function t(e){return 0==e?o.ret(o.i64_eq(o.i64_load(o.getLocal("px")),o.i64_load(o.getLocal("py")))):o.if(o.i64_eq(o.i64_load(o.getLocal("px"),8*e),o.i64_load(o.getLocal("py"),8*e)),t(e-1),o.ret(o.i32_const(0)))}(e-1)),a.addCode(o.ret(o.i32_const(0)))}(),function(){const a=t.addFunction(i+"_gte");a.addParam("px","i32"),a.addParam("py","i32"),a.setReturnType("i32");const o=a.getCodeBuilder();a.addCode(function t(e){return 0==e?o.ret(o.i64_ge_u(o.i64_load(o.getLocal("px")),o.i64_load(o.getLocal("py")))):o.if(o.i64_lt_u(o.i64_load(o.getLocal("px"),8*e),o.i64_load(o.getLocal("py"),8*e)),o.ret(o.i32_const(0)),o.if(o.i64_gt_u(o.i64_load(o.getLocal("px"),8*e),o.i64_load(o.getLocal("py"),8*e)),o.ret(o.i32_const(1)),t(e-1)))}(e-1)),a.addCode(o.ret(o.i32_const(0)))}(),function(){const e=t.addFunction(i+"_add");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32"),e.setReturnType("i32"),e.addLocal("c","i64");const a=e.getCodeBuilder();e.addCode(a.setLocal("c",a.i64_add(a.i64_load32_u(a.getLocal("x")),a.i64_load32_u(a.getLocal("y"))))),e.addCode(a.i64_store32(a.getLocal("r"),a.getLocal("c")));for(let t=1;t<o;t++)e.addCode(a.setLocal("c",a.i64_add(a.i64_add(a.i64_load32_u(a.getLocal("x"),4*t),a.i64_load32_u(a.getLocal("y"),4*t)),a.i64_shr_u(a.getLocal("c"),a.i64_const(32))))),e.addCode(a.i64_store32(a.getLocal("r"),4*t,a.getLocal("c")));e.addCode(a.i32_wrap_i64(a.i64_shr_u(a.getLocal("c"),a.i64_const(32))))}(),function(){const e=t.addFunction(i+"_sub");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32"),e.setReturnType("i32"),e.addLocal("c","i64");const a=e.getCodeBuilder();e.addCode(a.setLocal("c",a.i64_sub(a.i64_load32_u(a.getLocal("x")),a.i64_load32_u(a.getLocal("y"))))),e.addCode(a.i64_store32(a.getLocal("r"),a.i64_and(a.getLocal("c"),a.i64_const("0xFFFFFFFF"))));for(let t=1;t<o;t++)e.addCode(a.setLocal("c",a.i64_add(a.i64_sub(a.i64_load32_u(a.getLocal("x"),4*t),a.i64_load32_u(a.getLocal("y"),4*t)),a.i64_shr_s(a.getLocal("c"),a.i64_const(32))))),e.addCode(a.i64_store32(a.getLocal("r"),4*t,a.i64_and(a.getLocal("c"),a.i64_const("0xFFFFFFFF"))));e.addCode(a.i32_wrap_i64(a.i64_shr_s(a.getLocal("c"),a.i64_const(32))))}(),function(){const e=t.addFunction(i+"_mul");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32"),e.addLocal("c0","i64"),e.addLocal("c1","i64");for(let t=0;t<o;t++)e.addLocal("x"+t,"i64"),e.addLocal("y"+t,"i64");const a=e.getCodeBuilder(),n=[],c=[];function r(t,e){let i,o;return n[t]?i=a.getLocal("x"+t):(i=a.teeLocal("x"+t,a.i64_load32_u(a.getLocal("x"),4*t)),n[t]=!0),c[e]?o=a.getLocal("y"+e):(o=a.teeLocal("y"+e,a.i64_load32_u(a.getLocal("y"),4*e)),c[e]=!0),a.i64_mul(i,o)}let l="c0",s="c1";for(let t=0;t<2*o-1;t++){for(let i=Math.max(0,t-o+1);i<=t&&i<o;i++){const o=t-i;e.addCode(a.setLocal(l,a.i64_add(a.i64_and(a.getLocal(l),a.i64_const(4294967295)),r(i,o)))),e.addCode(a.setLocal(s,a.i64_add(a.getLocal(s),a.i64_shr_u(a.getLocal(l),a.i64_const(32)))))}e.addCode(a.i64_store32(a.getLocal("r"),4*t,a.getLocal(l))),[l,s]=[s,l],e.addCode(a.setLocal(s,a.i64_shr_u(a.getLocal(l),a.i64_const(32))))}e.addCode(a.i64_store32(a.getLocal("r"),4*o*2-4,a.getLocal(l)))}(),function(){const e=t.addFunction(i+"_square");e.addParam("x","i32"),e.addParam("r","i32"),e.addLocal("c0","i64"),e.addLocal("c1","i64"),e.addLocal("c0_old","i64"),e.addLocal("c1_old","i64");for(let t=0;t<o;t++)e.addLocal("x"+t,"i64");const a=e.getCodeBuilder(),n=[];function c(t,e){let i,o;return n[t]?i=a.getLocal("x"+t):(i=a.teeLocal("x"+t,a.i64_load32_u(a.getLocal("x"),4*t)),n[t]=!0),n[e]?o=a.getLocal("x"+e):(o=a.teeLocal("x"+e,a.i64_load32_u(a.getLocal("x"),4*e)),n[e]=!0),a.i64_mul(i,o)}let r="c0",l="c1",s="c0_old",d="c1_old";for(let t=0;t<2*o-1;t++){e.addCode(a.setLocal(r,a.i64_const(0)),a.setLocal(l,a.i64_const(0)));for(let i=Math.max(0,t-o+1);i<t+1>>1&&i<o;i++){const o=t-i;e.addCode(a.setLocal(r,a.i64_add(a.i64_and(a.getLocal(r),a.i64_const(4294967295)),c(i,o)))),e.addCode(a.setLocal(l,a.i64_add(a.getLocal(l),a.i64_shr_u(a.getLocal(r),a.i64_const(32)))))}e.addCode(a.setLocal(r,a.i64_shl(a.i64_and(a.getLocal(r),a.i64_const(4294967295)),a.i64_const(1)))),e.addCode(a.setLocal(l,a.i64_add(a.i64_shl(a.getLocal(l),a.i64_const(1)),a.i64_shr_u(a.getLocal(r),a.i64_const(32))))),t%2==0&&(e.addCode(a.setLocal(r,a.i64_add(a.i64_and(a.getLocal(r),a.i64_const(4294967295)),c(t>>1,t>>1)))),e.addCode(a.setLocal(l,a.i64_add(a.getLocal(l),a.i64_shr_u(a.getLocal(r),a.i64_const(32)))))),t>0&&(e.addCode(a.setLocal(r,a.i64_add(a.i64_and(a.getLocal(r),a.i64_const(4294967295)),a.i64_and(a.getLocal(s),a.i64_const(4294967295))))),e.addCode(a.setLocal(l,a.i64_add(a.i64_add(a.getLocal(l),a.i64_shr_u(a.getLocal(r),a.i64_const(32))),a.getLocal(d))))),e.addCode(a.i64_store32(a.getLocal("r"),4*t,a.getLocal(r))),e.addCode(a.setLocal(s,a.getLocal(l)),a.setLocal(d,a.i64_shr_u(a.getLocal(s),a.i64_const(32))))}e.addCode(a.i64_store32(a.getLocal("r"),4*o*2-4,a.getLocal(s)))}(),function(){const e=t.addFunction(i+"_squareOld");e.addParam("x","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.call(i+"_mul",a.getLocal("x"),a.getLocal("x"),a.getLocal("r")))}(),function(){!function(){const e=t.addFunction(i+"__mul1");e.addParam("px","i32"),e.addParam("y","i64"),e.addParam("pr","i32"),e.addLocal("c","i64");const a=e.getCodeBuilder();e.addCode(a.setLocal("c",a.i64_mul(a.i64_load32_u(a.getLocal("px"),0,0),a.getLocal("y")))),e.addCode(a.i64_store32(a.getLocal("pr"),0,0,a.getLocal("c")));for(let t=1;t<o;t++)e.addCode(a.setLocal("c",a.i64_add(a.i64_mul(a.i64_load32_u(a.getLocal("px"),4*t,0),a.getLocal("y")),a.i64_shr_u(a.getLocal("c"),a.i64_const(32))))),e.addCode(a.i64_store32(a.getLocal("pr"),4*t,0,a.getLocal("c")))}(),function(){const e=t.addFunction(i+"__add1");e.addParam("x","i32"),e.addParam("y","i64"),e.addLocal("c","i64"),e.addLocal("px","i32");const a=e.getCodeBuilder();e.addCode(a.setLocal("px",a.getLocal("x"))),e.addCode(a.setLocal("c",a.i64_add(a.i64_load32_u(a.getLocal("px"),0,0),a.getLocal("y")))),e.addCode(a.i64_store32(a.getLocal("px"),0,0,a.getLocal("c"))),e.addCode(a.setLocal("c",a.i64_shr_u(a.getLocal("c"),a.i64_const(32)))),e.addCode(a.block(a.loop(a.br_if(1,a.i64_eqz(a.getLocal("c"))),a.setLocal("px",a.i32_add(a.getLocal("px"),a.i32_const(4))),a.setLocal("c",a.i64_add(a.i64_load32_u(a.getLocal("px"),0,0),a.getLocal("c"))),a.i64_store32(a.getLocal("px"),0,0,a.getLocal("c")),a.setLocal("c",a.i64_shr_u(a.getLocal("c"),a.i64_const(32))),a.br(0))))}();const e=t.addFunction(i+"_div");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("c","i32"),e.addParam("r","i32"),e.addLocal("rr","i32"),e.addLocal("cc","i32"),e.addLocal("eX","i32"),e.addLocal("eY","i32"),e.addLocal("sy","i64"),e.addLocal("sx","i64"),e.addLocal("ec","i32");const a=e.getCodeBuilder(),c=a.i32_const(t.alloc(n)),r=a.i32_const(t.alloc(n)),l=a.i32_const(t.alloc(n)),s=a.getLocal("cc"),d=a.getLocal("rr"),u=t.alloc(2*n),g=a.i32_const(u),_=a.i32_const(u+n);e.addCode(a.if(a.getLocal("c"),a.setLocal("cc",a.getLocal("c")),a.setLocal("cc",r))),e.addCode(a.if(a.getLocal("r"),a.setLocal("rr",a.getLocal("r")),a.setLocal("rr",l))),e.addCode(a.call(i+"_copy",a.getLocal("x"),d)),e.addCode(a.call(i+"_copy",a.getLocal("y"),c)),e.addCode(a.call(i+"_zero",s)),e.addCode(a.call(i+"_zero",g)),e.addCode(a.setLocal("eX",a.i32_const(n-1))),e.addCode(a.setLocal("eY",a.i32_const(n-1))),e.addCode(a.block(a.loop(a.br_if(1,a.i32_or(a.i32_load8_u(a.i32_add(c,a.getLocal("eY")),0,0),a.i32_eq(a.getLocal("eY"),a.i32_const(3)))),a.setLocal("eY",a.i32_sub(a.getLocal("eY"),a.i32_const(1))),a.br(0)))),e.addCode(a.setLocal("sy",a.i64_add(a.i64_load32_u(a.i32_sub(a.i32_add(c,a.getLocal("eY")),a.i32_const(3)),0,0),a.i64_const(1)))),e.addCode(a.if(a.i64_eq(a.getLocal("sy"),a.i64_const(1)),a.drop(a.i64_div_u(a.i64_const(0),a.i64_const(0))))),e.addCode(a.block(a.loop(a.block(a.loop(a.br_if(1,a.i32_or(a.i32_load8_u(a.i32_add(d,a.getLocal("eX")),0,0),a.i32_eq(a.getLocal("eX"),a.i32_const(7)))),a.setLocal("eX",a.i32_sub(a.getLocal("eX"),a.i32_const(1))),a.br(0))),a.setLocal("sx",a.i64_load(a.i32_sub(a.i32_add(d,a.getLocal("eX")),a.i32_const(7)),0,0)),a.setLocal("sx",a.i64_div_u(a.getLocal("sx"),a.getLocal("sy"))),a.setLocal("ec",a.i32_sub(a.i32_sub(a.getLocal("eX"),a.getLocal("eY")),a.i32_const(4))),a.block(a.loop(a.br_if(1,a.i32_and(a.i64_eqz(a.i64_and(a.getLocal("sx"),a.i64_const("0xFFFFFFFF00000000"))),a.i32_ge_s(a.getLocal("ec"),a.i32_const(0)))),a.setLocal("sx",a.i64_shr_u(a.getLocal("sx"),a.i64_const(8))),a.setLocal("ec",a.i32_add(a.getLocal("ec"),a.i32_const(1))),a.br(0))),a.if(a.i64_eqz(a.getLocal("sx")),[...a.br_if(2,a.i32_eqz(a.call(i+"_gte",d,c))),...a.setLocal("sx",a.i64_const(1)),...a.setLocal("ec",a.i32_const(0))]),a.call(i+"__mul1",c,a.getLocal("sx"),_),a.drop(a.call(i+"_sub",d,a.i32_sub(_,a.getLocal("ec")),d)),a.call(i+"__add1",a.i32_add(s,a.getLocal("ec")),a.getLocal("sx")),a.br(0))))}(),function(){const e=t.addFunction(i+"_inverseMod");e.addParam("px","i32"),e.addParam("pm","i32"),e.addParam("pr","i32"),e.addLocal("t","i32"),e.addLocal("newt","i32"),e.addLocal("r","i32"),e.addLocal("qq","i32"),e.addLocal("qr","i32"),e.addLocal("newr","i32"),e.addLocal("swp","i32"),e.addLocal("x","i32"),e.addLocal("signt","i32"),e.addLocal("signnewt","i32"),e.addLocal("signx","i32");const a=e.getCodeBuilder(),o=a.i32_const(t.alloc(n)),c=a.i32_const(t.alloc(n)),r=a.i32_const(t.alloc(n)),l=a.i32_const(t.alloc(n)),s=a.i32_const(t.alloc(n)),d=a.i32_const(t.alloc(n)),u=a.i32_const(t.alloc(2*n)),g=a.i32_const(t.alloc(n));e.addCode(a.setLocal("t",o),a.call(i+"_zero",o),a.setLocal("signt",a.i32_const(0))),e.addCode(a.setLocal("r",c),a.call(i+"_copy",a.getLocal("pm"),c)),e.addCode(a.setLocal("newt",r),a.call(i+"_one",r),a.setLocal("signnewt",a.i32_const(0))),e.addCode(a.setLocal("newr",l),a.call(i+"_copy",a.getLocal("px"),l)),e.addCode(a.setLocal("qq",s)),e.addCode(a.setLocal("qr",d)),e.addCode(a.setLocal("x",g)),e.addCode(a.block(a.loop(a.br_if(1,a.call(i+"_isZero",a.getLocal("newr"))),a.call(i+"_div",a.getLocal("r"),a.getLocal("newr"),a.getLocal("qq"),a.getLocal("qr")),a.call(i+"_mul",a.getLocal("qq"),a.getLocal("newt"),u),a.if(a.getLocal("signt"),a.if(a.getLocal("signnewt"),a.if(a.call(i+"_gte",u,a.getLocal("t")),[...a.drop(a.call(i+"_sub",u,a.getLocal("t"),a.getLocal("x"))),...a.setLocal("signx",a.i32_const(0))],[...a.drop(a.call(i+"_sub",a.getLocal("t"),u,a.getLocal("x"))),...a.setLocal("signx",a.i32_const(1))]),[...a.drop(a.call(i+"_add",u,a.getLocal("t"),a.getLocal("x"))),...a.setLocal("signx",a.i32_const(1))]),a.if(a.getLocal("signnewt"),[...a.drop(a.call(i+"_add",u,a.getLocal("t"),a.getLocal("x"))),...a.setLocal("signx",a.i32_const(0))],a.if(a.call(i+"_gte",a.getLocal("t"),u),[...a.drop(a.call(i+"_sub",a.getLocal("t"),u,a.getLocal("x"))),...a.setLocal("signx",a.i32_const(0))],[...a.drop(a.call(i+"_sub",u,a.getLocal("t"),a.getLocal("x"))),...a.setLocal("signx",a.i32_const(1))]))),a.setLocal("swp",a.getLocal("t")),a.setLocal("t",a.getLocal("newt")),a.setLocal("newt",a.getLocal("x")),a.setLocal("x",a.getLocal("swp")),a.setLocal("signt",a.getLocal("signnewt")),a.setLocal("signnewt",a.getLocal("signx")),a.setLocal("swp",a.getLocal("r")),a.setLocal("r",a.getLocal("newr")),a.setLocal("newr",a.getLocal("qr")),a.setLocal("qr",a.getLocal("swp")),a.br(0)))),e.addCode(a.if(a.getLocal("signt"),a.drop(a.call(i+"_sub",a.getLocal("pm"),a.getLocal("t"),a.getLocal("pr"))),a.call(i+"_copy",a.getLocal("t"),a.getLocal("pr"))))}(),t.exportFunction(i+"_copy"),t.exportFunction(i+"_zero"),t.exportFunction(i+"_one"),t.exportFunction(i+"_isZero"),t.exportFunction(i+"_eq"),t.exportFunction(i+"_gte"),t.exportFunction(i+"_add"),t.exportFunction(i+"_sub"),t.exportFunction(i+"_mul"),t.exportFunction(i+"_square"),t.exportFunction(i+"_squareOld"),t.exportFunction(i+"_div"),t.exportFunction(i+"_inverseMod"),i},_t=H,ft=$,ht=Y,pt=W,mt=Z,{bitLength:Lt,modInv:wt,modPow:At,isPrime:bt,isOdd:yt,square:It}=J;var Ct=function(t,e,a,i){const o=BigInt(e),n=Math.floor((Lt(o-1n)-1)/64)+1,c=2*n,r=8*n,l=a||"f1m";if(t.modules[l])return l;const s=gt(t,n,i),d=t.alloc(r,_t.bigInt2BytesLE(o,r)),u=t.alloc(_t.bigInt2BytesLE(It(1n<<BigInt(64*n))%o,r)),g=t.alloc(_t.bigInt2BytesLE((1n<<BigInt(64*n))%o,r)),_=t.alloc(_t.bigInt2BytesLE(0n,r)),f=o-1n,h=f>>1n,p=t.alloc(r,_t.bigInt2BytesLE(h,r)),m=h+1n,L=t.alloc(r,_t.bigInt2BytesLE(m,r));t.modules[l]={pq:d,pR2:u,n64:n,q:o,pOne:g,pZero:_,pePlusOne:L};let w=2n;if(bt(o))for(;At(w,h,o)!==f;)w+=1n;let A=0,b=f;for(;!yt(b)&&0n!==b;)A++,b>>=1n;const y=t.alloc(r,_t.bigInt2BytesLE(b,r)),I=At(w,b,o),C=t.alloc(_t.bigInt2BytesLE((I<<BigInt(64*n))%o,r)),F=b+1n>>1n,x=t.alloc(r,_t.bigInt2BytesLE(F,r));return t.exportFunction(s+"_copy",l+"_copy"),t.exportFunction(s+"_zero",l+"_zero"),t.exportFunction(s+"_isZero",l+"_isZero"),t.exportFunction(s+"_eq",l+"_eq"),function(){const e=t.addFunction(l+"_isOne");e.addParam("x","i32"),e.setReturnType("i32");const a=e.getCodeBuilder();e.addCode(a.ret(a.call(s+"_eq",a.getLocal("x"),a.i32_const(g))))}(),function(){const e=t.addFunction(l+"_add");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.if(a.call(s+"_add",a.getLocal("x"),a.getLocal("y"),a.getLocal("r")),a.drop(a.call(s+"_sub",a.getLocal("r"),a.i32_const(d),a.getLocal("r"))),a.if(a.call(s+"_gte",a.getLocal("r"),a.i32_const(d)),a.drop(a.call(s+"_sub",a.getLocal("r"),a.i32_const(d),a.getLocal("r"))))))}(),function(){const e=t.addFunction(l+"_sub");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.if(a.call(s+"_sub",a.getLocal("x"),a.getLocal("y"),a.getLocal("r")),a.drop(a.call(s+"_add",a.getLocal("r"),a.i32_const(d),a.getLocal("r")))))}(),function(){const e=t.addFunction(l+"_neg");e.addParam("x","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.call(l+"_sub",a.i32_const(_),a.getLocal("x"),a.getLocal("r")))}(),function(){const e=t.alloc(c*c*8),a=t.addFunction(l+"_mReduct");a.addParam("t","i32"),a.addParam("r","i32"),a.addLocal("np32","i64"),a.addLocal("c","i64"),a.addLocal("m","i64");const i=a.getCodeBuilder(),n=Number(0x100000000n-wt(o,0x100000000n));a.addCode(i.setLocal("np32",i.i64_const(n)));for(let t=0;t<c;t++){a.addCode(i.setLocal("c",i.i64_const(0))),a.addCode(i.setLocal("m",i.i64_and(i.i64_mul(i.i64_load32_u(i.getLocal("t"),4*t),i.getLocal("np32")),i.i64_const("0xFFFFFFFF"))));for(let e=0;e<c;e++)a.addCode(i.setLocal("c",i.i64_add(i.i64_add(i.i64_load32_u(i.getLocal("t"),4*(t+e)),i.i64_shr_u(i.getLocal("c"),i.i64_const(32))),i.i64_mul(i.i64_load32_u(i.i32_const(d),4*e),i.getLocal("m"))))),a.addCode(i.i64_store32(i.getLocal("t"),4*(t+e),i.getLocal("c")));a.addCode(i.i64_store32(i.i32_const(e),4*t,i.i64_shr_u(i.getLocal("c"),i.i64_const(32))))}a.addCode(i.call(l+"_add",i.i32_const(e),i.i32_add(i.getLocal("t"),i.i32_const(4*c)),i.getLocal("r")))}(),function(){const e=t.addFunction(l+"_mul");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32"),e.addLocal("c0","i64"),e.addLocal("c1","i64"),e.addLocal("np32","i64");for(let t=0;t<c;t++)e.addLocal("x"+t,"i64"),e.addLocal("y"+t,"i64"),e.addLocal("m"+t,"i64"),e.addLocal("q"+t,"i64");const a=e.getCodeBuilder(),i=Number(0x100000000n-wt(o,0x100000000n));e.addCode(a.setLocal("np32",a.i64_const(i)));const n=[],r=[],u=[];function g(t,e){let i,o;return n[t]?i=a.getLocal("x"+t):(i=a.teeLocal("x"+t,a.i64_load32_u(a.getLocal("x"),4*t)),n[t]=!0),r[e]?o=a.getLocal("y"+e):(o=a.teeLocal("y"+e,a.i64_load32_u(a.getLocal("y"),4*e)),r[e]=!0),a.i64_mul(i,o)}function _(t,e){let i,o;return u[t]?i=a.getLocal("q"+t):(i=a.teeLocal("q"+t,a.i64_load32_u(a.i32_const(0),d+4*t)),u[t]=!0),o=a.getLocal("m"+e),a.i64_mul(i,o)}let f="c0",h="c1";for(let t=0;t<2*c-1;t++){for(let i=Math.max(0,t-c+1);i<=t&&i<c;i++){const o=t-i;e.addCode(a.setLocal(f,a.i64_add(a.i64_and(a.getLocal(f),a.i64_const(4294967295)),g(i,o)))),e.addCode(a.setLocal(h,a.i64_add(a.getLocal(h),a.i64_shr_u(a.getLocal(f),a.i64_const(32)))))}for(let i=Math.max(1,t-c+1);i<=t&&i<c;i++){const o=t-i;e.addCode(a.setLocal(f,a.i64_add(a.i64_and(a.getLocal(f),a.i64_const(4294967295)),_(i,o)))),e.addCode(a.setLocal(h,a.i64_add(a.getLocal(h),a.i64_shr_u(a.getLocal(f),a.i64_const(32)))))}t<c&&(e.addCode(a.setLocal("m"+t,a.i64_and(a.i64_mul(a.i64_and(a.getLocal(f),a.i64_const(4294967295)),a.getLocal("np32")),a.i64_const("0xFFFFFFFF")))),e.addCode(a.setLocal(f,a.i64_add(a.i64_and(a.getLocal(f),a.i64_const(4294967295)),_(0,t)))),e.addCode(a.setLocal(h,a.i64_add(a.getLocal(h),a.i64_shr_u(a.getLocal(f),a.i64_const(32)))))),t>=c&&e.addCode(a.i64_store32(a.getLocal("r"),4*(t-c),a.getLocal(f))),[f,h]=[h,f],e.addCode(a.setLocal(h,a.i64_shr_u(a.getLocal(f),a.i64_const(32))))}e.addCode(a.i64_store32(a.getLocal("r"),4*c-4,a.getLocal(f))),e.addCode(a.if(a.i32_wrap_i64(a.getLocal(h)),a.drop(a.call(s+"_sub",a.getLocal("r"),a.i32_const(d),a.getLocal("r"))),a.if(a.call(s+"_gte",a.getLocal("r"),a.i32_const(d)),a.drop(a.call(s+"_sub",a.getLocal("r"),a.i32_const(d),a.getLocal("r"))))))}(),function(){const e=t.addFunction(l+"_square");e.addParam("x","i32"),e.addParam("r","i32"),e.addLocal("c0","i64"),e.addLocal("c1","i64"),e.addLocal("c0_old","i64"),e.addLocal("c1_old","i64"),e.addLocal("np32","i64");for(let t=0;t<c;t++)e.addLocal("x"+t,"i64"),e.addLocal("m"+t,"i64"),e.addLocal("q"+t,"i64");const a=e.getCodeBuilder(),i=Number(0x100000000n-wt(o,0x100000000n));e.addCode(a.setLocal("np32",a.i64_const(i)));const n=[],r=[];function u(t,e){let i,o;return n[t]?i=a.getLocal("x"+t):(i=a.teeLocal("x"+t,a.i64_load32_u(a.getLocal("x"),4*t)),n[t]=!0),n[e]?o=a.getLocal("x"+e):(o=a.teeLocal("x"+e,a.i64_load32_u(a.getLocal("x"),4*e)),n[e]=!0),a.i64_mul(i,o)}function g(t,e){let i,o;return r[t]?i=a.getLocal("q"+t):(i=a.teeLocal("q"+t,a.i64_load32_u(a.i32_const(0),d+4*t)),r[t]=!0),o=a.getLocal("m"+e),a.i64_mul(i,o)}let _="c0",f="c1",h="c0_old",p="c1_old";for(let t=0;t<2*c-1;t++){e.addCode(a.setLocal(_,a.i64_const(0)),a.setLocal(f,a.i64_const(0)));for(let i=Math.max(0,t-c+1);i<t+1>>1&&i<c;i++){const o=t-i;e.addCode(a.setLocal(_,a.i64_add(a.i64_and(a.getLocal(_),a.i64_const(4294967295)),u(i,o)))),e.addCode(a.setLocal(f,a.i64_add(a.getLocal(f),a.i64_shr_u(a.getLocal(_),a.i64_const(32)))))}e.addCode(a.setLocal(_,a.i64_shl(a.i64_and(a.getLocal(_),a.i64_const(4294967295)),a.i64_const(1)))),e.addCode(a.setLocal(f,a.i64_add(a.i64_shl(a.getLocal(f),a.i64_const(1)),a.i64_shr_u(a.getLocal(_),a.i64_const(32))))),t%2==0&&(e.addCode(a.setLocal(_,a.i64_add(a.i64_and(a.getLocal(_),a.i64_const(4294967295)),u(t>>1,t>>1)))),e.addCode(a.setLocal(f,a.i64_add(a.getLocal(f),a.i64_shr_u(a.getLocal(_),a.i64_const(32)))))),t>0&&(e.addCode(a.setLocal(_,a.i64_add(a.i64_and(a.getLocal(_),a.i64_const(4294967295)),a.i64_and(a.getLocal(h),a.i64_const(4294967295))))),e.addCode(a.setLocal(f,a.i64_add(a.i64_add(a.getLocal(f),a.i64_shr_u(a.getLocal(_),a.i64_const(32))),a.getLocal(p)))));for(let i=Math.max(1,t-c+1);i<=t&&i<c;i++){const o=t-i;e.addCode(a.setLocal(_,a.i64_add(a.i64_and(a.getLocal(_),a.i64_const(4294967295)),g(i,o)))),e.addCode(a.setLocal(f,a.i64_add(a.getLocal(f),a.i64_shr_u(a.getLocal(_),a.i64_const(32)))))}t<c&&(e.addCode(a.setLocal("m"+t,a.i64_and(a.i64_mul(a.i64_and(a.getLocal(_),a.i64_const(4294967295)),a.getLocal("np32")),a.i64_const("0xFFFFFFFF")))),e.addCode(a.setLocal(_,a.i64_add(a.i64_and(a.getLocal(_),a.i64_const(4294967295)),g(0,t)))),e.addCode(a.setLocal(f,a.i64_add(a.getLocal(f),a.i64_shr_u(a.getLocal(_),a.i64_const(32)))))),t>=c&&e.addCode(a.i64_store32(a.getLocal("r"),4*(t-c),a.getLocal(_))),e.addCode(a.setLocal(h,a.getLocal(f)),a.setLocal(p,a.i64_shr_u(a.getLocal(h),a.i64_const(32))))}e.addCode(a.i64_store32(a.getLocal("r"),4*c-4,a.getLocal(h))),e.addCode(a.if(a.i32_wrap_i64(a.getLocal(p)),a.drop(a.call(s+"_sub",a.getLocal("r"),a.i32_const(d),a.getLocal("r"))),a.if(a.call(s+"_gte",a.getLocal("r"),a.i32_const(d)),a.drop(a.call(s+"_sub",a.getLocal("r"),a.i32_const(d),a.getLocal("r"))))))}(),function(){const e=t.addFunction(l+"_squareOld");e.addParam("x","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.call(l+"_mul",a.getLocal("x"),a.getLocal("x"),a.getLocal("r")))}(),function(){const e=t.addFunction(l+"_toMontgomery");e.addParam("x","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.call(l+"_mul",a.getLocal("x"),a.i32_const(u),a.getLocal("r")))}(),function(){const e=t.alloc(2*r),a=t.addFunction(l+"_fromMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const i=a.getCodeBuilder();a.addCode(i.call(s+"_copy",i.getLocal("x"),i.i32_const(e))),a.addCode(i.call(s+"_zero",i.i32_const(e+r))),a.addCode(i.call(l+"_mReduct",i.i32_const(e),i.getLocal("r")))}(),function(){const e=t.addFunction(l+"_isNegative");e.addParam("x","i32"),e.setReturnType("i32");const a=e.getCodeBuilder(),i=a.i32_const(t.alloc(r));e.addCode(a.call(l+"_fromMontgomery",a.getLocal("x"),i),a.call(s+"_gte",i,a.i32_const(L)))}(),function(){const e=t.addFunction(l+"_sign");e.addParam("x","i32"),e.setReturnType("i32");const a=e.getCodeBuilder(),i=a.i32_const(t.alloc(r));e.addCode(a.if(a.call(s+"_isZero",a.getLocal("x")),a.ret(a.i32_const(0))),a.call(l+"_fromMontgomery",a.getLocal("x"),i),a.if(a.call(s+"_gte",i,a.i32_const(L)),a.ret(a.i32_const(-1))),a.ret(a.i32_const(1)))}(),function(){const e=t.addFunction(l+"_inverse");e.addParam("x","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.call(l+"_fromMontgomery",a.getLocal("x"),a.getLocal("r"))),e.addCode(a.call(s+"_inverseMod",a.getLocal("r"),a.i32_const(d),a.getLocal("r"))),e.addCode(a.call(l+"_toMontgomery",a.getLocal("r"),a.getLocal("r")))}(),function(){const e=t.addFunction(l+"_one");e.addParam("pr","i32");const a=e.getCodeBuilder();e.addCode(a.call(s+"_copy",a.i32_const(g),a.getLocal("pr")))}(),function(){const e=t.addFunction(l+"_load");e.addParam("scalar","i32"),e.addParam("scalarLen","i32"),e.addParam("r","i32"),e.addLocal("p","i32"),e.addLocal("l","i32"),e.addLocal("i","i32"),e.addLocal("j","i32");const a=e.getCodeBuilder(),i=a.i32_const(t.alloc(r)),o=t.alloc(r),n=a.i32_const(o);e.addCode(a.call(s+"_zero",a.getLocal("r")),a.setLocal("i",a.i32_const(r)),a.setLocal("p",a.getLocal("scalar")),a.block(a.loop(a.br_if(1,a.i32_gt_u(a.getLocal("i"),a.getLocal("scalarLen"))),a.if(a.i32_eq(a.getLocal("i"),a.i32_const(r)),a.call(l+"_one",i),a.call(l+"_mul",i,a.i32_const(u),i)),a.call(l+"_mul",a.getLocal("p"),i,n),a.call(l+"_add",a.getLocal("r"),n,a.getLocal("r")),a.setLocal("p",a.i32_add(a.getLocal("p"),a.i32_const(r))),a.setLocal("i",a.i32_add(a.getLocal("i"),a.i32_const(r))),a.br(0))),a.setLocal("l",a.i32_rem_u(a.getLocal("scalarLen"),a.i32_const(r))),a.if(a.i32_eqz(a.getLocal("l")),a.ret([])),a.call(s+"_zero",n),a.setLocal("j",a.i32_const(0)),a.block(a.loop(a.br_if(1,a.i32_eq(a.getLocal("j"),a.getLocal("l"))),a.i32_store8(a.getLocal("j"),o,a.i32_load8_u(a.getLocal("p"))),a.setLocal("p",a.i32_add(a.getLocal("p"),a.i32_const(1))),a.setLocal("j",a.i32_add(a.getLocal("j"),a.i32_const(1))),a.br(0))),a.if(a.i32_eq(a.getLocal("i"),a.i32_const(r)),a.call(l+"_one",i),a.call(l+"_mul",i,a.i32_const(u),i)),a.call(l+"_mul",n,i,n),a.call(l+"_add",a.getLocal("r"),n,a.getLocal("r")))}(),function(){const e=t.addFunction(l+"_timesScalar");e.addParam("x","i32"),e.addParam("scalar","i32"),e.addParam("scalarLen","i32"),e.addParam("r","i32");const a=e.getCodeBuilder(),i=a.i32_const(t.alloc(r));e.addCode(a.call(l+"_load",a.getLocal("scalar"),a.getLocal("scalarLen"),i),a.call(l+"_toMontgomery",i,i),a.call(l+"_mul",a.getLocal("x"),i,a.getLocal("r")))}(),ht(t,l),pt(t,l+"_batchToMontgomery",l+"_toMontgomery",r,r),pt(t,l+"_batchFromMontgomery",l+"_fromMontgomery",r,r),pt(t,l+"_batchNeg",l+"_neg",r,r),mt(t,l+"_batchAdd",l+"_add",r,r),mt(t,l+"_batchSub",l+"_sub",r,r),mt(t,l+"_batchMul",l+"_mul",r,r),t.exportFunction(l+"_add"),t.exportFunction(l+"_sub"),t.exportFunction(l+"_neg"),t.exportFunction(l+"_isNegative"),t.exportFunction(l+"_isOne"),t.exportFunction(l+"_sign"),t.exportFunction(l+"_mReduct"),t.exportFunction(l+"_mul"),t.exportFunction(l+"_square"),t.exportFunction(l+"_squareOld"),t.exportFunction(l+"_fromMontgomery"),t.exportFunction(l+"_toMontgomery"),t.exportFunction(l+"_inverse"),t.exportFunction(l+"_one"),t.exportFunction(l+"_load"),t.exportFunction(l+"_timesScalar"),ft(t,l+"_exp",r,l+"_mul",l+"_square",s+"_copy",l+"_one"),t.exportFunction(l+"_exp"),t.exportFunction(l+"_batchInverse"),bt(o)&&(!function(){const e=t.addFunction(l+"_sqrt");e.addParam("n","i32"),e.addParam("r","i32"),e.addLocal("m","i32"),e.addLocal("i","i32"),e.addLocal("j","i32");const a=e.getCodeBuilder(),i=a.i32_const(g),o=a.i32_const(t.alloc(r)),n=a.i32_const(t.alloc(r)),c=a.i32_const(t.alloc(r)),s=a.i32_const(t.alloc(r)),d=a.i32_const(t.alloc(r));e.addCode(a.if(a.call(l+"_isZero",a.getLocal("n")),a.ret(a.call(l+"_zero",a.getLocal("r")))),a.setLocal("m",a.i32_const(A)),a.call(l+"_copy",a.i32_const(C),o),a.call(l+"_exp",a.getLocal("n"),a.i32_const(y),a.i32_const(r),n),a.call(l+"_exp",a.getLocal("n"),a.i32_const(x),a.i32_const(r),c),a.block(a.loop(a.br_if(1,a.call(l+"_eq",n,i)),a.call(l+"_square",n,s),a.setLocal("i",a.i32_const(1)),a.block(a.loop(a.br_if(1,a.call(l+"_eq",s,i)),a.call(l+"_square",s,s),a.setLocal("i",a.i32_add(a.getLocal("i"),a.i32_const(1))),a.br(0))),a.call(l+"_copy",o,d),a.setLocal("j",a.i32_sub(a.i32_sub(a.getLocal("m"),a.getLocal("i")),a.i32_const(1))),a.block(a.loop(a.br_if(1,a.i32_eqz(a.getLocal("j"))),a.call(l+"_square",d,d),a.setLocal("j",a.i32_sub(a.getLocal("j"),a.i32_const(1))),a.br(0))),a.setLocal("m",a.getLocal("i")),a.call(l+"_square",d,o),a.call(l+"_mul",n,o,n),a.call(l+"_mul",c,d,c),a.br(0))),a.if(a.call(l+"_isNegative",c),a.call(l+"_neg",c,a.getLocal("r")),a.call(l+"_copy",c,a.getLocal("r"))))}(),function(){const e=t.addFunction(l+"_isSquare");e.addParam("n","i32"),e.setReturnType("i32");const a=e.getCodeBuilder(),i=a.i32_const(g),o=a.i32_const(t.alloc(r));e.addCode(a.if(a.call(l+"_isZero",a.getLocal("n")),a.ret(a.i32_const(1))),a.call(l+"_exp",a.getLocal("n"),a.i32_const(p),a.i32_const(r),o),a.call(l+"_eq",o,i))}(),t.exportFunction(l+"_sqrt"),t.exportFunction(l+"_isSquare")),t.exportFunction(l+"_batchToMontgomery"),t.exportFunction(l+"_batchFromMontgomery"),l};const Ft=Ct,{bitLength:xt}=J;var Et=function(t,e,a,i,o){const n=BigInt(e),c=Math.floor((xt(n-1n)-1)/64)+1,r=8*c,l=a||"f1";if(t.modules[l])return l;t.modules[l]={n64:c};const s=o||"int",d=Ft(t,n,i,s),u=t.modules[d].pR2,g=t.modules[d].pq,_=t.modules[d].pePlusOne;return function(){const e=t.alloc(r),a=t.addFunction(l+"_mul");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const i=a.getCodeBuilder();a.addCode(i.call(d+"_mul",i.getLocal("x"),i.getLocal("y"),i.i32_const(e))),a.addCode(i.call(d+"_mul",i.i32_const(e),i.i32_const(u),i.getLocal("r")))}(),function(){const e=t.addFunction(l+"_square");e.addParam("x","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.call(l+"_mul",a.getLocal("x"),a.getLocal("x"),a.getLocal("r")))}(),function(){const e=t.addFunction(l+"_inverse");e.addParam("x","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.call(s+"_inverseMod",a.getLocal("x"),a.i32_const(g),a.getLocal("r")))}(),function(){const e=t.addFunction(l+"_isNegative");e.addParam("x","i32"),e.setReturnType("i32");const a=e.getCodeBuilder();e.addCode(a.call(s+"_gte",a.getLocal("x"),a.i32_const(_)))}(),t.exportFunction(d+"_add",l+"_add"),t.exportFunction(d+"_sub",l+"_sub"),t.exportFunction(d+"_neg",l+"_neg"),t.exportFunction(l+"_mul"),t.exportFunction(l+"_square"),t.exportFunction(l+"_inverse"),t.exportFunction(l+"_isNegative"),t.exportFunction(d+"_copy",l+"_copy"),t.exportFunction(d+"_zero",l+"_zero"),t.exportFunction(d+"_one",l+"_one"),t.exportFunction(d+"_isZero",l+"_isZero"),t.exportFunction(d+"_eq",l+"_eq"),l};const Bt=$,vt=Y,St=H;var Gt=function(t,e,a,i){if(t.modules[a])return a;const o=8*t.modules[i].n64,n=t.modules[i].q;return t.modules[a]={n64:2*t.modules[i].n64},function(){const e=t.addFunction(a+"_isZero");e.addParam("x","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),c=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o));e.addCode(n.i32_and(n.call(i+"_isZero",c),n.call(i+"_isZero",r)))}(),function(){const e=t.addFunction(a+"_isOne");e.addParam("x","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),c=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o));e.addCode(n.ret(n.i32_and(n.call(i+"_isOne",c),n.call(i+"_isZero",r))))}(),function(){const e=t.addFunction(a+"_zero");e.addParam("x","i32");const n=e.getCodeBuilder(),c=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o));e.addCode(n.call(i+"_zero",c),n.call(i+"_zero",r))}(),function(){const e=t.addFunction(a+"_one");e.addParam("x","i32");const n=e.getCodeBuilder(),c=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o));e.addCode(n.call(i+"_one",c),n.call(i+"_zero",r))}(),function(){const e=t.addFunction(a+"_copy");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),c=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.getLocal("r"),s=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_copy",c,l),n.call(i+"_copy",r,s))}(),function(){const n=t.addFunction(a+"_mul");n.addParam("x","i32"),n.addParam("y","i32"),n.addParam("r","i32");const c=n.getCodeBuilder(),r=c.getLocal("x"),l=c.i32_add(c.getLocal("x"),c.i32_const(o)),s=c.getLocal("y"),d=c.i32_add(c.getLocal("y"),c.i32_const(o)),u=c.getLocal("r"),g=c.i32_add(c.getLocal("r"),c.i32_const(o)),_=c.i32_const(t.alloc(o)),f=c.i32_const(t.alloc(o)),h=c.i32_const(t.alloc(o)),p=c.i32_const(t.alloc(o));n.addCode(c.call(i+"_mul",r,s,_),c.call(i+"_mul",l,d,f),c.call(i+"_add",r,l,h),c.call(i+"_add",s,d,p),c.call(i+"_mul",h,p,h),c.call(e,f,u),c.call(i+"_add",_,u,u),c.call(i+"_add",_,f,g),c.call(i+"_sub",h,g,g))}(),function(){const e=t.addFunction(a+"_mul1");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),c=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.getLocal("y"),s=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_mul",c,l,s),n.call(i+"_mul",r,l,d))}(),function(){const n=t.addFunction(a+"_square");n.addParam("x","i32"),n.addParam("r","i32");const c=n.getCodeBuilder(),r=c.getLocal("x"),l=c.i32_add(c.getLocal("x"),c.i32_const(o)),s=c.getLocal("r"),d=c.i32_add(c.getLocal("r"),c.i32_const(o)),u=c.i32_const(t.alloc(o)),g=c.i32_const(t.alloc(o)),_=c.i32_const(t.alloc(o)),f=c.i32_const(t.alloc(o));n.addCode(c.call(i+"_mul",r,l,u),c.call(i+"_add",r,l,g),c.call(e,l,_),c.call(i+"_add",r,_,_),c.call(e,u,f),c.call(i+"_add",f,u,f),c.call(i+"_mul",g,_,s),c.call(i+"_sub",s,f,s),c.call(i+"_add",u,u,d))}(),function(){const e=t.addFunction(a+"_add");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),c=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.getLocal("y"),s=n.i32_add(n.getLocal("y"),n.i32_const(o)),d=n.getLocal("r"),u=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_add",c,l,d),n.call(i+"_add",r,s,u))}(),function(){const e=t.addFunction(a+"_sub");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),c=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.getLocal("y"),s=n.i32_add(n.getLocal("y"),n.i32_const(o)),d=n.getLocal("r"),u=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_sub",c,l,d),n.call(i+"_sub",r,s,u))}(),function(){const e=t.addFunction(a+"_neg");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),c=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.getLocal("r"),s=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_neg",c,l),n.call(i+"_neg",r,s))}(),function(){const e=t.addFunction(a+"_conjugate");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),c=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.getLocal("r"),s=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_copy",c,l),n.call(i+"_neg",r,s))}(),function(){const e=t.addFunction(a+"_toMontgomery");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),c=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.getLocal("r"),s=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_toMontgomery",c,l),n.call(i+"_toMontgomery",r,s))}(),function(){const e=t.addFunction(a+"_fromMontgomery");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),c=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.getLocal("r"),s=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_fromMontgomery",c,l),n.call(i+"_fromMontgomery",r,s))}(),function(){const e=t.addFunction(a+"_eq");e.addParam("x","i32"),e.addParam("y","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),c=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.getLocal("y"),s=n.i32_add(n.getLocal("y"),n.i32_const(o));e.addCode(n.i32_and(n.call(i+"_eq",c,l),n.call(i+"_eq",r,s)))}(),function(){const n=t.addFunction(a+"_inverse");n.addParam("x","i32"),n.addParam("r","i32");const c=n.getCodeBuilder(),r=c.getLocal("x"),l=c.i32_add(c.getLocal("x"),c.i32_const(o)),s=c.getLocal("r"),d=c.i32_add(c.getLocal("r"),c.i32_const(o)),u=c.i32_const(t.alloc(o)),g=c.i32_const(t.alloc(o)),_=c.i32_const(t.alloc(o)),f=c.i32_const(t.alloc(o));n.addCode(c.call(i+"_square",r,u),c.call(i+"_square",l,g),c.call(e,g,_),c.call(i+"_sub",u,_,_),c.call(i+"_inverse",_,f),c.call(i+"_mul",r,f,s),c.call(i+"_mul",l,f,d),c.call(i+"_neg",d,d))}(),function(){const e=t.addFunction(a+"_timesScalar");e.addParam("x","i32"),e.addParam("scalar","i32"),e.addParam("scalarLen","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),c=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.getLocal("r"),s=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_timesScalar",c,n.getLocal("scalar"),n.getLocal("scalarLen"),l),n.call(i+"_timesScalar",r,n.getLocal("scalar"),n.getLocal("scalarLen"),s))}(),function(){const e=t.addFunction(a+"_sign");e.addParam("x","i32"),e.addLocal("s","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),c=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o));e.addCode(n.setLocal("s",n.call(i+"_sign",r)),n.if(n.getLocal("s"),n.ret(n.getLocal("s"))),n.ret(n.call(i+"_sign",c)))}(),function(){const e=t.addFunction(a+"_isNegative");e.addParam("x","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),c=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o));e.addCode(n.if(n.call(i+"_isZero",r),n.ret(n.call(i+"_isNegative",c))),n.ret(n.call(i+"_isNegative",r)))}(),t.exportFunction(a+"_isZero"),t.exportFunction(a+"_isOne"),t.exportFunction(a+"_zero"),t.exportFunction(a+"_one"),t.exportFunction(a+"_copy"),t.exportFunction(a+"_mul"),t.exportFunction(a+"_mul1"),t.exportFunction(a+"_square"),t.exportFunction(a+"_add"),t.exportFunction(a+"_sub"),t.exportFunction(a+"_neg"),t.exportFunction(a+"_sign"),t.exportFunction(a+"_conjugate"),t.exportFunction(a+"_fromMontgomery"),t.exportFunction(a+"_toMontgomery"),t.exportFunction(a+"_eq"),t.exportFunction(a+"_inverse"),vt(t,a),Bt(t,a+"_exp",2*o,a+"_mul",a+"_square",a+"_copy",a+"_one"),function(){const e=t.addFunction(a+"_sqrt");e.addParam("a","i32"),e.addParam("pr","i32");const c=e.getCodeBuilder(),r=c.i32_const(t.alloc(St.bigInt2BytesLE((BigInt(n||0)-3n)/4n,o))),l=c.i32_const(t.alloc(St.bigInt2BytesLE((BigInt(n||0)-1n)/2n,o))),s=c.getLocal("a"),d=c.i32_const(t.alloc(2*o)),u=c.i32_const(t.alloc(2*o)),g=c.i32_const(t.alloc(2*o)),_=t.alloc(2*o),f=c.i32_const(_),h=c.i32_const(_),p=c.i32_const(_+o),m=c.i32_const(t.alloc(2*o)),L=c.i32_const(t.alloc(2*o));e.addCode(c.call(a+"_one",f),c.call(a+"_neg",f,f),c.call(a+"_exp",s,r,c.i32_const(o),d),c.call(a+"_square",d,u),c.call(a+"_mul",s,u,u),c.call(a+"_conjugate",u,g),c.call(a+"_mul",g,u,g),c.if(c.call(a+"_eq",g,f),c.unreachable()),c.call(a+"_mul",d,s,m),c.if(c.call(a+"_eq",u,f),[...c.call(i+"_zero",h),...c.call(i+"_one",p),...c.call(a+"_mul",f,m,c.getLocal("pr"))],[...c.call(a+"_one",L),...c.call(a+"_add",L,u,L),...c.call(a+"_exp",L,l,c.i32_const(o),L),...c.call(a+"_mul",L,m,c.getLocal("pr"))]))}(),function(){const e=t.addFunction(a+"_isSquare");e.addParam("a","i32"),e.setReturnType("i32");const i=e.getCodeBuilder(),c=i.i32_const(t.alloc(St.bigInt2BytesLE((BigInt(n||0)-3n)/4n,o))),r=i.getLocal("a"),l=i.i32_const(t.alloc(2*o)),s=i.i32_const(t.alloc(2*o)),d=i.i32_const(t.alloc(2*o)),u=t.alloc(2*o),g=i.i32_const(u);e.addCode(i.call(a+"_one",g),i.call(a+"_neg",g,g),i.call(a+"_exp",r,c,i.i32_const(o),l),i.call(a+"_square",l,s),i.call(a+"_mul",r,s,s),i.call(a+"_conjugate",s,d),i.call(a+"_mul",d,s,d),i.if(i.call(a+"_eq",d,g),i.ret(i.i32_const(0))),i.ret(i.i32_const(1)))}(),t.exportFunction(a+"_exp"),t.exportFunction(a+"_timesScalar"),t.exportFunction(a+"_batchInverse"),t.exportFunction(a+"_sqrt"),t.exportFunction(a+"_isSquare"),t.exportFunction(a+"_isNegative"),a};const Pt=$,Ut=Y;var Ot=function(t,e,a,i){if(t.modules[a])return a;const o=8*t.modules[i].n64;return t.modules[a]={n64:3*t.modules[i].n64},function(){const e=t.addFunction(a+"_isZero");e.addParam("x","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),c=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o));e.addCode(n.i32_and(n.i32_and(n.call(i+"_isZero",c),n.call(i+"_isZero",r)),n.call(i+"_isZero",l)))}(),function(){const e=t.addFunction(a+"_isOne");e.addParam("x","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),c=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o));e.addCode(n.ret(n.i32_and(n.i32_and(n.call(i+"_isOne",c),n.call(i+"_isZero",r)),n.call(i+"_isZero",l))))}(),function(){const e=t.addFunction(a+"_zero");e.addParam("x","i32");const n=e.getCodeBuilder(),c=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o));e.addCode(n.call(i+"_zero",c),n.call(i+"_zero",r),n.call(i+"_zero",l))}(),function(){const e=t.addFunction(a+"_one");e.addParam("x","i32");const n=e.getCodeBuilder(),c=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o));e.addCode(n.call(i+"_one",c),n.call(i+"_zero",r),n.call(i+"_zero",l))}(),function(){const e=t.addFunction(a+"_copy");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),c=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),s=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(o)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*o));e.addCode(n.call(i+"_copy",c,s),n.call(i+"_copy",r,d),n.call(i+"_copy",l,u))}(),function(){const n=t.addFunction(a+"_mul");n.addParam("x","i32"),n.addParam("y","i32"),n.addParam("r","i32");const c=n.getCodeBuilder(),r=c.getLocal("x"),l=c.i32_add(c.getLocal("x"),c.i32_const(o)),s=c.i32_add(c.getLocal("x"),c.i32_const(2*o)),d=c.getLocal("y"),u=c.i32_add(c.getLocal("y"),c.i32_const(o)),g=c.i32_add(c.getLocal("y"),c.i32_const(2*o)),_=c.getLocal("r"),f=c.i32_add(c.getLocal("r"),c.i32_const(o)),h=c.i32_add(c.getLocal("r"),c.i32_const(2*o)),p=c.i32_const(t.alloc(o)),m=c.i32_const(t.alloc(o)),L=c.i32_const(t.alloc(o)),w=c.i32_const(t.alloc(o)),A=c.i32_const(t.alloc(o)),b=c.i32_const(t.alloc(o)),y=c.i32_const(t.alloc(o)),I=c.i32_const(t.alloc(o)),C=c.i32_const(t.alloc(o)),F=c.i32_const(t.alloc(o)),x=c.i32_const(t.alloc(o)),E=c.i32_const(t.alloc(o)),B=c.i32_const(t.alloc(o));n.addCode(c.call(i+"_mul",r,d,p),c.call(i+"_mul",l,u,m),c.call(i+"_mul",s,g,L),c.call(i+"_add",r,l,w),c.call(i+"_add",d,u,A),c.call(i+"_add",r,s,b),c.call(i+"_add",d,g,y),c.call(i+"_add",l,s,I),c.call(i+"_add",u,g,C),c.call(i+"_add",p,m,F),c.call(i+"_add",p,L,x),c.call(i+"_add",m,L,E),c.call(i+"_mul",I,C,_),c.call(i+"_sub",_,E,_),c.call(e,_,_),c.call(i+"_add",p,_,_),c.call(i+"_mul",w,A,f),c.call(i+"_sub",f,F,f),c.call(e,L,B),c.call(i+"_add",f,B,f),c.call(i+"_mul",b,y,h),c.call(i+"_sub",h,x,h),c.call(i+"_add",h,m,h))}(),function(){const n=t.addFunction(a+"_square");n.addParam("x","i32"),n.addParam("r","i32");const c=n.getCodeBuilder(),r=c.getLocal("x"),l=c.i32_add(c.getLocal("x"),c.i32_const(o)),s=c.i32_add(c.getLocal("x"),c.i32_const(2*o)),d=c.getLocal("r"),u=c.i32_add(c.getLocal("r"),c.i32_const(o)),g=c.i32_add(c.getLocal("r"),c.i32_const(2*o)),_=c.i32_const(t.alloc(o)),f=c.i32_const(t.alloc(o)),h=c.i32_const(t.alloc(o)),p=c.i32_const(t.alloc(o)),m=c.i32_const(t.alloc(o)),L=c.i32_const(t.alloc(o)),w=c.i32_const(t.alloc(o));n.addCode(c.call(i+"_square",r,_),c.call(i+"_mul",r,l,f),c.call(i+"_add",f,f,h),c.call(i+"_sub",r,l,p),c.call(i+"_add",p,s,p),c.call(i+"_square",p,p),c.call(i+"_mul",l,s,m),c.call(i+"_add",m,m,L),c.call(i+"_square",s,w),c.call(e,L,d),c.call(i+"_add",_,d,d),c.call(e,w,u),c.call(i+"_add",h,u,u),c.call(i+"_add",_,w,g),c.call(i+"_sub",L,g,g),c.call(i+"_add",p,g,g),c.call(i+"_add",h,g,g))}(),function(){const e=t.addFunction(a+"_add");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),c=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),s=n.getLocal("y"),d=n.i32_add(n.getLocal("y"),n.i32_const(o)),u=n.i32_add(n.getLocal("y"),n.i32_const(2*o)),g=n.getLocal("r"),_=n.i32_add(n.getLocal("r"),n.i32_const(o)),f=n.i32_add(n.getLocal("r"),n.i32_const(2*o));e.addCode(n.call(i+"_add",c,s,g),n.call(i+"_add",r,d,_),n.call(i+"_add",l,u,f))}(),function(){const e=t.addFunction(a+"_sub");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),c=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),s=n.getLocal("y"),d=n.i32_add(n.getLocal("y"),n.i32_const(o)),u=n.i32_add(n.getLocal("y"),n.i32_const(2*o)),g=n.getLocal("r"),_=n.i32_add(n.getLocal("r"),n.i32_const(o)),f=n.i32_add(n.getLocal("r"),n.i32_const(2*o));e.addCode(n.call(i+"_sub",c,s,g),n.call(i+"_sub",r,d,_),n.call(i+"_sub",l,u,f))}(),function(){const e=t.addFunction(a+"_neg");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),c=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),s=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(o)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*o));e.addCode(n.call(i+"_neg",c,s),n.call(i+"_neg",r,d),n.call(i+"_neg",l,u))}(),function(){const e=t.addFunction(a+"_sign");e.addParam("x","i32"),e.addLocal("s","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),c=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o));e.addCode(n.setLocal("s",n.call(i+"_sign",l)),n.if(n.getLocal("s"),n.ret(n.getLocal("s"))),n.setLocal("s",n.call(i+"_sign",r)),n.if(n.getLocal("s"),n.ret(n.getLocal("s"))),n.ret(n.call(i+"_sign",c)))}(),function(){const e=t.addFunction(a+"_toMontgomery");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),c=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),s=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(o)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*o));e.addCode(n.call(i+"_toMontgomery",c,s),n.call(i+"_toMontgomery",r,d),n.call(i+"_toMontgomery",l,u))}(),function(){const e=t.addFunction(a+"_fromMontgomery");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),c=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),s=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(o)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*o));e.addCode(n.call(i+"_fromMontgomery",c,s),n.call(i+"_fromMontgomery",r,d),n.call(i+"_fromMontgomery",l,u))}(),function(){const e=t.addFunction(a+"_eq");e.addParam("x","i32"),e.addParam("y","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),c=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),s=n.getLocal("y"),d=n.i32_add(n.getLocal("y"),n.i32_const(o)),u=n.i32_add(n.getLocal("y"),n.i32_const(2*o));e.addCode(n.i32_and(n.i32_and(n.call(i+"_eq",c,s),n.call(i+"_eq",r,d)),n.call(i+"_eq",l,u)))}(),function(){const n=t.addFunction(a+"_inverse");n.addParam("x","i32"),n.addParam("r","i32");const c=n.getCodeBuilder(),r=c.getLocal("x"),l=c.i32_add(c.getLocal("x"),c.i32_const(o)),s=c.i32_add(c.getLocal("x"),c.i32_const(2*o)),d=c.getLocal("r"),u=c.i32_add(c.getLocal("r"),c.i32_const(o)),g=c.i32_add(c.getLocal("r"),c.i32_const(2*o)),_=c.i32_const(t.alloc(o)),f=c.i32_const(t.alloc(o)),h=c.i32_const(t.alloc(o)),p=c.i32_const(t.alloc(o)),m=c.i32_const(t.alloc(o)),L=c.i32_const(t.alloc(o)),w=c.i32_const(t.alloc(o)),A=c.i32_const(t.alloc(o)),b=c.i32_const(t.alloc(o)),y=c.i32_const(t.alloc(o)),I=c.i32_const(t.alloc(o));n.addCode(c.call(i+"_square",r,_),c.call(i+"_square",l,f),c.call(i+"_square",s,h),c.call(i+"_mul",r,l,p),c.call(i+"_mul",r,s,m),c.call(i+"_mul",l,s,L),c.call(e,L,w),c.call(i+"_sub",_,w,w),c.call(e,h,A),c.call(i+"_sub",A,p,A),c.call(i+"_sub",f,m,b),c.call(i+"_mul",s,A,y),c.call(i+"_mul",l,b,I),c.call(i+"_add",y,I,y),c.call(e,y,y),c.call(i+"_mul",r,w,I),c.call(i+"_add",I,y,y),c.call(i+"_inverse",y,y),c.call(i+"_mul",y,w,d),c.call(i+"_mul",y,A,u),c.call(i+"_mul",y,b,g))}(),function(){const e=t.addFunction(a+"_timesScalar");e.addParam("x","i32"),e.addParam("scalar","i32"),e.addParam("scalarLen","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),c=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),s=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(o)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*o));e.addCode(n.call(i+"_timesScalar",c,n.getLocal("scalar"),n.getLocal("scalarLen"),s),n.call(i+"_timesScalar",r,n.getLocal("scalar"),n.getLocal("scalarLen"),d),n.call(i+"_timesScalar",l,n.getLocal("scalar"),n.getLocal("scalarLen"),u))}(),function(){const e=t.addFunction(a+"_isNegative");e.addParam("x","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),c=n.getLocal("x"),r=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o));e.addCode(n.if(n.call(i+"_isZero",l),n.if(n.call(i+"_isZero",r),n.ret(n.call(i+"_isNegative",c)),n.ret(n.call(i+"_isNegative",r)))),n.ret(n.call(i+"_isNegative",l)))}(),t.exportFunction(a+"_isZero"),t.exportFunction(a+"_isOne"),t.exportFunction(a+"_zero"),t.exportFunction(a+"_one"),t.exportFunction(a+"_copy"),t.exportFunction(a+"_mul"),t.exportFunction(a+"_square"),t.exportFunction(a+"_add"),t.exportFunction(a+"_sub"),t.exportFunction(a+"_neg"),t.exportFunction(a+"_sign"),t.exportFunction(a+"_fromMontgomery"),t.exportFunction(a+"_toMontgomery"),t.exportFunction(a+"_eq"),t.exportFunction(a+"_inverse"),Ut(t,a),Pt(t,a+"_exp",3*o,a+"_mul",a+"_square",a+"_copy",a+"_one"),t.exportFunction(a+"_exp"),t.exportFunction(a+"_timesScalar"),t.exportFunction(a+"_batchInverse"),t.exportFunction(a+"_isNegative"),a};const zt=function(t,e,a,i,o,n,c,r){const l=t.addFunction(e);l.addParam("base","i32"),l.addParam("scalar","i32"),l.addParam("scalarLength","i32"),l.addParam("r","i32"),l.addLocal("old0","i32"),l.addLocal("nbits","i32"),l.addLocal("i","i32"),l.addLocal("last","i32"),l.addLocal("cur","i32"),l.addLocal("carry","i32"),l.addLocal("p","i32");const s=l.getCodeBuilder(),d=s.i32_const(t.alloc(a));function u(t){return s.i32_and(s.i32_shr_u(s.i32_load(s.i32_add(s.getLocal("scalar"),s.i32_and(s.i32_shr_u(t,s.i32_const(3)),s.i32_const(4294967292)))),s.i32_and(t,s.i32_const(31))),s.i32_const(1))}function g(t){return[...s.i32_store8(s.getLocal("p"),s.i32_const(t)),...s.setLocal("p",s.i32_add(s.getLocal("p"),s.i32_const(1)))]}l.addCode(s.if(s.i32_eqz(s.getLocal("scalarLength")),[...s.call(r,s.getLocal("r")),...s.ret([])]),s.setLocal("nbits",s.i32_shl(s.getLocal("scalarLength"),s.i32_const(3))),s.setLocal("old0",s.i32_load(s.i32_const(0))),s.setLocal("p",s.getLocal("old0")),s.i32_store(s.i32_const(0),s.i32_and(s.i32_add(s.i32_add(s.getLocal("old0"),s.i32_const(32)),s.getLocal("nbits")),s.i32_const(4294967288))),s.setLocal("i",s.i32_const(1)),s.setLocal("last",u(s.i32_const(0))),s.setLocal("carry",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("nbits"))),s.setLocal("cur",u(s.getLocal("i"))),s.if(s.getLocal("last"),s.if(s.getLocal("cur"),s.if(s.getLocal("carry"),[...s.setLocal("last",s.i32_const(0)),...s.setLocal("carry",s.i32_const(1)),...g(1)],[...s.setLocal("last",s.i32_const(0)),...s.setLocal("carry",s.i32_const(1)),...g(255)]),s.if(s.getLocal("carry"),[...s.setLocal("last",s.i32_const(0)),...s.setLocal("carry",s.i32_const(1)),...g(255)],[...s.setLocal("last",s.i32_const(0)),...s.setLocal("carry",s.i32_const(0)),...g(1)])),s.if(s.getLocal("cur"),s.if(s.getLocal("carry"),[...s.setLocal("last",s.i32_const(0)),...s.setLocal("carry",s.i32_const(1)),...g(0)],[...s.setLocal("last",s.i32_const(1)),...s.setLocal("carry",s.i32_const(0)),...g(0)]),s.if(s.getLocal("carry"),[...s.setLocal("last",s.i32_const(1)),...s.setLocal("carry",s.i32_const(0)),...g(0)],[...s.setLocal("last",s.i32_const(0)),...s.setLocal("carry",s.i32_const(0)),...g(0)]))),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))),s.if(s.getLocal("last"),s.if(s.getLocal("carry"),[...g(255),...g(0),...g(1)],[...g(1)]),s.if(s.getLocal("carry"),[...g(0),...g(1)])),s.setLocal("p",s.i32_sub(s.getLocal("p"),s.i32_const(1))),s.call(c,s.getLocal("base"),d),s.call(r,s.getLocal("r")),s.block(s.loop(s.call(o,s.getLocal("r"),s.getLocal("r")),s.setLocal("cur",s.i32_load8_u(s.getLocal("p"))),s.if(s.getLocal("cur"),s.if(s.i32_eq(s.getLocal("cur"),s.i32_const(1)),s.call(i,s.getLocal("r"),d,s.getLocal("r")),s.call(n,s.getLocal("r"),d,s.getLocal("r")))),s.br_if(1,s.i32_eq(s.getLocal("old0"),s.getLocal("p"))),s.setLocal("p",s.i32_sub(s.getLocal("p"),s.i32_const(1))),s.br(0))),s.i32_store(s.i32_const(0),s.getLocal("old0")))},Qt=W,qt=function(t,e,a,i,o){const n=8*t.modules[e].n64;function c(){const i=t.addFunction(a);i.addParam("pBases","i32"),i.addParam("pScalars","i32"),i.addParam("scalarSize","i32"),i.addParam("n","i32"),i.addParam("pr","i32"),i.addLocal("chunkSize","i32"),i.addLocal("nChunks","i32"),i.addLocal("itScalar","i32"),i.addLocal("endScalar","i32"),i.addLocal("itBase","i32"),i.addLocal("itBit","i32"),i.addLocal("i","i32"),i.addLocal("j","i32"),i.addLocal("nTable","i32"),i.addLocal("pTable","i32"),i.addLocal("idx","i32"),i.addLocal("pIdxTable","i32");const o=i.getCodeBuilder(),c=o.i32_const(t.alloc(n)),r=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]);i.addCode(o.call(e+"_zero",o.getLocal("pr")),o.if(o.i32_eqz(o.getLocal("n")),o.ret([])),o.setLocal("chunkSize",o.i32_load8_u(o.i32_clz(o.getLocal("n")),r)),o.setLocal("nChunks",o.i32_add(o.i32_div_u(o.i32_sub(o.i32_shl(o.getLocal("scalarSize"),o.i32_const(3)),o.i32_const(1)),o.getLocal("chunkSize")),o.i32_const(1))),o.setLocal("itBit",o.i32_mul(o.i32_sub(o.getLocal("nChunks"),o.i32_const(1)),o.getLocal("chunkSize"))),o.block(o.loop(o.br_if(1,o.i32_lt_s(o.getLocal("itBit"),o.i32_const(0))),o.if(o.i32_eqz(o.call(e+"_isZero",o.getLocal("pr"))),[...o.setLocal("j",o.i32_const(0)),...o.block(o.loop(o.br_if(1,o.i32_eq(o.getLocal("j"),o.getLocal("chunkSize"))),o.call(e+"_double",o.getLocal("pr"),o.getLocal("pr")),o.setLocal("j",o.i32_add(o.getLocal("j"),o.i32_const(1))),o.br(0)))]),o.call(a+"_chunk",o.getLocal("pBases"),o.getLocal("pScalars"),o.getLocal("scalarSize"),o.getLocal("n"),o.getLocal("itBit"),o.getLocal("chunkSize"),c),o.call(e+"_add",o.getLocal("pr"),c,o.getLocal("pr")),o.setLocal("itBit",o.i32_sub(o.getLocal("itBit"),o.getLocal("chunkSize"))),o.br(0))))}!function(){const e=t.addFunction(a+"_getChunk");e.addParam("pScalar","i32"),e.addParam("scalarSize","i32"),e.addParam("startBit","i32"),e.addParam("chunkSize","i32"),e.addLocal("bitsToEnd","i32"),e.addLocal("mask","i32"),e.setReturnType("i32");const i=e.getCodeBuilder();e.addCode(i.setLocal("bitsToEnd",i.i32_sub(i.i32_mul(i.getLocal("scalarSize"),i.i32_const(8)),i.getLocal("startBit"))),i.if(i.i32_gt_s(i.getLocal("chunkSize"),i.getLocal("bitsToEnd")),i.setLocal("mask",i.i32_sub(i.i32_shl(i.i32_const(1),i.getLocal("bitsToEnd")),i.i32_const(1))),i.setLocal("mask",i.i32_sub(i.i32_shl(i.i32_const(1),i.getLocal("chunkSize")),i.i32_const(1)))),i.i32_and(i.i32_shr_u(i.i32_load(i.i32_add(i.getLocal("pScalar"),i.i32_shr_u(i.getLocal("startBit"),i.i32_const(3))),0,0),i.i32_and(i.getLocal("startBit"),i.i32_const(7))),i.getLocal("mask")))}(),function(){const i=t.addFunction(a+"_reduceTable");i.addParam("pTable","i32"),i.addParam("p","i32"),i.addLocal("half","i32"),i.addLocal("it1","i32"),i.addLocal("it2","i32"),i.addLocal("pAcc","i32");const o=i.getCodeBuilder();i.addCode(o.if(o.i32_eq(o.getLocal("p"),o.i32_const(1)),o.ret([])),o.setLocal("half",o.i32_shl(o.i32_const(1),o.i32_sub(o.getLocal("p"),o.i32_const(1)))),o.setLocal("it1",o.getLocal("pTable")),o.setLocal("it2",o.i32_add(o.getLocal("pTable"),o.i32_mul(o.getLocal("half"),o.i32_const(n)))),o.setLocal("pAcc",o.i32_sub(o.getLocal("it2"),o.i32_const(n))),o.block(o.loop(o.br_if(1,o.i32_eq(o.getLocal("it1"),o.getLocal("pAcc"))),o.call(e+"_add",o.getLocal("it1"),o.getLocal("it2"),o.getLocal("it1")),o.call(e+"_add",o.getLocal("pAcc"),o.getLocal("it2"),o.getLocal("pAcc")),o.setLocal("it1",o.i32_add(o.getLocal("it1"),o.i32_const(n))),o.setLocal("it2",o.i32_add(o.getLocal("it2"),o.i32_const(n))),o.br(0))),o.call(a+"_reduceTable",o.getLocal("pTable"),o.i32_sub(o.getLocal("p"),o.i32_const(1))),o.setLocal("p",o.i32_sub(o.getLocal("p"),o.i32_const(1))),o.block(o.loop(o.br_if(1,o.i32_eqz(o.getLocal("p"))),o.call(e+"_double",o.getLocal("pAcc"),o.getLocal("pAcc")),o.setLocal("p",o.i32_sub(o.getLocal("p"),o.i32_const(1))),o.br(0))),o.call(e+"_add",o.getLocal("pTable"),o.getLocal("pAcc"),o.getLocal("pTable")))}(),function(){const c=t.addFunction(a+"_chunk");c.addParam("pBases","i32"),c.addParam("pScalars","i32"),c.addParam("scalarSize","i32"),c.addParam("n","i32"),c.addParam("startBit","i32"),c.addParam("chunkSize","i32"),c.addParam("pr","i32"),c.addLocal("nChunks","i32"),c.addLocal("itScalar","i32"),c.addLocal("endScalar","i32"),c.addLocal("itBase","i32"),c.addLocal("i","i32"),c.addLocal("j","i32"),c.addLocal("nTable","i32"),c.addLocal("pTable","i32"),c.addLocal("idx","i32"),c.addLocal("pIdxTable","i32");const r=c.getCodeBuilder();c.addCode(r.if(r.i32_eqz(r.getLocal("n")),[...r.call(e+"_zero",r.getLocal("pr")),...r.ret([])]),r.setLocal("nTable",r.i32_shl(r.i32_const(1),r.getLocal("chunkSize"))),r.setLocal("pTable",r.i32_load(r.i32_const(0))),r.i32_store(r.i32_const(0),r.i32_add(r.getLocal("pTable"),r.i32_mul(r.getLocal("nTable"),r.i32_const(n)))),r.setLocal("j",r.i32_const(0)),r.block(r.loop(r.br_if(1,r.i32_eq(r.getLocal("j"),r.getLocal("nTable"))),r.call(e+"_zero",r.i32_add(r.getLocal("pTable"),r.i32_mul(r.getLocal("j"),r.i32_const(n)))),r.setLocal("j",r.i32_add(r.getLocal("j"),r.i32_const(1))),r.br(0))),r.setLocal("itBase",r.getLocal("pBases")),r.setLocal("itScalar",r.getLocal("pScalars")),r.setLocal("endScalar",r.i32_add(r.getLocal("pScalars"),r.i32_mul(r.getLocal("n"),r.getLocal("scalarSize")))),r.block(r.loop(r.br_if(1,r.i32_eq(r.getLocal("itScalar"),r.getLocal("endScalar"))),r.setLocal("idx",r.call(a+"_getChunk",r.getLocal("itScalar"),r.getLocal("scalarSize"),r.getLocal("startBit"),r.getLocal("chunkSize"))),r.if(r.getLocal("idx"),[...r.setLocal("pIdxTable",r.i32_add(r.getLocal("pTable"),r.i32_mul(r.i32_sub(r.getLocal("idx"),r.i32_const(1)),r.i32_const(n)))),...r.call(i,r.getLocal("pIdxTable"),r.getLocal("itBase"),r.getLocal("pIdxTable"))]),r.setLocal("itScalar",r.i32_add(r.getLocal("itScalar"),r.getLocal("scalarSize"))),r.setLocal("itBase",r.i32_add(r.getLocal("itBase"),r.i32_const(o))),r.br(0))),r.call(a+"_reduceTable",r.getLocal("pTable"),r.getLocal("chunkSize")),r.call(e+"_copy",r.getLocal("pTable"),r.getLocal("pr")),r.i32_store(r.i32_const(0),r.getLocal("pTable")))}(),c(),t.exportFunction(a),t.exportFunction(a+"_chunk")};var Mt=function(t,e,a,i){const o=t.modules[a].n64,n=8*o;if(t.modules[e])return e;return t.modules[e]={n64:3*o},function(){const i=t.addFunction(e+"_isZeroAffine");i.addParam("p1","i32"),i.setReturnType("i32");const o=i.getCodeBuilder();i.addCode(o.i32_and(o.call(a+"_isZero",o.getLocal("p1")),o.call(a+"_isZero",o.i32_add(o.getLocal("p1"),o.i32_const(n)))))}(),function(){const i=t.addFunction(e+"_isZero");i.addParam("p1","i32"),i.setReturnType("i32");const o=i.getCodeBuilder();i.addCode(o.call(a+"_isZero",o.i32_add(o.getLocal("p1"),o.i32_const(2*n))))}(),function(){const i=t.addFunction(e+"_zeroAffine");i.addParam("pr","i32");const o=i.getCodeBuilder();i.addCode(o.call(a+"_zero",o.getLocal("pr"))),i.addCode(o.call(a+"_zero",o.i32_add(o.getLocal("pr"),o.i32_const(n))))}(),function(){const i=t.addFunction(e+"_zero");i.addParam("pr","i32");const o=i.getCodeBuilder();i.addCode(o.call(a+"_zero",o.getLocal("pr"))),i.addCode(o.call(a+"_one",o.i32_add(o.getLocal("pr"),o.i32_const(n)))),i.addCode(o.call(a+"_zero",o.i32_add(o.getLocal("pr"),o.i32_const(2*n))))}(),function(){const a=t.addFunction(e+"_copyAffine");a.addParam("ps","i32"),a.addParam("pd","i32");const i=a.getCodeBuilder();for(let t=0;t<2*o;t++)a.addCode(i.i64_store(i.getLocal("pd"),8*t,i.i64_load(i.getLocal("ps"),8*t)))}(),function(){const a=t.addFunction(e+"_copy");a.addParam("ps","i32"),a.addParam("pd","i32");const i=a.getCodeBuilder();for(let t=0;t<3*o;t++)a.addCode(i.i64_store(i.getLocal("pd"),8*t,i.i64_load(i.getLocal("ps"),8*t)))}(),function(){const i=t.addFunction(e+"_toJacobian");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder(),c=o.getLocal("p1"),r=o.i32_add(o.getLocal("p1"),o.i32_const(n)),l=o.getLocal("pr"),s=o.i32_add(o.getLocal("pr"),o.i32_const(n)),d=o.i32_add(o.getLocal("pr"),o.i32_const(2*n));i.addCode(o.if(o.call(e+"_isZeroAffine",o.getLocal("p1")),o.call(e+"_zero",o.getLocal("pr")),[...o.call(a+"_one",d),...o.call(a+"_copy",r,s),...o.call(a+"_copy",c,l)]))}(),function(){const i=t.addFunction(e+"_eqAffine");i.addParam("p1","i32"),i.addParam("p2","i32"),i.setReturnType("i32"),i.addLocal("z1","i32");const o=i.getCodeBuilder();i.addCode(o.ret(o.i32_and(o.call(a+"_eq",o.getLocal("p1"),o.getLocal("p2")),o.call(a+"_eq",o.i32_add(o.getLocal("p1"),o.i32_const(n)),o.i32_add(o.getLocal("p2"),o.i32_const(n))))))}(),function(){const i=t.addFunction(e+"_eqMixed");i.addParam("p1","i32"),i.addParam("p2","i32"),i.setReturnType("i32"),i.addLocal("z1","i32");const o=i.getCodeBuilder(),c=o.getLocal("p1"),r=o.i32_add(o.getLocal("p1"),o.i32_const(n));i.addCode(o.setLocal("z1",o.i32_add(o.getLocal("p1"),o.i32_const(2*n))));const l=o.getLocal("z1"),s=o.getLocal("p2"),d=o.i32_add(o.getLocal("p2"),o.i32_const(n)),u=o.i32_const(t.alloc(n)),g=o.i32_const(t.alloc(n)),_=o.i32_const(t.alloc(n)),f=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZero",o.getLocal("p1")),o.ret(o.call(e+"_isZeroAffine",o.getLocal("p2")))),o.if(o.call(e+"_isZeroAffine",o.getLocal("p2")),o.ret(o.i32_const(0))),o.if(o.call(a+"_isOne",l),o.ret(o.call(e+"_eqAffine",o.getLocal("p1"),o.getLocal("p2")))),o.call(a+"_square",l,u),o.call(a+"_mul",s,u,g),o.call(a+"_mul",l,u,_),o.call(a+"_mul",d,_,f),o.if(o.call(a+"_eq",c,g),o.if(o.call(a+"_eq",r,f),o.ret(o.i32_const(1)))),o.ret(o.i32_const(0)))}(),function(){const i=t.addFunction(e+"_eq");i.addParam("p1","i32"),i.addParam("p2","i32"),i.setReturnType("i32"),i.addLocal("z1","i32"),i.addLocal("z2","i32");const o=i.getCodeBuilder(),c=o.getLocal("p1"),r=o.i32_add(o.getLocal("p1"),o.i32_const(n));i.addCode(o.setLocal("z1",o.i32_add(o.getLocal("p1"),o.i32_const(2*n))));const l=o.getLocal("z1"),s=o.getLocal("p2"),d=o.i32_add(o.getLocal("p2"),o.i32_const(n));i.addCode(o.setLocal("z2",o.i32_add(o.getLocal("p2"),o.i32_const(2*n))));const u=o.getLocal("z2"),g=o.i32_const(t.alloc(n)),_=o.i32_const(t.alloc(n)),f=o.i32_const(t.alloc(n)),h=o.i32_const(t.alloc(n)),p=o.i32_const(t.alloc(n)),m=o.i32_const(t.alloc(n)),L=o.i32_const(t.alloc(n)),w=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZero",o.getLocal("p1")),o.ret(o.call(e+"_isZero",o.getLocal("p2")))),o.if(o.call(e+"_isZero",o.getLocal("p2")),o.ret(o.i32_const(0))),o.if(o.call(a+"_isOne",l),o.ret(o.call(e+"_eqMixed",o.getLocal("p2"),o.getLocal("p1")))),o.if(o.call(a+"_isOne",u),o.ret(o.call(e+"_eqMixed",o.getLocal("p1"),o.getLocal("p2")))),o.call(a+"_square",l,g),o.call(a+"_square",u,_),o.call(a+"_mul",c,_,f),o.call(a+"_mul",s,g,h),o.call(a+"_mul",l,g,p),o.call(a+"_mul",u,_,m),o.call(a+"_mul",r,m,L),o.call(a+"_mul",d,p,w),o.if(o.call(a+"_eq",f,h),o.if(o.call(a+"_eq",L,w),o.ret(o.i32_const(1)))),o.ret(o.i32_const(0)))}(),function(){const i=t.addFunction(e+"_doubleAffine");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder(),c=o.getLocal("p1"),r=o.i32_add(o.getLocal("p1"),o.i32_const(n)),l=o.getLocal("pr"),s=o.i32_add(o.getLocal("pr"),o.i32_const(n)),d=o.i32_add(o.getLocal("pr"),o.i32_const(2*n)),u=o.i32_const(t.alloc(n)),g=o.i32_const(t.alloc(n)),_=o.i32_const(t.alloc(n)),f=o.i32_const(t.alloc(n)),h=o.i32_const(t.alloc(n)),p=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZeroAffine",o.getLocal("p1")),[...o.call(e+"_toJacobian",o.getLocal("p1"),o.getLocal("pr")),...o.ret([])]),o.call(a+"_square",c,u),o.call(a+"_square",r,g),o.call(a+"_square",g,_),o.call(a+"_add",c,g,f),o.call(a+"_square",f,f),o.call(a+"_sub",f,u,f),o.call(a+"_sub",f,_,f),o.call(a+"_add",f,f,f),o.call(a+"_add",u,u,h),o.call(a+"_add",h,u,h),o.call(a+"_add",r,r,d),o.call(a+"_square",h,l),o.call(a+"_sub",l,f,l),o.call(a+"_sub",l,f,l),o.call(a+"_add",_,_,p),o.call(a+"_add",p,p,p),o.call(a+"_add",p,p,p),o.call(a+"_sub",f,l,s),o.call(a+"_mul",s,h,s),o.call(a+"_sub",s,p,s))}(),function(){const i=t.addFunction(e+"_double");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder(),c=o.getLocal("p1"),r=o.i32_add(o.getLocal("p1"),o.i32_const(n)),l=o.i32_add(o.getLocal("p1"),o.i32_const(2*n)),s=o.getLocal("pr"),d=o.i32_add(o.getLocal("pr"),o.i32_const(n)),u=o.i32_add(o.getLocal("pr"),o.i32_const(2*n)),g=o.i32_const(t.alloc(n)),_=o.i32_const(t.alloc(n)),f=o.i32_const(t.alloc(n)),h=o.i32_const(t.alloc(n)),p=o.i32_const(t.alloc(n)),m=o.i32_const(t.alloc(n)),L=o.i32_const(t.alloc(n)),w=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZero",o.getLocal("p1")),[...o.call(e+"_copy",o.getLocal("p1"),o.getLocal("pr")),...o.ret([])]),o.if(o.call(a+"_isOne",l),[...o.ret(o.call(e+"_doubleAffine",o.getLocal("p1"),o.getLocal("pr"))),...o.ret([])]),o.call(a+"_square",c,g),o.call(a+"_square",r,_),o.call(a+"_square",_,f),o.call(a+"_add",c,_,h),o.call(a+"_square",h,h),o.call(a+"_sub",h,g,h),o.call(a+"_sub",h,f,h),o.call(a+"_add",h,h,h),o.call(a+"_add",g,g,p),o.call(a+"_add",p,g,p),o.call(a+"_square",p,m),o.call(a+"_mul",r,l,L),o.call(a+"_add",h,h,s),o.call(a+"_sub",m,s,s),o.call(a+"_add",f,f,w),o.call(a+"_add",w,w,w),o.call(a+"_add",w,w,w),o.call(a+"_sub",h,s,d),o.call(a+"_mul",d,p,d),o.call(a+"_sub",d,w,d),o.call(a+"_add",L,L,u))}(),function(){const i=t.addFunction(e+"_addAffine");i.addParam("p1","i32"),i.addParam("p2","i32"),i.addParam("pr","i32"),i.addLocal("z1","i32");const o=i.getCodeBuilder(),c=o.getLocal("p1"),r=o.i32_add(o.getLocal("p1"),o.i32_const(n));i.addCode(o.setLocal("z1",o.i32_add(o.getLocal("p1"),o.i32_const(2*n))));const l=o.getLocal("p2"),s=o.i32_add(o.getLocal("p2"),o.i32_const(n)),d=o.getLocal("pr"),u=o.i32_add(o.getLocal("pr"),o.i32_const(n)),g=o.i32_add(o.getLocal("pr"),o.i32_const(2*n)),_=o.i32_const(t.alloc(n)),f=o.i32_const(t.alloc(n)),h=o.i32_const(t.alloc(n)),p=o.i32_const(t.alloc(n)),m=o.i32_const(t.alloc(n)),L=o.i32_const(t.alloc(n)),w=o.i32_const(t.alloc(n)),A=o.i32_const(t.alloc(n)),b=o.i32_const(t.alloc(n)),y=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZeroAffine",o.getLocal("p1")),[...o.call(e+"_copyAffine",o.getLocal("p2"),o.getLocal("pr")),...o.call(a+"_one",o.i32_add(o.getLocal("pr"),o.i32_const(2*n))),...o.ret([])]),o.if(o.call(e+"_isZeroAffine",o.getLocal("p2")),[...o.call(e+"_copyAffine",o.getLocal("p1"),o.getLocal("pr")),...o.call(a+"_one",o.i32_add(o.getLocal("pr"),o.i32_const(2*n))),...o.ret([])]),o.if(o.call(a+"_eq",c,l),o.if(o.call(a+"_eq",r,s),[...o.call(e+"_doubleAffine",o.getLocal("p2"),o.getLocal("pr")),...o.ret([])])),o.call(a+"_sub",l,c,_),o.call(a+"_sub",s,r,h),o.call(a+"_square",_,f),o.call(a+"_add",f,f,p),o.call(a+"_add",p,p,p),o.call(a+"_mul",_,p,m),o.call(a+"_add",h,h,L),o.call(a+"_mul",c,p,A),o.call(a+"_square",L,w),o.call(a+"_add",A,A,b),o.call(a+"_sub",w,m,d),o.call(a+"_sub",d,b,d),o.call(a+"_mul",r,m,y),o.call(a+"_add",y,y,y),o.call(a+"_sub",A,d,u),o.call(a+"_mul",u,L,u),o.call(a+"_sub",u,y,u),o.call(a+"_add",_,_,g))}(),function(){const i=t.addFunction(e+"_addMixed");i.addParam("p1","i32"),i.addParam("p2","i32"),i.addParam("pr","i32"),i.addLocal("z1","i32");const o=i.getCodeBuilder(),c=o.getLocal("p1"),r=o.i32_add(o.getLocal("p1"),o.i32_const(n));i.addCode(o.setLocal("z1",o.i32_add(o.getLocal("p1"),o.i32_const(2*n))));const l=o.getLocal("z1"),s=o.getLocal("p2"),d=o.i32_add(o.getLocal("p2"),o.i32_const(n)),u=o.getLocal("pr"),g=o.i32_add(o.getLocal("pr"),o.i32_const(n)),_=o.i32_add(o.getLocal("pr"),o.i32_const(2*n)),f=o.i32_const(t.alloc(n)),h=o.i32_const(t.alloc(n)),p=o.i32_const(t.alloc(n)),m=o.i32_const(t.alloc(n)),L=o.i32_const(t.alloc(n)),w=o.i32_const(t.alloc(n)),A=o.i32_const(t.alloc(n)),b=o.i32_const(t.alloc(n)),y=o.i32_const(t.alloc(n)),I=o.i32_const(t.alloc(n)),C=o.i32_const(t.alloc(n)),F=o.i32_const(t.alloc(n)),x=o.i32_const(t.alloc(n)),E=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZero",o.getLocal("p1")),[...o.call(e+"_copyAffine",o.getLocal("p2"),o.getLocal("pr")),...o.call(a+"_one",o.i32_add(o.getLocal("pr"),o.i32_const(2*n))),...o.ret([])]),o.if(o.call(e+"_isZeroAffine",o.getLocal("p2")),[...o.call(e+"_copy",o.getLocal("p1"),o.getLocal("pr")),...o.ret([])]),o.if(o.call(a+"_isOne",l),[...o.call(e+"_addAffine",c,s,u),...o.ret([])]),o.call(a+"_square",l,f),o.call(a+"_mul",s,f,h),o.call(a+"_mul",l,f,p),o.call(a+"_mul",d,p,m),o.if(o.call(a+"_eq",c,h),o.if(o.call(a+"_eq",r,m),[...o.call(e+"_doubleAffine",o.getLocal("p2"),o.getLocal("pr")),...o.ret([])])),o.call(a+"_sub",h,c,L),o.call(a+"_sub",m,r,A),o.call(a+"_square",L,w),o.call(a+"_add",w,w,b),o.call(a+"_add",b,b,b),o.call(a+"_mul",L,b,y),o.call(a+"_add",A,A,I),o.call(a+"_mul",c,b,F),o.call(a+"_square",I,C),o.call(a+"_add",F,F,x),o.call(a+"_sub",C,y,u),o.call(a+"_sub",u,x,u),o.call(a+"_mul",r,y,E),o.call(a+"_add",E,E,E),o.call(a+"_sub",F,u,g),o.call(a+"_mul",g,I,g),o.call(a+"_sub",g,E,g),o.call(a+"_add",l,L,_),o.call(a+"_square",_,_),o.call(a+"_sub",_,f,_),o.call(a+"_sub",_,w,_))}(),function(){const i=t.addFunction(e+"_add");i.addParam("p1","i32"),i.addParam("p2","i32"),i.addParam("pr","i32"),i.addLocal("z1","i32"),i.addLocal("z2","i32");const o=i.getCodeBuilder(),c=o.getLocal("p1"),r=o.i32_add(o.getLocal("p1"),o.i32_const(n));i.addCode(o.setLocal("z1",o.i32_add(o.getLocal("p1"),o.i32_const(2*n))));const l=o.getLocal("z1"),s=o.getLocal("p2"),d=o.i32_add(o.getLocal("p2"),o.i32_const(n));i.addCode(o.setLocal("z2",o.i32_add(o.getLocal("p2"),o.i32_const(2*n))));const u=o.getLocal("z2"),g=o.getLocal("pr"),_=o.i32_add(o.getLocal("pr"),o.i32_const(n)),f=o.i32_add(o.getLocal("pr"),o.i32_const(2*n)),h=o.i32_const(t.alloc(n)),p=o.i32_const(t.alloc(n)),m=o.i32_const(t.alloc(n)),L=o.i32_const(t.alloc(n)),w=o.i32_const(t.alloc(n)),A=o.i32_const(t.alloc(n)),b=o.i32_const(t.alloc(n)),y=o.i32_const(t.alloc(n)),I=o.i32_const(t.alloc(n)),C=o.i32_const(t.alloc(n)),F=o.i32_const(t.alloc(n)),x=o.i32_const(t.alloc(n)),E=o.i32_const(t.alloc(n)),B=o.i32_const(t.alloc(n)),v=o.i32_const(t.alloc(n)),S=o.i32_const(t.alloc(n)),G=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZero",o.getLocal("p1")),[...o.call(e+"_copy",o.getLocal("p2"),o.getLocal("pr")),...o.ret([])]),o.if(o.call(e+"_isZero",o.getLocal("p2")),[...o.call(e+"_copy",o.getLocal("p1"),o.getLocal("pr")),...o.ret([])]),o.if(o.call(a+"_isOne",l),[...o.call(e+"_addMixed",s,c,g),...o.ret([])]),o.if(o.call(a+"_isOne",u),[...o.call(e+"_addMixed",c,s,g),...o.ret([])]),o.call(a+"_square",l,h),o.call(a+"_square",u,p),o.call(a+"_mul",c,p,m),o.call(a+"_mul",s,h,L),o.call(a+"_mul",l,h,w),o.call(a+"_mul",u,p,A),o.call(a+"_mul",r,A,b),o.call(a+"_mul",d,w,y),o.if(o.call(a+"_eq",m,L),o.if(o.call(a+"_eq",b,y),[...o.call(e+"_double",o.getLocal("p1"),o.getLocal("pr")),...o.ret([])])),o.call(a+"_sub",L,m,I),o.call(a+"_sub",y,b,C),o.call(a+"_add",I,I,F),o.call(a+"_square",F,F),o.call(a+"_mul",I,F,x),o.call(a+"_add",C,C,E),o.call(a+"_mul",m,F,v),o.call(a+"_square",E,B),o.call(a+"_add",v,v,S),o.call(a+"_sub",B,x,g),o.call(a+"_sub",g,S,g),o.call(a+"_mul",b,x,G),o.call(a+"_add",G,G,G),o.call(a+"_sub",v,g,_),o.call(a+"_mul",_,E,_),o.call(a+"_sub",_,G,_),o.call(a+"_add",l,u,f),o.call(a+"_square",f,f),o.call(a+"_sub",f,h,f),o.call(a+"_sub",f,p,f),o.call(a+"_mul",f,I,f))}(),function(){const i=t.addFunction(e+"_negAffine");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder(),c=o.getLocal("p1"),r=o.i32_add(o.getLocal("p1"),o.i32_const(n)),l=o.getLocal("pr"),s=o.i32_add(o.getLocal("pr"),o.i32_const(n));i.addCode(o.call(a+"_copy",c,l),o.call(a+"_neg",r,s))}(),function(){const i=t.addFunction(e+"_neg");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder(),c=o.getLocal("p1"),r=o.i32_add(o.getLocal("p1"),o.i32_const(n)),l=o.i32_add(o.getLocal("p1"),o.i32_const(2*n)),s=o.getLocal("pr"),d=o.i32_add(o.getLocal("pr"),o.i32_const(n)),u=o.i32_add(o.getLocal("pr"),o.i32_const(2*n));i.addCode(o.call(a+"_copy",c,s),o.call(a+"_neg",r,d),o.call(a+"_copy",l,u))}(),function(){const a=t.addFunction(e+"_subAffine");a.addParam("p1","i32"),a.addParam("p2","i32"),a.addParam("pr","i32");const i=a.getCodeBuilder(),o=i.i32_const(t.alloc(3*n));a.addCode(i.call(e+"_negAffine",i.getLocal("p2"),o),i.call(e+"_addAffine",i.getLocal("p1"),o,i.getLocal("pr")))}(),function(){const a=t.addFunction(e+"_subMixed");a.addParam("p1","i32"),a.addParam("p2","i32"),a.addParam("pr","i32");const i=a.getCodeBuilder(),o=i.i32_const(t.alloc(3*n));a.addCode(i.call(e+"_negAffine",i.getLocal("p2"),o),i.call(e+"_addMixed",i.getLocal("p1"),o,i.getLocal("pr")))}(),function(){const a=t.addFunction(e+"_sub");a.addParam("p1","i32"),a.addParam("p2","i32"),a.addParam("pr","i32");const i=a.getCodeBuilder(),o=i.i32_const(t.alloc(3*n));a.addCode(i.call(e+"_neg",i.getLocal("p2"),o),i.call(e+"_add",i.getLocal("p1"),o,i.getLocal("pr")))}(),function(){const i=t.addFunction(e+"_fromMontgomeryAffine");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder();i.addCode(o.call(a+"_fromMontgomery",o.getLocal("p1"),o.getLocal("pr")));for(let t=1;t<2;t++)i.addCode(o.call(a+"_fromMontgomery",o.i32_add(o.getLocal("p1"),o.i32_const(t*n)),o.i32_add(o.getLocal("pr"),o.i32_const(t*n))))}(),function(){const i=t.addFunction(e+"_fromMontgomery");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder();i.addCode(o.call(a+"_fromMontgomery",o.getLocal("p1"),o.getLocal("pr")));for(let t=1;t<3;t++)i.addCode(o.call(a+"_fromMontgomery",o.i32_add(o.getLocal("p1"),o.i32_const(t*n)),o.i32_add(o.getLocal("pr"),o.i32_const(t*n))))}(),function(){const i=t.addFunction(e+"_toMontgomeryAffine");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder();i.addCode(o.call(a+"_toMontgomery",o.getLocal("p1"),o.getLocal("pr")));for(let t=1;t<2;t++)i.addCode(o.call(a+"_toMontgomery",o.i32_add(o.getLocal("p1"),o.i32_const(t*n)),o.i32_add(o.getLocal("pr"),o.i32_const(t*n))))}(),function(){const i=t.addFunction(e+"_toMontgomery");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder();i.addCode(o.call(a+"_toMontgomery",o.getLocal("p1"),o.getLocal("pr")));for(let t=1;t<3;t++)i.addCode(o.call(a+"_toMontgomery",o.i32_add(o.getLocal("p1"),o.i32_const(t*n)),o.i32_add(o.getLocal("pr"),o.i32_const(t*n))))}(),function(){const i=t.addFunction(e+"_toAffine");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder(),c=o.getLocal("p1"),r=o.i32_add(o.getLocal("p1"),o.i32_const(n)),l=o.i32_add(o.getLocal("p1"),o.i32_const(2*n)),s=o.getLocal("pr"),d=o.i32_add(o.getLocal("pr"),o.i32_const(n)),u=o.i32_const(t.alloc(n)),g=o.i32_const(t.alloc(n)),_=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZero",o.getLocal("p1")),[...o.call(a+"_zero",s),...o.call(a+"_zero",d)],[...o.call(a+"_inverse",l,u),...o.call(a+"_square",u,g),...o.call(a+"_mul",u,g,_),...o.call(a+"_mul",c,g,s),...o.call(a+"_mul",r,_,d)]))}(),function(){const o=t.addFunction(e+"_inCurveAffine");o.addParam("pIn","i32"),o.setReturnType("i32");const c=o.getCodeBuilder(),r=c.getLocal("pIn"),l=c.i32_add(c.getLocal("pIn"),c.i32_const(n)),s=c.i32_const(t.alloc(n)),d=c.i32_const(t.alloc(n));o.addCode(c.call(a+"_square",l,s),c.call(a+"_square",r,d),c.call(a+"_mul",r,d,d),c.call(a+"_add",d,c.i32_const(i),d),c.ret(c.call(a+"_eq",s,d)))}(),function(){const a=t.addFunction(e+"_inCurve");a.addParam("pIn","i32"),a.setReturnType("i32");const i=a.getCodeBuilder(),o=i.i32_const(t.alloc(2*n));a.addCode(i.call(e+"_toAffine",i.getLocal("pIn"),o),i.ret(i.call(e+"_inCurveAffine",o)))}(),function(){const i=t.addFunction(e+"_batchToAffine");i.addParam("pIn","i32"),i.addParam("n","i32"),i.addParam("pOut","i32"),i.addLocal("pAux","i32"),i.addLocal("itIn","i32"),i.addLocal("itAux","i32"),i.addLocal("itOut","i32"),i.addLocal("i","i32");const o=i.getCodeBuilder(),c=o.i32_const(t.alloc(n));i.addCode(o.setLocal("pAux",o.i32_load(o.i32_const(0))),o.i32_store(o.i32_const(0),o.i32_add(o.getLocal("pAux"),o.i32_mul(o.getLocal("n"),o.i32_const(n)))),o.call(a+"_batchInverse",o.i32_add(o.getLocal("pIn"),o.i32_const(2*n)),o.i32_const(3*n),o.getLocal("n"),o.getLocal("pAux"),o.i32_const(n)),o.setLocal("itIn",o.getLocal("pIn")),o.setLocal("itAux",o.getLocal("pAux")),o.setLocal("itOut",o.getLocal("pOut")),o.setLocal("i",o.i32_const(0)),o.block(o.loop(o.br_if(1,o.i32_eq(o.getLocal("i"),o.getLocal("n"))),o.if(o.call(a+"_isZero",o.getLocal("itAux")),[...o.call(a+"_zero",o.getLocal("itOut")),...o.call(a+"_zero",o.i32_add(o.getLocal("itOut"),o.i32_const(n)))],[...o.call(a+"_mul",o.getLocal("itAux"),o.i32_add(o.getLocal("itIn"),o.i32_const(n)),c),...o.call(a+"_square",o.getLocal("itAux"),o.getLocal("itAux")),...o.call(a+"_mul",o.getLocal("itAux"),o.getLocal("itIn"),o.getLocal("itOut")),...o.call(a+"_mul",o.getLocal("itAux"),c,o.i32_add(o.getLocal("itOut"),o.i32_const(n)))]),o.setLocal("itIn",o.i32_add(o.getLocal("itIn"),o.i32_const(3*n))),o.setLocal("itOut",o.i32_add(o.getLocal("itOut"),o.i32_const(2*n))),o.setLocal("itAux",o.i32_add(o.getLocal("itAux"),o.i32_const(n))),o.setLocal("i",o.i32_add(o.getLocal("i"),o.i32_const(1))),o.br(0))),o.i32_store(o.i32_const(0),o.getLocal("pAux")))}(),function(){const i=t.addFunction(e+"_normalize");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder(),c=o.getLocal("p1"),r=o.i32_add(o.getLocal("p1"),o.i32_const(n)),l=o.i32_add(o.getLocal("p1"),o.i32_const(2*n)),s=o.getLocal("pr"),d=o.i32_add(o.getLocal("pr"),o.i32_const(n)),u=o.i32_add(o.getLocal("pr"),o.i32_const(2*n)),g=o.i32_const(t.alloc(n)),_=o.i32_const(t.alloc(n)),f=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZero",o.getLocal("p1")),o.call(e+"_zero",o.getLocal("pr")),[...o.call(a+"_inverse",l,g),...o.call(a+"_square",g,_),...o.call(a+"_mul",g,_,f),...o.call(a+"_mul",c,_,s),...o.call(a+"_mul",r,f,d),...o.call(a+"_one",u)]))}(),function(){const a=t.addFunction(e+"__reverseBytes");a.addParam("pIn","i32"),a.addParam("n","i32"),a.addParam("pOut","i32"),a.addLocal("itOut","i32"),a.addLocal("itIn","i32");const i=a.getCodeBuilder();a.addCode(i.setLocal("itOut",i.i32_sub(i.i32_add(i.getLocal("pOut"),i.getLocal("n")),i.i32_const(1))),i.setLocal("itIn",i.getLocal("pIn")),i.block(i.loop(i.br_if(1,i.i32_lt_s(i.getLocal("itOut"),i.getLocal("pOut"))),i.i32_store8(i.getLocal("itOut"),i.i32_load8_u(i.getLocal("itIn"))),i.setLocal("itOut",i.i32_sub(i.getLocal("itOut"),i.i32_const(1))),i.setLocal("itIn",i.i32_add(i.getLocal("itIn"),i.i32_const(1))),i.br(0))))}(),function(){const a=t.addFunction(e+"_LEMtoU");a.addParam("pIn","i32"),a.addParam("pOut","i32");const i=a.getCodeBuilder(),o=t.alloc(2*n),c=i.i32_const(o),r=i.i32_const(o),l=i.i32_const(o+n);a.addCode(i.if(i.call(e+"_isZeroAffine",i.getLocal("pIn")),[...i.call(e+"_zeroAffine",i.getLocal("pOut")),...i.i32_store8(i.getLocal("pOut"),i.i32_const(64)),...i.ret([])]),i.call(e+"_fromMontgomeryAffine",i.getLocal("pIn"),c),i.call(e+"__reverseBytes",r,i.i32_const(n),i.getLocal("pOut")),i.call(e+"__reverseBytes",l,i.i32_const(n),i.i32_add(i.getLocal("pOut"),i.i32_const(n))))}(),function(){const i=t.addFunction(e+"_LEMtoC");i.addParam("pIn","i32"),i.addParam("pOut","i32");const o=i.getCodeBuilder(),c=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZero",o.getLocal("pIn")),[...o.call(a+"_zero",o.getLocal("pOut")),...o.i32_store8(o.getLocal("pOut"),o.i32_const(64)),...o.ret([])]),o.call(a+"_fromMontgomery",o.getLocal("pIn"),c),o.call(e+"__reverseBytes",c,o.i32_const(n),o.getLocal("pOut")),o.if(o.i32_eq(o.call(a+"_sign",o.i32_add(o.getLocal("pIn"),o.i32_const(n))),o.i32_const(-1)),o.i32_store8(o.getLocal("pOut"),o.i32_or(o.i32_load8_u(o.getLocal("pOut")),o.i32_const(128)))))}(),function(){const a=t.addFunction(e+"_UtoLEM");a.addParam("pIn","i32"),a.addParam("pOut","i32");const i=a.getCodeBuilder(),o=t.alloc(2*n),c=i.i32_const(o),r=i.i32_const(o),l=i.i32_const(o+n);a.addCode(i.if(i.i32_and(i.i32_load8_u(i.getLocal("pIn")),i.i32_const(64)),[...i.call(e+"_zeroAffine",i.getLocal("pOut")),...i.ret([])]),i.call(e+"__reverseBytes",i.getLocal("pIn"),i.i32_const(n),r),i.call(e+"__reverseBytes",i.i32_add(i.getLocal("pIn"),i.i32_const(n)),i.i32_const(n),l),i.call(e+"_toMontgomeryAffine",c,i.getLocal("pOut")))}(),function(){const o=t.addFunction(e+"_CtoLEM");o.addParam("pIn","i32"),o.addParam("pOut","i32"),o.addLocal("firstByte","i32"),o.addLocal("greatest","i32");const c=o.getCodeBuilder(),r=t.alloc(2*n),l=c.i32_const(r),s=c.i32_const(r+n);o.addCode(c.setLocal("firstByte",c.i32_load8_u(c.getLocal("pIn"))),c.if(c.i32_and(c.getLocal("firstByte"),c.i32_const(64)),[...c.call(e+"_zeroAffine",c.getLocal("pOut")),...c.ret([])]),c.setLocal("greatest",c.i32_and(c.getLocal("firstByte"),c.i32_const(128))),c.call(a+"_copy",c.getLocal("pIn"),s),c.i32_store8(s,c.i32_and(c.getLocal("firstByte"),c.i32_const(63))),c.call(e+"__reverseBytes",s,c.i32_const(n),l),c.call(a+"_toMontgomery",l,c.getLocal("pOut")),c.call(a+"_square",c.getLocal("pOut"),s),c.call(a+"_mul",c.getLocal("pOut"),s,s),c.call(a+"_add",s,c.i32_const(i),s),c.call(a+"_sqrt",s,s),c.call(a+"_neg",s,l),c.if(c.i32_eq(c.call(a+"_sign",s),c.i32_const(-1)),c.if(c.getLocal("greatest"),c.call(a+"_copy",s,c.i32_add(c.getLocal("pOut"),c.i32_const(n))),c.call(a+"_neg",s,c.i32_add(c.getLocal("pOut"),c.i32_const(n)))),c.if(c.getLocal("greatest"),c.call(a+"_neg",s,c.i32_add(c.getLocal("pOut"),c.i32_const(n))),c.call(a+"_copy",s,c.i32_add(c.getLocal("pOut"),c.i32_const(n))))))}(),Qt(t,e+"_batchLEMtoU",e+"_LEMtoU",2*n,2*n),Qt(t,e+"_batchLEMtoC",e+"_LEMtoC",2*n,n),Qt(t,e+"_batchUtoLEM",e+"_UtoLEM",2*n,2*n),Qt(t,e+"_batchCtoLEM",e+"_CtoLEM",n,2*n,!0),Qt(t,e+"_batchToJacobian",e+"_toJacobian",2*n,3*n,!0),qt(t,e,e+"_multiexp",e+"_add",3*n),qt(t,e,e+"_multiexpAffine",e+"_addMixed",2*n),zt(t,e+"_timesScalar",3*n,e+"_add",e+"_double",e+"_sub",e+"_copy",e+"_zero"),zt(t,e+"_timesScalarAffine",2*n,e+"_addMixed",e+"_double",e+"_subMixed",e+"_copyAffine",e+"_zero"),t.exportFunction(e+"_isZero"),t.exportFunction(e+"_isZeroAffine"),t.exportFunction(e+"_eq"),t.exportFunction(e+"_eqMixed"),t.exportFunction(e+"_eqAffine"),t.exportFunction(e+"_copy"),t.exportFunction(e+"_copyAffine"),t.exportFunction(e+"_zero"),t.exportFunction(e+"_zeroAffine"),t.exportFunction(e+"_double"),t.exportFunction(e+"_doubleAffine"),t.exportFunction(e+"_add"),t.exportFunction(e+"_addMixed"),t.exportFunction(e+"_addAffine"),t.exportFunction(e+"_neg"),t.exportFunction(e+"_negAffine"),t.exportFunction(e+"_sub"),t.exportFunction(e+"_subMixed"),t.exportFunction(e+"_subAffine"),t.exportFunction(e+"_fromMontgomery"),t.exportFunction(e+"_fromMontgomeryAffine"),t.exportFunction(e+"_toMontgomery"),t.exportFunction(e+"_toMontgomeryAffine"),t.exportFunction(e+"_timesScalar"),t.exportFunction(e+"_timesScalarAffine"),t.exportFunction(e+"_normalize"),t.exportFunction(e+"_LEMtoU"),t.exportFunction(e+"_LEMtoC"),t.exportFunction(e+"_UtoLEM"),t.exportFunction(e+"_CtoLEM"),t.exportFunction(e+"_batchLEMtoU"),t.exportFunction(e+"_batchLEMtoC"),t.exportFunction(e+"_batchUtoLEM"),t.exportFunction(e+"_batchCtoLEM"),t.exportFunction(e+"_toAffine"),t.exportFunction(e+"_toJacobian"),t.exportFunction(e+"_batchToAffine"),t.exportFunction(e+"_batchToJacobian"),t.exportFunction(e+"_inCurve"),t.exportFunction(e+"_inCurveAffine"),e};const{isOdd:Tt,modInv:kt,modPow:Rt}=J,Dt=H;var Nt=function(t,e,a,i,o){const n=8*t.modules[i].n64,c=8*t.modules[a].n64,r=t.modules[i].q;let l=r-1n,s=0;for(;!Tt(l);)s++,l>>=1n;let d=2n;for(;1n===Rt(d,r>>1n,r);)d+=1n;const u=new Array(s+1);u[s]=Rt(d,l,r);let g=s-1;for(;g>=0;)u[g]=Rt(u[g+1],2n,r),g--;const _=[],f=(1n<<BigInt(8*n))%r;for(let t=0;t<u.length;t++){const e=u[t]*f%r;_.push(...Dt.bigInt2BytesLE(e,n))}const h=t.alloc(_),p=new Array(s+1);p[0]=1n;for(let t=1;t<=s;t++)p[t]=2n*p[t-1];const m=[];for(let t=0;t<=s;t++){const e=kt(p[t],r)*f%r;m.push(...Dt.bigInt2BytesLE(e,n))}const L=t.alloc(m),w=Rt(d,2n,r),A=[],b=[];for(let t=0;t<=s;t++){const e=Rt(w,2n**BigInt(t),r),a=kt(r+1n-e,r);A.push(...Dt.bigInt2BytesLE(e*f%r,n)),b.push(...Dt.bigInt2BytesLE(a*f%r,n))}const y=t.alloc(A),I=t.alloc(b);function C(t){let e=0;for(let a=0;a<8;a++)t&1<<a&&(e|=128>>a);return e}const F=Array(256);for(let t=0;t<256;t++)F[t]=C(t);const x=t.alloc(F);function E(){const a=t.addFunction(e+"_fft");a.addParam("px","i32"),a.addParam("n","i32"),a.addLocal("bits","i32");const o=a.getCodeBuilder(),c=o.i32_const(t.alloc(n));a.addCode(o.setLocal("bits",o.call(e+"__log2",o.getLocal("n"))),o.call(i+"_one",c),o.call(e+"_rawfft",o.getLocal("px"),o.getLocal("bits"),o.i32_const(0),c))}!function(){const a=t.addFunction(e+"__rev");a.addParam("x","i32"),a.addParam("bits","i32"),a.setReturnType("i32");const i=a.getCodeBuilder();a.addCode(i.i32_rotl(i.i32_add(i.i32_add(i.i32_shl(i.i32_load8_u(i.i32_and(i.getLocal("x"),i.i32_const(255)),x,0),i.i32_const(24)),i.i32_shl(i.i32_load8_u(i.i32_and(i.i32_shr_u(i.getLocal("x"),i.i32_const(8)),i.i32_const(255)),x,0),i.i32_const(16))),i.i32_add(i.i32_shl(i.i32_load8_u(i.i32_and(i.i32_shr_u(i.getLocal("x"),i.i32_const(16)),i.i32_const(255)),x,0),i.i32_const(8)),i.i32_load8_u(i.i32_and(i.i32_shr_u(i.getLocal("x"),i.i32_const(24)),i.i32_const(255)),x,0))),i.getLocal("bits")))}(),function(){const i=t.addFunction(e+"__reversePermutation");i.addParam("px","i32"),i.addParam("bits","i32"),i.addLocal("n","i32"),i.addLocal("i","i32"),i.addLocal("ri","i32"),i.addLocal("idx1","i32"),i.addLocal("idx2","i32");const o=i.getCodeBuilder(),n=o.i32_const(t.alloc(c));i.addCode(o.setLocal("n",o.i32_shl(o.i32_const(1),o.getLocal("bits"))),o.setLocal("i",o.i32_const(0)),o.block(o.loop(o.br_if(1,o.i32_eq(o.getLocal("i"),o.getLocal("n"))),o.setLocal("idx1",o.i32_add(o.getLocal("px"),o.i32_mul(o.getLocal("i"),o.i32_const(c)))),o.setLocal("ri",o.call(e+"__rev",o.getLocal("i"),o.getLocal("bits"))),o.setLocal("idx2",o.i32_add(o.getLocal("px"),o.i32_mul(o.getLocal("ri"),o.i32_const(c)))),o.if(o.i32_lt_u(o.getLocal("i"),o.getLocal("ri")),[...o.call(a+"_copy",o.getLocal("idx1"),n),...o.call(a+"_copy",o.getLocal("idx2"),o.getLocal("idx1")),...o.call(a+"_copy",n,o.getLocal("idx2"))]),o.setLocal("i",o.i32_add(o.getLocal("i"),o.i32_const(1))),o.br(0))))}(),function(){const n=t.addFunction(e+"__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 r=n.getCodeBuilder(),l=r.i32_const(t.alloc(c));n.addCode(r.if(r.i32_and(r.i32_eqz(r.getLocal("reverse")),r.call(i+"_isOne",r.getLocal("mulFactor"))),r.ret([])),r.setLocal("n",r.i32_shl(r.i32_const(1),r.getLocal("bits"))),r.setLocal("mask",r.i32_sub(r.getLocal("n"),r.i32_const(1))),r.setLocal("i",r.i32_const(1)),r.setLocal("ndiv2",r.i32_shr_u(r.getLocal("n"),r.i32_const(1))),r.block(r.loop(r.br_if(1,r.i32_ge_u(r.getLocal("i"),r.getLocal("ndiv2"))),r.setLocal("idx1",r.i32_add(r.getLocal("px"),r.i32_mul(r.getLocal("i"),r.i32_const(c)))),r.setLocal("idx2",r.i32_add(r.getLocal("px"),r.i32_mul(r.i32_sub(r.getLocal("n"),r.getLocal("i")),r.i32_const(c)))),r.if(r.getLocal("reverse"),r.if(r.call(i+"_isOne",r.getLocal("mulFactor")),[...r.call(a+"_copy",r.getLocal("idx1"),l),...r.call(a+"_copy",r.getLocal("idx2"),r.getLocal("idx1")),...r.call(a+"_copy",l,r.getLocal("idx2"))],[...r.call(a+"_copy",r.getLocal("idx1"),l),...r.call(o,r.getLocal("idx2"),r.getLocal("mulFactor"),r.getLocal("idx1")),...r.call(o,l,r.getLocal("mulFactor"),r.getLocal("idx2"))]),r.if(r.call(i+"_isOne",r.getLocal("mulFactor")),[],[...r.call(o,r.getLocal("idx1"),r.getLocal("mulFactor"),r.getLocal("idx1")),...r.call(o,r.getLocal("idx2"),r.getLocal("mulFactor"),r.getLocal("idx2"))])),r.setLocal("i",r.i32_add(r.getLocal("i"),r.i32_const(1))),r.br(0))),r.if(r.call(i+"_isOne",r.getLocal("mulFactor")),[],[...r.call(o,r.getLocal("px"),r.getLocal("mulFactor"),r.getLocal("px")),...r.setLocal("idx2",r.i32_add(r.getLocal("px"),r.i32_mul(r.getLocal("ndiv2"),r.i32_const(c)))),...r.call(o,r.getLocal("idx2"),r.getLocal("mulFactor"),r.getLocal("idx2"))]))}(),function(){const r=t.addFunction(e+"_rawfft");r.addParam("px","i32"),r.addParam("bits","i32"),r.addParam("reverse","i32"),r.addParam("mulFactor","i32"),r.addLocal("s","i32"),r.addLocal("k","i32"),r.addLocal("j","i32"),r.addLocal("m","i32"),r.addLocal("mdiv2","i32"),r.addLocal("n","i32"),r.addLocal("pwm","i32"),r.addLocal("idx1","i32"),r.addLocal("idx2","i32");const l=r.getCodeBuilder(),s=l.i32_const(t.alloc(n)),d=l.i32_const(t.alloc(c)),u=l.i32_const(t.alloc(c));r.addCode(l.call(e+"__reversePermutation",l.getLocal("px"),l.getLocal("bits")),l.setLocal("n",l.i32_shl(l.i32_const(1),l.getLocal("bits"))),l.setLocal("s",l.i32_const(1)),l.block(l.loop(l.br_if(1,l.i32_gt_u(l.getLocal("s"),l.getLocal("bits"))),l.setLocal("m",l.i32_shl(l.i32_const(1),l.getLocal("s"))),l.setLocal("pwm",l.i32_add(l.i32_const(h),l.i32_mul(l.getLocal("s"),l.i32_const(n)))),l.setLocal("k",l.i32_const(0)),l.block(l.loop(l.br_if(1,l.i32_ge_u(l.getLocal("k"),l.getLocal("n"))),l.call(i+"_one",s),l.setLocal("mdiv2",l.i32_shr_u(l.getLocal("m"),l.i32_const(1))),l.setLocal("j",l.i32_const(0)),l.block(l.loop(l.br_if(1,l.i32_ge_u(l.getLocal("j"),l.getLocal("mdiv2"))),l.setLocal("idx1",l.i32_add(l.getLocal("px"),l.i32_mul(l.i32_add(l.getLocal("k"),l.getLocal("j")),l.i32_const(c)))),l.setLocal("idx2",l.i32_add(l.getLocal("idx1"),l.i32_mul(l.getLocal("mdiv2"),l.i32_const(c)))),l.call(o,l.getLocal("idx2"),s,d),l.call(a+"_copy",l.getLocal("idx1"),u),l.call(a+"_add",u,d,l.getLocal("idx1")),l.call(a+"_sub",u,d,l.getLocal("idx2")),l.call(i+"_mul",s,l.getLocal("pwm"),s),l.setLocal("j",l.i32_add(l.getLocal("j"),l.i32_const(1))),l.br(0))),l.setLocal("k",l.i32_add(l.getLocal("k"),l.getLocal("m"))),l.br(0))),l.setLocal("s",l.i32_add(l.getLocal("s"),l.i32_const(1))),l.br(0))),l.call(e+"__fftFinal",l.getLocal("px"),l.getLocal("bits"),l.getLocal("reverse"),l.getLocal("mulFactor")))}(),function(){const a=t.addFunction(e+"__log2");a.addParam("n","i32"),a.setReturnType("i32"),a.addLocal("bits","i32"),a.addLocal("aux","i32");const i=a.getCodeBuilder();a.addCode(i.setLocal("aux",i.i32_shr_u(i.getLocal("n"),i.i32_const(1)))),a.addCode(i.setLocal("bits",i.i32_const(0))),a.addCode(i.block(i.loop(i.br_if(1,i.i32_eqz(i.getLocal("aux"))),i.setLocal("aux",i.i32_shr_u(i.getLocal("aux"),i.i32_const(1))),i.setLocal("bits",i.i32_add(i.getLocal("bits"),i.i32_const(1))),i.br(0)))),a.addCode(i.if(i.i32_ne(i.getLocal("n"),i.i32_shl(i.i32_const(1),i.getLocal("bits"))),i.unreachable())),a.addCode(i.if(i.i32_gt_u(i.getLocal("bits"),i.i32_const(s)),i.unreachable())),a.addCode(i.getLocal("bits"))}(),E(),function(){const a=t.addFunction(e+"_ifft");a.addParam("px","i32"),a.addParam("n","i32"),a.addLocal("bits","i32"),a.addLocal("pInv2","i32");const i=a.getCodeBuilder();a.addCode(i.setLocal("bits",i.call(e+"__log2",i.getLocal("n"))),i.setLocal("pInv2",i.i32_add(i.i32_const(L),i.i32_mul(i.getLocal("bits"),i.i32_const(n)))),i.call(e+"_rawfft",i.getLocal("px"),i.getLocal("bits"),i.i32_const(1),i.getLocal("pInv2")))}(),function(){const r=t.addFunction(e+"_fftJoin");r.addParam("pBuff1","i32"),r.addParam("pBuff2","i32"),r.addParam("n","i32"),r.addParam("first","i32"),r.addParam("inc","i32"),r.addLocal("idx1","i32"),r.addLocal("idx2","i32"),r.addLocal("i","i32");const l=r.getCodeBuilder(),s=l.i32_const(t.alloc(n)),d=l.i32_const(t.alloc(c)),u=l.i32_const(t.alloc(c));r.addCode(l.call(i+"_copy",l.getLocal("first"),s),l.setLocal("i",l.i32_const(0)),l.block(l.loop(l.br_if(1,l.i32_eq(l.getLocal("i"),l.getLocal("n"))),l.setLocal("idx1",l.i32_add(l.getLocal("pBuff1"),l.i32_mul(l.getLocal("i"),l.i32_const(c)))),l.setLocal("idx2",l.i32_add(l.getLocal("pBuff2"),l.i32_mul(l.getLocal("i"),l.i32_const(c)))),l.call(o,l.getLocal("idx2"),s,d),l.call(a+"_copy",l.getLocal("idx1"),u),l.call(a+"_add",u,d,l.getLocal("idx1")),l.call(a+"_sub",u,d,l.getLocal("idx2")),l.call(i+"_mul",s,l.getLocal("inc"),s),l.setLocal("i",l.i32_add(l.getLocal("i"),l.i32_const(1))),l.br(0))))}(),function(){const r=t.addFunction(e+"_fftJoinExt");r.addParam("pBuff1","i32"),r.addParam("pBuff2","i32"),r.addParam("n","i32"),r.addParam("first","i32"),r.addParam("inc","i32"),r.addParam("totalBits","i32"),r.addLocal("idx1","i32"),r.addLocal("idx2","i32"),r.addLocal("i","i32"),r.addLocal("pShiftToM","i32");const l=r.getCodeBuilder(),s=l.i32_const(t.alloc(n)),d=l.i32_const(t.alloc(c));r.addCode(l.setLocal("pShiftToM",l.i32_add(l.i32_const(y),l.i32_mul(l.getLocal("totalBits"),l.i32_const(n)))),l.call(i+"_copy",l.getLocal("first"),s),l.setLocal("i",l.i32_const(0)),l.block(l.loop(l.br_if(1,l.i32_eq(l.getLocal("i"),l.getLocal("n"))),l.setLocal("idx1",l.i32_add(l.getLocal("pBuff1"),l.i32_mul(l.getLocal("i"),l.i32_const(c)))),l.setLocal("idx2",l.i32_add(l.getLocal("pBuff2"),l.i32_mul(l.getLocal("i"),l.i32_const(c)))),l.call(a+"_add",l.getLocal("idx1"),l.getLocal("idx2"),d),l.call(o,l.getLocal("idx2"),l.getLocal("pShiftToM"),l.getLocal("idx2")),l.call(a+"_add",l.getLocal("idx1"),l.getLocal("idx2"),l.getLocal("idx2")),l.call(o,l.getLocal("idx2"),s,l.getLocal("idx2")),l.call(a+"_copy",d,l.getLocal("idx1")),l.call(i+"_mul",s,l.getLocal("inc"),s),l.setLocal("i",l.i32_add(l.getLocal("i"),l.i32_const(1))),l.br(0))))}(),function(){const r=t.addFunction(e+"_fftJoinExtInv");r.addParam("pBuff1","i32"),r.addParam("pBuff2","i32"),r.addParam("n","i32"),r.addParam("first","i32"),r.addParam("inc","i32"),r.addParam("totalBits","i32"),r.addLocal("idx1","i32"),r.addLocal("idx2","i32"),r.addLocal("i","i32"),r.addLocal("pShiftToM","i32"),r.addLocal("pSConst","i32");const l=r.getCodeBuilder(),s=l.i32_const(t.alloc(n)),d=l.i32_const(t.alloc(c));r.addCode(l.setLocal("pShiftToM",l.i32_add(l.i32_const(y),l.i32_mul(l.getLocal("totalBits"),l.i32_const(n)))),l.setLocal("pSConst",l.i32_add(l.i32_const(I),l.i32_mul(l.getLocal("totalBits"),l.i32_const(n)))),l.call(i+"_copy",l.getLocal("first"),s),l.setLocal("i",l.i32_const(0)),l.block(l.loop(l.br_if(1,l.i32_eq(l.getLocal("i"),l.getLocal("n"))),l.setLocal("idx1",l.i32_add(l.getLocal("pBuff1"),l.i32_mul(l.getLocal("i"),l.i32_const(c)))),l.setLocal("idx2",l.i32_add(l.getLocal("pBuff2"),l.i32_mul(l.getLocal("i"),l.i32_const(c)))),l.call(o,l.getLocal("idx2"),s,d),l.call(a+"_sub",l.getLocal("idx1"),d,l.getLocal("idx2")),l.call(o,l.getLocal("idx2"),l.getLocal("pSConst"),l.getLocal("idx2")),l.call(o,l.getLocal("idx1"),l.getLocal("pShiftToM"),l.getLocal("idx1")),l.call(a+"_sub",d,l.getLocal("idx1"),l.getLocal("idx1")),l.call(o,l.getLocal("idx1"),l.getLocal("pSConst"),l.getLocal("idx1")),l.call(i+"_mul",s,l.getLocal("inc"),s),l.setLocal("i",l.i32_add(l.getLocal("i"),l.i32_const(1))),l.br(0))))}(),function(){const r=t.addFunction(e+"_fftMix");r.addParam("pBuff","i32"),r.addParam("n","i32"),r.addParam("exp","i32"),r.addLocal("nGroups","i32"),r.addLocal("nPerGroup","i32"),r.addLocal("nPerGroupDiv2","i32"),r.addLocal("pairOffset","i32"),r.addLocal("idx1","i32"),r.addLocal("idx2","i32"),r.addLocal("i","i32"),r.addLocal("j","i32"),r.addLocal("pwm","i32");const l=r.getCodeBuilder(),s=l.i32_const(t.alloc(n)),d=l.i32_const(t.alloc(c)),u=l.i32_const(t.alloc(c));r.addCode(l.setLocal("nPerGroup",l.i32_shl(l.i32_const(1),l.getLocal("exp"))),l.setLocal("nPerGroupDiv2",l.i32_shr_u(l.getLocal("nPerGroup"),l.i32_const(1))),l.setLocal("nGroups",l.i32_shr_u(l.getLocal("n"),l.getLocal("exp"))),l.setLocal("pairOffset",l.i32_mul(l.getLocal("nPerGroupDiv2"),l.i32_const(c))),l.setLocal("pwm",l.i32_add(l.i32_const(h),l.i32_mul(l.getLocal("exp"),l.i32_const(n)))),l.setLocal("i",l.i32_const(0)),l.block(l.loop(l.br_if(1,l.i32_eq(l.getLocal("i"),l.getLocal("nGroups"))),l.call(i+"_one",s),l.setLocal("j",l.i32_const(0)),l.block(l.loop(l.br_if(1,l.i32_eq(l.getLocal("j"),l.getLocal("nPerGroupDiv2"))),l.setLocal("idx1",l.i32_add(l.getLocal("pBuff"),l.i32_mul(l.i32_add(l.i32_mul(l.getLocal("i"),l.getLocal("nPerGroup")),l.getLocal("j")),l.i32_const(c)))),l.setLocal("idx2",l.i32_add(l.getLocal("idx1"),l.getLocal("pairOffset"))),l.call(o,l.getLocal("idx2"),s,d),l.call(a+"_copy",l.getLocal("idx1"),u),l.call(a+"_add",u,d,l.getLocal("idx1")),l.call(a+"_sub",u,d,l.getLocal("idx2")),l.call(i+"_mul",s,l.getLocal("pwm"),s),l.setLocal("j",l.i32_add(l.getLocal("j"),l.i32_const(1))),l.br(0))),l.setLocal("i",l.i32_add(l.getLocal("i"),l.i32_const(1))),l.br(0))))}(),function(){const i=t.addFunction(e+"_fftFinal");i.addParam("pBuff","i32"),i.addParam("n","i32"),i.addParam("factor","i32"),i.addLocal("idx1","i32"),i.addLocal("idx2","i32"),i.addLocal("i","i32"),i.addLocal("ndiv2","i32");const n=i.getCodeBuilder(),r=n.i32_const(t.alloc(c));i.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(o,n.i32_add(n.getLocal("pBuff"),n.i32_mul(n.getLocal("ndiv2"),n.i32_const(c))),n.getLocal("factor"),n.i32_add(n.getLocal("pBuff"),n.i32_mul(n.getLocal("ndiv2"),n.i32_const(c))))),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(c)))),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(c)))),n.call(o,n.getLocal("idx2"),n.getLocal("factor"),r),n.call(o,n.getLocal("idx1"),n.getLocal("factor"),n.getLocal("idx2")),n.call(a+"_copy",r,n.getLocal("idx1")),n.setLocal("i",n.i32_add(n.getLocal("i"),n.i32_const(1))),n.br(0))))}(),function(){const r=t.addFunction(e+"_prepareLagrangeEvaluation");r.addParam("pBuff1","i32"),r.addParam("pBuff2","i32"),r.addParam("n","i32"),r.addParam("first","i32"),r.addParam("inc","i32"),r.addParam("totalBits","i32"),r.addLocal("idx1","i32"),r.addLocal("idx2","i32"),r.addLocal("i","i32"),r.addLocal("pShiftToM","i32"),r.addLocal("pSConst","i32");const l=r.getCodeBuilder(),s=l.i32_const(t.alloc(n)),d=l.i32_const(t.alloc(c));r.addCode(l.setLocal("pShiftToM",l.i32_add(l.i32_const(y),l.i32_mul(l.getLocal("totalBits"),l.i32_const(n)))),l.setLocal("pSConst",l.i32_add(l.i32_const(I),l.i32_mul(l.getLocal("totalBits"),l.i32_const(n)))),l.call(i+"_copy",l.getLocal("first"),s),l.setLocal("i",l.i32_const(0)),l.block(l.loop(l.br_if(1,l.i32_eq(l.getLocal("i"),l.getLocal("n"))),l.setLocal("idx1",l.i32_add(l.getLocal("pBuff1"),l.i32_mul(l.getLocal("i"),l.i32_const(c)))),l.setLocal("idx2",l.i32_add(l.getLocal("pBuff2"),l.i32_mul(l.getLocal("i"),l.i32_const(c)))),l.call(o,l.getLocal("idx1"),l.getLocal("pShiftToM"),d),l.call(a+"_sub",l.getLocal("idx2"),d,d),l.call(a+"_sub",l.getLocal("idx1"),l.getLocal("idx2"),l.getLocal("idx2")),l.call(o,d,l.getLocal("pSConst"),l.getLocal("idx1")),l.call(o,l.getLocal("idx2"),s,l.getLocal("idx2")),l.call(i+"_mul",s,l.getLocal("inc"),s),l.setLocal("i",l.i32_add(l.getLocal("i"),l.i32_const(1))),l.br(0))))}(),t.exportFunction(e+"_fft"),t.exportFunction(e+"_ifft"),t.exportFunction(e+"_rawfft"),t.exportFunction(e+"_fftJoin"),t.exportFunction(e+"_fftJoinExt"),t.exportFunction(e+"_fftJoinExtInv"),t.exportFunction(e+"_fftMix"),t.exportFunction(e+"_fftFinal"),t.exportFunction(e+"_prepareLagrangeEvaluation")},Vt=function(t,e,a){const i=8*t.modules[a].n64;return function(){const o=t.addFunction(e+"_zero");o.addParam("px","i32"),o.addParam("n","i32"),o.addLocal("lastp","i32"),o.addLocal("p","i32");const n=o.getCodeBuilder();o.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(i)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("p"),n.getLocal("lastp"))),n.call(a+"_zero",n.getLocal("p")),n.setLocal("p",n.i32_add(n.getLocal("p"),n.i32_const(i))),n.br(0))))}(),function(){const o=t.addFunction(e+"_constructLC");o.addParam("ppolynomials","i32"),o.addParam("psignals","i32"),o.addParam("nSignals","i32"),o.addParam("pres","i32"),o.addLocal("i","i32"),o.addLocal("j","i32"),o.addLocal("pp","i32"),o.addLocal("ps","i32"),o.addLocal("pd","i32"),o.addLocal("ncoefs","i32");const n=o.getCodeBuilder(),c=n.i32_const(t.alloc(i));o.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(i)))),n.setLocal("pp",n.i32_add(n.getLocal("pp"),n.i32_const(4))),n.call(a+"_mul",n.getLocal("ps"),n.getLocal("pp"),c),n.call(a+"_add",c,n.getLocal("pd"),n.getLocal("pd")),n.setLocal("pp",n.i32_add(n.getLocal("pp"),n.i32_const(i))),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(i))),n.setLocal("i",n.i32_add(n.getLocal("i"),n.i32_const(1))),n.br(0))))}(),t.exportFunction(e+"_zero"),t.exportFunction(e+"_constructLC"),e},Kt=function(t,e,a){const i=8*t.modules[a].n64;return function(){const o=t.addFunction(e+"_buildABC");o.addParam("pCoefs","i32"),o.addParam("nCoefs","i32"),o.addParam("pWitness","i32"),o.addParam("pA","i32"),o.addParam("pB","i32"),o.addParam("pC","i32"),o.addParam("offsetOut","i32"),o.addParam("nOut","i32"),o.addParam("offsetWitness","i32"),o.addParam("nWitness","i32"),o.addLocal("it","i32"),o.addLocal("ita","i32"),o.addLocal("itb","i32"),o.addLocal("last","i32"),o.addLocal("m","i32"),o.addLocal("c","i32"),o.addLocal("s","i32"),o.addLocal("pOut","i32");const n=o.getCodeBuilder(),c=n.i32_const(t.alloc(i));o.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(i)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(a+"_zero",n.getLocal("ita")),n.call(a+"_zero",n.getLocal("itb")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(i))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(i))),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(i+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(i+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(i+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(i+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(i)))),n.call(a+"_mul",n.i32_add(n.getLocal("pWitness"),n.i32_mul(n.i32_sub(n.getLocal("s"),n.getLocal("offsetWitness")),n.i32_const(i))),n.i32_add(n.getLocal("it"),n.i32_const(12)),c),n.call(a+"_add",n.getLocal("pOut"),c,n.getLocal("pOut")),n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(i+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(i)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(a+"_mul",n.getLocal("ita"),n.getLocal("itb"),n.getLocal("it")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(i))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(i))),n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(i))),n.br(0))))}(),function(){const o=t.addFunction(e+"_joinABC");o.addParam("pA","i32"),o.addParam("pB","i32"),o.addParam("pC","i32"),o.addParam("n","i32"),o.addParam("pP","i32"),o.addLocal("ita","i32"),o.addLocal("itb","i32"),o.addLocal("itc","i32"),o.addLocal("itp","i32"),o.addLocal("last","i32");const n=o.getCodeBuilder(),c=n.i32_const(t.alloc(i));o.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(i)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(a+"_mul",n.getLocal("ita"),n.getLocal("itb"),c),n.call(a+"_sub",c,n.getLocal("itc"),n.getLocal("itp")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(i))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(i))),n.setLocal("itc",n.i32_add(n.getLocal("itc"),n.i32_const(i))),n.setLocal("itp",n.i32_add(n.getLocal("itp"),n.i32_const(i))),n.br(0))))}(),function(){const o=t.addFunction(e+"_batchAdd");o.addParam("pa","i32"),o.addParam("pb","i32"),o.addParam("n","i32"),o.addParam("pr","i32"),o.addLocal("ita","i32"),o.addLocal("itb","i32"),o.addLocal("itr","i32"),o.addLocal("last","i32");const n=o.getCodeBuilder();o.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(i)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(a+"_add",n.getLocal("ita"),n.getLocal("itb"),n.getLocal("itr")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(i))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(i))),n.setLocal("itr",n.i32_add(n.getLocal("itr"),n.i32_const(i))),n.br(0))))}(),t.exportFunction(e+"_buildABC"),t.exportFunction(e+"_joinABC"),t.exportFunction(e+"_batchAdd"),e},jt=function(t,e,a,i,o,n,c,r){const l=t.addFunction(e);l.addParam("pIn","i32"),l.addParam("n","i32"),l.addParam("pFirst","i32"),l.addParam("pInc","i32"),l.addParam("pOut","i32"),l.addLocal("pOldFree","i32"),l.addLocal("i","i32"),l.addLocal("pFrom","i32"),l.addLocal("pTo","i32");const s=l.getCodeBuilder(),d=s.i32_const(t.alloc(c));l.addCode(s.setLocal("pFrom",s.getLocal("pIn")),s.setLocal("pTo",s.getLocal("pOut"))),l.addCode(s.call(i+"_copy",s.getLocal("pFirst"),d)),l.addCode(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.call(r,s.getLocal("pFrom"),d,s.getLocal("pTo")),s.setLocal("pFrom",s.i32_add(s.getLocal("pFrom"),s.i32_const(o))),s.setLocal("pTo",s.i32_add(s.getLocal("pTo"),s.i32_const(n))),s.call(i+"_mul",d,s.getLocal("pInc"),d),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0)))),t.exportFunction(e)};const Ht=H,$t=Ct,Yt=Et,Wt=Gt,Zt=Ot,Jt=Mt,Xt=Nt,te=Vt,ee=Kt,ae=jt,{bitLength:ie,modInv:oe,isOdd:ne,isNegative:ce}=J;const re=H,le=Ct,se=Et,de=Gt,ue=Ot,ge=Mt,_e=Nt,fe=Vt,he=Kt,pe=jt,{bitLength:me,isOdd:Le,isNegative:we}=J;var Ae=function(t,e){const a=e||"bn128";if(t.modules[a])return a;const i=21888242871839275222246405745257275088696311157297823662689037894645226208583n,o=21888242871839275222246405745257275088548364400416034343698204186575808495617n,n=Math.floor((ie(i-1n)-1)/64)+1,c=8*n,r=c,l=c,s=2*l,d=12*l,u=t.alloc(Ht.bigInt2BytesLE(o,r)),g=$t(t,i,"f1m");Yt(t,o,"fr","frm");const _=t.alloc(Ht.bigInt2BytesLE(w(3n),l)),f=Jt(t,"g1m","f1m",_);Xt(t,"frm","frm","frm","frm_mul"),te(t,"pol","frm"),ee(t,"qap","frm");const h=Wt(t,"f1m_neg","f2m","f1m"),p=t.alloc([...Ht.bigInt2BytesLE(w(19485874751759354771024239261021720505790618469301721065564631296452457478373n),l),...Ht.bigInt2BytesLE(w(266929791119991161246907387137283842545076965332900288569378510910307636690n),l)]),m=Jt(t,"g2m","f2m",p);function L(e,a){const i=t.addFunction(e);i.addParam("pG","i32"),i.addParam("pFr","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder(),n=o.i32_const(t.alloc(c));i.addCode(o.call("frm_fromMontgomery",o.getLocal("pFr"),n),o.call(a,o.getLocal("pG"),n,o.i32_const(c),o.getLocal("pr"))),t.exportFunction(e)}function w(t){return BigInt(t)*(1n<<BigInt(8*l))%i}L("g1m_timesFr","g1m_timesScalar"),Xt(t,"g1m","g1m","frm","g1m_timesFr"),L("g2m_timesFr","g2m_timesScalar"),Xt(t,"g2m","g2m","frm","g2m_timesFr"),L("g1m_timesFrAffine","g1m_timesScalarAffine"),L("g2m_timesFrAffine","g2m_timesScalarAffine"),ae(t,"frm_batchApplyKey","fmr","frm",c,c,c,"frm_mul"),ae(t,"g1m_batchApplyKey","g1m","frm",3*c,3*c,c,"g1m_timesFr"),ae(t,"g1m_batchApplyKeyMixed","g1m","frm",2*c,3*c,c,"g1m_timesFrAffine"),ae(t,"g2m_batchApplyKey","g2m","frm",2*c*3,3*c*2,c,"g2m_timesFr"),ae(t,"g2m_batchApplyKeyMixed","g2m","frm",2*c*2,3*c*2,c,"g2m_timesFrAffine");const A=[1n,2n,1n],b=t.alloc([...Ht.bigInt2BytesLE(w(A[0]),l),...Ht.bigInt2BytesLE(w(A[1]),l),...Ht.bigInt2BytesLE(w(A[2]),l)]),y=[0n,1n,0n],I=t.alloc([...Ht.bigInt2BytesLE(w(y[0]),l),...Ht.bigInt2BytesLE(w(y[1]),l),...Ht.bigInt2BytesLE(w(y[2]),l)]),C=[[10857046999023057135944570762232829481370756359578518086990519993285655852781n,11559732032986387107991004021392285783925812861821192530917403151452391805634n],[8495653923123431417604973247489272438418190587263600148770280649306958101930n,4082367875863433681332203403145435568316851327593401208105741076214120093531n],[1n,0n]],F=t.alloc([...Ht.bigInt2BytesLE(w(C[0][0]),l),...Ht.bigInt2BytesLE(w(C[0][1]),l),...Ht.bigInt2BytesLE(w(C[1][0]),l),...Ht.bigInt2BytesLE(w(C[1][1]),l),...Ht.bigInt2BytesLE(w(C[2][0]),l),...Ht.bigInt2BytesLE(w(C[2][1]),l)]),x=[[0n,0n],[1n,0n],[0n,0n]],E=t.alloc([...Ht.bigInt2BytesLE(w(x[0][0]),l),...Ht.bigInt2BytesLE(w(x[0][1]),l),...Ht.bigInt2BytesLE(w(x[1][0]),l),...Ht.bigInt2BytesLE(w(x[1][1]),l),...Ht.bigInt2BytesLE(w(x[2][0]),l),...Ht.bigInt2BytesLE(w(x[2][1]),l)]),B=t.alloc([...Ht.bigInt2BytesLE(w(1),l),...Ht.bigInt2BytesLE(w(0),l),...Ht.bigInt2BytesLE(w(0),l),...Ht.bigInt2BytesLE(w(0),l),...Ht.bigInt2BytesLE(w(0),l),...Ht.bigInt2BytesLE(w(0),l),...Ht.bigInt2BytesLE(w(0),l),...Ht.bigInt2BytesLE(w(0),l),...Ht.bigInt2BytesLE(w(0),l),...Ht.bigInt2BytesLE(w(0),l),...Ht.bigInt2BytesLE(w(0),l),...Ht.bigInt2BytesLE(w(0),l)]),v=t.alloc([...Ht.bigInt2BytesLE(w(9),l),...Ht.bigInt2BytesLE(w(1),l)]),S=t.alloc([...Ht.bigInt2BytesLE(w(oe(2n,i)),l),...Ht.bigInt2BytesLE(0n,l)]),G=v,P=t.alloc([...Ht.bigInt2BytesLE(w(19485874751759354771024239261021720505790618469301721065564631296452457478373n),l),...Ht.bigInt2BytesLE(w(266929791119991161246907387137283842545076965332900288569378510910307636690n),l)]);!function(){const e=t.addFunction(a+"_mulNR6");e.addParam("x","i32"),e.addParam("pr","i32");const i=e.getCodeBuilder();e.addCode(i.call(h+"_mul",i.i32_const(v),i.getLocal("x"),i.getLocal("pr")))}();const U=Zt(t,a+"_mulNR6","f6m","f2m");!function(){const e=t.addFunction(a+"_mulNR12");e.addParam("x","i32"),e.addParam("pr","i32");const i=e.getCodeBuilder();e.addCode(i.call(h+"_mul",i.i32_const(v),i.i32_add(i.getLocal("x"),i.i32_const(4*c)),i.getLocal("pr")),i.call(h+"_copy",i.getLocal("x"),i.i32_add(i.getLocal("pr"),i.i32_const(2*c))),i.call(h+"_copy",i.i32_add(i.getLocal("x"),i.i32_const(2*c)),i.i32_add(i.getLocal("pr"),i.i32_const(4*c))))}();const O=Wt(t,a+"_mulNR12","ftm",U),z=function(t){let e=t;const a=[];for(;e>0n;)ne(e)?a.push(1):a.push(0),e>>=1n;return a}(29793968203157093288n),Q=t.alloc(z),q=3*s,M=z.length-1,T=z.reduce(((t,e)=>t+(0!=e?1:0)),0),k=6*c,R=3*c*2+(T+M+1)*q;t.modules[a]={n64:n,pG1gen:b,pG1zero:I,pG1b:_,pG2gen:F,pG2zero:E,pG2b:p,pq:t.modules.f1m.pq,pr:u,pOneT:B,prePSize:k,preQSize:R,r:o.toString(),q:i.toString()};const D=4965661367192848881n;function N(e){const o=[[[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]]],c=t.addFunction(a+"__frobeniusMap"+e);c.addParam("x","i32"),c.addParam("r","i32");const r=c.getCodeBuilder();for(let a=0;a<6;a++){const i=0==a?r.getLocal("x"):r.i32_add(r.getLocal("x"),r.i32_const(a*s)),u=i,_=r.i32_add(r.getLocal("x"),r.i32_const(a*s+l)),f=0==a?r.getLocal("r"):r.i32_add(r.getLocal("r"),r.i32_const(a*s)),p=f,m=r.i32_add(r.getLocal("r"),r.i32_const(a*s+l)),L=d(o[Math.floor(a/3)][e%12],n[a%3][e%6]),A=t.alloc([...Ht.bigInt2BytesLE(w(L[0]),32),...Ht.bigInt2BytesLE(w(L[1]),32)]);e%2==1?c.addCode(r.call(g+"_copy",u,p),r.call(g+"_neg",_,m),r.call(h+"_mul",f,r.i32_const(A),f)):c.addCode(r.call(h+"_mul",i,r.i32_const(A),f))}function d(t,e){const a=BigInt(t[0]),o=BigInt(t[1]),n=BigInt(e[0]),c=BigInt(e[1]),r=[(a*n-o*c)%i,(a*c+o*n)%i];return ce(r[0])&&(r[0]=r[0]+i),r}}function V(e,i){const o=function(t){let e=t;const a=[];for(;e>0n;){if(ne(e)){const t=2-Number(e%4n);a.push(t),e-=BigInt(t)}else a.push(0);e>>=1n}return a}(e).map((t=>-1==t?255:t)),n=t.alloc(o),c=t.addFunction(a+"__cyclotomicExp_"+i);c.addParam("x","i32"),c.addParam("r","i32"),c.addLocal("bit","i32"),c.addLocal("i","i32");const r=c.getCodeBuilder(),l=r.getLocal("x"),s=r.getLocal("r"),u=r.i32_const(t.alloc(d));c.addCode(r.call(O+"_conjugate",l,u),r.call(O+"_one",s),r.if(r.teeLocal("bit",r.i32_load8_s(r.i32_const(o.length-1),n)),r.if(r.i32_eq(r.getLocal("bit"),r.i32_const(1)),r.call(O+"_mul",s,l,s),r.call(O+"_mul",s,u,s))),r.setLocal("i",r.i32_const(o.length-2)),r.block(r.loop(r.call(a+"__cyclotomicSquare",s,s),r.if(r.teeLocal("bit",r.i32_load8_s(r.getLocal("i"),n)),r.if(r.i32_eq(r.getLocal("bit"),r.i32_const(1)),r.call(O+"_mul",s,l,s),r.call(O+"_mul",s,u,s))),r.br_if(1,r.i32_eqz(r.getLocal("i"))),r.setLocal("i",r.i32_sub(r.getLocal("i"),r.i32_const(1))),r.br(0))))}function K(){!function(){const e=t.addFunction(a+"__cyclotomicSquare");e.addParam("x","i32"),e.addParam("r","i32");const i=e.getCodeBuilder(),o=i.getLocal("x"),n=i.i32_add(i.getLocal("x"),i.i32_const(s)),c=i.i32_add(i.getLocal("x"),i.i32_const(2*s)),r=i.i32_add(i.getLocal("x"),i.i32_const(3*s)),l=i.i32_add(i.getLocal("x"),i.i32_const(4*s)),d=i.i32_add(i.getLocal("x"),i.i32_const(5*s)),u=i.getLocal("r"),g=i.i32_add(i.getLocal("r"),i.i32_const(s)),_=i.i32_add(i.getLocal("r"),i.i32_const(2*s)),f=i.i32_add(i.getLocal("r"),i.i32_const(3*s)),p=i.i32_add(i.getLocal("r"),i.i32_const(4*s)),m=i.i32_add(i.getLocal("r"),i.i32_const(5*s)),L=i.i32_const(t.alloc(s)),w=i.i32_const(t.alloc(s)),A=i.i32_const(t.alloc(s)),b=i.i32_const(t.alloc(s)),y=i.i32_const(t.alloc(s)),I=i.i32_const(t.alloc(s)),C=i.i32_const(t.alloc(s)),F=i.i32_const(t.alloc(s));e.addCode(i.call(h+"_mul",o,l,C),i.call(h+"_mul",l,i.i32_const(v),L),i.call(h+"_add",o,L,L),i.call(h+"_add",o,l,F),i.call(h+"_mul",F,L,L),i.call(h+"_mul",i.i32_const(v),C,F),i.call(h+"_add",C,F,F),i.call(h+"_sub",L,F,L),i.call(h+"_add",C,C,w),i.call(h+"_mul",r,c,C),i.call(h+"_mul",c,i.i32_const(v),A),i.call(h+"_add",r,A,A),i.call(h+"_add",r,c,F),i.call(h+"_mul",F,A,A),i.call(h+"_mul",i.i32_const(v),C,F),i.call(h+"_add",C,F,F),i.call(h+"_sub",A,F,A),i.call(h+"_add",C,C,b),i.call(h+"_mul",n,d,C),i.call(h+"_mul",d,i.i32_const(v),y),i.call(h+"_add",n,y,y),i.call(h+"_add",n,d,F),i.call(h+"_mul",F,y,y),i.call(h+"_mul",i.i32_const(v),C,F),i.call(h+"_add",C,F,F),i.call(h+"_sub",y,F,y),i.call(h+"_add",C,C,I),i.call(h+"_sub",L,o,u),i.call(h+"_add",u,u,u),i.call(h+"_add",L,u,u),i.call(h+"_add",w,l,p),i.call(h+"_add",p,p,p),i.call(h+"_add",w,p,p),i.call(h+"_mul",I,i.i32_const(G),F),i.call(h+"_add",F,r,f),i.call(h+"_add",f,f,f),i.call(h+"_add",F,f,f),i.call(h+"_sub",y,c,_),i.call(h+"_add",_,_,_),i.call(h+"_add",y,_,_),i.call(h+"_sub",A,n,g),i.call(h+"_add",g,g,g),i.call(h+"_add",A,g,g),i.call(h+"_add",b,d,m),i.call(h+"_add",m,m,m),i.call(h+"_add",b,m,m))}(),V(D,"w0");const e=t.addFunction(a+"__finalExponentiationLastChunk");e.addParam("x","i32"),e.addParam("r","i32");const i=e.getCodeBuilder(),o=i.getLocal("x"),n=i.getLocal("r"),c=i.i32_const(t.alloc(d)),r=i.i32_const(t.alloc(d)),l=i.i32_const(t.alloc(d)),u=i.i32_const(t.alloc(d)),g=i.i32_const(t.alloc(d)),_=i.i32_const(t.alloc(d)),f=i.i32_const(t.alloc(d)),p=i.i32_const(t.alloc(d)),m=i.i32_const(t.alloc(d)),L=i.i32_const(t.alloc(d)),w=i.i32_const(t.alloc(d)),A=i.i32_const(t.alloc(d)),b=i.i32_const(t.alloc(d)),y=i.i32_const(t.alloc(d)),I=i.i32_const(t.alloc(d)),C=i.i32_const(t.alloc(d)),F=i.i32_const(t.alloc(d)),x=i.i32_const(t.alloc(d)),E=i.i32_const(t.alloc(d)),B=i.i32_const(t.alloc(d)),S=i.i32_const(t.alloc(d));e.addCode(i.call(a+"__cyclotomicExp_w0",o,c),i.call(O+"_conjugate",c,c),i.call(a+"__cyclotomicSquare",c,r),i.call(a+"__cyclotomicSquare",r,l),i.call(O+"_mul",l,r,u),i.call(a+"__cyclotomicExp_w0",u,g),i.call(O+"_conjugate",g,g),i.call(a+"__cyclotomicSquare",g,_),i.call(a+"__cyclotomicExp_w0",_,f),i.call(O+"_conjugate",f,f),i.call(O+"_conjugate",u,p),i.call(O+"_conjugate",f,m),i.call(O+"_mul",m,g,L),i.call(O+"_mul",L,p,w),i.call(O+"_mul",w,r,A),i.call(O+"_mul",w,g,b),i.call(O+"_mul",b,o,y),i.call(a+"__frobeniusMap1",A,I),i.call(O+"_mul",I,y,C),i.call(a+"__frobeniusMap2",w,F),i.call(O+"_mul",F,C,x),i.call(O+"_conjugate",o,E),i.call(O+"_mul",E,A,B),i.call(a+"__frobeniusMap3",B,S),i.call(O+"_mul",S,x,n))}const j=t.alloc(k),H=t.alloc(R);function $(e){const i=t.addFunction(a+"_pairingEq"+e);for(let t=0;t<e;t++)i.addParam("p_"+t,"i32"),i.addParam("q_"+t,"i32");i.addParam("c","i32"),i.setReturnType("i32");const o=i.getCodeBuilder(),n=o.i32_const(t.alloc(d)),c=o.i32_const(t.alloc(d));i.addCode(o.call(O+"_one",n));for(let t=0;t<e;t++)i.addCode(o.call(a+"_prepareG1",o.getLocal("p_"+t),o.i32_const(j))),i.addCode(o.call(a+"_prepareG2",o.getLocal("q_"+t),o.i32_const(H))),i.addCode(o.call(a+"_millerLoop",o.i32_const(j),o.i32_const(H),c)),i.addCode(o.call(O+"_mul",n,c,n));i.addCode(o.call(a+"_finalExponentiation",n,n)),i.addCode(o.call(O+"_eq",n,o.getLocal("c")))}!function(){const e=t.addFunction(a+"_prepAddStep");e.addParam("pQ","i32"),e.addParam("pR","i32"),e.addParam("pCoef","i32");const i=e.getCodeBuilder(),o=i.getLocal("pQ"),n=i.i32_add(i.getLocal("pQ"),i.i32_const(s)),c=i.getLocal("pR"),r=i.i32_add(i.getLocal("pR"),i.i32_const(s)),l=i.i32_add(i.getLocal("pR"),i.i32_const(2*s)),d=i.getLocal("pCoef"),u=i.i32_add(i.getLocal("pCoef"),i.i32_const(s)),g=i.i32_add(i.getLocal("pCoef"),i.i32_const(2*s)),_=u,f=i.i32_const(t.alloc(s)),p=i.i32_const(t.alloc(s)),m=i.i32_const(t.alloc(s)),L=i.i32_const(t.alloc(s)),w=i.i32_const(t.alloc(s)),A=i.i32_const(t.alloc(s)),b=i.i32_const(t.alloc(s));e.addCode(i.call(h+"_mul",o,l,_),i.call(h+"_sub",c,_,_),i.call(h+"_mul",n,l,f),i.call(h+"_sub",r,f,f),i.call(h+"_square",_,p),i.call(h+"_square",f,m),i.call(h+"_mul",_,p,L),i.call(h+"_mul",c,p,w),i.call(h+"_add",w,w,b),i.call(h+"_mul",l,m,A),i.call(h+"_add",L,A,A),i.call(h+"_sub",A,b,A),i.call(h+"_mul",_,A,c),i.call(h+"_mul",L,r,r),i.call(h+"_sub",w,A,b),i.call(h+"_mul",f,b,b),i.call(h+"_sub",b,r,r),i.call(h+"_mul",l,L,l),i.call(h+"_mul",_,n,b),i.call(h+"_mul",f,o,d),i.call(h+"_sub",d,b,d),i.call(h+"_mul",d,i.i32_const(G),d),i.call(h+"_neg",f,g))}(),function(){const e=t.addFunction(a+"_prepDblStep");e.addParam("pR","i32"),e.addParam("pCoef","i32");const i=e.getCodeBuilder(),o=i.getLocal("pR"),n=i.i32_add(i.getLocal("pR"),i.i32_const(s)),c=i.i32_add(i.getLocal("pR"),i.i32_const(2*s)),r=i.getLocal("pCoef"),l=i.i32_add(i.getLocal("pCoef"),i.i32_const(s)),d=i.i32_add(i.getLocal("pCoef"),i.i32_const(2*s)),u=i.i32_const(t.alloc(s)),g=i.i32_const(t.alloc(s)),_=i.i32_const(t.alloc(s)),f=i.i32_const(t.alloc(s)),p=i.i32_const(t.alloc(s)),m=i.i32_const(t.alloc(s)),L=i.i32_const(t.alloc(s)),w=i.i32_const(t.alloc(s)),A=i.i32_const(t.alloc(s)),b=i.i32_const(t.alloc(s)),y=i.i32_const(t.alloc(s)),I=i.i32_const(t.alloc(s));e.addCode(i.call(h+"_mul",n,i.i32_const(S),u),i.call(h+"_mul",o,u,u),i.call(h+"_square",n,g),i.call(h+"_square",c,_),i.call(h+"_add",_,_,f),i.call(h+"_add",f,_,f),i.call(h+"_mul",i.i32_const(P),f,p),i.call(h+"_add",p,p,m),i.call(h+"_add",p,m,m),i.call(h+"_add",g,m,L),i.call(h+"_mul",L,i.i32_const(S),L),i.call(h+"_add",g,_,I),i.call(h+"_add",n,c,w),i.call(h+"_square",w,w),i.call(h+"_sub",w,I,w),i.call(h+"_sub",p,g,A),i.call(h+"_square",o,b),i.call(h+"_square",p,y),i.call(h+"_sub",g,m,I),i.call(h+"_mul",u,I,o),i.call(h+"_add",y,y,I),i.call(h+"_add",y,I,I),i.call(h+"_square",L,n),i.call(h+"_sub",n,I,n),i.call(h+"_mul",g,w,c),i.call(h+"_mul",i.i32_const(G),A,r),i.call(h+"_neg",w,l),i.call(h+"_add",b,b,d),i.call(h+"_add",b,d,d))}(),function(){const e=t.addFunction(a+"_prepareG1");e.addParam("pP","i32"),e.addParam("ppreP","i32");const i=e.getCodeBuilder();e.addCode(i.call(f+"_normalize",i.getLocal("pP"),i.getLocal("ppreP")))}(),function(){!function(){const e=t.addFunction(a+"_mulByQ");e.addParam("p1","i32"),e.addParam("pr","i32");const i=e.getCodeBuilder(),o=i.getLocal("p1"),n=i.i32_add(i.getLocal("p1"),i.i32_const(s)),c=i.i32_add(i.getLocal("p1"),i.i32_const(2*s)),r=i.getLocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(s)),u=i.i32_add(i.getLocal("pr"),i.i32_const(2*s)),g=i.i32_const(t.alloc([...Ht.bigInt2BytesLE(w("21575463638280843010398324269430826099269044274347216827212613867836435027261"),l),...Ht.bigInt2BytesLE(w("10307601595873709700152284273816112264069230130616436755625194854815875713954"),l)])),_=i.i32_const(t.alloc([...Ht.bigInt2BytesLE(w("2821565182194536844548159561693502659359617185244120367078079554186484126554"),l),...Ht.bigInt2BytesLE(w("3505843767911556378687030309984248845540243509899259641013678093033130930403"),l)]));e.addCode(i.call(h+"_conjugate",o,r),i.call(h+"_mul",g,r,r),i.call(h+"_conjugate",n,d),i.call(h+"_mul",_,d,d),i.call(h+"_conjugate",c,u))}();const e=t.addFunction(a+"_prepareG2");e.addParam("pQ","i32"),e.addParam("ppreQ","i32"),e.addLocal("pCoef","i32"),e.addLocal("i","i32");const i=e.getCodeBuilder(),o=i.getLocal("pQ"),n=t.alloc(3*s),c=i.i32_const(n),r=i.i32_const(n),d=i.i32_const(n+s),u=i.i32_const(n+2*s),g=i.i32_add(i.getLocal("ppreQ"),i.i32_const(0)),_=i.i32_add(i.getLocal("ppreQ"),i.i32_const(s)),f=t.alloc(3*s),p=i.i32_const(f),L=t.alloc(3*s),A=i.i32_const(L),b=i.i32_const(L+s);e.addCode(i.call(m+"_normalize",o,g),i.call(h+"_copy",g,r),i.call(h+"_copy",_,d),i.call(h+"_one",u)),e.addCode(i.setLocal("pCoef",i.i32_add(i.getLocal("ppreQ"),i.i32_const(3*s))),i.setLocal("i",i.i32_const(z.length-2)),i.block(i.loop(i.call(a+"_prepDblStep",c,i.getLocal("pCoef")),i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(q))),i.if(i.i32_load8_s(i.getLocal("i"),Q),[...i.call(a+"_prepAddStep",g,c,i.getLocal("pCoef")),...i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(q)))]),i.br_if(1,i.i32_eqz(i.getLocal("i"))),i.setLocal("i",i.i32_sub(i.getLocal("i"),i.i32_const(1))),i.br(0)))),e.addCode(i.call(a+"_mulByQ",g,p),i.call(a+"_mulByQ",p,A)),e.addCode(i.call(h+"_neg",b,b),i.call(a+"_prepAddStep",p,c,i.getLocal("pCoef")),i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(q))),i.call(a+"_prepAddStep",A,c,i.getLocal("pCoef")),i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(q))))}(),function(){const e=t.addFunction(a+"__mulBy024");e.addParam("pEll0","i32"),e.addParam("pEllVW","i32"),e.addParam("pEllVV","i32"),e.addParam("pR","i32");const i=e.getCodeBuilder(),o=i.getLocal("pEll0"),n=i.getLocal("pEllVV"),r=i.getLocal("pEllVW"),l=i.getLocal("pR"),d=i.i32_add(i.getLocal("pR"),i.i32_const(2*c)),u=i.i32_add(i.getLocal("pR"),i.i32_const(4*c)),g=i.i32_add(i.getLocal("pR"),i.i32_const(6*c)),_=i.i32_add(i.getLocal("pR"),i.i32_const(8*c)),f=i.i32_add(i.getLocal("pR"),i.i32_const(10*c)),p=i.i32_const(t.alloc(s)),m=i.i32_const(t.alloc(s)),L=i.i32_const(t.alloc(s)),w=i.i32_const(t.alloc(s)),A=i.i32_const(t.alloc(s)),b=i.i32_const(t.alloc(s)),y=i.i32_const(t.alloc(s)),I=i.i32_const(t.alloc(s)),C=i.i32_const(t.alloc(s)),F=i.i32_const(t.alloc(s)),x=i.i32_const(t.alloc(s));e.addCode(i.call(h+"_mul",l,o,y),i.call(h+"_mul",u,n,I),i.call(h+"_mul",_,r,C),i.call(h+"_add",l,_,L),i.call(h+"_add",l,u,m),i.call(h+"_add",d,g,w),i.call(h+"_add",w,f,w),i.call(h+"_mul",d,n,F),i.call(h+"_add",F,C,A),i.call(h+"_mul",i.i32_const(v),A,b),i.call(h+"_add",b,y,l),i.call(h+"_mul",f,r,A),i.call(h+"_add",F,A,F),i.call(h+"_add",A,I,A),i.call(h+"_mul",i.i32_const(v),A,b),i.call(h+"_mul",d,o,A),i.call(h+"_add",F,A,F),i.call(h+"_add",b,A,d),i.call(h+"_add",o,n,p),i.call(h+"_mul",m,p,A),i.call(h+"_add",y,I,x),i.call(h+"_sub",A,x,A),i.call(h+"_mul",g,r,b),i.call(h+"_add",F,b,F),i.call(h+"_add",u,_,p),i.call(h+"_add",A,b,u),i.call(h+"_add",n,r,m),i.call(h+"_mul",m,p,A),i.call(h+"_add",I,C,x),i.call(h+"_sub",A,x,A),i.call(h+"_mul",i.i32_const(v),A,b),i.call(h+"_mul",g,o,A),i.call(h+"_add",F,A,F),i.call(h+"_add",b,A,g),i.call(h+"_mul",f,n,A),i.call(h+"_add",F,A,F),i.call(h+"_mul",i.i32_const(v),A,b),i.call(h+"_add",o,r,p),i.call(h+"_mul",L,p,A),i.call(h+"_add",y,C,x),i.call(h+"_sub",A,x,A),i.call(h+"_add",b,A,_),i.call(h+"_add",o,n,p),i.call(h+"_add",p,r,p),i.call(h+"_mul",w,p,A),i.call(h+"_sub",A,F,f))}(),function(){const e=t.addFunction(a+"__mulBy024Old");e.addParam("pEll0","i32"),e.addParam("pEllVW","i32"),e.addParam("pEllVV","i32"),e.addParam("pR","i32");const i=e.getCodeBuilder(),o=i.getLocal("pEll0"),n=i.getLocal("pEllVV"),c=i.getLocal("pEllVW"),r=i.getLocal("pR"),l=t.alloc(d),u=i.i32_const(l),g=i.i32_const(l),_=i.i32_const(l+s),f=i.i32_const(l+2*s),p=i.i32_const(l+3*s),m=i.i32_const(l+4*s),L=i.i32_const(l+5*s);e.addCode(i.call(h+"_copy",o,g),i.call(h+"_zero",_),i.call(h+"_copy",n,f),i.call(h+"_zero",p),i.call(h+"_copy",c,m),i.call(h+"_zero",L),i.call(O+"_mul",u,r,r))}(),function(){const e=t.addFunction(a+"_millerLoop");e.addParam("ppreP","i32"),e.addParam("ppreQ","i32"),e.addParam("r","i32"),e.addLocal("pCoef","i32"),e.addLocal("i","i32");const i=e.getCodeBuilder(),o=i.getLocal("ppreP"),n=i.i32_add(i.getLocal("ppreP"),i.i32_const(l)),c=i.getLocal("pCoef"),r=i.i32_add(i.getLocal("pCoef"),i.i32_const(s)),d=i.i32_add(i.getLocal("pCoef"),i.i32_const(2*s)),u=t.alloc(s),g=i.i32_const(u),_=t.alloc(s),f=i.i32_const(_),p=i.getLocal("r");e.addCode(i.call(O+"_one",p),i.setLocal("pCoef",i.i32_add(i.getLocal("ppreQ"),i.i32_const(3*s))),i.setLocal("i",i.i32_const(z.length-2)),i.block(i.loop(i.call(O+"_square",p,p),i.call(h+"_mul1",r,n,g),i.call(h+"_mul1",d,o,f),i.call(a+"__mulBy024",c,g,f,p),i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(q))),i.if(i.i32_load8_s(i.getLocal("i"),Q),[...i.call(h+"_mul1",r,n,g),...i.call(h+"_mul1",d,o,f),...i.call(a+"__mulBy024",c,g,f,p),...i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(q)))]),i.br_if(1,i.i32_eqz(i.getLocal("i"))),i.setLocal("i",i.i32_sub(i.getLocal("i"),i.i32_const(1))),i.br(0)))),e.addCode(i.call(h+"_mul1",r,n,g),i.call(h+"_mul1",d,o,f),i.call(a+"__mulBy024",c,g,f,p),i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(q))),i.call(h+"_mul1",r,n,g),i.call(h+"_mul1",d,o,f),i.call(a+"__mulBy024",c,g,f,p),i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(q))))}();for(let e=0;e<10;e++)N(e),t.exportFunction(a+"__frobeniusMap"+e);!function(){const e=t.addFunction(a+"_finalExponentiationOld");e.addParam("x","i32"),e.addParam("r","i32");const i=t.alloc(Ht.bigInt2BytesLE(552484233613224096312617126783173147097382103762957654188882734314196910839907541213974502761540629817009608548654680343627701153829446747810907373256841551006201639677726139946029199968412598804882391702273019083653272047566316584365559776493027495458238373902875937659943504873220554161550525926302303331747463515644711876653177129578303191095900909191624817826566688241804408081892785725967931714097716709526092261278071952560171111444072049229123565057483750161460024353346284167282452756217662335528813519139808291170539072125381230815729071544861602750936964829313608137325426383735122175229541155376346436093930287402089517426973178917569713384748081827255472576937471496195752727188261435633271238710131736096299798168852925540549342330775279877006784354801422249722573783561685179618816480037695005515426162362431072245638324744480n,352)),o=e.getCodeBuilder();e.addCode(o.call(O+"_exp",o.getLocal("x"),o.i32_const(i),o.i32_const(352),o.getLocal("r")))}(),function(){!function(){const e=t.addFunction(a+"__finalExponentiationFirstChunk");e.addParam("x","i32"),e.addParam("r","i32");const i=e.getCodeBuilder(),o=i.getLocal("x"),n=o,r=i.i32_add(o,i.i32_const(6*c)),l=i.getLocal("r"),s=t.alloc(d),u=i.i32_const(s),g=u,_=i.i32_const(s+6*c),f=i.i32_const(t.alloc(d)),h=i.i32_const(t.alloc(d)),p=i.i32_const(t.alloc(d));e.addCode(i.call(U+"_copy",n,g),i.call(U+"_neg",r,_),i.call(O+"_inverse",o,f),i.call(O+"_mul",u,f,h),i.call(a+"__frobeniusMap2",h,p),i.call(O+"_mul",h,p,l))}(),K();const e=t.addFunction(a+"_finalExponentiation");e.addParam("x","i32"),e.addParam("r","i32");const i=e.getCodeBuilder(),o=i.getLocal("x"),n=i.getLocal("r"),r=i.i32_const(t.alloc(d));e.addCode(i.call(a+"__finalExponentiationFirstChunk",o,r),i.call(a+"__finalExponentiationLastChunk",r,n))}();for(let e=1;e<=5;e++)$(e),t.exportFunction(a+"_pairingEq"+e);!function(){const e=t.addFunction(a+"_pairing");e.addParam("p","i32"),e.addParam("q","i32"),e.addParam("r","i32");const i=e.getCodeBuilder(),o=i.i32_const(t.alloc(d));e.addCode(i.call(a+"_prepareG1",i.getLocal("p"),i.i32_const(j))),e.addCode(i.call(a+"_prepareG2",i.getLocal("q"),i.i32_const(H))),e.addCode(i.call(a+"_millerLoop",i.i32_const(j),i.i32_const(H),o)),e.addCode(i.call(a+"_finalExponentiation",o,i.getLocal("r")))}(),t.exportFunction(a+"_pairing"),t.exportFunction(a+"_prepareG1"),t.exportFunction(a+"_prepareG2"),t.exportFunction(a+"_millerLoop"),t.exportFunction(a+"_finalExponentiation"),t.exportFunction(a+"_finalExponentiationOld"),t.exportFunction(a+"__mulBy024"),t.exportFunction(a+"__mulBy024Old"),t.exportFunction(a+"__cyclotomicSquare"),t.exportFunction(a+"__cyclotomicExp_w0")},be=function(t,e){const a=e||"bls12381";if(t.modules[a])return a;const i=0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaabn,o=0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001n,n=Math.floor((me(i-1n)-1)/64)+1,c=8*n,r=c,l=2*r,s=12*r,d=Math.floor((me(o-1n)-1)/64)+1,u=8*d,g=u,_=t.alloc(re.bigInt2BytesLE(o,g)),f=le(t,i,"f1m","intq");se(t,o,"fr","frm","intr");const h=t.alloc(re.bigInt2BytesLE(b(4n),r)),p=ge(t,"g1m","f1m",h);_e(t,"frm","frm","frm","frm_mul"),fe(t,"pol","frm"),he(t,"qap","frm");const m=de(t,"f1m_neg","f2m","f1m"),L=t.alloc([...re.bigInt2BytesLE(b(4n),r),...re.bigInt2BytesLE(b(4n),r)]),w=ge(t,"g2m","f2m",L);function A(e,a){const i=t.addFunction(e);i.addParam("pG","i32"),i.addParam("pFr","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder(),n=o.i32_const(t.alloc(u));i.addCode(o.call("frm_fromMontgomery",o.getLocal("pFr"),n),o.call(a,o.getLocal("pG"),n,o.i32_const(u),o.getLocal("pr"))),t.exportFunction(e)}function b(t){return BigInt(t)*(1n<<BigInt(8*r))%i}A("g1m_timesFr","g1m_timesScalar"),_e(t,"g1m","g1m","frm","g1m_timesFr"),A("g2m_timesFr","g2m_timesScalar"),_e(t,"g2m","g2m","frm","g2m_timesFr"),A("g1m_timesFrAffine","g1m_timesScalarAffine"),A("g2m_timesFrAffine","g2m_timesScalarAffine"),pe(t,"frm_batchApplyKey","fmr","frm",u,u,u,"frm_mul"),pe(t,"g1m_batchApplyKey","g1m","frm",3*c,3*c,u,"g1m_timesFr"),pe(t,"g1m_batchApplyKeyMixed","g1m","frm",2*c,3*c,u,"g1m_timesFrAffine"),pe(t,"g2m_batchApplyKey","g2m","frm",2*c*3,3*c*2,u,"g2m_timesFr"),pe(t,"g2m_batchApplyKeyMixed","g2m","frm",2*c*2,3*c*2,u,"g2m_timesFrAffine");const y=[3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507n,1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569n,1n],I=t.alloc([...re.bigInt2BytesLE(b(y[0]),r),...re.bigInt2BytesLE(b(y[1]),r),...re.bigInt2BytesLE(b(y[2]),r)]),C=[0n,1n,0n],F=t.alloc([...re.bigInt2BytesLE(b(C[0]),r),...re.bigInt2BytesLE(b(C[1]),r),...re.bigInt2BytesLE(b(C[2]),r)]),x=[[352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160n,3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758n],[1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905n,927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582n],[1n,0n]],E=t.alloc([...re.bigInt2BytesLE(b(x[0][0]),r),...re.bigInt2BytesLE(b(x[0][1]),r),...re.bigInt2BytesLE(b(x[1][0]),r),...re.bigInt2BytesLE(b(x[1][1]),r),...re.bigInt2BytesLE(b(x[2][0]),r),...re.bigInt2BytesLE(b(x[2][1]),r)]),B=[[0n,0n],[1n,0n],[0n,0n]],v=t.alloc([...re.bigInt2BytesLE(b(B[0][0]),r),...re.bigInt2BytesLE(b(B[0][1]),r),...re.bigInt2BytesLE(b(B[1][0]),r),...re.bigInt2BytesLE(b(B[1][1]),r),...re.bigInt2BytesLE(b(B[2][0]),r),...re.bigInt2BytesLE(b(B[2][1]),r)]),S=t.alloc([...re.bigInt2BytesLE(b(1n),r),...re.bigInt2BytesLE(b(0n),r),...re.bigInt2BytesLE(b(0n),r),...re.bigInt2BytesLE(b(0n),r),...re.bigInt2BytesLE(b(0n),r),...re.bigInt2BytesLE(b(0n),r),...re.bigInt2BytesLE(b(0n),r),...re.bigInt2BytesLE(b(0n),r),...re.bigInt2BytesLE(b(0n),r),...re.bigInt2BytesLE(b(0n),r),...re.bigInt2BytesLE(b(0n),r),...re.bigInt2BytesLE(b(0n),r)]),G=t.alloc([...re.bigInt2BytesLE(b(1n),r),...re.bigInt2BytesLE(b(1n),r)]);!function(){const e=t.addFunction(m+"_mulNR");e.addParam("x","i32"),e.addParam("pr","i32");const a=e.getCodeBuilder(),i=a.i32_const(t.alloc(r)),o=a.getLocal("x"),n=a.i32_add(a.getLocal("x"),a.i32_const(r)),c=a.getLocal("pr"),l=a.i32_add(a.getLocal("pr"),a.i32_const(r));e.addCode(a.call(f+"_copy",o,i),a.call(f+"_sub",o,n,c),a.call(f+"_add",i,n,l))}();const P=ue(t,m+"_mulNR","f6m","f2m");!function(){const e=t.addFunction(P+"_mulNR");e.addParam("x","i32"),e.addParam("pr","i32");const a=e.getCodeBuilder(),i=a.i32_const(t.alloc(2*r));e.addCode(a.call(m+"_copy",a.getLocal("x"),i),a.call(m+"_mulNR",a.i32_add(a.getLocal("x"),a.i32_const(4*c)),a.getLocal("pr")),a.call(m+"_copy",a.i32_add(a.getLocal("x"),a.i32_const(2*c)),a.i32_add(a.getLocal("pr"),a.i32_const(4*c))),a.call(m+"_copy",i,a.i32_add(a.getLocal("pr"),a.i32_const(2*c))))}();const U=de(t,P+"_mulNR","ftm",P),O=function(t){let e=t;const a=[];for(;e>0n;)Le(e)?a.push(1):a.push(0),e>>=1n;return a}(0xd201000000010000n),z=t.alloc(O),Q=3*l,q=O.length-1,M=O.reduce(((t,e)=>t+(0!=e?1:0)),0),T=6*c,k=3*c*2+(M+q+1)*Q,R=15132376222941642752n;function D(e){const a=[[[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]]],o=[[[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(U+"_frobeniusMap"+e);n.addParam("x","i32"),n.addParam("r","i32");const s=n.getCodeBuilder();for(let i=0;i<6;i++){const u=0==i?s.getLocal("x"):s.i32_add(s.getLocal("x"),s.i32_const(i*l)),g=u,_=s.i32_add(s.getLocal("x"),s.i32_const(i*l+r)),h=0==i?s.getLocal("r"):s.i32_add(s.getLocal("r"),s.i32_const(i*l)),p=h,L=s.i32_add(s.getLocal("r"),s.i32_const(i*l+r)),w=d(a[Math.floor(i/3)][e%12],o[i%3][e%6]),A=t.alloc([...re.bigInt2BytesLE(b(w[0]),c),...re.bigInt2BytesLE(b(w[1]),c)]);e%2==1?n.addCode(s.call(f+"_copy",g,p),s.call(f+"_neg",_,L),s.call(m+"_mul",h,s.i32_const(A),h)):n.addCode(s.call(m+"_mul",u,s.i32_const(A),h))}function d(t,e){const a=t[0],o=t[1],n=e[0],c=e[1],r=[(a*n-o*c)%i,(a*c+o*n)%i];return we(r[0])&&(r[0]=r[0]+i),r}}function N(e,i,o){const n=function(t){let e=t;const a=[];for(;e>0n;){if(Le(e)){const t=2-Number(e%4n);a.push(t),e-=BigInt(t)}else a.push(0);e>>=1n}return a}(e).map((t=>-1==t?255:t)),c=t.alloc(n),r=t.addFunction(a+"__cyclotomicExp_"+o);r.addParam("x","i32"),r.addParam("r","i32"),r.addLocal("bit","i32"),r.addLocal("i","i32");const l=r.getCodeBuilder(),d=l.getLocal("x"),u=l.getLocal("r"),g=l.i32_const(t.alloc(s));r.addCode(l.call(U+"_conjugate",d,g),l.call(U+"_one",u),l.if(l.teeLocal("bit",l.i32_load8_s(l.i32_const(n.length-1),c)),l.if(l.i32_eq(l.getLocal("bit"),l.i32_const(1)),l.call(U+"_mul",u,d,u),l.call(U+"_mul",u,g,u))),l.setLocal("i",l.i32_const(n.length-2)),l.block(l.loop(l.call(a+"__cyclotomicSquare",u,u),l.if(l.teeLocal("bit",l.i32_load8_s(l.getLocal("i"),c)),l.if(l.i32_eq(l.getLocal("bit"),l.i32_const(1)),l.call(U+"_mul",u,d,u),l.call(U+"_mul",u,g,u))),l.br_if(1,l.i32_eqz(l.getLocal("i"))),l.setLocal("i",l.i32_sub(l.getLocal("i"),l.i32_const(1))),l.br(0)))),i&&r.addCode(l.call(U+"_conjugate",u,u))}t.modules[a]={n64q:n,n64r:d,n8q:c,n8r:u,pG1gen:I,pG1zero:F,pG1b:h,pG2gen:E,pG2zero:v,pG2b:L,pq:t.modules.f1m.pq,pr:_,pOneT:S,r:o,q:i,prePSize:T,preQSize:k},function(){const e=t.addFunction(P+"_mul1");e.addParam("pA","i32"),e.addParam("pC1","i32"),e.addParam("pR","i32");const a=e.getCodeBuilder(),i=a.getLocal("pA"),o=a.i32_add(a.getLocal("pA"),a.i32_const(2*r)),n=a.i32_add(a.getLocal("pA"),a.i32_const(4*r)),c=a.getLocal("pC1"),l=a.getLocal("pR"),s=a.i32_add(a.getLocal("pR"),a.i32_const(2*r)),d=a.i32_add(a.getLocal("pR"),a.i32_const(4*r)),u=a.i32_const(t.alloc(2*r)),g=a.i32_const(t.alloc(2*r));e.addCode(a.call(m+"_add",i,o,u),a.call(m+"_add",o,n,g),a.call(m+"_mul",o,c,d),a.call(m+"_mul",g,c,l),a.call(m+"_sub",l,d,l),a.call(m+"_mulNR",l,l),a.call(m+"_mul",u,c,s),a.call(m+"_sub",s,d,s))}(),function(){const e=t.addFunction(P+"_mul01");e.addParam("pA","i32"),e.addParam("pC0","i32"),e.addParam("pC1","i32"),e.addParam("pR","i32");const a=e.getCodeBuilder(),i=a.getLocal("pA"),o=a.i32_add(a.getLocal("pA"),a.i32_const(2*r)),n=a.i32_add(a.getLocal("pA"),a.i32_const(4*r)),c=a.getLocal("pC0"),l=a.getLocal("pC1"),s=a.getLocal("pR"),d=a.i32_add(a.getLocal("pR"),a.i32_const(2*r)),u=a.i32_add(a.getLocal("pR"),a.i32_const(4*r)),g=a.i32_const(t.alloc(2*r)),_=a.i32_const(t.alloc(2*r)),f=a.i32_const(t.alloc(2*r)),h=a.i32_const(t.alloc(2*r));e.addCode(a.call(m+"_mul",i,c,g),a.call(m+"_mul",o,l,_),a.call(m+"_add",i,o,f),a.call(m+"_add",i,n,h),a.call(m+"_add",o,n,s),a.call(m+"_mul",s,l,s),a.call(m+"_sub",s,_,s),a.call(m+"_mulNR",s,s),a.call(m+"_add",s,g,s),a.call(m+"_add",c,l,d),a.call(m+"_mul",d,f,d),a.call(m+"_sub",d,g,d),a.call(m+"_sub",d,_,d),a.call(m+"_mul",h,c,u),a.call(m+"_sub",u,g,u),a.call(m+"_add",u,_,u))}(),function(){const e=t.addFunction(U+"_mul014");e.addParam("pA","i32"),e.addParam("pC0","i32"),e.addParam("pC1","i32"),e.addParam("pC4","i32"),e.addParam("pR","i32");const a=e.getCodeBuilder(),i=a.getLocal("pA"),o=a.i32_add(a.getLocal("pA"),a.i32_const(6*r)),n=a.getLocal("pC0"),c=a.getLocal("pC1"),l=a.getLocal("pC4"),s=a.i32_const(t.alloc(6*r)),d=a.i32_const(t.alloc(6*r)),u=a.i32_const(t.alloc(2*r)),g=a.getLocal("pR"),_=a.i32_add(a.getLocal("pR"),a.i32_const(6*r));e.addCode(a.call(P+"_mul01",i,n,c,s),a.call(P+"_mul1",o,l,d),a.call(m+"_add",c,l,u),a.call(P+"_add",o,i,_),a.call(P+"_mul01",_,n,u,_),a.call(P+"_sub",_,s,_),a.call(P+"_sub",_,d,_),a.call(P+"_copy",d,g),a.call(P+"_mulNR",g,g),a.call(P+"_add",g,s,g))}(),function(){const e=t.addFunction(a+"_ell");e.addParam("pP","i32"),e.addParam("pCoefs","i32"),e.addParam("pF","i32");const i=e.getCodeBuilder(),o=i.getLocal("pP"),n=i.i32_add(i.getLocal("pP"),i.i32_const(c)),l=i.getLocal("pF"),s=i.getLocal("pCoefs"),d=i.i32_add(i.getLocal("pCoefs"),i.i32_const(r)),u=i.i32_add(i.getLocal("pCoefs"),i.i32_const(2*r)),g=i.i32_add(i.getLocal("pCoefs"),i.i32_const(3*r)),_=i.i32_add(i.getLocal("pCoefs"),i.i32_const(4*r)),h=t.alloc(2*r),p=i.i32_const(h),m=i.i32_const(h),L=i.i32_const(h+r),w=t.alloc(2*r),A=i.i32_const(w),b=i.i32_const(w),y=i.i32_const(w+r);e.addCode(i.call(f+"_mul",s,n,m),i.call(f+"_mul",d,n,L),i.call(f+"_mul",u,o,b),i.call(f+"_mul",g,o,y),i.call(U+"_mul014",l,_,A,p,l))}();const V=t.alloc(T),K=t.alloc(k);function j(e){const i=t.addFunction(a+"_pairingEq"+e);for(let t=0;t<e;t++)i.addParam("p_"+t,"i32"),i.addParam("q_"+t,"i32");i.addParam("c","i32"),i.setReturnType("i32");const o=i.getCodeBuilder(),n=o.i32_const(t.alloc(s)),c=o.i32_const(t.alloc(s));i.addCode(o.call(U+"_one",n));for(let t=0;t<e;t++)i.addCode(o.call(a+"_prepareG1",o.getLocal("p_"+t),o.i32_const(V))),i.addCode(o.call(a+"_prepareG2",o.getLocal("q_"+t),o.i32_const(K))),i.addCode(o.if(o.i32_eqz(o.call(p+"_inGroupAffine",o.i32_const(V))),o.ret(o.i32_const(0))),o.if(o.i32_eqz(o.call(w+"_inGroupAffine",o.i32_const(K))),o.ret(o.i32_const(0)))),i.addCode(o.call(a+"_millerLoop",o.i32_const(V),o.i32_const(K),c)),i.addCode(o.call(U+"_mul",n,c,n));i.addCode(o.call(a+"_finalExponentiation",n,n)),i.addCode(o.call(U+"_eq",n,o.getLocal("c")))}for(let e=0;e<10;e++)D(e),t.exportFunction(U+"_frobeniusMap"+e);!function(){const e=t.addFunction(p+"_inGroupAffine");e.addParam("p","i32"),e.setReturnType("i32");const a=e.getCodeBuilder(),i=(R*R-1n)/3n,o=a.i32_const(t.alloc(re.bigInt2BytesLE(b(4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436n),c))),n=a.i32_const(t.alloc(re.bigInt2BytesLE(b(793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350n),c))),l=a.i32_const(t.alloc(re.bigInt2BytesLE(i,16))),s=a.getLocal("p"),d=a.i32_add(a.getLocal("p"),a.i32_const(r)),u=t.alloc(3*r),g=a.i32_const(u),_=a.i32_const(u),h=a.i32_const(u+r),m=t.alloc(2*r),L=a.i32_const(m),w=a.i32_const(m),A=a.i32_const(m+r);e.addCode(a.if(a.call(p+"_isZeroAffine",a.getLocal("p")),a.ret(a.i32_const(1))),a.if(a.i32_eqz(a.call(p+"_inCurveAffine",a.getLocal("p"))),a.ret(a.i32_const(0))),a.call(f+"_mul",s,o,_),a.call(f+"_copy",d,h),a.call(f+"_mul",s,n,w),a.call(f+"_copy",d,A),a.call(p+"_doubleAffine",g,g),a.call(p+"_subMixed",g,a.getLocal("p"),g),a.call(p+"_subMixed",g,L,g),a.call(p+"_timesScalar",g,l,a.i32_const(16),g),a.ret(a.call(p+"_eqMixed",g,L)));const y=t.addFunction(p+"_inGroup");y.addParam("pIn","i32"),y.setReturnType("i32");const I=y.getCodeBuilder(),C=I.i32_const(t.alloc(2*r));y.addCode(I.call(p+"_toAffine",I.getLocal("pIn"),C),I.ret(I.call(p+"_inGroupAffine",C)))}(),function(){const e=t.addFunction(w+"_inGroupAffine");e.addParam("p","i32"),e.setReturnType("i32");const a=e.getCodeBuilder(),i=[2001204777610833696708894912867952078278441409969503942666029068062015825245418932221343814564507832018947136279894n,2001204777610833696708894912867952078278441409969503942666029068062015825245418932221343814564507832018947136279893n],o=[2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530n,2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530n],n=a.i32_const(t.alloc([...re.bigInt2BytesLE(b(i[0]),c),...re.bigInt2BytesLE(b(i[1]),c)])),s=a.i32_const(t.alloc(re.bigInt2BytesLE(b(4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436n),c))),d=a.i32_const(t.alloc([...re.bigInt2BytesLE(b(o[0]),c),...re.bigInt2BytesLE(b(o[1]),c)])),u=a.i32_const(t.alloc(re.bigInt2BytesLE(R,8))),g=a.getLocal("p"),_=a.i32_add(a.getLocal("p"),a.i32_const(l)),h=a.i32_const(t.alloc(r)),p=a.i32_const(t.alloc(l)),L=a.i32_const(t.alloc(l)),A=t.alloc(2*l),y=a.i32_const(A),I=a.i32_const(A),C=a.i32_const(A),F=a.i32_const(A+r),x=a.i32_const(A+l),E=a.i32_const(A+l),B=a.i32_const(A+l+r),v=t.alloc(3*l),S=a.i32_const(v),G=a.i32_const(v),P=a.i32_const(v),U=a.i32_const(v+r),O=a.i32_const(v+l),z=a.i32_const(v+l),Q=a.i32_const(v+l+r),q=a.i32_const(v+2*l);e.addCode(a.if(a.call(w+"_isZeroAffine",a.getLocal("p")),a.ret(a.i32_const(1))),a.if(a.i32_eqz(a.call(w+"_inCurveAffine",a.getLocal("p"))),a.ret(a.i32_const(0))),a.call(m+"_mul",g,n,p),a.call(m+"_mul",_,n,L),a.call(m+"_mul1",p,s,I),a.call(m+"_neg",L,x),a.call(m+"_neg",p,G),a.call(m+"_mul",L,d,O),a.call(f+"_sub",C,F,h),a.call(f+"_add",C,F,F),a.call(f+"_copy",h,C),a.call(f+"_sub",E,B,h),a.call(f+"_add",E,B,B),a.call(f+"_copy",h,E),a.call(f+"_add",P,U,h),a.call(f+"_sub",P,U,U),a.call(f+"_copy",h,P),a.call(f+"_sub",Q,z,h),a.call(f+"_add",z,Q,Q),a.call(f+"_copy",h,z),a.call(m+"_one",q),a.call(w+"_timesScalar",S,u,a.i32_const(8),S),a.call(w+"_addMixed",S,y,S),a.ret(a.call(w+"_eqMixed",S,a.getLocal("p"))));const M=t.addFunction(w+"_inGroup");M.addParam("pIn","i32"),M.setReturnType("i32");const T=M.getCodeBuilder(),k=T.i32_const(t.alloc(2*l));M.addCode(T.call(w+"_toAffine",T.getLocal("pIn"),k),T.ret(T.call(w+"_inGroupAffine",k)))}(),function(){const e=t.addFunction(a+"_prepAddStep");e.addParam("R","i32"),e.addParam("Q","i32"),e.addParam("r","i32");const i=e.getCodeBuilder(),o=i.getLocal("R"),n=i.i32_add(i.getLocal("R"),i.i32_const(2*c)),r=i.i32_add(i.getLocal("R"),i.i32_const(4*c)),s=i.getLocal("Q"),d=i.i32_add(i.getLocal("Q"),i.i32_const(2*c)),u=i.getLocal("r"),g=i.i32_add(i.getLocal("r"),i.i32_const(2*c)),_=i.i32_add(i.getLocal("r"),i.i32_const(4*c)),f=i.i32_const(t.alloc(l)),h=i.i32_const(t.alloc(l)),p=i.i32_const(t.alloc(l)),L=i.i32_const(t.alloc(l)),w=i.i32_const(t.alloc(l)),A=i.i32_const(t.alloc(l)),b=i.i32_const(t.alloc(l)),y=i.i32_const(t.alloc(l)),I=i.i32_const(t.alloc(l)),C=i.i32_const(t.alloc(l)),F=i.i32_const(t.alloc(l));e.addCode(i.call(m+"_square",r,f),i.call(m+"_square",d,h),i.call(m+"_mul",f,s,L),i.call(m+"_add",d,r,g),i.call(m+"_square",g,g),i.call(m+"_sub",g,h,g),i.call(m+"_sub",g,f,g),i.call(m+"_mul",g,f,g),i.call(m+"_sub",L,o,w),i.call(m+"_square",w,A),i.call(m+"_add",A,A,b),i.call(m+"_add",b,b,b),i.call(m+"_mul",b,w,y),i.call(m+"_sub",g,n,I),i.call(m+"_sub",I,n,I),i.call(m+"_mul",I,s,_),i.call(m+"_mul",b,o,C),i.call(m+"_square",I,o),i.call(m+"_sub",o,y,o),i.call(m+"_sub",o,C,o),i.call(m+"_sub",o,C,o),i.call(m+"_add",r,w,r),i.call(m+"_square",r,r),i.call(m+"_sub",r,f,r),i.call(m+"_sub",r,A,r),i.call(m+"_add",d,r,u),i.call(m+"_sub",C,o,F),i.call(m+"_mul",F,I,F),i.call(m+"_mul",n,y,L),i.call(m+"_add",L,L,L),i.call(m+"_sub",F,L,n),i.call(m+"_square",u,u),i.call(m+"_sub",u,h,u),i.call(m+"_square",r,p),i.call(m+"_sub",u,p,u),i.call(m+"_add",_,_,_),i.call(m+"_sub",_,u,_),i.call(m+"_add",r,r,u),i.call(m+"_neg",I,I),i.call(m+"_add",I,I,g))}(),function(){const e=t.addFunction(a+"_prepDblStep");e.addParam("R","i32"),e.addParam("r","i32");const i=e.getCodeBuilder(),o=i.getLocal("R"),n=i.i32_add(i.getLocal("R"),i.i32_const(2*c)),r=i.i32_add(i.getLocal("R"),i.i32_const(4*c)),s=i.getLocal("r"),d=i.i32_add(i.getLocal("r"),i.i32_const(2*c)),u=i.i32_add(i.getLocal("r"),i.i32_const(4*c)),g=i.i32_const(t.alloc(l)),_=i.i32_const(t.alloc(l)),f=i.i32_const(t.alloc(l)),h=i.i32_const(t.alloc(l)),p=i.i32_const(t.alloc(l));e.addCode(i.call(m+"_square",o,s),i.call(m+"_square",n,_),i.call(m+"_square",_,f),i.call(m+"_add",_,o,d),i.call(m+"_square",d,d),i.call(m+"_sub",d,s,d),i.call(m+"_sub",d,f,d),i.call(m+"_add",d,d,d),i.call(m+"_add",s,s,h),i.call(m+"_add",h,s,h),i.call(m+"_add",o,h,u),i.call(m+"_square",h,p),i.call(m+"_square",r,g),i.call(m+"_sub",p,d,o),i.call(m+"_sub",o,d,o),i.call(m+"_add",r,n,r),i.call(m+"_square",r,r),i.call(m+"_sub",r,_,r),i.call(m+"_sub",r,g,r),i.call(m+"_sub",d,o,n),i.call(m+"_mul",n,h,n),i.call(m+"_add",f,f,f),i.call(m+"_add",f,f,f),i.call(m+"_add",f,f,f),i.call(m+"_sub",n,f,n),i.call(m+"_mul",h,g,d),i.call(m+"_add",d,d,d),i.call(m+"_neg",d,d),i.call(m+"_square",u,u),i.call(m+"_sub",u,s,u),i.call(m+"_sub",u,p,u),i.call(m+"_add",_,_,_),i.call(m+"_add",_,_,_),i.call(m+"_sub",u,_,u),i.call(m+"_mul",r,g,s),i.call(m+"_add",s,s,s))}(),function(){const e=t.addFunction(a+"_prepareG1");e.addParam("pP","i32"),e.addParam("ppreP","i32");const i=e.getCodeBuilder();e.addCode(i.call(p+"_normalize",i.getLocal("pP"),i.getLocal("ppreP")))}(),function(){const e=t.addFunction(a+"_prepareG2");e.addParam("pQ","i32"),e.addParam("ppreQ","i32"),e.addLocal("pCoef","i32"),e.addLocal("i","i32");const i=e.getCodeBuilder(),o=i.getLocal("pQ"),n=t.alloc(3*l),c=i.i32_const(n),r=i.getLocal("ppreQ");e.addCode(i.call(w+"_normalize",o,r),i.if(i.call(w+"_isZero",r),i.ret([])),i.call(w+"_copy",r,c),i.setLocal("pCoef",i.i32_add(i.getLocal("ppreQ"),i.i32_const(3*l)))),e.addCode(i.setLocal("i",i.i32_const(O.length-2)),i.block(i.loop(i.call(a+"_prepDblStep",c,i.getLocal("pCoef")),i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(Q))),i.if(i.i32_load8_s(i.getLocal("i"),z),[...i.call(a+"_prepAddStep",c,r,i.getLocal("pCoef")),...i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(Q)))]),i.br_if(1,i.i32_eqz(i.getLocal("i"))),i.setLocal("i",i.i32_sub(i.getLocal("i"),i.i32_const(1))),i.br(0))))}(),function(){const e=t.addFunction(a+"_millerLoop");e.addParam("ppreP","i32"),e.addParam("ppreQ","i32"),e.addParam("r","i32"),e.addLocal("pCoef","i32"),e.addLocal("i","i32");const i=e.getCodeBuilder(),o=i.getLocal("ppreP"),n=i.getLocal("pCoef"),c=i.getLocal("r");e.addCode(i.call(U+"_one",c),i.if(i.call(p+"_isZero",o),i.ret([])),i.if(i.call(p+"_isZero",i.getLocal("ppreQ")),i.ret([])),i.setLocal("pCoef",i.i32_add(i.getLocal("ppreQ"),i.i32_const(3*l))),i.setLocal("i",i.i32_const(O.length-2)),i.block(i.loop(i.call(a+"_ell",o,n,c),i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(Q))),i.if(i.i32_load8_s(i.getLocal("i"),z),[...i.call(a+"_ell",o,n,c),...i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(Q)))]),i.call(U+"_square",c,c),i.br_if(1,i.i32_eq(i.getLocal("i"),i.i32_const(1))),i.setLocal("i",i.i32_sub(i.getLocal("i"),i.i32_const(1))),i.br(0))),i.call(a+"_ell",o,n,c)),e.addCode(i.call(U+"_conjugate",c,c))}(),function(){const e=t.addFunction(a+"_finalExponentiationOld");e.addParam("x","i32"),e.addParam("r","i32");const i=t.alloc(re.bigInt2BytesLE(322277361516934140462891564586510139908379969514828494218366688025288661041104682794998680497580008899973249814104447692778988208376779573819485263026159588510513834876303014016798809919343532899164848730280942609956670917565618115867287399623286813270357901731510188149934363360381614501334086825442271920079363289954510565375378443704372994881406797882676971082200626541916413184642520269678897559532260949334760604962086348898118982248842634379637598665468817769075878555493752214492790122785850202957575200176084204422751485957336465472324810982833638490904279282696134323072515220044451592646885410572234451732790590013479358343841220074174848221722017083597872017638514103174122784843925578370430843522959600095676285723737049438346544753168912974976791528535276317256904336520179281145394686565050419250614107803233314658825463117900250701199181529205942363159325765991819433914303908860460720581408201373164047773794825411011922305820065611121544561808414055302212057471395719432072209245600258134364584636810093520285711072578721435517884103526483832733289802426157301542744476740008494780363354305116978805620671467071400711358839553375340724899735460480144599782014906586543813292157922220645089192130209334926661588737007768565838519456601560804957985667880395221049249803753582637708560n,544)),o=e.getCodeBuilder();e.addCode(o.call(U+"_exp",o.getLocal("x"),o.i32_const(i),o.i32_const(544),o.getLocal("r")))}(),function(){!function(){const e=t.addFunction(a+"__cyclotomicSquare");e.addParam("x","i32"),e.addParam("r","i32");const i=e.getCodeBuilder(),o=i.getLocal("x"),n=i.i32_add(i.getLocal("x"),i.i32_const(l)),c=i.i32_add(i.getLocal("x"),i.i32_const(2*l)),r=i.i32_add(i.getLocal("x"),i.i32_const(3*l)),s=i.i32_add(i.getLocal("x"),i.i32_const(4*l)),d=i.i32_add(i.getLocal("x"),i.i32_const(5*l)),u=i.getLocal("r"),g=i.i32_add(i.getLocal("r"),i.i32_const(l)),_=i.i32_add(i.getLocal("r"),i.i32_const(2*l)),f=i.i32_add(i.getLocal("r"),i.i32_const(3*l)),h=i.i32_add(i.getLocal("r"),i.i32_const(4*l)),p=i.i32_add(i.getLocal("r"),i.i32_const(5*l)),L=i.i32_const(t.alloc(l)),w=i.i32_const(t.alloc(l)),A=i.i32_const(t.alloc(l)),b=i.i32_const(t.alloc(l)),y=i.i32_const(t.alloc(l)),I=i.i32_const(t.alloc(l)),C=i.i32_const(t.alloc(l)),F=i.i32_const(t.alloc(l));e.addCode(i.call(m+"_mul",o,s,C),i.call(m+"_mulNR",s,L),i.call(m+"_add",o,L,L),i.call(m+"_add",o,s,F),i.call(m+"_mul",F,L,L),i.call(m+"_mulNR",C,F),i.call(m+"_add",C,F,F),i.call(m+"_sub",L,F,L),i.call(m+"_add",C,C,w),i.call(m+"_mul",r,c,C),i.call(m+"_mulNR",c,A),i.call(m+"_add",r,A,A),i.call(m+"_add",r,c,F),i.call(m+"_mul",F,A,A),i.call(m+"_mulNR",C,F),i.call(m+"_add",C,F,F),i.call(m+"_sub",A,F,A),i.call(m+"_add",C,C,b),i.call(m+"_mul",n,d,C),i.call(m+"_mulNR",d,y),i.call(m+"_add",n,y,y),i.call(m+"_add",n,d,F),i.call(m+"_mul",F,y,y),i.call(m+"_mulNR",C,F),i.call(m+"_add",C,F,F),i.call(m+"_sub",y,F,y),i.call(m+"_add",C,C,I),i.call(m+"_sub",L,o,u),i.call(m+"_add",u,u,u),i.call(m+"_add",L,u,u),i.call(m+"_add",w,s,h),i.call(m+"_add",h,h,h),i.call(m+"_add",w,h,h),i.call(m+"_mul",I,i.i32_const(G),F),i.call(m+"_add",F,r,f),i.call(m+"_add",f,f,f),i.call(m+"_add",F,f,f),i.call(m+"_sub",y,c,_),i.call(m+"_add",_,_,_),i.call(m+"_add",y,_,_),i.call(m+"_sub",A,n,g),i.call(m+"_add",g,g,g),i.call(m+"_add",A,g,g),i.call(m+"_add",b,d,p),i.call(m+"_add",p,p,p),i.call(m+"_add",b,p,p))}(),N(R,true,"w0");const e=t.addFunction(a+"_finalExponentiation");e.addParam("x","i32"),e.addParam("r","i32");const i=e.getCodeBuilder(),o=i.getLocal("x"),n=i.getLocal("r"),c=i.i32_const(t.alloc(s)),r=i.i32_const(t.alloc(s)),d=i.i32_const(t.alloc(s)),u=i.i32_const(t.alloc(s)),g=i.i32_const(t.alloc(s)),_=i.i32_const(t.alloc(s)),f=i.i32_const(t.alloc(s));e.addCode(i.call(U+"_frobeniusMap6",o,c),i.call(U+"_inverse",o,r),i.call(U+"_mul",c,r,d),i.call(U+"_copy",d,r),i.call(U+"_frobeniusMap2",d,d),i.call(U+"_mul",d,r,d),i.call(a+"__cyclotomicSquare",d,r),i.call(U+"_conjugate",r,r),i.call(a+"__cyclotomicExp_w0",d,u),i.call(a+"__cyclotomicSquare",u,g),i.call(U+"_mul",r,u,_),i.call(a+"__cyclotomicExp_w0",_,r),i.call(a+"__cyclotomicExp_w0",r,c),i.call(a+"__cyclotomicExp_w0",c,f),i.call(U+"_mul",f,g,f),i.call(a+"__cyclotomicExp_w0",f,g),i.call(U+"_conjugate",_,_),i.call(U+"_mul",g,_,g),i.call(U+"_mul",g,d,g),i.call(U+"_conjugate",d,_),i.call(U+"_mul",r,d,r),i.call(U+"_frobeniusMap3",r,r),i.call(U+"_mul",f,_,f),i.call(U+"_frobeniusMap1",f,f),i.call(U+"_mul",u,c,u),i.call(U+"_frobeniusMap2",u,u),i.call(U+"_mul",u,r,u),i.call(U+"_mul",u,f,u),i.call(U+"_mul",u,g,n))}();for(let e=1;e<=5;e++)j(e),t.exportFunction(a+"_pairingEq"+e);!function(){const e=t.addFunction(a+"_pairing");e.addParam("p","i32"),e.addParam("q","i32"),e.addParam("r","i32");const i=e.getCodeBuilder(),o=i.i32_const(t.alloc(s));e.addCode(i.call(a+"_prepareG1",i.getLocal("p"),i.i32_const(V))),e.addCode(i.call(a+"_prepareG2",i.getLocal("q"),i.i32_const(K))),e.addCode(i.call(a+"_millerLoop",i.i32_const(V),i.i32_const(K),o)),e.addCode(i.call(a+"_finalExponentiation",o,i.getLocal("r")))}(),t.exportFunction(a+"_pairing"),t.exportFunction(a+"_prepareG1"),t.exportFunction(a+"_prepareG2"),t.exportFunction(a+"_millerLoop"),t.exportFunction(a+"_finalExponentiation"),t.exportFunction(a+"_finalExponentiationOld"),t.exportFunction(a+"__cyclotomicSquare"),t.exportFunction(a+"__cyclotomicExp_w0"),t.exportFunction(P+"_mul1"),t.exportFunction(P+"_mul01"),t.exportFunction(U+"_mul014"),t.exportFunction(p+"_inGroupAffine"),t.exportFunction(p+"_inGroup"),t.exportFunction(w+"_inGroupAffine"),t.exportFunction(w+"_inGroup")};function ye(t,e){let a=t;void 0===e&&0==(e=Math.floor((o(t)-1)/8)+1)&&(e=1);const i=new Uint8Array(e),n=new DataView(i.buffer);let c=0;for(;c<e;)c+4<=e?(n.setUint32(c,Number(a&BigInt(4294967295)),!0),c+=4,a>>=BigInt(32)):c+2<=e?(n.setUint16(Number(c,a&BigInt(65535)),!0),c+=2,a>>=BigInt(16)):(n.setUint8(Number(c,a&BigInt(255)),!0),c+=1,a>>=BigInt(8));if(a)throw new Error("Number does not fit in this length");return i}const Ie=[];for(let t=0;t<256;t++)Ie[t]=Ce(t,8);function Ce(t,e){let a=0,i=t;for(let t=0;t<e;t++)a<<=1,a|=1&i,i>>=1;return a}function Fe(t,e){return(Ie[t>>>24]|Ie[t>>>16&255]<<8|Ie[t>>>8&255]<<16|Ie[255&t]<<24)>>>32-e}function xe(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 Ee(t,e){const a=t.byteLength/e,i=xe(a);if(a!=1<<i)throw new Error("Invalid number of pointers");for(let o=0;o<a;o++){const a=Fe(o,i);if(o>a){const i=t.slice(o*e,(o+1)*e);t.set(t.slice(a*e,(a+1)*e),o*e),t.set(i,a*e)}}}function Be(t,e){const a=new Uint8Array(e*t.length);for(let i=0;i<t.length;i++)a.set(t[i],i*e);return a}function ve(t,e){const a=t.byteLength/e,i=new Array(a);for(let o=0;o<a;o++)i[o]=t.slice(o*e,o*e+e);return i}var Se=Object.freeze({__proto__:null,stringifyBigInts:function t(e){if("bigint"==typeof e||void 0!==e.eq)return e.toString(10);if(e instanceof Uint8Array)return E(e,0);if(Array.isArray(e))return e.map(t);if("object"==typeof e){const a={};return Object.keys(e).forEach((i=>{a[i]=t(e[i])})),a}return e},unstringifyBigInts:function t(e){if("string"==typeof e&&/^[0-9]+$/.test(e))return BigInt(e);if("string"==typeof e&&/^0x[0-9a-fA-F]+$/.test(e))return BigInt(e);if(Array.isArray(e))return e.map(t);if("object"==typeof e){if(null===e)return null;const a={};return Object.keys(e).forEach((i=>{a[i]=t(e[i])})),a}return e},beBuff2int:function(t){let e=BigInt(0),a=t.length,i=0;const o=new DataView(t.buffer,t.byteOffset,t.byteLength);for(;a>0;)a>=4?(a-=4,e+=BigInt(o.getUint32(a))<<BigInt(8*i),i+=4):a>=2?(a-=2,e+=BigInt(o.getUint16(a))<<BigInt(8*i),i+=2):(a-=1,e+=BigInt(o.getUint8(a))<<BigInt(8*i),i+=1);return e},beInt2Buff:function(t,e){let a=t;const i=new Uint8Array(e),o=new DataView(i.buffer);let n=e;for(;n>0;)n-4>=0?(n-=4,o.setUint32(n,Number(a&BigInt(4294967295))),a>>=BigInt(32)):n-2>=0?(n-=2,o.setUint16(n,Number(a&BigInt(65535))),a>>=BigInt(16)):(n-=1,o.setUint8(n,Number(a&BigInt(255))),a>>=BigInt(8));if(a)throw new Error("Number does not fit in this length");return i},leBuff2int:function(t){let e=BigInt(0),a=0;const i=new DataView(t.buffer,t.byteOffset,t.byteLength);for(;a<t.length;)a+4<=t.length?(e+=BigInt(i.getUint32(a,!0))<<BigInt(8*a),a+=4):a+4<=t.length?(e+=BigInt(i.getUint16(a,!0))<<BigInt(8*a),a+=2):(e+=BigInt(i.getUint8(a,!0))<<BigInt(8*a),a+=1);return e},leInt2Buff:ye,stringifyFElements:function t(e,a){if("bigint"==typeof a||void 0!==a.eq)return a.toString(10);if(a instanceof Uint8Array)return e.toString(e.e(a));if(Array.isArray(a))return a.map(t.bind(this,e));if("object"==typeof a){const i={};return Object.keys(a).forEach((o=>{i[o]=t(e,a[o])})),i}return a},unstringifyFElements:function t(e,a){if("string"==typeof a&&/^[0-9]+$/.test(a))return e.e(a);if("string"==typeof a&&/^0x[0-9a-fA-F]+$/.test(a))return e.e(a);if(Array.isArray(a))return a.map(t.bind(this,e));if("object"==typeof a){if(null===a)return null;const i={};return Object.keys(a).forEach((o=>{i[o]=t(e,a[o])})),i}return a},bitReverse:Fe,log2:xe,buffReverseBits:Ee,array2buffer:Be,buffer2array:ve});const Ge=1<<30;class Pe{constructor(t){this.buffers=[],this.byteLength=t;for(let e=0;e<t;e+=Ge){const a=Math.min(t-e,Ge);this.buffers.push(new Uint8Array(a))}}slice(t,e){void 0===e&&(e=this.byteLength),void 0===t&&(t=0);const a=e-t,i=Math.floor(t/Ge);if(i==Math.floor((t+a-1)/Ge)||0==a)return this.buffers[i].slice(t%Ge,t%Ge+a);let o,n=i,c=t%Ge,r=a;for(;r>0;){const t=c+r>Ge?Ge-c:r,e=new Uint8Array(this.buffers[n].buffer,this.buffers[n].byteOffset+c,t);if(t==a)return e.slice();o||(o=a<=Ge?new Uint8Array(a):new Pe(a)),o.set(e,a-r),r-=t,n++,c=0}return o}set(t,e){void 0===e&&(e=0);const a=t.byteLength;if(0==a)return;const i=Math.floor(e/Ge);if(i==Math.floor((e+a-1)/Ge))return t instanceof Pe&&1==t.buffers.length?this.buffers[i].set(t.buffers[0],e%Ge):this.buffers[i].set(t,e%Ge);let o=i,n=e%Ge,c=a;for(;c>0;){const e=n+c>Ge?Ge-n:c,i=t.slice(a-c,a-c+e);new Uint8Array(this.buffers[o].buffer,this.buffers[o].byteOffset+n,e).set(i),c-=e,o++,n=0}}}function Ue(t,e,a,i){return async function(o){const n=Math.floor(o.byteLength/a);if(n*a!==o.byteLength)throw new Error("Invalid buffer size");const c=Math.floor(n/t.concurrency),r=[];for(let l=0;l<t.concurrency;l++){let s;if(s=l<t.concurrency-1?c:n-l*c,0==s)continue;const d=[{cmd:"ALLOCSET",var:0,buff:o.slice(l*c*a,l*c*a+s*a)},{cmd:"ALLOC",var:1,len:i*s},{cmd:"CALL",fnName:e,params:[{var:0},{val:s},{var:1}]},{cmd:"GET",out:0,var:1,len:i*s}];r.push(t.queueAction(d))}const l=await Promise.all(r);let s;s=o instanceof Pe?new Pe(n*i):new Uint8Array(n*i);let d=0;for(let t=0;t<l.length;t++)s.set(l[t][0],d),d+=l[t][0].byteLength;return s}}class Oe{constructor(t,e,a,i){if(this.tm=t,this.prefix=e,this.p=i,this.n8=a,this.type="F1",this.m=1,this.half=l(i,P),this.bitLength=o(i),this.mask=h(r(P,this.bitLength),P),this.pOp1=t.alloc(a),this.pOp2=t.alloc(a),this.pOp3=t.alloc(a),this.tm.instance.exports[e+"_zero"](this.pOp1),this.zero=this.tm.getBuff(this.pOp1,this.n8),this.tm.instance.exports[e+"_one"](this.pOp1),this.one=this.tm.getBuff(this.pOp1,this.n8),this.negone=this.neg(this.one),this.two=this.add(this.one,this.one),this.n64=Math.floor(a/8),this.n32=Math.floor(a/4),8*this.n64!=this.n8)throw new Error("n8 must be a multiple of 8");this.half=l(this.p,P),this.nqr=this.two;let n=this.exp(this.nqr,this.half);for(;!this.eq(n,this.negone);)this.nqr=this.add(this.nqr,this.one),n=this.exp(this.nqr,this.half);this.shift=this.mul(this.nqr,this.nqr),this.shiftInv=this.inv(this.shift),this.s=0;let c=h(this.p,P);for(;!u(c);)this.s=this.s+1,c=l(c,P);this.w=[],this.w[this.s]=this.exp(this.nqr,c);for(let t=this.s-1;t>=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=Ue(t,e+"_batchToMontgomery",this.n8,this.n8),this.batchFromMontgomery=Ue(t,e+"_batchFromMontgomery",this.n8,this.n8)}op2(t,e,a){return this.tm.setBuff(this.pOp1,e),this.tm.setBuff(this.pOp2,a),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op2Bool(t,e,a){return this.tm.setBuff(this.pOp1,e),this.tm.setBuff(this.pOp2,a),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2)}op1(t,e){return this.tm.setBuff(this.pOp1,e),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op1Bool(t,e){return this.tm.setBuff(this.pOp1,e),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3)}add(t,e){return this.op2("_add",t,e)}eq(t,e){return this.op2Bool("_eq",t,e)}isZero(t){return this.op1Bool("_isZero",t)}sub(t,e){return this.op2("_sub",t,e)}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,e){return this.op2("_mul",t,e)}div(t,e){return this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,e),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,e){return e instanceof Uint8Array||(e=S(i(e))),this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,e),this.tm.instance.exports[this.prefix+"_exp"](this.pOp1,this.pOp2,e.byteLength,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}isNegative(t){return this.op1Bool("_isNegative",t)}e(t,e){if(t instanceof Uint8Array)return t;let a=i(t,e);n(a)?(a=p(a),y(a,this.p)&&(a=A(a,this.p)),a=h(this.p,a)):y(a,this.p)&&(a=A(a,this.p));const o=ye(a,this.n8);return this.toMontgomery(o)}toString(t,e){return v(E(this.fromMontgomery(t),0),e)}fromRng(t){let e;const a=new Uint8Array(this.n8);do{e=G;for(let a=0;a<this.n64;a++)e=f(e,r(t.nextU64(),64*a));e=C(e,this.mask)}while(I(e,this.p));return F(a,0,e,this.n8),a}random(){return this.fromRng(R())}toObject(t){return E(this.fromMontgomery(t),0)}fromObject(t){const e=new Uint8Array(this.n8);return F(e,0,t,this.n8),this.toMontgomery(e)}toRprLE(t,e,a){t.set(this.fromMontgomery(a),e)}toRprBE(t,e,a){const i=this.fromMontgomery(a);for(let t=0;t<this.n8/2;t++){const e=i[t];i[t]=i[this.n8-1-t],i[this.n8-1-t]=e}t.set(i,e)}fromRprLE(t,e){e=e||0;const a=t.slice(e,e+this.n8);return this.toMontgomery(a)}async batchInverse(t){let e=!1;const a=this.n8,i=this.n8;Array.isArray(t)?(t=Be(t,a),e=!0):t=t.slice(0,t.byteLength);const o=Math.floor(t.byteLength/a);if(o*a!==t.byteLength)throw new Error("Invalid buffer size");const n=Math.floor(o/this.tm.concurrency),c=[];for(let e=0;e<this.tm.concurrency;e++){let r;if(r=e<this.tm.concurrency-1?n:o-e*n,0==r)continue;const l=[{cmd:"ALLOCSET",var:0,buff:t.slice(e*n*a,e*n*a+r*a)},{cmd:"ALLOC",var:1,len:i*r},{cmd:"CALL",fnName:this.prefix+"_batchInverse",params:[{var:0},{val:a},{val:r},{var:1},{val:i}]},{cmd:"GET",out:0,var:1,len:i*r}];c.push(this.tm.queueAction(l))}const r=await Promise.all(c);let l;l=t instanceof Pe?new Pe(o*i):new Uint8Array(o*i);let s=0;for(let t=0;t<r.length;t++)l.set(r[t][0],s),s+=r[t][0].byteLength;return e?ve(l,i):l}}class ze{constructor(t,e,a){this.tm=t,this.prefix=e,this.F=a,this.type="F2",this.m=2*a.m,this.n8=2*this.F.n8,this.n32=2*this.F.n32,this.n64=2*this.F.n64,this.pOp1=t.alloc(2*a.n8),this.pOp2=t.alloc(2*a.n8),this.pOp3=t.alloc(2*a.n8),this.tm.instance.exports[e+"_zero"](this.pOp1),this.zero=t.getBuff(this.pOp1,this.n8),this.tm.instance.exports[e+"_one"](this.pOp1),this.one=t.getBuff(this.pOp1,this.n8),this.negone=this.neg(this.one),this.two=this.add(this.one,this.one)}op2(t,e,a){return this.tm.setBuff(this.pOp1,e),this.tm.setBuff(this.pOp2,a),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op2Bool(t,e,a){return this.tm.setBuff(this.pOp1,e),this.tm.setBuff(this.pOp2,a),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2)}op1(t,e){return this.tm.setBuff(this.pOp1,e),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op1Bool(t,e){return this.tm.setBuff(this.pOp1,e),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3)}add(t,e){return this.op2("_add",t,e)}eq(t,e){return this.op2Bool("_eq",t,e)}isZero(t){return this.op1Bool("_isZero",t)}sub(t,e){return this.op2("_sub",t,e)}neg(t){return this.op1("_neg",t)}inv(t){return this.op1("_inverse",t)}isNegative(t){return this.op1Bool("_isNegative",t)}toMontgomery(t){return this.op1("_toMontgomery",t)}fromMontgomery(t){return this.op1("_fromMontgomery",t)}mul(t,e){return this.op2("_mul",t,e)}mul1(t,e){return this.op2("_mul1",t,e)}div(t,e){return this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,e),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,e){return e instanceof Uint8Array||(e=S(i(e))),this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,e),this.tm.instance.exports[this.prefix+"_exp"](this.pOp1,this.pOp2,e.byteLength,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}e(t,e){if(t instanceof Uint8Array)return t;if(Array.isArray(t)&&2==t.length){const a=this.F.e(t[0],e),i=this.F.e(t[1],e),o=new Uint8Array(2*this.F.n8);return o.set(a),o.set(i,2*this.F.n8),o}throw new Error("invalid F2")}toString(t,e){return`[${this.F.toString(t.slice(0,this.F.n8),e)}, ${this.F.toString(t.slice(this.F.n8),e)}]`}fromRng(t){const e=this.F.fromRng(t),a=this.F.fromRng(t),i=new Uint8Array(2*this.F.n8);return i.set(e),i.set(a,this.F.n8),i}random(){return this.fromRng(R())}toObject(t){return[this.F.toObject(t.slice(0,this.F.n8)),this.F.toObject(t.slice(this.F.n8,2*this.F.n8))]}fromObject(t){const e=new Uint8Array(2*this.F.n8),a=this.F.fromObject(t[0]),i=this.F.fromObject(t[1]);return e.set(a),e.set(i,this.F.n8),e}c1(t){return t.slice(0,this.F.n8)}c2(t){return t.slice(this.F.n8)}}class Qe{constructor(t,e,a){this.tm=t,this.prefix=e,this.F=a,this.type="F3",this.m=3*a.m,this.n8=3*this.F.n8,this.n32=3*this.F.n32,this.n64=3*this.F.n64,this.pOp1=t.alloc(3*a.n8),this.pOp2=t.alloc(3*a.n8),this.pOp3=t.alloc(3*a.n8),this.tm.instance.exports[e+"_zero"](this.pOp1),this.zero=t.getBuff(this.pOp1,this.n8),this.tm.instance.exports[e+"_one"](this.pOp1),this.one=t.getBuff(this.pOp1,this.n8),this.negone=this.neg(this.one),this.two=this.add(this.one,this.one)}op2(t,e,a){return this.tm.setBuff(this.pOp1,e),this.tm.setBuff(this.pOp2,a),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op2Bool(t,e,a){return this.tm.setBuff(this.pOp1,e),this.tm.setBuff(this.pOp2,a),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2)}op1(t,e){return this.tm.setBuff(this.pOp1,e),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op1Bool(t,e){return this.tm.setBuff(this.pOp1,e),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3)}eq(t,e){return this.op2Bool("_eq",t,e)}isZero(t){return this.op1Bool("_isZero",t)}add(t,e){return this.op2("_add",t,e)}sub(t,e){return this.op2("_sub",t,e)}neg(t){return this.op1("_neg",t)}inv(t){return this.op1("_inverse",t)}isNegative(t){return this.op1Bool("_isNegative",t)}toMontgomery(t){return this.op1("_toMontgomery",t)}fromMontgomery(t){return this.op1("_fromMontgomery",t)}mul(t,e){return this.op2("_mul",t,e)}div(t,e){return this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,e),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,e){return e instanceof Uint8Array||(e=S(i(e))),this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,e),this.tm.instance.exports[this.prefix+"_exp"](this.pOp1,this.pOp2,e.byteLength,this.pOp3),this.getBuff(this.pOp3,this.n8)}e(t,e){if(t instanceof Uint8Array)return t;if(Array.isArray(t)&&3==t.length){const a=this.F.e(t[0],e),i=this.F.e(t[1],e),o=this.F.e(t[2],e),n=new Uint8Array(3*this.F.n8);return n.set(a),n.set(i,this.F.n8),n.set(o,2*this.F.n8),n}throw new Error("invalid F3")}toString(t,e){return`[${this.F.toString(t.slice(0,this.F.n8),e)}, ${this.F.toString(t.slice(this.F.n8,2*this.F.n8),e)}, ${this.F.toString(t.slice(2*this.F.n8),e)}]`}fromRng(t){const e=this.F.fromRng(t),a=this.F.fromRng(t),i=this.F.fromRng(t),o=new Uint8Array(3*this.F.n8);return o.set(e),o.set(a,this.F.n8),o.set(i,2*this.F.n8),o}random(){return this.fromRng(R())}toObject(t){return[this.F.toObject(t.slice(0,this.F.n8)),this.F.toObject(t.slice(this.F.n8,2*this.F.n8)),this.F.toObject(t.slice(2*this.F.n8,3*this.F.n8))]}fromObject(t){const e=new Uint8Array(3*this.F.n8),a=this.F.fromObject(t[0]),i=this.F.fromObject(t[1]),o=this.F.fromObject(t[2]);return e.set(a),e.set(i,this.F.n8),e.set(o,2*this.F.n8),e}c1(t){return t.slice(0,this.F.n8)}c2(t){return t.slice(this.F.n8,2*this.F.n8)}c3(t){return t.slice(2*this.F.n8)}}class qe{constructor(t,e,a,i,o,n){this.tm=t,this.prefix=e,this.F=a,this.pOp1=t.alloc(3*a.n8),this.pOp2=t.alloc(3*a.n8),this.pOp3=t.alloc(3*a.n8),this.tm.instance.exports[e+"_zero"](this.pOp1),this.zero=this.tm.getBuff(this.pOp1,3*a.n8),this.tm.instance.exports[e+"_zeroAffine"](this.pOp1),this.zeroAffine=this.tm.getBuff(this.pOp1,2*a.n8),this.one=this.tm.getBuff(i,3*a.n8),this.g=this.one,this.oneAffine=this.tm.getBuff(i,2*a.n8),this.gAffine=this.oneAffine,this.b=this.tm.getBuff(o,a.n8),n&&(this.cofactor=S(n)),this.negone=this.neg(this.one),this.two=this.add(this.one,this.one),this.batchLEMtoC=Ue(t,e+"_batchLEMtoC",2*a.n8,a.n8),this.batchLEMtoU=Ue(t,e+"_batchLEMtoU",2*a.n8,2*a.n8),this.batchCtoLEM=Ue(t,e+"_batchCtoLEM",a.n8,2*a.n8),this.batchUtoLEM=Ue(t,e+"_batchUtoLEM",2*a.n8,2*a.n8),this.batchToJacobian=Ue(t,e+"_batchToJacobian",2*a.n8,3*a.n8),this.batchToAffine=Ue(t,e+"_batchToAffine",3*a.n8,2*a.n8)}op2(t,e,a){return this.tm.setBuff(this.pOp1,e),this.tm.setBuff(this.pOp2,a),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,3*this.F.n8)}op2bool(t,e,a){return this.tm.setBuff(this.pOp1,e),this.tm.setBuff(this.pOp2,a),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2,this.pOp3)}op1(t,e){return this.tm.setBuff(this.pOp1,e),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3),this.tm.getBuff(this.pOp3,3*this.F.n8)}op1Affine(t,e){return this.tm.setBuff(this.pOp1,e),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3),this.tm.getBuff(this.pOp3,2*this.F.n8)}op1Bool(t,e){return this.tm.setBuff(this.pOp1,e),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3)}add(t,e){if(t.byteLength==3*this.F.n8){if(e.byteLength==3*this.F.n8)return this.op2("_add",t,e);if(e.byteLength==2*this.F.n8)return this.op2("_addMixed",t,e);throw new Error("invalid point size")}if(t.byteLength==2*this.F.n8){if(e.byteLength==3*this.F.n8)return this.op2("_addMixed",e,t);if(e.byteLength==2*this.F.n8)return this.op2("_addAffine",t,e);throw new Error("invalid point size")}throw new Error("invalid point size")}sub(t,e){if(t.byteLength==3*this.F.n8){if(e.byteLength==3*this.F.n8)return this.op2("_sub",t,e);if(e.byteLength==2*this.F.n8)return this.op2("_subMixed",t,e);throw new Error("invalid point size")}if(t.byteLength==2*this.F.n8){if(e.byteLength==3*this.F.n8)return this.op2("_subMixed",e,t);if(e.byteLength==2*this.F.n8)return this.op2("_subAffine",t,e);throw new Error("invalid point size")}throw new Error("invalid point size")}neg(t){if(t.byteLength==3*this.F.n8)return this.op1("_neg",t);if(t.byteLength==2*this.F.n8)return this.op1Affine("_negAffine",t);throw new Error("invalid point size")}double(t){if(t.byteLength==3*this.F.n8)return this.op1("_double",t);if(t.byteLength==2*this.F.n8)return this.op1("_doubleAffine",t);throw new Error("invalid point size")}isZero(t){if(t.byteLength==3*this.F.n8)return this.op1Bool("_isZero",t);if(t.byteLength==2*this.F.n8)return this.op1Bool("_isZeroAffine",t);throw new Error("invalid point size")}timesScalar(t,e){let a;if(e instanceof Uint8Array||(e=S(i(e))),t.byteLength==3*this.F.n8)a=this.prefix+"_timesScalar";else{if(t.byteLength!=2*this.F.n8)throw new Error("invalid point size");a=this.prefix+"_timesScalarAffine"}return this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,e),this.tm.instance.exports[a](this.pOp1,this.pOp2,e.byteLength,this.pOp3),this.tm.getBuff(this.pOp3,3*this.F.n8)}timesFr(t,e){let a;if(t.byteLength==3*this.F.n8)a=this.prefix+"_timesFr";else{if(t.byteLength!=2*this.F.n8)throw new Error("invalid point size");a=this.prefix+"_timesFrAffine"}return this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,e),this.tm.instance.exports[a](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,3*this.F.n8)}eq(t,e){if(t.byteLength==3*this.F.n8){if(e.byteLength==3*this.F.n8)return this.op2bool("_eq",t,e);if(e.byteLength==2*this.F.n8)return this.op2bool("_eqMixed",t,e);throw new Error("invalid point size")}if(t.byteLength==2*this.F.n8){if(e.byteLength==3*this.F.n8)return this.op2bool("_eqMixed",e,t);if(e.byteLength==2*this.F.n8)return this.op2bool("_eqAffine",t,e);throw new Error("invalid point size")}throw new Error("invalid point size")}toAffine(t){if(t.byteLength==3*this.F.n8)return this.op1Affine("_toAffine",t);if(t.byteLength==2*this.F.n8)return t;throw new Error("invalid point size")}toJacobian(t){if(t.byteLength==3*this.F.n8)return t;if(t.byteLength==2*this.F.n8)return this.op1("_toJacobian",t);throw new Error("invalid point size")}toRprUncompressed(t,e,a){if(this.tm.setBuff(this.pOp1,a),a.byteLength==3*this.F.n8)this.tm.instance.exports[this.prefix+"_toAffine"](this.pOp1,this.pOp1);else if(a.byteLength!=2*this.F.n8)throw new Error("invalid point size");this.tm.instance.exports[this.prefix+"_LEMtoU"](this.pOp1,this.pOp1);const i=this.tm.getBuff(this.pOp1,2*this.F.n8);t.set(i,e)}fromRprUncompressed(t,e){const a=t.slice(e,e+2*this.F.n8);return this.tm.setBuff(this.pOp1,a),this.tm.instance.exports[this.prefix+"_UtoLEM"](this.pOp1,this.pOp1),this.tm.getBuff(this.pOp1,2*this.F.n8)}toRprCompressed(t,e,a){if(this.tm.setBuff(this.pOp1,a),a.byteLength==3*this.F.n8)this.tm.instance.exports[this.prefix+"_toAffine"](this.pOp1,this.pOp1);else if(a.byteLength!=2*this.F.n8)throw new Error("invalid point size");this.tm.instance.exports[this.prefix+"_LEMtoC"](this.pOp1,this.pOp1);const i=this.tm.getBuff(this.pOp1,this.F.n8);t.set(i,e)}fromRprCompressed(t,e){const a=t.slice(e,e+this.F.n8);return this.tm.setBuff(this.pOp1,a),this.tm.instance.exports[this.prefix+"_CtoLEM"](this.pOp1,this.pOp2),this.tm.getBuff(this.pOp2,2*this.F.n8)}toUncompressed(t){const e=new Uint8Array(2*this.F.n8);return this.toRprUncompressed(e,0,t),e}toRprLEM(t,e,a){if(a.byteLength!=2*this.F.n8){if(a.byteLength!=3*this.F.n8)throw new Error("invalid point size");{this.tm.setBuff(this.pOp1,a),this.tm.instance.exports[this.prefix+"_toAffine"](this.pOp1,this.pOp1);const i=this.tm.getBuff(this.pOp1,2*this.F.n8);t.set(i,e)}}else t.set(a,e)}fromRprLEM(t,e){return e=e||0,t.slice(e,e+2*this.F.n8)}toString(t,e){if(t.byteLength==3*this.F.n8){return`[ ${this.F.toString(t.slice(0,this.F.n8),e)}, ${this.F.toString(t.slice(this.F.n8,2*this.F.n8),e)}, ${this.F.toString(t.slice(2*this.F.n8),e)} ]`}if(t.byteLength==2*this.F.n8){return`[ ${this.F.toString(t.slice(0,this.F.n8),e)}, ${this.F.toString(t.slice(this.F.n8),e)} ]`}throw new Error("invalid point size")}isValid(t){if(this.isZero(t))return!0;const e=this.F,a=this.toAffine(t),i=a.slice(0,this.F.n8),o=a.slice(this.F.n8,2*this.F.n8),n=e.add(e.mul(e.square(i),i),this.b),c=e.square(o);return e.eq(n,c)}fromRng(t){const e=this.F;let a,i,o=[];do{o[0]=e.fromRng(t),a=t.nextBool(),i=e.add(e.mul(e.square(o[0]),o[0]),this.b)}while(!e.isSquare(i));o[1]=e.sqrt(i);a^e.isNegative(o[1])&&(o[1]=e.neg(o[1]));let n=new Uint8Array(2*this.F.n8);return n.set(o[0]),n.set(o[1],this.F.n8),this.cofactor&&(n=this.timesScalar(n,this.cofactor)),n}toObject(t){if(this.isZero(t))return[this.F.toObject(this.F.zero),this.F.toObject(this.F.one),this.F.toObject(this.F.zero)];const e=this.F.toObject(t.slice(0,this.F.n8)),a=this.F.toObject(t.slice(this.F.n8,2*this.F.n8));let i;return i=t.byteLength==3*this.F.n8?this.F.toObject(t.slice(2*this.F.n8,3*this.F.n8)):this.F.toObject(this.F.one),[e,a,i]}fromObject(t){const e=this.F.fromObject(t[0]),a=this.F.fromObject(t[1]);let i;if(i=3==t.length?this.F.fromObject(t[2]):this.F.one,this.F.isZero(i,this.F.one))return this.zeroAffine;if(this.F.eq(i,this.F.one)){const t=new Uint8Array(2*this.F.n8);return t.set(e),t.set(a,this.F.n8),t}{const t=new Uint8Array(3*this.F.n8);return t.set(e),t.set(a,this.F.n8),t.set(i,2*this.F.n8),t}}e(t){return t instanceof Uint8Array?t:this.fromObject(t)}x(t){return this.toAffine(t).slice(0,this.F.n8)}y(t){return this.toAffine(t).slice(this.F.n8)}}function Me(t){const e=32767;let a,i;async function o(t){const o=new Uint8Array(t.code),n=await WebAssembly.compile(o);i=new WebAssembly.Memory({initial:t.init,maximum:e}),a=await WebAssembly.instantiate(n,{env:{memory:i}})}function n(t){const a=new Uint32Array(i.buffer,0,1);for(;3&a[0];)a[0]++;const o=a[0];if(a[0]+=t,a[0]+t>i.buffer.byteLength){const o=i.buffer.byteLength/65536;let n=Math.floor((a[0]+t)/65536)+1;n>e&&(n=e),i.grow(n-o)}return o}function c(t){const e=n(t.byteLength);return l(e,t),e}function r(t,e){const a=new Uint8Array(i.buffer);return new Uint8Array(a.buffer,a.byteOffset+t,e)}function l(t,e){new Uint8Array(i.buffer).set(new Uint8Array(e),t)}function s(t){if("INIT"==t[0].cmd)return o(t[0]);const e={vars:[],out:[]},s=new Uint32Array(i.buffer,0,1)[0];for(let i=0;i<t.length;i++)switch(t[i].cmd){case"ALLOCSET":e.vars[t[i].var]=c(t[i].buff);break;case"ALLOC":e.vars[t[i].var]=n(t[i].len);break;case"SET":l(e.vars[t[i].var],t[i].buff);break;case"CALL":{const o=[];for(let a=0;a<t[i].params.length;a++){const n=t[i].params[a];void 0!==n.var?o.push(e.vars[n.var]+(n.offset||0)):void 0!==n.val&&o.push(n.val)}a.exports[t[i].fnName](...o);break}case"GET":e.out[t[i].out]=r(e.vars[t[i].var],t[i].len).slice();break;default:throw new Error("Invalid cmd")}return new Uint32Array(i.buffer,0,1)[0]=s,e.out}return t&&(t.onmessage=function(e){let a;if(a=e.data?e.data:e,"INIT"==a[0].cmd)o(a[0]).then((function(){t.postMessage(a.result)}));else if("TERMINATE"==a[0].cmd)t.close();else{const e=s(a);t.postMessage(e)}}),s}var Te={},ke=Worker;class Re{constructor(){this.promise=new Promise(((t,e)=>{this.reject=e,this.resolve=t}))}}var De;const Ne="data:application/javascript;base64,"+(De="("+Me.toString()+")(self)",globalThis.btoa(De));class Ve{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,e,a,i){if(this.working[t])throw new Error("Posting a job t a working worker");return this.working[t]=!0,this.pendingDeferreds[t]=i||new Re,this.workers[t].postMessage(e,a),this.pendingDeferreds[t].promise}processWorks(){for(let t=0;t<this.workers.length&&this.actionQueue.length>0;t++)if(0==this.working[t]){const e=this.actionQueue.shift();this.postAction(t,e.data,e.transfers,e.deferred)}}queueAction(t,e){const a=new Re;if(this.singleThread){const e=this.taskManager(t);a.resolve(e)}else this.actionQueue.push({data:t,transfers:e,deferred:a}),this.processWorks();return a.promise}resetMemory(){this.u32[0]=this.initalPFree}allocBuff(t){const e=this.alloc(t.byteLength);return this.setBuff(e,t),e}getBuff(t,e){return this.u8.slice(t,t+e)}setBuff(t,e){this.u8.set(new Uint8Array(e),t)}alloc(t){for(;3&this.u32[0];)this.u32[0]++;const e=this.u32[0];return this.u32[0]+=t,e}async terminate(){for(let t=0;t<this.workers.length;t++)this.workers[t].postMessage([{cmd:"TERMINATE"}]);var t;await(t=200,new Promise((e=>setTimeout(e,t))))}}function Ke(t,e){const a=t[e],i=t.Fr,o=t.tm;t[e].batchApplyKey=async function(t,n,c,r,l){let s,d,u,g,_;if(r=r||"affine",l=l||"affine","G1"==e)"jacobian"==r?(u=3*a.F.n8,s="g1m_batchApplyKey"):(u=2*a.F.n8,s="g1m_batchApplyKeyMixed"),g=3*a.F.n8,"jacobian"==l?_=3*a.F.n8:(d="g1m_batchToAffine",_=2*a.F.n8);else if("G2"==e)"jacobian"==r?(u=3*a.F.n8,s="g2m_batchApplyKey"):(u=2*a.F.n8,s="g2m_batchApplyKeyMixed"),g=3*a.F.n8,"jacobian"==l?_=3*a.F.n8:(d="g2m_batchToAffine",_=2*a.F.n8);else{if("Fr"!=e)throw new Error("Invalid group: "+e);s="frm_batchApplyKey",u=a.n8,g=a.n8,_=a.n8}const f=Math.floor(t.byteLength/u),h=Math.floor(f/o.concurrency),p=[];c=i.e(c);let m=i.e(n);for(let e=0;e<o.concurrency;e++){let a;if(a=e<o.concurrency-1?h:f-e*h,0==a)continue;const n=[];n.push({cmd:"ALLOCSET",var:0,buff:t.slice(e*h*u,e*h*u+a*u)}),n.push({cmd:"ALLOCSET",var:1,buff:m}),n.push({cmd:"ALLOCSET",var:2,buff:c}),n.push({cmd:"ALLOC",var:3,len:a*Math.max(g,_)}),n.push({cmd:"CALL",fnName:s,params:[{var:0},{val:a},{var:1},{var:2},{var:3}]}),d&&n.push({cmd:"CALL",fnName:d,params:[{var:3},{val:a},{var:3}]}),n.push({cmd:"GET",out:0,var:3,len:a*_}),p.push(o.queueAction(n)),m=i.mul(m,i.exp(c,a))}const L=await Promise.all(p);let w;w=t instanceof Pe?new Pe(f*_):new Uint8Array(f*_);let A=0;for(let t=0;t<L.length;t++)w.set(L[t][0],A),A+=L[t][0].byteLength;return w}}const je=[1,1,1,1,2,3,4,5,6,7,7,8,9,10,11,12,13,13,14,15,16,16,17,17,17,17,17,17,17,17,17,17];function He(t,e){const a=t[e],i=a.tm;async function o(t,i,o,n,c){if(!(t instanceof Uint8Array))throw n&&n.error(`${c} _multiExpChunk buffBases is not Uint8Array`),new Error(`${c} _multiExpChunk buffBases is not Uint8Array`);if(!(i instanceof Uint8Array))throw n&&n.error(`${c} _multiExpChunk buffScalars is not Uint8Array`),new Error(`${c} _multiExpChunk buffScalars is not Uint8Array`);let r,l;if(o=o||"affine","G1"==e)"affine"==o?(l="g1m_multiexpAffine_chunk",r=2*a.F.n8):(l="g1m_multiexp_chunk",r=3*a.F.n8);else{if("G2"!=e)throw new Error("Invalid group");"affine"==o?(l="g2m_multiexpAffine_chunk",r=2*a.F.n8):(l="g2m_multiexp_chunk",r=3*a.F.n8)}const s=Math.floor(t.byteLength/r);if(0==s)return a.zero;const d=Math.floor(i.byteLength/s);if(d*s!=i.byteLength)throw new Error("Scalar size does not match");const u=je[xe(s)],g=Math.floor((8*d-1)/u)+1,_=[];for(let e=0;e<g;e++){const o=[{cmd:"ALLOCSET",var:0,buff:t},{cmd:"ALLOCSET",var:1,buff:i},{cmd:"ALLOC",var:2,len:3*a.F.n8},{cmd:"CALL",fnName:l,params:[{var:0},{var:1},{val:d},{val:s},{val:e*u},{val:Math.min(8*d-e*u,u)},{var:2}]},{cmd:"GET",out:0,var:2,len:3*a.F.n8}];_.push(a.tm.queueAction(o))}const f=await Promise.all(_);let h=a.zero;for(let t=f.length-1;t>=0;t--){if(!a.isZero(h))for(let t=0;t<u;t++)h=a.double(h);h=a.add(h,f[t][0])}return h}async function n(t,n,c,r,l){const s=1<<22;let d;if("G1"==e)d="affine"==c?2*a.F.n8:3*a.F.n8;else{if("G2"!=e)throw new Error("Invalid group");d="affine"==c?2*a.F.n8:3*a.F.n8}const u=Math.floor(t.byteLength/d),g=Math.floor(n.byteLength/u);if(g*u!=n.byteLength)throw new Error("Scalar size does not match");const _=je[xe(u)],f=Math.floor((8*g-1)/_)+1;let h;h=Math.floor(u/(i.concurrency/f)),h>s&&(h=s),h<1024&&(h=1024);const p=[];for(let e=0;e<u;e+=h){r&&r.debug(`Multiexp start: ${l}: ${e}/${u}`);const a=Math.min(u-e,h),i=t.slice(e*d,(e+a)*d),s=n.slice(e*g,(e+a)*g);p.push(o(i,s,c,r,l).then((t=>(r&&r.debug(`Multiexp end: ${l}: ${e}/${u}`),t))))}const m=await Promise.all(p);let L=a.zero;for(let t=m.length-1;t>=0;t--)L=a.add(L,m[t]);return L}a.multiExp=async function(t,e,a,i){return await n(t,e,"jacobian",a,i)},a.multiExpAffine=async function(t,e,a,i){return await n(t,e,"affine",a,i)}}function $e(t,e){const a=t[e],i=t.Fr,o=a.tm;async function n(t,r,l,s,d,u){l=l||"affine",s=s||"affine";let g,_,f,h,p,m,L,w;"G1"==e?("affine"==l?(g=2*a.F.n8,h="g1m_batchToJacobian"):g=3*a.F.n8,_=3*a.F.n8,r&&(w="g1m_fftFinal"),L="g1m_fftJoin",m="g1m_fftMix","affine"==s?(f=2*a.F.n8,p="g1m_batchToAffine"):f=3*a.F.n8):"G2"==e?("affine"==l?(g=2*a.F.n8,h="g2m_batchToJacobian"):g=3*a.F.n8,_=3*a.F.n8,r&&(w="g2m_fftFinal"),L="g2m_fftJoin",m="g2m_fftMix","affine"==s?(f=2*a.F.n8,p="g2m_batchToAffine"):f=3*a.F.n8):"Fr"==e&&(g=a.n8,_=a.n8,f=a.n8,r&&(w="frm_fftFinal"),m="frm_fftMix",L="frm_fftJoin");let A=!1;Array.isArray(t)?(t=Be(t,g),A=!0):t=t.slice(0,t.byteLength);const b=t.byteLength/g,y=xe(b);if(1<<y!=b)throw new Error("fft must be multiple of 2");if(y==i.s+1){let e;return e=r?await async function(t,e,a,o,r){let l,s;l=t.slice(0,t.byteLength/2),s=t.slice(t.byteLength/2,t.byteLength);const d=[];d.push(n(l,!0,e,"jacobian",o,r)),d.push(n(s,!0,e,"jacobian",o,r)),[l,s]=await Promise.all(d);const u=await c(l,s,"fftJoinExtInv",i.one,i.shiftInv,"jacobian",a,o,r);let g;g=u[0].byteLength>1<<28?new Pe(2*u[0].byteLength):new Uint8Array(2*u[0].byteLength);return g.set(u[0]),g.set(u[1],u[0].byteLength),g}(t,l,s,d,u):await async function(t,e,a,o,r){let l,s;l=t.slice(0,t.byteLength/2),s=t.slice(t.byteLength/2,t.byteLength);const d=[];[l,s]=await c(l,s,"fftJoinExt",i.one,i.shift,e,"jacobian",o,r),d.push(n(l,!1,"jacobian",a,o,r)),d.push(n(s,!1,"jacobian",a,o,r));const u=await Promise.all(d);let g;g=u[0].byteLength>1<<28?new Pe(2*u[0].byteLength):new Uint8Array(2*u[0].byteLength);return g.set(u[0]),g.set(u[1],u[0].byteLength),g}(t,l,s,d,u),A?ve(e,f):e}let I,C,F;r&&(I=i.inv(i.e(b))),Ee(t,g);let x=Math.min(16384,b),E=b/x;for(;E<o.concurrency&&x>=16;)E*=2,x/=2;const B=xe(x),v=[];for(let e=0;e<E;e++){d&&d.debug(`${u}: fft ${y} mix start: ${e}/${E}`);const a=[];a.push({cmd:"ALLOC",var:0,len:_*x});const i=t.slice(x*e*g,x*(e+1)*g);a.push({cmd:"SET",var:0,buff:i}),h&&a.push({cmd:"CALL",fnName:h,params:[{var:0},{val:x},{var:0}]});for(let t=1;t<=B;t++)a.push({cmd:"CALL",fnName:m,params:[{var:0},{val:x},{val:t}]});B==y?(w&&(a.push({cmd:"ALLOCSET",var:1,buff:I}),a.push({cmd:"CALL",fnName:w,params:[{var:0},{val:x},{var:1}]})),p&&a.push({cmd:"CALL",fnName:p,params:[{var:0},{val:x},{var:0}]}),a.push({cmd:"GET",out:0,var:0,len:x*f})):a.push({cmd:"GET",out:0,var:0,len:_*x}),v.push(o.queueAction(a).then((t=>(d&&d.debug(`${u}: fft ${y} mix end: ${e}/${E}`),t))))}F=await Promise.all(v);for(let t=0;t<E;t++)F[t]=F[t][0];for(let t=B+1;t<=y;t++){d&&d.debug(`${u}: fft ${y} join: ${t}/${y}`);const e=1<<y-t,a=E/e,n=[];for(let c=0;c<e;c++)for(let r=0;r<a/2;r++){const l=i.exp(i.w[t],r*x),s=i.w[t],g=c*a+r,h=c*a+r+a/2,m=[];m.push({cmd:"ALLOCSET",var:0,buff:F[g]}),m.push({cmd:"ALLOCSET",var:1,buff:F[h]}),m.push({cmd:"ALLOCSET",var:2,buff:l}),m.push({cmd:"ALLOCSET",var:3,buff:s}),m.push({cmd:"CALL",fnName:L,params:[{var:0},{var:1},{val:x},{var:2},{var:3}]}),t==y?(w&&(m.push({cmd:"ALLOCSET",var:4,buff:I}),m.push({cmd:"CALL",fnName:w,params:[{var:0},{val:x},{var:4}]}),m.push({cmd:"CALL",fnName:w,params:[{var:1},{val:x},{var:4}]})),p&&(m.push({cmd:"CALL",fnName:p,params:[{var:0},{val:x},{var:0}]}),m.push({cmd:"CALL",fnName:p,params:[{var:1},{val:x},{var:1}]})),m.push({cmd:"GET",out:0,var:0,len:x*f}),m.push({cmd:"GET",out:1,var:1,len:x*f})):(m.push({cmd:"GET",out:0,var:0,len:x*_}),m.push({cmd:"GET",out:1,var:1,len:x*_})),n.push(o.queueAction(m).then((i=>(d&&d.debug(`${u}: fft ${y} join ${t}/${y} ${c+1}/${e} ${r}/${a/2}`),i))))}const c=await Promise.all(n);for(let t=0;t<e;t++)for(let e=0;e<a/2;e++){const i=t*a+e,o=t*a+e+a/2,n=c.shift();F[i]=n[0],F[o]=n[1]}}if(C=t instanceof Pe?new Pe(b*f):new Uint8Array(b*f),r){C.set(F[0].slice((x-1)*f));let t=f;for(let e=E-1;e>0;e--)C.set(F[e],t),t+=x*f,delete F[e];C.set(F[0].slice(0,(x-1)*f),t),delete F[0]}else for(let t=0;t<E;t++)C.set(F[t],x*f*t),delete F[t];return A?ve(C,f):C}async function c(t,n,c,r,l,s,d,u,g){let _,f,h,p,m,L;if("G1"==e)"affine"==s?(m=2*a.F.n8,f="g1m_batchToJacobian"):m=3*a.F.n8,L=3*a.F.n8,_="g1m_"+c,"affine"==d?(h="g1m_batchToAffine",p=2*a.F.n8):p=3*a.F.n8;else if("G2"==e)"affine"==s?(m=2*a.F.n8,f="g2m_batchToJacobian"):m=3*a.F.n8,_="g2m_"+c,L=3*a.F.n8,"affine"==d?(h="g2m_batchToAffine",p=2*a.F.n8):p=3*a.F.n8;else{if("Fr"!=e)throw new Error("Invalid group");m=i.n8,p=i.n8,L=i.n8,_="frm_"+c}if(t.byteLength!=n.byteLength)throw new Error("Invalid buffer size");const w=Math.floor(t.byteLength/m);if(w!=1<<xe(w))throw new Error("Invalid number of points");let A=Math.floor(w/o.concurrency);A<16&&(A=16),A>65536&&(A=65536);const b=[];for(let e=0;e<w;e+=A){u&&u.debug(`${g}: fftJoinExt Start: ${e}/${w}`);const a=Math.min(w-e,A),c=i.mul(r,i.exp(l,e)),s=[],d=t.slice(e*m,(e+a)*m),y=n.slice(e*m,(e+a)*m);s.push({cmd:"ALLOC",var:0,len:L*a}),s.push({cmd:"SET",var:0,buff:d}),s.push({cmd:"ALLOC",var:1,len:L*a}),s.push({cmd:"SET",var:1,buff:y}),s.push({cmd:"ALLOCSET",var:2,buff:c}),s.push({cmd:"ALLOCSET",var:3,buff:l}),f&&(s.push({cmd:"CALL",fnName:f,params:[{var:0},{val:a},{var:0}]}),s.push({cmd:"CALL",fnName:f,params:[{var:1},{val:a},{var:1}]})),s.push({cmd:"CALL",fnName:_,params:[{var:0},{var:1},{val:a},{var:2},{var:3},{val:i.s}]}),h&&(s.push({cmd:"CALL",fnName:h,params:[{var:0},{val:a},{var:0}]}),s.push({cmd:"CALL",fnName:h,params:[{var:1},{val:a},{var:1}]})),s.push({cmd:"GET",out:0,var:0,len:a*p}),s.push({cmd:"GET",out:1,var:1,len:a*p}),b.push(o.queueAction(s).then((t=>(u&&u.debug(`${g}: fftJoinExt End: ${e}/${w}`),t))))}const y=await Promise.all(b);let I,C;w*p>1<<28?(I=new Pe(w*p),C=new Pe(w*p)):(I=new Uint8Array(w*p),C=new Uint8Array(w*p));let F=0;for(let t=0;t<y.length;t++)I.set(y[t][0],F),C.set(y[t][1],F),F+=y[t][0].byteLength;return[I,C]}a.fft=async function(t,e,a,i,o){return await n(t,!1,e,a,i,o)},a.ifft=async function(t,e,a,i,o){return await n(t,!0,e,a,i,o)},a.lagrangeEvaluations=async function(t,o,r,l,s){let d;if(o=o||"affine",r=r||"affine","G1"==e)d="affine"==o?2*a.F.n8:3*a.F.n8;else if("G2"==e)d="affine"==o?2*a.F.n8:3*a.F.n8;else{if("Fr"!=e)throw new Error("Invalid group");d=i.n8}const u=t.byteLength/d,g=xe(u);if(2**g*d!=t.byteLength)throw l&&l.error("lagrangeEvaluations iinvalid input size"),new Error("lagrangeEvaluations invalid Input size");if(g<=i.s)return await a.ifft(t,o,r,l,s);if(g>i.s+1)throw l&&l.error("lagrangeEvaluations input too big"),new Error("lagrangeEvaluations input too big");let _=t.slice(0,t.byteLength/2),f=t.slice(t.byteLength/2,t.byteLength);const h=i.exp(i.shift,u/2),p=i.inv(i.sub(i.one,h));[_,f]=await c(_,f,"prepareLagrangeEvaluation",p,i.shiftInv,o,"jacobian",l,s+" prep");const m=[];let L;return m.push(n(_,!0,"jacobian",r,l,s+" t0")),m.push(n(f,!0,"jacobian",r,l,s+" t1")),[_,f]=await Promise.all(m),L=_.byteLength>1<<28?new Pe(2*_.byteLength):new Uint8Array(2*_.byteLength),L.set(_),L.set(f,_.byteLength),L},a.fftMix=async function(t){const n=3*a.F.n8;let c,r;if("G1"==e)c="g1m_fftMix",r="g1m_fftJoin";else if("G2"==e)c="g2m_fftMix",r="g2m_fftJoin";else{if("Fr"!=e)throw new Error("Invalid group");c="frm_fftMix",r="frm_fftJoin"}const l=Math.floor(t.byteLength/n),s=xe(l);let d=1<<xe(o.concurrency);l<=2*d&&(d=1);const u=l/d,g=xe(u),_=[];for(let e=0;e<d;e++){const a=[],i=t.slice(e*u*n,(e+1)*u*n);a.push({cmd:"ALLOCSET",var:0,buff:i});for(let t=1;t<=g;t++)a.push({cmd:"CALL",fnName:c,params:[{var:0},{val:u},{val:t}]});a.push({cmd:"GET",out:0,var:0,len:u*n}),_.push(o.queueAction(a))}const f=await Promise.all(_),h=[];for(let t=0;t<f.length;t++)h[t]=f[t][0];for(let t=g+1;t<=s;t++){const e=1<<s-t,a=d/e,c=[];for(let l=0;l<e;l++)for(let e=0;e<a/2;e++){const s=i.exp(i.w[t],e*u),d=i.w[t],g=l*a+e,_=l*a+e+a/2,f=[];f.push({cmd:"ALLOCSET",var:0,buff:h[g]}),f.push({cmd:"ALLOCSET",var:1,buff:h[_]}),f.push({cmd:"ALLOCSET",var:2,buff:s}),f.push({cmd:"ALLOCSET",var:3,buff:d}),f.push({cmd:"CALL",fnName:r,params:[{var:0},{var:1},{val:u},{var:2},{var:3}]}),f.push({cmd:"GET",out:0,var:0,len:u*n}),f.push({cmd:"GET",out:1,var:1,len:u*n}),c.push(o.queueAction(f))}const l=await Promise.all(c);for(let t=0;t<e;t++)for(let e=0;e<a/2;e++){const i=t*a+e,o=t*a+e+a/2,n=l.shift();h[i]=n[0],h[o]=n[1]}}let p;p=t instanceof Pe?new Pe(l*n):new Uint8Array(l*n);let m=0;for(let t=0;t<d;t++)p.set(h[t],m),m+=h[t].byteLength;return p},a.fftJoin=async function(t,n,c,r){const l=3*a.F.n8;let s;if("G1"==e)s="g1m_fftJoin";else if("G2"==e)s="g2m_fftJoin";else{if("Fr"!=e)throw new Error("Invalid group");s="frm_fftJoin"}if(t.byteLength!=n.byteLength)throw new Error("Invalid buffer size");const d=Math.floor(t.byteLength/l);if(d!=1<<xe(d))throw new Error("Invalid number of points");let u=1<<xe(o.concurrency);d<=2*u&&(u=1);const g=d/u,_=[];for(let e=0;e<u;e++){const a=[],d=i.mul(c,i.exp(r,e*g)),u=t.slice(e*g*l,(e+1)*g*l),f=n.slice(e*g*l,(e+1)*g*l);a.push({cmd:"ALLOCSET",var:0,buff:u}),a.push({cmd:"ALLOCSET",var:1,buff:f}),a.push({cmd:"ALLOCSET",var:2,buff:d}),a.push({cmd:"ALLOCSET",var:3,buff:r}),a.push({cmd:"CALL",fnName:s,params:[{var:0},{var:1},{val:g},{var:2},{var:3}]}),a.push({cmd:"GET",out:0,var:0,len:g*l}),a.push({cmd:"GET",out:1,var:1,len:g*l}),_.push(o.queueAction(a))}const f=await Promise.all(_);let h,p;t instanceof Pe?(h=new Pe(d*l),p=new Pe(d*l)):(h=new Uint8Array(d*l),p=new Uint8Array(d*l));let m=0;for(let t=0;t<f.length;t++)h.set(f[t][0],m),p.set(f[t][1],m),m+=f[t][0].byteLength;return[h,p]},a.fftFinal=async function(t,i){const n=3*a.F.n8,c=2*a.F.n8;let r,l;if("G1"==e)r="g1m_fftFinal",l="g1m_batchToAffine";else{if("G2"!=e)throw new Error("Invalid group");r="g2m_fftFinal",l="g2m_batchToAffine"}const s=Math.floor(t.byteLength/n);if(s!=1<<xe(s))throw new Error("Invalid number of points");const d=Math.floor(s/o.concurrency),u=[];for(let e=0;e<o.concurrency;e++){let a;if(a=e<o.concurrency-1?d:s-e*d,0==a)continue;const g=[],_=t.slice(e*d*n,(e*d+a)*n);g.push({cmd:"ALLOCSET",var:0,buff:_}),g.push({cmd:"ALLOCSET",var:1,buff:i}),g.push({cmd:"CALL",fnName:r,params:[{var:0},{val:a},{var:1}]}),g.push({cmd:"CALL",fnName:l,params:[{var:0},{val:a},{var:0}]}),g.push({cmd:"GET",out:0,var:0,len:a*c}),u.push(o.queueAction(g))}const g=await Promise.all(u);let _;_=t instanceof Pe?new Pe(s*c):new Uint8Array(s*c);let f=0;for(let t=g.length-1;t>=0;t--)_.set(g[t][0],f),f+=g[t][0].byteLength;return _}}async function Ye(t){const e=await async function(t,e){const a=new Ve;a.memory=new WebAssembly.Memory({initial:25}),a.u8=new Uint8Array(a.memory.buffer),a.u32=new Uint32Array(a.memory.buffer);const i=await WebAssembly.compile(t.code);if(a.instance=await WebAssembly.instantiate(i,{env:{memory:a.memory}}),a.singleThread=e,a.initalPFree=a.u32[0],a.pq=t.pq,a.pr=t.pr,a.pG1gen=t.pG1gen,a.pG1zero=t.pG1zero,a.pG2gen=t.pG2gen,a.pG2zero=t.pG2zero,a.pOneT=t.pOneT,e)a.code=t.code,a.taskManager=Me(),await a.taskManager([{cmd:"INIT",init:25,code:a.code.slice()}]),a.concurrency=1;else{let e;a.workers=[],a.pendingDeferreds=[],a.working=[],e="object"==typeof navigator&&navigator.hardwareConcurrency?navigator.hardwareConcurrency:Te.cpus().length,0==e&&(e=2),e>64&&(e=64),a.concurrency=e;for(let t=0;t<e;t++)a.workers[t]=new ke(Ne),a.workers[t].addEventListener("message",o(t)),a.working[t]=!1;const i=[];for(let e=0;e<a.workers.length;e++){const o=t.code.slice();i.push(a.postAction(e,[{cmd:"INIT",init:25,code:o}],[o.buffer]))}await Promise.all(i)}return a;function o(t){return function(e){let i;i=e&&e.data?e.data:e,a.working[t]=!1,a.pendingDeferreds[t].resolve(i),a.processWorks()}}}(t.wasm,t.singleThread),a={};return a.q=i(t.wasm.q.toString()),a.r=i(t.wasm.r.toString()),a.name=t.name,a.tm=e,a.prePSize=t.wasm.prePSize,a.preQSize=t.wasm.preQSize,a.Fr=new Oe(e,"frm",t.n8r,t.r),a.F1=new Oe(e,"f1m",t.n8q,t.q),a.F2=new ze(e,"f2m",a.F1),a.G1=new qe(e,"g1m",a.F1,t.wasm.pG1gen,t.wasm.pG1b,t.cofactorG1),a.G2=new qe(e,"g2m",a.F2,t.wasm.pG2gen,t.wasm.pG2b,t.cofactorG2),a.F6=new Qe(e,"f6m",a.F2),a.F12=new ze(e,"ftm",a.F6),a.Gt=a.F12,Ke(a,"G1"),Ke(a,"G2"),Ke(a,"Fr"),He(a,"G1"),He(a,"G2"),$e(a,"G1"),$e(a,"G2"),$e(a,"Fr"),function(t){const e=t.tm;t.pairing=function(a,i){e.startSyncOp();const o=e.allocBuff(t.G1.toJacobian(a)),n=e.allocBuff(t.G2.toJacobian(i)),c=e.alloc(t.Gt.n8);e.instance.exports[t.name+"_pairing"](o,n,c);const r=e.getBuff(c,t.Gt.n8);return e.endSyncOp(),r},t.pairingEq=async function(){let a,i;arguments.length%2==1?(a=arguments[arguments.length-1],i=(arguments.length-1)/2):(a=t.Gt.one,i=arguments.length/2);const o=[];for(let a=0;a<i;a++){const i=[],n=t.G1.toJacobian(arguments[2*a]);i.push({cmd:"ALLOCSET",var:0,buff:n}),i.push({cmd:"ALLOC",var:1,len:t.prePSize});const c=t.G2.toJacobian(arguments[2*a+1]);i.push({cmd:"ALLOCSET",var:2,buff:c}),i.push({cmd:"ALLOC",var:3,len:t.preQSize}),i.push({cmd:"ALLOC",var:4,len:t.Gt.n8}),i.push({cmd:"CALL",fnName:t.name+"_prepareG1",params:[{var:0},{var:1}]}),i.push({cmd:"CALL",fnName:t.name+"_prepareG2",params:[{var:2},{var:3}]}),i.push({cmd:"CALL",fnName:t.name+"_millerLoop",params:[{var:1},{var:3},{var:4}]}),i.push({cmd:"GET",out:0,var:4,len:t.Gt.n8}),o.push(e.queueAction(i))}const n=await Promise.all(o);e.startSyncOp();const c=e.alloc(t.Gt.n8);e.instance.exports.ftm_one(c);for(let t=0;t<n.length;t++){const a=e.allocBuff(n[t][0]);e.instance.exports.ftm_mul(c,a,c)}e.instance.exports[t.name+"_finalExponentiation"](c,c);const r=e.allocBuff(a),l=!!e.instance.exports.ftm_eq(c,r);return e.endSyncOp(),l},t.prepareG1=function(t){this.tm.startSyncOp();const e=this.tm.allocBuff(t),a=this.tm.alloc(this.prePSize);this.tm.instance.exports[this.name+"_prepareG1"](e,a);const i=this.tm.getBuff(a,this.prePSize);return this.tm.endSyncOp(),i},t.prepareG2=function(t){this.tm.startSyncOp();const e=this.tm.allocBuff(t),a=this.tm.alloc(this.preQSize);this.tm.instance.exports[this.name+"_prepareG2"](e,a);const i=this.tm.getBuff(a,this.preQSize);return this.tm.endSyncOp(),i},t.millerLoop=function(t,e){this.tm.startSyncOp();const a=this.tm.allocBuff(t),i=this.tm.allocBuff(e),o=this.tm.alloc(this.Gt.n8);this.tm.instance.exports[this.name+"_millerLoop"](a,i,o);const n=this.tm.getBuff(o,this.Gt.n8);return this.tm.endSyncOp(),n},t.finalExponentiation=function(t){this.tm.startSyncOp();const e=this.tm.allocBuff(t),a=this.tm.alloc(this.Gt.n8);this.tm.instance.exports[this.name+"_finalExponentiation"](e,a);const i=this.tm.getBuff(a,this.Gt.n8);return this.tm.endSyncOp(),i}}(a),a.array2buffer=function(t,e){const a=new Uint8Array(e*t.length);for(let i=0;i<t.length;i++)a.set(t[i],i*e);return a},a.buffer2array=function(t,e){const a=t.byteLength/e,i=new Array(a);for(let o=0;o<a;o++)i[o]=t.slice(o*e,o*e+e);return i},a}function We(t){return BigInt(t)}function Ze(t){return t<0n}function Je(t){return 0n===t}function Xe(t){const e=[],a=We(t);return e.push(Number(0xFFn&a)),e.push(Number(a>>8n&0xFFn)),e.push(Number(a>>16n&0xFFn)),e.push(Number(a>>24n&0xFFn)),e}function ta(t){const e=function(t){for(var e=[],a=0;a<t.length;a++){var i=t.charCodeAt(a);i<128?e.push(i):i<2048?e.push(192|i>>6,128|63&i):i<55296||i>=57344?e.push(224|i>>12,128|i>>6&63,128|63&i):(a++,i=65536+((1023&i)<<10|1023&t.charCodeAt(a)),e.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|63&i))}return e}(t);return[...na(e.length),...e]}function ea(t){const e=[];let a=We(t);if(Ze(a))throw new Error("Number cannot be negative");for(;!Je(a);)e.push(Number(0x7Fn&a)),a>>=7n;0==e.length&&e.push(0);for(let t=0;t<e.length-1;t++)e[t]=128|e[t];return e}function aa(t){let e,a;const i=function(t){return Ze(t)?t.toString(2).length-1:t.toString(2).length}(t);t<0?(a=!0,e=(1n<<BigInt(i))+t):(a=!1,e=We(t));const o=7-i%7,n=(1<<7-o)-1|128,c=ea(e+((1n<<BigInt(o))-1n<<BigInt(i)));return a||(c[c.length-1]=c[c.length-1]&n),c}function ia(t){let e=We(t);if(e>0xFFFFFFFFn)throw new Error("Number too big");if(e>0x7FFFFFFFn&&(e-=0x100000000n),e<-2147483648n)throw new Error("Number too small");return aa(e)}function oa(t){let e=We(t);if(e>0xFFFFFFFFFFFFFFFFn)throw new Error("Number too big");if(e>0x7FFFFFFFFFFFFFFFn&&(e-=0x10000000000000000n),e<-9223372036854775808n)throw new Error("Number too small");return aa(e)}function na(t){let e=We(t);if(e>0xFFFFFFFFn)throw new Error("Number too big");return ea(e)}function ca(t){return Array.from(t,(function(t){return("0"+(255&t).toString(16)).slice(-2)})).join("")}class ra{constructor(t){this.func=t,this.functionName=t.functionName,this.module=t.module}setLocal(t,e){const a=this.func.localIdxByName[t];if(void 0===a)throw new Error(`Local Variable not defined: Function: ${this.functionName} local: ${t} `);return[...e,33,...na(a)]}teeLocal(t,e){const a=this.func.localIdxByName[t];if(void 0===a)throw new Error(`Local Variable not defined: Function: ${this.functionName} local: ${t} `);return[...e,34,...na(a)]}getLocal(t){const e=this.func.localIdxByName[t];if(void 0===e)throw new Error(`Local Variable not defined: Function: ${this.functionName} local: ${t} `);return[32,...na(e)]}i64_load8_s(t,e,a){return[...t,48,void 0===a?0:a,...na(e||0)]}i64_load8_u(t,e,a){return[...t,49,void 0===a?0:a,...na(e||0)]}i64_load16_s(t,e,a){return[...t,50,void 0===a?1:a,...na(e||0)]}i64_load16_u(t,e,a){return[...t,51,void 0===a?1:a,...na(e||0)]}i64_load32_s(t,e,a){return[...t,52,void 0===a?2:a,...na(e||0)]}i64_load32_u(t,e,a){return[...t,53,void 0===a?2:a,...na(e||0)]}i64_load(t,e,a){return[...t,41,void 0===a?3:a,...na(e||0)]}i64_store(t,e,a,i){let o,n,c;return Array.isArray(e)?(o=0,n=3,c=e):Array.isArray(a)?(o=e,n=3,c=a):Array.isArray(i)&&(o=e,n=a,c=i),[...t,...c,55,n,...na(o)]}i64_store32(t,e,a,i){let o,n,c;return Array.isArray(e)?(o=0,n=2,c=e):Array.isArray(a)?(o=e,n=2,c=a):Array.isArray(i)&&(o=e,n=a,c=i),[...t,...c,62,n,...na(o)]}i64_store16(t,e,a,i){let o,n,c;return Array.isArray(e)?(o=0,n=1,c=e):Array.isArray(a)?(o=e,n=1,c=a):Array.isArray(i)&&(o=e,n=a,c=i),[...t,...c,61,n,...na(o)]}i64_store8(t,e,a,i){let o,n,c;return Array.isArray(e)?(o=0,n=0,c=e):Array.isArray(a)?(o=e,n=0,c=a):Array.isArray(i)&&(o=e,n=a,c=i),[...t,...c,60,n,...na(o)]}i32_load8_s(t,e,a){return[...t,44,void 0===a?0:a,...na(e||0)]}i32_load8_u(t,e,a){return[...t,45,void 0===a?0:a,...na(e||0)]}i32_load16_s(t,e,a){return[...t,46,void 0===a?1:a,...na(e||0)]}i32_load16_u(t,e,a){return[...t,47,void 0===a?1:a,...na(e||0)]}i32_load(t,e,a){return[...t,40,void 0===a?2:a,...na(e||0)]}i32_store(t,e,a,i){let o,n,c;return Array.isArray(e)?(o=0,n=2,c=e):Array.isArray(a)?(o=e,n=2,c=a):Array.isArray(i)&&(o=e,n=a,c=i),[...t,...c,54,n,...na(o)]}i32_store16(t,e,a,i){let o,n,c;return Array.isArray(e)?(o=0,n=1,c=e):Array.isArray(a)?(o=e,n=1,c=a):Array.isArray(i)&&(o=e,n=a,c=i),[...t,...c,59,n,...na(o)]}i32_store8(t,e,a,i){let o,n,c;return Array.isArray(e)?(o=0,n=0,c=e):Array.isArray(a)?(o=e,n=0,c=a):Array.isArray(i)&&(o=e,n=a,c=i),[...t,...c,58,n,...na(o)]}call(t,...e){const a=this.module.functionIdxByName[t];if(void 0===a)throw new Error(`Function not defined: Function: ${t}`);return[...[].concat(...e),16,...na(a)]}call_indirect(t,...e){return[...[].concat(...e),...t,17,0,0]}if(t,e,a){return a?[...t,4,64,...e,5,...a,11]:[...t,4,64,...e,11]}block(t){return[2,64,...t,11]}loop(...t){return[3,64,...[].concat(...t),11]}br_if(t,e){return[...e,13,...na(t)]}br(t){return[12,...na(t)]}ret(t){return[...t,15]}drop(t){return[...t,26]}i64_const(t){return[66,...oa(t)]}i32_const(t){return[65,...ia(t)]}i64_eqz(t){return[...t,80]}i64_eq(t,e){return[...t,...e,81]}i64_ne(t,e){return[...t,...e,82]}i64_lt_s(t,e){return[...t,...e,83]}i64_lt_u(t,e){return[...t,...e,84]}i64_gt_s(t,e){return[...t,...e,85]}i64_gt_u(t,e){return[...t,...e,86]}i64_le_s(t,e){return[...t,...e,87]}i64_le_u(t,e){return[...t,...e,88]}i64_ge_s(t,e){return[...t,...e,89]}i64_ge_u(t,e){return[...t,...e,90]}i64_add(t,e){return[...t,...e,124]}i64_sub(t,e){return[...t,...e,125]}i64_mul(t,e){return[...t,...e,126]}i64_div_s(t,e){return[...t,...e,127]}i64_div_u(t,e){return[...t,...e,128]}i64_rem_s(t,e){return[...t,...e,129]}i64_rem_u(t,e){return[...t,...e,130]}i64_and(t,e){return[...t,...e,131]}i64_or(t,e){return[...t,...e,132]}i64_xor(t,e){return[...t,...e,133]}i64_shl(t,e){return[...t,...e,134]}i64_shr_s(t,e){return[...t,...e,135]}i64_shr_u(t,e){return[...t,...e,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,e){return[...t,...e,70]}i32_ne(t,e){return[...t,...e,71]}i32_lt_s(t,e){return[...t,...e,72]}i32_lt_u(t,e){return[...t,...e,73]}i32_gt_s(t,e){return[...t,...e,74]}i32_gt_u(t,e){return[...t,...e,75]}i32_le_s(t,e){return[...t,...e,76]}i32_le_u(t,e){return[...t,...e,77]}i32_ge_s(t,e){return[...t,...e,78]}i32_ge_u(t,e){return[...t,...e,79]}i32_add(t,e){return[...t,...e,106]}i32_sub(t,e){return[...t,...e,107]}i32_mul(t,e){return[...t,...e,108]}i32_div_s(t,e){return[...t,...e,109]}i32_div_u(t,e){return[...t,...e,110]}i32_rem_s(t,e){return[...t,...e,111]}i32_rem_u(t,e){return[...t,...e,112]}i32_and(t,e){return[...t,...e,113]}i32_or(t,e){return[...t,...e,114]}i32_xor(t,e){return[...t,...e,115]}i32_shl(t,e){return[...t,...e,116]}i32_shr_s(t,e){return[...t,...e,117]}i32_shr_u(t,e){return[...t,...e,118]}i32_rotl(t,e){return[...t,...e,119]}i32_rotr(t,e){return[...t,...e,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 la={i32:127,i64:126,f32:125,f64:124,anyfunc:112,func:96,emptyblock:64};class sa{constructor(t,e,a,i,o){if("import"==a)this.fnType="import",this.moduleName=i,this.fieldName=o;else{if("internal"!=a)throw new Error("Invalid function fnType: "+a);this.fnType="internal"}this.module=t,this.fnName=e,this.params=[],this.locals=[],this.localIdxByName={},this.code=[],this.returnType=null,this.nextLocal=0}addParam(t,e){if(this.localIdxByName[t])throw new Error(`param already exists. Function: ${this.fnName}, Param: ${t} `);const a=this.nextLocal++;this.localIdxByName[t]=a,this.params.push({type:e})}addLocal(t,e,a){const i=a||1;if(this.localIdxByName[t])throw new Error(`local already exists. Function: ${this.fnName}, Param: ${t} `);const o=this.nextLocal++;this.localIdxByName[t]=o,this.locals.push({type:e,length:i})}setReturnType(t){if(this.returnType)throw new Error(`returnType already defined. Function: ${this.fnName}`);this.returnType=t}getSignature(){return[96,...[...na(this.params.length),...this.params.map((t=>la[t.type]))],...this.returnType?[1,la[this.returnType]]:[0]]}getBody(){const t=this.locals.map((t=>[...na(t.length),la[t.type]])),e=[...na(this.locals.length),...[].concat(...t),...this.code,11];return[...na(e.length),...e]}addCode(...t){this.code.push(...[].concat(...t))}getCodeBuilder(){return new ra(this)}}class da{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([...Xe(1836278016),...Xe(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 e=this.functions.length;return this.functionIdxByName[t]=e,this.functions.push(new sa(this,t,"internal")),this.nInternalFunctions++,this.functions[e]}addIimportFunction(t,e,a){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 i=a||t;const o=this.functions.length;return this.functionIdxByName[t]=o,this.functions.push(new sa(this,t,"import",e,i)),this.nImportFunctions++,this.functions[o]}setMemory(t,e,a){this.memory={pagesSize:t,moduleName:e||"env",fieldName:a||"memory"}}exportFunction(t,e){const a=e||t;if(void 0===this.functionIdxByName[t])throw new Error(`Function not defined: ${t}`);const i=this.functionIdxByName[t];a!=t&&(this.functionIdxByName[a]=i),this.exports.push({exportName:a,idx:i})}addFunctionToTable(t){const e=this.functionIdxByName[t];this.functionsTable.push(e)}addData(t,e){this.datas.push({offset:t,bytes:e})}alloc(t,e){let a,i;(Array.isArray(t)||ArrayBuffer.isView(t))&&void 0===e?(a=t.length,i=t):(a=t,i=e),a=1+(a-1>>3)<<3;const o=this.free;return this.free+=a,i&&this.addData(o,i),o}allocString(t){const e=(new globalThis.TextEncoder).encode(t);return this.alloc([...e,0])}_setSignatures(){this.signatures=[];const t={};if(this.functionsTable.length>0){const e=this.functions[this.functionsTable[0]].getSignature();t["s_"+ca(e)]=0,this.signatures.push(e)}for(let e=0;e<this.functions.length;e++){const a=this.functions[e].getSignature(),i="s_"+ca(a);void 0===t[i]&&(t[i]=this.signatures.length,this.signatures.push(a)),this.functions[e].signatureIdx=t[i]}}_buildSection(t,e){return[t,...na(e.length),...e]}_buildType(){return this._buildSection(1,[...na(this.signatures.length),...[].concat(...this.signatures)])}_buildImport(){const t=[];t.push([...ta(this.memory.moduleName),...ta(this.memory.fieldName),2,0,...na(this.memory.pagesSize)]);for(let e=0;e<this.nImportFunctions;e++)t.push([...ta(this.functions[e].moduleName),...ta(this.functions[e].fieldName),0,...na(this.functions[e].signatureIdx)]);return this._buildSection(2,na(t.length).concat(...t))}_buildFunctionDeclarations(){const t=[];for(let e=this.nImportFunctions;e<this.nImportFunctions+this.nInternalFunctions;e++)t.push(...na(this.functions[e].signatureIdx));return this._buildSection(3,[...na(t.length),...t])}_buildFunctionsTable(){return 0==this.functionsTable.length?[]:this._buildSection(4,[...na(1),112,0,...na(this.functionsTable.length)])}_buildElements(){if(0==this.functionsTable.length)return[];const t=[];for(let e=0;e<this.functionsTable.length;e++)t.push(...na(this.functionsTable[e]));return this._buildSection(9,[...na(1),...na(0),65,...ia(0),11,...na(this.functionsTable.length),...t])}_buildExports(){const t=[];for(let e=0;e<this.exports.length;e++)t.push([...ta(this.exports[e].exportName),0,...na(this.exports[e].idx)]);return this._buildSection(7,na(t.length).concat(...t))}_buildCode(){const t=[];for(let e=this.nImportFunctions;e<this.nImportFunctions+this.nInternalFunctions;e++)t.push(this.functions[e].getBody());return this._buildSection(10,na(t.length).concat(...t))}_buildData(){const t=[];t.push([0,65,0,11,4,...Xe(this.free)]);for(let e=0;e<this.datas.length;e++)t.push([0,65,...ia(this.datas[e].offset),11,...na(this.datas[e].bytes.length),...this.datas[e].bytes]);return this._buildSection(11,na(t.length).concat(...t))}}async function ua(t,e){const a=new da;a.setMemory(25),Ae(a),e&&e(a);const o={};if(o.code=a.build(),o.pq=a.modules.f1m.pq,o.pr=a.modules.frm.pq,o.pG1gen=a.modules.bn128.pG1gen,o.pG1zero=a.modules.bn128.pG1zero,o.pG1b=a.modules.bn128.pG1b,o.pG2gen=a.modules.bn128.pG2gen,o.pG2zero=a.modules.bn128.pG2zero,o.pG2b=a.modules.bn128.pG2b,o.pOneT=a.modules.bn128.pOneT,o.prePSize=a.modules.bn128.prePSize,o.preQSize=a.modules.bn128.preQSize,o.n8q=32,o.n8r=32,o.q=a.modules.bn128.q,o.r=a.modules.bn128.r,!t&&globalThis.curve_bn128)return globalThis.curve_bn128;const n={name:"bn128",wasm:o,q:i("21888242871839275222246405745257275088696311157297823662689037894645226208583"),r:i("21888242871839275222246405745257275088548364400416034343698204186575808495617"),n8q:32,n8r:32,cofactorG2:i("30644e72e131a029b85045b68181585e06ceecda572a2489345f2299c0f9fa8d",16),singleThread:!!t},c=await Ye(n);return c.terminate=async function(){n.singleThread||(globalThis.curve_bn128=null,await this.tm.terminate())},t||(globalThis.curve_bn128=c),c}async function ga(t,e){const a=new da;a.setMemory(25),be(a),e&&e(a);const o={};if(o.code=a.build(),o.pq=a.modules.f1m.pq,o.pr=a.modules.frm.pq,o.pG1gen=a.modules.bls12381.pG1gen,o.pG1zero=a.modules.bls12381.pG1zero,o.pG1b=a.modules.bls12381.pG1b,o.pG2gen=a.modules.bls12381.pG2gen,o.pG2zero=a.modules.bls12381.pG2zero,o.pG2b=a.modules.bls12381.pG2b,o.pOneT=a.modules.bls12381.pOneT,o.prePSize=a.modules.bls12381.prePSize,o.preQSize=a.modules.bls12381.preQSize,o.n8q=48,o.n8r=32,o.q=a.modules.bls12381.q,o.r=a.modules.bls12381.r,!t&&globalThis.curve_bls12381)return globalThis.curve_bls12381;const n={name:"bls12381",wasm:o,q:i("1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab",16),r:i("73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",16),n8q:48,n8r:32,cofactorG1:i("0x396c8c005555e1568c00aaab0000aaab",16),cofactorG2:i("0x5d543a95414e7f1091d50792876a202cd91de4547085abaa68a205b2e5a7ddfa628f1cb4d9e82ef21537e293a6691ae1616ec6e786f0c70cf1c38e31c7238e5",16),singleThread:!!t},c=await Ye(n);return c.terminate=async function(){n.singleThread||(globalThis.curve_bls12381=null,await this.tm.terminate())},t||(globalThis.curve_bls12381=c),c}globalThis.curve_bn128=null,globalThis.curve_bls12381=null;const _a=i("73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",16),fa=i("21888242871839275222246405745257275088548364400416034343698204186575808495617");i("1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab",16),i("21888242871839275222246405745257275088696311157297823662689037894645226208583");const ha=U,pa=Se;var ma={};async function La(t,e,a,i){if(a=a||262144,"number"!=typeof e&&["w+","wx+","r","ax+","a+"].indexOf(e)<0)throw new Error("Invalid open option");const o=await ma.promises.open(t,e),n=await o.stat();return new wa(o,n,a,i,t)}class wa{constructor(t,e,a,i,o){for(this.fileName=o,this.fd=t,this.pos=0,this.pageSize=i||256;this.pageSize<e.blksize;)this.pageSize*=2;this.totalSize=e.size,this.totalPages=Math.floor((e.size-1)/this.pageSize)+1,this.maxPagesLoaded=Math.floor(a/this.pageSize)+1,this.pages={},this.pendingLoads=[],this.writing=!1,this.reading=!1,this.avBuffs=[],this.history={}}_loadPage(t){const e=this,a=new Promise(((a,i)=>{e.pendingLoads.push({page:t,resolve:a,reject:i})}));return e.__statusPage("After Load request: ",t),a}__statusPage(t,e){const a=[],i=this;if(!i.logHistory)return;a.push("=="+t+" "+e);let o="";for(let t=0;t<i.pendingLoads.length;t++)i.pendingLoads[t].page==e&&(o=o+" "+t);if(o&&a.push("Pending loads:"+o),void 0!==i.pages[e]){const t=i.pages[e];a.push("Loaded"),a.push("pendingOps: "+t.pendingOps),t.loading&&a.push("loading: "+t.loading),t.writing&&a.push("writing"),t.dirty&&a.push("dirty")}a.push("=="),i.history[e]||(i.history[e]=[]),i.history[e].push(a)}__printHistory(t){const e=this;e.history[t]||console.log("Empty History ",t),console.log("History "+t);for(let a=0;a<e.history[t].length;a++)for(let i=0;i<e.history[t][a].length;i++)console.log("-> "+e.history[t][a][i])}_triggerLoad(){const t=this;if(t.reading)return;if(0==t.pendingLoads.length)return;const e=Object.keys(t.pages),a=[];for(let i=0;i<e.length;i++){const o=t.pages[parseInt(e[i])];0!=o.dirty||0!=o.pendingOps||o.writing||o.loading||a.push(parseInt(e[i]))}let i=t.maxPagesLoaded-e.length;const o=[];for(;t.pendingLoads.length>0&&(void 0!==t.pages[t.pendingLoads[0].page]||i>0||a.length>0);){const e=t.pendingLoads.shift();if(void 0!==t.pages[e.page]){t.pages[e.page].pendingOps++;const i=a.indexOf(e.page);i>=0&&a.splice(i,1),t.pages[e.page].loading?t.pages[e.page].loading.push(e):e.resolve(),t.__statusPage("After Load (cached): ",e.page)}else{if(i)i--;else{const e=a.shift();t.__statusPage("Before Unload: ",e),t.avBuffs.unshift(t.pages[e]),delete t.pages[e],t.__statusPage("After Unload: ",e)}e.page>=t.totalPages?(t.pages[e.page]=n(),e.resolve(),t.__statusPage("After Load (new): ",e.page)):(t.reading=!0,t.pages[e.page]=n(),t.pages[e.page].loading=[e],o.push(t.fd.read(t.pages[e.page].buff,0,t.pageSize,e.page*t.pageSize).then((a=>{t.pages[e.page].size=a.bytesRead;const i=t.pages[e.page].loading;delete t.pages[e.page].loading;for(let t=0;t<i.length;t++)i[t].resolve();return t.__statusPage("After Load (loaded): ",e.page),a}),(t=>{e.reject(t)}))),t.__statusPage("After Load (loading): ",e.page))}}function n(){if(t.avBuffs.length>0){const e=t.avBuffs.shift();return e.dirty=!1,e.pendingOps=1,e.size=0,e}return{dirty:!1,buff:new Uint8Array(t.pageSize),pendingOps:1,size:0}}Promise.all(o).then((()=>{t.reading=!1,t.pendingLoads.length>0&&setImmediate(t._triggerLoad.bind(t)),t._tryClose()}))}_triggerWrite(){const t=this;if(t.writing)return;const e=Object.keys(t.pages),a=[];for(let i=0;i<e.length;i++){const o=t.pages[parseInt(e[i])];o.dirty&&(o.dirty=!1,o.writing=!0,t.writing=!0,a.push(t.fd.write(o.buff,0,o.size,parseInt(e[i])*t.pageSize).then((()=>{o.writing=!1}),(e=>{console.log("ERROR Writing: "+e),t.error=e,t._tryClose()}))))}t.writing&&Promise.all(a).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,e){if(0==t.byteLength)return;const a=this;if(void 0===e&&(e=a.pos),a.pos=e+t.byteLength,a.totalSize<e+t.byteLength&&(a.totalSize=e+t.byteLength),a.pendingClose)throw new Error("Writing a closing file");const i=Math.floor(e/a.pageSize),o=Math.floor((e+t.byteLength-1)/a.pageSize),n=[];for(let t=i;t<=o;t++)n.push(a._loadPage(t));a._triggerLoad();let c=i,r=e%a.pageSize,l=t.byteLength;for(;l>0;){await n[c-i];const e=r+l>a.pageSize?a.pageSize-r:l,o=t.slice(t.byteLength-l,t.byteLength-l+e);new Uint8Array(a.pages[c].buff.buffer,r,e).set(o),a.pages[c].dirty=!0,a.pages[c].pendingOps--,a.pages[c].size=Math.max(r+e,a.pages[c].size),c>=a.totalPages&&(a.totalPages=c+1),l-=e,c++,r=0,a.writing||setImmediate(a._triggerWrite.bind(a))}}async read(t,e){let a=new Uint8Array(t);return await this.readToBuffer(a,0,t,e),a}async readToBuffer(t,e,a,i){if(0==a)return;const o=this;if(a>o.pageSize*o.maxPagesLoaded*.8){const t=Math.floor(1.1*a);this.maxPagesLoaded=Math.floor(t/o.pageSize)+1}if(void 0===i&&(i=o.pos),o.pos=i+a,o.pendingClose)throw new Error("Reading a closing file");const n=Math.floor(i/o.pageSize),c=Math.floor((i+a-1)/o.pageSize),r=[];for(let t=n;t<=c;t++)r.push(o._loadPage(t));o._triggerLoad();let l=n,s=i%o.pageSize,d=i+a>o.totalSize?a-(i+a-o.totalSize):a;for(;d>0;){await r[l-n],o.__statusPage("After Await (read): ",l);const i=s+d>o.pageSize?o.pageSize-s:d,c=new Uint8Array(o.pages[l].buff.buffer,o.pages[l].buff.byteOffset+s,i);t.set(c,e+a-d),o.pages[l].pendingOps--,o.__statusPage("After Op done: ",l),d-=i,l++,s=0,o.pendingLoads.length>0&&setImmediate(o._triggerLoad.bind(o))}this.pos=i+a}_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(((e,a)=>{t.pendingClose=e,t.pendingCloseReject=a,t._tryClose()})).then((()=>{t.fd.close()}),(e=>{throw t.fd.close(),e}))}async discard(){await this.close(),await ma.promises.unlink(this.fileName)}async writeULE32(t,e){const a=new Uint8Array(4);new DataView(a.buffer).setUint32(0,t,!0),await this.write(a,e)}async writeUBE32(t,e){const a=new Uint8Array(4);new DataView(a.buffer).setUint32(0,t,!1),await this.write(a,e)}async writeULE64(t,e){const a=new Uint8Array(8),i=new DataView(a.buffer);i.setUint32(0,4294967295&t,!0),i.setUint32(4,Math.floor(t/4294967296),!0),await this.write(a,e)}async readULE32(t){const e=await this.read(4,t);return new Uint32Array(e.buffer)[0]}async readUBE32(t){const e=await this.read(4,t);return new DataView(e.buffer).getUint32(0,!1)}async readULE64(t){const e=await this.read(8,t),a=new Uint32Array(e.buffer);return 4294967296*a[1]+a[0]}async readString(t){const e=this;if(e.pendingClose)throw new Error("Reading a closing file");let a=void 0===t?e.pos:t,i=Math.floor(a/e.pageSize),o=!1,n="";for(;!o;){let t=e._loadPage(i);e._triggerLoad(),await t,e.__statusPage("After Await (read): ",i);let c=a%e.pageSize;const r=new Uint8Array(e.pages[i].buff.buffer,e.pages[i].buff.byteOffset+c,e.pageSize-c);let l=r.findIndex((t=>0===t));o=-1!==l,o?(n+=(new TextDecoder).decode(r.slice(0,l)),e.pos=i*this.pageSize+c+l+1):(n+=(new TextDecoder).decode(r),e.pos=i*this.pageSize+c+r.length),e.pages[i].pendingOps--,e.__statusPage("After Op done: ",i),a=e.pos,i++,e.pendingLoads.length>0&&setImmediate(e._triggerLoad.bind(e))}return n}}const Aa=new Uint8Array(4),ba=new DataView(Aa.buffer),ya=new Uint8Array(8),Ia=new DataView(ya.buffer);class Ca{constructor(){this.pageSize=16384}_resizeIfNeeded(t){if(t>this.allocSize){const e=Math.max(this.allocSize+(1<<20),Math.floor(1.1*this.allocSize),t),a=new Uint8Array(e);a.set(this.o.data),this.o.data=a,this.allocSize=e}}async write(t,e){if(void 0===e&&(e=this.pos),this.readOnly)throw new Error("Writing a read only file");this._resizeIfNeeded(e+t.byteLength),this.o.data.set(t.slice(),e),e+t.byteLength>this.totalSize&&(this.totalSize=e+t.byteLength),this.pos=e+t.byteLength}async readToBuffer(t,e,a,i){if(void 0===i&&(i=this.pos),this.readOnly&&i+a>this.totalSize)throw new Error("Reading out of bounds");this._resizeIfNeeded(i+a);const o=new Uint8Array(this.o.data.buffer,this.o.data.byteOffset+i,a);t.set(o,e),this.pos=i+a}async read(t,e){const a=new Uint8Array(t);return await this.readToBuffer(a,0,t,e),a}close(){this.o.data.byteLength!=this.totalSize&&(this.o.data=this.o.data.slice(0,this.totalSize))}async discard(){}async writeULE32(t,e){ba.setUint32(0,t,!0),await this.write(Aa,e)}async writeUBE32(t,e){ba.setUint32(0,t,!1),await this.write(Aa,e)}async writeULE64(t,e){Ia.setUint32(0,4294967295&t,!0),Ia.setUint32(4,Math.floor(t/4294967296),!0),await this.write(ya,e)}async readULE32(t){const e=await this.read(4,t);return new Uint32Array(e.buffer)[0]}async readUBE32(t){const e=await this.read(4,t);return new DataView(e.buffer).getUint32(0,!1)}async readULE64(t){const e=await this.read(8,t),a=new Uint32Array(e.buffer);return 4294967296*a[1]+a[0]}async readString(t){const e=this;let a=void 0===t?e.pos:t;if(a>this.totalSize){if(this.readOnly)throw new Error("Reading out of bounds");this._resizeIfNeeded(t)}const i=new Uint8Array(e.o.data.buffer,a,this.totalSize-a);let o=i.findIndex((t=>0===t)),n="";return-1!==o?(n=(new TextDecoder).decode(i.slice(0,o)),e.pos=a+o+1):e.pos=a,n}}const Fa=1<<22;const xa=new Uint8Array(4),Ea=new DataView(xa.buffer),Ba=new Uint8Array(8),va=new DataView(Ba.buffer);class Sa{constructor(){this.pageSize=16384}_resizeIfNeeded(t){if(t<=this.totalSize)return;if(this.readOnly)throw new Error("Reading out of file bounds");const e=Math.floor((t-1)/Fa)+1;for(let a=Math.max(this.o.data.length-1,0);a<e;a++){const i=new Uint8Array(a<e-1?Fa:t-(e-1)*Fa);a==this.o.data.length-1&&i.set(this.o.data[a]),this.o.data[a]=i}this.totalSize=t}async write(t,e){const a=this;if(void 0===e&&(e=a.pos),this.readOnly)throw new Error("Writing a read only file");this._resizeIfNeeded(e+t.byteLength);let i=Math.floor(e/Fa),o=e%Fa,n=t.byteLength;for(;n>0;){const e=o+n>Fa?Fa-o:n,c=t.slice(t.byteLength-n,t.byteLength-n+e);new Uint8Array(a.o.data[i].buffer,o,e).set(c),n-=e,i++,o=0}this.pos=e+t.byteLength}async readToBuffer(t,e,a,i){const o=this;if(void 0===i&&(i=o.pos),this.readOnly&&i+a>this.totalSize)throw new Error("Reading out of bounds");this._resizeIfNeeded(i+a);let n=Math.floor(i/Fa),c=i%Fa,r=a;for(;r>0;){const i=c+r>Fa?Fa-c:r,l=new Uint8Array(o.o.data[n].buffer,c,i);t.set(l,e+a-r),r-=i,n++,c=0}this.pos=i+a}async read(t,e){const a=new Uint8Array(t);return await this.readToBuffer(a,0,t,e),a}close(){}async discard(){}async writeULE32(t,e){Ea.setUint32(0,t,!0),await this.write(xa,e)}async writeUBE32(t,e){Ea.setUint32(0,t,!1),await this.write(xa,e)}async writeULE64(t,e){va.setUint32(0,4294967295&t,!0),va.setUint32(4,Math.floor(t/4294967296),!0),await this.write(Ba,e)}async readULE32(t){const e=await this.read(4,t);return new Uint32Array(e.buffer)[0]}async readUBE32(t){const e=await this.read(4,t);return new DataView(e.buffer).getUint32(0,!1)}async readULE64(t){const e=await this.read(8,t),a=new Uint32Array(e.buffer);return 4294967296*a[1]+a[0]}async readString(t){const e=this;let a=void 0===t?e.pos:t;if(a>this.totalSize){if(this.readOnly)throw new Error("Reading out of bounds");this._resizeIfNeeded(t)}let i=!1,o="";for(;!i;){let t=Math.floor(a/Fa),n=a%Fa;if(void 0===e.o.data[t])throw new Error("ERROR");let c=Math.min(2048,e.o.data[t].length-n);const r=new Uint8Array(e.o.data[t].buffer,n,c);let l=r.findIndex((t=>0===t));i=-1!==l,i?(o+=(new TextDecoder).decode(r.slice(0,l)),e.pos=t*Fa+n+l+1):(o+=(new TextDecoder).decode(r),e.pos=t*Fa+n+r.length),a=e.pos}return o}}async function Ga(t,e,a){if("string"==typeof t&&(t={type:"file",fileName:t,cacheSize:e||65536,pageSize:a||8192}),"file"==t.type)return await La(t.fileName,1538,t.cacheSize,t.pageSize);if("mem"==t.type)return function(t){const e=t.initialSize||1<<20,a=new Ca;return a.o=t,a.o.data=new Uint8Array(e),a.allocSize=e,a.totalSize=0,a.readOnly=!1,a.pos=0,a}(t);if("bigMem"==t.type)return function(t){const e=t.initialSize||0,a=new Sa;a.o=t;const i=e?Math.floor((e-1)/Fa)+1:0;a.o.data=[];for(let t=0;t<i-1;t++)a.o.data.push(new Uint8Array(Fa));return i&&a.o.data.push(new Uint8Array(e-Fa*(i-1))),a.totalSize=0,a.readOnly=!1,a.pos=0,a}(t);throw new Error("Invalid FastFile type: "+t.type)}async function Pa(t,e,a){if(t instanceof Uint8Array&&(t={type:"mem",data:t}),"string"==typeof t){t={type:"mem",data:await fetch(t).then((function(t){return t.arrayBuffer()})).then((function(t){return new Uint8Array(t)}))}}if("file"==t.type)return await La(t.fileName,0,t.cacheSize,t.pageSize);if("mem"==t.type)return await function(t){const e=new Ca;return e.o=t,e.allocSize=t.data.byteLength,e.totalSize=t.data.byteLength,e.readOnly=!0,e.pos=0,e}(t);if("bigMem"==t.type)return await function(t){const e=new Sa;return e.o=t,e.totalSize=(t.data.length-1)*Fa+t.data[t.data.length-1].byteLength,e.readOnly=!0,e.pos=0,e}(t);throw new Error("Invalid FastFile type: "+t.type)}async function Ua(t,e,a,i,o){const n=await Pa(t),c=await n.read(4);let r="";for(let t=0;t<4;t++)r+=String.fromCharCode(c[t]);if(r!=e)throw new Error(t+": Invalid File format");if(await n.readULE32()>a)throw new Error("Version not supported");const l=await n.readULE32();let s=[];for(let t=0;t<l;t++){let t=await n.readULE32(),e=await n.readULE64();void 0===s[t]&&(s[t]=[]),s[t].push({p:n.pos,size:e}),n.pos+=e}return{fd:n,sections:s}}async function Oa(t,e,a,i,o,n){const c=await Ga(t,o,n),r=new Uint8Array(4);for(let t=0;t<4;t++)r[t]=e.charCodeAt(t);return await c.write(r,0),await c.writeULE32(a),await c.writeULE32(i),c}async function za(t,e){if(void 0!==t.writingSection)throw new Error("Already writing a section");await t.writeULE32(e),t.writingSection={pSectionSize:t.pos},await t.writeULE64(0)}async function Qa(t){if(void 0===t.writingSection)throw new Error("Not writing a section");const e=t.pos-t.writingSection.pSectionSize-8,a=t.pos;t.pos=t.writingSection.pSectionSize,await t.writeULE64(e),t.pos=a,delete t.writingSection}async function qa(t,e,a){if(void 0!==t.readingSection)throw new Error("Already reading a section");if(!e[a])throw new Error(t.fileName+": Missing section "+a);if(e[a].length>1)throw new Error(t.fileName+": Section Duplicated "+a);t.pos=e[a][0].p,t.readingSection=e[a][0]}async function Ma(t,e){if(void 0===t.readingSection)throw new Error("Not reading a section");if(!e&&t.pos-t.readingSection.p!=t.readingSection.size)throw new Error("Invalid section size reading");delete t.readingSection}async function Ta(t,e,a,i){const o=new Uint8Array(a);ha.toRprLE(o,0,e,a),await t.write(o,i)}async function ka(t,e,a){const i=await t.read(e,a);return ha.fromRprLE(i,0,e)}async function Ra(t,e,a,i,o){void 0===o&&(o=e[i][0].size);const n=t.pageSize;await qa(t,e,i),await za(a,i);for(let e=0;e<o;e+=n){const i=Math.min(o-e,n),c=await t.read(i);await a.write(c)}await Qa(a),await Ma(t,o!=e[i][0].size)}async function Da(t,e,a,i,o){if((i=void 0===i?0:i)+(o=void 0===o?e[a][0].size-i:o)>e[a][0].size)throw new Error("Reading out of the range of the section");let n;return n=o<1<<30?new Uint8Array(o):new Pe(o),await t.readToBuffer(n,0,o,e[a][0].p+i),n}async function Na(t,e,a,i,o){const n=16*t.pageSize;if(await qa(t,e,o),await qa(a,i,o),e[o][0].size!=i[o][0].size)return!1;const c=e[o][0].size;for(let e=0;e<c;e+=n){const i=Math.min(c-e,n),o=await t.read(i),r=await a.read(i);for(let t=0;t<i;t++)if(o[t]!=r[t])return!1}return await Ma(t),await Ma(a),!0}ha.e("73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",16),ha.e("21888242871839275222246405745257275088548364400416034343698204186575808495617");const Va=ha.e("1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab",16),Ka=ha.e("21888242871839275222246405745257275088696311157297823662689037894645226208583");async function ja(t){let e;if(ha.eq(t,Ka))e=await ua();else{if(!ha.eq(t,Va))throw new Error(`Curve not supported: ${ha.toString(t)}`);e=await ga()}return e}async function Ha(t){let e;const a=t.toUpperCase().match(/[A-Za-z0-9]+/g).join("");if(["BN128","BN254","ALTBN128"].indexOf(a)>=0)e=await ua();else{if(!(["BLS12381"].indexOf(a)>=0))throw new Error(`Curve not supported: ${t}`);e=await ga()}return e}var $a={exports:{}},Ya=function t(e,a){if(!e){var i=new Wa(a);throw Error.captureStackTrace&&Error.captureStackTrace(i,t),i}};class Wa extends Error{}function Za(t){return t.length}Wa.prototype.name="AssertionError";var Ja={byteLength:Za,toString:function(t){const e=t.byteLength;let a="";for(let i=0;i<e;i++)a+=String.fromCharCode(t[i]);return a},write:function(t,e,a=0,i=Za(e)){const o=Math.min(i,t.byteLength-a);for(let i=0;i<o;i++)t[a+i]=e.charCodeAt(i);return o}};const Xa="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",ti=new Uint8Array(256);for(let t=0;t<Xa.length;t++)ti[Xa.charCodeAt(t)]=t;function ei(t){let e=t.length;return 61===t.charCodeAt(e-1)&&e--,e>1&&61===t.charCodeAt(e-1)&&e--,3*e>>>2}ti[45]=62,ti[95]=63;var ai={byteLength:ei,toString:function(t){const e=t.byteLength;let a="";for(let i=0;i<e;i+=3)a+=Xa[t[i]>>2]+Xa[(3&t[i])<<4|t[i+1]>>4]+Xa[(15&t[i+1])<<2|t[i+2]>>6]+Xa[63&t[i+2]];return e%3==2?a=a.substring(0,a.length-1)+"=":e%3==1&&(a=a.substring(0,a.length-2)+"=="),a},write:function(t,e,a=0,i=ei(e)){const o=Math.min(i,t.byteLength-a);for(let a=0,i=0;a<o;a+=4){const o=ti[e.charCodeAt(a)],n=ti[e.charCodeAt(a+1)],c=ti[e.charCodeAt(a+2)],r=ti[e.charCodeAt(a+3)];t[i++]=o<<2|n>>4,t[i++]=(15&n)<<4|c>>2,t[i++]=(3&c)<<6|63&r}return o}};function ii(t){return t.length>>>1}var oi={byteLength:ii,toString:function(t){const e=t.byteLength;t=new DataView(t.buffer,t.byteOffset,e);let a="",i=0;for(let o=e-e%4;i<o;i+=4)a+=t.getUint32(i).toString(16).padStart(8,"0");for(;i<e;i++)a+=t.getUint8(i).toString(16).padStart(2,"0");return a},write:function(t,e,a=0,i=ii(e)){const o=Math.min(i,t.byteLength-a);for(let i=0;i<o;i++){const o=ni(e.charCodeAt(2*i)),n=ni(e.charCodeAt(2*i+1));if(void 0===o||void 0===n)return t.subarray(0,i);t[a+i]=o<<4|n}return o}};function ni(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-65+10:t>=97&&t<=102?t-97+10:void 0}function ci(t){let e=0;for(let a=0,i=t.length;a<i;a++){const o=t.charCodeAt(a);if(o>=55296&&o<=56319&&a+1<i){const i=t.charCodeAt(a+1);if(i>=56320&&i<=57343){e+=4,a++;continue}}e+=o<=127?1:o<=2047?2:3}return e}let ri,li;if("undefined"!=typeof TextDecoder){const t=new TextDecoder;ri=function(e){return t.decode(e)}}else ri=function(t){const e=t.byteLength;let a="",i=0;for(;i<e;){let o=t[i];if(o<=127){a+=String.fromCharCode(o),i++;continue}let n=0,c=0;if(o<=223?(n=1,c=31&o):o<=239?(n=2,c=15&o):o<=244&&(n=3,c=7&o),e-i-n>0){let e=0;for(;e<n;)o=t[i+e+1],c=c<<6|63&o,e+=1}else c=65533,n=e-i;a+=String.fromCodePoint(c),i+=n+1}return a};if("undefined"!=typeof TextEncoder){const t=new TextEncoder;li=function(e,a,i=0,o=ci(a)){const n=Math.min(o,e.byteLength-i);return t.encodeInto(a,e.subarray(i,i+n)),n}}else li=function(t,e,a=0,i=ci(e)){const o=Math.min(i,t.byteLength-a);t=t.subarray(a,a+o);let n=0,c=0;for(;n<e.length;){const a=e.codePointAt(n);if(a<=127){t[c++]=a,n++;continue}let i=0,o=0;for(a<=2047?(i=6,o=192):a<=65535?(i=12,o=224):a<=2097151&&(i=18,o=240),t[c++]=o|a>>i,i-=6;i>=0;)t[c++]=128|a>>i&63,i-=6;n+=a>=65536?2:1}return o};function si(t){return 2*t.length}var di={byteLength:si,toString:function(t){const e=t.byteLength;let a="";for(let i=0;i<e-1;i+=2)a+=String.fromCharCode(t[i]+256*t[i+1]);return a},write:function(t,e,a=0,i=si(e)){const o=Math.min(i,t.byteLength-a);let n=o;for(let i=0;i<e.length&&!((n-=2)<0);++i){const o=e.charCodeAt(i),n=o>>8,c=o%256;t[a+2*i]=c,t[a+2*i+1]=n}return o}};const ui=Ja,gi=ai,_i=oi,fi={byteLength:ci,toString:ri,write:li},hi=di,pi=255===new Uint8Array(Uint16Array.of(255).buffer)[0];function mi(t){switch(t){case"ascii":return ui;case"base64":return gi;case"hex":return _i;case"utf8":case"utf-8":case void 0:return fi;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return hi;default:throw new Error(`Unknown encoding: ${t}`)}}function Li(t){return t instanceof Uint8Array}function wi(t,e,a){return"string"==typeof t?function(t,e){const a=mi(e),i=new Uint8Array(a.byteLength(t));return a.write(i,t,0,i.byteLength),i}(t,e):Array.isArray(t)?function(t){const e=new Uint8Array(t.length);return e.set(t),e}(t):ArrayBuffer.isView(t)?function(t){const e=new Uint8Array(t.byteLength);return e.set(t),e}(t):function(t,e,a){return new Uint8Array(t,e,a)}(t,e,a)}function Ai(t,e,a,i,o){if(0===t.byteLength)return-1;if("string"==typeof a?(i=a,a=0):void 0===a?a=o?0:t.length-1:a<0&&(a+=t.byteLength),a>=t.byteLength){if(o)return-1;a=t.byteLength-1}else if(a<0){if(!o)return-1;a=0}if("string"==typeof e)e=wi(e,i);else if("number"==typeof e)return e&=255,o?t.indexOf(e,a):t.lastIndexOf(e,a);if(0===e.byteLength)return-1;if(o){let i=-1;for(let o=a;o<t.byteLength;o++)if(t[o]===e[-1===i?0:o-i]){if(-1===i&&(i=o),o-i+1===e.byteLength)return i}else-1!==i&&(o-=o-i),i=-1}else{a+e.byteLength>t.byteLength&&(a=t.byteLength-e.byteLength);for(let i=a;i>=0;i--){let a=!0;for(let o=0;o<e.byteLength;o++)if(t[i+o]!==e[o]){a=!1;break}if(a)return i}}return-1}function bi(t,e,a,i){return Ai(t,e,a,i,!0)}function yi(t,e,a){const i=t[e];t[e]=t[a],t[a]=i}var Ii,Ci,Fi={isBuffer:Li,isEncoding:function(t){try{return mi(t),!0}catch{return!1}},alloc:function(t,e,a){const i=new Uint8Array(t);return void 0!==e&&e(i,e,0,i.byteLength,a),i},allocUnsafe:function(t){return new Uint8Array(t)},allocUnsafeSlow:function(t){return new Uint8Array(t)},byteLength:function(t,e){return mi(e).byteLength(t)},compare:function(t,e){if(t===e)return 0;const a=Math.min(t.byteLength,e.byteLength);t=new DataView(t.buffer,t.byteOffset,t.byteLength),e=new DataView(e.buffer,e.byteOffset,e.byteLength);let i=0;for(let o=a-a%4;i<o;i+=4){if(t.getUint32(i,pi)!==e.getUint32(i,pi))break}for(;i<a;i++){const a=t.getUint8(i),o=e.getUint8(i);if(a<o)return-1;if(a>o)return 1}return t.byteLength>e.byteLength?1:t.byteLength<e.byteLength?-1:0},concat:function(t,e){void 0===e&&(e=t.reduce(((t,e)=>t+e.byteLength),0));const a=new Uint8Array(e);return t.reduce(((t,e)=>(a.set(e,t),t+e.byteLength)),0),a},copy:function(t,e,a=0,i=0,o=t.byteLength){if(o>0&&o<i)return 0;if(o===i)return 0;if(0===t.byteLength||0===e.byteLength)return 0;if(a<0)throw new RangeError("targetStart is out of range");if(i<0||i>=t.byteLength)throw new RangeError("sourceStart is out of range");if(o<0)throw new RangeError("sourceEnd is out of range");a>=e.byteLength&&(a=e.byteLength),o>t.byteLength&&(o=t.byteLength),e.byteLength-a<o-i&&(o=e.length-a+i);const n=o-i;return t===e?e.copyWithin(a,i,o):e.set(t.subarray(i,o),a),n},equals:function(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;const a=t.byteLength;t=new DataView(t.buffer,t.byteOffset,t.byteLength),e=new DataView(e.buffer,e.byteOffset,e.byteLength);let i=0;for(let o=a-a%4;i<o;i+=4)if(t.getUint32(i,pi)!==e.getUint32(i,pi))return!1;for(;i<a;i++)if(t.getUint8(i)!==e.getUint8(i))return!1;return!0},fill:function(t,e,a,i,o){if("string"==typeof e?"string"==typeof a?(o=a,a=0,i=t.byteLength):"string"==typeof i&&(o=i,i=t.byteLength):"number"==typeof val?e&=255:"boolean"==typeof val&&(e=+e),a<0||t.byteLength<a||t.byteLength<i)throw new RangeError("Out of range index");if(void 0===a&&(a=0),void 0===i&&(i=t.byteLength),i<=a)return t;if(e||(e=0),"number"==typeof e)for(let o=a;o<i;++o)t[o]=e;else{const n=(e=Li(e)?e:wi(e,o)).byteLength;for(let o=0;o<i-a;++o)t[o+a]=e[o%n]}return t},from:wi,includes:function(t,e,a,i){return-1!==bi(t,e,a,i)},indexOf:bi,lastIndexOf:function(t,e,a,i){return Ai(t,e,a,i,!1)},swap16:function(t){const e=t.byteLength;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let a=0;a<e;a+=2)yi(t,a,a+1);return t},swap32:function(t){const e=t.byteLength;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let a=0;a<e;a+=4)yi(t,a,a+3),yi(t,a+1,a+2);return t},swap64:function(t){const e=t.byteLength;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let a=0;a<e;a+=8)yi(t,a,a+7),yi(t,a+1,a+6),yi(t,a+2,a+5),yi(t,a+3,a+4);return t},toBuffer:function(t){return t},toString:function(t,e,a=0,i=t.byteLength){const o=t.byteLength;return a>=o||i<=a?"":(a<0&&(a=0),i>o&&(i=o),(0!==a||i<o)&&(t=t.subarray(a,i)),mi(e).toString(t))},write:function(t,e,a,i,o){return void 0===a?o="utf8":void 0===i&&"string"==typeof a?(o=a,a=void 0):void 0===o&&"string"==typeof i&&(o=i,i=void 0),mi(o).write(t,e,a,i)},writeDoubleLE:function(t,e,a){return void 0===a&&(a=0),new DataView(t.buffer,t.byteOffset,t.byteLength).setFloat64(a,e,!0),a+8},writeFloatLE:function(t,e,a){return void 0===a&&(a=0),new DataView(t.buffer,t.byteOffset,t.byteLength).setFloat32(a,e,!0),a+4},writeUInt32LE:function(t,e,a){return void 0===a&&(a=0),new DataView(t.buffer,t.byteOffset,t.byteLength).setUint32(a,e,!0),a+4},writeInt32LE:function(t,e,a){return void 0===a&&(a=0),new DataView(t.buffer,t.byteOffset,t.byteLength).setInt32(a,e,!0),a+4},readDoubleLE:function(t,e){return void 0===e&&(e=0),new DataView(t.buffer,t.byteOffset,t.byteLength).getFloat64(e,!0)},readFloatLE:function(t,e){return void 0===e&&(e=0),new DataView(t.buffer,t.byteOffset,t.byteLength).getFloat32(e,!0)},readUInt32LE:function(t,e){return void 0===e&&(e=0),new DataView(t.buffer,t.byteOffset,t.byteLength).getUint32(e,!0)},readInt32LE:function(t,e){return void 0===e&&(e=0),new DataView(t.buffer,t.byteOffset,t.byteLength).getInt32(e,!0)}};var xi=Ya,Ei=Fi,Bi=null,vi="undefined"!=typeof WebAssembly&&function(){if(Ci)return Ii;Ci=1;var t=(()=>{for(var t=new Uint8Array(128),e=0;e<64;e++)t[e<26?e+65:e<52?e+71:e<62?e-4:4*e-205]=e;return e=>{for(var a=e.length,i=new Uint8Array(3*(a-("="==e[a-1])-("="==e[a-2]))/4|0),o=0,n=0;o<a;){var c=t[e.charCodeAt(o++)],r=t[e.charCodeAt(o++)],l=t[e.charCodeAt(o++)],s=t[e.charCodeAt(o++)];i[n++]=c<<2|r>>4,i[n++]=r<<4|l>>2,i[n++]=l<<6|s}return i}})(),e=((t,e)=>function(){return e||(0,t[Object.keys(t)[0]])((e={exports:{}}).exports,e),e.exports})({"wasm-binary:./blake2b.wat"(e,a){a.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=")}}),a=e(),i=WebAssembly.compile(a);return Ii=async t=>(await WebAssembly.instantiate(await i,t)).exports}()().then((t=>{Bi=t})),Si=64,Gi=[];$a.exports=Mi;var Pi=$a.exports.BYTES_MIN=16,Ui=$a.exports.BYTES_MAX=64;$a.exports.BYTES=32;var Oi=$a.exports.KEYBYTES_MIN=16,zi=$a.exports.KEYBYTES_MAX=64;$a.exports.KEYBYTES=32;var Qi=$a.exports.SALTBYTES=16,qi=$a.exports.PERSONALBYTES=16;function Mi(t,e,a,i,o){if(!(this instanceof Mi))return new Mi(t,e,a,i,o);if(!Bi)throw new Error("WASM not loaded. Wait for Blake2b.ready(cb)");t||(t=32),!0!==o&&(xi(t>=Pi,"digestLength must be at least "+Pi+", was given "+t),xi(t<=Ui,"digestLength must be at most "+Ui+", was given "+t),null!=e&&(xi(e instanceof Uint8Array,"key must be Uint8Array or Buffer"),xi(e.length>=Oi,"key must be at least "+Oi+", was given "+e.length),xi(e.length<=zi,"key must be at least "+zi+", was given "+e.length)),null!=a&&(xi(a instanceof Uint8Array,"salt must be Uint8Array or Buffer"),xi(a.length===Qi,"salt must be exactly "+Qi+", was given "+a.length)),null!=i&&(xi(i instanceof Uint8Array,"personal must be Uint8Array or Buffer"),xi(i.length===qi,"personal must be exactly "+qi+", was given "+i.length))),Gi.length||(Gi.push(Si),Si+=216),this.digestLength=t,this.finalized=!1,this.pointer=Gi.pop(),this._memory=new Uint8Array(Bi.memory.buffer),this._memory.fill(0,0,64),this._memory[0]=this.digestLength,this._memory[1]=e?e.length:0,this._memory[2]=1,this._memory[3]=1,a&&this._memory.set(a,32),i&&this._memory.set(i,48),this.pointer+216>this._memory.length&&this._realloc(this.pointer+216),Bi.blake2b_init(this.pointer,this.digestLength),e&&(this.update(e),this._memory.fill(0,Si,Si+e.length),this._memory[this.pointer+200]=128)}function Ti(){}function ki(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 Ri(t,e){const a=new DataView(t.buffer,t.byteOffset,t.byteLength);let i="";for(let t=0;t<4;t++){t>0&&(i+="\n"),i+="\t\t";for(let e=0;e<4;e++)e>0&&(i+=" "),i+=a.getUint32(16*t+4*e).toString(16).padStart(8,"0")}return e&&(i=e+"\n"+i),i}function Di(t,e){if(t.byteLength!=e.byteLength)return!1;for(var a=new Int8Array(t),i=new Int8Array(e),o=0;o!=t.byteLength;o++)if(a[o]!=i[o])return!1;return!0}function Ni(t){const e=t.getPartialHash(),a=$a.exports(64);return a.setPartialHash(e),a}async function Vi(t,e,a,i,o){if(t.G1.isZero(e))return!1;if(t.G1.isZero(a))return!1;if(t.G2.isZero(i))return!1;if(t.G2.isZero(o))return!1;return await t.pairingEq(e,o,t.G1.neg(a),i)}async function Ki(t){for(;!t;)t=await window.prompt("Enter a random text. (Entropy): ","");const e=$a.exports(64);e.update(M.randomBytes(64));const a=new TextEncoder;e.update(a.encode(t));const i=Buffer.from(e.digest()),o=[];for(let t=0;t<8;t++)o[t]=i.readUInt32BE(4*t);return new q(o)}function ji(t,e){let a,i;e<32?(a=1<<e>>>0,i=1):(a=4294967296,i=1<<e-32>>>0);let o=t;for(let t=0;t<i;t++)for(let t=0;t<a;t++)o=M.createHash("sha256").update(o).digest();const n=new DataView(o.buffer,o.byteOffset,o.byteLength),c=[];for(let t=0;t<8;t++)c[t]=n.getUint32(4*t,!1);return new q(c)}function Hi(t){return t instanceof Uint8Array?t:("0x"==t.slice(0,2)&&(t=t.slice(2)),new Uint8Array(t.match(/[\da-f]{2}/gi).map((function(t){return parseInt(t,16)}))))}function $i(t){return Array.prototype.map.call(t,(function(t){return("0"+(255&t).toString(16)).slice(-2)})).join("")}function Yi(t,e){if(e instanceof Uint8Array)return t.toString(e);if(Array.isArray(e))return e.map(Yi.bind(null,t));if("object"==typeof e){const a={};return Object.keys(e).forEach((i=>{a[i]=Yi(t,e[i])})),a}return"bigint"==typeof e||void 0!==e.eq?e.toString(10):e}async function Wi(t,e){await za(t,1),await t.writeULE32(1),await Qa(t);const a=await ja(e.q);await za(t,2);const i=a.q,o=8*(Math.floor((ha.bitLength(i)-1)/64)+1),n=a.r,c=8*(Math.floor((ha.bitLength(n)-1)/64)+1);await t.writeULE32(o),await Ta(t,i,o),await t.writeULE32(c),await Ta(t,n,c),await t.writeULE32(e.nVars),await t.writeULE32(e.nPublic),await t.writeULE32(e.domainSize),await Zi(t,a,e.vk_alpha_1),await Zi(t,a,e.vk_beta_1),await Ji(t,a,e.vk_beta_2),await Ji(t,a,e.vk_gamma_2),await Zi(t,a,e.vk_delta_1),await Ji(t,a,e.vk_delta_2),await Qa(t)}async function Zi(t,e,a){const i=new Uint8Array(2*e.G1.F.n8);e.G1.toRprLEM(i,0,a),await t.write(i)}async function Ji(t,e,a){const i=new Uint8Array(2*e.G2.F.n8);e.G2.toRprLEM(i,0,a),await t.write(i)}async function Xi(t,e,a){const i=await t.read(2*e.G1.F.n8),o=e.G1.fromRprLEM(i,0);return a?e.G1.toObject(o):o}async function to(t,e,a){const i=await t.read(2*e.G2.F.n8),o=e.G2.fromRprLEM(i,0);return a?e.G2.toObject(o):o}async function eo(t,e,a){await qa(t,e,1);const i=await t.readULE32();if(await Ma(t),1==i)return await async function(t,e,a){const i={protocol:"groth16"};await qa(t,e,2);const o=await t.readULE32();i.n8q=o,i.q=await ka(t,o);const n=await t.readULE32();return i.n8r=n,i.r=await ka(t,n),i.curve=await ja(i.q),i.nVars=await t.readULE32(),i.nPublic=await t.readULE32(),i.domainSize=await t.readULE32(),i.power=ki(i.domainSize),i.vk_alpha_1=await Xi(t,i.curve,a),i.vk_beta_1=await Xi(t,i.curve,a),i.vk_beta_2=await to(t,i.curve,a),i.vk_gamma_2=await to(t,i.curve,a),i.vk_delta_1=await Xi(t,i.curve,a),i.vk_delta_2=await to(t,i.curve,a),await Ma(t),i}(t,e,a);if(2==i)return await async function(t,e,a){const i={protocol:"plonk"};await qa(t,e,2);const o=await t.readULE32();i.n8q=o,i.q=await ka(t,o);const n=await t.readULE32();return i.n8r=n,i.r=await ka(t,n),i.curve=await ja(i.q),i.nVars=await t.readULE32(),i.nPublic=await t.readULE32(),i.domainSize=await t.readULE32(),i.power=ki(i.domainSize),i.nAdditions=await t.readULE32(),i.nConstrains=await t.readULE32(),i.k1=await t.read(n),i.k2=await t.read(n),i.Qm=await Xi(t,i.curve,a),i.Ql=await Xi(t,i.curve,a),i.Qr=await Xi(t,i.curve,a),i.Qo=await Xi(t,i.curve,a),i.Qc=await Xi(t,i.curve,a),i.S1=await Xi(t,i.curve,a),i.S2=await Xi(t,i.curve,a),i.S3=await Xi(t,i.curve,a),i.X_2=await to(t,i.curve,a),await Ma(t),i}(t,e,a);throw new Error("Protocol not supported: ")}async function ao(t,e,a){const i={delta:{}};i.deltaAfter=await Xi(t,e,a),i.delta.g1_s=await Xi(t,e,a),i.delta.g1_sx=await Xi(t,e,a),i.delta.g2_spx=await to(t,e,a),i.transcript=await t.read(64),i.type=await t.readULE32();const o=await t.readULE32(),n=t.pos;let c=0;for(;t.pos-n<o;){const e=await t.read(1);if(e[0]<=c)throw new Error("Parameters in the contribution must be sorted");if(c=e[0],1==e[0]){const e=await t.read(1),a=await t.read(e[0]);i.name=(new TextDecoder).decode(a)}else if(2==e[0]){const e=await t.read(1);i.numIterationsExp=e[0]}else{if(3!=e[0])throw new Error("Parameter not recognized");{const e=await t.read(1);i.beaconHash=await t.read(e[0])}}}if(t.pos!=n+o)throw new Error("Parametes do not match");return i}async function io(t,e,a){await qa(t,a,10);const i={contributions:[]};i.csHash=await t.read(64);const o=await t.readULE32();for(let a=0;a<o;a++){const a=await ao(t,e);i.contributions.push(a)}return await Ma(t),i}async function oo(t,e,a){await Zi(t,e,a.deltaAfter),await Zi(t,e,a.delta.g1_s),await Zi(t,e,a.delta.g1_sx),await Ji(t,e,a.delta.g2_spx),await t.write(a.transcript),await t.writeULE32(a.type||0);const i=[];if(a.name){i.push(1);const t=new TextEncoder("utf-8").encode(a.name.substring(0,64));i.push(t.byteLength);for(let e=0;e<t.byteLength;e++)i.push(t[e])}if(1==a.type){i.push(2),i.push(a.numIterationsExp),i.push(3),i.push(a.beaconHash.byteLength);for(let t=0;t<a.beaconHash.byteLength;t++)i.push(a.beaconHash[t])}if(i.length>0){const e=new Uint8Array(i);await t.writeULE32(e.byteLength),await t.write(e)}else await t.writeULE32(0)}async function no(t,e,a){await za(t,10),await t.write(a.csHash),await t.writeULE32(a.contributions.length);for(let i=0;i<a.contributions.length;i++)await oo(t,e,a.contributions[i]);await Qa(t)}function co(t,e,a){const i=new Uint8Array(2*e.G1.F.n8);e.G1.toRprUncompressed(i,0,a),t.update(i)}function ro(t,e,a){co(t,e,a.deltaAfter),co(t,e,a.delta.g1_s),co(t,e,a.delta.g1_sx),function(t,e,a){const i=new Uint8Array(2*e.G2.F.n8);e.G2.toRprUncompressed(i,0,a),t.update(i)}(t,e,a.delta.g2_spx),t.update(a.transcript)}async function lo(t,e){await qa(t,e,1);const a=await t.readULE32(),i=await ka(t,a),o=await t.readULE32();return await Ma(t),{n8:a,q:i,nWitness:o}}Mi.prototype._realloc=function(t){Bi.memory.grow(Math.max(0,Math.ceil(Math.abs(t-this._memory.length)/65536))),this._memory=new Uint8Array(Bi.memory.buffer)},Mi.prototype.update=function(t){return xi(!1===this.finalized,"Hash instance finalized"),xi(t instanceof Uint8Array,"input must be Uint8Array or Buffer"),Si+t.length>this._memory.length&&this._realloc(Si+t.length),this._memory.set(t,Si),Bi.blake2b_update(this.pointer,Si,Si+t.length),this},Mi.prototype.digest=function(t){if(xi(!1===this.finalized,"Hash instance finalized"),this.finalized=!0,Gi.push(this.pointer),Bi.blake2b_final(this.pointer),!t||"binary"===t)return this._memory.slice(this.pointer+128,this.pointer+128+this.digestLength);if("string"==typeof t)return Ei.toString(this._memory,t,this.pointer+128,this.pointer+128+this.digestLength);xi(t instanceof Uint8Array&&t.length>=this.digestLength,"input must be Uint8Array or Buffer");for(var e=0;e<this.digestLength;e++)t[e]=this._memory[this.pointer+128+e];return t},Mi.prototype.final=Mi.prototype.digest,Mi.WASM=Bi,Mi.SUPPORTED="undefined"!=typeof WebAssembly,Mi.ready=function(t){return t||(t=Ti),vi?vi.then((()=>t()),t):t(new Error("WebAssembly not supported"))},Mi.prototype.ready=Mi.ready,Mi.prototype.getPartialHash=function(){return this._memory.slice(this.pointer,this.pointer+216)},Mi.prototype.setPartialHash=function(t){this._memory.set(t,this.pointer)};const{stringifyBigInts:so}=pa;async function uo(t,e,a){const{fd:i,sections:o}=await Ua(e,"wtns",2),n=await lo(i,o),{fd:c,sections:r}=await Ua(t,"zkey",2),l=await eo(c,r);if("groth16"!=l.protocol)throw new Error("zkey file is not groth16");if(!ha.eq(l.r,n.q))throw new Error("Curve of the witness does not match the curve of the proving key");if(n.nWitness!=l.nVars)throw new Error(`Invalid witness length. Circuit: ${l.nVars}, witness: ${n.nWitness}`);const s=l.curve,d=s.Fr,u=s.G1,g=s.G2,_=ki(l.domainSize);a&&a.debug("Reading Wtns");const f=await Da(i,o,2);a&&a.debug("Reading Coeffs");const h=await Da(c,r,4);a&&a.debug("Building ABC");const[p,m,L]=await async function(t,e,a,i,o){const n=t.Fr.n8,c=12+e.n8r,r=(i.byteLength-4)/c,l=new Pe(e.domainSize*n),s=new Pe(e.domainSize*n),d=new Pe(e.domainSize*n),u=[l,s];for(let e=0;e<r;e++){o&&e%1e6==0&&o.debug(`QAP AB: ${e}/${r}`);const l=i.slice(4+e*c,4+e*c+c),s=new DataView(l.buffer),d=s.getUint32(0,!0),g=s.getUint32(4,!0),_=s.getUint32(8,!0),f=l.slice(12,12+n);u[d].set(t.Fr.add(u[d].slice(g*n,g*n+n),t.Fr.mul(f,a.slice(_*n,_*n+n))),g*n)}for(let a=0;a<e.domainSize;a++)o&&a%1e6==0&&o.debug(`QAP C: ${a}/${e.domainSize}`),d.set(t.Fr.mul(l.slice(a*n,a*n+n),s.slice(a*n,a*n+n)),a*n);return[l,s,d]}(s,l,f,h,a),w=_==d.s?s.Fr.shift:s.Fr.w[_+1],A=await d.ifft(p,"","",a,"IFFT_A"),b=await d.batchApplyKey(A,d.e(1),w),y=await d.fft(b,"","",a,"FFT_A"),I=await d.ifft(m,"","",a,"IFFT_B"),C=await d.batchApplyKey(I,d.e(1),w),F=await d.fft(C,"","",a,"FFT_B"),x=await d.ifft(L,"","",a,"IFFT_C"),E=await d.batchApplyKey(x,d.e(1),w),B=await d.fft(E,"","",a,"FFT_C");a&&a.debug("Join ABC");const v=await async function(t,e,a,i,o,n){const c=1<<22,r=t.Fr.n8,l=Math.floor(a.byteLength/t.Fr.n8),s=[];for(let e=0;e<l;e+=c){n&&n.debug(`JoinABC: ${e}/${l}`);const d=Math.min(l-e,c),u=[],g=a.slice(e*r,(e+d)*r),_=i.slice(e*r,(e+d)*r),f=o.slice(e*r,(e+d)*r);u.push({cmd:"ALLOCSET",var:0,buff:g}),u.push({cmd:"ALLOCSET",var:1,buff:_}),u.push({cmd:"ALLOCSET",var:2,buff:f}),u.push({cmd:"ALLOC",var:3,len:d*r}),u.push({cmd:"CALL",fnName:"qap_joinABC",params:[{var:0},{var:1},{var:2},{val:d},{var:3}]}),u.push({cmd:"CALL",fnName:"frm_batchFromMontgomery",params:[{var:3},{val:d},{var:3}]}),u.push({cmd:"GET",out:0,var:3,len:d*r}),s.push(t.tm.queueAction(u))}const d=await Promise.all(s);let u;u=a instanceof Pe?new Pe(a.byteLength):new Uint8Array(a.byteLength);let g=0;for(let t=0;t<d.length;t++)u.set(d[t][0],g),g+=d[t][0].byteLength;return u}(s,0,y,F,B,a);let S={};a&&a.debug("Reading A Points");const G=await Da(c,r,5);S.pi_a=await s.G1.multiExpAffine(G,f,a,"multiexp A"),a&&a.debug("Reading B1 Points");const P=await Da(c,r,6);let U=await s.G1.multiExpAffine(P,f,a,"multiexp B1");a&&a.debug("Reading B2 Points");const O=await Da(c,r,7);S.pi_b=await s.G2.multiExpAffine(O,f,a,"multiexp B2"),a&&a.debug("Reading C Points");const z=await Da(c,r,8);S.pi_c=await s.G1.multiExpAffine(z,f.slice((l.nPublic+1)*s.Fr.n8),a,"multiexp C"),a&&a.debug("Reading H Points");const Q=await Da(c,r,9),q=await s.G1.multiExpAffine(Q,v,a,"multiexp H"),M=s.Fr.random(),T=s.Fr.random();S.pi_a=u.add(S.pi_a,l.vk_alpha_1),S.pi_a=u.add(S.pi_a,u.timesFr(l.vk_delta_1,M)),S.pi_b=g.add(S.pi_b,l.vk_beta_2),S.pi_b=g.add(S.pi_b,g.timesFr(l.vk_delta_2,T)),U=u.add(U,l.vk_beta_1),U=u.add(U,u.timesFr(l.vk_delta_1,T)),S.pi_c=u.add(S.pi_c,q),S.pi_c=u.add(S.pi_c,u.timesFr(S.pi_a,T)),S.pi_c=u.add(S.pi_c,u.timesFr(U,M)),S.pi_c=u.add(S.pi_c,u.timesFr(l.vk_delta_1,d.neg(d.mul(M,T))));let k=[];for(let t=1;t<=l.nPublic;t++){const e=f.slice(t*d.n8,t*d.n8+d.n8);k.push(ha.fromRprLE(e))}return S.pi_a=u.toObject(u.toAffine(S.pi_a)),S.pi_b=g.toObject(g.toAffine(S.pi_b)),S.pi_c=u.toObject(u.toAffine(S.pi_c)),S.protocol="groth16",S.curve=s.name,await c.close(),await i.close(),S=so(S),k=so(k),{proof:S,publicSignals:k}}function go(t){var e=[];return function t(e,a){if(Array.isArray(a))for(let i=0;i<a.length;i++)t(e,a[i]);else e.push(a)}(e,t),e}function _o(t){const e=BigInt(2)**BigInt(64);let a=BigInt("0xCBF29CE484222325");for(var i=0;i<t.length;i++)a^=BigInt(t[i].charCodeAt()),a*=BigInt(1099511628211),a%=e;let o=a.toString(16),n=16-o.length;return o="0".repeat(n).concat(o),o}function fo(t,e){const a=[];let i=BigInt(t);const o=BigInt(4294967296);for(;i;)a.unshift(Number(i%o)),i/=o;if(e)for(var n=e-a.length;n>0;)a.unshift(0),n--;return a}async function ho(t,e){e=e||{};let a,i=32767,o=!1;for(;!o;)try{a=new WebAssembly.Memory({initial:i}),o=!0}catch(t){if(1===i)throw t;console.warn("Could not allocate "+1024*i*64+" bytes. This may cause severe instability. Trying with "+1024*i*64/2+" bytes"),i=Math.floor(i/2)}const n=await WebAssembly.compile(t);let c,r="",l="",s=1,d=0,u=0;const g=await WebAssembly.instantiate(n,{env:{memory:a},runtime:{exceptionHandler:function(t){let e;throw e=1==t?"Signal not found. ":2==t?"Too many signals set. ":3==t?"Signal already set. ":4==t?"Assert Failed. ":5==t?"Not enough memory. ":6==t?"Input signal array access exceeds the size. ":"Unknown error. ",console.error("ERROR: ",t,r),new Error(e+r)},printErrorMessage:function(){r+=f()+"\n"},writeBufferMessage:function(){const t=f();"\n"===t?(console.log(l),l=""):(""!==l&&(l+=" "),l+=t)},showSharedRWMemory:function(){const t=g.exports.getFieldNumLen32(),e=new Uint32Array(t);for(let a=0;a<t;a++)e[t-1-a]=g.exports.readSharedRWMemory(a);if(s>=2&&(d>=1||u>=7)){""!==l&&(l+=" ");const t=ha.fromArray(e,4294967296).toString();l+=t}else console.log(ha.fromArray(e,4294967296))},error:function(t,a,i,o,n,r){let l;throw l=7==t?h(a)+" "+c.getFr(o).toString()+" != "+c.getFr(n).toString()+" "+h(r):9==t?h(a)+" "+c.getFr(o).toString()+" "+h(n):5==t&&e.sym?h(a)+" "+e.sym.labelIdx2Name[n]:h(a)+" "+i+" "+o+" "+n+" "+r,console.log("ERROR: ",t,l),new Error(l)},log:function(t){console.log(c.getFr(t).toString())},logGetSignal:function(t,a){e.logGetSignal&&e.logGetSignal(t,c.getFr(a))},logSetSignal:function(t,a){e.logSetSignal&&e.logSetSignal(t,c.getFr(a))},logStartComponent:function(t){e.logStartComponent&&e.logStartComponent(t)},logFinishComponent:function(t){e.logFinishComponent&&e.logFinishComponent(t)}}});"function"==typeof g.exports.getVersion&&(s=g.exports.getVersion()),"function"==typeof g.exports.getMinorVersion&&(d=g.exports.getMinorVersion()),"function"==typeof g.exports.getPatchVersion&&(u=g.exports.getPatchVersion());const _=e&&(e.sanityCheck||e.logGetSignal||e.logSetSignal||e.logStartComponent||e.logFinishComponent);return c=2===s?new mo(g,_):new po(a,g,_),c;function f(){for(var t="",e=g.exports.getMessageChar();0!=e;)t+=String.fromCharCode(e),e=g.exports.getMessageChar();return t}function h(t){const e=new Uint8Array(a.buffer),i=[];for(let a=0;e[t+a]>0;a++)i.push(e[t+a]);return String.fromCharCode.apply(null,i)}}class po{constructor(t,e,a){this.memory=t,this.i32=new Uint32Array(t.buffer),this.instance=e,this.n32=(this.instance.exports.getFrLen()>>2)-2;const i=this.instance.exports.getPRawPrime(),o=new Array(this.n32);for(let t=0;t<this.n32;t++)o[this.n32-1-t]=this.i32[(i>>2)+t];this.prime=ha.fromArray(o,4294967296),this.Fr=new K(this.prime),this.mask32=ha.fromString("FFFFFFFF",16),this.NVars=this.instance.exports.getNVars(),this.n64=Math.floor((this.Fr.bitLength-1)/64)+1,this.R=this.Fr.e(ha.shiftLeft(1,64*this.n64)),this.RInv=this.Fr.inv(this.R),this.sanityCheck=a}circom_version(){return 1}async _doCalculateWitness(t,e){this.instance.exports.init(this.sanityCheck||e?1:0);const a=this.allocInt(),i=this.allocFr();Object.keys(t).forEach((e=>{const o=_o(e),n=parseInt(o.slice(0,8),16),c=parseInt(o.slice(8,16),16);try{this.instance.exports.getSignalOffset32(a,0,n,c)}catch(t){throw new Error(`Signal ${e} is not an input of the circuit.`)}const r=this.getInt(a),l=go(t[e]);for(let t=0;t<l.length;t++)this.setFr(i,l[t]),this.instance.exports.setSignal(0,0,r+t,i)}))}async calculateWitness(t,e){const a=this,i=a.i32[0],o=[];await a._doCalculateWitness(t,e);for(let t=0;t<a.NVars;t++){const e=a.instance.exports.getPWitness(t);o.push(a.getFr(e))}return a.i32[0]=i,o}async calculateBinWitness(t,e){const a=this,i=a.i32[0];await a._doCalculateWitness(t,e);const o=a.instance.exports.getWitnessBuffer();a.i32[0]=i;const n=a.memory.buffer.slice(o,o+a.NVars*a.n64*8);return new Uint8Array(n)}allocInt(){const t=this.i32[0];return this.i32[0]=t+8,t}allocFr(){const t=this.i32[0];return this.i32[0]=t+4*this.n32+8,t}getInt(t){return this.i32[t>>2]}setInt(t,e){this.i32[t>>2]=e}getFr(t){const e=this,a=t>>2;if(2147483648&e.i32[a+1]){const t=new Array(e.n32);for(let i=0;i<e.n32;i++)t[e.n32-1-i]=e.i32[a+2+i];const o=e.Fr.e(ha.fromArray(t,4294967296));return 1073741824&e.i32[a+1]?(i=o,e.Fr.mul(e.RInv,i)):o}return 2147483648&e.i32[a]?e.Fr.e(e.i32[a]-4294967296):e.Fr.e(e.i32[a]);var i}setFr(t,e){const a=this;e=a.Fr.e(e);const i=a.Fr.neg(a.Fr.e("80000000",16)),o=a.Fr.e("7FFFFFFF",16);if(a.Fr.geq(e,i)&&a.Fr.leq(e,o)){let o;return a.Fr.geq(e,a.Fr.zero)?o=ha.toNumber(e):(o=ha.toNumber(a.Fr.sub(e,i)),o-=2147483648,o=4294967296+o),a.i32[t>>2]=o,void(a.i32[1+(t>>2)]=0)}a.i32[t>>2]=0,a.i32[1+(t>>2)]=2147483648;const n=ha.toArray(e,4294967296);for(let e=0;e<a.n32;e++){const i=n.length-1-e;a.i32[2+(t>>2)+e]=i>=0?n[i]:0}}}class mo{constructor(t,e){this.instance=t,this.version=this.instance.exports.getVersion(),this.n32=this.instance.exports.getFieldNumLen32(),this.instance.exports.getRawPrime();const a=new Array(this.n32);for(let t=0;t<this.n32;t++)a[this.n32-1-t]=this.instance.exports.readSharedRWMemory(t);this.prime=ha.fromArray(a,4294967296),this.witnessSize=this.instance.exports.getWitnessSize(),this.sanityCheck=e}circom_version(){return this.instance.exports.getVersion()}async _doCalculateWitness(t,e){this.instance.exports.init(this.sanityCheck||e?1:0);const a=Object.keys(t);var i=0;if(a.forEach((e=>{const a=_o(e),o=parseInt(a.slice(0,8),16),n=parseInt(a.slice(8,16),16),c=go(t[e]);for(let t=0;t<c.length;t++){const e=fo(c[t],this.n32);for(let t=0;t<this.n32;t++)this.instance.exports.writeSharedRWMemory(t,e[this.n32-1-t]);try{this.instance.exports.setInputSignal(o,n,t),i++}catch(t){throw new Error(t)}}})),i<this.instance.exports.getInputSize())throw new Error(`Not all inputs have been set. Only ${i} out of ${this.instance.exports.getInputSize()}`)}async calculateWitness(t,e){const a=[];await this._doCalculateWitness(t,e);for(let t=0;t<this.witnessSize;t++){this.instance.exports.getWitness(t);const e=new Uint32Array(this.n32);for(let t=0;t<this.n32;t++)e[this.n32-1-t]=this.instance.exports.readSharedRWMemory(t);a.push(ha.fromArray(e,4294967296))}return a}async calculateWTNSBin(t,e){const a=new Uint32Array(this.witnessSize*this.n32+this.n32+11),i=new Uint8Array(a.buffer);await this._doCalculateWitness(t,e),i[0]="w".charCodeAt(0),i[1]="t".charCodeAt(0),i[2]="n".charCodeAt(0),i[3]="s".charCodeAt(0),a[1]=2,a[2]=2,a[3]=1;const o=4*this.n32,n=(8+o).toString(16);a[4]=parseInt(n.slice(0,8),16),a[5]=parseInt(n.slice(8,16),16),a[6]=o,this.instance.exports.getRawPrime();var c=7;for(let t=0;t<this.n32;t++)a[c+t]=this.instance.exports.readSharedRWMemory(t);a[c+=this.n32]=this.witnessSize,a[++c]=2,c++;const r=(o*this.witnessSize).toString(16);a[c]=parseInt(r.slice(0,8),16),a[c+1]=parseInt(r.slice(8,16),16),c+=2;for(let t=0;t<this.witnessSize;t++){this.instance.exports.getWitness(t);for(let t=0;t<this.n32;t++)a[c+t]=this.instance.exports.readSharedRWMemory(t);c+=this.n32}return i}}const{unstringifyBigInts:Lo}=pa;async function wo(t,e,a,i){const o=Lo(t),n=await Pa(e),c=await n.read(n.totalSize);await n.close();const r=await ho(c);if(1==r.circom_version()){const t=await r.calculateBinWitness(o),e=await Oa(a,"wtns",2,2);await async function(t,e,a){await za(t,1);const i=8*(Math.floor((ha.bitLength(a)-1)/64)+1);if(await t.writeULE32(i),await Ta(t,a,i),e.byteLength%i!=0)throw new Error("Invalid witness length");await t.writeULE32(e.byteLength/i),await Qa(t),await za(t,2),await t.write(e),await Qa(t)}(e,t,r.prime),await e.close()}else{const t=await Ga(a),e=await r.calculateWTNSBin(o);await t.write(e),await t.close()}}const{unstringifyBigInts:Ao}=pa;const{unstringifyBigInts:bo}=pa;const{unstringifyBigInts:yo}=pa;function Io(t){let e=t.toString(16);for(;e.length<64;)e="0"+e;return e=`"0x${e}"`,e}var Co=Object.freeze({__proto__:null,fullProve:async function(t,e,a,i){const o=Ao(t),n={type:"mem"};return await wo(o,e,n),await uo(a,n,i)},prove:uo,verify:async function(t,e,a,i){const o=bo(t),n=bo(a),c=bo(e),r=await Ha(o.curve),l=r.G1.fromObject(o.IC[0]),s=new Uint8Array(2*r.G1.F.n8*c.length),d=new Uint8Array(r.Fr.n8*c.length);for(let t=0;t<c.length;t++){const e=r.G1.fromObject(o.IC[t+1]);s.set(e,t*r.G1.F.n8*2),ha.toRprLE(d,r.Fr.n8*t,c[t],r.Fr.n8)}let u=await r.G1.multiExpAffine(s,d);u=r.G1.add(u,l);const g=r.G1.fromObject(n.pi_a),_=r.G2.fromObject(n.pi_b),f=r.G1.fromObject(n.pi_c),h=r.G2.fromObject(o.vk_gamma_2),p=r.G2.fromObject(o.vk_delta_2),m=r.G1.fromObject(o.vk_alpha_1),L=r.G2.fromObject(o.vk_beta_2);return await r.pairingEq(r.G1.neg(g),_,u,h,f,p,m,L)?(i&&i.info("OK!"),!0):(i&&i.error("Invalid proof"),!1)},exportSolidityCallData:async function(t,e){const a=yo(t),i=yo(e);let o,n="";for(let t=0;t<i.length;t++)""!=n&&(n+=","),n+=Io(i[t]);return o=`[${Io(a.pi_a[0])}, ${Io(a.pi_a[1])}],[[${Io(a.pi_b[0][1])}, ${Io(a.pi_b[0][0])}],[${Io(a.pi_b[1][1])}, ${Io(a.pi_b[1][0])}]],[${Io(a.pi_c[0])}, ${Io(a.pi_c[1])}],[${n}]`,o}});function Fo(t,e){const a=new DataView(e.buffer,e.byteOffset,e.byteLength),i=[];for(let t=0;t<8;t++)i[t]=a.getUint32(4*t);const o=new q(i);return t.G2.fromRng(o)}function xo(t,e,a,i,o){const n=$a.exports(64),c=new Uint8Array([e]);n.update(c),n.update(a);const r=t.G1.toUncompressed(i);n.update(r);const l=t.G1.toUncompressed(o);n.update(l);return Fo(t,n.digest())}function Eo(t,e,a,i,o){return t.g1_s=e.G1.toAffine(e.G1.fromRng(o)),t.g1_sx=e.G1.toAffine(e.G1.timesFr(t.g1_s,t.prvKey)),t.g2_sp=e.G2.toAffine(xo(e,a,i,t.g1_s,t.g1_sx)),t.g2_spx=e.G2.toAffine(e.G2.timesFr(t.g2_sp,t.prvKey)),t}function Bo(t,e,a){const i={tau:{},alpha:{},beta:{}};return i.tau.prvKey=t.Fr.fromRng(a),i.alpha.prvKey=t.Fr.fromRng(a),i.beta.prvKey=t.Fr.fromRng(a),Eo(i.tau,t,0,e,a),Eo(i.alpha,t,1,e,a),Eo(i.beta,t,2,e,a),i}async function vo(t,e,a,i){i||(i=a),await t.writeULE32(1);const o=t.pos;await t.writeULE64(0),await t.writeULE32(8*e.F1.n64);const n=new Uint8Array(e.F1.n8);ha.toRprLE(n,0,e.q,e.F1.n8),await t.write(n),await t.writeULE32(a),await t.writeULE32(i);const c=t.pos-o-8,r=t.pos;await t.writeULE64(c,o),t.pos=r}async function So(t,e){if(!e[1])throw new Error(t.fileName+": File has no header");if(e[1].length>1)throw new Error(t.fileName+": File has more than one header");t.pos=e[1][0].p;const a=await t.readULE32(),i=await t.read(a),o=ha.fromRprLE(i),n=await ja(o);if(8*n.F1.n64!=a)throw new Error(t.fileName+": Invalid size");const c=await t.readULE32(),r=await t.readULE32();if(t.pos-e[1][0].p!=e[1][0].size)throw new Error("Invalid PTau header size");return{curve:n,power:c,ceremonyPower:r}}function Go(t,e,a,i){const o={tau:{},alpha:{},beta:{}};return 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=n(),o.tau.g2_spx=c(),o.alpha.g2_spx=c(),o.beta.g2_spx=c(),o;function n(){let o;return o=i?a.G1.fromRprLEM(t,e):a.G1.fromRprUncompressed(t,e),e+=2*a.G1.F.n8,o}function c(){let o;return o=i?a.G2.fromRprLEM(t,e):a.G2.fromRprUncompressed(t,e),e+=2*a.G2.F.n8,o}}function Po(t,e,a,i,o){async function n(i){o?a.G1.toRprLEM(t,e,i):a.G1.toRprUncompressed(t,e,i),e+=2*a.F1.n8}async function c(i){o?a.G2.toRprLEM(t,e,i):a.G2.toRprUncompressed(t,e,i),e+=2*a.F2.n8}return n(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),c(i.tau.g2_spx),c(i.alpha.g2_spx),c(i.beta.g2_spx),t}async function Uo(t,e){const a={};a.tauG1=await l(),a.tauG2=await s(),a.alphaG1=await l(),a.betaG1=await l(),a.betaG2=await s(),a.key=await async function(t,e,a){return Go(await t.read(2*e.F1.n8*6+2*e.F2.n8*3),0,e,a)}(t,e,!0),a.partialHash=await t.read(216),a.nextChallenge=await t.read(64),a.type=await t.readULE32();const i=new Uint8Array(2*e.G1.F.n8*6+2*e.G2.F.n8*3);Po(i,0,e,a.key,!1);const o=$a.exports(64);o.setPartialHash(a.partialHash),o.update(i),a.responseHash=o.digest();const n=await t.readULE32(),c=t.pos;let r=0;for(;t.pos-c<n;){const t=await d(1);if(t[0]<=r)throw new Error("Parameters in the contribution must be sorted");if(r=t[0],1==t[0]){const t=await d(1),e=await d(t[0]);a.name=(new TextDecoder).decode(e)}else if(2==t[0]){const t=await d(1);a.numIterationsExp=t[0]}else{if(3!=t[0])throw new Error("Parameter not recognized");{const t=await d(1);a.beaconHash=await d(t[0])}}}if(t.pos!=c+n)throw new Error("Parametes do not match");return a;async function l(){const a=await t.read(2*e.G1.F.n8);return e.G1.fromRprLEM(a)}async function s(){const a=await t.read(2*e.G2.F.n8);return e.G2.fromRprLEM(a)}async function d(e){const a=await t.read(e);return new Uint8Array(a)}}async function Oo(t,e,a){if(!a[7])throw new Error(t.fileName+": File has no contributions");if(a[7][0].length>1)throw new Error(t.fileName+": File has more than one contributions section");t.pos=a[7][0].p;const i=await t.readULE32(),o=[];for(let a=0;a<i;a++){const i=await Uo(t,e);i.id=a+1,o.push(i)}if(t.pos-a[7][0].p!=a[7][0].size)throw new Error("Invalid contribution section size");return o}async function zo(t,e,a){const i=new Uint8Array(2*e.F1.n8),o=new Uint8Array(2*e.F2.n8);await c(a.tauG1),await r(a.tauG2),await c(a.alphaG1),await c(a.betaG1),await r(a.betaG2),await async function(t,e,a,i){const o=new Uint8Array(2*e.F1.n8*6+2*e.F2.n8*3);Po(o,0,e,a,i),await t.write(o)}(t,e,a.key,!0),await t.write(a.partialHash),await t.write(a.nextChallenge),await t.writeULE32(a.type||0);const n=[];if(a.name){n.push(1);const t=new TextEncoder("utf-8").encode(a.name.substring(0,64));n.push(t.byteLength);for(let e=0;e<t.byteLength;e++)n.push(t[e])}if(1==a.type){n.push(2),n.push(a.numIterationsExp),n.push(3),n.push(a.beaconHash.byteLength);for(let t=0;t<a.beaconHash.byteLength;t++)n.push(a.beaconHash[t])}if(n.length>0){const e=new Uint8Array(n);await t.writeULE32(e.byteLength),await t.write(e)}else await t.writeULE32(0);async function c(a){e.G1.toRprLEM(i,0,a),await t.write(i)}async function r(a){e.G2.toRprLEM(o,0,a),await t.write(o)}}async function Qo(t,e,a){await t.writeULE32(7);const i=t.pos;await t.writeULE64(0),await t.writeULE32(a.length);for(let i=0;i<a.length;i++)await zo(t,e,a[i]);const o=t.pos-i-8,n=t.pos;await t.writeULE64(o,i),t.pos=n}function qo(t,e,a){a&&a.debug("Calculating First Challenge Hash");const i=new $a.exports(64),o=new Uint8Array(2*t.G1.F.n8),n=new Uint8Array(2*t.G2.F.n8);let c;return t.G1.toRprUncompressed(o,0,t.G1.g),t.G2.toRprUncompressed(n,0,t.G2.g),i.update($a.exports(64).digest()),c=2**e*2-1,a&&a.debug("Calculate Initial Hash: tauG1"),r(o,c),c=2**e,a&&a.debug("Calculate Initial Hash: tauG2"),r(n,c),a&&a.debug("Calculate Initial Hash: alphaTauG1"),r(o,c),a&&a.debug("Calculate Initial Hash: betaTauG1"),r(o,c),i.update(n),i.digest();function r(t,e){const o=341e3,n=Math.floor(e/o),c=e%o,r=new Uint8Array(o*t.byteLength);for(let e=0;e<o;e++)r.set(t,e*t.byteLength);for(let t=0;t<n;t++)i.update(r),a&&a.debug("Initial hash: "+t*o);for(let e=0;e<c;e++)i.update(t)}}function Mo(t,e,a,i){return Bo(t,e,ji(a,i))}const To=Vi;async function ko(t,e,a,i){let o;if(1==e.type){const o=Mo(t,a.nextChallenge,e.beaconHash,e.numIterationsExp);if(!t.G1.eq(e.key.tau.g1_s,o.tau.g1_s))return i&&i.error(`BEACON key (tauG1_s) is not generated correctly in challenge #${e.id} ${e.name||""}`),!1;if(!t.G1.eq(e.key.tau.g1_sx,o.tau.g1_sx))return i&&i.error(`BEACON key (tauG1_sx) is not generated correctly in challenge #${e.id} ${e.name||""}`),!1;if(!t.G2.eq(e.key.tau.g2_spx,o.tau.g2_spx))return i&&i.error(`BEACON key (tauG2_spx) is not generated correctly in challenge #${e.id} ${e.name||""}`),!1;if(!t.G1.eq(e.key.alpha.g1_s,o.alpha.g1_s))return i&&i.error(`BEACON key (alphaG1_s) is not generated correctly in challenge #${e.id} ${e.name||""}`),!1;if(!t.G1.eq(e.key.alpha.g1_sx,o.alpha.g1_sx))return i&&i.error(`BEACON key (alphaG1_sx) is not generated correctly in challenge #${e.id} ${e.name||""}`),!1;if(!t.G2.eq(e.key.alpha.g2_spx,o.alpha.g2_spx))return i&&i.error(`BEACON key (alphaG2_spx) is not generated correctly in challenge #${e.id} ${e.name||""}`),!1;if(!t.G1.eq(e.key.beta.g1_s,o.beta.g1_s))return i&&i.error(`BEACON key (betaG1_s) is not generated correctly in challenge #${e.id} ${e.name||""}`),!1;if(!t.G1.eq(e.key.beta.g1_sx,o.beta.g1_sx))return i&&i.error(`BEACON key (betaG1_sx) is not generated correctly in challenge #${e.id} ${e.name||""}`),!1;if(!t.G2.eq(e.key.beta.g2_spx,o.beta.g2_spx))return i&&i.error(`BEACON key (betaG2_spx) is not generated correctly in challenge #${e.id} ${e.name||""}`),!1}return e.key.tau.g2_sp=t.G2.toAffine(xo(t,0,a.nextChallenge,e.key.tau.g1_s,e.key.tau.g1_sx)),e.key.alpha.g2_sp=t.G2.toAffine(xo(t,1,a.nextChallenge,e.key.alpha.g1_s,e.key.alpha.g1_sx)),e.key.beta.g2_sp=t.G2.toAffine(xo(t,2,a.nextChallenge,e.key.beta.g1_s,e.key.beta.g1_sx)),o=await To(t,e.key.tau.g1_s,e.key.tau.g1_sx,e.key.tau.g2_sp,e.key.tau.g2_spx),!0!==o?(i&&i.error("INVALID key (tau) in challenge #"+e.id),!1):(o=await To(t,e.key.alpha.g1_s,e.key.alpha.g1_sx,e.key.alpha.g2_sp,e.key.alpha.g2_spx),!0!==o?(i&&i.error("INVALID key (alpha) in challenge #"+e.id),!1):(o=await To(t,e.key.beta.g1_s,e.key.beta.g1_sx,e.key.beta.g2_sp,e.key.beta.g2_spx),!0!==o?(i&&i.error("INVALID key (beta) in challenge #"+e.id),!1):(o=await To(t,a.tauG1,e.tauG1,e.key.tau.g2_sp,e.key.tau.g2_spx),!0!==o?(i&&i.error("INVALID tau*G1. challenge #"+e.id+" It does not follow the previous contribution"),!1):(o=await To(t,e.key.tau.g1_s,e.key.tau.g1_sx,a.tauG2,e.tauG2),!0!==o?(i&&i.error("INVALID tau*G2. challenge #"+e.id+" It does not follow the previous contribution"),!1):(o=await To(t,a.alphaG1,e.alphaG1,e.key.alpha.g2_sp,e.key.alpha.g2_spx),!0!==o?(i&&i.error("INVALID alpha*G1. challenge #"+e.id+" It does not follow the previous contribution"),!1):(o=await To(t,a.betaG1,e.betaG1,e.key.beta.g2_sp,e.key.beta.g2_spx),!0!==o?(i&&i.error("INVALID beta*G1. challenge #"+e.id+" It does not follow the previous contribution"),!1):(o=await To(t,e.key.beta.g1_s,e.key.beta.g1_sx,a.betaG2,e.betaG2),!0!==o?(i&&i.error("INVALID beta*G2. challenge #"+e.id+"It does not follow the previous contribution"),!1):(i&&i.info("Powers Of tau file OK!"),!0))))))))}async function Ro(t,e,a,i,o,n,c,r,l,s){const d=o[n],u=2*d.F.n8,g=e[i][0].size/u;await qa(t,e,i),await za(a,i);let _=c;for(let e=0;e<g;e+=65536){s&&s.debug(`Applying key: ${l}: ${e}/${g}`);const i=Math.min(g-e,65536);let n;n=await t.read(i*u),n=await d.batchApplyKey(n,_,r),await a.write(n),_=o.Fr.mul(_,o.Fr.exp(r,i))}await Qa(a),await Ma(t)}async function Do(t,e,a,i,o,n,c,r,l,s,d){const u=i[o],g=2*u.F.n8,_=Math.floor((1<<20)/g);let f=c;for(let o=0;o<n;o+=_){d&&d.debug(`Applying key ${s}: ${o}/${n}`);const c=Math.min(n-o,_),h=await t.read(c*g),p=await u.batchUtoLEM(h),m=await u.batchApplyKey(p,f,r);let L;L="COMPRESSED"==l?await u.batchLEMtoC(m):await u.batchLEMtoU(m),a&&a.update(L),await e.write(L),f=i.Fr.mul(f,i.Fr.exp(r,c))}}var No=Object.freeze({__proto__:null,newAccumulator:async function(t,e,a,i){await $a.exports.ready();const o=await Oa(a,"ptau",1,7);await vo(o,t,e,0);const n=t.G1.oneAffine,c=t.G2.oneAffine;await za(o,2);const r=2**e*2-1;for(let t=0;t<r;t++)await o.write(n),i&&t%1e5==0&&t&&i.log("tauG1: "+t);await Qa(o),await za(o,3);const l=2**e;for(let t=0;t<l;t++)await o.write(c),i&&t%1e5==0&&t&&i.log("tauG2: "+t);await Qa(o),await za(o,4);const s=2**e;for(let t=0;t<s;t++)await o.write(n),i&&t%1e5==0&&t&&i.log("alphaTauG1: "+t);await Qa(o),await za(o,5);const d=2**e;for(let t=0;t<d;t++)await o.write(n),i&&t%1e5==0&&t&&i.log("betaTauG1: "+t);await Qa(o),await za(o,6),await o.write(c),await Qa(o),await za(o,7),await o.writeULE32(0),await Qa(o),await o.close();const u=qo(t,e,i);return i&&i.debug(Ri($a.exports(64).digest(),"Blank Contribution Hash:")),i&&i.info(Ri(u,"First Contribution Hash:")),u},exportChallenge:async function(t,e,a){await $a.exports.ready();const{fd:i,sections:o}=await Ua(t,"ptau",1),{curve:n,power:c}=await So(i,o),r=await Oo(i,n,o);let l,s;0==r.length?(l=$a.exports(64).digest(),s=qo(n,c)):(l=r[r.length-1].responseHash,s=r[r.length-1].nextChallenge),a&&a.info(Ri(l,"Last Response Hash: ")),a&&a.info(Ri(s,"New Challenge Hash: "));const d=await Ga(e),u=$a.exports(64);await d.write(l),u.update(l),await _(2,"G1",2**c*2-1,"tauG1"),await _(3,"G2",2**c,"tauG2"),await _(4,"G1",2**c,"alphaTauG1"),await _(5,"G1",2**c,"betaTauG1"),await _(6,"G2",1,"betaG2"),await i.close(),await d.close();const g=u.digest();if(!Di(s,g))throw a&&a.info(Ri(g,"Calc Curret Challenge Hash: ")),a&&a.error("PTau file is corrupted. Calculated new challenge hash does not match with the eclared one"),new Error("PTau file is corrupted. Calculated new challenge hash does not match with the eclared one");return s;async function _(t,e,c,r){const l=n[e],s=2*l.F.n8,g=Math.floor((1<<24)/s);await qa(i,o,t);for(let t=0;t<c;t+=g){a&&a.debug(`Exporting ${r}: ${t}/${c}`);const e=Math.min(c-t,g);let o;o=await i.read(e*s),o=await l.batchLEMtoU(o),await d.write(o),u.update(o)}await Ma(i)}},importResponse:async function(t,e,a,i,o,n){await $a.exports.ready();const c=new Uint8Array(64);for(let t=0;t<64;t++)c[t]=255;const{fd:r,sections:l}=await Ua(t,"ptau",1),{curve:s,power:d}=await So(r,l),u=await Oo(r,s,l),g={};i&&(g.name=i);const _=2*s.F1.n8,f=s.F1.n8,h=2*s.F2.n8,p=s.F2.n8,m=await Pa(e);if(m.totalSize!=64+(2**d*2-1)*f+2**d*p+2**d*f+2**d*f+p+6*_+3*h)throw new Error("Size of the contribution is invalid");let L;L=u.length>0?u[u.length-1].nextChallenge:qo(s,d,n);const w=await Oa(a,"ptau",1,o?7:2);await vo(w,s,d);const A=await m.read(64);if(Di(c,L)&&(L=A,u[u.length-1].nextChallenge=L),!Di(A,L))throw new Error("Wrong contribution. this contribution is not based on the previus hash");const b=new $a.exports(64);b.update(A);const y=[];let I;I=await x(m,w,"G1",2,2**d*2-1,[1],"tauG1"),g.tauG1=I[0],I=await x(m,w,"G2",3,2**d,[1],"tauG2"),g.tauG2=I[0],I=await x(m,w,"G1",4,2**d,[0],"alphaG1"),g.alphaG1=I[0],I=await x(m,w,"G1",5,2**d,[0],"betaG1"),g.betaG1=I[0],I=await x(m,w,"G2",6,1,[0],"betaG2"),g.betaG2=I[0],g.partialHash=b.getPartialHash();const C=await m.read(2*s.F1.n8*6+2*s.F2.n8*3);g.key=Go(C,0,s,!1),b.update(new Uint8Array(C));const F=b.digest();if(n&&n.info(Ri(F,"Contribution Response Hash imported: ")),o){const t=new $a.exports(64);t.update(F),await E(t,w,"G1",2,2**d*2-1,"tauG1",n),await E(t,w,"G2",3,2**d,"tauG2",n),await E(t,w,"G1",4,2**d,"alphaTauG1",n),await E(t,w,"G1",5,2**d,"betaTauG1",n),await E(t,w,"G2",6,1,"betaG2",n),g.nextChallenge=t.digest(),n&&n.info(Ri(g.nextChallenge,"Next Challenge Hash: "))}else g.nextChallenge=c;return u.push(g),await Qo(w,s,u),await m.close(),await w.close(),await r.close(),g.nextChallenge;async function x(t,e,a,i,c,r,l){return o?await async function(t,e,a,i,o,c,r){const l=s[a],d=l.F.n8,u=2*l.F.n8,g=[];await za(e,i);const _=Math.floor((1<<24)/u);y[i]=e.pos;for(let a=0;a<o;a+=_){n&&n.debug(`Importing ${r}: ${a}/${o}`);const i=Math.min(o-a,_),s=await t.read(i*d);b.update(s);const f=await l.batchCtoLEM(s);await e.write(f);for(let t=0;t<c.length;t++){const e=c[t];if(e>=a&&e<a+i){const t=l.fromRprLEM(f,(e-a)*u);g.push(t)}}}return await Qa(e),g}(t,e,a,i,c,r,l):await async function(t,e,a,i,o,c,r){const l=s[a],d=l.F.n8,u=[],g=Math.floor((1<<24)/d);for(let e=0;e<o;e+=g){n&&n.debug(`Importing ${r}: ${e}/${o}`);const a=Math.min(o-e,g),i=await t.read(a*d);b.update(i);for(let t=0;t<c.length;t++){const o=c[t];if(o>=e&&o<e+a){const t=l.fromRprCompressed(i,(o-e)*d);u.push(t)}}}return u}(t,0,a,0,c,r,l)}async function E(t,e,a,i,o,n,c){const r=s[a],l=2*r.F.n8,d=Math.floor((1<<24)/l),u=e.pos;e.pos=y[i];for(let a=0;a<o;a+=d){c&&c.debug(`Hashing ${n}: ${a}/${o}`);const i=Math.min(o-a,d),s=await e.read(i*l),u=await r.batchLEMtoU(s);t.update(u)}e.pos=u}},verify:async function(t,e){let a;await $a.exports.ready();const{fd:i,sections:o}=await Ua(t,"ptau",1),{curve:n,power:c,ceremonyPower:r}=await So(i,o),l=await Oo(i,n,o);e&&e.debug("power: 2**"+c),e&&e.debug("Computing initial contribution hash");const s={tauG1:n.G1.g,tauG2:n.G2.g,alphaG1:n.G1.g,betaG1:n.G1.g,betaG2:n.G2.g,nextChallenge:qo(n,r,e),responseHash:$a.exports(64).digest()};if(0==l.length)return e&&e.error("This file has no contribution! It cannot be used in production"),!1;let d;d=l.length>1?l[l.length-2]:s;const u=l[l.length-1];if(e&&e.debug("Validating contribution #"+l[l.length-1].id),!await ko(n,u,d,e))return!1;const g=$a.exports(64);g.update(u.responseHash),e&&e.debug("Verifying powers in tau*G1 section");const _=await A(2,"G1","tauG1",2**c*2-1,[0,1],e);if(a=await To(n,_.R1,_.R2,n.G2.g,u.tauG2),!0!==a)return e&&e.error("tauG1 section. Powers do not match"),!1;if(!n.G1.eq(n.G1.g,_.singularPoints[0]))return e&&e.error("First element of tau*G1 section must be the generator"),!1;if(!n.G1.eq(u.tauG1,_.singularPoints[1]))return e&&e.error("Second element of tau*G1 section does not match the one in the contribution section"),!1;e&&e.debug("Verifying powers in tau*G2 section");const f=await A(3,"G2","tauG2",2**c,[0,1],e);if(a=await To(n,n.G1.g,u.tauG1,f.R1,f.R2),!0!==a)return e&&e.error("tauG2 section. Powers do not match"),!1;if(!n.G2.eq(n.G2.g,f.singularPoints[0]))return e&&e.error("First element of tau*G2 section must be the generator"),!1;if(!n.G2.eq(u.tauG2,f.singularPoints[1]))return e&&e.error("Second element of tau*G2 section does not match the one in the contribution section"),!1;e&&e.debug("Verifying powers in alpha*tau*G1 section");const h=await A(4,"G1","alphatauG1",2**c,[0],e);if(a=await To(n,h.R1,h.R2,n.G2.g,u.tauG2),!0!==a)return e&&e.error("alphaTauG1 section. Powers do not match"),!1;if(!n.G1.eq(u.alphaG1,h.singularPoints[0]))return e&&e.error("First element of alpha*tau*G1 section (alpha*G1) does not match the one in the contribution section"),!1;e&&e.debug("Verifying powers in beta*tau*G1 section");const p=await A(5,"G1","betatauG1",2**c,[0],e);if(a=await To(n,p.R1,p.R2,n.G2.g,u.tauG2),!0!==a)return e&&e.error("betaTauG1 section. Powers do not match"),!1;if(!n.G1.eq(u.betaG1,p.singularPoints[0]))return e&&e.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 e=n.G2,a=2*e.F.n8,c=new Uint8Array(a);if(!o[6])throw t.error("File has no BetaG2 section"),new Error("File has no BetaG2 section");if(o[6].length>1)throw t.error("File has no BetaG2 section"),new Error("File has more than one GetaG2 section");i.pos=o[6][0].p;const r=await i.read(a),l=e.fromRprLEM(r);return e.toRprUncompressed(c,0,l),g.update(c),l}(e);if(!n.G2.eq(u.betaG2,m))return e&&e.error("betaG2 element in betaG2 section does not match the one in the contribution section"),!1;const L=g.digest();if(c==r&&!Di(L,u.nextChallenge))return e&&e.error("Hash of the values does not match the next challenge of the last contributor in the contributions section"),!1;e&&e.info(Ri(L,"Next challenge hash: ")),w(u,d);for(let t=l.length-2;t>=0;t--){const a=l[t],i=t>0?l[t-1]:s;if(!await ko(n,a,i,e))return!1;w(a,i)}if(e&&e.info("-----------------------------------------------------"),o[12]&&o[13]&&o[14]&&o[15]){let t;if(t=await b("G1",2,12,"tauG1",e),!t)return!1;if(t=await b("G2",3,13,"tauG2",e),!t)return!1;if(t=await b("G1",4,14,"alphaTauG1",e),!t)return!1;if(t=await b("G1",5,15,"betaTauG1",e),!t)return!1}else e&&e.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 i.close(),e&&e.info("Powers of Tau Ok!"),!0;function w(t,a){if(!e)return;e.info("-----------------------------------------------------"),e.info(`Contribution #${t.id}: ${t.name||""}`),e.info(Ri(t.nextChallenge,"Next Challenge: "));const i=new Uint8Array(2*n.G1.F.n8*6+2*n.G2.F.n8*3);Po(i,0,n,t.key,!1);const o=$a.exports(64);o.setPartialHash(t.partialHash),o.update(i);const c=o.digest();e.info(Ri(c,"Response Hash:")),e.info(Ri(a.nextChallenge,"Response Hash:")),1==t.type&&(e.info(`Beacon generator: ${$i(t.beaconHash)}`),e.info(`Beacon iterations Exp: ${t.numIterationsExp}`))}async function A(t,e,a,c,r,l){const s=n[e],d=2*s.F.n8;await qa(i,o,t);const u=[];let _=s.zero,f=s.zero,h=s.zero;for(let t=0;t<c;t+=65536){l&&l.debug(`points relations: ${a}: ${t}/${c} `);const e=Math.min(c-t,65536),o=await i.read(e*d),n=await s.batchLEMtoU(o);g.update(n);const p=new Uint8Array(4*(e-1));if(M.randomFillSync(p),t>0){const t=s.fromRprLEM(o,0),e=M.randomBytes(4).readUInt32BE(0,!0);_=s.add(_,s.timesScalar(h,e)),f=s.add(f,s.timesScalar(t,e))}const m=await s.multiExpAffine(o.slice(0,(e-1)*d),p),L=await s.multiExpAffine(o.slice(d),p);_=s.add(_,m),f=s.add(f,L),h=s.fromRprLEM(o,(e-1)*d);for(let a=0;a<r.length;a++){const i=r[a];if(i>=t&&i<t+e){const e=s.fromRprLEM(o,(i-t)*d);u.push(e)}}}return await Ma(i),{R1:_,R2:f,singularPoints:u}}async function b(t,e,a,r,l){l&&l.debug(`Verifying phase2 calculated values ${r}...`);const s=n[t],d=2*s.F.n8,u=new Array(8);for(let t=0;t<8;t++)u[t]=M.randomBytes(4).readUInt32BE(0,!0);for(let t=0;t<=c;t++){if(!await g(t))return!1}if(2==e){if(!await g(c+1))return!1}return!0;async function g(t){l&&l.debug(`Power ${t}...`);const g=n.Fr.n8,_=2**t;let f,h=new Uint32Array(_),p=new q(u);l&&l.debug(`Creating random numbers Powers${t}...`);for(let e=0;e<_;e++)h[e]=t==c+1&&e==_-1?0:p.nextU32();h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength),l&&l.debug(`reading points Powers${t}...`),await qa(i,o,e),f=new Pe(_*d),t==c+1?(await i.readToBuffer(f,0,(_-1)*d),f.set(n.G1.zeroAffine,(_-1)*d)):await i.readToBuffer(f,0,_*d),await Ma(i,!0);const m=await s.multiExpAffine(f,h,l,r+"_"+t);h=new Pe(_*g),p=new q(u);const L=new Uint8Array(4),w=new DataView(L.buffer);l&&l.debug(`Creating random numbers Powers${t}...`);for(let e=0;e<_;e++)e==_-1&&t==c+1||(w.setUint32(0,p.nextU32(),!0),h.set(L,e*g));l&&l.debug(`batchToMontgomery ${t}...`),h=await n.Fr.batchToMontgomery(h),l&&l.debug(`fft ${t}...`),h=await n.Fr.fft(h),l&&l.debug(`batchFromMontgomery ${t}...`),h=await n.Fr.batchFromMontgomery(h),l&&l.debug(`reading points Lagrange${t}...`),await qa(i,o,a),i.pos+=d*(2**t-1),await i.readToBuffer(f,0,_*d),await Ma(i,!0);const A=await s.multiExpAffine(f,h,l,r+"_"+t+"_transformed");return!!s.eq(m,A)||(l&&l.error("Phase2 caclutation does not match with powers of tau"),!1)}}},challengeContribute:async function(t,e,a,i,o){await $a.exports.ready();const n=await Pa(e),c=8*t.F1.n64*2,r=8*t.F2.n64*2,l=(n.totalSize+c-64-r)/(4*c+r);let s=l,d=0;for(;s>1;)s/=2,d+=1;if(2**d!=l)throw new Error("Invalid file size");o&&o.debug("Power to tau size: "+d);const u=await Ki(i),g=await Ga(a),_=$a.exports(64);for(let t=0;t<n.totalSize;t+=n.pageSize){o&&o.debug(`Hashing challenge ${t}/${n.totalSize}`);const e=Math.min(n.totalSize-t,n.pageSize),a=await n.read(e);_.update(a)}const f=await n.read(64,0);o&&o.info(Ri(f,"Claimed Previous Response Hash: "));const h=_.digest();o&&o.info(Ri(h,"Current Challenge Hash: "));const p=Bo(t,h,u);o&&["tau","alpha","beta"].forEach((e=>{o.debug(e+".g1_s: "+t.G1.toString(p[e].g1_s,16)),o.debug(e+".g1_sx: "+t.G1.toString(p[e].g1_sx,16)),o.debug(e+".g2_sp: "+t.G2.toString(p[e].g2_sp,16)),o.debug(e+".g2_spx: "+t.G2.toString(p[e].g2_spx,16)),o.debug("")}));const m=$a.exports(64);await g.write(h),m.update(h),await Do(n,g,m,t,"G1",2**d*2-1,t.Fr.one,p.tau.prvKey,"COMPRESSED","tauG1",o),await Do(n,g,m,t,"G2",2**d,t.Fr.one,p.tau.prvKey,"COMPRESSED","tauG2",o),await Do(n,g,m,t,"G1",2**d,p.alpha.prvKey,p.tau.prvKey,"COMPRESSED","alphaTauG1",o),await Do(n,g,m,t,"G1",2**d,p.beta.prvKey,p.tau.prvKey,"COMPRESSED","betaTauG1",o),await Do(n,g,m,t,"G2",1,p.beta.prvKey,p.tau.prvKey,"COMPRESSED","betaTauG2",o);const L=new Uint8Array(2*t.F1.n8*6+2*t.F2.n8*3);Po(L,0,t,p,!1),await g.write(L),m.update(L);const w=m.digest();o&&o.info(Ri(w,"Contribution Response Hash: ")),await g.close(),await n.close()},beacon:async function(t,e,a,i,o,n){const c=Hi(i);if(0==c.byteLength||2*c.byteLength!=i.length)return n&&n.error("Invalid Beacon Hash. (It must be a valid hexadecimal sequence)"),!1;if(c.length>=256)return n&&n.error("Maximum lenght of beacon hash is 255 bytes"),!1;if((o=parseInt(o))<10||o>63)return n&&n.error("Invalid numIterationsExp. (Must be between 10 and 63)"),!1;await $a.exports.ready();const{fd:r,sections:l}=await Ua(t,"ptau",1),{curve:s,power:d,ceremonyPower:u}=await So(r,l);if(d!=u)return n&&n.error("This file has been reduced. You cannot contribute into a reduced file."),!1;l[12]&&n&&n.warn("Contributing into a file that has phase2 calculated. You will have to prepare phase2 again.");const g=await Oo(r,s,l),_={name:a,type:1,numIterationsExp:o,beaconHash:c};let f;f=g.length>0?g[g.length-1].nextChallenge:qo(s,d,n),_.key=Mo(s,f,c,o);const h=new $a.exports(64);h.update(f);const p=await Oa(e,"ptau",1,7);await vo(p,s,d);const m=[];let L;L=await y(2,"G1",2**d*2-1,s.Fr.e(1),_.key.tau.prvKey,"tauG1",n),_.tauG1=L[1],L=await y(3,"G2",2**d,s.Fr.e(1),_.key.tau.prvKey,"tauG2",n),_.tauG2=L[1],L=await y(4,"G1",2**d,_.key.alpha.prvKey,_.key.tau.prvKey,"alphaTauG1",n),_.alphaG1=L[0],L=await y(5,"G1",2**d,_.key.beta.prvKey,_.key.tau.prvKey,"betaTauG1",n),_.betaG1=L[0],L=await y(6,"G2",1,_.key.beta.prvKey,_.key.tau.prvKey,"betaTauG2",n),_.betaG2=L[0],_.partialHash=h.getPartialHash();const w=new Uint8Array(2*s.F1.n8*6+2*s.F2.n8*3);Po(w,0,s,_.key,!1),h.update(new Uint8Array(w));const A=h.digest();n&&n.info(Ri(A,"Contribution Response Hash imported: "));const b=new $a.exports(64);return b.update(A),await I(p,"G1",2,2**d*2-1,"tauG1",n),await I(p,"G2",3,2**d,"tauG2",n),await I(p,"G1",4,2**d,"alphaTauG1",n),await I(p,"G1",5,2**d,"betaTauG1",n),await I(p,"G2",6,1,"betaG2",n),_.nextChallenge=b.digest(),n&&n.info(Ri(_.nextChallenge,"Next Challenge Hash: ")),g.push(_),await Qo(p,s,g),await r.close(),await p.close(),A;async function y(t,e,a,i,o,n,c){const d=[];r.pos=l[t][0].p,await za(p,t),m[t]=p.pos;const u=s[e],g=2*u.F.n8,_=Math.floor((1<<20)/g);let f=i;for(let t=0;t<a;t+=_){c&&c.debug(`applying key${n}: ${t}/${a}`);const e=Math.min(a-t,_),i=await r.read(e*g),l=await u.batchApplyKey(i,f,o),m=p.write(l),L=await u.batchLEMtoC(l);if(h.update(L),await m,0==t)for(let t=0;t<Math.min(2,a);t++)d.push(u.fromRprLEM(l,t*g));f=s.Fr.mul(f,s.Fr.exp(o,e))}return await Qa(p),d}async function I(t,e,a,i,o,n){const c=s[e],r=2*c.F.n8,l=Math.floor((1<<24)/r),d=t.pos;t.pos=m[a];for(let e=0;e<i;e+=l){n&&n.debug(`Hashing ${o}: ${e}/${i}`);const a=Math.min(i-e,l),s=await t.read(a*r),d=await c.batchLEMtoU(s);b.update(d)}t.pos=d}},contribute:async function(t,e,a,i,o){await $a.exports.ready();const{fd:n,sections:c}=await Ua(t,"ptau",1),{curve:r,power:l,ceremonyPower:s}=await So(n,c);if(l!=s)throw o&&o.error("This file has been reduced. You cannot contribute into a reduced file."),new Error("This file has been reduced. You cannot contribute into a reduced file.");c[12]&&o&&o.warn("WARNING: Contributing into a file that has phase2 calculated. You will have to prepare phase2 again.");const d=await Oo(n,r,c),u={name:a,type:0};let g;const _=await Ki(i);g=d.length>0?d[d.length-1].nextChallenge:qo(r,l,o),u.key=Bo(r,g,_);const f=new $a.exports(64);f.update(g);const h=await Oa(e,"ptau",1,7);await vo(h,r,l);const p=[];let m;m=await b(2,"G1",2**l*2-1,r.Fr.e(1),u.key.tau.prvKey,"tauG1"),u.tauG1=m[1],m=await b(3,"G2",2**l,r.Fr.e(1),u.key.tau.prvKey,"tauG2"),u.tauG2=m[1],m=await b(4,"G1",2**l,u.key.alpha.prvKey,u.key.tau.prvKey,"alphaTauG1"),u.alphaG1=m[0],m=await b(5,"G1",2**l,u.key.beta.prvKey,u.key.tau.prvKey,"betaTauG1"),u.betaG1=m[0],m=await b(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*r.F1.n8*6+2*r.F2.n8*3);Po(L,0,r,u.key,!1),f.update(new Uint8Array(L));const w=f.digest();o&&o.info(Ri(w,"Contribution Response Hash imported: "));const A=new $a.exports(64);return A.update(w),await y(h,"G1",2,2**l*2-1,"tauG1"),await y(h,"G2",3,2**l,"tauG2"),await y(h,"G1",4,2**l,"alphaTauG1"),await y(h,"G1",5,2**l,"betaTauG1"),await y(h,"G2",6,1,"betaG2"),u.nextChallenge=A.digest(),o&&o.info(Ri(u.nextChallenge,"Next Challenge Hash: ")),d.push(u),await Qo(h,r,d),await n.close(),await h.close(),w;async function b(t,e,a,i,l,s){const d=[];n.pos=c[t][0].p,await za(h,t),p[t]=h.pos;const u=r[e],g=2*u.F.n8,_=Math.floor((1<<20)/g);let m=i;for(let t=0;t<a;t+=_){o&&o.debug(`processing: ${s}: ${t}/${a}`);const e=Math.min(a-t,_),i=await n.read(e*g),c=await u.batchApplyKey(i,m,l),p=h.write(c),L=await u.batchLEMtoC(c);if(f.update(L),await p,0==t)for(let t=0;t<Math.min(2,a);t++)d.push(u.fromRprLEM(c,t*g));m=r.Fr.mul(m,r.Fr.exp(l,e))}return await Qa(h),d}async function y(t,e,a,i,n){const c=r[e],l=2*c.F.n8,s=Math.floor((1<<24)/l),d=t.pos;t.pos=p[a];for(let e=0;e<i;e+=s){o&&e&&o.debug(`Hashing ${n}: `+e);const a=Math.min(i-e,s),r=await t.read(a*l),d=await c.batchLEMtoU(r);A.update(d)}t.pos=d}},preparePhase2:async function(t,e,a){const{fd:i,sections:o}=await Ua(t,"ptau",1),{curve:n,power:c}=await So(i,o),r=await Oa(e,"ptau",1,11);return await vo(r,n,c),await Ra(i,o,r,2),await Ra(i,o,r,3),await Ra(i,o,r,4),await Ra(i,o,r,5),await Ra(i,o,r,6),await Ra(i,o,r,7),await l(2,12,"G1","tauG1"),await l(3,13,"G2","tauG2"),await l(4,14,"G1","alphaTauG1"),await l(5,15,"G1","betaTauG1"),await i.close(),void await r.close();async function l(t,e,l,s){a&&a.debug("Starting section: "+s),await za(r,e);for(let t=0;t<=c;t++)await d(t);async function d(e){const d=2**e,u=n[l];n.Fr;const g=2*u.F.n8;let _;u.F.n8,_=new Pe(d*g),await qa(i,o,t),2==t&&e==c+1?(await i.readToBuffer(_,0,(d-1)*g),_.set(n.G1.zeroAffine,(d-1)*g)):await i.readToBuffer(_,0,d*g),await Ma(i,!0),_=await u.lagrangeEvaluations(_,"affine","affine",a,s),await r.write(_)}2==t&&await d(c+1),await Qa(r)}},truncate:async function(t,e,a){const{fd:i,sections:o}=await Ua(t,"ptau",1),{curve:n,power:c,ceremonyPower:r}=await So(i,o),l=2*n.G1.F.n8,s=2*n.G2.F.n8;for(let t=1;t<c;t++)await d(t);return await i.close(),!0;async function d(t){let c=t.toString();for(;c.length<2;)c="0"+c;a&&a.debug("Writing Power: "+c);const d=await Oa(e+c+".ptau","ptau",1,11);await vo(d,n,t,r),await Ra(i,o,d,2,(2**t*2-1)*l),await Ra(i,o,d,3,2**t*s),await Ra(i,o,d,4,2**t*l),await Ra(i,o,d,5,2**t*l),await Ra(i,o,d,6,s),await Ra(i,o,d,7),await Ra(i,o,d,12,(2**(t+1)*2-1)*l),await Ra(i,o,d,13,(2**t*2-1)*s),await Ra(i,o,d,14,(2**t*2-1)*l),await Ra(i,o,d,15,(2**t*2-1)*l),await d.close()}},convert:async function(t,e,a){const{fd:i,sections:o}=await Ua(t,"ptau",1),{curve:n,power:c}=await So(i,o),r=await Oa(e,"ptau",1,11);return await vo(r,n,c),await Ra(i,o,r,2),await Ra(i,o,r,3),await Ra(i,o,r,4),await Ra(i,o,r,5),await Ra(i,o,r,6),await Ra(i,o,r,7),await async function(t,e,l,s){a&&a.debug("Starting section: "+s);await za(r,e);const d=o[e][0].size,u=i.pageSize;await qa(i,o,e);for(let t=0;t<d;t+=u){const e=Math.min(d-t,u),a=await i.read(e);await r.write(a)}await Ma(i),2==t&&await async function(e){const d=2**e,u=n[l],g=2*u.F.n8;let _;_=new Pe(d*g),await qa(i,o,t),2==t&&e==c+1?(await i.readToBuffer(_,0,(d-1)*g),_.set(n.G1.zeroAffine,(d-1)*g)):await i.readToBuffer(_,0,d*g);await Ma(i,!0),_=await u.lagrangeEvaluations(_,"affine","affine",a,s),await r.write(_)}(c+1);await Qa(r)}(2,12,"G1","tauG1"),await Ra(i,o,r,13),await Ra(i,o,r,14),await Ra(i,o,r,15),await i.close(),void await r.close()},exportJson:async function(t,e){const{fd:a,sections:i}=await Ua(t,"ptau",1),{curve:o,power:n}=await So(a,i),c={};return c.q=o.q,c.power=n,c.contributions=await Oo(a,o,i),c.tauG1=await r(2,"G1",2**n*2-1,"tauG1"),c.tauG2=await r(3,"G2",2**n,"tauG2"),c.alphaTauG1=await r(4,"G1",2**n,"alphaTauG1"),c.betaTauG1=await r(5,"G1",2**n,"betaTauG1"),c.betaG2=await r(6,"G2",1,"betaG2"),c.lTauG1=await l(12,"G1","lTauG1"),c.lTauG2=await l(13,"G2","lTauG2"),c.lAlphaTauG1=await l(14,"G1","lAlphaTauG2"),c.lBetaTauG1=await l(15,"G1","lBetaTauG2"),await a.close(),Yi(o.Fr,c);async function r(t,n,c,r){const l=o[n],s=2*l.F.n8,d=[];await qa(a,i,t);for(let t=0;t<c;t++){e&&t&&t%1e4==0&&console.log(`${r}: `+t);const i=await a.read(s);d.push(l.fromRprLEM(i,0))}return await Ma(a),d}async function l(t,c,r){const l=o[c],s=2*l.F.n8,d=[];await qa(a,i,t);for(let t=0;t<=n;t++){e&&console.log(`${r}: Power: ${t}`),d[t]=[];const i=2**t;for(let o=0;o<i;o++){e&&o&&o%1e4==0&&console.log(`${r}: ${o}/${i}`);const n=await a.read(s);d[t].push(l.fromRprLEM(n,0))}}return await Ma(a,!0),d}}});const Vo=262144,Ko={get:function(t,e){return isNaN(e)?t[e]:t.getElement(e)},set:function(t,e,a){return isNaN(e)?(t[e]=a,!0):t.setElement(e,a)}};class jo{constructor(t){this.length=t||0,this.arr=new Array(Vo);for(let e=0;e<t;e+=Vo)this.arr[e/Vo]=new Array(Math.min(Vo,t-e));return this}push(){for(let t=0;t<arguments.length;t++)this.setElement(this.length,arguments[t])}slice(t,e){const a=new Array(e-t);for(let i=t;i<e;i++)a[i-t]=this.getElement(i);return a}getElement(t){t=parseInt(t);const e=Math.floor(t/Vo),a=t%Vo;return this.arr[e]?this.arr[e][a]:void 0}setElement(t,e){t=parseInt(t);const a=Math.floor(t/Vo);this.arr[a]||(this.arr[a]=new Array(Vo));const i=t%Vo;return this.arr[a][i]=e,t>=this.length&&(this.length=t+1),!0}getKeys(){const t=new Ho;for(let e=0;e<this.arr.length;e++)if(this.arr[e])for(let a=0;a<this.arr[e].length;a++)void 0!==this.arr[e][a]&&t.push(e*Vo+a);return t}}class Ho{constructor(t){const e=new jo(t);return new Proxy(e,Ko)}}async function $o(t,e,a){let i;i="object"==typeof a?a:void 0===a?{singleThread:!1}:{singleThread:a};const o={};if(await qa(t,e,1),o.n8=await t.readULE32(),o.prime=await ka(t,o.n8),i.F){if(i.F.p!=o.prime)throw new Error("Different Prime");o.F=i.F}else if(i.getFieldFromPrime)o.F=await i.getFieldFromPrime(o.prime,i.singleThread);else if(i.getCurveFromPrime)o.curve=await i.getCurveFromPrime(o.prime,i.singleThread),o.F=o.curve.Fr;else try{o.curve=await async function(t,e,a){let i;if(b(t,fa))i=await ua(e,a);else{if(!b(t,_a))throw new Error(`Curve not supported: ${v(t)}`);i=await ga(e,a)}return i}(o.prime,i.singleThread),o.F=o.curve.Fr}catch(t){o.F=new K(o.prime)}return o.nVars=await t.readULE32(),o.nOutputs=await t.readULE32(),o.nPubInputs=await t.readULE32(),o.nPrvInputs=await t.readULE32(),o.nLabels=await t.readULE64(),o.nConstraints=await t.readULE32(),o.useCustomGates=void 0!==e[4]&&null!==e[4]&&void 0!==e[5]&&null!==e[5],await Ma(t),o}async function Yo(t,e,a){if("object"!=typeof a)throw new Error("readR1csFd: options must be an object");a.loadConstraints=a.loadConstraints||!0,a.loadMap=a.loadMap||!1,a.loadCustomGates=a.loadCustomGates||!0;const i=await $o(t,e,a);return a.loadConstraints&&(i.constraints=await async function(t,e,a,i,o){let n;n="object"==typeof i?i:void 0===i?{}:{logger:i,loggerCtx:o};const c=await Da(t,e,2);let r,l=0;r=a.nConstraints>1<<20?new Ho:[];for(let t=0;t<a.nConstraints;t++){n.logger&&t%1e5==0&&n.logger.info(`${n.loggerCtx}: Loading constraints: ${t}/${a.nConstraints}`);const e=s();r.push(e)}return r;function s(){const t=[];return t[0]=d(),t[1]=d(),t[2]=d(),t}function d(){const t={},e=c.slice(l,l+4);l+=4;const i=new DataView(e.buffer).getUint32(0,!0),o=c.slice(l,l+(4+a.n8)*i);l+=(4+a.n8)*i;const n=new DataView(o.buffer);for(let e=0;e<i;e++){const i=n.getUint32(e*(4+a.n8),!0),c=a.F.fromRprLE(o,e*(4+a.n8)+4);t[i]=c}return t}}(t,e,i,a)),a.loadMap&&(i.map=await async function(t,e,a,i,o){let n;n="object"==typeof i?i:void 0===i?{}:{logger:i,loggerCtx:o};const c=await Da(t,e,3);let r,l=0;r=a.nVars>1<<20?new Ho:[];for(let t=0;t<a.nVars;t++){n.logger&&t%1e4==0&&n.logger.info(`${n.loggerCtx}: Loading map: ${t}/${a.nVars}`);const e=s();r.push(e)}return r;function s(){const t=c.slice(l,l+8);l+=8;const e=new DataView(t.buffer),a=e.getUint32(0,!0);return 4294967296*e.getUint32(4,!0)+a}}(t,e,i,a)),a.loadCustomGates&&(i.useCustomGates?(i.customGates=await async function(t,e,a){await qa(t,e,4);let i=await t.readULE32(),o=[];for(let e=0;e<i;e++){let e={};e.templateName=await t.readString();let i=await t.readULE32();e.parameters=Array(i);let n=await t.read(a*i);for(let t=0;t<i;t++)e.parameters[t]=n.slice(t*a,t*a+a);o.push(e)}return await Ma(t),o}(t,e,i.F.n8),i.customGatesUses=await async function(t,e,a){const i=await Da(t,e,5),o=new Uint32Array(i.buffer,i.byteOffset,i.byteLength/4),n=o[0];let c,r=1;c=n>1<<20?new Ho:[];for(let t=0;t<n;t++){a.logger&&t%1e5==0&&a.logger.info(`${a.loggerCtx}: Loading custom gate uses: ${t}/${n}`);let e={};e.id=o[r++];let i=o[r++];e.signals=[];for(let t=0;t<i;t++){const t=o[r++],a=o[r++];e.signals.push(4294967296*a+t)}c.push(e)}return c}(t,e,a)):(i.customGates=[],i.customGatesUses=[])),i}async function Wo(t,e,a,i,o,n){let c;c="object"==typeof e?e:void 0===e?{loadConstraints:!0,loadMap:!1,loadCustomGates:!0}:{loadConstraints:e,loadMap:a,singleThread:i,logger:o,loggerCtx:n};const{fd:r,sections:l}=await Ua(t,"r1cs",1),s=await Yo(r,l,c);return await r.close(),s}const Zo=ha.e("73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",16),Jo=ha.e("21888242871839275222246405745257275088548364400416034343698204186575808495617");var Xo=Object.freeze({__proto__:null,print:function(t,e,a){for(let e=0;e<t.constraints.length;e++)i(t.constraints[e]);function i(i){const o=a=>{let i="";return Object.keys(a).forEach((o=>{let n=e.varIdx2Name[o];"one"==n&&(n="");let c=t.curve.Fr.toString(a[o]);"1"==c&&(c=""),"-1"==c&&(c="-"),""!=i&&"-"!=c[0]&&(c="+"+c),""!=i&&(c=" "+c),i=i+c+n})),i},n=`[ ${o(i[0])} ] * [ ${o(i[1])} ] - [ ${o(i[2])} ] = 0`;a&&a.info(n)}},info:async function(t,e){const a=await Wo(t);return ha.eq(a.prime,Jo)?e&&e.info("Curve: bn-128"):ha.eq(a.prime,Zo)?e&&e.info("Curve: bls12-381"):e&&e.info(`Unknown Curve. Prime: ${ha.toString(a.prime)}`),e&&e.info(`# of Wires: ${a.nVars}`),e&&e.info(`# of Constraints: ${a.nConstraints}`),e&&e.info(`# of Private Inputs: ${a.nPrvInputs}`),e&&e.info(`# of Public Inputs: ${a.nPubInputs}`),e&&e.info(`# of Labels: ${a.nLabels}`),e&&e.info(`# of Outputs: ${a.nOutputs}`),a},exportJson:async function(t,e){const a=await Wo(t,!0,!0,!0,e),i=a.curve.Fr;return delete a.curve,delete a.F,Yi(i,a)}});async function tn(t){const e={labelIdx2Name:["one"],varIdx2Name:["one"],componentIdx2Name:[]},a=await Pa(t),i=await a.read(a.totalSize),o=new TextDecoder("utf-8").decode(i).split("\n");for(let t=0;t<o.length;t++){const a=o[t].split(",");4==a.length&&(e.varIdx2Name[a[1]]?e.varIdx2Name[a[1]]+="|"+a[3]:e.varIdx2Name[a[1]]=a[3],e.labelIdx2Name[a[0]]=a[3],e.componentIdx2Name[a[2]]||(e.componentIdx2Name[a[2]]=n(a[3])))}return await a.close(),e;function n(t){const e=t.split(".");return e.pop(),e.join(".")}}const{unstringifyBigInts:en}=pa;var an=Object.freeze({__proto__:null,calculate:wo,debug:async function(t,e,a,i,o,n){const c=en(t),r=await Pa(e),l=await r.read(r.totalSize);await r.close();let s={sanityCheck:!0},d=await tn(i);o.set&&(d||(d=await tn(i)),s.logSetSignal=function(t,e){n&&n.info("SET "+d.labelIdx2Name[t]+" <-- "+e.toString())}),o.get&&(d||(d=await tn(i)),s.logGetSignal=function(t,e){n&&n.info("GET "+d.labelIdx2Name[t]+" --\x3e "+e.toString())}),o.trigger&&(d||(d=await tn(i)),s.logStartComponent=function(t){n&&n.info("START: "+d.componentIdx2Name[t])},s.logFinishComponent=function(t){n&&n.info("FINISH: "+d.componentIdx2Name[t])}),s.sym=d;const u=await ho(l,s),g=await u.calculateWitness(c),_=await Oa(a,"wtns",2,2);await async function(t,e,a){await za(t,1);const i=8*(Math.floor((ha.bitLength(a)-1)/64)+1);await t.writeULE32(i),await Ta(t,a,i),await t.writeULE32(e.length),await Qa(t),await za(t,2);for(let a=0;a<e.length;a++)await Ta(t,e[a],i);await Qa(t)}(_,g,u.prime),await _.close()},exportJson:async function(t){return await async function(t){const{fd:e,sections:a}=await Ua(t,"wtns",2),{n8:i,nWitness:o}=await lo(e,a);await qa(e,a,2);const n=[];for(let t=0;t<o;t++){const t=await ka(e,i);n.push(t)}return await Ma(e),await e.close(),n}(t)}});const on=262144,nn={get:function(t,e){return isNaN(e)?t[e]:t.getElement(e)},set:function(t,e,a){return isNaN(e)?(t[e]=a,!0):t.setElement(e,a)}};class cn{constructor(t){this.length=t||0,this.arr=new Array(on);for(let e=0;e<t;e+=on)this.arr[e/on]=new Array(Math.min(on,t-e));return this}push(){for(let t=0;t<arguments.length;t++)this.setElement(this.length,arguments[t])}slice(t,e){const a=new Array(e-t);for(let i=t;i<e;i++)a[i-t]=this.getElement(i);return a}getElement(t){t=parseInt(t);const e=Math.floor(t/on),a=t%on;return this.arr[e]?this.arr[e][a]:void 0}setElement(t,e){t=parseInt(t);const a=Math.floor(t/on);this.arr[a]||(this.arr[a]=new Array(on));const i=t%on;return this.arr[a][i]=e,t>=this.length&&(this.length=t+1),!0}getKeys(){const t=new rn;for(let e=0;e<this.arr.length;e++)if(this.arr[e])for(let a=0;a<this.arr[e].length;a++)void 0!==this.arr[e][a]&&t.push(e*on+a);return t}}class rn{constructor(t){const e=new cn(t);return new Proxy(e,nn)}}async function ln(t,e,a,i){await $a.exports.ready();const o=$a.exports(64),{fd:n,sections:c}=await Ua(e,"ptau",1),{curve:r,power:l}=await So(n,c),{fd:s,sections:d}=await Ua(t,"r1cs",1),u=await $o(s,d,!1),g=await Oa(a,"zkey",1,10,1<<22,1<<24),_=2*r.G1.F.n8,f=2*r.G2.F.n8;if(u.prime!=r.r)return i&&i.error("r1cs curve does not match powers of tau ceremony curve"),-1;const h=ki(u.nConstraints+u.nPubInputs+u.nOutputs+1-1)+1;if(h>l)return i&&i.error(`circuit too big for this power of tau ceremony. ${u.nConstraints}*2 > 2**${l}`),-1;if(!c[12])return i&&i.error("Powers of tau is not prepared."),-1;const p=u.nOutputs+u.nPubInputs,m=2**h;await za(g,1),await g.writeULE32(1),await Qa(g),await za(g,2);const L=r.q,w=8*(Math.floor((ha.bitLength(L)-1)/64)+1),A=r.r,b=8*(Math.floor((ha.bitLength(A)-1)/64)+1),y=ha.mod(ha.shl(1,8*b),A),I=r.Fr.e(ha.mod(ha.mul(y,y),A));let C,F,x;await g.writeULE32(w),await Ta(g,L,w),await g.writeULE32(b),await Ta(g,A,b),await g.writeULE32(u.nVars),await g.writeULE32(p),await g.writeULE32(m),C=await n.read(_,c[4][0].p),await g.write(C),C=await r.G1.batchLEMtoU(C),o.update(C),F=await n.read(_,c[5][0].p),await g.write(F),F=await r.G1.batchLEMtoU(F),o.update(F),x=await n.read(f,c[6][0].p),await g.write(x),x=await r.G2.batchLEMtoU(x),o.update(x);const E=new Uint8Array(_);r.G1.toRprLEM(E,0,r.G1.g);const B=new Uint8Array(f);r.G2.toRprLEM(B,0,r.G2.g);const v=new Uint8Array(_);r.G1.toRprUncompressed(v,0,r.G1.g);const S=new Uint8Array(f);r.G2.toRprUncompressed(S,0,r.G2.g),await g.write(B),await g.write(E),await g.write(B),o.update(S),o.update(v),o.update(S),await Qa(g),i&&i.info("Reading r1cs");let G=await Da(s,d,2);const P=new rn(u.nVars),U=new rn(u.nVars),O=new rn(u.nVars),z=new rn(u.nVars-p-1),Q=new Array(p+1);i&&i.info("Reading tauG1");let q=await Da(n,c,12,(m-1)*_,m*_);i&&i.info("Reading tauG2");let M=await Da(n,c,13,(m-1)*f,m*f);i&&i.info("Reading alphatauG1");let T=await Da(n,c,14,(m-1)*_,m*_);i&&i.info("Reading betatauG1");let k=await Da(n,c,15,(m-1)*_,m*_);await async function(){const t=new Uint8Array(12+r.Fr.n8),e=new DataView(t.buffer),a=new Uint8Array(r.Fr.n8);r.Fr.toRprLE(a,0,r.Fr.e(1));let o=0;function n(){const t=G.slice(o,o+4);o+=4;return new DataView(t.buffer).getUint32(0,!0)}const c=new rn;for(let t=0;t<u.nConstraints;t++){i&&t%1e4==0&&i.debug(`processing constraints: ${t}/${u.nConstraints}`);const e=n();for(let a=0;a<e;a++){const e=n(),a=o;o+=r.Fr.n8;const i=0,l=_*t,s=3,d=_*t;void 0===P[e]&&(P[e]=[]),P[e].push([i,l,a]),e<=p?(void 0===Q[e]&&(Q[e]=[]),Q[e].push([s,d,a])):(void 0===z[e-p-1]&&(z[e-p-1]=[]),z[e-p-1].push([s,d,a])),c.push([0,t,e,a])}const a=n();for(let e=0;e<a;e++){const e=n(),a=o;o+=r.Fr.n8;const i=0,l=_*t,s=1,d=f*t,u=2,g=_*t;void 0===U[e]&&(U[e]=[]),U[e].push([i,l,a]),void 0===O[e]&&(O[e]=[]),O[e].push([s,d,a]),e<=p?(void 0===Q[e]&&(Q[e]=[]),Q[e].push([u,g,a])):(void 0===z[e-p-1]&&(z[e-p-1]=[]),z[e-p-1].push([u,g,a])),c.push([1,t,e,a])}const l=n();for(let e=0;e<l;e++){const e=n(),a=o;o+=r.Fr.n8;const i=0,c=_*t;e<=p?(void 0===Q[e]&&(Q[e]=[]),Q[e].push([i,c,a])):(void 0===z[e-p-1]&&(z[e-p-1]=[]),z[e-p-1].push([i,c,a]))}}for(let t=0;t<=p;t++){const e=0,a=_*(u.nConstraints+t),i=3,o=_*(u.nConstraints+t);void 0===P[t]&&(P[t]=[]),P[t].push([e,a,-1]),void 0===Q[t]&&(Q[t]=[]),Q[t].push([i,o,-1]),c.push([0,u.nConstraints+t,t,-1])}await za(g,4);const l=new Pe(c.length*(12+r.Fr.n8)+4),s=new Uint8Array(4);new DataView(s.buffer).setUint32(0,c.length,!0),l.set(s);let d=4;for(let t=0;t<c.length;t++)i&&t%1e5==0&&i.debug(`writing coeffs: ${t}/${c.length}`),h(c[t]);function h(i){let o;e.setUint32(0,i[0],!0),e.setUint32(4,i[1],!0),e.setUint32(8,i[2],!0),o=i[3]>=0?r.Fr.fromRprLE(G.slice(i[3],i[3]+r.Fr.n8),0):r.Fr.fromRprLE(a,0);const n=r.Fr.mul(o,I);r.Fr.toRprLE(t,12,n),l.set(t,d),d+=t.length}await g.write(l),await Qa(g)}(),await D(3,"G1",Q,"IC"),await async function(){await za(g,9);const t=new Pe(m*_);if(h<r.Fr.s){let e=await Da(n,c,12,(2*m-1)*_,2*m*_);for(let a=0;a<m;a++){i&&a%1e4==0&&i.debug(`spliting buffer: ${a}/${m}`);const o=e.slice((2*a+1)*_,(2*a+1)*_+_);t.set(o,a*_)}}else{if(h!=r.Fr.s)throw i&&i.error("Circuit too big"),new Error("Circuit too big for this curve");{const e=c[12][0].p+(2**(h+1)-1)*_;await n.readToBuffer(t,0,m*_,e+m*_)}}await g.write(t),await Qa(g)}(),await async function(){j(m-1);for(let t=0;t<m-1;t+=16384){i&&i.debug(`HashingHPoints: ${t}/${m}`);const e=Math.min(m-1,16384);await V(t,e)}}(),await D(8,"G1",z,"C"),await D(5,"G1",P,"A"),await D(6,"G1",U,"B1"),await D(7,"G2",O,"B2");const R=o.digest();return await za(g,10),await g.write(R),await g.writeULE32(0),await Qa(g),i&&i.info(Ri(R,"Circuit hash: ")),await g.close(),await s.close(),await n.close(),R;async function D(t,e,a,n){const c=r[e];j(a.length),await za(g,t);let l=[],s=0;for(;s<a.length;){let t=0;for(;s<a.length&&t<r.tm.concurrency;){i&&i.debug(`Writing points start ${n}: ${s}/${a.length}`);let o=1,c=a[s]?a[s].length:0;for(;s+o<a.length&&c+(a[s+o]?a[s+o].length:0)<32768&&o<32768;)c+=a[s+o]?a[s+o].length:0,o++;const r=a.slice(s,s+o),d=s;l.push(N(e,r,i,n).then((t=>(i&&i.debug(`Writing points end ${n}: ${d}/${a.length}`),t)))),s+=o,t++}const d=await Promise.all(l);for(let t=0;t<d.length;t++){await g.write(d[t][0]);const e=await c.batchLEMtoU(d[t][0]);o.update(e)}l=[]}await Qa(g)}async function N(t,e,a,i){const o=r[t],n=2*o.F.n8,c=3*o.F.n8,l=2*o.F.n8;let s,d,u,g;if("G1"==t)s="g1m_timesScalarAffine",d="g1m_multiexpAffine",u="g1m_batchToAffine",g="g1m_zero";else{if("G2"!=t)throw new Error("Invalid group");s="g2m_timesScalarAffine",d="g2m_multiexpAffine",u="g2m_batchToAffine",g="g2m_zero"}let _,f,h=0;for(let t=0;t<e.length;t++)h+=e[t]?e[t].length:0;h>32768?(_=new Pe(h*n),f=new Pe(h*r.Fr.n8)):(_=new Uint8Array(h*n),f=new Uint8Array(h*r.Fr.n8));let p=0,m=0;const L=[q,M,T,k],w=new Uint8Array(r.Fr.n8);r.Fr.toRprLE(w,0,r.Fr.e(1));let A=0;for(let t=0;t<e.length;t++)if(e[t])for(let o=0;o<e[t].length;o++)a&&o&&o%1e4==0&&a.debug(`Configuring big array ${i}: ${o}/${e[t].length}`),_.set(L[e[t][o][0]].slice(e[t][o][1],e[t][o][1]+n),A*n),e[t][o][2]>=0?f.set(G.slice(e[t][o][2],e[t][o][2]+r.Fr.n8),A*r.Fr.n8):f.set(w,A*r.Fr.n8),A++;if(e.length>1){const t=[];t.push({cmd:"ALLOCSET",var:0,buff:_}),t.push({cmd:"ALLOCSET",var:1,buff:f}),t.push({cmd:"ALLOC",var:2,len:e.length*c}),p=0,m=0;let a=0;for(let i=0;i<e.length;i++)e[i]?(1==e[i].length?t.push({cmd:"CALL",fnName:s,params:[{var:0,offset:p},{var:1,offset:m},{val:r.Fr.n8},{var:2,offset:a}]}):t.push({cmd:"CALL",fnName:d,params:[{var:0,offset:p},{var:1,offset:m},{val:r.Fr.n8},{val:e[i].length},{var:2,offset:a}]}),p+=n*e[i].length,m+=r.Fr.n8*e[i].length,a+=c):(t.push({cmd:"CALL",fnName:g,params:[{var:2,offset:a}]}),a+=c);t.push({cmd:"CALL",fnName:u,params:[{var:2},{val:e.length},{var:2}]}),t.push({cmd:"GET",out:0,var:2,len:e.length*l});return await r.tm.queueAction(t)}{let t=await o.multiExpAffine(_,f,a,i);return t=[o.toAffine(t)],t}}async function V(t,e){const a=await n.read(e*_,c[2][0].p+(t+m)*_),i=await n.read(e*_,c[2][0].p+t*_),l=r.tm.concurrency,s=Math.floor(e/l),d=[];for(let t=0;t<l;t++){let o;if(o=t<l-1?s:e-t*s,0==o)continue;const n=a.slice(t*s*_,(t*s+o)*_),c=i.slice(t*s*_,(t*s+o)*_);d.push(K(n,c))}const u=await Promise.all(d);for(let t=0;t<u.length;t++)o.update(u[t][0])}async function K(t,e){const a=t.byteLength/_,i=3*r.G1.F.n8,o=[];o.push({cmd:"ALLOCSET",var:0,buff:t}),o.push({cmd:"ALLOCSET",var:1,buff:e}),o.push({cmd:"ALLOC",var:2,len:a*i});for(let t=0;t<a;t++)o.push({cmd:"CALL",fnName:"g1m_subAffine",params:[{var:0,offset:t*_},{var:1,offset:t*_},{var:2,offset:t*i}]});o.push({cmd:"CALL",fnName:"g1m_batchToAffine",params:[{var:2},{val:a},{var:2}]}),o.push({cmd:"CALL",fnName:"g1m_batchLEMtoU",params:[{var:2},{val:a},{var:2}]}),o.push({cmd:"GET",out:0,var:2,len:a*_});return await r.tm.queueAction(o)}function j(t){const e=new Uint8Array(4);new DataView(e.buffer,e.byteOffset,e.byteLength).setUint32(0,t,!1),o.update(e)}}const sn=Vi;async function dn(t,e,a,i){let o;await $a.exports.ready();const{fd:n,sections:c}=await Ua(a,"zkey",2),r=await eo(n,c,!1);if("groth16"!=r.protocol)throw new Error("zkey file is not groth16");const l=await ja(r.q),s=2*l.G1.F.n8,d=await io(n,l,c),u=$a.exports(64);u.update(d.csHash);let g=l.G1.g;for(let t=0;t<d.contributions.length;t++){const e=d.contributions[t],a=Ni(u);if(co(a,l,e.delta.g1_s),co(a,l,e.delta.g1_sx),!Di(a.digest(),e.transcript))return console.log(`INVALID(${t}): Inconsistent transcript `),!1;const i=Fo(l,e.transcript);if(o=await sn(l,e.delta.g1_s,e.delta.g1_sx,i,e.delta.g2_spx),!0!==o)return console.log(`INVALID(${t}): public key G1 and G2 do not have the same ration `),!1;if(o=await sn(l,g,e.deltaAfter,i,e.delta.g2_spx),!0!==o)return console.log(`INVALID(${t}): deltaAfter does not fillow the public key `),!1;if(1==e.type){const a=ji(e.beaconHash,e.numIterationsExp),i=l.Fr.fromRng(a),o=l.G1.toAffine(l.G1.fromRng(a)),n=l.G1.toAffine(l.G1.timesFr(o,i));if(!0!==l.G1.eq(o,e.delta.g1_s))return console.log(`INVALID(${t}): Key of the beacon does not match. g1_s `),!1;if(!0!==l.G1.eq(n,e.delta.g1_sx))return console.log(`INVALID(${t}): Key of the beacon does not match. g1_sx `),!1}ro(u,l,e);const n=$a.exports(64);ro(n,l,e),e.contributionHash=n.digest(),g=e.deltaAfter}const{fd:_,sections:f}=await Ua(t,"zkey",2),h=await eo(_,f,!1);if("groth16"!=h.protocol)throw new Error("zkeyinit file is not groth16");if(!ha.eq(h.q,r.q)||!ha.eq(h.r,r.r)||h.n8q!=r.n8q||h.n8r!=r.n8r)return i&&i.error("INVALID: Different curves"),!1;if(h.nVars!=r.nVars||h.nPublic!=r.nPublic||h.domainSize!=r.domainSize)return i&&i.error("INVALID: Different circuit parameters"),!1;if(!l.G1.eq(r.vk_alpha_1,h.vk_alpha_1))return i&&i.error("INVALID: Invalid alpha1"),!1;if(!l.G1.eq(r.vk_beta_1,h.vk_beta_1))return i&&i.error("INVALID: Invalid beta1"),!1;if(!l.G2.eq(r.vk_beta_2,h.vk_beta_2))return i&&i.error("INVALID: Invalid beta2"),!1;if(!l.G2.eq(r.vk_gamma_2,h.vk_gamma_2))return i&&i.error("INVALID: Invalid gamma2"),!1;if(!l.G1.eq(r.vk_delta_1,g))return i&&i.error("INVALID: Invalid delta1"),!1;if(o=await sn(l,l.G1.g,g,l.G2.g,r.vk_delta_2),!0!==o)return i&&i.error("INVALID: Invalid delta2"),!1;const p=await io(_,l,f);if(!Di(d.csHash,p.csHash))return i&&i.error("INVALID: Circuit does not match"),!1;if(c[8][0].size!=s*(r.nVars-r.nPublic-1))return i&&i.error("INVALID: Invalid L section size"),!1;if(c[9][0].size!=s*r.domainSize)return i&&i.error("INVALID: Invalid H section size"),!1;let m;if(m=await Na(n,c,_,f,3),!m)return i&&i.error("INVALID: IC section is not identical"),!1;if(m=await Na(n,c,_,f,4),!m)return i&&i.error("Coeffs section is not identical"),!1;if(m=await Na(n,c,_,f,5),!m)return i&&i.error("A section is not identical"),!1;if(m=await Na(n,c,_,f,6),!m)return i&&i.error("B1 section is not identical"),!1;if(m=await Na(n,c,_,f,7),!m)return i&&i.error("B2 section is not identical"),!1;if(o=await async function(t,e,a,n,c,r,s,d,u){const g=1<<20,_=l[t],f=2*_.F.n8;await qa(e,a,r),await qa(n,c,r);let h=_.zero,p=_.zero;const m=a[r][0].size/f;for(let t=0;t<m;t+=g){i&&i.debug(`Same ratio check ${u}: ${t}/${m}`);const a=Math.min(m-t,g),o=await e.read(a*f),c=await n.read(a*f),r=new Uint8Array(4*a);M.randomFillSync(r);const l=await _.multiExpAffine(o,r),s=await _.multiExpAffine(c,r);h=_.add(h,l),p=_.add(p,s)}return await Ma(e),await Ma(n),0==m||(o=await sn(l,h,p,s,d),!0===o)}("G1",_,f,n,c,8,r.vk_delta_2,h.vk_delta_2,"L section"),!0!==o)return i&&i.error("L section does not match"),!1;if(o=await async function(){const t=1<<20,a=l.G1,s=l.Fr,d=2*a.F.n8,{fd:u,sections:g}=await Ua(e,"ptau",1);let _=new Pe(r.domainSize*r.n8r);const f=new Array(8);for(let t=0;t<8;t++)f[t]=M.randomBytes(4).readUInt32BE(0,!0);const p=new q(f);for(let t=0;t<r.domainSize-1;t++){const e=s.fromRng(p);s.toRprLE(_,t*r.n8r,e)}s.toRprLE(_,(r.domainSize-1)*r.n8r,s.zero);let m,w=a.zero;for(let e=0;e<r.domainSize;e+=t){i&&i.debug(`H Verificaition(tau): ${e}/${r.domainSize}`);const o=Math.min(r.domainSize-e,t),n=await u.read(d*o,g[2][0].p+r.domainSize*d+e*d),c=await u.read(d*o,g[2][0].p+e*d),l=await L(n,c),s=_.slice(e*r.n8r,(e+o)*r.n8r),f=await a.multiExpAffine(l,s);w=a.add(w,f)}if(_=await s.batchToMontgomery(_),r.power<s.s)m=s.neg(s.e(2));else{const t=2**s.s,e=s.exp(s.shift,t);m=s.sub(e,s.one)}const A=r.power<s.s?s.w[r.power+1]:s.shift;_=await s.batchApplyKey(_,m,A),_=await s.fft(_),_=await s.batchFromMontgomery(_),await qa(n,c,9);let b=a.zero;for(let e=0;e<r.domainSize;e+=t){i&&i.debug(`H Verificaition(lagrange): ${e}/${r.domainSize}`);const o=Math.min(r.domainSize-e,t),c=await n.read(d*o),l=_.slice(e*r.n8r,(e+o)*r.n8r),s=await a.multiExpAffine(c,l);b=a.add(b,s)}return await Ma(n),o=await sn(l,w,b,r.vk_delta_2,h.vk_delta_2),!0===o}(),!0!==o)return i&&i.error("H section does not match"),!1;i&&i.info(Ri(d.csHash,"Circuit Hash: ")),await n.close(),await _.close();for(let t=d.contributions.length-1;t>=0;t--){const e=d.contributions[t];i&&i.info("-------------------------"),i&&i.info(Ri(e.contributionHash,`contribution #${t+1} ${e.name?e.name:""}:`)),1==e.type&&(i&&i.info(`Beacon generator: ${$i(e.beaconHash)}`),i&&i.info(`Beacon iterations Exp: ${e.numIterationsExp}`))}return i&&i.info("-------------------------"),i&&i.info("ZKey Ok!"),!0;async function L(t,e){const a=2*l.G1.F.n8,i=t.byteLength/a,o=l.tm.concurrency,n=Math.floor(i/o),c=[];for(let a=0;a<o;a++){let r;if(r=a<o-1?n:i-a*n,0==r)continue;const l=t.slice(a*n*s,(a*n+r)*s),d=e.slice(a*n*s,(a*n+r)*s);c.push(w(l,d))}const r=await Promise.all(c),d=new Uint8Array(i*a);let u=0;for(let t=0;t<r.length;t++)d.set(r[t][0],u),u+=r[t][0].byteLength;return d}async function w(t,e){const a=2*l.G1.F.n8,i=3*l.G1.F.n8,o=t.byteLength/a,n=[];n.push({cmd:"ALLOCSET",var:0,buff:t}),n.push({cmd:"ALLOCSET",var:1,buff:e}),n.push({cmd:"ALLOC",var:2,len:o*i});for(let t=0;t<o;t++)n.push({cmd:"CALL",fnName:"g1m_subAffine",params:[{var:0,offset:t*a},{var:1,offset:t*a},{var:2,offset:t*i}]});n.push({cmd:"CALL",fnName:"g1m_batchToAffine",params:[{var:2},{val:o},{var:2}]}),n.push({cmd:"GET",out:0,var:2,len:o*a});return await l.tm.queueAction(n)}}const{stringifyBigInts:un}=pa;async function gn(t){const{fd:e,sections:a}=await Ua(t,"zkey",2),i=await eo(e,a);let o;if("groth16"==i.protocol)o=await async function(t,e,a){const i=await ja(t.q),o=2*i.G1.F.n8,n=await i.pairing(t.vk_alpha_1,t.vk_beta_2);let c={protocol:t.protocol,curve:i.name,nPublic:t.nPublic,vk_alpha_1:i.G1.toObject(t.vk_alpha_1),vk_beta_2:i.G2.toObject(t.vk_beta_2),vk_gamma_2:i.G2.toObject(t.vk_gamma_2),vk_delta_2:i.G2.toObject(t.vk_delta_2),vk_alphabeta_12:i.Gt.toObject(n)};await qa(e,a,3),c.IC=[];for(let a=0;a<=t.nPublic;a++){const t=await e.read(o),a=i.G1.toObject(t);c.IC.push(a)}return await Ma(e),c=un(c),c}(i,e,a);else{if("plonk"!=i.protocol)throw new Error("zkey file is not groth16");o=await async function(t){const e=await ja(t.q);let a={protocol:t.protocol,curve:e.name,nPublic:t.nPublic,power:t.power,k1:e.Fr.toObject(t.k1),k2:e.Fr.toObject(t.k2),Qm:e.G1.toObject(t.Qm),Ql:e.G1.toObject(t.Ql),Qr:e.G1.toObject(t.Qr),Qo:e.G1.toObject(t.Qo),Qc:e.G1.toObject(t.Qc),S1:e.G1.toObject(t.S1),S2:e.G1.toObject(t.S2),S3:e.G1.toObject(t.S3),X_2:e.G2.toObject(t.X_2),w:e.Fr.toObject(e.Fr.w[t.power])};return a=un(a),a}(i)}return await e.close(),o}var _n={};var fn=Object.freeze({__proto__:null,newZKey:ln,exportBellman:async function(t,e,a){const{fd:i,sections:o}=await Ua(t,"zkey",2),n=await eo(i,o);if("groth16"!=n.protocol)throw new Error("zkey file is not groth16");const c=await ja(n.q),r=2*c.G1.F.n8,l=2*c.G2.F.n8,s=await io(i,c,o),d=await Ga(e);let u;await L(n.vk_alpha_1),await L(n.vk_beta_1),await w(n.vk_beta_2),await w(n.vk_gamma_2),await L(n.vk_delta_1),await w(n.vk_delta_2),u=await Da(i,o,3),u=await c.G1.batchLEMtoU(u),await A("G1",u);const g=await Da(i,o,9);let _,f,h,p,m;_=await c.G1.fft(g,"affine","jacobian",a),_=await c.G1.batchApplyKey(_,c.Fr.neg(c.Fr.e(2)),c.Fr.w[n.power+1],"jacobian","affine",a),_=_.slice(0,_.byteLength-r),_=await c.G1.batchLEMtoU(_),await A("G1",_),f=await Da(i,o,8),f=await c.G1.batchLEMtoU(f),await A("G1",f),h=await Da(i,o,5),h=await c.G1.batchLEMtoU(h),await A("G1",h),p=await Da(i,o,6),p=await c.G1.batchLEMtoU(p),await A("G1",p),m=await Da(i,o,7),m=await c.G2.batchLEMtoU(m),await A("G2",m),await d.write(s.csHash),await async function(t){const e=new Uint8Array(4);new DataView(e.buffer,e.byteOffset,e.byteLength).setUint32(0,t,!1),await d.write(e)}(s.contributions.length);for(let t=0;t<s.contributions.length;t++){const e=s.contributions[t];await L(e.deltaAfter),await L(e.delta.g1_s),await L(e.delta.g1_sx),await w(e.delta.g2_spx),await d.write(e.transcript)}async function L(t){const e=new Uint8Array(r);c.G1.toRprUncompressed(e,0,t),await d.write(e)}async function w(t){const e=new Uint8Array(l);c.G2.toRprUncompressed(e,0,t),await d.write(e)}async function A(t,e){let a;a="G1"==t?r:l;const i=new Uint8Array(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint32(0,e.byteLength/a,!1),await d.write(i),await d.write(e)}await i.close(),await d.close()},importBellman:async function(t,e,a,i,o){const{fd:n,sections:c}=await Ua(t,"zkey",2),r=await eo(n,c,!1);if("groth16"!=r.protocol)throw new Error("zkey file is not groth16");const l=await ja(r.q),s=2*l.G1.F.n8,d=2*l.G2.F.n8,u=await io(n,l,c),g={},_=await Pa(e);_.pos=3*s+3*d+8+s*r.nVars+4+s*(r.domainSize-1)+4+s*r.nVars+4+s*r.nVars+4+d*r.nVars,g.csHash=await _.read(64);const f=await _.readUBE32();g.contributions=[];for(let t=0;t<f;t++){const e={delta:{}};e.deltaAfter=await y(_),e.delta.g1_s=await y(_),e.delta.g1_sx=await y(_),e.delta.g2_spx=await I(_),e.transcript=await _.read(64),t<u.contributions.length&&(e.type=u.contributions[t].type,1==e.type&&(e.beaconHash=u.contributions[t].beaconHash,e.numIterationsExp=u.contributions[t].numIterationsExp),u.contributions[t].name&&(e.name=u.contributions[t].name)),g.contributions.push(e)}if(!Di(g.csHash,u.csHash))return o&&o.error("Hash of the original circuit does not match with the MPC one"),!1;if(u.contributions.length>g.contributions.length)return o&&o.error("The impoerted file does not include new contributions"),!1;for(let t=0;t<u.contributions.length;t++)if(!C(u.contributions[t],g.contributions[t]))return o&&o.error(`Previos contribution ${t} does not match`),!1;if(i)for(let t=u.contributions.length;t<g.contributions.length;t++)g.contributions[t].name=i;const h=await Oa(a,"zkey",1,10);if(_.pos=0,_.pos+=s,_.pos+=s,_.pos+=d,_.pos+=d,r.vk_delta_1=await y(_),r.vk_delta_2=await I(_),await Wi(h,r),await _.readUBE32()!=r.nPublic+1)return o&&o.error("Invalid number of points in IC"),await h.discard(),!1;if(_.pos+=s*(r.nPublic+1),await Ra(n,c,h,3),await Ra(n,c,h,4),await _.readUBE32()!=r.domainSize-1)return o&&o.error("Invalid number of points in H"),await h.discard(),!1;let p;const m=await _.read(s*(r.domainSize-1)),L=await l.G1.batchUtoLEM(m);p=new Uint8Array(r.domainSize*s),p.set(L),l.G1.toRprLEM(p,s*(r.domainSize-1),l.G1.zeroAffine);const w=l.Fr.neg(l.Fr.inv(l.Fr.e(2))),A=l.Fr.inv(l.Fr.w[r.power+1]);if(p=await l.G1.batchApplyKey(p,w,A,"affine","jacobian",o),p=await l.G1.ifft(p,"jacobian","affine",o),await za(h,9),await h.write(p),await Qa(h),await _.readUBE32()!=r.nVars-r.nPublic-1)return o&&o.error("Invalid number of points in L"),await h.discard(),!1;let b;return b=await _.read(s*(r.nVars-r.nPublic-1)),b=await l.G1.batchUtoLEM(b),await za(h,8),await h.write(b),await Qa(h),await _.readUBE32()!=r.nVars?(o&&o.error("Invalid number of points in A"),await h.discard(),!1):(_.pos+=s*r.nVars,await Ra(n,c,h,5),await _.readUBE32()!=r.nVars?(o&&o.error("Invalid number of points in B1"),await h.discard(),!1):(_.pos+=s*r.nVars,await Ra(n,c,h,6),await _.readUBE32()!=r.nVars?(o&&o.error("Invalid number of points in B2"),await h.discard(),!1):(_.pos+=d*r.nVars,await Ra(n,c,h,7),await no(h,l,g),await _.close(),await h.close(),await n.close(),!0)));async function y(t){const e=await t.read(2*l.G1.F.n8);return l.G1.fromRprUncompressed(e,0)}async function I(t){const e=await t.read(2*l.G2.F.n8);return l.G2.fromRprUncompressed(e,0)}function C(t,e){return!!l.G1.eq(t.deltaAfter,e.deltaAfter)&&(!!l.G1.eq(t.delta.g1_s,e.delta.g1_s)&&(!!l.G1.eq(t.delta.g1_sx,e.delta.g1_sx)&&(!!l.G2.eq(t.delta.g2_spx,e.delta.g2_spx)&&!!Di(t.transcript,e.transcript))))}},verifyFromR1cs:async function(t,e,a,i){const o={type:"bigMem"};return await ln(t,e,o,i),await dn(o,e,a,i)},verifyFromInit:dn,contribute:async function(t,e,a,i,o){await $a.exports.ready();const{fd:n,sections:c}=await Ua(t,"zkey",2),r=await eo(n,c);if("groth16"!=r.protocol)throw new Error("zkey file is not groth16");const l=await ja(r.q),s=await io(n,l,c),d=await Oa(e,"zkey",1,10),u=await Ki(i),g=$a.exports(64);g.update(s.csHash);for(let t=0;t<s.contributions.length;t++)ro(g,l,s.contributions[t]);const _={delta:{}};_.delta.prvKey=l.Fr.fromRng(u),_.delta.g1_s=l.G1.toAffine(l.G1.fromRng(u)),_.delta.g1_sx=l.G1.toAffine(l.G1.timesFr(_.delta.g1_s,_.delta.prvKey)),co(g,l,_.delta.g1_s),co(g,l,_.delta.g1_sx),_.transcript=g.digest(),_.delta.g2_sp=Fo(l,_.transcript),_.delta.g2_spx=l.G2.toAffine(l.G2.timesFr(_.delta.g2_sp,_.delta.prvKey)),r.vk_delta_1=l.G1.timesFr(r.vk_delta_1,_.delta.prvKey),r.vk_delta_2=l.G2.timesFr(r.vk_delta_2,_.delta.prvKey),_.deltaAfter=r.vk_delta_1,_.type=0,a&&(_.name=a),s.contributions.push(_),await Wi(d,r),await Ra(n,c,d,3),await Ra(n,c,d,4),await Ra(n,c,d,5),await Ra(n,c,d,6),await Ra(n,c,d,7);const f=l.Fr.inv(_.delta.prvKey);await Ro(n,c,d,8,l,"G1",f,l.Fr.e(1),"L Section",o),await Ro(n,c,d,9,l,"G1",f,l.Fr.e(1),"H Section",o),await no(d,l,s),await n.close(),await d.close();const h=$a.exports(64);ro(h,l,_);const p=h.digest();return o&&o.info(Ri(s.csHash,"Circuit Hash: ")),o&&o.info(Ri(p,"Contribution Hash: ")),p},beacon:async function(t,e,a,i,o,n){await $a.exports.ready();const c=Hi(i);if(0==c.byteLength||2*c.byteLength!=i.length)return n&&n.error("Invalid Beacon Hash. (It must be a valid hexadecimal sequence)"),!1;if(c.length>=256)return n&&n.error("Maximum lenght of beacon hash is 255 bytes"),!1;if((o=parseInt(o))<10||o>63)return n&&n.error("Invalid numIterationsExp. (Must be between 10 and 63)"),!1;const{fd:r,sections:l}=await Ua(t,"zkey",2),s=await eo(r,l);if("groth16"!=s.protocol)throw new Error("zkey file is not groth16");const d=await ja(s.q),u=await io(r,d,l),g=await Oa(e,"zkey",1,10),_=await ji(c,o),f=$a.exports(64);f.update(u.csHash);for(let t=0;t<u.contributions.length;t++)ro(f,d,u.contributions[t]);const h={delta:{}};h.delta.prvKey=d.Fr.fromRng(_),h.delta.g1_s=d.G1.toAffine(d.G1.fromRng(_)),h.delta.g1_sx=d.G1.toAffine(d.G1.timesFr(h.delta.g1_s,h.delta.prvKey)),co(f,d,h.delta.g1_s),co(f,d,h.delta.g1_sx),h.transcript=f.digest(),h.delta.g2_sp=Fo(d,h.transcript),h.delta.g2_spx=d.G2.toAffine(d.G2.timesFr(h.delta.g2_sp,h.delta.prvKey)),s.vk_delta_1=d.G1.timesFr(s.vk_delta_1,h.delta.prvKey),s.vk_delta_2=d.G2.timesFr(s.vk_delta_2,h.delta.prvKey),h.deltaAfter=s.vk_delta_1,h.type=1,h.numIterationsExp=o,h.beaconHash=c,a&&(h.name=a),u.contributions.push(h),await Wi(g,s),await Ra(r,l,g,3),await Ra(r,l,g,4),await Ra(r,l,g,5),await Ra(r,l,g,6),await Ra(r,l,g,7);const p=d.Fr.inv(h.delta.prvKey);await Ro(r,l,g,8,d,"G1",p,d.Fr.e(1),"L Section",n),await Ro(r,l,g,9,d,"G1",p,d.Fr.e(1),"H Section",n),await no(g,d,u),await r.close(),await g.close();const m=$a.exports(64);ro(m,d,h);const L=m.digest();return n&&n.info(Ri(L,"Contribution Hash: ")),L},exportJson:async function(t){const e=await async function(t,e){const{fd:a,sections:i}=await Ua(t,"zkey",1),o=await eo(a,i,e),n=new K(o.r),c=ha.mod(ha.shl(1,8*o.n8r),o.r),r=n.inv(c),l=n.mul(r,r);let s=await ja(o.q);await qa(a,i,3),o.IC=[];for(let t=0;t<=o.nPublic;t++){const t=await Xi(a,s,e);o.IC.push(t)}await Ma(a),await qa(a,i,4);const d=await a.readULE32();o.ccoefs=[];for(let t=0;t<d;t++){const t=await a.readULE32(),e=await a.readULE32(),i=await a.readULE32(),n=await u();o.ccoefs.push({matrix:t,constraint:e,signal:i,value:n})}await Ma(a),await qa(a,i,5),o.A=[];for(let t=0;t<o.nVars;t++){const i=await Xi(a,s,e);o.A[t]=i}await Ma(a),await qa(a,i,6),o.B1=[];for(let t=0;t<o.nVars;t++){const i=await Xi(a,s,e);o.B1[t]=i}await Ma(a),await qa(a,i,7),o.B2=[];for(let t=0;t<o.nVars;t++){const i=await to(a,s,e);o.B2[t]=i}await Ma(a),await qa(a,i,8),o.C=[];for(let t=o.nPublic+1;t<o.nVars;t++){const i=await Xi(a,s,e);o.C[t]=i}await Ma(a),await qa(a,i,9),o.hExps=[];for(let t=0;t<o.domainSize;t++){const t=await Xi(a,s,e);o.hExps.push(t)}return await Ma(a),await a.close(),o;async function u(){const t=await ka(a,o.n8r);return n.mul(t,l)}}(t,!0);return delete e.curve,delete e.F,pa.stringifyBigInts(e)},bellmanContribute:async function(t,e,a,i,o){await $a.exports.ready();const n=await Ki(i),c=t.Fr.fromRng(n),r=t.Fr.inv(c),l=2*t.G1.F.n8,s=2*t.G2.F.n8,d=await Pa(e),u=await Ga(a);await B(l),await B(l),await B(s),await B(s);const g=await v(),_=t.G1.timesFr(g,c);await G(_);const f=await S(),h=t.G2.timesFr(f,c);await P(h);const p=await d.readUBE32();await u.writeUBE32(p),await B(p*l);const m=await d.readUBE32();await u.writeUBE32(m),await Do(d,u,null,t,"G1",m,r,t.Fr.e(1),"UNCOMPRESSED","H",o);const L=await d.readUBE32();await u.writeUBE32(L),await Do(d,u,null,t,"G1",L,r,t.Fr.e(1),"UNCOMPRESSED","L",o);const w=await d.readUBE32();await u.writeUBE32(w),await B(w*l);const A=await d.readUBE32();await u.writeUBE32(A),await B(A*l);const b=await d.readUBE32();await u.writeUBE32(b),await B(b*s);const y=$a.exports(64),I={};I.csHash=await d.read(64),y.update(I.csHash);const C=await d.readUBE32();I.contributions=[];for(let e=0;e<C;e++){const e={delta:{}};e.deltaAfter=await v(),e.delta.g1_s=await v(),e.delta.g1_sx=await v(),e.delta.g2_spx=await S(),e.transcript=await d.read(64),I.contributions.push(e),ro(y,t,e)}const F={delta:{}};F.delta.prvKey=c,F.delta.g1_s=t.G1.toAffine(t.G1.fromRng(n)),F.delta.g1_sx=t.G1.toAffine(t.G1.timesFr(F.delta.g1_s,c)),co(y,t,F.delta.g1_s),co(y,t,F.delta.g1_sx),F.transcript=y.digest(),F.delta.g2_sp=Fo(t,F.transcript),F.delta.g2_spx=t.G2.toAffine(t.G2.timesFr(F.delta.g2_sp,c)),F.deltaAfter=_,F.type=0,I.contributions.push(F),await u.write(I.csHash),await u.writeUBE32(I.contributions.length);for(let t=0;t<I.contributions.length;t++){const e=I.contributions[t];await G(e.deltaAfter),await G(e.delta.g1_s),await G(e.delta.g1_sx),await P(e.delta.g2_spx),await u.write(e.transcript)}const x=$a.exports(64);ro(x,t,F);const E=x.digest();return o&&o.info(Ri(E,"Contribution Hash: ")),await u.close(),await d.close(),E;async function B(t){const e=2*d.pageSize;for(let a=0;a<t;a+=e){const i=Math.min(t-a,e),o=await d.read(i);await u.write(o)}}async function v(){const e=await d.read(2*t.G1.F.n8);return t.G1.fromRprUncompressed(e,0)}async function S(){const e=await d.read(2*t.G2.F.n8);return t.G2.fromRprUncompressed(e,0)}async function G(e){const a=new Uint8Array(l);t.G1.toRprUncompressed(a,0,e),await u.write(a)}async function P(e){const a=new Uint8Array(s);t.G2.toRprUncompressed(a,0,e),await u.write(a)}},exportVerificationKey:gn,exportSolidityVerifier:async function(t,e,a){const i=await gn(t);let o=e[i.protocol];return _n.render(o,i)}});var hn,pn={exports:{}};
/**
* [js-sha3]{@link https://github.com/emn178/js-sha3}
*
* @version 0.8.0
* @author Chen, Yi-Cyuan [[email protected]]
* @copyright Chen, Yi-Cyuan 2015-2018
* @license MIT
*/hn=pn,function(){var t="input is invalid type",e="object"==typeof window,a=e?window:{};a.JS_SHA3_NO_WINDOW&&(e=!1);var i=!e&&"object"==typeof self;!a.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node?a=j:i&&(a=self);var o=!a.JS_SHA3_NO_COMMON_JS&&hn.exports,n=!a.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,c="0123456789abcdef".split(""),r=[4,1024,262144,67108864],l=[0,8,16,24],s=[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],g=["hex","buffer","arrayBuffer","array","digest"],_={128:168,256:136};!a.JS_SHA3_NO_NODE_JS&&Array.isArray||(Array.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)}),!n||!a.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,e,a){return function(i){return new v(t,e,t).update(i)[a]()}},h=function(t,e,a){return function(i,o){return new v(t,e,o).update(i)[a]()}},p=function(t,e,a){return function(e,i,o,n){return b["cshake"+t].update(e,i,o,n)[a]()}},m=function(t,e,a){return function(e,i,o,n){return b["kmac"+t].update(e,i,o,n)[a]()}},L=function(t,e,a,i){for(var o=0;o<g.length;++o){var n=g[o];t[n]=e(a,i,n)}return t},w=function(t,e){var a=f(t,e,"hex");return a.create=function(){return new v(t,e,t)},a.update=function(t){return a.create().update(t)},L(a,f,t,e)},A=[{name:"keccak",padding:[1,256,65536,16777216],bits:d,createMethod:w},{name:"sha3",padding:[6,1536,393216,100663296],bits:d,createMethod:w},{name:"shake",padding:[31,7936,2031616,520093696],bits:u,createMethod:function(t,e){var a=h(t,e,"hex");return a.create=function(a){return new v(t,e,a)},a.update=function(t,e){return a.create(e).update(t)},L(a,h,t,e)}},{name:"cshake",padding:r,bits:u,createMethod:function(t,e){var a=_[t],i=p(t,0,"hex");return i.create=function(i,o,n){return o||n?new v(t,e,i).bytepad([o,n],a):b["shake"+t].create(i)},i.update=function(t,e,a,o){return i.create(e,a,o).update(t)},L(i,p,t,e)}},{name:"kmac",padding:r,bits:u,createMethod:function(t,e){var a=_[t],i=m(t,0,"hex");return i.create=function(i,o,n){return new S(t,e,o).bytepad(["KMAC",n],a).bytepad([i],a)},i.update=function(t,e,a,o){return i.create(t,a,o).update(e)},L(i,m,t,e)}}],b={},y=[],I=0;I<A.length;++I)for(var C=A[I],F=C.bits,x=0;x<F.length;++x){var E=C.name+"_"+F[x];if(y.push(E),b[E]=C.createMethod(F[x],C.padding),"sha3"!==C.name){var B=C.name+F[x];y.push(B),b[B]=b[E]}}function v(t,e,a){this.blocks=[],this.s=[],this.padding=e,this.outputBits=a,this.reset=!0,this.finalized=!1,this.block=0,this.start=0,this.blockCount=1600-(t<<1)>>5,this.byteCount=this.blockCount<<2,this.outputBlocks=a>>5,this.extraBytes=(31&a)>>3;for(var i=0;i<50;++i)this.s[i]=0}function S(t,e,a){v.call(this,t,e,a)}v.prototype.update=function(e){if(this.finalized)throw new Error("finalize already called");var a,i=typeof e;if("string"!==i){if("object"!==i)throw new Error(t);if(null===e)throw new Error(t);if(n&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!(Array.isArray(e)||n&&ArrayBuffer.isView(e)))throw new Error(t);a=!0}for(var o,c,r=this.blocks,s=this.byteCount,d=e.length,u=this.blockCount,g=0,_=this.s;g<d;){if(this.reset)for(this.reset=!1,r[0]=this.block,o=1;o<u+1;++o)r[o]=0;if(a)for(o=this.start;g<d&&o<s;++g)r[o>>2]|=e[g]<<l[3&o++];else for(o=this.start;g<d&&o<s;++g)(c=e.charCodeAt(g))<128?r[o>>2]|=c<<l[3&o++]:c<2048?(r[o>>2]|=(192|c>>6)<<l[3&o++],r[o>>2]|=(128|63&c)<<l[3&o++]):c<55296||c>=57344?(r[o>>2]|=(224|c>>12)<<l[3&o++],r[o>>2]|=(128|c>>6&63)<<l[3&o++],r[o>>2]|=(128|63&c)<<l[3&o++]):(c=65536+((1023&c)<<10|1023&e.charCodeAt(++g)),r[o>>2]|=(240|c>>18)<<l[3&o++],r[o>>2]|=(128|c>>12&63)<<l[3&o++],r[o>>2]|=(128|c>>6&63)<<l[3&o++],r[o>>2]|=(128|63&c)<<l[3&o++]);if(this.lastByteIndex=o,o>=s){for(this.start=o-s,this.block=r[u],o=0;o<u;++o)_[o]^=r[o];G(_),this.reset=!0}else this.start=o}return this},v.prototype.encode=function(t,e){var a=255&t,i=1,o=[a];for(a=255&(t>>=8);a>0;)o.unshift(a),a=255&(t>>=8),++i;return e?o.push(i):o.unshift(i),this.update(o),o.length},v.prototype.encodeString=function(e){var a,i=typeof e;if("string"!==i){if("object"!==i)throw new Error(t);if(null===e)throw new Error(t);if(n&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!(Array.isArray(e)||n&&ArrayBuffer.isView(e)))throw new Error(t);a=!0}var o=0,c=e.length;if(a)o=c;else for(var r=0;r<e.length;++r){var l=e.charCodeAt(r);l<128?o+=1:l<2048?o+=2:l<55296||l>=57344?o+=3:(l=65536+((1023&l)<<10|1023&e.charCodeAt(++r)),o+=4)}return o+=this.encode(8*o),this.update(e),o},v.prototype.bytepad=function(t,e){for(var a=this.encode(e),i=0;i<t.length;++i)a+=this.encodeString(t[i]);var o=e-a%e,n=[];return n.length=o,this.update(n),this},v.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,e=this.lastByteIndex,a=this.blockCount,i=this.s;if(t[e>>2]|=this.padding[3&e],this.lastByteIndex===this.byteCount)for(t[0]=t[a],e=1;e<a+1;++e)t[e]=0;for(t[a-1]|=2147483648,e=0;e<a;++e)i[e]^=t[e];G(i)}},v.prototype.toString=v.prototype.hex=function(){this.finalize();for(var t,e=this.blockCount,a=this.s,i=this.outputBlocks,o=this.extraBytes,n=0,r=0,l="";r<i;){for(n=0;n<e&&r<i;++n,++r)t=a[n],l+=c[t>>4&15]+c[15&t]+c[t>>12&15]+c[t>>8&15]+c[t>>20&15]+c[t>>16&15]+c[t>>28&15]+c[t>>24&15];r%e==0&&(G(a),n=0)}return o&&(t=a[n],l+=c[t>>4&15]+c[15&t],o>1&&(l+=c[t>>12&15]+c[t>>8&15]),o>2&&(l+=c[t>>20&15]+c[t>>16&15])),l},v.prototype.arrayBuffer=function(){this.finalize();var t,e=this.blockCount,a=this.s,i=this.outputBlocks,o=this.extraBytes,n=0,c=0,r=this.outputBits>>3;t=o?new ArrayBuffer(i+1<<2):new ArrayBuffer(r);for(var l=new Uint32Array(t);c<i;){for(n=0;n<e&&c<i;++n,++c)l[c]=a[n];c%e==0&&G(a)}return o&&(l[n]=a[n],t=t.slice(0,r)),t},v.prototype.buffer=v.prototype.arrayBuffer,v.prototype.digest=v.prototype.array=function(){this.finalize();for(var t,e,a=this.blockCount,i=this.s,o=this.outputBlocks,n=this.extraBytes,c=0,r=0,l=[];r<o;){for(c=0;c<a&&r<o;++c,++r)t=r<<2,e=i[c],l[t]=255&e,l[t+1]=e>>8&255,l[t+2]=e>>16&255,l[t+3]=e>>24&255;r%a==0&&G(i)}return n&&(t=r<<2,e=i[c],l[t]=255&e,n>1&&(l[t+1]=e>>8&255),n>2&&(l[t+2]=e>>16&255)),l},S.prototype=new v,S.prototype.finalize=function(){return this.encode(this.outputBits,!0),v.prototype.finalize.call(this)};var G=function(t){var e,a,i,o,n,c,r,l,d,u,g,_,f,h,p,m,L,w,A,b,y,I,C,F,x,E,B,v,S,G,P,U,O,z,Q,q,M,T,k,R,D,N,V,K,j,H,$,Y,W,Z,J,X,tt,et,at,it,ot,nt,ct,rt,lt,st,dt;for(i=0;i<48;i+=2)o=t[0]^t[10]^t[20]^t[30]^t[40],n=t[1]^t[11]^t[21]^t[31]^t[41],c=t[2]^t[12]^t[22]^t[32]^t[42],r=t[3]^t[13]^t[23]^t[33]^t[43],l=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],g=t[7]^t[17]^t[27]^t[37]^t[47],e=(_=t[8]^t[18]^t[28]^t[38]^t[48])^(c<<1|r>>>31),a=(f=t[9]^t[19]^t[29]^t[39]^t[49])^(r<<1|c>>>31),t[0]^=e,t[1]^=a,t[10]^=e,t[11]^=a,t[20]^=e,t[21]^=a,t[30]^=e,t[31]^=a,t[40]^=e,t[41]^=a,e=o^(l<<1|d>>>31),a=n^(d<<1|l>>>31),t[2]^=e,t[3]^=a,t[12]^=e,t[13]^=a,t[22]^=e,t[23]^=a,t[32]^=e,t[33]^=a,t[42]^=e,t[43]^=a,e=c^(u<<1|g>>>31),a=r^(g<<1|u>>>31),t[4]^=e,t[5]^=a,t[14]^=e,t[15]^=a,t[24]^=e,t[25]^=a,t[34]^=e,t[35]^=a,t[44]^=e,t[45]^=a,e=l^(_<<1|f>>>31),a=d^(f<<1|_>>>31),t[6]^=e,t[7]^=a,t[16]^=e,t[17]^=a,t[26]^=e,t[27]^=a,t[36]^=e,t[37]^=a,t[46]^=e,t[47]^=a,e=u^(o<<1|n>>>31),a=g^(n<<1|o>>>31),t[8]^=e,t[9]^=a,t[18]^=e,t[19]^=a,t[28]^=e,t[29]^=a,t[38]^=e,t[39]^=a,t[48]^=e,t[49]^=a,h=t[0],p=t[1],H=t[11]<<4|t[10]>>>28,$=t[10]<<4|t[11]>>>28,v=t[20]<<3|t[21]>>>29,S=t[21]<<3|t[20]>>>29,rt=t[31]<<9|t[30]>>>23,lt=t[30]<<9|t[31]>>>23,N=t[40]<<18|t[41]>>>14,V=t[41]<<18|t[40]>>>14,z=t[2]<<1|t[3]>>>31,Q=t[3]<<1|t[2]>>>31,m=t[13]<<12|t[12]>>>20,L=t[12]<<12|t[13]>>>20,Y=t[22]<<10|t[23]>>>22,W=t[23]<<10|t[22]>>>22,G=t[33]<<13|t[32]>>>19,P=t[32]<<13|t[33]>>>19,st=t[42]<<2|t[43]>>>30,dt=t[43]<<2|t[42]>>>30,et=t[5]<<30|t[4]>>>2,at=t[4]<<30|t[5]>>>2,q=t[14]<<6|t[15]>>>26,M=t[15]<<6|t[14]>>>26,w=t[25]<<11|t[24]>>>21,A=t[24]<<11|t[25]>>>21,Z=t[34]<<15|t[35]>>>17,J=t[35]<<15|t[34]>>>17,U=t[45]<<29|t[44]>>>3,O=t[44]<<29|t[45]>>>3,F=t[6]<<28|t[7]>>>4,x=t[7]<<28|t[6]>>>4,it=t[17]<<23|t[16]>>>9,ot=t[16]<<23|t[17]>>>9,T=t[26]<<25|t[27]>>>7,k=t[27]<<25|t[26]>>>7,b=t[36]<<21|t[37]>>>11,y=t[37]<<21|t[36]>>>11,X=t[47]<<24|t[46]>>>8,tt=t[46]<<24|t[47]>>>8,K=t[8]<<27|t[9]>>>5,j=t[9]<<27|t[8]>>>5,E=t[18]<<20|t[19]>>>12,B=t[19]<<20|t[18]>>>12,nt=t[29]<<7|t[28]>>>25,ct=t[28]<<7|t[29]>>>25,R=t[38]<<8|t[39]>>>24,D=t[39]<<8|t[38]>>>24,I=t[48]<<14|t[49]>>>18,C=t[49]<<14|t[48]>>>18,t[0]=h^~m&w,t[1]=p^~L&A,t[10]=F^~E&v,t[11]=x^~B&S,t[20]=z^~q&T,t[21]=Q^~M&k,t[30]=K^~H&Y,t[31]=j^~$&W,t[40]=et^~it&nt,t[41]=at^~ot&ct,t[2]=m^~w&b,t[3]=L^~A&y,t[12]=E^~v&G,t[13]=B^~S&P,t[22]=q^~T&R,t[23]=M^~k&D,t[32]=H^~Y&Z,t[33]=$^~W&J,t[42]=it^~nt&rt,t[43]=ot^~ct<,t[4]=w^~b&I,t[5]=A^~y&C,t[14]=v^~G&U,t[15]=S^~P&O,t[24]=T^~R&N,t[25]=k^~D&V,t[34]=Y^~Z&X,t[35]=W^~J&tt,t[44]=nt^~rt&st,t[45]=ct^~lt&dt,t[6]=b^~I&h,t[7]=y^~C&p,t[16]=G^~U&F,t[17]=P^~O&x,t[26]=R^~N&z,t[27]=D^~V&Q,t[36]=Z^~X&K,t[37]=J^~tt&j,t[46]=rt^~st&et,t[47]=lt^~dt&at,t[8]=I^~h&m,t[9]=C^~p&L,t[18]=U^~F&E,t[19]=O^~x&B,t[28]=N^~z&q,t[29]=V^~Q&M,t[38]=X^~K&H,t[39]=tt^~j&$,t[48]=st^~et&it,t[49]=dt^~at&ot,t[0]^=s[i],t[1]^=s[i+1]};if(o)hn.exports=b;else for(I=0;I<y.length;++I)a[y[I]]=b[y[I]]}();var mn=pn.exports;const{stringifyBigInts:Ln}=pa,{keccak256:wn}=mn;async function An(t,e,a){const{fd:i,sections:o}=await Ua(e,"wtns",2),n=await lo(i,o),{fd:c,sections:r}=await Ua(t,"zkey",2),l=await eo(c,r);if("plonk"!=l.protocol)throw new Error("zkey file is not plonk");if(!ha.eq(l.r,n.q))throw new Error("Curve of the witness does not match the curve of the proving key");if(n.nWitness!=l.nVars-l.nAdditions)throw new Error(`Invalid witness length. Circuit: ${l.nVars}, witness: ${n.nWitness}, ${l.nAdditions}`);const s=l.curve,d=s.Fr,u=s.G1,g=s.Fr.n8;a&&a.debug("Reading Wtns");const _=await Da(i,o,2);_.set(d.zero,0);const f=new Pe(g*l.nAdditions);let h,p,m,L,w,A,b,y,I,C,F,x,E,B;await async function(){const t=await Da(c,r,3),e=8+2*s.Fr.n8;for(let a=0;a<l.nAdditions;a++){const i=q(t,a*e),o=q(t,a*e+4),n=t.slice(a*e+8,a*e+8+g),c=t.slice(a*e+8+g,a*e+8+2*g),r=M(i),l=M(o),d=s.Fr.add(s.Fr.mul(n,r),s.Fr.mul(c,l));f.set(d,g*a)}}();let v={};const S=new Pe(l.domainSize*g*4*3);let G=r[12][0].p+l.domainSize*g;await c.readToBuffer(S,0,l.domainSize*g*4,G),G+=l.domainSize*g*5,await c.readToBuffer(S,l.domainSize*g*4,l.domainSize*g*4,G),G+=l.domainSize*g*5,await c.readToBuffer(S,l.domainSize*g*8,l.domainSize*g*4,G);const P=new Pe(l.domainSize*g);await c.readToBuffer(P,0,l.domainSize*g,r[12][0].p);const U=new Pe(l.domainSize*g);await c.readToBuffer(U,0,l.domainSize*g,r[12][0].p+5*l.domainSize*g);const O=await Da(c,r,14),z={};await async function(){z.b=[];for(let t=1;t<=11;t++)z.b[t]=s.Fr.random();[h,p,m]=await async function(){let t=new Pe(l.domainSize*g),e=new Pe(l.domainSize*g),a=new Pe(l.domainSize*g);const i=await Da(c,r,4),o=await Da(c,r,5),n=await Da(c,r,6);for(let c=0;c<l.nConstrains;c++){const r=q(i,4*c);t.set(M(r),c*g);const l=q(o,4*c);e.set(M(l),c*g);const s=q(n,4*c);a.set(M(s),c*g)}return t=await d.batchToMontgomery(t),e=await d.batchToMontgomery(e),a=await d.batchToMontgomery(a),[t,e,a]}(),[I,w]=await N(h,[z.b[2],z.b[1]]),[C,A]=await N(p,[z.b[4],z.b[3]]),[F,b]=await N(m,[z.b[6],z.b[5]]),v.A=await D(I,"multiexp A"),v.B=await D(C,"multiexp B"),v.C=await D(F,"multiexp C")}(),await async function(){const t=new Uint8Array(l.nPublic*g+2*u.F.n8*3);for(let e=0;e<l.nPublic;e++)d.toRprBE(t,e*g,h.slice(e*g,(e+1)*g));u.toRprUncompressed(t,l.nPublic*g+0,v.A),u.toRprUncompressed(t,l.nPublic*g+2*u.F.n8,v.B),u.toRprUncompressed(t,l.nPublic*g+4*u.F.n8,v.C),z.beta=T(t),a&&a.debug("beta: "+d.toString(z.beta));const e=new Uint8Array(g);d.toRprBE(e,0,z.beta),z.gamma=T(e),a&&a.debug("gamma: "+d.toString(z.gamma));let i=new Pe(d.n8*l.domainSize),o=new Pe(d.n8*l.domainSize);i.set(d.one,0),o.set(d.one,0);let n=d.one;for(let t=0;t<l.domainSize;t++){let e=h.slice(t*g,(t+1)*g);e=d.add(e,d.mul(z.beta,n)),e=d.add(e,z.gamma);let a=p.slice(t*g,(t+1)*g);a=d.add(a,d.mul(l.k1,d.mul(z.beta,n))),a=d.add(a,z.gamma);let c=m.slice(t*g,(t+1)*g);c=d.add(c,d.mul(l.k2,d.mul(z.beta,n))),c=d.add(c,z.gamma);const r=d.mul(e,d.mul(a,c));let s=h.slice(t*g,(t+1)*g);s=d.add(s,d.mul(S.slice(t*g*4,t*g*4+g),z.beta)),s=d.add(s,z.gamma);let u=p.slice(t*g,(t+1)*g);u=d.add(u,d.mul(S.slice(4*(l.domainSize+t)*g,4*(l.domainSize+t)*g+g),z.beta)),u=d.add(u,z.gamma);let _=m.slice(t*g,(t+1)*g);_=d.add(_,d.mul(S.slice(4*(2*l.domainSize+t)*g,4*(2*l.domainSize+t)*g+g),z.beta)),_=d.add(_,z.gamma);const f=d.mul(s,d.mul(u,_));i.set(d.mul(i.slice(t*g,(t+1)*g),r),(t+1)%l.domainSize*g),o.set(d.mul(o.slice(t*g,(t+1)*g),f),(t+1)%l.domainSize*g),n=d.mul(n,d.w[l.power])}o=await d.batchInverse(o);for(let t=0;t<l.domainSize;t++)i.set(d.mul(i.slice(t*g,(t+1)*g),o.slice(t*g,(t+1)*g)),t*g);if(!d.eq(i.slice(0,g),d.one))throw new Error("Copy constraints does not match");L=i,[x,y]=await N(L,[z.b[9],z.b[8],z.b[7]]),v.Z=await D(x,"multiexp Z")}(),await async function(){a&&a.debug("phse3: Reading QM4");const t=new Pe(4*l.domainSize*g);await c.readToBuffer(t,0,l.domainSize*g*4,r[7][0].p+l.domainSize*g),a&&a.debug("phse3: Reading QL4");const e=new Pe(4*l.domainSize*g);await c.readToBuffer(e,0,l.domainSize*g*4,r[8][0].p+l.domainSize*g),a&&a.debug("phse3: Reading QR4");const i=new Pe(4*l.domainSize*g);await c.readToBuffer(i,0,l.domainSize*g*4,r[9][0].p+l.domainSize*g),a&&a.debug("phse3: Reading QO4");const o=new Pe(4*l.domainSize*g);await c.readToBuffer(o,0,l.domainSize*g*4,r[10][0].p+l.domainSize*g),a&&a.debug("phse3: Reading QC4");const n=new Pe(4*l.domainSize*g);await c.readToBuffer(n,0,l.domainSize*g*4,r[11][0].p+l.domainSize*g);const s=await Da(c,r,13),_=new Uint8Array(2*u.F.n8);u.toRprUncompressed(_,0,v.Z),z.alpha=T(_),a&&a.debug("alpha: "+d.toString(z.alpha));const f=[d.zero,d.add(d.e(-1),d.w[2]),d.e(-2),d.sub(d.e(-1),d.w[2])],p=[d.zero,d.add(d.zero,d.mul(d.e(-2),d.w[2])),d.e(4),d.sub(d.zero,d.mul(d.e(-2),d.w[2]))],m=[d.zero,d.add(d.e(2),d.mul(d.e(2),d.w[2])),d.e(-8),d.sub(d.e(2),d.mul(d.e(2),d.w[2]))],L=new Pe(4*l.domainSize*g),I=new Pe(4*l.domainSize*g);let C=d.one;for(let c=0;c<4*l.domainSize;c++){c%4096==0&&a&&a.debug(`calculating t ${c}/${4*l.domainSize}`);const r=w.slice(c*g,c*g+g),u=A.slice(c*g,c*g+g),_=b.slice(c*g,c*g+g),f=y.slice(c*g,c*g+g),p=y.slice((c+4*l.domainSize+4)%(4*l.domainSize)*g,(c+4*l.domainSize+4)%(4*l.domainSize)*g+g),m=t.slice(c*g,c*g+g),F=e.slice(c*g,c*g+g),x=i.slice(c*g,c*g+g),E=o.slice(c*g,c*g+g),B=n.slice(c*g,c*g+g),v=S.slice(c*g,c*g+g),G=S.slice((c+4*l.domainSize)*g,(c+4*l.domainSize)*g+g),P=S.slice((c+8*l.domainSize)*g,(c+8*l.domainSize)*g+g),U=d.add(z.b[2],d.mul(z.b[1],C)),O=d.add(z.b[4],d.mul(z.b[3],C)),M=d.add(z.b[6],d.mul(z.b[5],C)),T=d.square(C),k=d.add(d.add(d.mul(z.b[7],T),d.mul(z.b[8],C)),z.b[9]),R=d.mul(C,d.w[l.power]),D=d.square(R),N=d.add(d.add(d.mul(z.b[7],D),d.mul(z.b[8],R)),z.b[9]);let V=d.zero;for(let t=0;t<l.nPublic;t++)V=d.sub(V,d.mul(s.slice((5*t*l.domainSize+l.domainSize+c)*g,(5*t*l.domainSize+l.domainSize+c+1)*g),h.slice(t*g,(t+1)*g)));let[K,j]=Q(r,u,U,O,c%4);K=d.mul(K,m),j=d.mul(j,m),K=d.add(K,d.mul(r,F)),j=d.add(j,d.mul(U,F)),K=d.add(K,d.mul(u,x)),j=d.add(j,d.mul(O,x)),K=d.add(K,d.mul(_,E)),j=d.add(j,d.mul(M,E)),K=d.add(K,V),K=d.add(K,B);const H=d.mul(z.beta,C);let $=r;$=d.add($,H),$=d.add($,z.gamma);let Y=u;Y=d.add(Y,d.mul(H,l.k1)),Y=d.add(Y,z.gamma);let W=_;W=d.add(W,d.mul(H,l.k2)),W=d.add(W,z.gamma);let Z=f,[J,X]=q($,Y,W,Z,U,O,M,k,c%4);J=d.mul(J,z.alpha),X=d.mul(X,z.alpha);let tt=r;tt=d.add(tt,d.mul(z.beta,v)),tt=d.add(tt,z.gamma);let et=u;et=d.add(et,d.mul(z.beta,G)),et=d.add(et,z.gamma);let at=_;at=d.add(at,d.mul(z.beta,P)),at=d.add(at,z.gamma);let it=p,[ot,nt]=q(tt,et,at,it,U,O,M,N,c%4);ot=d.mul(ot,z.alpha),nt=d.mul(nt,z.alpha);let ct=d.sub(f,d.one);ct=d.mul(ct,s.slice((l.domainSize+c)*g,(l.domainSize+c+1)*g)),ct=d.mul(ct,d.mul(z.alpha,z.alpha));let rt=d.mul(k,s.slice((l.domainSize+c)*g,(l.domainSize+c+1)*g));rt=d.mul(rt,d.mul(z.alpha,z.alpha));let lt=d.add(d.sub(d.add(K,J),ot),ct),st=d.add(d.sub(d.add(j,X),nt),rt);L.set(lt,c*g),I.set(st,c*g),C=d.mul(C,d.w[l.power+2])}a&&a.debug("ifft T");let F=await d.ifft(L);a&&a.debug("dividing T/Z");for(let t=0;t<l.domainSize;t++)F.set(d.neg(F.slice(t*g,t*g+g)),t*g);for(let t=l.domainSize;t<4*l.domainSize;t++){const e=d.sub(F.slice((t-l.domainSize)*g,(t-l.domainSize)*g+g),F.slice(t*g,t*g+g));if(F.set(e,t*g),t>3*l.domainSize-4&&!d.isZero(e))throw new Error("T Polynomial is not divisible")}a&&a.debug("ifft Tz");const x=await d.ifft(I);for(let t=0;t<4*l.domainSize;t++){const e=x.slice(t*g,(t+1)*g);if(t>3*l.domainSize+5){if(!d.isZero(e))throw new Error("Tz Polynomial is not well calculated")}else F.set(d.add(F.slice(t*g,(t+1)*g),e),t*g)}E=F.slice(0,(3*l.domainSize+6)*g);let B=new Pe((l.domainSize+1)*g);B.set(F.slice(0,l.domainSize*g),0),B.set(z.b[10],l.domainSize*g);let G=new Pe((l.domainSize+1)*g);G.set(F.slice(l.domainSize*g,2*l.domainSize*g),0);const P=d.sub(G.slice(0,g),z.b[10]);G.set(P,0),G.set(z.b[11],l.domainSize*g);let U=new Pe((l.domainSize+6)*g);U.set(F.slice(2*l.domainSize*g,(3*l.domainSize+6)*g),0);const O=d.sub(U.slice(0,g),z.b[11]);function Q(t,e,a,i,o){let n,c;const r=d.mul(t,e),l=d.mul(t,i),s=d.mul(a,e);n=r;let u=d.mul(a,i);return c=d.add(l,s),o&&(c=d.add(c,d.mul(f[o],u))),[n,c]}function q(t,e,a,i,o,n,c,r,l){let s,u;const g=d.mul(t,e),_=d.mul(t,n),h=d.mul(o,e),L=d.mul(o,n),w=d.mul(a,i),A=d.mul(a,r),b=d.mul(c,i),y=d.mul(c,r);s=d.mul(g,w);let I=d.mul(h,w);I=d.add(I,d.mul(_,w)),I=d.add(I,d.mul(g,b)),I=d.add(I,d.mul(g,A));let C=d.mul(L,w);C=d.add(C,d.mul(h,b)),C=d.add(C,d.mul(h,A)),C=d.add(C,d.mul(_,b)),C=d.add(C,d.mul(_,A)),C=d.add(C,d.mul(g,y));let F=d.mul(_,y);F=d.add(F,d.mul(h,y)),F=d.add(F,d.mul(L,A)),F=d.add(F,d.mul(L,b));let x=d.mul(L,y);return u=I,l&&(u=d.add(u,d.mul(f[l],C)),u=d.add(u,d.mul(p[l],F)),u=d.add(u,d.mul(m[l],x))),[s,u]}U.set(O,0),v.T1=await D(B,"multiexp T1"),v.T2=await D(G,"multiexp T2"),v.T3=await D(U,"multiexp T3")}(),await async function(){const t=new Pe(l.domainSize*g);await c.readToBuffer(t,0,l.domainSize*g,r[7][0].p);const e=new Pe(l.domainSize*g);await c.readToBuffer(e,0,l.domainSize*g,r[8][0].p);const i=new Pe(l.domainSize*g);await c.readToBuffer(i,0,l.domainSize*g,r[9][0].p);const o=new Pe(l.domainSize*g);await c.readToBuffer(o,0,l.domainSize*g,r[10][0].p);const n=new Pe(l.domainSize*g);await c.readToBuffer(n,0,l.domainSize*g,r[11][0].p);const s=new Pe(l.domainSize*g);await c.readToBuffer(s,0,l.domainSize*g,r[12][0].p+10*l.domainSize*g);const _=new Uint8Array(2*u.F.n8*3);u.toRprUncompressed(_,0,v.T1),u.toRprUncompressed(_,2*u.F.n8,v.T2),u.toRprUncompressed(_,4*u.F.n8,v.T3),z.xi=T(_),a&&a.debug("xi: "+d.toString(z.xi));v.eval_a=k(I,z.xi),v.eval_b=k(C,z.xi),v.eval_c=k(F,z.xi),v.eval_s1=k(P,z.xi),v.eval_s2=k(U,z.xi),v.eval_t=k(E,z.xi),v.eval_zw=k(x,d.mul(z.xi,d.w[l.power]));const f=d.mul(v.eval_a,v.eval_b);let h=v.eval_a;const p=d.mul(z.beta,z.xi);h=d.add(h,p),h=d.add(h,z.gamma);let m=v.eval_b;m=d.add(m,d.mul(p,l.k1)),m=d.add(m,z.gamma);let L=v.eval_c;L=d.add(L,d.mul(p,l.k2)),L=d.add(L,z.gamma);const w=d.mul(d.mul(d.mul(h,m),L),z.alpha);let A=v.eval_a;A=d.add(A,d.mul(z.beta,v.eval_s1)),A=d.add(A,z.gamma);let b=v.eval_b;b=d.add(b,d.mul(z.beta,v.eval_s2)),b=d.add(b,z.gamma);let y=d.mul(A,b);y=d.mul(y,z.beta),y=d.mul(y,v.eval_zw),y=d.mul(y,z.alpha),z.xim=z.xi;for(let t=0;t<l.power;t++)z.xim=d.mul(z.xim,z.xim);const S=d.div(d.sub(z.xim,d.one),d.mul(d.sub(z.xi,d.one),d.e(l.domainSize))),G=d.mul(S,d.mul(z.alpha,z.alpha)),O=y,Q=d.add(w,G);B=new Pe((l.domainSize+3)*g);for(let a=0;a<l.domainSize+3;a++){let c=d.mul(Q,x.slice(a*g,(a+1)*g));a<l.domainSize&&(c=d.add(c,d.mul(f,t.slice(a*g,(a+1)*g))),c=d.add(c,d.mul(v.eval_a,e.slice(a*g,(a+1)*g))),c=d.add(c,d.mul(v.eval_b,i.slice(a*g,(a+1)*g))),c=d.add(c,d.mul(v.eval_c,o.slice(a*g,(a+1)*g))),c=d.add(c,n.slice(a*g,(a+1)*g)),c=d.sub(c,d.mul(O,s.slice(a*g,(a+1)*g)))),B.set(c,a*g)}v.eval_r=k(B,z.xi)}(),await async function(){const t=new Uint8Array(7*g);d.toRprBE(t,0,v.eval_a),d.toRprBE(t,g,v.eval_b),d.toRprBE(t,2*g,v.eval_c),d.toRprBE(t,3*g,v.eval_s1),d.toRprBE(t,4*g,v.eval_s2),d.toRprBE(t,5*g,v.eval_zw),d.toRprBE(t,6*g,v.eval_r),z.v=[],z.v[1]=T(t),a&&a.debug("v: "+d.toString(z.v[1]));for(let t=2;t<=6;t++)z.v[t]=d.mul(z.v[t-1],z.v[1]);let e=new Pe((l.domainSize+6)*g);const i=d.mul(z.xim,z.xim);for(let t=0;t<l.domainSize+6;t++){let a=d.zero;const o=E.slice((2*l.domainSize+t)*g,(2*l.domainSize+t+1)*g);if(a=d.add(a,d.mul(i,o)),t<l.domainSize+3&&(a=d.add(a,d.mul(z.v[1],B.slice(t*g,(t+1)*g)))),t<l.domainSize+2&&(a=d.add(a,d.mul(z.v[2],I.slice(t*g,(t+1)*g))),a=d.add(a,d.mul(z.v[3],C.slice(t*g,(t+1)*g))),a=d.add(a,d.mul(z.v[4],F.slice(t*g,(t+1)*g)))),t<l.domainSize){const e=E.slice(t*g,(t+1)*g);a=d.add(a,e);const i=E.slice((l.domainSize+t)*g,(l.domainSize+t+1)*g);a=d.add(a,d.mul(z.xim,i)),a=d.add(a,d.mul(z.v[5],P.slice(t*g,(t+1)*g))),a=d.add(a,d.mul(z.v[6],U.slice(t*g,(t+1)*g)))}0===t&&(a=d.sub(a,d.mul(i,z.b[11])),a=d.sub(a,d.mul(z.xim,z.b[10]))),t===l.domainSize&&(a=d.add(a,z.b[10]),a=d.add(a,d.mul(z.xim,z.b[11]))),e.set(a,t*g)}let o=e.slice(0,g);o=d.sub(o,v.eval_t),o=d.sub(o,d.mul(z.v[1],v.eval_r)),o=d.sub(o,d.mul(z.v[2],v.eval_a)),o=d.sub(o,d.mul(z.v[3],v.eval_b)),o=d.sub(o,d.mul(z.v[4],v.eval_c)),o=d.sub(o,d.mul(z.v[5],v.eval_s1)),o=d.sub(o,d.mul(z.v[6],v.eval_s2)),e.set(o,0),e=R(e,z.xi),v.Wxi=await D(e,"multiexp Wxi");let n=new Pe((l.domainSize+3)*g);for(let t=0;t<l.domainSize+3;t++){const e=x.slice(t*g,(t+1)*g);n.set(e,t*g)}o=n.slice(0,g),o=d.sub(o,v.eval_zw),n.set(o,0),n=R(n,d.mul(z.xi,d.w[l.power])),v.Wxiw=await D(n,"multiexp Wxiw")}(),v.protocol="plonk",v.curve=s.name,await c.close(),await i.close();let Q=[];for(let t=1;t<=l.nPublic;t++){const e=_.slice(t*d.n8,t*d.n8+d.n8);Q.push(ha.fromRprLE(e))}return v.A=u.toObject(v.A),v.B=u.toObject(v.B),v.C=u.toObject(v.C),v.Z=u.toObject(v.Z),v.T1=u.toObject(v.T1),v.T2=u.toObject(v.T2),v.T3=u.toObject(v.T3),v.eval_a=d.toObject(v.eval_a),v.eval_b=d.toObject(v.eval_b),v.eval_c=d.toObject(v.eval_c),v.eval_s1=d.toObject(v.eval_s1),v.eval_s2=d.toObject(v.eval_s2),v.eval_zw=d.toObject(v.eval_zw),v.eval_t=d.toObject(v.eval_t),v.eval_r=d.toObject(v.eval_r),v.Wxi=u.toObject(v.Wxi),v.Wxiw=u.toObject(v.Wxiw),delete v.eval_t,v=Ln(v),Q=Ln(Q),{proof:v,publicSignals:Q};function q(t,e){const a=t.slice(e,e+4);return new DataView(a.buffer,a.byteOffset,a.byteLength).getUint32(0,!0)}function M(t){return t<l.nVars-l.nAdditions?_.slice(t*g,t*g+g):t<l.nVars?f.slice((t-(l.nVars-l.nAdditions))*g,(t-(l.nVars-l.nAdditions))*g+g):s.Fr.zero}function T(t){const e=ha.fromRprBE(new Uint8Array(wn.arrayBuffer(t)));return d.e(e)}function k(t,e){const a=t.byteLength/g;if(0==a)return d.zero;let i=t.slice((a-1)*g,a*g);for(let o=a-2;o>=0;o--)i=d.add(d.mul(i,e),t.slice(o*g,(o+1)*g));return i}function R(t,e){const a=t.byteLength/g,i=new Pe(a*g);i.set(d.zero,(a-1)*g),i.set(t.slice((a-1)*g,a*g),(a-2)*g);for(let o=a-3;o>=0;o--)i.set(d.add(t.slice((o+1)*g,(o+2)*g),d.mul(e,i.slice((o+1)*g,(o+2)*g))),o*g);if(!d.eq(t.slice(0,g),d.mul(d.neg(e),i.slice(0,g))))throw new Error("Polinomial does not divide");return i}async function D(t,e){const i=t.byteLength/g,o=O.slice(0,i*s.G1.F.n8*2),n=await s.Fr.batchFromMontgomery(t);let c=await s.G1.multiExpAffine(o,n,a,e);return c=s.G1.toAffine(c),c}async function N(t,e){e=e||[];let a=await d.ifft(t);const i=new Pe(g*l.domainSize*4);i.set(a,0);const o=new Pe(g*(l.domainSize+e.length));o.set(a,0);for(let t=0;t<e.length;t++)o.set(d.add(o.slice((l.domainSize+t)*g,(l.domainSize+t+1)*g),e[t]),(l.domainSize+t)*g),o.set(d.sub(o.slice(t*g,(t+1)*g),e[t]),t*g);return[o,await d.fft(i)]}}const{unstringifyBigInts:bn}=pa;const{unstringifyBigInts:yn}=pa,{keccak256:In}=mn;function Cn(t,e){const a=ha.fromRprBE(new Uint8Array(In.arrayBuffer(e)));return t.Fr.e(a)}const{unstringifyBigInts:Fn}=pa;function xn(t){return("0"+t.toString(16)).slice(-2)}function En(t){let e=t.toString(16);for(;e.length<64;)e="0"+e;return e=`"0x${e}"`,e}var Bn=Object.freeze({__proto__:null,setup:async function(t,e,a,i){globalThis.gc&&globalThis.gc(),await $a.exports.ready();const{fd:o,sections:n}=await Ua(e,"ptau",1),{curve:c,power:r}=await So(o,n),{fd:l,sections:s}=await Ua(t,"r1cs",1),d=await Yo(l,s,{loadConstraints:!0,loadCustomGates:!0}),u=2*c.G1.F.n8,g=c.G1,_=2*c.G2.F.n8,f=c.Fr,h=c.Fr.n8;i&&i.info("Reading r1cs"),await Da(l,s,2);const p=new rn,m=new rn;let L=d.nVars;const w=d.nOutputs+d.nPubInputs;await async function(t,e,a){function i(t){const e=Object.keys(t);for(let a=0;a<e.length;a++)0n==t[e[a]]&&delete t[e[a]]}function o(e,a,o){const n={};for(let i in e)void 0===n[i]?n[i]=t.mul(a,e[i]):n[i]=t.add(n[i],t.mul(a,e[i]));for(let e in o)void 0===n[e]?n[e]=o[e]:n[e]=t.add(n[e],o[e]);return i(n),n}function n(e,a){const i={k:t.zero,s:[],coefs:[]},o=[];for(let a in e)0==a?i.k=t.add(i.k,e[a]):0n!=e[a]&&o.push([Number(a),e[a]]);for(;o.length>a;){const e=o.shift(),a=o.shift(),i=e[0],n=a[0],c=L++,r=t.zero,l=t.neg(e[1]),s=t.neg(a[1]),d=t.one,u=t.zero;p.push([i,n,c,r,l,s,d,u]),m.push([i,n,e[1],a[1]]),o.push([c,t.one])}for(let t=0;t<o.length;t++)i.s[t]=o[t][0],i.coefs[t]=o[t][1];for(;i.coefs.length<a;)i.s.push(0),i.coefs.push(t.zero);return i}function c(e){const a=n(e,3),i=a.s[0],o=a.s[1],c=a.s[2],r=t.zero,l=a.coefs[0],s=a.coefs[1],d=a.coefs[2],u=a.k;p.push([i,o,c,r,l,s,d,u])}function r(e){let a=t.zero,i=0;const o=Object.keys(e);for(let n=0;n<o.length;n++)0n==e[o[n]]?delete e[o[n]]:0==o[n]?a=t.add(a,e[o[n]]):i++;return i>0?i.toString():a!=t.zero?"k":"0"}function l(e,a,l){const s=r(e),d=r(a);if("0"===s||"0"===d)i(l),c(l);else if("k"===s){c(o(a,e[0],l))}else if("k"===d){c(o(e,a[0],l))}else!function(e,a,i){const o=n(e,1),c=n(a,1),r=n(i,1),l=o.s[0],s=c.s[0],d=r.s[0],u=t.mul(o.coefs[0],c.coefs[0]),g=t.mul(o.coefs[0],c.k),_=t.mul(o.k,c.coefs[0]),f=t.neg(r.coefs[0]),h=t.sub(t.mul(o.k,c.k),r.k);p.push([l,s,d,u,g,_,f,h])}(e,a,l)}for(let e=1;e<=w;e++){const a=e,i=0,o=0,n=t.zero,c=t.one,r=t.zero,l=t.zero,s=t.zero;p.push([a,i,o,n,c,r,l,s])}for(let t=0;t<e.constraints.length;t++)a&&t%1e4==0&&a.debug(`processing constraints: ${t}/${e.nConstraints}`),l(...e.constraints[t])}(c.Fr,d,i),globalThis.gc&&globalThis.gc();const A=await Oa(a,"zkey",1,14,1<<22,1<<24);if(d.prime!=c.r)return i&&i.error("r1cs curve does not match powers of tau ceremony curve"),-1;let b=ki(p.length-1)+1;b<3&&(b=3);const y=2**b;if(i&&i.info("Plonk constraints: "+p.length),b>r)return i&&i.error(`circuit too big for this power of tau ceremony. ${p.length} > 2**${r}`),-1;if(!n[12])return i&&i.error("Powers of tau is not prepared."),-1;const I=new Pe(y*u),C=n[12][0].p+(2**b-1)*u;await o.readToBuffer(I,0,y*u,C);const[F,x]=function(){let t=f.two;for(;a(t,[],b);)f.add(t,f.one);let e=f.add(t,f.one);for(;a(e,[t],b);)f.add(e,f.one);return[t,e];function a(t,e,a){const i=2**a;let o=f.one;for(let n=0;n<i;n++){if(f.eq(t,o))return!0;for(let a=0;a<e.length;a++)if(f.eq(t,f.mul(e[a],o)))return!0;o=f.mul(o,f.w[a])}return!1}}(),E={};await async function(t,e){await za(A,t);const a=new Uint8Array(8+2*h),o=new DataView(a.buffer);for(let t=0;t<m.length;t++){const n=m[t];let c=0;o.setUint32(c,n[0],!0),c+=4,o.setUint32(c,n[1],!0),c+=4,a.set(n[2],c),c+=h,a.set(n[3],c),c+=h,await A.write(a),i&&t%1e6==0&&i.debug(`writing ${e}: ${t}/${m.length}`)}await Qa(A)}(3,"Additions"),globalThis.gc&&globalThis.gc(),await v(4,0,"Amap"),globalThis.gc&&globalThis.gc(),await v(5,1,"Bmap"),globalThis.gc&&globalThis.gc(),await v(6,2,"Cmap"),globalThis.gc&&globalThis.gc(),await S(7,3,"Qm"),globalThis.gc&&globalThis.gc(),await S(8,4,"Ql"),globalThis.gc&&globalThis.gc(),await S(9,5,"Qr"),globalThis.gc&&globalThis.gc(),await S(10,6,"Qo"),globalThis.gc&&globalThis.gc(),await S(11,7,"Qc"),globalThis.gc&&globalThis.gc(),await async function(t,e){const a=new Pe(h*y*3),o=new rn(L),n=new rn(L);let r=f.one;for(let t=0;t<y;t++)t<p.length?(u(p[t][0],t),u(p[t][1],y+t),u(p[t][2],2*y+t)):(u(0,t),u(0,y+t),u(0,2*y+t)),r=f.mul(r,f.w[b]),i&&t%1e6==0&&i.debug(`writing ${e} phase1: ${t}/${p.length}`);for(let t=0;t<L;t++)void 0!==n[t]?a.set(o[t],n[t]*h):console.log("Variable not used"),i&&t%1e6==0&&i.debug(`writing ${e} phase2: ${t}/${L}`);globalThis.gc&&globalThis.gc();await za(A,t);let l=a.slice(0,y*h);await G(l),globalThis.gc&&globalThis.gc();let s=a.slice(y*h,y*h*2);await G(s),globalThis.gc&&globalThis.gc();let d=a.slice(y*h*2,y*h*3);await G(d),globalThis.gc&&globalThis.gc();await Qa(A),l=await f.batchFromMontgomery(l),s=await f.batchFromMontgomery(s),d=await f.batchFromMontgomery(d),E.S1=await c.G1.multiExpAffine(I,l,i,"multiexp S1"),globalThis.gc&&globalThis.gc();E.S2=await c.G1.multiExpAffine(I,s,i,"multiexp S2"),globalThis.gc&&globalThis.gc();E.S3=await c.G1.multiExpAffine(I,d,i,"multiexp S3"),globalThis.gc&&globalThis.gc();function u(t,e){let i;void 0===o[t]?n[t]=e:a.set(o[t],e*h),i=e<y?r:e<2*y?f.mul(r,F):f.mul(r,x),o[t]=i}}(12,"sigma"),globalThis.gc&&globalThis.gc(),await async function(t,e){await za(A,t);const a=Math.max(w,1);for(let t=0;t<a;t++){let o=new Pe(y*h);o.set(f.one,t*h),await G(o),i&&i.debug(`writing ${e} ${t}/${a}`)}await Qa(A)}(13,"lagrange polynomials"),globalThis.gc&&globalThis.gc(),await za(A,14);const B=new Pe((y+6)*u);return await o.readToBuffer(B,0,(y+6)*u,n[2][0].p),await A.write(B),await Qa(A),globalThis.gc&&globalThis.gc(),await async function(){await za(A,1),await A.writeULE32(2),await Qa(A),await za(A,2);const t=c.q,e=8*(Math.floor((ha.bitLength(t)-1)/64)+1),a=c.r,i=8*(Math.floor((ha.bitLength(a)-1)/64)+1);let r;await A.writeULE32(e),await Ta(A,t,e),await A.writeULE32(i),await Ta(A,a,i),await A.writeULE32(L),await A.writeULE32(w),await A.writeULE32(y),await A.writeULE32(m.length),await A.writeULE32(p.length),await A.write(F),await A.write(x),await A.write(g.toAffine(E.Qm)),await A.write(g.toAffine(E.Ql)),await A.write(g.toAffine(E.Qr)),await A.write(g.toAffine(E.Qo)),await A.write(g.toAffine(E.Qc)),await A.write(g.toAffine(E.S1)),await A.write(g.toAffine(E.S2)),await A.write(g.toAffine(E.S3)),r=await o.read(_,n[3][0].p+_),await A.write(r),await Qa(A)}(),await A.close(),await l.close(),await o.close(),void(i&&i.info("Setup Finished"));async function v(t,e,a){await za(A,t);for(let t=0;t<p.length;t++)await A.writeULE32(p[t][e]),i&&t%1e6==0&&i.debug(`writing ${a}: ${t}/${p.length}`);await Qa(A)}async function S(t,e,a){let o=new Pe(y*h);for(let t=0;t<p.length;t++)o.set(p[t][e],t*h),i&&t%1e6==0&&i.debug(`writing ${a}: ${t}/${p.length}`);await za(A,t),await G(o),await Qa(A),o=await f.batchFromMontgomery(o),E[a]=await c.G1.multiExpAffine(I,o,i,"multiexp "+a)}async function G(t){const e=await f.ifft(t),a=new Pe(y*h*4);a.set(e,0);const i=await f.fft(a);await A.write(e),await A.write(i)}},fullProve:async function(t,e,a,i){const o=bn(t),n={type:"mem"};return await wo(o,e,n),await An(a,n,i)},prove:An,verify:async function(t,e,a,i){let o=yn(t),n=yn(a),c=yn(e);const r=await Ha(o.curve),l=r.Fr,s=r.G1;if(n=function(t,e){const a=t.G1,i=t.Fr,o={};return o.A=a.fromObject(e.A),o.B=a.fromObject(e.B),o.C=a.fromObject(e.C),o.Z=a.fromObject(e.Z),o.T1=a.fromObject(e.T1),o.T2=a.fromObject(e.T2),o.T3=a.fromObject(e.T3),o.eval_a=i.fromObject(e.eval_a),o.eval_b=i.fromObject(e.eval_b),o.eval_c=i.fromObject(e.eval_c),o.eval_zw=i.fromObject(e.eval_zw),o.eval_s1=i.fromObject(e.eval_s1),o.eval_s2=i.fromObject(e.eval_s2),o.eval_r=i.fromObject(e.eval_r),o.Wxi=a.fromObject(e.Wxi),o.Wxiw=a.fromObject(e.Wxiw),o}(r,n),o=function(t,e){const a=t.G1,i=t.G2,o=t.Fr,n=e;return n.Qm=a.fromObject(e.Qm),n.Ql=a.fromObject(e.Ql),n.Qr=a.fromObject(e.Qr),n.Qo=a.fromObject(e.Qo),n.Qc=a.fromObject(e.Qc),n.S1=a.fromObject(e.S1),n.S2=a.fromObject(e.S2),n.S3=a.fromObject(e.S3),n.k1=o.fromObject(e.k1),n.k2=o.fromObject(e.k2),n.X_2=i.fromObject(e.X_2),n}(r,o),!function(t,e){const a=t.G1;return!!a.isValid(e.A)&&(!!a.isValid(e.B)&&(!!a.isValid(e.C)&&(!!a.isValid(e.Z)&&(!!a.isValid(e.T1)&&(!!a.isValid(e.T2)&&(!!a.isValid(e.T3)&&(!!a.isValid(e.Wxi)&&!!a.isValid(e.Wxiw))))))))}(r,n))return i.error("Proof is not well constructed"),!1;if(c.length!=o.nPublic)return i.error("Invalid number of public inputs"),!1;const d=function(t,e,a){const i=t.G1,o=t.Fr,n=t.Fr.n8,c={},r=new Uint8Array(a.length*n+2*i.F.n8*3);for(let t=0;t<a.length;t++)o.toRprBE(r,t*n,o.e(a[t]));i.toRprUncompressed(r,a.length*n+0,e.A),i.toRprUncompressed(r,a.length*n+2*i.F.n8,e.B),i.toRprUncompressed(r,a.length*n+4*i.F.n8,e.C),c.beta=Cn(t,r);const l=new Uint8Array(n);o.toRprBE(l,0,c.beta),c.gamma=Cn(t,l);const s=new Uint8Array(2*i.F.n8);i.toRprUncompressed(s,0,e.Z),c.alpha=Cn(t,s);const d=new Uint8Array(2*i.F.n8*3);i.toRprUncompressed(d,0,e.T1),i.toRprUncompressed(d,2*i.F.n8,e.T2),i.toRprUncompressed(d,4*i.F.n8,e.T3),c.xi=Cn(t,d);const u=new Uint8Array(7*n);o.toRprBE(u,0,e.eval_a),o.toRprBE(u,n,e.eval_b),o.toRprBE(u,2*n,e.eval_c),o.toRprBE(u,3*n,e.eval_s1),o.toRprBE(u,4*n,e.eval_s2),o.toRprBE(u,5*n,e.eval_zw),o.toRprBE(u,6*n,e.eval_r),c.v=[],c.v[1]=Cn(t,u);for(let t=2;t<=6;t++)c.v[t]=o.mul(c.v[t-1],c.v[1]);const g=new Uint8Array(2*i.F.n8*2);return i.toRprUncompressed(g,0,e.Wxi),i.toRprUncompressed(g,2*i.F.n8,e.Wxiw),c.u=Cn(t,g),c}(r,n,c);i&&(i.debug("beta: "+l.toString(d.beta,16)),i.debug("gamma: "+l.toString(d.gamma,16)),i.debug("alpha: "+l.toString(d.alpha,16)),i.debug("xi: "+l.toString(d.xi,16)),i.debug("v1: "+l.toString(d.v[1],16)),i.debug("v6: "+l.toString(d.v[6],16)),i.debug("u: "+l.toString(d.u,16)));const u=function(t,e,a){const i=t.Fr;let o=e.xi,n=1;for(let t=0;t<a.power;t++)o=i.square(o),n*=2;e.xin=o,e.zh=i.sub(o,i.one);const c=[],r=i.e(n);let l=i.one;for(let t=1;t<=Math.max(1,a.nPublic);t++)c[t]=i.div(i.mul(l,e.zh),i.mul(r,i.sub(e.xi,l))),l=i.mul(l,i.w[a.power]);return c}(r,d,o);if(i){i.debug("Lagrange Evaluations: ");for(let t=1;t<u.length;t++)i.debug(`L${t}(xi)=`+l.toString(u[t],16))}if(c.length!=o.nPublic)return i.error("Number of public signals does not match with vk"),!1;const g=function(t,e,a){const i=t.Fr;let o=i.zero;for(let t=0;t<e.length;t++){const n=i.e(e[t]);o=i.sub(o,i.mul(n,a[t+1]))}return o}(r,c,u);i&&i.debug("Pl: "+l.toString(g,16));const _=function(t,e,a,i,o){const n=t.Fr;let c=e.eval_r;c=n.add(c,i);let r=e.eval_a;r=n.add(r,n.mul(a.beta,e.eval_s1)),r=n.add(r,a.gamma);let l=e.eval_b;l=n.add(l,n.mul(a.beta,e.eval_s2)),l=n.add(l,a.gamma);let s=e.eval_c;s=n.add(s,a.gamma);let d=n.mul(n.mul(r,l),s);d=n.mul(d,e.eval_zw),d=n.mul(d,a.alpha),c=n.sub(c,d),c=n.sub(c,n.mul(o,n.square(a.alpha)));return n.div(c,a.zh)}(r,n,d,g,u[1]);i&&i.debug("t: "+l.toString(_,16));const f=function(t,e,a,i,o){const n=t.G1,c=t.Fr;let r=c.mul(c.mul(e.eval_a,e.eval_b),a.v[1]),l=n.timesFr(i.Qm,r),s=c.mul(e.eval_a,a.v[1]);l=n.add(l,n.timesFr(i.Ql,s));let d=c.mul(e.eval_b,a.v[1]);l=n.add(l,n.timesFr(i.Qr,d));let u=c.mul(e.eval_c,a.v[1]);l=n.add(l,n.timesFr(i.Qo,u)),l=n.add(l,n.timesFr(i.Qc,a.v[1]));const g=c.mul(a.beta,a.xi);let _=e.eval_a;_=c.add(_,g),_=c.add(_,a.gamma);let f=e.eval_b;f=c.add(f,c.mul(g,i.k1)),f=c.add(f,a.gamma);let h=e.eval_c;h=c.add(h,c.mul(g,i.k2)),h=c.add(h,a.gamma);let p=c.mul(c.mul(_,f),h);p=c.mul(p,c.mul(a.alpha,a.v[1]));let m=c.mul(c.mul(o,c.square(a.alpha)),a.v[1]);p=c.add(p,m),p=c.add(p,a.u),l=n.add(l,n.timesFr(e.Z,p));let L=e.eval_a;L=c.add(L,c.mul(a.beta,e.eval_s1)),L=c.add(L,a.gamma);let w=e.eval_b;w=c.add(w,c.mul(a.beta,e.eval_s2)),w=c.add(w,a.gamma);let A=c.mul(L,w);return A=c.mul(A,a.alpha),A=c.mul(A,a.v[1]),A=c.mul(A,a.beta),A=c.mul(A,e.eval_zw),l=n.sub(l,n.timesFr(i.S3,A)),l}(r,n,d,o,u[1]);i&&i.debug("D: "+s.toString(s.toAffine(f),16));const h=function(t,e,a,i,o){const n=t.G1,c=t.Fr;let r=e.T1;return r=n.add(r,n.timesFr(e.T2,a.xin)),r=n.add(r,n.timesFr(e.T3,c.square(a.xin))),r=n.add(r,o),r=n.add(r,n.timesFr(e.A,a.v[2])),r=n.add(r,n.timesFr(e.B,a.v[3])),r=n.add(r,n.timesFr(e.C,a.v[4])),r=n.add(r,n.timesFr(i.S1,a.v[5])),r=n.add(r,n.timesFr(i.S2,a.v[6])),r}(r,n,d,o,f);i&&i.debug("F: "+s.toString(s.toAffine(h),16));const p=function(t,e,a,i,o){const n=t.G1,c=t.Fr;let r=o;r=c.add(r,c.mul(a.v[1],e.eval_r)),r=c.add(r,c.mul(a.v[2],e.eval_a)),r=c.add(r,c.mul(a.v[3],e.eval_b)),r=c.add(r,c.mul(a.v[4],e.eval_c)),r=c.add(r,c.mul(a.v[5],e.eval_s1)),r=c.add(r,c.mul(a.v[6],e.eval_s2)),r=c.add(r,c.mul(a.u,e.eval_zw));return n.timesFr(n.one,r)}(r,n,d,0,_);i&&i.debug("E: "+s.toString(s.toAffine(p),16));const m=await async function(t,e,a,i,o,n){const c=t.G1,r=t.Fr;let l=e.Wxi;l=c.add(l,c.timesFr(e.Wxiw,a.u));let s=c.timesFr(e.Wxi,a.xi);const d=r.mul(r.mul(a.u,a.xi),r.w[i.power]);s=c.add(s,c.timesFr(e.Wxiw,d)),s=c.add(s,n),s=c.sub(s,o);return await t.pairingEq(c.neg(l),i.X_2,s,t.G2.one)}(r,n,d,o,p,h);return i&&(m?i.info("OK!"):i.warn("Invalid Proof")),m},exportSolidityCallData:async function(t,e){const a=Fn(t),i=Fn(e),o=await Ha(a.curve),n=o.G1,c=o.Fr;let r="";for(let t=0;t<i.length;t++)""!=r&&(r+=","),r+=En(i[t]);const l=new Uint8Array(2*n.F.n8*9+7*c.n8);return n.toRprUncompressed(l,0,n.e(a.A)),n.toRprUncompressed(l,2*n.F.n8,n.e(a.B)),n.toRprUncompressed(l,4*n.F.n8,n.e(a.C)),n.toRprUncompressed(l,6*n.F.n8,n.e(a.Z)),n.toRprUncompressed(l,8*n.F.n8,n.e(a.T1)),n.toRprUncompressed(l,10*n.F.n8,n.e(a.T2)),n.toRprUncompressed(l,12*n.F.n8,n.e(a.T3)),n.toRprUncompressed(l,14*n.F.n8,n.e(a.Wxi)),n.toRprUncompressed(l,16*n.F.n8,n.e(a.Wxiw)),c.toRprBE(l,18*n.F.n8,c.e(a.eval_a)),c.toRprBE(l,18*n.F.n8+c.n8,c.e(a.eval_b)),c.toRprBE(l,18*n.F.n8+2*c.n8,c.e(a.eval_c)),c.toRprBE(l,18*n.F.n8+3*c.n8,c.e(a.eval_s1)),c.toRprBE(l,18*n.F.n8+4*c.n8,c.e(a.eval_s2)),c.toRprBE(l,18*n.F.n8+5*c.n8,c.e(a.eval_zw)),c.toRprBE(l,18*n.F.n8+6*c.n8,c.e(a.eval_r)),"0x"+Array.from(l).map(xn).join("")+",["+r+"]"}});return t.groth16=Co,t.plonk=Bn,t.powersOfTau=No,t.r1cs=Xo,t.wtns=an,t.zKey=fn,Object.defineProperty(t,"__esModule",{value:!0}),t}({});