1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[968],{17985:function(t,a,o){o.d(a,{FX:function(){return K},Ru:function(){return xo},qM:function(){return bo},utils:function(){return yo}});const e=[0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4];function i(t,a){return a&&10!=a?16==a?"0x"==t.slice(0,2)?BigInt(t):BigInt("0x"+t):void 0:BigInt(t)}const c=i;function l(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 s(t){return!t}function r(t,a){return BigInt(t)<<BigInt(a)}function d(t,a){return BigInt(t)>>BigInt(a)}const _=r,u=d;function g(t){return(BigInt(t)&BigInt(1))==BigInt(1)}function L(t){let a=BigInt(t);const o=[];for(;a;){if(a&BigInt(1)){const t=2-Number(a%BigInt(4));o.push(t),a-=BigInt(t)}else o.push(0);a>>=BigInt(1)}return o}function p(t){let a=BigInt(t);const o=[];for(;a;)a&BigInt(1)?o.push(1):o.push(0),a>>=BigInt(1);return o}function f(t){if(t>BigInt(Number.MAX_SAFE_INTEGER))throw new Error("Number too big");return Number(t)}function m(t,a){return BigInt(t)+BigInt(a)}function h(t,a){return BigInt(t)-BigInt(a)}function b(t){return-BigInt(t)}function x(t,a){return BigInt(t)*BigInt(a)}function y(t,a){return BigInt(t)**BigInt(a)}function F(t,a){return BigInt(t)/BigInt(a)}function C(t,a){return BigInt(t)%BigInt(a)}function B(t,a){return BigInt(t)==BigInt(a)}function P(t,a){return BigInt(t)>BigInt(a)}function A(t,a){return BigInt(t)>=BigInt(a)}function w(t,a){return BigInt(t)&BigInt(a)}function q(t,a,o,e){const i="0000000"+o.toString(16),c=new Uint32Array(t.buffer,t.byteOffset+a,e/4),l=1+(4*(i.length-7)-1>>5);for(let t=0;t<l;t++)c[t]=parseInt(i.substring(i.length-8*t-8,i.length-8*t),16);for(let t=l;t<c.length;t++)c[t]=0;for(let a=4*c.length;a<e;a++)t[a]=f(w(d(o,8*a),255))}function v(t,a,o,e){const i="0000000"+o.toString(16),c=new DataView(t.buffer,t.byteOffset+a,e),l=1+(4*(i.length-7)-1>>5);for(let t=0;t<l;t++)c.setUint32(e-4*t-4,parseInt(i.substring(i.length-8*t-8,i.length-8*t),16),!1);for(let t=0;t<e/4-l;t++)c[t]=0}function I(t,a,o){o=o||t.byteLength,a=a||0;const e=new Uint32Array(t.buffer,t.byteOffset+a,o/4),c=new Array(o/4);return e.forEach((t,a)=>c[c.length-a-1]=t.toString(16).padStart(8,"0")),i(c.join(""),16)}function O(t,a,o){o=o||t.byteLength,a=a||0;const e=new DataView(t.buffer,t.byteOffset+a,o),c=new Array(o/4);for(let t=0;t<o/4;t++)c[t]=e.getUint32(4*t,!1).toString(16).padStart(8,"0");return i(c.join(""),16)}function E(t,a){return t.toString(a)}function M(t){const a=new Uint8Array(Math.floor((l(t)-1)/8)+1);return q(a,0,t,a.byteLength),a}const S=c(0),z=c(1);var T=Object.freeze({__proto__:null,abs:function(t){return BigInt(t)>=0?BigInt(t):-BigInt(t)},add:m,band:w,bitLength:l,bits:p,bor:function(t,a){return BigInt(t)|BigInt(a)},bxor:function(t,a){return BigInt(t)^BigInt(a)},div:F,e:c,eq:B,exp:function(t,a){return BigInt(t)**BigInt(a)},fromArray:function(t,a){let o=BigInt(0);a=BigInt(a);for(let e=0;e<t.length;e++)o=o*a+BigInt(t[e]);return o},fromRprBE:O,fromRprLE:I,fromString:i,geq:A,gt:P,isNegative:n,isOdd:g,isZero:s,land:function(t,a){return BigInt(t)&&BigInt(a)},leq:function(t,a){return BigInt(t)<=BigInt(a)},lnot:function(t){return!BigInt(t)},lor:function(t,a){return BigInt(t)||BigInt(a)},lt:function(t,a){return BigInt(t)<BigInt(a)},mod:C,mul:x,naf:L,neg:b,neq:function(t,a){return BigInt(t)!=BigInt(a)},one:z,pow:y,shiftLeft:r,shiftRight:d,shl:_,shr:u,square:function(t){return BigInt(t)*BigInt(t)},sub:h,toArray:function(t,a){const o=[];let e=BigInt(t);for(a=BigInt(a);e;)o.unshift(Number(e%a)),e/=a;return o},toLEBuff:M,toNumber:f,toRprBE:v,toRprLE:q,toString:E,zero:S});const k=[];for(let t=0;t<256;t++)k[t]=G(t,8);function G(t,a){let o=0,e=t;for(let t=0;t<a;t++)o<<=1,o|=1&e,e>>=1;return o}function N(t,a,o){if(s(o))return t.one;const e=p(o);if(0==e.length)return t.one;let i=a;for(let o=e.length-2;o>=0;o--)i=t.square(i),e[o]&&(i=t.mul(i,a));return i}function R(t){if(t.m%2==1)if(B(C(t.p,4),1))if(B(C(t.p,8),1))if(B(C(t.p,16),1))!function(t){t.sqrt_q=y(t.p,t.m),t.sqrt_s=0,t.sqrt_t=h(t.sqrt_q,1);for(;!g(t.sqrt_t);)t.sqrt_s=t.sqrt_s+1,t.sqrt_t=F(t.sqrt_t,2);let a=t.one;for(;t.eq(a,t.one);){const o=t.random();t.sqrt_z=t.pow(o,t.sqrt_t),a=t.pow(t.sqrt_z,2**(t.sqrt_s-1))}t.sqrt_tm1d2=F(h(t.sqrt_t,1),2),t.sqrt=function(t){const a=this;if(a.isZero(t))return a.zero;let o=a.pow(t,a.sqrt_tm1d2);const e=a.pow(a.mul(a.square(o),t),2**(a.sqrt_s-1));if(a.eq(e,a.negone))return null;let i=a.sqrt_s,c=a.mul(t,o),l=a.mul(c,o),n=a.sqrt_z;for(;!a.eq(l,a.one);){let t=a.square(l),e=1;for(;!a.eq(t,a.one);)t=a.square(t),e++;o=n;for(let t=0;t<i-e-1;t++)o=a.square(o);n=a.square(o),l=a.mul(l,n),c=a.mul(c,o),i=e}return a.geq(c,a.zero)?c:a.neg(c)}}(t);else{if(!B(C(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(C(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(C(t.p,4),3)&&function(t){t.sqrt_q=y(t.p,t.m),t.sqrt_e1=F(h(t.sqrt_q,3),4),t.sqrt=function(a){if
1(this.isZero(a))return this.zero;const o=this.pow(a,this.sqrt_e1),e=this.mul(this.square(o),a);if(this.eq(e,this.negone))return null;const i=this.mul(o,a);return t.geq(i,t.zero)?i:t.neg(i)}}(t);else{const a=C(y(t.p,t.m/2),4);1==a?function(t){t.sqrt=function(){throw new Error("Sqrt alg 10 not implemented")}}(t):3==a?function(t){t.sqrt_q=y(t.p,t.m/2),t.sqrt_e34=F(h(t.sqrt_q,3),4),t.sqrt_e12=F(h(t.sqrt_q,1),2),t.frobenius=function(a,o){return a%2==1?t.conjugate(o):o},t.sqrt=function(t){const a=this,o=a.pow(t,a.sqrt_e34),e=a.mul(a.square(o),t),i=a.mul(a.frobenius(1,e),e);if(a.eq(i,a.negone))return null;const c=a.mul(o,t);let l;if(a.eq(e,a.negone))l=a.mul(c,[a.F.zero,a.F.one]);else{const t=a.pow(a.add(a.one,e),a.sqrt_e12);l=a.mul(t,c)}return a.geq(l,a.zero)?l:a.neg(l)}}(t):function(t){t.sqrt=function(){throw new Error("Sqrt alg 8 not implemented")}}(t)}}function j(t,a,o,e,i){t[a]=t[a]+t[o]>>>0,t[i]=(t[i]^t[a])>>>0,t[i]=(t[i]<<16|t[i]>>>16&65535)>>>0,t[e]=t[e]+t[i]>>>0,t[o]=(t[o]^t[e])>>>0,t[o]=(t[o]<<12|t[o]>>>20&4095)>>>0,t[a]=t[a]+t[o]>>>0,t[i]=(t[i]^t[a])>>>0,t[i]=(t[i]<<8|t[i]>>>24&255)>>>0,t[e]=t[e]+t[i]>>>0,t[o]=(t[o]^t[e])>>>0,t[o]=(t[o]<<7|t[o]>>>25&127)>>>0}function U(t){j(t,0,4,8,12),j(t,1,5,9,13),j(t,2,6,10,14),j(t,3,7,11,15),j(t,0,5,10,15),j(t,1,6,11,12),j(t,2,7,8,13),j(t,3,4,9,14)}class Z{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 m(x(this.nextU32(),4294967296),this.nextU32())}nextBool(){return!(1&~this.nextU32())}update(){for(let t=0;t<16;t++)this.buff[t]=this.state[t];for(let t=0;t<10;t++)U(this.buff);for(let t=0;t<16;t++)this.buff[t]=this.buff[t]+this.state[t]>>>0;this.idx=0,this.state[12]=this.state[12]+1>>>0,0==this.state[12]&&(this.state[13]=this.state[13]+1>>>0,0==this.state[13]&&(this.state[14]=this.state[14]+1>>>0,0==this.state[14]&&(this.state[15]=this.state[15]+1>>>0)))}}function $(t){let a=new Uint8Array(t);if(void 0!==globalThis.crypto)globalThis.crypto.getRandomValues(a);else for(let o=0;o<t;o++)a[o]=4294967296*Math.random()>>>0;return a}let Q=null;function J(){return Q||(Q=new Z(function(){const t=$(32),a=new Uint32Array(t.buffer),o=[];for(let t=0;t<8;t++)o.push(a[t]);return o}()),Q)}class D{constructor(t,a,o){this.F=a,this.G=t,this.opMulGF=o;let e=a.sqrt_t||a.t,i=a.sqrt_s||a.s,c=a.one;for(;a.eq(a.pow(c,a.half),a.one);)c=a.add(c,a.one);this.w=new Array(i+1),this.wi=new Array(i+1),this.w[i]=this.F.pow(c,e),this.wi[i]=this.F.inv(this.w[i]);let l=i-1;for(;l>=0;)this.w[l]=this.F.square(this.w[l+1]),this.wi[l]=this.F.square(this.wi[l+1]),l--;this.roots=[],this._setRoots(Math.min(i,15))}_setRoots(t){for(let a=t;a>=0&&!this.roots[a];a--){let t=this.F.one;const o=1<<a,e=new Array(o);for(let i=0;i<o;i++)e[i]=t,t=this.F.mul(t,this.w[a]);this.roots[a]=e}}fft(t){if(t.length<=1)return t;const a=W(t.length-1)+1;this._setRoots(a);const o=1<<a;if(t.length!=o)throw new Error("Size must be multiple of 2");return V(this,t,a,0,1)}ifft(t){if(t.length<=1)return t;const a=W(t.length-1)+1;this._setRoots(a);const o=1<<a;if(t.length!=o)throw new Error("Size must be multiple of 2");const e=V(this,t,a,0,1),i=this.F.inv(this.F.mulScalar(this.F.one,o)),c=new Array(o);for(let t=0;t<o;t++)c[t]=this.opMulGF(e[(o-t)%o],i);return c}}function W(t){return(4294901760&t?(t&=4294901760,16):0)|(4278255360&t?(t&=4278255360,8):0)|(4042322160&t?(t&=4042322160,4):0)|(3435973836&t?(t&=3435973836,2):0)|!!(2863311530&t)}function V(t,a,o,e,i){const c=1<<o;if(1==c)return[a[e]];if(2==c)return[t.G.add(a[e],a[e+i]),t.G.sub(a[e],a[e+i])];const l=c>>1,n=V(t,a,o-1,e,2*i),s=V(t,a,o-1,e+i,2*i),r=new Array(c);for(let a=0;a<l;a++)r[a]=t.G.add(n[a],t.opMulGF(s[a],t.roots[o][a])),r[a+l]=t.G.sub(n[a],t.opMulGF(s[a],t.roots[o][a]));return r}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=l(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 a=this.negone>>this.one;this.nqr=this.two;let o=this.pow(this.nqr,a);for(;!this.eq(o,this.negone);)this.nqr=this.nqr+this.one,o=this.pow(this.nqr,a);for(this.s=0,this.t=this.negone;(this.t&this.one)==this.zero;)this.s=this.s+1,this.t=this.t>>this.one;this.nqr_to_t=this.pow(this.nqr,this.t),R(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,a){let o;if(a?16==a&&(o=BigInt("0x"+t)):o=BigInt(t),o<0){let t=-o;return t>=this.p&&(t%=this.p),this.p-t}return o>=this.p?o%this.p:o}add(t,a){const o=t+a;return o>=this.p?o-this.p:o}sub(t,a){return t>=a?t-a:this.p-a+t}neg(t){return t?this.p-t:t}mul(t,a){return t*a%this.p}mulScalar(t,a){return t*this.e(a)%this.p}square(t){return t*t%this.p}eq(t,a){return t==a}neq(t,a){return t!=a}lt(t,a){return(t>this.half?t-this.p:t)<(a>this.half?a-this.p:a)}gt(t,a){return(t>this.half?t-this.p:t)>(a>this.half?a-this.p:a)}leq(t,a){return(t>this.half?t-this.p:t)<=(a>this.half?a-this.p:a)}geq(t,a){return(t>this.half?t-this.p:t)>=(a>this.half?a-this.p:a)}div(t,a){return this.mul(t,this.inv(a))}idiv(t,a){if(!a)throw new Error("Division by zero");return t/a}inv(t){if(!t)throw new Error("Division by zero");let a=this.zero,o=this.p,e=this.one,i=t%this.p;for(;i;){let t=o/i;[a,e]=[e,a-t*e],[o,i]=[i,o-t*i]}return a<this.zero&&(a+=this.p),a}mod(t,a){return t%a}pow(t,a){return N(this,t,a)}exp(t,a){return N(this,t,a)}band(t,a){const o=t&a&this.mask;return o>=this.p?o-this.p:o}bor(t,a){const o=(t|a)&this.mask;return o>=this.p?o-this.p:o}bxor(t,a){const o=(t^a)&this.mask;return o>=this.p?o-this.p:o}bnot(t){const a=t^this.mask;return a>=this.p?a-this.p:a}shl(t,a){if(Number(a)<this.bitLength){const o=t<<a&this.mask;return o>=this.p?o-this.p:o}{const o=this.p-a;return Number(o)<this.bitLength?t>>o:this.zero}}
1shr(t,a){if(Number(a)<this.bitLength)return t>>a;{const o=this.p-a;if(Number(o)<this.bitLength){const a=t<<o&this.mask;return a>=this.p?a-this.p:a}return 0}}land(t,a){return t&&a?this.one:this.zero}lor(t,a){return t||a?this.one:this.zero}lnot(t){return t?this.zero:this.one}sqrt_old(t){if(t==this.zero)return this.zero;if(this.pow(t,this.negone>>this.one)!=this.one)return null;let a=this.s,o=this.nqr_to_t,e=this.pow(t,this.t),i=this.pow(t,this.add(this.t,this.one)>>this.one);for(;e!=this.one;){let t=this.square(e),c=1;for(;t!=this.one;)c++,t=this.square(t);let l=o;for(let t=0;t<a-c-1;t++)l=this.square(l);a=c,o=this.square(l),e=this.mul(e,o),i=this.mul(i,l)}return i>this.p>>this.one&&(i=this.neg(i)),i}normalize(t,a){if((t=BigInt(t,a))<0){let a=-t;return a>=this.p&&(a%=this.p),this.p-a}return t>=this.p?t%this.p:t}random(){const t=2*this.bitLength/8;let a=this.zero;for(let o=0;o<t;o++)a=(a<<BigInt(8))+BigInt($(1)[0]);return a%this.p}toString(t,a){let o;if(a=a||10,t>this.half&&10==a){o="-"+(this.p-t).toString(a)}else o=t.toString(a);return o}isZero(t){return t==this.zero}fromRng(t){let a;do{a=this.zero;for(let o=0;o<this.n64;o++)a+=t.nextU64()<<BigInt(64*o);a&=this.mask}while(a>=this.p);return a=a*this.Ri%this.p,a}fft(t){return this.FFT.fft(t)}ifft(t){return this.FFT.ifft(t)}toRprLE(t,a,o){q(t,a,o,8*this.n64)}
1toRprBE(t,a,o){v(t,a,o,8*this.n64)}toRprBEM(t,a,o){return this.toRprBE(t,a,this.mul(this.R,o))}toRprLEM(t,a,o){return this.toRprLE(t,a,this.mul(this.R,o))}fromRprLE(t,a){return I(t,a,this.n8)}fromRprBE(t,a){return O(t,a,this.n8)}fromRprLEM(t,a){return this.mul(this.fromRprLE(t,a),this.Ri)}fromRprBEM(t,a){return this.mul(this.fromRprBE(t,a),this.Ri)}toObject(t){return t}}function X(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Y={bigInt2BytesLE:function(t,a){const o=Array(a);let e=BigInt(t);for(let t=0;t<a;t++)o[t]=Number(0xFFn&e),e>>=8n;return o},bigInt2U32LE:function(t,a){const o=Array(a);let e=BigInt(t);for(let t=0;t<a;t++)o[t]=Number(0xFFFFFFFFn&e),e>>=32n;return o},isOcamNum:function(t){return!!Array.isArray(t)&&(3==t.length&&("number"==typeof t[0]&&("number"==typeof t[1]&&!!Array.isArray(t[2]))))}},H=function(t,a,o,e,i,c,l){const n=t.addFunction(a);n.addParam("base","i32"),n.addParam("scalar","i32"),n.addParam("scalarLength","i32"),n.addParam("r","i32"),n.addLocal("i","i32"),n.addLocal("b","i32");const s=n.getCodeBuilder(),r=s.i32_const(t.alloc(o));n.addCode(s.if(s.i32_eqz(s.getLocal("scalarLength")),[...s.call(l,s.getLocal("r")),...s.ret([])])),n.addCode(s.call(c,s.getLocal("base"),r)),n.addCode(s.call(l,s.getLocal("r"))),n.addCode(s.setLocal("i",s.getLocal("scalarLength"))),n.addCode(s.block(s.loop(s.setLocal("i",s.i32_sub(s.getLocal("i"),s.i32_const(1))),s.setLocal("b",s.i32_load8_u(s.i32_add(s.getLocal("scalar"),s.getLocal("i")))),...function(){const t=[];for(let a=0;a<8;a++)t.push(...s.call(i,s.getLocal("r"),s.getLocal("r")),...s.if(s.i32_ge_u(s.getLocal("b"),s.i32_const(128>>a)),[...s.setLocal("b",s.i32_sub(s.getLocal("b"),s.i32_const(128>>a))),...s.call(e,s.getLocal("r"),r,s.getLocal("r"))]));return t}(),s.br_if(1,s.i32_eqz(s.getLocal("i"))),s.br(0))))},tt=function(t,a){const o=8*t.modules[a].n64,e=t.addFunction(a+"_batchInverse");e.addParam("pIn","i32"),e.addParam("inStep","i32"),e.addParam("n","i32"),e.addParam("pOut","i32"),e.addParam("outStep","i32"),e.addLocal("itAux","i32"),e.addLocal("itIn","i32"),e.addLocal("itOut","i32"),e.addLocal("i","i32");const i=e.getCodeBuilder(),c=i.i32_const(t.alloc(o));e.addCode(i.setLocal("itAux",i.i32_load(i.i32_const(0))),i.i32_store(i.i32_const(0),i.i32_add(i.getLocal("itAux"),i.i32_mul(i.i32_add(i.getLocal("n"),i.i32_const(1)),i.i32_const(o))))),e.addCode(i.call(a+"_one",i.getLocal("itAux")),i.setLocal("itIn",i.getLocal("pIn")),i.setLocal("itAux",i.i32_add(i.getLocal("itAux"),i.i32_const(o))),i.setLocal("i",i.i32_const(0)),i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("i"),i.getLocal("n"))),i.if(i.call(a+"_isZero",i.getLocal("itIn")),i.call(a+"_copy",i.i32_sub(i.getLocal("itAux"),i.i32_const(o)),i.getLocal("itAux")),i.call(a+"_mul",i.getLocal("itIn"),i.i32_sub(i.getLocal("itAux"),i.i32_const(o)),i.getLocal("itAux"))),i.setLocal("itIn",i.i32_add(i.getLocal("itIn"),i.getLocal("inStep"))),i.setLocal("itAux",i.i32_add(i.getLocal("itAux"),i.i32_const(o))),i.setLocal("i",i.i32_add(i.getLocal("i"),i.i32_const(1))),i.br(0))),i.setLocal("itIn",i.i32_sub(i.getLocal("itIn"),i.getLocal("inStep"))),i.setLocal("itAux",i.i32_sub(i.getLocal("itAux"),i.i32_const(o))),i.setLocal("itOut",i.i32_add(i.getLocal("pOut"),i.i32_mul(i.i32_sub(i.getLocal("n"),i.i32_const(1)),i.getLocal("outStep")))),i.call(a+"_inverse",i.getLocal("itAux"),i.getLocal("itAux")),i.block(i.loop(i.br_if(1,i.i32_eqz(i.getLocal("i"))),i.if(i.call(a+"_isZero",i.getLocal("itIn")),[...i.call(a+"_copy",i.getLocal("itAux"),i.i32_sub(i.getLocal("itAux"),i.i32_const(o))),...i.call(a+"_zero",i.getLocal("itOut"))],[...i.call(a+"_copy",i.i32_sub(i.getLocal("itAux"),i.i32_const(o)),c),...i.call(a+"_mul",i.getLocal("itAux"),i.getLocal("itIn"),i.i32_sub(i.getLocal("itAux"),i.i32_const(o))),...i.call(a+"_mul",i.getLocal("itAux"),c,i.getLocal("itOut"))]),i.setLocal("itIn",i.i32_sub(i.getLocal("itIn"),i.getLocal("inStep"))),i.setLocal("itOut",i.i32_sub(i.getLocal("itOut"),i.getLocal("outStep"))),i.setLocal("itAux",i.i32_sub(i.getLocal("itAux"),i.i32_const(o))),i.setLocal("i",i.i32_sub(i.getLocal("i"),i.i32_const(1))),i.br(0)))),e.addCode(i.i32_store(i.i32_const(0),i.getLocal("itAux")))};var at=function(t,a,o,e,i,c){void 0===c&&(c=e<i);const l=t.addFunction(a);l.addParam("pIn","i32"),l.addParam("n","i32"),l.addParam("pOut","i32"),l.addLocal("i","i32"),l.addLocal("itIn","i32"),l.addLocal("itOut","i32");const n=l.getCodeBuilder();c?l.addCode(n.setLocal("itIn",n.i32_add(n.getLocal("pIn"),n.i32_mul(n.i32_sub(n.getLocal("n"),n.i32_const(1)),n.i32_const(e)))
1),n.setLocal("itOut",n.i32_add(n.getLocal("pOut"),n.i32_mul(n.i32_sub(n.getLocal("n"),n.i32_const(1)),n.i32_const(i)))),n.setLocal("i",n.i32_const(0)),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("i"),n.getLocal("n"))),n.call(o,n.getLocal("itIn"),n.getLocal("itOut")),n.setLocal("itIn",n.i32_sub(n.getLocal("itIn"),n.i32_const(e))),n.setLocal("itOut",n.i32_sub(n.getLocal("itOut"),n.i32_const(i))),n.setLocal("i",n.i32_add(n.getLocal("i"),n.i32_const(1))),n.br(0)))):l.addCode(n.setLocal("itIn",n.getLocal("pIn")),n.setLocal("itOut",n.getLocal("pOut")),n.setLocal("i",n.i32_const(0)),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("i"),n.getLocal("n"))),n.call(o,n.getLocal("itIn"),n.getLocal("itOut")),n.setLocal("itIn",n.i32_add(n.getLocal("itIn"),n.i32_const(e))),n.setLocal("itOut",n.i32_add(n.getLocal("itOut"),n.i32_const(i))),n.setLocal("i",n.i32_add(n.getLocal("i"),n.i32_const(1))),n.br(0))))};var ot=function(t,a,o,e,i,c){void 0===c&&(c=e<i);const l=t.addFunction(a);l.addParam("pIn1","i32"),l.addParam("pIn2","i32"),l.addParam("n","i32"),l.addParam("pOut","i32"),l.addLocal("i","i32"),l.addLocal("itIn1","i32"),l.addLocal("itIn2","i32"),l.addLocal("itOut","i32");const n=l.getCodeBuilder();c?l.addCode(n.setLocal("itIn1",n.i32_add(n.getLocal("pIn1"),n.i32_mul(n.i32_sub(n.getLocal("n"),n.i32_const(1)),n.i32_const(e)))),n.setLocal("itIn2",n.i32_add(n.getLocal("pIn2"),n.i32_mul(n.i32_sub(n.getLocal("n"),n.i32_const(1)),n.i32_const(e)))),n.setLocal("itOut",n.i32_add(n.getLocal("pOut"),n.i32_mul(n.i32_sub(n.getLocal("n"),n.i32_const(1)),n.i32_const(i)))),n.setLocal("i",n.i32_const(0)),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("i"),n.getLocal("n"))),n.call(o,n.getLocal("itIn1"),n.getLocal("itIn2"),n.getLocal("itOut")),n.setLocal("itIn1",n.i32_sub(n.getLocal("itIn1"),n.i32_const(e))),n.setLocal("itIn2",n.i32_sub(n.getLocal("itIn2"),n.i32_const(e))),n.setLocal("itOut",n.i32_sub(n.getLocal("itOut"),n.i32_const(i))),n.setLocal("i",n.i32_add(n.getLocal("i"),n.i32_const(1))),n.br(0)))):l.addCode(n.setLocal("itIn1",n.getLocal("pIn1")),n.setLocal("itIn2",n.getLocal("pIn2")),n.setLocal("itOut",n.getLocal("pOut")),n.setLocal("i",n.i32_const(0)),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("i"),n.getLocal("n"))),n.call(o,n.getLocal("itIn1"),n.getLocal("itIn2"),n.getLocal("itOut")),n.setLocal("itIn1",n.i32_add(n.getLocal("itIn1"),n.i32_const(e))),n.setLocal("itIn2",n.i32_add(n.getLocal("itIn2"),n.i32_const(e))),n.setLocal("itOut",n.i32_add(n.getLocal("itOut"),n.i32_const(i))),n.setLocal("i",n.i32_add(n.getLocal("i"),n.i32_const(1))),n.br(0))))};var et={};function it(t,a){return t===a?0:t>a?1:-1}function ct(t){return t*t}function lt(t){return t%2n!=0n}function nt(t){return t%2n==0n}function st(t){return t<0n}function rt(t){return t>0n}function dt(t){return st(t)?t.toString(2).length-1:t.toString(2).length}function _t(t){return t<0n?-t:t}function ut(t){return 1n===_t(t)}function gt(t,a){for(var o,e,i,c=0n,l=1n,n=a,s=_t(t);0n!==s;)o=n/s,e=c,i=n,c=l,n=s,l=e-o*l,s=i-o*s;if(!ut(n))throw new Error(t.toString()+" and "+a.toString()+" are not co-prime");return-1===it(c,0n)&&(c+=a),st(t)?-c:c}function Lt(t,a,o){if(0n===o)throw new Error("Cannot take modPow with modulus 0");var e=1n,i=t%o;for(st(a)&&(a*=-1n,i=gt(i,o));rt(a);){if(0n===i)return 0n;lt(a)&&(e=e*i%o),a/=2n,i=ct(i)%o}return e}function pt(t,a){return 0n!==a&&(!!ut(a)||(0===function(t,a){return(t=t>=0n?t:-t)===(a=a>=0n?a:-a)?0:t>a?1:-1}(a,2n)?nt(t):t%a===0n))}function ft(t,a){for(var o,e,i,c=function(t){return t-1n}(t),l=c,n=0;nt(l);)l/=2n,n++;t:for(e=0;e<a.length;e++)if(!(t<a[e]||ut(i=Lt(BigInt(a[e]),l,t))||i===c)){for(o=n-1;0!=o;o--){if(ut(i=ct(i)%t))return!1;if(i===c)continue t}return!1}return!0}et.bitLength=dt,et.isOdd=lt,et.isNegative=st,et.abs=_t,et.isUnit=ut,et.compare=it,et.modInv=gt,et.modPow=Lt,et.isPrime=function(t){var a=function(t){var a=_t(t);return!ut(a)&&(2n===a||3n===a||5n===a||!(nt(a)||pt(a,3n)||pt(a,5n))&&(a<49n||void 0))}(t);if(void 0!==a)return a;var o=_t(t),e=dt(o);if(e<=64)return ft(o,[2,3,5,7,11,13,17,19,23,29,31,37]);for(var i=Math.log(2)*Number(e),c=Math.ceil(i),l=[],n=0;n<c;
1n++)l.push(BigInt(n+2));return ft(o,l)},et.square=ct;const mt=function(t,a,o){const e=o||"int";if(t.modules[e])return e;t.modules[e]={};const i=2*a,c=8*a;return function(){const o=t.addFunction(e+"_copy");o.addParam("px","i32"),o.addParam("pr","i32");const i=o.getCodeBuilder();for(let t=0;t<a;t++)o.addCode(i.i64_store(i.getLocal("pr"),8*t,i.i64_load(i.getLocal("px"),8*t)))}(),function(){const o=t.addFunction(e+"_zero");o.addParam("pr","i32");const i=o.getCodeBuilder();for(let t=0;t<a;t++)o.addCode(i.i64_store(i.getLocal("pr"),8*t,i.i64_const(0)))}(),function(){const o=t.addFunction(e+"_isZero");o.addParam("px","i32"),o.setReturnType("i32");const i=o.getCodeBuilder();o.addCode(function t(a){return 0==a?i.ret(i.i64_eqz(i.i64_load(i.getLocal("px")))):i.if(i.i64_eqz(i.i64_load(i.getLocal("px"),8*a)),t(a-1),i.ret(i.i32_const(0)))}(a-1)),o.addCode(i.ret(i.i32_const(0)))}(),function(){const o=t.addFunction(e+"_one");o.addParam("pr","i32");const i=o.getCodeBuilder();o.addCode(i.i64_store(i.getLocal("pr"),0,i.i64_const(1)));for(let t=1;t<a;t++)o.addCode(i.i64_store(i.getLocal("pr"),8*t,i.i64_const(0)))}(),function(){const o=t.addFunction(e+"_eq");o.addParam("px","i32"),o.addParam("py","i32"),o.setReturnType("i32");const i=o.getCodeBuilder();o.addCode(function t(a){return 0==a?i.ret(i.i64_eq(i.i64_load(i.getLocal("px")),i.i64_load(i.getLocal("py")))):i.if(i.i64_eq(i.i64_load(i.getLocal("px"),8*a),i.i64_load(i.getLocal("py"),8*a)),t(a-1),i.ret(i.i32_const(0)))}(a-1)),o.addCode(i.ret(i.i32_const(0)))}(),function(){const o=t.addFunction(e+"_gte");o.addParam("px","i32"),o.addParam("py","i32"),o.setReturnType("i32");const i=o.getCodeBuilder();o.addCode(function t(a){return 0==a?i.ret(i.i64_ge_u(i.i64_load(i.getLocal("px")),i.i64_load(i.getLocal("py")))):i.if(i.i64_lt_u(i.i64_load(i.getLocal("px"),8*a),i.i64_load(i.getLocal("py"),8*a)),i.ret(i.i32_const(0)),i.if(i.i64_gt_u(i.i64_load(i.getLocal("px"),8*a),i.i64_load(i.getLocal("py"),8*a)),i.ret(i.i32_const(1)),t(a-1)))}(a-1)),o.addCode(i.ret(i.i32_const(0)))}(),function(){const a=t.addFunction(e+"_add");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32"),a.setReturnType("i32"),a.addLocal("c","i64");const o=a.getCodeBuilder();a.addCode(o.setLocal("c",o.i64_add(o.i64_load32_u(o.getLocal("x")),o.i64_load32_u(o.getLocal("y"))))),a.addCode(o.i64_store32(o.getLocal("r"),o.getLocal("c")));for(let t=1;t<i;t++)a.addCode(o.setLocal("c",o.i64_add(o.i64_add(o.i64_load32_u(o.getLocal("x"),4*t),o.i64_load32_u(o.getLocal("y"),4*t)),o.i64_shr_u(o.getLocal("c"),o.i64_const(32))))),a.addCode(o.i64_store32(o.getLocal("r"),4*t,o.getLocal("c")));a.addCode(o.i32_wrap_i64(o.i64_shr_u(o.getLocal("c"),o.i64_const(32))))}(),function(){const a=t.addFunction(e+"_sub");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32"),a.setReturnType("i32"),a.addLocal("c","i64");const o=a.getCodeBuilder();a.addCode(o.setLocal("c",o.i64_sub(o.i64_load32_u(o.getLocal("x")),o.i64_load32_u(o.getLocal("y"))))),a.addCode(o.i64_store32(o.getLocal("r"),o.i64_and(o.getLocal("c"),o.i64_const("0xFFFFFFFF"))));for(let t=1;t<i;t++)a.addCode(o.setLocal("c",o.i64_add(o.i64_sub(o.i64_load32_u(o.getLocal("x"),4*t),o.i64_load32_u(o.getLocal("y"),4*t)),o.i64_shr_s(o.getLocal("c"),o.i64_const(32))))),a.addCode(o.i64_store32(o.getLocal("r"),4*t,o.i64_and(o.getLocal("c"),o.i64_const("0xFFFFFFFF"))));a.addCode(o.i32_wrap_i64(o.i64_shr_s(o.getLocal("c"),o.i64_const(32))))}(),function(){const a=t.addFunction(e+"_mul");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32"),a.addLocal("c0","i64"),a.addLocal("c1","i64");for(let t=0;t<i;t++)a.addLocal("x"+t,"i64"),a.addLocal("y"+t,"i64");const o=a.getCodeBuilder(),c=[],l=[];function n(t,a){let e,i;return c[t]?e=o.getLocal("x"+t):(e=o.teeLocal("x"+t,o.i64_load32_u(o.getLocal("x"),4*t)),c[t]=!0),l[a]?i=o.getLocal("y"+a):(i=o.teeLocal("y"+a,o.i64_load32_u(o.getLocal("y"),4*a)),l[a]=!0),o.i64_mul(e,i)}let s="c0",r="c1";for(let t=0;t<2*i-1;t++){for(let e=Math.max(0,t-i+1);e<=t&&e<i;e++){const i=t-e;a.addCode(o.setLocal(s,o.i64_add(o.i64_and(o.getLocal(s),o.i64_const(4294967295)),n(e,i)))),a.addCode(o.set
1Local(r,o.i64_add(o.getLocal(r),o.i64_shr_u(o.getLocal(s),o.i64_const(32)))))}a.addCode(o.i64_store32(o.getLocal("r"),4*t,o.getLocal(s))),[s,r]=[r,s],a.addCode(o.setLocal(r,o.i64_shr_u(o.getLocal(s),o.i64_const(32))))}a.addCode(o.i64_store32(o.getLocal("r"),4*i*2-4,o.getLocal(s)))}(),function(){const a=t.addFunction(e+"_square");a.addParam("x","i32"),a.addParam("r","i32"),a.addLocal("c0","i64"),a.addLocal("c1","i64"),a.addLocal("c0_old","i64"),a.addLocal("c1_old","i64");for(let t=0;t<i;t++)a.addLocal("x"+t,"i64");const o=a.getCodeBuilder(),c=[];function l(t,a){let e,i;return c[t]?e=o.getLocal("x"+t):(e=o.teeLocal("x"+t,o.i64_load32_u(o.getLocal("x"),4*t)),c[t]=!0),c[a]?i=o.getLocal("x"+a):(i=o.teeLocal("x"+a,o.i64_load32_u(o.getLocal("x"),4*a)),c[a]=!0),o.i64_mul(e,i)}let n="c0",s="c1",r="c0_old",d="c1_old";for(let t=0;t<2*i-1;t++){a.addCode(o.setLocal(n,o.i64_const(0)),o.setLocal(s,o.i64_const(0)));for(let e=Math.max(0,t-i+1);e<t+1>>1&&e<i;e++){const i=t-e;a.addCode(o.setLocal(n,o.i64_add(o.i64_and(o.getLocal(n),o.i64_const(4294967295)),l(e,i)))),a.addCode(o.setLocal(s,o.i64_add(o.getLocal(s),o.i64_shr_u(o.getLocal(n),o.i64_const(32)))))}a.addCode(o.setLocal(n,o.i64_shl(o.i64_and(o.getLocal(n),o.i64_const(4294967295)),o.i64_const(1)))),a.addCode(o.setLocal(s,o.i64_add(o.i64_shl(o.getLocal(s),o.i64_const(1)),o.i64_shr_u(o.getLocal(n),o.i64_const(32))))),t%2==0&&(a.addCode(o.setLocal(n,o.i64_add(o.i64_and(o.getLocal(n),o.i64_const(4294967295)),l(t>>1,t>>1)))),a.addCode(o.setLocal(s,o.i64_add(o.getLocal(s),o.i64_shr_u(o.getLocal(n),o.i64_const(32)))))),t>0&&(a.addCode(o.setLocal(n,o.i64_add(o.i64_and(o.getLocal(n),o.i64_const(4294967295)),o.i64_and(o.getLocal(r),o.i64_const(4294967295))))),a.addCode(o.setLocal(s,o.i64_add(o.i64_add(o.getLocal(s),o.i64_shr_u(o.getLocal(n),o.i64_const(32))),o.getLocal(d))))),a.addCode(o.i64_store32(o.getLocal("r"),4*t,o.getLocal(n))),a.addCode(o.setLocal(r,o.getLocal(s)),o.setLocal(d,o.i64_shr_u(o.getLocal(r),o.i64_const(32))))}a.addCode(o.i64_store32(o.getLocal("r"),4*i*2-4,o.getLocal(r)))}(),function(){const a=t.addFunction(e+"_squareOld");a.addParam("x","i32"),a.addParam("r","i32");const o=a.getCodeBuilder();a.addCode(o.call(e+"_mul",o.getLocal("x"),o.getLocal("x"),o.getLocal("r")))}(),function(){!function(){const a=t.addFunction(e+"__mul1");a.addParam("px","i32"),a.addParam("y","i64"),a.addParam("pr","i32"),a.addLocal("c","i64");const o=a.getCodeBuilder();a.addCode(o.setLocal("c",o.i64_mul(o.i64_load32_u(o.getLocal("px"),0,0),o.getLocal("y")))),a.addCode(o.i64_store32(o.getLocal("pr"),0,0,o.getLocal("c")));for(let t=1;t<i;t++)a.addCode(o.setLocal("c",o.i64_add(o.i64_mul(o.i64_load32_u(o.getLocal("px"),4*t,0),o.getLocal("y")),o.i64_shr_u(o.getLocal("c"),o.i64_const(32))))),a.addCode(o.i64_store32(o.getLocal("pr"),4*t,0,o.getLocal("c")))}(),function(){const a=t.addFunction(e+"__add1");a.addParam("x","i32"),a.addParam("y","i64"),a.addLocal("c","i64"),a.addLocal("px","i32");const o=a.getCodeBuilder();a.addCode(o.setLocal("px",o.getLocal("x"))),a.addCode(o.setLocal("c",o.i64_add(o.i64_load32_u(o.getLocal("px"),0,0),o.getLocal("y")))),a.addCode(o.i64_store32(o.getLocal("px"),0,0,o.getLocal("c"))),a.addCode(o.setLocal("c",o.i64_shr_u(o.getLocal("c"),o.i64_const(32)))),a.addCode(o.block(o.loop(o.br_if(1,o.i64_eqz(o.getLocal("c"))),o.setLocal("px",o.i32_add(o.getLocal("px"),o.i32_const(4))),o.setLocal("c",o.i64_add(o.i64_load32_u(o.getLocal("px"),0,0),o.getLocal("c"))),o.i64_store32(o.getLocal("px"),0,0,o.getLocal("c")),o.setLocal("c",o.i64_shr_u(o.getLocal("c"),o.i64_const(32))),o.br(0))))}();const a=t.addFunction(e+"_div");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("c","i32"),a.addParam("r","i32"),a.addLocal("rr","i32"),a.addLocal("cc","i32"),a.addLocal("eX","i32"),a.addLocal("eY","i32"),a.addLocal("sy","i64"),a.addLocal("sx","i64"),a.addLocal("ec","i32");const o=a.getCodeBuilder(),l=o.i32_const(t.alloc(c)),n=o.i32_const(t.alloc(c)),s=o.i32_const(t.alloc(c)),r=o.getLocal("cc"),d=o.getLocal("rr"),_=t.alloc(2*c),u=o.i32_const(_),g=o.i32_const(_+c);a.addCode(o.if(o.getLocal("c"),o.setLocal("cc",o.getLocal("c")),o.setLocal("cc",n))),a.addCode(o.if(o.getLocal("r"),o.setLocal("rr",o.getLocal("r")),o.setLocal("rr",s))),a.addCode(o.call(e+"_copy",o.getLocal("x"),d)),a.addCode(o.call(e+"_copy",o.getLocal("y"),l)),a.addCode(o.call(e+"_zero",r)),a.addCode(o.call(e+"_zero",u)),a.addCode(o.set
1Local("eX",o.i32_const(c-1))),a.addCode(o.setLocal("eY",o.i32_const(c-1))),a.addCode(o.block(o.loop(o.br_if(1,o.i32_or(o.i32_load8_u(o.i32_add(l,o.getLocal("eY")),0,0),o.i32_eq(o.getLocal("eY"),o.i32_const(3)))),o.setLocal("eY",o.i32_sub(o.getLocal("eY"),o.i32_const(1))),o.br(0)))),a.addCode(o.setLocal("sy",o.i64_add(o.i64_load32_u(o.i32_sub(o.i32_add(l,o.getLocal("eY")),o.i32_const(3)),0,0),o.i64_const(1)))),a.addCode(o.if(o.i64_eq(o.getLocal("sy"),o.i64_const(1)),o.drop(o.i64_div_u(o.i64_const(0),o.i64_const(0))))),a.addCode(o.block(o.loop(o.block(o.loop(o.br_if(1,o.i32_or(o.i32_load8_u(o.i32_add(d,o.getLocal("eX")),0,0),o.i32_eq(o.getLocal("eX"),o.i32_const(7)))),o.setLocal("eX",o.i32_sub(o.getLocal("eX"),o.i32_const(1))),o.br(0))),o.setLocal("sx",o.i64_load(o.i32_sub(o.i32_add(d,o.getLocal("eX")),o.i32_const(7)),0,0)),o.setLocal("sx",o.i64_div_u(o.getLocal("sx"),o.getLocal("sy"))),o.setLocal("ec",o.i32_sub(o.i32_sub(o.getLocal("eX"),o.getLocal("eY")),o.i32_const(4))),o.block(o.loop(o.br_if(1,o.i32_and(o.i64_eqz(o.i64_and(o.getLocal("sx"),o.i64_const("0xFFFFFFFF00000000"))),o.i32_ge_s(o.getLocal("ec"),o.i32_const(0)))),o.setLocal("sx",o.i64_shr_u(o.getLocal("sx"),o.i64_const(8))),o.setLocal("ec",o.i32_add(o.getLocal("ec"),o.i32_const(1))),o.br(0))),o.if(o.i64_eqz(o.getLocal("sx")),[...o.br_if(2,o.i32_eqz(o.call(e+"_gte",d,l))),...o.setLocal("sx",o.i64_const(1)),...o.setLocal("ec",o.i32_const(0))]),o.call(e+"__mul1",l,o.getLocal("sx"),g),o.drop(o.call(e+"_sub",d,o.i32_sub(g,o.getLocal("ec")),d)),o.call(e+"__add1",o.i32_add(r,o.getLocal("ec")),o.getLocal("sx")),o.br(0))))}(),function(){const a=t.addFunction(e+"_inverseMod");a.addParam("px","i32"),a.addParam("pm","i32"),a.addParam("pr","i32"),a.addLocal("t","i32"),a.addLocal("newt","
1i32"),a.addLocal("r","i32"),a.addLocal("qq","i32"),a.addLocal("qr","i32"),a.addLocal("newr","i32"),a.addLocal("swp","i32"),a.addLocal("x","i32"),a.addLocal("signt","i32"),a.addLocal("signnewt","i32"),a.addLocal("signx","i32");const o=a.getCodeBuilder(),i=o.i32_const(t.alloc(c)),l=o.i32_const(t.alloc(c)),n=o.i32_const(t.alloc(c)),s=o.i32_const(t.alloc(c)),r=o.i32_const(t.alloc(c)),d=o.i32_const(t.alloc(c)),_=o.i32_const(t.alloc(2*c)),u=o.i32_const(t.alloc(c));a.addCode(o.setLocal("t",i),o.call(e+"_zero",i),o.setLocal("signt",o.i32_const(0))),a.addCode(o.setLocal("r",l),o.call(e+"_copy",o.getLocal("pm"),l)),a.addCode(o.setLocal("newt",n),o.call(e+"_one",n),o.setLocal("signnewt",o.i32_const(0))),a.addCode(o.setLocal("newr",s),o.call(e+"_copy",o.getLocal("px"),s)),a.addCode(o.setLocal("qq",r)),a.addCode(o.setLocal("qr",d)),a.addCode(o.setLocal("x",u)),a.addCode(o.block(o.loop(o.br_if(1,o.call(e+"_isZero",o.getLocal("newr"))),o.call(e+"_div",o.getLocal("r"),o.getLocal("newr"),o.getLocal("qq"),o.getLocal("qr")),o.call(e+"_mul",o.getLocal("qq"),o.getLocal("newt"),_),o.if(o.getLocal("signt"),o.if(o.getLocal("signnewt"),o.if(o.call(e+"_gte",_,o.getLocal("t")),[...o.drop(o.call(e+"_sub",_,o.getLocal("t"),o.getL
1ocal("x"))),...o.setLocal("signx",o.i32_const(0))],[...o.drop(o.call(e+"_sub",o.getLocal("t"),_,o.getLocal("x"))),...o.setLocal("signx",o.i32_const(1))]),[...o.drop(o.call(e+"_add",_,o.getLocal("t"),o.getLocal("x"))),...o.setLocal("signx",o.i32_const(1))]),o.if(o.getLocal("signnewt"),[...o.drop(o.call(e+"_add",_,o.getLocal("t"),o.getLocal("x"))),...o.setLocal("signx",o.i32_const(0))],o.if(o.call(e+"_gte",o.getLocal("t"),_),[...o.drop(o.call(e+"_sub",o.getLocal("t"),_,o.getLocal("x"))),...o.setLocal("signx",o.i32_const(0))],[...o.drop(o.call(e+"_sub",_,o.getLocal("t"),o.getLocal("x"))),...o.setLocal("signx",o.i32_const(1))]))),o.setLocal("swp",o.getLocal("t")),o.setLocal("t",o.getLocal("newt")),o.setLocal("newt",o.getLocal("x")),o.setLocal("x",o.getLocal("swp")),o.setLocal("signt",o.getLocal("signnewt")),o.setLocal("signnewt",o.getLocal("signx")),o.setLocal("swp",o.getLocal("r")),o.setLocal("r",o.getLocal("newr")),o.setLocal("newr",o.getLocal("qr")),o.setLocal("qr",o.getLocal("swp")),o.br(0)))),a.addCode(o.if(o.getLocal("signt"),o.drop(o.call(e+"_sub",o.getLocal("pm"),o.getLocal("t"),o.getL
1ocal("pr"))),o.call(e+"_copy",o.getLocal("t"),o.getLocal("pr"))))}(),t.exportFunction(e+"_copy"),t.exportFunction(e+"_zero"),t.exportFunction(e+"_one"),t.exportFunction(e+"_isZero"),t.exportFunction(e+"_eq"),t.exportFunction(e+"_gte"),t.exportFunction(e+"_add"),t.exportFunction(e+"_sub"),t.exportFunction(e+"_mul"),t.exportFunction(e+"_square"),t.exportFunction(e+"_squareOld"),t.exportFunction(e+"_div"),t.exportFunction(e+"_inverseMod"),e},ht=Y,bt=H,xt=tt,yt=at,Ft=ot,{bitLength:Ct,modInv:Bt,modPow:Pt,isPrime:At,isOdd:wt,square:qt}=et;var vt=function(t,a,o,e){const i=BigInt(a),c=Math.floor((Ct(i-1n)-1)/64)+1,l=2*c,n=8*c,s=o||"f1m";if(t.modules[s])return s;const r=mt(t,c,e),d=t.alloc(n,ht.bigInt2BytesLE(i,n)),_=t.alloc(ht.bigInt2BytesLE(qt(1n<<BigInt(64*c))%i,n)),u=t.alloc(ht.bigInt2BytesLE((1n<<BigInt(64*c))%i,n)),g=t.alloc(ht.bigInt2BytesLE(0n,n)),L=i-1n,p=L>>1n,f=t.alloc(n,ht.bigInt2BytesLE(p,n)),m=p+1n,h=t.alloc(n,ht.bigInt2BytesLE(m,n));t.modules[s]={pq:d,pR2:_,n64:c,q:i,pOne:u,pZero:g,pePlusOne:h};let b=2n;if(At(i))for(;Pt(b,p,i)!==L;)b+=1n;let x=0,y=L;for(;!wt(y)&&0n!==y;)x++,y>>=1n;const F=t.alloc(n,ht.bigInt2BytesLE(y,n)),C=Pt(b,y,i),B=t.alloc(ht.bigInt2BytesLE((C<<BigInt(64*c))%i,n)),P=y+1n>>1n,A=t.alloc(n,ht.bigInt2BytesLE(P,n));return t.exportFunction(r+"_copy",s+"_copy"),t.exportFunction(r+"_zero",s+"_zero"),t.exportFunction(r+"_isZero",s+"_isZero"),t.exportFunction(r+"_eq",s+"_eq"),function(){const a=t.addFunction(s+"_isOne");a.addParam("x","i32"),a.setReturnType("i32");const o=a.getCodeBuilder();a.addCode(o.ret(o.call(r+"_eq",o.getLocal("x"),o.i32_const(u))))}(),function(){const a=t.addFunction(s+"_add");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const o=a.getCodeBuilder();a.addCode(o.if(o.call(r+"_add",o.getLocal("x"),o.getLocal("y"),o.getLocal("r")),o.drop(o.call(r+"_sub",o.getLocal("r"),o.i32_const(d),o.getLocal("r"))),o.if(o.call(r+"_gte",o.getLocal("r"),o.i32_const(d)),o.drop(o.call(r+"_sub",o.getLocal("r"),o.i32_const(d),o.getLocal("r"))))))}(),function(){const a=t.addFunction(s+"_sub");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const o=a.getCodeBuilder();a.addCode(o.if(o.call(r+"_sub",o.getLocal("x"),o.getLocal("y"),o.getLocal("r")),o.drop(o.call(r+"_add",o.getLocal("r"),o.i32_const(d),o.getLocal("r")))))}(),function(){const a=t.addFunction(s+"_neg");a.addParam("x","i32"),a.addParam("r","i32");const o=a.getCodeBuilder();a.addCode(o.call(s+"_sub",o.i32_const(g),o.getLocal("x"),o.getLocal("r")))}(),function(){const a=t.alloc(l*l*8),o=t.addFunction(s+"_mReduct");o.addParam("t","i32"),o.addParam("r","i32"),o.addLocal("np32","i64"),o.addLocal("c","i64"),o.addLocal("m","i64");const e=o.getCodeBuilder(),c=Number(0x100000000n-Bt(i,0x100000000n));o.addCode(e.setLocal("np32",e.i64_const(c)));for(let t=0;t<l;t++){o.addCode(e.setLocal("c",e.i64_const(0))),o.addCode(e.setLocal("m",e.i64_and(e.i64_mul(e.i64_load32_u(e.getLocal("t"),4*t),e.getLocal("np32")),e.i64_const("0xFFFFFFFF"))));for(let a=0;a<l;a++)o.addCode(e.setLocal("c",e.i64_add(e.i64_add(e.i64_load32_u(e.getLocal("t"),4*(t+a)),e.i64_shr_u(e.getLocal("c"),e.i64_const(32))),e.i64_mul(e.i64_load32_u(e.i32_const(d),4*a),e.getLocal("m"))))),o.addCode(e.i64_store32(e.getLocal("t"),4*(t+a),e.getLocal("c")));o.addCode(e.i64_store32(e.i32_const(a),4*t,e.i64_shr_u(e.getLocal("c"),e.i64_const(32))))}o.addCode(e.call(s+"_add",e.i32_const(a),e.i32_add(e.getLocal("t"),e.i32_const(4*l)),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_mul");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32"),a.addLocal("c0","i64"),a.addLocal("c1","i64"),a.addLocal("np32","i64");for(let t=0;t<l;t++)a.addLocal("x"+t,"i64"),a.addLocal("y"+t,"i64"),a.addLocal("m"+t,"i64"),a.addLocal("q"+t,"i64");const o=a.getCodeBuilder(),e=Number(0x100000000n-Bt(i,0x100000000n));a.addCode(o.setLocal("np32",o.i64_const(e)));const c=[],n=[],_=[];function u(t,a){let e,i;return c[t]?e=o.getLocal("x"+t):(e=o.teeLocal("x"+t,o.i64_load32_u(o.getLocal("x"),4*t)),c[t]=!0),n[a]?i=o.getLocal("y"+a):(i=o.teeLocal("y"+a,o.i64_load32_u(o.getLocal("y"),4*a)),n[a]=!0),o.i64_mul(e,i)}function g(t,a){let e,i;return _[t]?e=o.getLocal("q"+t):(e=o.teeLocal("q"+t,o.i64_load32_u(o.i32_const(0),d+4*t)),_[t]=!0),i=o.getLocal("m"+a),o.i64_mul(e,i)}let L="c0",p="c1";for(let t=0;t<2*l-1;t++){for(let e=Math.max(0,t-l+1);e<=t&&e<l;e++){const i=t-e;
1a.addCode(o.setLocal(L,o.i64_add(o.i64_and(o.getLocal(L),o.i64_const(4294967295)),u(e,i)))),a.addCode(o.setLocal(p,o.i64_add(o.getLocal(p),o.i64_shr_u(o.getLocal(L),o.i64_const(32)))))}for(let e=Math.max(1,t-l+1);e<=t&&e<l;e++){const i=t-e;a.addCode(o.setLocal(L,o.i64_add(o.i64_and(o.getLocal(L),o.i64_const(4294967295)),g(e,i)))),a.addCode(o.setLocal(p,o.i64_add(o.getLocal(p),o.i64_shr_u(o.getLocal(L),o.i64_const(32)))))}t<l&&(a.addCode(o.setLocal("m"+t,o.i64_and(o.i64_mul(o.i64_and(o.getLocal(L),o.i64_const(4294967295)),o.getLocal("np32")),o.i64_const("0xFFFFFFFF")))),a.addCode(o.setLocal(L,o.i64_add(o.i64_and(o.getLocal(L),o.i64_const(4294967295)),g(0,t)))),a.addCode(o.setLocal(p,o.i64_add(o.getLocal(p),o.i64_shr_u(o.getLocal(L),o.i64_const(32)))))),t>=l&&a.addCode(o.i64_store32(o.getLocal("r"),4*(t-l),o.getLocal(L))),[L,p]=[p,L],a.addCode(o.setLocal(p,o.i64_shr_u(o.getLocal(L),o.i64_const(32))))}a.addCode(o.i64_store32(o.getLocal("r"),4*l-4,o.getLocal(L))),a.addCode(o.if(o.i32_wrap_i64(o.getLocal(p)),o.drop(o.call(r+"_sub",o.getLocal("r"),o.i32_const(d),o.getLocal("r"))),o.if(o.call(r+"_gte",o.getLocal("r"),o.i32_const(d)),o.drop(o.call(r+"_sub",o.getLocal("r"),o.i32_const(d),o.getLocal("r"))))))}(),function(){const a=t.addFunction(s+"_square");a.addParam("x","i32"),a.addParam("r","i32"),a.addLocal("c0","i64"),a.addLocal("c1","i64"),a.addLocal("c0_old","i64"),a.addLocal("c1_old","i64"),a.addLocal("np32","i64");for(let t=0;t<l;t++)a.addLocal("x"+t,"i64"),a.addLocal("m"+t,"i64"),a.addLocal("q"+t,"i64");const o=a.getCodeBuilder(),e=Number(0x100000000n-Bt(i,0x100000000n));a.addCode(o.setLocal("np32",o.i64_const(e)));const c=[],n=[];function _(t,a){let e,i;return c[t]?e=o.getLocal("x"+t):(e=o.teeLocal("x"+t,o.i64_load32_u(o.getLocal("x"),4*t)),c[t]=!0),c[a]?i=o.getLocal("x"+a):(i=o.teeLocal("x"+a,o.i64_load32_u(o.getLocal("x"),4*a)),c[a]=!0),o.i64_mul(e,i)}function u(t,a){let e,i;return n[t]?e=o.getLocal("q"+t):(e=o.teeLocal("q"+t,o.i64_load32_u(o.i32_const(0),d+4*t)),n[t]=!0),i=o.getLocal("m"+a),o.i64_mul(e,i)}let g="c0",L="c1",p="c0_old",f="c1_old";for(let t=0;t<2*l-1;t++){a.addCode(o.setLocal(g,o.i64_const(0)),o.setLocal(L,o.i64_const(0)));for(let e=Math.max(0,t-l+1);e<t+1>>1&&e<l;e++){const i=t-e;a.addCode(o.setLocal(g,o.i64_add(o.i64_and(o.getLocal(g),o.i64_const(4294967295)),_(e,i)))),a.addCode(o.setLocal(L,o.i64_add(o.getLocal(L),o.i64_shr_u(o.getLocal(g),o.i64_const(32)))))}a.addCode(o.setLocal(g,o.i64_shl(o.i64_and(o.getLocal(g),o.i64_const(4294967295)),o.i64_const(1)))),a.addCode(o.setLocal(L,o.i64_add(o.i64_shl(o.getLocal(L),o.i64_const(1)),o.i64_shr_u(o.getLocal(g),o.i64_const(32))))),t%2==0&&(a.addCode(o.setLocal(g,o.i64_add(o.i64_and(o.getLocal(g),o.i64_const(4294967295)),_(t>>1,t>>1)))),a.addCode(o.setLocal(L,o.i64_add(o.getLocal(L),o.i64_shr_u(o.getLocal(g),o.i64_const(32)))))),t>0&&(a.addCode(o.setLocal(g,o.i64_add(o.i64_and(o.getLocal(g),o.i64_const(4294967295)),o.i64_and(o.getLocal(p),o.i64_const(4294967295))))),a.addCode(o.setLocal(L,o.i64_add(o.i64_add(o.getLocal(L),o.i64_shr_u(o.getLocal(g),o.i64_const(32))),o.getLocal(f)))));for(let e=Math.max(1,t-l+1);e<=t&&e<l;e++){const i=t-e;a.addCode(o.setLocal(g,o.i64_add(o.i64_and(o.getLocal(g),o.i64_const(4294967295)),u(e,i)))),a.addCode(o.setLocal(L,o.i64_add(o.getLocal(L),o.i64_shr_u(o.getLocal(g),o.i64_const(32)))))}t<l&&(a.addCode(o.setLocal("m"+t,o.i64_and(o.i64_mul(o.i64_and(o.getLocal(g),o.i64_const(4294967295)),o.getLocal("np32")),o.i64_const("0xFFFFFFFF")))),a.addCode(o.setLocal(g,o.i64_add(o.i64_and(o.getLocal(g),o.i64_const(4294967295)),u(0,t)))),a.addCode(o.setLocal(L,o.i64_add(o.getLocal(L),o.i64_shr_u(o.getLocal(g),o.i64_const(32)))))),t>=l&&a.addCode(o.i64_store32(o.getLocal("r"),4*(t-l),o.getLocal(g))),a.addCode(o.setLocal(p,o.getLocal(L)),o.setLocal(f,o.i64_shr_u(o.getLocal(p),o.i64_const(32))))}a.addCode(o.i64_store32(o.getLocal("r"),4*l-4,o.getLocal(p))),a.addCode(o.if(o.i32_wrap_i64(o.getLocal(f)),o.drop(o.call(r+"_sub",o.getLocal("r"),o.i32_const(d),o.getLocal("r"))),o.if(o.call(r+"_gte",o.getLocal("r"),o.i32_const(d)),o.drop(o.call(r+"_sub",o.getLocal("r"),o.i32_const(d),o.getLocal("r"))))))}(),function(){const a=t.addFunction(s+"_squareOld");a.addParam("x","i32"),a.addParam("r","i32");const o=a.getCodeBuilder();
1a.addCode(o.call(s+"_mul",o.getLocal("x"),o.getLocal("x"),o.getLocal("r")))}(),function(){const a=t.addFunction(s+"_toMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const o=a.getCodeBuilder();a.addCode(o.call(s+"_mul",o.getLocal("x"),o.i32_const(_),o.getLocal("r")))}(),function(){const a=t.alloc(2*n),o=t.addFunction(s+"_fromMontgomery");o.addParam("x","i32"),o.addParam("r","i32");const e=o.getCodeBuilder();o.addCode(e.call(r+"_copy",e.getLocal("x"),e.i32_const(a))),o.addCode(e.call(r+"_zero",e.i32_const(a+n))),o.addCode(e.call(s+"_mReduct",e.i32_const(a),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_isNegative");a.addParam("x","i32"),a.setReturnType("i32");const o=a.getCodeBuilder(),e=o.i32_const(t.alloc(n));a.addCode(o.call(s+"_fromMontgomery",o.getLocal("x"),e),o.call(r+"_gte",e,o.i32_const(h)))}(),function(){const a=t.addFunction(s+"_sign");a.addParam("x","i32"),a.setReturnType("i32");const o=a.getCodeBuilder(),e=o.i32_const(t.alloc(n));a.addCode(o.if(o.call(r+"_isZero",o.getLocal("x")),o.ret(o.i32_const(0))),o.call(s+"_fromMontgomery",o.getLocal("x"),e),o.if(o.call(r+"_gte",e,o.i32_const(h)),o.ret(o.i32_const(-1))),o.ret(o.i32_const(1)))}(),function(){const a=t.addFunction(s+"_inverse");a.addParam("x","i32"),a.addParam("r","i32");const o=a.getCodeBuilder();a.addCode(o.call(s+"_fromMontgomery",o.getLocal("x"),o.getLocal("r"))),a.addCode(o.call(r+"_inverseMod",o.getLocal("r"),o.i32_const(d),o.getLocal("r"))),a.addCode(o.call(s+"_toMontgomery",o.getLocal("r"),o.getLocal("r")))}(),function(){const a=t.addFunction(s+"_one");a.addParam("pr","i32");const o=a.getCodeBuilder();a.addCode(o.call(r+"_copy",o.i32_const(u),o.getLocal("pr")))}(),function(){const a=t.addFunction(s+"_load");a.addParam("scalar","i32"),a.addParam("scalarLen","i32"),a.addParam("r","i32"),a.addLocal("p","i32"),a.addLocal("l","i32"),a.addLocal("i","i32"),a.addLocal("j","i32");const o=a.getCodeBuilder(),e=o.i32_const(t.alloc(n)),i=t.alloc(n),c=o.i32_const(i);a.addCode(o.call(r+"_zero",o.getLocal("r")),o.setLocal("i",o.i32_const(n)),o.setLocal("p",o.getLocal("scalar")),o.block(o.loop(o.br_if(1,o.i32_gt_u(o.getLocal("i"),o.getLocal("scalarLen"))),o.if(o.i32_eq(o.getLocal("i"),o.i32_const(n)),o.call(s+"_one",e),o.call(s+"_mul",e,o.i32_const(_),e)),o.call(s+"_mul",o.getLocal("p"),e,c),o.call(s+"_add",o.getLocal("r"),c,o.getLocal("r")),o.setLocal("p",o.i32_add(o.getLocal("p"),o.i32_const(n))),o.setLocal("i",o.i32_add(o.getLocal("i"),o.i32_const(n))),o.br(0))),o.setLocal("l",o.i32_rem_u(o.getLocal("scalarLen"),o.i32_const(n))),o.if(o.i32_eqz(o.getLocal("l")),o.ret([])),o.call(r+"_zero",c),o.setLocal("j",o.i32_const(0)),o.block(o.loop(o.br_if(1,o.i32_eq(o.getLocal("j"),o.getLocal("l"))),o.i32_store8(o.getLocal("j"),i,o.i32_load8_u(o.getLocal("p"))),o.setLocal("p",o.i32_add(o.getLocal("p"),o.i32_const(1))),o.setLocal("j",o.i32_add(o.getLocal("j"),o.i32_const(1))),o.br(0))),o.if(o.i32_eq(o.getLocal("i"),o.i32_const(n)),o.call(s+"_one",e),o.call(s+"_mul",e,o.i32_const(_),e)),o.call(s+"_mul",c,e,c),o.call(s+"_add",o.getLocal("r"),c,o.getLocal("r")))}(),function(){const a=t.addFunction(s+"_timesScalar");a.addParam("x","i32"),a.addParam("scalar","i32"),a.addParam("scalarLen","i32"),a.addParam("r","i32");const o=a.getCodeBuilder(),e=o.i32_const(t.alloc(n));a.addCode(o.call(s+"_load",o.getLocal("scalar"),o.getLocal("scalarLen"),e),o.call(s+"_toMontgomery",e,e),o.call(s+"_mul",o.getLocal("x"),e,o.getLocal("r")))}(),xt(t,s),yt(t,s+"_batchToMontgomery",s+"_toMontgomery",n,n),yt(t,s+"_batchFromMontgomery",s+"_fromMontgomery",n,n),yt(t,s+"_batchNeg",s+"_neg",n,n),Ft(t,s+"_batchAdd",s+"_add",n,n),Ft(t,s+"_batchSub",s+"_sub",n,n),Ft(t,s+"_batchMul",s+"_mul",n,n),t.exportFunction(s+"_add"),t.exp
1ortFunction(s+"_sub"),t.exportFunction(s+"_neg"),t.exportFunction(s+"_isNegative"),t.exportFunction(s+"_isOne"),t.exportFunction(s+"_sign"),t.exportFunction(s+"_mReduct"),t.exportFunction(s+"_mul"),t.exportFunction(s+"_square"),t.exportFunction(s+"_squareOld"),t.exportFunction(s+"_fromMontgomery"),t.exportFunction(s+"_toMontgomery"),t.exportFunction(s+"_inverse"),t.exportFunction(s+"_one"),t.exportFunction(s+"_load"),t.exportFunction(s+"_timesScalar"),bt(t,s+"_exp",n,s+"_mul",s+"_square",r+"_copy",s+"_one"),t.exportFunction(s+"_exp"),t.exportFunction(s+"_batchInverse"),At(i)&&(!function(){const a=t.addFunction(s+"_sqrt");a.addParam("n","i32"),a.addParam("r","i32"),a.addLocal("m","i32"),a.addLocal("i","i32"),a.addLocal("j","i32");const o=a.getCodeBuilder(),e=o.i32_const(u),i=o.i32_const(t.alloc(n)),c=o.i32_const(t.alloc(n)),l=o.i32_const(t.alloc(n)),r=o.i32_const(t.alloc(n)),d=o.i32_const(t.alloc(n));a.addCode(o.if(o.call(s+"_isZero",o.getLocal("n")),o.ret(o.call(s+"_zero",o.getLocal("r")))),o.setLocal("m",o.i32_const(x)),o.call(s+"_copy",o.i32_const(B),i),o.call(s+"_exp",o.getLocal("n"),o.i32_const(F),o.i32_const(n),c),o.call(s+"_exp",o.getLocal("n"),o.i32_const(A),o.i32_const(n),l),o.block(o.loop(o.br_if(1,o.call(s+"_eq",c,e)),o.call(s+"_square",c,r),o.setLocal("i",o.i32_const(1)),o.block(o.loop(o.br_if(1,o.call(s+"_eq",r,e)),o.call(s+"_square",r,r),o.setLocal("i",o.i32_add(o.getLocal("i"),o.i32_const(1))),o.br(0))),o.call(s+"_copy",i,d),o.setLocal("j",o.i32_sub(o.i32_sub(o.getLocal("m"),o.getLocal("i")),o.i32_const(1))),o.block(o.loop(o.br_if(1,o.i32_eqz(o.getLocal("j"))),o.call(s+"_square",d,d),o.setLocal("j",o.i32_sub(o.getLocal("j"),o.i32_const(1))),o.br(0))),o.setLocal("m",o.getLocal("i")),o.call(s+"_square",d,i),o.call(s+"_mul",c,i,c),o.call(s+"_mul",l,d,l),o.br(0))),o.if(o.call(s+"_isNegative",l),o.call(s+"_neg",l,o.getLocal("r")),o.call(s+"_copy",l,o.getLocal("r"))))}(),function(){const a=t.addFunction(s+"_isSquare");a.addParam("n","i32"),a.setReturnType("i32");const o=a.getCodeBuilder(),e=o.i32_const(u),i=o.i32_const(t.alloc(n));a.addCode(o.if(o.call(s+"_isZero",o.getLocal("n")),o.ret(o.i32_const(1))),o.call(s+"_exp",o.getLocal("n"),o.i32_const(f),o.i32_const(n),i),o.call(s+"_eq",i,e))}(),t.exportFunction(s+"_sqrt"),t.exportFunction(s+"_isSquare")),t.exportFunction(s+"_batchToMontgomery"),t.exportFunction(s+"_batchFromMontgomery"),s};const It=vt,{bitLength:Ot}=et;var Et=function(t,a,o,e,i){const c=BigInt(a),l=Math.floor((Ot(c-1n)-1)/64)+1,n=8*l,s=o||"f1";if(t.modules[s])return s;t.modules[s]={n64:l};const r=i||"int",d=It(t,c,e,r),_=t.modules[d].pR2,u=t.modules[d].pq,g=t.modules[d].pePlusOne;return function(){const a=t.alloc(n),o=t.addFunction(s+"_mul");o.addParam("x","i32"),o.addParam("y","i32"),o.addParam("r","i32");const e=o.getCodeBuilder();o.addCode(e.call(d+"_mul",e.getLocal("x"),e.getLocal("y"),e.i32_const(a))),o.addCode(e.call(d+"_mul",e.i32_const(a),e.i32_const(_),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_square");a.addParam("x","i32"),a.addParam("r","i32");const o=a.getCodeBuilder();a.addCode(o.call(s+"_mul",o.getLocal("x"),o.getLocal("x"),o.getLocal("r")))}(),function(){const a=t.addFunction(s+"_inverse");a.addParam("x","i32"),a.addParam("r","i32");const o=a.getCodeBuilder();a.addCode(o.call(r+"_inverseMod",o.getLocal("x"),o.i32_const(u),o.getLocal("r")))}(),function(){const a=t.addFunction(s+"_isNegative");a.addParam("x","i32"),a.setReturnType("i32");const o=a.getCodeBuilder();a.addCode(o.call(r+"_gte",o.getLocal("x"),o.i32_const(g)))}
1(),t.exportFunction(d+"_add",s+"_add"),t.exportFunction(d+"_sub",s+"_sub"),t.exportFunction(d+"_neg",s+"_neg"),t.exportFunction(s+"_mul"),t.exportFunction(s+"_square"),t.exportFunction(s+"_inverse"),t.exportFunction(s+"_isNegative"),t.exportFunction(d+"_copy",s+"_copy"),t.exportFunction(d+"_zero",s+"_zero"),t.exportFunction(d+"_one",s+"_one"),t.exportFunction(d+"_isZero",s+"_isZero"),t.exportFunction(d+"_eq",s+"_eq"),s};const Mt=H,St=tt,zt=Y;var Tt=function(t,a,o,e){if(t.modules[o])return o;const i=8*t.modules[e].n64,c=t.modules[e].q;return t.modules[o]={n64:2*t.modules[e].n64},function(){const a=t.addFunction(o+"_isZero");a.addParam("x","i32"),a.setReturnType("i32");const c=a.getCodeBuilder(),l=c.getLocal("x"),n=c.i32_add(c.getLocal("x"),c.i32_const(i));a.addCode(c.i32_and(c.call(e+"_isZero",l),c.call(e+"_isZero",n)))}(),function(){const a=t.addFunction(o+"_isOne");a.addParam("x","i32"),a.setReturnType("i32");const c=a.getCodeBuilder(),l=c.getLocal("x"),n=c.i32_add(c.getLocal("x"),c.i32_const(i));a.addCode(c.ret(c.i32_and(c.call(e+"_isOne",l),c.call(e+"_isZero",n))))}(),function(){const a=t.addFunction(o+"_zero");a.addParam("x","i32");const c=a.getCodeBuilder(),l=c.getLocal("x"),n=c.i32_add(c.getLocal("x"),c.i32_const(i));a.addCode(c.call(e+"_zero",l),c.call(e+"_zero",n))}(),function(){const a=t.addFunction(o+"_one");a.addParam("x","i32");const c=a.getCodeBuilder(),l=c.getLocal("x"),n=c.i32_add(c.getLocal("x"),c.i32_const(i));a.addCode(c.call(e+"_one",l),c.call(e+"_zero",n))}(),function(){const a=t.addFunction(o+"_copy");a.addParam("x","i32"),a.addParam("r","i32");const c=a.getCodeBuilder(),l=c.getLocal("x"),n=c.i32_add(c.getLocal("x"),c.i32_const(i)),s=c.getLocal("r"),r=c.i32_add(c.getLocal("r"),c.i32_const(i));a.addCode(c.call(e+"_copy",l,s),c.call(e+"_copy",n,r))}(),function(){const c=t.addFunction(o+"_mul");c.addParam("x","i32"),c.addParam("y","i32"),c.addParam("r","i32");const l=c.getCodeBuilder(),n=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.getLocal("y"),d=l.i32_add(l.getLocal("y"),l.i32_const(i)),_=l.getLocal("r"),u=l.i32_add(l.getLocal("r"),l.i32_const(i)),g=l.i32_const(t.alloc(i)),L=l.i32_const(t.alloc(i)),p=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i));c.addCode(l.call(e+"_mul",n,r,g),l.call(e+"_mul",s,d,L),l.call(e+"_add",n,s,p),l.call(e+"_add",r,d,f),l.call(e+"_mul",p,f,p),l.call(a,L,_),l.call(e+"_add",g,_,_),l.call(e+"_add",g,L,u),l.call(e+"_sub",p,u,u))}(),function(){const a=t.addFunction(o+"_mul1");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const c=a.getCodeBuilder(),l=c.getLocal("x"),n=c.i32_add(c.getLocal("x"),c.i32_const(i)),s=c.getLocal("y"),r=c.getLocal("r"),d=c.i32_add(c.getLocal("r"),c.i32_const(i));a.addCode(c.call(e+"_mul",l,s,r),c.call(e+"_mul",n,s,d))}(),function(){const c=t.addFunction(o+"_square");c.addParam("x","i32"),c.addParam("r","i32");const l=c.getCodeBuilder(),n=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.getLocal("r"),d=l.i32_add(l.getLocal("r"),l.i32_const(i)),_=l.i32_const(t.alloc(i)),u=l.i32_const(t.alloc(i)),g=l.i32_const(t.alloc(i)),L=l.i32_const(t.alloc(i));c.addCode(l.call(e+"_mul",n,s,_),l.call(e+"_add",n,s,u),l.call(a,s,g),l.call(e+"_add",n,g,g),l.call(a,_,L),l.call(e+"_add",L,_,L),l.call(e+"_mul",u,g,r),l.call(e+"_sub",r,L,r),l.call(e+"_add",_,_,d))}(),function(){const a=t.addFunction(o+"_add");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const c=a.getCodeBuilder(),l=c.getLocal("x"),n=c.i32_add(c.getLocal("x"),c.i32_const(i)),s=c.getLocal("y"),r=c.i32_add(c.getLocal("y"),c.i32_const(i)),d=c.getLocal("r"),_=c.i32_add(c.getLocal("r"),c.i32_const(i));a.addCode(c.call(e+"_add",l,s,d),c.call(e+"_add",n,r,_))}(),function(){const a=t.addFunction(o+"_sub");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const c=a.getCodeBuilder(),l=c.getLocal("x"),n=c.i32_add(c.getLocal("x"),c.i32_const(i)),s=c.getLocal("y"),r=c.i32_add(c.getLocal("y"),c.i32_const(i)),d=c.getLocal("r"),_=c.i32_add(c.getLocal("r"),c.i32_const(i));a.addCode(c.call(e+"_sub",l,s,d),c.call(e+"_sub",n,r,_))}(),function(){const a=t.addFunction(o+"_neg");a.addParam("x","i32"),a.addParam("r","i32");const c=a.getCodeBuilder(),l=c.getLocal("x"),n=c.i32_add(c.getLocal("x"),
1c.i32_const(i)),s=c.getLocal("r"),r=c.i32_add(c.getLocal("r"),c.i32_const(i));a.addCode(c.call(e+"_neg",l,s),c.call(e+"_neg",n,r))}(),function(){const a=t.addFunction(o+"_conjugate");a.addParam("x","i32"),a.addParam("r","i32");const c=a.getCodeBuilder(),l=c.getLocal("x"),n=c.i32_add(c.getLocal("x"),c.i32_const(i)),s=c.getLocal("r"),r=c.i32_add(c.getLocal("r"),c.i32_const(i));a.addCode(c.call(e+"_copy",l,s),c.call(e+"_neg",n,r))}(),function(){const a=t.addFunction(o+"_toMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const c=a.getCodeBuilder(),l=c.getLocal("x"),n=c.i32_add(c.getLocal("x"),c.i32_const(i)),s=c.getLocal("r"),r=c.i32_add(c.getLocal("r"),c.i32_const(i));a.addCode(c.call(e+"_toMontgomery",l,s),c.call(e+"_toMontgomery",n,r))}(),function(){const a=t.addFunction(o+"_fromMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const c=a.getCodeBuilder(),l=c.getLocal("x"),n=c.i32_add(c.getLocal("x"),c.i32_const(i)),s=c.getLocal("r"),r=c.i32_add(c.getLocal("r"),c.i32_const(i));a.addCode(c.call(e+"_fromMontgomery",l,s),c.call(e+"_fromMontgomery",n,r))}(),function(){const a=t.addFunction(o+"_eq");a.addParam("x","i32"),a.addParam("y","i32"),a.setReturnType("i32");const c=a.getCodeBuilder(),l=c.getLocal("x"),n=c.i32_add(c.getLocal("x"),c.i32_const(i)),s=c.getLocal("y"),r=c.i32_add(c.getLocal("y"),c.i32_const(i));a.addCode(c.i32_and(c.call(e+"_eq",l,s),c.call(e+"_eq",n,r)))}(),function(){const c=t.addFunction(o+"_inverse");c.addParam("x","i32"),c.addParam("r","i32");const l=c.getCodeBuilder(),n=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.getLocal("r"),d=l.i32_add(l.getLocal("r"),l.i32_const(i)),_=l.i32_const(t.alloc(i)),u=l.i32_const(t.alloc(i)),g=l.i32_const(t.alloc(i)),L=l.i32_const(t.alloc(i));c.addCode(l.call(e+"_square",n,_),l.call(e+"_square",s,u),l.call(a,u,g),l.call(e+"_sub",_,g,g),l.call(e+"_inverse",g,L),l.call(e+"_mul",n,L,r),l.call(e+"_mul",s,L,d),l.call(e+"_neg",d,d))}(),function(){const a=t.addFunction(o+"_timesScalar");a.addParam("x","i32"),a.addParam("scalar","i32"),a.addParam("scalarLen","i32"),a.addParam("r","i32");const c=a.getCodeBuilder(),l=c.getLocal("x"),n=c.i32_add(c.getLocal("x"),c.i32_const(i)),s=c.getLocal("r"),r=c.i32_add(c.getLocal("r"),c.i32_const(i));a.addCode(c.call(e+"_timesScalar",l,c.getLocal("scalar"),c.getLocal("scalarLen"),s),c.call(e+"_timesScalar",n,c.getLocal("scalar"),c.getLocal("scalarLen"),r))}(),function(){const a=t.addFunction(o+"_sign");a.addParam("x","i32"),a.addLocal("s","i32"),a.setReturnType("i32");const c=a.getCodeBuilder(),l=c.getLocal("x"),n=c.i32_add(c.getLocal("x"),c.i32_const(i));a.addCode(c.setLocal("s",c.call(e+"_sign",n)),c.if(c.getLocal("s"),c.ret(c.getLocal("s"))),c.ret(c.call(e+"_sign",l)))}(),function(){const a=t.addFunction(o+"_isNegative");a.addParam("x","i32"),a.setReturnType("i32");const c=a.getCodeBuilder(),l=c.getLocal("x"),n=c.i32_add(c.getLocal("x"),c.i32_const(i));a.addCode(c.if(c.call(e+"_isZero",n),c.ret(c.call(e+"_isNegative",l))),c.ret(c.call(e+"_isNegative",n)))}(),t.exportFunction(o+"_isZero"),t.exportFunction(o+"_isOne"),t.exportFunction(o+"_zero"),t.exportFunction(o+"_one"),t.exportFunction(o+"_copy"),t.exportFunction(o+"_mul"),t.exportFunction(o+"_mul1"),t.exp
1ortFunction(o+"_square"),t.exportFunction(o+"_add"),t.exportFunction(o+"_sub"),t.exportFunction(o+"_neg"),t.exportFunction(o+"_sign"),t.exportFunction(o+"_conjugate"),t.exportFunction(o+"_fromMontgomery"),t.exportFunction(o+"_toMontgomery"),t.exportFunction(o+"_eq"),t.exportFunction(o+"_inverse"),St(t,o),Mt(t,o+"_exp",2*i,o+"_mul",o+"_square",o+"_copy",o+"_one"),function(){const a=t.addFunction(o+"_sqrt");a.addParam("a","i32"),a.addParam("pr","i32");const l=a.getCodeBuilder(),n=l.i32_const(t.alloc(zt.bigInt2BytesLE((BigInt(c||0)-3n)/4n,i))),s=l.i32_const(t.alloc(zt.bigInt2BytesLE((BigInt(c||0)-1n)/2n,i))),r=l.getLocal("a"),d=l.i32_const(t.alloc(2*i)),_=l.i32_const(t.alloc(2*i)),u=l.i32_const(t.alloc(2*i)),g=t.alloc(2*i),L=l.i32_const(g),p=l.i32_const(g),f=l.i32_const(g+i),m=l.i32_const(t.alloc(2*i)),h=l.i32_const(t.alloc(2*i));a.addCode(l.call(o+"_one",L),l.call(o+"_neg",L,L),l.call(o+"_exp",r,n,l.i32_const(i),d),l.call(o+"_square",d,_),l.call(o+"_mul",r,_,_),l.call(o+"_conjugate",_,u),l.call(o+"_mul",u,_,u),l.if(l.call(o+"_eq",u,L),l.unreachable()),l.call(o+"_mul",d,r,m),l.if(l.call(o+"_eq",_,L),[...l.call(e+"_zero",p),...l.call(e+"_one",f),...l.call(o+"_mul",L,m,l.getLocal("pr"))],[...l.call(o+"_one",h),...l.call(o+"_add",h,_,h),...l.call(o+"_exp",h,s,l.i32_const(i),h),...l.call(o+"_mul",h,m,l.getLocal("pr"))]))}(),function(){const a=t.addFunction(o+"_isSquare");a.addParam("a","i32"),a.setReturnType("i32");const e=a.getCodeBuilder(),l=e.i32_const(t.alloc(zt.bigInt2BytesLE((BigInt(c||0)-3n)/4n,i))),n=e.getLocal("a"),s=e.i32_const(t.alloc(2*i)),r=e.i32_const(t.alloc(2*i)),d=e.i32_const(t.alloc(2*i)),_=t.alloc(2*i),u=e.i32_const(_);a.addCode(e.call(o+"_one",u),e.call(o+"_neg",u,u),e.call(o+"_exp",n,l,e.i32_const(i),s),e.call(o+"_square",s,r),e.call(o+"_mul",n,r,r),e.call(o+"_conjugate",r,d),e.call(o+"_mul",d,r,d),e.if(e.call(o+"_eq",d,u),e.ret(e.i32_const(0))),e.ret(e.i32_const(1)))}
1(),t.exportFunction(o+"_exp"),t.exportFunction(o+"_timesScalar"),t.exportFunction(o+"_batchInverse"),t.exportFunction(o+"_sqrt"),t.exportFunction(o+"_isSquare"),t.exportFunction(o+"_isNegative"),o};const kt=H,Gt=tt;var Nt=function(t,a,o,e){if(t.modules[o])return o;const i=8*t.modules[e].n64;return t.modules[o]={n64:3*t.modules[e].n64},function(){const a=t.addFunction(o+"_isZero");a.addParam("x","i32"),a.setReturnType("i32");const c=a.getCodeBuilder(),l=c.getLocal("x"),n=c.i32_add(c.getLocal("x"),c.i32_const(i)),s=c.i32_add(c.getLocal("x"),c.i32_const(2*i));a.addCode(c.i32_and(c.i32_and(c.call(e+"_isZero",l),c.call(e+"_isZero",n)),c.call(e+"_isZero",s)))}(),function(){const a=t.addFunction(o+"_isOne");a.addParam("x","i32"),a.setReturnType("i32");const c=a.getCodeBuilder(),l=c.getLocal("x"),n=c.i32_add(c.getLocal("x"),c.i32_const(i)),s=c.i32_add(c.getLocal("x"),c.i32_const(2*i));a.addCode(c.ret(c.i32_and(c.i32_and(c.call(e+"_isOne",l),c.call(e+"_isZero",n)),c.call(e+"_isZero",s))))}(),function(){const a=t.addFunction(o+"_zero");a.addParam("x","i32");const c=a.getCodeBuilder(),l=c.getLocal("x"),n=c.i32_add(c.getLocal("x"),c.i32_const(i)),s=c.i32_add(c.getLocal("x"),c.i32_const(2*i));a.addCode(c.call(e+"_zero",l),c.call(e+"_zero",n),c.call(e+"_zero",s))}(),function(){const a=t.addFunction(o+"_one");a.addParam("x","i32");const c=a.getCodeBuilder(),l=c.getLocal("x"),n=c.i32_add(c.getLocal("x"),c.i32_const(i)),s=c.i32_add(c.getLocal("x"),c.i32_const(2*i));a.addCode(c.call(e+"_one",l),c.call(e+"_zero",n),c.call(e+"_zero",s))}(),function(){const a=t.addFunction(o+"_copy");a.addParam("x","i32"),a.addParam("r","i32");const c=a.getCodeBuilder(),l=c.getLocal("x"),n=c.i32_add(c.getLocal("x"),c.i32_const(i)),s=c.i32_add(c.getLocal("x"),c.i32_const(2*i)),r=c.getLocal("r"),d=c.i32_add(c.getLocal("r"),c.i32_const(i)),_=c.i32_add(c.getLocal("r"),c.i32_const(2*i));a.addCode(c.call(e+"_copy",l,r),c.call(e+"_copy",n,d),c.call(e+"_copy",s,_))}(),function(){const c=t.addFunction(o+"_mul");c.addParam("x","i32"),c.addParam("y","i32"),c.addParam("r","i32");const l=c.getCodeBuilder(),n=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.i32_add(l.getLocal("x"),l.i32_const(2*i)),d=l.getLocal("y"),_=l.i32_add(l.getLocal("y"),l.i32_const(i)),u=l.i32_add(l.getLocal("y"),l.i32_const(2*i)),g=l.getLocal("r"),L=l.i32_add(l.getLocal("r"),l.i32_const(i)),p=l.i32_add(l.getLocal("r"),l.i32_const(2*i)),f=l.i32_const(t.alloc(i)),m=l.i32_const(t.alloc(i)),h=l.i32_const(t.alloc(i)),b=l.i32_const(t.alloc(i)),x=l.i32_const(t.alloc(i)),y=l.i32_const(t.alloc(i)),F=l.i32_const(t.alloc(i)),C=l.i32_const(t.alloc(i)),B=l.i32_const(t.alloc(i)),P=l.i32_const(t.alloc(i)),A=l.i32_const(t.alloc(i)),w=l.i32_const(t.alloc(i)),q=l.i32_const(t.alloc(i));c.addCode(l.call(e+"_mul",n,d,f),l.call(e+"_mul",s,_,m),l.call(e+"_mul",r,u,h),l.call(e+"_add",n,s,b),l.call(e+"_add",d,_,x),l.call(e+"_add",n,r,y),l.call(e+"_add",d,u,F),l.call(e+"_add",s,r,C),l.call(e+"_add",_,u,B),l.call(e+"_add",f,m,P),l.call(e+"_add",f,h,A),l.call(e+"_add",m,h,w),l.call(e+"_mul",C,B,g),l.call(e+"_sub",g,w,g),l.call(a,g,g),l.call(e+"_add",f,g,g),l.call(e+"_mul",b,x,L),l.call(e+"_sub",L,P,L),l.call(a,h,q),l.call(e+"_add",L,q,L),l.call(e+"_mul",y,F,p),l.call(e+"_sub",p,A,p),l.call(e+"_add",p,m,p))}(),function(){const c=t.addFunction(o+"_square");c.addParam("x","i32"),c.addParam("r","i32");const l=c.getCodeBuilder(),n=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.i32_add(l.getLocal("x"),l.i32_const(2*i)),d=l.getLocal("r"),_=l.i32_add(l.getLocal("r"),l.i32_const(i)),u=l.i32_add(l.getLocal("r"),l.i32_const(2*i)),g=l.i32_const(t.alloc(i)),L=l.i32_const(t.alloc(i)),p=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i)),m=l.i32_const(t.alloc(i)),h=l.i32_const(t.alloc(i)),b=l.i32_const(t.alloc(i));c.addCode(l.call(e+"_square",n,g),l.call(e+"_mul",n,s,L),l.call(e+"_add",L,L,p),l.call(e+"_sub",n,s,f),l.call(e+"_add",f,r,f),l.call(e+"_square",f,f),l.call(e+"_mul",s,r,m),l.call(e+"_add",m,m,h),l.call(e+"_square",r,b),l.call(a,h,d),l.call(e+"_add",g,d,d),l.call(a,b,_),l.call(e+"_add",p,_,_),l.call(e+"_add",g,b,u),l.call(e+"_sub",h,u,u),l.call(e+"_add",f,u,u),l.call(e+"_add",p,u,u))}(),function(){const a=t.addFunction(o+"_add");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const c=a.getCodeBuilder(),l=c.getLocal("x"),n=c.i32_add(c.getLocal("x"),
1c.i32_const(i)),s=c.i32_add(c.getLocal("x"),c.i32_const(2*i)),r=c.getLocal("y"),d=c.i32_add(c.getLocal("y"),c.i32_const(i)),_=c.i32_add(c.getLocal("y"),c.i32_const(2*i)),u=c.getLocal("r"),g=c.i32_add(c.getLocal("r"),c.i32_const(i)),L=c.i32_add(c.getLocal("r"),c.i32_const(2*i));a.addCode(c.call(e+"_add",l,r,u),c.call(e+"_add",n,d,g),c.call(e+"_add",s,_,L))}(),function(){const a=t.addFunction(o+"_sub");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const c=a.getCodeBuilder(),l=c.getLocal("x"),n=c.i32_add(c.getLocal("x"),c.i32_const(i)),s=c.i32_add(c.getLocal("x"),c.i32_const(2*i)),r=c.getLocal("y"),d=c.i32_add(c.getLocal("y"),c.i32_const(i)),_=c.i32_add(c.getLocal("y"),c.i32_const(2*i)),u=c.getLocal("r"),g=c.i32_add(c.getLocal("r"),c.i32_const(i)),L=c.i32_add(c.getLocal("r"),c.i32_const(2*i));a.addCode(c.call(e+"_sub",l,r,u),c.call(e+"_sub",n,d,g),c.call(e+"_sub",s,_,L))}(),function(){const a=t.addFunction(o+"_neg");a.addParam("x","i32"),a.addParam("r","i32");const c=a.getCodeBuilder(),l=c.getLocal("x"),n=c.i32_add(c.getLocal("x"),c.i32_const(i)),s=c.i32_add(c.getLocal("x"),c.i32_const(2*i)),r=c.getLocal("r"),d=c.i32_add(c.getLocal("r"),c.i32_const(i)),_=c.i32_add(c.getLocal("r"),c.i32_const(2*i));a.addCode(c.call(e+"_neg",l,r),c.call(e+"_neg",n,d),c.call(e+"_neg",s,_))}(),function(){const a=t.addFunction(o+"_sign");a.addParam("x","i32"),a.addLocal("s","i32"),a.setReturnType("i32");const c=a.getCodeBuilder(),l=c.getLocal("x"),n=c.i32_add(c.getLocal("x"),c.i32_const(i)),s=c.i32_add(c.getLocal("x"),c.i32_const(2*i));a.addCode(c.setLocal("s",c.call(e+"_sign",s)),c.if(c.getLocal("s"),c.ret(c.getLocal("s"))),c.setLocal("s",c.call(e+"_sign",n)),c.if(c.getLocal("s"),c.ret(c.getLocal("s"))),c.ret(c.call(e+"_sign",l)))}(),function(){const a=t.addFunction(o+"_toMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const c=a.getCodeBuilder(),l=c.getLocal("x"),n=c.i32_add(c.getLocal("x"),c.i32_const(i)),s=c.i32_add(c.getLocal("x"),c.i32_const(2*i)),r=c.getLocal("r"),d=c.i32_add(c.getLocal("r"),c.i32_const(i)),_=c.i32_add(c.getLocal("r"),c.i32_const(2*i));a.addCode(c.call(e+"_toMontgomery",l,r),c.call(e+"_toMontgomery",n,d),c.call(e+"_toMontgomery",s,_))}(),function(){const a=t.addFunction(o+"_fromMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const c=a.getCodeBuilder(),l=c.getLocal("x"),n=c.i32_add(c.getLocal("x"),c.i32_const(i)),s=c.i32_add(c.getLocal("x"),c.i32_const(2*i)),r=c.getLocal("r"),d=c.i32_add(c.getLocal("r"),c.i32_const(i)),_=c.i32_add(c.getLocal("r"),c.i32_const(2*i));a.addCode(c.call(e+"_fromMontgomery",l,r),c.call(e+"_fromMontgomery",n,d),c.call(e+"_fromMontgomery",s,_))}(),function(){const a=t.addFunction(o+"_eq");a.addParam("x","i32"),a.addParam("y","i32"),a.setReturnType("i32");const c=a.getCodeBuilder(),l=c.getLocal("x"),n=c.i32_add(c.getLocal("x"),c.i32_const(i)),s=c.i32_add(c.getLocal("x"),c.i32_const(2*i)),r=c.getLocal("y"),d=c.i32_add(c.getLocal("y"),c.i32_const(i)),_=c.i32_add(c.getLocal("y"),c.i32_const(2*i));a.addCode(c.i32_and(c.i32_and(c.call(e+"_eq",l,r),c.call(e+"_eq",n,d)),c.call(e+"_eq",s,_)))}(),function(){const c=t.addFunction(o+"_inverse");c.addParam("x","i32"),c.addParam("r","i32");const l=c.getCodeBuilder(),n=l.getLocal("x"),s=l.i32_add(l.getLocal("x"),l.i32_const(i)),r=l.i32_add(l.getLocal("x"),l.i32_const(2*i)),d=l.getLocal("r"),_=l.i32_add(l.getLocal("r"),l.i32_const(i)),u=l.i32_add(l.getLocal("r"),l.i32_const(2*i)),g=l.i32_const(t.alloc(i)),L=l.i32_const(t.alloc(i)),p=l.i32_const(t.alloc(i)),f=l.i32_const(t.alloc(i)),m=l.i32_const(t.alloc(i)),h=l.i32_const(t.alloc(i)),b=l.i32_const(t.alloc(i)),x=l.i32_const(t.alloc(i)),y=l.i32_const(t.alloc(i)),F=l.i32_const(t.alloc(i)),C=l.i32_const(t.alloc(i));c.addCode(l.call(e+"_square",n,g),l.call(e+"_square",s,L),l.call(e+"_square",r,p),l.call(e+"_mul",n,s,f),l.call(e+"_mul",n,r,m),l.call(e+"_mul",s,r,h),l.call(a,h,b),l.call(e+"_sub",g,b,b),l.call(a,p,x),l.call(e+"_sub",x,f,x),l.call(e+"_sub",L,m,y),l.call(e+"_mul",r,x,F),l.call(e+"_mul",s,y,C),l.call(e+"_add",F,C,F),l.call(a,F,F),l.call(e+"_mul",n,b,C),l.call(e+"_add",C,F,F),l.call(e+"_inverse",F,F),l.call(e+"_mul",F,b,d),l.call(e+"_mul",F,x,_),l.call(e+"_mul",F,y,u))}(),function(){const a=t.addFunction(o+"_timesScalar");a.addParam("x","i32"),a.addParam("scalar","i32"),a.addParam("scalarLen","i32"),a.addParam("r","i32");const c=a.getCodeBuilder(),l=c.getLocal("x"),n=c.i32_add(c.getLocal("x"),
1c.i32_const(i)),s=c.i32_add(c.getLocal("x"),c.i32_const(2*i)),r=c.getLocal("r"),d=c.i32_add(c.getLocal("r"),c.i32_const(i)),_=c.i32_add(c.getLocal("r"),c.i32_const(2*i));a.addCode(c.call(e+"_timesScalar",l,c.getLocal("scalar"),c.getLocal("scalarLen"),r),c.call(e+"_timesScalar",n,c.getLocal("scalar"),c.getLocal("scalarLen"),d),c.call(e+"_timesScalar",s,c.getLocal("scalar"),c.getLocal("scalarLen"),_))}(),function(){const a=t.addFunction(o+"_isNegative");a.addParam("x","i32"),a.setReturnType("i32");const c=a.getCodeBuilder(),l=c.getLocal("x"),n=c.i32_add(c.getLocal("x"),c.i32_const(i)),s=c.i32_add(c.getLocal("x"),c.i32_const(2*i));a.addCode(c.if(c.call(e+"_isZero",s),c.if(c.call(e+"_isZero",n),c.ret(c.call(e+"_isNegative",l)),c.ret(c.call(e+"_isNegative",n)))),c.ret(c.call(e+"_isNegative",s)))}(),t.exportFunction(o+"_isZero"),t.exportFunction(o+"_isOne"),t.exportFunction(o+"_zero"),t.exportFunction(o+"_one"),t.exportFunction(o+"_copy"),t.exportFunction(o+"_mul"),t.exportFunction(o+"_square"),t.exportFunction(o+"_add"),t.exportFunction(o+"_sub"),t.exportFunction(o+"_neg"),t.exportFunction(o+"_sign"),t.exportFunction(o+"_fromMontgomery"),t.exportFunction(o+"_toMontgomery"),t.exportFunction(o+"_eq"),t.exportFunction(o+"_inverse"),Gt(t,o),kt(t,o+"_exp",3*i,o+"_mul",o+"_square",o+"_copy",o+"_one"),t.exportFunction(o+"_exp"),t.exp
1ortFunction(o+"_timesScalar"),t.exportFunction(o+"_batchInverse"),t.exportFunction(o+"_isNegative"),o};const Rt=function(t,a,o,e,i,c,l,n){const s=t.addFunction(a);s.addParam("base","i32"),s.addParam("scalar","i32"),s.addParam("scalarLength","i32"),s.addParam("r","i32"),s.addLocal("old0","i32"),s.addLocal("nbits","i32"),s.addLocal("i","i32"),s.addLocal("last","i32"),s.addLocal("cur","i32"),s.addLocal("carry","i32"),s.addLocal("p","i32");const r=s.getCodeBuilder(),d=r.i32_const(t.alloc(o));function _(t){return r.i32_and(r.i32_shr_u(r.i32_load(r.i32_add(r.getLocal("scalar"),r.i32_and(r.i32_shr_u(t,r.i32_const(3)),r.i32_const(4294967292)))),r.i32_and(t,r.i32_const(31))),r.i32_const(1))}function u(t){return[...r.i32_store8(r.getLocal("p"),r.i32_const(t)),...r.setLocal("p",r.i32_add(r.getLocal("p"),r.i32_const(1)))]}s.addCode(r.if(r.i32_eqz(r.getLocal("scalarLength")),[...r.call(n,r.getLocal("r")),...r.ret([])]),r.setLocal("nbits",r.i32_shl(r.getLocal("scalarLength"),r.i32_const(3))),r.setLocal("old0",r.i32_load(r.i32_const(0))),r.setLocal("p",r.getLocal("old0")),r.i32_store(r.i32_const(0),r.i32_and(r.i32_add(r.i32_add(r.getLocal("old0"),r.i32_const(32)),r.getLocal("nbits")),r.i32_const(4294967288))),r.setLocal("i",r.i32_const(1)),r.setLocal("last",_(r.i32_const(0))),r.setLocal("carry",r.i32_const(0)),r.block(r.loop(r.br_if(1,r.i32_eq(r.getLocal("i"),r.getLocal("nbits"))),r.setLocal("cur",_(r.getLocal("i"))),r.if(r.getLocal("last"),r.if(r.getLocal("cur"),r.if(r.getLocal("carry"),[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(1)),...u(1)],[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(1)),...u(255)]),r.if(r.getLocal("carry"),[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(1)),...u(255)],[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(0)),...u(1)])),r.if(r.getLocal("cur"),r.if(r.getLocal("carry"),[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(1)),...u(0)],[...r.setLocal("last",r.i32_const(1)),...r.setLocal("carry",r.i32_const(0)),...u(0)]),r.if(r.getLocal("carry"),[...r.setLocal("last",r.i32_const(1)),...r.setLocal("carry",r.i32_const(0)),...u(0)],[...r.setLocal("last",r.i32_const(0)),...r.setLocal("carry",r.i32_const(0)),...u(0)]))),r.setLocal("i",r.i32_add(r.getLocal("i"),r.i32_const(1))),r.br(0))),r.if(r.getLocal("last"),r.if(r.getLocal("carry"),[...u(255),...u(0),...u(1)],[...u(1)]),r.if(r.getLocal("carry"),[...u(0),...u(1)])),r.setLocal("p",r.i32_sub(r.getLocal("p"),r.i32_const(1))),r.call(l,r.getLocal("base"),d),r.call(n,r.getLocal("r")),r.block(r.loop(r.call(i,r.getLocal("r"),r.getLocal("r")),r.setLocal("cur",r.i32_load8_u(r.getLocal("p"))),r.if(r.getLocal("cur"),r.if(r.i32_eq(r.getLocal("cur"),r.i32_const(1)),r.call(e,r.getLocal("r"),d,r.getLocal("r")),r.call(c,r.getLocal("r"),d,r.getLocal("r")))),r.br_if(1,r.i32_eq(r.getLocal("old0"),r.getLocal("p"))),r.setLocal("p",r.i32_sub(r.getLocal("p"),r.i32_const(1))),r.br(0))),r.i32_store(r.i32_const(0),r.getLocal("old0")))},jt=at,Ut=function(t,a,o,e,i){const c=8*t.modules[a].n64;function l(){const e=t.addFunction(o);e.addParam("pBases","i32"),e.addParam("pScalars","i32"),e.addParam("scalarSize","i32"),e.addParam("n","i32"),e.addParam("pr","i32"),e.addLocal("chunkSize","i32"),e.addLocal("nChunks","i32"),e.addLocal("itScalar","i32"),e.addLocal("endScalar","i32"),e.addLocal("itBase","i32"),e.addLocal("itBit","i32"),e.addLocal("i","i32"),e.addLocal("j","i32"),e.addLocal("nTable","i32"),e.addLocal("pTable","i32"),e.addLocal("idx","i32"),e.addLocal("pIdxTable","i32");const i=e.getCodeBuilder(),l=i.i32_const(t.alloc(c)),n=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]);e.addCode(i.call(a+"_zero",i.getLocal("pr")),i.if(i.i32_eqz(i.getLocal("n")),i.ret([])),i.setLocal("chunkSize",i.i32_load8_u(i.i32_clz(i.getLocal("n")),n)),i.setLocal("nChunks",i.i32_add(i.i32_div_u(i.i32_sub(i.i32_shl(i.getLocal("scalarSize"),i.i32_const(3)),i.i32_const(1)),i.getLocal("chunkSize")),i.i32_const(1))),i.setLocal("itBit",i.i32_mul(i.i32_sub(i.getLocal("nChunks"),i.i32_const(1)),i.getLocal("chunkSize"))),i.block(i.loop(i.br_if(1,i.i32_lt_s(i.getLocal("itBit"),i.i32_const(0))),i.if(i.i32_eqz(i.call(a+"_isZero",i.getLocal("pr"))),[...i.set
1Local("j",i.i32_const(0)),...i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("j"),i.getLocal("chunkSize"))),i.call(a+"_double",i.getLocal("pr"),i.getLocal("pr")),i.setLocal("j",i.i32_add(i.getLocal("j"),i.i32_const(1))),i.br(0)))]),i.call(o+"_chunk",i.getLocal("pBases"),i.getLocal("pScalars"),i.getLocal("scalarSize"),i.getLocal("n"),i.getLocal("itBit"),i.getLocal("chunkSize"),l),i.call(a+"_add",i.getLocal("pr"),l,i.getLocal("pr")),i.setLocal("itBit",i.i32_sub(i.getLocal("itBit"),i.getLocal("chunkSize"))),i.br(0))))}!function(){const a=t.addFunction(o+"_getChunk");a.addParam("pScalar","i32"),a.addParam("scalarSize","i32"),a.addParam("startBit","i32"),a.addParam("chunkSize","i32"),a.addLocal("bitsToEnd","i32"),a.addLocal("mask","i32"),a.setReturnType("i32");const e=a.getCodeBuilder();a.addCode(e.setLocal("bitsToEnd",e.i32_sub(e.i32_mul(e.getLocal("scalarSize"),e.i32_const(8)),e.getLocal("startBit"))),e.if(e.i32_gt_s(e.getLocal("chunkSize"),e.getLocal("bitsToEnd")),e.setLocal("mask",e.i32_sub(e.i32_shl(e.i32_const(1),e.getLocal("bitsToEnd")),e.i32_const(1))),e.setLocal("mask",e.i32_sub(e.i32_shl(e.i32_const(1),e.getLocal("chunkSize")),e.i32_const(1)))),e.i32_and(e.i32_shr_u(e.i32_load(e.i32_add(e.getLocal("pScalar"),e.i32_shr_u(e.getLocal("startBit"),e.i32_const(3))),0,0),e.i32_and(e.getLocal("startBit"),e.i32_const(7))),e.getLocal("mask")))}(),function(){const e=t.addFunction(o+"_reduceTable");e.addParam("pTable","i32"),e.addParam("p","i32"),e.addLocal("half","i32"),e.addLocal("it1","i32"),e.addLocal("it2","i32"),e.addLocal("pAcc","i32");const i=e.getCodeBuilder();e.addCode(i.if(i.i32_eq(i.getLocal("p"),i.i32_const(1)),i.ret([])),i.setLocal("half",i.i32_shl(i.i32_const(1),i.i32_sub(i.getLocal("p"),i.i32_const(1)))),i.setLocal("it1",i.getLocal("pTable")),i.setLocal("it2",i.i32_add(i.getLocal("pTable"),i.i32_mul(i.getLocal("half"),i.i32_const(c)))),i.setLocal("pAcc",i.i32_sub(i.getLocal("it2"),i.i32_const(c))),i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("it1"),i.getLocal("pAcc"))),i.call(a+"_add",i.getLocal("it1"),i.getLocal("it2"),i.getLocal("it1")),i.call(a+"_add",i.getLocal("pAcc"),i.getLocal("it2"),i.getLocal("pAcc")),i.setLocal("it1",i.i32_add(i.getLocal("it1"),i.i32_const(c))),i.setLocal("it2",i.i32_add(i.getLocal("it2"),i.i32_const(c))),i.br(0))),i.call(o+"_reduceTable",i.getLocal("pTable"),i.i32_sub(i.getLocal("p"),i.i32_const(1))),i.setLocal("p",i.i32_sub(i.getLocal("p"),i.i32_const(1))),i.block(i.loop(i.br_if(1,i.i32_eqz(i.getLocal("p"))),i.call(a+"_double",i.getLocal("pAcc"),i.getLocal("pAcc")),i.setLocal("p",i.i32_sub(i.getLocal("p"),i.i32_const(1))),i.br(0))),i.call(a+"_add",i.getLocal("pTable"),i.getLocal("pAcc"),i.getLocal("pTable")))}(),function(){const l=t.addFunction(o+"_chunk");l.addParam("pBases","i32"),l.addParam("pScalars","i32"),l.addParam("scalarSize","i32"),l.addParam("n","i32"),l.addParam("startBit","i32"),l.addParam("chunkSize","i32"),l.addParam("pr","i32"),l.addLocal("nChunks","i32"),l.addLocal("itScalar","i32"),l.addLocal("endScalar","i32"),l.addLocal("itBase","i32"),l.addLocal("i","i32"),l.addLocal("j","i32"),l.addLocal("nTable","i32"),l.addLocal("pTable","i32"),l.addLocal("idx","i32"),l.addLocal("pIdxTable","i32");const n=l.getCodeBuilder();l.addCode(n.if(n.i32_eqz(n.getLocal("n")),[...n.call(a+"_zero",n.getLocal("pr")),...n.ret([])]),n.setLocal("nTable",n.i32_shl(n.i32_const(1),n.getLocal("chunkSize"))),n.setLocal("pTable",n.i32_load(n.i32_const(0))),n.i32_store(n.i32_const(0),n.i32_add(n.getLocal("pTable"),n.i32_mul(n.getL
1ocal("nTable"),n.i32_const(c)))),n.setLocal("j",n.i32_const(0)),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("j"),n.getLocal("nTable"))),n.call(a+"_zero",n.i32_add(n.getLocal("pTable"),n.i32_mul(n.getLocal("j"),n.i32_const(c)))),n.setLocal("j",n.i32_add(n.getLocal("j"),n.i32_const(1))),n.br(0))),n.setLocal("itBase",n.getLocal("pBases")),n.setLocal("itScalar",n.getLocal("pScalars")),n.setLocal("endScalar",n.i32_add(n.getLocal("pScalars"),n.i32_mul(n.getLocal("n"),n.getLocal("scalarSize")))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("itScalar"),n.getLocal("endScalar"))),n.setLocal("idx",n.call(o+"_getChunk",n.getLocal("itScalar"),n.getLocal("scalarSize"),n.getLocal("startBit"),n.getLocal("chunkSize"))),n.if(n.getLocal("idx"),[...n.setLocal("pIdxTable",n.i32_add(n.getLocal("pTable"),n.i32_mul(n.i32_sub(n.getLocal("idx"),n.i32_const(1)),n.i32_const(c)))),...n.call(e,n.getLocal("pIdxTable"),n.getLocal("itBase"),n.getLocal("pIdxTable"))]),n.setLocal("itScalar",n.i32_add(n.getLocal("itScalar"),n.getLocal("scalarSize"))),n.setLocal("itBase",n.i32_add(n.getLocal("itBase"),n.i32_const(i))),n.br(0))),n.call(o+"_reduceTable",n.getLocal("pTable"),n.getLocal("chunkSize")),n.call(a+"_copy",n.getLocal("pTable"),n.getLocal("pr")),n.i32_store(n.i32_const(0),n.getLocal("pTable")))}(),l(),t.exportFunction(o),t.exportFunction(o+"_chunk")};var Zt=function(t,a,o,e){const i=t.modules[o].n64,c=8*i;if(t.modules[a])return a;return t.modules[a]={n64:3*i},function(){const e=t.addFunction(a+"_isZeroAffine");e.addParam("p1","i32"),e.setReturnType("i32");const i=e.getCodeBuilder();e.addCode(i.i32_and(i.call(o+"_isZero",i.getLocal("p1")),i.call(o+"_isZero",i.i32_add(i.getLocal("p1"),i.i32_const(c)))))}(),function(){const e=t.addFunction(a+"_isZero");e.addParam("p1","i32"),e.setReturnType("i32");const i=e.getCodeBuilder();e.addCode(i.call(o+"_isZero",i.i32_add(i.getLocal("p1"),i.i32_const(2*c))))}(),function(){const e=t.addFunction(a+"_zeroAffine");e.addParam("pr","i32");const i=e.getCodeBuilder();e.addCode(i.call(o+"_zero",i.getLocal("pr"))),e.addCode(i.call(o+"_zero",i.i32_add(i.getLocal("pr"),i.i32_const(c))))}(),function(){const e=t.addFunction(a+"_zero");e.addParam("pr","i32");const i=e.getCodeBuilder();e.addCode(i.call(o+"_zero",i.getLocal("pr"))),e.addCode(i.call(o+"_one",i.i32_add(i.getLocal("pr"),i.i32_const(c)))),e.addCode(i.call(o+"_zero",i.i32_add(i.getLocal("pr"),i.i32_const(2*c))))}(),function(){const o=t.addFunction(a+"_copyAffine");o.addParam("ps","i32"),o.addParam("pd","i32");const e=o.getCodeBuilder();for(let t=0;t<2*i;t++)o.addCode(e.i64_store(e.getLocal("pd"),8*t,e.i64_load(e.getLocal("ps"),8*t)))}(),function(){const o=t.addFunction(a+"_copy");o.addParam("ps","i32"),o.addParam("pd","i32");const e=o.getCodeBuilder();for(let t=0;t<3*i;t++)o.addCode(e.i64_store(e.getLocal("pd"),8*t,e.i64_load(e.getLocal("ps"),8*t)))}(),function(){const e=t.addFunction(a+"_toJacobian");e.addParam("p1","i32"),e.addParam("pr","i32");const i=e.getCodeBuilder(),l=i.getLocal("p1"),n=i.i32_add(i.getLocal("p1"),i.i32_const(c)),s=i.getLocal("pr"),r=i.i32_add(i.getLocal("pr"),i.i32_const(c)),d=i.i32_add(i.getLocal("pr"),i.i32_const(2*c));e.addCode(i.if(i.call(a+"_isZeroAffine",i.getLocal("p1")),i.call(a+"_zero",i.getLocal("pr")),[...i.call(o+"_one",d),...i.call(o+"_copy",n,r),...i.call(o+"_copy",l,s)]))}(),function(){const e=t.addFunction(a+"_eqAffine");e.addParam("p1","i32"),e.addParam("p2","i32"),e.setReturnType("i32"),e.addLocal("z1","i32");const i=e.getCodeBuilder();e.addCode(i.ret(i.i32_and(i.call(o+"_eq",i.getLocal("p1"),i.getLocal("p2")),i.call(o+"_eq",i.i32_add(i.getLocal("p1"),i.i32_const(c)),i.i32_add(i.getLocal("p2"),i.i32_const(c))))))}(),function(){const e=t.addFunction(a+"_eqMixed");e.addParam("p1","i32"),e.addParam("p2","i32"),e.setReturnType("i32"),e.addLocal("z1","i32");const i=e.getCodeBuilder(),l=i.getLocal("p1"),n=i.i32_add(i.getLocal("p1"),i.i32_const(c));e.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*c))));const s=i.getLocal("z1"),r=i.getLocal("p2"),d=i.i32_add(i.getLocal("p2"),i.i32_const(c)),_=i.i32_const(t.alloc(c)),u=i.i32_const(t.alloc(c)),g=i.i32_const(t.alloc(c)),L=i.i32_const(t.alloc(c));e.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),i.ret(i.call(a+"_isZeroAffine",i.getLocal("p2")))),i.if(i.call(a+"_isZeroAffine",i.getLocal("p2")),i.ret(i.i32_const(0))),i.if(i.call(o+"_isOne",s),i.ret(i.call(a+"_eqAffine",i.getLocal("p1"),i.getLocal("p2")))),i.call(o+"_square",s,_),i.call(o+"_mul",r,_,u),i.call(o+"_mul",s,_,g),i.call(o+"_mul",d,g,L),i.if(i.call(o+"_eq",l,u),i.if(i.call(o+"_eq",n,L),i.ret(i.i32_const(1)))),i.ret(i.i32_const(0)))}(),function(){const e=t.addFunction(a+"_eq");e.addParam("p1","i32"),e.addParam("p2","i32"),e.setReturnType("i32"),e.addLocal("z1","i32"),e.addLocal("z2","i32");const i=e.getCodeBuilder(),l=i.getLocal("p1"),n=i.i32_add(i.getLocal("p1"),i.i32_const(c));e.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*c))));
1const s=i.getLocal("z1"),r=i.getLocal("p2"),d=i.i32_add(i.getLocal("p2"),i.i32_const(c));e.addCode(i.setLocal("z2",i.i32_add(i.getLocal("p2"),i.i32_const(2*c))));const _=i.getLocal("z2"),u=i.i32_const(t.alloc(c)),g=i.i32_const(t.alloc(c)),L=i.i32_const(t.alloc(c)),p=i.i32_const(t.alloc(c)),f=i.i32_const(t.alloc(c)),m=i.i32_const(t.alloc(c)),h=i.i32_const(t.alloc(c)),b=i.i32_const(t.alloc(c));e.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),i.ret(i.call(a+"_isZero",i.getLocal("p2")))),i.if(i.call(a+"_isZero",i.getLocal("p2")),i.ret(i.i32_const(0))),i.if(i.call(o+"_isOne",s),i.ret(i.call(a+"_eqMixed",i.getLocal("p2"),i.getLocal("p1")))),i.if(i.call(o+"_isOne",_),i.ret(i.call(a+"_eqMixed",i.getLocal("p1"),i.getLocal("p2")))),i.call(o+"_square",s,u),i.call(o+"_square",_,g),i.call(o+"_mul",l,g,L),i.call(o+"_mul",r,u,p),i.call(o+"_mul",s,u,f),i.call(o+"_mul",_,g,m),i.call(o+"_mul",n,m,h),i.call(o+"_mul",d,f,b),i.if(i.call(o+"_eq",L,p),i.if(i.call(o+"_eq",h,b),i.ret(i.i32_const(1)))),i.ret(i.i32_const(0)))}(),function(){const e=t.addFunction(a+"_doubleAffine");e.addParam("p1","i32"),e.addParam("pr","i32");const i=e.getCodeBuilder(),l=i.getLocal("p1"),n=i.i32_add(i.getLocal("p1"),i.i32_const(c)),s=i.getLocal("pr"),r=i.i32_add(i.getLocal("pr"),i.i32_const(c)),d=i.i32_add(i.getLocal("pr"),i.i32_const(2*c)),_=i.i32_const(t.alloc(c)),u=i.i32_const(t.alloc(c)),g=i.i32_const(t.alloc(c)),L=i.i32_const(t.alloc(c)),p=i.i32_const(t.alloc(c)),f=i.i32_const(t.alloc(c));e.addCode(i.if(i.call(a+"_isZeroAffine",i.getLocal("p1")),[...i.call(a+"_toJacobian",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])]),i.call(o+"_square",l,_),i.call(o+"_square",n,u),i.call(o+"_square",u,g),i.call(o+"_add",l,u,L),i.call(o+"_square",L,L),i.call(o+"_sub",L,_,L),i.call(o+"_sub",L,g,L),i.call(o+"_add",L,L,L),i.call(o+"_add",_,_,p),i.call(o+"_add",p,_,p),i.call(o+"_add",n,n,d),i.call(o+"_square",p,s),i.call(o+"_sub",s,L,s),i.call(o+"_sub",s,L,s),i.call(o+"_add",g,g,f),i.call(o+"_add",f,f,f),i.call(o+"_add",f,f,f),i.call(o+"_sub",L,s,r),i.call(o+"_mul",r,p,r),i.call(o+"_sub",r,f,r))}(),function(){const e=t.addFunction(a+"_double");e.addParam("p1","i32"),e.addParam("pr","i32");const i=e.getCodeBuilder(),l=i.getLocal("p1"),n=i.i32_add(i.getLocal("p1"),i.i32_const(c)),s=i.i32_add(i.getLocal("p1"),i.i32_const(2*c)),r=i.getLocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(c)),_=i.i32_add(i.getLocal("pr"),i.i32_const(2*c)),u=i.i32_const(t.alloc(c)),g=i.i32_const(t.alloc(c)),L=i.i32_const(t.alloc(c)),p=i.i32_const(t.alloc(c)),f=i.i32_const(t.alloc(c)),m=i.i32_const(t.alloc(c)),h=i.i32_const(t.alloc(c)),b=i.i32_const(t.alloc(c));e.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),[...i.call(a+"_copy",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])]),i.if(i.call(o+"_isOne",s),[...i.ret(i.call(a+"_doubleAffine",i.getLocal("p1"),i.getLocal("pr"))),...i.ret([])]),i.call(o+"_square",l,u),i.call(o+"_square",n,g),i.call(o+"_square",g,L),i.call(o+"_add",l,g,p),i.call(o+"_square",p,p),i.call(o+"_sub",p,u,p),i.call(o+"_sub",p,L,p),i.call(o+"_add",p,p,p),i.call(o+"_add",u,u,f),i.call(o+"_add",f,u,f),i.call(o+"_square",f,m),i.call(o+"_mul",n,s,h),i.call(o+"_add",p,p,r),i.call(o+"_sub",m,r,r),i.call(o+"_add",L,L,b),i.call(o+"_add",b,b,b),i.call(o+"_add",b,b,b),i.call(o+"_sub",p,r,d),i.call(o+"_mul",d,f,d),i.call(o+"_sub",d,b,d),i.call(o+"_add",h,h,_))}(),function(){const e=t.addFunction(a+"_addAffine");e.addParam("p1","i32"),e.addParam("p2","i32"),e.addParam("pr","i32"),e.addLocal("z1","i32");const i=e.getCodeBuilder(),l=i.getLocal("p1"),n=i.i32_add(i.getLocal("p1"),i.i32_const(c));e.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*c))));const s=i.getLocal("p2"),r=i.i32_add(i.getLocal("p2"),i.i32_const(c)),d=i.getLocal("pr"),_=i.i32_add(i.getLocal("pr"),i.i32_const(c)),u=i.i32_add(i.getLocal("pr"),i.i32_const(2*c)),g=i.i32_const(t.alloc(c)),L=i.i32_const(t.alloc(c)),p=i.i32_const(t.alloc(c)),f=i.i32_const(t.alloc(c)),m=i.i32_const(t.alloc(c)),h=i.i32_const(t.alloc(c)),b=i.i32_const(t.alloc(c)),x=i.i32_const(t.alloc(c)),y=i.i32_const(t.alloc(c)),F=i.i32_const(t.alloc(c));e.addCode(i.if(i.call(a+"_isZeroAffine",i.getLocal("p1")),[...i.call(a+"_copyAffine",i.getLocal("p2"),i.getLocal("pr")),...i.call(o+"_one",i.i32_add(i.getLocal("pr"),i.i32_const(2*c))),...i.ret([])]),i.if(i.call(a+"_isZeroAffine",i.getLocal("p2")),[...i.call(a+"_copyAffine",i.getLocal("p1"),i.getLocal("pr")),...i.call(o+"_one",i.i32_add(i.getLocal("pr"),i.i32_const(2*c))),...i.ret([])]),i.if(i.call(o+"_eq",l,s),i.if(i.call(o+"_eq",n,r),[...i.call(a+"_doubleAffine",i.getLocal("p2"),i.getLocal("pr")),...i.ret([])])),i.call(o+"_sub",s,l,g),i.call(o+"_sub",r,n,p),i.call(o+"_square",g,L),i.call(o+"_add",L,L,f),i.call(o+"_add",f,f,f),i.call(o+"_mul",g,f,m),i.call(o+"_add",p,p,h),i.call(o+"_mul",l,f,x),i.call(o+"_square",h,b),i.call(o+"_add",x,x,y),i.call(o+"_sub",b,m,d),i.call(o+"_sub",d,y,d),i.call(o+"_mul",n,m,F),i.call(o+"_add",F,F,F),i.call(o+"_sub",x,d,_),i.call(o+"_mul",_,h,_),i.call(o+"_sub",_,F,_),i.call(o+"_add",g,g,u))}(),function(){const e=t.addFunction(a+"_addMixed");e.addParam("p1","i32"),e.addParam("p2","i32"),e.addParam("pr","i32"),e.addLocal("z1","i32");const i=e.getCodeBuilder(),l=i.getLocal("p1"),n=i.i32_add(i.getLocal("p1"),i.i32_const(c));e.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*c))));
1const s=i.getLocal("z1"),r=i.getLocal("p2"),d=i.i32_add(i.getLocal("p2"),i.i32_const(c)),_=i.getLocal("pr"),u=i.i32_add(i.getLocal("pr"),i.i32_const(c)),g=i.i32_add(i.getLocal("pr"),i.i32_const(2*c)),L=i.i32_const(t.alloc(c)),p=i.i32_const(t.alloc(c)),f=i.i32_const(t.alloc(c)),m=i.i32_const(t.alloc(c)),h=i.i32_const(t.alloc(c)),b=i.i32_const(t.alloc(c)),x=i.i32_const(t.alloc(c)),y=i.i32_const(t.alloc(c)),F=i.i32_const(t.alloc(c)),C=i.i32_const(t.alloc(c)),B=i.i32_const(t.alloc(c)),P=i.i32_const(t.alloc(c)),A=i.i32_const(t.alloc(c)),w=i.i32_const(t.alloc(c));e.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),[...i.call(a+"_copyAffine",i.getLocal("p2"),i.getLocal("pr")),...i.call(o+"_one",i.i32_add(i.getLocal("pr"),i.i32_const(2*c))),...i.ret([])]),i.if(i.call(a+"_isZeroAffine",i.getLocal("p2")),[...i.call(a+"_copy",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])]),i.if(i.call(o+"_isOne",s),[...i.call(a+"_addAffine",l,r,_),...i.ret([])]),i.call(o+"_square",s,L),i.call(o+"_mul",r,L,p),i.call(o+"_mul",s,L,f),i.call(o+"_mul",d,f,m),i.if(i.call(o+"_eq",l,p),i.if(i.call(o+"_eq",n,m),[...i.call(a+"_doubleAffine",i.getLocal("p2"),i.getLocal("pr")),...i.ret([])])),i.call(o+"_sub",p,l,h),i.call(o+"_sub",m,n,x),i.call(o+"_square",h,b),i.call(o+"_add",b,b,y),i.call(o+"_add",y,y,y),i.call(o+"_mul",h,y,F),i.call(o+"_add",x,x,C),i.call(o+"_mul",l,y,P),i.call(o+"_square",C,B),i.call(o+"_add",P,P,A),i.call(o+"_sub",B,F,_),i.call(o+"_sub",_,A,_),i.call(o+"_mul",n,F,w),i.call(o+"_add",w,w,w),i.call(o+"_sub",P,_,u),i.call(o+"_mul",u,C,u),i.call(o+"_sub",u,w,u),i.call(o+"_add",s,h,g),i.call(o+"_square",g,g),i.call(o+"_sub",g,L,g),i.call(o+"_sub",g,b,g))}(),function(){const e=t.addFunction(a+"_add");e.addParam("p1","i32"),e.addParam("p2","i32"),e.addParam("pr","i32"),e.addLocal("z1","i32"),e.addLocal("z2","i32");const i=e.getCodeBuilder(),l=i.getLocal("p1"),n=i.i32_add(i.getLocal("p1"),i.i32_const(c));e.addCode(i.setLocal("z1",i.i32_add(i.getLocal("p1"),i.i32_const(2*c))));const s=i.getLocal("z1"),r=i.getLocal("p2"),d=i.i32_add(i.getLocal("p2"),i.i32_const(c));e.addCode(i.setLocal("z2",i.i32_add(i.getLocal("p2"),i.i32_const(2*c))));const _=i.getLocal("z2"),u=i.getLocal("pr"),g=i.i32_add(i.getLocal("pr"),i.i32_const(c)),L=i.i32_add(i.getLocal("pr"),i.i32_const(2*c)),p=i.i32_const(t.alloc(c)),f=i.i32_const(t.alloc(c)),m=i.i32_const(t.alloc(c)),h=i.i32_const(t.alloc(c)),b=i.i32_const(t.alloc(c)),x=i.i32_const(t.alloc(c)),y=i.i32_const(t.alloc(c)),F=i.i32_const(t.alloc(c)),C=i.i32_const(t.alloc(c)),B=i.i32_const(t.alloc(c)),P=i.i32_const(t.alloc(c)),A=i.i32_const(t.alloc(c)),w=i.i32_const(t.alloc(c)),q=i.i32_const(t.alloc(c)),v=i.i32_const(t.alloc(c)),I=i.i32_const(t.alloc(c)),O=i.i32_const(t.alloc(c));e.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),[...i.call(a+"_copy",i.getLocal("p2"),i.getLocal("pr")),...i.ret([])]),i.if(i.call(a+"_isZero",i.getLocal("p2")),[...i.call(a+"_copy",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])]),i.if(i.call(o+"_isOne",s),[...i.call(a+"_addMixed",r,l,u),...i.ret([])]),i.if(i.call(o+"_isOne",_),[...i.call(a+"_addMixed",l,r,u),...i.ret([])]),i.call(o+"_square",s,p),i.call(o+"_square",_,f),i.call(o+"_mul",l,f,m),i.call(o+"_mul",r,p,h),i.call(o+"_mul",s,p,b),i.call(o+"_mul",_,f,x),i.call(o+"_mul",n,x,y),i.call(o+"_mul",d,b,F),i.if(i.call(o+"_eq",m,h),i.if(i.call(o+"_eq",y,F),[...i.call(a+"_double",i.getLocal("p1"),i.getLocal("pr")),...i.ret([])])),i.call(o+"_sub",h,m,C),i.call(o+"_sub",F,y,B),i.call(o+"_add",C,C,P),i.call(o+"_square",P,P),i.call(o+"_mul",C,P,A),i.call(o+"_add",B,B,w),i.call(o+"_mul",m,P,v),i.call(o+"_square",w,q),i.call(o+"_add",v,v,I),i.call(o+"_sub",q,A,u),i.call(o+"_sub",u,I,u),i.call(o+"_mul",y,A,O),i.call(o+"_add",O,O,O),i.call(o+"_sub",v,u,g),i.call(o+"_mul",g,w,g),i.call(o+"_sub",g,O,g),i.call(o+"_add",s,_,L),i.call(o+"_square",L,L),i.call(o+"_sub",L,p,L),i.call(o+"_sub",L,f,L),i.call(o+"_mul",L,C,L))}(),function(){const e=t.addFunction(a+"_negAffine");e.addParam("p1","i32"),e.addParam("pr","i32");const i=e.getCodeBuilder(),l=i.getLocal("p1"),n=i.i32_add(i.getLocal("p1"),i.i32_const(c)),s=i.getLocal("pr"),r=i.i32_add(i.getLocal("pr"),i.i32_const(c));e.addCode(i.call(o+"_copy",l,s),i.call(o+"_neg",n,r))}(),function(){const e=t.addFunction(a+"_neg");e.addParam("p1","i32"),e.addParam("pr","i32");const i=e.getCodeBuilder(),l=i.getLocal("p1"),n=i.i32_add(i.getLocal("p1"),i.i32_const(c)),s=i.i32_add(i.getLocal("p1"),i.i32_const(2*c)),r=i.getL
1ocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(c)),_=i.i32_add(i.getLocal("pr"),i.i32_const(2*c));e.addCode(i.call(o+"_copy",l,r),i.call(o+"_neg",n,d),i.call(o+"_copy",s,_))}(),function(){const o=t.addFunction(a+"_subAffine");o.addParam("p1","i32"),o.addParam("p2","i32"),o.addParam("pr","i32");const e=o.getCodeBuilder(),i=e.i32_const(t.alloc(3*c));o.addCode(e.call(a+"_negAffine",e.getLocal("p2"),i),e.call(a+"_addAffine",e.getLocal("p1"),i,e.getLocal("pr")))}(),function(){const o=t.addFunction(a+"_subMixed");o.addParam("p1","i32"),o.addParam("p2","i32"),o.addParam("pr","i32");const e=o.getCodeBuilder(),i=e.i32_const(t.alloc(3*c));o.addCode(e.call(a+"_negAffine",e.getLocal("p2"),i),e.call(a+"_addMixed",e.getLocal("p1"),i,e.getLocal("pr")))}(),function(){const o=t.addFunction(a+"_sub");o.addParam("p1","i32"),o.addParam("p2","i32"),o.addParam("pr","i32");const e=o.getCodeBuilder(),i=e.i32_const(t.alloc(3*c));o.addCode(e.call(a+"_neg",e.getLocal("p2"),i),e.call(a+"_add",e.getLocal("p1"),i,e.getLocal("pr")))}(),function(){const e=t.addFunction(a+"_fromMontgomeryAffine");e.addParam("p1","i32"),e.addParam("pr","i32");const i=e.getCodeBuilder();e.addCode(i.call(o+"_fromMontgomery",i.getLocal("p1"),i.getLocal("pr")));for(let t=1;t<2;t++)e.addCode(i.call(o+"_fromMontgomery",i.i32_add(i.getLocal("p1"),i.i32_const(t*c)),i.i32_add(i.getLocal("pr"),i.i32_const(t*c))))}(),function(){const e=t.addFunction(a+"_fromMontgomery");e.addParam("p1","i32"),e.addParam("pr","i32");const i=e.getCodeBuilder();e.addCode(i.call(o+"_fromMontgomery",i.getLocal("p1"),i.getLocal("pr")));for(let t=1;t<3;t++)e.addCode(i.call(o+"_fromMontgomery",i.i32_add(i.getLocal("p1"),i.i32_const(t*c)),i.i32_add(i.getLocal("pr"),i.i32_const(t*c))))}(),function(){const e=t.addFunction(a+"_toMontgomeryAffine");e.addParam("p1","i32"),e.addParam("pr","i32");const i=e.getCodeBuilder();e.addCode(i.call(o+"_toMontgomery",i.getLocal("p1"),i.getLocal("pr")));for(let t=1;t<2;t++)e.addCode(i.call(o+"_toMontgomery",i.i32_add(i.getLocal("p1"),i.i32_const(t*c)),i.i32_add(i.getLocal("pr"),i.i32_const(t*c))))}(),function(){const e=t.addFunction(a+"_toMontgomery");e.addParam("p1","i32"),e.addParam("pr","i32");const i=e.getCodeBuilder();e.addCode(i.call(o+"_toMontgomery",i.getLocal("p1"),i.getLocal("pr")));for(let t=1;t<3;t++)e.addCode(i.call(o+"_toMontgomery",i.i32_add(i.getLocal("p1"),i.i32_const(t*c)),i.i32_add(i.getLocal("pr"),i.i32_const(t*c))))}(),function(){const e=t.addFunction(a+"_toAffine");e.addParam("p1","i32"),e.addParam("pr","i32");const i=e.getCodeBuilder(),l=i.getLocal("p1"),n=i.i32_add(i.getLocal("p1"),i.i32_const(c)),s=i.i32_add(i.getLocal("p1"),i.i32_const(2*c)),r=i.getLocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(c)),_=i.i32_const(t.alloc(c)),u=i.i32_const(t.alloc(c)),g=i.i32_const(t.alloc(c));e.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),[...i.call(o+"_zero",r),...i.call(o+"_zero",d)],[...i.call(o+"_inverse",s,_),...i.call(o+"_square",_,u),...i.call(o+"_mul",_,u,g),...i.call(o+"_mul",l,u,r),...i.call(o+"_mul",n,g,d)]))}(),function(){const i=t.addFunction(a+"_inCurveAffine");i.addParam("pIn","i32"),i.setReturnType("i32");const l=i.getCodeBuilder(),n=l.getLocal("pIn"),s=l.i32_add(l.getLocal("pIn"),l.i32_const(c)),r=l.i32_const(t.alloc(c)),d=l.i32_const(t.alloc(c));i.addCode(l.call(o+"_square",s,r),l.call(o+"_square",n,d),l.call(o+"_mul",n,d,d),l.call(o+"_add",d,l.i32_const(e),d),l.ret(l.call(o+"_eq",r,d)))}(),function(){const o=t.addFunction(a+"_inCurve");o.addParam("pIn","i32"),o.setReturnType("i32");const e=o.getCodeBuilder(),i=e.i32_const(t.alloc(2*c));o.addCode(e.call(a+"_toAffine",e.getLocal("pIn"),i),e.ret(e.call(a+"_inCurveAffine",i)))}(),function(){const e=t.addFunction(a+"_batchToAffine");e.addParam("pIn","i32"),e.addParam("n","i32"),e.addParam("pOut","i32"),e.addLocal("pAux","i32"),e.addLocal("itIn","i32"),e.addLocal("itAux","i32"),e.addLocal("itOut","i32"),e.addLocal("i","i32");const i=e.getCodeBuilder(),l=i.i32_const(t.alloc(c));e.addCode(i.setLocal("pAux",i.i32_load(i.i32_const(0))),i.i32_store(i.i32_const(0),i.i32_add(i.getLocal("pAux"),i.i32_mul(i.getL
1ocal("n"),i.i32_const(c)))),i.call(o+"_batchInverse",i.i32_add(i.getLocal("pIn"),i.i32_const(2*c)),i.i32_const(3*c),i.getLocal("n"),i.getLocal("pAux"),i.i32_const(c)),i.setLocal("itIn",i.getLocal("pIn")),i.setLocal("itAux",i.getLocal("pAux")),i.setLocal("itOut",i.getLocal("pOut")),i.setLocal("i",i.i32_const(0)),i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("i"),i.getLocal("n"))),i.if(i.call(o+"_isZero",i.getLocal("itAux")),[...i.call(o+"_zero",i.getLocal("itOut")),...i.call(o+"_zero",i.i32_add(i.getLocal("itOut"),i.i32_const(c)))],[...i.call(o+"_mul",i.getLocal("itAux"),i.i32_add(i.getLocal("itIn"),i.i32_const(c)),l),...i.call(o+"_square",i.getLocal("itAux"),i.getLocal("itAux")),...i.call(o+"_mul",i.getLocal("itAux"),i.getLocal("itIn"),i.getLocal("itOut")),...i.call(o+"_mul",i.getLocal("itAux"),l,i.i32_add(i.getLocal("itOut"),i.i32_const(c)))]),i.setLocal("itIn",i.i32_add(i.getLocal("itIn"),i.i32_const(3*c))),i.setLocal("itOut",i.i32_add(i.getLocal("itOut"),i.i32_const(2*c))),i.setLocal("itAux",i.i32_add(i.getLocal("itAux"),i.i32_const(c))),i.setLocal("i",i.i32_add(i.getLocal("i"),i.i32_const(1))),i.br(0))),i.i32_store(i.i32_const(0),i.getLocal("pAux")))}(),function(){const e=t.addFunction(a+"_normalize");e.addParam("p1","i32"),e.addParam("pr","i32");const i=e.getCodeBuilder(),l=i.getLocal("p1"),n=i.i32_add(i.getLocal("p1"),i.i32_const(c)),s=i.i32_add(i.getLocal("p1"),i.i32_const(2*c)),r=i.getLocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(c)),_=i.i32_add(i.getLocal("pr"),i.i32_const(2*c)),u=i.i32_const(t.alloc(c)),g=i.i32_const(t.alloc(c)),L=i.i32_const(t.alloc(c));e.addCode(i.if(i.call(a+"_isZero",i.getLocal("p1")),i.call(a+"_zero",i.getLocal("pr")),[...i.call(o+"_inverse",s,u),...i.call(o+"_square",u,g),...i.call(o+"_mul",u,g,L),...i.call(o+"_mul",l,g,r),...i.call(o+"_mul",n,L,d),...i.call(o+"_one",_)]))}(),function(){const o=t.addFunction(a+"__reverseBytes");o.addParam("pIn","i32"),o.addParam("n","i32"),o.addParam("pOut","i32"),o.addLocal("itOut","i32"),o.addLocal("itIn","i32");const e=o.getCodeBuilder();o.addCode(e.setLocal("itOut",e.i32_sub(e.i32_add(e.getLocal("pOut"),e.getLocal("n")),e.i32_const(1))),e.setLocal("itIn",e.getLocal("pIn")),e.block(e.loop(e.br_if(1,e.i32_lt_s(e.getLocal("itOut"),e.getLocal("pOut"))),e.i32_store8(e.getLocal("itOut"),e.i32_load8_u(e.getLocal("itIn"))),e.setLocal("itOut",e.i32_sub(e.getLocal("itOut"),e.i32_const(1))),e.setLocal("itIn",e.i32_add(e.getLocal("itIn"),e.i32_const(1))),e.br(0))))}(),function(){const o=t.addFunction(a+"_LEMtoU");o.addParam("pIn","i32"),o.addParam("pOut","i32");const e=o.getCodeBuilder(),i=t.alloc(2*c),l=e.i32_const(i),n=e.i32_const(i),s=e.i32_const(i+c);o.addCode(e.if(e.call(a+"_isZeroAffine",e.getLocal("pIn")),[...e.call(a+"_zeroAffine",e.getLocal("pOut")),...e.ret([])]),e.call(a+"_fromMontgomeryAffine",e.getLocal("pIn"),l),e.call(a+"__reverseBytes",n,e.i32_const(c),e.getLocal("pOut")),e.call(a+"__reverseBytes",s,e.i32_const(c),e.i32_add(e.getLocal("pOut"),e.i32_const(c))))}(),function(){const e=t.addFunction(a+"_LEMtoC");e.addParam("pIn","i32"),e.addParam("pOut","i32");const i=e.getCodeBuilder(),l=i.i32_const(t.alloc(c));e.addCode(i.if(i.call(a+"_isZeroAffine",i.getLocal("pIn")),[...i.call(o+"_zero",i.getLocal("pOut")),...i.i32_store8(i.getLocal("pOut"),i.i32_const(64)),...i.ret([])]),i.call(o+"_fromMontgomery",i.getLocal("pIn"),l),i.call(a+"__reverseBytes",l,i.i32_const(c),i.getLocal("pOut")),i.if(i.i32_eq(i.call(o+"_sign",i.i32_add(i.getLocal("pIn"),i.i32_const(c))),i.i32_const(-1)),i.i32_store8(i.getLocal("pOut"),i.i32_or(i.i32_load8_u(i.getLocal("pOut")),i.i32_const(128)))))}(),function(){const o=t.addFunction(a+"_UtoLEM");o.addParam("pIn","i32"),o.addParam("pOut","i32");const e=o.getCodeBuilder(),i=t.alloc(2*c),l=e.i32_const(i),n=e.i32_const(i),s=e.i32_const(i+c);o.addCode(e.if(e.i32_and(e.i32_load8_u(e.getLocal("pIn")),e.i32_const(64)),[...e.call(a+"_zeroAffine",e.getLocal("pOut")),...e.ret([])]),e.call(a+"__reverseBytes",e.getLocal("pIn"),e.i32_const(c),n),e.call(a+"__reverseBytes",e.i32_add(e.getLocal("pIn"),e.i32_const(c)),e.i32_const(c),s),e.call(a+"_toMontgomeryAffine",l,e.getLocal("pOut")))}(),function(){const i=t.addFunction(a+"_CtoLEM");i.addParam("pIn","i32"),i.addParam("pOut","i32"),i.addLocal("firstByte","i32"),i.addLocal("greatest","i32");const l=i.getCodeBuilder(),n=t.alloc(2*c),s=l.i32_const(n),r=l.i32_const(n+c);i.addCode(l.setLocal("firstByte",l.i32_load8_u(l.getLocal("pIn"))),l.if(l.i32_and(l.getLocal("firstByte"),l.i32_const(64)),[...l.call(a+"_zeroAffine",l.getLocal("pOut")),...l.ret([])]),l.setLocal("greatest",l.i32_and(l.getLocal("firstByte"),l.i32_const(128))),l.call(o+"_copy",l.getLocal("pIn"),r),l.i32_store8(r,l.i32_and(l.getLocal("firstByte"),l.i32_const(63))),l.call(a+"__reverseBytes",r,l.i32_const(c),s),l.call(o+"_toMontgomery",s,l.getLocal("pOut")),l.call(o+"_square",l.getLocal("pOut"),r),l.call(o+"_mul",l.getLocal("pOut"),r,r),l.call(o+"_add",r,l.i32_const(e),r),l.call(o+"_sqrt",r,r),l.call(o+"_neg",r,s),l.
1if(l.i32_eq(l.call(o+"_sign",r),l.i32_const(-1)),l.if(l.getLocal("greatest"),l.call(o+"_copy",r,l.i32_add(l.getLocal("pOut"),l.i32_const(c))),l.call(o+"_neg",r,l.i32_add(l.getLocal("pOut"),l.i32_const(c)))),l.if(l.getLocal("greatest"),l.call(o+"_neg",r,l.i32_add(l.getLocal("pOut"),l.i32_const(c))),l.call(o+"_copy",r,l.i32_add(l.getLocal("pOut"),l.i32_const(c))))))}(),jt(t,a+"_batchLEMtoU",a+"_LEMtoU",2*c,2*c),jt(t,a+"_batchLEMtoC",a+"_LEMtoC",2*c,c),jt(t,a+"_batchUtoLEM",a+"_UtoLEM",2*c,2*c),jt(t,a+"_batchCtoLEM",a+"_CtoLEM",c,2*c,!0),jt(t,a+"_batchToJacobian",a+"_toJacobian",2*c,3*c,!0),Ut(t,a,a+"_multiexp",a+"_add",3*c),Ut(t,a,a+"_multiexpAffine",a+"_addMixed",2*c),Rt(t,a+"_timesScalar",3*c,a+"_add",a+"_double",a+"_sub",a+"_copy",a+"_zero"),Rt(t,a+"_timesScalarAffine",2*c,a+"_addMixed",a+"_double",a+"_subMixed",a+"_copyAffine",a+"_zero"),t.exportFunction(a+"_isZero"),t.exportFunction(a+"_isZeroAffine"),t.exportFunction(a+"_eq"),t.exportFunction(a+"_eqMixed"),t.exportFunction(a+"_eqAffine"),t.exportFunction(a+"_copy"),t.exportFunction(a+"_copyAffine"),t.exportFunction(a+"_zero"),t.exportFunction(a+"_zeroAffine"),t.exportFunction(a+"_double"),t.exportFunction(a+"_doubleAffine"),t.exportFunction(a+"_add"),t.exp
1ortFunction(a+"_addMixed"),t.exportFunction(a+"_addAffine"),t.exportFunction(a+"_neg"),t.exportFunction(a+"_negAffine"),t.exportFunction(a+"_sub"),t.exportFunction(a+"_subMixed"),t.exportFunction(a+"_subAffine"),t.exportFunction(a+"_fromMontgomery"),t.exportFunction(a+"_fromMontgomeryAffine"),t.exportFunction(a+"_toMontgomery"),t.exportFunction(a+"_toMontgomeryAffine"),t.exportFunction(a+"_timesScalar"),t.exportFunction(a+"_timesScalarAffine"),t.exportFunction(a+"_normalize"),t.exportFunction(a+"_LEMtoU"),t.exportFunction(a+"_LEMtoC"),t.exportFunction(a+"_UtoLEM"),t.exportFunction(a+"_CtoLEM"),t.exportFunction(a+"_batchLEMtoU"),t.exportFunction(a+"_batchLEMtoC"),t.exportFunction(a+"_batchUtoLEM"),t.exportFunction(a+"_batchCtoLEM"),t.exportFunction(a+"_toAffine"),t.exportFunction(a+"_toJacobian"),t.exportFunction(a+"_batchToAffine"),t.exportFunction(a+"_batchToJacobian"),t.exportFunction(a+"_inCurve"),t.exportFunction(a+"_inCurveAffine"),a};const{isOdd:$t,modInv:Qt,modPow:Jt}=et,Dt=Y;var Wt=function(t,a,o,e,i){const c=8*t.modules[e].n64,l=8*t.modules[o].n64,n=t.modules[e].q;let s=n-1n,r=0;for(;!$t(s);)r++,s>>=1n;let d=2n;for(;1n===Jt(d,n>>1n,n);)d+=1n;const _=new Array(r+1);_[r]=Jt(d,s,n);let u=r-1;for(;u>=0;)_[u]=Jt(_[u+1],2n,n),u--;const g=[],L=(1n<<BigInt(8*c))%n;for(let t=0;t<_.length;t++){const a=_[t]*L%n;g.push(...Dt.bigInt2BytesLE(a,c))}const p=t.alloc(g),f=new Array(r+1);f[0]=1n;for(let t=1;t<=r;t++)f[t]=2n*f[t-1];const m=[];for(let t=0;t<=r;t++){const a=Qt(f[t],n)*L%n;m.push(...Dt.bigInt2BytesLE(a,c))}const h=t.alloc(m),b=Jt(d,2n,n),x=[],y=[];for(let t=0;t<=r;t++){const a=Jt(b,2n**BigInt(t),n),o=Qt(n+1n-a,n);x.push(...Dt.bigInt2BytesLE(a*L%n,c)),y.push(...Dt.bigInt2BytesLE(o*L%n,c))}const F=t.alloc(x),C=t.alloc(y);function B(t){let a=0;for(let o=0;o<8;o++)t&1<<o&&(a|=128>>o);return a}const P=Array(256);for(let t=0;t<256;t++)P[t]=B(t);const A=t.alloc(P);function w(){const o=t.addFunction(a+"_fft");o.addParam("px","i32"),o.addParam("n","i32"),o.addLocal("bits","i32");const i=o.getCodeBuilder(),l=i.i32_const(t.alloc(c));o.addCode(i.setLocal("bits",i.call(a+"__log2",i.getLocal("n"))),i.call(e+"_one",l),i.call(a+"_rawfft",i.getLocal("px"),i.getLocal("bits"),i.i32_const(0),l))}!function(){const o=t.addFunction(a+"__rev");o.addParam("x","i32"),o.addParam("bits","i32"),o.setReturnType("i32");const e=o.getCodeBuilder();o.addCode(e.i32_rotl(e.i32_add(e.i32_add(e.i32_shl(e.i32_load8_u(e.i32_and(e.getLocal("x"),e.i32_const(255)),A,0),e.i32_const(24)),e.i32_shl(e.i32_load8_u(e.i32_and(e.i32_shr_u(e.getLocal("x"),e.i32_const(8)),e.i32_const(255)),A,0),e.i32_const(16))),e.i32_add(e.i32_shl(e.i32_load8_u(e.i32_and(e.i32_shr_u(e.getLocal("x"),e.i32_const(16)),e.i32_const(255)),A,0),e.i32_const(8)),e.i32_load8_u(e.i32_and(e.i32_shr_u(e.getLocal("x"),e.i32_const(24)),e.i32_const(255)),A,0))),e.getLocal("bits")))}(),function(){const e=t.addFunction(a+"__reversePermutation");e.addParam("px","i32"),e.addParam("bits","i32"),e.addLocal("n","i32"),e.addLocal("i","i32"),e.addLocal("ri","i32"),e.addLocal("idx1","i32"),e.addLocal("idx2","i32");const i=e.getCodeBuilder(),c=i.i32_const(t.alloc(l));e.addCode(i.setLocal("n",i.i32_shl(i.i32_const(1),i.getLocal("bits"))),i.setLocal("i",i.i32_const(0)),i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("i"),i.getLocal("n"))),i.setLocal("idx1",i.i32_add(i.getLocal("px"),i.i32_mul(i.getLocal("i"),i.i32_const(l)))),i.setLocal("ri",i.call(a+"__rev",i.getLocal("i"),i.getLocal("bits"))),i.setLocal("idx2",i.i32_add(i.getLocal("px"),i.i32_mul(i.getLocal("ri"),i.i32_const(l)))),i.if(i.i32_lt_u(i.getLocal("i"),i.getLocal("ri")),[...i.call(o+"_copy",i.getLocal("idx1"),c),...i.call(o+"_copy",i.getLocal("idx2"),i.getLocal("idx1")),...i.call(o+"_copy",c,i.getLocal("idx2"))]),i.setLocal("i",i.i32_add(i.getLocal("i"),i.i32_const(1))),i.br(0))))}(),function(){const c=t.addFunction(a+"__fftFinal");c.addParam("px","i32"),c.addParam("bits","i32"),c.addParam("reverse","i32"),c.addParam("mulFactor","i32"),c.addLocal("n","i32"),c.addLocal("ndiv2","i32"),c.addLocal("pInv2","i32"),c.addLocal("i","i32"),c.addLocal("mask","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32");const n=c.getCodeBuilder(),s=n.i32_const(t.alloc(l));c.addCode(n.if(n.i32_and(n.i32_eqz(n.getLocal("reverse")),n.call(e+"_isOne",n.getLocal("mulFactor"))),n.ret([])),n.setLocal("n",n.i32_shl(n.i32_const(1),n.getLocal("bits"))),n.setLocal("mask",n.i32_sub(n.getLocal("n"),n.i32_const(1))),n.setLocal("i",n.i32_const(1)),n.setLocal("ndiv2",n.i32_shr_u(n.getL
1ocal("n"),n.i32_const(1))),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("px"),n.i32_mul(n.getLocal("i"),n.i32_const(l)))),n.setLocal("idx2",n.i32_add(n.getLocal("px"),n.i32_mul(n.i32_sub(n.getLocal("n"),n.getLocal("i")),n.i32_const(l)))),n.if(n.getLocal("reverse"),n.if(n.call(e+"_isOne",n.getLocal("mulFactor")),[...n.call(o+"_copy",n.getLocal("idx1"),s),...n.call(o+"_copy",n.getLocal("idx2"),n.getLocal("idx1")),...n.call(o+"_copy",s,n.getLocal("idx2"))],[...n.call(o+"_copy",n.getLocal("idx1"),s),...n.call(i,n.getLocal("idx2"),n.getLocal("mulFactor"),n.getLocal("idx1")),...n.call(i,s,n.getLocal("mulFactor"),n.getLocal("idx2"))]),n.if(n.call(e+"_isOne",n.getLocal("mulFactor")),[],[...n.call(i,n.getLocal("idx1"),n.getLocal("mulFactor"),n.getLocal("idx1")),...n.call(i,n.getLocal("idx2"),n.getLocal("mulFactor"),n.getLocal("idx2"))])),n.setLocal("i",n.i32_add(n.getLocal("i"),n.i32_const(1))),n.br(0))),n.if(n.call(e+"_isOne",n.getLocal("mulFactor")),[],[...n.call(i,n.getLocal("px"),n.getLocal("mulFactor"),n.getLocal("px")),...n.setLocal("idx2",n.i32_add(n.getLocal("px"),n.i32_mul(n.getL
1ocal("ndiv2"),n.i32_const(l)))),...n.call(i,n.getLocal("idx2"),n.getLocal("mulFactor"),n.getLocal("idx2"))]))}(),function(){const n=t.addFunction(a+"_rawfft");n.addParam("px","i32"),n.addParam("bits","i32"),n.addParam("reverse","i32"),n.addParam("mulFactor","i32"),n.addLocal("s","i32"),n.addLocal("k","i32"),n.addLocal("j","i32"),n.addLocal("m","i32"),n.addLocal("mdiv2","i32"),n.addLocal("n","i32"),n.addLocal("pwm","i32"),n.addLocal("idx1","i32"),n.addLocal("idx2","i32");const s=n.getCodeBuilder(),r=s.i32_const(t.alloc(c)),d=s.i32_const(t.alloc(l)),_=s.i32_const(t.alloc(l));n.addCode(s.call(a+"__reversePermutation",s.getLocal("px"),s.getLocal("bits")),s.setLocal("n",s.i32_shl(s.i32_const(1),s.getLocal("bits"))),s.setLocal("s",s.i32_const(1)),s.block(s.loop(s.br_if(1,s.i32_gt_u(s.getLocal("s"),s.getLocal("bits"))),s.setLocal("m",s.i32_shl(s.i32_const(1),s.getLocal("s"))),s.setLocal("pwm",s.i32_add(s.i32_const(p),s.i32_mul(s.getLocal("s"),s.i32_const(c)))),s.setLocal("k",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_ge_u(s.getLocal("k"),s.getLocal("n"))),s.call(e+"_one",r),s.setLocal("mdiv2",s.i32_shr_u(s.getLocal("m"),s.i32_const(1))),s.setLocal("j",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_ge_u(s.getLocal("j"),s.getLocal("mdiv2"))),s.setLocal("idx1",s.i32_add(s.getLocal("px"),s.i32_mul(s.i32_add(s.getLocal("k"),s.getLocal("j")),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("idx1"),s.i32_mul(s.getLocal("mdiv2"),s.i32_const(l)))),s.call(i,s.getLocal("idx2"),r,d),s.call(o+"_copy",s.getLocal("idx1"),_),s.call(o+"_add",_,d,s.getLocal("idx1")),s.call(o+"_sub",_,d,s.getLocal("idx2")),s.call(e+"_mul",r,s.getLocal("pwm"),r),s.setLocal("j",s.i32_add(s.getLocal("j"),s.i32_const(1))),s.br(0))),s.setLocal("k",s.i32_add(s.getLocal("k"),s.getLocal("m"))),s.br(0))),s.setLocal("s",s.i32_add(s.getLocal("s"),s.i32_const(1))),s.br(0))),s.call(a+"__fftFinal",s.getLocal("px"),s.getLocal("bits"),s.getLocal("reverse"),s.getLocal("mulFactor")))}(),function(){const o=t.addFunction(a+"__log2");o.addParam("n","i32"),o.setReturnType("i32"),o.addLocal("bits","i32"),o.addLocal("aux","i32");const e=o.getCodeBuilder();o.addCode(e.setLocal("aux",e.i32_shr_u(e.getLocal("n"),e.i32_const(1)))),o.addCode(e.setLocal("bits",e.i32_const(0))),o.addCode(e.block(e.loop(e.br_if(1,e.i32_eqz(e.getLocal("aux"))),e.setLocal("aux",e.i32_shr_u(e.getLocal("aux"),e.i32_const(1))),e.setLocal("bits",e.i32_add(e.getLocal("bits"),e.i32_const(1))),e.br(0)))),o.addCode(e.if(e.i32_ne(e.getLocal("n"),e.i32_shl(e.i32_const(1),e.getLocal("bits"))),e.unreachable())),o.addCode(e.if(e.i32_gt_u(e.getLocal("bits"),e.i32_const(r)),e.unreachable())),o.addCode(e.getLocal("bits"))}(),w(),function(){const o=t.addFunction(a+"_ifft");o.addParam("px","i32"),o.addParam("n","i32"),o.addLocal("bits","i32"),o.addLocal("pInv2","i32");const e=o.getCodeBuilder();o.addCode(e.setLocal("bits",e.call(a+"__log2",e.getLocal("n"))),e.setLocal("pInv2",e.i32_add(e.i32_const(h),e.i32_mul(e.getLocal("bits"),e.i32_const(c)))),e.call(a+"_rawfft",e.getLocal("px"),e.getLocal("bits"),e.i32_const(1),e.getLocal("pInv2")))}(),function(){const n=t.addFunction(a+"_fftJoin");n.addParam("pBuff1","i32"),n.addParam("pBuff2","i32"),n.addParam("n","i32"),n.addParam("first","i32"),n.addParam("inc","i32"),n.addLocal("idx1","i32"),n.addLocal("idx2","i32"),n.addLocal("i","i32");const s=n.getCodeBuilder(),r=s.i32_const(t.alloc(c)),d=s.i32_const(t.alloc(l)),_=s.i32_const(t.alloc(l));n.addCode(s.call(e+"_copy",s.getLocal("first"),r),s.setLocal("i",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("n"))),s.setLocal("idx1",s.i32_add(s.getLocal("pBuff1"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("pBuff2"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.call(i,s.getLocal("idx2"),r,d),s.call(o+"_copy",s.getLocal("idx1"),_),s.call(o+"_add",_,d,s.getLocal("idx1")),s.call(o+"_sub",_,d,s.getLocal("idx2")),s.call(e+"_mul",r,s.getLocal("inc"),r),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),function(){const n=t.addFunction(a+"_fftJoinExt");n.addParam("pBuff1","i32"),n.addParam("pBuff2","i32"),n.addParam("n","i32"),n.addParam("first","i32"),n.addParam("inc","i32"),n.addParam("totalBits","i32"),n.addLocal("idx1","i32"),n.addLocal("idx2","i32"),n.addLocal("i","i32"),n.addLocal("pShiftToM","i32");const s=n.getCodeBuilder(),r=s.i32_const(t.alloc(c)),d=s.i32_const(t.alloc(l));n.addCode(s.setLocal("pShiftToM",s.i32_add(s.i32_const(F),s.i32_mul(s.getL
1ocal("totalBits"),s.i32_const(c)))),s.call(e+"_copy",s.getLocal("first"),r),s.setLocal("i",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("n"))),s.setLocal("idx1",s.i32_add(s.getLocal("pBuff1"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("pBuff2"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.call(o+"_add",s.getLocal("idx1"),s.getLocal("idx2"),d),s.call(i,s.getLocal("idx2"),s.getLocal("pShiftToM"),s.getLocal("idx2")),s.call(o+"_add",s.getLocal("idx1"),s.getLocal("idx2"),s.getLocal("idx2")),s.call(i,s.getLocal("idx2"),r,s.getLocal("idx2")),s.call(o+"_copy",d,s.getLocal("idx1")),s.call(e+"_mul",r,s.getLocal("inc"),r),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),function(){const n=t.addFunction(a+"_fftJoinExtInv");n.addParam("pBuff1","i32"),n.addParam("pBuff2","i32"),n.addParam("n","i32"),n.addParam("first","i32"),n.addParam("inc","i32"),n.addParam("totalBits","i32"),n.addLocal("idx1","i32"),n.addLocal("idx2","i32"),n.addLocal("i","i32"),n.addLocal("pShiftToM","i32"),n.addLocal("pSConst","i32");const s=n.getCodeBuilder(),r=s.i32_const(t.alloc(c)),d=s.i32_const(t.alloc(l));n.addCode(s.setLocal("pShiftToM",s.i32_add(s.i32_const(F),s.i32_mul(s.getLocal("totalBits"),s.i32_const(c)))),s.setLocal("pSConst",s.i32_add(s.i32_const(C),s.i32_mul(s.getLocal("totalBits"),s.i32_const(c)))),s.call(e+"_copy",s.getLocal("first"),r),s.setLocal("i",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("n"))),s.setLocal("idx1",s.i32_add(s.getLocal("pBuff1"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("pBuff2"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.call(i,s.getLocal("idx2"),r,d),s.call(o+"_sub",s.getLocal("idx1"),d,s.getLocal("idx2")),s.call(i,s.getLocal("idx2"),s.getLocal("pSConst"),s.getLocal("idx2")),s.call(i,s.getLocal("idx1"),s.getLocal("pShiftToM"),s.getLocal("idx1")),s.call(o+"_sub",d,s.getLocal("idx1"),s.getLocal("idx1")),s.call(i,s.getLocal("idx1"),s.getLocal("pSConst"),s.getLocal("idx1")),s.call(e+"_mul",r,s.getLocal("inc"),r),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),function(){const n=t.addFunction(a+"_fftMix");n.addParam("pBuff","i32"),n.addParam("n","i32"),n.addParam("exp","i32"),n.addLocal("nGroups","i32"),n.addLocal("nPerGroup","i32"),n.addLocal("nPerGroupDiv2","i32"),n.addLocal("pairOffset","i32"),n.addLocal("idx1","i32"),n.addLocal("idx2","i32"),n.addLocal("i","i32"),n.addLocal("j","i32"),n.addLocal("pwm","i32");const s=n.getCodeBuilder(),r=s.i32_const(t.alloc(c)),d=s.i32_const(t.alloc(l)),_=s.i32_const(t.alloc(l));n.addCode(s.setLocal("nPerGroup",s.i32_shl(s.i32_const(1),s.getLocal("exp"))),s.setLocal("nPerGroupDiv2",s.i32_shr_u(s.getLocal("nPerGroup"),s.i32_const(1))),s.setLocal("nGroups",s.i32_shr_u(s.getLocal("n"),s.getLocal("exp"))),s.setLocal("pairOffset",s.i32_mul(s.getLocal("nPerGroupDiv2"),s.i32_const(l))),s.setLocal("pwm",s.i32_add(s.i32_const(p),s.i32_mul(s.getLocal("exp"),s.i32_const(c)))),s.setLocal("i",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("nGroups"))),s.call(e+"_one",r),s.setLocal("j",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("j"),s.getLocal("nPerGroupDiv2"))),s.setLocal("idx1",s.i32_add(s.getLocal("pBuff"),s.i32_mul(s.i32_add(s.i32_mul(s.getLocal("i"),s.getLocal("nPerGroup")),s.getLocal("j")),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("idx1"),s.getLocal("pairOffset"))),s.call(i,s.getLocal("idx2"),r,d),s.call(o+"_copy",s.getLocal("idx1"),_),s.call(o+"_add",_,d,s.getLocal("idx1")),s.call(o+"_sub",_,d,s.getLocal("idx2")),s.call(e+"_mul",r,s.getLocal("pwm"),r),s.setLocal("j",s.i32_add(s.getLocal("j"),s.i32_const(1))),s.br(0))),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),function(){const e=t.addFunction(a+"_fftFinal");e.addParam("pBuff","i32"),e.addParam("n","i32"),e.addParam("factor","i32"),e.addLocal("idx1","i32"),e.addLocal("idx2","i32"),e.addLocal("i","i32"),e.addLocal("ndiv2","i32");const c=e.getCodeBuilder(),n=c.i32_const(t.alloc(l));e.addCode(c.setLocal("ndiv2",c.i32_shr_u(c.getLocal("n"),c.i32_const(1))),c.if(c.i32_and(c.getLocal("n"),c.i32_const(1)),c.call(i,c.i32_add(c.getLocal("pBuff"),c.i32_mul(c.getLocal("ndiv2"),c.i32_const(l))),c.getLocal("factor"),c.i32_add(c.getLocal("pBuff"),c.i32_mul(c.getLocal("ndiv2"),c.i32_const(l))))),c.set
1Local("i",c.i32_const(0)),c.block(c.loop(c.br_if(1,c.i32_ge_u(c.getLocal("i"),c.getLocal("ndiv2"))),c.setLocal("idx1",c.i32_add(c.getLocal("pBuff"),c.i32_mul(c.getLocal("i"),c.i32_const(l)))),c.setLocal("idx2",c.i32_add(c.getLocal("pBuff"),c.i32_mul(c.i32_sub(c.i32_sub(c.getLocal("n"),c.i32_const(1)),c.getLocal("i")),c.i32_const(l)))),c.call(i,c.getLocal("idx2"),c.getLocal("factor"),n),c.call(i,c.getLocal("idx1"),c.getLocal("factor"),c.getLocal("idx2")),c.call(o+"_copy",n,c.getLocal("idx1")),c.setLocal("i",c.i32_add(c.getLocal("i"),c.i32_const(1))),c.br(0))))}(),function(){const n=t.addFunction(a+"_prepareLagrangeEvaluation");n.addParam("pBuff1","i32"),n.addParam("pBuff2","i32"),n.addParam("n","i32"),n.addParam("first","i32"),n.addParam("inc","i32"),n.addParam("totalBits","i32"),n.addLocal("idx1","i32"),n.addLocal("idx2","i32"),n.addLocal("i","i32"),n.addLocal("pShiftToM","i32"),n.addLocal("pSConst","i32");const s=n.getCodeBuilder(),r=s.i32_const(t.alloc(c)),d=s.i32_const(t.alloc(l));n.addCode(s.setLocal("pShiftToM",s.i32_add(s.i32_const(F),s.i32_mul(s.getLocal("totalBits"),s.i32_const(c)))),s.setLocal("pSConst",s.i32_add(s.i32_const(C),s.i32_mul(s.getLocal("totalBits"),s.i32_const(c)))),s.call(e+"_copy",s.getLocal("first"),r),s.setLocal("i",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("n"))),s.setLocal("idx1",s.i32_add(s.getLocal("pBuff1"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.setLocal("idx2",s.i32_add(s.getLocal("pBuff2"),s.i32_mul(s.getLocal("i"),s.i32_const(l)))),s.call(i,s.getLocal("idx1"),s.getLocal("pShiftToM"),d),s.call(o+"_sub",s.getLocal("idx2"),d,d),s.call(o+"_sub",s.getLocal("idx1"),s.getLocal("idx2"),s.getLocal("idx2")),s.call(i,d,s.getLocal("pSConst"),s.getLocal("idx1")),s.call(i,s.getLocal("idx2"),r,s.getLocal("idx2")),s.call(e+"_mul",r,s.getLocal("inc"),r),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))))}(),t.exportFunction(a+"_fft"),t.exportFunction(a+"_ifft"),t.exportFunction(a+"_rawfft"),t.exportFunction(a+"_fftJoin"),t.exportFunction(a+"_fftJoinExt"),t.exportFunction(a+"_fftJoinExtInv"),t.exportFunction(a+"_fftMix"),t.exportFunction(a+"_fftFinal"),t.exportFunction(a+"_prepareLagrangeEvaluation")},Vt=function(t,a,o){const e=8*t.modules[o].n64;return function(){const i=t.addFunction(a+"_zero");i.addParam("px","i32"),i.addParam("n","i32"),i.addLocal("lastp","i32"),i.addLocal("p","i32");const c=i.getCodeBuilder();i.addCode(c.setLocal("p",c.getLocal("px")),c.setLocal("lastp",c.i32_add(c.getLocal("px"),c.i32_mul(c.getLocal("n"),c.i32_const(e)))),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("p"),c.getLocal("lastp"))),c.call(o+"_zero",c.getLocal("p")),c.setLocal("p",c.i32_add(c.getLocal("p"),c.i32_const(e))),c.br(0))))}(),function(){const i=t.addFunction(a+"_constructLC");i.addParam("ppolynomials","i32"),i.addParam("psignals","i32"),i.addParam("nSignals","i32"),i.addParam("pres","i32"),i.addLocal("i","i32"),i.addLocal("j","i32"),i.addLocal("pp","i32"),i.addLocal("ps","i32"),i.addLocal("pd","i32"),i.addLocal("ncoefs","i32");const c=i.getCodeBuilder(),l=c.i32_const(t.alloc(e));i.addCode(c.setLocal("i",c.i32_const(0)),c.setLocal("pp",c.getLocal("ppolynomials")),c.setLocal("ps",c.getLocal("psignals")),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("i"),c.getLocal("nSignals"))),c.setLocal("ncoefs",c.i32_load(c.getLocal("pp"))),c.setLocal("pp",c.i32_add(c.getLocal("pp"),c.i32_const(4))),c.setLocal("j",c.i32_const(0)),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("j"),c.getLocal("ncoefs"))),c.setLocal("pd",c.i32_add(c.getLocal("pres"),c.i32_mul(c.i32_load(c.getLocal("pp")),c.i32_const(e)))),c.setLocal("pp",c.i32_add(c.getLocal("pp"),c.i32_const(4))),c.call(o+"_mul",c.getLocal("ps"),c.getLocal("pp"),l),c.call(o+"_add",l,c.getLocal("pd"),c.getLocal("pd")),c.setLocal("pp",c.i32_add(c.getLocal("pp"),c.i32_const(e))),c.setLocal("j",c.i32_add(c.getLocal("j"),c.i32_const(1))),c.br(0))),c.setLocal("ps",c.i32_add(c.getLocal("ps"),c.i32_const(e))),c.setLocal("i",c.i32_add(c.getLocal("i"),c.i32_const(1))),c.br(0))))}(),t.exportFunction(a+"_zero"),t.exportFunction(a+"_constructLC"),a},Kt=function(t,a,o){const e=8*t.modules[o].n64;return function(){const i=t.addFunction(a+"_buildABC");i.addParam("pCoefs","i32"),i.addParam("nCoefs","i32"),i.addParam("pWitness","i32"),i.addParam("pA","i32"),i.addParam("pB","i32"),i.addParam("pC","i32"),i.addParam("offsetOut","i32"),i.addParam("nOut","i32"),i.addParam("offsetWitness","i32"),i.addParam("nWitness","i32"),i.addLocal("it","i32"),i.addLocal("ita","i32"),i.addLocal("itb","i32"),i.addLocal("last","i32"),i.addLocal("m","i32"),i.addLocal("c","i32"),i.addLocal("s","i32"),i.addLocal("pOut","i32");const c=i.getCodeBuilder(),l=c.i32_const(t.alloc(e));i.addCode(c.setLocal("ita",c.getLocal("pA")),c.setLocal("itb",c.getLocal("pB")),c.setLocal("last",c.i32_add(c.getLocal("pA"),c.i32_mul(c.getLocal("nOut"),c.i32_const(e)))
1),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("ita"),c.getLocal("last"))),c.call(o+"_zero",c.getLocal("ita")),c.call(o+"_zero",c.getLocal("itb")),c.setLocal("ita",c.i32_add(c.getLocal("ita"),c.i32_const(e))),c.setLocal("itb",c.i32_add(c.getLocal("itb"),c.i32_const(e))),c.br(0))),c.setLocal("it",c.getLocal("pCoefs")),c.setLocal("last",c.i32_add(c.getLocal("pCoefs"),c.i32_mul(c.getLocal("nCoefs"),c.i32_const(e+12)))),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("it"),c.getLocal("last"))),c.setLocal("s",c.i32_load(c.getLocal("it"),8)),c.if(c.i32_or(c.i32_lt_u(c.getLocal("s"),c.getLocal("offsetWitness")),c.i32_ge_u(c.getLocal("s"),c.i32_add(c.getLocal("offsetWitness"),c.getLocal("nWitness")))),[...c.setLocal("it",c.i32_add(c.getLocal("it"),c.i32_const(e+12))),...c.br(1)]),c.setLocal("m",c.i32_load(c.getLocal("it"))),c.if(c.i32_eq(c.getLocal("m"),c.i32_const(0)),c.setLocal("pOut",c.getLocal("pA")),c.if(c.i32_eq(c.getLocal("m"),c.i32_const(1)),c.setLocal("pOut",c.getLocal("pB")),[...c.setLocal("it",c.i32_add(c.getLocal("it"),c.i32_const(e+12))),...c.br(1)])),c.setLocal("c",c.i32_load(c.getLocal("it"),4)),c.if(c.i32_or(c.i32_lt_u(c.getLocal("c"),c.getLocal("offsetOut")),c.i32_ge_u(c.getLocal("c"),c.i32_add(c.getLocal("offsetOut"),c.getLocal("nOut")))),[...c.setLocal("it",c.i32_add(c.getLocal("it"),c.i32_const(e+12))),...c.br(1)]),c.setLocal("pOut",c.i32_add(c.getLocal("pOut"),c.i32_mul(c.i32_sub(c.getLocal("c"),c.getLocal("offsetOut")),c.i32_const(e)))),c.call(o+"_mul",c.i32_add(c.getLocal("pWitness"),c.i32_mul(c.i32_sub(c.getLocal("s"),c.getLocal("offsetWitness")),c.i32_const(e))),c.i32_add(c.getLocal("it"),c.i32_const(12)),l),c.call(o+"_add",c.getLocal("pOut"),l,c.getLocal("pOut")),c.setLocal("it",c.i32_add(c.getLocal("it"),c.i32_const(e+12))),c.br(0))),c.setLocal("ita",c.getLocal("pA")),c.setLocal("itb",c.getLocal("pB")),c.setLocal("it",c.getLocal("pC")),c.setLocal("last",c.i32_add(c.getLocal("pA"),c.i32_mul(c.getLocal("nOut"),c.i32_const(e)))),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("ita"),c.getLocal("last"))),c.call(o+"_mul",c.getLocal("ita"),c.getLocal("itb"),c.getLocal("it")),c.setLocal("ita",c.i32_add(c.getLocal("ita"),c.i32_const(e))),c.setLocal("itb",c.i32_add(c.getLocal("itb"),c.i32_const(e))),c.setLocal("it",c.i32_add(c.getLocal("it"),c.i32_const(e))),c.br(0))))}(),function(){const i=t.addFunction(a+"_joinABC");i.addParam("pA","i32"),i.addParam("pB","i32"),i.addParam("pC","i32"),i.addParam("n","i32"),i.addParam("pP","i32"),i.addLocal("ita","i32"),i.addLocal("itb","i32"),i.addLocal("itc","i32"),i.addLocal("itp","i32"),i.addLocal("last","i32");const c=i.getCodeBuilder(),l=c.i32_const(t.alloc(e));i.addCode(c.setLocal("ita",c.getLocal("pA")),c.setLocal("itb",c.getLocal("pB")),c.setLocal("itc",c.getLocal("pC")),c.setLocal("itp",c.getLocal("pP")),c.setLocal("last",c.i32_add(c.getLocal("pA"),c.i32_mul(c.getLocal("n"),c.i32_const(e)))),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("ita"),c.getLocal("last"))),c.call(o+"_mul",c.getLocal("ita"),c.getLocal("itb"),l),c.call(o+"_sub",l,c.getLocal("itc"),c.getLocal("itp")),c.setLocal("ita",c.i32_add(c.getLocal("ita"),c.i32_const(e))),c.setLocal("itb",c.i32_add(c.getLocal("itb"),c.i32_const(e))),c.setLocal("itc",c.i32_add(c.getLocal("itc"),c.i32_const(e))),c.setLocal("itp",c.i32_add(c.getLocal("itp"),c.i32_const(e))),c.br(0))))}(),function(){const i=t.addFunction(a+"_batchAdd");i.addParam("pa","i32"),i.addParam("pb","i32"),i.addParam("n","i32"),i.addParam("pr","i32"),i.addLocal("ita","i32"),i.addLocal("itb","i32"),i.addLocal("itr","i32"),i.addLocal("last","i32");const c=i.getCodeBuilder();i.addCode(c.setLocal("ita",c.getLocal("pa")),c.setLocal("itb",c.getLocal("pb")),c.setLocal("itr",c.getLocal("pr")),c.setLocal("last",c.i32_add(c.getLocal("pa"),c.i32_mul(c.getLocal("n"),c.i32_const(e)))),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("ita"),c.getLocal("last"))),c.call(o+"_add",c.getLocal("ita"),c.getLocal("itb"),c.getLocal("itr")),c.setLocal("ita",c.i32_add(c.getLocal("ita"),c.i32_const(e))),c.setLocal("itb",c.i32_add(c.getLocal("itb"),c.i32_const(e))),c.setLocal("itr",c.i32_add(c.getLocal("itr"),c.i32_const(e))),c.br(0))))}
1(),t.exportFunction(a+"_buildABC"),t.exportFunction(a+"_joinABC"),t.exportFunction(a+"_batchAdd"),a},Xt=function(t,a,o,e,i,c,l,n){const s=t.addFunction(a);s.addParam("pIn","i32"),s.addParam("n","i32"),s.addParam("pFirst","i32"),s.addParam("pInc","i32"),s.addParam("pOut","i32"),s.addLocal("pOldFree","i32"),s.addLocal("i","i32"),s.addLocal("pFrom","i32"),s.addLocal("pTo","i32");const r=s.getCodeBuilder(),d=r.i32_const(t.alloc(l));s.addCode(r.setLocal("pFrom",r.getLocal("pIn")),r.setLocal("pTo",r.getLocal("pOut"))),s.addCode(r.call(e+"_copy",r.getLocal("pFirst"),d)),s.addCode(r.setLocal("i",r.i32_const(0)),r.block(r.loop(r.br_if(1,r.i32_eq(r.getLocal("i"),r.getLocal("n"))),r.call(n,r.getLocal("pFrom"),d,r.getLocal("pTo")),r.setLocal("pFrom",r.i32_add(r.getLocal("pFrom"),r.i32_const(i))),r.setLocal("pTo",r.i32_add(r.getLocal("pTo"),r.i32_const(c))),r.call(e+"_mul",d,r.getLocal("pInc"),d),r.setLocal("i",r.i32_add(r.getLocal("i"),r.i32_const(1))),r.br(0)))),t.exportFunction(a)};const Yt=Y,Ht=vt,ta=Et,aa=Tt,oa=Nt,ea=Zt,ia=Wt,ca=Vt,la=Kt,na=Xt,{bitLength:sa,modInv:ra,isOdd:da,isNegative:_a}=et;const ua=Y,ga=vt,La=Et,pa=Tt,fa=Nt,ma=Zt,ha=Wt,ba=Vt,xa=Kt,ya=Xt,{bitLength:Fa,isOdd:Ca,isNegative:Ba}=et;var Pa=function(t,a){const o=a||"bn128";if(t.modules[o])return o;const e=21888242871839275222246405745257275088696311157297823662689037894645226208583n,i=21888242871839275222246405745257275088548364400416034343698204186575808495617n,c=Math.floor((sa(e-1n)-1)/64)+1,l=8*c,n=l,s=l,r=2*s,d=12*s,_=t.alloc(Yt.bigInt2BytesLE(i,n)),u=Ht(t,e,"f1m");ta(t,i,"fr","frm");const g=t.alloc(Yt.bigInt2BytesLE(b(3n),s)),L=ea(t,"g1m","f1m",g);ia(t,"frm","frm","frm","frm_mul"),ca(t,"pol","frm"),la(t,"qap","frm");const p=aa(t,"f1m_neg","f2m","f1m"),f=t.alloc([...Yt.bigInt2BytesLE(b(19485874751759354771024239261021720505790618469301721065564631296452457478373n),s),...Yt.bigInt2BytesLE(b(266929791119991161246907387137283842545076965332900288569378510910307636690n),s)]),m=ea(t,"g2m","f2m",f);function h(a,o){const e=t.addFunction(a);e.addParam("pG","i32"),e.addParam("pFr","i32"),e.addParam("pr","i32");const i=e.getCodeBuilder(),c=i.i32_const(t.alloc(l));e.addCode(i.call("frm_fromMontgomery",i.getLocal("pFr"),c),i.call(o,i.getLocal("pG"),c,i.i32_const(l),i.getLocal("pr"))),t.exportFunction(a)}function b(t){return BigInt(t)*(1n<<BigInt(8*s))%e}h("g1m_timesFr","g1m_timesScalar"),ia(t,"g1m","g1m","frm","g1m_timesFr"),h("g2m_timesFr","g2m_timesScalar"),ia(t,"g2m","g2m","frm","g2m_timesFr"),h("g1m_timesFrAffine","g1m_timesScalarAffine"),h("g2m_timesFrAffine","g2m_timesScalarAffine"),na(t,"frm_batchApplyKey","fmr","frm",l,l,l,"frm_mul"),na(t,"g1m_batchApplyKey","g1m","frm",3*l,3*l,l,"g1m_timesFr"),na(t,"g1m_batchApplyKeyMixed","g1m","frm",2*l,3*l,l,"g1m_timesFrAffine"),na(t,"g2m_batchApplyKey","g2m","frm",2*l*3,3*l*2,l,"g2m_timesFr"),na(t,"g2m_batchApplyKeyMixed","g2m","frm",2*l*2,3*l*2,l,"g2m_timesFrAffine");const x=[1n,2n,1n],y=t.alloc([...Yt.bigInt2BytesLE(b(x[0]),s),...Yt.bigInt2BytesLE(b(x[1]),s),...Yt.bigInt2BytesLE(b(x[2]),s)]),F=[0n,1n,0n],C=t.alloc([...Yt.bigInt2BytesLE(b(F[0]),s),...Yt.bigInt2BytesLE(b(F[1]),s),...Yt.bigInt2BytesLE(b(F[2]),s)]),B=[[10857046999023057135944570762232829481370756359578518086990519993285655852781n,11559732032986387107991004021392285783925812861821192530917403151452391805634n],[8495653923123431417604973247489272438418190587263600148770280649306958101930n,4082367875863433681332203403145435568316851327593401208105741076214120093531n],[1n,0n]],P=t.alloc([...Yt.bigInt2BytesLE(b(B[0][0]),s),...Yt.bigInt2BytesLE(b(B[0][1]),s),...Yt.bigInt2BytesLE(b(B[1][0]),s),...Yt.bigInt2BytesLE(b(B[1][1]),s),...Yt.bigInt2BytesLE(b(B[2][0]),s),...Yt.bigInt2BytesLE(b(B[2][1]),s)]),A=[[0n,0n],[1n,0n],[0n,0n]],w=t.alloc([...Yt.bigInt2BytesLE(b(A[0][0]),s),...Yt.bigInt2BytesLE(b(A[0][1]),s),...Yt.bigInt2BytesLE(b(A[1][0]),s),...Yt.bigInt2BytesLE(b(A[1][1]),s),...Yt.bigInt2BytesLE(b(A[2][0]),s),...Yt.bigInt2BytesLE(b(A[2][1]),s)]),q=t.alloc([...Yt.bigInt2BytesLE(b(1),s),...Yt.bigInt2BytesLE(b(0),s),...Yt.bigInt2BytesLE(b(0),s),...Yt.bigInt2BytesLE(b(0),s),...Yt.bigInt2BytesLE(b(0),s),...Yt.bigInt2BytesLE(b(0),s),...Yt.bigInt2BytesLE(b(0),s),...Yt.bigInt2BytesLE(b(0),s),...Yt.bigInt2BytesLE(b(0),s),...Yt.bigInt2BytesLE(b(0),s),...Yt.bigInt2BytesLE(b(0),s),...Yt.bigInt2BytesLE(b(0),s)]),v=t.alloc([...Yt.bigInt2BytesLE(b(9),s),...Yt.bigInt2BytesLE(b(1),s)]),I=t.alloc([...Yt.bigInt2BytesLE(b(ra(2n,e)),s),...Yt.bigInt2BytesLE(0n,s)]),O=v,E=t.alloc([...Yt.bigInt2BytesLE(b(19485874751759354771024239261021720505790618469301721065564631296452457478373n),s),...Yt.bigInt2BytesLE(b(266929791119991161246907387137283842545076965332900288569378510910307636690n),s)]);!function(){const a=t.addFunction(o+"_mulNR6");a.addParam("x","i32"),a.addParam("pr","i32");const e=a.getCodeBuilder();a.addCode(e.call(p+"_mul",e.i32_const(v),e.getLocal("x"),e.getLocal("pr")))}();const M=oa(t,o+"_mulNR6","f6m","f2m");!function(){const a=t.addFunction(o+"_mulNR12");a.addParam("x","i32"),a.addParam("pr","i32");const e=a.getCodeBuilder();a.addCode(e.call(p+"_mul",e.i32_const(v),e.i32_add(e.getLocal("x"),e.i32_const(4*l)),e.getLocal("pr")),e.call(p+"_copy",e.getLocal("x"),e.i32_add(e.getLocal("pr"),e.i32_const(2*l))),e.call(p+"_copy",e.i32_add(e.getLocal("x"),e.i32_const(2*l)),e.i32_add(e.getLocal("pr"),e.i32_const(4*l))))}();const S=aa(t,o+"_mulNR12","ftm",M),z=function(t){let a=t;const o=[];for(;a>0n;)da(a)?o.push(1):o.push(0),a>>=1n;return o}(29793968203157093288n),T=t.alloc(z),k=3*r,G=z.length-1,N=z.reduce((t,a)=>t+(0!=a?1:0),0),R=6*l,j=3*l*2+(N+G+1)*k;t.modules[o]={n64:c,pG1gen:y,pG1zero:C,pG1b:g,pG2gen:P,pG2zero:w,pG2b:f,pq:t.modules.f1m.pq,pr:_,pOneT:q,prePSize:R,preQSize:j,r:i.toString(),q:e.toString()};function U(a){const i=[[[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n]],[[1n,0n],[8376118865763821496583973867626364092589906065868298776909617916018768340080n,16469823323077808223889137241176536799009286646108169935659301613961712198316n],[21888242871839275220042445260109153167277707414472061641714758635765020556617n,0n],[11697423496358154304825782922584725312912383441159505038794027105778954184319n,303847389135065887422783454877609941456349188919719272345083954437860409601n],[21888242871839275220042445260109153167277707414472061641714758635765020556616n,0n],[3321304630594332808241809054958361220322477375291206261884409189760185844239n,5722266937896532885780051958958348231143373700109372999374820235121374419868n],[21888242871839275222246405745257275088696311157297823662689037894645226208582n,0n],[13512124006075453725662431877630910996106405091429524885779419978626457868503n,5418419548761466998357268504080738289687024511189653727029736280683514010267n],[2203960485148121921418603742825762020974279258880205651966n,0n],[10190819375481120917420622822672549775783927716138318623895010788866272024264n,21584395482704209334823622290379665147239961968378104390343953940207365798982n],[2203960485148121921418603742825762020974279258880205651967n,0n],[18566938241244942414004596690298913868373833782006617400804628704885040364344n,16165975933942742336466353786298926857552937457188450663314217659523851788715n]]],c=[[[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n]],[[1n,0n],[2157546363828084301039832426943
10826099269044274347216827212613867836435027261n,10307601595873709700152284273816112264069230130616436755625194854815875713954n],[21888242871839275220042445260109153167277707414472061641714758635765020556616n,0n],[3772000881919853776433695186713858239009073593817195771773381919316419345261n,2236595495967245188281701248203181795121068902605861227855261137820944008926n],[2203960485148121921418603742825762020974279258880205651966n,0n],[18429021223477853657660792034369865839114504446431234726392080002137598044644n,9344045779998320333812420223237981029506012124075525679208581902008406485703n]],[[1n,0n],[2581911344467009335267311115468803099551665605076196740867805258568234346338n,19937756971775647987995932169929341994314640652964949448313374472400716661030n],[2203960485148121921418603742825762020974279258880205651966n,0n],[5324479202449903542726783395506214481928257762400643279780343368557297135718n,16208900380737693084919495127334387981393726419856888799917914180988844123039n],[21888242871839275220042445260109153167277707414472061641714758635765020556616n,0n],[13981852324922362344252311234282257507216387789820983642040889267519694726527n,7629828391165209371577384193250820201684255241773809077146787135900891633097n]]],l=t.addFunction(o+"__frobeniusMap"+a);l.addParam("x","i32"),l.addParam("r","i32");const n=l.getCodeBuilder();for(let o=0;o<6;o++){const e=0==o?n.getLocal("x"):n.i32_add(n.getLocal("x"),n.i32_const(o*r)),_=e,g=n.i32_add(n.getLocal("x"),n.i32_const(o*r+s)),L=0==o?n.getLocal("r"):n.i32_add(n.getLocal("r"),n.i32_const(o*r)),f=L,m=n.i32_add(n.getLocal("r"),n.i32_const(o*r+s)),h=d(i[Math.floor(o/3)][a%12],c[o%3][a%6]),x=t.alloc([...Yt.bigInt2BytesLE(b(h[0]),32),...Yt.bigInt2BytesLE(b(h[1]),32)]);a%2==1?l.addCode(n.call(u+"_copy",_,f),n.call(u+"_neg",g,m),n.call(p+"_mul",L,n.i32_const(x),L)):l.addCode(n.call(p+"_mul",e,n.i32_const(x),L))}function d(t,a){const o=BigInt(t[0]),i=BigInt(t[1]),c=BigInt(a[0]),l=BigInt(a[1]),n=[(o*c-i*l)%e,(o*l+i*c)%e];return _a(n[0])&&(n[0]=n[0]+e),n}}function Z(a,e){const i=function(t){let a=t;const o=[];for(;a>0n;){if(da(a)){const t=2-Number(a%4n);o.push(t),a-=BigInt(t)}else o.push(0);a>>=1n}return o}(a).map(t=>-1==t?255:t),c=t.alloc(i),l=t.addFunction(o+"__cyclotomicExp_"+e);l.addParam("x","i32"),l.addParam("r","i32"),l.addLocal("bit","i32"),l.addLocal("i","i32");const n=l.getCodeBuilder(),s=n.getLocal("x"),r=n.getLocal("r"),_=n.i32_const(t.alloc(d));l.addCode(n.call(S+"_conjugate",s,_),n.call(S+"_one",r),n.if(n.teeLocal("bit",n.i32_load8_s(n.i32_const(i.length-1),c)),n.if(n.i32_eq(n.getLocal("bit"),n.i32_const(1)),n.call(S+"_mul",r,s,r),n.call(S+"_mul",r,_,r))),n.setLocal("i",n.i32_const(i.length-2)),n.block(n.loop(n.call(o+"__cyclotomicSquare",r,r),n.if(n.teeLocal("bit",n.i32_load8_s(n.getLocal("i"),c)),n.if(n.i32_eq(n.getLocal("bit"),n.i32_const(1)),n.call(S+"_mul",r,s,r),n.call(S+"_mul",r,_,r))),n.br_if(1,n.i32_eqz(n.getLocal("i"))),n.setLocal("i",n.i32_sub(n.getLocal("i"),n.i32_const(1))),n.br(0))))}function $(){!function(){const a=t.addFunction(o+"__cyclotomicSquare");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder(),i=e.getLocal("x"),c=e.i32_add(e.getLocal("x"),e.i32_const(r)),l=e.i32_add(e.getLocal("x"),e.i32_const(2*r)),n=e.i32_add(e.getLocal("x"),e.i32_const(3*r)),s=e.i32_add(e.getLocal("x"),e.i32_const(4*r)),d=e.i32_add(e.getLocal("x"),e.i32_const(5*r)),_=e.getLocal("r"),u=e.i32_add(e.getLocal("r"),e.i32_const(r)),g=e.i32_add(e.getLocal("r"),e.i32_const(2*r)),L=e.i32_add(e.getLocal("r"),e.i32_const(3*r)),f=e.i32_add(e.getLocal("r"),e.i32_const(4*r)),m=e.i32_add(e.getLocal("r"),e.i32_const(5*r)),h=e.i32_const(t.alloc(r)),b=e.i32_const(t.alloc(r)),x=e.i32_const(t.alloc(r)),y=e.i32_const(t.alloc(r)),F=e.i32_const(t.alloc(r)),C=e.i32_const(t.alloc(r)),B=e.i32_const(t.alloc(r)),P=e.i32_const(t.alloc(r));a.addCode(e.call(p+"_mul",i,s,B),e.call(p+"_mul",s,e.i32_const(v),h),e.call(p+"_add",i,h,h),e.call(p+"_add",i,s,P),e.call(p+"_mul",P,h,h),e.call(p+"_mul",e.i32_const(v),B,P),e.call(p+"_add",B,P,P),e.call(p+"_sub",h,P,h),e.call(p+"_add",B,B,b),e.call(p+"_mul",n,l,B),e.call(p+"_mul",l,e.i32_const(v),x),e.call(p+"_add",n,x,x),e.call(p+"_add",n,l,P),e.call(p+"_mul",P,x,x),e.call(p+"_mul",e.i32_const(v),B,P),e.call(p+"_add",B,P,P),e.call(p+"_sub",x,P,x),e.call(p+"_add",B,B,y),e.call(p+"_mul",c,d,B),e.call(p+"_mul",d,e.i32_const(v),F),e.call(p+"_add",c,F,F),e.call(p+"_add",c,d,P),e.call(p+"_mul",P,F,F),e.call(p+"_mul",e.i32_const(v),B,P),e.call(p+"_add",B,P,P),e.call(p+"_sub",F,P,F),e.call(p+"_add",B,B,C),e.call(p+"_sub",h,i,_),e.call(p+"_add",_,_,_),e.call(p+"_add",h,_,_),e.call(p+"_add",b,s,f),e.call(p+"_add",f,f,f),e.call(p+"_add",b,f,f),e.call(p+"_mul",C,e.i32_const(O),P),e.call(p+"_add",P,n,L),e.call(p+"_add",L,L,L),e.call(p+"_add",P,L,L),e.call(p+"_sub",F,l,g),e.call(p+"_add",g,g,g),e.call(p+"_add",F,g,g),e.call(p+"_sub",x,c,u),e.call(p+"_add",u,u,u),e.call(p+"_add",x,u,u),e.call(p+"_add",y,d,m),e.call(p+"_add",m,m,m),e.call(p+"_add",y,m,m))}(),Z(4965661367192848881n,"w0");const a=t.addFunction(o+"__finalExponentiationLastChunk");a.addParam("x","i32"),a.addParam("r","i32");
1const e=a.getCodeBuilder(),i=e.getLocal("x"),c=e.getLocal("r"),l=e.i32_const(t.alloc(d)),n=e.i32_const(t.alloc(d)),s=e.i32_const(t.alloc(d)),_=e.i32_const(t.alloc(d)),u=e.i32_const(t.alloc(d)),g=e.i32_const(t.alloc(d)),L=e.i32_const(t.alloc(d)),f=e.i32_const(t.alloc(d)),m=e.i32_const(t.alloc(d)),h=e.i32_const(t.alloc(d)),b=e.i32_const(t.alloc(d)),x=e.i32_const(t.alloc(d)),y=e.i32_const(t.alloc(d)),F=e.i32_const(t.alloc(d)),C=e.i32_const(t.alloc(d)),B=e.i32_const(t.alloc(d)),P=e.i32_const(t.alloc(d)),A=e.i32_const(t.alloc(d)),w=e.i32_const(t.alloc(d)),q=e.i32_const(t.alloc(d)),I=e.i32_const(t.alloc(d));a.addCode(e.call(o+"__cyclotomicExp_w0",i,l),e.call(S+"_conjugate",l,l),e.call(o+"__cyclotomicSquare",l,n),e.call(o+"__cyclotomicSquare",n,s),e.call(S+"_mul",s,n,_),e.call(o+"__cyclotomicExp_w0",_,u),e.call(S+"_conjugate",u,u),e.call(o+"__cyclotomicSquare",u,g),e.call(o+"__cyclotomicExp_w0",g,L),e.call(S+"_conjugate",L,L),e.call(S+"_conjugate",_,f),e.call(S+"_conjugate",L,m),e.call(S+"_mul",m,u,h),e.call(S+"_mul",h,f,b),e.call(S+"_mul",b,n,x),e.call(S+"_mul",b,u,y),e.call(S+"_mul",y,i,F),e.call(o+"__frobeniusMap1",x,C),e.call(S+"_mul",C,F,B),e.call(o+"__frobeniusMap2",b,P),e.call(S+"_mul",P,B,A),e.call(S+"_conjugate",i,w),e.call(S+"_mul",w,x,q),e.call(o+"__frobeniusMap3",q,I),e.call(S+"_mul",I,A,c))}const Q=t.alloc(R),J=t.alloc(j);function D(a){const e=t.addFunction(o+"_pairingEq"+a);for(let t=0;t<a;t++)e.addParam("p_"+t,"i32"),e.addParam("q_"+t,"i32");e.addParam("c","i32"),e.setReturnType("i32");const i=e.getCodeBuilder(),c=i.i32_const(t.alloc(d)),l=i.i32_const(t.alloc(d));e.addCode(i.call(S+"_one",c));for(let t=0;t<a;t++)e.addCode(i.call(o+"_prepareG1",i.getLocal("p_"+t),i.i32_const(Q))),e.addCode(i.call(o+"_prepareG2",i.getLocal("q_"+t),i.i32_const(J))),e.addCode(i.call(o+"_millerLoop",i.i32_const(Q),i.i32_const(J),l)),e.addCode(i.call(S+"_mul",c,l,c));e.addCode(i.call(o+"_finalExponentiation",c,c)),e.addCode(i.call(S+"_eq",c,i.getLocal("c")))}!function(){const a=t.addFunction(o+"_prepAddStep");a.addParam("pQ","i32"),a.addParam("pR","i32"),a.addParam("pCoef","i32");const e=a.getCodeBuilder(),i=e.getLocal("pQ"),c=e.i32_add(e.getLocal("pQ"),e.i32_const(r)),l=e.getLocal("pR"),n=e.i32_add(e.getLocal("pR"),e.i32_const(r)),s=e.i32_add(e.getLocal("pR"),e.i32_const(2*r)),d=e.getLocal("pCoef"),_=e.i32_add(e.getLocal("pCoef"),e.i32_const(r)),u=e.i32_add(e.getLocal("pCoef"),e.i32_const(2*r)),g=_,L=e.i32_const(t.alloc(r)),f=e.i32_const(t.alloc(r)),m=e.i32_const(t.alloc(r)),h=e.i32_const(t.alloc(r)),b=e.i32_const(t.alloc(r)),x=e.i32_const(t.alloc(r)),y=e.i32_const(t.alloc(r));a.addCode(e.call(p+"_mul",i,s,g),e.call(p+"_sub",l,g,g),e.call(p+"_mul",c,s,L),e.call(p+"_sub",n,L,L),e.call(p+"_square",g,f),e.call(p+"_square",L,m),e.call(p+"_mul",g,f,h),e.call(p+"_mul",l,f,b),e.call(p+"_add",b,b,y),e.call(p+"_mul",s,m,x),e.call(p+"_add",h,x,x),e.call(p+"_sub",x,y,x),e.call(p+"_mul",g,x,l),e.call(p+"_mul",h,n,n),e.call(p+"_sub",b,x,y),e.call(p+"_mul",L,y,y),e.call(p+"_sub",y,n,n),e.call(p+"_mul",s,h,s),e.call(p+"_mul",g,c,y),e.call(p+"_mul",L,i,d),e.call(p+"_sub",d,y,d),e.call(p+"_mul",d,e.i32_const(O),d),e.call(p+"_neg",L,u))}(),function(){const a=t.addFunction(o+"_prepDblStep");a.addParam("pR","i32"),a.addParam("pCoef","i32");const e=a.getCodeBuilder(),i=e.getLocal("pR"),c=e.i32_add(e.getLocal("pR"),e.i32_const(r)),l=e.i32_add(e.getLocal("pR"),e.i32_const(2*r)),n=e.getLocal("pCoef"),s=e.i32_add(e.getLocal("pCoef"),e.i32_const(r)),d=e.i32_add(e.getLocal("pCoef"),e.i32_const(2*r)),_=e.i32_const(t.alloc(r)),u=e.i32_const(t.alloc(r)),g=e.i32_const(t.alloc(r)),L=e.i32_const(t.alloc(r)),f=e.i32_const(t.alloc(r)),m=e.i32_const(t.alloc(r)),h=e.i32_const(t.alloc(r)),b=e.i32_const(t.alloc(r)),x=e.i32_const(t.alloc(r)),y=e.i32_const(t.alloc(r)),F=e.i32_const(t.alloc(r)),C=e.i32_const(t.alloc(r));a.addCode(e.call(p+"_mul",c,e.i32_const(I),_),e.call(p+"_mul",i,_,_),e.call(p+"_square",c,u),e.call(p+"_square",l,g),e.call(p+"_add",g,g,L),e.call(p+"_add",L,g,L),e.call(p+"_mul",e.i32_const(E),L,f),e.call(p+"_add",f,f,m),e.call(p+"_add",f,m,m),e.call(p+"_add",u,m,h),e.call(p+"_mul",h,e.i32_const(I),h),e.call(p+"_add",u,g,C),e.call(p+"_add",c,l,b),e.call(p+"_square",b,b),e.call(p+"_sub",b,C,b),e.call(p+"_sub",f,u,x),e.call(p+"_square",i,y),e.call(p+"_square",f,F),e.call(p+"_sub",u,m,C),e.call(p+"_mul",_,C,i),e.call(p+"_add",F,F,C),e.call(p+"_add",F,C,C),e.call(p+"_square",h,c),e.call(p+"_sub",c,C,c),e.call(p+"_mul",u,b,l),e.call(p+"_mul",e.i32_const(O),x,n),e.call(p+"_neg",b,s),e.call(p+"_add",y,y,d),e.call(p+"_add",y,d,d))}(),function(){const a=t.addFunction(o+"_prepareG1");a.addParam("pP","i32"),a.addParam("ppreP","i32");const e=a.getCodeBuilder();a.addCode(e.call(L+"_normalize",e.getLocal("pP"),e.getLocal("ppreP")))}(),function(){!function(){const a=t.addFunction(o+"_mulByQ");a.addParam("p1","i32"),a.addParam("pr","i32");
1const e=a.getCodeBuilder(),i=e.getLocal("p1"),c=e.i32_add(e.getLocal("p1"),e.i32_const(r)),l=e.i32_add(e.getLocal("p1"),e.i32_const(2*r)),n=e.getLocal("pr"),d=e.i32_add(e.getLocal("pr"),e.i32_const(r)),_=e.i32_add(e.getLocal("pr"),e.i32_const(2*r)),u=e.i32_const(t.alloc([...Yt.bigInt2BytesLE(b("21575463638280843010398324269430826099269044274347216827212613867836435027261"),s),...Yt.bigInt2BytesLE(b("10307601595873709700152284273816112264069230130616436755625194854815875713954"),s)])),g=e.i32_const(t.alloc([...Yt.bigInt2BytesLE(b("2821565182194536844548159561693502659359617185244120367078079554186484126554"),s),...Yt.bigInt2BytesLE(b("3505843767911556378687030309984248845540243509899259641013678093033130930403"),s)]));a.addCode(e.call(p+"_conjugate",i,n),e.call(p+"_mul",u,n,n),e.call(p+"_conjugate",c,d),e.call(p+"_mul",g,d,d),e.call(p+"_conjugate",l,_))}();const a=t.addFunction(o+"_prepareG2");a.addParam("pQ","i32"),a.addParam("ppreQ","i32"),a.addLocal("pCoef","i32"),a.addLocal("i","i32");const e=a.getCodeBuilder(),i=e.getLocal("pQ"),c=t.alloc(3*r),l=e.i32_const(c),n=e.i32_const(c),d=e.i32_const(c+r),_=e.i32_const(c+2*r),u=e.i32_add(e.getLocal("ppreQ"),e.i32_const(0)),g=e.i32_add(e.getLocal("ppreQ"),e.i32_const(r)),L=t.alloc(3*r),f=e.i32_const(L),h=t.alloc(3*r),x=e.i32_const(h),y=e.i32_const(h+r);a.addCode(e.call(m+"_normalize",i,u),e.call(p+"_copy",u,n),e.call(p+"_copy",g,d),e.call(p+"_one",_)),a.addCode(e.setLocal("pCoef",e.i32_add(e.getLocal("ppreQ"),e.i32_const(3*r))),e.setLocal("i",e.i32_const(z.length-2)),e.block(e.loop(e.call(o+"_prepDblStep",l,e.getLocal("pCoef")),e.setLocal("pCoef",e.i32_add(e.getLocal("pCoef"),e.i32_const(k))),e.if(e.i32_load8_s(e.getLocal("i"),T),[...e.call(o+"_prepAddStep",u,l,e.getLocal("pCoef")),...e.setLocal("pCoef",e.i32_add(e.getLocal("pCoef"),e.i32_const(k)))]),e.br_if(1,e.i32_eqz(e.getLocal("i"))),e.setLocal("i",e.i32_sub(e.getLocal("i"),e.i32_const(1))),e.br(0)))),a.addCode(e.call(o+"_mulByQ",u,f),e.call(o+"_mulByQ",f,x)),a.addCode(e.call(p+"_neg",y,y),e.call(o+"_prepAddStep",f,l,e.getLocal("pCoef")),e.setLocal("pCoef",e.i32_add(e.getLocal("pCoef"),e.i32_const(k))),e.call(o+"_prepAddStep",x,l,e.getLocal("pCoef")),e.setLocal("pCoef",e.i32_add(e.getLocal("pCoef"),e.i32_const(k))))}(),function(){const a=t.addFunction(o+"__mulBy024");a.addParam("pEll0","i32"),a.addParam("pEllVW","i32"),a.addParam("pEllVV","i32"),a.addParam("pR","i32");const e=a.getCodeBuilder(),i=e.getLocal("pEll0"),c=e.getLocal("pEllVV"),n=e.getLocal("pEllVW"),s=e.getLocal("pR"),d=e.i32_add(e.getLocal("pR"),e.i32_const(2*l)),_=e.i32_add(e.getLocal("pR"),e.i32_const(4*l)),u=e.i32_add(e.getLocal("pR"),e.i32_const(6*l)),g=e.i32_add(e.getLocal("pR"),e.i32_const(8*l)),L=e.i32_add(e.getLocal("pR"),e.i32_const(10*l)),f=e.i32_const(t.alloc(r)),m=e.i32_const(t.alloc(r)),h=e.i32_const(t.alloc(r)),b=e.i32_const(t.alloc(r)),x=e.i32_const(t.alloc(r)),y=e.i32_const(t.alloc(r)),F=e.i32_const(t.alloc(r)),C=e.i32_const(t.alloc(r)),B=e.i32_const(t.alloc(r)),P=e.i32_const(t.alloc(r)),A=e.i32_const(t.alloc(r));a.addCode(e.call(p+"_mul",s,i,F),e.call(p+"_mul",_,c,C),e.call(p+"_mul",g,n,B),e.call(p+"_add",s,g,h),e.call(p+"_add",s,_,m),e.call(p+"_add",d,u,b),e.call(p+"_add",b,L,b),e.call(p+"_mul",d,c,P),e.call(p+"_add",P,B,x),e.call(p+"_mul",e.i32_const(v),x,y),e.call(p+"_add",y,F,s),e.call(p+"_mul",L,n,x),e.call(p+"_add",P,x,P),e.call(p+"_add",x,C,x),e.call(p+"_mul",e.i32_const(v),x,y),e.call(p+"_mul",d,i,x),e.call(p+"_add",P,x,P),e.call(p+"_add",y,x,d),e.call(p+"_add",i,c,f),e.call(p+"_mul",m,f,x),e.call(p+"_add",F,C,A),e.call(p+"_sub",x,A,x),e.call(p+"_mul",u,n,y),e.call(p+"_add",P,y,P),e.call(p+"_add",_,g,f),e.call(p+"_add",x,y,_),e.call(p+"_add",c,n,m),e.call(p+"_mul",m,f,x),e.call(p+"_add",C,B,A),e.call(p+"_sub",x,A,x),e.call(p+"_mul",e.i32_const(v),x,y),e.call(p+"_mul",u,i,x),e.call(p+"_add",P,x,P),e.call(p+"_add",y,x,u),e.call(p+"_mul",L,c,x),e.call(p+"_add",P,x,P),e.call(p+"_mul",e.i32_const(v),x,y),e.call(p+"_add",i,n,f),e.call(p+"_mul",h,f,x),e.call(p+"_add",F,B,A),e.call(p+"_sub",x,A,x),e.call(p+"_add",y,x,g),e.call(p+"_add",i,c,f),e.call(p+"_add",f,n,f),e.call(p+"_mul",b,f,x),e.call(p+"_sub",x,P,L))}(),function(){const a=t.addFunction(o+"__mulBy024Old");a.addParam("pEll0","i32"),a.addParam("pEllVW","i32"),a.addParam("pEllVV","i32"),a.addParam("pR","i32");const e=a.getCodeBuilder(),i=e.getLocal("pEll0"),c=e.getLocal("pEllVV"),l=e.getLocal("pEllVW"),n=e.getLocal("pR"),s=t.alloc(d),_=e.i32_const(s),u=e.i32_const(s),g=e.i32_const(s+r),L=e.i32_const(s+2*r),f=e.i32_const(s+3*r),m=e.i32_const(s+4*r),h=e.i32_const(s+5*r);a.addCode(e.call(p+"_copy",i,u),e.call(p+"_zero",g),e.call(p+"_copy",c,L),e.call(p+"_zero",f),e.call(p+"_copy",l,m),e.call(p+"_zero",h),e.call(S+"_mul",_,n,n))}(),function(){const a=t.addFunction(o+"_millerLoop");a.addParam("ppreP","i32"),a.addParam("ppreQ","i32"),a.addParam("r","i32"),a.addLocal("pCoef","i32"),a.addLocal("i","i32");const e=a.getCodeBuilder(),i=e.getLocal("ppreP"),c=e.i32_add(e.getLocal("ppreP"),e.i32_const(s)),l=e.getLocal("pCoef"),n=e.i32_add(e.getLocal("pCoef"),e.i32_const(r)),d=e.i32_add(e.getLocal("pCoef"),e.i32_const(2*r)),_=t.alloc(r),u=e.i32_const(_),g=t.alloc(r),L=e.i32_const(g),f=e.getLocal("r");a.addCode(e.call(S+"_one",f),e.setLocal("pCoef",e.i32_add(e.getLocal("ppreQ"),e.i32_const(3*r))),e.setLocal("i",e.i32_const(z.length-2)),e.block(e.loop(e.call(S+"_square",f,f),e.call(p+"_mul1",n,c,u),e.call(p+"_mul1",d,i,L),e.call(o+"__mulBy024",l,u,L,f),e.setLocal("pCoef",e.i32_add(e.getLocal("pCoef"),e.i32_const(k))),e.if(e.i32_load8_s(e.getLocal("i"),T),[...e.call(p+"_mul1",n,c,u),...e.call(p+"_mul1",d,i,L),...e.call(o+"__mulBy024",l,u,L,f),...e.setLocal("pCoef",e.i32_add(e.getLocal("pCoef"),e.i32_const(k)))]),e.br_if(1,e.i32_eqz(e.getLocal("i"))),e.setLocal("i",e.i32_sub(e.getLocal("i"),e.i32_const(1))),e.br(0)))),a.addCode(e.call(p+"_mul1",n,c,u),e.call(p+"_mul1",d,i,L),e.call(o+"__mulBy024",l,u,L,f),e.setLocal("pCoef",e.i32_add(e.getLocal("pCoef"),e.i32_const(k))),e.call(p+"_mul1",n,c,u),e.call(p+"_mul1",d,i,L),e.call(o+"__mulBy024",l,u,L,f),e.setLocal("pCoef",e.i32_add(e.getLocal("pCoef"),e.i32_const(k))))}();for(let a=0;a<10;a++)U(a),t.exportFunction(o+"__frobeniusMap"+a);!function(){const a=t.addFunction(o+"_finalExponentiationOld");a.addParam("x","i32"),a.addParam("r","i32");const e=t.alloc(Yt.bigInt2BytesLE(552484233613224096312617126783173147097382103762957654188882734314196910839907541213974502761540629817009608548654680343627701153829446747810907373256841551006201639677726139946029199968412598804882391702273019083653272047566316584365559776493027495458238373902875937659943504873220554161550525926302303331747463515644711876653177129578303191095900909191624817826566688241804408081892785725967931714097716709526092261278071952560171111444072049229123565057483750161460024353346284167282452756217662335528813519139808291170539072125381230815729071544861602750936964829313608137325426383735122175229541155376346436093930287402089517426973178917569713384748081827255472576937471496195752727188261435633271238710131736096299798168852925540549342330775279877006784354801422249722573783561685179618816480037695005515426162362431072245638324744480n,352)),i=a.getCodeBuilder();a.addCode(i.call(S+"_exp",i.getLocal("x"),i.i32_const(e),i.i32_const(352),i.getLocal("r")))}(),function(){!function(){const a=t.addFunction(o+"__finalExponentiationFirstChunk");a.addParam("x","i32"),a.addParam("r","i32");
1const e=a.getCodeBuilder(),i=e.getLocal("x"),c=i,n=e.i32_add(i,e.i32_const(6*l)),s=e.getLocal("r"),r=t.alloc(d),_=e.i32_const(r),u=_,g=e.i32_const(r+6*l),L=e.i32_const(t.alloc(d)),p=e.i32_const(t.alloc(d)),f=e.i32_const(t.alloc(d));a.addCode(e.call(M+"_copy",c,u),e.call(M+"_neg",n,g),e.call(S+"_inverse",i,L),e.call(S+"_mul",_,L,p),e.call(o+"__frobeniusMap2",p,f),e.call(S+"_mul",p,f,s))}(),$();const a=t.addFunction(o+"_finalExponentiation");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder(),i=e.getLocal("x"),c=e.getLocal("r"),n=e.i32_const(t.alloc(d));a.addCode(e.call(o+"__finalExponentiationFirstChunk",i,n),e.call(o+"__finalExponentiationLastChunk",n,c))}();for(let a=1;a<=5;a++)D(a),t.exportFunction(o+"_pairingEq"+a);!function(){const a=t.addFunction(o+"_pairing");a.addParam("p","i32"),a.addParam("q","i32"),a.addParam("r","i32");const e=a.getCodeBuilder(),i=e.i32_const(t.alloc(d));a.addCode(e.call(o+"_prepareG1",e.getLocal("p"),e.i32_const(Q))),a.addCode(e.call(o+"_prepareG2",e.getLocal("q"),e.i32_const(J))),a.addCode(e.call(o+"_millerLoop",e.i32_const(Q),e.i32_const(J),i)),a.addCode(e.call(o+"_finalExponentiation",i,e.getLocal("r")))}(),t.exportFunction(o+"_pairing"),t.exportFunction(o+"_prepareG1"),t.exportFunction(o+"_prepareG2"),t.exportFunction(o+"_millerLoop"),t.exportFunction(o+"_finalExponentiation"),t.exportFunction(o+"_finalExponentiationOld"),t.exportFunction(o+"__mulBy024"),t.exportFunction(o+"__mulBy024Old"),t.exportFunction(o+"__cyclotomicSquare"),t.exportFunction(o+"__cyclotomicExp_w0")},Aa=function(t,a){const o=a||"bls12381";if(t.modules[o])return o;const e=0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaabn,i=0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001n,c=Math.floor((Fa(e-1n)-1)/64)+1,l=8*c,n=l,s=2*n,r=12*n,d=Math.floor((Fa(i-1n)-1)/64)+1,_=8*d,u=_,g=t.alloc(ua.bigInt2BytesLE(i,u)),L=ga(t,e,"f1m","intq");La(t,i,"fr","frm","intr");const p=t.alloc(ua.bigInt2BytesLE(y(4n),n)),f=ma(t,"g1m","f1m",p);ha(t,"frm","frm","frm","frm_mul"),ba(t,"pol","frm"),xa(t,"qap","frm");const m=pa(t,"f1m_neg","f2m","f1m"),h=t.alloc([...ua.bigInt2BytesLE(y(4n),n),...ua.bigInt2BytesLE(y(4n),n)]),b=ma(t,"g2m","f2m",h);function x(a,o){const e=t.addFunction(a);e.addParam("pG","i32"),e.addParam("pFr","i32"),e.addParam("pr","i32");const i=e.getCodeBuilder(),c=i.i32_const(t.alloc(_));e.addCode(i.call("frm_fromMontgomery",i.getLocal("pFr"),c),i.call(o,i.getLocal("pG"),c,i.i32_const(_),i.getLocal("pr"))),t.exportFunction(a)}function y(t){return BigInt(t)*(1n<<BigInt(8*n))%e}x("g1m_timesFr","g1m_timesScalar"),ha(t,"g1m","g1m","frm","g1m_timesFr"),x("g2m_timesFr","g2m_timesScalar"),ha(t,"g2m","g2m","frm","g2m_timesFr"),x("g1m_timesFrAffine","g1m_timesScalarAffine"),x("g2m_timesFrAffine","g2m_timesScalarAffine"),ya(t,"frm_batchApplyKey","fmr","frm",_,_,_,"frm_mul"),ya(t,"g1m_batchApplyKey","g1m","frm",3*l,3*l,_,"g1m_timesFr"),ya(t,"g1m_batchApplyKeyMixed","g1m","frm",2*l,3*l,_,"g1m_timesFrAffine"),ya(t,"g2m_batchApplyKey","g2m","frm",2*l*3,3*l*2,_,"g2m_timesFr"),ya(t,"g2m_batchApplyKeyMixed","g2m","frm",2*l*2,3*l*2,_,"g2m_timesFrAffine");const F=[3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507n,1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569n,1n],C=t.alloc([...ua.bigInt2BytesLE(y(F[0]),n),...ua.bigInt2BytesLE(y(F[1]),n),...ua.bigInt2BytesLE(y(F[2]),n)]),B=[0n,1n,0n],P=t.alloc([...ua.bigInt2BytesLE(y(B[0]),n),...ua.bigInt2BytesLE(y(B[1]),n),...ua.bigInt2BytesLE(y(B[2]),n)]),A=[[352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160n,3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758n],[1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905n,927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582n],[1n,0n]],w=t.alloc([...ua.bigInt2BytesLE(y(A[0][0]),n),...ua.bigInt2BytesLE(y(A[0][1]),n),...ua.bigInt2BytesLE(y(A[1][0]),n),...ua.bigInt2BytesLE(y(A[1][1]),n),...ua.bigInt2BytesLE(y(A[2][0]),n),...ua.bigInt2BytesLE(y(A[2][1]),n)]),q=[[0n,0n],[1n,0n],[0n,0n]],v=t.alloc([...ua.bigInt2BytesLE(y(q[0][0]),n),...ua.bigInt2BytesLE(y(q[0][1]),n),...ua.bigInt2BytesLE(y(q[1][0]),n),...ua.bigInt2BytesLE(y(q[1][1]),n),...ua.bigInt2BytesLE(y(q[2][0]),n),...ua.bigInt2BytesLE(y(q[2][1]),n)]),I=t.alloc([...ua.bigInt2BytesLE(y(1n),n),...ua.bigInt2BytesLE(y(0n),n),...ua.bigInt2BytesLE(y(0n),n),...ua.bigInt2BytesLE(y(0n),n),...ua.bigInt2BytesLE(y(0n),n),...ua.bigInt2BytesLE(y(0n),n),...ua.bigInt2BytesLE(y(0n),n),...ua.bigInt2BytesLE(y(0n),n),...ua.bigInt2BytesLE(y(0n),n),...ua.bigInt2BytesLE(y(0n),n),...ua.bigInt2BytesLE(y(0n),n),...ua.bigInt2BytesLE(y(0n),n)]),O=t.alloc([...ua.bigInt2BytesLE(y(1n),n),...ua.bigInt2BytesLE(y(1n),n)]);!function(){const a=t.addFunction(m+"_mulNR");a.addParam("x","i32"),a.addParam("pr","i32");const o=a.getCodeBuilder(),e=o.i32_const(t.alloc(n)),i=o.getLocal("x"),
1c=o.i32_add(o.getLocal("x"),o.i32_const(n)),l=o.getLocal("pr"),s=o.i32_add(o.getLocal("pr"),o.i32_const(n));a.addCode(o.call(L+"_copy",i,e),o.call(L+"_sub",i,c,l),o.call(L+"_add",e,c,s))}();const E=fa(t,m+"_mulNR","f6m","f2m");!function(){const a=t.addFunction(E+"_mulNR");a.addParam("x","i32"),a.addParam("pr","i32");const o=a.getCodeBuilder(),e=o.i32_const(t.alloc(2*n));a.addCode(o.call(m+"_copy",o.getLocal("x"),e),o.call(m+"_mulNR",o.i32_add(o.getLocal("x"),o.i32_const(4*l)),o.getLocal("pr")),o.call(m+"_copy",o.i32_add(o.getLocal("x"),o.i32_const(2*l)),o.i32_add(o.getLocal("pr"),o.i32_const(4*l))),o.call(m+"_copy",e,o.i32_add(o.getLocal("pr"),o.i32_const(2*l))))}();const M=pa(t,E+"_mulNR","ftm",E),S=function(t){let a=t;const o=[];for(;a>0n;)Ca(a)?o.push(1):o.push(0),a>>=1n;return o}(0xd201000000010000n),z=t.alloc(S),T=3*s,k=S.length-1,G=S.reduce((t,a)=>t+(0!=a?1:0),0),N=6*l,R=3*l*2+(G+k+1)*T,j=15132376222941642752n;function U(a){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],[3850754370037169011952147076051364057158807420970682438676050522613628423219637725072182697113062777891589506424760n,151655185184498381465642749684540099398075398968325446656007613510403227271200139370504932015952886146304766135027n],[793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620351n,0n],[2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530n,1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257n],[793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350n,0n],[3
1125332594171059424908108096204648978570118281977575435832422631601824034463382777937621250592425535493320683825557n,877076961050607968509681729531255177986764537961432449499635504522207616027455086505066378536590128544573588734230n],[4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559786n,0n],[151655185184498381465642749684540099398075398968325446656007613510403227271200139370504932015952886146304766135027n,3850754370037169011952147076051364057158807420970682438676050522613628423219637725072182697113062777891589506424760n],[4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436n,0n],[1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257n,2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530n],[4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437n,0n],[877076961050607968509681729531255177986764537961432449499635504522207616027455086505066378536590128544573588734230n,3125332594171059424908108096204648978570118281977575435832422631601824034463382777937621250592425535493320683825557n]]],i=[[[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n],[1n,0n]],[[1n,0n],[0n,4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436n],[793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350n,0n],[0n,1n],[4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436n,0n],[0n,793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350n]],[[1n,0n],[4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437n,0n],[4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436n,0n],[4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559786n,0n],[793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350n,0n],[793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620351n,0n]]],c=t.addFunction(M+"_frobeniusMap"+a);c.addParam("x","i32"),c.addParam("r","i32");const r=c.getCodeBuilder();for(let e=0;e<6;e++){const _=0==e?r.getLocal("x"):r.i32_add(r.getLocal("x"),r.i32_const(e*s)),u=_,g=r.i32_add(r.getLocal("x"),r.i32_const(e*s+n)),p=0==e?r.getLocal("r"):r.i32_add(r.getLocal("r"),r.i32_const(e*s)),f=p,h=r.i32_add(r.getLocal("r"),r.i32_const(e*s+n)),b=d(o[Math.floor(e/3)][a%12],i[e%3][a%6]),x=t.alloc([...ua.bigInt2BytesLE(y(b[0]),l),...ua.bigInt2BytesLE(y(b[1]),l)]);a%2==1?c.addCode(r.call(L+"_copy",u,f),r.call(L+"_neg",g,h),r.call(m+"_mul",p,r.i32_const(x),p)):c.addCode(r.call(m+"_mul",_,r.i32_const(x),p))}function d(t,a){const o=t[0],i=t[1],c=a[0],l=a[1],n=[(o*c-i*l)%e,(o*l+i*c)%e];return Ba(n[0])&&(n[0]=n[0]+e),n}}function Z(a,e,i){const c=function(t){let a=t;const o=[];for(;a>0n;){if(Ca(a)){const t=2-Number(a%4n);o.push(t),a-=BigInt(t)}else o.push(0);a>>=1n}return o}(a).map(t=>-1==t?255:t),l=t.alloc(c),n=t.addFunction(o+"__cyclotomicExp_"+i);n.addParam("x","i32"),n.addParam("r","i32"),n.addLocal("bit","i32"),n.addLocal("i","i32");const s=n.getCodeBuilder(),d=s.getLocal("x"),_=s.getLocal("r"),u=s.i32_const(t.alloc(r));n.addCode(s.call(M+"_conjugate",d,u),s.call(M+"_one",_),s.if(s.teeLocal("bit",s.i32_load8_s(s.i32_const(c.length-1),l)),s.if(s.i32_eq(s.getLocal("bit"),s.i32_const(1)),s.call(M+"_mul",_,d,_),s.call(M+"_mul",_,u,_))),s.setLocal("i",s.i32_const(c.length-2)),s.block(s.loop(s.call(o+"__cyclotomicSquare",_,_),s.if(s.teeLocal("bit",s.i32_load8_s(s.getLocal("i"),l)),s.if(s.i32_eq(s.getLocal("bit"),s.i32_const(1)),s.call(M+"_mul",_,d,_),s.call(M+"_mul",_,u,_))),s.br_if(1,s.i32_eqz(s.getLocal("i"))),s.setLocal("i",s.i32_sub(s.getLocal("i"),s.i32_const(1))),s.br(0)))),e&&n.addCode(s.call(M+"_conjugate",_,_))}
1t.modules[o]={n64q:c,n64r:d,n8q:l,n8r:_,pG1gen:C,pG1zero:P,pG1b:p,pG2gen:w,pG2zero:v,pG2b:h,pq:t.modules.f1m.pq,pr:g,pOneT:I,r:i,q:e,prePSize:N,preQSize:R},function(){const a=t.addFunction(E+"_mul1");a.addParam("pA","i32"),a.addParam("pC1","i32"),a.addParam("pR","i32");const o=a.getCodeBuilder(),e=o.getLocal("pA"),i=o.i32_add(o.getLocal("pA"),o.i32_const(2*n)),c=o.i32_add(o.getLocal("pA"),o.i32_const(4*n)),l=o.getLocal("pC1"),s=o.getLocal("pR"),r=o.i32_add(o.getLocal("pR"),o.i32_const(2*n)),d=o.i32_add(o.getLocal("pR"),o.i32_const(4*n)),_=o.i32_const(t.alloc(2*n)),u=o.i32_const(t.alloc(2*n));a.addCode(o.call(m+"_add",e,i,_),o.call(m+"_add",i,c,u),o.call(m+"_mul",i,l,d),o.call(m+"_mul",u,l,s),o.call(m+"_sub",s,d,s),o.call(m+"_mulNR",s,s),o.call(m+"_mul",_,l,r),o.call(m+"_sub",r,d,r))}(),function(){const a=t.addFunction(E+"_mul01");a.addParam("pA","i32"),a.addParam("pC0","i32"),a.addParam("pC1","i32"),a.addParam("pR","i32");const o=a.getCodeBuilder(),e=o.getLocal("pA"),i=o.i32_add(o.getLocal("pA"),o.i32_const(2*n)),c=o.i32_add(o.getLocal("pA"),o.i32_const(4*n)),l=o.getLocal("pC0"),s=o.getLocal("pC1"),r=o.getLocal("pR"),d=o.i32_add(o.getLocal("pR"),o.i32_const(2*n)),_=o.i32_add(o.getLocal("pR"),o.i32_const(4*n)),u=o.i32_const(t.alloc(2*n)),g=o.i32_const(t.alloc(2*n)),L=o.i32_const(t.alloc(2*n)),p=o.i32_const(t.alloc(2*n));a.addCode(o.call(m+"_mul",e,l,u),o.call(m+"_mul",i,s,g),o.call(m+"_add",e,i,L),o.call(m+"_add",e,c,p),o.call(m+"_add",i,c,r),o.call(m+"_mul",r,s,r),o.call(m+"_sub",r,g,r),o.call(m+"_mulNR",r,r),o.call(m+"_add",r,u,r),o.call(m+"_add",l,s,d),o.call(m+"_mul",d,L,d),o.call(m+"_sub",d,u,d),o.call(m+"_sub",d,g,d),o.call(m+"_mul",p,l,_),o.call(m+"_sub",_,u,_),o.call(m+"_add",_,g,_))}(),function(){const a=t.addFunction(M+"_mul014");a.addParam("pA","i32"),a.addParam("pC0","i32"),a.addParam("pC1","i32"),a.addParam("pC4","i32"),a.addParam("pR","i32");const o=a.getCodeBuilder(),e=o.getLocal("pA"),i=o.i32_add(o.getLocal("pA"),o.i32_const(6*n)),c=o.getLocal("pC0"),l=o.getLocal("pC1"),s=o.getLocal("pC4"),r=o.i32_const(t.alloc(6*n)),d=o.i32_const(t.alloc(6*n)),_=o.i32_const(t.alloc(2*n)),u=o.getLocal("pR"),g=o.i32_add(o.getLocal("pR"),o.i32_const(6*n));a.addCode(o.call(E+"_mul01",e,c,l,r),o.call(E+"_mul1",i,s,d),o.call(m+"_add",l,s,_),o.call(E+"_add",i,e,g),o.call(E+"_mul01",g,c,_,g),o.call(E+"_sub",g,r,g),o.call(E+"_sub",g,d,g),o.call(E+"_copy",d,u),o.call(E+"_mulNR",u,u),o.call(E+"_add",u,r,u))}(),function(){const a=t.addFunction(o+"_ell");a.addParam("pP","i32"),a.addParam("pCoefs","i32"),a.addParam("pF","i32");const e=a.getCodeBuilder(),i=e.getLocal("pP"),c=e.i32_add(e.getLocal("pP"),e.i32_const(l)),s=e.getLocal("pF"),r=e.getLocal("pCoefs"),d=e.i32_add(e.getLocal("pCoefs"),e.i32_const(n)),_=e.i32_add(e.getLocal("pCoefs"),e.i32_const(2*n)),u=e.i32_add(e.getLocal("pCoefs"),e.i32_const(3*n)),g=e.i32_add(e.getLocal("pCoefs"),e.i32_const(4*n)),p=t.alloc(2*n),f=e.i32_const(p),m=e.i32_const(p),h=e.i32_const(p+n),b=t.alloc(2*n),x=e.i32_const(b),y=e.i32_const(b),F=e.i32_const(b+n);a.addCode(e.call(L+"_mul",r,c,m),e.call(L+"_mul",d,c,h),e.call(L+"_mul",_,i,y),e.call(L+"_mul",u,i,F),e.call(M+"_mul014",s,g,x,f,s))}();const $=t.alloc(N),Q=t.alloc(R);function J(a){const e=t.addFunction(o+"_pairingEq"+a);for(let t=0;t<a;t++)e.addParam("p_"+t,"i32"),e.addParam("q_"+t,"i32");e.addParam("c","i32"),e.setReturnType("i32");const i=e.getCodeBuilder(),c=i.i32_const(t.alloc(r)),l=i.i32_const(t.alloc(r));e.addCode(i.call(M+"_one",c));for(let t=0;t<a;t++)e.addCode(i.call(o+"_prepareG1",i.getLocal("p_"+t),i.i32_const($))),e.addCode(i.call(o+"_prepareG2",i.getLocal("q_"+t),i.i32_const(Q))),e.addCode(i.if(i.i32_eqz(i.call(f+"_inGroupAffine",i.i32_const($))),i.ret(i.i32_const(0))),i.if(i.i32_eqz(i.call(b+"_inGroupAffine",i.i32_const(Q))),i.ret(i.i32_const(0)))),e.addCode(i.call(o+"_millerLoop",i.i32_const($),i.i32_const(Q),l)),e.addCode(i.call(M+"_mul",c,l,c));e.addCode(i.call(o+"_finalExponentiation",c,c)),e.addCode(i.call(M+"_eq",c,i.getLocal("c")))}for(let a=0;a<10;a++)U(a),t.exportFunction(M+"_frobeniusMap"+a);!function(){const a=t.addFunction(f+"_inGroupAffine");a.addParam("p","i32"),a.setReturnType("i32");const o=a.getCodeBuilder(),e=(j*j-1n)/3n,i=o.i32_const(t.alloc(ua.bigInt2BytesLE(y(4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436n),l))),c=o.i32_const(t.alloc(ua.bigInt2BytesLE(y(793479390729215512621379701633421447060886740281060493010456487427281649
1075476305620758731620350n),l))),s=o.i32_const(t.alloc(ua.bigInt2BytesLE(e,16))),r=o.getLocal("p"),d=o.i32_add(o.getLocal("p"),o.i32_const(n)),_=t.alloc(3*n),u=o.i32_const(_),g=o.i32_const(_),p=o.i32_const(_+n),m=t.alloc(2*n),h=o.i32_const(m),b=o.i32_const(m),x=o.i32_const(m+n);a.addCode(o.if(o.call(f+"_isZeroAffine",o.getLocal("p")),o.ret(o.i32_const(1))),o.if(o.i32_eqz(o.call(f+"_inCurveAffine",o.getLocal("p"))),o.ret(o.i32_const(0))),o.call(L+"_mul",r,i,g),o.call(L+"_copy",d,p),o.call(L+"_mul",r,c,b),o.call(L+"_copy",d,x),o.call(f+"_doubleAffine",u,u),o.call(f+"_subMixed",u,o.getLocal("p"),u),o.call(f+"_subMixed",u,h,u),o.call(f+"_timesScalar",u,s,o.i32_const(16),u),o.ret(o.call(f+"_eqMixed",u,h)));const F=t.addFunction(f+"_inGroup");F.addParam("pIn","i32"),F.setReturnType("i32");const C=F.getCodeBuilder(),B=C.i32_const(t.alloc(2*n));F.addCode(C.call(f+"_toAffine",C.getLocal("pIn"),B),C.ret(C.call(f+"_inGroupAffine",B)))}(),function(){const a=t.addFunction(b+"_inGroupAffine");a.addParam("p","i32"),a.setReturnType("i32");const o=a.getCodeBuilder(),e=[2001204777610833696708894912867952078278441409969503942666029068062015825245418932221343814564507832018947136279894n,2001204777610833696708894912867952078278441409969503942666029068062015825245418932221343814564507832018947136279893n],i=[2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530n,2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530n],c=o.i32_const(t.alloc([...ua.bigInt2BytesLE(y(e[0]),l),...ua.bigInt2BytesLE(y(e[1]),l)])),r=o.i32_const(t.alloc(ua.bigInt2BytesLE(y(4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436n),l))),d=o.i32_const(t.alloc([...ua.bigInt2BytesLE(y(i[0]),l),...ua.bigInt2BytesLE(y(i[1]),l)])),_=o.i32_const(t.alloc(ua.bigInt2BytesLE(j,8))),u=o.getLocal("p"),g=o.i32_add(o.getLocal("p"),o.i32_const(s)),p=o.i32_const(t.alloc(n)),f=o.i32_const(t.alloc(s)),h=o.i32_const(t.alloc(s)),x=t.alloc(2*s),F=o.i32_const(x),C=o.i32_const(x),B=o.i32_const(x),P=o.i32_const(x+n),A=o.i32_const(x+s),w=o.i32_const(x+s),q=o.i32_const(x+s+n),v=t.alloc(3*s),I=o.i32_const(v),O=o.i32_const(v),E=o.i32_const(v),M=o.i32_const(v+n),S=o.i32_const(v+s),z=o.i32_const(v+s),T=o.i32_const(v+s+n),k=o.i32_const(v+2*s);a.addCode(o.if(o.call(b+"_isZeroAffine",o.getLocal("p")),o.ret(o.i32_const(1))),o.if(o.i32_eqz(o.call(b+"_inCurveAffine",o.getLocal("p"))),o.ret(o.i32_const(0))),o.call(m+"_mul",u,c,f),o.call(m+"_mul",g,c,h),o.call(m+"_mul1",f,r,C),o.call(m+"_neg",h,A),o.call(m+"_neg",f,O),o.call(m+"_mul",h,d,S),o.call(L+"_sub",B,P,p),o.call(L+"_add",B,P,P),o.call(L+"_copy",p,B),o.call(L+"_sub",w,q,p),o.call(L+"_add",w,q,q),o.call(L+"_copy",p,w),o.call(L+"_add",E,M,p),o.call(L+"_sub",E,M,M),o.call(L+"_copy",p,E),o.call(L+"_sub",T,z,p),o.call(L+"_add",z,T,T),o.call(L+"_copy",p,z),o.call(m+"_one",k),o.call(b+"_timesScalar",I,_,o.i32_const(8),I),o.call(b+"_addMixed",I,F,I),o.ret(o.call(b+"_eqMixed",I,o.getLocal("p"))));const G=t.addFunction(b+"_inGroup");G.addParam("pIn","i32"),G.setReturnType("i32");const N=G.getCodeBuilder(),R=N.i32_const(t.alloc(2*s));G.addCode(N.call(b+"_toAffine",N.getLocal("pIn"),R),N.ret(N.call(b+"_inGroupAffine",R)))}(),function(){const a=t.addFunction(o+"_prepAddStep");a.addParam("R","i32"),a.addParam("Q","i32"),a.addParam("r","i32");const e=a.getCodeBuilder(),i=e.getLocal("R"),c=e.i32_add(e.getLocal("R"),e.i32_const(2*l)),n=e.i32_add(e.getLocal("R"),e.i32_const(4*l)),r=e.getLocal("Q"),d=e.i32_add(e.getLocal("Q"),e.i32_const(2*l)),_=e.getLocal("r"),u=e.i32_add(e.getLocal("r"),e.i32_const(2*l)),g=e.i32_add(e.getLocal("r"),e.i32_const(4*l)),L=e.i32_const(t.alloc(s)),p=e.i32_const(t.alloc(s)),f=e.i32_const(t.alloc(s)),h=e.i32_const(t.alloc(s)),b=e.i32_const(t.alloc(s)),x=e.i32_const(t.alloc(s)),y=e.i32_const(t.alloc(s)),F=e.i32_const(t.alloc(s)),C=e.i32_const(t.alloc(s)),B=e.i32_const(t.alloc(s)),P=e.i32_const(t.alloc(s));a.addCode(e.call(m+"_square",n,L),e.call(m+"_square",d,p),e.call(m+"_mul",L,r,h),e.call(m+"_add",d,n,u),e.call(m+"_square",u,u),e.call(m+"_sub",u,p,u),e.call(m+"_sub",u,L,u),e.call(m+"_mul",u,L,u),e.call(m+"_sub",h,i,b),e.call(m+"_square",b,x),e.call(m+"_add",x,x,y),e.call(m+"_add",y,y,y),e.call(m+"_mul",y,b,F),e.call(m+"_sub",u,c,C),e.call(m+"_sub",C,c,C),e.call(m+"_mul",C,r,g),e.call(m+"_mul",y,i,B),e.call(m+"_square",C,i),e.call(m+"_sub",i,F,i),e.call(m+"_sub",i,B,i),e.call(m+"_sub",i,B,i),e.call(m+"_add",n,b,n),e.call(m+"_square",n,n),e.call(m+"_sub",n,L,n),e.call(m+"_sub",n,x,n),e.call(m+"_add",d,n,_),e.call(m+"_sub",B,i,P),e.call(m+"_mul",P,C,P),e.call(m+"_mul",c,F,h),e.call(m+"_add",h,h,h),e.call(m+"_sub",P,h,c),e.call(m+"_square",_,_),e.call(m+"_sub",_,p,_),e.call(m+"_square",n,f),e.call(m+"_sub",_,f,_),e.call(m+"_add",g,g,g),e.call(m+"_sub",g,_,g),e.call(m+"_add",n,n,_),e.call(m+"_neg",C,C),e.call(m+"_add",C,C,u))}(),function(){const a=t.addFunction(o+"_prepDblStep");a.addParam("R","i32"),a.addParam("r","i32");const e=a.getCodeBuilder(),i=e.getLocal("R"),c=e.i32_add(e.getLocal("R"),e.i32_const(2*l)),n=e.i32_add(e.getLocal("R"),e.i32_const(4*l)),r=e.getLocal("r"),d=e.i32_add(e.getLocal("r"),e.i32_const(2*l)),_=e.i32_add(e.getLocal("r"),e.i32_const(4*l)),u=e.i32_const(t.alloc(s)),g=e.i32_const(t.alloc(s)),L=e.i32_const(t.alloc(s)),p=e.i32_const(t.alloc(s)),f=e.i32_const(t.alloc(s));a.addCode(e.call(m+"_square",i,r),e.call(m+"_square",c,g),e.call(m+"_square",g,L),e.call(m+"_add",g,i,d),e.call(m+"_square",d,d),e.call(m+"_sub",d,r,d),e.call(m+"_sub",d,L,d),e.call(m+"_add",d,d,d),e.call(m+"_add",r,r,p),e.call(m+"_add",p,r,p),e.call(m+"_add",i,p,_),e.call(m+"_square",p,f),e.call(m+"_square",n,u),e.call(m+"_sub",f,d,i),e.call(m+"_sub",i,d,i),e.call(m+"_add",n,c,n),e.call(m+"_square",n,n),e.call(m+"_sub",n,g,n),e.call(m+"_sub",n,u,
1n),e.call(m+"_sub",d,i,c),e.call(m+"_mul",c,p,c),e.call(m+"_add",L,L,L),e.call(m+"_add",L,L,L),e.call(m+"_add",L,L,L),e.call(m+"_sub",c,L,c),e.call(m+"_mul",p,u,d),e.call(m+"_add",d,d,d),e.call(m+"_neg",d,d),e.call(m+"_square",_,_),e.call(m+"_sub",_,r,_),e.call(m+"_sub",_,f,_),e.call(m+"_add",g,g,g),e.call(m+"_add",g,g,g),e.call(m+"_sub",_,g,_),e.call(m+"_mul",n,u,r),e.call(m+"_add",r,r,r))}(),function(){const a=t.addFunction(o+"_prepareG1");a.addParam("pP","i32"),a.addParam("ppreP","i32");const e=a.getCodeBuilder();a.addCode(e.call(f+"_normalize",e.getLocal("pP"),e.getLocal("ppreP")))}(),function(){const a=t.addFunction(o+"_prepareG2");a.addParam("pQ","i32"),a.addParam("ppreQ","i32"),a.addLocal("pCoef","i32"),a.addLocal("i","i32");const e=a.getCodeBuilder(),i=e.getLocal("pQ"),c=t.alloc(3*s),l=e.i32_const(c),n=e.getLocal("ppreQ");a.addCode(e.call(b+"_normalize",i,n),e.if(e.call(b+"_isZero",n),e.ret([])),e.call(b+"_copy",n,l),e.setLocal("pCoef",e.i32_add(e.getLocal("ppreQ"),e.i32_const(3*s)))),a.addCode(e.setLocal("i",e.i32_const(S.length-2)),e.block(e.loop(e.call(o+"_prepDblStep",l,e.getLocal("pCoef")),e.setLocal("pCoef",e.i32_add(e.getLocal("pCoef"),e.i32_const(T))),e.if(e.i32_load8_s(e.getLocal("i"),z),[...e.call(o+"_prepAddStep",l,n,e.getLocal("pCoef")),...e.setLocal("pCoef",e.i32_add(e.getLocal("pCoef"),e.i32_const(T)))]),e.br_if(1,e.i32_eqz(e.getLocal("i"))),e.setLocal("i",e.i32_sub(e.getLocal("i"),e.i32_const(1))),e.br(0))))}(),function(){const a=t.addFunction(o+"_millerLoop");a.addParam("ppreP","i32"),a.addParam("ppreQ","i32"),a.addParam("r","i32"),a.addLocal("pCoef","i32"),a.addLocal("i","i32");const e=a.getCodeBuilder(),i=e.getLocal("ppreP"),c=e.getLocal("pCoef"),l=e.getLocal("r");a.addCode(e.call(M+"_one",l),e.if(e.call(f+"_isZero",i),e.ret([])),e.if(e.call(f+"_isZero",e.getLocal("ppreQ")),e.ret([])),e.setLocal("pCoef",e.i32_add(e.getLocal("ppreQ"),e.i32_const(3*s))),e.setLocal("i",e.i32_const(S.length-2)),e.block(e.loop(e.call(o+"_ell",i,c,l),e.setLocal("pCoef",e.i32_add(e.getLocal("pCoef"),e.i32_const(T))),e.if(e.i32_load8_s(e.getLocal("i"),z),[...e.call(o+"_ell",i,c,l),...e.setLocal("pCoef",e.i32_add(e.getLocal("pCoef"),e.i32_const(T)))]),e.call(M+"_square",l,l),e.br_if(1,e.i32_eq(e.getLocal("i"),e.i32_const(1))),e.setLocal("i",e.i32_sub(e.getLocal("i"),e.i32_const(1))),e.br(0))),e.call(o+"_ell",i,c,l)),a.addCode(e.call(M+"_conjugate",l,l))}(),function(){const a=t.addFunction(o+"_finalExponentiationOld");a.addParam("x","i32"),a.addParam("r","i32");const e=t.alloc(ua.bigInt2BytesLE(322277361516934140462891564586510139908379969514828494218366688025288661041104682794998680497580008899973249814104447692778988208376779573819485263026159588510513834876303014016798809919343532899164848730280942609956670917565618115867287399623286813270357901731510188149934363360381614501334086825442271920079363289954510565375378443704372994881406797882676971082200626541916413184642520269678897559532260949334760604962086348898118982248842634379637598665468817769075878555493752214492790122785850202957575200176084204422751485957336465472324810982833638490904279282696134323072515220044451592646885410572234451732790590013479358343841220074174848221722017083597872017638514103174122784843925578370430843522959600095676285723737049438346544753168912974976791528535276317256904336520179281145394686565050419250614107803233314658825463117900250701199181529205942363159325765991819433914303908860460720581408201373164047773794825411011922305820065611121544561808414055302212057471395719432072209245600258134364584636810093520285711072578721435517884103526483832733289802426157301542744476740008494780363354305116978805620671467071400711358839553375340724899735460480144599782014906586543813292157922220645089192130209334926661588737007768565838519456601560804957985667880395221049249803753582637708560n,544)),i=a.getCodeBuilder();a.addCode(i.call(M+"_exp",i.getLocal("x"),i.i32_const(e),i.i32_const(544),i.getLocal("r")))}(),function(){!function(){const a=t.addFunction(o+"__cyclotomicSquare");a.addParam("x","i32"),a.addParam("r","i32");
1const e=a.getCodeBuilder(),i=e.getLocal("x"),c=e.i32_add(e.getLocal("x"),e.i32_const(s)),l=e.i32_add(e.getLocal("x"),e.i32_const(2*s)),n=e.i32_add(e.getLocal("x"),e.i32_const(3*s)),r=e.i32_add(e.getLocal("x"),e.i32_const(4*s)),d=e.i32_add(e.getLocal("x"),e.i32_const(5*s)),_=e.getLocal("r"),u=e.i32_add(e.getLocal("r"),e.i32_const(s)),g=e.i32_add(e.getLocal("r"),e.i32_const(2*s)),L=e.i32_add(e.getLocal("r"),e.i32_const(3*s)),p=e.i32_add(e.getLocal("r"),e.i32_const(4*s)),f=e.i32_add(e.getLocal("r"),e.i32_const(5*s)),h=e.i32_const(t.alloc(s)),b=e.i32_const(t.alloc(s)),x=e.i32_const(t.alloc(s)),y=e.i32_const(t.alloc(s)),F=e.i32_const(t.alloc(s)),C=e.i32_const(t.alloc(s)),B=e.i32_const(t.alloc(s)),P=e.i32_const(t.alloc(s));a.addCode(e.call(m+"_mul",i,r,B),e.call(m+"_mulNR",r,h),e.call(m+"_add",i,h,h),e.call(m+"_add",i,r,P),e.call(m+"_mul",P,h,h),e.call(m+"_mulNR",B,P),e.call(m+"_add",B,P,P),e.call(m+"_sub",h,P,h),e.call(m+"_add",B,B,b),e.call(m+"_mul",n,l,B),e.call(m+"_mulNR",l,x),e.call(m+"_add",n,x,x),e.call(m+"_add",n,l,P),e.call(m+"_mul",P,x,x),e.call(m+"_mulNR",B,P),e.call(m+"_add",B,P,P),e.call(m+"_sub",x,P,x),e.call(m+"_add",B,B,y),e.call(m+"_mul",c,d,B),e.call(m+"_mulNR",d,F),e.call(m+"_add",c,F,F),e.call(m+"_add",c,d,P),e.call(m+"_mul",P,F,F),e.call(m+"_mulNR",B,P),e.call(m+"_add",B,P,P),e.call(m+"_sub",F,P,F),e.call(m+"_add",B,B,C),e.call(m+"_sub",h,i,_),e.call(m+"_add",_,_,_),e.call(m+"_add",h,_,_),e.call(m+"_add",b,r,p),e.call(m+"_add",p,p,p),e.call(m+"_add",b,p,p),e.call(m+"_mul",C,e.i32_const(O),P),e.call(m+"_add",P,n,L),e.call(m+"_add",L,L,L),e.call(m+"_add",P,L,L),e.call(m+"_sub",F,l,g),e.call(m+"_add",g,g,g),e.call(m+"_add",F,g,g),e.call(m+"_sub",x,c,u),e.call(m+"_add",u,u,u),e.call(m+"_add",x,u,u),e.call(m+"_add",y,d,f),e.call(m+"_add",f,f,f),e.call(m+"_add",y,f,f))}(),Z(j,true,"w0");const a=t.addFunction(o+"_finalExponentiation");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder(),i=e.getLocal("x"),c=e.getLocal("r"),l=e.i32_const(t.alloc(r)),n=e.i32_const(t.alloc(r)),d=e.i32_const(t.alloc(r)),_=e.i32_const(t.alloc(r)),u=e.i32_const(t.alloc(r)),g=e.i32_const(t.alloc(r)),L=e.i32_const(t.alloc(r));a.addCode(e.call(M+"_frobeniusMap6",i,l),e.call(M+"_inverse",i,n),e.call(M+"_mul",l,n,d),e.call(M+"_copy",d,n),e.call(M+"_frobeniusMap2",d,d),e.call(M+"_mul",d,n,d),e.call(o+"__cyclotomicSquare",d,n),e.call(M+"_conjugate",n,n),e.call(o+"__cyclotomicExp_w0",d,_),e.call(o+"__cyclotomicSquare",_,u),e.call(M+"_mul",n,_,g),e.call(o+"__cyclotomicExp_w0",g,n),e.call(o+"__cyclotomicExp_w0",n,l),e.call(o+"__cyclotomicExp_w0",l,L),e.call(M+"_mul",L,u,L),e.call(o+"__cyclotomicExp_w0",L,u),e.call(M+"_conjugate",g,g),e.call(M+"_mul",u,g,u),e.call(M+"_mul",u,d,u),e.call(M+"_conjugate",d,g),e.call(M+"_mul",n,d,n),e.call(M+"_frobeniusMap3",n,n),e.call(M+"_mul",L,g,L),e.call(M+"_frobeniusMap1",L,L),e.call(M+"_mul",_,l,_),e.call(M+"_frobeniusMap2",_,_),e.call(M+"_mul",_,n,_),e.call(M+"_mul",_,L,_),e.call(M+"_mul",_,u,c))}();for(let a=1;a<=5;a++)J(a),t.exportFunction(o+"_pairingEq"+a);!function(){const a=t.addFunction(o+"_pairing");a.addParam("p","i32"),a.addParam("q","i32"),a.addParam("r","i32");const e=a.getCodeBuilder(),i=e.i32_const(t.alloc(r));a.addCode(e.call(o+"_prepareG1",e.getLocal("p"),e.i32_const($))),a.addCode(e.call(o+"_prepareG2",e.getLocal("q"),e.i32_const(Q))),a.addCode(e.call(o+"_millerLoop",e.i32_const($),e.i32_const(Q),i)),a.addCode(e.call(o+"_finalExponentiation",i,e.getLocal("r")))}(),t.exportFunction(o+"_pairing"),t.exportFunction(o+"_prepareG1"),t.exportFunction(o+"_prepareG2"),t.exportFunction(o+"_millerLoop"),t.exportFunction(o+"_finalExponentiation"),t.exportFunction(o+"_finalExponentiationOld"),t.exportFunction(o+"__cyclotomicSquare"),t.exportFunction(o+"__cyclotomicExp_w0"),t.exportFunction(E+"_mul1"),t.exp
1ortFunction(E+"_mul01"),t.exportFunction(M+"_mul014"),t.exportFunction(f+"_inGroupAffine"),t.exportFunction(f+"_inGroup"),t.exportFunction(b+"_inGroupAffine"),t.exportFunction(b+"_inGroup")};function wa(t,a){let o=t;void 0===a&&0==(a=Math.floor((l(t)-1)/8)+1)&&(a=1);const e=new Uint8Array(a),i=new DataView(e.buffer);let c=0;for(;c<a;)c+4<=a?(i.setUint32(c,Number(o&BigInt(4294967295)),!0),c+=4,o>>=BigInt(32)):c+2<=a?(i.setUint16(c,Number(o&BigInt(65535)),!0),c+=2,o>>=BigInt(16)):(i.setUint8(c,Number(o&BigInt(255)),!0),c+=1,o>>=BigInt(8));if(o)throw new Error("Number does not fit in this length");return e}const qa=[];for(let t=0;t<256;t++)qa[t]=va(t,8);function va(t,a){let o=0,e=t;for(let t=0;t<a;t++)o<<=1,o|=1&e,e>>=1;return o}function Ia(t,a){return(qa[t>>>24]|qa[t>>>16&255]<<8|qa[t>>>8&255]<<16|qa[255&t]<<24)>>>32-a}function Oa(t){return(4294901760&t?(t&=4294901760,16):0)|(4278255360&t?(t&=4278255360,8):0)|(4042322160&t?(t&=4042322160,4):0)|(3435973836&t?(t&=3435973836,2):0)|!!(2863311530&t)}function Ea(t,a){const o=t.byteLength/a,e=Oa(o);if(o!=1<<e)throw new Error("Invalid number of pointers");for(let i=0;i<o;i++){const o=Ia(i,e);if(i>o){const e=t.slice(i*a,(i+1)*a);t.set(t.slice(o*a,(o+1)*a),i*a),t.set(e,o*a)}}}function Ma(t,a){const o=new Uint8Array(a*t.length);for(let e=0;e<t.length;e++)o.set(t[e],e*a);return o}function Sa(t,a){const o=t.byteLength/a,e=new Array(o);for(let i=0;i<o;i++)e[i]=t.slice(i*a,i*a+a);return e}var za=Object.freeze({__proto__:null,array2buffer:Ma,beBuff2int:function(t){let a=BigInt(0),o=t.length,e=0;const i=new DataView(t.buffer,t.byteOffset,t.byteLength);for(;o>0;)o>=4?(o-=4,a+=BigInt(i.getUint32(o))<<BigInt(8*e),e+=4):o>=2?(o-=2,a+=BigInt(i.getUint16(o))<<BigInt(8*e),e+=2):(o-=1,a+=BigInt(i.getUint8(o))<<BigInt(8*e),e+=1);return a},beInt2Buff:function(t,a){let o=t;const e=new Uint8Array(a),i=new DataView(e.buffer);let c=a;for(;c>0;)c-4>=0?(c-=4,i.setUint32(c,Number(o&BigInt(4294967295))),o>>=BigInt(32)):c-2>=0?(c-=2,i.setUint16(c,Number(o&BigInt(65535))),o>>=BigInt(16)):(c-=1,i.setUint8(c,Number(o&BigInt(255))),o>>=BigInt(8));if(o)throw new Error("Number does not fit in this length");return e},bitReverse:Ia,buffReverseBits:Ea,buffer2array:Sa,leBuff2int:function(t){let a=BigInt(0),o=0;const e=new DataView(t.buffer,t.byteOffset,t.byteLength);for(;o<t.length;)o+4<=t.length?(a+=BigInt(e.getUint32(o,!0))<<BigInt(8*o),o+=4):o+2<=t.length?(a+=BigInt(e.getUint16(o,!0))<<BigInt(8*o),o+=2):(a+=BigInt(e.getUint8(o,!0))<<BigInt(8*o),o+=1);return a},leInt2Buff:wa,log2:Oa,stringifyBigInts:function t(a){if("bigint"==typeof a||void 0!==a.eq)return a.toString(10);if(a instanceof Uint8Array)return I(a,0);if(Array.isArray(a))return a.map(t);if("object"==typeof a){const o={};return Object.keys(a).forEach(e=>{o[e]=t(a[e])}),o}return a},stringifyFElements:function t(a,o){if("bigint"==typeof o||void 0!==o.eq)return o.toString(10);if(o instanceof Uint8Array)return a.toString(a.e(o));if(Array.isArray(o))return o.map(t.bind(this,a));if("object"==typeof o){const e={};return Object.keys(o).forEach(i=>{e[i]=t(a,o[i])}),e}return o},unstringifyBigInts:function t(a){if("string"==typeof a&&/^[0-9]+$/.test(a))return BigInt(a);if("string"==typeof a&&/^0x[0-9a-fA-F]+$/.test(a))return BigInt(a);if(Array.isArray(a))return a.map(t);if("object"==typeof a){if(null===a)return null;const o={};return Object.keys(a).forEach(e=>{o[e]=t(a[e])}),o}return a},unstringifyFElements:function t(a,o){if("string"==typeof o&&/^[0-9]+$/.test(o))return a.e(o);if("string"==typeof o&&/^0x[0-9a-fA-F]+$/.test(o))return a.e(o);if(Array.isArray(o))return o.map(t.bind(this,a));if("object"==typeof o){if(null===o)return null;const e={};return Object.keys(o).forEach(i=>{e[i]=t(a,o[i])}),e}return o}});const Ta=1<<30;class ka{constructor(t){this.buffers=[],this.byteLength=t;for(let a=0;a<t;a+=Ta){const o=Math.min(t-a,Ta);this.buffers.push(new Uint8Array(o))}}slice(t,a){void 0===a&&(a=this.byteLength),void 0===t&&(t=0);const o=a-t,e=Math.floor(t/Ta);if(e==Math.floor((t+o-1)/Ta)||0==o)return this.buffers[e].slice(t%Ta,t%Ta+o);let i,c=e,l=t%Ta,n=o;for(;n>0;){const t=l+n>Ta?Ta-l:n,a=new Uint8Array(this.buffers[c].buffer,this.buffers[c].byteOffset+l,t);if(t==o)return a.slice();i||(i=o<=Ta?new Uint8Array(o):new ka(o)),i.set(a,o-n),n-=t,c++,l=0}return i}set(t,a){void 0===a&&(a=0);const o=t.byteLength;if(0==o)return;const e=Math.floor(a/Ta);if(e==Math.floor((a+o-1)/Ta))return t instanceof ka&&1==t.buffers.length?this.buffers[e].set(t.buffers[0],a%Ta):this.buffers[e].set(t,a%Ta);let i=e,c=a%Ta,l=o;for(;l>0;){const a=c+l>
1Ta?Ta-c:l,e=t.slice(o-l,o-l+a);new Uint8Array(this.buffers[i].buffer,this.buffers[i].byteOffset+c,a).set(e),l-=a,i++,c=0}}}function Ga(t,a,o,e){return async function(i){const c=Math.floor(i.byteLength/o);if(c*o!==i.byteLength)throw new Error("Invalid buffer size");const l=Math.floor(c/t.concurrency),n=[];for(let s=0;s<t.concurrency;s++){let r;if(r=s<t.concurrency-1?l:c-s*l,0==r)continue;const d=[{cmd:"ALLOCSET",var:0,buff:i.slice(s*l*o,s*l*o+r*o)},{cmd:"ALLOC",var:1,len:e*r},{cmd:"CALL",fnName:a,params:[{var:0},{val:r},{var:1}]},{cmd:"GET",out:0,var:1,len:e*r}];n.push(t.queueAction(d))}const s=await Promise.all(n);let r;r=i instanceof ka?new ka(c*e):new Uint8Array(c*e);let d=0;for(let t=0;t<s.length;t++)r.set(s[t][0],d),d+=s[t][0].byteLength;return r}}class Na{constructor(t,a,o,e){if(this.tm=t,this.prefix=a,this.p=e,this.n8=o,this.type="F1",this.m=1,this.half=d(e,z),this.bitLength=l(e),this.mask=h(r(z,this.bitLength),z),this.pOp1=t.alloc(o),this.pOp2=t.alloc(o),this.pOp3=t.alloc(o),this.tm.instance.exports[a+"_zero"](this.pOp1),this.zero=this.tm.getBuff(this.pOp1,this.n8),this.tm.instance.exports[a+"_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(o/8),this.n32=Math.floor(o/4),8*this.n64!=this.n8)throw new Error("n8 must be a multiple of 8");this.half=d(this.p,z),this.nqr=this.two;let i=this.exp(this.nqr,this.half);for(;!this.eq(i,this.negone);)this.nqr=this.add(this.nqr,this.one),i=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,z);for(;!g(c);)this.s=this.s+1,c=d(c,z);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=Ga(t,a+"_batchToMontgomery",this.n8,this.n8),this.batchFromMontgomery=Ga(t,a+"_batchFromMontgomery",this.n8,this.n8)}op2(t,a,o){return this.tm.setBuff(this.pOp1,a),this.tm.setBuff(this.pOp2,o),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op2Bool(t,a,o){return this.tm.setBuff(this.pOp1,a),this.tm.setBuff(this.pOp2,o),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2)}op1(t,a){return this.tm.setBuff(this.pOp1,a),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op1Bool(t,a){return this.tm.setBuff(this.pOp1,a),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3)}add(t,a){return this.op2("_add",t,a)}eq(t,a){return this.op2Bool("_eq",t,a)}isZero(t){return this.op1Bool("_isZero",t)}sub(t,a){return this.op2("_sub",t,a)}neg(t){return this.op1("_neg",t)}inv(t){return this.op1("_inverse",t)}toMontgomery(t){return this.op1("_toMontgomery",t)}fromMontgomery(t){return this.op1("_fromMontgomery",t)}mul(t,a){return this.op2("_mul",t,a)}div(t,a){return this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,a),this.tm.instance.exports[this.prefix+"_inverse"](this.pOp2,this.pOp2),this.tm.instance.exports[this.prefix+"_mul"](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}square(t){return this.op1("_square",t)}isSquare(t){return this.op1Bool("_isSquare",t)}sqrt(t){return this.op1("_sqrt",t)}exp(t,a){return a instanceof Uint8Array||(a=M(c(a))),this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,a),this.tm.instance.exports[this.prefix+"_exp"](this.pOp1,this.pOp2,a.byteLength,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}isNegative(t){return this.op1Bool("_isNegative",t)}e(t,a){if(t instanceof Uint8Array)return t;let o=c(t,a);n(o)?(o=b(o),P(o,this.p)&&(o=C(o,this.p)),o=h(this.p,o)):P(o,this.p)&&(o=C(o,this.p));const e=wa(o,this.n8);return this.toMontgomery(e)}toString(t,a){return E(I(this.fromMontgomery(t),0),a)}fromRng(t){let a;const o=new Uint8Array(this.n8);do{a=S;for(let o=0;o<this.n64;o++)a=m(a,r(t.nextU64(),64*o));a=w(a,this.mask)}while(A(a,this.p));return q(o,0,a,this.n8),o}random(){return this.fromRng(J())}toObject(t){return I(this.fromMontgomery(t),0)}fromObject(t){const a=new Uint8Array(this.n8);return q(a,0,t,this.n8),this.toMontgomery(a)}toRprLE(t,a,o){t.set(this.fromMontgomery(o),a)}toRprBE(t,a,o){const e=this.fromMontgomery(o);for(let t=0;t<this.n8/2;t++){const a=e[t];e[t]=e[this.n8-1-t],e[this.n8-1-t]=a}t.set(e,a)}fromRprLE(t,a){a=a||0;const o=t.slice(a,a+this.n8);return this.toMontgomery(o)}async batchInverse(t){let a=!1;const o=this.n8,e=this.n8;Array.isArray(t)?(t=Ma(t,o),a=!0):t=t.slice(0,t.byteLength);const i=Math.floor(t.byteLength/o);if(i*o!==t.byteLength)throw new Error("Invalid buffer size");const c=Math.floor(i/this.tm.concurrency),l=[];for(let a=0;a<this.tm.concurrency;a++){let n;if(n=a<this.tm.concurrency-1?c:i-a*c,0==n)continue;const s=[{cmd:"ALLOCSET",var:0,buff:t.slice(a*c*o,a*c*o+n*o)},{cmd:"ALLOC",var:1,len:e*n},{cmd:"CALL",fnName:this.prefix+"_batchInverse",params:[{var:0},{val:o},{val:n}
1,{var:1},{val:e}]},{cmd:"GET",out:0,var:1,len:e*n}];l.push(this.tm.queueAction(s))}const n=await Promise.all(l);let s;s=t instanceof ka?new ka(i*e):new Uint8Array(i*e);let r=0;for(let t=0;t<n.length;t++)s.set(n[t][0],r),r+=n[t][0].byteLength;return a?Sa(s,e):s}}class Ra{constructor(t,a,o){this.tm=t,this.prefix=a,this.F=o,this.type="F2",this.m=2*o.m,this.n8=2*this.F.n8,this.n32=2*this.F.n32,this.n64=2*this.F.n64,this.pOp1=t.alloc(2*o.n8),this.pOp2=t.alloc(2*o.n8),this.pOp3=t.alloc(2*o.n8),this.tm.instance.exports[a+"_zero"](this.pOp1),this.zero=t.getBuff(this.pOp1,this.n8),this.tm.instance.exports[a+"_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,a,o){return this.tm.setBuff(this.pOp1,a),this.tm.setBuff(this.pOp2,o),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op2Bool(t,a,o){return this.tm.setBuff(this.pOp1,a),this.tm.setBuff(this.pOp2,o),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2)}op1(t,a){return this.tm.setBuff(this.pOp1,a),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op1Bool(t,a){return this.tm.setBuff(this.pOp1,a),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3)}add(t,a){return this.op2("_add",t,a)}eq(t,a){return this.op2Bool("_eq",t,a)}isZero(t){return this.op1Bool("_isZero",t)}sub(t,a){return this.op2("_sub",t,a)}neg(t){return this.op1("_neg",t)}inv(t){return this.op1("_inverse",t)}isNegative(t){return this.op1Bool("_isNegative",t)}toMontgomery(t){return this.op1("_toMontgomery",t)}fromMontgomery(t){return this.op1("_fromMontgomery",t)}mul(t,a){return this.op2("_mul",t,a)}mul1(t,a){return this.op2("_mul1",t,a)}div(t,a){return this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,a),this.tm.instance.exports[this.prefix+"_inverse"](this.pOp2,this.pOp2),this.tm.instance.exports[this.prefix+"_mul"](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}square(t){return this.op1("_square",t)}isSquare(t){return this.op1Bool("_isSquare",t)}sqrt(t){return this.op1("_sqrt",t)}exp(t,a){return a instanceof Uint8Array||(a=M(c(a))),this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,a),this.tm.instance.exports[this.prefix+"_exp"](this.pOp1,this.pOp2,a.byteLength,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}e(t,a){if(t instanceof Uint8Array)return t;if(Array.isArray(t)&&2==t.length){const o=this.F.e(t[0],a),e=this.F.e(t[1],a),i=new Uint8Array(2*this.F.n8);return i.set(o),i.set(e,2*this.F.n8),i}throw new Error("invalid F2")}toString(t,a){return`[${this.F.toString(t.slice(0,this.F.n8),a)}, ${this.F.toString(t.slice(this.F.n8),a)}]`}fromRng(t){const a=this.F.fromRng(t),o=this.F.fromRng(t),e=new Uint8Array(2*this.F.n8);return e.set(a),e.set(o,this.F.n8),e}random(){return this.fromRng(J())}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 a=new Uint8Array(2*this.F.n8),o=this.F.fromObject(t[0]),e=this.F.fromObject(t[1]);return a.set(o),a.set(e,this.F.n8),a}c1(t){return t.slice(0,this.F.n8)}c2(t){return t.slice(this.F.n8)}}class ja{constructor(t,a,o){this.tm=t,this.prefix=a,this.F=o,this.type="F3",this.m=3*o.m,this.n8=3*this.F.n8,this.n32=3*this.F.n32,this.n64=3*this.F.n64,this.pOp1=t.alloc(3*o.n8),this.pOp2=t.alloc(3*o.n8),this.pOp3=t.alloc(3*o.n8),this.tm.instance.exports[a+"_zero"](this.pOp1),this.zero=t.getBuff(this.pOp1,this.n8),this.tm.instance.exports[a+"_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,a,o){return this.tm.setBuff(this.pOp1,a),this.tm.setBuff(this.pOp2,o),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op2Bool(t,a,o){return this.tm.setBuff(this.pOp1,a),this.tm.setBuff(this.pOp2,o),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2)}op1(t,a){return this.tm.setBuff(this.pOp1,a),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op1Bool(t,a){return this.tm.setBuff(this.pOp1,a),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3)}eq(t,a){return this.op2Bool("_eq",t,a)}isZero(t){return this.op1Bool("_isZero",t)}add(t,a){return this.op2("_add",t,a)}sub(t,a){return this.op2("_sub",t,a)}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,a){return this.op2("_mul",t,a)}div(t,a){return this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,a),this.tm.instance.exports[this.prefix+"_inverse"](this.pOp2,this.pOp2),this.tm.instance.exports[this.prefix+"_mul"](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}square(t){return this.op1("_square",t)}isSquare(t){return this.op1Bool("_isSquare",t)}sqrt(t){return this.op1("_sqrt",t)}exp(t,a){return a instanceof Uint8Array||(a=M(c(a))),this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,a),this.tm.instance.exports[this.prefix+"_exp"](this.pOp1,this.pOp2,a.byteLength,this.pOp3),this.getBuff(this.pOp3,this.n8)}e(t,a){if(t instanceof Uint8Array)return t;if(Array.isArray(t)&&3==t.length){const o=this.F.e(t[0],a),e=this.F.e(t[1],a),i=this.F.e(t[2],a),c=new Uint8Array(3*this.F.n8);return c.set(o),c.set(e,this.F.n8),c.set(i,2*this.F.n8),c}throw new Error("invalid F3")}toString(t,a){return`[${this.F.toString(t.slice(0,this.F.n8),a)}, ${this.F.toString(t.slice(this.F.n8,2*this.F.n8),a)}, ${this.F.toString(t.slice(2*this.F.n8),a)}]`}fromRng(t){const a=this.F.fromRng(t),o=this.F.fromRng(t),e=this.F.fromRng(t),i=new Uint8Array(3*this.F.n8);return i.set(a),i.set(o,this.F.n8),i.set(e,2*this.F.n8),i}random(){return this.fromRng(J())}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 a=new Uint8Array(3*this.F.n8),o=this.F.fromObject(t[0]),e=this.F.fromObject(t[1]),i=this.F.fromObject(t[2]);return a.set(o),a.set(e,this.F.n8),a.set(i,2*this.F.n8),a}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 Ua{constructor(t,a,o,e,i,c){this.tm=t,this.prefix=a,this.F=o,this.pOp1=t.alloc(3*o.n8),this.pOp2=t.alloc(3*o.n8),this.pOp3=t.alloc(3*o.n8),this.tm.instance.exports[a+"_zero"](this.pOp1),this.zero=this.tm.getBuff(this.pOp1,3*o.n8),this.tm.instance.exports[a+"_zeroAffine"](this.pOp1),this.zeroAffine=this.tm.getBuff(this.pOp1,2*o.n8),this.one=this.tm.getBuff(e,3*o.n8),this.g=this.one,this.oneAffine=this.tm.getBuff(e,2*o.n8),this.gAffine=this.oneAffine,this.b=this.tm.getBuff(i,o.n8),c&&(this.cofactor=M(c)),this.negone=this.neg(this.one),this.two=this.add(this.one,this.one),this.batchLEMtoC=Ga(t,a+"_batchLEMtoC",2*o.n8,o.n8),this.batchLEMtoU=Ga(t,a+"_batchLEMtoU",2*o.n8,2*o.n8),this.batchCtoLEM=Ga(t,a+"_batchCtoLEM",o.n8,2*o.n8),this.batchUtoLEM=Ga(t,a+"_batchUtoLEM",2*o.n8,2*o.n8),this.batchToJacobian=Ga(t,a+"_batchToJacobian",2*o.n8,3*o.n8),this.batchToAffine=Ga(t,a+"_batchToAffine",3*o.n8,2*o.n8)}op2(t,a,o){return this.tm.setBuff(this.pOp1,a),this.tm.setBuff(this.pOp2,o),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,3*this.F.n8)}op2bool(t,a,o){return this.tm.setBuff(this.pOp1,a),this.tm.setBuff(this.pOp2,o),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2,this.pOp3)}op1(t,a){return this.tm.setBuff(this.pOp1,a),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3),this.tm.getBuff(this.pOp3,3*this.F.n8)}op1Affine(t,a){return this.tm.setBuff(this.pOp1,a),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3),this.tm.getBuff(this.pOp3,2*this.F.n8)}op1Bool(t,a){return this.tm.setBuff(this.pOp1,a),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3)}add(t,a){if(t.byteLength==3*this.F.n8){if(a.byteLength==3*this.F.n8)return this.op2("_add",t,a);if(a.byteLength==2*this.F.n8)return this.op2("_addMixed",t,a);throw new Error("invalid point size")}if(t.byteLength==2*this.F.n8){if(a.byteLength==3*this.F.n8)return this.op2("_addMixed",a,t);if(a.byteLength==2*this.F.n8)return this.op2("_addAffine",t,a);throw new Error("invalid point size")}throw new Error("invalid point size")}sub(t,a){if(t.byteLength==3*this.F.n8){if(a.byteLength==3*this.F.n8)return this.op2("_sub",t,a);if(a.byteLength==2*this.F.n8)return this.op2("_subMixed",t,a);throw new Error("invalid point size")}if(t.byteLength==2*this.F.n8){if(a.byteLength==3*this.F.n8)return this.op2("_subMixed",a,t);if(a.byteLength==2*this.F.n8)return this.op2("_subAffine",t,a);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")}
1timesScalar(t,a){let o;if(a instanceof Uint8Array||(a=M(c(a))),t.byteLength==3*this.F.n8)o=this.prefix+"_timesScalar";else{if(t.byteLength!=2*this.F.n8)throw new Error("invalid point size");o=this.prefix+"_timesScalarAffine"}return this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,a),this.tm.instance.exports[o](this.pOp1,this.pOp2,a.byteLength,this.pOp3),this.tm.getBuff(this.pOp3,3*this.F.n8)}timesFr(t,a){let o;if(t.byteLength==3*this.F.n8)o=this.prefix+"_timesFr";else{if(t.byteLength!=2*this.F.n8)throw new Error("invalid point size");o=this.prefix+"_timesFrAffine"}return this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,a),this.tm.instance.exports[o](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,3*this.F.n8)}eq(t,a){if(t.byteLength==3*this.F.n8){if(a.byteLength==3*this.F.n8)return this.op2bool("_eq",t,a);if(a.byteLength==2*this.F.n8)return this.op2bool("_eqMixed",t,a);throw new Error("invalid point size")}if(t.byteLength==2*this.F.n8){if(a.byteLength==3*this.F.n8)return this.op2bool("_eqMixed",a,t);if(a.byteLength==2*this.F.n8)return this.op2bool("_eqAffine",t,a);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,a,o){if(this.tm.setBuff(this.pOp1,o),o.byteLength==3*this.F.n8)this.tm.instance.exports[this.prefix+"_toAffine"](this.pOp1,this.pOp1);else if(o.byteLength!=2*this.F.n8)throw new Error("invalid point size");this.tm.instance.exports[this.prefix+"_LEMtoU"](this.pOp1,this.pOp1);const e=this.tm.getBuff(this.pOp1,2*this.F.n8);t.set(e,a)}fromRprUncompressed(t,a){const o=t.slice(a,a+2*this.F.n8);return this.tm.setBuff(this.pOp1,o),this.tm.instance.exports[this.prefix+"_UtoLEM"](this.pOp1,this.pOp1),this.tm.getBuff(this.pOp1,2*this.F.n8)}toRprCompressed(t,a,o){if(this.tm.setBuff(this.pOp1,o),o.byteLength==3*this.F.n8)this.tm.instance.exports[this.prefix+"_toAffine"](this.pOp1,this.pOp1);else if(o.byteLength!=2*this.F.n8)throw new Error("invalid point size");this.tm.instance.exports[this.prefix+"_LEMtoC"](this.pOp1,this.pOp1);const e=this.tm.getBuff(this.pOp1,this.F.n8);t.set(e,a)}fromRprCompressed(t,a){const o=t.slice(a,a+this.F.n8);return this.tm.setBuff(this.pOp1,o),this.tm.instance.exports[this.prefix+"_CtoLEM"](this.pOp1,this.pOp2),this.tm.getBuff(this.pOp2,2*this.F.n8)}toUncompressed(t){const a=new Uint8Array(2*this.F.n8);return this.toRprUncompressed(a,0,t),a}toRprLEM(t,a,o){if(o.byteLength!=2*this.F.n8){if(o.byteLength!=3*this.F.n8)throw new Error("invalid point size");{this.tm.setBuff(this.pOp1,o),this.tm.instance.exports[this.prefix+"_toAffine"](this.pOp1,this.pOp1);const e=this.tm.getBuff(this.pOp1,2*this.F.n8);t.set(e,a)}}else t.set(o,a)}fromRprLEM(t,a){return a=a||0,t.slice(a,a+2*this.F.n8)}toString(t,a){if(t.byteLength==3*this.F.n8){return`[ ${this.F.toString(t.slice(0,this.F.n8),a)}, ${this.F.toString(t.slice(this.F.n8,2*this.F.n8),a)}, ${this.F.toString(t.slice(2*this.F.n8),a)} ]`}if(t.byteLength==2*this.F.n8){return`[ ${this.F.toString(t.slice(0,this.F.n8),a)}, ${this.F.toString(t.slice(this.F.n8),a)} ]`}throw new Error("invalid point size")}isValid(t){if(this.isZero(t))return!0;const a=this.F,o=this.toAffine(t),e=o.slice(0,this.F.n8),i=o.slice(this.F.n8,2*this.F.n8),c=a.add(a.mul(a.square(e),e),this.b),l=a.square(i);return a.eq(c,l)}fromRng(t){const a=this.F;let o,e,i=[];do{i[0]=a.fromRng(t),o=t.nextBool(),e=a.add(a.mul(a.square(i[0]),i[0]),this.b)}while(!a.isSquare(e));i[1]=a.sqrt(e);o^a.isNegative(i[1])&&(i[1]=a.neg(i[1]));let c=new Uint8Array(2*this.F.n8);return c.set(i[0]),c.set(i[1],this.F.n8),this.cofactor&&(c=this.timesScalar(c,this.cofactor)),c}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 a=this.F.toObject(t.slice(0,this.F.n8)),o=this.F.toObject(t.slice(this.F.n8,2*this.F.n8));let e;return e=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),[a,o,e]}fromObject(t){const a=this.F.fromObject(t[0]),o=this.F.fromObject(t[1]);let e;if(e=3==t.length?this.F.fromObject(t[2]):this.F.one,this.F.isZero(e,this.F.one))return this.zeroAffine;if(this.F.eq(e,this.F.one)){const t=new Uint8Array(2*this.F.n8);return t.set(a),t.set(o,this.F.n8),t}{const t=new Uint8Array(3*this.F.n8);return t.set(a),t.set(o,this.F.n8),t.set(e,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)}}var Za=X(Worker);const $a=25;class Qa{constructor(){this.promise=new Promise((t,a)=>{this.reject=a,this.resolve=t})}}var Ja;const Da="data:application/javascript;base64,"+(Ja='(function thread(self) {\n const MAXMEM = 32767;\n let instance;\n let memory;\n\n if (self) {\n self.onmessage = function(e) {\n let data;\n if (e.data) {\n data = e.data;\n } else {\n data = e;\n }\n\n if (data[0].cmd == "INIT") {\n init(data[0]).then(function() {\
1n self.postMessage(data.result);\n });\n } else if (data[0].cmd == "TERMINATE") {\n self.close();\n } else {\n const res = runTask(data);\n self.postMessage(res);\n }\n };\n }\n\n async function init(data) {\n const code = new Uint8Array(data.code);\n const wasmModule = await WebAssembly.compile(code);\n memory = new WebAssembly.Memory({initial:data.init, maximum: MAXMEM});\n\n instance = await WebAssembly.instantiate(wasmModule, {\n env: {\n "memory": memory\n }\n });\n }\n\n\n\n function alloc(length) {\n const u32 = new Uint32Array(memory.buffer, 0, 1);\n while (u32[0] & 3) u32[0]++; // Return always aligned pointers\n const res = u32[0];\n u32[0] += length;\n if (u32[0] + length > memory.buffer.byteLength) {\n const currentPages = memory.buffer.byteLength / 0x10000;\n let requiredPages = Math.floor((u32[0] + length) / 0x10000)+1;\n if (requiredPages>MAXMEM) requiredPages=MAXMEM;\n memory.grow(requiredPages-currentPages);\n }\n return res;\n }\n\n function allocBuffer(buffer) {\n const p = alloc(buffer.byteLength);\n setBuffer(p, buffer);\n return p;\n }\n\n function getBuffer(pointer, length) {\n const u8 = new Uint8Array(memory.buffer);\n return new Uint8Array(u8.buffer, u8.byteOffset + pointer, length);\n }\n\n function setBuffer(pointer, buffer) {\n const u8 = new Uint8Array(memory.buffer);\n u8.set(new Uint8Array(buffer), pointer);\n }\n\n function runTask(task) {\n if (task[0].cmd == "INIT") {\n return init(task[0]);\n }\n const ctx = {\n vars: [],\n out: []\n };\n const u32a = new Uint32Array(memory.buffer, 0, 1);\n const oldAlloc = u32a[0];\n for (let i=0; i<task.length; i++) {\n switch (task[i].cmd) {\n case "ALLOCSET":\n ctx.vars[task[i].var] = allocBuffer(task[i].buff);\n break;\n case "ALLOC":\n ctx.vars[task[i].var] = alloc(task[i].len);\n break;\n case "SET":\n setBuffer(ctx.vars[task[i].var], task[i].buff);\n break;\n case "CALL": {\n const params = [];\n for (let j=0; j<task[i].params.length; j++) {\n const p = task[i].params[j];\n if (typeof p.var !== "undefined") {\n params.push(ctx.vars[p.var] + (p.offset || 0));\n }
1 else if (typeof p.val != "undefined") {\n params.push(p.val);\n }\n }\n instance.exports[task[i].fnName](...params);\n break;\n }\n case "GET":\n ctx.out[task[i].out] = getBuffer(ctx.vars[task[i].var], task[i].len).slice();\n break;\n default:\n throw new Error("Invalid cmd");\n }\n }\n const u32b = new Uint32Array(memory.buffer, 0, 1);\n u32b[0] = oldAlloc;\n return ctx.out;\n }\n\n\n return runTask;\n})(self)',globalThis.btoa(Ja));async function Wa(t,a){const o=new Va;o.memory=new WebAssembly.Memory({initial:$a}),o.u8=new Uint8Array(o.memory.buffer),o.u32=new Uint32Array(o.memory.buffer);const e=await WebAssembly.compile(t.code);if(o.instance=await WebAssembly.instantiate(e,{env:{memory:o.memory}}),o.singleThread=a,o.initalPFree=o.u32[0],o.pq=t.pq,o.pr=t.pr,o.pG1gen=t.pG1gen,o.pG1zero=t.pG1zero,o.pG2gen=t.pG2gen,o.pG2zero=t.pG2zero,o.pOneT=t.pOneT,a)o.code=t.code,o.taskManager=function(t){const a=32767;let o,e;async function i(t){const i=new Uint8Array(t.code),c=await WebAssembly.compile(i);e=new WebAssembly.Memory({initial:t.init,maximum:a}),o=await WebAssembly.instantiate(c,{env:{memory:e}})}function c(t){const o=new Uint32Array(e.buffer,0,1);for(;3&o[0];)o[0]++;const i=o[0];if(o[0]+=t,o[0]+t>e.buffer.byteLength){const i=e.buffer.byteLength/65536;let c=Math.floor((o[0]+t)/65536)+1;c>a&&(c=a),e.grow(c-i)}return i}function l(t){const a=c(t.byteLength);return s(a,t),a}function n(t,a){const o=new Uint8Array(e.buffer);return new Uint8Array(o.buffer,o.byteOffset+t,a)}function s(t,a){new Uint8Array(e.buffer).set(new Uint8Array(a),t)}function r(t){if("INIT"==t[0].cmd)return i(t[0]);const a={vars:[],out:[]},r=new Uint32Array(e.buffer,0,1)[0];for(let e=0;e<t.length;e++)switch(t[e].cmd){case"ALLOCSET":a.vars[t[e].var]=l(t[e].buff);break;case"ALLOC":a.vars[t[e].var]=c(t[e].len);break;case"SET":s(a.vars[t[e].var],t[e].buff);break;case"CALL":{const i=[];for(let o=0;o<t[e].params.length;o++){const c=t[e].params[o];void 0!==c.var?i.push(a.vars[c.var]+(c.offset||0)):void 0!==c.val&&i.push(c.val)}o.exports[t[e].fnName](...i);break}case"GET":a.out[t[e].out]=n(a.vars[t[e].var],t[e].len).slice();break;default:throw new Error("Invalid cmd")}return new Uint32Array(e.buffer,0,1)[0]=r,a.out}return t&&(t.onmessage=function(a){let o;if(o=a.data?a.data:a,"INIT"==o[0].cmd)i(o[0]).then(function(){t.postMessage(o.result)});else if("TERMINATE"==o[0].cmd)t.close();else{const a=r(o);t.postMessage(a)}}),r}(),await o.taskManager([{cmd:"INIT",init:$a,code:o.code.slice()}]),o.concurrency=1;else{o.workers=[],o.pendingDeferreds=[],o.working=[];let a=2;"object"==typeof navigator&&navigator.hardwareConcurrency&&(a=navigator.hardwareConcurrency),0==a&&(a=2),a>64&&(a=64),o.concurrency=a;for(let t=0;t<a;t++)o.workers[t]=new Za(Da),o.workers[t].addEventListener("message",i(t)),o.working[t]=!1;const e=[];for(let a=0;a<o.workers.length;a++){const i=t.code.slice();e.push(o.postAction(a,[{cmd:"INIT",init:$a,code:i}],[i.buffer]))}await Promise.all(e)}return o;function i(t){return function(a){let e;e=a&&a.data?a.data:a,o.working[t]=!1,o.pendingDeferreds[t].resolve(e),o.processWorks()}}}class Va{constructor(){this.actionQueue=[],this.oldPFree=0}startSyncOp(){if(0!=this.oldPFree)throw new Error("Sync operation in progress");this.oldPFree=this.u32[0]}endSyncOp(){if(0==this.oldPFree)throw new Error("No sync operation in progress");this.u32[0]=this.oldPFree,this.oldPFree=0}postAction(t,a,o,e){if(this.working[t])throw new Error("Posting a job t a working worker");return this.working[t]=!0,this.pendingDeferreds[t]=e||new Qa,this.workers[t].postMessage(a,o),this.pendingDeferreds[t].promise}processWorks(){for(let t=0;t<this.workers.length&&this.actionQueue.length>0;t++)if(0==this.working[t]){const a=this.actionQueue.shift();this.postAction(t,a.data,a.transfers,a.deferred)}}queueAction(t,a){const o=new Qa;if(this.singleThread){const a=this.taskManager(t);o.resolve(a)}else this.actionQueue.push({data:t,transfers:a,deferred:o}),this.processWorks();return o.promise}resetMemory(){this.u32[0]=this.initalPFree}allocBuff(t){const a=this.alloc(t.byteLength);return this.setBuff(a,t),a}getBuff(t,a){return this.u8.slice(t,t+a)}setBuff(t,a){this.u8.set(new Uint8Array(a),t)}alloc(t){for(;3&this.u32[0];)this.u32[0]++;const a=this.u32[0];return this.u32[0]+=t,a}async terminate(){for(let t=0;t<this.workers.length;t++)this.workers[t].postMessage([{cmd:"TERMINATE"}]);var t;await(t=200,new Promise(a=>setTimeout(a,t)))}}function Ka(t,a){const o=t[a],e=t.Fr,i=t.tm;t[a].batchApplyKey=async function(t,c,l,n,s){let r,d,_,u,g;if(n=n||"affine",s=s||"affine","G1"==a)"jacobian"==n?(_=3*o.F.n8,r="g1m_batchApplyKey"):(_=2*o.F.n8,r="g1m_batchApplyKeyMixed"),u=3*o.F.n8,"jacobian"==s?g=3*o.F.n8:(d="g1m_batchToAffine",g=2*o.F.n8);else if("G2"==a)"jacobian"==n?(_=3*o.F.n8,r="g2m_batchApplyKey"):(_=2*o.F.n8,r="g2m_batchApplyKeyMixed"),u=3*o.F.n8,"jacobian"==s?g=3*o.F.n8:(d="g2m_batchToAffine",g=2*o.F.n8);else{if("Fr"!=a)throw new Error("Invalid group: "+a);r="frm_batchApplyKey",_=o.n8,u=o.n8,g=o.n8}const L=Math.floor(t.byteLength/_),p=Math.floor(L/i.concurrency),f=[];l=e.e(l);let m=e.e(c);for(let a=0;a<i.concurrency;a++){let o;if(o=a<i.concurrency-1?p:L-a*p,0==o)continue;const c=[];c.push({cmd:"ALLOCSET",var:0,buff:t.slice(a*p*_,a*p*_+o*_)}),c.push({cmd:"ALLOCSET",var:1,buff:m}),c.push({cmd:"ALLOCSET",var:2,buff:l}),c.push({cmd:"ALLOC",var:3,len:o*Math.max(u,g)}),c.push({cmd:"CALL",fnName:r,params:[{var:0},{val:o},{var:1},{var:2},{var:3}]}),d&&c.push({cmd:"CALL",fnName:d,params:[{var:3},{val:o},{var:3}]}),c.push({cmd:"GET",out:0,var:3,len:o*g}),f.push(i.queueAction(c)),m=e.mul(m,e.exp(l,o))}const h=await Promise.all(f);let b;b=t instanceof ka?new ka(L*g):new Uint8Array(L*g);let x=0;for(let t=0;t<h.length;t++)b.set(h[t][0],x),x+=h[t][0].byteLength;return b}}const Xa=[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 Ya(t,a){const o=t[a],e=o.tm;async function i(t,e,i,c,l){if(!(t instanceof Uint8Array))throw c&&c.error(`${l} _multiExpChunk buffBases is not Uint8Array`),new Error(`${l} _multiExpChunk buffBases is not Uint8Array`);if(!(e instanceof Uint8Array))throw c&&c.error(`${l} _multiExpChunk buffScalars is not Uint8Array`),new Error(`${l} _multiExpChunk buffScalars is not Uint8Array`);let n,s;if(i=i||"affine","G1"==a)"affine"==i?(s="g1m_multiexpAffine_chunk",n=2*o.F.n8):(s="g1m_multiexp_chunk",n=3*o.F.n8);else{if("G2"!=a)throw new Error("Invalid group");"affine"==i?(s="g2m_multiexpAffine_chunk",n=2*o.F.n8):(s="g2m_multiexp_chunk",n=3*o.F.n8)}const r=Math.floor(t.byteLength/n);if(0==r)return o.zero;const d=Math.floor(e.byteLength/r);if(d*r!=e.byteLength)throw new Error("Scalar size does not match");const _=Xa[Oa(r)],u=Math.floor((8*d-1)/_)+1,g=[];for(let a=0;a<u;a++){const i=[{cmd:"ALLOCSET",var:0,buff:t},{cmd:"ALLOCSET",var:1,buff:e},{cmd:"ALLOC",var:2,len:3*o.F.n8},{cmd:"CALL",fnName:s,params:[{var:0},{var:1},{val:d},{val:r},{val:a*_},{val:Math.min(8*d-a*_,_)},{var:2}]},{cmd:"GET",out:0,var:2,len:3*o.F.n8}];g.push(o.tm.queueAction(i))}const L=await Promise.all(g);let p=o.zero;for(let t=L.length-1;t>=0;t--){if(!o.isZero(p))for(let t=0;t<_;t++)p=o.double(p);p=o.add(p,L[t][0])}return p}async function c(t,c,l,n,s){const r=1<<22;let d;if("G1"==a)d="affine"==l?2*o.F.n8:3*o.F.n8;else{if("G2"!=a)throw new Error("Invalid group");d="affine"==l?2*o.F.n8:3*o.F.n8}const _=Math.floor(t.byteLength/d),u=Math.floor(c.byteLength/_);if(u*_!=c.byteLength)throw new Error("Scalar size does not match");const g=Xa[Oa(_)],L=Math.floor((8*u-1)/g)+1;let p;p=Math.floor(_/(e.concurrency/L)),p>r&&(p=r),p<1024&&(p=1024);const f=[];for(let a=0;a<_;a+=p){n&&n.debug(`Multiexp start: ${s}: ${a}/${_}`);
1const o=Math.min(_-a,p),e=t.slice(a*d,(a+o)*d),r=c.slice(a*u,(a+o)*u);f.push(i(e,r,l,n,s).then(t=>(n&&n.debug(`Multiexp end: ${s}: ${a}/${_}`),t)))}const m=await Promise.all(f);let h=o.zero;for(let t=m.length-1;t>=0;t--)h=o.add(h,m[t]);return h}o.multiExp=async function(t,a,o,e){return await c(t,a,"jacobian",o,e)},o.multiExpAffine=async function(t,a,o,e){return await c(t,a,"affine",o,e)}}function Ha(t,a){const o=t[a],e=t.Fr,i=o.tm;async function c(t,n,s,r,d,_){s=s||"affine",r=r||"affine";let u,g,L,p,f,m,h,b;"G1"==a?("affine"==s?(u=2*o.F.n8,p="g1m_batchToJacobian"):u=3*o.F.n8,g=3*o.F.n8,n&&(b="g1m_fftFinal"),h="g1m_fftJoin",m="g1m_fftMix","affine"==r?(L=2*o.F.n8,f="g1m_batchToAffine"):L=3*o.F.n8):"G2"==a?("affine"==s?(u=2*o.F.n8,p="g2m_batchToJacobian"):u=3*o.F.n8,g=3*o.F.n8,n&&(b="g2m_fftFinal"),h="g2m_fftJoin",m="g2m_fftMix","affine"==r?(L=2*o.F.n8,f="g2m_batchToAffine"):L=3*o.F.n8):"Fr"==a&&(u=o.n8,g=o.n8,L=o.n8,n&&(b="frm_fftFinal"),m="frm_fftMix",h="frm_fftJoin");let x=!1;Array.isArray(t)?(t=Ma(t,u),x=!0):t=t.slice(0,t.byteLength);const y=t.byteLength/u,F=Oa(y);if(1<<F!=y)throw new Error("fft must be multiple of 2");if(F==e.s+1){let a;return a=n?await async function(t,a,o,i,n){let s,r;s=t.slice(0,t.byteLength/2),r=t.slice(t.byteLength/2,t.byteLength);const d=[];d.push(c(s,!0,a,"jacobian",i,n)),d.push(c(r,!0,a,"jacobian",i,n)),[s,r]=await Promise.all(d);const _=await l(s,r,"fftJoinExtInv",e.one,e.shiftInv,"jacobian",o,i,n);let u;u=_[0].byteLength>1<<28?new ka(2*_[0].byteLength):new Uint8Array(2*_[0].byteLength);return u.set(_[0]),u.set(_[1],_[0].byteLength),u}(t,s,r,d,_):await async function(t,a,o,i,n){let s,r;s=t.slice(0,t.byteLength/2),r=t.slice(t.byteLength/2,t.byteLength);const d=[];[s,r]=await l(s,r,"fftJoinExt",e.one,e.shift,a,"jacobian",i,n),d.push(c(s,!1,"jacobian",o,i,n)),d.push(c(r,!1,"jacobian",o,i,n));const _=await Promise.all(d);let u;u=_[0].byteLength>1<<28?new ka(2*_[0].byteLength):new Uint8Array(2*_[0].byteLength);return u.set(_[0]),u.set(_[1],_[0].byteLength),u}(t,s,r,d,_),x?Sa(a,L):a}let C,B,P;n&&(C=e.inv(e.e(y))),Ea(t,u);let A=Math.min(16384,y),w=y/A;for(;w<i.concurrency&&A>=16;)w*=2,A/=2;const q=Oa(A),v=[];for(let a=0;a<w;a++){d&&d.debug(`${_}: fft ${F} mix start: ${a}/${w}`);const o=[];o.push({cmd:"ALLOC",var:0,len:g*A});const e=t.slice(A*a*u,A*(a+1)*u);o.push({cmd:"SET",var:0,buff:e}),p&&o.push({cmd:"CALL",fnName:p,params:[{var:0},{val:A},{var:0}]});for(let t=1;t<=q;t++)o.push({cmd:"CALL",fnName:m,params:[{var:0},{val:A},{val:t}]});q==F?(b&&(o.push({cmd:"ALLOCSET",var:1,buff:C}),o.push({cmd:"CALL",fnName:b,params:[{var:0},{val:A},{var:1}]})),f&&o.push({cmd:"CALL",fnName:f,params:[{var:0},{val:A},{var:0}]}),o.push({cmd:"GET",out:0,var:0,len:A*L})):o.push({cmd:"GET",out:0,var:0,len:g*A}),v.push(i.queueAction(o).then(t=>(d&&d.debug(`${_}: fft ${F} mix end: ${a}/${w}`),t)))}P=await Promise.all(v);for(let t=0;t<w;t++)P[t]=P[t][0];for(let t=q+1;t<=F;t++){d&&d.debug(`${_}: fft ${F} join: ${t}/${F}`);const a=1<<F-t,o=w/a,c=[];for(let l=0;l<a;l++)for(let n=0;n<o/2;n++){const s=e.exp(e.w[t],n*A),r=e.w[t],u=l*o+n,p=l*o+n+o/2,m=[];m.push({cmd:"ALLOCSET",var:0,buff:P[u]}),m.push({cmd:"ALLOCSET",var:1,buff:P[p]}),m.push({cmd:"ALLOCSET",var:2,buff:s}),m.push({cmd:"ALLOCSET",var:3,buff:r}),m.push({cmd:"CALL",fnName:h,params:[{var:0},{var:1},{val:A},{var:2},{var:3}]}),t==F?(b&&(m.push({cmd:"ALLOCSET",var:4,buff:C}),m.push({cmd:"CALL",fnName:b,params:[{var:0},{val:A},{var:4}]}),m.push({cmd:"CALL",fnName:b,params:[{var:1},{val:A},{var:4}]})),f&&(m.push({cmd:"CALL",fnName:f,params:[{var:0},{val:A},{var:0}]}),m.push({cmd:"CALL",fnName:f,params:[{var:1},{val:A},{var:1}]})),m.push({cmd:"GET",out:0,var:0,len:A*L}),m.push({cmd:"GET",out:1,var:1,len:A*L})):(m.push({cmd:"GET",out:0,var:0,len:A*g}),m.push({cmd:"GET",out:1,var:1,len:A*g})),c.push(i.queueAction(m).then(e=>(d&&d.debug(`${_}: fft ${F} join ${t}/${F} ${l+1}/${a} ${n}/${o/2}`),e)))}const l=await Promise.all(c);for(let t=0;t<a;t++)for(let a=0;a<o/2;a++){const e=t*o+a,i=t*o+a+o/2,c=l.shift();P[e]=c[0],P[i]=c[1]}}if(B=t instanceof ka?new ka(y*L):new Uint8Array(y*L),n){B.set(P[0].slice((A-1)*L));let t=L;for(let a=w-1;a>0;a--)B.set(P[a],t),t+=A*L,delete P[a];B.set(P[0].slice(0,(A-1)*L),t),delete P[0]}else for(let t=0;t<w;t++)B.set(P[t],A*L*t),delete P[t];return x?Sa(B,L):B}async function l(t,c,l,n,s,r,d,_,u){let g,L,p,f,m,h;if("G1"==a)"affine"==r?(m=2*o.F.n8,L="g1m_batchToJacobian"):m=3*o.F.n8,h=3*o.F.n8,g="g1m_"+l,"affine"==d?(p="g1m_batchToAffine",f=2*o.F.n8):f=3*o.F.n8;else if("G2"==a)"affine"==r?(m=2*o.F.n8,L="g2m_batchToJacobian"):m=3*o.F.n8,g="g2m_"+l,h=3*o.F.n8,"affine"==d?(p="g2m_batchToAffine",f=2*o.F.n8):f=3*o.F.n8;else{if("Fr"!=a)throw new Error("Invalid group");m=e.n8,f=e.n8,h=e.n8,g="frm_"+l}if(t.byteLength!=c.byteLength)throw new Error("Invalid buffer size");const b=Math.floor(t.byteLength/m);
1if(b!=1<<Oa(b))throw new Error("Invalid number of points");let x=Math.floor(b/i.concurrency);x<16&&(x=16),x>65536&&(x=65536);const y=[];for(let a=0;a<b;a+=x){_&&_.debug(`${u}: fftJoinExt Start: ${a}/${b}`);const o=Math.min(b-a,x),l=e.mul(n,e.exp(s,a)),r=[],d=t.slice(a*m,(a+o)*m),F=c.slice(a*m,(a+o)*m);r.push({cmd:"ALLOC",var:0,len:h*o}),r.push({cmd:"SET",var:0,buff:d}),r.push({cmd:"ALLOC",var:1,len:h*o}),r.push({cmd:"SET",var:1,buff:F}),r.push({cmd:"ALLOCSET",var:2,buff:l}),r.push({cmd:"ALLOCSET",var:3,buff:s}),L&&(r.push({cmd:"CALL",fnName:L,params:[{var:0},{val:o},{var:0}]}),r.push({cmd:"CALL",fnName:L,params:[{var:1},{val:o},{var:1}]})),r.push({cmd:"CALL",fnName:g,params:[{var:0},{var:1},{val:o},{var:2},{var:3},{val:e.s}]}),p&&(r.push({cmd:"CALL",fnName:p,params:[{var:0},{val:o},{var:0}]}),r.push({cmd:"CALL",fnName:p,params:[{var:1},{val:o},{var:1}]})),r.push({cmd:"GET",out:0,var:0,len:o*f}),r.push({cmd:"GET",out:1,var:1,len:o*f}),y.push(i.queueAction(r).then(t=>(_&&_.debug(`${u}: fftJoinExt End: ${a}/${b}`),t)))}const F=await Promise.all(y);let C,B;b*f>1<<28?(C=new ka(b*f),B=new ka(b*f)):(C=new Uint8Array(b*f),B=new Uint8Array(b*f));let P=0;for(let t=0;t<F.length;t++)C.set(F[t][0],P),B.set(F[t][1],P),P+=F[t][0].byteLength;return[C,B]}o.fft=async function(t,a,o,e,i){return await c(t,!1,a,o,e,i)},o.ifft=async function(t,a,o,e,i){return await c(t,!0,a,o,e,i)},o.lagrangeEvaluations=async function(t,i,n,s,r){let d;if(i=i||"affine",n=n||"affine","G1"==a)d="affine"==i?2*o.F.n8:3*o.F.n8;else if("G2"==a)d="affine"==i?2*o.F.n8:3*o.F.n8;else{if("Fr"!=a)throw new Error("Invalid group");d=e.n8}const _=t.byteLength/d,u=Oa(_);if(2**u*d!=t.byteLength)throw s&&s.error("lagrangeEvaluations iinvalid input size"),new Error("lagrangeEvaluations invalid Input size");if(u<=e.s)return await o.ifft(t,i,n,s,r);if(u>e.s+1)throw s&&s.error("lagrangeEvaluations input too big"),new Error("lagrangeEvaluations input too big");let g=t.slice(0,t.byteLength/2),L=t.slice(t.byteLength/2,t.byteLength);const p=e.exp(e.shift,_/2),f=e.inv(e.sub(e.one,p));[g,L]=await l(g,L,"prepareLagrangeEvaluation",f,e.shiftInv,i,"jacobian",s,r+" prep");const m=[];let h;return m.push(c(g,!0,"jacobian",n,s,r+" t0")),m.push(c(L,!0,"jacobian",n,s,r+" t1")),[g,L]=await Promise.all(m),h=g.byteLength>1<<28?new ka(2*g.byteLength):new Uint8Array(2*g.byteLength),h.set(g),h.set(L,g.byteLength),h},o.fftMix=async function(t){const c=3*o.F.n8;let l,n;if("G1"==a)l="g1m_fftMix",n="g1m_fftJoin";else if("G2"==a)l="g2m_fftMix",n="g2m_fftJoin";else{if("Fr"!=a)throw new Error("Invalid group");l="frm_fftMix",n="frm_fftJoin"}const s=Math.floor(t.byteLength/c),r=Oa(s);let d=1<<Oa(i.concurrency);s<=2*d&&(d=1);const _=s/d,u=Oa(_),g=[];for(let a=0;a<d;a++){const o=[],e=t.slice(a*_*c,(a+1)*_*c);o.push({cmd:"ALLOCSET",var:0,buff:e});for(let t=1;t<=u;t++)o.push({cmd:"CALL",fnName:l,params:[{var:0},{val:_},{val:t}]});o.push({cmd:"GET",out:0,var:0,len:_*c}),g.push(i.queueAction(o))}const L=await Promise.all(g),p=[];for(let t=0;t<L.length;t++)p[t]=L[t][0];for(let t=u+1;t<=r;t++){const a=1<<r-t,o=d/a,l=[];for(let s=0;s<a;s++)for(let a=0;a<o/2;a++){const r=e.exp(e.w[t],a*_),d=e.w[t],u=s*o+a,g=s*o+a+o/2,L=[];L.push({cmd:"ALLOCSET",var:0,buff:p[u]}),L.push({cmd:"ALLOCSET",var:1,buff:p[g]}),L.push({cmd:"ALLOCSET",var:2,buff:r}),L.push({cmd:"ALLOCSET",var:3,buff:d}),L.push({cmd:"CALL",fnName:n,params:[{var:0},{var:1},{val:_},{var:2},{var:3}]}),L.push({cmd:"GET",out:0,var:0,len:_*c}),L.push({cmd:"GET",out:1,var:1,len:_*c}),l.push(i.queueAction(L))}const s=await Promise.all(l);for(let t=0;t<a;t++)for(let a=0;a<o/2;a++){const e=t*o+a,i=t*o+a+o/2,c=s.shift();p[e]=c[0],p[i]=c[1]}}let f;f=t instanceof ka?new ka(s*c):new Uint8Array(s*c);let m=0;for(let t=0;t<d;t++)f.set(p[t],m),m+=p[t].byteLength;return f},o.fftJoin=async function(t,c,l,n){const s=3*o.F.n8;let r;if("G1"==a)r="g1m_fftJoin";else if("G2"==a)r="g2m_fftJoin";else{if("Fr"!=a)throw new Error("Invalid group");r="frm_fftJoin"}if(t.byteLength!=c.byteLength)throw new Error("Invalid buffer size");const d=Math.floor(t.byteLength/s);if(d!=1<<Oa(d))throw new Error("Invalid number of points");let _=1<<Oa(i.concurrency);d<=2*_&&(_=1);const u=d/_,g=[];for(let a=0;a<_;a++){const o=[],d=e.mul(l,e.exp(n,a*u)),_=t.slice(a*u*s,(a+1)*u*s),L=c.slice(a*u*s,(a+1)*u*s);o.push({cmd:"ALLOCSET",var:0,buff:_}),o.push({cmd:"ALLOCSET",var:1,buff:L}),o.push({cmd:"ALLOCSET",var:2,buff:d}),o.push({cmd:"ALLOCSET",var:3,buff:n}),o.push({cmd:"CALL",fnName:r,params:[{var:0},{var:1},{val:u},{var:2},{var:3}]}),o.push({cmd:"GET",out:0,var:0,len:u*s}),o.push({cmd:"GET",out:1,var:1,len:u*s}),g.push(i.queueAction(o))}const L=await Promise.all(g);let p,f;t instanceof ka?(p=new ka(d*s),f=new ka(d*s)):(p=new Uint8Array(d*s),f=new Uint8Array(d*s));let m=0;for(let t=0;t<L.length;t++)p.set(L[t][0],m),f.set(L[t][1],m),m+=L[t][0].byteLength;return[p,f]},o.fftFinal=async function(t,e){const c=3*o.F.n8,l=2*o.F.n8;let n,s;if("G1"==a)n="g1m_fftFinal",s="g1m_batchToAffine";else{if("G2"!=a)throw new Error("Invalid group");n="g2m_fftFinal",s="g2m_batchToAffine"}const r=Math.floor(t.byteLength/c);if(r!=1<<Oa(r))throw new Error("Invalid number of points");const d=Math.floor(r/i.concurrency),_=[];for(let a=0;a<i.concurrency;a++){let o;if(o=a<i.concurrency-1?d:r-a*d,0==o)continue;const u=[],g=t.slice(a*d*c,(a*d+o)*c);u.push({cmd:"ALLOCSET",var:0,buff:g}),u.push({cmd:"ALLOCSET",var:1,buff:e}),u.push({cmd:"CALL",fnName:n,params:[{var:0},{val:o},{var:1}]}),u.push({cmd:"CALL",fnName:s,params:[{var:0},{val:o},{var:0}]}),u.push({cmd:"GET",out:0,var:0,len:o*l}),_.push(i.queueAction(u))}const u=await Promise.all(_);let g;g=t instanceof ka?new ka(r*l):new Uint8Array(r*l);let L=0;for(let t=u.length-1;t>=0;t--)g.set(u[t][0],L),L+=u[t][0].byteLength;return g}}async function to(t){const a=await Wa(t.wasm,t.singleThread),o={};return o.q=c(t.wasm.q.toString()),o.r=c(t.wasm.r.toString()),o.name=t.name,o.tm=a,o.prePSize=t.wasm.prePSize,o.preQSize=t.wasm.preQSize,o.Fr=new Na(a,"frm",t.n8r,t.r),o.F1=new Na(a,"f1m",t.n8q,t.q),o.F2=new Ra(a,"f2m",o.F1),o.G1=new Ua(a,"g1m",o.F1,t.wasm.pG1gen,t.wasm.pG1b,t.cofactorG1),o.G2=new
1Ua(a,"g2m",o.F2,t.wasm.pG2gen,t.wasm.pG2b,t.cofactorG2),o.F6=new ja(a,"f6m",o.F2),o.F12=new Ra(a,"ftm",o.F6),o.Gt=o.F12,Ka(o,"G1"),Ka(o,"G2"),Ka(o,"Fr"),Ya(o,"G1"),Ya(o,"G2"),Ha(o,"G1"),Ha(o,"G2"),Ha(o,"Fr"),function(t){const a=t.tm;t.pairing=function(o,e){a.startSyncOp();const i=a.allocBuff(t.G1.toJacobian(o)),c=a.allocBuff(t.G2.toJacobian(e)),l=a.alloc(t.Gt.n8);a.instance.exports[t.name+"_pairing"](i,c,l);const n=a.getBuff(l,t.Gt.n8);return a.endSyncOp(),n},t.pairingEq=async function(){let o,e;arguments.length%2==1?(o=arguments[arguments.length-1],e=(arguments.length-1)/2):(o=t.Gt.one,e=arguments.length/2);const i=[];for(let o=0;o<e;o++){const e=[],c=t.G1.toJacobian(arguments[2*o]);e.push({cmd:"ALLOCSET",var:0,buff:c}),e.push({cmd:"ALLOC",var:1,len:t.prePSize});const l=t.G2.toJacobian(arguments[2*o+1]);e.push({cmd:"ALLOCSET",var:2,buff:l}),e.push({cmd:"ALLOC",var:3,len:t.preQSize}),e.push({cmd:"ALLOC",var:4,len:t.Gt.n8}),e.push({cmd:"CALL",fnName:t.name+"_prepareG1",params:[{var:0},{var:1}]}),e.push({cmd:"CALL",fnName:t.name+"_prepareG2",params:[{var:2},{var:3}]}),e.push({cmd:"CALL",fnName:t.name+"_millerLoop",params:[{var:1},{var:3},{var:4}]}),e.push({cmd:"GET",out:0,var:4,len:t.Gt.n8}),i.push(a.queueAction(e))}const c=await Promise.all(i);a.startSyncOp();const l=a.alloc(t.Gt.n8);a.instance.exports.ftm_one(l);for(let t=0;t<c.length;t++){const o=a.allocBuff(c[t][0]);a.instance.exports.ftm_mul(l,o,l)}a.instance.exports[t.name+"_finalExponentiation"](l,l);const n=a.allocBuff(o),s=!!a.instance.exports.ftm_eq(l,n);return a.endSyncOp(),s},t.prepareG1=function(t){this.tm.startSyncOp();const a=this.tm.allocBuff(t),o=this.tm.alloc(this.prePSize);this.tm.instance.exports[this.name+"_prepareG1"](a,o);const e=this.tm.getBuff(o,this.prePSize);return this.tm.endSyncOp(),e},t.prepareG2=function(t){this.tm.startSyncOp();const a=this.tm.allocBuff(t),o=this.tm.alloc(this.preQSize);this.tm.instance.exports[this.name+"_prepareG2"](a,o);const e=this.tm.getBuff(o,this.preQSize);return this.tm.endSyncOp(),e},t.millerLoop=function(t,a){this.tm.startSyncOp();const o=this.tm.allocBuff(t),e=this.tm.allocBuff(a),i=this.tm.alloc(this.Gt.n8);this.tm.instance.exports[this.name+"_millerLoop"](o,e,i);const c=this.tm.getBuff(i,this.Gt.n8);return this.tm.endSyncOp(),c},t.finalExponentiation=function(t){this.tm.startSyncOp();const a=this.tm.allocBuff(t),o=this.tm.alloc(this.Gt.n8);this.tm.instance.exports[this.name+"_finalExponentiation"](a,o);const e=this.tm.getBuff(o,this.Gt.n8);return this.tm.endSyncOp(),e}}(o),o.array2buffer=function(t,a){const o=new Uint8Array(a*t.length);for(let e=0;e<t.length;e++)o.set(t[e],e*a);return o},o.buffer2array=function(t,a){const o=t.byteLength/a,e=new Array(o);for(let i=0;i<o;i++)e[i]=t.slice(i*a,i*a+a);return e},o}function ao(t){return BigInt(t)}function oo(t){return t<0n}function eo(t){return 0n===t}function io(t){const a=[],o=ao(t);return a.push(Number(0xFFn&o)),a.push(Number(o>>8n&0xFFn)),a.push(Number(o>>16n&0xFFn)),a.push(Number(o>>24n&0xFFn)),a}function co(t){const a=function(t){for(var a=[],o=0;o<t.length;o++){var e=t.charCodeAt(o);e<128?a.push(e):e<2048?a.push(192|e>>6,128|63&e):e<55296||e>=57344?a.push(224|e>>12,128|e>>6&63,128|63&e):(o++,e=65536+((1023&e)<<10|1023&t.charCodeAt(o)),a.push(240|e>>18,128|e>>12&63,128|e>>6&63,128|63&e))}return a}(t);return[..._o(a.length),...a]}function lo(t){const a=[];let o=ao(t);if(oo(o))throw new Error("Number cannot be negative");for(;!eo(o);)a.push(Number(0x7Fn&o)),o>>=7n;0==a.length&&a.push(0);for(let t=0;t<a.length-1;t++)a[t]=128|a[t];return a}function no(t){let a,o;const e=function(t){return oo(t)?t.toString(2).length-1:t.toString(2).length}(t);t<0?(o=!0,a=(1n<<BigInt(e))+t):(o=!1,a=ao(t));const i=7-e%7,c=(1<<7-i)-1|128,l=lo(a+((1n<<BigInt(i))-1n<<BigInt(e)));return o||(l[l.length-1]=l[l.length-1]&c),l}function so(t){let a=ao(t);if(a>0xFFFFFFFFn)throw new Error("Number too big");if(a>0x7FFFFFFFn&&(a-=0x100000000n),a<-2147483648n)throw new Error("Number too small");return no(a)}function ro(t){let a=ao(t);if(a>0xFFFFFFFFFFFFFFFFn)throw new Error("Number too big");if(a>0x7FFFFFFFFFFFFFFFn&&(a-=0x10000000000000000n),a<-9223372036854775808n)throw new Error("Number too small");return no(a)}function _o(t){let a=ao(t);if(a>0xFFFFFFFFn)throw new Error("Number too big");return lo(a)}function uo(t){return Array.from(t,function(t){return("0"+(255&t).toString(16)).slice(-2)}).join("")}class go{constructor(t){this.func=t,this.functionName=t.functionName,this.module=t.module}setLocal(t,a){const o=this.func.localIdxByName[t];if(void 0===o)throw new Error(`Local Variable not defined: Function: ${this.functionName} local: ${t} `);return[...a,33,..._o(o)]}teeLocal(t,a){const o=this.func.localIdxByName[t];if(void 0===o)throw new Error(`Local Variable not defined: Function: ${this.functionName} local: ${t} `);return[...a,34,..._o(o)]}getLocal(t){const a=this.func.localIdxByName[t];if(void 0===a)throw new Error(`Local Variable not defined: Function: ${this.functionName} local: ${t} `);return[32,..._o(a)]}i64_load8_s(t,a,o){return[...t,48,void 0===o?0:o,..._o(a||0)]}i64_load8_u(t,a,o){return[...t,49,void 0===o?0:o,..._o(a||0)]}i64_load16_s(t,a,o){return[...t,50,void 0===o?1:o,..._o(a||0)]}i64_load16_u(t,a,o){return[...t,51,void 0===o?1:o,..._o(a||0)]}i64_load32_s(t,a,o){return[...t,52,void 0===o?2:o,..._o(a||0)]}i64_load32_u(t,a,o){return[...t,53,void 0===o?2:o,..._o(a||0)]}i64_load(t,a,o){return[...t,41,void 0===o?3:o,..._o(a||0)]}i64_store(t,a,o,e){let i,c,l;return Array.isArray(a)?(i=0,c=3,l=a):Array.isArray(o)?(i=a,c=3,l=o):Array.isArray(e)&&(i=a,c=o,l=e),[...t,...l,55,c,..._o(i)]}i64_store32(t,a,o,e){let i,c,l;return Array.isArray(a)?(i=0,c=2,l=a):Array.isArray(o)?(i=a,c=2,l=o):Array.isArray(e)&&(i=a,c=o,l=e),[...t,...l,62,c,..._o(i)]}i64_store16(t,a,o,e){let i,c,l;return Array.isArray(a)?(i=0,c=1,l=a):Array.isArray(o)?(i=a,c=1,l=o):Array.isArray(e)&&(i=a,c=o,l=e),[...t,...l,61,c,..._o(i)]}i64_store8(t,a,o,e){let i,c,l;return Array.isArray(a)?(i=0,c=0,l=a):Array.isArray(o)?(i=a,c=0,l=o):Array.isArray(e)&&(i=a,c=o,l=e),[...t,...l,60,c,..._o(i)]}i32_load8_s(t,a,o){return[...t,44,void 0===o?0:o,..._o(a||0)]}i32_load8_u(t,a,o){return[...t,45,void 0===o?0:o,..._o(a||0)]}i32_load16_s(t,a,o){return[...t,46,void 0===o?1:o,..._o(a||0)]}i32_load16_u(t,a,o){return[...t,47,void 0===o?1:o,..._o(a||0)]}i32_load(t,a,o){return[...t,40,void 0===o?2:o,..._o(a||0)]}i32_store(t,a,o,e){let i,c,l;return Array.isArray(a)?(i=0,c=2,l=a):Array.isArray(o)?(i=a,c=2,l=o):Array.isArray(e)&&(i=a,c=o,l=e),[...t,...l,54,c,..._o(i)]}i32_store16(t,a,o,e){let i,c,l;return Array.isArray(a)?(i=0,c=1,l=a):Array.isArray(o)?(i=a,c=1,l=o):Array.isArray(e)&&(i=a,c=o,l=e),[...t,...l,59,c,..._o(i)]}i32_store8(t,a,o,e){let i,c,l;return Array.isArray(a)?(i=0,c=0,l=a):Array.isArray(o)?(i=a,c=0,l=o):Array.isArray(e)&&(i=a,c=o,l=e),[...t,...l,58,c,..._o(i)]}call(t,...a){const o=this.module.functionIdxByName[t];if(void 0===o)throw new Error(`Function not defined: Function: ${t}`);return[...[].concat(...a),16,..._o(o)]}call_indirect(t,...a){return[...[].concat(...a),...t,17,0,0]}if(t,a,o){return o?[...t,4,64,...a,5,...o,11]:[...t,4,64,...a,11]}block(t){return[2,64,...t,11]}loop(...t){return[3,64,...[].concat(...t),11]}br_if(t,a){return[...a,13,..._o(t)]}br(t){return[12,..._o(t)]}ret(t){return[...t,15]}drop(t){return[...t,26]}i64_const(t){return[66,...ro(t)]}i32_const(t){return[65,...so(t)]}i64_eqz(t){return[...t,80]}i64_eq(t,a){return[...t,...a,81]}i64_ne(t,a){return[...t,...a,82]}i64_lt_s(t,a){return[...t,...a,83]}i64_lt_u(t,a){return[...t,...a,84]}i64_gt_s(t,a){return[...t,...a,85]}i64_gt_u(t,a){return[...t,...a,86]}i64_le_s(t,a){return[...t,...a,87]}i64_le_u(t,a){return[...t,...a,88]}i64_ge_s(t,a){return[...t,...a,89]}i64_ge_u(t,a){return[...t,...a,90]}i64_add(t,a){return[...t,...a,124]}i64_sub(t,a){return[...t,...a,125]}i64_mul(t,a){return[...t,...a,126]}i64_div_s(t,a){return[...t,...a,127]}i64_div_u(t,a){return[...t,...a,128]}i64_rem_s(t,a){return[...t,...a,129]}i64_rem_u(t,a){return[...t,...a,130]}i64_and(t,a){return[...t,...a,131]}i64_or(t,a){return[...t,...a,132]}i64_xor(t,a){return[...t,...a,133]}i64_shl(t,a){return[...t,...a,134]}i64_shr_s(t,a){return[...t,...a,135]}i64_shr_u(t,a){return[...t,...a,136]}i64_extend_i32_s(t){return[...t,172]}i64_extend_i32_u(t){return[...t,173]}i64_clz(t){return[...t,121]}i64_ctz(t){return[...t,122]}i32_eqz(t){return[...t,69]}i32_eq(t,a){return[...t,...a,70]}i32_ne(t,a){return[...t,...a,71]}i32_lt_s(t,a){return[...t,...a,72]}i32_lt_u(t,a){return[...t,...a,73]}i32_gt_s(t,a){return[...t,...a,74]}i32_gt_u(t,a){return[...t,...a,75]}i32_le_s(t,a){return[...t,...a,76]}i32_le_u(t,a){return[...t,...a,77]}i32_ge_s(t,a){return[...t,...a,78]}i32_ge_u(t,a){return[...t,...a,79]}i32_add(t,a){return[...t,...a,106]}i32_sub(t,a){return[...t,...a,107]}i32_mul(t,a){return[...t,...a,108]}i32_div_s(t,a){return[...t,...a,109]}i32_div_u(t,a){return[...t,...a,110]}i32_rem_s(t,a){return[...t,...a,111]}i32_rem_u(t,a){return[...t,...a,112]}i32_and(t,a){return[...t,...a,113]}i32_or(t,a){return[...t,...a,114]}i32_xor(t,a){return[...t,...a,115]}i32_shl(t,a){return[...t,...a,116]}i32_shr_s(t,a){return[...t,...a,117]}i32_shr_u(t,a){return[...t,...a,118]}i32_rotl(t,a){return[...t,...a,119]}i32_rotr(t,a){return[...t,...a,120]}i32_wrap_i64(t){return[...t,167]}i32_clz(t){return[...t,103]}i32_ctz(t){return[...t,104]}unreachable(){return[0]}current_memory(){return[63,0]}comment(){return[]}}
1const Lo={i32:127,i64:126,f32:125,f64:124,anyfunc:112,func:96,emptyblock:64};class po{constructor(t,a,o,e,i){if("import"==o)this.fnType="import",this.moduleName=e,this.fieldName=i;else{if("internal"!=o)throw new Error("Invalid function fnType: "+o);this.fnType="internal"}this.module=t,this.fnName=a,this.params=[],this.locals=[],this.localIdxByName={},this.code=[],this.returnType=null,this.nextLocal=0}addParam(t,a){if(this.localIdxByName[t])throw new Error(`param already exists. Function: ${this.fnName}, Param: ${t} `);const o=this.nextLocal++;this.localIdxByName[t]=o,this.params.push({type:a})}addLocal(t,a,o){const e=o||1;if(this.localIdxByName[t])throw new Error(`local already exists. Function: ${this.fnName}, Param: ${t} `);const i=this.nextLocal++;this.localIdxByName[t]=i,this.locals.push({type:a,length:e})}setReturnType(t){if(this.returnType)throw new Error(`returnType already defined. Function: ${this.fnName}`);this.returnType=t}getSignature(){return[96,...[..._o(this.params.length),...this.params.map(t=>Lo[t.type])],...this.returnType?[1,Lo[this.returnType]]:[0]]}getBody(){const t=this.locals.map(t=>[..._o(t.length),Lo[t.type]]),a=[..._o(this.locals.length),...[].concat(...t),...this.code,11];return[..._o(a.length),...a]}addCode(...t){this.code.push(...[].concat(...t))}getCodeBuilder(){return new go(this)}}class fo{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([...io(1836278016),...io(1),...this._buildType(),...this._buildImport(),...this._buildFunctionDeclarations(),...this._buildFunctionsTable(),...this._buildExports(),...this._buildElements(),...this._buildCode(),...this._buildData()])}addFunction(t){if(void 0!==this.functionIdxByName[t])throw new Error(`Function already defined: ${t}`);const a=this.functions.length;return this.functionIdxByName[t]=a,this.functions.push(new po(this,t,"internal")),this.nInternalFunctions++,this.functions[a]}addIimportFunction(t,a,o){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 e=o||t;const i=this.functions.length;return this.functionIdxByName[t]=i,this.functions.push(new po(this,t,"import",a,e)),this.nImportFunctions++,this.functions[i]}setMemory(t,a,o){this.memory={pagesSize:t,moduleName:a||"env",fieldName:o||"memory"}}exportFunction(t,a){const o=a||t;if(void 0===this.functionIdxByName[t])throw new Error(`Function not defined: ${t}`);const e=this.functionIdxByName[t];o!=t&&(this.functionIdxByName[o]=e),this.exports.push({exportName:o,idx:e})}addFunctionToTable(t){const a=this.functionIdxByName[t];this.functionsTable.push(a)}addData(t,a){this.datas.push({offset:t,bytes:a})}alloc(t,a){let o,e;(Array.isArray(t)||ArrayBuffer.isView(t))&&void 0===a?(o=t.length,e=t):(o=t,e=a),o=1+(o-1>>3)<<3;const i=this.free;return this.free+=o,e&&this.addData(i,e),i}allocString(t){const a=(new globalThis.TextEncoder).encode(t);return this.alloc([...a,0])}_setSignatures(){this.signatures=[];const t={};if(this.functionsTable.length>0){const a=this.functions[this.functionsTable[0]].getSignature();t["s_"+uo(a)]=0,this.signatures.push(a)}for(let a=0;a<this.functions.length;a++){const o=this.functions[a].getSignature(),e="s_"+uo(o);void 0===t[e]&&(t[e]=this.signatures.length,this.signatures.push(o)),this.functions[a].signatureIdx=t[e]}}_buildSection(t,a){return[t,..._o(a.length),...a]}_buildType(){return this._buildSection(1,[..._o(this.signatures.length),...[].concat(...this.signatures)])}_buildImport(){const t=[];t.push([...co(this.memory.moduleName),...co(this.memory.fieldName),2,0,..._o(this.memory.pagesSize)]);for(let a=0;a<this.nImportFunctions;a++)t.push([...co(this.functions[a].moduleName),...co(this.functions[a].fieldName),0,..._o(this.functions[a].signatureIdx)]);return this._buildSection(2,_o(t.length).concat(...t))}_buildFunctionDeclarations(){const t=[];for(let a=this.nImportFunctions;a<this.nImportFunctions+this.nInternalFunctions;a++)t.push(..._o(this.functions[a].signatureIdx));return this._buildSection(3,[..._o(t.length),...t])}_buildFunctionsTable(){return 0==this.functionsTable.length?[]:this._buildSection(4,[..._o(1),112,0,..._o(this.functionsTable.length)])}_buildElements(){if(0==this.functionsTable.length)return[];const t=[];for(let a=0;a<this.functionsTable.length;a++)t.push(..._o(this.functionsTable[a]));return this._buildSection(9,[..._o(1),..._o(0),65,...so(0),11,..._o(this.functionsTable.length),...t])}_buildExports(){const t=[];for(let a=0;a<this.exports.length;a++)t.push([...co(this.exports[a].exportName),0,..._o(this.exports[a].idx)]);return this._buildSection(7,_o(t.length).concat(...t))}_buildCode(){const t=[];for(let a=this.nImportFunctions;a<this.nImportFunctions+this.nInternalFunctions;a++)t.push(this.functions[a].getBody());return this._buildSection(10,_o(t.length).concat(...t))}_buildData(){const t=[];t.push([0,65,0,11,4,...io(this.free)]);for(let a=0;a<this.datas.length;a++)t.push([0,65,...so(this.datas[a].offset),11,..._o(this.datas[a].bytes.length),...this.datas[a].bytes]);return this._buildSection(11,_o(t.length).concat(...t))}}async function mo(t,a){if(!t&&globalThis.curve_bn128)return globalThis.curve_bn128;const o=new fo;o.setMemory(25),Pa(o),a&&a(o);const e={};e.code=o.build(),e.pq=o.modules.f1m.pq,e.pr=o.modules.frm.pq,e.pG1gen=o.modules.bn128.pG1gen,e.pG1zero=o.modules.bn128.pG1zero,e.pG1b=o.modules.bn128.pG1b,e.pG2gen=o.modules.bn128.pG2gen,e.pG2zero=o.modules.bn128.pG2zero,e.pG2b=o.modules.bn128.pG2b,e.pOneT=o.modules.bn128.pOneT,e.prePSize=o.modules.bn128.prePSize,e.preQSize=o.modules.bn128.preQSize,e.n8q=32,e.n8r=32,e.q=o.modules.bn128.q,e.r=o.modules.bn128.r;const i={name:"bn128",wasm:e,q:c("21888242871839275222246405745257275088696311157297823662689037894645226208583"),r:c("21888242871839275222246405745257275088548364400416034343698204186575808495617"),n8q:32,n8r:32,cofactorG2:c("30644e72e131a029b85045b68181585e06ceecda572a2489345f2299c0f9fa8d",16),singleThread:!!t},l=await to(i);return l.terminate=async function(){i.singleThread||(globalThis.curve_bn128=null,await this.tm.terminate())},t||(globalThis.curve_bn128=l),l}async function ho(t,a){if(!t&&globalThis.curve_bls12381)return globalThis.curve_bls12381;const o=new fo;o.setMemory(25),Aa(o),a&&a(o);const e={};e.code=o.build(),e.pq=o.modules.f1m.pq,e.pr=o.modules.frm.pq,e.pG1gen=o.modules.bls12381.pG1gen,e.pG1zero=o.modules.bls12381.pG1zero,e.pG1b=o.modules.bls12381.pG1b,e.pG2gen=o.modules.bls12381.pG2gen,e.pG2zero=o.modules.bls12381.pG2zero,e.pG2b=o.modules.bls12381.pG2b,e.pOneT=o.modules.bls12381.pOneT,e.prePSize=o.modules.bls12381.prePSize,e.preQSize=o.modules.bls12381.preQSize,e.n8q=48,e.n8r=32,e.q=o.modules.bls12381.q,e.r=o.modules.bls12381.r;const i={name:"bls12381",wasm:e,q:c("1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab",16),r:c("73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",16),n8q:48,n8r:32,cofactorG1:c("0x396c8c005555e1568c00aaab0000aaab",16),cofactorG2:c("0x5d543a95414e7f1091d50792876a202cd91de4547085abaa68a205b2e5a7ddfa628f1cb4d9e82ef21537e293a6691ae1616ec6e786f0c70cf1c38e31c7238e5",16),singleThread:!!t},l=await to(i);return l.terminate=async function(){i.singleThread||(globalThis.curve_bls12381=null,await this.tm.terminate())},t||(globalThis.curve_bls12381=l),l}globalThis.curve_bn128=null,globalThis.curve_bls12381=null;c("73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",16),c("21888242871839275222246405745257275088548364400416034343698204186575808495617"),c("1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab",16),c("21888242871839275222246405745257275088696311157297823662689037894645226208583");async function bo(t,a,o){let e;const i=t.toUpperCase().match(/[A-Za-z0-9]+/g).join("");if(["BN128","BN254","ALTBN128"].indexOf(i)>=0)e=await mo(a,o);else{if(!(["BLS12381"].indexOf(i)>=0))throw new Error(`Curve not supported: ${t}`);e=await ho(a,o)}return e}const xo=T,yo=za}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.