snarkjs/build/snarkjs.min.js

11 lines
412 KiB
JavaScript

var snarkjs=function(t){"use strict";const e=[0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4];function a(t,e){return e&&10!=e?16==e?"0x"==t.slice(0,2)?BigInt(t):BigInt("0x"+t):void 0:BigInt(t)}const i=a;function o(t,e){return BigInt(t)<<BigInt(e)}function n(t,e){return BigInt(t)>>BigInt(e)}const r=o,c=n;var l=Object.freeze({__proto__:null,fromString:a,e:i,fromArray:function(t,e){let a=BigInt(0);e=BigInt(e);for(let i=0;i<t.length;i++)a=a*e+BigInt(t[i]);return a},bitLength:function(t){const a=t.toString(16);return 4*(a.length-1)+e[parseInt(a[0],16)]},isNegative:function(t){return BigInt(t)<BigInt(0)},isZero:function(t){return!t},shiftLeft:o,shiftRight:n,shl:r,shr:c,isOdd:function(t){return(BigInt(t)&BigInt(1))==BigInt(1)},naf:function(t){let e=BigInt(t);const a=[];for(;e;){if(e&BigInt(1)){const t=2-Number(e%BigInt(4));a.push(t),e-=BigInt(t)}else a.push(0);e>>=BigInt(1)}return a},bits:function(t){let e=BigInt(t);const a=[];for(;e;)e&BigInt(1)?a.push(1):a.push(0),e>>=BigInt(1);return a},toNumber:function(t){if(t>BigInt(Number.MAX_SAFE_INTEGER))throw new Error("Number too big");return Number(t)},toArray:function(t,e){const a=[];let i=BigInt(t);for(e=BigInt(e);i;)a.unshift(Number(i%e)),i/=e;return a},add:function(t,e){return BigInt(t)+BigInt(e)},sub:function(t,e){return BigInt(t)-BigInt(e)},neg:function(t){return-BigInt(t)},mul:function(t,e){return BigInt(t)*BigInt(e)},square:function(t){return BigInt(t)*BigInt(t)},pow:function(t,e){return BigInt(t)**BigInt(e)},exp:function(t,e){return BigInt(t)**BigInt(e)},abs:function(t){return BigInt(t)>=0?BigInt(t):-BigInt(t)},div:function(t,e){return BigInt(t)/BigInt(e)},mod:function(t,e){return BigInt(t)%BigInt(e)},eq:function(t,e){return BigInt(t)==BigInt(e)},neq:function(t,e){return BigInt(t)!=BigInt(e)},lt:function(t,e){return BigInt(t)<BigInt(e)},gt:function(t,e){return BigInt(t)>BigInt(e)},leq:function(t,e){return BigInt(t)<=BigInt(e)},geq:function(t,e){return BigInt(t)>=BigInt(e)},band:function(t,e){return BigInt(t)&BigInt(e)},bor:function(t,e){return BigInt(t)|BigInt(e)},bxor:function(t,e){return BigInt(t)^BigInt(e)},land:function(t,e){return BigInt(t)&&BigInt(e)},lor:function(t,e){return BigInt(t)||BigInt(e)},lnot:function(t){return!BigInt(t)}}),s="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function d(t){var e={exports:{}};return t(e,e.exports),e.exports}var u=d((function(t){var e=function(t){var a=1e7,i=9007199254740992,o=g(i),n="0123456789abcdefghijklmnopqrstuvwxyz",r="function"==typeof BigInt;function c(t,e,a,i){return void 0===t?c[0]:void 0!==e&&(10!=+e||a)?K(t,e,a,i):Z(t)}function l(t,e){this.value=t,this.sign=e,this.isSmall=!1}function s(t){this.value=t,this.sign=t<0,this.isSmall=!0}function d(t){this.value=t}function u(t){return-i<t&&t<i}function g(t){return t<1e7?[t]:t<1e14?[t%1e7,Math.floor(t/1e7)]:[t%1e7,Math.floor(t/1e7)%1e7,Math.floor(t/1e14)]}function f(t){_(t);var e=t.length;if(e<4&&S(t,o)<0)switch(e){case 0:return 0;case 1:return t[0];case 2:return t[0]+t[1]*a;default:return t[0]+(t[1]+t[2]*a)*a}return t}function _(t){for(var e=t.length;0===t[--e];);t.length=e+1}function p(t){for(var e=new Array(t),a=-1;++a<t;)e[a]=0;return e}function h(t){return t>0?Math.floor(t):Math.ceil(t)}function m(t,e){var i,o,n=t.length,r=e.length,c=new Array(n),l=0,s=a;for(o=0;o<r;o++)l=(i=t[o]+e[o]+l)>=s?1:0,c[o]=i-l*s;for(;o<n;)l=(i=t[o]+l)===s?1:0,c[o++]=i-l*s;return l>0&&c.push(l),c}function L(t,e){return t.length>=e.length?m(t,e):m(e,t)}function w(t,e){var i,o,n=t.length,r=new Array(n),c=a;for(o=0;o<n;o++)i=t[o]-c+e,e=Math.floor(i/c),r[o]=i-e*c,e+=1;for(;e>0;)r[o++]=e%c,e=Math.floor(e/c);return r}function A(t,e){var i,o,n=t.length,r=e.length,c=new Array(n),l=0,s=a;for(i=0;i<r;i++)(o=t[i]-l-e[i])<0?(o+=s,l=1):l=0,c[i]=o;for(i=r;i<n;i++){if(!((o=t[i]-l)<0)){c[i++]=o;break}o+=s,c[i]=o}for(;i<n;i++)c[i]=t[i];return _(c),c}function b(t,e,i){var o,n,r=t.length,c=new Array(r),d=-e,u=a;for(o=0;o<r;o++)n=t[o]+d,d=Math.floor(n/u),n%=u,c[o]=n<0?n+u:n;return"number"==typeof(c=f(c))?(i&&(c=-c),new s(c)):new l(c,i)}function y(t,e){var i,o,n,r,c=t.length,l=e.length,s=p(c+l),d=a;for(n=0;n<c;++n){r=t[n];for(var u=0;u<l;++u)i=r*e[u]+s[n+u],o=Math.floor(i/d),s[n+u]=i-o*d,s[n+u+1]+=o}return _(s),s}function I(t,e){var i,o,n=t.length,r=new Array(n),c=a,l=0;for(o=0;o<n;o++)i=t[o]*e+l,l=Math.floor(i/c),r[o]=i-l*c;for(;l>0;)r[o++]=l%c,l=Math.floor(l/c);return r}function C(t,e){for(var a=[];e-- >0;)a.push(0);return a.concat(t)}function F(t,e){var a=Math.max(t.length,e.length);if(a<=30)return y(t,e);a=Math.ceil(a/2);var i=t.slice(a),o=t.slice(0,a),n=e.slice(a),r=e.slice(0,a),c=F(o,r),l=F(i,n),s=F(L(o,i),L(r,n)),d=L(L(c,C(A(A(s,c),l),a)),C(l,2*a));return _(d),d}function x(t,e,i){return new l(t<a?I(e,t):y(e,g(t)),i)}function v(t){var e,i,o,n,r=t.length,c=p(r+r),l=a;for(o=0;o<r;o++){i=0-(n=t[o])*n;for(var s=o;s<r;s++)e=n*t[s]*2+c[o+s]+i,i=Math.floor(e/l),c[o+s]=e-i*l;c[o+r]=i}return _(c),c}function E(t,e){var a,i,o,n,r=t.length,c=p(r);for(o=0,a=r-1;a>=0;--a)o=(n=1e7*o+t[a])-(i=h(n/e))*e,c[a]=0|i;return[c,0|o]}function B(t,e){var i,o=Z(e);if(r)return[new d(t.value/o.value),new d(t.value%o.value)];var n,u=t.value,m=o.value;if(0===m)throw new Error("Cannot divide by zero");if(t.isSmall)return o.isSmall?[new s(h(u/m)),new s(u%m)]:[c[0],t];if(o.isSmall){if(1===m)return[t,c[0]];if(-1==m)return[t.negate(),c[0]];var L=Math.abs(m);if(L<a){n=f((i=E(u,L))[0]);var w=i[1];return t.sign&&(w=-w),"number"==typeof n?(t.sign!==o.sign&&(n=-n),[new s(n),new s(w)]):[new l(n,t.sign!==o.sign),new s(w)]}m=g(L)}var b=S(u,m);if(-1===b)return[c[0],t];if(0===b)return[c[t.sign===o.sign?1:-1],c[0]];i=u.length+m.length<=200?function(t,e){var i,o,n,r,c,l,s,d=t.length,u=e.length,g=a,_=p(e.length),h=e[u-1],m=Math.ceil(g/(2*h)),L=I(t,m),w=I(e,m);for(L.length<=d&&L.push(0),w.push(0),h=w[u-1],o=d-u;o>=0;o--){for(i=g-1,L[o+u]!==h&&(i=Math.floor((L[o+u]*g+L[o+u-1])/h)),n=0,r=0,l=w.length,c=0;c<l;c++)n+=i*w[c],s=Math.floor(n/g),r+=L[o+c]-(n-s*g),n=s,r<0?(L[o+c]=r+g,r=-1):(L[o+c]=r,r=0);for(;0!==r;){for(i-=1,n=0,c=0;c<l;c++)(n+=L[o+c]-g+w[c])<0?(L[o+c]=n+g,n=0):(L[o+c]=n,n=1);r+=n}_[o]=i}return L=E(L,m)[0],[f(_),f(L)]}(u,m):function(t,e){for(var i,o,n,r,c,l=t.length,s=e.length,d=[],u=[],g=a;l;)if(u.unshift(t[--l]),_(u),S(u,e)<0)d.push(0);else{n=u[(o=u.length)-1]*g+u[o-2],r=e[s-1]*g+e[s-2],o>s&&(n=(n+1)*g),i=Math.ceil(n/r);do{if(S(c=I(e,i),u)<=0)break;i--}while(i);d.push(i),u=A(u,c)}return d.reverse(),[f(d),f(u)]}(u,m),n=i[0];var y=t.sign!==o.sign,C=i[1],F=t.sign;return"number"==typeof n?(y&&(n=-n),n=new s(n)):n=new l(n,y),"number"==typeof C?(F&&(C=-C),C=new s(C)):C=new l(C,F),[n,C]}function S(t,e){if(t.length!==e.length)return t.length>e.length?1:-1;for(var a=t.length-1;a>=0;a--)if(t[a]!==e[a])return t[a]>e[a]?1:-1;return 0}function G(t){var e=t.abs();return!e.isUnit()&&(!!(e.equals(2)||e.equals(3)||e.equals(5))||!(e.isEven()||e.isDivisibleBy(3)||e.isDivisibleBy(5))&&(!!e.lesser(49)||void 0))}function P(t,a){for(var i,o,n,r=t.prev(),c=r,l=0;c.isEven();)c=c.divide(2),l++;t:for(o=0;o<a.length;o++)if(!t.lesser(a[o])&&!(n=e(a[o]).modPow(c,t)).isUnit()&&!n.equals(r)){for(i=l-1;0!=i;i--){if((n=n.square().mod(t)).isUnit())return!1;if(n.equals(r))continue t}return!1}return!0}l.prototype=Object.create(c.prototype),s.prototype=Object.create(c.prototype),d.prototype=Object.create(c.prototype),l.prototype.add=function(t){var e=Z(t);if(this.sign!==e.sign)return this.subtract(e.negate());var a=this.value,i=e.value;return e.isSmall?new l(w(a,Math.abs(i)),this.sign):new l(L(a,i),this.sign)},l.prototype.plus=l.prototype.add,s.prototype.add=function(t){var e=Z(t),a=this.value;if(a<0!==e.sign)return this.subtract(e.negate());var i=e.value;if(e.isSmall){if(u(a+i))return new s(a+i);i=g(Math.abs(i))}return new l(w(i,Math.abs(a)),a<0)},s.prototype.plus=s.prototype.add,d.prototype.add=function(t){return new d(this.value+Z(t).value)},d.prototype.plus=d.prototype.add,l.prototype.subtract=function(t){var e=Z(t);if(this.sign!==e.sign)return this.add(e.negate());var a=this.value,i=e.value;return e.isSmall?b(a,Math.abs(i),this.sign):function(t,e,a){var i;return S(t,e)>=0?i=A(t,e):(i=A(e,t),a=!a),"number"==typeof(i=f(i))?(a&&(i=-i),new s(i)):new l(i,a)}(a,i,this.sign)},l.prototype.minus=l.prototype.subtract,s.prototype.subtract=function(t){var e=Z(t),a=this.value;if(a<0!==e.sign)return this.add(e.negate());var i=e.value;return e.isSmall?new s(a-i):b(i,Math.abs(a),a>=0)},s.prototype.minus=s.prototype.subtract,d.prototype.subtract=function(t){return new d(this.value-Z(t).value)},d.prototype.minus=d.prototype.subtract,l.prototype.negate=function(){return new l(this.value,!this.sign)},s.prototype.negate=function(){var t=this.sign,e=new s(-this.value);return e.sign=!t,e},d.prototype.negate=function(){return new d(-this.value)},l.prototype.abs=function(){return new l(this.value,!1)},s.prototype.abs=function(){return new s(Math.abs(this.value))},d.prototype.abs=function(){return new d(this.value>=0?this.value:-this.value)},l.prototype.multiply=function(t){var e,i,o,n=Z(t),r=this.value,s=n.value,d=this.sign!==n.sign;if(n.isSmall){if(0===s)return c[0];if(1===s)return this;if(-1===s)return this.negate();if((e=Math.abs(s))<a)return new l(I(r,e),d);s=g(e)}return i=r.length,o=s.length,new l(-.012*i-.012*o+15e-6*i*o>0?F(r,s):y(r,s),d)},l.prototype.times=l.prototype.multiply,s.prototype._multiplyBySmall=function(t){return u(t.value*this.value)?new s(t.value*this.value):x(Math.abs(t.value),g(Math.abs(this.value)),this.sign!==t.sign)},l.prototype._multiplyBySmall=function(t){return 0===t.value?c[0]:1===t.value?this:-1===t.value?this.negate():x(Math.abs(t.value),this.value,this.sign!==t.sign)},s.prototype.multiply=function(t){return Z(t)._multiplyBySmall(this)},s.prototype.times=s.prototype.multiply,d.prototype.multiply=function(t){return new d(this.value*Z(t).value)},d.prototype.times=d.prototype.multiply,l.prototype.square=function(){return new l(v(this.value),!1)},s.prototype.square=function(){var t=this.value*this.value;return u(t)?new s(t):new l(v(g(Math.abs(this.value))),!1)},d.prototype.square=function(t){return new d(this.value*this.value)},l.prototype.divmod=function(t){var e=B(this,t);return{quotient:e[0],remainder:e[1]}},d.prototype.divmod=s.prototype.divmod=l.prototype.divmod,l.prototype.divide=function(t){return B(this,t)[0]},d.prototype.over=d.prototype.divide=function(t){return new d(this.value/Z(t).value)},s.prototype.over=s.prototype.divide=l.prototype.over=l.prototype.divide,l.prototype.mod=function(t){return B(this,t)[1]},d.prototype.mod=d.prototype.remainder=function(t){return new d(this.value%Z(t).value)},s.prototype.remainder=s.prototype.mod=l.prototype.remainder=l.prototype.mod,l.prototype.pow=function(t){var e,a,i,o=Z(t),n=this.value,r=o.value;if(0===r)return c[1];if(0===n)return c[0];if(1===n)return c[1];if(-1===n)return o.isEven()?c[1]:c[-1];if(o.sign)return c[0];if(!o.isSmall)throw new Error("The exponent "+o.toString()+" is too large.");if(this.isSmall&&u(e=Math.pow(n,r)))return new s(h(e));for(a=this,i=c[1];!0&r&&(i=i.times(a),--r),0!==r;)r/=2,a=a.square();return i},s.prototype.pow=l.prototype.pow,d.prototype.pow=function(t){var e=Z(t),a=this.value,i=e.value,o=BigInt(0),n=BigInt(1),r=BigInt(2);if(i===o)return c[1];if(a===o)return c[0];if(a===n)return c[1];if(a===BigInt(-1))return e.isEven()?c[1]:c[-1];if(e.isNegative())return new d(o);for(var l=this,s=c[1];(i&n)===n&&(s=s.times(l),--i),i!==o;)i/=r,l=l.square();return s},l.prototype.modPow=function(t,e){if(t=Z(t),(e=Z(e)).isZero())throw new Error("Cannot take modPow with modulus 0");var a=c[1],i=this.mod(e);for(t.isNegative()&&(t=t.multiply(c[-1]),i=i.modInv(e));t.isPositive();){if(i.isZero())return c[0];t.isOdd()&&(a=a.multiply(i).mod(e)),t=t.divide(2),i=i.square().mod(e)}return a},d.prototype.modPow=s.prototype.modPow=l.prototype.modPow,l.prototype.compareAbs=function(t){var e=Z(t),a=this.value,i=e.value;return e.isSmall?1:S(a,i)},s.prototype.compareAbs=function(t){var e=Z(t),a=Math.abs(this.value),i=e.value;return e.isSmall?a===(i=Math.abs(i))?0:a>i?1:-1:-1},d.prototype.compareAbs=function(t){var e=this.value,a=Z(t).value;return(e=e>=0?e:-e)===(a=a>=0?a:-a)?0:e>a?1:-1},l.prototype.compare=function(t){if(t===1/0)return-1;if(t===-1/0)return 1;var e=Z(t),a=this.value,i=e.value;return this.sign!==e.sign?e.sign?1:-1:e.isSmall?this.sign?-1:1:S(a,i)*(this.sign?-1:1)},l.prototype.compareTo=l.prototype.compare,s.prototype.compare=function(t){if(t===1/0)return-1;if(t===-1/0)return 1;var e=Z(t),a=this.value,i=e.value;return e.isSmall?a==i?0:a>i?1:-1:a<0!==e.sign?a<0?-1:1:a<0?1:-1},s.prototype.compareTo=s.prototype.compare,d.prototype.compare=function(t){if(t===1/0)return-1;if(t===-1/0)return 1;var e=this.value,a=Z(t).value;return e===a?0:e>a?1:-1},d.prototype.compareTo=d.prototype.compare,l.prototype.equals=function(t){return 0===this.compare(t)},d.prototype.eq=d.prototype.equals=s.prototype.eq=s.prototype.equals=l.prototype.eq=l.prototype.equals,l.prototype.notEquals=function(t){return 0!==this.compare(t)},d.prototype.neq=d.prototype.notEquals=s.prototype.neq=s.prototype.notEquals=l.prototype.neq=l.prototype.notEquals,l.prototype.greater=function(t){return this.compare(t)>0},d.prototype.gt=d.prototype.greater=s.prototype.gt=s.prototype.greater=l.prototype.gt=l.prototype.greater,l.prototype.lesser=function(t){return this.compare(t)<0},d.prototype.lt=d.prototype.lesser=s.prototype.lt=s.prototype.lesser=l.prototype.lt=l.prototype.lesser,l.prototype.greaterOrEquals=function(t){return this.compare(t)>=0},d.prototype.geq=d.prototype.greaterOrEquals=s.prototype.geq=s.prototype.greaterOrEquals=l.prototype.geq=l.prototype.greaterOrEquals,l.prototype.lesserOrEquals=function(t){return this.compare(t)<=0},d.prototype.leq=d.prototype.lesserOrEquals=s.prototype.leq=s.prototype.lesserOrEquals=l.prototype.leq=l.prototype.lesserOrEquals,l.prototype.isEven=function(){return 0==(1&this.value[0])},s.prototype.isEven=function(){return 0==(1&this.value)},d.prototype.isEven=function(){return(this.value&BigInt(1))===BigInt(0)},l.prototype.isOdd=function(){return 1==(1&this.value[0])},s.prototype.isOdd=function(){return 1==(1&this.value)},d.prototype.isOdd=function(){return(this.value&BigInt(1))===BigInt(1)},l.prototype.isPositive=function(){return!this.sign},s.prototype.isPositive=function(){return this.value>0},d.prototype.isPositive=s.prototype.isPositive,l.prototype.isNegative=function(){return this.sign},s.prototype.isNegative=function(){return this.value<0},d.prototype.isNegative=s.prototype.isNegative,l.prototype.isUnit=function(){return!1},s.prototype.isUnit=function(){return 1===Math.abs(this.value)},d.prototype.isUnit=function(){return this.abs().value===BigInt(1)},l.prototype.isZero=function(){return!1},s.prototype.isZero=function(){return 0===this.value},d.prototype.isZero=function(){return this.value===BigInt(0)},l.prototype.isDivisibleBy=function(t){var e=Z(t);return!e.isZero()&&(!!e.isUnit()||(0===e.compareAbs(2)?this.isEven():this.mod(e).isZero()))},d.prototype.isDivisibleBy=s.prototype.isDivisibleBy=l.prototype.isDivisibleBy,l.prototype.isPrime=function(a){var i=G(this);if(i!==t)return i;var o=this.abs(),n=o.bitLength();if(n<=64)return P(o,[2,3,5,7,11,13,17,19,23,29,31,37]);for(var r=Math.log(2)*n.toJSNumber(),c=Math.ceil(!0===a?2*Math.pow(r,2):r),l=[],s=0;s<c;s++)l.push(e(s+2));return P(o,l)},d.prototype.isPrime=s.prototype.isPrime=l.prototype.isPrime,l.prototype.isProbablePrime=function(a,i){var o=G(this);if(o!==t)return o;for(var n=this.abs(),r=a===t?5:a,c=[],l=0;l<r;l++)c.push(e.randBetween(2,n.minus(2),i));return P(n,c)},d.prototype.isProbablePrime=s.prototype.isProbablePrime=l.prototype.isProbablePrime,l.prototype.modInv=function(t){for(var a,i,o,n=e.zero,r=e.one,c=Z(t),l=this.abs();!l.isZero();)a=c.divide(l),i=n,o=c,n=r,c=l,r=i.subtract(a.multiply(r)),l=o.subtract(a.multiply(l));if(!c.isUnit())throw new Error(this.toString()+" and "+t.toString()+" are not co-prime");return-1===n.compare(0)&&(n=n.add(t)),this.isNegative()?n.negate():n},d.prototype.modInv=s.prototype.modInv=l.prototype.modInv,l.prototype.next=function(){var t=this.value;return this.sign?b(t,1,this.sign):new l(w(t,1),this.sign)},s.prototype.next=function(){var t=this.value;return t+1<i?new s(t+1):new l(o,!1)},d.prototype.next=function(){return new d(this.value+BigInt(1))},l.prototype.prev=function(){var t=this.value;return this.sign?new l(w(t,1),!0):b(t,1,this.sign)},s.prototype.prev=function(){var t=this.value;return t-1>-i?new s(t-1):new l(o,!0)},d.prototype.prev=function(){return new d(this.value-BigInt(1))};for(var O=[1];2*O[O.length-1]<=a;)O.push(2*O[O.length-1]);var U=O.length,z=O[U-1];function q(t){return Math.abs(t)<=a}function Q(t,a,i){a=Z(a);for(var o=t.isNegative(),n=a.isNegative(),r=o?t.not():t,c=n?a.not():a,l=0,s=0,d=null,u=null,g=[];!r.isZero()||!c.isZero();)l=(d=B(r,z))[1].toJSNumber(),o&&(l=z-1-l),s=(u=B(c,z))[1].toJSNumber(),n&&(s=z-1-s),r=d[0],c=u[0],g.push(i(l,s));for(var f=0!==i(o?1:0,n?1:0)?e(-1):e(0),_=g.length-1;_>=0;_-=1)f=f.multiply(z).add(e(g[_]));return f}l.prototype.shiftLeft=function(t){var e=Z(t).toJSNumber();if(!q(e))throw new Error(String(e)+" is too large for shifting.");if(e<0)return this.shiftRight(-e);var a=this;if(a.isZero())return a;for(;e>=U;)a=a.multiply(z),e-=U-1;return a.multiply(O[e])},d.prototype.shiftLeft=s.prototype.shiftLeft=l.prototype.shiftLeft,l.prototype.shiftRight=function(t){var e,a=Z(t).toJSNumber();if(!q(a))throw new Error(String(a)+" is too large for shifting.");if(a<0)return this.shiftLeft(-a);for(var i=this;a>=U;){if(i.isZero()||i.isNegative()&&i.isUnit())return i;i=(e=B(i,z))[1].isNegative()?e[0].prev():e[0],a-=U-1}return(e=B(i,O[a]))[1].isNegative()?e[0].prev():e[0]},d.prototype.shiftRight=s.prototype.shiftRight=l.prototype.shiftRight,l.prototype.not=function(){return this.negate().prev()},d.prototype.not=s.prototype.not=l.prototype.not,l.prototype.and=function(t){return Q(this,t,(function(t,e){return t&e}))},d.prototype.and=s.prototype.and=l.prototype.and,l.prototype.or=function(t){return Q(this,t,(function(t,e){return t|e}))},d.prototype.or=s.prototype.or=l.prototype.or,l.prototype.xor=function(t){return Q(this,t,(function(t,e){return t^e}))},d.prototype.xor=s.prototype.xor=l.prototype.xor;var M=1<<30;function k(t){var e=t.value,i="number"==typeof e?e|M:"bigint"==typeof e?e|BigInt(M):e[0]+e[1]*a|1073758208;return i&-i}function R(t,a){if(a.compareTo(t)<=0){var i=R(t,a.square(a)),o=i.p,n=i.e,r=o.multiply(a);return r.compareTo(t)<=0?{p:r,e:2*n+1}:{p:o,e:2*n}}return{p:e(1),e:0}}function N(t,e){return t=Z(t),e=Z(e),t.greater(e)?t:e}function T(t,e){return t=Z(t),e=Z(e),t.lesser(e)?t:e}function D(t,e){if(t=Z(t).abs(),e=Z(e).abs(),t.equals(e))return t;if(t.isZero())return e;if(e.isZero())return t;for(var a,i,o=c[1];t.isEven()&&e.isEven();)a=T(k(t),k(e)),t=t.divide(a),e=e.divide(a),o=o.multiply(a);for(;t.isEven();)t=t.divide(k(t));do{for(;e.isEven();)e=e.divide(k(e));t.greater(e)&&(i=e,e=t,t=i),e=e.subtract(t)}while(!e.isZero());return o.isUnit()?t:t.multiply(o)}l.prototype.bitLength=function(){var t=this;return t.compareTo(e(0))<0&&(t=t.negate().subtract(e(1))),0===t.compareTo(e(0))?e(0):e(R(t,e(2)).e).add(e(1))},d.prototype.bitLength=s.prototype.bitLength=l.prototype.bitLength;var K=function(t,e,a,i){a=a||n,t=String(t),i||(t=t.toLowerCase(),a=a.toLowerCase());var o,r=t.length,c=Math.abs(e),l={};for(o=0;o<a.length;o++)l[a[o]]=o;for(o=0;o<r;o++){if("-"!==(u=t[o])&&(u in l&&l[u]>=c)){if("1"===u&&1===c)continue;throw new Error(u+" is not a valid digit in base "+e+".")}}e=Z(e);var s=[],d="-"===t[0];for(o=d?1:0;o<t.length;o++){var u;if((u=t[o])in l)s.push(Z(l[u]));else{if("<"!==u)throw new Error(u+" is not a valid character");var g=o;do{o++}while(">"!==t[o]&&o<t.length);s.push(Z(t.slice(g+1,o)))}}return V(s,e,d)};function V(t,e,a){var i,o=c[0],n=c[1];for(i=t.length-1;i>=0;i--)o=o.add(t[i].times(n)),n=n.times(e);return a?o.negate():o}function j(t,a){if((a=e(a)).isZero()){if(t.isZero())return{value:[0],isNegative:!1};throw new Error("Cannot convert nonzero numbers to base 0.")}if(a.equals(-1)){if(t.isZero())return{value:[0],isNegative:!1};if(t.isNegative())return{value:[].concat.apply([],Array.apply(null,Array(-t.toJSNumber())).map(Array.prototype.valueOf,[1,0])),isNegative:!1};var i=Array.apply(null,Array(t.toJSNumber()-1)).map(Array.prototype.valueOf,[0,1]);return i.unshift([1]),{value:[].concat.apply([],i),isNegative:!1}}var o=!1;if(t.isNegative()&&a.isPositive()&&(o=!0,t=t.abs()),a.isUnit())return t.isZero()?{value:[0],isNegative:!1}:{value:Array.apply(null,Array(t.toJSNumber())).map(Number.prototype.valueOf,1),isNegative:o};for(var n,r=[],c=t;c.isNegative()||c.compareAbs(a)>=0;){n=c.divmod(a),c=n.quotient;var l=n.remainder;l.isNegative()&&(l=a.minus(l).abs(),c=c.next()),r.push(l.toJSNumber())}return r.push(c.toJSNumber()),{value:r.reverse(),isNegative:o}}function H(t,e,a){var i=j(t,e);return(i.isNegative?"-":"")+i.value.map((function(t){return function(t,e){return t<(e=e||n).length?e[t]:"<"+t+">"}(t,a)})).join("")}function $(t){if(u(+t)){var e=+t;if(e===h(e))return r?new d(BigInt(e)):new s(e);throw new Error("Invalid integer: "+t)}var a="-"===t[0];a&&(t=t.slice(1));var i=t.split(/e/i);if(i.length>2)throw new Error("Invalid integer: "+i.join("e"));if(2===i.length){var o=i[1];if("+"===o[0]&&(o=o.slice(1)),(o=+o)!==h(o)||!u(o))throw new Error("Invalid integer: "+o+" is not a valid exponent.");var n=i[0],c=n.indexOf(".");if(c>=0&&(o-=n.length-c-1,n=n.slice(0,c)+n.slice(c+1)),o<0)throw new Error("Cannot include negative exponent part for integers");t=n+=new Array(o+1).join("0")}if(!/^([0-9][0-9]*)$/.test(t))throw new Error("Invalid integer: "+t);if(r)return new d(BigInt(a?"-"+t:t));for(var g=[],f=t.length,p=f-7;f>0;)g.push(+t.slice(p,f)),(p-=7)<0&&(p=0),f-=7;return _(g),new l(g,a)}function Z(t){return"number"==typeof t?function(t){if(r)return new d(BigInt(t));if(u(t)){if(t!==h(t))throw new Error(t+" is not an integer.");return new s(t)}return $(t.toString())}(t):"string"==typeof t?$(t):"bigint"==typeof t?new d(t):t}l.prototype.toArray=function(t){return j(this,t)},s.prototype.toArray=function(t){return j(this,t)},d.prototype.toArray=function(t){return j(this,t)},l.prototype.toString=function(e,a){if(e===t&&(e=10),10!==e)return H(this,e,a);for(var i,o=this.value,n=o.length,r=String(o[--n]);--n>=0;)i=String(o[n]),r+="0000000".slice(i.length)+i;return(this.sign?"-":"")+r},s.prototype.toString=function(e,a){return e===t&&(e=10),10!=e?H(this,e,a):String(this.value)},d.prototype.toString=s.prototype.toString,d.prototype.toJSON=l.prototype.toJSON=s.prototype.toJSON=function(){return this.toString()},l.prototype.valueOf=function(){return parseInt(this.toString(),10)},l.prototype.toJSNumber=l.prototype.valueOf,s.prototype.valueOf=function(){return this.value},s.prototype.toJSNumber=s.prototype.valueOf,d.prototype.valueOf=d.prototype.toJSNumber=function(){return parseInt(this.toString(),10)};for(var Y=0;Y<1e3;Y++)c[Y]=Z(Y),Y>0&&(c[-Y]=Z(-Y));return c.one=c[1],c.zero=c[0],c.minusOne=c[-1],c.max=N,c.min=T,c.gcd=D,c.lcm=function(t,e){return t=Z(t).abs(),e=Z(e).abs(),t.divide(D(t,e)).multiply(e)},c.isInstance=function(t){return t instanceof l||t instanceof s||t instanceof d},c.randBetween=function(t,e,i){t=Z(t),e=Z(e);var o=i||Math.random,n=T(t,e),r=N(t,e).subtract(n).add(1);if(r.isSmall)return n.add(Math.floor(o()*r));for(var l=j(r,a).value,s=[],d=!0,u=0;u<l.length;u++){var g=d?l[u]+(u+1<l.length?l[u+1]/a:0):a,f=h(o()*g);s.push(f),f<l[u]&&(d=!1)}return n.add(c.fromArray(s,a,!1))},c.fromArray=function(t,e,a){return V(t.map(Z),Z(e||10),a)},c}();t.hasOwnProperty("exports")&&(t.exports=e)}));function g(t,e){return"string"==typeof t&&"0x"==t.slice(0,2)?u(t.slice(2),16):u(t,e)}const f=g;function _(t,e){return u(t).shiftLeft(e)}function p(t,e){return u(t).shiftRight(e)}const h=_,m=p;var L=Object.freeze({__proto__:null,fromString:g,e:f,fromArray:function(t,e){return u.fromArray(t,e)},bitLength:function(t){return u(t).bitLength()},isNegative:function(t){return u(t).isNegative()},isZero:function(t){return u(t).isZero()},shiftLeft:_,shiftRight:p,shl:h,shr:m,isOdd:function(t){return u(t).isOdd()},naf:function(t){let e=u(t);const a=[];for(;e.gt(u.zero);){if(e.isOdd()){const t=2-e.mod(4).toJSNumber();a.push(t),e=e.minus(t)}else a.push(0);e=e.shiftRight(1)}return a},bits:function(t){let e=u(t);const a=[];for(;e.gt(u.zero);)e.isOdd()?a.push(1):a.push(0),e=e.shiftRight(1);return a},toNumber:function(t){if(!t.lt(u("9007199254740992",10)))throw new Error("Number too big");return t.toJSNumber()},toArray:function(t,e){return u(t).toArray(e)},add:function(t,e){return u(t).add(u(e))},sub:function(t,e){return u(t).minus(u(e))},neg:function(t){return u.zero.minus(u(t))},mul:function(t,e){return u(t).times(u(e))},square:function(t){return u(t).square()},pow:function(t,e){return u(t).pow(u(e))},exp:function(t,e){return u(t).pow(u(e))},abs:function(t){return u(t).abs()},div:function(t,e){return u(t).divide(u(e))},mod:function(t,e){return u(t).mod(u(e))},eq:function(t,e){return u(t).eq(u(e))},neq:function(t,e){return u(t).neq(u(e))},lt:function(t,e){return u(t).lt(u(e))},gt:function(t,e){return u(t).gt(u(e))},leq:function(t,e){return u(t).leq(u(e))},geq:function(t,e){return u(t).geq(u(e))},band:function(t,e){return u(t).and(u(e))},bor:function(t,e){return u(t).or(u(e))},bxor:function(t,e){return u(t).xor(u(e))},land:function(t,e){return!u(t).isZero()&&!u(e).isZero()},lor:function(t,e){return!u(t).isZero()||!u(e).isZero()},lnot:function(t){return u(t).isZero()}});const w="function"==typeof BigInt;let A={};w?Object.assign(A,l):Object.assign(A,L),A.toRprLE=function(t,e,a,i){const o="0000000"+a.toString(16),n=new Uint32Array(t.buffer,e,i/4),r=1+(4*(o.length-7)-1>>5);for(let t=0;t<r;t++)n[t]=parseInt(o.substring(o.length-8*t-8,o.length-8*t),16);for(let t=r;t<n.length;t++)n[t]=0;for(let e=4*n.length;e<i;e++)t[e]=A.toNumber(A.band(A.shiftRight(a,8*e),255))},A.toRprBE=function(t,e,a,i){const o="0000000"+a.toString(16),n=new DataView(t.buffer,t.byteOffset+e,i),r=1+(4*(o.length-7)-1>>5);for(let t=0;t<r;t++)n.setUint32(i-4*t-4,parseInt(o.substring(o.length-8*t-8,o.length-8*t),16),!1);for(let t=0;t<i/4-r;t++)n[t]=0},A.fromRprLE=function(t,e,a){a=a||t.byteLength,e=e||0;const i=new Uint32Array(t.buffer,e,a/4),o=new Array(a/4);return i.forEach(((t,e)=>o[o.length-e-1]=t.toString(16).padStart(8,"0"))),A.fromString(o.join(""),16)},A.fromRprBE=function(t,e,a){a=a||t.byteLength,e=e||0;const i=new DataView(t.buffer,t.byteOffset+e,a),o=new Array(a/4);for(let t=0;t<a/4;t++)o[t]=i.getUint32(4*t,!1).toString(16).padStart(8,"0");return A.fromString(o.join(""),16)},A.toString=function(t,e){return t.toString(e)},A.toLEBuff=function(t){const e=new Uint8Array(Math.floor((A.bitLength(t)-1)/8)+1);return A.toRprLE(e,0,t,e.byteLength),e},A.zero=A.e(0),A.one=A.e(1);let{toRprLE:b,toRprBE:y,fromRprLE:I,fromRprBE:C,toString:F,toLEBuff:x,zero:v,one:E,fromString:B,e:S,fromArray:G,bitLength:P,isNegative:O,isZero:U,shiftLeft:z,shiftRight:q,shl:Q,shr:M,isOdd:k,naf:R,bits:N,toNumber:T,toArray:D,add:K,sub:V,neg:j,mul:H,square:$,pow:Z,exp:Y,abs:J,div:W,mod:X,eq:tt,neq:et,lt:at,gt:it,leq:ot,geq:nt,band:rt,bor:ct,bxor:lt,land:st,lor:dt,lnot:ut}=A;var gt=Object.freeze({__proto__:null,toRprLE:b,toRprBE:y,fromRprLE:I,fromRprBE:C,toString:F,toLEBuff:x,zero:v,one:E,fromString:B,e:S,fromArray:G,bitLength:P,isNegative:O,isZero:U,shiftLeft:z,shiftRight:q,shl:Q,shr:M,isOdd:k,naf:R,bits:N,toNumber:T,toArray:D,add:K,sub:V,neg:j,mul:H,square:$,pow:Z,exp:Y,abs:J,div:W,mod:X,eq:tt,neq:et,lt:at,gt:it,leq:ot,geq:nt,band:rt,bor:ct,bxor:lt,land:st,lor:dt,lnot:ut});const ft=[];for(let t=0;t<256;t++)ft[t]=_t(t,8);function _t(t,e){let a=0,i=t;for(let t=0;t<e;t++)a<<=1,a|=1&i,i>>=1;return a}function pt(t,e,a){if(U(a))return t.one;const i=N(a);if(0==i.legth)return t.one;let o=e;for(let a=i.length-2;a>=0;a--)o=t.square(o),i[a]&&(o=t.mul(o,e));return o}function ht(t){if(t.m%2==1)if(tt(X(t.p,4),1))if(tt(X(t.p,8),1))if(tt(X(t.p,16),1))!function(t){t.sqrt_q=Z(t.p,t.m),t.sqrt_s=0,t.sqrt_t=V(t.sqrt_q,1);for(;!k(t.sqrt_t);)t.sqrt_s=t.sqrt_s+1,t.sqrt_t=W(t.sqrt_t,2);let e=t.one;for(;t.eq(e,t.one);){const a=t.random();t.sqrt_z=t.pow(a,t.sqrt_t),e=t.pow(t.sqrt_z,2**(t.sqrt_s-1))}t.sqrt_tm1d2=W(V(t.sqrt_t,1),2),t.sqrt=function(t){const e=this;if(e.isZero(t))return e.zero;let a=e.pow(t,e.sqrt_tm1d2);const i=e.pow(e.mul(e.square(a),t),2**(e.sqrt_s-1));if(e.eq(i,e.negone))return null;let o=e.sqrt_s,n=e.mul(t,a),r=e.mul(n,a),c=e.sqrt_z;for(;!e.eq(r,e.one);){let t=e.square(r),i=1;for(;!e.eq(t,e.one);)t=e.square(t),i++;a=c;for(let t=0;t<o-i-1;t++)a=e.square(a);c=e.square(a),r=e.mul(r,c),n=e.mul(n,a),o=i}return e.geq(n,e.zero)?n:e.neg(n)}}(t);else{if(!tt(X(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(!tt(X(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 tt(X(t.p,4),3)&&function(t){t.sqrt_q=Z(t.p,t.m),t.sqrt_e1=W(V(t.sqrt_q,3),4),t.sqrt=function(e){if(this.isZero(e))return this.zero;const a=this.pow(e,this.sqrt_e1),i=this.mul(this.square(a),e);if(this.eq(i,this.negone))return null;const o=this.mul(a,e);return t.geq(o,t.zero)?o:t.neg(o)}}(t);else{const e=X(Z(t.p,t.m/2),4);1==e?function(t){t.sqrt=function(){throw new Error("Sqrt alg 10 not implemented")}}(t):3==e?function(t){t.sqrt_q=Z(t.p,t.m/2),t.sqrt_e34=W(V(t.sqrt_q,3),4),t.sqrt_e12=W(V(t.sqrt_q,1),2),t.frobenius=function(e,a){return e%2==1?t.conjugate(a):a},t.sqrt=function(t){const e=this,a=e.pow(t,e.sqrt_e34),i=e.mul(e.square(a),t),o=e.mul(e.frobenius(1,i),i);if(e.eq(o,e.negone))return null;const n=e.mul(a,t);let r;if(e.eq(i,e.negone))r=e.mul(n,[e.F.zero,e.F.one]);else{const t=e.pow(e.add(e.one,i),e.sqrt_e12);r=e.mul(t,n)}return e.geq(r,e.zero)?r:e.neg(r)}}(t):function(t){t.sqrt=function(){throw new Error("Sqrt alg 8 not implemented")}}(t)}}function mt(t,e,a,i,o){t[e]=t[e]+t[a]>>>0,t[o]=(t[o]^t[e])>>>0,t[o]=(t[o]<<16|t[o]>>>16&65535)>>>0,t[i]=t[i]+t[o]>>>0,t[a]=(t[a]^t[i])>>>0,t[a]=(t[a]<<12|t[a]>>>20&4095)>>>0,t[e]=t[e]+t[a]>>>0,t[o]=(t[o]^t[e])>>>0,t[o]=(t[o]<<8|t[o]>>>24&255)>>>0,t[i]=t[i]+t[o]>>>0,t[a]=(t[a]^t[i])>>>0,t[a]=(t[a]<<7|t[a]>>>25&127)>>>0}class Lt{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 K(H(this.nextU32(),4294967296),this.nextU32())}nextBool(){return 1==(1&this.nextU32())}update(){for(let t=0;t<16;t++)this.buff[t]=this.state[t];for(let e=0;e<10;e++)mt(t=this.buff,0,4,8,12),mt(t,1,5,9,13),mt(t,2,6,10,14),mt(t,3,7,11,15),mt(t,0,5,10,15),mt(t,1,6,11,12),mt(t,2,7,8,13),mt(t,3,4,9,14);var t;for(let t=0;t<16;t++)this.buff[t]=this.buff[t]+this.state[t]>>>0;this.idx=0,this.state[12]=this.state[12]+1>>>0,0==this.state[12]&&(this.state[13]=this.state[13]+1>>>0,0==this.state[13]&&(this.state[14]=this.state[14]+1>>>0,0==this.state[14]&&(this.state[15]=this.state[15]+1>>>0)))}}var wt={};function At(t){let e=new Uint8Array(t);if(void 0!==globalThis.crypto)globalThis.crypto.getRandomValues(e);else for(let a=0;a<t;a++)e[a]=4294967296*Math.random()>>>0;return e}let bt=null;function yt(){return bt||(bt=new Lt(function(){const t=At(32),e=new Uint32Array(t.buffer),a=[];for(let t=0;t<8;t++)a.push(e[t]);return a}()),bt)}class It{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=P(this.p),this.mask=(this.one<<BigInt(this.bitLength))-this.one,this.n64=Math.floor((this.bitLength-1)/64)+1,this.n32=2*this.n64,this.n8=8*this.n64,this.R=this.e(this.one<<BigInt(64*this.n64)),this.Ri=this.inv(this.R);const e=this.negone>>this.one;this.nqr=this.two;let a=this.pow(this.nqr,e);for(;!this.eq(a,this.negone);)this.nqr=this.nqr+this.one,a=this.pow(this.nqr,e);for(this.s=0,this.t=this.negone;(this.t&this.one)==this.zero;)this.s=this.s+1,this.t=this.t>>this.one;this.nqr_to_t=this.pow(this.nqr,this.t),ht(this)}e(t,e){let a;if(e?16==e&&(a=BigInt("0x"+t)):a=BigInt(t),a<0){let t=-a;return t>=this.p&&(t%=this.p),this.p-t}return a>=this.p?a%this.p:a}add(t,e){const a=t+e;return a>=this.p?a-this.p:a}sub(t,e){return t>=e?t-e:this.p-e+t}neg(t){return t?this.p-t:t}mul(t,e){return t*e%this.p}mulScalar(t,e){return t*this.e(e)%this.p}square(t){return t*t%this.p}eq(t,e){return t==e}neq(t,e){return t!=e}lt(t,e){return(t>this.half?t-this.p:t)<(e>this.half?e-this.p:e)}gt(t,e){return(t>this.half?t-this.p:t)>(e>this.half?e-this.p:e)}leq(t,e){return(t>this.half?t-this.p:t)<=(e>this.half?e-this.p:e)}geq(t,e){return(t>this.half?t-this.p:t)>=(e>this.half?e-this.p:e)}div(t,e){return this.mul(t,this.inv(e))}idiv(t,e){if(!e)throw new Error("Division by zero");return t/e}inv(t){if(!t)throw new Error("Division by zero");let e=this.zero,a=this.p,i=this.one,o=t%this.p;for(;o;){let t=a/o;[e,i]=[i,e-t*i],[a,o]=[o,a-t*o]}return e<this.zero&&(e+=this.p),e}mod(t,e){return t%e}pow(t,e){return pt(this,t,e)}exp(t,e){return pt(this,t,e)}band(t,e){const a=t&e&this.mask;return a>=this.p?a-this.p:a}bor(t,e){const a=(t|e)&this.mask;return a>=this.p?a-this.p:a}bxor(t,e){const a=(t^e)&this.mask;return a>=this.p?a-this.p:a}bnot(t){const e=t^this.mask;return e>=this.p?e-this.p:e}shl(t,e){if(Number(e)<this.bitLength){const a=t<<e&this.mask;return a>=this.p?a-this.p:a}{const a=this.p-e;return Number(a)<this.bitLength?t>>a:this.zero}}shr(t,e){if(Number(e)<this.bitLength)return t>>e;{const a=this.p-e;if(Number(a)<this.bitLength){const e=t<<a&this.mask;return e>=this.p?e-this.p:e}return 0}}land(t,e){return t&&e?this.one:this.zero}lor(t,e){return t||e?this.one:this.zero}lnot(t){return t?this.zero:this.one}sqrt_old(t){if(t==this.zero)return this.zero;if(this.pow(t,this.negone>>this.one)!=this.one)return null;let e=this.s,a=this.nqr_to_t,i=this.pow(t,this.t),o=this.pow(t,this.add(this.t,this.one)>>this.one);for(;i!=this.one;){let t=this.square(i),n=1;for(;t!=this.one;)n++,t=this.square(t);let r=a;for(let t=0;t<e-n-1;t++)r=this.square(r);e=n,a=this.square(r),i=this.mul(i,a),o=this.mul(o,r)}return o>this.p>>this.one&&(o=this.neg(o)),o}normalize(t,e){if((t=BigInt(t,e))<0){let e=-t;return e>=this.p&&(e%=this.p),this.p-e}return t>=this.p?t%this.p:t}random(){const t=2*this.bitLength/8;let e=this.zero;for(let a=0;a<t;a++)e=(e<<BigInt(8))+BigInt(At(1)[0]);return e%this.p}toString(t,e){let a;if(t>this.half){a="-"+(this.p-t).toString(e)}else a=t.toString(e);return a}isZero(t){return t==this.zero}fromRng(t){let e;do{e=this.zero;for(let a=0;a<this.n64;a++)e+=t.nextU64()<<BigInt(64*a);e&=this.mask}while(e>=this.p);return e=e*this.Ri%this.p,e}}class Ct{constructor(t){this.type="F1",this.one=u.one,this.zero=u.zero,this.p=u(t),this.m=1,this.negone=this.p.minus(u.one),this.two=u(2),this.half=this.p.shiftRight(1),this.bitLength=this.p.bitLength(),this.mask=u.one.shiftLeft(this.bitLength).minus(u.one),this.n64=Math.floor((this.bitLength-1)/64)+1,this.n32=2*this.n64,this.n8=8*this.n64,this.R=u.one.shiftLeft(64*this.n64),this.Ri=this.inv(this.R);const e=this.negone.shiftRight(this.one);this.nqr=this.two;let a=this.pow(this.nqr,e);for(;!a.equals(this.negone);)this.nqr=this.nqr.add(this.one),a=this.pow(this.nqr,e);for(this.s=this.zero,this.t=this.negone;!this.t.isOdd();)this.s=this.s.add(this.one),this.t=this.t.shiftRight(this.one);this.nqr_to_t=this.pow(this.nqr,this.t),ht(this)}e(t,e){const a=u(t,e);return this.normalize(a)}add(t,e){let a=t.add(e);return a.geq(this.p)&&(a=a.minus(this.p)),a}sub(t,e){return t.geq(e)?t.minus(e):this.p.minus(e.minus(t))}neg(t){return t.isZero()?t:this.p.minus(t)}mul(t,e){return t.times(e).mod(this.p)}mulScalar(t,e){return t.times(u(e)).mod(this.p)}square(t){return t.square().mod(this.p)}eq(t,e){return t.eq(e)}neq(t,e){return t.neq(e)}lt(t,e){const a=t.gt(this.half)?t.minus(this.p):t,i=e.gt(this.half)?e.minus(this.p):e;return a.lt(i)}gt(t,e){const a=t.gt(this.half)?t.minus(this.p):t,i=e.gt(this.half)?e.minus(this.p):e;return a.gt(i)}leq(t,e){const a=t.gt(this.half)?t.minus(this.p):t,i=e.gt(this.half)?e.minus(this.p):e;return a.leq(i)}geq(t,e){const a=t.gt(this.half)?t.minus(this.p):t,i=e.gt(this.half)?e.minus(this.p):e;return a.geq(i)}div(t,e){if(e.isZero())throw new Error("Division by zero");return t.times(e.modInv(this.p)).mod(this.p)}idiv(t,e){if(e.isZero())throw new Error("Division by zero");return t.divide(e)}inv(t){if(t.isZero())throw new Error("Division by zero");return t.modInv(this.p)}mod(t,e){return t.mod(e)}pow(t,e){return t.modPow(e,this.p)}exp(t,e){return t.modPow(e,this.p)}band(t,e){return t.and(e).and(this.mask).mod(this.p)}bor(t,e){return t.or(e).and(this.mask).mod(this.p)}bxor(t,e){return t.xor(e).and(this.mask).mod(this.p)}bnot(t){return t.xor(this.mask).mod(this.p)}shl(t,e){if(e.lt(this.bitLength))return t.shiftLeft(e).and(this.mask).mod(this.p);{const a=this.p.minus(e);return a.lt(this.bitLength)?this.shr(t,a):u.zero}}shr(t,e){if(e.lt(this.bitLength))return t.shiftRight(e);{const a=this.p.minus(e);return a.lt(this.bitLength)?this.shl(t,a):u.zero}}land(t,e){return t.isZero()||e.isZero()?u.zero:u.one}lor(t,e){return t.isZero()&&e.isZero()?u.zero:u.one}lnot(t){return t.isZero()?u.one:u.zero}sqrt_old(t){if(t.equals(this.zero))return this.zero;if(!this.pow(t,this.negone.shiftRight(this.one)).equals(this.one))return null;let e=parseInt(this.s),a=this.nqr_to_t,i=this.pow(t,this.t),o=this.pow(t,this.add(this.t,this.one).shiftRight(this.one));for(;!i.equals(this.one);){let t=this.square(i),n=1;for(;!t.equals(this.one);)n++,t=this.square(t);let r=a;for(let t=0;t<e-n-1;t++)r=this.square(r);e=n,a=this.square(r),i=this.mul(i,a),o=this.mul(o,r)}return o.greater(this.p.shiftRight(this.one))&&(o=this.neg(o)),o}normalize(t){return(t=u(t)).isNegative()?this.p.minus(t.abs().mod(this.p)):t.mod(this.p)}random(){let t=u(0),e=u(this.p.square());for(;!e.isZero();)t=t.shiftLeft(8).add(u(At(1)[0])),e=e.shiftRight(8);return t.mod(this.p)}toString(t,e){let a;if(t.lesserOrEquals(this.p.shiftRight(u(1))))a=t.toString(e);else{a="-"+this.p.minus(t).toString(e)}return a}isZero(t){return t.isZero()}fromRng(t){let e;do{e=u(0);for(let a=0;a<this.n64;a++)e=e.add(e,t.nextU64().shiftLeft(64*a));e=e.and(this.mask)}while(e.geq(this.p));return e=e.times(this.Ri).mod(this.q),e}}const Ft="function"==typeof BigInt;let xt;xt=Ft?It:Ct;class vt extends xt{toRprLE(t,e,a){b(t,e,a,8*this.n64)}toRprBE(t,e,a){y(t,e,a,8*this.n64)}toRprBEM(t,e,a){return this.toRprBE(t,e,this.mul(this.R,a))}toRprLEM(t,e,a){return this.toRprLE(t,e,this.mul(this.R,a))}fromRprLE(t,e){return I(t,e,this.n8)}fromRprBE(t,e){return C(t,e,this.n8)}fromRprLEM(t,e){return this.mul(this.fromRprLE(t,e),this.Ri)}fromRprBEM(t,e){return this.mul(this.fromRprBE(t,e),this.Ri)}}var Et=function(t,e){const a=Array(e);let i=u(t);for(let t=0;t<e;t++)a[t]=i.and(255).toJSNumber(),i=i.shiftRight(8);return a},Bt=function(t,e,a){const i=a||"int";if(t.modules[i])return i;t.modules[i]={};const o=2*e,n=8*e;return t.alloc(n,Et(1,n)),function(){const a=t.addFunction(i+"_copy");a.addParam("px","i32"),a.addParam("pr","i32");const o=a.getCodeBuilder();for(let t=0;t<e;t++)a.addCode(o.i64_store(o.getLocal("pr"),8*t,o.i64_load(o.getLocal("px"),8*t)))}(),function(){const a=t.addFunction(i+"_zero");a.addParam("pr","i32");const o=a.getCodeBuilder();for(let t=0;t<e;t++)a.addCode(o.i64_store(o.getLocal("pr"),8*t,o.i64_const(0)))}(),function(){const a=t.addFunction(i+"_isZero");a.addParam("px","i32"),a.setReturnType("i32");const o=a.getCodeBuilder();a.addCode(function t(e){return 0==e?o.ret(o.i64_eqz(o.i64_load(o.getLocal("px")))):o.if(o.i64_eqz(o.i64_load(o.getLocal("px"),8*e)),t(e-1),o.ret(o.i32_const(0)))}(e-1)),a.addCode(o.ret(o.i32_const(0)))}(),function(){const a=t.addFunction(i+"_one");a.addParam("pr","i32");const o=a.getCodeBuilder();a.addCode(o.i64_store(o.getLocal("pr"),0,o.i64_const(1)));for(let t=1;t<e;t++)a.addCode(o.i64_store(o.getLocal("pr"),8*t,o.i64_const(0)))}(),function(){const a=t.addFunction(i+"_eq");a.addParam("px","i32"),a.addParam("py","i32"),a.setReturnType("i32");const o=a.getCodeBuilder();a.addCode(function t(e){return 0==e?o.ret(o.i64_eq(o.i64_load(o.getLocal("px")),o.i64_load(o.getLocal("py")))):o.if(o.i64_eq(o.i64_load(o.getLocal("px"),8*e),o.i64_load(o.getLocal("py"),8*e)),t(e-1),o.ret(o.i32_const(0)))}(e-1)),a.addCode(o.ret(o.i32_const(0)))}(),function(){const a=t.addFunction(i+"_gte");a.addParam("px","i32"),a.addParam("py","i32"),a.setReturnType("i32");const o=a.getCodeBuilder();a.addCode(function t(e){return 0==e?o.ret(o.i64_ge_u(o.i64_load(o.getLocal("px")),o.i64_load(o.getLocal("py")))):o.if(o.i64_lt_u(o.i64_load(o.getLocal("px"),8*e),o.i64_load(o.getLocal("py"),8*e)),o.ret(o.i32_const(0)),o.if(o.i64_gt_u(o.i64_load(o.getLocal("px"),8*e),o.i64_load(o.getLocal("py"),8*e)),o.ret(o.i32_const(1)),t(e-1)))}(e-1)),a.addCode(o.ret(o.i32_const(0)))}(),function(){const e=t.addFunction(i+"_add");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32"),e.setReturnType("i32"),e.addLocal("c","i64");const a=e.getCodeBuilder();e.addCode(a.setLocal("c",a.i64_add(a.i64_load32_u(a.getLocal("x")),a.i64_load32_u(a.getLocal("y"))))),e.addCode(a.i64_store32(a.getLocal("r"),a.getLocal("c")));for(let t=1;t<o;t++)e.addCode(a.setLocal("c",a.i64_add(a.i64_add(a.i64_load32_u(a.getLocal("x"),4*t),a.i64_load32_u(a.getLocal("y"),4*t)),a.i64_shr_u(a.getLocal("c"),a.i64_const(32))))),e.addCode(a.i64_store32(a.getLocal("r"),4*t,a.getLocal("c")));e.addCode(a.i32_wrap_i64(a.i64_shr_u(a.getLocal("c"),a.i64_const(32))))}(),function(){const e=t.addFunction(i+"_sub");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32"),e.setReturnType("i32"),e.addLocal("c","i64");const a=e.getCodeBuilder();e.addCode(a.setLocal("c",a.i64_sub(a.i64_load32_u(a.getLocal("x")),a.i64_load32_u(a.getLocal("y"))))),e.addCode(a.i64_store32(a.getLocal("r"),a.i64_and(a.getLocal("c"),a.i64_const("0xFFFFFFFF"))));for(let t=1;t<o;t++)e.addCode(a.setLocal("c",a.i64_add(a.i64_sub(a.i64_load32_u(a.getLocal("x"),4*t),a.i64_load32_u(a.getLocal("y"),4*t)),a.i64_shr_s(a.getLocal("c"),a.i64_const(32))))),e.addCode(a.i64_store32(a.getLocal("r"),4*t,a.i64_and(a.getLocal("c"),a.i64_const("0xFFFFFFFF"))));e.addCode(a.i32_wrap_i64(a.i64_shr_s(a.getLocal("c"),a.i64_const(32))))}(),function(){const e=t.addFunction(i+"_mul");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32"),e.addLocal("c0","i64"),e.addLocal("c1","i64");for(let t=0;t<o;t++)e.addLocal("x"+t,"i64"),e.addLocal("y"+t,"i64");const a=e.getCodeBuilder(),n=[],r=[];function c(t,e){let i,o;return n[t]?i=a.getLocal("x"+t):(i=a.teeLocal("x"+t,a.i64_load32_u(a.getLocal("x"),4*t)),n[t]=!0),r[e]?o=a.getLocal("y"+e):(o=a.teeLocal("y"+e,a.i64_load32_u(a.getLocal("y"),4*e)),r[e]=!0),a.i64_mul(i,o)}let l="c0",s="c1";for(let t=0;t<2*o-1;t++){for(let i=Math.max(0,t-o+1);i<=t&&i<o;i++){const o=t-i;e.addCode(a.setLocal(l,a.i64_add(a.i64_and(a.getLocal(l),a.i64_const(4294967295)),c(i,o)))),e.addCode(a.setLocal(s,a.i64_add(a.getLocal(s),a.i64_shr_u(a.getLocal(l),a.i64_const(32)))))}e.addCode(a.i64_store32(a.getLocal("r"),4*t,a.getLocal(l))),[l,s]=[s,l],e.addCode(a.setLocal(s,a.i64_shr_u(a.getLocal(l),a.i64_const(32))))}e.addCode(a.i64_store32(a.getLocal("r"),4*o*2-4,a.getLocal(l)))}(),function(){const e=t.addFunction(i+"_square");e.addParam("x","i32"),e.addParam("r","i32"),e.addLocal("c0","i64"),e.addLocal("c1","i64"),e.addLocal("c0_old","i64"),e.addLocal("c1_old","i64");for(let t=0;t<o;t++)e.addLocal("x"+t,"i64");const a=e.getCodeBuilder(),n=[];function r(t,e){let i,o;return n[t]?i=a.getLocal("x"+t):(i=a.teeLocal("x"+t,a.i64_load32_u(a.getLocal("x"),4*t)),n[t]=!0),n[e]?o=a.getLocal("x"+e):(o=a.teeLocal("x"+e,a.i64_load32_u(a.getLocal("x"),4*e)),n[e]=!0),a.i64_mul(i,o)}let c="c0",l="c1",s="c0_old",d="c1_old";for(let t=0;t<2*o-1;t++){e.addCode(a.setLocal(c,a.i64_const(0)),a.setLocal(l,a.i64_const(0)));for(let i=Math.max(0,t-o+1);i<t+1>>1&&i<o;i++){const o=t-i;e.addCode(a.setLocal(c,a.i64_add(a.i64_and(a.getLocal(c),a.i64_const(4294967295)),r(i,o)))),e.addCode(a.setLocal(l,a.i64_add(a.getLocal(l),a.i64_shr_u(a.getLocal(c),a.i64_const(32)))))}e.addCode(a.setLocal(c,a.i64_shl(a.i64_and(a.getLocal(c),a.i64_const(4294967295)),a.i64_const(1)))),e.addCode(a.setLocal(l,a.i64_add(a.i64_shl(a.getLocal(l),a.i64_const(1)),a.i64_shr_u(a.getLocal(c),a.i64_const(32))))),t%2==0&&(e.addCode(a.setLocal(c,a.i64_add(a.i64_and(a.getLocal(c),a.i64_const(4294967295)),r(t>>1,t>>1)))),e.addCode(a.setLocal(l,a.i64_add(a.getLocal(l),a.i64_shr_u(a.getLocal(c),a.i64_const(32)))))),t>0&&(e.addCode(a.setLocal(c,a.i64_add(a.i64_and(a.getLocal(c),a.i64_const(4294967295)),a.i64_and(a.getLocal(s),a.i64_const(4294967295))))),e.addCode(a.setLocal(l,a.i64_add(a.i64_add(a.getLocal(l),a.i64_shr_u(a.getLocal(c),a.i64_const(32))),a.getLocal(d))))),e.addCode(a.i64_store32(a.getLocal("r"),4*t,a.getLocal(c))),e.addCode(a.setLocal(s,a.getLocal(l)),a.setLocal(d,a.i64_shr_u(a.getLocal(s),a.i64_const(32))))}e.addCode(a.i64_store32(a.getLocal("r"),4*o*2-4,a.getLocal(s)))}(),function(){const e=t.addFunction(i+"_squareOld");e.addParam("x","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.call(i+"_mul",a.getLocal("x"),a.getLocal("x"),a.getLocal("r")))}(),function(){!function(){const e=t.addFunction(i+"__mul1");e.addParam("px","i32"),e.addParam("y","i64"),e.addParam("pr","i32"),e.addLocal("c","i64");const a=e.getCodeBuilder();e.addCode(a.setLocal("c",a.i64_mul(a.i64_load32_u(a.getLocal("px"),0,0),a.getLocal("y")))),e.addCode(a.i64_store32(a.getLocal("pr"),0,0,a.getLocal("c")));for(let t=1;t<o;t++)e.addCode(a.setLocal("c",a.i64_add(a.i64_mul(a.i64_load32_u(a.getLocal("px"),4*t,0),a.getLocal("y")),a.i64_shr_u(a.getLocal("c"),a.i64_const(32))))),e.addCode(a.i64_store32(a.getLocal("pr"),4*t,0,a.getLocal("c")))}(),function(){const e=t.addFunction(i+"__add1");e.addParam("x","i32"),e.addParam("y","i64"),e.addLocal("c","i64"),e.addLocal("px","i32");const a=e.getCodeBuilder();e.addCode(a.setLocal("px",a.getLocal("x"))),e.addCode(a.setLocal("c",a.i64_add(a.i64_load32_u(a.getLocal("px"),0,0),a.getLocal("y")))),e.addCode(a.i64_store32(a.getLocal("px"),0,0,a.getLocal("c"))),e.addCode(a.setLocal("c",a.i64_shr_u(a.getLocal("c"),a.i64_const(32)))),e.addCode(a.block(a.loop(a.br_if(1,a.i64_eqz(a.getLocal("c"))),a.setLocal("px",a.i32_add(a.getLocal("px"),a.i32_const(4))),a.setLocal("c",a.i64_add(a.i64_load32_u(a.getLocal("px"),0,0),a.getLocal("c"))),a.i64_store32(a.getLocal("px"),0,0,a.getLocal("c")),a.setLocal("c",a.i64_shr_u(a.getLocal("c"),a.i64_const(32))),a.br(0))))}();const e=t.addFunction(i+"_div");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("c","i32"),e.addParam("r","i32"),e.addLocal("rr","i32"),e.addLocal("cc","i32"),e.addLocal("eX","i32"),e.addLocal("eY","i32"),e.addLocal("sy","i64"),e.addLocal("sx","i64"),e.addLocal("ec","i32");const a=e.getCodeBuilder(),r=a.i32_const(t.alloc(n)),c=a.i32_const(t.alloc(n)),l=a.i32_const(t.alloc(n)),s=a.getLocal("cc"),d=a.getLocal("rr"),u=t.alloc(2*n),g=a.i32_const(u),f=a.i32_const(u+n);e.addCode(a.if(a.getLocal("c"),a.setLocal("cc",a.getLocal("c")),a.setLocal("cc",c))),e.addCode(a.if(a.getLocal("r"),a.setLocal("rr",a.getLocal("r")),a.setLocal("rr",l))),e.addCode(a.call(i+"_copy",a.getLocal("x"),d)),e.addCode(a.call(i+"_copy",a.getLocal("y"),r)),e.addCode(a.call(i+"_zero",s)),e.addCode(a.call(i+"_zero",g)),e.addCode(a.setLocal("eX",a.i32_const(n-1))),e.addCode(a.setLocal("eY",a.i32_const(n-1))),e.addCode(a.block(a.loop(a.br_if(1,a.i32_or(a.i32_load8_u(a.i32_add(r,a.getLocal("eY")),0,0),a.i32_eq(a.getLocal("eY"),a.i32_const(3)))),a.setLocal("eY",a.i32_sub(a.getLocal("eY"),a.i32_const(1))),a.br(0)))),e.addCode(a.setLocal("sy",a.i64_add(a.i64_load32_u(a.i32_sub(a.i32_add(r,a.getLocal("eY")),a.i32_const(3)),0,0),a.i64_const(1)))),e.addCode(a.if(a.i64_eq(a.getLocal("sy"),a.i64_const(1)),a.drop(a.i64_div_u(a.i64_const(0),a.i64_const(0))))),e.addCode(a.block(a.loop(a.block(a.loop(a.br_if(1,a.i32_or(a.i32_load8_u(a.i32_add(d,a.getLocal("eX")),0,0),a.i32_eq(a.getLocal("eX"),a.i32_const(7)))),a.setLocal("eX",a.i32_sub(a.getLocal("eX"),a.i32_const(1))),a.br(0))),a.setLocal("sx",a.i64_load(a.i32_sub(a.i32_add(d,a.getLocal("eX")),a.i32_const(7)),0,0)),a.setLocal("sx",a.i64_div_u(a.getLocal("sx"),a.getLocal("sy"))),a.setLocal("ec",a.i32_sub(a.i32_sub(a.getLocal("eX"),a.getLocal("eY")),a.i32_const(4))),a.block(a.loop(a.br_if(1,a.i32_and(a.i64_eqz(a.i64_and(a.getLocal("sx"),a.i64_const("0xFFFFFFFF00000000"))),a.i32_ge_s(a.getLocal("ec"),a.i32_const(0)))),a.setLocal("sx",a.i64_shr_u(a.getLocal("sx"),a.i64_const(8))),a.setLocal("ec",a.i32_add(a.getLocal("ec"),a.i32_const(1))),a.br(0))),a.if(a.i64_eqz(a.getLocal("sx")),[...a.br_if(2,a.i32_eqz(a.call(i+"_gte",d,r))),...a.setLocal("sx",a.i64_const(1)),...a.setLocal("ec",a.i32_const(0))]),a.call(i+"__mul1",r,a.getLocal("sx"),f),a.drop(a.call(i+"_sub",d,a.i32_sub(f,a.getLocal("ec")),d)),a.call(i+"__add1",a.i32_add(s,a.getLocal("ec")),a.getLocal("sx")),a.br(0))))}(),function(){const e=t.addFunction(i+"_inverseMod");e.addParam("px","i32"),e.addParam("pm","i32"),e.addParam("pr","i32"),e.addLocal("t","i32"),e.addLocal("newt","i32"),e.addLocal("r","i32"),e.addLocal("qq","i32"),e.addLocal("qr","i32"),e.addLocal("newr","i32"),e.addLocal("swp","i32"),e.addLocal("x","i32"),e.addLocal("signt","i32"),e.addLocal("signnewt","i32"),e.addLocal("signx","i32");const a=e.getCodeBuilder(),o=a.i32_const(t.alloc(n)),r=a.i32_const(t.alloc(n)),c=a.i32_const(t.alloc(n)),l=a.i32_const(t.alloc(n)),s=a.i32_const(t.alloc(n)),d=a.i32_const(t.alloc(n)),u=a.i32_const(t.alloc(2*n)),g=a.i32_const(t.alloc(n));e.addCode(a.setLocal("t",o),a.call(i+"_zero",o),a.setLocal("signt",a.i32_const(0))),e.addCode(a.setLocal("r",r),a.call(i+"_copy",a.getLocal("pm"),r)),e.addCode(a.setLocal("newt",c),a.call(i+"_one",c),a.setLocal("signnewt",a.i32_const(0))),e.addCode(a.setLocal("newr",l),a.call(i+"_copy",a.getLocal("px"),l)),e.addCode(a.setLocal("qq",s)),e.addCode(a.setLocal("qr",d)),e.addCode(a.setLocal("x",g)),e.addCode(a.block(a.loop(a.br_if(1,a.call(i+"_isZero",a.getLocal("newr"))),a.call(i+"_div",a.getLocal("r"),a.getLocal("newr"),a.getLocal("qq"),a.getLocal("qr")),a.call(i+"_mul",a.getLocal("qq"),a.getLocal("newt"),u),a.if(a.getLocal("signt"),a.if(a.getLocal("signnewt"),a.if(a.call(i+"_gte",u,a.getLocal("t")),[...a.drop(a.call(i+"_sub",u,a.getLocal("t"),a.getLocal("x"))),...a.setLocal("signx",a.i32_const(0))],[...a.drop(a.call(i+"_sub",a.getLocal("t"),u,a.getLocal("x"))),...a.setLocal("signx",a.i32_const(1))]),[...a.drop(a.call(i+"_add",u,a.getLocal("t"),a.getLocal("x"))),...a.setLocal("signx",a.i32_const(1))]),a.if(a.getLocal("signnewt"),[...a.drop(a.call(i+"_add",u,a.getLocal("t"),a.getLocal("x"))),...a.setLocal("signx",a.i32_const(0))],a.if(a.call(i+"_gte",a.getLocal("t"),u),[...a.drop(a.call(i+"_sub",a.getLocal("t"),u,a.getLocal("x"))),...a.setLocal("signx",a.i32_const(0))],[...a.drop(a.call(i+"_sub",u,a.getLocal("t"),a.getLocal("x"))),...a.setLocal("signx",a.i32_const(1))]))),a.setLocal("swp",a.getLocal("t")),a.setLocal("t",a.getLocal("newt")),a.setLocal("newt",a.getLocal("x")),a.setLocal("x",a.getLocal("swp")),a.setLocal("signt",a.getLocal("signnewt")),a.setLocal("signnewt",a.getLocal("signx")),a.setLocal("swp",a.getLocal("r")),a.setLocal("r",a.getLocal("newr")),a.setLocal("newr",a.getLocal("qr")),a.setLocal("qr",a.getLocal("swp")),a.br(0)))),e.addCode(a.if(a.getLocal("signt"),a.drop(a.call(i+"_sub",a.getLocal("pm"),a.getLocal("t"),a.getLocal("pr"))),a.call(i+"_copy",a.getLocal("t"),a.getLocal("pr"))))}(),t.exportFunction(i+"_copy"),t.exportFunction(i+"_zero"),t.exportFunction(i+"_one"),t.exportFunction(i+"_isZero"),t.exportFunction(i+"_eq"),t.exportFunction(i+"_gte"),t.exportFunction(i+"_add"),t.exportFunction(i+"_sub"),t.exportFunction(i+"_mul"),t.exportFunction(i+"_square"),t.exportFunction(i+"_squareOld"),t.exportFunction(i+"_div"),t.exportFunction(i+"_inverseMod"),i},St=function(t,e,a,i,o,n,r){const c=t.addFunction(e);c.addParam("base","i32"),c.addParam("scalar","i32"),c.addParam("scalarLength","i32"),c.addParam("r","i32"),c.addLocal("i","i32"),c.addLocal("b","i32");const l=c.getCodeBuilder(),s=l.i32_const(t.alloc(a));c.addCode(l.if(l.i32_eqz(l.getLocal("scalarLength")),[...l.call(r,l.getLocal("r")),...l.ret([])])),c.addCode(l.call(n,l.getLocal("base"),s)),c.addCode(l.call(r,l.getLocal("r"))),c.addCode(l.setLocal("i",l.getLocal("scalarLength"))),c.addCode(l.block(l.loop(l.setLocal("i",l.i32_sub(l.getLocal("i"),l.i32_const(1))),l.setLocal("b",l.i32_load8_u(l.i32_add(l.getLocal("scalar"),l.getLocal("i")))),...function(){const t=[];for(let e=0;e<8;e++)t.push(...l.call(o,l.getLocal("r"),l.getLocal("r")),...l.if(l.i32_ge_u(l.getLocal("b"),l.i32_const(128>>e)),[...l.setLocal("b",l.i32_sub(l.getLocal("b"),l.i32_const(128>>e))),...l.call(i,l.getLocal("r"),s,l.getLocal("r"))]));return t}(),l.br_if(1,l.i32_eqz(l.getLocal("i"))),l.br(0))))},Gt=function(t,e){const a=8*t.modules[e].n64,i=t.addFunction(e+"_batchInverse");i.addParam("pIn","i32"),i.addParam("inStep","i32"),i.addParam("n","i32"),i.addParam("pOut","i32"),i.addParam("outStep","i32"),i.addLocal("itAux","i32"),i.addLocal("itIn","i32"),i.addLocal("itOut","i32"),i.addLocal("i","i32");const o=i.getCodeBuilder(),n=o.i32_const(t.alloc(a));i.addCode(o.setLocal("itAux",o.i32_load(o.i32_const(0))),o.i32_store(o.i32_const(0),o.i32_add(o.getLocal("itAux"),o.i32_mul(o.i32_add(o.getLocal("n"),o.i32_const(1)),o.i32_const(a))))),i.addCode(o.call(e+"_one",o.getLocal("itAux")),o.setLocal("itIn",o.getLocal("pIn")),o.setLocal("itAux",o.i32_add(o.getLocal("itAux"),o.i32_const(a))),o.setLocal("i",o.i32_const(0)),o.block(o.loop(o.br_if(1,o.i32_eq(o.getLocal("i"),o.getLocal("n"))),o.if(o.call(e+"_isZero",o.getLocal("itIn")),o.call(e+"_copy",o.i32_sub(o.getLocal("itAux"),o.i32_const(a)),o.getLocal("itAux")),o.call(e+"_mul",o.getLocal("itIn"),o.i32_sub(o.getLocal("itAux"),o.i32_const(a)),o.getLocal("itAux"))),o.setLocal("itIn",o.i32_add(o.getLocal("itIn"),o.getLocal("inStep"))),o.setLocal("itAux",o.i32_add(o.getLocal("itAux"),o.i32_const(a))),o.setLocal("i",o.i32_add(o.getLocal("i"),o.i32_const(1))),o.br(0))),o.setLocal("itIn",o.i32_sub(o.getLocal("itIn"),o.getLocal("inStep"))),o.setLocal("itAux",o.i32_sub(o.getLocal("itAux"),o.i32_const(a))),o.setLocal("itOut",o.i32_add(o.getLocal("pOut"),o.i32_mul(o.i32_sub(o.getLocal("n"),o.i32_const(1)),o.getLocal("outStep")))),o.call(e+"_inverse",o.getLocal("itAux"),o.getLocal("itAux")),o.block(o.loop(o.br_if(1,o.i32_eqz(o.getLocal("i"))),o.if(o.call(e+"_isZero",o.getLocal("itIn")),[...o.call(e+"_copy",o.getLocal("itAux"),o.i32_sub(o.getLocal("itAux"),o.i32_const(a))),...o.call(e+"_zero",o.getLocal("itOut"))],[...o.call(e+"_copy",o.i32_sub(o.getLocal("itAux"),o.i32_const(a)),n),...o.call(e+"_mul",o.getLocal("itAux"),o.getLocal("itIn"),o.i32_sub(o.getLocal("itAux"),o.i32_const(a))),...o.call(e+"_mul",o.getLocal("itAux"),n,o.getLocal("itOut"))]),o.setLocal("itIn",o.i32_sub(o.getLocal("itIn"),o.getLocal("inStep"))),o.setLocal("itOut",o.i32_sub(o.getLocal("itOut"),o.getLocal("outStep"))),o.setLocal("itAux",o.i32_sub(o.getLocal("itAux"),o.i32_const(a))),o.setLocal("i",o.i32_sub(o.getLocal("i"),o.i32_const(1))),o.br(0)))),i.addCode(o.i32_store(o.i32_const(0),o.getLocal("itAux")))};var Pt=function(t,e,a,i,o,n){void 0===n&&(n=i<o);const r=t.addFunction(e);r.addParam("pIn","i32"),r.addParam("n","i32"),r.addParam("pOut","i32"),r.addLocal("i","i32"),r.addLocal("itIn","i32"),r.addLocal("itOut","i32");const c=r.getCodeBuilder();n?r.addCode(c.setLocal("itIn",c.i32_add(c.getLocal("pIn"),c.i32_mul(c.i32_sub(c.getLocal("n"),c.i32_const(1)),c.i32_const(i)))),c.setLocal("itOut",c.i32_add(c.getLocal("pOut"),c.i32_mul(c.i32_sub(c.getLocal("n"),c.i32_const(1)),c.i32_const(o)))),c.setLocal("i",c.i32_const(0)),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("i"),c.getLocal("n"))),c.call(a,c.getLocal("itIn"),c.getLocal("itOut")),c.setLocal("itIn",c.i32_sub(c.getLocal("itIn"),c.i32_const(i))),c.setLocal("itOut",c.i32_sub(c.getLocal("itOut"),c.i32_const(o))),c.setLocal("i",c.i32_add(c.getLocal("i"),c.i32_const(1))),c.br(0)))):r.addCode(c.setLocal("itIn",c.getLocal("pIn")),c.setLocal("itOut",c.getLocal("pOut")),c.setLocal("i",c.i32_const(0)),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("i"),c.getLocal("n"))),c.call(a,c.getLocal("itIn"),c.getLocal("itOut")),c.setLocal("itIn",c.i32_add(c.getLocal("itIn"),c.i32_const(i))),c.setLocal("itOut",c.i32_add(c.getLocal("itOut"),c.i32_const(o))),c.setLocal("i",c.i32_add(c.getLocal("i"),c.i32_const(1))),c.br(0))))};var Ot=function(t,e,a,i,o,n){void 0===n&&(n=i<o);const r=t.addFunction(e);r.addParam("pIn1","i32"),r.addParam("pIn2","i32"),r.addParam("n","i32"),r.addParam("pOut","i32"),r.addLocal("i","i32"),r.addLocal("itIn1","i32"),r.addLocal("itIn2","i32"),r.addLocal("itOut","i32");const c=r.getCodeBuilder();n?r.addCode(c.setLocal("itIn1",c.i32_add(c.getLocal("pIn1"),c.i32_mul(c.i32_sub(c.getLocal("n"),c.i32_const(1)),c.i32_const(i)))),c.setLocal("itIn2",c.i32_add(c.getLocal("pIn2"),c.i32_mul(c.i32_sub(c.getLocal("n"),c.i32_const(1)),c.i32_const(i)))),c.setLocal("itOut",c.i32_add(c.getLocal("pOut"),c.i32_mul(c.i32_sub(c.getLocal("n"),c.i32_const(1)),c.i32_const(o)))),c.setLocal("i",c.i32_const(0)),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("i"),c.getLocal("n"))),c.call(a,c.getLocal("itIn1"),c.getLocal("itIn2"),c.getLocal("itOut")),c.setLocal("itIn1",c.i32_sub(c.getLocal("itIn1"),c.i32_const(i))),c.setLocal("itIn2",c.i32_sub(c.getLocal("itIn2"),c.i32_const(i))),c.setLocal("itOut",c.i32_sub(c.getLocal("itOut"),c.i32_const(o))),c.setLocal("i",c.i32_add(c.getLocal("i"),c.i32_const(1))),c.br(0)))):r.addCode(c.setLocal("itIn1",c.getLocal("pIn1")),c.setLocal("itIn2",c.getLocal("pIn2")),c.setLocal("itOut",c.getLocal("pOut")),c.setLocal("i",c.i32_const(0)),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("i"),c.getLocal("n"))),c.call(a,c.getLocal("itIn1"),c.getLocal("itIn2"),c.getLocal("itOut")),c.setLocal("itIn1",c.i32_add(c.getLocal("itIn1"),c.i32_const(i))),c.setLocal("itIn2",c.i32_add(c.getLocal("itIn2"),c.i32_const(i))),c.setLocal("itOut",c.i32_add(c.getLocal("itOut"),c.i32_const(o))),c.setLocal("i",c.i32_add(c.getLocal("i"),c.i32_const(1))),c.br(0))))};var Ut=function(t,e,a,i){const o=u(e),n=Math.floor((o.minus(1).bitLength()-1)/64)+1,r=2*n,c=8*n,l=a||"f1m";if(t.modules[l])return l;const s=Bt(t,n,i),d=t.alloc(c,Et(o,c));t.alloc(Et(u.one.shiftLeft(64*n).mod(o),c));const g=t.alloc(Et(u.one.shiftLeft(64*n).square().mod(o),c)),f=t.alloc(Et(u.one.shiftLeft(64*n).mod(o),c)),_=t.alloc(Et(u.zero,c)),p=o.minus(u.one),h=p.shiftRight(1),m=t.alloc(c,Et(h,c)),L=h.add(u.one),w=t.alloc(c,Et(L,c));t.modules[l]={pq:d,pR2:g,n64:n,q:o,pOne:f,pZero:_,pePlusOne:w};let A=u(2);if(o.isPrime())for(;!A.modPow(h,o).equals(p);)A=A.add(u.one);t.alloc(Et(A.shiftLeft(64*n).mod(o),c));let b=0,y=p;for(;!y.isOdd()&&!y.isZero();)b++,y=y.shiftRight(1);const I=t.alloc(c,Et(y,c)),C=A.modPow(y,o),F=t.alloc(Et(C.shiftLeft(64*n).mod(o),c)),x=y.add(1).shiftRight(1),v=t.alloc(c,Et(x,c));return t.exportFunction(s+"_copy",l+"_copy"),t.exportFunction(s+"_zero",l+"_zero"),t.exportFunction(s+"_isZero",l+"_isZero"),t.exportFunction(s+"_eq",l+"_eq"),function(){const e=t.addFunction(l+"_isOne");e.addParam("x","i32"),e.setReturnType("i32");const a=e.getCodeBuilder();e.addCode(a.ret(a.call(s+"_eq",a.getLocal("x"),a.i32_const(f))))}(),function(){const e=t.addFunction(l+"_add");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.if(a.call(s+"_add",a.getLocal("x"),a.getLocal("y"),a.getLocal("r")),a.drop(a.call(s+"_sub",a.getLocal("r"),a.i32_const(d),a.getLocal("r"))),a.if(a.call(s+"_gte",a.getLocal("r"),a.i32_const(d)),a.drop(a.call(s+"_sub",a.getLocal("r"),a.i32_const(d),a.getLocal("r"))))))}(),function(){const e=t.addFunction(l+"_sub");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.if(a.call(s+"_sub",a.getLocal("x"),a.getLocal("y"),a.getLocal("r")),a.drop(a.call(s+"_add",a.getLocal("r"),a.i32_const(d),a.getLocal("r")))))}(),function(){const e=t.addFunction(l+"_neg");e.addParam("x","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.call(l+"_sub",a.i32_const(_),a.getLocal("x"),a.getLocal("r")))}(),function(){const e=t.alloc(r*r*8),a=t.addFunction(l+"_mReduct");a.addParam("t","i32"),a.addParam("r","i32"),a.addLocal("np32","i64"),a.addLocal("c","i64"),a.addLocal("m","i64");const i=a.getCodeBuilder(),n=u("100000000",16).minus(o.modInv(u("100000000",16))).toJSNumber();a.addCode(i.setLocal("np32",i.i64_const(n)));for(let t=0;t<r;t++){a.addCode(i.setLocal("c",i.i64_const(0))),a.addCode(i.setLocal("m",i.i64_and(i.i64_mul(i.i64_load32_u(i.getLocal("t"),4*t),i.getLocal("np32")),i.i64_const("0xFFFFFFFF"))));for(let e=0;e<r;e++)a.addCode(i.setLocal("c",i.i64_add(i.i64_add(i.i64_load32_u(i.getLocal("t"),4*(t+e)),i.i64_shr_u(i.getLocal("c"),i.i64_const(32))),i.i64_mul(i.i64_load32_u(i.i32_const(d),4*e),i.getLocal("m"))))),a.addCode(i.i64_store32(i.getLocal("t"),4*(t+e),i.getLocal("c")));a.addCode(i.i64_store32(i.i32_const(e),4*t,i.i64_shr_u(i.getLocal("c"),i.i64_const(32))))}a.addCode(i.call(l+"_add",i.i32_const(e),i.i32_add(i.getLocal("t"),i.i32_const(4*r)),i.getLocal("r")))}(),function(){const e=t.addFunction(l+"_mul");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32"),e.addLocal("c0","i64"),e.addLocal("c1","i64"),e.addLocal("np32","i64");for(let t=0;t<r;t++)e.addLocal("x"+t,"i64"),e.addLocal("y"+t,"i64"),e.addLocal("m"+t,"i64"),e.addLocal("q"+t,"i64");const a=e.getCodeBuilder(),i=u("100000000",16).minus(o.modInv(u("100000000",16))).toJSNumber();e.addCode(a.setLocal("np32",a.i64_const(i)));const n=[],c=[],g=[];function f(t,e){let i,o;return n[t]?i=a.getLocal("x"+t):(i=a.teeLocal("x"+t,a.i64_load32_u(a.getLocal("x"),4*t)),n[t]=!0),c[e]?o=a.getLocal("y"+e):(o=a.teeLocal("y"+e,a.i64_load32_u(a.getLocal("y"),4*e)),c[e]=!0),a.i64_mul(i,o)}function _(t,e){let i,o;return g[t]?i=a.getLocal("q"+t):(i=a.teeLocal("q"+t,a.i64_load32_u(a.i32_const(0),d+4*t)),g[t]=!0),o=a.getLocal("m"+e),a.i64_mul(i,o)}let p="c0",h="c1";for(let t=0;t<2*r-1;t++){for(let i=Math.max(0,t-r+1);i<=t&&i<r;i++){const o=t-i;e.addCode(a.setLocal(p,a.i64_add(a.i64_and(a.getLocal(p),a.i64_const(4294967295)),f(i,o)))),e.addCode(a.setLocal(h,a.i64_add(a.getLocal(h),a.i64_shr_u(a.getLocal(p),a.i64_const(32)))))}for(let i=Math.max(1,t-r+1);i<=t&&i<r;i++){const o=t-i;e.addCode(a.setLocal(p,a.i64_add(a.i64_and(a.getLocal(p),a.i64_const(4294967295)),_(i,o)))),e.addCode(a.setLocal(h,a.i64_add(a.getLocal(h),a.i64_shr_u(a.getLocal(p),a.i64_const(32)))))}t<r&&(e.addCode(a.setLocal("m"+t,a.i64_and(a.i64_mul(a.i64_and(a.getLocal(p),a.i64_const(4294967295)),a.getLocal("np32")),a.i64_const("0xFFFFFFFF")))),e.addCode(a.setLocal(p,a.i64_add(a.i64_and(a.getLocal(p),a.i64_const(4294967295)),_(0,t)))),e.addCode(a.setLocal(h,a.i64_add(a.getLocal(h),a.i64_shr_u(a.getLocal(p),a.i64_const(32)))))),t>=r&&e.addCode(a.i64_store32(a.getLocal("r"),4*(t-r),a.getLocal(p))),[p,h]=[h,p],e.addCode(a.setLocal(h,a.i64_shr_u(a.getLocal(p),a.i64_const(32))))}e.addCode(a.i64_store32(a.getLocal("r"),4*r-4,a.getLocal(p))),e.addCode(a.if(a.i32_wrap_i64(a.getLocal(h)),a.drop(a.call(s+"_sub",a.getLocal("r"),a.i32_const(d),a.getLocal("r"))),a.if(a.call(s+"_gte",a.getLocal("r"),a.i32_const(d)),a.drop(a.call(s+"_sub",a.getLocal("r"),a.i32_const(d),a.getLocal("r"))))))}(),function(){const e=t.addFunction(l+"_square");e.addParam("x","i32"),e.addParam("r","i32"),e.addLocal("c0","i64"),e.addLocal("c1","i64"),e.addLocal("c0_old","i64"),e.addLocal("c1_old","i64"),e.addLocal("np32","i64");for(let t=0;t<r;t++)e.addLocal("x"+t,"i64"),e.addLocal("m"+t,"i64"),e.addLocal("q"+t,"i64");const a=e.getCodeBuilder(),i=u("100000000",16).minus(o.modInv(u("100000000",16))).toJSNumber();e.addCode(a.setLocal("np32",a.i64_const(i)));const n=[],c=[];function g(t,e){let i,o;return n[t]?i=a.getLocal("x"+t):(i=a.teeLocal("x"+t,a.i64_load32_u(a.getLocal("x"),4*t)),n[t]=!0),n[e]?o=a.getLocal("x"+e):(o=a.teeLocal("x"+e,a.i64_load32_u(a.getLocal("x"),4*e)),n[e]=!0),a.i64_mul(i,o)}function f(t,e){let i,o;return c[t]?i=a.getLocal("q"+t):(i=a.teeLocal("q"+t,a.i64_load32_u(a.i32_const(0),d+4*t)),c[t]=!0),o=a.getLocal("m"+e),a.i64_mul(i,o)}let _="c0",p="c1",h="c0_old",m="c1_old";for(let t=0;t<2*r-1;t++){e.addCode(a.setLocal(_,a.i64_const(0)),a.setLocal(p,a.i64_const(0)));for(let i=Math.max(0,t-r+1);i<t+1>>1&&i<r;i++){const o=t-i;e.addCode(a.setLocal(_,a.i64_add(a.i64_and(a.getLocal(_),a.i64_const(4294967295)),g(i,o)))),e.addCode(a.setLocal(p,a.i64_add(a.getLocal(p),a.i64_shr_u(a.getLocal(_),a.i64_const(32)))))}e.addCode(a.setLocal(_,a.i64_shl(a.i64_and(a.getLocal(_),a.i64_const(4294967295)),a.i64_const(1)))),e.addCode(a.setLocal(p,a.i64_add(a.i64_shl(a.getLocal(p),a.i64_const(1)),a.i64_shr_u(a.getLocal(_),a.i64_const(32))))),t%2==0&&(e.addCode(a.setLocal(_,a.i64_add(a.i64_and(a.getLocal(_),a.i64_const(4294967295)),g(t>>1,t>>1)))),e.addCode(a.setLocal(p,a.i64_add(a.getLocal(p),a.i64_shr_u(a.getLocal(_),a.i64_const(32)))))),t>0&&(e.addCode(a.setLocal(_,a.i64_add(a.i64_and(a.getLocal(_),a.i64_const(4294967295)),a.i64_and(a.getLocal(h),a.i64_const(4294967295))))),e.addCode(a.setLocal(p,a.i64_add(a.i64_add(a.getLocal(p),a.i64_shr_u(a.getLocal(_),a.i64_const(32))),a.getLocal(m)))));for(let i=Math.max(1,t-r+1);i<=t&&i<r;i++){const o=t-i;e.addCode(a.setLocal(_,a.i64_add(a.i64_and(a.getLocal(_),a.i64_const(4294967295)),f(i,o)))),e.addCode(a.setLocal(p,a.i64_add(a.getLocal(p),a.i64_shr_u(a.getLocal(_),a.i64_const(32)))))}t<r&&(e.addCode(a.setLocal("m"+t,a.i64_and(a.i64_mul(a.i64_and(a.getLocal(_),a.i64_const(4294967295)),a.getLocal("np32")),a.i64_const("0xFFFFFFFF")))),e.addCode(a.setLocal(_,a.i64_add(a.i64_and(a.getLocal(_),a.i64_const(4294967295)),f(0,t)))),e.addCode(a.setLocal(p,a.i64_add(a.getLocal(p),a.i64_shr_u(a.getLocal(_),a.i64_const(32)))))),t>=r&&e.addCode(a.i64_store32(a.getLocal("r"),4*(t-r),a.getLocal(_))),e.addCode(a.setLocal(h,a.getLocal(p)),a.setLocal(m,a.i64_shr_u(a.getLocal(h),a.i64_const(32))))}e.addCode(a.i64_store32(a.getLocal("r"),4*r-4,a.getLocal(h))),e.addCode(a.if(a.i32_wrap_i64(a.getLocal(m)),a.drop(a.call(s+"_sub",a.getLocal("r"),a.i32_const(d),a.getLocal("r"))),a.if(a.call(s+"_gte",a.getLocal("r"),a.i32_const(d)),a.drop(a.call(s+"_sub",a.getLocal("r"),a.i32_const(d),a.getLocal("r"))))))}(),function(){const e=t.addFunction(l+"_squareOld");e.addParam("x","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.call(l+"_mul",a.getLocal("x"),a.getLocal("x"),a.getLocal("r")))}(),function(){const e=t.addFunction(l+"_toMontgomery");e.addParam("x","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.call(l+"_mul",a.getLocal("x"),a.i32_const(g),a.getLocal("r")))}(),function(){const e=t.alloc(2*c),a=t.addFunction(l+"_fromMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const i=a.getCodeBuilder();a.addCode(i.call(s+"_copy",i.getLocal("x"),i.i32_const(e))),a.addCode(i.call(s+"_zero",i.i32_const(e+c))),a.addCode(i.call(l+"_mReduct",i.i32_const(e),i.getLocal("r")))}(),function(){const e=t.addFunction(l+"_isNegative");e.addParam("x","i32"),e.setReturnType("i32");const a=e.getCodeBuilder(),i=a.i32_const(t.alloc(c));e.addCode(a.call(l+"_fromMontgomery",a.getLocal("x"),i),a.call(s+"_gte",i,a.i32_const(w)))}(),function(){const e=t.addFunction(l+"_sign");e.addParam("x","i32"),e.setReturnType("i32");const a=e.getCodeBuilder(),i=a.i32_const(t.alloc(c));e.addCode(a.if(a.call(s+"_isZero",a.getLocal("x")),a.ret(a.i32_const(0))),a.call(l+"_fromMontgomery",a.getLocal("x"),i),a.if(a.call(s+"_gte",i,a.i32_const(w)),a.ret(a.i32_const(-1))),a.ret(a.i32_const(1)))}(),function(){const e=t.addFunction(l+"_inverse");e.addParam("x","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.call(l+"_fromMontgomery",a.getLocal("x"),a.getLocal("r"))),e.addCode(a.call(s+"_inverseMod",a.getLocal("r"),a.i32_const(d),a.getLocal("r"))),e.addCode(a.call(l+"_toMontgomery",a.getLocal("r"),a.getLocal("r")))}(),function(){const e=t.addFunction(l+"_one");e.addParam("pr","i32");const a=e.getCodeBuilder();e.addCode(a.call(s+"_copy",a.i32_const(f),a.getLocal("pr")))}(),function(){const e=t.addFunction(l+"_load");e.addParam("scalar","i32"),e.addParam("scalarLen","i32"),e.addParam("r","i32"),e.addLocal("p","i32"),e.addLocal("l","i32"),e.addLocal("i","i32"),e.addLocal("j","i32");const a=e.getCodeBuilder(),i=a.i32_const(t.alloc(c)),o=t.alloc(c),n=a.i32_const(o);e.addCode(a.call(s+"_zero",a.getLocal("r")),a.setLocal("i",a.i32_const(c)),a.setLocal("p",a.getLocal("scalar")),a.block(a.loop(a.br_if(1,a.i32_gt_u(a.getLocal("i"),a.getLocal("scalarLen"))),a.if(a.i32_eq(a.getLocal("i"),a.i32_const(c)),a.call(l+"_one",i),a.call(l+"_mul",i,a.i32_const(g),i)),a.call(l+"_mul",a.getLocal("p"),i,n),a.call(l+"_add",a.getLocal("r"),n,a.getLocal("r")),a.setLocal("p",a.i32_add(a.getLocal("p"),a.i32_const(c))),a.setLocal("i",a.i32_add(a.getLocal("i"),a.i32_const(c))),a.br(0))),a.setLocal("l",a.i32_rem_u(a.getLocal("scalarLen"),a.i32_const(c))),a.if(a.i32_eqz(a.getLocal("l")),a.ret([])),a.call(s+"_zero",n),a.setLocal("j",a.i32_const(0)),a.block(a.loop(a.br_if(1,a.i32_eq(a.getLocal("j"),a.getLocal("l"))),a.i32_store8(a.getLocal("j"),o,a.i32_load8_u(a.getLocal("p"))),a.setLocal("p",a.i32_add(a.getLocal("p"),a.i32_const(1))),a.setLocal("j",a.i32_add(a.getLocal("j"),a.i32_const(1))),a.br(0))),a.if(a.i32_eq(a.getLocal("i"),a.i32_const(c)),a.call(l+"_one",i),a.call(l+"_mul",i,a.i32_const(g),i)),a.call(l+"_mul",n,i,n),a.call(l+"_add",a.getLocal("r"),n,a.getLocal("r")))}(),function(){const e=t.addFunction(l+"_timesScalar");e.addParam("x","i32"),e.addParam("scalar","i32"),e.addParam("scalarLen","i32"),e.addParam("r","i32");const a=e.getCodeBuilder(),i=a.i32_const(t.alloc(c));e.addCode(a.call(l+"_load",a.getLocal("scalar"),a.getLocal("scalarLen"),i),a.call(l+"_toMontgomery",i,i),a.call(l+"_mul",a.getLocal("x"),i,a.getLocal("r")))}(),Gt(t,l),Pt(t,l+"_batchToMontgomery",l+"_toMontgomery",c,c),Pt(t,l+"_batchFromMontgomery",l+"_fromMontgomery",c,c),Pt(t,l+"_batchNeg",l+"_neg",c,c),Ot(t,l+"_batchAdd",l+"_add",c,c),Ot(t,l+"_batchSub",l+"_sub",c,c),Ot(t,l+"_batchMul",l+"_mul",c,c),t.exportFunction(l+"_add"),t.exportFunction(l+"_sub"),t.exportFunction(l+"_neg"),t.exportFunction(l+"_isNegative"),t.exportFunction(l+"_isOne"),t.exportFunction(l+"_sign"),t.exportFunction(l+"_mReduct"),t.exportFunction(l+"_mul"),t.exportFunction(l+"_square"),t.exportFunction(l+"_squareOld"),t.exportFunction(l+"_fromMontgomery"),t.exportFunction(l+"_toMontgomery"),t.exportFunction(l+"_inverse"),t.exportFunction(l+"_one"),t.exportFunction(l+"_load"),t.exportFunction(l+"_timesScalar"),St(t,l+"_exp",c,l+"_mul",l+"_square",s+"_copy",l+"_one"),t.exportFunction(l+"_exp"),t.exportFunction(l+"_batchInverse"),o.isPrime()&&(!function(){const e=t.addFunction(l+"_sqrt");e.addParam("n","i32"),e.addParam("r","i32"),e.addLocal("m","i32"),e.addLocal("i","i32"),e.addLocal("j","i32");const a=e.getCodeBuilder(),i=a.i32_const(f),o=a.i32_const(t.alloc(c)),n=a.i32_const(t.alloc(c)),r=a.i32_const(t.alloc(c)),s=a.i32_const(t.alloc(c)),d=a.i32_const(t.alloc(c));e.addCode(a.if(a.call(l+"_isZero",a.getLocal("n")),a.ret(a.call(l+"_zero",a.getLocal("r")))),a.setLocal("m",a.i32_const(b)),a.call(l+"_copy",a.i32_const(F),o),a.call(l+"_exp",a.getLocal("n"),a.i32_const(I),a.i32_const(c),n),a.call(l+"_exp",a.getLocal("n"),a.i32_const(v),a.i32_const(c),r),a.block(a.loop(a.br_if(1,a.call(l+"_eq",n,i)),a.call(l+"_square",n,s),a.setLocal("i",a.i32_const(1)),a.block(a.loop(a.br_if(1,a.call(l+"_eq",s,i)),a.call(l+"_square",s,s),a.setLocal("i",a.i32_add(a.getLocal("i"),a.i32_const(1))),a.br(0))),a.call(l+"_copy",o,d),a.setLocal("j",a.i32_sub(a.i32_sub(a.getLocal("m"),a.getLocal("i")),a.i32_const(1))),a.block(a.loop(a.br_if(1,a.i32_eqz(a.getLocal("j"))),a.call(l+"_square",d,d),a.setLocal("j",a.i32_sub(a.getLocal("j"),a.i32_const(1))),a.br(0))),a.setLocal("m",a.getLocal("i")),a.call(l+"_square",d,o),a.call(l+"_mul",n,o,n),a.call(l+"_mul",r,d,r),a.br(0))),a.if(a.call(l+"_isNegative",r),a.call(l+"_neg",r,a.getLocal("r")),a.call(l+"_copy",r,a.getLocal("r"))))}(),function(){const e=t.addFunction(l+"_isSquare");e.addParam("n","i32"),e.setReturnType("i32");const a=e.getCodeBuilder(),i=a.i32_const(f),o=a.i32_const(t.alloc(c));e.addCode(a.if(a.call(l+"_isZero",a.getLocal("n")),a.ret(a.i32_const(1))),a.call(l+"_exp",a.getLocal("n"),a.i32_const(m),a.i32_const(c),o),a.call(l+"_eq",o,i))}(),t.exportFunction(l+"_sqrt"),t.exportFunction(l+"_isSquare")),t.exportFunction(l+"_batchToMontgomery"),t.exportFunction(l+"_batchFromMontgomery"),l},zt=function(t,e,a,i,o){const n=u(e),r=Math.floor((n.minus(1).bitLength()-1)/64)+1,c=8*r,l=a||"f1";if(t.modules[l])return l;t.modules[l]={n64:r};const s=o||"int",d=Ut(t,n,i,s),g=t.modules[d].pR2,f=t.modules[d].pq,_=t.modules[d].pePlusOne;return function(){const e=t.alloc(c),a=t.addFunction(l+"_mul");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const i=a.getCodeBuilder();a.addCode(i.call(d+"_mul",i.getLocal("x"),i.getLocal("y"),i.i32_const(e))),a.addCode(i.call(d+"_mul",i.i32_const(e),i.i32_const(g),i.getLocal("r")))}(),function(){const e=t.addFunction(l+"_square");e.addParam("x","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.call(l+"_mul",a.getLocal("x"),a.getLocal("x"),a.getLocal("r")))}(),function(){const e=t.addFunction(l+"_inverse");e.addParam("x","i32"),e.addParam("r","i32");const a=e.getCodeBuilder();e.addCode(a.call(s+"_inverseMod",a.getLocal("x"),a.i32_const(f),a.getLocal("r")))}(),function(){const e=t.addFunction(l+"_isNegative");e.addParam("x","i32"),e.setReturnType("i32");const a=e.getCodeBuilder();e.addCode(a.call(s+"_gte",a.getLocal("x"),a.i32_const(_)))}(),t.exportFunction(d+"_add",l+"_add"),t.exportFunction(d+"_sub",l+"_sub"),t.exportFunction(d+"_neg",l+"_neg"),t.exportFunction(l+"_mul"),t.exportFunction(l+"_square"),t.exportFunction(l+"_inverse"),t.exportFunction(l+"_isNegative"),t.exportFunction(d+"_copy",l+"_copy"),t.exportFunction(d+"_zero",l+"_zero"),t.exportFunction(d+"_one",l+"_one"),t.exportFunction(d+"_isZero",l+"_isZero"),t.exportFunction(d+"_eq",l+"_eq"),l},qt=function(t,e,a,i){if(t.modules[a])return a;const o=8*t.modules[i].n64,n=t.modules[i].q;return t.modules[a]={n64:2*t.modules[i].n64},function(){const e=t.addFunction(a+"_isZero");e.addParam("x","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o));e.addCode(n.i32_and(n.call(i+"_isZero",r),n.call(i+"_isZero",c)))}(),function(){const e=t.addFunction(a+"_isOne");e.addParam("x","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o));e.addCode(n.ret(n.i32_and(n.call(i+"_isOne",r),n.call(i+"_isZero",c))))}(),function(){const e=t.addFunction(a+"_zero");e.addParam("x","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o));e.addCode(n.call(i+"_zero",r),n.call(i+"_zero",c))}(),function(){const e=t.addFunction(a+"_one");e.addParam("x","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o));e.addCode(n.call(i+"_one",r),n.call(i+"_zero",c))}(),function(){const e=t.addFunction(a+"_copy");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.getLocal("r"),s=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_copy",r,l),n.call(i+"_copy",c,s))}(),function(){const n=t.addFunction(a+"_mul");n.addParam("x","i32"),n.addParam("y","i32"),n.addParam("r","i32");const r=n.getCodeBuilder(),c=r.getLocal("x"),l=r.i32_add(r.getLocal("x"),r.i32_const(o)),s=r.getLocal("y"),d=r.i32_add(r.getLocal("y"),r.i32_const(o)),u=r.getLocal("r"),g=r.i32_add(r.getLocal("r"),r.i32_const(o)),f=r.i32_const(t.alloc(o)),_=r.i32_const(t.alloc(o)),p=r.i32_const(t.alloc(o)),h=r.i32_const(t.alloc(o));n.addCode(r.call(i+"_mul",c,s,f),r.call(i+"_mul",l,d,_),r.call(i+"_add",c,l,p),r.call(i+"_add",s,d,h),r.call(i+"_mul",p,h,p),r.call(e,_,u),r.call(i+"_add",f,u,u),r.call(i+"_add",f,_,g),r.call(i+"_sub",p,g,g))}(),function(){const e=t.addFunction(a+"_mul1");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.getLocal("y"),s=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_mul",r,l,s),n.call(i+"_mul",c,l,d))}(),function(){const n=t.addFunction(a+"_square");n.addParam("x","i32"),n.addParam("r","i32");const r=n.getCodeBuilder(),c=r.getLocal("x"),l=r.i32_add(r.getLocal("x"),r.i32_const(o)),s=r.getLocal("r"),d=r.i32_add(r.getLocal("r"),r.i32_const(o)),u=r.i32_const(t.alloc(o)),g=r.i32_const(t.alloc(o)),f=r.i32_const(t.alloc(o)),_=r.i32_const(t.alloc(o));n.addCode(r.call(i+"_mul",c,l,u),r.call(i+"_add",c,l,g),r.call(e,l,f),r.call(i+"_add",c,f,f),r.call(e,u,_),r.call(i+"_add",_,u,_),r.call(i+"_mul",g,f,s),r.call(i+"_sub",s,_,s),r.call(i+"_add",u,u,d))}(),function(){const e=t.addFunction(a+"_add");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.getLocal("y"),s=n.i32_add(n.getLocal("y"),n.i32_const(o)),d=n.getLocal("r"),u=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_add",r,l,d),n.call(i+"_add",c,s,u))}(),function(){const e=t.addFunction(a+"_sub");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.getLocal("y"),s=n.i32_add(n.getLocal("y"),n.i32_const(o)),d=n.getLocal("r"),u=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_sub",r,l,d),n.call(i+"_sub",c,s,u))}(),function(){const e=t.addFunction(a+"_neg");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.getLocal("r"),s=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_neg",r,l),n.call(i+"_neg",c,s))}(),function(){const e=t.addFunction(a+"_conjugate");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.getLocal("r"),s=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_copy",r,l),n.call(i+"_neg",c,s))}(),function(){const e=t.addFunction(a+"_toMontgomery");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.getLocal("r"),s=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_toMontgomery",r,l),n.call(i+"_toMontgomery",c,s))}(),function(){const e=t.addFunction(a+"_fromMontgomery");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.getLocal("r"),s=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_fromMontgomery",r,l),n.call(i+"_fromMontgomery",c,s))}(),function(){const e=t.addFunction(a+"_eq");e.addParam("x","i32"),e.addParam("y","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.getLocal("y"),s=n.i32_add(n.getLocal("y"),n.i32_const(o));e.addCode(n.i32_and(n.call(i+"_eq",r,l),n.call(i+"_eq",c,s)))}(),function(){const n=t.addFunction(a+"_inverse");n.addParam("x","i32"),n.addParam("r","i32");const r=n.getCodeBuilder(),c=r.getLocal("x"),l=r.i32_add(r.getLocal("x"),r.i32_const(o)),s=r.getLocal("r"),d=r.i32_add(r.getLocal("r"),r.i32_const(o)),u=r.i32_const(t.alloc(o)),g=r.i32_const(t.alloc(o)),f=r.i32_const(t.alloc(o)),_=r.i32_const(t.alloc(o));n.addCode(r.call(i+"_square",c,u),r.call(i+"_square",l,g),r.call(e,g,f),r.call(i+"_sub",u,f,f),r.call(i+"_inverse",f,_),r.call(i+"_mul",c,_,s),r.call(i+"_mul",l,_,d),r.call(i+"_neg",d,d))}(),function(){const e=t.addFunction(a+"_timesScalar");e.addParam("x","i32"),e.addParam("scalar","i32"),e.addParam("scalarLen","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.getLocal("r"),s=n.i32_add(n.getLocal("r"),n.i32_const(o));e.addCode(n.call(i+"_timesScalar",r,n.getLocal("scalar"),n.getLocal("scalarLen"),l),n.call(i+"_timesScalar",c,n.getLocal("scalar"),n.getLocal("scalarLen"),s))}(),function(){const e=t.addFunction(a+"_sign");e.addParam("x","i32"),e.addLocal("s","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o));e.addCode(n.setLocal("s",n.call(i+"_sign",c)),n.if(n.getLocal("s"),n.ret(n.getLocal("s"))),n.ret(n.call(i+"_sign",r)))}(),function(){const e=t.addFunction(a+"_isNegative");e.addParam("x","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o));e.addCode(n.if(n.call(i+"_isZero",c),n.ret(n.call(i+"_isNegative",r))),n.ret(n.call(i+"_isNegative",c)))}(),t.exportFunction(a+"_isZero"),t.exportFunction(a+"_isOne"),t.exportFunction(a+"_zero"),t.exportFunction(a+"_one"),t.exportFunction(a+"_copy"),t.exportFunction(a+"_mul"),t.exportFunction(a+"_mul1"),t.exportFunction(a+"_square"),t.exportFunction(a+"_add"),t.exportFunction(a+"_sub"),t.exportFunction(a+"_neg"),t.exportFunction(a+"_sign"),t.exportFunction(a+"_conjugate"),t.exportFunction(a+"_fromMontgomery"),t.exportFunction(a+"_toMontgomery"),t.exportFunction(a+"_eq"),t.exportFunction(a+"_inverse"),Gt(t,a),St(t,a+"_exp",2*o,a+"_mul",a+"_square",a+"_copy",a+"_one"),function(){const e=t.addFunction(a+"_sqrt");e.addParam("a","i32"),e.addParam("pr","i32");const r=e.getCodeBuilder(),c=r.i32_const(t.alloc(Et(u(n).minus(u(3)).divide(4),o))),l=r.i32_const(t.alloc(Et(u(n).minus(u(1)).divide(2),o))),s=r.getLocal("a"),d=r.i32_const(t.alloc(2*o)),g=r.i32_const(t.alloc(2*o)),f=r.i32_const(t.alloc(2*o)),_=t.alloc(2*o),p=r.i32_const(_),h=r.i32_const(_),m=r.i32_const(_+o),L=r.i32_const(t.alloc(2*o)),w=r.i32_const(t.alloc(2*o));e.addCode(r.call(a+"_one",p),r.call(a+"_neg",p,p),r.call(a+"_exp",s,c,r.i32_const(o),d),r.call(a+"_square",d,g),r.call(a+"_mul",s,g,g),r.call(a+"_conjugate",g,f),r.call(a+"_mul",f,g,f),r.if(r.call(a+"_eq",f,p),r.unreachable()),r.call(a+"_mul",d,s,L),r.if(r.call(a+"_eq",g,p),[...r.call(i+"_zero",h),...r.call(i+"_one",m),...r.call(a+"_mul",p,L,r.getLocal("pr"))],[...r.call(a+"_one",w),...r.call(a+"_add",w,g,w),...r.call(a+"_exp",w,l,r.i32_const(o),w),...r.call(a+"_mul",w,L,r.getLocal("pr"))]))}(),function(){const e=t.addFunction(a+"_isSquare");e.addParam("a","i32"),e.setReturnType("i32");const i=e.getCodeBuilder(),r=i.i32_const(t.alloc(Et(u(n).minus(u(3)).divide(4),o))),c=i.getLocal("a"),l=i.i32_const(t.alloc(2*o)),s=i.i32_const(t.alloc(2*o)),d=i.i32_const(t.alloc(2*o)),g=t.alloc(2*o),f=i.i32_const(g);e.addCode(i.call(a+"_one",f),i.call(a+"_neg",f,f),i.call(a+"_exp",c,r,i.i32_const(o),l),i.call(a+"_square",l,s),i.call(a+"_mul",c,s,s),i.call(a+"_conjugate",s,d),i.call(a+"_mul",d,s,d),i.if(i.call(a+"_eq",d,f),i.ret(i.i32_const(0))),i.ret(i.i32_const(1)))}(),t.exportFunction(a+"_exp"),t.exportFunction(a+"_timesScalar"),t.exportFunction(a+"_batchInverse"),t.exportFunction(a+"_sqrt"),t.exportFunction(a+"_isSquare"),t.exportFunction(a+"_isNegative"),a},Qt=function(t,e,a,i){if(t.modules[a])return a;const o=8*t.modules[i].n64;return t.modules[a]={n64:3*t.modules[i].n64},function(){const e=t.addFunction(a+"_isZero");e.addParam("x","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o));e.addCode(n.i32_and(n.i32_and(n.call(i+"_isZero",r),n.call(i+"_isZero",c)),n.call(i+"_isZero",l)))}(),function(){const e=t.addFunction(a+"_isOne");e.addParam("x","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o));e.addCode(n.ret(n.i32_and(n.i32_and(n.call(i+"_isOne",r),n.call(i+"_isZero",c)),n.call(i+"_isZero",l))))}(),function(){const e=t.addFunction(a+"_zero");e.addParam("x","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o));e.addCode(n.call(i+"_zero",r),n.call(i+"_zero",c),n.call(i+"_zero",l))}(),function(){const e=t.addFunction(a+"_one");e.addParam("x","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o));e.addCode(n.call(i+"_one",r),n.call(i+"_zero",c),n.call(i+"_zero",l))}(),function(){const e=t.addFunction(a+"_copy");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),s=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(o)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*o));e.addCode(n.call(i+"_copy",r,s),n.call(i+"_copy",c,d),n.call(i+"_copy",l,u))}(),function(){const n=t.addFunction(a+"_mul");n.addParam("x","i32"),n.addParam("y","i32"),n.addParam("r","i32");const r=n.getCodeBuilder(),c=r.getLocal("x"),l=r.i32_add(r.getLocal("x"),r.i32_const(o)),s=r.i32_add(r.getLocal("x"),r.i32_const(2*o)),d=r.getLocal("y"),u=r.i32_add(r.getLocal("y"),r.i32_const(o)),g=r.i32_add(r.getLocal("y"),r.i32_const(2*o)),f=r.getLocal("r"),_=r.i32_add(r.getLocal("r"),r.i32_const(o)),p=r.i32_add(r.getLocal("r"),r.i32_const(2*o)),h=r.i32_const(t.alloc(o)),m=r.i32_const(t.alloc(o)),L=r.i32_const(t.alloc(o)),w=r.i32_const(t.alloc(o)),A=r.i32_const(t.alloc(o)),b=r.i32_const(t.alloc(o)),y=r.i32_const(t.alloc(o)),I=r.i32_const(t.alloc(o)),C=r.i32_const(t.alloc(o)),F=r.i32_const(t.alloc(o)),x=r.i32_const(t.alloc(o)),v=r.i32_const(t.alloc(o)),E=r.i32_const(t.alloc(o));n.addCode(r.call(i+"_mul",c,d,h),r.call(i+"_mul",l,u,m),r.call(i+"_mul",s,g,L),r.call(i+"_add",c,l,w),r.call(i+"_add",d,u,A),r.call(i+"_add",c,s,b),r.call(i+"_add",d,g,y),r.call(i+"_add",l,s,I),r.call(i+"_add",u,g,C),r.call(i+"_add",h,m,F),r.call(i+"_add",h,L,x),r.call(i+"_add",m,L,v),r.call(i+"_mul",I,C,f),r.call(i+"_sub",f,v,f),r.call(e,f,f),r.call(i+"_add",h,f,f),r.call(i+"_mul",w,A,_),r.call(i+"_sub",_,F,_),r.call(e,L,E),r.call(i+"_add",_,E,_),r.call(i+"_mul",b,y,p),r.call(i+"_sub",p,x,p),r.call(i+"_add",p,m,p))}(),function(){const n=t.addFunction(a+"_square");n.addParam("x","i32"),n.addParam("r","i32");const r=n.getCodeBuilder(),c=r.getLocal("x"),l=r.i32_add(r.getLocal("x"),r.i32_const(o)),s=r.i32_add(r.getLocal("x"),r.i32_const(2*o)),d=r.getLocal("r"),u=r.i32_add(r.getLocal("r"),r.i32_const(o)),g=r.i32_add(r.getLocal("r"),r.i32_const(2*o)),f=r.i32_const(t.alloc(o)),_=r.i32_const(t.alloc(o)),p=r.i32_const(t.alloc(o)),h=r.i32_const(t.alloc(o)),m=r.i32_const(t.alloc(o)),L=r.i32_const(t.alloc(o)),w=r.i32_const(t.alloc(o));n.addCode(r.call(i+"_square",c,f),r.call(i+"_mul",c,l,_),r.call(i+"_add",_,_,p),r.call(i+"_sub",c,l,h),r.call(i+"_add",h,s,h),r.call(i+"_square",h,h),r.call(i+"_mul",l,s,m),r.call(i+"_add",m,m,L),r.call(i+"_square",s,w),r.call(e,L,d),r.call(i+"_add",f,d,d),r.call(e,w,u),r.call(i+"_add",p,u,u),r.call(i+"_add",f,w,g),r.call(i+"_sub",L,g,g),r.call(i+"_add",h,g,g),r.call(i+"_add",p,g,g))}(),function(){const e=t.addFunction(a+"_add");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),s=n.getLocal("y"),d=n.i32_add(n.getLocal("y"),n.i32_const(o)),u=n.i32_add(n.getLocal("y"),n.i32_const(2*o)),g=n.getLocal("r"),f=n.i32_add(n.getLocal("r"),n.i32_const(o)),_=n.i32_add(n.getLocal("r"),n.i32_const(2*o));e.addCode(n.call(i+"_add",r,s,g),n.call(i+"_add",c,d,f),n.call(i+"_add",l,u,_))}(),function(){const e=t.addFunction(a+"_sub");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),s=n.getLocal("y"),d=n.i32_add(n.getLocal("y"),n.i32_const(o)),u=n.i32_add(n.getLocal("y"),n.i32_const(2*o)),g=n.getLocal("r"),f=n.i32_add(n.getLocal("r"),n.i32_const(o)),_=n.i32_add(n.getLocal("r"),n.i32_const(2*o));e.addCode(n.call(i+"_sub",r,s,g),n.call(i+"_sub",c,d,f),n.call(i+"_sub",l,u,_))}(),function(){const e=t.addFunction(a+"_neg");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),s=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(o)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*o));e.addCode(n.call(i+"_neg",r,s),n.call(i+"_neg",c,d),n.call(i+"_neg",l,u))}(),function(){const e=t.addFunction(a+"_sign");e.addParam("x","i32"),e.addLocal("s","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o));e.addCode(n.setLocal("s",n.call(i+"_sign",l)),n.if(n.getLocal("s"),n.ret(n.getLocal("s"))),n.setLocal("s",n.call(i+"_sign",c)),n.if(n.getLocal("s"),n.ret(n.getLocal("s"))),n.ret(n.call(i+"_sign",r)))}(),function(){const e=t.addFunction(a+"_toMontgomery");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),s=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(o)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*o));e.addCode(n.call(i+"_toMontgomery",r,s),n.call(i+"_toMontgomery",c,d),n.call(i+"_toMontgomery",l,u))}(),function(){const e=t.addFunction(a+"_fromMontgomery");e.addParam("x","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),s=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(o)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*o));e.addCode(n.call(i+"_fromMontgomery",r,s),n.call(i+"_fromMontgomery",c,d),n.call(i+"_fromMontgomery",l,u))}(),function(){const e=t.addFunction(a+"_eq");e.addParam("x","i32"),e.addParam("y","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),s=n.getLocal("y"),d=n.i32_add(n.getLocal("y"),n.i32_const(o)),u=n.i32_add(n.getLocal("y"),n.i32_const(2*o));e.addCode(n.i32_and(n.i32_and(n.call(i+"_eq",r,s),n.call(i+"_eq",c,d)),n.call(i+"_eq",l,u)))}(),function(){const n=t.addFunction(a+"_inverse");n.addParam("x","i32"),n.addParam("r","i32");const r=n.getCodeBuilder(),c=r.getLocal("x"),l=r.i32_add(r.getLocal("x"),r.i32_const(o)),s=r.i32_add(r.getLocal("x"),r.i32_const(2*o)),d=r.getLocal("r"),u=r.i32_add(r.getLocal("r"),r.i32_const(o)),g=r.i32_add(r.getLocal("r"),r.i32_const(2*o)),f=r.i32_const(t.alloc(o)),_=r.i32_const(t.alloc(o)),p=r.i32_const(t.alloc(o)),h=r.i32_const(t.alloc(o)),m=r.i32_const(t.alloc(o)),L=r.i32_const(t.alloc(o)),w=r.i32_const(t.alloc(o)),A=r.i32_const(t.alloc(o)),b=r.i32_const(t.alloc(o)),y=r.i32_const(t.alloc(o)),I=r.i32_const(t.alloc(o));n.addCode(r.call(i+"_square",c,f),r.call(i+"_square",l,_),r.call(i+"_square",s,p),r.call(i+"_mul",c,l,h),r.call(i+"_mul",c,s,m),r.call(i+"_mul",l,s,L),r.call(e,L,w),r.call(i+"_sub",f,w,w),r.call(e,p,A),r.call(i+"_sub",A,h,A),r.call(i+"_sub",_,m,b),r.call(i+"_mul",s,A,y),r.call(i+"_mul",l,b,I),r.call(i+"_add",y,I,y),r.call(e,y,y),r.call(i+"_mul",c,w,I),r.call(i+"_add",I,y,y),r.call(i+"_inverse",y,y),r.call(i+"_mul",y,w,d),r.call(i+"_mul",y,A,u),r.call(i+"_mul",y,b,g))}(),function(){const e=t.addFunction(a+"_timesScalar");e.addParam("x","i32"),e.addParam("scalar","i32"),e.addParam("scalarLen","i32"),e.addParam("r","i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o)),s=n.getLocal("r"),d=n.i32_add(n.getLocal("r"),n.i32_const(o)),u=n.i32_add(n.getLocal("r"),n.i32_const(2*o));e.addCode(n.call(i+"_timesScalar",r,n.getLocal("scalar"),n.getLocal("scalarLen"),s),n.call(i+"_timesScalar",c,n.getLocal("scalar"),n.getLocal("scalarLen"),d),n.call(i+"_timesScalar",l,n.getLocal("scalar"),n.getLocal("scalarLen"),u))}(),function(){const e=t.addFunction(a+"_isNegative");e.addParam("x","i32"),e.setReturnType("i32");const n=e.getCodeBuilder(),r=n.getLocal("x"),c=n.i32_add(n.getLocal("x"),n.i32_const(o)),l=n.i32_add(n.getLocal("x"),n.i32_const(2*o));e.addCode(n.if(n.call(i+"_isZero",l),n.if(n.call(i+"_isZero",c),n.ret(n.call(i+"_isNegative",r)),n.ret(n.call(i+"_isNegative",c)))),n.ret(n.call(i+"_isNegative",l)))}(),t.exportFunction(a+"_isZero"),t.exportFunction(a+"_isOne"),t.exportFunction(a+"_zero"),t.exportFunction(a+"_one"),t.exportFunction(a+"_copy"),t.exportFunction(a+"_mul"),t.exportFunction(a+"_square"),t.exportFunction(a+"_add"),t.exportFunction(a+"_sub"),t.exportFunction(a+"_neg"),t.exportFunction(a+"_sign"),t.exportFunction(a+"_fromMontgomery"),t.exportFunction(a+"_toMontgomery"),t.exportFunction(a+"_eq"),t.exportFunction(a+"_inverse"),Gt(t,a),St(t,a+"_exp",3*o,a+"_mul",a+"_square",a+"_copy",a+"_one"),t.exportFunction(a+"_exp"),t.exportFunction(a+"_timesScalar"),t.exportFunction(a+"_batchInverse"),t.exportFunction(a+"_isNegative"),a},Mt=function(t,e,a,i,o,n,r,c){const l=t.addFunction(e);l.addParam("base","i32"),l.addParam("scalar","i32"),l.addParam("scalarLength","i32"),l.addParam("r","i32"),l.addLocal("old0","i32"),l.addLocal("nbits","i32"),l.addLocal("i","i32"),l.addLocal("last","i32"),l.addLocal("cur","i32"),l.addLocal("carry","i32"),l.addLocal("p","i32");const s=l.getCodeBuilder(),d=s.i32_const(t.alloc(a));function u(t){return s.i32_and(s.i32_shr_u(s.i32_load(s.i32_add(s.getLocal("scalar"),s.i32_and(s.i32_shr_u(t,s.i32_const(3)),s.i32_const(4294967292)))),s.i32_and(t,s.i32_const(31))),s.i32_const(1))}function g(t){return[...s.i32_store8(s.getLocal("p"),s.i32_const(t)),...s.setLocal("p",s.i32_add(s.getLocal("p"),s.i32_const(1)))]}l.addCode(s.if(s.i32_eqz(s.getLocal("scalarLength")),[...s.call(c,s.getLocal("r")),...s.ret([])]),s.setLocal("nbits",s.i32_shl(s.getLocal("scalarLength"),s.i32_const(3))),s.setLocal("old0",s.i32_load(s.i32_const(0))),s.setLocal("p",s.getLocal("old0")),s.i32_store(s.i32_const(0),s.i32_and(s.i32_add(s.i32_add(s.getLocal("old0"),s.i32_const(32)),s.getLocal("nbits")),s.i32_const(4294967288))),s.setLocal("i",s.i32_const(1)),s.setLocal("last",u(s.i32_const(0))),s.setLocal("carry",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("nbits"))),s.setLocal("cur",u(s.getLocal("i"))),s.if(s.getLocal("last"),s.if(s.getLocal("cur"),s.if(s.getLocal("carry"),[...s.setLocal("last",s.i32_const(0)),...s.setLocal("carry",s.i32_const(1)),...g(1)],[...s.setLocal("last",s.i32_const(0)),...s.setLocal("carry",s.i32_const(1)),...g(255)]),s.if(s.getLocal("carry"),[...s.setLocal("last",s.i32_const(0)),...s.setLocal("carry",s.i32_const(1)),...g(255)],[...s.setLocal("last",s.i32_const(0)),...s.setLocal("carry",s.i32_const(0)),...g(1)])),s.if(s.getLocal("cur"),s.if(s.getLocal("carry"),[...s.setLocal("last",s.i32_const(0)),...s.setLocal("carry",s.i32_const(1)),...g(0)],[...s.setLocal("last",s.i32_const(1)),...s.setLocal("carry",s.i32_const(0)),...g(0)]),s.if(s.getLocal("carry"),[...s.setLocal("last",s.i32_const(1)),...s.setLocal("carry",s.i32_const(0)),...g(0)],[...s.setLocal("last",s.i32_const(0)),...s.setLocal("carry",s.i32_const(0)),...g(0)]))),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0))),s.if(s.getLocal("last"),s.if(s.getLocal("carry"),[...g(255),...g(0),...g(1)],[...g(1)]),s.if(s.getLocal("carry"),[...g(0),...g(1)])),s.setLocal("p",s.i32_sub(s.getLocal("p"),s.i32_const(1))),s.call(r,s.getLocal("base"),d),s.call(c,s.getLocal("r")),s.block(s.loop(s.call(o,s.getLocal("r"),s.getLocal("r")),s.setLocal("cur",s.i32_load8_u(s.getLocal("p"))),s.if(s.getLocal("cur"),s.if(s.i32_eq(s.getLocal("cur"),s.i32_const(1)),s.call(i,s.getLocal("r"),d,s.getLocal("r")),s.call(n,s.getLocal("r"),d,s.getLocal("r")))),s.br_if(1,s.i32_eq(s.getLocal("old0"),s.getLocal("p"))),s.setLocal("p",s.i32_sub(s.getLocal("p"),s.i32_const(1))),s.br(0))),s.i32_store(s.i32_const(0),s.getLocal("old0")))},kt=function(t,e,a,i,o){const n=8*t.modules[e].n64;function r(){const i=t.addFunction(a);i.addParam("pBases","i32"),i.addParam("pScalars","i32"),i.addParam("scalarSize","i32"),i.addParam("n","i32"),i.addParam("pr","i32"),i.addLocal("chunkSize","i32"),i.addLocal("nChunks","i32"),i.addLocal("itScalar","i32"),i.addLocal("endScalar","i32"),i.addLocal("itBase","i32"),i.addLocal("itBit","i32"),i.addLocal("i","i32"),i.addLocal("j","i32"),i.addLocal("nTable","i32"),i.addLocal("pTable","i32"),i.addLocal("idx","i32"),i.addLocal("pIdxTable","i32");const o=i.getCodeBuilder(),r=o.i32_const(t.alloc(n)),c=t.alloc([17,17,17,17,17,17,17,17,17,17,16,16,15,14,13,13,12,11,10,9,8,7,7,6,5,4,3,2,1,1,1,1]);i.addCode(o.call(e+"_zero",o.getLocal("pr")),o.if(o.i32_eqz(o.getLocal("n")),o.ret([])),o.setLocal("chunkSize",o.i32_load8_u(o.i32_clz(o.getLocal("n")),c)),o.setLocal("nChunks",o.i32_add(o.i32_div_u(o.i32_sub(o.i32_shl(o.getLocal("scalarSize"),o.i32_const(3)),o.i32_const(1)),o.getLocal("chunkSize")),o.i32_const(1))),o.setLocal("itBit",o.i32_mul(o.i32_sub(o.getLocal("nChunks"),o.i32_const(1)),o.getLocal("chunkSize"))),o.block(o.loop(o.br_if(1,o.i32_lt_s(o.getLocal("itBit"),o.i32_const(0))),o.if(o.i32_eqz(o.call(e+"_isZero",o.getLocal("pr"))),[...o.setLocal("j",o.i32_const(0)),...o.block(o.loop(o.br_if(1,o.i32_eq(o.getLocal("j"),o.getLocal("chunkSize"))),o.call(e+"_double",o.getLocal("pr"),o.getLocal("pr")),o.setLocal("j",o.i32_add(o.getLocal("j"),o.i32_const(1))),o.br(0)))]),o.call(a+"_chunk",o.getLocal("pBases"),o.getLocal("pScalars"),o.getLocal("scalarSize"),o.getLocal("n"),o.getLocal("itBit"),o.getLocal("chunkSize"),r),o.call(e+"_add",o.getLocal("pr"),r,o.getLocal("pr")),o.setLocal("itBit",o.i32_sub(o.getLocal("itBit"),o.getLocal("chunkSize"))),o.br(0))))}!function(){const e=t.addFunction(a+"_getChunk");e.addParam("pScalar","i32"),e.addParam("scalarSize","i32"),e.addParam("startBit","i32"),e.addParam("chunkSize","i32"),e.addLocal("bitsToEnd","i32"),e.addLocal("mask","i32"),e.setReturnType("i32");const i=e.getCodeBuilder();e.addCode(i.setLocal("bitsToEnd",i.i32_sub(i.i32_mul(i.getLocal("scalarSize"),i.i32_const(8)),i.getLocal("startBit"))),i.if(i.i32_gt_s(i.getLocal("chunkSize"),i.getLocal("bitsToEnd")),i.setLocal("mask",i.i32_sub(i.i32_shl(i.i32_const(1),i.getLocal("bitsToEnd")),i.i32_const(1))),i.setLocal("mask",i.i32_sub(i.i32_shl(i.i32_const(1),i.getLocal("chunkSize")),i.i32_const(1)))),i.i32_and(i.i32_shr_u(i.i32_load(i.i32_add(i.getLocal("pScalar"),i.i32_shr_u(i.getLocal("startBit"),i.i32_const(3))),0,0),i.i32_and(i.getLocal("startBit"),i.i32_const(7))),i.getLocal("mask")))}(),function(){const i=t.addFunction(a+"_reduceTable");i.addParam("pTable","i32"),i.addParam("p","i32"),i.addLocal("half","i32"),i.addLocal("it1","i32"),i.addLocal("it2","i32"),i.addLocal("pAcc","i32");const o=i.getCodeBuilder();i.addCode(o.if(o.i32_eq(o.getLocal("p"),o.i32_const(1)),o.ret([])),o.setLocal("half",o.i32_shl(o.i32_const(1),o.i32_sub(o.getLocal("p"),o.i32_const(1)))),o.setLocal("it1",o.getLocal("pTable")),o.setLocal("it2",o.i32_add(o.getLocal("pTable"),o.i32_mul(o.getLocal("half"),o.i32_const(n)))),o.setLocal("pAcc",o.i32_sub(o.getLocal("it2"),o.i32_const(n))),o.block(o.loop(o.br_if(1,o.i32_eq(o.getLocal("it1"),o.getLocal("pAcc"))),o.call(e+"_add",o.getLocal("it1"),o.getLocal("it2"),o.getLocal("it1")),o.call(e+"_add",o.getLocal("pAcc"),o.getLocal("it2"),o.getLocal("pAcc")),o.setLocal("it1",o.i32_add(o.getLocal("it1"),o.i32_const(n))),o.setLocal("it2",o.i32_add(o.getLocal("it2"),o.i32_const(n))),o.br(0))),o.call(a+"_reduceTable",o.getLocal("pTable"),o.i32_sub(o.getLocal("p"),o.i32_const(1))),o.setLocal("p",o.i32_sub(o.getLocal("p"),o.i32_const(1))),o.block(o.loop(o.br_if(1,o.i32_eqz(o.getLocal("p"))),o.call(e+"_double",o.getLocal("pAcc"),o.getLocal("pAcc")),o.setLocal("p",o.i32_sub(o.getLocal("p"),o.i32_const(1))),o.br(0))),o.call(e+"_add",o.getLocal("pTable"),o.getLocal("pAcc"),o.getLocal("pTable")))}(),function(){const r=t.addFunction(a+"_chunk");r.addParam("pBases","i32"),r.addParam("pScalars","i32"),r.addParam("scalarSize","i32"),r.addParam("n","i32"),r.addParam("startBit","i32"),r.addParam("chunkSize","i32"),r.addParam("pr","i32"),r.addLocal("nChunks","i32"),r.addLocal("itScalar","i32"),r.addLocal("endScalar","i32"),r.addLocal("itBase","i32"),r.addLocal("i","i32"),r.addLocal("j","i32"),r.addLocal("nTable","i32"),r.addLocal("pTable","i32"),r.addLocal("idx","i32"),r.addLocal("pIdxTable","i32");const c=r.getCodeBuilder();r.addCode(c.if(c.i32_eqz(c.getLocal("n")),[...c.call(e+"_zero",c.getLocal("pr")),...c.ret([])]),c.setLocal("nTable",c.i32_shl(c.i32_const(1),c.getLocal("chunkSize"))),c.setLocal("pTable",c.i32_load(c.i32_const(0))),c.i32_store(c.i32_const(0),c.i32_add(c.getLocal("pTable"),c.i32_mul(c.getLocal("nTable"),c.i32_const(n)))),c.setLocal("j",c.i32_const(0)),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("j"),c.getLocal("nTable"))),c.call(e+"_zero",c.i32_add(c.getLocal("pTable"),c.i32_mul(c.getLocal("j"),c.i32_const(n)))),c.setLocal("j",c.i32_add(c.getLocal("j"),c.i32_const(1))),c.br(0))),c.setLocal("itBase",c.getLocal("pBases")),c.setLocal("itScalar",c.getLocal("pScalars")),c.setLocal("endScalar",c.i32_add(c.getLocal("pScalars"),c.i32_mul(c.getLocal("n"),c.getLocal("scalarSize")))),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("itScalar"),c.getLocal("endScalar"))),c.setLocal("idx",c.call(a+"_getChunk",c.getLocal("itScalar"),c.getLocal("scalarSize"),c.getLocal("startBit"),c.getLocal("chunkSize"))),c.if(c.getLocal("idx"),[...c.setLocal("pIdxTable",c.i32_add(c.getLocal("pTable"),c.i32_mul(c.i32_sub(c.getLocal("idx"),c.i32_const(1)),c.i32_const(n)))),...c.call(i,c.getLocal("pIdxTable"),c.getLocal("itBase"),c.getLocal("pIdxTable"))]),c.setLocal("itScalar",c.i32_add(c.getLocal("itScalar"),c.getLocal("scalarSize"))),c.setLocal("itBase",c.i32_add(c.getLocal("itBase"),c.i32_const(o))),c.br(0))),c.call(a+"_reduceTable",c.getLocal("pTable"),c.getLocal("chunkSize")),c.call(e+"_copy",c.getLocal("pTable"),c.getLocal("pr")),c.i32_store(c.i32_const(0),c.getLocal("pTable")))}(),r(),t.exportFunction(a),t.exportFunction(a+"_chunk")},Rt=function(t,e,a,i){const o=t.modules[a].n64,n=8*o;if(t.modules[e])return e;return t.modules[e]={n64:3*o},function(){const i=t.addFunction(e+"_isZeroAffine");i.addParam("p1","i32"),i.setReturnType("i32");const o=i.getCodeBuilder();i.addCode(o.i32_and(o.call(a+"_isZero",o.getLocal("p1")),o.call(a+"_isZero",o.i32_add(o.getLocal("p1"),o.i32_const(n)))))}(),function(){const i=t.addFunction(e+"_isZero");i.addParam("p1","i32"),i.setReturnType("i32");const o=i.getCodeBuilder();i.addCode(o.call(a+"_isZero",o.i32_add(o.getLocal("p1"),o.i32_const(2*n))))}(),function(){const i=t.addFunction(e+"_zeroAffine");i.addParam("pr","i32");const o=i.getCodeBuilder();i.addCode(o.call(a+"_zero",o.getLocal("pr"))),i.addCode(o.call(a+"_zero",o.i32_add(o.getLocal("pr"),o.i32_const(n))))}(),function(){const i=t.addFunction(e+"_zero");i.addParam("pr","i32");const o=i.getCodeBuilder();i.addCode(o.call(a+"_zero",o.getLocal("pr"))),i.addCode(o.call(a+"_one",o.i32_add(o.getLocal("pr"),o.i32_const(n)))),i.addCode(o.call(a+"_zero",o.i32_add(o.getLocal("pr"),o.i32_const(2*n))))}(),function(){const a=t.addFunction(e+"_copyAffine");a.addParam("ps","i32"),a.addParam("pd","i32");const i=a.getCodeBuilder();for(let t=0;t<2*o;t++)a.addCode(i.i64_store(i.getLocal("pd"),8*t,i.i64_load(i.getLocal("ps"),8*t)))}(),function(){const a=t.addFunction(e+"_copy");a.addParam("ps","i32"),a.addParam("pd","i32");const i=a.getCodeBuilder();for(let t=0;t<3*o;t++)a.addCode(i.i64_store(i.getLocal("pd"),8*t,i.i64_load(i.getLocal("ps"),8*t)))}(),function(){const i=t.addFunction(e+"_toJacobian");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder(),r=o.getLocal("p1"),c=o.i32_add(o.getLocal("p1"),o.i32_const(n)),l=o.getLocal("pr"),s=o.i32_add(o.getLocal("pr"),o.i32_const(n)),d=o.i32_add(o.getLocal("pr"),o.i32_const(2*n));i.addCode(o.if(o.call(e+"_isZeroAffine",o.getLocal("p1")),o.call(e+"_zero",o.getLocal("pr")),[...o.call(a+"_one",d),...o.call(a+"_copy",c,s),...o.call(a+"_copy",r,l)]))}(),function(){const i=t.addFunction(e+"_eqAffine");i.addParam("p1","i32"),i.addParam("p2","i32"),i.setReturnType("i32"),i.addLocal("z1","i32");const o=i.getCodeBuilder();i.addCode(o.ret(o.i32_and(o.call(a+"_eq",o.getLocal("p1"),o.getLocal("p2")),o.call(a+"_eq",o.i32_add(o.getLocal("p1"),o.i32_const(n)),o.i32_add(o.getLocal("p2"),o.i32_const(n))))))}(),function(){const i=t.addFunction(e+"_eqMixed");i.addParam("p1","i32"),i.addParam("p2","i32"),i.setReturnType("i32"),i.addLocal("z1","i32");const o=i.getCodeBuilder(),r=o.getLocal("p1"),c=o.i32_add(o.getLocal("p1"),o.i32_const(n));i.addCode(o.setLocal("z1",o.i32_add(o.getLocal("p1"),o.i32_const(2*n))));const l=o.getLocal("z1"),s=o.getLocal("p2"),d=o.i32_add(o.getLocal("p2"),o.i32_const(n)),u=o.i32_const(t.alloc(n)),g=o.i32_const(t.alloc(n)),f=o.i32_const(t.alloc(n)),_=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZero",o.getLocal("p1")),o.ret(o.call(e+"_isZeroAffine",o.getLocal("p2")))),o.if(o.call(e+"_isZeroAffine",o.getLocal("p2")),o.ret(o.i32_const(0))),o.if(o.call(a+"_isOne",l),o.ret(o.call(e+"_eqAffine",o.getLocal("p1"),o.getLocal("p2")))),o.call(a+"_square",l,u),o.call(a+"_mul",s,u,g),o.call(a+"_mul",l,u,f),o.call(a+"_mul",d,f,_),o.if(o.call(a+"_eq",r,g),o.if(o.call(a+"_eq",c,_),o.ret(o.i32_const(1)))),o.ret(o.i32_const(0)))}(),function(){const i=t.addFunction(e+"_eq");i.addParam("p1","i32"),i.addParam("p2","i32"),i.setReturnType("i32"),i.addLocal("z1","i32"),i.addLocal("z2","i32");const o=i.getCodeBuilder(),r=o.getLocal("p1"),c=o.i32_add(o.getLocal("p1"),o.i32_const(n));i.addCode(o.setLocal("z1",o.i32_add(o.getLocal("p1"),o.i32_const(2*n))));const l=o.getLocal("z1"),s=o.getLocal("p2"),d=o.i32_add(o.getLocal("p2"),o.i32_const(n));i.addCode(o.setLocal("z2",o.i32_add(o.getLocal("p2"),o.i32_const(2*n))));const u=o.getLocal("z2"),g=o.i32_const(t.alloc(n)),f=o.i32_const(t.alloc(n)),_=o.i32_const(t.alloc(n)),p=o.i32_const(t.alloc(n)),h=o.i32_const(t.alloc(n)),m=o.i32_const(t.alloc(n)),L=o.i32_const(t.alloc(n)),w=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZero",o.getLocal("p1")),o.ret(o.call(e+"_isZero",o.getLocal("p2")))),o.if(o.call(e+"_isZero",o.getLocal("p2")),o.ret(o.i32_const(0))),o.if(o.call(a+"_isOne",l),o.ret(o.call(e+"_eqMixed",o.getLocal("p2"),o.getLocal("p1")))),o.if(o.call(a+"_isOne",u),o.ret(o.call(e+"_eqMixed",o.getLocal("p1"),o.getLocal("p2")))),o.call(a+"_square",l,g),o.call(a+"_square",u,f),o.call(a+"_mul",r,f,_),o.call(a+"_mul",s,g,p),o.call(a+"_mul",l,g,h),o.call(a+"_mul",u,f,m),o.call(a+"_mul",c,m,L),o.call(a+"_mul",d,h,w),o.if(o.call(a+"_eq",_,p),o.if(o.call(a+"_eq",L,w),o.ret(o.i32_const(1)))),o.ret(o.i32_const(0)))}(),function(){const i=t.addFunction(e+"_doubleAffine");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder(),r=o.getLocal("p1"),c=o.i32_add(o.getLocal("p1"),o.i32_const(n)),l=o.getLocal("pr"),s=o.i32_add(o.getLocal("pr"),o.i32_const(n)),d=o.i32_add(o.getLocal("pr"),o.i32_const(2*n)),u=o.i32_const(t.alloc(n)),g=o.i32_const(t.alloc(n)),f=o.i32_const(t.alloc(n)),_=o.i32_const(t.alloc(n)),p=o.i32_const(t.alloc(n)),h=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZeroAffine",o.getLocal("p1")),[...o.call(e+"_toJacobian",o.getLocal("p1"),o.getLocal("pr")),...o.ret([])]),o.call(a+"_square",r,u),o.call(a+"_square",c,g),o.call(a+"_square",g,f),o.call(a+"_add",r,g,_),o.call(a+"_square",_,_),o.call(a+"_sub",_,u,_),o.call(a+"_sub",_,f,_),o.call(a+"_add",_,_,_),o.call(a+"_add",u,u,p),o.call(a+"_add",p,u,p),o.call(a+"_add",c,c,d),o.call(a+"_square",p,l),o.call(a+"_sub",l,_,l),o.call(a+"_sub",l,_,l),o.call(a+"_add",f,f,h),o.call(a+"_add",h,h,h),o.call(a+"_add",h,h,h),o.call(a+"_sub",_,l,s),o.call(a+"_mul",s,p,s),o.call(a+"_sub",s,h,s))}(),function(){const i=t.addFunction(e+"_double");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder(),r=o.getLocal("p1"),c=o.i32_add(o.getLocal("p1"),o.i32_const(n)),l=o.i32_add(o.getLocal("p1"),o.i32_const(2*n)),s=o.getLocal("pr"),d=o.i32_add(o.getLocal("pr"),o.i32_const(n)),u=o.i32_add(o.getLocal("pr"),o.i32_const(2*n)),g=o.i32_const(t.alloc(n)),f=o.i32_const(t.alloc(n)),_=o.i32_const(t.alloc(n)),p=o.i32_const(t.alloc(n)),h=o.i32_const(t.alloc(n)),m=o.i32_const(t.alloc(n)),L=o.i32_const(t.alloc(n)),w=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZero",o.getLocal("p1")),[...o.call(e+"_copy",o.getLocal("p1"),o.getLocal("pr")),...o.ret([])]),o.if(o.call(a+"_isOne",l),[...o.ret(o.call(e+"_doubleAffine",o.getLocal("p1"),o.getLocal("pr"))),...o.ret([])]),o.call(a+"_square",r,g),o.call(a+"_square",c,f),o.call(a+"_square",f,_),o.call(a+"_add",r,f,p),o.call(a+"_square",p,p),o.call(a+"_sub",p,g,p),o.call(a+"_sub",p,_,p),o.call(a+"_add",p,p,p),o.call(a+"_add",g,g,h),o.call(a+"_add",h,g,h),o.call(a+"_square",h,m),o.call(a+"_mul",c,l,L),o.call(a+"_add",p,p,s),o.call(a+"_sub",m,s,s),o.call(a+"_add",_,_,w),o.call(a+"_add",w,w,w),o.call(a+"_add",w,w,w),o.call(a+"_sub",p,s,d),o.call(a+"_mul",d,h,d),o.call(a+"_sub",d,w,d),o.call(a+"_add",L,L,u))}(),function(){const i=t.addFunction(e+"_addAffine");i.addParam("p1","i32"),i.addParam("p2","i32"),i.addParam("pr","i32"),i.addLocal("z1","i32");const o=i.getCodeBuilder(),r=o.getLocal("p1"),c=o.i32_add(o.getLocal("p1"),o.i32_const(n));i.addCode(o.setLocal("z1",o.i32_add(o.getLocal("p1"),o.i32_const(2*n))));const l=o.getLocal("p2"),s=o.i32_add(o.getLocal("p2"),o.i32_const(n)),d=o.getLocal("pr"),u=o.i32_add(o.getLocal("pr"),o.i32_const(n)),g=o.i32_add(o.getLocal("pr"),o.i32_const(2*n)),f=o.i32_const(t.alloc(n)),_=o.i32_const(t.alloc(n)),p=o.i32_const(t.alloc(n)),h=o.i32_const(t.alloc(n)),m=o.i32_const(t.alloc(n)),L=o.i32_const(t.alloc(n)),w=o.i32_const(t.alloc(n)),A=o.i32_const(t.alloc(n)),b=o.i32_const(t.alloc(n)),y=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZeroAffine",o.getLocal("p1")),[...o.call(e+"_copyAffine",o.getLocal("p2"),o.getLocal("pr")),...o.call(a+"_one",o.i32_add(o.getLocal("pr"),o.i32_const(2*n))),...o.ret([])]),o.if(o.call(e+"_isZeroAffine",o.getLocal("p2")),[...o.call(e+"_copyAffine",o.getLocal("p1"),o.getLocal("pr")),...o.call(a+"_one",o.i32_add(o.getLocal("pr"),o.i32_const(2*n))),...o.ret([])]),o.if(o.call(a+"_eq",r,l),o.if(o.call(a+"_eq",c,s),[...o.call(e+"_doubleAffine",o.getLocal("p2"),o.getLocal("pr")),...o.ret([])])),o.call(a+"_sub",l,r,f),o.call(a+"_sub",s,c,p),o.call(a+"_square",f,_),o.call(a+"_add",_,_,h),o.call(a+"_add",h,h,h),o.call(a+"_mul",f,h,m),o.call(a+"_add",p,p,L),o.call(a+"_mul",r,h,A),o.call(a+"_square",L,w),o.call(a+"_add",A,A,b),o.call(a+"_sub",w,m,d),o.call(a+"_sub",d,b,d),o.call(a+"_mul",c,m,y),o.call(a+"_add",y,y,y),o.call(a+"_sub",A,d,u),o.call(a+"_mul",u,L,u),o.call(a+"_sub",u,y,u),o.call(a+"_add",f,f,g))}(),function(){const i=t.addFunction(e+"_addMixed");i.addParam("p1","i32"),i.addParam("p2","i32"),i.addParam("pr","i32"),i.addLocal("z1","i32");const o=i.getCodeBuilder(),r=o.getLocal("p1"),c=o.i32_add(o.getLocal("p1"),o.i32_const(n));i.addCode(o.setLocal("z1",o.i32_add(o.getLocal("p1"),o.i32_const(2*n))));const l=o.getLocal("z1"),s=o.getLocal("p2"),d=o.i32_add(o.getLocal("p2"),o.i32_const(n)),u=o.getLocal("pr"),g=o.i32_add(o.getLocal("pr"),o.i32_const(n)),f=o.i32_add(o.getLocal("pr"),o.i32_const(2*n)),_=o.i32_const(t.alloc(n)),p=o.i32_const(t.alloc(n)),h=o.i32_const(t.alloc(n)),m=o.i32_const(t.alloc(n)),L=o.i32_const(t.alloc(n)),w=o.i32_const(t.alloc(n)),A=o.i32_const(t.alloc(n)),b=o.i32_const(t.alloc(n)),y=o.i32_const(t.alloc(n)),I=o.i32_const(t.alloc(n)),C=o.i32_const(t.alloc(n)),F=o.i32_const(t.alloc(n)),x=o.i32_const(t.alloc(n)),v=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZero",o.getLocal("p1")),[...o.call(e+"_copyAffine",o.getLocal("p2"),o.getLocal("pr")),...o.call(a+"_one",o.i32_add(o.getLocal("pr"),o.i32_const(2*n))),...o.ret([])]),o.if(o.call(e+"_isZeroAffine",o.getLocal("p2")),[...o.call(e+"_copy",o.getLocal("p1"),o.getLocal("pr")),...o.ret([])]),o.if(o.call(a+"_isOne",l),[...o.call(e+"_addAffine",r,s,u),...o.ret([])]),o.call(a+"_square",l,_),o.call(a+"_mul",s,_,p),o.call(a+"_mul",l,_,h),o.call(a+"_mul",d,h,m),o.if(o.call(a+"_eq",r,p),o.if(o.call(a+"_eq",c,m),[...o.call(e+"_doubleAffine",o.getLocal("p2"),o.getLocal("pr")),...o.ret([])])),o.call(a+"_sub",p,r,L),o.call(a+"_sub",m,c,A),o.call(a+"_square",L,w),o.call(a+"_add",w,w,b),o.call(a+"_add",b,b,b),o.call(a+"_mul",L,b,y),o.call(a+"_add",A,A,I),o.call(a+"_mul",r,b,F),o.call(a+"_square",I,C),o.call(a+"_add",F,F,x),o.call(a+"_sub",C,y,u),o.call(a+"_sub",u,x,u),o.call(a+"_mul",c,y,v),o.call(a+"_add",v,v,v),o.call(a+"_sub",F,u,g),o.call(a+"_mul",g,I,g),o.call(a+"_sub",g,v,g),o.call(a+"_add",l,L,f),o.call(a+"_square",f,f),o.call(a+"_sub",f,_,f),o.call(a+"_sub",f,w,f))}(),function(){const i=t.addFunction(e+"_add");i.addParam("p1","i32"),i.addParam("p2","i32"),i.addParam("pr","i32"),i.addLocal("z1","i32"),i.addLocal("z2","i32");const o=i.getCodeBuilder(),r=o.getLocal("p1"),c=o.i32_add(o.getLocal("p1"),o.i32_const(n));i.addCode(o.setLocal("z1",o.i32_add(o.getLocal("p1"),o.i32_const(2*n))));const l=o.getLocal("z1"),s=o.getLocal("p2"),d=o.i32_add(o.getLocal("p2"),o.i32_const(n));i.addCode(o.setLocal("z2",o.i32_add(o.getLocal("p2"),o.i32_const(2*n))));const u=o.getLocal("z2"),g=o.getLocal("pr"),f=o.i32_add(o.getLocal("pr"),o.i32_const(n)),_=o.i32_add(o.getLocal("pr"),o.i32_const(2*n)),p=o.i32_const(t.alloc(n)),h=o.i32_const(t.alloc(n)),m=o.i32_const(t.alloc(n)),L=o.i32_const(t.alloc(n)),w=o.i32_const(t.alloc(n)),A=o.i32_const(t.alloc(n)),b=o.i32_const(t.alloc(n)),y=o.i32_const(t.alloc(n)),I=o.i32_const(t.alloc(n)),C=o.i32_const(t.alloc(n)),F=o.i32_const(t.alloc(n)),x=o.i32_const(t.alloc(n)),v=o.i32_const(t.alloc(n)),E=o.i32_const(t.alloc(n)),B=o.i32_const(t.alloc(n)),S=o.i32_const(t.alloc(n)),G=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZero",o.getLocal("p1")),[...o.call(e+"_copy",o.getLocal("p2"),o.getLocal("pr")),...o.ret([])]),o.if(o.call(e+"_isZero",o.getLocal("p2")),[...o.call(e+"_copy",o.getLocal("p1"),o.getLocal("pr")),...o.ret([])]),o.if(o.call(a+"_isOne",l),[...o.call(e+"_addMixed",s,r,g),...o.ret([])]),o.if(o.call(a+"_isOne",u),[...o.call(e+"_addMixed",r,s,g),...o.ret([])]),o.call(a+"_square",l,p),o.call(a+"_square",u,h),o.call(a+"_mul",r,h,m),o.call(a+"_mul",s,p,L),o.call(a+"_mul",l,p,w),o.call(a+"_mul",u,h,A),o.call(a+"_mul",c,A,b),o.call(a+"_mul",d,w,y),o.if(o.call(a+"_eq",m,L),o.if(o.call(a+"_eq",b,y),[...o.call(e+"_double",o.getLocal("p1"),o.getLocal("pr")),...o.ret([])])),o.call(a+"_sub",L,m,I),o.call(a+"_sub",y,b,C),o.call(a+"_add",I,I,F),o.call(a+"_square",F,F),o.call(a+"_mul",I,F,x),o.call(a+"_add",C,C,v),o.call(a+"_mul",m,F,B),o.call(a+"_square",v,E),o.call(a+"_add",B,B,S),o.call(a+"_sub",E,x,g),o.call(a+"_sub",g,S,g),o.call(a+"_mul",b,x,G),o.call(a+"_add",G,G,G),o.call(a+"_sub",B,g,f),o.call(a+"_mul",f,v,f),o.call(a+"_sub",f,G,f),o.call(a+"_add",l,u,_),o.call(a+"_square",_,_),o.call(a+"_sub",_,p,_),o.call(a+"_sub",_,h,_),o.call(a+"_mul",_,I,_))}(),function(){const i=t.addFunction(e+"_negAffine");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder(),r=o.getLocal("p1"),c=o.i32_add(o.getLocal("p1"),o.i32_const(n)),l=o.getLocal("pr"),s=o.i32_add(o.getLocal("pr"),o.i32_const(n));i.addCode(o.call(a+"_copy",r,l),o.call(a+"_neg",c,s))}(),function(){const i=t.addFunction(e+"_neg");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder(),r=o.getLocal("p1"),c=o.i32_add(o.getLocal("p1"),o.i32_const(n)),l=o.i32_add(o.getLocal("p1"),o.i32_const(2*n)),s=o.getLocal("pr"),d=o.i32_add(o.getLocal("pr"),o.i32_const(n)),u=o.i32_add(o.getLocal("pr"),o.i32_const(2*n));i.addCode(o.call(a+"_copy",r,s),o.call(a+"_neg",c,d),o.call(a+"_copy",l,u))}(),function(){const a=t.addFunction(e+"_subAffine");a.addParam("p1","i32"),a.addParam("p2","i32"),a.addParam("pr","i32");const i=a.getCodeBuilder(),o=i.i32_const(t.alloc(3*n));a.addCode(i.call(e+"_negAffine",i.getLocal("p2"),o),i.call(e+"_addAffine",i.getLocal("p1"),o,i.getLocal("pr")))}(),function(){const a=t.addFunction(e+"_subMixed");a.addParam("p1","i32"),a.addParam("p2","i32"),a.addParam("pr","i32");const i=a.getCodeBuilder(),o=i.i32_const(t.alloc(3*n));a.addCode(i.call(e+"_negAffine",i.getLocal("p2"),o),i.call(e+"_addMixed",i.getLocal("p1"),o,i.getLocal("pr")))}(),function(){const a=t.addFunction(e+"_sub");a.addParam("p1","i32"),a.addParam("p2","i32"),a.addParam("pr","i32");const i=a.getCodeBuilder(),o=i.i32_const(t.alloc(3*n));a.addCode(i.call(e+"_neg",i.getLocal("p2"),o),i.call(e+"_add",i.getLocal("p1"),o,i.getLocal("pr")))}(),function(){const i=t.addFunction(e+"_fromMontgomeryAffine");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder();i.addCode(o.call(a+"_fromMontgomery",o.getLocal("p1"),o.getLocal("pr")));for(let t=1;t<2;t++)i.addCode(o.call(a+"_fromMontgomery",o.i32_add(o.getLocal("p1"),o.i32_const(t*n)),o.i32_add(o.getLocal("pr"),o.i32_const(t*n))))}(),function(){const i=t.addFunction(e+"_fromMontgomery");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder();i.addCode(o.call(a+"_fromMontgomery",o.getLocal("p1"),o.getLocal("pr")));for(let t=1;t<3;t++)i.addCode(o.call(a+"_fromMontgomery",o.i32_add(o.getLocal("p1"),o.i32_const(t*n)),o.i32_add(o.getLocal("pr"),o.i32_const(t*n))))}(),function(){const i=t.addFunction(e+"_toMontgomeryAffine");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder();i.addCode(o.call(a+"_toMontgomery",o.getLocal("p1"),o.getLocal("pr")));for(let t=1;t<2;t++)i.addCode(o.call(a+"_toMontgomery",o.i32_add(o.getLocal("p1"),o.i32_const(t*n)),o.i32_add(o.getLocal("pr"),o.i32_const(t*n))))}(),function(){const i=t.addFunction(e+"_toMontgomery");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder();i.addCode(o.call(a+"_toMontgomery",o.getLocal("p1"),o.getLocal("pr")));for(let t=1;t<3;t++)i.addCode(o.call(a+"_toMontgomery",o.i32_add(o.getLocal("p1"),o.i32_const(t*n)),o.i32_add(o.getLocal("pr"),o.i32_const(t*n))))}(),function(){const i=t.addFunction(e+"_toAffine");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder(),r=o.getLocal("p1"),c=o.i32_add(o.getLocal("p1"),o.i32_const(n)),l=o.i32_add(o.getLocal("p1"),o.i32_const(2*n)),s=o.getLocal("pr"),d=o.i32_add(o.getLocal("pr"),o.i32_const(n)),u=o.i32_const(t.alloc(n)),g=o.i32_const(t.alloc(n)),f=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZero",o.getLocal("p1")),[...o.call(a+"_zero",s),...o.call(a+"_zero",d)],[...o.call(a+"_inverse",l,u),...o.call(a+"_square",u,g),...o.call(a+"_mul",u,g,f),...o.call(a+"_mul",r,g,s),...o.call(a+"_mul",c,f,d)]))}(),function(){const o=t.addFunction(e+"_inCurveAffine");o.addParam("pIn","i32"),o.setReturnType("i32");const r=o.getCodeBuilder(),c=r.getLocal("pIn"),l=r.i32_add(r.getLocal("pIn"),r.i32_const(n)),s=r.i32_const(t.alloc(n)),d=r.i32_const(t.alloc(n));o.addCode(r.call(a+"_square",l,s),r.call(a+"_square",c,d),r.call(a+"_mul",c,d,d),r.call(a+"_add",d,r.i32_const(i),d),r.ret(r.call(a+"_eq",s,d)))}(),function(){const a=t.addFunction(e+"_inCurve");a.addParam("pIn","i32"),a.setReturnType("i32");const i=a.getCodeBuilder(),o=i.i32_const(t.alloc(2*n));a.addCode(i.call(e+"_toAffine",i.getLocal("pIn"),o),i.ret(i.call(e+"_inCurveAffine",o)))}(),function(){const i=t.addFunction(e+"_batchToAffine");i.addParam("pIn","i32"),i.addParam("n","i32"),i.addParam("pOut","i32"),i.addLocal("pAux","i32"),i.addLocal("itIn","i32"),i.addLocal("itAux","i32"),i.addLocal("itOut","i32"),i.addLocal("i","i32");const o=i.getCodeBuilder(),r=o.i32_const(t.alloc(n));i.addCode(o.setLocal("pAux",o.i32_load(o.i32_const(0))),o.i32_store(o.i32_const(0),o.i32_add(o.getLocal("pAux"),o.i32_mul(o.getLocal("n"),o.i32_const(n)))),o.call(a+"_batchInverse",o.i32_add(o.getLocal("pIn"),o.i32_const(2*n)),o.i32_const(3*n),o.getLocal("n"),o.getLocal("pAux"),o.i32_const(n)),o.setLocal("itIn",o.getLocal("pIn")),o.setLocal("itAux",o.getLocal("pAux")),o.setLocal("itOut",o.getLocal("pOut")),o.setLocal("i",o.i32_const(0)),o.block(o.loop(o.br_if(1,o.i32_eq(o.getLocal("i"),o.getLocal("n"))),o.if(o.call(a+"_isZero",o.getLocal("itAux")),[...o.call(a+"_zero",o.getLocal("itOut")),...o.call(a+"_zero",o.i32_add(o.getLocal("itOut"),o.i32_const(n)))],[...o.call(a+"_mul",o.getLocal("itAux"),o.i32_add(o.getLocal("itIn"),o.i32_const(n)),r),...o.call(a+"_square",o.getLocal("itAux"),o.getLocal("itAux")),...o.call(a+"_mul",o.getLocal("itAux"),o.getLocal("itIn"),o.getLocal("itOut")),...o.call(a+"_mul",o.getLocal("itAux"),r,o.i32_add(o.getLocal("itOut"),o.i32_const(n)))]),o.setLocal("itIn",o.i32_add(o.getLocal("itIn"),o.i32_const(3*n))),o.setLocal("itOut",o.i32_add(o.getLocal("itOut"),o.i32_const(2*n))),o.setLocal("itAux",o.i32_add(o.getLocal("itAux"),o.i32_const(n))),o.setLocal("i",o.i32_add(o.getLocal("i"),o.i32_const(1))),o.br(0))),o.i32_store(o.i32_const(0),o.getLocal("pAux")))}(),function(){const i=t.addFunction(e+"_normalize");i.addParam("p1","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder(),r=o.getLocal("p1"),c=o.i32_add(o.getLocal("p1"),o.i32_const(n)),l=o.i32_add(o.getLocal("p1"),o.i32_const(2*n)),s=o.getLocal("pr"),d=o.i32_add(o.getLocal("pr"),o.i32_const(n)),u=o.i32_add(o.getLocal("pr"),o.i32_const(2*n)),g=o.i32_const(t.alloc(n)),f=o.i32_const(t.alloc(n)),_=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZero",o.getLocal("p1")),o.call(e+"_zero",o.getLocal("pr")),[...o.call(a+"_inverse",l,g),...o.call(a+"_square",g,f),...o.call(a+"_mul",g,f,_),...o.call(a+"_mul",r,f,s),...o.call(a+"_mul",c,_,d),...o.call(a+"_one",u)]))}(),function(){const a=t.addFunction(e+"__reverseBytes");a.addParam("pIn","i32"),a.addParam("n","i32"),a.addParam("pOut","i32"),a.addLocal("itOut","i32"),a.addLocal("itIn","i32");const i=a.getCodeBuilder();a.addCode(i.setLocal("itOut",i.i32_sub(i.i32_add(i.getLocal("pOut"),i.getLocal("n")),i.i32_const(1))),i.setLocal("itIn",i.getLocal("pIn")),i.block(i.loop(i.br_if(1,i.i32_lt_s(i.getLocal("itOut"),i.getLocal("pOut"))),i.i32_store8(i.getLocal("itOut"),i.i32_load8_u(i.getLocal("itIn"))),i.setLocal("itOut",i.i32_sub(i.getLocal("itOut"),i.i32_const(1))),i.setLocal("itIn",i.i32_add(i.getLocal("itIn"),i.i32_const(1))),i.br(0))))}(),function(){const a=t.addFunction(e+"_LEMtoU");a.addParam("pIn","i32"),a.addParam("pOut","i32");const i=a.getCodeBuilder(),o=t.alloc(2*n),r=i.i32_const(o),c=i.i32_const(o),l=i.i32_const(o+n);a.addCode(i.if(i.call(e+"_isZeroAffine",i.getLocal("pIn")),[...i.call(e+"_zeroAffine",i.getLocal("pOut")),...i.i32_store8(i.getLocal("pOut"),i.i32_const(64)),...i.ret([])]),i.call(e+"_fromMontgomeryAffine",i.getLocal("pIn"),r),i.call(e+"__reverseBytes",c,i.i32_const(n),i.getLocal("pOut")),i.call(e+"__reverseBytes",l,i.i32_const(n),i.i32_add(i.getLocal("pOut"),i.i32_const(n))))}(),function(){const i=t.addFunction(e+"_LEMtoC");i.addParam("pIn","i32"),i.addParam("pOut","i32");const o=i.getCodeBuilder(),r=o.i32_const(t.alloc(n));i.addCode(o.if(o.call(e+"_isZero",o.getLocal("pIn")),[...o.call(a+"_zero",o.getLocal("pOut")),...o.i32_store8(o.getLocal("pOut"),o.i32_const(64)),...o.ret([])]),o.call(a+"_fromMontgomery",o.getLocal("pIn"),r),o.call(e+"__reverseBytes",r,o.i32_const(n),o.getLocal("pOut")),o.if(o.i32_eq(o.call(a+"_sign",o.i32_add(o.getLocal("pIn"),o.i32_const(n))),o.i32_const(-1)),o.i32_store8(o.getLocal("pOut"),o.i32_or(o.i32_load8_u(o.getLocal("pOut")),o.i32_const(128)))))}(),function(){const a=t.addFunction(e+"_UtoLEM");a.addParam("pIn","i32"),a.addParam("pOut","i32");const i=a.getCodeBuilder(),o=t.alloc(2*n),r=i.i32_const(o),c=i.i32_const(o),l=i.i32_const(o+n);a.addCode(i.if(i.i32_and(i.i32_load8_u(i.getLocal("pIn")),i.i32_const(64)),[...i.call(e+"_zeroAffine",i.getLocal("pOut")),...i.ret([])]),i.call(e+"__reverseBytes",i.getLocal("pIn"),i.i32_const(n),c),i.call(e+"__reverseBytes",i.i32_add(i.getLocal("pIn"),i.i32_const(n)),i.i32_const(n),l),i.call(e+"_toMontgomeryAffine",r,i.getLocal("pOut")))}(),function(){const o=t.addFunction(e+"_CtoLEM");o.addParam("pIn","i32"),o.addParam("pOut","i32"),o.addLocal("firstByte","i32"),o.addLocal("greatest","i32");const r=o.getCodeBuilder(),c=t.alloc(2*n),l=r.i32_const(c),s=r.i32_const(c+n);o.addCode(r.setLocal("firstByte",r.i32_load8_u(r.getLocal("pIn"))),r.if(r.i32_and(r.getLocal("firstByte"),r.i32_const(64)),[...r.call(e+"_zeroAffine",r.getLocal("pOut")),...r.ret([])]),r.setLocal("greatest",r.i32_and(r.getLocal("firstByte"),r.i32_const(128))),r.call(a+"_copy",r.getLocal("pIn"),s),r.i32_store8(s,r.i32_and(r.getLocal("firstByte"),r.i32_const(63))),r.call(e+"__reverseBytes",s,r.i32_const(n),l),r.call(a+"_toMontgomery",l,r.getLocal("pOut")),r.call(a+"_square",r.getLocal("pOut"),s),r.call(a+"_mul",r.getLocal("pOut"),s,s),r.call(a+"_add",s,r.i32_const(i),s),r.call(a+"_sqrt",s,s),r.call(a+"_neg",s,l),r.if(r.i32_eq(r.call(a+"_sign",s),r.i32_const(-1)),r.if(r.getLocal("greatest"),r.call(a+"_copy",s,r.i32_add(r.getLocal("pOut"),r.i32_const(n))),r.call(a+"_neg",s,r.i32_add(r.getLocal("pOut"),r.i32_const(n)))),r.if(r.getLocal("greatest"),r.call(a+"_neg",s,r.i32_add(r.getLocal("pOut"),r.i32_const(n))),r.call(a+"_copy",s,r.i32_add(r.getLocal("pOut"),r.i32_const(n))))))}(),Pt(t,e+"_batchLEMtoU",e+"_LEMtoU",2*n,2*n),Pt(t,e+"_batchLEMtoC",e+"_LEMtoC",2*n,n),Pt(t,e+"_batchUtoLEM",e+"_UtoLEM",2*n,2*n),Pt(t,e+"_batchCtoLEM",e+"_CtoLEM",n,2*n,!0),Pt(t,e+"_batchToJacobian",e+"_toJacobian",2*n,3*n,!0),kt(t,e,e+"_multiexp",e+"_add",3*n),kt(t,e,e+"_multiexpAffine",e+"_addMixed",2*n),Mt(t,e+"_timesScalar",3*n,e+"_add",e+"_double",e+"_sub",e+"_copy",e+"_zero"),Mt(t,e+"_timesScalarAffine",2*n,e+"_addMixed",e+"_double",e+"_subMixed",e+"_copyAffine",e+"_zero"),t.exportFunction(e+"_isZero"),t.exportFunction(e+"_isZeroAffine"),t.exportFunction(e+"_eq"),t.exportFunction(e+"_eqMixed"),t.exportFunction(e+"_eqAffine"),t.exportFunction(e+"_copy"),t.exportFunction(e+"_copyAffine"),t.exportFunction(e+"_zero"),t.exportFunction(e+"_zeroAffine"),t.exportFunction(e+"_double"),t.exportFunction(e+"_doubleAffine"),t.exportFunction(e+"_add"),t.exportFunction(e+"_addMixed"),t.exportFunction(e+"_addAffine"),t.exportFunction(e+"_neg"),t.exportFunction(e+"_negAffine"),t.exportFunction(e+"_sub"),t.exportFunction(e+"_subMixed"),t.exportFunction(e+"_subAffine"),t.exportFunction(e+"_fromMontgomery"),t.exportFunction(e+"_fromMontgomeryAffine"),t.exportFunction(e+"_toMontgomery"),t.exportFunction(e+"_toMontgomeryAffine"),t.exportFunction(e+"_timesScalar"),t.exportFunction(e+"_timesScalarAffine"),t.exportFunction(e+"_normalize"),t.exportFunction(e+"_LEMtoU"),t.exportFunction(e+"_LEMtoC"),t.exportFunction(e+"_UtoLEM"),t.exportFunction(e+"_CtoLEM"),t.exportFunction(e+"_batchLEMtoU"),t.exportFunction(e+"_batchLEMtoC"),t.exportFunction(e+"_batchUtoLEM"),t.exportFunction(e+"_batchCtoLEM"),t.exportFunction(e+"_toAffine"),t.exportFunction(e+"_toJacobian"),t.exportFunction(e+"_batchToAffine"),t.exportFunction(e+"_batchToJacobian"),t.exportFunction(e+"_inCurve"),t.exportFunction(e+"_inCurveAffine"),e},Nt=function(t,e,a,i,o){const n=8*t.modules[i].n64,r=8*t.modules[a].n64,c=t.modules[i].q;let l=c.minus(u(1)),s=0;for(;!l.isOdd();)s++,l=l.shiftRight(1);let d=u(2);for(;d.modPow(c.shiftRight(1),c).equals(1);)d=d.add(1);const g=new Array(s+1);g[s]=d.modPow(l,c);let f=s-1;for(;f>=0;)g[f]=g[f+1].modPow(2,c),f--;const _=[],p=u(1).shiftLeft(8*n).mod(c);for(let t=0;t<g.length;t++){const e=g[t].times(p).mod(c);_.push(...Et(e,n))}const h=t.alloc(_),m=new Array(s+1);m[0]=u(1);for(let t=1;t<=s;t++)m[t]=m[t-1].times(2);const L=[];for(let t=0;t<=s;t++){const e=m[t].modInv(c).times(p).mod(c);L.push(...Et(e,n))}const w=t.alloc(L),A=d.modPow(2,c),b=[],y=[];for(let t=0;t<=s;t++){const e=A.modPow(u(2).pow(t),c),a=c.add(u.one).minus(e).modInv(c);b.push(...Et(e.times(p).mod(c),n)),y.push(...Et(a.times(p).mod(c),n))}const I=t.alloc(b),C=t.alloc(y);function F(t){let e=0;for(let a=0;a<8;a++)t&1<<a&&(e|=128>>a);return e}const x=Array(256);for(let t=0;t<256;t++)x[t]=F(t);const v=t.alloc(x);function E(){const a=t.addFunction(e+"_fft");a.addParam("px","i32"),a.addParam("n","i32"),a.addLocal("bits","i32");const o=a.getCodeBuilder(),r=o.i32_const(t.alloc(n));a.addCode(o.setLocal("bits",o.call(e+"__log2",o.getLocal("n"))),o.call(i+"_one",r),o.call(e+"_rawfft",o.getLocal("px"),o.getLocal("bits"),o.i32_const(0),r))}!function(){const a=t.addFunction(e+"__rev");a.addParam("x","i32"),a.addParam("bits","i32"),a.setReturnType("i32");const i=a.getCodeBuilder();a.addCode(i.i32_rotl(i.i32_add(i.i32_add(i.i32_shl(i.i32_load8_u(i.i32_and(i.getLocal("x"),i.i32_const(255)),v,0),i.i32_const(24)),i.i32_shl(i.i32_load8_u(i.i32_and(i.i32_shr_u(i.getLocal("x"),i.i32_const(8)),i.i32_const(255)),v,0),i.i32_const(16))),i.i32_add(i.i32_shl(i.i32_load8_u(i.i32_and(i.i32_shr_u(i.getLocal("x"),i.i32_const(16)),i.i32_const(255)),v,0),i.i32_const(8)),i.i32_load8_u(i.i32_and(i.i32_shr_u(i.getLocal("x"),i.i32_const(24)),i.i32_const(255)),v,0))),i.getLocal("bits")))}(),function(){const i=t.addFunction(e+"__reversePermutation");i.addParam("px","i32"),i.addParam("bits","i32"),i.addLocal("n","i32"),i.addLocal("i","i32"),i.addLocal("ri","i32"),i.addLocal("idx1","i32"),i.addLocal("idx2","i32");const o=i.getCodeBuilder(),n=o.i32_const(t.alloc(r));i.addCode(o.setLocal("n",o.i32_shl(o.i32_const(1),o.getLocal("bits"))),o.setLocal("i",o.i32_const(0)),o.block(o.loop(o.br_if(1,o.i32_eq(o.getLocal("i"),o.getLocal("n"))),o.setLocal("idx1",o.i32_add(o.getLocal("px"),o.i32_mul(o.getLocal("i"),o.i32_const(r)))),o.setLocal("ri",o.call(e+"__rev",o.getLocal("i"),o.getLocal("bits"))),o.setLocal("idx2",o.i32_add(o.getLocal("px"),o.i32_mul(o.getLocal("ri"),o.i32_const(r)))),o.if(o.i32_lt_u(o.getLocal("i"),o.getLocal("ri")),[...o.call(a+"_copy",o.getLocal("idx1"),n),...o.call(a+"_copy",o.getLocal("idx2"),o.getLocal("idx1")),...o.call(a+"_copy",n,o.getLocal("idx2"))]),o.setLocal("i",o.i32_add(o.getLocal("i"),o.i32_const(1))),o.br(0))))}(),function(){const n=t.addFunction(e+"__fftFinal");n.addParam("px","i32"),n.addParam("bits","i32"),n.addParam("reverse","i32"),n.addParam("mulFactor","i32"),n.addLocal("n","i32"),n.addLocal("ndiv2","i32"),n.addLocal("pInv2","i32"),n.addLocal("i","i32"),n.addLocal("mask","i32"),n.addLocal("idx1","i32"),n.addLocal("idx2","i32");const c=n.getCodeBuilder(),l=c.i32_const(t.alloc(r));n.addCode(c.if(c.i32_and(c.i32_eqz(c.getLocal("reverse")),c.call(i+"_isOne",c.getLocal("mulFactor"))),c.ret([])),c.setLocal("n",c.i32_shl(c.i32_const(1),c.getLocal("bits"))),c.setLocal("mask",c.i32_sub(c.getLocal("n"),c.i32_const(1))),c.setLocal("i",c.i32_const(1)),c.setLocal("ndiv2",c.i32_shr_u(c.getLocal("n"),c.i32_const(1))),c.block(c.loop(c.br_if(1,c.i32_ge_u(c.getLocal("i"),c.getLocal("ndiv2"))),c.setLocal("idx1",c.i32_add(c.getLocal("px"),c.i32_mul(c.getLocal("i"),c.i32_const(r)))),c.setLocal("idx2",c.i32_add(c.getLocal("px"),c.i32_mul(c.i32_sub(c.getLocal("n"),c.getLocal("i")),c.i32_const(r)))),c.if(c.getLocal("reverse"),c.if(c.call(i+"_isOne",c.getLocal("mulFactor")),[...c.call(a+"_copy",c.getLocal("idx1"),l),...c.call(a+"_copy",c.getLocal("idx2"),c.getLocal("idx1")),...c.call(a+"_copy",l,c.getLocal("idx2"))],[...c.call(a+"_copy",c.getLocal("idx1"),l),...c.call(o,c.getLocal("idx2"),c.getLocal("mulFactor"),c.getLocal("idx1")),...c.call(o,l,c.getLocal("mulFactor"),c.getLocal("idx2"))]),c.if(c.call(i+"_isOne",c.getLocal("mulFactor")),[],[...c.call(o,c.getLocal("idx1"),c.getLocal("mulFactor"),c.getLocal("idx1")),...c.call(o,c.getLocal("idx2"),c.getLocal("mulFactor"),c.getLocal("idx2"))])),c.setLocal("i",c.i32_add(c.getLocal("i"),c.i32_const(1))),c.br(0))),c.if(c.call(i+"_isOne",c.getLocal("mulFactor")),[],[...c.call(o,c.getLocal("px"),c.getLocal("mulFactor"),c.getLocal("px")),...c.setLocal("idx2",c.i32_add(c.getLocal("px"),c.i32_mul(c.getLocal("ndiv2"),c.i32_const(r)))),...c.call(o,c.getLocal("idx2"),c.getLocal("mulFactor"),c.getLocal("idx2"))]))}(),function(){const c=t.addFunction(e+"_rawfft");c.addParam("px","i32"),c.addParam("bits","i32"),c.addParam("reverse","i32"),c.addParam("mulFactor","i32"),c.addLocal("s","i32"),c.addLocal("k","i32"),c.addLocal("j","i32"),c.addLocal("m","i32"),c.addLocal("mdiv2","i32"),c.addLocal("n","i32"),c.addLocal("pwm","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32");const l=c.getCodeBuilder(),s=l.i32_const(t.alloc(n)),d=l.i32_const(t.alloc(r)),u=l.i32_const(t.alloc(r));c.addCode(l.call(e+"__reversePermutation",l.getLocal("px"),l.getLocal("bits")),l.setLocal("n",l.i32_shl(l.i32_const(1),l.getLocal("bits"))),l.setLocal("s",l.i32_const(1)),l.block(l.loop(l.br_if(1,l.i32_gt_u(l.getLocal("s"),l.getLocal("bits"))),l.setLocal("m",l.i32_shl(l.i32_const(1),l.getLocal("s"))),l.setLocal("pwm",l.i32_add(l.i32_const(h),l.i32_mul(l.getLocal("s"),l.i32_const(n)))),l.setLocal("k",l.i32_const(0)),l.block(l.loop(l.br_if(1,l.i32_ge_u(l.getLocal("k"),l.getLocal("n"))),l.call(i+"_one",s),l.setLocal("mdiv2",l.i32_shr_u(l.getLocal("m"),l.i32_const(1))),l.setLocal("j",l.i32_const(0)),l.block(l.loop(l.br_if(1,l.i32_ge_u(l.getLocal("j"),l.getLocal("mdiv2"))),l.setLocal("idx1",l.i32_add(l.getLocal("px"),l.i32_mul(l.i32_add(l.getLocal("k"),l.getLocal("j")),l.i32_const(r)))),l.setLocal("idx2",l.i32_add(l.getLocal("idx1"),l.i32_mul(l.getLocal("mdiv2"),l.i32_const(r)))),l.call(o,l.getLocal("idx2"),s,d),l.call(a+"_copy",l.getLocal("idx1"),u),l.call(a+"_add",u,d,l.getLocal("idx1")),l.call(a+"_sub",u,d,l.getLocal("idx2")),l.call(i+"_mul",s,l.getLocal("pwm"),s),l.setLocal("j",l.i32_add(l.getLocal("j"),l.i32_const(1))),l.br(0))),l.setLocal("k",l.i32_add(l.getLocal("k"),l.getLocal("m"))),l.br(0))),l.setLocal("s",l.i32_add(l.getLocal("s"),l.i32_const(1))),l.br(0))),l.call(e+"__fftFinal",l.getLocal("px"),l.getLocal("bits"),l.getLocal("reverse"),l.getLocal("mulFactor")))}(),function(){const a=t.addFunction(e+"__log2");a.addParam("n","i32"),a.setReturnType("i32"),a.addLocal("bits","i32"),a.addLocal("aux","i32");const i=a.getCodeBuilder();a.addCode(i.setLocal("aux",i.i32_shr_u(i.getLocal("n"),i.i32_const(1)))),a.addCode(i.setLocal("bits",i.i32_const(0))),a.addCode(i.block(i.loop(i.br_if(1,i.i32_eqz(i.getLocal("aux"))),i.setLocal("aux",i.i32_shr_u(i.getLocal("aux"),i.i32_const(1))),i.setLocal("bits",i.i32_add(i.getLocal("bits"),i.i32_const(1))),i.br(0)))),a.addCode(i.if(i.i32_ne(i.getLocal("n"),i.i32_shl(i.i32_const(1),i.getLocal("bits"))),i.unreachable())),a.addCode(i.if(i.i32_gt_u(i.getLocal("bits"),i.i32_const(s)),i.unreachable())),a.addCode(i.getLocal("bits"))}(),E(),function(){const a=t.addFunction(e+"_ifft");a.addParam("px","i32"),a.addParam("n","i32"),a.addLocal("bits","i32"),a.addLocal("pInv2","i32");const i=a.getCodeBuilder();a.addCode(i.setLocal("bits",i.call(e+"__log2",i.getLocal("n"))),i.setLocal("pInv2",i.i32_add(i.i32_const(w),i.i32_mul(i.getLocal("bits"),i.i32_const(n)))),i.call(e+"_rawfft",i.getLocal("px"),i.getLocal("bits"),i.i32_const(1),i.getLocal("pInv2")))}(),function(){const c=t.addFunction(e+"_fftJoin");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32");const l=c.getCodeBuilder(),s=l.i32_const(t.alloc(n)),d=l.i32_const(t.alloc(r)),u=l.i32_const(t.alloc(r));c.addCode(l.call(i+"_copy",l.getLocal("first"),s),l.setLocal("i",l.i32_const(0)),l.block(l.loop(l.br_if(1,l.i32_eq(l.getLocal("i"),l.getLocal("n"))),l.setLocal("idx1",l.i32_add(l.getLocal("pBuff1"),l.i32_mul(l.getLocal("i"),l.i32_const(r)))),l.setLocal("idx2",l.i32_add(l.getLocal("pBuff2"),l.i32_mul(l.getLocal("i"),l.i32_const(r)))),l.call(o,l.getLocal("idx2"),s,d),l.call(a+"_copy",l.getLocal("idx1"),u),l.call(a+"_add",u,d,l.getLocal("idx1")),l.call(a+"_sub",u,d,l.getLocal("idx2")),l.call(i+"_mul",s,l.getLocal("inc"),s),l.setLocal("i",l.i32_add(l.getLocal("i"),l.i32_const(1))),l.br(0))))}(),function(){const c=t.addFunction(e+"_fftJoinExt");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addParam("totalBits","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("pShiftToM","i32");const l=c.getCodeBuilder(),s=l.i32_const(t.alloc(n)),d=l.i32_const(t.alloc(r));c.addCode(l.setLocal("pShiftToM",l.i32_add(l.i32_const(I),l.i32_mul(l.getLocal("totalBits"),l.i32_const(n)))),l.call(i+"_copy",l.getLocal("first"),s),l.setLocal("i",l.i32_const(0)),l.block(l.loop(l.br_if(1,l.i32_eq(l.getLocal("i"),l.getLocal("n"))),l.setLocal("idx1",l.i32_add(l.getLocal("pBuff1"),l.i32_mul(l.getLocal("i"),l.i32_const(r)))),l.setLocal("idx2",l.i32_add(l.getLocal("pBuff2"),l.i32_mul(l.getLocal("i"),l.i32_const(r)))),l.call(a+"_add",l.getLocal("idx1"),l.getLocal("idx2"),d),l.call(o,l.getLocal("idx2"),l.getLocal("pShiftToM"),l.getLocal("idx2")),l.call(a+"_add",l.getLocal("idx1"),l.getLocal("idx2"),l.getLocal("idx2")),l.call(o,l.getLocal("idx2"),s,l.getLocal("idx2")),l.call(a+"_copy",d,l.getLocal("idx1")),l.call(i+"_mul",s,l.getLocal("inc"),s),l.setLocal("i",l.i32_add(l.getLocal("i"),l.i32_const(1))),l.br(0))))}(),function(){const c=t.addFunction(e+"_fftJoinExtInv");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addParam("totalBits","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("pShiftToM","i32"),c.addLocal("pSConst","i32");const l=c.getCodeBuilder(),s=l.i32_const(t.alloc(n)),d=l.i32_const(t.alloc(r));c.addCode(l.setLocal("pShiftToM",l.i32_add(l.i32_const(I),l.i32_mul(l.getLocal("totalBits"),l.i32_const(n)))),l.setLocal("pSConst",l.i32_add(l.i32_const(C),l.i32_mul(l.getLocal("totalBits"),l.i32_const(n)))),l.call(i+"_copy",l.getLocal("first"),s),l.setLocal("i",l.i32_const(0)),l.block(l.loop(l.br_if(1,l.i32_eq(l.getLocal("i"),l.getLocal("n"))),l.setLocal("idx1",l.i32_add(l.getLocal("pBuff1"),l.i32_mul(l.getLocal("i"),l.i32_const(r)))),l.setLocal("idx2",l.i32_add(l.getLocal("pBuff2"),l.i32_mul(l.getLocal("i"),l.i32_const(r)))),l.call(o,l.getLocal("idx2"),s,d),l.call(a+"_sub",l.getLocal("idx1"),d,l.getLocal("idx2")),l.call(o,l.getLocal("idx2"),l.getLocal("pSConst"),l.getLocal("idx2")),l.call(o,l.getLocal("idx1"),l.getLocal("pShiftToM"),l.getLocal("idx1")),l.call(a+"_sub",d,l.getLocal("idx1"),l.getLocal("idx1")),l.call(o,l.getLocal("idx1"),l.getLocal("pSConst"),l.getLocal("idx1")),l.call(i+"_mul",s,l.getLocal("inc"),s),l.setLocal("i",l.i32_add(l.getLocal("i"),l.i32_const(1))),l.br(0))))}(),function(){const c=t.addFunction(e+"_fftMix");c.addParam("pBuff","i32"),c.addParam("n","i32"),c.addParam("exp","i32"),c.addLocal("nGroups","i32"),c.addLocal("nPerGroup","i32"),c.addLocal("nPerGroupDiv2","i32"),c.addLocal("pairOffset","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("j","i32"),c.addLocal("pwm","i32");const l=c.getCodeBuilder(),s=l.i32_const(t.alloc(n)),d=l.i32_const(t.alloc(r)),u=l.i32_const(t.alloc(r));c.addCode(l.setLocal("nPerGroup",l.i32_shl(l.i32_const(1),l.getLocal("exp"))),l.setLocal("nPerGroupDiv2",l.i32_shr_u(l.getLocal("nPerGroup"),l.i32_const(1))),l.setLocal("nGroups",l.i32_shr_u(l.getLocal("n"),l.getLocal("exp"))),l.setLocal("pairOffset",l.i32_mul(l.getLocal("nPerGroupDiv2"),l.i32_const(r))),l.setLocal("pwm",l.i32_add(l.i32_const(h),l.i32_mul(l.getLocal("exp"),l.i32_const(n)))),l.setLocal("i",l.i32_const(0)),l.block(l.loop(l.br_if(1,l.i32_eq(l.getLocal("i"),l.getLocal("nGroups"))),l.call(i+"_one",s),l.setLocal("j",l.i32_const(0)),l.block(l.loop(l.br_if(1,l.i32_eq(l.getLocal("j"),l.getLocal("nPerGroupDiv2"))),l.setLocal("idx1",l.i32_add(l.getLocal("pBuff"),l.i32_mul(l.i32_add(l.i32_mul(l.getLocal("i"),l.getLocal("nPerGroup")),l.getLocal("j")),l.i32_const(r)))),l.setLocal("idx2",l.i32_add(l.getLocal("idx1"),l.getLocal("pairOffset"))),l.call(o,l.getLocal("idx2"),s,d),l.call(a+"_copy",l.getLocal("idx1"),u),l.call(a+"_add",u,d,l.getLocal("idx1")),l.call(a+"_sub",u,d,l.getLocal("idx2")),l.call(i+"_mul",s,l.getLocal("pwm"),s),l.setLocal("j",l.i32_add(l.getLocal("j"),l.i32_const(1))),l.br(0))),l.setLocal("i",l.i32_add(l.getLocal("i"),l.i32_const(1))),l.br(0))))}(),function(){const i=t.addFunction(e+"_fftFinal");i.addParam("pBuff","i32"),i.addParam("n","i32"),i.addParam("factor","i32"),i.addLocal("idx1","i32"),i.addLocal("idx2","i32"),i.addLocal("i","i32"),i.addLocal("ndiv2","i32");const n=i.getCodeBuilder(),c=n.i32_const(t.alloc(r));i.addCode(n.setLocal("ndiv2",n.i32_shr_u(n.getLocal("n"),n.i32_const(1))),n.if(n.i32_and(n.getLocal("n"),n.i32_const(1)),n.call(o,n.i32_add(n.getLocal("pBuff"),n.i32_mul(n.getLocal("ndiv2"),n.i32_const(r))),n.getLocal("factor"),n.i32_add(n.getLocal("pBuff"),n.i32_mul(n.getLocal("ndiv2"),n.i32_const(r))))),n.setLocal("i",n.i32_const(0)),n.block(n.loop(n.br_if(1,n.i32_ge_u(n.getLocal("i"),n.getLocal("ndiv2"))),n.setLocal("idx1",n.i32_add(n.getLocal("pBuff"),n.i32_mul(n.getLocal("i"),n.i32_const(r)))),n.setLocal("idx2",n.i32_add(n.getLocal("pBuff"),n.i32_mul(n.i32_sub(n.i32_sub(n.getLocal("n"),n.i32_const(1)),n.getLocal("i")),n.i32_const(r)))),n.call(o,n.getLocal("idx2"),n.getLocal("factor"),c),n.call(o,n.getLocal("idx1"),n.getLocal("factor"),n.getLocal("idx2")),n.call(a+"_copy",c,n.getLocal("idx1")),n.setLocal("i",n.i32_add(n.getLocal("i"),n.i32_const(1))),n.br(0))))}(),function(){const c=t.addFunction(e+"_prepareLagrangeEvaluation");c.addParam("pBuff1","i32"),c.addParam("pBuff2","i32"),c.addParam("n","i32"),c.addParam("first","i32"),c.addParam("inc","i32"),c.addParam("totalBits","i32"),c.addLocal("idx1","i32"),c.addLocal("idx2","i32"),c.addLocal("i","i32"),c.addLocal("pShiftToM","i32"),c.addLocal("pSConst","i32");const l=c.getCodeBuilder(),s=l.i32_const(t.alloc(n)),d=l.i32_const(t.alloc(r));c.addCode(l.setLocal("pShiftToM",l.i32_add(l.i32_const(I),l.i32_mul(l.getLocal("totalBits"),l.i32_const(n)))),l.setLocal("pSConst",l.i32_add(l.i32_const(C),l.i32_mul(l.getLocal("totalBits"),l.i32_const(n)))),l.call(i+"_copy",l.getLocal("first"),s),l.setLocal("i",l.i32_const(0)),l.block(l.loop(l.br_if(1,l.i32_eq(l.getLocal("i"),l.getLocal("n"))),l.setLocal("idx1",l.i32_add(l.getLocal("pBuff1"),l.i32_mul(l.getLocal("i"),l.i32_const(r)))),l.setLocal("idx2",l.i32_add(l.getLocal("pBuff2"),l.i32_mul(l.getLocal("i"),l.i32_const(r)))),l.call(o,l.getLocal("idx1"),l.getLocal("pShiftToM"),d),l.call(a+"_sub",l.getLocal("idx2"),d,d),l.call(a+"_sub",l.getLocal("idx1"),l.getLocal("idx2"),l.getLocal("idx2")),l.call(o,d,l.getLocal("pSConst"),l.getLocal("idx1")),l.call(o,l.getLocal("idx2"),s,l.getLocal("idx2")),l.call(i+"_mul",s,l.getLocal("inc"),s),l.setLocal("i",l.i32_add(l.getLocal("i"),l.i32_const(1))),l.br(0))))}(),t.exportFunction(e+"_fft"),t.exportFunction(e+"_ifft"),t.exportFunction(e+"_rawfft"),t.exportFunction(e+"_fftJoin"),t.exportFunction(e+"_fftJoinExt"),t.exportFunction(e+"_fftJoinExtInv"),t.exportFunction(e+"_fftMix"),t.exportFunction(e+"_fftFinal"),t.exportFunction(e+"_prepareLagrangeEvaluation")},Tt=function(t,e,a){const i=8*t.modules[a].n64;return function(){const o=t.addFunction(e+"_zero");o.addParam("px","i32"),o.addParam("n","i32"),o.addLocal("lastp","i32"),o.addLocal("p","i32");const n=o.getCodeBuilder();o.addCode(n.setLocal("p",n.getLocal("px")),n.setLocal("lastp",n.i32_add(n.getLocal("px"),n.i32_mul(n.getLocal("n"),n.i32_const(i)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("p"),n.getLocal("lastp"))),n.call(a+"_zero",n.getLocal("p")),n.setLocal("p",n.i32_add(n.getLocal("p"),n.i32_const(i))),n.br(0))))}(),function(){const o=t.addFunction(e+"_constructLC");o.addParam("ppolynomials","i32"),o.addParam("psignals","i32"),o.addParam("nSignals","i32"),o.addParam("pres","i32"),o.addLocal("i","i32"),o.addLocal("j","i32"),o.addLocal("pp","i32"),o.addLocal("ps","i32"),o.addLocal("pd","i32"),o.addLocal("ncoefs","i32");const n=o.getCodeBuilder(),r=n.i32_const(t.alloc(i));o.addCode(n.setLocal("i",n.i32_const(0)),n.setLocal("pp",n.getLocal("ppolynomials")),n.setLocal("ps",n.getLocal("psignals")),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("i"),n.getLocal("nSignals"))),n.setLocal("ncoefs",n.i32_load(n.getLocal("pp"))),n.setLocal("pp",n.i32_add(n.getLocal("pp"),n.i32_const(4))),n.setLocal("j",n.i32_const(0)),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("j"),n.getLocal("ncoefs"))),n.setLocal("pd",n.i32_add(n.getLocal("pres"),n.i32_mul(n.i32_load(n.getLocal("pp")),n.i32_const(i)))),n.setLocal("pp",n.i32_add(n.getLocal("pp"),n.i32_const(4))),n.call(a+"_mul",n.getLocal("ps"),n.getLocal("pp"),r),n.call(a+"_add",r,n.getLocal("pd"),n.getLocal("pd")),n.setLocal("pp",n.i32_add(n.getLocal("pp"),n.i32_const(i))),n.setLocal("j",n.i32_add(n.getLocal("j"),n.i32_const(1))),n.br(0))),n.setLocal("ps",n.i32_add(n.getLocal("ps"),n.i32_const(i))),n.setLocal("i",n.i32_add(n.getLocal("i"),n.i32_const(1))),n.br(0))))}(),t.exportFunction(e+"_zero"),t.exportFunction(e+"_constructLC"),e},Dt=function(t,e,a){const i=8*t.modules[a].n64;return function(){const o=t.addFunction(e+"_buildABC");o.addParam("pCoefs","i32"),o.addParam("nCoefs","i32"),o.addParam("pWitness","i32"),o.addParam("pA","i32"),o.addParam("pB","i32"),o.addParam("pC","i32"),o.addParam("offsetOut","i32"),o.addParam("nOut","i32"),o.addParam("offsetWitness","i32"),o.addParam("nWitness","i32"),o.addLocal("it","i32"),o.addLocal("ita","i32"),o.addLocal("itb","i32"),o.addLocal("last","i32"),o.addLocal("m","i32"),o.addLocal("c","i32"),o.addLocal("s","i32"),o.addLocal("pOut","i32");const n=o.getCodeBuilder(),r=n.i32_const(t.alloc(i));o.addCode(n.setLocal("ita",n.getLocal("pA")),n.setLocal("itb",n.getLocal("pB")),n.setLocal("last",n.i32_add(n.getLocal("pA"),n.i32_mul(n.getLocal("nOut"),n.i32_const(i)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(a+"_zero",n.getLocal("ita")),n.call(a+"_zero",n.getLocal("itb")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(i))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(i))),n.br(0))),n.setLocal("it",n.getLocal("pCoefs")),n.setLocal("last",n.i32_add(n.getLocal("pCoefs"),n.i32_mul(n.getLocal("nCoefs"),n.i32_const(i+12)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("it"),n.getLocal("last"))),n.setLocal("s",n.i32_load(n.getLocal("it"),8)),n.if(n.i32_or(n.i32_lt_u(n.getLocal("s"),n.getLocal("offsetWitness")),n.i32_ge_u(n.getLocal("s"),n.i32_add(n.getLocal("offsetWitness"),n.getLocal("nWitness")))),[...n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(i+12))),...n.br(1)]),n.setLocal("m",n.i32_load(n.getLocal("it"))),n.if(n.i32_eq(n.getLocal("m"),n.i32_const(0)),n.setLocal("pOut",n.getLocal("pA")),n.if(n.i32_eq(n.getLocal("m"),n.i32_const(1)),n.setLocal("pOut",n.getLocal("pB")),[...n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(i+12))),...n.br(1)])),n.setLocal("c",n.i32_load(n.getLocal("it"),4)),n.if(n.i32_or(n.i32_lt_u(n.getLocal("c"),n.getLocal("offsetOut")),n.i32_ge_u(n.getLocal("c"),n.i32_add(n.getLocal("offsetOut"),n.getLocal("nOut")))),[...n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(i+12))),...n.br(1)]),n.setLocal("pOut",n.i32_add(n.getLocal("pOut"),n.i32_mul(n.i32_sub(n.getLocal("c"),n.getLocal("offsetOut")),n.i32_const(i)))),n.call(a+"_mul",n.i32_add(n.getLocal("pWitness"),n.i32_mul(n.i32_sub(n.getLocal("s"),n.getLocal("offsetWitness")),n.i32_const(i))),n.i32_add(n.getLocal("it"),n.i32_const(12)),r),n.call(a+"_add",n.getLocal("pOut"),r,n.getLocal("pOut")),n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(i+12))),n.br(0))),n.setLocal("ita",n.getLocal("pA")),n.setLocal("itb",n.getLocal("pB")),n.setLocal("it",n.getLocal("pC")),n.setLocal("last",n.i32_add(n.getLocal("pA"),n.i32_mul(n.getLocal("nOut"),n.i32_const(i)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(a+"_mul",n.getLocal("ita"),n.getLocal("itb"),n.getLocal("it")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(i))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(i))),n.setLocal("it",n.i32_add(n.getLocal("it"),n.i32_const(i))),n.br(0))))}(),function(){const o=t.addFunction(e+"_joinABC");o.addParam("pA","i32"),o.addParam("pB","i32"),o.addParam("pC","i32"),o.addParam("n","i32"),o.addParam("pP","i32"),o.addLocal("ita","i32"),o.addLocal("itb","i32"),o.addLocal("itc","i32"),o.addLocal("itp","i32"),o.addLocal("last","i32");const n=o.getCodeBuilder(),r=n.i32_const(t.alloc(i));o.addCode(n.setLocal("ita",n.getLocal("pA")),n.setLocal("itb",n.getLocal("pB")),n.setLocal("itc",n.getLocal("pC")),n.setLocal("itp",n.getLocal("pP")),n.setLocal("last",n.i32_add(n.getLocal("pA"),n.i32_mul(n.getLocal("n"),n.i32_const(i)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(a+"_mul",n.getLocal("ita"),n.getLocal("itb"),r),n.call(a+"_sub",r,n.getLocal("itc"),n.getLocal("itp")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(i))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(i))),n.setLocal("itc",n.i32_add(n.getLocal("itc"),n.i32_const(i))),n.setLocal("itp",n.i32_add(n.getLocal("itp"),n.i32_const(i))),n.br(0))))}(),function(){const o=t.addFunction(e+"_batchAdd");o.addParam("pa","i32"),o.addParam("pb","i32"),o.addParam("n","i32"),o.addParam("pr","i32"),o.addLocal("ita","i32"),o.addLocal("itb","i32"),o.addLocal("itr","i32"),o.addLocal("last","i32");const n=o.getCodeBuilder();o.addCode(n.setLocal("ita",n.getLocal("pa")),n.setLocal("itb",n.getLocal("pb")),n.setLocal("itr",n.getLocal("pr")),n.setLocal("last",n.i32_add(n.getLocal("pa"),n.i32_mul(n.getLocal("n"),n.i32_const(i)))),n.block(n.loop(n.br_if(1,n.i32_eq(n.getLocal("ita"),n.getLocal("last"))),n.call(a+"_add",n.getLocal("ita"),n.getLocal("itb"),n.getLocal("itr")),n.setLocal("ita",n.i32_add(n.getLocal("ita"),n.i32_const(i))),n.setLocal("itb",n.i32_add(n.getLocal("itb"),n.i32_const(i))),n.setLocal("itr",n.i32_add(n.getLocal("itr"),n.i32_const(i))),n.br(0))))}(),t.exportFunction(e+"_buildABC"),t.exportFunction(e+"_joinABC"),t.exportFunction(e+"_batchAdd"),e},Kt=function(t,e,a,i,o,n,r,c){const l=t.addFunction(e);l.addParam("pIn","i32"),l.addParam("n","i32"),l.addParam("pFirst","i32"),l.addParam("pInc","i32"),l.addParam("pOut","i32"),l.addLocal("pOldFree","i32"),l.addLocal("i","i32"),l.addLocal("pFrom","i32"),l.addLocal("pTo","i32");const s=l.getCodeBuilder(),d=s.i32_const(t.alloc(r));l.addCode(s.setLocal("pFrom",s.getLocal("pIn")),s.setLocal("pTo",s.getLocal("pOut"))),l.addCode(s.call(i+"_copy",s.getLocal("pFirst"),d)),l.addCode(s.setLocal("i",s.i32_const(0)),s.block(s.loop(s.br_if(1,s.i32_eq(s.getLocal("i"),s.getLocal("n"))),s.call(c,s.getLocal("pFrom"),d,s.getLocal("pTo")),s.setLocal("pFrom",s.i32_add(s.getLocal("pFrom"),s.i32_const(o))),s.setLocal("pTo",s.i32_add(s.getLocal("pTo"),s.i32_const(n))),s.call(i+"_mul",d,s.getLocal("pInc"),d),s.setLocal("i",s.i32_add(s.getLocal("i"),s.i32_const(1))),s.br(0)))),t.exportFunction(e)},Vt=function(t,e){const a=e||"bn128";if(t.modules[a])return a;const i=u("21888242871839275222246405745257275088696311157297823662689037894645226208583"),o=u("21888242871839275222246405745257275088548364400416034343698204186575808495617"),n=Math.floor((i.minus(1).bitLength()-1)/64)+1,r=8*n,c=r,l=r,s=2*l,d=12*l,g=t.alloc(Et(o,c)),f=Ut(t,i,"f1m");zt(t,o,"fr","frm");const _=t.alloc(Et(A(u(3)),l)),p=Rt(t,"g1m","f1m",_);Nt(t,"frm","frm","frm","frm_mul"),Tt(t,"pol","frm"),Dt(t,"qap","frm");const h=qt(t,"f1m_neg","f2m","f1m"),m=t.alloc([...Et(A(u("19485874751759354771024239261021720505790618469301721065564631296452457478373")),l),...Et(A(u("266929791119991161246907387137283842545076965332900288569378510910307636690")),l)]),L=Rt(t,"g2m","f2m",m);function w(e,a){const i=t.addFunction(e);i.addParam("pG","i32"),i.addParam("pFr","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder(),n=o.i32_const(t.alloc(r));i.addCode(o.call("frm_fromMontgomery",o.getLocal("pFr"),n),o.call(a,o.getLocal("pG"),n,o.i32_const(r),o.getLocal("pr"))),t.exportFunction(e)}function A(t){return u(t).times(u.one.shiftLeft(8*l)).mod(i)}w("g1m_timesFr","g1m_timesScalar"),Nt(t,"g1m","g1m","frm","g1m_timesFr"),w("g2m_timesFr","g2m_timesScalar"),Nt(t,"g2m","g2m","frm","g2m_timesFr"),w("g1m_timesFrAffine","g1m_timesScalarAffine"),w("g2m_timesFrAffine","g2m_timesScalarAffine"),Kt(t,"frm_batchApplyKey",0,"frm",r,r,r,"frm_mul"),Kt(t,"g1m_batchApplyKey",0,"frm",3*r,3*r,r,"g1m_timesFr"),Kt(t,"g1m_batchApplyKeyMixed",0,"frm",2*r,3*r,r,"g1m_timesFrAffine"),Kt(t,"g2m_batchApplyKey",0,"frm",2*r*3,3*r*2,r,"g2m_timesFr"),Kt(t,"g2m_batchApplyKeyMixed",0,"frm",2*r*2,3*r*2,r,"g2m_timesFrAffine");const b=[u("1"),u("2"),u.one],y=t.alloc([...Et(A(b[0]),l),...Et(A(b[1]),l),...Et(A(b[2]),l)]),I=[u.zero,u.one,u.zero],C=t.alloc([...Et(A(I[0]),l),...Et(A(I[1]),l),...Et(A(I[2]),l)]),F=[[u("10857046999023057135944570762232829481370756359578518086990519993285655852781"),u("11559732032986387107991004021392285783925812861821192530917403151452391805634")],[u("8495653923123431417604973247489272438418190587263600148770280649306958101930"),u("4082367875863433681332203403145435568316851327593401208105741076214120093531")],[u.one,u.zero]],x=t.alloc([...Et(A(F[0][0]),l),...Et(A(F[0][1]),l),...Et(A(F[1][0]),l),...Et(A(F[1][1]),l),...Et(A(F[2][0]),l),...Et(A(F[2][1]),l)]),v=[[u.zero,u.zero],[u.one,u.zero],[u.zero,u.zero]],E=t.alloc([...Et(A(v[0][0]),l),...Et(A(v[0][1]),l),...Et(A(v[1][0]),l),...Et(A(v[1][1]),l),...Et(A(v[2][0]),l),...Et(A(v[2][1]),l)]),B=t.alloc([...Et(A(1),l),...Et(A(0),l),...Et(A(0),l),...Et(A(0),l),...Et(A(0),l),...Et(A(0),l),...Et(A(0),l),...Et(A(0),l),...Et(A(0),l),...Et(A(0),l),...Et(A(0),l),...Et(A(0),l)]),S=t.alloc([...Et(A(9),l),...Et(A(1),l)]),G=t.alloc([...Et(A(u(2).modInv(i)),l),...Et(u(0),l)]),P=S,O=t.alloc([...Et(A("19485874751759354771024239261021720505790618469301721065564631296452457478373"),l),...Et(A("266929791119991161246907387137283842545076965332900288569378510910307636690"),l)]);!function(){const e=t.addFunction(a+"_mulNR6");e.addParam("x","i32"),e.addParam("pr","i32");const i=e.getCodeBuilder();e.addCode(i.call(h+"_mul",i.i32_const(S),i.getLocal("x"),i.getLocal("pr")))}();const U=Qt(t,a+"_mulNR6","f6m","f2m");!function(){const e=t.addFunction(a+"_mulNR12");e.addParam("x","i32"),e.addParam("pr","i32");const i=e.getCodeBuilder();e.addCode(i.call(h+"_mul",i.i32_const(S),i.i32_add(i.getLocal("x"),i.i32_const(4*r)),i.getLocal("pr")),i.call(h+"_copy",i.getLocal("x"),i.i32_add(i.getLocal("pr"),i.i32_const(2*r))),i.call(h+"_copy",i.i32_add(i.getLocal("x"),i.i32_const(2*r)),i.i32_add(i.getLocal("pr"),i.i32_const(4*r))))}();const z=qt(t,a+"_mulNR12","ftm",U),q=function(t){let e=t;const a=[];for(;e.gt(u.zero);)e.isOdd()?a.push(1):a.push(0),e=e.shiftRight(1);return a}(u("29793968203157093288")),Q=t.alloc(q),M=3*s,k=q.length-1,R=q.reduce(((t,e)=>t+(0!=e?1:0)),0),N=6*r,T=3*r*2+(R+k+1)*M;t.modules[a]={n64:n,pG1gen:y,pG1zero:C,pG1b:_,pG2gen:x,pG2zero:E,pG2b:m,pq:t.modules.f1m.pq,pr:g,pOneT:B,prePSize:N,preQSize:T,r:o.toString(),q:i.toString()};const D=u("4965661367192848881");function K(e){const o=[[[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")]],[[u("1"),u("0")],[u("8376118865763821496583973867626364092589906065868298776909617916018768340080"),u("16469823323077808223889137241176536799009286646108169935659301613961712198316")],[u("21888242871839275220042445260109153167277707414472061641714758635765020556617"),u("0")],[u("11697423496358154304825782922584725312912383441159505038794027105778954184319"),u("303847389135065887422783454877609941456349188919719272345083954437860409601")],[u("21888242871839275220042445260109153167277707414472061641714758635765020556616"),u("0")],[u("3321304630594332808241809054958361220322477375291206261884409189760185844239"),u("5722266937896532885780051958958348231143373700109372999374820235121374419868")],[u("21888242871839275222246405745257275088696311157297823662689037894645226208582"),u("0")],[u("13512124006075453725662431877630910996106405091429524885779419978626457868503"),u("5418419548761466998357268504080738289687024511189653727029736280683514010267")],[u("2203960485148121921418603742825762020974279258880205651966"),u("0")],[u("10190819375481120917420622822672549775783927716138318623895010788866272024264"),u("21584395482704209334823622290379665147239961968378104390343953940207365798982")],[u("2203960485148121921418603742825762020974279258880205651967"),u("0")],[u("18566938241244942414004596690298913868373833782006617400804628704885040364344"),u("16165975933942742336466353786298926857552937457188450663314217659523851788715")]]],n=[[[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")]],[[u("1"),u("0")],[u("21575463638280843010398324269430826099269044274347216827212613867836435027261"),u("10307601595873709700152284273816112264069230130616436755625194854815875713954")],[u("21888242871839275220042445260109153167277707414472061641714758635765020556616"),u("0")],[u("3772000881919853776433695186713858239009073593817195771773381919316419345261"),u("2236595495967245188281701248203181795121068902605861227855261137820944008926")],[u("2203960485148121921418603742825762020974279258880205651966"),u("0")],[u("18429021223477853657660792034369865839114504446431234726392080002137598044644"),u("9344045779998320333812420223237981029506012124075525679208581902008406485703")]],[[u("1"),u("0")],[u("2581911344467009335267311115468803099551665605076196740867805258568234346338"),u("19937756971775647987995932169929341994314640652964949448313374472400716661030")],[u("2203960485148121921418603742825762020974279258880205651966"),u("0")],[u("5324479202449903542726783395506214481928257762400643279780343368557297135718"),u("16208900380737693084919495127334387981393726419856888799917914180988844123039")],[u("21888242871839275220042445260109153167277707414472061641714758635765020556616"),u("0")],[u("13981852324922362344252311234282257507216387789820983642040889267519694726527"),u("7629828391165209371577384193250820201684255241773809077146787135900891633097")]]],r=t.addFunction(a+"__frobeniusMap"+e);r.addParam("x","i32"),r.addParam("r","i32");const c=r.getCodeBuilder();for(let a=0;a<6;a++){const i=0==a?c.getLocal("x"):c.i32_add(c.getLocal("x"),c.i32_const(a*s)),u=i,g=c.i32_add(c.getLocal("x"),c.i32_const(a*s+l)),_=0==a?c.getLocal("r"):c.i32_add(c.getLocal("r"),c.i32_const(a*s)),p=_,m=c.i32_add(c.getLocal("r"),c.i32_const(a*s+l)),L=d(o[Math.floor(a/3)][e%12],n[a%3][e%6]),w=t.alloc([...Et(A(L[0]),32),...Et(A(L[1]),32)]);e%2==1?r.addCode(c.call(f+"_copy",u,p),c.call(f+"_neg",g,m),c.call(h+"_mul",_,c.i32_const(w),_)):r.addCode(c.call(h+"_mul",i,c.i32_const(w),_))}function d(t,e){const a=u(t[0]),o=u(t[1]),n=u(e[0]),r=u(e[1]),c=[a.times(n).minus(o.times(r)).mod(i),a.times(r).add(o.times(n)).mod(i)];return c[0].isNegative()&&(c[0]=c[0].add(i)),c}}function V(e,i){const o=function(t){let e=t;const a=[];for(;e.gt(u.zero);){if(e.isOdd()){const t=2-e.mod(4).toJSNumber();a.push(t),e=e.minus(t)}else a.push(0);e=e.shiftRight(1)}return a}(e).map((t=>-1==t?255:t)),n=t.alloc(o);t.alloc(Et(e,32));const r=t.addFunction(a+"__cyclotomicExp_"+i);r.addParam("x","i32"),r.addParam("r","i32"),r.addLocal("bit","i32"),r.addLocal("i","i32");const c=r.getCodeBuilder(),l=c.getLocal("x"),s=c.getLocal("r"),g=c.i32_const(t.alloc(d));r.addCode(c.call(z+"_conjugate",l,g),c.call(z+"_one",s),c.if(c.teeLocal("bit",c.i32_load8_s(c.i32_const(o.length-1),n)),c.if(c.i32_eq(c.getLocal("bit"),c.i32_const(1)),c.call(z+"_mul",s,l,s),c.call(z+"_mul",s,g,s))),c.setLocal("i",c.i32_const(o.length-2)),c.block(c.loop(c.call(a+"__cyclotomicSquare",s,s),c.if(c.teeLocal("bit",c.i32_load8_s(c.getLocal("i"),n)),c.if(c.i32_eq(c.getLocal("bit"),c.i32_const(1)),c.call(z+"_mul",s,l,s),c.call(z+"_mul",s,g,s))),c.br_if(1,c.i32_eqz(c.getLocal("i"))),c.setLocal("i",c.i32_sub(c.getLocal("i"),c.i32_const(1))),c.br(0))))}function j(){!function(){const e=t.addFunction(a+"__cyclotomicSquare");e.addParam("x","i32"),e.addParam("r","i32");const i=e.getCodeBuilder(),o=i.getLocal("x"),n=i.i32_add(i.getLocal("x"),i.i32_const(s)),r=i.i32_add(i.getLocal("x"),i.i32_const(2*s)),c=i.i32_add(i.getLocal("x"),i.i32_const(3*s)),l=i.i32_add(i.getLocal("x"),i.i32_const(4*s)),d=i.i32_add(i.getLocal("x"),i.i32_const(5*s)),u=i.getLocal("r"),g=i.i32_add(i.getLocal("r"),i.i32_const(s)),f=i.i32_add(i.getLocal("r"),i.i32_const(2*s)),_=i.i32_add(i.getLocal("r"),i.i32_const(3*s)),p=i.i32_add(i.getLocal("r"),i.i32_const(4*s)),m=i.i32_add(i.getLocal("r"),i.i32_const(5*s)),L=i.i32_const(t.alloc(s)),w=i.i32_const(t.alloc(s)),A=i.i32_const(t.alloc(s)),b=i.i32_const(t.alloc(s)),y=i.i32_const(t.alloc(s)),I=i.i32_const(t.alloc(s)),C=i.i32_const(t.alloc(s)),F=i.i32_const(t.alloc(s));e.addCode(i.call(h+"_mul",o,l,C),i.call(h+"_mul",l,i.i32_const(S),L),i.call(h+"_add",o,L,L),i.call(h+"_add",o,l,F),i.call(h+"_mul",F,L,L),i.call(h+"_mul",i.i32_const(S),C,F),i.call(h+"_add",C,F,F),i.call(h+"_sub",L,F,L),i.call(h+"_add",C,C,w),i.call(h+"_mul",c,r,C),i.call(h+"_mul",r,i.i32_const(S),A),i.call(h+"_add",c,A,A),i.call(h+"_add",c,r,F),i.call(h+"_mul",F,A,A),i.call(h+"_mul",i.i32_const(S),C,F),i.call(h+"_add",C,F,F),i.call(h+"_sub",A,F,A),i.call(h+"_add",C,C,b),i.call(h+"_mul",n,d,C),i.call(h+"_mul",d,i.i32_const(S),y),i.call(h+"_add",n,y,y),i.call(h+"_add",n,d,F),i.call(h+"_mul",F,y,y),i.call(h+"_mul",i.i32_const(S),C,F),i.call(h+"_add",C,F,F),i.call(h+"_sub",y,F,y),i.call(h+"_add",C,C,I),i.call(h+"_sub",L,o,u),i.call(h+"_add",u,u,u),i.call(h+"_add",L,u,u),i.call(h+"_add",w,l,p),i.call(h+"_add",p,p,p),i.call(h+"_add",w,p,p),i.call(h+"_mul",I,i.i32_const(P),F),i.call(h+"_add",F,c,_),i.call(h+"_add",_,_,_),i.call(h+"_add",F,_,_),i.call(h+"_sub",y,r,f),i.call(h+"_add",f,f,f),i.call(h+"_add",y,f,f),i.call(h+"_sub",A,n,g),i.call(h+"_add",g,g,g),i.call(h+"_add",A,g,g),i.call(h+"_add",b,d,m),i.call(h+"_add",m,m,m),i.call(h+"_add",b,m,m))}(),V(D,"w0");const e=t.addFunction(a+"__finalExponentiationLastChunk");e.addParam("x","i32"),e.addParam("r","i32");const i=e.getCodeBuilder(),o=i.getLocal("x"),n=i.getLocal("r"),r=i.i32_const(t.alloc(d)),c=i.i32_const(t.alloc(d)),l=i.i32_const(t.alloc(d)),u=i.i32_const(t.alloc(d)),g=i.i32_const(t.alloc(d)),f=i.i32_const(t.alloc(d)),_=i.i32_const(t.alloc(d)),p=i.i32_const(t.alloc(d)),m=i.i32_const(t.alloc(d)),L=i.i32_const(t.alloc(d)),w=i.i32_const(t.alloc(d)),A=i.i32_const(t.alloc(d)),b=i.i32_const(t.alloc(d)),y=i.i32_const(t.alloc(d)),I=i.i32_const(t.alloc(d)),C=i.i32_const(t.alloc(d)),F=i.i32_const(t.alloc(d)),x=i.i32_const(t.alloc(d)),v=i.i32_const(t.alloc(d)),E=i.i32_const(t.alloc(d)),B=i.i32_const(t.alloc(d));e.addCode(i.call(a+"__cyclotomicExp_w0",o,r),i.call(z+"_conjugate",r,r),i.call(a+"__cyclotomicSquare",r,c),i.call(a+"__cyclotomicSquare",c,l),i.call(z+"_mul",l,c,u),i.call(a+"__cyclotomicExp_w0",u,g),i.call(z+"_conjugate",g,g),i.call(a+"__cyclotomicSquare",g,f),i.call(a+"__cyclotomicExp_w0",f,_),i.call(z+"_conjugate",_,_),i.call(z+"_conjugate",u,p),i.call(z+"_conjugate",_,m),i.call(z+"_mul",m,g,L),i.call(z+"_mul",L,p,w),i.call(z+"_mul",w,c,A),i.call(z+"_mul",w,g,b),i.call(z+"_mul",b,o,y),i.call(a+"__frobeniusMap1",A,I),i.call(z+"_mul",I,y,C),i.call(a+"__frobeniusMap2",w,F),i.call(z+"_mul",F,C,x),i.call(z+"_conjugate",o,v),i.call(z+"_mul",v,A,E),i.call(a+"__frobeniusMap3",E,B),i.call(z+"_mul",B,x,n))}const H=t.alloc(N),$=t.alloc(T);function Z(e){const i=t.addFunction(a+"_pairingEq"+e);for(let t=0;t<e;t++)i.addParam("p_"+t,"i32"),i.addParam("q_"+t,"i32");i.addParam("c","i32"),i.setReturnType("i32");const o=i.getCodeBuilder(),n=o.i32_const(t.alloc(d)),r=o.i32_const(t.alloc(d));i.addCode(o.call(z+"_one",n));for(let t=0;t<e;t++)i.addCode(o.call(a+"_prepareG1",o.getLocal("p_"+t),o.i32_const(H))),i.addCode(o.call(a+"_prepareG2",o.getLocal("q_"+t),o.i32_const($))),i.addCode(o.call(a+"_millerLoop",o.i32_const(H),o.i32_const($),r)),i.addCode(o.call(z+"_mul",n,r,n));i.addCode(o.call(a+"_finalExponentiation",n,n)),i.addCode(o.call(z+"_eq",n,o.getLocal("c")))}!function(){const e=t.addFunction(a+"_prepAddStep");e.addParam("pQ","i32"),e.addParam("pR","i32"),e.addParam("pCoef","i32");const i=e.getCodeBuilder(),o=i.getLocal("pQ"),n=i.i32_add(i.getLocal("pQ"),i.i32_const(s)),r=i.getLocal("pR"),c=i.i32_add(i.getLocal("pR"),i.i32_const(s)),l=i.i32_add(i.getLocal("pR"),i.i32_const(2*s)),d=i.getLocal("pCoef"),u=i.i32_add(i.getLocal("pCoef"),i.i32_const(s)),g=i.i32_add(i.getLocal("pCoef"),i.i32_const(2*s)),f=u,_=i.i32_const(t.alloc(s)),p=i.i32_const(t.alloc(s)),m=i.i32_const(t.alloc(s)),L=i.i32_const(t.alloc(s)),w=i.i32_const(t.alloc(s)),A=i.i32_const(t.alloc(s)),b=i.i32_const(t.alloc(s));e.addCode(i.call(h+"_mul",o,l,f),i.call(h+"_sub",r,f,f),i.call(h+"_mul",n,l,_),i.call(h+"_sub",c,_,_),i.call(h+"_square",f,p),i.call(h+"_square",_,m),i.call(h+"_mul",f,p,L),i.call(h+"_mul",r,p,w),i.call(h+"_add",w,w,b),i.call(h+"_mul",l,m,A),i.call(h+"_add",L,A,A),i.call(h+"_sub",A,b,A),i.call(h+"_mul",f,A,r),i.call(h+"_mul",L,c,c),i.call(h+"_sub",w,A,b),i.call(h+"_mul",_,b,b),i.call(h+"_sub",b,c,c),i.call(h+"_mul",l,L,l),i.call(h+"_mul",f,n,b),i.call(h+"_mul",_,o,d),i.call(h+"_sub",d,b,d),i.call(h+"_mul",d,i.i32_const(P),d),i.call(h+"_neg",_,g))}(),function(){const e=t.addFunction(a+"_prepDblStep");e.addParam("pR","i32"),e.addParam("pCoef","i32");const i=e.getCodeBuilder(),o=i.getLocal("pR"),n=i.i32_add(i.getLocal("pR"),i.i32_const(s)),r=i.i32_add(i.getLocal("pR"),i.i32_const(2*s)),c=i.getLocal("pCoef"),l=i.i32_add(i.getLocal("pCoef"),i.i32_const(s)),d=i.i32_add(i.getLocal("pCoef"),i.i32_const(2*s)),u=i.i32_const(t.alloc(s)),g=i.i32_const(t.alloc(s)),f=i.i32_const(t.alloc(s)),_=i.i32_const(t.alloc(s)),p=i.i32_const(t.alloc(s)),m=i.i32_const(t.alloc(s)),L=i.i32_const(t.alloc(s)),w=i.i32_const(t.alloc(s)),A=i.i32_const(t.alloc(s)),b=i.i32_const(t.alloc(s)),y=i.i32_const(t.alloc(s)),I=i.i32_const(t.alloc(s));e.addCode(i.call(h+"_mul",n,i.i32_const(G),u),i.call(h+"_mul",o,u,u),i.call(h+"_square",n,g),i.call(h+"_square",r,f),i.call(h+"_add",f,f,_),i.call(h+"_add",_,f,_),i.call(h+"_mul",i.i32_const(O),_,p),i.call(h+"_add",p,p,m),i.call(h+"_add",p,m,m),i.call(h+"_add",g,m,L),i.call(h+"_mul",L,i.i32_const(G),L),i.call(h+"_add",g,f,I),i.call(h+"_add",n,r,w),i.call(h+"_square",w,w),i.call(h+"_sub",w,I,w),i.call(h+"_sub",p,g,A),i.call(h+"_square",o,b),i.call(h+"_square",p,y),i.call(h+"_sub",g,m,I),i.call(h+"_mul",u,I,o),i.call(h+"_add",y,y,I),i.call(h+"_add",y,I,I),i.call(h+"_square",L,n),i.call(h+"_sub",n,I,n),i.call(h+"_mul",g,w,r),i.call(h+"_mul",i.i32_const(P),A,c),i.call(h+"_neg",w,l),i.call(h+"_add",b,b,d),i.call(h+"_add",b,d,d))}(),function(){const e=t.addFunction(a+"_prepareG1");e.addParam("pP","i32"),e.addParam("ppreP","i32");const i=e.getCodeBuilder();e.addCode(i.call(p+"_normalize",i.getLocal("pP"),i.getLocal("ppreP")))}(),function(){!function(){const e=t.addFunction(a+"_mulByQ");e.addParam("p1","i32"),e.addParam("pr","i32");const i=e.getCodeBuilder(),o=i.getLocal("p1"),n=i.i32_add(i.getLocal("p1"),i.i32_const(s)),r=i.i32_add(i.getLocal("p1"),i.i32_const(2*s)),c=i.getLocal("pr"),d=i.i32_add(i.getLocal("pr"),i.i32_const(s)),u=i.i32_add(i.getLocal("pr"),i.i32_const(2*s)),g=i.i32_const(t.alloc([...Et(A("21575463638280843010398324269430826099269044274347216827212613867836435027261"),l),...Et(A("10307601595873709700152284273816112264069230130616436755625194854815875713954"),l)])),f=i.i32_const(t.alloc([...Et(A("2821565182194536844548159561693502659359617185244120367078079554186484126554"),l),...Et(A("3505843767911556378687030309984248845540243509899259641013678093033130930403"),l)]));e.addCode(i.call(h+"_conjugate",o,c),i.call(h+"_mul",g,c,c),i.call(h+"_conjugate",n,d),i.call(h+"_mul",f,d,d),i.call(h+"_conjugate",r,u))}();const e=t.addFunction(a+"_prepareG2");e.addParam("pQ","i32"),e.addParam("ppreQ","i32"),e.addLocal("pCoef","i32"),e.addLocal("i","i32");const i=e.getCodeBuilder(),o=i.getLocal("pQ");i.i32_add(i.getLocal("pQ"),i.i32_const(s)),i.i32_add(i.getLocal("pQ"),i.i32_const(2*s));const n=t.alloc(3*s),r=i.i32_const(n),c=i.i32_const(n),d=i.i32_const(n+s),u=i.i32_const(n+2*s),g=i.i32_add(i.getLocal("ppreQ"),i.i32_const(0)),f=i.i32_add(i.getLocal("ppreQ"),i.i32_const(s));i.i32_add(i.getLocal("ppreQ"),i.i32_const(2*s));const _=t.alloc(3*s),p=i.i32_const(_),m=t.alloc(3*s),w=i.i32_const(m);i.i32_const(m);const b=i.i32_const(m+s);i.i32_const(m+2*s),e.addCode(i.call(L+"_normalize",o,g),i.call(h+"_copy",g,c),i.call(h+"_copy",f,d),i.call(h+"_one",u)),e.addCode(i.setLocal("pCoef",i.i32_add(i.getLocal("ppreQ"),i.i32_const(3*s))),i.setLocal("i",i.i32_const(q.length-2)),i.block(i.loop(i.call(a+"_prepDblStep",r,i.getLocal("pCoef")),i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(M))),i.if(i.i32_load8_s(i.getLocal("i"),Q),[...i.call(a+"_prepAddStep",g,r,i.getLocal("pCoef")),...i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(M)))]),i.br_if(1,i.i32_eqz(i.getLocal("i"))),i.setLocal("i",i.i32_sub(i.getLocal("i"),i.i32_const(1))),i.br(0)))),e.addCode(i.call(a+"_mulByQ",g,p),i.call(a+"_mulByQ",p,w)),e.addCode(i.call(h+"_neg",b,b),i.call(a+"_prepAddStep",p,r,i.getLocal("pCoef")),i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(M))),i.call(a+"_prepAddStep",w,r,i.getLocal("pCoef")),i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(M))))}(),function(){const e=t.addFunction(a+"__mulBy024");e.addParam("pEll0","i32"),e.addParam("pEllVW","i32"),e.addParam("pEllVV","i32"),e.addParam("pR","i32");const i=e.getCodeBuilder(),o=i.getLocal("pEll0"),n=i.getLocal("pEllVV"),c=i.getLocal("pEllVW"),l=i.getLocal("pR"),d=i.i32_add(i.getLocal("pR"),i.i32_const(2*r)),u=i.i32_add(i.getLocal("pR"),i.i32_const(4*r)),g=i.i32_add(i.getLocal("pR"),i.i32_const(6*r)),f=i.i32_add(i.getLocal("pR"),i.i32_const(8*r)),_=i.i32_add(i.getLocal("pR"),i.i32_const(10*r)),p=i.i32_const(t.alloc(s)),m=i.i32_const(t.alloc(s)),L=i.i32_const(t.alloc(s)),w=i.i32_const(t.alloc(s)),A=i.i32_const(t.alloc(s)),b=i.i32_const(t.alloc(s)),y=i.i32_const(t.alloc(s)),I=i.i32_const(t.alloc(s)),C=i.i32_const(t.alloc(s)),F=i.i32_const(t.alloc(s)),x=i.i32_const(t.alloc(s));e.addCode(i.call(h+"_mul",l,o,y),i.call(h+"_mul",u,n,I),i.call(h+"_mul",f,c,C),i.call(h+"_add",l,f,L),i.call(h+"_add",l,u,m),i.call(h+"_add",d,g,w),i.call(h+"_add",w,_,w),i.call(h+"_mul",d,n,F),i.call(h+"_add",F,C,A),i.call(h+"_mul",i.i32_const(S),A,b),i.call(h+"_add",b,y,l),i.call(h+"_mul",_,c,A),i.call(h+"_add",F,A,F),i.call(h+"_add",A,I,A),i.call(h+"_mul",i.i32_const(S),A,b),i.call(h+"_mul",d,o,A),i.call(h+"_add",F,A,F),i.call(h+"_add",b,A,d),i.call(h+"_add",o,n,p),i.call(h+"_mul",m,p,A),i.call(h+"_add",y,I,x),i.call(h+"_sub",A,x,A),i.call(h+"_mul",g,c,b),i.call(h+"_add",F,b,F),i.call(h+"_add",u,f,p),i.call(h+"_add",A,b,u),i.call(h+"_add",n,c,m),i.call(h+"_mul",m,p,A),i.call(h+"_add",I,C,x),i.call(h+"_sub",A,x,A),i.call(h+"_mul",i.i32_const(S),A,b),i.call(h+"_mul",g,o,A),i.call(h+"_add",F,A,F),i.call(h+"_add",b,A,g),i.call(h+"_mul",_,n,A),i.call(h+"_add",F,A,F),i.call(h+"_mul",i.i32_const(S),A,b),i.call(h+"_add",o,c,p),i.call(h+"_mul",L,p,A),i.call(h+"_add",y,C,x),i.call(h+"_sub",A,x,A),i.call(h+"_add",b,A,f),i.call(h+"_add",o,n,p),i.call(h+"_add",p,c,p),i.call(h+"_mul",w,p,A),i.call(h+"_sub",A,F,_))}(),function(){const e=t.addFunction(a+"__mulBy024Old");e.addParam("pEll0","i32"),e.addParam("pEllVW","i32"),e.addParam("pEllVV","i32"),e.addParam("pR","i32");const i=e.getCodeBuilder(),o=i.getLocal("pEll0"),n=i.getLocal("pEllVV"),r=i.getLocal("pEllVW"),c=i.getLocal("pR"),l=t.alloc(d),u=i.i32_const(l),g=i.i32_const(l),f=i.i32_const(l+s),_=i.i32_const(l+2*s),p=i.i32_const(l+3*s),m=i.i32_const(l+4*s),L=i.i32_const(l+5*s);e.addCode(i.call(h+"_copy",o,g),i.call(h+"_zero",f),i.call(h+"_copy",n,_),i.call(h+"_zero",p),i.call(h+"_copy",r,m),i.call(h+"_zero",L),i.call(z+"_mul",u,c,c))}(),function(){const e=t.addFunction(a+"_millerLoop");e.addParam("ppreP","i32"),e.addParam("ppreQ","i32"),e.addParam("r","i32"),e.addLocal("pCoef","i32"),e.addLocal("i","i32");const i=e.getCodeBuilder(),o=i.getLocal("ppreP"),n=i.i32_add(i.getLocal("ppreP"),i.i32_const(l)),r=i.getLocal("pCoef"),c=i.i32_add(i.getLocal("pCoef"),i.i32_const(s)),d=i.i32_add(i.getLocal("pCoef"),i.i32_const(2*s)),u=t.alloc(s),g=i.i32_const(u),f=t.alloc(s),_=i.i32_const(f),p=i.getLocal("r");e.addCode(i.call(z+"_one",p),i.setLocal("pCoef",i.i32_add(i.getLocal("ppreQ"),i.i32_const(3*s))),i.setLocal("i",i.i32_const(q.length-2)),i.block(i.loop(i.call(z+"_square",p,p),i.call(h+"_mul1",c,n,g),i.call(h+"_mul1",d,o,_),i.call(a+"__mulBy024",r,g,_,p),i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(M))),i.if(i.i32_load8_s(i.getLocal("i"),Q),[...i.call(h+"_mul1",c,n,g),...i.call(h+"_mul1",d,o,_),...i.call(a+"__mulBy024",r,g,_,p),...i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(M)))]),i.br_if(1,i.i32_eqz(i.getLocal("i"))),i.setLocal("i",i.i32_sub(i.getLocal("i"),i.i32_const(1))),i.br(0)))),e.addCode(i.call(h+"_mul1",c,n,g),i.call(h+"_mul1",d,o,_),i.call(a+"__mulBy024",r,g,_,p),i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(M))),i.call(h+"_mul1",c,n,g),i.call(h+"_mul1",d,o,_),i.call(a+"__mulBy024",r,g,_,p),i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(M))))}();for(let e=0;e<10;e++)K(e),t.exportFunction(a+"__frobeniusMap"+e);!function(){const e=t.addFunction(a+"_finalExponentiationOld");e.addParam("x","i32"),e.addParam("r","i32");const i=u("552484233613224096312617126783173147097382103762957654188882734314196910839907541213974502761540629817009608548654680343627701153829446747810907373256841551006201639677726139946029199968412598804882391702273019083653272047566316584365559776493027495458238373902875937659943504873220554161550525926302303331747463515644711876653177129578303191095900909191624817826566688241804408081892785725967931714097716709526092261278071952560171111444072049229123565057483750161460024353346284167282452756217662335528813519139808291170539072125381230815729071544861602750936964829313608137325426383735122175229541155376346436093930287402089517426973178917569713384748081827255472576937471496195752727188261435633271238710131736096299798168852925540549342330775279877006784354801422249722573783561685179618816480037695005515426162362431072245638324744480"),o=t.alloc(Et(i,352)),n=e.getCodeBuilder();e.addCode(n.call(z+"_exp",n.getLocal("x"),n.i32_const(o),n.i32_const(352),n.getLocal("r")))}(),function(){!function(){const e=t.addFunction(a+"__finalExponentiationFirstChunk");e.addParam("x","i32"),e.addParam("r","i32");const i=e.getCodeBuilder(),o=i.getLocal("x"),n=o,c=i.i32_add(o,i.i32_const(6*r)),l=i.getLocal("r"),s=t.alloc(d),u=i.i32_const(s),g=u,f=i.i32_const(s+6*r),_=i.i32_const(t.alloc(d)),p=i.i32_const(t.alloc(d)),h=i.i32_const(t.alloc(d));e.addCode(i.call(U+"_copy",n,g),i.call(U+"_neg",c,f),i.call(z+"_inverse",o,_),i.call(z+"_mul",u,_,p),i.call(a+"__frobeniusMap2",p,h),i.call(z+"_mul",p,h,l))}(),j();const e=t.addFunction(a+"_finalExponentiation");e.addParam("x","i32"),e.addParam("r","i32");const i=e.getCodeBuilder(),o=i.getLocal("x"),n=i.getLocal("r"),c=i.i32_const(t.alloc(d));e.addCode(i.call(a+"__finalExponentiationFirstChunk",o,c),i.call(a+"__finalExponentiationLastChunk",c,n))}();for(let e=1;e<=5;e++)Z(e),t.exportFunction(a+"_pairingEq"+e);!function(){const e=t.addFunction(a+"_pairing");e.addParam("p","i32"),e.addParam("q","i32"),e.addParam("r","i32");const i=e.getCodeBuilder(),o=i.i32_const(t.alloc(d));e.addCode(i.call(a+"_prepareG1",i.getLocal("p"),i.i32_const(H))),e.addCode(i.call(a+"_prepareG2",i.getLocal("q"),i.i32_const($))),e.addCode(i.call(a+"_millerLoop",i.i32_const(H),i.i32_const($),o)),e.addCode(i.call(a+"_finalExponentiation",o,i.getLocal("r")))}(),t.exportFunction(a+"_pairing"),t.exportFunction(a+"_prepareG1"),t.exportFunction(a+"_prepareG2"),t.exportFunction(a+"_millerLoop"),t.exportFunction(a+"_finalExponentiation"),t.exportFunction(a+"_finalExponentiationOld"),t.exportFunction(a+"__mulBy024"),t.exportFunction(a+"__mulBy024Old"),t.exportFunction(a+"__cyclotomicSquare"),t.exportFunction(a+"__cyclotomicExp_w0")},jt=function(t,e){const a=e||"bls12381";if(t.modules[a])return a;const i=u("1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab",16),o=u("73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",16),n=Math.floor((i.minus(1).bitLength()-1)/64)+1,r=8*n,c=r,l=2*c,s=12*c,d=Math.floor((o.minus(1).bitLength()-1)/64)+1,g=8*d,f=g,_=t.alloc(Et(o,f)),p=Ut(t,i,"f1m","intq");zt(t,o,"fr","frm","intr");const h=t.alloc(Et(y(u(4)),c)),m=Rt(t,"g1m","f1m",h);Nt(t,"frm","frm","frm","frm_mul"),Tt(t,"pol","frm"),Dt(t,"qap","frm");const L=qt(t,"f1m_neg","f2m","f1m"),w=t.alloc([...Et(y(u("4")),c),...Et(y(u("4")),c)]),A=Rt(t,"g2m","f2m",w);function b(e,a){const i=t.addFunction(e);i.addParam("pG","i32"),i.addParam("pFr","i32"),i.addParam("pr","i32");const o=i.getCodeBuilder(),n=o.i32_const(t.alloc(g));i.addCode(o.call("frm_fromMontgomery",o.getLocal("pFr"),n),o.call(a,o.getLocal("pG"),n,o.i32_const(g),o.getLocal("pr"))),t.exportFunction(e)}function y(t){return u(t).times(u.one.shiftLeft(8*c)).mod(i)}b("g1m_timesFr","g1m_timesScalar"),Nt(t,"g1m","g1m","frm","g1m_timesFr"),b("g2m_timesFr","g2m_timesScalar"),Nt(t,"g2m","g2m","frm","g2m_timesFr"),b("g1m_timesFrAffine","g1m_timesScalarAffine"),b("g2m_timesFrAffine","g2m_timesScalarAffine"),Kt(t,"frm_batchApplyKey",0,"frm",g,g,g,"frm_mul"),Kt(t,"g1m_batchApplyKey",0,"frm",3*r,3*r,g,"g1m_timesFr"),Kt(t,"g1m_batchApplyKeyMixed",0,"frm",2*r,3*r,g,"g1m_timesFrAffine"),Kt(t,"g2m_batchApplyKey",0,"frm",2*r*3,3*r*2,g,"g2m_timesFr"),Kt(t,"g2m_batchApplyKeyMixed",0,"frm",2*r*2,3*r*2,g,"g2m_timesFrAffine");const I=[u("3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507"),u("1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569"),u.one],C=t.alloc([...Et(y(I[0]),c),...Et(y(I[1]),c),...Et(y(I[2]),c)]),F=[u.zero,u.one,u.zero],x=t.alloc([...Et(y(F[0]),c),...Et(y(F[1]),c),...Et(y(F[2]),c)]),v=[[u("352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160"),u("3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758")],[u("1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905"),u("927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582")],[u.one,u.zero]],E=t.alloc([...Et(y(v[0][0]),c),...Et(y(v[0][1]),c),...Et(y(v[1][0]),c),...Et(y(v[1][1]),c),...Et(y(v[2][0]),c),...Et(y(v[2][1]),c)]),B=[[u.zero,u.zero],[u.one,u.zero],[u.zero,u.zero]],S=t.alloc([...Et(y(B[0][0]),c),...Et(y(B[0][1]),c),...Et(y(B[1][0]),c),...Et(y(B[1][1]),c),...Et(y(B[2][0]),c),...Et(y(B[2][1]),c)]),G=t.alloc([...Et(y(1),c),...Et(y(0),c),...Et(y(0),c),...Et(y(0),c),...Et(y(0),c),...Et(y(0),c),...Et(y(0),c),...Et(y(0),c),...Et(y(0),c),...Et(y(0),c),...Et(y(0),c),...Et(y(0),c)]);t.alloc([...Et(y(u(2).modInv(i)),c),...Et(u(0),c)]);const P=t.alloc([...Et(y(1),c),...Et(y(1),c)]);t.alloc([...Et(y("4"),c),...Et(y("4"),c)]),function(){const e=t.addFunction(L+"_mulNR");e.addParam("x","i32"),e.addParam("pr","i32");const a=e.getCodeBuilder(),i=a.i32_const(t.alloc(c)),o=a.getLocal("x"),n=a.i32_add(a.getLocal("x"),a.i32_const(c)),r=a.getLocal("pr"),l=a.i32_add(a.getLocal("pr"),a.i32_const(c));e.addCode(a.call(p+"_copy",o,i),a.call(p+"_sub",o,n,r),a.call(p+"_add",i,n,l))}();const O=Qt(t,L+"_mulNR","f6m","f2m");!function(){const e=t.addFunction(O+"_mulNR");e.addParam("x","i32"),e.addParam("pr","i32");const a=e.getCodeBuilder(),i=a.i32_const(t.alloc(2*c));e.addCode(a.call(L+"_copy",a.getLocal("x"),i),a.call(L+"_mulNR",a.i32_add(a.getLocal("x"),a.i32_const(4*r)),a.getLocal("pr")),a.call(L+"_copy",a.i32_add(a.getLocal("x"),a.i32_const(2*r)),a.i32_add(a.getLocal("pr"),a.i32_const(4*r))),a.call(L+"_copy",i,a.i32_add(a.getLocal("pr"),a.i32_const(2*r))))}();const U=qt(t,O+"_mulNR","ftm",O),z=function(t){let e=t;const a=[];for(;e.gt(u.zero);)e.isOdd()?a.push(1):a.push(0),e=e.shiftRight(1);return a}(u("d201000000010000",16)),q=t.alloc(z),Q=3*l,M=z.length-1,k=z.reduce(((t,e)=>t+(0!=e?1:0)),0),R=6*r,N=3*r*2+(k+M+1)*Q,T=u("15132376222941642752");function D(e){const a=[[[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")]],[[u("1"),u("0")],[u("3850754370037169011952147076051364057158807420970682438676050522613628423219637725072182697113062777891589506424760"),u("151655185184498381465642749684540099398075398968325446656007613510403227271200139370504932015952886146304766135027")],[u("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620351"),u("0")],[u("2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530"),u("1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257")],[u("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"),u("0")],[u("3125332594171059424908108096204648978570118281977575435832422631601824034463382777937621250592425535493320683825557"),u("877076961050607968509681729531255177986764537961432449499635504522207616027455086505066378536590128544573588734230")],[u("4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559786"),u("0")],[u("151655185184498381465642749684540099398075398968325446656007613510403227271200139370504932015952886146304766135027"),u("3850754370037169011952147076051364057158807420970682438676050522613628423219637725072182697113062777891589506424760")],[u("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"),u("0")],[u("1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257"),u("2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530")],[u("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437"),u("0")],[u("877076961050607968509681729531255177986764537961432449499635504522207616027455086505066378536590128544573588734230"),u("3125332594171059424908108096204648978570118281977575435832422631601824034463382777937621250592425535493320683825557")]]],o=[[[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")],[u("1"),u("0")]],[[u("1"),u("0")],[u("0"),u("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436")],[u("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"),u("0")],[u("0"),u("1")],[u("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"),u("0")],[u("0"),u("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350")]],[[u("1"),u("0")],[u("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437"),u("0")],[u("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"),u("0")],[u("4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559786"),u("0")],[u("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"),u("0")],[u("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620351"),u("0")]]],n=t.addFunction(U+"_frobeniusMap"+e);n.addParam("x","i32"),n.addParam("r","i32");const s=n.getCodeBuilder();for(let i=0;i<6;i++){const u=0==i?s.getLocal("x"):s.i32_add(s.getLocal("x"),s.i32_const(i*l)),g=u,f=s.i32_add(s.getLocal("x"),s.i32_const(i*l+c)),_=0==i?s.getLocal("r"):s.i32_add(s.getLocal("r"),s.i32_const(i*l)),h=_,m=s.i32_add(s.getLocal("r"),s.i32_const(i*l+c)),w=d(a[Math.floor(i/3)][e%12],o[i%3][e%6]),A=t.alloc([...Et(y(w[0]),r),...Et(y(w[1]),r)]);e%2==1?n.addCode(s.call(p+"_copy",g,h),s.call(p+"_neg",f,m),s.call(L+"_mul",_,s.i32_const(A),_)):n.addCode(s.call(L+"_mul",u,s.i32_const(A),_))}function d(t,e){const a=u(t[0]),o=u(t[1]),n=u(e[0]),r=u(e[1]),c=[a.times(n).minus(o.times(r)).mod(i),a.times(r).add(o.times(n)).mod(i)];return c[0].isNegative()&&(c[0]=c[0].add(i)),c}}function K(e,i,o){const n=function(t){let e=t;const a=[];for(;e.gt(u.zero);){if(e.isOdd()){const t=2-e.mod(4).toJSNumber();a.push(t),e=e.minus(t)}else a.push(0);e=e.shiftRight(1)}return a}(e).map((t=>-1==t?255:t)),r=t.alloc(n),c=t.addFunction(a+"__cyclotomicExp_"+o);c.addParam("x","i32"),c.addParam("r","i32"),c.addLocal("bit","i32"),c.addLocal("i","i32");const l=c.getCodeBuilder(),d=l.getLocal("x"),g=l.getLocal("r"),f=l.i32_const(t.alloc(s));c.addCode(l.call(U+"_conjugate",d,f),l.call(U+"_one",g),l.if(l.teeLocal("bit",l.i32_load8_s(l.i32_const(n.length-1),r)),l.if(l.i32_eq(l.getLocal("bit"),l.i32_const(1)),l.call(U+"_mul",g,d,g),l.call(U+"_mul",g,f,g))),l.setLocal("i",l.i32_const(n.length-2)),l.block(l.loop(l.call(a+"__cyclotomicSquare",g,g),l.if(l.teeLocal("bit",l.i32_load8_s(l.getLocal("i"),r)),l.if(l.i32_eq(l.getLocal("bit"),l.i32_const(1)),l.call(U+"_mul",g,d,g),l.call(U+"_mul",g,f,g))),l.br_if(1,l.i32_eqz(l.getLocal("i"))),l.setLocal("i",l.i32_sub(l.getLocal("i"),l.i32_const(1))),l.br(0)))),i&&c.addCode(l.call(U+"_conjugate",g,g))}t.modules[a]={n64q:n,n64r:d,n8q:r,n8r:g,pG1gen:C,pG1zero:x,pG1b:h,pG2gen:E,pG2zero:S,pG2b:w,pq:t.modules.f1m.pq,pr:_,pOneT:G,r:o,q:i,prePSize:R,preQSize:N},function(){const e=t.addFunction(O+"_mul1");e.addParam("pA","i32"),e.addParam("pC1","i32"),e.addParam("pR","i32");const a=e.getCodeBuilder(),i=a.getLocal("pA"),o=a.i32_add(a.getLocal("pA"),a.i32_const(2*c)),n=a.i32_add(a.getLocal("pA"),a.i32_const(4*c)),r=a.getLocal("pC1"),l=a.getLocal("pR"),s=a.i32_add(a.getLocal("pR"),a.i32_const(2*c)),d=a.i32_add(a.getLocal("pR"),a.i32_const(4*c)),u=a.i32_const(t.alloc(2*c)),g=a.i32_const(t.alloc(2*c));e.addCode(a.call(L+"_add",i,o,u),a.call(L+"_add",o,n,g),a.call(L+"_mul",o,r,d),a.call(L+"_mul",g,r,l),a.call(L+"_sub",l,d,l),a.call(L+"_mulNR",l,l),a.call(L+"_mul",u,r,s),a.call(L+"_sub",s,d,s))}(),function(){const e=t.addFunction(O+"_mul01");e.addParam("pA","i32"),e.addParam("pC0","i32"),e.addParam("pC1","i32"),e.addParam("pR","i32");const a=e.getCodeBuilder(),i=a.getLocal("pA"),o=a.i32_add(a.getLocal("pA"),a.i32_const(2*c)),n=a.i32_add(a.getLocal("pA"),a.i32_const(4*c)),r=a.getLocal("pC0"),l=a.getLocal("pC1"),s=a.getLocal("pR"),d=a.i32_add(a.getLocal("pR"),a.i32_const(2*c)),u=a.i32_add(a.getLocal("pR"),a.i32_const(4*c)),g=a.i32_const(t.alloc(2*c)),f=a.i32_const(t.alloc(2*c)),_=a.i32_const(t.alloc(2*c)),p=a.i32_const(t.alloc(2*c));e.addCode(a.call(L+"_mul",i,r,g),a.call(L+"_mul",o,l,f),a.call(L+"_add",i,o,_),a.call(L+"_add",i,n,p),a.call(L+"_add",o,n,s),a.call(L+"_mul",s,l,s),a.call(L+"_sub",s,f,s),a.call(L+"_mulNR",s,s),a.call(L+"_add",s,g,s),a.call(L+"_add",r,l,d),a.call(L+"_mul",d,_,d),a.call(L+"_sub",d,g,d),a.call(L+"_sub",d,f,d),a.call(L+"_mul",p,r,u),a.call(L+"_sub",u,g,u),a.call(L+"_add",u,f,u))}(),function(){const e=t.addFunction(U+"_mul014");e.addParam("pA","i32"),e.addParam("pC0","i32"),e.addParam("pC1","i32"),e.addParam("pC4","i32"),e.addParam("pR","i32");const a=e.getCodeBuilder(),i=a.getLocal("pA"),o=a.i32_add(a.getLocal("pA"),a.i32_const(6*c)),n=a.getLocal("pC0"),r=a.getLocal("pC1"),l=a.getLocal("pC4"),s=a.i32_const(t.alloc(6*c)),d=a.i32_const(t.alloc(6*c)),u=a.i32_const(t.alloc(2*c)),g=a.getLocal("pR"),f=a.i32_add(a.getLocal("pR"),a.i32_const(6*c));e.addCode(a.call(O+"_mul01",i,n,r,s),a.call(O+"_mul1",o,l,d),a.call(L+"_add",r,l,u),a.call(O+"_add",o,i,f),a.call(O+"_mul01",f,n,u,f),a.call(O+"_sub",f,s,f),a.call(O+"_sub",f,d,f),a.call(O+"_copy",d,g),a.call(O+"_mulNR",g,g),a.call(O+"_add",g,s,g))}(),function(){const e=t.addFunction(a+"_ell");e.addParam("pP","i32"),e.addParam("pCoefs","i32"),e.addParam("pF","i32");const i=e.getCodeBuilder(),o=i.getLocal("pP"),n=i.i32_add(i.getLocal("pP"),i.i32_const(r)),l=i.getLocal("pF"),s=i.getLocal("pCoefs"),d=i.i32_add(i.getLocal("pCoefs"),i.i32_const(c)),u=i.i32_add(i.getLocal("pCoefs"),i.i32_const(2*c)),g=i.i32_add(i.getLocal("pCoefs"),i.i32_const(3*c)),f=i.i32_add(i.getLocal("pCoefs"),i.i32_const(4*c)),_=t.alloc(2*c),h=i.i32_const(_),m=i.i32_const(_),L=i.i32_const(_+c),w=t.alloc(2*c),A=i.i32_const(w),b=i.i32_const(w),y=i.i32_const(w+c);e.addCode(i.call(p+"_mul",s,n,m),i.call(p+"_mul",d,n,L),i.call(p+"_mul",u,o,b),i.call(p+"_mul",g,o,y),i.call(U+"_mul014",l,f,A,h,l))}();const V=t.alloc(R),j=t.alloc(N);function H(e){const i=t.addFunction(a+"_pairingEq"+e);for(let t=0;t<e;t++)i.addParam("p_"+t,"i32"),i.addParam("q_"+t,"i32");i.addParam("c","i32"),i.setReturnType("i32");const o=i.getCodeBuilder(),n=o.i32_const(t.alloc(s)),r=o.i32_const(t.alloc(s));i.addCode(o.call(U+"_one",n));for(let t=0;t<e;t++)i.addCode(o.call(a+"_prepareG1",o.getLocal("p_"+t),o.i32_const(V))),i.addCode(o.call(a+"_prepareG2",o.getLocal("q_"+t),o.i32_const(j))),i.addCode(o.if(o.i32_eqz(o.call(m+"_inGroupAffine",o.i32_const(V))),o.ret(o.i32_const(0))),o.if(o.i32_eqz(o.call(A+"_inGroupAffine",o.i32_const(j))),o.ret(o.i32_const(0)))),i.addCode(o.call(a+"_millerLoop",o.i32_const(V),o.i32_const(j),r)),i.addCode(o.call(U+"_mul",n,r,n));i.addCode(o.call(a+"_finalExponentiation",n,n)),i.addCode(o.call(U+"_eq",n,o.getLocal("c")))}for(let e=0;e<10;e++)D(e),t.exportFunction(U+"_frobeniusMap"+e);!function(){const e=t.addFunction(m+"_inGroupAffine");e.addParam("p","i32"),e.setReturnType("i32");const a=e.getCodeBuilder(),i=u("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"),o=u("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"),n=T.times(T).minus(u.one).divide(u(3)),l=a.i32_const(t.alloc(Et(y(i),r))),s=a.i32_const(t.alloc(Et(y(o),r))),d=a.i32_const(t.alloc(Et(n,16))),g=a.getLocal("p"),f=a.i32_add(a.getLocal("p"),a.i32_const(c)),_=t.alloc(3*c),h=a.i32_const(_),L=a.i32_const(_),w=a.i32_const(_+c);a.i32_const(_+2*c);const A=t.alloc(2*c),b=a.i32_const(A),I=a.i32_const(A),C=a.i32_const(A+c);e.addCode(a.if(a.call(m+"_isZeroAffine",a.getLocal("p")),a.ret(a.i32_const(1))),a.if(a.i32_eqz(a.call(m+"_inCurveAffine",a.getLocal("p"))),a.ret(a.i32_const(0))),a.call(p+"_mul",g,l,L),a.call(p+"_copy",f,w),a.call(p+"_mul",g,s,I),a.call(p+"_copy",f,C),a.call(m+"_doubleAffine",h,h),a.call(m+"_subMixed",h,a.getLocal("p"),h),a.call(m+"_subMixed",h,b,h),a.call(m+"_timesScalar",h,d,a.i32_const(16),h),a.ret(a.call(m+"_eqMixed",h,b)));const F=t.addFunction(m+"_inGroup");F.addParam("pIn","i32"),F.setReturnType("i32");const x=F.getCodeBuilder(),v=x.i32_const(t.alloc(2*c));F.addCode(x.call(m+"_toAffine",x.getLocal("pIn"),v),x.ret(x.call(m+"_inGroupAffine",v)))}(),function(){const e=t.addFunction(A+"_inGroupAffine");e.addParam("p","i32"),e.setReturnType("i32");const a=e.getCodeBuilder(),i=[u("2001204777610833696708894912867952078278441409969503942666029068062015825245418932221343814564507832018947136279894"),u("2001204777610833696708894912867952078278441409969503942666029068062015825245418932221343814564507832018947136279893")],o=u("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"),n=[u("2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530"),u("2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530")],s=a.i32_const(t.alloc([...Et(y(i[0]),r),...Et(y(i[1]),r)])),d=a.i32_const(t.alloc(Et(y(o),r))),g=a.i32_const(t.alloc([...Et(y(n[0]),r),...Et(y(n[1]),r)])),f=a.i32_const(t.alloc(Et(T,8))),_=a.getLocal("p"),h=a.i32_add(a.getLocal("p"),a.i32_const(l)),m=a.i32_const(t.alloc(c)),w=a.i32_const(t.alloc(l)),b=a.i32_const(t.alloc(l)),I=t.alloc(2*l),C=a.i32_const(I),F=a.i32_const(I),x=a.i32_const(I),v=a.i32_const(I+c),E=a.i32_const(I+l),B=a.i32_const(I+l),S=a.i32_const(I+l+c),G=t.alloc(3*l),P=a.i32_const(G),O=a.i32_const(G),U=a.i32_const(G),z=a.i32_const(G+c),q=a.i32_const(G+l),Q=a.i32_const(G+l),M=a.i32_const(G+l+c),k=a.i32_const(G+2*l);e.addCode(a.if(a.call(A+"_isZeroAffine",a.getLocal("p")),a.ret(a.i32_const(1))),a.if(a.i32_eqz(a.call(A+"_inCurveAffine",a.getLocal("p"))),a.ret(a.i32_const(0))),a.call(L+"_mul",_,s,w),a.call(L+"_mul",h,s,b),a.call(L+"_mul1",w,d,F),a.call(L+"_neg",b,E),a.call(L+"_neg",w,O),a.call(L+"_mul",b,g,q),a.call(p+"_sub",x,v,m),a.call(p+"_add",x,v,v),a.call(p+"_copy",m,x),a.call(p+"_sub",B,S,m),a.call(p+"_add",B,S,S),a.call(p+"_copy",m,B),a.call(p+"_add",U,z,m),a.call(p+"_sub",U,z,z),a.call(p+"_copy",m,U),a.call(p+"_sub",M,Q,m),a.call(p+"_add",Q,M,M),a.call(p+"_copy",m,Q),a.call(L+"_one",k),a.call(A+"_timesScalar",P,f,a.i32_const(8),P),a.call(A+"_addMixed",P,C,P),a.ret(a.call(A+"_eqMixed",P,a.getLocal("p"))));const R=t.addFunction(A+"_inGroup");R.addParam("pIn","i32"),R.setReturnType("i32");const N=R.getCodeBuilder(),D=N.i32_const(t.alloc(2*l));R.addCode(N.call(A+"_toAffine",N.getLocal("pIn"),D),N.ret(N.call(A+"_inGroupAffine",D)))}(),function(){const e=t.addFunction(a+"_prepAddStep");e.addParam("R","i32"),e.addParam("Q","i32"),e.addParam("r","i32");const i=e.getCodeBuilder(),o=i.getLocal("R"),n=i.i32_add(i.getLocal("R"),i.i32_const(2*r)),c=i.i32_add(i.getLocal("R"),i.i32_const(4*r)),s=i.getLocal("Q"),d=i.i32_add(i.getLocal("Q"),i.i32_const(2*r)),u=i.getLocal("r"),g=i.i32_add(i.getLocal("r"),i.i32_const(2*r)),f=i.i32_add(i.getLocal("r"),i.i32_const(4*r)),_=i.i32_const(t.alloc(l)),p=i.i32_const(t.alloc(l)),h=i.i32_const(t.alloc(l)),m=i.i32_const(t.alloc(l)),w=i.i32_const(t.alloc(l)),A=i.i32_const(t.alloc(l)),b=i.i32_const(t.alloc(l)),y=i.i32_const(t.alloc(l)),I=i.i32_const(t.alloc(l)),C=i.i32_const(t.alloc(l)),F=i.i32_const(t.alloc(l));e.addCode(i.call(L+"_square",c,_),i.call(L+"_square",d,p),i.call(L+"_mul",_,s,m),i.call(L+"_add",d,c,g),i.call(L+"_square",g,g),i.call(L+"_sub",g,p,g),i.call(L+"_sub",g,_,g),i.call(L+"_mul",g,_,g),i.call(L+"_sub",m,o,w),i.call(L+"_square",w,A),i.call(L+"_add",A,A,b),i.call(L+"_add",b,b,b),i.call(L+"_mul",b,w,y),i.call(L+"_sub",g,n,I),i.call(L+"_sub",I,n,I),i.call(L+"_mul",I,s,f),i.call(L+"_mul",b,o,C),i.call(L+"_square",I,o),i.call(L+"_sub",o,y,o),i.call(L+"_sub",o,C,o),i.call(L+"_sub",o,C,o),i.call(L+"_add",c,w,c),i.call(L+"_square",c,c),i.call(L+"_sub",c,_,c),i.call(L+"_sub",c,A,c),i.call(L+"_add",d,c,u),i.call(L+"_sub",C,o,F),i.call(L+"_mul",F,I,F),i.call(L+"_mul",n,y,m),i.call(L+"_add",m,m,m),i.call(L+"_sub",F,m,n),i.call(L+"_square",u,u),i.call(L+"_sub",u,p,u),i.call(L+"_square",c,h),i.call(L+"_sub",u,h,u),i.call(L+"_add",f,f,f),i.call(L+"_sub",f,u,f),i.call(L+"_add",c,c,u),i.call(L+"_neg",I,I),i.call(L+"_add",I,I,g))}(),function(){const e=t.addFunction(a+"_prepDblStep");e.addParam("R","i32"),e.addParam("r","i32");const i=e.getCodeBuilder(),o=i.getLocal("R"),n=i.i32_add(i.getLocal("R"),i.i32_const(2*r)),c=i.i32_add(i.getLocal("R"),i.i32_const(4*r)),s=i.getLocal("r"),d=i.i32_add(i.getLocal("r"),i.i32_const(2*r)),u=i.i32_add(i.getLocal("r"),i.i32_const(4*r)),g=i.i32_const(t.alloc(l)),f=i.i32_const(t.alloc(l)),_=i.i32_const(t.alloc(l)),p=i.i32_const(t.alloc(l)),h=i.i32_const(t.alloc(l));e.addCode(i.call(L+"_square",o,s),i.call(L+"_square",n,f),i.call(L+"_square",f,_),i.call(L+"_add",f,o,d),i.call(L+"_square",d,d),i.call(L+"_sub",d,s,d),i.call(L+"_sub",d,_,d),i.call(L+"_add",d,d,d),i.call(L+"_add",s,s,p),i.call(L+"_add",p,s,p),i.call(L+"_add",o,p,u),i.call(L+"_square",p,h),i.call(L+"_square",c,g),i.call(L+"_sub",h,d,o),i.call(L+"_sub",o,d,o),i.call(L+"_add",c,n,c),i.call(L+"_square",c,c),i.call(L+"_sub",c,f,c),i.call(L+"_sub",c,g,c),i.call(L+"_sub",d,o,n),i.call(L+"_mul",n,p,n),i.call(L+"_add",_,_,_),i.call(L+"_add",_,_,_),i.call(L+"_add",_,_,_),i.call(L+"_sub",n,_,n),i.call(L+"_mul",p,g,d),i.call(L+"_add",d,d,d),i.call(L+"_neg",d,d),i.call(L+"_square",u,u),i.call(L+"_sub",u,s,u),i.call(L+"_sub",u,h,u),i.call(L+"_add",f,f,f),i.call(L+"_add",f,f,f),i.call(L+"_sub",u,f,u),i.call(L+"_mul",c,g,s),i.call(L+"_add",s,s,s))}(),function(){const e=t.addFunction(a+"_prepareG1");e.addParam("pP","i32"),e.addParam("ppreP","i32");const i=e.getCodeBuilder();e.addCode(i.call(m+"_normalize",i.getLocal("pP"),i.getLocal("ppreP")))}(),function(){const e=t.addFunction(a+"_prepareG2");e.addParam("pQ","i32"),e.addParam("ppreQ","i32"),e.addLocal("pCoef","i32"),e.addLocal("i","i32");const i=e.getCodeBuilder(),o=i.getLocal("pQ"),n=t.alloc(3*l),r=i.i32_const(n),c=i.getLocal("ppreQ");e.addCode(i.call(A+"_normalize",o,c),i.if(i.call(A+"_isZero",c),i.ret([])),i.call(A+"_copy",c,r),i.setLocal("pCoef",i.i32_add(i.getLocal("ppreQ"),i.i32_const(3*l)))),e.addCode(i.setLocal("i",i.i32_const(z.length-2)),i.block(i.loop(i.call(a+"_prepDblStep",r,i.getLocal("pCoef")),i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(Q))),i.if(i.i32_load8_s(i.getLocal("i"),q),[...i.call(a+"_prepAddStep",r,c,i.getLocal("pCoef")),...i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(Q)))]),i.br_if(1,i.i32_eqz(i.getLocal("i"))),i.setLocal("i",i.i32_sub(i.getLocal("i"),i.i32_const(1))),i.br(0))))}(),function(){const e=t.addFunction(a+"_millerLoop");e.addParam("ppreP","i32"),e.addParam("ppreQ","i32"),e.addParam("r","i32"),e.addLocal("pCoef","i32"),e.addLocal("i","i32");const i=e.getCodeBuilder(),o=i.getLocal("ppreP");i.getLocal("ppreQ");const n=i.getLocal("pCoef"),r=i.getLocal("r");e.addCode(i.call(U+"_one",r),i.if(i.call(m+"_isZero",o),i.ret([])),i.if(i.call(m+"_isZero",i.getLocal("ppreQ")),i.ret([])),i.setLocal("pCoef",i.i32_add(i.getLocal("ppreQ"),i.i32_const(3*l))),i.setLocal("i",i.i32_const(z.length-2)),i.block(i.loop(i.call(a+"_ell",o,n,r),i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(Q))),i.if(i.i32_load8_s(i.getLocal("i"),q),[...i.call(a+"_ell",o,n,r),...i.setLocal("pCoef",i.i32_add(i.getLocal("pCoef"),i.i32_const(Q)))]),i.call(U+"_square",r,r),i.br_if(1,i.i32_eq(i.getLocal("i"),i.i32_const(1))),i.setLocal("i",i.i32_sub(i.getLocal("i"),i.i32_const(1))),i.br(0))),i.call(a+"_ell",o,n,r)),e.addCode(i.call(U+"_conjugate",r,r))}(),function(){const e=t.addFunction(a+"_finalExponentiationOld");e.addParam("x","i32"),e.addParam("r","i32");const i=u("322277361516934140462891564586510139908379969514828494218366688025288661041104682794998680497580008899973249814104447692778988208376779573819485263026159588510513834876303014016798809919343532899164848730280942609956670917565618115867287399623286813270357901731510188149934363360381614501334086825442271920079363289954510565375378443704372994881406797882676971082200626541916413184642520269678897559532260949334760604962086348898118982248842634379637598665468817769075878555493752214492790122785850202957575200176084204422751485957336465472324810982833638490904279282696134323072515220044451592646885410572234451732790590013479358343841220074174848221722017083597872017638514103174122784843925578370430843522959600095676285723737049438346544753168912974976791528535276317256904336520179281145394686565050419250614107803233314658825463117900250701199181529205942363159325765991819433914303908860460720581408201373164047773794825411011922305820065611121544561808414055302212057471395719432072209245600258134364584636810093520285711072578721435517884103526483832733289802426157301542744476740008494780363354305116978805620671467071400711358839553375340724899735460480144599782014906586543813292157922220645089192130209334926661588737007768565838519456601560804957985667880395221049249803753582637708560"),o=t.alloc(Et(i,544)),n=e.getCodeBuilder();e.addCode(n.call(U+"_exp",n.getLocal("x"),n.i32_const(o),n.i32_const(544),n.getLocal("r")))}(),function(){!function(){const e=t.addFunction(a+"__cyclotomicSquare");e.addParam("x","i32"),e.addParam("r","i32");const i=e.getCodeBuilder(),o=i.getLocal("x"),n=i.i32_add(i.getLocal("x"),i.i32_const(l)),r=i.i32_add(i.getLocal("x"),i.i32_const(2*l)),c=i.i32_add(i.getLocal("x"),i.i32_const(3*l)),s=i.i32_add(i.getLocal("x"),i.i32_const(4*l)),d=i.i32_add(i.getLocal("x"),i.i32_const(5*l)),u=i.getLocal("r"),g=i.i32_add(i.getLocal("r"),i.i32_const(l)),f=i.i32_add(i.getLocal("r"),i.i32_const(2*l)),_=i.i32_add(i.getLocal("r"),i.i32_const(3*l)),p=i.i32_add(i.getLocal("r"),i.i32_const(4*l)),h=i.i32_add(i.getLocal("r"),i.i32_const(5*l)),m=i.i32_const(t.alloc(l)),w=i.i32_const(t.alloc(l)),A=i.i32_const(t.alloc(l)),b=i.i32_const(t.alloc(l)),y=i.i32_const(t.alloc(l)),I=i.i32_const(t.alloc(l)),C=i.i32_const(t.alloc(l)),F=i.i32_const(t.alloc(l));e.addCode(i.call(L+"_mul",o,s,C),i.call(L+"_mulNR",s,m),i.call(L+"_add",o,m,m),i.call(L+"_add",o,s,F),i.call(L+"_mul",F,m,m),i.call(L+"_mulNR",C,F),i.call(L+"_add",C,F,F),i.call(L+"_sub",m,F,m),i.call(L+"_add",C,C,w),i.call(L+"_mul",c,r,C),i.call(L+"_mulNR",r,A),i.call(L+"_add",c,A,A),i.call(L+"_add",c,r,F),i.call(L+"_mul",F,A,A),i.call(L+"_mulNR",C,F),i.call(L+"_add",C,F,F),i.call(L+"_sub",A,F,A),i.call(L+"_add",C,C,b),i.call(L+"_mul",n,d,C),i.call(L+"_mulNR",d,y),i.call(L+"_add",n,y,y),i.call(L+"_add",n,d,F),i.call(L+"_mul",F,y,y),i.call(L+"_mulNR",C,F),i.call(L+"_add",C,F,F),i.call(L+"_sub",y,F,y),i.call(L+"_add",C,C,I),i.call(L+"_sub",m,o,u),i.call(L+"_add",u,u,u),i.call(L+"_add",m,u,u),i.call(L+"_add",w,s,p),i.call(L+"_add",p,p,p),i.call(L+"_add",w,p,p),i.call(L+"_mul",I,i.i32_const(P),F),i.call(L+"_add",F,c,_),i.call(L+"_add",_,_,_),i.call(L+"_add",F,_,_),i.call(L+"_sub",y,r,f),i.call(L+"_add",f,f,f),i.call(L+"_add",y,f,f),i.call(L+"_sub",A,n,g),i.call(L+"_add",g,g,g),i.call(L+"_add",A,g,g),i.call(L+"_add",b,d,h),i.call(L+"_add",h,h,h),i.call(L+"_add",b,h,h))}(),K(T,true,"w0");const e=t.addFunction(a+"_finalExponentiation");e.addParam("x","i32"),e.addParam("r","i32");const i=e.getCodeBuilder(),o=i.getLocal("x"),n=i.getLocal("r"),r=i.i32_const(t.alloc(s)),c=i.i32_const(t.alloc(s)),d=i.i32_const(t.alloc(s)),u=i.i32_const(t.alloc(s)),g=i.i32_const(t.alloc(s)),f=i.i32_const(t.alloc(s)),_=i.i32_const(t.alloc(s));e.addCode(i.call(U+"_frobeniusMap6",o,r),i.call(U+"_inverse",o,c),i.call(U+"_mul",r,c,d),i.call(U+"_copy",d,c),i.call(U+"_frobeniusMap2",d,d),i.call(U+"_mul",d,c,d),i.call(a+"__cyclotomicSquare",d,c),i.call(U+"_conjugate",c,c),i.call(a+"__cyclotomicExp_w0",d,u),i.call(a+"__cyclotomicSquare",u,g),i.call(U+"_mul",c,u,f),i.call(a+"__cyclotomicExp_w0",f,c),i.call(a+"__cyclotomicExp_w0",c,r),i.call(a+"__cyclotomicExp_w0",r,_),i.call(U+"_mul",_,g,_),i.call(a+"__cyclotomicExp_w0",_,g),i.call(U+"_conjugate",f,f),i.call(U+"_mul",g,f,g),i.call(U+"_mul",g,d,g),i.call(U+"_conjugate",d,f),i.call(U+"_mul",c,d,c),i.call(U+"_frobeniusMap3",c,c),i.call(U+"_mul",_,f,_),i.call(U+"_frobeniusMap1",_,_),i.call(U+"_mul",u,r,u),i.call(U+"_frobeniusMap2",u,u),i.call(U+"_mul",u,c,u),i.call(U+"_mul",u,_,u),i.call(U+"_mul",u,g,n))}();for(let e=1;e<=5;e++)H(e),t.exportFunction(a+"_pairingEq"+e);!function(){const e=t.addFunction(a+"_pairing");e.addParam("p","i32"),e.addParam("q","i32"),e.addParam("r","i32");const i=e.getCodeBuilder(),o=i.i32_const(t.alloc(s));e.addCode(i.call(a+"_prepareG1",i.getLocal("p"),i.i32_const(V))),e.addCode(i.call(a+"_prepareG2",i.getLocal("q"),i.i32_const(j))),e.addCode(i.call(a+"_millerLoop",i.i32_const(V),i.i32_const(j),o)),e.addCode(i.call(a+"_finalExponentiation",o,i.getLocal("r")))}(),t.exportFunction(a+"_pairing"),t.exportFunction(a+"_prepareG1"),t.exportFunction(a+"_prepareG2"),t.exportFunction(a+"_millerLoop"),t.exportFunction(a+"_finalExponentiation"),t.exportFunction(a+"_finalExponentiationOld"),t.exportFunction(a+"__cyclotomicSquare"),t.exportFunction(a+"__cyclotomicExp_w0"),t.exportFunction(O+"_mul1"),t.exportFunction(O+"_mul01"),t.exportFunction(U+"_mul014"),t.exportFunction(m+"_inGroupAffine"),t.exportFunction(m+"_inGroup"),t.exportFunction(A+"_inGroupAffine"),t.exportFunction(A+"_inGroup")};var Ht=Object.freeze({__proto__:null,stringifyBigInts:function t(e){if("bigint"==typeof e||void 0!==e.eq)return e.toString(10);if(e instanceof Uint8Array)return I(e,0);if(Array.isArray(e))return e.map(t);if("object"==typeof e){const a={};return Object.keys(e).forEach((i=>{a[i]=t(e[i])})),a}return e},unstringifyBigInts:function t(e){if("string"==typeof e&&/^[0-9]+$/.test(e))return BigInt(e);if("string"==typeof e&&/^0x[0-9a-fA-F]+$/.test(e))return BigInt(e);if(Array.isArray(e))return e.map(t);if("object"==typeof e){if(null===e)return null;const a={};return Object.keys(e).forEach((i=>{a[i]=t(e[i])})),a}return e},beBuff2int:function(t){let e=BigInt(0),a=t.length,i=0;const o=new DataView(t.buffer,t.byteOffset,t.byteLength);for(;a>0;)a>=4?(a-=4,e+=BigInt(o.getUint32(a))<<BigInt(8*i),i+=4):a>=2?(a-=2,e+=BigInt(o.getUint16(a))<<BigInt(8*i),i+=2):(a-=1,e+=BigInt(o.getUint8(a))<<BigInt(8*i),i+=1);return e},beInt2Buff:function(t,e){let a=t;const i=new Uint8Array(e),o=new DataView(i.buffer);let n=e;for(;n>0;)n-4>=0?(n-=4,o.setUint32(n,Number(a&BigInt(4294967295))),a>>=BigInt(32)):n-2>=0?(n-=2,o.setUint16(n,Number(a&BigInt(65535))),a>>=BigInt(16)):(n-=1,o.setUint8(n,Number(a&BigInt(255))),a>>=BigInt(8));if(a)throw new Error("Number does not fit in this length");return i},leBuff2int:function(t){let e=BigInt(0),a=0;const i=new DataView(t.buffer,t.byteOffset,t.byteLength);for(;a<t.length;)a+4<=t.length?(e+=BigInt(i.getUint32(a,!0))<<BigInt(8*a),a+=4):a+4<=t.length?(e+=BigInt(i.getUint16(a,!0))<<BigInt(8*a),a+=2):(e+=BigInt(i.getUint8(a,!0))<<BigInt(8*a),a+=1);return e},leInt2Buff:function(t,e){let a=t;void 0===e&&0==(e=Math.floor((P(t)-1)/8)+1)&&(e=1);const i=new Uint8Array(e),o=new DataView(i.buffer);let n=0;for(;n<e;)n+4<=e?(o.setUint32(n,Number(a&BigInt(4294967295)),!0),n+=4,a>>=BigInt(32)):n+2<=e?(o.setUint16(Number(n,a&BigInt(65535)),!0),n+=2,a>>=BigInt(16)):(o.setUint8(Number(n,a&BigInt(255)),!0),n+=1,a>>=BigInt(8));if(a)throw new Error("Number does not fit in this length");return i},stringifyFElements:function t(e,a){if("bigint"==typeof a||void 0!==a.eq)return a.toString(10);if(a instanceof Uint8Array)return e.toString(e.e(a));if(Array.isArray(a))return a.map(t.bind(this,e));if("object"==typeof a){const i={};return Object.keys(a).forEach((o=>{i[o]=t(e,a[o])})),i}return a},unstringifyFElements:function t(e,a){if("string"==typeof a&&/^[0-9]+$/.test(a))return e.e(a);if("string"==typeof a&&/^0x[0-9a-fA-F]+$/.test(a))return e.e(a);if(Array.isArray(a))return a.map(t.bind(this,e));if("object"==typeof a){if(null===a)return null;const i={};return Object.keys(a).forEach((o=>{i[o]=t(e,a[o])})),i}return a}});var $t=Object.freeze({__proto__:null,stringifyBigInts:function t(e){if("bigint"==typeof e||void 0!==e.eq)return e.toString(10);if(Array.isArray(e))return e.map(t);if("object"==typeof e){const a={};return Object.keys(e).forEach((i=>{a[i]=t(e[i])})),a}return e},unstringifyBigInts:function t(e){if("string"==typeof e&&/^[0-9]+$/.test(e))return u(e);if("string"==typeof e&&/^0x[0-9a-fA-F]+$/.test(e))return u(e);if(Array.isArray(e))return e.map(t);if("object"==typeof e){const a={};return Object.keys(e).forEach((i=>{a[i]=t(e[i])})),a}return e},beBuff2int:function(t){let e=u.zero;for(let a=0;a<t.length;a++){const i=u(t[t.length-a-1]);e=e.add(i.shiftLeft(8*a))}return e},beInt2Buff:function(t,e){let a=t,i=e-1;const o=new Uint8Array(e);for(;a.gt(u.zero)&&i>=0;){let t=Number(a.and(u("255")));o[i]=t,i--,a=a.shiftRight(8)}if(!a.eq(u.zero))throw new Error("Number does not fit in this length");return o},leBuff2int:function(t){let e=u.zero;for(let a=0;a<t.length;a++){const i=u(t[a]);e=e.add(i.shiftLeft(8*a))}return e},leInt2Buff:function(t,e){let a=t,i=0;const o=new Uint8Array(e);for(;a.gt(u.zero)&&i<o.length;){let t=Number(a.and(u(255)));o[i]=t,i++,a=a.shiftRight(8)}if(!a.eq(u.zero))throw new Error("Number does not fit in this length");return o}});let Zt={};"function"==typeof BigInt?Object.assign(Zt,Ht):Object.assign(Zt,$t);const Yt=[];for(let t=0;t<256;t++)Yt[t]=Jt(t,8);function Jt(t,e){let a=0,i=t;for(let t=0;t<e;t++)a<<=1,a|=1&i,i>>=1;return a}Zt.bitReverse=function(t,e){return(Yt[t>>>24]|Yt[t>>>16&255]<<8|Yt[t>>>8&255]<<16|Yt[255&t]<<24)>>>32-e},Zt.log2=function(t){return(0!=(4294901760&t)?(t&=4294901760,16):0)|(0!=(4278255360&t)?(t&=4278255360,8):0)|(0!=(4042322160&t)?(t&=4042322160,4):0)|(0!=(3435973836&t)?(t&=3435973836,2):0)|0!=(2863311530&t)},Zt.buffReverseBits=function(t,e){const a=t.byteLength/e,i=Zt.log2(a);if(a!=1<<i)throw new Error("Invalid number of pointers");for(let o=0;o<a;o++){const a=Zt.bitReverse(o,i);if(o>a){const i=t.slice(o*e,(o+1)*e);t.set(t.slice(a*e,(a+1)*e),o*e),t.set(i,a*e)}}},Zt.array2buffer=function(t,e){const a=new Uint8Array(e*t.length);for(let i=0;i<t.length;i++)a.set(t[i],i*e);return a},Zt.buffer2array=function(t,e){const a=t.byteLength/e,i=new Array(a);for(let o=0;o<a;o++)i[o]=t.slice(o*e,o*e+e);return i};let{bitReverse:Wt,log2:Xt,buffReverseBits:te,stringifyBigInts:ee,unstringifyBigInts:ae,beBuff2int:ie,beInt2Buff:oe,leBuff2int:ne,leInt2Buff:re,array2buffer:ce,buffer2array:le,stringifyFElements:se,unstringifyFElements:de}=Zt;var ue=Object.freeze({__proto__:null,bitReverse:Wt,log2:Xt,buffReverseBits:te,stringifyBigInts:ee,unstringifyBigInts:ae,beBuff2int:ie,beInt2Buff:oe,leBuff2int:ne,leInt2Buff:re,array2buffer:ce,buffer2array:le,stringifyFElements:se,unstringifyFElements:de});const ge=1<<30;class fe{constructor(t){this.buffers=[],this.byteLength=t;for(let e=0;e<t;e+=ge){const a=Math.min(t-e,ge);this.buffers.push(new Uint8Array(a))}}slice(t,e){void 0===e&&(e=this.byteLength),void 0===t&&(t=0);const a=e-t,i=Math.floor(t/ge);if(i==Math.floor((t+a-1)/ge)||0==a)return this.buffers[i].slice(t%ge,t%ge+a);let o,n=i,r=t%ge,c=a;for(;c>0;){const t=r+c>ge?ge-r:c,e=new Uint8Array(this.buffers[n].buffer,this.buffers[n].byteOffset+r,t);if(t==a)return e.slice();o||(o=a<=ge?new Uint8Array(a):new fe(a)),o.set(e,a-c),c-=t,n++,r=0}return o}set(t,e){void 0===e&&(e=0);const a=t.byteLength;if(0==a)return;const i=Math.floor(e/ge);if(i==Math.floor((e+a-1)/ge))return t instanceof fe&&1==t.buffers.length?this.buffers[i].set(t.buffers[0],e%ge):this.buffers[i].set(t,e%ge);let o=i,n=e%ge,r=a;for(;r>0;){const e=n+r>ge?ge-n:r,i=t.slice(a-r,a-r+e);new Uint8Array(this.buffers[o].buffer,this.buffers[o].byteOffset+n,e).set(i),r-=e,o++,n=0}}}function _e(t,e,a,i){return async function(o){const n=Math.floor(o.byteLength/a);if(n*a!==o.byteLength)throw new Error("Invalid buffer size");const r=Math.floor(n/t.concurrency),c=[];for(let l=0;l<t.concurrency;l++){let s;if(s=l<t.concurrency-1?r:n-l*r,0==s)continue;const d=[{cmd:"ALLOCSET",var:0,buff:o.slice(l*r*a,l*r*a+s*a)},{cmd:"ALLOC",var:1,len:i*s},{cmd:"CALL",fnName:e,params:[{var:0},{val:s},{var:1}]},{cmd:"GET",out:0,var:1,len:i*s}];c.push(t.queueAction(d))}const l=await Promise.all(c);let s;s=o instanceof fe?new fe(n*i):new Uint8Array(n*i);let d=0;for(let t=0;t<l.length;t++)s.set(l[t][0],d),d+=l[t][0].byteLength;return s}}class pe{constructor(t,e,a,i){if(this.tm=t,this.prefix=e,this.p=i,this.n8=a,this.type="F1",this.m=1,this.half=q(i,E),this.bitLength=P(i),this.mask=V(z(E,this.bitLength),E),this.pOp1=t.alloc(a),this.pOp2=t.alloc(a),this.pOp3=t.alloc(a),this.tm.instance.exports[e+"_zero"](this.pOp1),this.zero=this.tm.getBuff(this.pOp1,this.n8),this.tm.instance.exports[e+"_one"](this.pOp1),this.one=this.tm.getBuff(this.pOp1,this.n8),this.negone=this.neg(this.one),this.two=this.add(this.one,this.one),this.n64=Math.floor(a/8),this.n32=Math.floor(a/4),8*this.n64!=this.n8)throw new Error("n8 must be a multiple of 8");this.half=q(this.p,E),this.nqr=this.two;let o=this.exp(this.nqr,this.half);for(;!this.eq(o,this.negone);)this.nqr=this.add(this.nqr,this.one),o=this.exp(this.nqr,this.half);this.shift=this.mul(this.nqr,this.nqr),this.shiftInv=this.inv(this.shift),this.s=0;let n=V(this.p,E);for(;!k(n);)this.s=this.s+1,n=q(n,E);this.w=[],this.w[this.s]=this.exp(this.nqr,n);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=_e(t,e+"_batchToMontgomery",this.n8,this.n8),this.batchFromMontgomery=_e(t,e+"_batchFromMontgomery",this.n8,this.n8)}op2(t,e,a){return this.tm.setBuff(this.pOp1,e),this.tm.setBuff(this.pOp2,a),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op2Bool(t,e,a){return this.tm.setBuff(this.pOp1,e),this.tm.setBuff(this.pOp2,a),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2)}op1(t,e){return this.tm.setBuff(this.pOp1,e),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op1Bool(t,e){return this.tm.setBuff(this.pOp1,e),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3)}add(t,e){return this.op2("_add",t,e)}eq(t,e){return this.op2Bool("_eq",t,e)}isZero(t){return this.op1Bool("_isZero",t)}sub(t,e){return this.op2("_sub",t,e)}neg(t){return this.op1("_neg",t)}inv(t){return this.op1("_inverse",t)}toMontgomery(t){return this.op1("_toMontgomery",t)}fromMontgomery(t){return this.op1("_fromMontgomery",t)}mul(t,e){return this.op2("_mul",t,e)}div(t,e){return this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,e),this.tm.instance.exports[this.prefix+"_inverse"](this.pOp2,this.pOp2),this.tm.instance.exports[this.prefix+"_mul"](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}square(t){return this.op1("_square",t)}isSquare(t){return this.op1Bool("_isSquare",t)}sqrt(t){return this.op1("_sqrt",t)}exp(t,e){return e instanceof Uint8Array||(e=x(S(e))),this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,e),this.tm.instance.exports[this.prefix+"_exp"](this.pOp1,this.pOp2,e.byteLength,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}isNegative(t){return this.op1Bool("_isNegative",t)}e(t,e){if(t instanceof Uint8Array)return t;let a=S(t,e);O(a)?(a=j(a),it(a,this.p)&&(a=X(a,this.p)),a=V(this.p,a)):it(a,this.p)&&(a=X(a,this.p));const i=re(a,this.n8);return this.toMontgomery(i)}toString(t,e){const a=this.fromMontgomery(t),i=I(a,0);return F(i,e)}fromRng(t){let e;const a=new Uint8Array(this.n8);do{e=v;for(let a=0;a<this.n64;a++)e=K(e,z(t.nextU64(),64*a));e=rt(e,this.mask)}while(nt(e,this.p));return b(a,0,e,this.n8),a}random(){return this.fromRng(yt())}toObject(t){const e=this.fromMontgomery(t);return I(e,0)}fromObject(t){const e=new Uint8Array(this.n8);return b(e,0,t,this.n8),this.toMontgomery(e)}toRprLE(t,e,a){t.set(this.fromMontgomery(a),e)}toRprBE(t,e,a){const i=this.fromMontgomery(a);for(let t=0;t<this.n8/2;t++){const e=i[t];i[t]=i[this.n8-1-t],i[this.n8-1-t]=e}t.set(i,e)}fromRprLE(t,e){e=e||0;const a=t.slice(e,e+this.n8);return this.toMontgomery(a)}async batchInverse(t){let e=!1;const a=this.n8,i=this.n8;Array.isArray(t)?(t=ce(t,a),e=!0):t=t.slice(0,t.byteLength);const o=Math.floor(t.byteLength/a);if(o*a!==t.byteLength)throw new Error("Invalid buffer size");const n=Math.floor(o/this.tm.concurrency),r=[];for(let e=0;e<this.tm.concurrency;e++){let c;if(c=e<this.tm.concurrency-1?n:o-e*n,0==c)continue;const l=[{cmd:"ALLOCSET",var:0,buff:t.slice(e*n*a,e*n*a+c*a)},{cmd:"ALLOC",var:1,len:i*c},{cmd:"CALL",fnName:this.prefix+"_batchInverse",params:[{var:0},{val:a},{val:c},{var:1},{val:i}]},{cmd:"GET",out:0,var:1,len:i*c}];r.push(this.tm.queueAction(l))}const c=await Promise.all(r);let l;l=t instanceof fe?new fe(o*i):new Uint8Array(o*i);let s=0;for(let t=0;t<c.length;t++)l.set(c[t][0],s),s+=c[t][0].byteLength;return e?le(l,i):l}}class he{constructor(t,e,a){this.tm=t,this.prefix=e,this.F=a,this.type="F2",this.m=2*a.m,this.n8=2*this.F.n8,this.n32=2*this.F.n32,this.n64=2*this.F.n64,this.pOp1=t.alloc(2*a.n8),this.pOp2=t.alloc(2*a.n8),this.pOp3=t.alloc(2*a.n8),this.tm.instance.exports[e+"_zero"](this.pOp1),this.zero=t.getBuff(this.pOp1,this.n8),this.tm.instance.exports[e+"_one"](this.pOp1),this.one=t.getBuff(this.pOp1,this.n8),this.negone=this.neg(this.one),this.two=this.add(this.one,this.one)}op2(t,e,a){return this.tm.setBuff(this.pOp1,e),this.tm.setBuff(this.pOp2,a),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op2Bool(t,e,a){return this.tm.setBuff(this.pOp1,e),this.tm.setBuff(this.pOp2,a),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2)}op1(t,e){return this.tm.setBuff(this.pOp1,e),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op1Bool(t,e){return this.tm.setBuff(this.pOp1,e),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3)}add(t,e){return this.op2("_add",t,e)}eq(t,e){return this.op2Bool("_eq",t,e)}isZero(t){return this.op1Bool("_isZero",t)}sub(t,e){return this.op2("_sub",t,e)}neg(t){return this.op1("_neg",t)}inv(t){return this.op1("_inverse",t)}isNegative(t){return this.op1Bool("_isNegative",t)}toMontgomery(t){return this.op1("_toMontgomery",t)}fromMontgomery(t){return this.op1("_fromMontgomery",t)}mul(t,e){return this.op2("_mul",t,e)}mul1(t,e){return this.op2("_mul1",t,e)}div(t,e){return this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,e),this.tm.instance.exports[this.prefix+"_inverse"](this.pOp2,this.pOp2),this.tm.instance.exports[this.prefix+"_mul"](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}square(t){return this.op1("_square",t)}isSquare(t){return this.op1Bool("_isSquare",t)}sqrt(t){return this.op1("_sqrt",t)}exp(t,e){return e instanceof Uint8Array||(e=x(S(e))),this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,e),this.tm.instance.exports[this.prefix+"_exp"](this.pOp1,this.pOp2,e.byteLength,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}e(t,e){if(t instanceof Uint8Array)return t;if(Array.isArray(t)&&2==t.length){const a=this.F.e(t[0],e),i=this.F.e(t[1],e),o=new Uint8Array(2*this.F.n8);return o.set(a),o.set(i,2*this.F.n8),o}throw new Error("invalid F2")}toString(t,e){return`[${this.F.toString(t.slice(0,this.F.n8),e)}, ${this.F.toString(t.slice(this.F.n8),e)}]`}fromRng(t){const e=this.F.fromRng(t),a=this.F.fromRng(t),i=new Uint8Array(2*this.F.n8);return i.set(e),i.set(a,this.F.n8),i}random(){return this.fromRng(yt())}toObject(t){return[this.F.toObject(t.slice(0,this.F.n8)),this.F.toObject(t.slice(this.F.n8,2*this.F.n8))]}fromObject(t){const e=new Uint8Array(2*this.F.n8),a=this.F.fromObject(t[0]),i=this.F.fromObject(t[1]);return e.set(a),e.set(i,this.F.n8),e}c1(t){return t.slice(0,this.F.n8)}c2(t){return t.slice(this.F.n8)}}class me{constructor(t,e,a){this.tm=t,this.prefix=e,this.F=a,this.type="F3",this.m=3*a.m,this.n8=3*this.F.n8,this.n32=3*this.F.n32,this.n64=3*this.F.n64,this.pOp1=t.alloc(3*a.n8),this.pOp2=t.alloc(3*a.n8),this.pOp3=t.alloc(3*a.n8),this.tm.instance.exports[e+"_zero"](this.pOp1),this.zero=t.getBuff(this.pOp1,this.n8),this.tm.instance.exports[e+"_one"](this.pOp1),this.one=t.getBuff(this.pOp1,this.n8),this.negone=this.neg(this.one),this.two=this.add(this.one,this.one)}op2(t,e,a){return this.tm.setBuff(this.pOp1,e),this.tm.setBuff(this.pOp2,a),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op2Bool(t,e,a){return this.tm.setBuff(this.pOp1,e),this.tm.setBuff(this.pOp2,a),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2)}op1(t,e){return this.tm.setBuff(this.pOp1,e),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}op1Bool(t,e){return this.tm.setBuff(this.pOp1,e),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3)}eq(t,e){return this.op2Bool("_eq",t,e)}isZero(t){return this.op1Bool("_isZero",t)}add(t,e){return this.op2("_add",t,e)}sub(t,e){return this.op2("_sub",t,e)}neg(t){return this.op1("_neg",t)}inv(t){return this.op1("_inverse",t)}isNegative(t){return this.op1Bool("_isNegative",t)}toMontgomery(t){return this.op1("_toMontgomery",t)}fromMontgomery(t){return this.op1("_fromMontgomery",t)}mul(t,e){return this.op2("_mul",t,e)}div(t,e){return this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,e),this.tm.instance.exports[this.prefix+"_inverse"](this.pOp2,this.pOp2),this.tm.instance.exports[this.prefix+"_mul"](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,this.n8)}square(t){return this.op1("_square",t)}isSquare(t){return this.op1Bool("_isSquare",t)}sqrt(t){return this.op1("_sqrt",t)}exp(t,e){return e instanceof Uint8Array||(e=x(S(e))),this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,e),this.tm.instance.exports[this.prefix+"_exp"](this.pOp1,this.pOp2,e.byteLength,this.pOp3),this.getBuff(this.pOp3,this.n8)}e(t,e){if(t instanceof Uint8Array)return t;if(Array.isArray(t)&&3==t.length){const a=this.F.e(t[0],e),i=this.F.e(t[1],e),o=this.F.e(t[2],e),n=new Uint8Array(3*this.F.n8);return n.set(a),n.set(i,this.F.n8),n.set(o,2*this.F.n8),n}throw new Error("invalid F3")}toString(t,e){return`[${this.F.toString(t.slice(0,this.F.n8),e)}, ${this.F.toString(t.slice(this.F.n8,2*this.F.n8),e)}, ${this.F.toString(t.slice(2*this.F.n8),e)}]`}fromRng(t){const e=this.F.fromRng(t),a=this.F.fromRng(t),i=this.F.fromRng(t),o=new Uint8Array(3*this.F.n8);return o.set(e),o.set(a,this.F.n8),o.set(i,2*this.F.n8),o}random(){return this.fromRng(yt())}toObject(t){return[this.F.toObject(t.slice(0,this.F.n8)),this.F.toObject(t.slice(this.F.n8,2*this.F.n8)),this.F.toObject(t.slice(2*this.F.n8,3*this.F.n8))]}fromObject(t){const e=new Uint8Array(3*this.F.n8),a=this.F.fromObject(t[0]),i=this.F.fromObject(t[1]),o=this.F.fromObject(t[2]);return e.set(a),e.set(i,this.F.n8),e.set(o,2*this.F.n8),e}c1(t){return t.slice(0,this.F.n8)}c2(t){return t.slice(this.F.n8,2*this.F.n8)}c3(t){return t.slice(2*this.F.n8)}}class Le{constructor(t,e,a,i,o,n){this.tm=t,this.prefix=e,this.F=a,this.pOp1=t.alloc(3*a.n8),this.pOp2=t.alloc(3*a.n8),this.pOp3=t.alloc(3*a.n8),this.tm.instance.exports[e+"_zero"](this.pOp1),this.zero=this.tm.getBuff(this.pOp1,3*a.n8),this.tm.instance.exports[e+"_zeroAffine"](this.pOp1),this.zeroAffine=this.tm.getBuff(this.pOp1,2*a.n8),this.one=this.tm.getBuff(i,3*a.n8),this.g=this.one,this.oneAffine=this.tm.getBuff(i,2*a.n8),this.gAffine=this.oneAffine,this.b=this.tm.getBuff(o,a.n8),n&&(this.cofactor=x(n)),this.negone=this.neg(this.one),this.two=this.add(this.one,this.one),this.batchLEMtoC=_e(t,e+"_batchLEMtoC",2*a.n8,a.n8),this.batchLEMtoU=_e(t,e+"_batchLEMtoU",2*a.n8,2*a.n8),this.batchCtoLEM=_e(t,e+"_batchCtoLEM",a.n8,2*a.n8),this.batchUtoLEM=_e(t,e+"_batchUtoLEM",2*a.n8,2*a.n8),this.batchToJacobian=_e(t,e+"_batchToJacobian",2*a.n8,3*a.n8),this.batchToAffine=_e(t,e+"_batchToAffine",3*a.n8,2*a.n8)}op2(t,e,a){return this.tm.setBuff(this.pOp1,e),this.tm.setBuff(this.pOp2,a),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,3*this.F.n8)}op2bool(t,e,a){return this.tm.setBuff(this.pOp1,e),this.tm.setBuff(this.pOp2,a),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp2,this.pOp3)}op1(t,e){return this.tm.setBuff(this.pOp1,e),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3),this.tm.getBuff(this.pOp3,3*this.F.n8)}op1Affine(t,e){return this.tm.setBuff(this.pOp1,e),this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3),this.tm.getBuff(this.pOp3,2*this.F.n8)}op1Bool(t,e){return this.tm.setBuff(this.pOp1,e),!!this.tm.instance.exports[this.prefix+t](this.pOp1,this.pOp3)}add(t,e){if(t.byteLength==3*this.F.n8){if(e.byteLength==3*this.F.n8)return this.op2("_add",t,e);if(e.byteLength==2*this.F.n8)return this.op2("_addMixed",t,e);throw new Error("invalid point size")}if(t.byteLength==2*this.F.n8){if(e.byteLength==3*this.F.n8)return this.op2("_addMixed",e,t);if(e.byteLength==2*this.F.n8)return this.op2("_addAffine",t,e);throw new Error("invalid point size")}throw new Error("invalid point size")}sub(t,e){if(t.byteLength==3*this.F.n8){if(e.byteLength==3*this.F.n8)return this.op2("_sub",t,e);if(e.byteLength==2*this.F.n8)return this.op2("_subMixed",t,e);throw new Error("invalid point size")}if(t.byteLength==2*this.F.n8){if(e.byteLength==3*this.F.n8)return this.op2("_subMixed",e,t);if(e.byteLength==2*this.F.n8)return this.op2("_subAffine",t,e);throw new Error("invalid point size")}throw new Error("invalid point size")}neg(t){if(t.byteLength==3*this.F.n8)return this.op1("_neg",t);if(t.byteLength==2*this.F.n8)return this.op1Affine("_negAffine",t);throw new Error("invalid point size")}double(t){if(t.byteLength==3*this.F.n8)return this.op1("_double",t);if(t.byteLength==2*this.F.n8)return this.op1("_doubleAffine",t);throw new Error("invalid point size")}isZero(t){if(t.byteLength==3*this.F.n8)return this.op1Bool("_isZero",t);if(t.byteLength==2*this.F.n8)return this.op1Bool("_isZeroAffine",t);throw new Error("invalid point size")}timesScalar(t,e){let a;if(e instanceof Uint8Array||(e=x(S(e))),t.byteLength==3*this.F.n8)a=this.prefix+"_timesScalar";else{if(t.byteLength!=2*this.F.n8)throw new Error("invalid point size");a=this.prefix+"_timesScalarAffine"}return this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,e),this.tm.instance.exports[a](this.pOp1,this.pOp2,e.byteLength,this.pOp3),this.tm.getBuff(this.pOp3,3*this.F.n8)}timesFr(t,e){let a;if(t.byteLength==3*this.F.n8)a=this.prefix+"_timesFr";else{if(t.byteLength!=2*this.F.n8)throw new Error("invalid point size");a=this.prefix+"_timesFrAffine"}return this.tm.setBuff(this.pOp1,t),this.tm.setBuff(this.pOp2,e),this.tm.instance.exports[a](this.pOp1,this.pOp2,this.pOp3),this.tm.getBuff(this.pOp3,3*this.F.n8)}eq(t,e){if(t.byteLength==3*this.F.n8){if(e.byteLength==3*this.F.n8)return this.op2bool("_eq",t,e);if(e.byteLength==2*this.F.n8)return this.op2bool("_eqMixed",t,e);throw new Error("invalid point size")}if(t.byteLength==2*this.F.n8){if(e.byteLength==3*this.F.n8)return this.op2bool("_eqMixed",e,t);if(e.byteLength==2*this.F.n8)return this.op2bool("_eqAffine",t,e);throw new Error("invalid point size")}throw new Error("invalid point size")}toAffine(t){if(t.byteLength==3*this.F.n8)return this.op1Affine("_toAffine",t);if(t.byteLength==2*this.F.n8)return t;throw new Error("invalid point size")}toJacobian(t){if(t.byteLength==3*this.F.n8)return t;if(t.byteLength==2*this.F.n8)return this.op1("_toJacobian",t);throw new Error("invalid point size")}toRprUncompressed(t,e,a){if(this.tm.setBuff(this.pOp1,a),a.byteLength==3*this.F.n8)this.tm.instance.exports[this.prefix+"_toAffine"](this.pOp1,this.pOp1);else if(a.byteLength!=2*this.F.n8)throw new Error("invalid point size");this.tm.instance.exports[this.prefix+"_LEMtoU"](this.pOp1,this.pOp1);const i=this.tm.getBuff(this.pOp1,2*this.F.n8);t.set(i,e)}fromRprUncompressed(t,e){const a=t.slice(e,e+2*this.F.n8);return this.tm.setBuff(this.pOp1,a),this.tm.instance.exports[this.prefix+"_UtoLEM"](this.pOp1,this.pOp1),this.tm.getBuff(this.pOp1,2*this.F.n8)}toRprCompressed(t,e,a){if(this.tm.setBuff(this.pOp1,a),a.byteLength==3*this.F.n8)this.tm.instance.exports[this.prefix+"_toAffine"](this.pOp1,this.pOp1);else if(a.byteLength!=2*this.F.n8)throw new Error("invalid point size");this.tm.instance.exports[this.prefix+"_LEMtoC"](this.pOp1,this.pOp1);const i=this.tm.getBuff(this.pOp1,this.F.n8);t.set(i,e)}fromRprCompressed(t,e){const a=t.slice(e,e+this.F.n8);return this.tm.setBuff(this.pOp1,a),this.tm.instance.exports[this.prefix+"_CtoLEM"](this.pOp1,this.pOp2),this.tm.getBuff(this.pOp2,2*this.F.n8)}toUncompressed(t){const e=new Uint8Array(2*this.F.n8);return this.toRprUncompressed(e,0,t),e}toRprLEM(t,e,a){if(a.byteLength!=2*this.F.n8){if(a.byteLength!=3*this.F.n8)throw new Error("invalid point size");{this.tm.setBuff(this.pOp1,a),this.tm.instance.exports[this.prefix+"_toAffine"](this.pOp1,this.pOp1);const i=this.tm.getBuff(this.pOp1,2*this.F.n8);t.set(i,e)}}else t.set(a,e)}fromRprLEM(t,e){return e=e||0,t.slice(e,e+2*this.F.n8)}toString(t,e){if(t.byteLength==3*this.F.n8){return`[ ${this.F.toString(t.slice(0,this.F.n8),e)}, ${this.F.toString(t.slice(this.F.n8,2*this.F.n8),e)}, ${this.F.toString(t.slice(2*this.F.n8),e)} ]`}if(t.byteLength==2*this.F.n8){return`[ ${this.F.toString(t.slice(0,this.F.n8),e)}, ${this.F.toString(t.slice(this.F.n8),e)} ]`}throw new Error("invalid point size")}isValid(t){if(this.isZero(t))return!0;const e=this.F,a=this.toAffine(t),i=a.slice(0,this.F.n8),o=a.slice(this.F.n8,2*this.F.n8),n=e.add(e.mul(e.square(i),i),this.b),r=e.square(o);return e.eq(n,r)}fromRng(t){const e=this.F;let a,i,o=[];do{o[0]=e.fromRng(t),a=t.nextBool(),i=e.add(e.mul(e.square(o[0]),o[0]),this.b)}while(!e.isSquare(i));o[1]=e.sqrt(i);a^e.isNegative(o[1])&&(o[1]=e.neg(o[1]));let n=new Uint8Array(2*this.F.n8);return n.set(o[0]),n.set(o[1],this.F.n8),this.cofactor&&(n=this.timesScalar(n,this.cofactor)),n}toObject(t){if(this.isZero(t))return[this.F.toObject(this.F.zero),this.F.toObject(this.F.one),this.F.toObject(this.F.zero)];const e=this.F.toObject(t.slice(0,this.F.n8)),a=this.F.toObject(t.slice(this.F.n8,2*this.F.n8));let i;return i=t.byteLength==3*this.F.n8?this.F.toObject(t.slice(2*this.F.n8,3*this.F.n8)):this.F.toObject(this.F.one),[e,a,i]}fromObject(t){const e=this.F.fromObject(t[0]),a=this.F.fromObject(t[1]);let i;if(i=3==t.length?this.F.fromObject(t[2]):this.F.one,this.F.isZero(i,this.F.one))return this.zeroAffine;if(this.F.eq(i,this.F.one)){const t=new Uint8Array(2*this.F.n8);return t.set(e),t.set(a,this.F.n8),t}{const t=new Uint8Array(3*this.F.n8);return t.set(e),t.set(a,this.F.n8),t.set(i,2*this.F.n8),t}}e(t){return t instanceof Uint8Array?t:this.fromObject(t)}x(t){return this.toAffine(t).slice(0,this.F.n8)}y(t){return this.toAffine(t).slice(this.F.n8)}}function we(t){const e=32767;let a,i;async function o(t){const o=new Uint8Array(t.code),n=await WebAssembly.compile(o);i=new WebAssembly.Memory({initial:t.init,maximum:e}),a=await WebAssembly.instantiate(n,{env:{memory:i}})}function n(t){const a=new Uint32Array(i.buffer,0,1);for(;3&a[0];)a[0]++;const o=a[0];if(a[0]+=t,a[0]+t>i.buffer.byteLength){const o=i.buffer.byteLength/65536;let n=Math.floor((a[0]+t)/65536)+1;n>e&&(n=e),i.grow(n-o)}return o}function r(t){const e=n(t.byteLength);return l(e,t),e}function c(t,e){const a=new Uint8Array(i.buffer);return new Uint8Array(a.buffer,a.byteOffset+t,e)}function l(t,e){new Uint8Array(i.buffer).set(new Uint8Array(e),t)}function s(t){if("INIT"==t[0].cmd)return o(t[0]);const e={vars:[],out:[]},s=new Uint32Array(i.buffer,0,1)[0];for(let i=0;i<t.length;i++)switch(t[i].cmd){case"ALLOCSET":e.vars[t[i].var]=r(t[i].buff);break;case"ALLOC":e.vars[t[i].var]=n(t[i].len);break;case"SET":l(e.vars[t[i].var],t[i].buff);break;case"CALL":{const o=[];for(let a=0;a<t[i].params.length;a++){const n=t[i].params[a];void 0!==n.var?o.push(e.vars[n.var]+(n.offset||0)):void 0!==n.val&&o.push(n.val)}a.exports[t[i].fnName](...o);break}case"GET":e.out[t[i].out]=c(e.vars[t[i].var],t[i].len).slice();break;default:throw new Error("Invalid cmd")}return new Uint32Array(i.buffer,0,1)[0]=s,e.out}return t&&(t.onmessage=function(e){let a;if(a=e.data?e.data:e,"INIT"==a[0].cmd)o(a[0]).then((function(){t.postMessage(a.result)}));else if("TERMINATE"==a[0].cmd)t.close();else{const e=s(a);t.postMessage(e)}}),s}var Ae={},be=Worker;class ye{constructor(){this.promise=new Promise(((t,e)=>{this.reject=e,this.resolve=t}))}}var Ie;const Ce="data:application/javascript;base64,"+(Ie="("+we.toString()+")(self)",globalThis.btoa(Ie));class Fe{constructor(){this.actionQueue=[],this.oldPFree=0}startSyncOp(){if(0!=this.oldPFree)throw new Error("Sync operation in progress");this.oldPFree=this.u32[0]}endSyncOp(){if(0==this.oldPFree)throw new Error("No sync operation in progress");this.u32[0]=this.oldPFree,this.oldPFree=0}postAction(t,e,a,i){if(this.working[t])throw new Error("Posting a job t a working worker");return this.working[t]=!0,this.pendingDeferreds[t]=i||new ye,this.workers[t].postMessage(e,a),this.pendingDeferreds[t].promise}processWorks(){for(let t=0;t<this.workers.length&&this.actionQueue.length>0;t++)if(0==this.working[t]){const e=this.actionQueue.shift();this.postAction(t,e.data,e.transfers,e.deferred)}}queueAction(t,e){const a=new ye;if(this.singleThread){const e=this.taskManager(t);a.resolve(e)}else this.actionQueue.push({data:t,transfers:e,deferred:a}),this.processWorks();return a.promise}resetMemory(){this.u32[0]=this.initalPFree}allocBuff(t){const e=this.alloc(t.byteLength);return this.setBuff(e,t),e}getBuff(t,e){return this.u8.slice(t,t+e)}setBuff(t,e){this.u8.set(new Uint8Array(e),t)}alloc(t){for(;3&this.u32[0];)this.u32[0]++;const e=this.u32[0];return this.u32[0]+=t,e}async terminate(){for(let t=0;t<this.workers.length;t++)this.workers[t].postMessage([{cmd:"TERMINATE"}]);var t;await(t=200,new Promise((e=>setTimeout(e,t))))}}function xe(t,e){const a=t[e],i=t.Fr,o=t.tm;t[e].batchApplyKey=async function(t,n,r,c,l){let s,d,u,g,f;if(c=c||"affine",l=l||"affine","G1"==e)"jacobian"==c?(u=3*a.F.n8,s="g1m_batchApplyKey"):(u=2*a.F.n8,s="g1m_batchApplyKeyMixed"),g=3*a.F.n8,"jacobian"==l?f=3*a.F.n8:(d="g1m_batchToAffine",f=2*a.F.n8);else if("G2"==e)"jacobian"==c?(u=3*a.F.n8,s="g2m_batchApplyKey"):(u=2*a.F.n8,s="g2m_batchApplyKeyMixed"),g=3*a.F.n8,"jacobian"==l?f=3*a.F.n8:(d="g2m_batchToAffine",f=2*a.F.n8);else{if("Fr"!=e)throw new Error("Invalid group: "+e);s="frm_batchApplyKey",u=a.n8,g=a.n8,f=a.n8}const _=Math.floor(t.byteLength/u),p=Math.floor(_/o.concurrency),h=[];r=i.e(r);let m=i.e(n);for(let e=0;e<o.concurrency;e++){let a;if(a=e<o.concurrency-1?p:_-e*p,0==a)continue;const n=[];n.push({cmd:"ALLOCSET",var:0,buff:t.slice(e*p*u,e*p*u+a*u)}),n.push({cmd:"ALLOCSET",var:1,buff:m}),n.push({cmd:"ALLOCSET",var:2,buff:r}),n.push({cmd:"ALLOC",var:3,len:a*Math.max(g,f)}),n.push({cmd:"CALL",fnName:s,params:[{var:0},{val:a},{var:1},{var:2},{var:3}]}),d&&n.push({cmd:"CALL",fnName:d,params:[{var:3},{val:a},{var:3}]}),n.push({cmd:"GET",out:0,var:3,len:a*f}),h.push(o.queueAction(n)),m=i.mul(m,i.exp(r,a))}const L=await Promise.all(h);let w;w=t instanceof fe?new fe(_*f):new Uint8Array(_*f);let A=0;for(let t=0;t<L.length;t++)w.set(L[t][0],A),A+=L[t][0].byteLength;return w}}const ve=[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 Ee(t,e){const a=t[e],i=a.tm;async function o(t,i,o,n,r){if(!(t instanceof Uint8Array))throw n&&n.error(`${r} _multiExpChunk buffBases is not Uint8Array`),new Error(`${r} _multiExpChunk buffBases is not Uint8Array`);if(!(i instanceof Uint8Array))throw n&&n.error(`${r} _multiExpChunk buffScalars is not Uint8Array`),new Error(`${r} _multiExpChunk buffScalars is not Uint8Array`);let c,l;if(o=o||"affine","G1"==e)"affine"==o?(l="g1m_multiexpAffine_chunk",c=2*a.F.n8):(l="g1m_multiexp_chunk",c=3*a.F.n8);else{if("G2"!=e)throw new Error("Invalid group");"affine"==o?(l="g2m_multiexpAffine_chunk",c=2*a.F.n8):(l="g2m_multiexp_chunk",c=3*a.F.n8)}const s=Math.floor(t.byteLength/c);if(0==s)return a.zero;const d=Math.floor(i.byteLength/s);if(d*s!=i.byteLength)throw new Error("Scalar size does not match");const u=ve[Xt(s)],g=Math.floor((8*d-1)/u)+1,f=[];for(let e=0;e<g;e++){const o=[{cmd:"ALLOCSET",var:0,buff:t},{cmd:"ALLOCSET",var:1,buff:i},{cmd:"ALLOC",var:2,len:3*a.F.n8},{cmd:"CALL",fnName:l,params:[{var:0},{var:1},{val:d},{val:s},{val:e*u},{val:Math.min(8*d-e*u,u)},{var:2}]},{cmd:"GET",out:0,var:2,len:3*a.F.n8}];f.push(a.tm.queueAction(o))}const _=await Promise.all(f);let p=a.zero;for(let t=_.length-1;t>=0;t--){if(!a.isZero(p))for(let t=0;t<u;t++)p=a.double(p);p=a.add(p,_[t][0])}return p}async function n(t,n,r,c,l){const s=1<<22;let d;if("G1"==e)d="affine"==r?2*a.F.n8:3*a.F.n8;else{if("G2"!=e)throw new Error("Invalid group");d="affine"==r?2*a.F.n8:3*a.F.n8}const u=Math.floor(t.byteLength/d),g=Math.floor(n.byteLength/u);if(g*u!=n.byteLength)throw new Error("Scalar size does not match");const f=ve[Xt(u)],_=Math.floor((8*g-1)/f)+1;let p;p=Math.floor(u/(i.concurrency/_)),p>s&&(p=s),p<1024&&(p=1024);const h=[];for(let e=0;e<u;e+=p){c&&c.debug(`Multiexp start: ${l}: ${e}/${u}`);const a=Math.min(u-e,p),i=t.slice(e*d,(e+a)*d),s=n.slice(e*g,(e+a)*g);h.push(o(i,s,r,c,l).then((t=>(c&&c.debug(`Multiexp end: ${l}: ${e}/${u}`),t))))}const m=await Promise.all(h);let L=a.zero;for(let t=m.length-1;t>=0;t--)L=a.add(L,m[t]);return L}a.multiExp=async function(t,e,a,i){return await n(t,e,"jacobian",a,i)},a.multiExpAffine=async function(t,e,a,i){return await n(t,e,"affine",a,i)}}function Be(t,e){const a=t[e],i=t.Fr,o=a.tm;async function n(t,c,l,s,d,u){l=l||"affine",s=s||"affine";let g,f,_,p,h,m,L,w;"G1"==e?("affine"==l?(g=2*a.F.n8,p="g1m_batchToJacobian"):g=3*a.F.n8,f=3*a.F.n8,c&&(w="g1m_fftFinal"),L="g1m_fftJoin",m="g1m_fftMix","affine"==s?(_=2*a.F.n8,h="g1m_batchToAffine"):_=3*a.F.n8):"G2"==e?("affine"==l?(g=2*a.F.n8,p="g2m_batchToJacobian"):g=3*a.F.n8,f=3*a.F.n8,c&&(w="g2m_fftFinal"),L="g2m_fftJoin",m="g2m_fftMix","affine"==s?(_=2*a.F.n8,h="g2m_batchToAffine"):_=3*a.F.n8):"Fr"==e&&(g=a.n8,f=a.n8,_=a.n8,c&&(w="frm_fftFinal"),m="frm_fftMix",L="frm_fftJoin");let A=!1;Array.isArray(t)?(t=ce(t,g),A=!0):t=t.slice(0,t.byteLength);const b=t.byteLength/g,y=Xt(b);if(1<<y!=b)throw new Error("fft must be multiple of 2");if(y==i.s+1){let e;return e=c?await async function(t,e,a,o,c){let l,s;l=t.slice(0,t.byteLength/2),s=t.slice(t.byteLength/2,t.byteLength);const d=[];d.push(n(l,!0,e,"jacobian",o,c)),d.push(n(s,!0,e,"jacobian",o,c)),[l,s]=await Promise.all(d);const u=await r(l,s,"fftJoinExtInv",i.one,i.shiftInv,"jacobian",a,o,c);let g;g=u[0].byteLength>1<<28?new fe(2*u[0].byteLength):new Uint8Array(2*u[0].byteLength);return g.set(u[0]),g.set(u[1],u[0].byteLength),g}(t,l,s,d,u):await async function(t,e,a,o,c){let l,s;l=t.slice(0,t.byteLength/2),s=t.slice(t.byteLength/2,t.byteLength);const d=[];[l,s]=await r(l,s,"fftJoinExt",i.one,i.shift,e,"jacobian",o,c),d.push(n(l,!1,"jacobian",a,o,c)),d.push(n(s,!1,"jacobian",a,o,c));const u=await Promise.all(d);let g;g=u[0].byteLength>1<<28?new fe(2*u[0].byteLength):new Uint8Array(2*u[0].byteLength);return g.set(u[0]),g.set(u[1],u[0].byteLength),g}(t,l,s,d,u),A?le(e,_):e}let I,C,F;c&&(I=i.inv(i.e(b))),te(t,g);let x=Math.min(16384,b),v=b/x;for(;v<o.concurrency&&x>=16;)v*=2,x/=2;const E=Xt(x),B=[];for(let e=0;e<v;e++){d&&d.debug(`${u}: fft ${y} mix start: ${e}/${v}`);const a=[];a.push({cmd:"ALLOC",var:0,len:f*x});const i=t.slice(x*e*g,x*(e+1)*g);a.push({cmd:"SET",var:0,buff:i}),p&&a.push({cmd:"CALL",fnName:p,params:[{var:0},{val:x},{var:0}]});for(let t=1;t<=E;t++)a.push({cmd:"CALL",fnName:m,params:[{var:0},{val:x},{val:t}]});E==y?(w&&(a.push({cmd:"ALLOCSET",var:1,buff:I}),a.push({cmd:"CALL",fnName:w,params:[{var:0},{val:x},{var:1}]})),h&&a.push({cmd:"CALL",fnName:h,params:[{var:0},{val:x},{var:0}]}),a.push({cmd:"GET",out:0,var:0,len:x*_})):a.push({cmd:"GET",out:0,var:0,len:f*x}),B.push(o.queueAction(a).then((t=>(d&&d.debug(`${u}: fft ${y} mix end: ${e}/${v}`),t))))}F=await Promise.all(B);for(let t=0;t<v;t++)F[t]=F[t][0];for(let t=E+1;t<=y;t++){d&&d.debug(`${u}: fft ${y} join: ${t}/${y}`);const e=1<<y-t,a=v/e,n=[];for(let r=0;r<e;r++)for(let c=0;c<a/2;c++){const l=i.exp(i.w[t],c*x),s=i.w[t],g=r*a+c,p=r*a+c+a/2,m=[];m.push({cmd:"ALLOCSET",var:0,buff:F[g]}),m.push({cmd:"ALLOCSET",var:1,buff:F[p]}),m.push({cmd:"ALLOCSET",var:2,buff:l}),m.push({cmd:"ALLOCSET",var:3,buff:s}),m.push({cmd:"CALL",fnName:L,params:[{var:0},{var:1},{val:x},{var:2},{var:3}]}),t==y?(w&&(m.push({cmd:"ALLOCSET",var:4,buff:I}),m.push({cmd:"CALL",fnName:w,params:[{var:0},{val:x},{var:4}]}),m.push({cmd:"CALL",fnName:w,params:[{var:1},{val:x},{var:4}]})),h&&(m.push({cmd:"CALL",fnName:h,params:[{var:0},{val:x},{var:0}]}),m.push({cmd:"CALL",fnName:h,params:[{var:1},{val:x},{var:1}]})),m.push({cmd:"GET",out:0,var:0,len:x*_}),m.push({cmd:"GET",out:1,var:1,len:x*_})):(m.push({cmd:"GET",out:0,var:0,len:x*f}),m.push({cmd:"GET",out:1,var:1,len:x*f})),n.push(o.queueAction(m).then((i=>(d&&d.debug(`${u}: fft ${y} join ${t}/${y} ${r+1}/${e} ${c}/${a/2}`),i))))}const r=await Promise.all(n);for(let t=0;t<e;t++)for(let e=0;e<a/2;e++){const i=t*a+e,o=t*a+e+a/2,n=r.shift();F[i]=n[0],F[o]=n[1]}}if(C=t instanceof fe?new fe(b*_):new Uint8Array(b*_),c){C.set(F[0].slice((x-1)*_));let t=_;for(let e=v-1;e>0;e--)C.set(F[e],t),t+=x*_,delete F[e];C.set(F[0].slice(0,(x-1)*_),t),delete F[0]}else for(let t=0;t<v;t++)C.set(F[t],x*_*t),delete F[t];return A?le(C,_):C}async function r(t,n,r,c,l,s,d,u,g){let f,_,p,h,m,L;if("G1"==e)"affine"==s?(m=2*a.F.n8,_="g1m_batchToJacobian"):m=3*a.F.n8,L=3*a.F.n8,f="g1m_"+r,"affine"==d?(p="g1m_batchToAffine",h=2*a.F.n8):h=3*a.F.n8;else if("G2"==e)"affine"==s?(m=2*a.F.n8,_="g2m_batchToJacobian"):m=3*a.F.n8,f="g2m_"+r,L=3*a.F.n8,"affine"==d?(p="g2m_batchToAffine",h=2*a.F.n8):h=3*a.F.n8;else{if("Fr"!=e)throw new Error("Invalid group");m=i.n8,h=i.n8,L=i.n8,f="frm_"+r}if(t.byteLength!=n.byteLength)throw new Error("Invalid buffer size");const w=Math.floor(t.byteLength/m);if(w!=1<<Xt(w))throw new Error("Invalid number of points");let A=Math.floor(w/o.concurrency);A<16&&(A=16),A>65536&&(A=65536);const b=[];for(let e=0;e<w;e+=A){u&&u.debug(`${g}: fftJoinExt Start: ${e}/${w}`);const a=Math.min(w-e,A),r=i.mul(c,i.exp(l,e)),s=[],d=t.slice(e*m,(e+a)*m),y=n.slice(e*m,(e+a)*m);s.push({cmd:"ALLOC",var:0,len:L*a}),s.push({cmd:"SET",var:0,buff:d}),s.push({cmd:"ALLOC",var:1,len:L*a}),s.push({cmd:"SET",var:1,buff:y}),s.push({cmd:"ALLOCSET",var:2,buff:r}),s.push({cmd:"ALLOCSET",var:3,buff:l}),_&&(s.push({cmd:"CALL",fnName:_,params:[{var:0},{val:a},{var:0}]}),s.push({cmd:"CALL",fnName:_,params:[{var:1},{val:a},{var:1}]})),s.push({cmd:"CALL",fnName:f,params:[{var:0},{var:1},{val:a},{var:2},{var:3},{val:i.s}]}),p&&(s.push({cmd:"CALL",fnName:p,params:[{var:0},{val:a},{var:0}]}),s.push({cmd:"CALL",fnName:p,params:[{var:1},{val:a},{var:1}]})),s.push({cmd:"GET",out:0,var:0,len:a*h}),s.push({cmd:"GET",out:1,var:1,len:a*h}),b.push(o.queueAction(s).then((t=>(u&&u.debug(`${g}: fftJoinExt End: ${e}/${w}`),t))))}const y=await Promise.all(b);let I,C;w*h>1<<28?(I=new fe(w*h),C=new fe(w*h)):(I=new Uint8Array(w*h),C=new Uint8Array(w*h));let F=0;for(let t=0;t<y.length;t++)I.set(y[t][0],F),C.set(y[t][1],F),F+=y[t][0].byteLength;return[I,C]}a.fft=async function(t,e,a,i,o){return await n(t,!1,e,a,i,o)},a.ifft=async function(t,e,a,i,o){return await n(t,!0,e,a,i,o)},a.lagrangeEvaluations=async function(t,o,c,l,s){let d;if(o=o||"affine",c=c||"affine","G1"==e)d="affine"==o?2*a.F.n8:3*a.F.n8;else if("G2"==e)d="affine"==o?2*a.F.n8:3*a.F.n8;else{if("Fr"!=e)throw new Error("Invalid group");d=i.n8}const u=t.byteLength/d,g=Xt(u);if(2**g*d!=t.byteLength)throw l&&l.error("lagrangeEvaluations iinvalid input size"),new Error("lagrangeEvaluations invalid Input size");if(g<=i.s)return await a.ifft(t,o,c,l,s);if(g>i.s+1)throw l&&l.error("lagrangeEvaluations input too big"),new Error("lagrangeEvaluations input too big");let f=t.slice(0,t.byteLength/2),_=t.slice(t.byteLength/2,t.byteLength);const p=i.exp(i.shift,u/2),h=i.inv(i.sub(i.one,p));[f,_]=await r(f,_,"prepareLagrangeEvaluation",h,i.shiftInv,o,"jacobian",l,s+" prep");const m=[];let L;return m.push(n(f,!0,"jacobian",c,l,s+" t0")),m.push(n(_,!0,"jacobian",c,l,s+" t1")),[f,_]=await Promise.all(m),L=f.byteLength>1<<28?new fe(2*f.byteLength):new Uint8Array(2*f.byteLength),L.set(f),L.set(_,f.byteLength),L},a.fftMix=async function(t){const n=3*a.F.n8;let r,c;if("G1"==e)r="g1m_fftMix",c="g1m_fftJoin";else if("G2"==e)r="g2m_fftMix",c="g2m_fftJoin";else{if("Fr"!=e)throw new Error("Invalid group");r="frm_fftMix",c="frm_fftJoin"}const l=Math.floor(t.byteLength/n),s=Xt(l);let d=1<<Xt(o.concurrency);l<=2*d&&(d=1);const u=l/d,g=Xt(u),f=[];for(let e=0;e<d;e++){const a=[],i=t.slice(e*u*n,(e+1)*u*n);a.push({cmd:"ALLOCSET",var:0,buff:i});for(let t=1;t<=g;t++)a.push({cmd:"CALL",fnName:r,params:[{var:0},{val:u},{val:t}]});a.push({cmd:"GET",out:0,var:0,len:u*n}),f.push(o.queueAction(a))}const _=await Promise.all(f),p=[];for(let t=0;t<_.length;t++)p[t]=_[t][0];for(let t=g+1;t<=s;t++){const e=1<<s-t,a=d/e,r=[];for(let l=0;l<e;l++)for(let e=0;e<a/2;e++){const s=i.exp(i.w[t],e*u),d=i.w[t],g=l*a+e,f=l*a+e+a/2,_=[];_.push({cmd:"ALLOCSET",var:0,buff:p[g]}),_.push({cmd:"ALLOCSET",var:1,buff:p[f]}),_.push({cmd:"ALLOCSET",var:2,buff:s}),_.push({cmd:"ALLOCSET",var:3,buff:d}),_.push({cmd:"CALL",fnName:c,params:[{var:0},{var:1},{val:u},{var:2},{var:3}]}),_.push({cmd:"GET",out:0,var:0,len:u*n}),_.push({cmd:"GET",out:1,var:1,len:u*n}),r.push(o.queueAction(_))}const l=await Promise.all(r);for(let t=0;t<e;t++)for(let e=0;e<a/2;e++){const i=t*a+e,o=t*a+e+a/2,n=l.shift();p[i]=n[0],p[o]=n[1]}}let h;h=t instanceof fe?new fe(l*n):new Uint8Array(l*n);let m=0;for(let t=0;t<d;t++)h.set(p[t],m),m+=p[t].byteLength;return h},a.fftJoin=async function(t,n,r,c){const l=3*a.F.n8;let s;if("G1"==e)s="g1m_fftJoin";else if("G2"==e)s="g2m_fftJoin";else{if("Fr"!=e)throw new Error("Invalid group");s="frm_fftJoin"}if(t.byteLength!=n.byteLength)throw new Error("Invalid buffer size");const d=Math.floor(t.byteLength/l);if(d!=1<<Xt(d))throw new Error("Invalid number of points");let u=1<<Xt(o.concurrency);d<=2*u&&(u=1);const g=d/u,f=[];for(let e=0;e<u;e++){const a=[],d=i.mul(r,i.exp(c,e*g)),u=t.slice(e*g*l,(e+1)*g*l),_=n.slice(e*g*l,(e+1)*g*l);a.push({cmd:"ALLOCSET",var:0,buff:u}),a.push({cmd:"ALLOCSET",var:1,buff:_}),a.push({cmd:"ALLOCSET",var:2,buff:d}),a.push({cmd:"ALLOCSET",var:3,buff:c}),a.push({cmd:"CALL",fnName:s,params:[{var:0},{var:1},{val:g},{var:2},{var:3}]}),a.push({cmd:"GET",out:0,var:0,len:g*l}),a.push({cmd:"GET",out:1,var:1,len:g*l}),f.push(o.queueAction(a))}const _=await Promise.all(f);let p,h;t instanceof fe?(p=new fe(d*l),h=new fe(d*l)):(p=new Uint8Array(d*l),h=new Uint8Array(d*l));let m=0;for(let t=0;t<_.length;t++)p.set(_[t][0],m),h.set(_[t][1],m),m+=_[t][0].byteLength;return[p,h]},a.fftFinal=async function(t,i){const n=3*a.F.n8,r=2*a.F.n8;let c,l;if("G1"==e)c="g1m_fftFinal",l="g1m_batchToAffine";else{if("G2"!=e)throw new Error("Invalid group");c="g2m_fftFinal",l="g2m_batchToAffine"}const s=Math.floor(t.byteLength/n);if(s!=1<<Xt(s))throw new Error("Invalid number of points");const d=Math.floor(s/o.concurrency),u=[];for(let e=0;e<o.concurrency;e++){let a;if(a=e<o.concurrency-1?d:s-e*d,0==a)continue;const g=[],f=t.slice(e*d*n,(e*d+a)*n);g.push({cmd:"ALLOCSET",var:0,buff:f}),g.push({cmd:"ALLOCSET",var:1,buff:i}),g.push({cmd:"CALL",fnName:c,params:[{var:0},{val:a},{var:1}]}),g.push({cmd:"CALL",fnName:l,params:[{var:0},{val:a},{var:0}]}),g.push({cmd:"GET",out:0,var:0,len:a*r}),u.push(o.queueAction(g))}const g=await Promise.all(u);let f;f=t instanceof fe?new fe(s*r):new Uint8Array(s*r);let _=0;for(let t=g.length-1;t>=0;t--)f.set(g[t][0],_),_+=g[t][0].byteLength;return f}}async function Se(t){const e=await async function(t,e){const a=new Fe;a.memory=new WebAssembly.Memory({initial:25}),a.u8=new Uint8Array(a.memory.buffer),a.u32=new Uint32Array(a.memory.buffer);const i=await WebAssembly.compile(t.code);if(a.instance=await WebAssembly.instantiate(i,{env:{memory:a.memory}}),a.singleThread=e,a.initalPFree=a.u32[0],a.pq=t.pq,a.pr=t.pr,a.pG1gen=t.pG1gen,a.pG1zero=t.pG1zero,a.pG2gen=t.pG2gen,a.pG2zero=t.pG2zero,a.pOneT=t.pOneT,e)a.code=t.code,a.taskManager=we(),await a.taskManager([{cmd:"INIT",init:25,code:a.code.slice()}]),a.concurrency=1;else{let e;a.workers=[],a.pendingDeferreds=[],a.working=[],e="object"==typeof navigator&&navigator.hardwareConcurrency?navigator.hardwareConcurrency:Ae.cpus().length,0==e&&(e=2),e>64&&(e=64),a.concurrency=e;for(let t=0;t<e;t++)a.workers[t]=new be(Ce),a.workers[t].addEventListener("message",o(t)),a.working[t]=!1;const i=[];for(let e=0;e<a.workers.length;e++){const o=t.code.slice();i.push(a.postAction(e,[{cmd:"INIT",init:25,code:o}],[o.buffer]))}await Promise.all(i)}return a;function o(t){return function(e){let i;i=e&&e.data?e.data:e,a.working[t]=!1,a.pendingDeferreds[t].resolve(i),a.processWorks()}}}(t.wasm,t.singleThread),a={};return a.q=S(t.wasm.q),a.r=S(t.wasm.r),a.name=t.name,a.tm=e,a.prePSize=t.wasm.prePSize,a.preQSize=t.wasm.preQSize,a.Fr=new pe(e,"frm",t.n8r,t.r),a.F1=new pe(e,"f1m",t.n8q,t.q),a.F2=new he(e,"f2m",a.F1),a.G1=new Le(e,"g1m",a.F1,t.wasm.pG1gen,t.wasm.pG1b,t.cofactorG1),a.G2=new Le(e,"g2m",a.F2,t.wasm.pG2gen,t.wasm.pG2b,t.cofactorG2),a.F6=new me(e,"f6m",a.F2),a.F12=new he(e,"ftm",a.F6),a.Gt=a.F12,xe(a,"G1"),xe(a,"G2"),xe(a,"Fr"),Ee(a,"G1"),Ee(a,"G2"),Be(a,"G1"),Be(a,"G2"),Be(a,"Fr"),function(t){const e=t.tm;t.pairing=function(a,i){e.startSyncOp();const o=e.allocBuff(t.G1.toJacobian(a)),n=e.allocBuff(t.G2.toJacobian(i)),r=e.alloc(t.Gt.n8);e.instance.exports[t.name+"_pairing"](o,n,r);const c=e.getBuff(r,t.Gt.n8);return e.endSyncOp(),c},t.pairingEq=async function(){let a,i;arguments.length%2==1?(a=arguments[arguments.length-1],i=(arguments.length-1)/2):(a=t.Gt.one,i=arguments.length/2);const o=[];for(let a=0;a<i;a++){const i=[],n=t.G1.toJacobian(arguments[2*a]);i.push({cmd:"ALLOCSET",var:0,buff:n}),i.push({cmd:"ALLOC",var:1,len:t.prePSize});const r=t.G2.toJacobian(arguments[2*a+1]);i.push({cmd:"ALLOCSET",var:2,buff:r}),i.push({cmd:"ALLOC",var:3,len:t.preQSize}),i.push({cmd:"ALLOC",var:4,len:t.Gt.n8}),i.push({cmd:"CALL",fnName:t.name+"_prepareG1",params:[{var:0},{var:1}]}),i.push({cmd:"CALL",fnName:t.name+"_prepareG2",params:[{var:2},{var:3}]}),i.push({cmd:"CALL",fnName:t.name+"_millerLoop",params:[{var:1},{var:3},{var:4}]}),i.push({cmd:"GET",out:0,var:4,len:t.Gt.n8}),o.push(e.queueAction(i))}const n=await Promise.all(o);e.startSyncOp();const r=e.alloc(t.Gt.n8);e.instance.exports.ftm_one(r);for(let t=0;t<n.length;t++){const a=e.allocBuff(n[t][0]);e.instance.exports.ftm_mul(r,a,r)}e.instance.exports[t.name+"_finalExponentiation"](r,r);const c=e.allocBuff(a),l=!!e.instance.exports.ftm_eq(r,c);return e.endSyncOp(),l},t.prepareG1=function(t){this.tm.startSyncOp();const e=this.tm.allocBuff(t),a=this.tm.alloc(this.prePSize);this.tm.instance.exports[this.name+"_prepareG1"](e,a);const i=this.tm.getBuff(a,this.prePSize);return this.tm.endSyncOp(),i},t.prepareG2=function(t){this.tm.startSyncOp();const e=this.tm.allocBuff(t),a=this.tm.alloc(this.preQSize);this.tm.instance.exports[this.name+"_prepareG2"](e,a);const i=this.tm.getBuff(a,this.preQSize);return this.tm.endSyncOp(),i},t.millerLoop=function(t,e){this.tm.startSyncOp();const a=this.tm.allocBuff(t),i=this.tm.allocBuff(e),o=this.tm.alloc(this.Gt.n8);this.tm.instance.exports[this.name+"_millerLoop"](a,i,o);const n=this.tm.getBuff(o,this.Gt.n8);return this.tm.endSyncOp(),n},t.finalExponentiation=function(t){this.tm.startSyncOp();const e=this.tm.allocBuff(t),a=this.tm.alloc(this.Gt.n8);this.tm.instance.exports[this.name+"_finalExponentiation"](e,a);const i=this.tm.getBuff(a,this.Gt.n8);return this.tm.endSyncOp(),i}}(a),a.array2buffer=function(t,e){const a=new Uint8Array(e*t.length);for(let i=0;i<t.length;i++)a.set(t[i],i*e);return a},a.buffer2array=function(t,e){const a=t.byteLength/e,i=new Array(a);for(let o=0;o<a;o++)i[o]=t.slice(o*e,o*e+e);return i},a}function Ge(t){let e;return e="string"==typeof t&&"0x"==t.slice(0,2).toLowerCase()?u(t.slice(2),16):u(t),e}function Pe(t){const e=[];let a=Ge(t);if(a.isNegative())throw new Error("Number cannot be negative");for(;!a.isZero();)e.push(a.and(127).toJSNumber()),a=a.shiftRight(7);0==e.length&&e.push(0);for(let t=0;t<e.length-1;t++)e[t]=128|e[t];return e}function Oe(t){let e,a;const i=t.bitLength().toJSNumber();t<0?(a=!0,e=u.one.shiftLeft(i).add(t)):(a=!1,e=Ge(t));const o=7-i%7,n=u.one.shiftLeft(o).minus(1).shiftLeft(i),r=(1<<7-o)-1|128,c=Pe(e.add(n));return a||(c[c.length-1]=c[c.length-1]&r),c}function Ue(t){let e=Ge(t);if(e.greater(u("FFFFFFFF",16)))throw new Error("Number too big");return Pe(e)}var ze=function(t){const e=function(t){for(var e=[],a=0;a<t.length;a++){var i=t.charCodeAt(a);i<128?e.push(i):i<2048?e.push(192|i>>6,128|63&i):i<55296||i>=57344?e.push(224|i>>12,128|i>>6&63,128|63&i):(a++,i=65536+((1023&i)<<10|1023&t.charCodeAt(a)),e.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|63&i))}return e}(t);return[...Ue(e.length),...e]},qe=function t(e){if("string"==typeof e){let t=e.split("\n");for(let e=0;e<t.length;e++)t[e]&&(t[e]=" "+t[e]);return t.join("\n")}if(Array.isArray(e)){for(let a=0;a<e.length;a++)e[a]=t(e[a]);return e}},Qe={toNumber:Ge,u32:function(t){const e=[],a=Ge(t);return e.push(a.and(255).toJSNumber()),e.push(a.shiftRight(8).and(255).toJSNumber()),e.push(a.shiftRight(16).and(255).toJSNumber()),e.push(a.shiftRight(24).and(255).toJSNumber()),e},u64:function(t){const e=[],a=Ge(t);return e.push(a.and(255).toJSNumber()),e.push(a.shiftRight(8).and(255).toJSNumber()),e.push(a.shiftRight(16).and(255).toJSNumber()),e.push(a.shiftRight(24).and(255).toJSNumber()),e.push(a.shiftRight(32).and(255).toJSNumber()),e.push(a.shiftRight(40).and(255).toJSNumber()),e.push(a.shiftRight(48).and(255).toJSNumber()),e.push(a.shiftRight(56).and(255).toJSNumber()),e},varuint32:Ue,varuint64:function(t){let e=Ge(t);if(e.greater(u("FFFFFFFFFFFFFFFF",16)))throw new Error("Number too big");return Pe(e)},varint32:function(t){let e=Ge(t);if(e.greater(u("FFFFFFFF",16)))throw new Error("Number too big");if(e.greater(u("7FFFFFFF",16))&&(e=e.minus(u("100000000",16))),e.lesser(u("-80000000",16)))throw new Error("Number too small");return Oe(e)},varint64:function(t){let e=Ge(t);if(e.greater(u("FFFFFFFFFFFFFFFF",16)))throw new Error("Number too big");if(e.greater(u("7FFFFFFFFFFFFFFF",16))&&(e=e.minus(u("10000000000000000",16))),e.lesser(u("-8000000000000000",16)))throw new Error("Number too small");return Oe(e)},string:ze,toHexString:function(t){return Array.from(t,(function(t){return("0"+(255&t).toString(16)).slice(-2)})).join("")},ident:qe};var Me=class{constructor(t){this.func=t,this.functionName=t.functionName,this.module=t.module}setLocal(t,e){const a=this.func.localIdxByName[t];if(void 0===a)throw new Error(`Local Variable not defined: Function: ${this.functionName} local: ${t} `);return[...e,33,...Qe.varuint32(a)]}teeLocal(t,e){const a=this.func.localIdxByName[t];if(void 0===a)throw new Error(`Local Variable not defined: Function: ${this.functionName} local: ${t} `);return[...e,34,...Qe.varuint32(a)]}getLocal(t){const e=this.func.localIdxByName[t];if(void 0===e)throw new Error(`Local Variable not defined: Function: ${this.functionName} local: ${t} `);return[32,...Qe.varuint32(e)]}i64_load8_s(t,e,a){const i=e||0;return[...t,48,void 0===a?0:a,...Qe.varuint32(i)]}i64_load8_u(t,e,a){const i=e||0;return[...t,49,void 0===a?0:a,...Qe.varuint32(i)]}i64_load16_s(t,e,a){const i=e||0;return[...t,50,void 0===a?1:a,...Qe.varuint32(i)]}i64_load16_u(t,e,a){const i=e||0;return[...t,51,void 0===a?1:a,...Qe.varuint32(i)]}i64_load32_s(t,e,a){const i=e||0;return[...t,52,void 0===a?2:a,...Qe.varuint32(i)]}i64_load32_u(t,e,a){const i=e||0;return[...t,53,void 0===a?2:a,...Qe.varuint32(i)]}i64_load(t,e,a){const i=e||0;return[...t,41,void 0===a?3:a,...Qe.varuint32(i)]}i64_store(t,e,a,i){let o,n,r;return Array.isArray(e)?(o=0,n=3,r=e):Array.isArray(a)?(o=e,n=3,r=a):Array.isArray(i)&&(o=e,n=a,r=i),[...t,...r,55,n,...Qe.varuint32(o)]}i64_store32(t,e,a,i){let o,n,r;return Array.isArray(e)?(o=0,n=2,r=e):Array.isArray(a)?(o=e,n=2,r=a):Array.isArray(i)&&(o=e,n=a,r=i),[...t,...r,62,n,...Qe.varuint32(o)]}i64_store16(t,e,a,i){let o,n,r;return Array.isArray(e)?(o=0,n=1,r=e):Array.isArray(a)?(o=e,n=1,r=a):Array.isArray(i)&&(o=e,n=a,r=i),[...t,...r,61,n,...Qe.varuint32(o)]}i64_store8(t,e,a,i){let o,n,r;return Array.isArray(e)?(o=0,n=0,r=e):Array.isArray(a)?(o=e,n=0,r=a):Array.isArray(i)&&(o=e,n=a,r=i),[...t,...r,60,n,...Qe.varuint32(o)]}i32_load8_s(t,e,a){const i=e||0;return[...t,44,void 0===a?0:a,...Qe.varuint32(i)]}i32_load8_u(t,e,a){const i=e||0;return[...t,45,void 0===a?0:a,...Qe.varuint32(i)]}i32_load16_s(t,e,a){const i=e||0;return[...t,46,void 0===a?1:a,...Qe.varuint32(i)]}i32_load16_u(t,e,a){const i=e||0;return[...t,47,void 0===a?1:a,...Qe.varuint32(i)]}i32_load(t,e,a){const i=e||0;return[...t,40,void 0===a?2:a,...Qe.varuint32(i)]}i32_store(t,e,a,i){let o,n,r;return Array.isArray(e)?(o=0,n=2,r=e):Array.isArray(a)?(o=e,n=2,r=a):Array.isArray(i)&&(o=e,n=a,r=i),[...t,...r,54,n,...Qe.varuint32(o)]}i32_store16(t,e,a,i){let o,n,r;return Array.isArray(e)?(o=0,n=1,r=e):Array.isArray(a)?(o=e,n=1,r=a):Array.isArray(i)&&(o=e,n=a,r=i),[...t,...r,59,n,...Qe.varuint32(o)]}i32_store8(t,e,a,i){let o,n,r;return Array.isArray(e)?(o=0,n=0,r=e):Array.isArray(a)?(o=e,n=0,r=a):Array.isArray(i)&&(o=e,n=a,r=i),[...t,...r,58,n,...Qe.varuint32(o)]}call(t,...e){const a=this.module.functionIdxByName[t];if(void 0===a)throw new Error(`Function not defined: Function: ${t}`);return[...[].concat(...e),16,...Qe.varuint32(a)]}call_indirect(t,...e){return[...[].concat(...e),...t,17,0,0]}if(t,e,a){return a?[...t,4,64,...e,5,...a,11]:[...t,4,64,...e,11]}block(t){return[2,64,...t,11]}loop(...t){return[3,64,...[].concat(...t),11]}br_if(t,e){return[...e,13,...Qe.varuint32(t)]}br(t){return[12,...Qe.varuint32(t)]}ret(t){return[...t,15]}drop(t){return[...t,26]}i64_const(t){return[66,...Qe.varint64(t)]}i32_const(t){return[65,...Qe.varint32(t)]}i64_eqz(t){return[...t,80]}i64_eq(t,e){return[...t,...e,81]}i64_ne(t,e){return[...t,...e,82]}i64_lt_s(t,e){return[...t,...e,83]}i64_lt_u(t,e){return[...t,...e,84]}i64_gt_s(t,e){return[...t,...e,85]}i64_gt_u(t,e){return[...t,...e,86]}i64_le_s(t,e){return[...t,...e,87]}i64_le_u(t,e){return[...t,...e,88]}i64_ge_s(t,e){return[...t,...e,89]}i64_ge_u(t,e){return[...t,...e,90]}i64_add(t,e){return[...t,...e,124]}i64_sub(t,e){return[...t,...e,125]}i64_mul(t,e){return[...t,...e,126]}i64_div_s(t,e){return[...t,...e,127]}i64_div_u(t,e){return[...t,...e,128]}i64_rem_s(t,e){return[...t,...e,129]}i64_rem_u(t,e){return[...t,...e,130]}i64_and(t,e){return[...t,...e,131]}i64_or(t,e){return[...t,...e,132]}i64_xor(t,e){return[...t,...e,133]}i64_shl(t,e){return[...t,...e,134]}i64_shr_s(t,e){return[...t,...e,135]}i64_shr_u(t,e){return[...t,...e,136]}i64_extend_i32_s(t){return[...t,172]}i64_extend_i32_u(t){return[...t,173]}i64_clz(t){return[...t,121]}i64_ctz(t){return[...t,122]}i32_eqz(t){return[...t,69]}i32_eq(t,e){return[...t,...e,70]}i32_ne(t,e){return[...t,...e,71]}i32_lt_s(t,e){return[...t,...e,72]}i32_lt_u(t,e){return[...t,...e,73]}i32_gt_s(t,e){return[...t,...e,74]}i32_gt_u(t,e){return[...t,...e,75]}i32_le_s(t,e){return[...t,...e,76]}i32_le_u(t,e){return[...t,...e,77]}i32_ge_s(t,e){return[...t,...e,78]}i32_ge_u(t,e){return[...t,...e,79]}i32_add(t,e){return[...t,...e,106]}i32_sub(t,e){return[...t,...e,107]}i32_mul(t,e){return[...t,...e,108]}i32_div_s(t,e){return[...t,...e,109]}i32_div_u(t,e){return[...t,...e,110]}i32_rem_s(t,e){return[...t,...e,111]}i32_rem_u(t,e){return[...t,...e,112]}i32_and(t,e){return[...t,...e,113]}i32_or(t,e){return[...t,...e,114]}i32_xor(t,e){return[...t,...e,115]}i32_shl(t,e){return[...t,...e,116]}i32_shr_s(t,e){return[...t,...e,117]}i32_shr_u(t,e){return[...t,...e,118]}i32_rotl(t,e){return[...t,...e,119]}i32_rotr(t,e){return[...t,...e,120]}i32_wrap_i64(t){return[...t,167]}i32_clz(t){return[...t,103]}i32_ctz(t){return[...t,104]}unreachable(){return[0]}current_memory(){return[63,0]}comment(){return[]}};const ke={i32:127,i64:126,f32:125,f64:124,anyfunc:112,func:96,emptyblock:64};var Re=class{constructor(t,e,a,i,o){if("import"==a)this.fnType="import",this.moduleName=i,this.fieldName=o;else{if("internal"!=a)throw new Error("Invalid function fnType: "+a);this.fnType="internal"}this.module=t,this.fnName=e,this.params=[],this.locals=[],this.localIdxByName={},this.code=[],this.returnType=null,this.nextLocal=0}addParam(t,e){if(this.localIdxByName[t])throw new Error(`param already exists. Function: ${this.fnName}, Param: ${t} `);const a=this.nextLocal++;this.localIdxByName[t]=a,this.params.push({type:e})}addLocal(t,e,a){const i=a||1;if(this.localIdxByName[t])throw new Error(`local already exists. Function: ${this.fnName}, Param: ${t} `);const o=this.nextLocal++;this.localIdxByName[t]=o,this.locals.push({type:e,length:i})}setReturnType(t){if(this.returnType)throw new Error(`returnType already defined. Function: ${this.fnName}`);this.returnType=t}getSignature(){return[96,...[...Qe.varuint32(this.params.length),...this.params.map((t=>ke[t.type]))],...this.returnType?[1,ke[this.returnType]]:[0]]}getBody(){const t=this.locals.map((t=>[...Qe.varuint32(t.length),ke[t.type]])),e=[...Qe.varuint32(this.locals.length),...[].concat(...t),...this.code,11];return[...Qe.varuint32(e.length),...e]}addCode(...t){this.code.push(...[].concat(...t))}getCodeBuilder(){return new Me(this)}};var Ne=class{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([...Qe.u32(1836278016),...Qe.u32(1),...this._buildType(),...this._buildImport(),...this._buildFunctionDeclarations(),...this._buildFunctionsTable(),...this._buildExports(),...this._buildElements(),...this._buildCode(),...this._buildData()])}addFunction(t){if(void 0!==this.functionIdxByName[t])throw new Error(`Function already defined: ${t}`);const e=this.functions.length;return this.functionIdxByName[t]=e,this.functions.push(new Re(this,t,"internal")),this.nInternalFunctions++,this.functions[e]}addIimportFunction(t,e,a){if(void 0!==this.functionIdxByName[t])throw new Error(`Function already defined: ${t}`);if(this.functions.length>0&&"internal"==this.functions[this.functions.length-1].type)throw new Error(`Import functions must be declared before internal: ${t}`);let i=a||t;const o=this.functions.length;return this.functionIdxByName[t]=o,this.functions.push(new Re(this,t,"import",e,i)),this.nImportFunctions++,this.functions[o]}setMemory(t,e,a){this.memory={pagesSize:t,moduleName:e||"env",fieldName:a||"memory"}}exportFunction(t,e){const a=e||t;if(void 0===this.functionIdxByName[t])throw new Error(`Function not defined: ${t}`);const i=this.functionIdxByName[t];a!=t&&(this.functionIdxByName[a]=i),this.exports.push({exportName:a,idx:i})}addFunctionToTable(t){const e=this.functionIdxByName[t];this.functionsTable.push(e)}addData(t,e){this.datas.push({offset:t,bytes:e})}alloc(t,e){let a,i;(Array.isArray(t)||ArrayBuffer.isView(t))&&void 0===e?(a=t.length,i=t):(a=t,i=e),a=1+(a-1>>3)<<3;const o=this.free;return this.free+=a,i&&this.addData(o,i),o}allocString(t){const e=(new globalThis.TextEncoder).encode(t);return this.alloc([...e,0])}_setSignatures(){this.signatures=[];const t={};if(this.functionsTable.length>0){const e=this.functions[this.functionsTable[0]].getSignature();t["s_"+Qe.toHexString(e)]=0,this.signatures.push(e)}for(let e=0;e<this.functions.length;e++){const a=this.functions[e].getSignature(),i="s_"+Qe.toHexString(a);void 0===t[i]&&(t[i]=this.signatures.length,this.signatures.push(a)),this.functions[e].signatureIdx=t[i]}}_buildSection(t,e){return[t,...Qe.varuint32(e.length),...e]}_buildType(){return this._buildSection(1,[...Qe.varuint32(this.signatures.length),...[].concat(...this.signatures)])}_buildImport(){const t=[];t.push([...Qe.string(this.memory.moduleName),...Qe.string(this.memory.fieldName),2,0,...Qe.varuint32(this.memory.pagesSize)]);for(let e=0;e<this.nImportFunctions;e++)t.push([...Qe.string(this.functions[e].moduleName),...Qe.string(this.functions[e].fieldName),0,...Qe.varuint32(this.functions[e].signatureIdx)]);return this._buildSection(2,Qe.varuint32(t.length).concat(...t))}_buildFunctionDeclarations(){const t=[];for(let e=this.nImportFunctions;e<this.nImportFunctions+this.nInternalFunctions;e++)t.push(...Qe.varuint32(this.functions[e].signatureIdx));return this._buildSection(3,[...Qe.varuint32(t.length),...t])}_buildFunctionsTable(){return 0==this.functionsTable.length?[]:this._buildSection(4,[...Qe.varuint32(1),112,0,...Qe.varuint32(this.functionsTable.length)])}_buildElements(){if(0==this.functionsTable.length)return[];const t=[];for(let e=0;e<this.functionsTable.length;e++)t.push(...Qe.varuint32(this.functionsTable[e]));return this._buildSection(9,[...Qe.varuint32(1),...Qe.varuint32(0),65,...Qe.varint32(0),11,...Qe.varuint32(this.functionsTable.length),...t])}_buildExports(){const t=[];for(let e=0;e<this.exports.length;e++)t.push([...Qe.string(this.exports[e].exportName),0,...Qe.varuint32(this.exports[e].idx)]);return this._buildSection(7,Qe.varuint32(t.length).concat(...t))}_buildCode(){const t=[];for(let e=this.nImportFunctions;e<this.nImportFunctions+this.nInternalFunctions;e++)t.push(this.functions[e].getBody());return this._buildSection(10,Qe.varuint32(t.length).concat(...t))}_buildData(){const t=[];t.push([0,65,0,11,4,...Qe.u32(this.free)]);for(let e=0;e<this.datas.length;e++)t.push([0,65,...Qe.varint32(this.datas[e].offset),11,...Qe.varuint32(this.datas[e].bytes.length),...this.datas[e].bytes]);return this._buildSection(11,Qe.varuint32(t.length).concat(...t))}},Te=Ne;async function De(t,e){const a=new Te;a.setMemory(25),Vt(a),e&&e(a);const i={};if(i.code=a.build(),i.pq=a.modules.f1m.pq,i.pr=a.modules.frm.pq,i.pG1gen=a.modules.bn128.pG1gen,i.pG1zero=a.modules.bn128.pG1zero,i.pG1b=a.modules.bn128.pG1b,i.pG2gen=a.modules.bn128.pG2gen,i.pG2zero=a.modules.bn128.pG2zero,i.pG2b=a.modules.bn128.pG2b,i.pOneT=a.modules.bn128.pOneT,i.prePSize=a.modules.bn128.prePSize,i.preQSize=a.modules.bn128.preQSize,i.n8q=32,i.n8r=32,i.q=a.modules.bn128.q,i.r=a.modules.bn128.r,!t&&globalThis.curve_bn128)return globalThis.curve_bn128;const o={name:"bn128",wasm:i,q:S("21888242871839275222246405745257275088696311157297823662689037894645226208583"),r:S("21888242871839275222246405745257275088548364400416034343698204186575808495617"),n8q:32,n8r:32,cofactorG2:S("30644e72e131a029b85045b68181585e06ceecda572a2489345f2299c0f9fa8d",16),singleThread:!!t},n=await Se(o);return n.terminate=async function(){o.singleThread||(globalThis.curve_bn128=null,await this.tm.terminate())},t||(globalThis.curve_bn128=n),n}async function Ke(t,e){const a=new Te;a.setMemory(25),jt(a),e&&e(a);const i={};if(i.code=a.build(),i.pq=a.modules.f1m.pq,i.pr=a.modules.frm.pq,i.pG1gen=a.modules.bls12381.pG1gen,i.pG1zero=a.modules.bls12381.pG1zero,i.pG1b=a.modules.bls12381.pG1b,i.pG2gen=a.modules.bls12381.pG2gen,i.pG2zero=a.modules.bls12381.pG2zero,i.pG2b=a.modules.bls12381.pG2b,i.pOneT=a.modules.bls12381.pOneT,i.prePSize=a.modules.bls12381.prePSize,i.preQSize=a.modules.bls12381.preQSize,i.n8q=48,i.n8r=32,i.q=a.modules.bn128.q,i.r=a.modules.bn128.r,!t&&globalThis.curve_bls12381)return globalThis.curve_bls12381;const o={name:"bls12381",wasm:i,q:S("1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab",16),r:S("73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",16),n8q:48,n8r:32,cofactorG1:S("0x396c8c005555e1568c00aaab0000aaab",16),cofactorG2:S("0x5d543a95414e7f1091d50792876a202cd91de4547085abaa68a205b2e5a7ddfa628f1cb4d9e82ef21537e293a6691ae1616ec6e786f0c70cf1c38e31c7238e5",16),singleThread:!!t},n=await Se(o);return n.terminate=async function(){o.singleThread||(globalThis.curve_bls12381=null,await this.tm.terminate())},t||(globalThis.curve_bls12381=n),n}globalThis.curve_bn128=null,globalThis.curve_bls12381=null;const Ve=S("73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",16),je=S("21888242871839275222246405745257275088548364400416034343698204186575808495617");S("1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab",16),S("21888242871839275222246405745257275088696311157297823662689037894645226208583");const He=gt,$e=ue;var Ze={};async function Ye(t,e,a,i){if(a=a||262144,["w+","wx+","r","ax+","a+"].indexOf(e)<0)throw new Error("Invalid open option");const o=await Ze.promises.open(t,e),n=await o.stat();return new Je(o,n,a,i,t)}class Je{constructor(t,e,a,i,o){for(this.fileName=o,this.fd=t,this.pos=0,this.pageSize=i||256;this.pageSize<e.blksize;)this.pageSize*=2;this.totalSize=e.size,this.totalPages=Math.floor((e.size-1)/this.pageSize)+1,this.maxPagesLoaded=Math.floor(a/this.pageSize)+1,this.pages={},this.pendingLoads=[],this.writing=!1,this.reading=!1,this.avBuffs=[],this.history={}}_loadPage(t){const e=this,a=new Promise(((a,i)=>{e.pendingLoads.push({page:t,resolve:a,reject:i})}));return e.__statusPage("After Load request: ",t),a}__statusPage(t,e){const a=[],i=this;if(!i.logHistory)return;a.push("=="+t+" "+e);let o="";for(let t=0;t<i.pendingLoads.length;t++)i.pendingLoads[t].page==e&&(o=o+" "+t);if(o&&a.push("Pending loads:"+o),void 0!==i.pages[e]){const t=i.pages[e];a.push("Loaded"),a.push("pendingOps: "+t.pendingOps),t.loading&&a.push("loading: "+t.loading),t.writing&&a.push("writing"),t.dirty&&a.push("dirty")}a.push("=="),i.history[e]||(i.history[e]=[]),i.history[e].push(a)}__printHistory(t){const e=this;e.history[t]||console.log("Empty History ",t),console.log("History "+t);for(let a=0;a<e.history[t].length;a++)for(let i=0;i<e.history[t][a].length;i++)console.log("-> "+e.history[t][a][i])}_triggerLoad(){const t=this;if(t.reading)return;if(0==t.pendingLoads.length)return;const e=Object.keys(t.pages),a=[];for(let i=0;i<e.length;i++){const o=t.pages[parseInt(e[i])];0!=o.dirty||0!=o.pendingOps||o.writing||o.loading||a.push(parseInt(e[i]))}let i=t.maxPagesLoaded-e.length;const o=[];for(;t.pendingLoads.length>0&&(void 0!==t.pages[t.pendingLoads[0].page]||i>0||a.length>0);){const e=t.pendingLoads.shift();if(void 0!==t.pages[e.page]){t.pages[e.page].pendingOps++;const i=a.indexOf(e.page);i>=0&&a.splice(i,1),t.pages[e.page].loading?t.pages[e.page].loading.push(e):e.resolve(),t.__statusPage("After Load (cached): ",e.page)}else{if(i)i--;else{const e=a.shift();t.__statusPage("Before Unload: ",e),t.avBuffs.unshift(t.pages[e]),delete t.pages[e],t.__statusPage("After Unload: ",e)}e.page>=t.totalPages?(t.pages[e.page]=n(),e.resolve(),t.__statusPage("After Load (new): ",e.page)):(t.reading=!0,t.pages[e.page]=n(),t.pages[e.page].loading=[e],o.push(t.fd.read(t.pages[e.page].buff,0,t.pageSize,e.page*t.pageSize).then((a=>{t.pages[e.page].size=a.bytesRead;const i=t.pages[e.page].loading;delete t.pages[e.page].loading;for(let t=0;t<i.length;t++)i[t].resolve();return t.__statusPage("After Load (loaded): ",e.page),a}),(t=>{e.reject(t)}))),t.__statusPage("After Load (loading): ",e.page))}}function n(){if(t.avBuffs.length>0){const e=t.avBuffs.shift();return e.dirty=!1,e.pendingOps=1,e.size=0,e}return{dirty:!1,buff:new Uint8Array(t.pageSize),pendingOps:1,size:0}}Promise.all(o).then((()=>{t.reading=!1,t.pendingLoads.length>0&&setImmediate(t._triggerLoad.bind(t)),t._tryClose()}))}_triggerWrite(){const t=this;if(t.writing)return;const e=Object.keys(t.pages),a=[];for(let i=0;i<e.length;i++){const o=t.pages[parseInt(e[i])];o.dirty&&(o.dirty=!1,o.writing=!0,t.writing=!0,a.push(t.fd.write(o.buff,0,o.size,parseInt(e[i])*t.pageSize).then((()=>{o.writing=!1}),(e=>{console.log("ERROR Writing: "+e),t.error=e,t._tryClose()}))))}t.writing&&Promise.all(a).then((()=>{t.writing=!1,setImmediate(t._triggerWrite.bind(t)),t._tryClose(),t.pendingLoads.length>0&&setImmediate(t._triggerLoad.bind(t))}))}_getDirtyPage(){for(let t in this.pages)if(this.pages[t].dirty)return t;return-1}async write(t,e){if(0==t.byteLength)return;const a=this;if(void 0===e&&(e=a.pos),a.pos=e+t.byteLength,a.totalSize<e+t.byteLength&&(a.totalSize=e+t.byteLength),a.pendingClose)throw new Error("Writing a closing file");const i=Math.floor(e/a.pageSize),o=Math.floor((e+t.byteLength-1)/a.pageSize),n=[];for(let t=i;t<=o;t++)n.push(a._loadPage(t));a._triggerLoad();let r=i,c=e%a.pageSize,l=t.byteLength;for(;l>0;){await n[r-i];const e=c+l>a.pageSize?a.pageSize-c:l,o=t.slice(t.byteLength-l,t.byteLength-l+e);new Uint8Array(a.pages[r].buff.buffer,c,e).set(o),a.pages[r].dirty=!0,a.pages[r].pendingOps--,a.pages[r].size=Math.max(c+e,a.pages[r].size),r>=a.totalPages&&(a.totalPages=r+1),l-=e,r++,c=0,a.writing||setImmediate(a._triggerWrite.bind(a))}}async read(t,e){let a=new Uint8Array(t);return await this.readToBuffer(a,0,t,e),a}async readToBuffer(t,e,a,i){if(0==a)return;const o=this;if(a>o.pageSize*o.maxPagesLoaded*.8){const t=Math.floor(1.1*a);this.maxPagesLoaded=Math.floor(t/o.pageSize)+1}if(void 0===i&&(i=o.pos),o.pos=i+a,o.pendingClose)throw new Error("Reading a closing file");const n=Math.floor(i/o.pageSize),r=Math.floor((i+a-1)/o.pageSize),c=[];for(let t=n;t<=r;t++)c.push(o._loadPage(t));o._triggerLoad();let l=n,s=i%o.pageSize,d=i+a>o.totalSize?a-(i+a-o.totalSize):a;for(;d>0;){await c[l-n],o.__statusPage("After Await (read): ",l);const i=s+d>o.pageSize?o.pageSize-s:d,r=new Uint8Array(o.pages[l].buff.buffer,o.pages[l].buff.byteOffset+s,i);t.set(r,e+a-d),o.pages[l].pendingOps--,o.__statusPage("After Op done: ",l),d-=i,l++,s=0,o.pendingLoads.length>0&&setImmediate(o._triggerLoad.bind(o))}this.pos=i+a}_tryClose(){const t=this;if(!t.pendingClose)return;t.error&&t.pendingCloseReject(t.error);t._getDirtyPage()>=0||t.writing||t.reading||t.pendingLoads.length>0||t.pendingClose()}close(){const t=this;if(t.pendingClose)throw new Error("Closing the file twice");return new Promise(((e,a)=>{t.pendingClose=e,t.pendingCloseReject=a,t._tryClose()})).then((()=>{t.fd.close()}),(e=>{throw t.fd.close(),e}))}async discard(){await this.close(),await Ze.promises.unlink(this.fileName)}async writeULE32(t,e){const a=new Uint8Array(4);new DataView(a.buffer).setUint32(0,t,!0),await this.write(a,e)}async writeUBE32(t,e){const a=new Uint8Array(4);new DataView(a.buffer).setUint32(0,t,!1),await this.write(a,e)}async writeULE64(t,e){const a=new Uint8Array(8),i=new DataView(a.buffer);i.setUint32(0,4294967295&t,!0),i.setUint32(4,Math.floor(t/4294967296),!0),await this.write(a,e)}async readULE32(t){const e=await this.read(4,t);return new Uint32Array(e.buffer)[0]}async readUBE32(t){const e=await this.read(4,t);return new DataView(e.buffer).getUint32(0,!1)}async readULE64(t){const e=await this.read(8,t),a=new Uint32Array(e.buffer);return 4294967296*a[1]+a[0]}}const We=new Uint8Array(4),Xe=new DataView(We.buffer),ta=new Uint8Array(8),ea=new DataView(ta.buffer);class aa{constructor(){this.pageSize=16384}_resizeIfNeeded(t){if(t>this.allocSize){const e=Math.max(this.allocSize+(1<<20),Math.floor(1.1*this.allocSize),t),a=new Uint8Array(e);a.set(this.o.data),this.o.data=a,this.allocSize=e}}async write(t,e){if(void 0===e&&(e=this.pos),this.readOnly)throw new Error("Writing a read only file");this._resizeIfNeeded(e+t.byteLength),this.o.data.set(t.slice(),e),e+t.byteLength>this.totalSize&&(this.totalSize=e+t.byteLength),this.pos=e+t.byteLength}async readToBuffer(t,e,a,i){if(void 0===i&&(i=this.pos),this.readOnly&&i+a>this.totalSize)throw new Error("Reading out of bounds");this._resizeIfNeeded(i+a);const o=new Uint8Array(this.o.data.buffer,this.o.data.byteOffset+i,a);t.set(o,e),this.pos=i+a}async read(t,e){const a=new Uint8Array(t);return await this.readToBuffer(a,0,t,e),a}close(){this.o.data.byteLength!=this.totalSize&&(this.o.data=this.o.data.slice(0,this.totalSize))}async discard(){}async writeULE32(t,e){Xe.setUint32(0,t,!0),await this.write(We,e)}async writeUBE32(t,e){Xe.setUint32(0,t,!1),await this.write(We,e)}async writeULE64(t,e){ea.setUint32(0,4294967295&t,!0),ea.setUint32(4,Math.floor(t/4294967296),!0),await this.write(ta,e)}async readULE32(t){const e=await this.read(4,t);return new Uint32Array(e.buffer)[0]}async readUBE32(t){const e=await this.read(4,t);return new DataView(e.buffer).getUint32(0,!1)}async readULE64(t){const e=await this.read(8,t),a=new Uint32Array(e.buffer);return 4294967296*a[1]+a[0]}}const ia=1<<22;const oa=new Uint8Array(4),na=new DataView(oa.buffer),ra=new Uint8Array(8),ca=new DataView(ra.buffer);class la{constructor(){this.pageSize=16384}_resizeIfNeeded(t){if(t<=this.totalSize)return;if(this.readOnly)throw new Error("Reading out of file bounds");const e=Math.floor((t-1)/ia)+1;for(let a=Math.max(this.o.data.length-1,0);a<e;a++){const i=new Uint8Array(a<e-1?ia:t-(e-1)*ia);a==this.o.data.length-1&&i.set(this.o.data[a]),this.o.data[a]=i}this.totalSize=t}async write(t,e){const a=this;if(void 0===e&&(e=a.pos),this.readOnly)throw new Error("Writing a read only file");this._resizeIfNeeded(e+t.byteLength);let i=Math.floor(e/ia),o=e%ia,n=t.byteLength;for(;n>0;){const e=o+n>ia?ia-o:n,r=t.slice(t.byteLength-n,t.byteLength-n+e);new Uint8Array(a.o.data[i].buffer,o,e).set(r),n-=e,i++,o=0}this.pos=e+t.byteLength}async readToBuffer(t,e,a,i){const o=this;if(void 0===i&&(i=o.pos),this.readOnly&&i+a>this.totalSize)throw new Error("Reading out of bounds");this._resizeIfNeeded(i+a);let n=Math.floor(i/ia),r=i%ia,c=a;for(;c>0;){const i=r+c>ia?ia-r:c,l=new Uint8Array(o.o.data[n].buffer,r,i);t.set(l,e+a-c),c-=i,n++,r=0}this.pos=i+a}async read(t,e){const a=new Uint8Array(t);return await this.readToBuffer(a,0,t,e),a}close(){}async discard(){}async writeULE32(t,e){na.setUint32(0,t,!0),await this.write(oa,e)}async writeUBE32(t,e){na.setUint32(0,t,!1),await this.write(oa,e)}async writeULE64(t,e){ca.setUint32(0,4294967295&t,!0),ca.setUint32(4,Math.floor(t/4294967296),!0),await this.write(ra,e)}async readULE32(t){const e=await this.read(4,t);return new Uint32Array(e.buffer)[0]}async readUBE32(t){const e=await this.read(4,t);return new DataView(e.buffer).getUint32(0,!1)}async readULE64(t){const e=await this.read(8,t),a=new Uint32Array(e.buffer);return 4294967296*a[1]+a[0]}}async function sa(t,e,a){if("string"==typeof t&&(t={type:"file",fileName:t,cacheSize:e||65536,pageSize:a||8192}),"file"==t.type)return await Ye(t.fileName,"w+",t.cacheSize,t.pageSize);if("mem"==t.type)return function(t){const e=t.initialSize||1<<20,a=new aa;return a.o=t,a.o.data=new Uint8Array(e),a.allocSize=e,a.totalSize=0,a.readOnly=!1,a.pos=0,a}(t);if("bigMem"==t.type)return function(t){const e=t.initialSize||0,a=new la;a.o=t;const i=e?Math.floor((e-1)/ia)+1:0;a.o.data=[];for(let t=0;t<i-1;t++)a.o.data.push(new Uint8Array(ia));return i&&a.o.data.push(new Uint8Array(e-ia*(i-1))),a.totalSize=0,a.readOnly=!1,a.pos=0,a}(t);throw new Error("Invalid FastFile type: "+t.type)}async function da(t,e,a){if(t instanceof Uint8Array&&(t={type:"mem",data:t}),"string"==typeof t){t={type:"mem",data:await fetch(t).then((function(t){return t.arrayBuffer()})).then((function(t){return new Uint8Array(t)}))}}if("file"==t.type)return await Ye(t.fileName,"r",t.cacheSize,t.pageSize);if("mem"==t.type)return await function(t){const e=new aa;return e.o=t,e.allocSize=t.data.byteLength,e.totalSize=t.data.byteLength,e.readOnly=!0,e.pos=0,e}(t);if("bigMem"==t.type)return await function(t){const e=new la;return e.o=t,e.totalSize=(t.data.length-1)*ia+t.data[t.data.length-1].byteLength,e.readOnly=!0,e.pos=0,e}(t);throw new Error("Invalid FastFile type: "+t.type)}async function ua(t,e,a,i,o){const n=await da(t),r=await n.read(4);let c="";for(let t=0;t<4;t++)c+=String.fromCharCode(r[t]);if(c!=e)throw new Error(t+": Invalid File format");if(await n.readULE32()>a)throw new Error("Version not supported");const l=await n.readULE32();let s=[];for(let t=0;t<l;t++){let t=await n.readULE32(),e=await n.readULE64();void 0===s[t]&&(s[t]=[]),s[t].push({p:n.pos,size:e}),n.pos+=e}return{fd:n,sections:s}}async function ga(t,e,a,i,o,n){const r=await sa(t,o,n),c=new Uint8Array(4);for(let t=0;t<4;t++)c[t]=e.charCodeAt(t);return await r.write(c,0),await r.writeULE32(a),await r.writeULE32(i),r}async function fa(t,e){if(void 0!==t.writingSection)throw new Error("Already writing a section");await t.writeULE32(e),t.writingSection={pSectionSize:t.pos},await t.writeULE64(0)}async function _a(t){if(void 0===t.writingSection)throw new Error("Not writing a section");const e=t.pos-t.writingSection.pSectionSize-8,a=t.pos;t.pos=t.writingSection.pSectionSize,await t.writeULE64(e),t.pos=a,delete t.writingSection}async function pa(t,e,a){if(void 0!==t.readingSection)throw new Error("Already reading a section");if(!e[a])throw new Error(t.fileName+": Missing section "+a);if(e[a].length>1)throw new Error(t.fileName+": Section Duplicated "+a);t.pos=e[a][0].p,t.readingSection=e[a][0]}async function ha(t,e){if(void 0===t.readingSection)throw new Error("Not reading a section");if(!e&&t.pos-t.readingSection.p!=t.readingSection.size)throw new Error("Invalid section size reading");delete t.readingSection}async function ma(t,e,a,i){const o=new Uint8Array(a);He.toRprLE(o,0,e,a),await t.write(o,i)}async function La(t,e,a){const i=await t.read(e,a);return He.fromRprLE(i,0,e)}async function wa(t,e,a,i,o){void 0===o&&(o=e[i][0].size);const n=t.pageSize;await pa(t,e,i),await fa(a,i);for(let e=0;e<o;e+=n){const i=Math.min(o-e,n),r=await t.read(i);await a.write(r)}await _a(a),await ha(t,o!=e[i][0].size)}async function Aa(t,e,a,i,o){if((i=void 0===i?0:i)+(o=void 0===o?e[a][0].size-i:o)>e[a][0].size)throw new Error("Reading out of the range of the section");let n;return n=o<1<<30?new Uint8Array(o):new fe(o),await t.readToBuffer(n,0,o,e[a][0].p+i),n}async function ba(t,e,a,i,o){const n=16*t.pageSize;if(await pa(t,e,o),await pa(a,i,o),e[o][0].size!=i[o][0].size)return!1;const r=e[o][0].size;for(let e=0;e<r;e+=n){const i=Math.min(r-e,n),o=await t.read(i),c=await a.read(i);for(let t=0;t<i;t++)if(o[t]!=c[t])return!1}return await ha(t),await ha(a),!0}He.e("73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",16),He.e("21888242871839275222246405745257275088548364400416034343698204186575808495617");const ya=He.e("1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab",16),Ia=He.e("21888242871839275222246405745257275088696311157297823662689037894645226208583");async function Ca(t){let e;if(He.eq(t,Ia))e=await De();else{if(!He.eq(t,ya))throw new Error(`Curve not supported: ${He.toString(t)}`);e=await Ke()}return e}async function Fa(t){let e;const a=t.toUpperCase().match(/[A-Za-z0-9]+/g).join("");if(["BN128","BN254","ALTBN128"].indexOf(a)>=0)e=await De();else{if(!(["BLS12381"].indexOf(a)>=0))throw new Error(`Curve not supported: ${t}`);e=await Ke()}return e}var xa=function t(e,a){if(!e){var i=new va(a);throw Error.captureStackTrace&&Error.captureStackTrace(i,t),i}};class va extends Error{}function Ea(t){return t.length}va.prototype.name="AssertionError";var Ba={byteLength:Ea,toString:function(t){const e=t.byteLength;let a="";for(let i=0;i<e;i++)a+=String.fromCharCode(t[i]);return a},write:function(t,e,a=0,i=Ea(e)){const o=Math.min(i,t.byteLength-a);for(let i=0;i<o;i++)t[a+i]=e.charCodeAt(i);return o}};const Sa="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Ga=new Uint8Array(256);for(let t=0;t<Sa.length;t++)Ga[Sa.charCodeAt(t)]=t;function Pa(t){let e=t.length;return 61===t.charCodeAt(e-1)&&e--,e>1&&61===t.charCodeAt(e-1)&&e--,3*e>>>2}Ga[45]=62,Ga[95]=63;var Oa={byteLength:Pa,toString:function(t){const e=t.byteLength;let a="";for(let i=0;i<e;i+=3)a+=Sa[t[i]>>2]+Sa[(3&t[i])<<4|t[i+1]>>4]+Sa[(15&t[i+1])<<2|t[i+2]>>6]+Sa[63&t[i+2]];return e%3==2?a=a.substring(0,a.length-1)+"=":e%3==1&&(a=a.substring(0,a.length-2)+"=="),a},write:function(t,e,a=0,i=Pa(e)){const o=Math.min(i,t.byteLength-a);for(let a=0,i=0;a<o;a+=4){const o=Ga[e.charCodeAt(a)],n=Ga[e.charCodeAt(a+1)],r=Ga[e.charCodeAt(a+2)],c=Ga[e.charCodeAt(a+3)];t[i++]=o<<2|n>>4,t[i++]=(15&n)<<4|r>>2,t[i++]=(3&r)<<6|63&c}return o}};function Ua(t){return t.length>>>1}var za={byteLength:Ua,toString:function(t){const e=t.byteLength;t=new DataView(t.buffer,t.byteOffset,e);let a="",i=0;for(let o=e-e%4;i<o;i+=4)a+=t.getUint32(i).toString(16).padStart(8,"0");for(;i<e;i++)a+=t.getUint8(i).toString(16).padStart(2,"0");return a},write:function(t,e,a=0,i=Ua(e)){const o=Math.min(i,t.byteLength-a);for(let i=0;i<o;i++){const o=qa(e.charCodeAt(2*i)),n=qa(e.charCodeAt(2*i+1));if(void 0===o||void 0===n)return t.subarray(0,i);t[a+i]=o<<4|n}return o}};function qa(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-65+10:t>=97&&t<=102?t-97+10:void 0}function Qa(t){let e=0;for(let a=0,i=t.length;a<i;a++){const o=t.charCodeAt(a);if(o>=55296&&o<=56319&&a+1<i){const i=t.charCodeAt(a+1);if(i>=56320&&i<=57343){e+=4,a++;continue}}e+=o<=127?1:o<=2047?2:3}return e}let Ma,ka;if("undefined"!=typeof TextDecoder){const t=new TextDecoder;Ma=function(e){return t.decode(e)}}else Ma=function(t){const e=t.byteLength;let a="",i=0;for(;i<e;){let o=t[i];if(o<=127){a+=String.fromCharCode(o),i++;continue}let n=0,r=0;if(o<=223?(n=1,r=31&o):o<=239?(n=2,r=15&o):o<=244&&(n=3,r=7&o),e-i-n>0){let e=0;for(;e<n;)o=t[i+e+1],r=r<<6|63&o,e+=1}else r=65533,n=e-i;a+=String.fromCodePoint(r),i+=n+1}return a};if("undefined"!=typeof TextEncoder){const t=new TextEncoder;ka=function(e,a,i=0,o=Qa(a)){const n=Math.min(o,e.byteLength-i);return t.encodeInto(a,e.subarray(i,i+n)),n}}else ka=function(t,e,a=0,i=Qa(e)){const o=Math.min(i,t.byteLength-a);t=t.subarray(a,a+o);let n=0,r=0;for(;n<e.length;){const a=e.codePointAt(n);if(a<=127){t[r++]=a,n++;continue}let i=0,o=0;for(a<=2047?(i=6,o=192):a<=65535?(i=12,o=224):a<=2097151&&(i=18,o=240),t[r++]=o|a>>i,i-=6;i>=0;)t[r++]=128|a>>i&63,i-=6;n+=a>=65536?2:1}return o};var Ra={byteLength:Qa,toString:Ma,write:ka};function Na(t){return 2*t.length}var Ta={byteLength:Na,toString:function(t){const e=t.byteLength;let a="";for(let i=0;i<e-1;i+=2)a+=String.fromCharCode(t[i]+256*t[i+1]);return a},write:function(t,e,a=0,i=Na(e)){const o=Math.min(i,t.byteLength-a);let n=o;for(let i=0;i<e.length&&!((n-=2)<0);++i){const o=e.charCodeAt(i),n=o>>8,r=o%256;t[a+2*i]=r,t[a+2*i+1]=n}return o}};function Da(t){switch(t){case"ascii":return Ba;case"base64":return Oa;case"hex":return za;case"utf8":case"utf-8":case void 0:return Ra;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Ta;default:throw new Error(`Unknown encoding: ${t}`)}}function Ka(t){return t instanceof Uint8Array}function Va(t,e,a){return"string"==typeof t?function(t,e){const a=Da(e),i=new Uint8Array(a.byteLength(t));return a.write(i,t,0,i.byteLength),i}(t,e):Array.isArray(t)?function(t){const e=new Uint8Array(t.length);return e.set(t),e}(t):ArrayBuffer.isView(t)?function(t){const e=new Uint8Array(t.byteLength);return e.set(t),e}(t):function(t,e,a){return new Uint8Array(t,e,a)}(t,e,a)}function ja(t,e,a){const i=t[e];t[e]=t[a],t[a]=i}var Ha={isBuffer:Ka,alloc:function(t,e,a){const i=new Uint8Array(t);return void 0!==e&&e(i,e,0,i.byteLength,a),i},allocUnsafe:function(t){return new Uint8Array(t)},allocUnsafeSlow:function(t){return new Uint8Array(t)},byteLength:function(t,e){return Da(e).byteLength(t)},compare:function(t,e){if(t===e)return 0;const a=Math.min(t.byteLength,e.byteLength);t=new DataView(t.buffer,t.byteOffset,t.byteLength),e=new DataView(e.buffer,e.byteOffset,e.byteLength);let i=0;for(let o=a-a%4;i<o;i+=4){const a=t.getUint32(i),o=e.getUint32(i);if(a<o)return-1;if(a>o)return 1}for(;i<a;i++){const a=t.getUint8(i),o=e.getUint8(i);if(a<o)return-1;if(a>o)return 1}return t.byteLength>e.byteLength?1:t.byteLength<e.byteLength?-1:0},concat:function(t,e){void 0===e&&(e=t.reduce(((t,e)=>t+e.byteLength),0));const a=new Uint8Array(e);return t.reduce(((t,e)=>(a.set(e,t),t+e.byteLength)),0),a},copy:function(t,e,a=0,i=0,o=t.byteLength){if(o>0&&o<i)return 0;if(o===i)return 0;if(0===t.byteLength||0===e.byteLength)return 0;if(a<0)throw new RangeError("targetStart is out of range");if(i<0||i>=t.byteLength)throw new RangeError("sourceStart is out of range");if(o<0)throw new RangeError("sourceEnd is out of range");a>=e.byteLength&&(a=e.byteLength),o>t.byteLength&&(o=t.byteLength),e.byteLength-a<o-i&&(o=e.length-a+i);const n=o-i;return t===e?e.copyWithin(a,i,o):e.set(t.subarray(i,o),a),n},equals:function(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;const a=t.byteLength;t=new DataView(t.buffer,t.byteOffset,t.byteLength),e=new DataView(e.buffer,e.byteOffset,e.byteLength);let i=0;for(let o=a-a%4;i<o;i+=4)if(t.getUint32(i)!==e.getUint32(i))return!1;for(;i<a;i++)if(t.getUint8(i)!==e.getUint8(i))return!1;return!0},fill:function(t,e,a,i,o){if("string"==typeof e?"string"==typeof a?(o=a,a=0,i=t.byteLength):"string"==typeof i&&(o=i,i=t.byteLength):"number"==typeof val?e&=255:"boolean"==typeof val&&(e=+e),a<0||t.byteLength<a||t.byteLength<i)throw new RangeError("Out of range index");if(void 0===a&&(a=0),void 0===i&&(i=t.byteLength),i<=a)return t;if(e||(e=0),"number"==typeof e)for(let o=a;o<i;++o)t[o]=e;else{const n=(e=Ka(e)?e:Va(e,o)).byteLength;for(let o=0;o<i-a;++o)t[o+a]=e[o%n]}return t},from:Va,swap16:function(t){const e=t.byteLength;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let a=0;a<e;a+=2)ja(t,a,a+1);return t},swap32:function(t){const e=t.byteLength;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let a=0;a<e;a+=4)ja(t,a,a+3),ja(t,a+1,a+2);return t},swap64:function(t){const e=t.byteLength;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let a=0;a<e;a+=8)ja(t,a,a+7),ja(t,a+1,a+6),ja(t,a+2,a+5),ja(t,a+3,a+4);return t},toBuffer:function(t){return t},toString:function(t,e,a=0,i=t.byteLength){const o=t.byteLength;return a>=o||i<=a?"":(a<0&&(a=0),i>o&&(i=o),(0!==a||i<o)&&(t=t.subarray(a,i)),Da(e).toString(t))},write:function(t,e,a,i,o){return void 0===a?o="utf8":void 0===i&&"string"==typeof a?(o=a,a=void 0):void 0===o&&"string"==typeof i&&(o=i,i=void 0),Da(o).write(t,e,a,i)}},$a=(()=>{for(var t=new Uint8Array(128),e=0;e<64;e++)t[e<26?e+65:e<52?e+71:e<62?e-4:4*e-205]=e;return e=>{for(var a=e.length,i=new Uint8Array(3*(a-("="==e[a-1])-("="==e[a-2]))/4|0),o=0,n=0;o<a;){var r=t[e.charCodeAt(o++)],c=t[e.charCodeAt(o++)],l=t[e.charCodeAt(o++)],s=t[e.charCodeAt(o++)];i[n++]=r<<2|c>>4,i[n++]=c<<4|l>>2,i[n++]=l<<6|s}return i}})(),Za=((t,e)=>function(){return e||(0,t[Object.keys(t)[0]])((e={exports:{}}).exports,e),e.exports})({"wasm-binary:./blake2b.wat"(t,e){e.exports=$a("AGFzbQEAAAABEANgAn9/AGADf39/AGABfwADBQQAAQICBQUBAQroBwdNBQZtZW1vcnkCAAxibGFrZTJiX2luaXQAAA5ibGFrZTJiX3VwZGF0ZQABDWJsYWtlMmJfZmluYWwAAhBibGFrZTJiX2NvbXByZXNzAAMKvz8EwAIAIABCADcDACAAQgA3AwggAEIANwMQIABCADcDGCAAQgA3AyAgAEIANwMoIABCADcDMCAAQgA3AzggAEIANwNAIABCADcDSCAAQgA3A1AgAEIANwNYIABCADcDYCAAQgA3A2ggAEIANwNwIABCADcDeCAAQoiS853/zPmE6gBBACkDAIU3A4ABIABCu86qptjQ67O7f0EIKQMAhTcDiAEgAEKr8NP0r+68tzxBECkDAIU3A5ABIABC8e30+KWn/aelf0EYKQMAhTcDmAEgAELRhZrv+s+Uh9EAQSApAwCFNwOgASAAQp/Y+dnCkdqCm39BKCkDAIU3A6gBIABC6/qG2r+19sEfQTApAwCFNwOwASAAQvnC+JuRo7Pw2wBBOCkDAIU3A7gBIABCADcDwAEgAEIANwPIASAAQgA3A9ABC20BA38gAEHAAWohAyAAQcgBaiEEIAQpAwCnIQUCQANAIAEgAkYNASAFQYABRgRAIAMgAykDACAFrXw3AwBBACEFIAAQAwsgACAFaiABLQAAOgAAIAVBAWohBSABQQFqIQEMAAsLIAQgBa03AwALYQEDfyAAQcABaiEBIABByAFqIQIgASABKQMAIAIpAwB8NwMAIABCfzcD0AEgAikDAKchAwJAA0AgA0GAAUYNASAAIANqQQA6AAAgA0EBaiEDDAALCyACIAOtNwMAIAAQAwuqOwIgfgl/IABBgAFqISEgAEGIAWohIiAAQZABaiEjIABBmAFqISQgAEGgAWohJSAAQagBaiEmIABBsAFqIScgAEG4AWohKCAhKQMAIQEgIikDACECICMpAwAhAyAkKQMAIQQgJSkDACEFICYpAwAhBiAnKQMAIQcgKCkDACEIQoiS853/zPmE6gAhCUK7zqqm2NDrs7t/IQpCq/DT9K/uvLc8IQtC8e30+KWn/aelfyEMQtGFmu/6z5SH0QAhDUKf2PnZwpHagpt/IQ5C6/qG2r+19sEfIQ9C+cL4m5Gjs/DbACEQIAApAwAhESAAKQMIIRIgACkDECETIAApAxghFCAAKQMgIRUgACkDKCEWIAApAzAhFyAAKQM4IRggACkDQCEZIAApA0ghGiAAKQNQIRsgACkDWCEcIAApA2AhHSAAKQNoIR4gACkDcCEfIAApA3ghICANIAApA8ABhSENIA8gACkD0AGFIQ8gASAFIBF8fCEBIA0gAYVCIIohDSAJIA18IQkgBSAJhUIYiiEFIAEgBSASfHwhASANIAGFQhCKIQ0gCSANfCEJIAUgCYVCP4ohBSACIAYgE3x8IQIgDiAChUIgiiEOIAogDnwhCiAGIAqFQhiKIQYgAiAGIBR8fCECIA4gAoVCEIohDiAKIA58IQogBiAKhUI/iiEGIAMgByAVfHwhAyAPIAOFQiCKIQ8gCyAPfCELIAcgC4VCGIohByADIAcgFnx8IQMgDyADhUIQiiEPIAsgD3whCyAHIAuFQj+KIQcgBCAIIBd8fCEEIBAgBIVCIIohECAMIBB8IQwgCCAMhUIYiiEIIAQgCCAYfHwhBCAQIASFQhCKIRAgDCAQfCEMIAggDIVCP4ohCCABIAYgGXx8IQEgECABhUIgiiEQIAsgEHwhCyAGIAuFQhiKIQYgASAGIBp8fCEBIBAgAYVCEIohECALIBB8IQsgBiALhUI/iiEGIAIgByAbfHwhAiANIAKFQiCKIQ0gDCANfCEMIAcgDIVCGIohByACIAcgHHx8IQIgDSAChUIQiiENIAwgDXwhDCAHIAyFQj+KIQcgAyAIIB18fCEDIA4gA4VCIIohDiAJIA58IQkgCCAJhUIYiiEIIAMgCCAefHwhAyAOIAOFQhCKIQ4gCSAOfCEJIAggCYVCP4ohCCAEIAUgH3x8IQQgDyAEhUIgiiEPIAogD3whCiAFIAqFQhiKIQUgBCAFICB8fCEEIA8gBIVCEIohDyAKIA98IQogBSAKhUI/iiEFIAEgBSAffHwhASANIAGFQiCKIQ0gCSANfCEJIAUgCYVCGIohBSABIAUgG3x8IQEgDSABhUIQiiENIAkgDXwhCSAFIAmFQj+KIQUgAiAGIBV8fCECIA4gAoVCIIohDiAKIA58IQogBiAKhUIYiiEGIAIgBiAZfHwhAiAOIAKFQhCKIQ4gCiAOfCEKIAYgCoVCP4ohBiADIAcgGnx8IQMgDyADhUIgiiEPIAsgD3whCyAHIAuFQhiKIQcgAyAHICB8fCEDIA8gA4VCEIohDyALIA98IQsgByALhUI/iiEHIAQgCCAefHwhBCAQIASFQiCKIRAgDCAQfCEMIAggDIVCGIohCCAEIAggF3x8IQQgECAEhUIQiiEQIAwgEHwhDCAIIAyFQj+KIQggASAGIBJ8fCEBIBAgAYVCIIohECALIBB8IQsgBiALhUIYiiEGIAEgBiAdfHwhASAQIAGFQhCKIRAgCyAQfCELIAYgC4VCP4ohBiACIAcgEXx8IQIgDSAChUIgiiENIAwgDXwhDCAHIAyFQhiKIQcgAiAHIBN8fCECIA0gAoVCEIohDSAMIA18IQwgByAMhUI/iiEHIAMgCCAcfHwhAyAOIAOFQiCKIQ4gCSAOfCEJIAggCYVCGIohCCADIAggGHx8IQMgDiADhUIQiiEOIAkgDnwhCSAIIAmFQj+KIQggBCAFIBZ8fCEEIA8gBIVCIIohDyAKIA98IQogBSAKhUIYiiEFIAQgBSAUfHwhBCAPIASFQhCKIQ8gCiAPfCEKIAUgCoVCP4ohBSABIAUgHHx8IQEgDSABhUIgiiENIAkgDXwhCSAFIAmFQhiKIQUgASAFIBl8fCEBIA0gAYVCEIohDSAJIA18IQkgBSAJhUI/iiEFIAIgBiAdfHwhAiAOIAKFQiCKIQ4gCiAOfCEKIAYgCoVCGIohBiACIAYgEXx8IQIgDiAChUIQiiEOIAogDnwhCiAGIAqFQj+KIQYgAyAHIBZ8fCEDIA8gA4VCIIohDyALIA98IQsgByALhUIYiiEHIAMgByATfHwhAyAPIAOFQhCKIQ8gCyAPfCELIAcgC4VCP4ohByAEIAggIHx8IQQgECAEhUIgiiEQIAwgEHwhDCAIIAyFQhiKIQggBCAIIB58fCEEIBAgBIVCEIohECAMIBB8IQwgCCAMhUI/iiEIIAEgBiAbfHwhASAQIAGFQiCKIRAgCyAQfCELIAYgC4VCGIohBiABIAYgH3x8IQEgECABhUIQiiEQIAsgEHwhCyAGIAuFQj+KIQYgAiAHIBR8fCECIA0gAoVCIIohDSAMIA18IQwgByAMhUIYiiEHIAIgByAXfHwhAiANIAKFQhCKIQ0gDCANfCEMIAcgDIVCP4ohByADIAggGHx8IQMgDiADhUIgiiEOIAkgDnwhCSAIIAmFQhiKIQggAyAIIBJ8fCEDIA4gA4VCEIohDiAJIA58IQkgCCAJhUI/iiEIIAQgBSAafHwhBCAPIASFQiCKIQ8gCiAPfCEKIAUgCoVCGIohBSAEIAUgFXx8IQQgDyAEhUIQiiEPIAogD3whCiAFIAqFQj+KIQUgASAFIBh8fCEBIA0gAYVCIIohDSAJIA18IQkgBSAJhUIYiiEFIAEgBSAafHwhASANIAGFQhCKIQ0gCSANfCEJIAUgCYVCP4ohBSACIAYgFHx8IQIgDiAChUIgiiEOIAogDnwhCiAGIAqFQhiKIQYgAiAGIBJ8fCECIA4gAoVCEIohDiAKIA58IQogBiAKhUI/iiEGIAMgByAefHwhAyAPIAOFQiCKIQ8gCyAPfCELIAcgC4VCGIohByADIAcgHXx8IQMgDyADhUIQiiEPIAsgD3whCyAHIAuFQj+KIQcgBCAIIBx8fCEEIBAgBIVCIIohECAMIBB8IQwgCCAMhUIYiiEIIAQgCCAffHwhBCAQIASFQhCKIRAgDCAQfCEMIAggDIVCP4ohCCABIAYgE3x8IQEgECABhUIgiiEQIAsgEHwhCyAGIAuFQhiKIQYgASAGIBd8fCEBIBAgAYVCEIohECALIBB8IQsgBiALhUI/iiEGIAIgByAWfHwhAiANIAKFQiCKIQ0gDCANfCEMIAcgDIVCGIohByACIAcgG3x8IQIgDSAChUIQiiENIAwgDXwhDCAHIAyFQj+KIQcgAyAIIBV8fCEDIA4gA4VCIIohDiAJIA58IQkgCCAJhUIYiiEIIAMgCCARfHwhAyAOIAOFQhCKIQ4gCSAOfCEJIAggCYVCP4ohCCAEIAUgIHx8IQQgDyAEhUIgiiEPIAogD3whCiAFIAqFQhiKIQUgBCAFIBl8fCEEIA8gBIVCEIohDyAKIA98IQogBSAKhUI/iiEFIAEgBSAafHwhASANIAGFQiCKIQ0gCSANfCEJIAUgCYVCGIohBSABIAUgEXx8IQEgDSABhUIQiiENIAkgDXwhCSAFIAmFQj+KIQUgAiAGIBZ8fCECIA4gAoVCIIohDiAKIA58IQogBiAKhUIYiiEGIAIgBiAYfHwhAiAOIAKFQhCKIQ4gCiAOfCEKIAYgCoVCP4ohBiADIAcgE3x8IQMgDyADhUIgiiEPIAsgD3whCyAHIAuFQhiKIQcgAyAHIBV8fCEDIA8gA4VCEIohDyALIA98IQsgByALhUI/iiEHIAQgCCAbfHwhBCAQIASFQiCKIRAgDCAQfCEMIAggDIVCGIohCCAEIAggIHx8IQQgECAEhUIQiiEQIAwgEHwhDCAIIAyFQj+KIQggASAGIB98fCEBIBAgAYVCIIohECALIBB8IQsgBiALhUIYiiEGIAEgBiASfHwhASAQIAGFQhCKIRAgCyAQfCELIAYgC4VCP4ohBiACIAcgHHx8IQIgDSAChUIgiiENIAwgDXwhDCAHIAyFQhiKIQcgAiAHIB18fCECIA0gAoVCEIohDSAMIA18IQwgByAMhUI/iiEHIAMgCCAXfHwhAyAOIAOFQiCKIQ4gCSAOfCEJIAggCYVCGIohCCADIAggGXx8IQMgDiADhUIQiiEOIAkgDnwhCSAIIAmFQj+KIQggBCAFIBR8fCEEIA8gBIVCIIohDyAKIA98IQogBSAKhUIYiiEFIAQgBSAefHwhBCAPIASFQhCKIQ8gCiAPfCEKIAUgCoVCP4ohBSABIAUgE3x8IQEgDSABhUIgiiENIAkgDXwhCSAFIAmFQhiKIQUgASAFIB18fCEBIA0gAYVCEIohDSAJIA18IQkgBSAJhUI/iiEFIAIgBiAXfHwhAiAOIAKFQiCKIQ4gCiAOfCEKIAYgCoVCGIohBiACIAYgG3x8IQIgDiAChUIQiiEOIAogDnwhCiAGIAqFQj+KIQYgAyAHIBF8fCEDIA8gA4VCIIohDyALIA98IQsgByALhUIYiiEHIAMgByAcfHwhAyAPIAOFQhCKIQ8gCyAPfCELIAcgC4VCP4ohByAEIAggGXx8IQQgECAEhUIgiiEQIAwgEHwhDCAIIAyFQhiKIQggBCAIIBR8fCEEIBAgBIVCEIohECAMIBB8IQwgCCAMhUI/iiEIIAEgBiAVfHwhASAQIAGFQiCKIRAgCyAQfCELIAYgC4VCGIohBiABIAYgHnx8IQEgECABhUIQiiEQIAsgEHwhCyAGIAuFQj+KIQYgAiAHIBh8fCECIA0gAoVCIIohDSAMIA18IQwgByAMhUIYiiEHIAIgByAWfHwhAiANIAKFQhCKIQ0gDCANfCEMIAcgDIVCP4ohByADIAggIHx8IQMgDiADhUIgiiEOIAkgDnwhCSAIIAmFQhiKIQggAyAIIB98fCEDIA4gA4VCEIohDiAJIA58IQkgCCAJhUI/iiEIIAQgBSASfHwhBCAPIASFQiCKIQ8gCiAPfCEKIAUgCoVCGIohBSAEIAUgGnx8IQQgDyAEhUIQiiEPIAogD3whCiAFIAqFQj+KIQUgASAFIB18fCEBIA0gAYVCIIohDSAJIA18IQkgBSAJhUIYiiEFIAEgBSAWfHwhASANIAGFQhCKIQ0gCSANfCEJIAUgCYVCP4ohBSACIAYgEnx8IQIgDiAChUIgiiEOIAogDnwhCiAGIAqFQhiKIQYgAiAGICB8fCECIA4gAoVCEIohDiAKIA58IQogBiAKhUI/iiEGIAMgByAffHwhAyAPIAOFQiCKIQ8gCyAPfCELIAcgC4VCGIohByADIAcgHnx8IQMgDyADhUIQiiEPIAsgD3whCyAHIAuFQj+KIQcgBCAIIBV8fCEEIBAgBIVCIIohECAMIBB8IQwgCCAMhUIYiiEIIAQgCCAbfHwhBCAQIASFQhCKIRAgDCAQfCEMIAggDIVCP4ohCCABIAYgEXx8IQEgECABhUIgiiEQIAsgEHwhCyAGIAuFQhiKIQYgASAGIBh8fCEBIBAgAYVCEIohECALIBB8IQsgBiALhUI/iiEGIAIgByAXfHwhAiANIAKFQiCKIQ0gDCANfCEMIAcgDIVCGIohByACIAcgFHx8IQIgDSAChUIQiiENIAwgDXwhDCAHIAyFQj+KIQcgAyAIIBp8fCEDIA4gA4VCIIohDiAJIA58IQkgCCAJhUIYiiEIIAMgCCATfHwhAyAOIAOFQhCKIQ4gCSAOfCEJIAggCYVCP4ohCCAEIAUgGXx8IQQgDyAEhUIgiiEPIAogD3whCiAFIAqFQhiKIQUgBCAFIBx8fCEEIA8gBIVCEIohDyAKIA98IQogBSAKhUI/iiEFIAEgBSAefHwhASANIAGFQiCKIQ0gCSANfCEJIAUgCYVCGIohBSABIAUgHHx8IQEgDSABhUIQiiENIAkgDXwhCSAFIAmFQj+KIQUgAiAGIBh8fCECIA4gAoVCIIohDiAKIA58IQogBiAKhUIYiiEGIAIgBiAffHwhAiAOIAKFQhCKIQ4gCiAOfCEKIAYgCoVCP4ohBiADIAcgHXx8IQMgDyADhUIgiiEPIAsgD3whCyAHIAuFQhiKIQcgAyAHIBJ8fCEDIA8gA4VCEIohDyALIA98IQsgByALhUI/iiEHIAQgCCAUfHwhBCAQIASFQiCKIRAgDCAQfCEMIAggDIVCGIohCCAEIAggGnx8IQQgECAEhUIQiiEQIAwgEHwhDCAIIAyFQj+KIQggASAGIBZ8fCEBIBAgAYVCIIohECALIBB8IQsgBiALhUIYiiEGIAEgBiARfHwhASAQIAGFQhCKIRAgCyAQfCELIAYgC4VCP4ohBiACIAcgIHx8IQIgDSAChUIgiiENIAwgDXwhDCAHIAyFQhiKIQcgAiAHIBV8fCECIA0gAoVCEIohDSAMIA18IQwgByAMhUI/iiEHIAMgCCAZfHwhAyAOIAOFQiCKIQ4gCSAOfCEJIAggCYVCGIohCCADIAggF3x8IQMgDiADhUIQiiEOIAkgDnwhCSAIIAmFQj+KIQggBCAFIBN8fCEEIA8gBIVCIIohDyAKIA98IQogBSAKhUIYiiEFIAQgBSAbfHwhBCAPIASFQhCKIQ8gCiAPfCEKIAUgCoVCP4ohBSABIAUgF3x8IQEgDSABhUIgiiENIAkgDXwhCSAFIAmFQhiKIQUgASAFICB8fCEBIA0gAYVCEIohDSAJIA18IQkgBSAJhUI/iiEFIAIgBiAffHwhAiAOIAKFQiCKIQ4gCiAOfCEKIAYgCoVCGIohBiACIAYgGnx8IQIgDiAChUIQiiEOIAogDnwhCiAGIAqFQj+KIQYgAyAHIBx8fCEDIA8gA4VCIIohDyALIA98IQsgByALhUIYiiEHIAMgByAUfHwhAyAPIAOFQhCKIQ8gCyAPfCELIAcgC4VCP4ohByAEIAggEXx8IQQgECAEhUIgiiEQIAwgEHwhDCAIIAyFQhiKIQggBCAIIBl8fCEEIBAgBIVCEIohECAMIBB8IQwgCCAMhUI/iiEIIAEgBiAdfHwhASAQIAGFQiCKIRAgCyAQfCELIAYgC4VCGIohBiABIAYgE3x8IQEgECABhUIQiiEQIAsgEHwhCyAGIAuFQj+KIQYgAiAHIB58fCECIA0gAoVCIIohDSAMIA18IQwgByAMhUIYiiEHIAIgByAYfHwhAiANIAKFQhCKIQ0gDCANfCEMIAcgDIVCP4ohByADIAggEnx8IQMgDiADhUIgiiEOIAkgDnwhCSAIIAmFQhiKIQggAyAIIBV8fCEDIA4gA4VCEIohDiAJIA58IQkgCCAJhUI/iiEIIAQgBSAbfHwhBCAPIASFQiCKIQ8gCiAPfCEKIAUgCoVCGIohBSAEIAUgFnx8IQQgDyAEhUIQiiEPIAogD3whCiAFIAqFQj+KIQUgASAFIBt8fCEBIA0gAYVCIIohDSAJIA18IQkgBSAJhUIYiiEFIAEgBSATfHwhASANIAGFQhCKIQ0gCSANfCEJIAUgCYVCP4ohBSACIAYgGXx8IQIgDiAChUIgiiEOIAogDnwhCiAGIAqFQhiKIQYgAiAGIBV8fCECIA4gAoVCEIohDiAKIA58IQogBiAKhUI/iiEGIAMgByAYfHwhAyAPIAOFQiCKIQ8gCyAPfCELIAcgC4VCGIohByADIAcgF3x8IQMgDyADhUIQiiEPIAsgD3whCyAHIAuFQj+KIQcgBCAIIBJ8fCEEIBAgBIVCIIohECAMIBB8IQwgCCAMhUIYiiEIIAQgCCAWfHwhBCAQIASFQhCKIRAgDCAQfCEMIAggDIVCP4ohCCABIAYgIHx8IQEgECABhUIgiiEQIAsgEHwhCyAGIAuFQhiKIQYgASAGIBx8fCEBIBAgAYVCEIohECALIBB8IQsgBiALhUI/iiEGIAIgByAafHwhAiANIAKFQiCKIQ0gDCANfCEMIAcgDIVCGIohByACIAcgH3x8IQIgDSAChUIQiiENIAwgDXwhDCAHIAyFQj+KIQcgAyAIIBR8fCEDIA4gA4VCIIohDiAJIA58IQkgCCAJhUIYiiEIIAMgCCAdfHwhAyAOIAOFQhCKIQ4gCSAOfCEJIAggCYVCP4ohCCAEIAUgHnx8IQQgDyAEhUIgiiEPIAogD3whCiAFIAqFQhiKIQUgBCAFIBF8fCEEIA8gBIVCEIohDyAKIA98IQogBSAKhUI/iiEFIAEgBSARfHwhASANIAGFQiCKIQ0gCSANfCEJIAUgCYVCGIohBSABIAUgEnx8IQEgDSABhUIQiiENIAkgDXwhCSAFIAmFQj+KIQUgAiAGIBN8fCECIA4gAoVCIIohDiAKIA58IQogBiAKhUIYiiEGIAIgBiAUfHwhAiAOIAKFQhCKIQ4gCiAOfCEKIAYgCoVCP4ohBiADIAcgFXx8IQMgDyADhUIgiiEPIAsgD3whCyAHIAuFQhiKIQcgAyAHIBZ8fCEDIA8gA4VCEIohDyALIA98IQsgByALhUI/iiEHIAQgCCAXfHwhBCAQIASFQiCKIRAgDCAQfCEMIAggDIVCGIohCCAEIAggGHx8IQQgECAEhUIQiiEQIAwgEHwhDCAIIAyFQj+KIQggASAGIBl8fCEBIBAgAYVCIIohECALIBB8IQsgBiALhUIYiiEGIAEgBiAafHwhASAQIAGFQhCKIRAgCyAQfCELIAYgC4VCP4ohBiACIAcgG3x8IQIgDSAChUIgiiENIAwgDXwhDCAHIAyFQhiKIQcgAiAHIBx8fCECIA0gAoVCEIohDSAMIA18IQwgByAMhUI/iiEHIAMgCCAdfHwhAyAOIAOFQiCKIQ4gCSAOfCEJIAggCYVCGIohCCADIAggHnx8IQMgDiADhUIQiiEOIAkgDnwhCSAIIAmFQj+KIQggBCAFIB98fCEEIA8gBIVCIIohDyAKIA98IQogBSAKhUIYiiEFIAQgBSAgfHwhBCAPIASFQhCKIQ8gCiAPfCEKIAUgCoVCP4ohBSABIAUgH3x8IQEgDSABhUIgiiENIAkgDXwhCSAFIAmFQhiKIQUgASAFIBt8fCEBIA0gAYVCEIohDSAJIA18IQkgBSAJhUI/iiEFIAIgBiAVfHwhAiAOIAKFQiCKIQ4gCiAOfCEKIAYgCoVCGIohBiACIAYgGXx8IQIgDiAChUIQiiEOIAogDnwhCiAGIAqFQj+KIQYgAyAHIBp8fCEDIA8gA4VCIIohDyALIA98IQsgByALhUIYiiEHIAMgByAgfHwhAyAPIAOFQhCKIQ8gCyAPfCELIAcgC4VCP4ohByAEIAggHnx8IQQgECAEhUIgiiEQIAwgEHwhDCAIIAyFQhiKIQggBCAIIBd8fCEEIBAgBIVCEIohECAMIBB8IQwgCCAMhUI/iiEIIAEgBiASfHwhASAQIAGFQiCKIRAgCyAQfCELIAYgC4VCGIohBiABIAYgHXx8IQEgECABhUIQiiEQIAsgEHwhCyAGIAuFQj+KIQYgAiAHIBF8fCECIA0gAoVCIIohDSAMIA18IQwgByAMhUIYiiEHIAIgByATfHwhAiANIAKFQhCKIQ0gDCANfCEMIAcgDIVCP4ohByADIAggHHx8IQMgDiADhUIgiiEOIAkgDnwhCSAIIAmFQhiKIQggAyAIIBh8fCEDIA4gA4VCEIohDiAJIA58IQkgCCAJhUI/iiEIIAQgBSAWfHwhBCAPIASFQiCKIQ8gCiAPfCEKIAUgCoVCGIohBSAEIAUgFHx8IQQgDyAEhUIQiiEPIAogD3whCiAFIAqFQj+KIQUgISAhKQMAIAEgCYWFNwMAICIgIikDACACIAqFhTcDACAjICMpAwAgAyALhYU3AwAgJCAkKQMAIAQgDIWFNwMAICUgJSkDACAFIA2FhTcDACAmICYpAwAgBiAOhYU3AwAgJyAnKQMAIAcgD4WFNwMAICggKCkDACAIIBCFhTcDAAs=")}}),Ya=Za(),Ja=WebAssembly.compile(Ya),Wa=d((function(t){var e=null,a="undefined"!=typeof WebAssembly&&(async t=>(await WebAssembly.instantiate(await Ja,t)).exports)().then((t=>{e=t})),i=64,o=[];t.exports=u;var n=t.exports.BYTES_MIN=16,r=t.exports.BYTES_MAX=64;t.exports.BYTES=32;var c=t.exports.KEYBYTES_MIN=16,l=t.exports.KEYBYTES_MAX=64;t.exports.KEYBYTES=32;var s=t.exports.SALTBYTES=16,d=t.exports.PERSONALBYTES=16;function u(t,a,g,f,_){if(!(this instanceof u))return new u(t,a,g,f,_);if(!e)throw new Error("WASM not loaded. Wait for Blake2b.ready(cb)");t||(t=32),!0!==_&&(xa(t>=n,"digestLength must be at least "+n+", was given "+t),xa(t<=r,"digestLength must be at most "+r+", was given "+t),null!=a&&(xa(a instanceof Uint8Array,"key must be Uint8Array or Buffer"),xa(a.length>=c,"key must be at least "+c+", was given "+a.length),xa(a.length<=l,"key must be at least "+l+", was given "+a.length)),null!=g&&(xa(g instanceof Uint8Array,"salt must be Uint8Array or Buffer"),xa(g.length===s,"salt must be exactly "+s+", was given "+g.length)),null!=f&&(xa(f instanceof Uint8Array,"personal must be Uint8Array or Buffer"),xa(f.length===d,"personal must be exactly "+d+", was given "+f.length))),o.length||(o.push(i),i+=216),this.digestLength=t,this.finalized=!1,this.pointer=o.pop(),this._memory=new Uint8Array(e.memory.buffer),this._memory.fill(0,0,64),this._memory[0]=this.digestLength,this._memory[1]=a?a.length:0,this._memory[2]=1,this._memory[3]=1,g&&this._memory.set(g,32),f&&this._memory.set(f,48),this.pointer+216>this._memory.length&&this._realloc(this.pointer+216),e.blake2b_init(this.pointer,this.digestLength),a&&(this.update(a),this._memory.fill(0,i,i+a.length),this._memory[this.pointer+200]=128)}function g(){}u.prototype._realloc=function(t){e.memory.grow(Math.max(0,Math.ceil(Math.abs(t-this._memory.length)/65536))),this._memory=new Uint8Array(e.memory.buffer)},u.prototype.update=function(t){return xa(!1===this.finalized,"Hash instance finalized"),xa(t instanceof Uint8Array,"input must be Uint8Array or Buffer"),i+t.length>this._memory.length&&this._realloc(i+t.length),this._memory.set(t,i),e.blake2b_update(this.pointer,i,i+t.length),this},u.prototype.digest=function(t){if(xa(!1===this.finalized,"Hash instance finalized"),this.finalized=!0,o.push(this.pointer),e.blake2b_final(this.pointer),!t||"binary"===t)return this._memory.slice(this.pointer+128,this.pointer+128+this.digestLength);if("string"==typeof t)return Ha.toString(this._memory,t,this.pointer+128,this.pointer+128+this.digestLength);xa(t instanceof Uint8Array&&t.length>=this.digestLength,"input must be Uint8Array or Buffer");for(var a=0;a<this.digestLength;a++)t[a]=this._memory[this.pointer+128+a];return t},u.prototype.final=u.prototype.digest,u.WASM=e,u.SUPPORTED="undefined"!=typeof WebAssembly,u.ready=function(t){return t||(t=g),a?a.then((()=>t()),t):t(new Error("WebAssembly not supported"))},u.prototype.ready=u.ready,u.prototype.getPartialHash=function(){return this._memory.slice(this.pointer,this.pointer+216)},u.prototype.setPartialHash=function(t){this._memory.set(t,this.pointer)}}));const Xa=[];for(let t=0;t<256;t++)Xa[t]=ti(t,8);function ti(t,e){let a=0,i=t;for(let t=0;t<e;t++)a<<=1,a|=1&i,i>>=1;return a}function ei(t){return(0!=(4294901760&t)?(t&=4294901760,16):0)|(0!=(4278255360&t)?(t&=4278255360,8):0)|(0!=(4042322160&t)?(t&=4042322160,4):0)|(0!=(3435973836&t)?(t&=3435973836,2):0)|0!=(2863311530&t)}function ai(t,e){const a=new DataView(t.buffer,t.byteOffset,t.byteLength);let i="";for(let t=0;t<4;t++){t>0&&(i+="\n"),i+="\t\t";for(let e=0;e<4;e++)e>0&&(i+=" "),i+=a.getUint32(16*t+4*e).toString(16).padStart(8,"0")}return e&&(i=e+"\n"+i),i}function ii(t,e){if(t.byteLength!=e.byteLength)return!1;for(var a=new Int8Array(t),i=new Int8Array(e),o=0;o!=t.byteLength;o++)if(a[o]!=i[o])return!1;return!0}function oi(t){const e=t.getPartialHash(),a=Wa(64);return a.setPartialHash(e),a}async function ni(t,e,a,i,o){if(t.G1.isZero(e))return!1;if(t.G1.isZero(a))return!1;if(t.G2.isZero(i))return!1;if(t.G2.isZero(o))return!1;return await t.pairingEq(e,o,t.G1.neg(a),i)}async function ri(t){for(;!t;)t=await window.prompt("Enter a random text. (Entropy): ","");const e=Wa(64);e.update(wt.randomBytes(64));const a=new TextEncoder;e.update(a.encode(t));const i=Buffer.from(e.digest()),o=[];for(let t=0;t<8;t++)o[t]=i.readUInt32BE(4*t);return new Lt(o)}function ci(t,e){let a,i;e<32?(a=1<<e>>>0,i=1):(a=4294967296,i=1<<e-32>>>0);let o=t;for(let t=0;t<i;t++)for(let t=0;t<a;t++)o=wt.createHash("sha256").update(o).digest();const n=new DataView(o.buffer,o.byteOffset,o.byteLength),r=[];for(let t=0;t<8;t++)r[t]=n.getUint32(4*t,!1);return new Lt(r)}function li(t){return t instanceof Uint8Array?t:("0x"==t.slice(0,2)&&(t=t.slice(2)),new Uint8Array(t.match(/[\da-f]{2}/gi).map((function(t){return parseInt(t,16)}))))}function si(t){return Array.prototype.map.call(t,(function(t){return("0"+(255&t).toString(16)).slice(-2)})).join("")}async function di(t,e){await fa(t,1),await t.writeULE32(1),await _a(t);const a=await Ca(e.q);await fa(t,2);const i=a.q,o=8*(Math.floor((He.bitLength(i)-1)/64)+1),n=a.r,r=8*(Math.floor((He.bitLength(n)-1)/64)+1);await t.writeULE32(o),await ma(t,i,o),await t.writeULE32(r),await ma(t,n,r),await t.writeULE32(e.nVars),await t.writeULE32(e.nPublic),await t.writeULE32(e.domainSize),await ui(t,a,e.vk_alpha_1),await ui(t,a,e.vk_beta_1),await gi(t,a,e.vk_beta_2),await gi(t,a,e.vk_gamma_2),await ui(t,a,e.vk_delta_1),await gi(t,a,e.vk_delta_2),await _a(t)}async function ui(t,e,a){const i=new Uint8Array(2*e.G1.F.n8);e.G1.toRprLEM(i,0,a),await t.write(i)}async function gi(t,e,a){const i=new Uint8Array(2*e.G2.F.n8);e.G2.toRprLEM(i,0,a),await t.write(i)}async function fi(t,e,a){const i=await t.read(2*e.G1.F.n8),o=e.G1.fromRprLEM(i,0);return a?e.G1.toObject(o):o}async function _i(t,e,a){const i=await t.read(2*e.G2.F.n8),o=e.G2.fromRprLEM(i,0);return a?e.G2.toObject(o):o}async function pi(t,e,a){await pa(t,e,1);const i=await t.readULE32();if(await ha(t),1==i)return await async function(t,e,a){const i={protocol:"groth16"};await pa(t,e,2);const o=await t.readULE32();i.n8q=o,i.q=await La(t,o);const n=await t.readULE32();i.n8r=n,i.r=await La(t,n);let r=await Ca(i.q);return i.nVars=await t.readULE32(),i.nPublic=await t.readULE32(),i.domainSize=await t.readULE32(),i.power=ei(i.domainSize),i.vk_alpha_1=await fi(t,r,a),i.vk_beta_1=await fi(t,r,a),i.vk_beta_2=await _i(t,r,a),i.vk_gamma_2=await _i(t,r,a),i.vk_delta_1=await fi(t,r,a),i.vk_delta_2=await _i(t,r,a),await ha(t),i}(t,e,a);if(2==i)return await async function(t,e,a,i){const o={protocol:"plonk"};await pa(t,e,2);const n=await t.readULE32();o.n8q=n,o.q=await La(t,n);const r=await t.readULE32();o.n8r=r,o.r=await La(t,r);let c=await Ca(o.q);return o.nVars=await t.readULE32(),o.nPublic=await t.readULE32(),o.domainSize=await t.readULE32(),o.power=ei(o.domainSize),o.nAdditions=await t.readULE32(),o.nConstrains=await t.readULE32(),o.k1=await t.read(r),o.k2=await t.read(r),o.Qm=await fi(t,c,i),o.Ql=await fi(t,c,i),o.Qr=await fi(t,c,i),o.Qo=await fi(t,c,i),o.Qc=await fi(t,c,i),o.S1=await fi(t,c,i),o.S2=await fi(t,c,i),o.S3=await fi(t,c,i),o.X_2=await _i(t,c,i),await ha(t),o}(t,e);throw new Error("Protocol not supported: ")}async function hi(t,e,a){const i={delta:{}};i.deltaAfter=await fi(t,e,a),i.delta.g1_s=await fi(t,e,a),i.delta.g1_sx=await fi(t,e,a),i.delta.g2_spx=await _i(t,e,a),i.transcript=await t.read(64),i.type=await t.readULE32();const o=await t.readULE32(),n=t.pos;let r=0;for(;t.pos-n<o;){const e=await t.read(1);if(e[0]<=r)throw new Error("Parameters in the contribution must be sorted");if(r=e[0],1==e[0]){const e=await t.read(1),a=await t.read(e[0]);i.name=(new TextDecoder).decode(a)}else if(2==e[0]){const e=await t.read(1);i.numIterationsExp=e[0]}else{if(3!=e[0])throw new Error("Parameter not recognized");{const e=await t.read(1);i.beaconHash=await t.read(e[0])}}}if(t.pos!=n+o)throw new Error("Parametes do not match");return i}async function mi(t,e,a){await pa(t,a,10);const i={contributions:[]};i.csHash=await t.read(64);const o=await t.readULE32();for(let a=0;a<o;a++){const a=await hi(t,e);i.contributions.push(a)}return await ha(t),i}async function Li(t,e,a){await ui(t,e,a.deltaAfter),await ui(t,e,a.delta.g1_s),await ui(t,e,a.delta.g1_sx),await gi(t,e,a.delta.g2_spx),await t.write(a.transcript),await t.writeULE32(a.type||0);const i=[];if(a.name){i.push(1);const t=new TextEncoder("utf-8").encode(a.name.substring(0,64));i.push(t.byteLength);for(let e=0;e<t.byteLength;e++)i.push(t[e])}if(1==a.type){i.push(2),i.push(a.numIterationsExp),i.push(3),i.push(a.beaconHash.byteLength);for(let t=0;t<a.beaconHash.byteLength;t++)i.push(a.beaconHash[t])}if(i.length>0){const e=new Uint8Array(i);await t.writeULE32(e.byteLength),await t.write(e)}else await t.writeULE32(0)}async function wi(t,e,a){await fa(t,10),await t.write(a.csHash),await t.writeULE32(a.contributions.length);for(let i=0;i<a.contributions.length;i++)await Li(t,e,a.contributions[i]);await _a(t)}function Ai(t,e,a){const i=new Uint8Array(2*e.G1.F.n8);e.G1.toRprUncompressed(i,0,a),t.update(i)}function bi(t,e,a){Ai(t,e,a.deltaAfter),Ai(t,e,a.delta.g1_s),Ai(t,e,a.delta.g1_sx),function(t,e,a){const i=new Uint8Array(2*e.G2.F.n8);e.G2.toRprUncompressed(i,0,a),t.update(i)}(t,e,a.delta.g2_spx),t.update(a.transcript)}async function yi(t,e){await pa(t,e,1);const a=await t.readULE32(),i=await La(t,a),o=await t.readULE32();return await ha(t),{n8:a,q:i,nWitness:o}}const{stringifyBigInts:Ii}=$e;async function Ci(t,e,a){const{fd:i,sections:o}=await ua(e,"wtns",2),n=await yi(i,o),{fd:r,sections:c}=await ua(t,"zkey",2),l=await pi(r,c);if("groth16"!=l.protocol)throw new Error("zkey file is not groth16");if(!He.eq(l.r,n.q))throw new Error("Curve of the witness does not match the curve of the proving key");if(n.nWitness!=l.nVars)throw new Error(`Invalid witness length. Circuit: ${l.nVars}, witness: ${n.nWitness}`);const s=await Ca(l.q),d=s.Fr,u=s.G1,g=s.G2,f=ei(l.domainSize);a&&a.debug("Reading Wtns");const _=await Aa(i,o,2);a&&a.debug("Reading Coeffs");const p=await Aa(r,c,4);a&&a.debug("Building ABC");const[h,m,L]=await async function(t,e,a,i,o){const n=t.Fr.n8,r=12+e.n8r,c=(i.byteLength-4)/r,l=new fe(e.domainSize*n),s=new fe(e.domainSize*n),d=new fe(e.domainSize*n),u=[l,s];for(let e=0;e<c;e++){o&&e%1e6==0&&o.debug(`QAP AB: ${e}/${c}`);const l=i.slice(4+e*r,4+e*r+r),s=new DataView(l.buffer),d=s.getUint32(0,!0),g=s.getUint32(4,!0),f=s.getUint32(8,!0),_=l.slice(12,12+n);u[d].set(t.Fr.add(u[d].slice(g*n,g*n+n),t.Fr.mul(_,a.slice(f*n,f*n+n))),g*n)}for(let a=0;a<e.domainSize;a++)o&&a%1e6==0&&o.debug(`QAP C: ${a}/${e.domainSize}`),d.set(t.Fr.mul(l.slice(a*n,a*n+n),s.slice(a*n,a*n+n)),a*n);return[l,s,d]}(s,l,_,p,a),w=f==d.s?s.Fr.shift:s.Fr.w[f+1],A=await d.ifft(h,"","",a,"IFFT_A"),b=await d.batchApplyKey(A,d.e(1),w),y=await d.fft(b,"","",a,"FFT_A"),I=await d.ifft(m,"","",a,"IFFT_B"),C=await d.batchApplyKey(I,d.e(1),w),F=await d.fft(C,"","",a,"FFT_B"),x=await d.ifft(L,"","",a,"IFFT_C"),v=await d.batchApplyKey(x,d.e(1),w),E=await d.fft(v,"","",a,"FFT_C");a&&a.debug("Join ABC");const B=await async function(t,e,a,i,o,n){const r=1<<22,c=t.Fr.n8,l=Math.floor(a.byteLength/t.Fr.n8),s=[];for(let e=0;e<l;e+=r){n&&n.debug(`JoinABC: ${e}/${l}`);const d=Math.min(l-e,r),u=[],g=a.slice(e*c,(e+d)*c),f=i.slice(e*c,(e+d)*c),_=o.slice(e*c,(e+d)*c);u.push({cmd:"ALLOCSET",var:0,buff:g}),u.push({cmd:"ALLOCSET",var:1,buff:f}),u.push({cmd:"ALLOCSET",var:2,buff:_}),u.push({cmd:"ALLOC",var:3,len:d*c}),u.push({cmd:"CALL",fnName:"qap_joinABC",params:[{var:0},{var:1},{var:2},{val:d},{var:3}]}),u.push({cmd:"CALL",fnName:"frm_batchFromMontgomery",params:[{var:3},{val:d},{var:3}]}),u.push({cmd:"GET",out:0,var:3,len:d*c}),s.push(t.tm.queueAction(u))}const d=await Promise.all(s);let u;u=a instanceof fe?new fe(a.byteLength):new Uint8Array(a.byteLength);let g=0;for(let t=0;t<d.length;t++)u.set(d[t][0],g),g+=d[t][0].byteLength;return u}(s,0,y,F,E,a);let S={};a&&a.debug("Reading A Points");const G=await Aa(r,c,5);S.pi_a=await s.G1.multiExpAffine(G,_,a,"multiexp A"),a&&a.debug("Reading B1 Points");const P=await Aa(r,c,6);let O=await s.G1.multiExpAffine(P,_,a,"multiexp B1");a&&a.debug("Reading B2 Points");const U=await Aa(r,c,7);S.pi_b=await s.G2.multiExpAffine(U,_,a,"multiexp B2"),a&&a.debug("Reading C Points");const z=await Aa(r,c,8);S.pi_c=await s.G1.multiExpAffine(z,_.slice((l.nPublic+1)*s.Fr.n8),a,"multiexp C"),a&&a.debug("Reading H Points");const q=await Aa(r,c,9),Q=await s.G1.multiExpAffine(q,B,a,"multiexp H"),M=s.Fr.random(),k=s.Fr.random();S.pi_a=u.add(S.pi_a,l.vk_alpha_1),S.pi_a=u.add(S.pi_a,u.timesFr(l.vk_delta_1,M)),S.pi_b=g.add(S.pi_b,l.vk_beta_2),S.pi_b=g.add(S.pi_b,g.timesFr(l.vk_delta_2,k)),O=u.add(O,l.vk_beta_1),O=u.add(O,u.timesFr(l.vk_delta_1,k)),S.pi_c=u.add(S.pi_c,Q),S.pi_c=u.add(S.pi_c,u.timesFr(S.pi_a,k)),S.pi_c=u.add(S.pi_c,u.timesFr(O,M)),S.pi_c=u.add(S.pi_c,u.timesFr(l.vk_delta_1,d.neg(d.mul(M,k))));let R=[];for(let t=1;t<=l.nPublic;t++){const e=_.slice(t*d.n8,t*d.n8+d.n8);R.push(He.fromRprLE(e))}return S.pi_a=u.toObject(u.toAffine(S.pi_a)),S.pi_b=g.toObject(g.toAffine(S.pi_b)),S.pi_c=u.toObject(u.toAffine(S.pi_c)),S.protocol="groth16",S.curve=s.name,await r.close(),await i.close(),S=Ii(S),R=Ii(R),{proof:S,publicSignals:R}}function Fi(t){var e=[];return function t(e,a){if(Array.isArray(a))for(let i=0;i<a.length;i++)t(e,a[i]);else e.push(a)}(e,t),e}function xi(t){const e=BigInt(2)**BigInt(64);let a=BigInt("0xCBF29CE484222325");for(var i=0;i<t.length;i++)a^=BigInt(t[i].charCodeAt()),a*=BigInt(1099511628211),a%=e;let o=a.toString(16),n=16-o.length;return o="0".repeat(n).concat(o),o}function vi(t,e){const a=[];let i=BigInt(t);const o=BigInt(4294967296);for(;i;)a.unshift(Number(i%o)),i/=o;if(e)for(var n=e-a.length;n>0;)a.unshift(0),n--;return a}async function Ei(t,e){e=e||{};let a,i=32767,o=!1;for(;!o;)try{a=new WebAssembly.Memory({initial:i}),o=!0}catch(t){if(1===i)throw t;console.warn("Could not allocate "+1024*i*64+" bytes. This may cause severe instability. Trying with "+1024*i*64/2+" bytes"),i=Math.floor(i/2)}const n=await WebAssembly.compile(t);let r;const c=await WebAssembly.instantiate(n,{env:{memory:a},runtime:{exceptionHandler:function(t){let e;throw e=1==t?"Signal not found. ":2==t?"Too many signals set. ":3==t?"Signal already set. ":4==t?"Assert Failed. ":5==t?"Not enough memory. ":"Unknown error.",console.log("ERROR: ",t,e),new Error(e)},showSharedRWMemory:function(){const t=c.exports.getFieldNumLen32(),e=new Uint32Array(t);for(let a=0;a<t;a++)e[t-1-a]=c.exports.readSharedRWMemory(a);console.log(He.fromArray(e,4294967296))},error:function(t,a,i,o,n,c){let l;throw l=7==t?s(a)+" "+r.getFr(o).toString()+" != "+r.getFr(n).toString()+" "+s(c):9==t?s(a)+" "+r.getFr(o).toString()+" "+s(n):5==t&&e.sym?s(a)+" "+e.sym.labelIdx2Name[n]:s(a)+" "+i+" "+o+" "+n+" "+c,console.log("ERROR: ",t,l),new Error(l)},log:function(t){console.log(r.getFr(t).toString())},logGetSignal:function(t,a){e.logGetSignal&&e.logGetSignal(t,r.getFr(a))},logSetSignal:function(t,a){e.logSetSignal&&e.logSetSignal(t,r.getFr(a))},logStartComponent:function(t){e.logStartComponent&&e.logStartComponent(t)},logFinishComponent:function(t){e.logFinishComponent&&e.logFinishComponent(t)}}}),l=e&&(e.sanityCheck||e.logGetSignal||e.logSetSignal||e.logStartComponent||e.logFinishComponent);return r="function"==typeof c.exports.getVersion?new Si(c,l):new Bi(a,c,l),r;function s(t){const e=new Uint8Array(a.buffer),i=[];for(let a=0;e[t+a]>0;a++)i.push(e[t+a]);return String.fromCharCode.apply(null,i)}}class Bi{constructor(t,e,a){this.memory=t,this.i32=new Uint32Array(t.buffer),this.instance=e,this.n32=(this.instance.exports.getFrLen()>>2)-2;const i=this.instance.exports.getPRawPrime(),o=new Array(this.n32);for(let t=0;t<this.n32;t++)o[this.n32-1-t]=this.i32[(i>>2)+t];this.prime=He.fromArray(o,4294967296),this.Fr=new vt(this.prime),this.mask32=He.fromString("FFFFFFFF",16),this.NVars=this.instance.exports.getNVars(),this.n64=Math.floor((this.Fr.bitLength-1)/64)+1,this.R=this.Fr.e(He.shiftLeft(1,64*this.n64)),this.RInv=this.Fr.inv(this.R),this.sanityCheck=a}circom_version(){return 1}async _doCalculateWitness(t,e){this.instance.exports.init(this.sanityCheck||e?1:0);const a=this.allocInt(),i=this.allocFr();Object.keys(t).forEach((e=>{const o=xi(e),n=parseInt(o.slice(0,8),16),r=parseInt(o.slice(8,16),16);try{this.instance.exports.getSignalOffset32(a,0,n,r)}catch(t){throw new Error(`Signal ${e} is not an input of the circuit.`)}const c=this.getInt(a),l=Fi(t[e]);for(let t=0;t<l.length;t++)this.setFr(i,l[t]),this.instance.exports.setSignal(0,0,c+t,i)}))}async calculateWitness(t,e){const a=this,i=a.i32[0],o=[];await a._doCalculateWitness(t,e);for(let t=0;t<a.NVars;t++){const e=a.instance.exports.getPWitness(t);o.push(a.getFr(e))}return a.i32[0]=i,o}async calculateBinWitness(t,e){const a=this,i=a.i32[0];await a._doCalculateWitness(t,e);const o=a.instance.exports.getWitnessBuffer();a.i32[0]=i;const n=a.memory.buffer.slice(o,o+a.NVars*a.n64*8);return new Uint8Array(n)}allocInt(){const t=this.i32[0];return this.i32[0]=t+8,t}allocFr(){const t=this.i32[0];return this.i32[0]=t+4*this.n32+8,t}getInt(t){return this.i32[t>>2]}setInt(t,e){this.i32[t>>2]=e}getFr(t){const e=this,a=t>>2;if(2147483648&e.i32[a+1]){const t=new Array(e.n32);for(let i=0;i<e.n32;i++)t[e.n32-1-i]=e.i32[a+2+i];const o=e.Fr.e(He.fromArray(t,4294967296));return 1073741824&e.i32[a+1]?(i=o,e.Fr.mul(e.RInv,i)):o}return 2147483648&e.i32[a]?e.Fr.e(e.i32[a]-4294967296):e.Fr.e(e.i32[a]);var i}setFr(t,e){const a=this;e=a.Fr.e(e);const i=a.Fr.neg(a.Fr.e("80000000",16)),o=a.Fr.e("7FFFFFFF",16);if(a.Fr.geq(e,i)&&a.Fr.leq(e,o)){let o;return a.Fr.geq(e,a.Fr.zero)?o=He.toNumber(e):(o=He.toNumber(a.Fr.sub(e,i)),o-=2147483648,o=4294967296+o),a.i32[t>>2]=o,void(a.i32[1+(t>>2)]=0)}a.i32[t>>2]=0,a.i32[1+(t>>2)]=2147483648;const n=He.toArray(e,4294967296);for(let e=0;e<a.n32;e++){const i=n.length-1-e;a.i32[2+(t>>2)+e]=i>=0?n[i]:0}}}class Si{constructor(t,e){this.instance=t,this.version=this.instance.exports.getVersion(),this.n32=this.instance.exports.getFieldNumLen32(),this.instance.exports.getRawPrime();const a=new Array(this.n32);for(let t=0;t<this.n32;t++)a[this.n32-1-t]=this.instance.exports.readSharedRWMemory(t);this.prime=He.fromArray(a,4294967296),this.witnessSize=this.instance.exports.getWitnessSize(),this.sanityCheck=e}circom_version(){return this.instance.exports.getVersion()}async _doCalculateWitness(t,e){this.instance.exports.init(this.sanityCheck||e?1:0);const a=Object.keys(t);var i=0;if(a.forEach((e=>{const a=xi(e),o=parseInt(a.slice(0,8),16),n=parseInt(a.slice(8,16),16),r=Fi(t[e]);for(let t=0;t<r.length;t++){const e=vi(r[t],this.n32);for(let t=0;t<this.n32;t++)this.instance.exports.writeSharedRWMemory(t,e[this.n32-1-t]);try{this.instance.exports.setInputSignal(o,n,t),i++}catch(t){throw new Error(t)}}})),i<this.instance.exports.getInputSize())throw new Error(`Not all inputs have been set. Only ${i} out of ${this.instance.exports.getInputSize()}`)}async calculateWitness(t,e){const a=[];await this._doCalculateWitness(t,e);for(let t=0;t<this.witnessSize;t++){this.instance.exports.getWitness(t);const e=new Uint32Array(this.n32);for(let t=0;t<this.n32;t++)e[this.n32-1-t]=this.instance.exports.readSharedRWMemory(t);a.push(fromArray32(e))}return a}async calculateWTNSBin(t,e){const a=new Uint32Array(this.witnessSize*this.n32+this.n32+11),i=new Uint8Array(a.buffer);await this._doCalculateWitness(t,e),i[0]="w".charCodeAt(0),i[1]="t".charCodeAt(0),i[2]="n".charCodeAt(0),i[3]="s".charCodeAt(0),a[1]=2,a[2]=2,a[3]=1;const o=4*this.n32,n=(8+o).toString(16);a[4]=parseInt(n.slice(0,8),16),a[5]=parseInt(n.slice(8,16),16),a[6]=o,this.instance.exports.getRawPrime();var r=7;for(let t=0;t<this.n32;t++)a[r+t]=this.instance.exports.readSharedRWMemory(t);a[r+=this.n32]=this.witnessSize,a[++r]=2,r++;const c=(o*this.witnessSize).toString(16);a[r]=parseInt(c.slice(0,8),16),a[r+1]=parseInt(c.slice(8,16),16),r+=2;for(let t=0;t<this.witnessSize;t++){this.instance.exports.getWitness(t);for(let t=0;t<this.n32;t++)a[r+t]=this.instance.exports.readSharedRWMemory(t);r+=this.n32}return i}}async function Gi(t,e,a,i){const o=await da(e),n=await o.read(o.totalSize);await o.close();const r=await Ei(n);if(1==r.circom_version()){const e=await r.calculateBinWitness(t,!0),i=await ga(a,"wtns",2,2);await async function(t,e,a){await fa(t,1);const i=8*(Math.floor((He.bitLength(a)-1)/64)+1);if(await t.writeULE32(i),await ma(t,a,i),e.byteLength%i!=0)throw new Error("Invalid witness length");await t.writeULE32(e.byteLength/i),await _a(t),await fa(t,2),await t.write(e),await _a(t)}(i,e,r.prime),await i.close()}else{const e=await sa(a),i=await r.calculateWTNSBin(t);await e.write(i),await e.close()}}const{unstringifyBigInts:Pi}=$e;function Oi(t){let e=t.toString(16);for(;e.length<64;)e="0"+e;return e=`"0x${e}"`,e}var Ui=Object.freeze({__proto__:null,fullProve:async function(t,e,a,i){const o={type:"mem"};return await Gi(t,e,o),await Ci(a,o,i)},prove:Ci,verify:async function(t,e,a,i){t=Pi(t),a=Pi(a),e=Pi(e);const o=await Fa(t.curve),n=o.G1.fromObject(t.IC[0]),r=new Uint8Array(2*o.G1.F.n8*e.length),c=new Uint8Array(o.Fr.n8*e.length);for(let a=0;a<e.length;a++){const i=o.G1.fromObject(t.IC[a+1]);r.set(i,a*o.G1.F.n8*2),He.toRprLE(c,o.Fr.n8*a,e[a],o.Fr.n8)}let l=await o.G1.multiExpAffine(r,c);l=o.G1.add(l,n);const s=o.G1.fromObject(a.pi_a),d=o.G2.fromObject(a.pi_b),u=o.G1.fromObject(a.pi_c),g=o.G2.fromObject(t.vk_gamma_2),f=o.G2.fromObject(t.vk_delta_2),_=o.G1.fromObject(t.vk_alpha_1),p=o.G2.fromObject(t.vk_beta_2);return await o.pairingEq(o.G1.neg(s),d,l,g,u,f,_,p)?(i&&i.info("OK!"),!0):(i&&i.error("Invalid proof"),!1)},exportSolidityCallData:async function(t,e){let a,i="";for(let t=0;t<e.length;t++)""!=i&&(i+=","),i+=Oi(e[t]);return a=`[${Oi(t.pi_a[0])}, ${Oi(t.pi_a[1])}],[[${Oi(t.pi_b[0][1])}, ${Oi(t.pi_b[0][0])}],[${Oi(t.pi_b[1][1])}, ${Oi(t.pi_b[1][0])}]],[${Oi(t.pi_c[0])}, ${Oi(t.pi_c[1])}],[${i}]`,a}});function zi(t,e){const a=new DataView(e.buffer,e.byteOffset,e.byteLength),i=[];for(let t=0;t<8;t++)i[t]=a.getUint32(4*t);const o=new Lt(i);return t.G2.fromRng(o)}function qi(t,e,a,i,o){const n=Wa(64),r=new Uint8Array([e]);n.update(r),n.update(a);const c=t.G1.toUncompressed(i);n.update(c);const l=t.G1.toUncompressed(o);n.update(l);return zi(t,n.digest())}function Qi(t,e,a,i,o){return t.g1_s=e.G1.toAffine(e.G1.fromRng(o)),t.g1_sx=e.G1.toAffine(e.G1.timesFr(t.g1_s,t.prvKey)),t.g2_sp=e.G2.toAffine(qi(e,a,i,t.g1_s,t.g1_sx)),t.g2_spx=e.G2.toAffine(e.G2.timesFr(t.g2_sp,t.prvKey)),t}function Mi(t,e,a){const i={tau:{},alpha:{},beta:{}};return i.tau.prvKey=t.Fr.fromRng(a),i.alpha.prvKey=t.Fr.fromRng(a),i.beta.prvKey=t.Fr.fromRng(a),Qi(i.tau,t,0,e,a),Qi(i.alpha,t,1,e,a),Qi(i.beta,t,2,e,a),i}async function ki(t,e,a,i){i||(i=a),await t.writeULE32(1);const o=t.pos;await t.writeULE64(0),await t.writeULE32(8*e.F1.n64);const n=new Uint8Array(e.F1.n8);He.toRprLE(n,0,e.q,e.F1.n8),await t.write(n),await t.writeULE32(a),await t.writeULE32(i);const r=t.pos-o-8,c=t.pos;await t.writeULE64(r,o),t.pos=c}async function Ri(t,e){if(!e[1])throw new Error(t.fileName+": File has no header");if(e[1].length>1)throw new Error(t.fileName+": File has more than one header");t.pos=e[1][0].p;const a=await t.readULE32(),i=await t.read(a),o=He.fromRprLE(i),n=await Ca(o);if(8*n.F1.n64!=a)throw new Error(t.fileName+": Invalid size");const r=await t.readULE32(),c=await t.readULE32();if(t.pos-e[1][0].p!=e[1][0].size)throw new Error("Invalid PTau header size");return{curve:n,power:r,ceremonyPower:c}}function Ni(t,e,a,i){const o={tau:{},alpha:{},beta:{}};return o.tau.g1_s=n(),o.tau.g1_sx=n(),o.alpha.g1_s=n(),o.alpha.g1_sx=n(),o.beta.g1_s=n(),o.beta.g1_sx=n(),o.tau.g2_spx=r(),o.alpha.g2_spx=r(),o.beta.g2_spx=r(),o;function n(){let o;return o=i?a.G1.fromRprLEM(t,e):a.G1.fromRprUncompressed(t,e),e+=2*a.G1.F.n8,o}function r(){let o;return o=i?a.G2.fromRprLEM(t,e):a.G2.fromRprUncompressed(t,e),e+=2*a.G2.F.n8,o}}function Ti(t,e,a,i,o){async function n(i){o?a.G1.toRprLEM(t,e,i):a.G1.toRprUncompressed(t,e,i),e+=2*a.F1.n8}async function r(i){o?a.G2.toRprLEM(t,e,i):a.G2.toRprUncompressed(t,e,i),e+=2*a.F2.n8}return n(i.tau.g1_s),n(i.tau.g1_sx),n(i.alpha.g1_s),n(i.alpha.g1_sx),n(i.beta.g1_s),n(i.beta.g1_sx),r(i.tau.g2_spx),r(i.alpha.g2_spx),r(i.beta.g2_spx),t}async function Di(t,e){const a={};a.tauG1=await l(),a.tauG2=await s(),a.alphaG1=await l(),a.betaG1=await l(),a.betaG2=await s(),a.key=await async function(t,e,a){return Ni(await t.read(2*e.F1.n8*6+2*e.F2.n8*3),0,e,a)}(t,e,!0),a.partialHash=await t.read(216),a.nextChallenge=await t.read(64),a.type=await t.readULE32();const i=new Uint8Array(2*e.G1.F.n8*6+2*e.G2.F.n8*3);Ti(i,0,e,a.key,!1);const o=Wa(64);o.setPartialHash(a.partialHash),o.update(i),a.responseHash=o.digest();const n=await t.readULE32(),r=t.pos;let c=0;for(;t.pos-r<n;){const t=await d(1);if(t[0]<=c)throw new Error("Parameters in the contribution must be sorted");if(c=t[0],1==t[0]){const t=await d(1),e=await d(t[0]);a.name=(new TextDecoder).decode(e)}else if(2==t[0]){const t=await d(1);a.numIterationsExp=t[0]}else{if(3!=t[0])throw new Error("Parameter not recognized");{const t=await d(1);a.beaconHash=await d(t[0])}}}if(t.pos!=r+n)throw new Error("Parametes do not match");return a;async function l(){const a=await t.read(2*e.G1.F.n8);return e.G1.fromRprLEM(a)}async function s(){const a=await t.read(2*e.G2.F.n8);return e.G2.fromRprLEM(a)}async function d(e){const a=await t.read(e);return new Uint8Array(a)}}async function Ki(t,e,a){if(!a[7])throw new Error(t.fileName+": File has no contributions");if(a[7][0].length>1)throw new Error(t.fileName+": File has more than one contributions section");t.pos=a[7][0].p;const i=await t.readULE32(),o=[];for(let a=0;a<i;a++){const i=await Di(t,e);i.id=a+1,o.push(i)}if(t.pos-a[7][0].p!=a[7][0].size)throw new Error("Invalid contribution section size");return o}async function Vi(t,e,a){const i=new Uint8Array(2*e.F1.n8),o=new Uint8Array(2*e.F2.n8);await r(a.tauG1),await c(a.tauG2),await r(a.alphaG1),await r(a.betaG1),await c(a.betaG2),await async function(t,e,a,i){const o=new Uint8Array(2*e.F1.n8*6+2*e.F2.n8*3);Ti(o,0,e,a,i),await t.write(o)}(t,e,a.key,!0),await t.write(a.partialHash),await t.write(a.nextChallenge),await t.writeULE32(a.type||0);const n=[];if(a.name){n.push(1);const t=new TextEncoder("utf-8").encode(a.name.substring(0,64));n.push(t.byteLength);for(let e=0;e<t.byteLength;e++)n.push(t[e])}if(1==a.type){n.push(2),n.push(a.numIterationsExp),n.push(3),n.push(a.beaconHash.byteLength);for(let t=0;t<a.beaconHash.byteLength;t++)n.push(a.beaconHash[t])}if(n.length>0){const e=new Uint8Array(n);await t.writeULE32(e.byteLength),await t.write(e)}else await t.writeULE32(0);async function r(a){e.G1.toRprLEM(i,0,a),await t.write(i)}async function c(a){e.G2.toRprLEM(o,0,a),await t.write(o)}}async function ji(t,e,a){await t.writeULE32(7);const i=t.pos;await t.writeULE64(0),await t.writeULE32(a.length);for(let i=0;i<a.length;i++)await Vi(t,e,a[i]);const o=t.pos-i-8,n=t.pos;await t.writeULE64(o,i),t.pos=n}function Hi(t,e,a){a&&a.debug("Calculating First Challenge Hash");const i=new Wa(64),o=new Uint8Array(2*t.G1.F.n8),n=new Uint8Array(2*t.G2.F.n8);let r;return t.G1.toRprUncompressed(o,0,t.G1.g),t.G2.toRprUncompressed(n,0,t.G2.g),i.update(Wa(64).digest()),r=2**e*2-1,a&&a.debug("Calculate Initial Hash: tauG1"),c(o,r),r=2**e,a&&a.debug("Calculate Initial Hash: tauG2"),c(n,r),a&&a.debug("Calculate Initial Hash: alphaTauG1"),c(o,r),a&&a.debug("Calculate Initial Hash: betaTauG1"),c(o,r),i.update(n),i.digest();function c(t,e){const o=5e5,n=Math.floor(e/o),r=e%o,c=new Uint8Array(o*t.byteLength);for(let e=0;e<o;e++)c.set(t,e*t.byteLength);for(let t=0;t<n;t++)i.update(c),a&&a.debug("Initial hash: "+t*o);for(let e=0;e<r;e++)i.update(t)}}function $i(t,e,a,i){return Mi(t,e,ci(a,i))}const Zi=ni;async function Yi(t,e,a,i){let o;if(1==e.type){const o=$i(t,a.nextChallenge,e.beaconHash,e.numIterationsExp);if(!t.G1.eq(e.key.tau.g1_s,o.tau.g1_s))return i&&i.error(`BEACON key (tauG1_s) is not generated correctly in challenge #${e.id} ${e.name||""}`),!1;if(!t.G1.eq(e.key.tau.g1_sx,o.tau.g1_sx))return i&&i.error(`BEACON key (tauG1_sx) is not generated correctly in challenge #${e.id} ${e.name||""}`),!1;if(!t.G2.eq(e.key.tau.g2_spx,o.tau.g2_spx))return i&&i.error(`BEACON key (tauG2_spx) is not generated correctly in challenge #${e.id} ${e.name||""}`),!1;if(!t.G1.eq(e.key.alpha.g1_s,o.alpha.g1_s))return i&&i.error(`BEACON key (alphaG1_s) is not generated correctly in challenge #${e.id} ${e.name||""}`),!1;if(!t.G1.eq(e.key.alpha.g1_sx,o.alpha.g1_sx))return i&&i.error(`BEACON key (alphaG1_sx) is not generated correctly in challenge #${e.id} ${e.name||""}`),!1;if(!t.G2.eq(e.key.alpha.g2_spx,o.alpha.g2_spx))return i&&i.error(`BEACON key (alphaG2_spx) is not generated correctly in challenge #${e.id} ${e.name||""}`),!1;if(!t.G1.eq(e.key.beta.g1_s,o.beta.g1_s))return i&&i.error(`BEACON key (betaG1_s) is not generated correctly in challenge #${e.id} ${e.name||""}`),!1;if(!t.G1.eq(e.key.beta.g1_sx,o.beta.g1_sx))return i&&i.error(`BEACON key (betaG1_sx) is not generated correctly in challenge #${e.id} ${e.name||""}`),!1;if(!t.G2.eq(e.key.beta.g2_spx,o.beta.g2_spx))return i&&i.error(`BEACON key (betaG2_spx) is not generated correctly in challenge #${e.id} ${e.name||""}`),!1}return e.key.tau.g2_sp=t.G2.toAffine(qi(t,0,a.nextChallenge,e.key.tau.g1_s,e.key.tau.g1_sx)),e.key.alpha.g2_sp=t.G2.toAffine(qi(t,1,a.nextChallenge,e.key.alpha.g1_s,e.key.alpha.g1_sx)),e.key.beta.g2_sp=t.G2.toAffine(qi(t,2,a.nextChallenge,e.key.beta.g1_s,e.key.beta.g1_sx)),o=await Zi(t,e.key.tau.g1_s,e.key.tau.g1_sx,e.key.tau.g2_sp,e.key.tau.g2_spx),!0!==o?(i&&i.error("INVALID key (tau) in challenge #"+e.id),!1):(o=await Zi(t,e.key.alpha.g1_s,e.key.alpha.g1_sx,e.key.alpha.g2_sp,e.key.alpha.g2_spx),!0!==o?(i&&i.error("INVALID key (alpha) in challenge #"+e.id),!1):(o=await Zi(t,e.key.beta.g1_s,e.key.beta.g1_sx,e.key.beta.g2_sp,e.key.beta.g2_spx),!0!==o?(i&&i.error("INVALID key (beta) in challenge #"+e.id),!1):(o=await Zi(t,a.tauG1,e.tauG1,e.key.tau.g2_sp,e.key.tau.g2_spx),!0!==o?(i&&i.error("INVALID tau*G1. challenge #"+e.id+" It does not follow the previous contribution"),!1):(o=await Zi(t,e.key.tau.g1_s,e.key.tau.g1_sx,a.tauG2,e.tauG2),!0!==o?(i&&i.error("INVALID tau*G2. challenge #"+e.id+" It does not follow the previous contribution"),!1):(o=await Zi(t,a.alphaG1,e.alphaG1,e.key.alpha.g2_sp,e.key.alpha.g2_spx),!0!==o?(i&&i.error("INVALID alpha*G1. challenge #"+e.id+" It does not follow the previous contribution"),!1):(o=await Zi(t,a.betaG1,e.betaG1,e.key.beta.g2_sp,e.key.beta.g2_spx),!0!==o?(i&&i.error("INVALID beta*G1. challenge #"+e.id+" It does not follow the previous contribution"),!1):(o=await Zi(t,e.key.beta.g1_s,e.key.beta.g1_sx,a.betaG2,e.betaG2),!0!==o?(i&&i.error("INVALID beta*G2. challenge #"+e.id+"It does not follow the previous contribution"),!1):(i&&i.info("Powers Of tau file OK!"),!0))))))))}async function Ji(t,e,a,i,o,n,r,c,l,s){const d=o[n],u=2*d.F.n8,g=e[i][0].size/u;await pa(t,e,i),await fa(a,i);let f=r;for(let e=0;e<g;e+=65536){s&&s.debug(`Applying key: ${l}: ${e}/${g}`);const i=Math.min(g-e,65536);let n;n=await t.read(i*u),n=await d.batchApplyKey(n,f,c),await a.write(n),f=o.Fr.mul(f,o.Fr.exp(c,i))}await _a(a),await ha(t)}async function Wi(t,e,a,i,o,n,r,c,l,s,d){const u=i[o],g=2*u.F.n8,f=Math.floor((1<<20)/g);let _=r;for(let o=0;o<n;o+=f){d&&d.debug(`Applying key ${s}: ${o}/${n}`);const r=Math.min(n-o,f),p=await t.read(r*g),h=await u.batchUtoLEM(p),m=await u.batchApplyKey(h,_,c);let L;L="COMPRESSED"==l?await u.batchLEMtoC(m):await u.batchLEMtoU(m),a&&a.update(L),await e.write(L),_=i.Fr.mul(_,i.Fr.exp(c,r))}}var Xi=Object.freeze({__proto__:null,newAccumulator:async function(t,e,a,i){await Wa.ready();const o=await ga(a,"ptau",1,7);await ki(o,t,e,0);const n=t.G1.oneAffine,r=t.G2.oneAffine;await fa(o,2);const c=2**e*2-1;for(let t=0;t<c;t++)await o.write(n),i&&t%1e5==0&&t&&i.log("tauG1: "+t);await _a(o),await fa(o,3);const l=2**e;for(let t=0;t<l;t++)await o.write(r),i&&t%1e5==0&&t&&i.log("tauG2: "+t);await _a(o),await fa(o,4);const s=2**e;for(let t=0;t<s;t++)await o.write(n),i&&t%1e5==0&&t&&i.log("alphaTauG1: "+t);await _a(o),await fa(o,5);const d=2**e;for(let t=0;t<d;t++)await o.write(n),i&&t%1e5==0&&t&&i.log("betaTauG1: "+t);await _a(o),await fa(o,6),await o.write(r),await _a(o),await fa(o,7),await o.writeULE32(0),await _a(o),await o.close();const u=Hi(t,e,i);return i&&i.debug(ai(Wa(64).digest(),"Blank Contribution Hash:")),i&&i.info(ai(u,"First Contribution Hash:")),u},exportChallenge:async function(t,e,a){await Wa.ready();const{fd:i,sections:o}=await ua(t,"ptau",1),{curve:n,power:r}=await Ri(i,o),c=await Ki(i,n,o);let l,s;0==c.length?(l=Wa(64).digest(),s=Hi(n,r)):(l=c[c.length-1].responseHash,s=c[c.length-1].nextChallenge),a&&a.info(ai(l,"Last Response Hash: ")),a&&a.info(ai(s,"New Challenge Hash: "));const d=await sa(e),u=Wa(64);await d.write(l),u.update(l),await f(2,"G1",2**r*2-1,"tauG1"),await f(3,"G2",2**r,"tauG2"),await f(4,"G1",2**r,"alphaTauG1"),await f(5,"G1",2**r,"betaTauG1"),await f(6,"G2",1,"betaG2"),await i.close(),await d.close();const g=u.digest();if(!ii(s,g))throw a&&a.info(ai(g,"Calc Curret Challenge Hash: ")),a&&a.error("PTau file is corrupted. Calculated new challenge hash does not match with the eclared one"),new Error("PTau file is corrupted. Calculated new challenge hash does not match with the eclared one");return s;async function f(t,e,r,c){const l=n[e],s=2*l.F.n8,g=Math.floor((1<<24)/s);await pa(i,o,t);for(let t=0;t<r;t+=g){a&&a.debug(`Exporting ${c}: ${t}/${r}`);const e=Math.min(r-t,g);let o;o=await i.read(e*s),o=await l.batchLEMtoU(o),await d.write(o),u.update(o)}await ha(i)}},importResponse:async function(t,e,a,i,o,n){await Wa.ready();const r=new Uint8Array(64);for(let t=0;t<64;t++)r[t]=255;const{fd:c,sections:l}=await ua(t,"ptau",1),{curve:s,power:d}=await Ri(c,l),u=await Ki(c,s,l),g={};i&&(g.name=i);const f=2*s.F1.n8,_=s.F1.n8,p=2*s.F2.n8,h=s.F2.n8,m=await da(e);if(m.totalSize!=64+(2**d*2-1)*_+2**d*h+2**d*_+2**d*_+h+6*f+3*p)throw new Error("Size of the contribution is invalid");let L;L=u.length>0?u[u.length-1].nextChallenge:Hi(s,d,n);const w=await ga(a,"ptau",1,o?7:2);await ki(w,s,d);const A=await m.read(64);if(ii(r,L)&&(L=A,u[u.length-1].nextChallenge=L),!ii(A,L))throw new Error("Wrong contribution. this contribution is not based on the previus hash");const b=new Wa(64);b.update(A);const y=[];let I;I=await x(m,w,"G1",2,2**d*2-1,[1],"tauG1"),g.tauG1=I[0],I=await x(m,w,"G2",3,2**d,[1],"tauG2"),g.tauG2=I[0],I=await x(m,w,"G1",4,2**d,[0],"alphaG1"),g.alphaG1=I[0],I=await x(m,w,"G1",5,2**d,[0],"betaG1"),g.betaG1=I[0],I=await x(m,w,"G2",6,1,[0],"betaG2"),g.betaG2=I[0],g.partialHash=b.getPartialHash();const C=await m.read(2*s.F1.n8*6+2*s.F2.n8*3);g.key=Ni(C,0,s,!1),b.update(new Uint8Array(C));const F=b.digest();if(n&&n.info(ai(F,"Contribution Response Hash imported: ")),o){const t=new Wa(64);t.update(F),await v(t,w,"G1",2,2**d*2-1,"tauG1",n),await v(t,w,"G2",3,2**d,"tauG2",n),await v(t,w,"G1",4,2**d,"alphaTauG1",n),await v(t,w,"G1",5,2**d,"betaTauG1",n),await v(t,w,"G2",6,1,"betaG2",n),g.nextChallenge=t.digest(),n&&n.info(ai(g.nextChallenge,"Next Challenge Hash: "))}else g.nextChallenge=r;return u.push(g),await ji(w,s,u),await m.close(),await w.close(),await c.close(),g.nextChallenge;async function x(t,e,a,i,r,c,l){return o?await async function(t,e,a,i,o,r,c){const l=s[a],d=l.F.n8,u=2*l.F.n8,g=[];await fa(e,i);const f=Math.floor((1<<24)/u);y[i]=e.pos;for(let a=0;a<o;a+=f){n&&n.debug(`Importing ${c}: ${a}/${o}`);const i=Math.min(o-a,f),s=await t.read(i*d);b.update(s);const _=await l.batchCtoLEM(s);await e.write(_);for(let t=0;t<r.length;t++){const e=r[t];if(e>=a&&e<a+i){const t=l.fromRprLEM(_,(e-a)*u);g.push(t)}}}return await _a(e),g}(t,e,a,i,r,c,l):await async function(t,e,a,i,o,r,c){const l=s[a],d=l.F.n8,u=[],g=Math.floor((1<<24)/d);for(let e=0;e<o;e+=g){n&&n.debug(`Importing ${c}: ${e}/${o}`);const a=Math.min(o-e,g),i=await t.read(a*d);b.update(i);for(let t=0;t<r.length;t++){const o=r[t];if(o>=e&&o<e+a){const t=l.fromRprCompressed(i,(o-e)*d);u.push(t)}}}return u}(t,0,a,0,r,c,l)}async function v(t,e,a,i,o,n,r){const c=s[a],l=2*c.F.n8,d=Math.floor((1<<24)/l),u=e.pos;e.pos=y[i];for(let a=0;a<o;a+=d){r&&r.debug(`Hashing ${n}: ${a}/${o}`);const i=Math.min(o-a,d),s=await e.read(i*l),u=await c.batchLEMtoU(s);t.update(u)}e.pos=u}},verify:async function(t,e){let a;await Wa.ready();const{fd:i,sections:o}=await ua(t,"ptau",1),{curve:n,power:r,ceremonyPower:c}=await Ri(i,o),l=await Ki(i,n,o);e&&e.debug("power: 2**"+r),e&&e.debug("Computing initial contribution hash");const s={tauG1:n.G1.g,tauG2:n.G2.g,alphaG1:n.G1.g,betaG1:n.G1.g,betaG2:n.G2.g,nextChallenge:Hi(n,c,e),responseHash:Wa(64).digest()};if(0==l.length)return e&&e.error("This file has no contribution! It cannot be used in production"),!1;let d;d=l.length>1?l[l.length-2]:s;const u=l[l.length-1];if(e&&e.debug("Validating contribution #"+l[l.length-1].id),!await Yi(n,u,d,e))return!1;const g=Wa(64);g.update(u.responseHash),e&&e.debug("Verifying powers in tau*G1 section");const f=await A(2,"G1","tauG1",2**r*2-1,[0,1],e);if(a=await Zi(n,f.R1,f.R2,n.G2.g,u.tauG2),!0!==a)return e&&e.error("tauG1 section. Powers do not match"),!1;if(!n.G1.eq(n.G1.g,f.singularPoints[0]))return e&&e.error("First element of tau*G1 section must be the generator"),!1;if(!n.G1.eq(u.tauG1,f.singularPoints[1]))return e&&e.error("Second element of tau*G1 section does not match the one in the contribution section"),!1;e&&e.debug("Verifying powers in tau*G2 section");const _=await A(3,"G2","tauG2",2**r,[0,1],e);if(a=await Zi(n,n.G1.g,u.tauG1,_.R1,_.R2),!0!==a)return e&&e.error("tauG2 section. Powers do not match"),!1;if(!n.G2.eq(n.G2.g,_.singularPoints[0]))return e&&e.error("First element of tau*G2 section must be the generator"),!1;if(!n.G2.eq(u.tauG2,_.singularPoints[1]))return e&&e.error("Second element of tau*G2 section does not match the one in the contribution section"),!1;e&&e.debug("Verifying powers in alpha*tau*G1 section");const p=await A(4,"G1","alphatauG1",2**r,[0],e);if(a=await Zi(n,p.R1,p.R2,n.G2.g,u.tauG2),!0!==a)return e&&e.error("alphaTauG1 section. Powers do not match"),!1;if(!n.G1.eq(u.alphaG1,p.singularPoints[0]))return e&&e.error("First element of alpha*tau*G1 section (alpha*G1) does not match the one in the contribution section"),!1;e&&e.debug("Verifying powers in beta*tau*G1 section");const h=await A(5,"G1","betatauG1",2**r,[0],e);if(a=await Zi(n,h.R1,h.R2,n.G2.g,u.tauG2),!0!==a)return e&&e.error("betaTauG1 section. Powers do not match"),!1;if(!n.G1.eq(u.betaG1,h.singularPoints[0]))return e&&e.error("First element of beta*tau*G1 section (beta*G1) does not match the one in the contribution section"),!1;const m=await async function(t){const e=n.G2,a=2*e.F.n8,r=new Uint8Array(a);if(!o[6])throw t.error("File has no BetaG2 section"),new Error("File has no BetaG2 section");if(o[6].length>1)throw t.error("File has no BetaG2 section"),new Error("File has more than one GetaG2 section");i.pos=o[6][0].p;const c=await i.read(a),l=e.fromRprLEM(c);return e.toRprUncompressed(r,0,l),g.update(r),l}(e);if(!n.G2.eq(u.betaG2,m))return e&&e.error("betaG2 element in betaG2 section does not match the one in the contribution section"),!1;const L=g.digest();if(r==c&&!ii(L,u.nextChallenge))return e&&e.error("Hash of the values does not match the next challenge of the last contributor in the contributions section"),!1;e&&e.info(ai(L,"Next challenge hash: ")),w(u,d);for(let t=l.length-2;t>=0;t--){const a=l[t],i=t>0?l[t-1]:s;if(!await Yi(n,a,i,e))return!1;w(a,i)}if(e&&e.info("-----------------------------------------------------"),o[12]&&o[13]&&o[14]&&o[15]){let t;if(t=await b("G1",2,12,"tauG1",e),!t)return!1;if(t=await b("G2",3,13,"tauG2",e),!t)return!1;if(t=await b("G1",4,14,"alphaTauG1",e),!t)return!1;if(t=await b("G1",5,15,"betaTauG1",e),!t)return!1}else e&&e.warn('this file does not contain phase2 precalculated values. Please run: \n snarkjs "powersoftau preparephase2" to prepare this file to be used in the phase2 ceremony.');return await i.close(),e&&e.info("Powers of Tau Ok!"),!0;function w(t,a){if(!e)return;e.info("-----------------------------------------------------"),e.info(`Contribution #${t.id}: ${t.name||""}`),e.info(ai(t.nextChallenge,"Next Challenge: "));const i=new Uint8Array(2*n.G1.F.n8*6+2*n.G2.F.n8*3);Ti(i,0,n,t.key,!1);const o=Wa(64);o.setPartialHash(t.partialHash),o.update(i);const r=o.digest();e.info(ai(r,"Response Hash:")),e.info(ai(a.nextChallenge,"Response Hash:")),1==t.type&&(e.info(`Beacon generator: ${si(t.beaconHash)}`),e.info(`Beacon iterations Exp: ${t.numIterationsExp}`))}async function A(t,e,a,r,c,l){const s=n[e],d=2*s.F.n8;await pa(i,o,t);const u=[];let f=s.zero,_=s.zero,p=s.zero;for(let t=0;t<r;t+=65536){l&&l.debug(`points relations: ${a}: ${t}/${r} `);const e=Math.min(r-t,65536),o=await i.read(e*d),n=await s.batchLEMtoU(o);g.update(n);const h=new Uint8Array(4*(e-1));if(wt.randomFillSync(h),t>0){const t=s.fromRprLEM(o,0),e=wt.randomBytes(4).readUInt32BE(0,!0);f=s.add(f,s.timesScalar(p,e)),_=s.add(_,s.timesScalar(t,e))}const m=await s.multiExpAffine(o.slice(0,(e-1)*d),h),L=await s.multiExpAffine(o.slice(d),h);f=s.add(f,m),_=s.add(_,L),p=s.fromRprLEM(o,(e-1)*d);for(let a=0;a<c.length;a++){const i=c[a];if(i>=t&&i<t+e){const e=s.fromRprLEM(o,(i-t)*d);u.push(e)}}}return await ha(i),{R1:f,R2:_,singularPoints:u}}async function b(t,e,a,c,l){l&&l.debug(`Verifying phase2 calculated values ${c}...`);const s=n[t],d=2*s.F.n8,u=new Array(8);for(let t=0;t<8;t++)u[t]=wt.randomBytes(4).readUInt32BE(0,!0);for(let t=0;t<=r;t++){if(!await g(t))return!1}if(2==e){if(!await g(r+1))return!1}return!0;async function g(t){l&&l.debug(`Power ${t}...`);const g=n.Fr.n8,f=2**t;let _,p=new Uint32Array(f),h=new Lt(u);l&&l.debug(`Creating random numbers Powers${t}...`);for(let e=0;e<f;e++)p[e]=t==r+1&&e==f-1?0:h.nextU32();p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength),l&&l.debug(`reading points Powers${t}...`),await pa(i,o,e),_=new fe(f*d),t==r+1?(await i.readToBuffer(_,0,(f-1)*d),_.set(n.G1.zeroAffine,(f-1)*d)):await i.readToBuffer(_,0,f*d),await ha(i,!0);const m=await s.multiExpAffine(_,p,l,c+"_"+t);p=new fe(f*g),h=new Lt(u);const L=new Uint8Array(4),w=new DataView(L.buffer);l&&l.debug(`Creating random numbers Powers${t}...`);for(let e=0;e<f;e++)e==f-1&&t==r+1||(w.setUint32(0,h.nextU32(),!0),p.set(L,e*g));l&&l.debug(`batchToMontgomery ${t}...`),p=await n.Fr.batchToMontgomery(p),l&&l.debug(`fft ${t}...`),p=await n.Fr.fft(p),l&&l.debug(`batchFromMontgomery ${t}...`),p=await n.Fr.batchFromMontgomery(p),l&&l.debug(`reading points Lagrange${t}...`),await pa(i,o,a),i.pos+=d*(2**t-1),await i.readToBuffer(_,0,f*d),await ha(i,!0);const A=await s.multiExpAffine(_,p,l,c+"_"+t+"_transformed");return!!s.eq(m,A)||(l&&l.error("Phase2 caclutation does not match with powers of tau"),!1)}}},challengeContribute:async function(t,e,a,i,o){await Wa.ready();const n=await da(e),r=8*t.F1.n64*2,c=8*t.F2.n64*2,l=(n.totalSize+r-64-c)/(4*r+c);let s=l,d=0;for(;s>1;)s/=2,d+=1;if(2**d!=l)throw new Error("Invalid file size");o&&o.debug("Power to tau size: "+d);const u=await ri(i),g=await sa(a),f=Wa(64);for(let t=0;t<n.totalSize;t+=n.pageSize){o&&o.debug(`Hashing challenge ${t}/${n.totalSize}`);const e=Math.min(n.totalSize-t,n.pageSize),a=await n.read(e);f.update(a)}const _=await n.read(64,0);o&&o.info(ai(_,"Claimed Previous Response Hash: "));const p=f.digest();o&&o.info(ai(p,"Current Challenge Hash: "));const h=Mi(t,p,u);o&&["tau","alpha","beta"].forEach((e=>{o.debug(e+".g1_s: "+t.G1.toString(h[e].g1_s,16)),o.debug(e+".g1_sx: "+t.G1.toString(h[e].g1_sx,16)),o.debug(e+".g2_sp: "+t.G2.toString(h[e].g2_sp,16)),o.debug(e+".g2_spx: "+t.G2.toString(h[e].g2_spx,16)),o.debug("")}));const m=Wa(64);await g.write(p),m.update(p),await Wi(n,g,m,t,"G1",2**d*2-1,t.Fr.one,h.tau.prvKey,"COMPRESSED","tauG1",o),await Wi(n,g,m,t,"G2",2**d,t.Fr.one,h.tau.prvKey,"COMPRESSED","tauG2",o),await Wi(n,g,m,t,"G1",2**d,h.alpha.prvKey,h.tau.prvKey,"COMPRESSED","alphaTauG1",o),await Wi(n,g,m,t,"G1",2**d,h.beta.prvKey,h.tau.prvKey,"COMPRESSED","betaTauG1",o),await Wi(n,g,m,t,"G2",1,h.beta.prvKey,h.tau.prvKey,"COMPRESSED","betaTauG2",o);const L=new Uint8Array(2*t.F1.n8*6+2*t.F2.n8*3);Ti(L,0,t,h,!1),await g.write(L),m.update(L);const w=m.digest();o&&o.info(ai(w,"Contribution Response Hash: ")),await g.close(),await n.close()},beacon:async function(t,e,a,i,o,n){const r=li(i);if(0==r.byteLength||2*r.byteLength!=i.length)return n&&n.error("Invalid Beacon Hash. (It must be a valid hexadecimal sequence)"),!1;if(r.length>=256)return n&&n.error("Maximum lenght of beacon hash is 255 bytes"),!1;if((o=parseInt(o))<10||o>63)return n&&n.error("Invalid numIterationsExp. (Must be between 10 and 63)"),!1;await Wa.ready();const{fd:c,sections:l}=await ua(t,"ptau",1),{curve:s,power:d,ceremonyPower:u}=await Ri(c,l);if(d!=u)return n&&n.error("This file has been reduced. You cannot contribute into a reduced file."),!1;l[12]&&n&&n.warn("Contributing into a file that has phase2 calculated. You will have to prepare phase2 again.");const g=await Ki(c,s,l),f={name:a,type:1,numIterationsExp:o,beaconHash:r};let _;_=g.length>0?g[g.length-1].nextChallenge:Hi(s,d,n),f.key=$i(s,_,r,o);const p=new Wa(64);p.update(_);const h=await ga(e,"ptau",1,7);await ki(h,s,d);const m=[];let L;L=await y(2,"G1",2**d*2-1,s.Fr.e(1),f.key.tau.prvKey,"tauG1",n),f.tauG1=L[1],L=await y(3,"G2",2**d,s.Fr.e(1),f.key.tau.prvKey,"tauG2",n),f.tauG2=L[1],L=await y(4,"G1",2**d,f.key.alpha.prvKey,f.key.tau.prvKey,"alphaTauG1",n),f.alphaG1=L[0],L=await y(5,"G1",2**d,f.key.beta.prvKey,f.key.tau.prvKey,"betaTauG1",n),f.betaG1=L[0],L=await y(6,"G2",1,f.key.beta.prvKey,f.key.tau.prvKey,"betaTauG2",n),f.betaG2=L[0],f.partialHash=p.getPartialHash();const w=new Uint8Array(2*s.F1.n8*6+2*s.F2.n8*3);Ti(w,0,s,f.key,!1),p.update(new Uint8Array(w));const A=p.digest();n&&n.info(ai(A,"Contribution Response Hash imported: "));const b=new Wa(64);return b.update(A),await I(h,"G1",2,2**d*2-1,"tauG1",n),await I(h,"G2",3,2**d,"tauG2",n),await I(h,"G1",4,2**d,"alphaTauG1",n),await I(h,"G1",5,2**d,"betaTauG1",n),await I(h,"G2",6,1,"betaG2",n),f.nextChallenge=b.digest(),n&&n.info(ai(f.nextChallenge,"Next Challenge Hash: ")),g.push(f),await ji(h,s,g),await c.close(),await h.close(),A;async function y(t,e,a,i,o,n,r){const d=[];c.pos=l[t][0].p,await fa(h,t),m[t]=h.pos;const u=s[e],g=2*u.F.n8,f=Math.floor((1<<20)/g);let _=i;for(let t=0;t<a;t+=f){r&&r.debug(`applying key${n}: ${t}/${a}`);const e=Math.min(a-t,f),i=await c.read(e*g),l=await u.batchApplyKey(i,_,o),m=h.write(l),L=await u.batchLEMtoC(l);if(p.update(L),await m,0==t)for(let t=0;t<Math.min(2,a);t++)d.push(u.fromRprLEM(l,t*g));_=s.Fr.mul(_,s.Fr.exp(o,e))}return await _a(h),d}async function I(t,e,a,i,o,n){const r=s[e],c=2*r.F.n8,l=Math.floor((1<<24)/c),d=t.pos;t.pos=m[a];for(let e=0;e<i;e+=l){n&&n.debug(`Hashing ${o}: ${e}/${i}`);const a=Math.min(i-e,l),s=await t.read(a*c),d=await r.batchLEMtoU(s);b.update(d)}t.pos=d}},contribute:async function(t,e,a,i,o){await Wa.ready();const{fd:n,sections:r}=await ua(t,"ptau",1),{curve:c,power:l,ceremonyPower:s}=await Ri(n,r);if(l!=s)throw o&&o.error("This file has been reduced. You cannot contribute into a reduced file."),new Error("This file has been reduced. You cannot contribute into a reduced file.");r[12]&&o&&o.warn("WARNING: Contributing into a file that has phase2 calculated. You will have to prepare phase2 again.");const d=await Ki(n,c,r),u={name:a,type:0};let g;const f=await ri(i);g=d.length>0?d[d.length-1].nextChallenge:Hi(c,l,o),u.key=Mi(c,g,f);const _=new Wa(64);_.update(g);const p=await ga(e,"ptau",1,7);await ki(p,c,l);const h=[];let m;m=await b(2,"G1",2**l*2-1,c.Fr.e(1),u.key.tau.prvKey,"tauG1"),u.tauG1=m[1],m=await b(3,"G2",2**l,c.Fr.e(1),u.key.tau.prvKey,"tauG2"),u.tauG2=m[1],m=await b(4,"G1",2**l,u.key.alpha.prvKey,u.key.tau.prvKey,"alphaTauG1"),u.alphaG1=m[0],m=await b(5,"G1",2**l,u.key.beta.prvKey,u.key.tau.prvKey,"betaTauG1"),u.betaG1=m[0],m=await b(6,"G2",1,u.key.beta.prvKey,u.key.tau.prvKey,"betaTauG2"),u.betaG2=m[0],u.partialHash=_.getPartialHash();const L=new Uint8Array(2*c.F1.n8*6+2*c.F2.n8*3);Ti(L,0,c,u.key,!1),_.update(new Uint8Array(L));const w=_.digest();o&&o.info(ai(w,"Contribution Response Hash imported: "));const A=new Wa(64);return A.update(w),await y(p,"G1",2,2**l*2-1,"tauG1"),await y(p,"G2",3,2**l,"tauG2"),await y(p,"G1",4,2**l,"alphaTauG1"),await y(p,"G1",5,2**l,"betaTauG1"),await y(p,"G2",6,1,"betaG2"),u.nextChallenge=A.digest(),o&&o.info(ai(u.nextChallenge,"Next Challenge Hash: ")),d.push(u),await ji(p,c,d),await n.close(),await p.close(),w;async function b(t,e,a,i,l,s){const d=[];n.pos=r[t][0].p,await fa(p,t),h[t]=p.pos;const u=c[e],g=2*u.F.n8,f=Math.floor((1<<20)/g);let m=i;for(let t=0;t<a;t+=f){o&&o.debug(`processing: ${s}: ${t}/${a}`);const e=Math.min(a-t,f),i=await n.read(e*g),r=await u.batchApplyKey(i,m,l),h=p.write(r),L=await u.batchLEMtoC(r);if(_.update(L),await h,0==t)for(let t=0;t<Math.min(2,a);t++)d.push(u.fromRprLEM(r,t*g));m=c.Fr.mul(m,c.Fr.exp(l,e))}return await _a(p),d}async function y(t,e,a,i,n){const r=c[e],l=2*r.F.n8,s=Math.floor((1<<24)/l),d=t.pos;t.pos=h[a];for(let e=0;e<i;e+=s){o&&e&&o.debug(`Hashing ${n}: `+e);const a=Math.min(i-e,s),c=await t.read(a*l),d=await r.batchLEMtoU(c);A.update(d)}t.pos=d}},preparePhase2:async function(t,e,a){const{fd:i,sections:o}=await ua(t,"ptau",1),{curve:n,power:r}=await Ri(i,o),c=await ga(e,"ptau",1,11);return await ki(c,n,r),await wa(i,o,c,2),await wa(i,o,c,3),await wa(i,o,c,4),await wa(i,o,c,5),await wa(i,o,c,6),await wa(i,o,c,7),await l(2,12,"G1","tauG1"),await l(3,13,"G2","tauG2"),await l(4,14,"G1","alphaTauG1"),await l(5,15,"G1","betaTauG1"),await i.close(),void await c.close();async function l(t,e,l,s){a&&a.debug("Starting section: "+s),await fa(c,e);for(let t=0;t<=r;t++)await d(t);async function d(e){const d=2**e,u=n[l];n.Fr;const g=2*u.F.n8;let f;u.F.n8,f=new fe(d*g),await pa(i,o,t),2==t&&e==r+1?(await i.readToBuffer(f,0,(d-1)*g),f.set(n.G1.zeroAffine,(d-1)*g)):await i.readToBuffer(f,0,d*g),await ha(i,!0),f=await u.lagrangeEvaluations(f,"affine","affine",a,s),await c.write(f)}2==t&&await d(r+1),await _a(c)}},truncate:async function(t,e,a){const{fd:i,sections:o}=await ua(t,"ptau",1),{curve:n,power:r,ceremonyPower:c}=await Ri(i,o),l=2*n.G1.F.n8,s=2*n.G2.F.n8;for(let t=1;t<r;t++)await d(t);return await i.close(),!0;async function d(t){let r=t.toString();for(;r.length<2;)r="0"+r;a&&a.debug("Writing Power: "+r);const d=await ga(e+r+".ptau","ptau",1,11);await ki(d,n,t,c),await wa(i,o,d,2,(2**t*2-1)*l),await wa(i,o,d,3,2**t*s),await wa(i,o,d,4,2**t*l),await wa(i,o,d,5,2**t*l),await wa(i,o,d,6,s),await wa(i,o,d,7),await wa(i,o,d,12,(2**(t+1)*2-1)*l),await wa(i,o,d,13,(2**t*2-1)*s),await wa(i,o,d,14,(2**t*2-1)*l),await wa(i,o,d,15,(2**t*2-1)*l),await d.close()}},convert:async function(t,e,a){const{fd:i,sections:o}=await ua(t,"ptau",1),{curve:n,power:r}=await Ri(i,o),c=await ga(e,"ptau",1,11);return await ki(c,n,r),await wa(i,o,c,2),await wa(i,o,c,3),await wa(i,o,c,4),await wa(i,o,c,5),await wa(i,o,c,6),await wa(i,o,c,7),await async function(t,e,l,s){a&&a.debug("Starting section: "+s);await fa(c,e);const d=o[e][0].size,u=i.pageSize;await pa(i,o,e);for(let t=0;t<d;t+=u){const e=Math.min(d-t,u),a=await i.read(e);await c.write(a)}await ha(i),2==t&&await async function(e){const d=2**e,u=n[l],g=2*u.F.n8;let f;f=new fe(d*g),await pa(i,o,t),2==t&&e==r+1?(await i.readToBuffer(f,0,(d-1)*g),f.set(n.G1.zeroAffine,(d-1)*g)):await i.readToBuffer(f,0,d*g);await ha(i,!0),f=await u.lagrangeEvaluations(f,"affine","affine",a,s),await c.write(f)}(r+1);await _a(c)}(2,12,"G1","tauG1"),await wa(i,o,c,13),await wa(i,o,c,14),await wa(i,o,c,15),await i.close(),void await c.close()},exportJson:async function(t,e){const{fd:a,sections:i}=await ua(t,"ptau",1),{curve:o,power:n}=await Ri(a,i),r={};return r.q=o.q,r.power=n,r.contributions=await Ki(a,o,i),r.tauG1=await c(2,"G1",2**n*2-1,"tauG1"),r.tauG2=await c(3,"G2",2**n,"tauG2"),r.alphaTauG1=await c(4,"G1",2**n,"alphaTauG1"),r.betaTauG1=await c(5,"G1",2**n,"betaTauG1"),r.betaG2=await c(6,"G2",1,"betaG2"),r.lTauG1=await l(12,"G1","lTauG1"),r.lTauG2=await l(13,"G2","lTauG2"),r.lAlphaTauG1=await l(14,"G1","lAlphaTauG2"),r.lBetaTauG1=await l(15,"G1","lBetaTauG2"),await a.close(),r;async function c(t,n,r,c){const l=o[n],s=2*l.F.n8,d=[];await pa(a,i,t);for(let t=0;t<r;t++){e&&t&&t%1e4==0&&console.log(`${c}: `+t);const i=await a.read(s);d.push(l.fromRprLEM(i,0))}return await ha(a),d}async function l(t,r,c){const l=o[r],s=2*l.F.n8,d=[];await pa(a,i,t);for(let t=0;t<=n;t++){e&&console.log(`${c}: Power: ${t}`),d[t]=[];const i=2**t;for(let o=0;o<i;o++){e&&o&&o%1e4==0&&console.log(`${c}: ${o}/${i}`);const n=await a.read(s);d[t].push(l.fromRprLEM(n,0))}}return await ha(a),d}}});const to=262144,eo={get:function(t,e){return isNaN(e)?t[e]:t.getElement(e)},set:function(t,e,a){return isNaN(e)?(t[e]=a,!0):t.setElement(e,a)}};class ao{constructor(t){this.length=t||0,this.arr=new Array(to);for(let e=0;e<t;e+=to)this.arr[e/to]=new Array(Math.min(to,t-e));return this}push(){for(let t=0;t<arguments.length;t++)this.setElement(this.length,arguments[t])}slice(t,e){const a=new Array(e-t);for(let i=t;i<e;i++)a[i-t]=this.getElement(i);return a}getElement(t){t=parseInt(t);const e=Math.floor(t/to),a=t%to;return this.arr[e]?this.arr[e][a]:void 0}setElement(t,e){t=parseInt(t);const a=Math.floor(t/to);this.arr[a]||(this.arr[a]=new Array(to));const i=t%to;return this.arr[a][i]=e,t>=this.length&&(this.length=t+1),!0}getKeys(){const t=new io;for(let e=0;e<this.arr.length;e++)if(this.arr[e])for(let a=0;a<this.arr[e].length;a++)void 0!==this.arr[e][a]&&t.push(e*to+a);return t}}class io{constructor(t){const e=new ao(t);return new Proxy(e,eo)}}async function oo(t,e,a){const i={};return await pa(t,e,1),i.n8=await t.readULE32(),i.prime=await La(t,i.n8),i.curve=await async function(t,e,a){let i;if(tt(t,je))i=await De(e,a);else{if(!tt(t,Ve))throw new Error(`Curve not supported: ${F(t)}`);i=await Ke(e,a)}return i}(i.prime,a),i.nVars=await t.readULE32(),i.nOutputs=await t.readULE32(),i.nPubInputs=await t.readULE32(),i.nPrvInputs=await t.readULE32(),i.nLabels=await t.readULE64(),i.nConstraints=await t.readULE32(),await ha(t),i}async function no(t,e,a,i,o,n){const{fd:r,sections:c}=await ua(t,"r1cs",1),l=await oo(r,c,i);return e&&(l.constraints=await async function(t,e,a,i,o){const n=await Aa(t,e,2);let r,c=0;r=a.nConstraints>1<<20?new io:[];for(let t=0;t<a.nConstraints;t++){i&&t%1e5==0&&i.info(`${o}: Loading constraints: ${t}/${a.nConstraints}`);const e=l();r.push(e)}return r;function l(){const t=[];return t[0]=s(),t[1]=s(),t[2]=s(),t}function s(){const t={},e=n.slice(c,c+4);c+=4;const i=new DataView(e.buffer).getUint32(0,!0),o=n.slice(c,c+(4+a.n8)*i);c+=(4+a.n8)*i;const r=new DataView(o.buffer);for(let e=0;e<i;e++){const i=r.getUint32(e*(4+a.n8),!0),n=a.curve.Fr.fromRprLE(o,e*(4+a.n8)+4);t[i]=n}return t}}(r,c,l,o,n)),a&&(l.map=await async function(t,e,a,i,o){const n=await Aa(t,e,3);let r,c=0;r=a.nVars>1<<20?new io:[];for(let t=0;t<a.nVars;t++){i&&t%1e4==0&&i.info(`${o}: Loading map: ${t}/${a.nVars}`);const e=l();r.push(e)}return r;function l(){const t=n.slice(c,c+8);c+=8;const e=new DataView(t.buffer),a=e.getUint32(0,!0);return 4294967296*e.getUint32(4,!0)+a}}(r,c,l,o,n)),await r.close(),l}const ro=He.e("73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001",16),co=He.e("21888242871839275222246405745257275088548364400416034343698204186575808495617");function lo(t,e){if(e instanceof Uint8Array)return t.toString(e);if(Array.isArray(e))return e.map(lo.bind(null,t));if("object"==typeof e){const a={};return Object.keys(e).forEach((i=>{a[i]=lo(t,e[i])})),a}return"bigint"==typeof e||void 0!==e.eq?e.toString(10):e}var so=Object.freeze({__proto__:null,print:function(t,e,a){for(let e=0;e<t.constraints.length;e++)i(t.constraints[e]);function i(i){const o=a=>{let i="";return Object.keys(a).forEach((o=>{let n=e.varIdx2Name[o];"one"==n&&(n="");let r=t.curve.Fr.toString(a[o]);"1"==r&&(r=""),"-1"==r&&(r="-"),""!=i&&"-"!=r[0]&&(r="+"+r),""!=i&&(r=" "+r),i=i+r+n})),i},n=`[ ${o(i[0])} ] * [ ${o(i[1])} ] - [ ${o(i[2])} ] = 0`;a&&a.info(n)}},info:async function(t,e){const a=await no(t);return He.eq(a.prime,co)?e&&e.info("Curve: bn-128"):He.eq(a.prime,ro)?e&&e.info("Curve: bls12-381"):e&&e.info(`Unknown Curve. Prime: ${He.toString(a.prime)}`),e&&e.info(`# of Wires: ${a.nVars}`),e&&e.info(`# of Constraints: ${a.nConstraints}`),e&&e.info(`# of Private Inputs: ${a.nPrvInputs}`),e&&e.info(`# of Public Inputs: ${a.nPubInputs}`),e&&e.info(`# of Labels: ${a.nLabels}`),e&&e.info(`# of Outputs: ${a.nOutputs}`),a},exportJson:async function(t,e){const a=await no(t,!0,!0,!0,e),i=a.curve.Fr;return delete a.curve,lo(i,a)}});async function uo(t){const e={labelIdx2Name:["one"],varIdx2Name:["one"],componentIdx2Name:[]},a=await da(t),i=await a.read(a.totalSize),o=new TextDecoder("utf-8").decode(i).split("\n");for(let t=0;t<o.length;t++){const a=o[t].split(",");4==a.length&&(e.varIdx2Name[a[1]]?e.varIdx2Name[a[1]]+="|"+a[3]:e.varIdx2Name[a[1]]=a[3],e.labelIdx2Name[a[0]]=a[3],e.componentIdx2Name[a[2]]||(e.componentIdx2Name[a[2]]=n(a[3])))}return await a.close(),e;function n(t){const e=t.split(".");return e.pop(),e.join(".")}}var go=Object.freeze({__proto__:null,calculate:Gi,debug:async function(t,e,a,i,o,n){const r=await da(e),c=await r.read(r.totalSize);await r.close();let l={sanityCheck:!0},s=await uo(i);o.set&&(s||(s=await uo(i)),l.logSetSignal=function(t,e){n&&n.info("SET "+s.labelIdx2Name[t]+" <-- "+e.toString())}),o.get&&(s||(s=await uo(i)),l.logGetSignal=function(t,e){n&&n.info("GET "+s.labelIdx2Name[t]+" --\x3e "+e.toString())}),o.trigger&&(s||(s=await uo(i)),l.logStartComponent=function(t){n&&n.info("START: "+s.componentIdx2Name[t])},l.logFinishComponent=function(t){n&&n.info("FINISH: "+s.componentIdx2Name[t])}),l.sym=s;const d=await Ei(c,l),u=await d.calculateWitness(t),g=await ga(a,"wtns",2,2);await async function(t,e,a){await fa(t,1);const i=8*(Math.floor((He.bitLength(a)-1)/64)+1);await t.writeULE32(i),await ma(t,a,i),await t.writeULE32(e.length),await _a(t),await fa(t,2);for(let a=0;a<e.length;a++)await ma(t,e[a],i);await _a(t)}(g,u,d.prime),await g.close()},exportJson:async function(t){return await async function(t){const{fd:e,sections:a}=await ua(t,"wtns",2),{n8:i,nWitness:o}=await yi(e,a);await pa(e,a,2);const n=[];for(let t=0;t<o;t++){const t=await La(e,i);n.push(t)}return await ha(e),await e.close(),n}(t)}});const fo=262144,_o={get:function(t,e){return isNaN(e)?t[e]:t.getElement(e)},set:function(t,e,a){return isNaN(e)?(t[e]=a,!0):t.setElement(e,a)}};class po{constructor(t){this.length=t||0,this.arr=new Array(fo);for(let e=0;e<t;e+=fo)this.arr[e/fo]=new Array(Math.min(fo,t-e));return this}push(){for(let t=0;t<arguments.length;t++)this.setElement(this.length,arguments[t])}slice(t,e){const a=new Array(e-t);for(let i=t;i<e;i++)a[i-t]=this.getElement(i);return a}getElement(t){t=parseInt(t);const e=Math.floor(t/fo),a=t%fo;return this.arr[e]?this.arr[e][a]:void 0}setElement(t,e){t=parseInt(t);const a=Math.floor(t/fo);this.arr[a]||(this.arr[a]=new Array(fo));const i=t%fo;return this.arr[a][i]=e,t>=this.length&&(this.length=t+1),!0}getKeys(){const t=new ho;for(let e=0;e<this.arr.length;e++)if(this.arr[e])for(let a=0;a<this.arr[e].length;a++)void 0!==this.arr[e][a]&&t.push(e*fo+a);return t}}class ho{constructor(t){const e=new po(t);return new Proxy(e,_o)}}async function mo(t,e,a,i){await Wa.ready();const o=Wa(64),{fd:n,sections:r}=await ua(e,"ptau",1),{curve:c,power:l}=await Ri(n,r),{fd:s,sections:d}=await ua(t,"r1cs",1),u=await oo(s,d,!1),g=await ga(a,"zkey",1,10,1<<22,1<<24),f=2*c.G1.F.n8,_=2*c.G2.F.n8;if(u.prime!=c.r)return i&&i.error("r1cs curve does not match powers of tau ceremony curve"),-1;const p=ei(u.nConstraints+u.nPubInputs+u.nOutputs+1-1)+1;if(p>l)return i&&i.error(`circuit too big for this power of tau ceremony. ${u.nConstraints}*2 > 2**${l}`),-1;if(!r[12])return i&&i.error("Powers of tau is not prepared."),-1;const h=u.nOutputs+u.nPubInputs,m=2**p;await fa(g,1),await g.writeULE32(1),await _a(g),await fa(g,2);const L=c.q,w=8*(Math.floor((He.bitLength(L)-1)/64)+1),A=c.r,b=8*(Math.floor((He.bitLength(A)-1)/64)+1),y=He.mod(He.shl(1,8*b),A),I=c.Fr.e(He.mod(He.mul(y,y),A));let C,F,x;await g.writeULE32(w),await ma(g,L,w),await g.writeULE32(b),await ma(g,A,b),await g.writeULE32(u.nVars),await g.writeULE32(h),await g.writeULE32(m),C=await n.read(f,r[4][0].p),await g.write(C),C=await c.G1.batchLEMtoU(C),o.update(C),F=await n.read(f,r[5][0].p),await g.write(F),F=await c.G1.batchLEMtoU(F),o.update(F),x=await n.read(_,r[6][0].p),await g.write(x),x=await c.G2.batchLEMtoU(x),o.update(x);const v=new Uint8Array(f);c.G1.toRprLEM(v,0,c.G1.g);const E=new Uint8Array(_);c.G2.toRprLEM(E,0,c.G2.g);const B=new Uint8Array(f);c.G1.toRprUncompressed(B,0,c.G1.g);const S=new Uint8Array(_);c.G2.toRprUncompressed(S,0,c.G2.g),await g.write(E),await g.write(v),await g.write(E),o.update(S),o.update(B),o.update(S),await _a(g),i&&i.info("Reading r1cs");let G=await Aa(s,d,2);const P=new ho(u.nVars),O=new ho(u.nVars),U=new ho(u.nVars),z=new ho(u.nVars-h-1),q=new Array(h+1);i&&i.info("Reading tauG1");let Q=await Aa(n,r,12,(m-1)*f,m*f);i&&i.info("Reading tauG2");let M=await Aa(n,r,13,(m-1)*_,m*_);i&&i.info("Reading alphatauG1");let k=await Aa(n,r,14,(m-1)*f,m*f);i&&i.info("Reading betatauG1");let R=await Aa(n,r,15,(m-1)*f,m*f);await async function(){const t=new Uint8Array(12+c.Fr.n8),e=new DataView(t.buffer),a=new Uint8Array(c.Fr.n8);c.Fr.toRprLE(a,0,c.Fr.e(1));let o=0;function n(){const t=G.slice(o,o+4);o+=4;return new DataView(t.buffer).getUint32(0,!0)}const r=new ho;for(let t=0;t<u.nConstraints;t++){i&&t%1e4==0&&i.debug(`processing constraints: ${t}/${u.nConstraints}`);const e=n();for(let a=0;a<e;a++){const e=n(),a=o;o+=c.Fr.n8;const i=0,l=f*t,s=3,d=f*t;void 0===P[e]&&(P[e]=[]),P[e].push([i,l,a]),e<=h?(void 0===q[e]&&(q[e]=[]),q[e].push([s,d,a])):(void 0===z[e-h-1]&&(z[e-h-1]=[]),z[e-h-1].push([s,d,a])),r.push([0,t,e,a])}const a=n();for(let e=0;e<a;e++){const e=n(),a=o;o+=c.Fr.n8;const i=0,l=f*t,s=1,d=_*t,u=2,g=f*t;void 0===O[e]&&(O[e]=[]),O[e].push([i,l,a]),void 0===U[e]&&(U[e]=[]),U[e].push([s,d,a]),e<=h?(void 0===q[e]&&(q[e]=[]),q[e].push([u,g,a])):(void 0===z[e-h-1]&&(z[e-h-1]=[]),z[e-h-1].push([u,g,a])),r.push([1,t,e,a])}const l=n();for(let e=0;e<l;e++){const e=n(),a=o;o+=c.Fr.n8;const i=0,r=f*t;e<=h?(void 0===q[e]&&(q[e]=[]),q[e].push([i,r,a])):(void 0===z[e-h-1]&&(z[e-h-1]=[]),z[e-h-1].push([i,r,a]))}}for(let t=0;t<=h;t++){const e=0,a=f*(u.nConstraints+t),i=3,o=f*(u.nConstraints+t);void 0===P[t]&&(P[t]=[]),P[t].push([e,a,-1]),void 0===q[t]&&(q[t]=[]),q[t].push([i,o,-1]),r.push([0,u.nConstraints+t,t,-1])}await fa(g,4);const l=new fe(r.length*(12+c.Fr.n8)+4),s=new Uint8Array(4);new DataView(s.buffer).setUint32(0,r.length,!0),l.set(s);let d=4;for(let t=0;t<r.length;t++)i&&t%1e5==0&&i.debug(`writing coeffs: ${t}/${r.length}`),p(r[t]);function p(i){let o;e.setUint32(0,i[0],!0),e.setUint32(4,i[1],!0),e.setUint32(8,i[2],!0),o=i[3]>=0?c.Fr.fromRprLE(G.slice(i[3],i[3]+c.Fr.n8),0):c.Fr.fromRprLE(a,0);const n=c.Fr.mul(o,I);c.Fr.toRprLE(t,12,n),l.set(t,d),d+=t.length}await g.write(l),await _a(g)}(),await T(3,"G1",q,"IC"),await async function(){await fa(g,9);const t=new fe(m*f);if(p<c.Fr.s){let e=await Aa(n,r,12,(2*m-1)*f,2*m*f);for(let a=0;a<m;a++){i&&a%1e4==0&&i.debug(`spliting buffer: ${a}/${m}`);const o=e.slice((2*a+1)*f,(2*a+1)*f+f);t.set(o,a*f)}}else{if(p!=c.Fr.s)throw i&&i.error("Circuit too big"),new Error("Circuit too big for this curve");{const e=r[12][0].p+(2**(p+1)-1)*f;await n.readToBuffer(t,0,m*f,e+m*f)}}await g.write(t),await _a(g)}(),await async function(){j(m-1);for(let t=0;t<m-1;t+=16384){i&&i.debug(`HashingHPoints: ${t}/${m}`);const e=Math.min(m-1,16384);await K(t,e)}}(),await T(8,"G1",z,"C"),await T(5,"G1",P,"A"),await T(6,"G1",O,"B1"),await T(7,"G2",U,"B2");const N=o.digest();return await fa(g,10),await g.write(N),await g.writeULE32(0),await _a(g),i&&i.info(ai(N,"Circuit hash: ")),await g.close(),await s.close(),await n.close(),N;async function T(t,e,a,n){const r=c[e];j(a.length),await fa(g,t);let l=[],s=0;for(;s<a.length;){let t=0;for(;s<a.length&&t<c.tm.concurrency;){i&&i.debug(`Writing points start ${n}: ${s}/${a.length}`);let o=1,r=a[s]?a[s].length:0;for(;s+o<a.length&&r+(a[s+o]?a[s+o].length:0)<32768&&o<32768;)r+=a[s+o]?a[s+o].length:0,o++;const c=a.slice(s,s+o),d=s;l.push(D(e,c,i,n).then((t=>(i&&i.debug(`Writing points end ${n}: ${d}/${a.length}`),t)))),s+=o,t++}const d=await Promise.all(l);for(let t=0;t<d.length;t++){await g.write(d[t][0]);const e=await r.batchLEMtoU(d[t][0]);o.update(e)}l=[]}await _a(g)}async function D(t,e,a,i){const o=c[t],n=2*o.F.n8,r=3*o.F.n8,l=2*o.F.n8;let s,d,u,g;if("G1"==t)s="g1m_timesScalarAffine",d="g1m_multiexpAffine",u="g1m_batchToAffine",g="g1m_zero";else{if("G2"!=t)throw new Error("Invalid group");s="g2m_timesScalarAffine",d="g2m_multiexpAffine",u="g2m_batchToAffine",g="g2m_zero"}let f,_,p=0;for(let t=0;t<e.length;t++)p+=e[t]?e[t].length:0;p>32768?(f=new fe(p*n),_=new fe(p*c.Fr.n8)):(f=new Uint8Array(p*n),_=new Uint8Array(p*c.Fr.n8));let h=0,m=0;const L=[Q,M,k,R],w=new Uint8Array(c.Fr.n8);c.Fr.toRprLE(w,0,c.Fr.e(1));let A=0;for(let t=0;t<e.length;t++)if(e[t])for(let o=0;o<e[t].length;o++)a&&o&&o%1e4==0&&a.debug(`Configuring big array ${i}: ${o}/${e[t].length}`),f.set(L[e[t][o][0]].slice(e[t][o][1],e[t][o][1]+n),A*n),e[t][o][2]>=0?_.set(G.slice(e[t][o][2],e[t][o][2]+c.Fr.n8),A*c.Fr.n8):_.set(w,A*c.Fr.n8),A++;if(e.length>1){const t=[];t.push({cmd:"ALLOCSET",var:0,buff:f}),t.push({cmd:"ALLOCSET",var:1,buff:_}),t.push({cmd:"ALLOC",var:2,len:e.length*r}),h=0,m=0;let a=0;for(let i=0;i<e.length;i++)e[i]?(1==e[i].length?t.push({cmd:"CALL",fnName:s,params:[{var:0,offset:h},{var:1,offset:m},{val:c.Fr.n8},{var:2,offset:a}]}):t.push({cmd:"CALL",fnName:d,params:[{var:0,offset:h},{var:1,offset:m},{val:c.Fr.n8},{val:e[i].length},{var:2,offset:a}]}),h+=n*e[i].length,m+=c.Fr.n8*e[i].length,a+=r):(t.push({cmd:"CALL",fnName:g,params:[{var:2,offset:a}]}),a+=r);t.push({cmd:"CALL",fnName:u,params:[{var:2},{val:e.length},{var:2}]}),t.push({cmd:"GET",out:0,var:2,len:e.length*l});return await c.tm.queueAction(t)}{let t=await o.multiExpAffine(f,_,a,i);return t=[o.toAffine(t)],t}}async function K(t,e){const a=await n.read(e*f,r[2][0].p+(t+m)*f),i=await n.read(e*f,r[2][0].p+t*f),l=c.tm.concurrency,s=Math.floor(e/l),d=[];for(let t=0;t<l;t++){let o;if(o=t<l-1?s:e-t*s,0==o)continue;const n=a.slice(t*s*f,(t*s+o)*f),r=i.slice(t*s*f,(t*s+o)*f);d.push(V(n,r))}const u=await Promise.all(d);for(let t=0;t<u.length;t++)o.update(u[t][0])}async function V(t,e){const a=t.byteLength/f,i=3*c.G1.F.n8,o=[];o.push({cmd:"ALLOCSET",var:0,buff:t}),o.push({cmd:"ALLOCSET",var:1,buff:e}),o.push({cmd:"ALLOC",var:2,len:a*i});for(let t=0;t<a;t++)o.push({cmd:"CALL",fnName:"g1m_subAffine",params:[{var:0,offset:t*f},{var:1,offset:t*f},{var:2,offset:t*i}]});o.push({cmd:"CALL",fnName:"g1m_batchToAffine",params:[{var:2},{val:a},{var:2}]}),o.push({cmd:"CALL",fnName:"g1m_batchLEMtoU",params:[{var:2},{val:a},{var:2}]}),o.push({cmd:"GET",out:0,var:2,len:a*f});return await c.tm.queueAction(o)}function j(t){const e=new Uint8Array(4);new DataView(e.buffer,e.byteOffset,e.byteLength).setUint32(0,t,!1),o.update(e)}}const Lo=ni;async function wo(t,e,a,i){let o;await Wa.ready();const{fd:n,sections:r}=await ua(a,"zkey",2),c=await pi(n,r,!1);if("groth16"!=c.protocol)throw new Error("zkey file is not groth16");const l=await Ca(c.q),s=2*l.G1.F.n8,d=await mi(n,l,r),u=Wa(64);u.update(d.csHash);let g=l.G1.g;for(let t=0;t<d.contributions.length;t++){const e=d.contributions[t],a=oi(u);if(Ai(a,l,e.delta.g1_s),Ai(a,l,e.delta.g1_sx),!ii(a.digest(),e.transcript))return console.log(`INVALID(${t}): Inconsistent transcript `),!1;const i=zi(l,e.transcript);if(o=await Lo(l,e.delta.g1_s,e.delta.g1_sx,i,e.delta.g2_spx),!0!==o)return console.log(`INVALID(${t}): public key G1 and G2 do not have the same ration `),!1;if(o=await Lo(l,g,e.deltaAfter,i,e.delta.g2_spx),!0!==o)return console.log(`INVALID(${t}): deltaAfter does not fillow the public key `),!1;if(1==e.type){const a=ci(e.beaconHash,e.numIterationsExp),i=l.Fr.fromRng(a),o=l.G1.toAffine(l.G1.fromRng(a)),n=l.G1.toAffine(l.G1.timesFr(o,i));if(!0!==l.G1.eq(o,e.delta.g1_s))return console.log(`INVALID(${t}): Key of the beacon does not match. g1_s `),!1;if(!0!==l.G1.eq(n,e.delta.g1_sx))return console.log(`INVALID(${t}): Key of the beacon does not match. g1_sx `),!1}bi(u,l,e);const n=Wa(64);bi(n,l,e),e.contributionHash=n.digest(),g=e.deltaAfter}const{fd:f,sections:_}=await ua(t,"zkey",2),p=await pi(f,_,!1);if("groth16"!=p.protocol)throw new Error("zkeyinit file is not groth16");if(!He.eq(p.q,c.q)||!He.eq(p.r,c.r)||p.n8q!=c.n8q||p.n8r!=c.n8r)return i&&i.error("INVALID: Different curves"),!1;if(p.nVars!=c.nVars||p.nPublic!=c.nPublic||p.domainSize!=c.domainSize)return i&&i.error("INVALID: Different circuit parameters"),!1;if(!l.G1.eq(c.vk_alpha_1,p.vk_alpha_1))return i&&i.error("INVALID: Invalid alpha1"),!1;if(!l.G1.eq(c.vk_beta_1,p.vk_beta_1))return i&&i.error("INVALID: Invalid beta1"),!1;if(!l.G2.eq(c.vk_beta_2,p.vk_beta_2))return i&&i.error("INVALID: Invalid beta2"),!1;if(!l.G2.eq(c.vk_gamma_2,p.vk_gamma_2))return i&&i.error("INVALID: Invalid gamma2"),!1;if(!l.G1.eq(c.vk_delta_1,g))return i&&i.error("INVALID: Invalid delta1"),!1;if(o=await Lo(l,l.G1.g,g,l.G2.g,c.vk_delta_2),!0!==o)return i&&i.error("INVALID: Invalid delta2"),!1;const h=await mi(f,l,_);if(!ii(d.csHash,h.csHash))return i&&i.error("INVALID: Circuit does not match"),!1;if(r[8][0].size!=s*(c.nVars-c.nPublic-1))return i&&i.error("INVALID: Invalid L section size"),!1;if(r[9][0].size!=s*c.domainSize)return i&&i.error("INVALID: Invalid H section size"),!1;let m;if(m=await ba(n,r,f,_,3),!m)return i&&i.error("INVALID: IC section is not identical"),!1;if(m=await ba(n,r,f,_,4),!m)return i&&i.error("Coeffs section is not identical"),!1;if(m=await ba(n,r,f,_,5),!m)return i&&i.error("A section is not identical"),!1;if(m=await ba(n,r,f,_,6),!m)return i&&i.error("B1 section is not identical"),!1;if(m=await ba(n,r,f,_,7),!m)return i&&i.error("B2 section is not identical"),!1;if(o=await async function(t,e,a,n,r,c,s,d,u){const g=1<<20,f=l[t],_=2*f.F.n8;await pa(e,a,c),await pa(n,r,c);let p=f.zero,h=f.zero;const m=a[c][0].size/_;for(let t=0;t<m;t+=g){i&&i.debug(`Same ratio check ${u}: ${t}/${m}`);const a=Math.min(m-t,g),o=await e.read(a*_),r=await n.read(a*_),c=new Uint8Array(4*a);wt.randomFillSync(c);const l=await f.multiExpAffine(o,c),s=await f.multiExpAffine(r,c);p=f.add(p,l),h=f.add(h,s)}return await ha(e),await ha(n),0==m||(o=await Lo(l,p,h,s,d),!0===o)}("G1",f,_,n,r,8,c.vk_delta_2,p.vk_delta_2,"L section"),!0!==o)return i&&i.error("L section does not match"),!1;if(o=await async function(){const t=1<<20,a=l.G1,s=l.Fr,d=2*a.F.n8,{fd:u,sections:g}=await ua(e,"ptau",1);let f=new fe(c.domainSize*c.n8r);const _=new Array(8);for(let t=0;t<8;t++)_[t]=wt.randomBytes(4).readUInt32BE(0,!0);const h=new Lt(_);for(let t=0;t<c.domainSize-1;t++){const e=s.fromRng(h);s.toRprLE(f,t*c.n8r,e)}s.toRprLE(f,(c.domainSize-1)*c.n8r,s.zero);let m,w=a.zero;for(let e=0;e<c.domainSize;e+=t){i&&i.debug(`H Verificaition(tau): ${e}/${c.domainSize}`);const o=Math.min(c.domainSize-e,t),n=await u.read(d*o,g[2][0].p+c.domainSize*d+e*d),r=await u.read(d*o,g[2][0].p+e*d),l=await L(n,r),s=f.slice(e*c.n8r,(e+o)*c.n8r),_=await a.multiExpAffine(l,s);w=a.add(w,_)}if(f=await s.batchToMontgomery(f),c.power<s.s)m=s.neg(s.e(2));else{const t=2**s.s,e=s.exp(s.shift,t);m=s.sub(e,s.one)}const A=c.power<s.s?s.w[c.power+1]:s.shift;f=await s.batchApplyKey(f,m,A),f=await s.fft(f),f=await s.batchFromMontgomery(f),await pa(n,r,9);let b=a.zero;for(let e=0;e<c.domainSize;e+=t){i&&i.debug(`H Verificaition(lagrange): ${e}/${c.domainSize}`);const o=Math.min(c.domainSize-e,t),r=await n.read(d*o),l=f.slice(e*c.n8r,(e+o)*c.n8r),s=await a.multiExpAffine(r,l);b=a.add(b,s)}return await ha(n),o=await Lo(l,w,b,c.vk_delta_2,p.vk_delta_2),!0===o}(),!0!==o)return i&&i.error("H section does not match"),!1;i&&i.info(ai(d.csHash,"Circuit Hash: ")),await n.close(),await f.close();for(let t=d.contributions.length-1;t>=0;t--){const e=d.contributions[t];i&&i.info("-------------------------"),i&&i.info(ai(e.contributionHash,`contribution #${t+1} ${e.name?e.name:""}:`)),1==e.type&&(i&&i.info(`Beacon generator: ${si(e.beaconHash)}`),i&&i.info(`Beacon iterations Exp: ${e.numIterationsExp}`))}return i&&i.info("-------------------------"),i&&i.info("ZKey Ok!"),!0;async function L(t,e){const a=2*l.G1.F.n8,i=t.byteLength/a,o=l.tm.concurrency,n=Math.floor(i/o),r=[];for(let a=0;a<o;a++){let c;if(c=a<o-1?n:i-a*n,0==c)continue;const l=t.slice(a*n*s,(a*n+c)*s),d=e.slice(a*n*s,(a*n+c)*s);r.push(w(l,d))}const c=await Promise.all(r),d=new Uint8Array(i*a);let u=0;for(let t=0;t<c.length;t++)d.set(c[t][0],u),u+=c[t][0].byteLength;return d}async function w(t,e){const a=2*l.G1.F.n8,i=3*l.G1.F.n8,o=t.byteLength/a,n=[];n.push({cmd:"ALLOCSET",var:0,buff:t}),n.push({cmd:"ALLOCSET",var:1,buff:e}),n.push({cmd:"ALLOC",var:2,len:o*i});for(let t=0;t<o;t++)n.push({cmd:"CALL",fnName:"g1m_subAffine",params:[{var:0,offset:t*a},{var:1,offset:t*a},{var:2,offset:t*i}]});n.push({cmd:"CALL",fnName:"g1m_batchToAffine",params:[{var:2},{val:o},{var:2}]}),n.push({cmd:"GET",out:0,var:2,len:o*a});return await l.tm.queueAction(n)}}const{stringifyBigInts:Ao}=$e;async function bo(t){const{fd:e,sections:a}=await ua(t,"zkey",2),i=await pi(e,a);let o;if("groth16"==i.protocol)o=await async function(t,e,a){const i=await Ca(t.q),o=2*i.G1.F.n8,n=await i.pairing(t.vk_alpha_1,t.vk_beta_2);let r={protocol:t.protocol,curve:i.name,nPublic:t.nPublic,vk_alpha_1:i.G1.toObject(t.vk_alpha_1),vk_beta_2:i.G2.toObject(t.vk_beta_2),vk_gamma_2:i.G2.toObject(t.vk_gamma_2),vk_delta_2:i.G2.toObject(t.vk_delta_2),vk_alphabeta_12:i.Gt.toObject(n)};await pa(e,a,3),r.IC=[];for(let a=0;a<=t.nPublic;a++){const t=await e.read(o),a=i.G1.toObject(t);r.IC.push(a)}return await ha(e),r=Ao(r),r}(i,e,a);else{if("plonk"!=i.protocol)throw new Error("zkey file is not groth16");o=await async function(t){const e=await Ca(t.q);let a={protocol:t.protocol,curve:e.name,nPublic:t.nPublic,power:t.power,k1:e.Fr.toObject(t.k1),k2:e.Fr.toObject(t.k2),Qm:e.G1.toObject(t.Qm),Ql:e.G1.toObject(t.Ql),Qr:e.G1.toObject(t.Qr),Qo:e.G1.toObject(t.Qo),Qc:e.G1.toObject(t.Qc),S1:e.G1.toObject(t.S1),S2:e.G1.toObject(t.S2),S3:e.G1.toObject(t.S3),X_2:e.G2.toObject(t.X_2),w:e.Fr.toObject(e.Fr.w[t.power])};return a=Ao(a),a}(i)}return await e.close(),o}var yo={};var Io=Object.freeze({__proto__:null,newZKey:mo,exportBellman:async function(t,e,a){const{fd:i,sections:o}=await ua(t,"zkey",2),n=await pi(i,o);if("groth16"!=n.protocol)throw new Error("zkey file is not groth16");const r=await Ca(n.q),c=2*r.G1.F.n8,l=2*r.G2.F.n8,s=await mi(i,r,o),d=await sa(e);let u;await L(n.vk_alpha_1),await L(n.vk_beta_1),await w(n.vk_beta_2),await w(n.vk_gamma_2),await L(n.vk_delta_1),await w(n.vk_delta_2),u=await Aa(i,o,3),u=await r.G1.batchLEMtoU(u),await A("G1",u);const g=await Aa(i,o,9);let f,_,p,h,m;f=await r.G1.fft(g,"affine","jacobian",a),f=await r.G1.batchApplyKey(f,r.Fr.neg(r.Fr.e(2)),r.Fr.w[n.power+1],"jacobian","affine",a),f=f.slice(0,f.byteLength-c),f=await r.G1.batchLEMtoU(f),await A("G1",f),_=await Aa(i,o,8),_=await r.G1.batchLEMtoU(_),await A("G1",_),p=await Aa(i,o,5),p=await r.G1.batchLEMtoU(p),await A("G1",p),h=await Aa(i,o,6),h=await r.G1.batchLEMtoU(h),await A("G1",h),m=await Aa(i,o,7),m=await r.G2.batchLEMtoU(m),await A("G2",m),await d.write(s.csHash),await async function(t){const e=new Uint8Array(4);new DataView(e.buffer,e.byteOffset,e.byteLength).setUint32(0,t,!1),await d.write(e)}(s.contributions.length);for(let t=0;t<s.contributions.length;t++){const e=s.contributions[t];await L(e.deltaAfter),await L(e.delta.g1_s),await L(e.delta.g1_sx),await w(e.delta.g2_spx),await d.write(e.transcript)}async function L(t){const e=new Uint8Array(c);r.G1.toRprUncompressed(e,0,t),await d.write(e)}async function w(t){const e=new Uint8Array(l);r.G2.toRprUncompressed(e,0,t),await d.write(e)}async function A(t,e){let a;a="G1"==t?c:l;const i=new Uint8Array(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint32(0,e.byteLength/a,!1),await d.write(i),await d.write(e)}await i.close(),await d.close()},importBellman:async function(t,e,a,i,o){const{fd:n,sections:r}=await ua(t,"zkey",2),c=await pi(n,r,!1);if("groth16"!=c.protocol)throw new Error("zkey file is not groth16");const l=await Ca(c.q),s=2*l.G1.F.n8,d=2*l.G2.F.n8,u=await mi(n,l,r),g={},f=await da(e);f.pos=3*s+3*d+8+s*c.nVars+4+s*(c.domainSize-1)+4+s*c.nVars+4+s*c.nVars+4+d*c.nVars,g.csHash=await f.read(64);const _=await f.readUBE32();g.contributions=[];for(let t=0;t<_;t++){const e={delta:{}};e.deltaAfter=await y(f),e.delta.g1_s=await y(f),e.delta.g1_sx=await y(f),e.delta.g2_spx=await I(f),e.transcript=await f.read(64),t<u.contributions.length&&(e.type=u.contributions[t].type,1==e.type&&(e.beaconHash=u.contributions[t].beaconHash,e.numIterationsExp=u.contributions[t].numIterationsExp),u.contributions[t].name&&(e.name=u.contributions[t].name)),g.contributions.push(e)}if(!ii(g.csHash,u.csHash))return o&&o.error("Hash of the original circuit does not match with the MPC one"),!1;if(u.contributions.length>g.contributions.length)return o&&o.error("The impoerted file does not include new contributions"),!1;for(let t=0;t<u.contributions.length;t++)if(!C(u.contributions[t],g.contributions[t]))return o&&o.error(`Previos contribution ${t} does not match`),!1;if(i)for(let t=u.contributions.length;t<g.contributions.length;t++)g.contributions[t].name=i;const p=await ga(a,"zkey",1,10);if(f.pos=0,f.pos+=s,f.pos+=s,f.pos+=d,f.pos+=d,c.vk_delta_1=await y(f),c.vk_delta_2=await I(f),await di(p,c),await f.readUBE32()!=c.nPublic+1)return o&&o.error("Invalid number of points in IC"),await p.discard(),!1;if(f.pos+=s*(c.nPublic+1),await wa(n,r,p,3),await wa(n,r,p,4),await f.readUBE32()!=c.domainSize-1)return o&&o.error("Invalid number of points in H"),await p.discard(),!1;let h;const m=await f.read(s*(c.domainSize-1)),L=await l.G1.batchUtoLEM(m);h=new Uint8Array(c.domainSize*s),h.set(L),l.G1.toRprLEM(h,s*(c.domainSize-1),l.G1.zeroAffine);const w=l.Fr.neg(l.Fr.inv(l.Fr.e(2))),A=l.Fr.inv(l.Fr.w[c.power+1]);if(h=await l.G1.batchApplyKey(h,w,A,"affine","jacobian",o),h=await l.G1.ifft(h,"jacobian","affine",o),await fa(p,9),await p.write(h),await _a(p),await f.readUBE32()!=c.nVars-c.nPublic-1)return o&&o.error("Invalid number of points in L"),await p.discard(),!1;let b;return b=await f.read(s*(c.nVars-c.nPublic-1)),b=await l.G1.batchUtoLEM(b),await fa(p,8),await p.write(b),await _a(p),await f.readUBE32()!=c.nVars?(o&&o.error("Invalid number of points in A"),await p.discard(),!1):(f.pos+=s*c.nVars,await wa(n,r,p,5),await f.readUBE32()!=c.nVars?(o&&o.error("Invalid number of points in B1"),await p.discard(),!1):(f.pos+=s*c.nVars,await wa(n,r,p,6),await f.readUBE32()!=c.nVars?(o&&o.error("Invalid number of points in B2"),await p.discard(),!1):(f.pos+=d*c.nVars,await wa(n,r,p,7),await wi(p,l,g),await f.close(),await p.close(),await n.close(),!0)));async function y(t){const e=await t.read(2*l.G1.F.n8);return l.G1.fromRprUncompressed(e,0)}async function I(t){const e=await t.read(2*l.G2.F.n8);return l.G2.fromRprUncompressed(e,0)}function C(t,e){return!!l.G1.eq(t.deltaAfter,e.deltaAfter)&&(!!l.G1.eq(t.delta.g1_s,e.delta.g1_s)&&(!!l.G1.eq(t.delta.g1_sx,e.delta.g1_sx)&&(!!l.G2.eq(t.delta.g2_spx,e.delta.g2_spx)&&!!ii(t.transcript,e.transcript))))}},verifyFromR1cs:async function(t,e,a,i){const o={type:"bigMem"};return await mo(t,e,o,i),await wo(o,e,a,i)},verifyFromInit:wo,contribute:async function(t,e,a,i,o){await Wa.ready();const{fd:n,sections:r}=await ua(t,"zkey",2),c=await pi(n,r);if("groth16"!=c.protocol)throw new Error("zkey file is not groth16");const l=await Ca(c.q),s=await mi(n,l,r),d=await ga(e,"zkey",1,10),u=await ri(i),g=Wa(64);g.update(s.csHash);for(let t=0;t<s.contributions.length;t++)bi(g,l,s.contributions[t]);const f={delta:{}};f.delta.prvKey=l.Fr.fromRng(u),f.delta.g1_s=l.G1.toAffine(l.G1.fromRng(u)),f.delta.g1_sx=l.G1.toAffine(l.G1.timesFr(f.delta.g1_s,f.delta.prvKey)),Ai(g,l,f.delta.g1_s),Ai(g,l,f.delta.g1_sx),f.transcript=g.digest(),f.delta.g2_sp=zi(l,f.transcript),f.delta.g2_spx=l.G2.toAffine(l.G2.timesFr(f.delta.g2_sp,f.delta.prvKey)),c.vk_delta_1=l.G1.timesFr(c.vk_delta_1,f.delta.prvKey),c.vk_delta_2=l.G2.timesFr(c.vk_delta_2,f.delta.prvKey),f.deltaAfter=c.vk_delta_1,f.type=0,a&&(f.name=a),s.contributions.push(f),await di(d,c),await wa(n,r,d,3),await wa(n,r,d,4),await wa(n,r,d,5),await wa(n,r,d,6),await wa(n,r,d,7);const _=l.Fr.inv(f.delta.prvKey);await Ji(n,r,d,8,l,"G1",_,l.Fr.e(1),"L Section",o),await Ji(n,r,d,9,l,"G1",_,l.Fr.e(1),"H Section",o),await wi(d,l,s),await n.close(),await d.close();const p=Wa(64);bi(p,l,f);const h=p.digest();return o&&o.info(ai(s.csHash,"Circuit Hash: ")),o&&o.info(ai(h,"Contribution Hash: ")),h},beacon:async function(t,e,a,i,o,n){await Wa.ready();const r=li(i);if(0==r.byteLength||2*r.byteLength!=i.length)return n&&n.error("Invalid Beacon Hash. (It must be a valid hexadecimal sequence)"),!1;if(r.length>=256)return n&&n.error("Maximum lenght of beacon hash is 255 bytes"),!1;if((o=parseInt(o))<10||o>63)return n&&n.error("Invalid numIterationsExp. (Must be between 10 and 63)"),!1;const{fd:c,sections:l}=await ua(t,"zkey",2),s=await pi(c,l);if("groth16"!=s.protocol)throw new Error("zkey file is not groth16");const d=await Ca(s.q),u=await mi(c,d,l),g=await ga(e,"zkey",1,10),f=await ci(r,o),_=Wa(64);_.update(u.csHash);for(let t=0;t<u.contributions.length;t++)bi(_,d,u.contributions[t]);const p={delta:{}};p.delta.prvKey=d.Fr.fromRng(f),p.delta.g1_s=d.G1.toAffine(d.G1.fromRng(f)),p.delta.g1_sx=d.G1.toAffine(d.G1.timesFr(p.delta.g1_s,p.delta.prvKey)),Ai(_,d,p.delta.g1_s),Ai(_,d,p.delta.g1_sx),p.transcript=_.digest(),p.delta.g2_sp=zi(d,p.transcript),p.delta.g2_spx=d.G2.toAffine(d.G2.timesFr(p.delta.g2_sp,p.delta.prvKey)),s.vk_delta_1=d.G1.timesFr(s.vk_delta_1,p.delta.prvKey),s.vk_delta_2=d.G2.timesFr(s.vk_delta_2,p.delta.prvKey),p.deltaAfter=s.vk_delta_1,p.type=1,p.numIterationsExp=o,p.beaconHash=r,a&&(p.name=a),u.contributions.push(p),await di(g,s),await wa(c,l,g,3),await wa(c,l,g,4),await wa(c,l,g,5),await wa(c,l,g,6),await wa(c,l,g,7);const h=d.Fr.inv(p.delta.prvKey);await Ji(c,l,g,8,d,"G1",h,d.Fr.e(1),"L Section",n),await Ji(c,l,g,9,d,"G1",h,d.Fr.e(1),"H Section",n),await wi(g,d,u),await c.close(),await g.close();const m=Wa(64);bi(m,d,p);const L=m.digest();return n&&n.info(ai(L,"Contribution Hash: ")),L},exportJson:async function(t){const e=await async function(t,e){const{fd:a,sections:i}=await ua(t,"zkey",1),o=await pi(a,i,"groth16"),n=new vt(o.r),r=He.mod(He.shl(1,8*o.n8r),o.r),c=n.inv(r),l=n.mul(c,c);let s=await Ca(o.q);await pa(a,i,3),o.IC=[];for(let t=0;t<=o.nPublic;t++){const t=await fi(a,s,e);o.IC.push(t)}await ha(a),await pa(a,i,4);const d=await a.readULE32();o.ccoefs=[];for(let t=0;t<d;t++){const t=await a.readULE32(),e=await a.readULE32(),i=await a.readULE32(),n=await u();o.ccoefs.push({matrix:t,constraint:e,signal:i,value:n})}await ha(a),await pa(a,i,5),o.A=[];for(let t=0;t<o.nVars;t++){const i=await fi(a,s,e);o.A[t]=i}await ha(a),await pa(a,i,6),o.B1=[];for(let t=0;t<o.nVars;t++){const i=await fi(a,s,e);o.B1[t]=i}await ha(a),await pa(a,i,7),o.B2=[];for(let t=0;t<o.nVars;t++){const i=await _i(a,s,e);o.B2[t]=i}await ha(a),await pa(a,i,8),o.C=[];for(let t=o.nPublic+1;t<o.nVars;t++){const i=await fi(a,s,e);o.C[t]=i}await ha(a),await pa(a,i,9),o.hExps=[];for(let t=0;t<o.domainSize;t++){const t=await fi(a,s,e);o.hExps.push(t)}return await ha(a),await a.close(),o;async function u(){const t=await La(a,o.n8r);return n.mul(t,l)}}(t,!0);return e},bellmanContribute:async function(t,e,a,i,o){await Wa.ready();const n=await ri(i),r=t.Fr.fromRng(n),c=t.Fr.inv(r),l=2*t.G1.F.n8,s=2*t.G2.F.n8,d=await da(e),u=await sa(a);await E(l),await E(l),await E(s),await E(s);const g=await B(),f=t.G1.timesFr(g,r);await G(f);const _=await S(),p=t.G2.timesFr(_,r);await P(p);const h=await d.readUBE32();await u.writeUBE32(h),await E(h*l);const m=await d.readUBE32();await u.writeUBE32(m),await Wi(d,u,null,t,"G1",m,c,t.Fr.e(1),"UNCOMPRESSED","H",o);const L=await d.readUBE32();await u.writeUBE32(L),await Wi(d,u,null,t,"G1",L,c,t.Fr.e(1),"UNCOMPRESSED","L",o);const w=await d.readUBE32();await u.writeUBE32(w),await E(w*l);const A=await d.readUBE32();await u.writeUBE32(A),await E(A*l);const b=await d.readUBE32();await u.writeUBE32(b),await E(b*s);const y=Wa(64),I={};I.csHash=await d.read(64),y.update(I.csHash);const C=await d.readUBE32();I.contributions=[];for(let e=0;e<C;e++){const e={delta:{}};e.deltaAfter=await B(),e.delta.g1_s=await B(),e.delta.g1_sx=await B(),e.delta.g2_spx=await S(),e.transcript=await d.read(64),I.contributions.push(e),bi(y,t,e)}const F={delta:{}};F.delta.prvKey=r,F.delta.g1_s=t.G1.toAffine(t.G1.fromRng(n)),F.delta.g1_sx=t.G1.toAffine(t.G1.timesFr(F.delta.g1_s,r)),Ai(y,t,F.delta.g1_s),Ai(y,t,F.delta.g1_sx),F.transcript=y.digest(),F.delta.g2_sp=zi(t,F.transcript),F.delta.g2_spx=t.G2.toAffine(t.G2.timesFr(F.delta.g2_sp,r)),F.deltaAfter=f,F.type=0,I.contributions.push(F),await u.write(I.csHash),await u.writeUBE32(I.contributions.length);for(let t=0;t<I.contributions.length;t++){const e=I.contributions[t];await G(e.deltaAfter),await G(e.delta.g1_s),await G(e.delta.g1_sx),await P(e.delta.g2_spx),await u.write(e.transcript)}const x=Wa(64);bi(x,t,F);const v=x.digest();return o&&o.info(ai(v,"Contribution Hash: ")),await u.close(),await d.close(),v;async function E(t){const e=2*d.pageSize;for(let a=0;a<t;a+=e){const i=Math.min(t-a,e),o=await d.read(i);await u.write(o)}}async function B(){const e=await d.read(2*t.G1.F.n8);return t.G1.fromRprUncompressed(e,0)}async function S(){const e=await d.read(2*t.G2.F.n8);return t.G2.fromRprUncompressed(e,0)}async function G(e){const a=new Uint8Array(l);t.G1.toRprUncompressed(a,0,e),await u.write(a)}async function P(e){const a=new Uint8Array(s);t.G2.toRprUncompressed(a,0,e),await u.write(a)}},exportVerificationKey:bo,exportSolidityVerifier:async function(t,e,a){const i=await bo(t);let o=e[i.protocol];return yo.render(o,i)}});
/**
* [js-sha3]{@link https://github.com/emn178/js-sha3}
*
* @version 0.8.0
* @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2015-2018
* @license MIT
*/
var Co=d((function(t){!function(){var e="input is invalid type",a="object"==typeof window,i=a?window:{};i.JS_SHA3_NO_WINDOW&&(a=!1);var o=!a&&"object"==typeof self;!i.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node?i=s:o&&(i=self);var n=!i.JS_SHA3_NO_COMMON_JS&&t.exports,r=!i.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,c="0123456789abcdef".split(""),l=[4,1024,262144,67108864],d=[0,8,16,24],u=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],g=[224,256,384,512],f=[128,256],_=["hex","buffer","arrayBuffer","array","digest"],p={128:168,256:136};!i.JS_SHA3_NO_NODE_JS&&Array.isArray||(Array.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)}),!r||!i.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView||(ArrayBuffer.isView=function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer});for(var h=function(t,e,a){return function(i){return new G(t,e,t).update(i)[a]()}},m=function(t,e,a){return function(i,o){return new G(t,e,o).update(i)[a]()}},L=function(t,e,a){return function(e,i,o,n){return I["cshake"+t].update(e,i,o,n)[a]()}},w=function(t,e,a){return function(e,i,o,n){return I["kmac"+t].update(e,i,o,n)[a]()}},A=function(t,e,a,i){for(var o=0;o<_.length;++o){var n=_[o];t[n]=e(a,i,n)}return t},b=function(t,e){var a=h(t,e,"hex");return a.create=function(){return new G(t,e,t)},a.update=function(t){return a.create().update(t)},A(a,h,t,e)},y=[{name:"keccak",padding:[1,256,65536,16777216],bits:g,createMethod:b},{name:"sha3",padding:[6,1536,393216,100663296],bits:g,createMethod:b},{name:"shake",padding:[31,7936,2031616,520093696],bits:f,createMethod:function(t,e){var a=m(t,e,"hex");return a.create=function(a){return new G(t,e,a)},a.update=function(t,e){return a.create(e).update(t)},A(a,m,t,e)}},{name:"cshake",padding:l,bits:f,createMethod:function(t,e){var a=p[t],i=L(t,0,"hex");return i.create=function(i,o,n){return o||n?new G(t,e,i).bytepad([o,n],a):I["shake"+t].create(i)},i.update=function(t,e,a,o){return i.create(e,a,o).update(t)},A(i,L,t,e)}},{name:"kmac",padding:l,bits:f,createMethod:function(t,e){var a=p[t],i=w(t,0,"hex");return i.create=function(i,o,n){return new P(t,e,o).bytepad(["KMAC",n],a).bytepad([i],a)},i.update=function(t,e,a,o){return i.create(t,a,o).update(e)},A(i,w,t,e)}}],I={},C=[],F=0;F<y.length;++F)for(var x=y[F],v=x.bits,E=0;E<v.length;++E){var B=x.name+"_"+v[E];if(C.push(B),I[B]=x.createMethod(v[E],x.padding),"sha3"!==x.name){var S=x.name+v[E];C.push(S),I[S]=I[B]}}function G(t,e,a){this.blocks=[],this.s=[],this.padding=e,this.outputBits=a,this.reset=!0,this.finalized=!1,this.block=0,this.start=0,this.blockCount=1600-(t<<1)>>5,this.byteCount=this.blockCount<<2,this.outputBlocks=a>>5,this.extraBytes=(31&a)>>3;for(var i=0;i<50;++i)this.s[i]=0}function P(t,e,a){G.call(this,t,e,a)}G.prototype.update=function(t){if(this.finalized)throw new Error("finalize already called");var a,i=typeof t;if("string"!==i){if("object"!==i)throw new Error(e);if(null===t)throw new Error(e);if(r&&t.constructor===ArrayBuffer)t=new Uint8Array(t);else if(!(Array.isArray(t)||r&&ArrayBuffer.isView(t)))throw new Error(e);a=!0}for(var o,n,c=this.blocks,l=this.byteCount,s=t.length,u=this.blockCount,g=0,f=this.s;g<s;){if(this.reset)for(this.reset=!1,c[0]=this.block,o=1;o<u+1;++o)c[o]=0;if(a)for(o=this.start;g<s&&o<l;++g)c[o>>2]|=t[g]<<d[3&o++];else for(o=this.start;g<s&&o<l;++g)(n=t.charCodeAt(g))<128?c[o>>2]|=n<<d[3&o++]:n<2048?(c[o>>2]|=(192|n>>6)<<d[3&o++],c[o>>2]|=(128|63&n)<<d[3&o++]):n<55296||n>=57344?(c[o>>2]|=(224|n>>12)<<d[3&o++],c[o>>2]|=(128|n>>6&63)<<d[3&o++],c[o>>2]|=(128|63&n)<<d[3&o++]):(n=65536+((1023&n)<<10|1023&t.charCodeAt(++g)),c[o>>2]|=(240|n>>18)<<d[3&o++],c[o>>2]|=(128|n>>12&63)<<d[3&o++],c[o>>2]|=(128|n>>6&63)<<d[3&o++],c[o>>2]|=(128|63&n)<<d[3&o++]);if(this.lastByteIndex=o,o>=l){for(this.start=o-l,this.block=c[u],o=0;o<u;++o)f[o]^=c[o];O(f),this.reset=!0}else this.start=o}return this},G.prototype.encode=function(t,e){var a=255&t,i=1,o=[a];for(a=255&(t>>=8);a>0;)o.unshift(a),a=255&(t>>=8),++i;return e?o.push(i):o.unshift(i),this.update(o),o.length},G.prototype.encodeString=function(t){var a,i=typeof t;if("string"!==i){if("object"!==i)throw new Error(e);if(null===t)throw new Error(e);if(r&&t.constructor===ArrayBuffer)t=new Uint8Array(t);else if(!(Array.isArray(t)||r&&ArrayBuffer.isView(t)))throw new Error(e);a=!0}var o=0,n=t.length;if(a)o=n;else for(var c=0;c<t.length;++c){var l=t.charCodeAt(c);l<128?o+=1:l<2048?o+=2:l<55296||l>=57344?o+=3:(l=65536+((1023&l)<<10|1023&t.charCodeAt(++c)),o+=4)}return o+=this.encode(8*o),this.update(t),o},G.prototype.bytepad=function(t,e){for(var a=this.encode(e),i=0;i<t.length;++i)a+=this.encodeString(t[i]);var o=e-a%e,n=[];return n.length=o,this.update(n),this},G.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,e=this.lastByteIndex,a=this.blockCount,i=this.s;if(t[e>>2]|=this.padding[3&e],this.lastByteIndex===this.byteCount)for(t[0]=t[a],e=1;e<a+1;++e)t[e]=0;for(t[a-1]|=2147483648,e=0;e<a;++e)i[e]^=t[e];O(i)}},G.prototype.toString=G.prototype.hex=function(){this.finalize();for(var t,e=this.blockCount,a=this.s,i=this.outputBlocks,o=this.extraBytes,n=0,r=0,l="";r<i;){for(n=0;n<e&&r<i;++n,++r)t=a[n],l+=c[t>>4&15]+c[15&t]+c[t>>12&15]+c[t>>8&15]+c[t>>20&15]+c[t>>16&15]+c[t>>28&15]+c[t>>24&15];r%e==0&&(O(a),n=0)}return o&&(t=a[n],l+=c[t>>4&15]+c[15&t],o>1&&(l+=c[t>>12&15]+c[t>>8&15]),o>2&&(l+=c[t>>20&15]+c[t>>16&15])),l},G.prototype.arrayBuffer=function(){this.finalize();var t,e=this.blockCount,a=this.s,i=this.outputBlocks,o=this.extraBytes,n=0,r=0,c=this.outputBits>>3;t=o?new ArrayBuffer(i+1<<2):new ArrayBuffer(c);for(var l=new Uint32Array(t);r<i;){for(n=0;n<e&&r<i;++n,++r)l[r]=a[n];r%e==0&&O(a)}return o&&(l[n]=a[n],t=t.slice(0,c)),t},G.prototype.buffer=G.prototype.arrayBuffer,G.prototype.digest=G.prototype.array=function(){this.finalize();for(var t,e,a=this.blockCount,i=this.s,o=this.outputBlocks,n=this.extraBytes,r=0,c=0,l=[];c<o;){for(r=0;r<a&&c<o;++r,++c)t=c<<2,e=i[r],l[t]=255&e,l[t+1]=e>>8&255,l[t+2]=e>>16&255,l[t+3]=e>>24&255;c%a==0&&O(i)}return n&&(t=c<<2,e=i[r],l[t]=255&e,n>1&&(l[t+1]=e>>8&255),n>2&&(l[t+2]=e>>16&255)),l},P.prototype=new G,P.prototype.finalize=function(){return this.encode(this.outputBits,!0),G.prototype.finalize.call(this)};var O=function(t){var e,a,i,o,n,r,c,l,s,d,g,f,_,p,h,m,L,w,A,b,y,I,C,F,x,v,E,B,S,G,P,O,U,z,q,Q,M,k,R,N,T,D,K,V,j,H,$,Z,Y,J,W,X,tt,et,at,it,ot,nt,rt,ct,lt,st,dt;for(i=0;i<48;i+=2)o=t[0]^t[10]^t[20]^t[30]^t[40],n=t[1]^t[11]^t[21]^t[31]^t[41],r=t[2]^t[12]^t[22]^t[32]^t[42],c=t[3]^t[13]^t[23]^t[33]^t[43],l=t[4]^t[14]^t[24]^t[34]^t[44],s=t[5]^t[15]^t[25]^t[35]^t[45],d=t[6]^t[16]^t[26]^t[36]^t[46],g=t[7]^t[17]^t[27]^t[37]^t[47],e=(f=t[8]^t[18]^t[28]^t[38]^t[48])^(r<<1|c>>>31),a=(_=t[9]^t[19]^t[29]^t[39]^t[49])^(c<<1|r>>>31),t[0]^=e,t[1]^=a,t[10]^=e,t[11]^=a,t[20]^=e,t[21]^=a,t[30]^=e,t[31]^=a,t[40]^=e,t[41]^=a,e=o^(l<<1|s>>>31),a=n^(s<<1|l>>>31),t[2]^=e,t[3]^=a,t[12]^=e,t[13]^=a,t[22]^=e,t[23]^=a,t[32]^=e,t[33]^=a,t[42]^=e,t[43]^=a,e=r^(d<<1|g>>>31),a=c^(g<<1|d>>>31),t[4]^=e,t[5]^=a,t[14]^=e,t[15]^=a,t[24]^=e,t[25]^=a,t[34]^=e,t[35]^=a,t[44]^=e,t[45]^=a,e=l^(f<<1|_>>>31),a=s^(_<<1|f>>>31),t[6]^=e,t[7]^=a,t[16]^=e,t[17]^=a,t[26]^=e,t[27]^=a,t[36]^=e,t[37]^=a,t[46]^=e,t[47]^=a,e=d^(o<<1|n>>>31),a=g^(n<<1|o>>>31),t[8]^=e,t[9]^=a,t[18]^=e,t[19]^=a,t[28]^=e,t[29]^=a,t[38]^=e,t[39]^=a,t[48]^=e,t[49]^=a,p=t[0],h=t[1],H=t[11]<<4|t[10]>>>28,$=t[10]<<4|t[11]>>>28,B=t[20]<<3|t[21]>>>29,S=t[21]<<3|t[20]>>>29,ct=t[31]<<9|t[30]>>>23,lt=t[30]<<9|t[31]>>>23,D=t[40]<<18|t[41]>>>14,K=t[41]<<18|t[40]>>>14,z=t[2]<<1|t[3]>>>31,q=t[3]<<1|t[2]>>>31,m=t[13]<<12|t[12]>>>20,L=t[12]<<12|t[13]>>>20,Z=t[22]<<10|t[23]>>>22,Y=t[23]<<10|t[22]>>>22,G=t[33]<<13|t[32]>>>19,P=t[32]<<13|t[33]>>>19,st=t[42]<<2|t[43]>>>30,dt=t[43]<<2|t[42]>>>30,et=t[5]<<30|t[4]>>>2,at=t[4]<<30|t[5]>>>2,Q=t[14]<<6|t[15]>>>26,M=t[15]<<6|t[14]>>>26,w=t[25]<<11|t[24]>>>21,A=t[24]<<11|t[25]>>>21,J=t[34]<<15|t[35]>>>17,W=t[35]<<15|t[34]>>>17,O=t[45]<<29|t[44]>>>3,U=t[44]<<29|t[45]>>>3,F=t[6]<<28|t[7]>>>4,x=t[7]<<28|t[6]>>>4,it=t[17]<<23|t[16]>>>9,ot=t[16]<<23|t[17]>>>9,k=t[26]<<25|t[27]>>>7,R=t[27]<<25|t[26]>>>7,b=t[36]<<21|t[37]>>>11,y=t[37]<<21|t[36]>>>11,X=t[47]<<24|t[46]>>>8,tt=t[46]<<24|t[47]>>>8,V=t[8]<<27|t[9]>>>5,j=t[9]<<27|t[8]>>>5,v=t[18]<<20|t[19]>>>12,E=t[19]<<20|t[18]>>>12,nt=t[29]<<7|t[28]>>>25,rt=t[28]<<7|t[29]>>>25,N=t[38]<<8|t[39]>>>24,T=t[39]<<8|t[38]>>>24,I=t[48]<<14|t[49]>>>18,C=t[49]<<14|t[48]>>>18,t[0]=p^~m&w,t[1]=h^~L&A,t[10]=F^~v&B,t[11]=x^~E&S,t[20]=z^~Q&k,t[21]=q^~M&R,t[30]=V^~H&Z,t[31]=j^~$&Y,t[40]=et^~it&nt,t[41]=at^~ot&rt,t[2]=m^~w&b,t[3]=L^~A&y,t[12]=v^~B&G,t[13]=E^~S&P,t[22]=Q^~k&N,t[23]=M^~R&T,t[32]=H^~Z&J,t[33]=$^~Y&W,t[42]=it^~nt&ct,t[43]=ot^~rt&lt,t[4]=w^~b&I,t[5]=A^~y&C,t[14]=B^~G&O,t[15]=S^~P&U,t[24]=k^~N&D,t[25]=R^~T&K,t[34]=Z^~J&X,t[35]=Y^~W&tt,t[44]=nt^~ct&st,t[45]=rt^~lt&dt,t[6]=b^~I&p,t[7]=y^~C&h,t[16]=G^~O&F,t[17]=P^~U&x,t[26]=N^~D&z,t[27]=T^~K&q,t[36]=J^~X&V,t[37]=W^~tt&j,t[46]=ct^~st&et,t[47]=lt^~dt&at,t[8]=I^~p&m,t[9]=C^~h&L,t[18]=O^~F&v,t[19]=U^~x&E,t[28]=D^~z&Q,t[29]=K^~q&M,t[38]=X^~V&H,t[39]=tt^~j&$,t[48]=st^~et&it,t[49]=dt^~at&ot,t[0]^=u[i],t[1]^=u[i+1]};if(n)t.exports=I;else for(F=0;F<C.length;++F)i[C[F]]=I[C[F]]}()}));const{stringifyBigInts:Fo}=$e,{keccak256:xo}=Co;async function vo(t,e,a){const{fd:i,sections:o}=await ua(e,"wtns",2),n=await yi(i,o),{fd:r,sections:c}=await ua(t,"zkey",2),l=await pi(r,c);if("plonk"!=l.protocol)throw new Error("zkey file is not groth16");if(!He.eq(l.r,n.q))throw new Error("Curve of the witness does not match the curve of the proving key");if(n.nWitness!=l.nVars-l.nAdditions)throw new Error(`Invalid witness length. Circuit: ${l.nVars}, witness: ${n.nWitness}, ${l.nAdditions}`);const s=await Ca(l.q),d=s.Fr,u=s.G1,g=s.Fr.n8;a&&a.debug("Reading Wtns");const f=await Aa(i,o,2);f.set(d.zero,0);const _=new fe(g*l.nAdditions);let p,h,m,L,w,A,b,y,I,C,F,x,v,E;await async function(){const t=await Aa(r,c,3),e=8+2*s.Fr.n8;for(let a=0;a<l.nAdditions;a++){const i=Q(t,a*e),o=Q(t,a*e+4),n=t.slice(a*e+8,a*e+8+g),r=t.slice(a*e+8+g,a*e+8+2*g),c=M(i),l=M(o),d=s.Fr.add(s.Fr.mul(n,c),s.Fr.mul(r,l));_.set(d,g*a)}}();let B={};const S=new fe(l.domainSize*g*4*3);let G=c[12][0].p+l.domainSize*g;await r.readToBuffer(S,0,l.domainSize*g*4,G),G+=l.domainSize*g*5,await r.readToBuffer(S,l.domainSize*g*4,l.domainSize*g*4,G),G+=l.domainSize*g*5,await r.readToBuffer(S,l.domainSize*g*8,l.domainSize*g*4,G);const P=new fe(l.domainSize*g);await r.readToBuffer(P,0,l.domainSize*g,c[12][0].p);const O=new fe(l.domainSize*g);await r.readToBuffer(O,0,l.domainSize*g,c[12][0].p+5*l.domainSize*g);const U=await Aa(r,c,14),z={};await async function(){z.b=[];for(let t=1;t<=9;t++)z.b[t]=s.Fr.random();[p,h,m]=await async function(){let t=new fe(l.domainSize*g),e=new fe(l.domainSize*g),a=new fe(l.domainSize*g);const i=await Aa(r,c,4),o=await Aa(r,c,5),n=await Aa(r,c,6);for(let r=0;r<l.nConstrains;r++){const c=Q(i,4*r);t.set(M(c),r*g);const l=Q(o,4*r);e.set(M(l),r*g);const s=Q(n,4*r);a.set(M(s),r*g)}return t=await d.batchToMontgomery(t),e=await d.batchToMontgomery(e),a=await d.batchToMontgomery(a),[t,e,a]}(),[I,w]=await D(p,[z.b[2],z.b[1]]),[C,A]=await D(h,[z.b[4],z.b[3]]),[F,b]=await D(m,[z.b[6],z.b[5]]),B.A=await T(I,"multiexp A"),B.B=await T(C,"multiexp B"),B.C=await T(F,"multiexp C")}(),await async function(){const t=new Uint8Array(2*u.F.n8*3);u.toRprUncompressed(t,0,B.A),u.toRprUncompressed(t,2*u.F.n8,B.B),u.toRprUncompressed(t,4*u.F.n8,B.C),z.beta=k(t),a&&a.debug("beta: "+d.toString(z.beta));const e=new Uint8Array(g);d.toRprBE(e,0,z.beta),z.gamma=k(e),a&&a.debug("gamma: "+d.toString(z.gamma));let i=new fe(d.n8*l.domainSize),o=new fe(d.n8*l.domainSize);i.set(d.one,0),o.set(d.one,0);let n=d.one;for(let t=0;t<l.domainSize;t++){let e=p.slice(t*g,(t+1)*g);e=d.add(e,d.mul(z.beta,n)),e=d.add(e,z.gamma);let a=h.slice(t*g,(t+1)*g);a=d.add(a,d.mul(l.k1,d.mul(z.beta,n))),a=d.add(a,z.gamma);let r=m.slice(t*g,(t+1)*g);r=d.add(r,d.mul(l.k2,d.mul(z.beta,n))),r=d.add(r,z.gamma);const c=d.mul(e,d.mul(a,r));let s=p.slice(t*g,(t+1)*g);s=d.add(s,d.mul(S.slice(t*g*4,t*g*4+g),z.beta)),s=d.add(s,z.gamma);let u=h.slice(t*g,(t+1)*g);u=d.add(u,d.mul(S.slice(4*(l.domainSize+t)*g,4*(l.domainSize+t)*g+g),z.beta)),u=d.add(u,z.gamma);let f=m.slice(t*g,(t+1)*g);f=d.add(f,d.mul(S.slice(4*(2*l.domainSize+t)*g,4*(2*l.domainSize+t)*g+g),z.beta)),f=d.add(f,z.gamma);const _=d.mul(s,d.mul(u,f));i.set(d.mul(i.slice(t*g,(t+1)*g),c),(t+1)%l.domainSize*g),o.set(d.mul(o.slice(t*g,(t+1)*g),_),(t+1)%l.domainSize*g),n=d.mul(n,d.w[l.power])}o=await d.batchInverse(o);for(let t=0;t<l.domainSize;t++)i.set(d.mul(i.slice(t*g,(t+1)*g),o.slice(t*g,(t+1)*g)),t*g);if(!d.eq(i.slice(0,g),d.one))throw new Error("Copy constraints does not match");L=i,[x,y]=await D(L,[z.b[9],z.b[8],z.b[7]]),B.Z=await T(x,"multiexp Z")}(),await async function(){a&&a.debug("phse3: Reading QM4");const t=new fe(4*l.domainSize*g);await r.readToBuffer(t,0,l.domainSize*g*4,c[7][0].p+l.domainSize*g),a&&a.debug("phse3: Reading QL4");const e=new fe(4*l.domainSize*g);await r.readToBuffer(e,0,l.domainSize*g*4,c[8][0].p+l.domainSize*g),a&&a.debug("phse3: Reading QR4");const i=new fe(4*l.domainSize*g);await r.readToBuffer(i,0,l.domainSize*g*4,c[9][0].p+l.domainSize*g),a&&a.debug("phse3: Reading QO4");const o=new fe(4*l.domainSize*g);await r.readToBuffer(o,0,l.domainSize*g*4,c[10][0].p+l.domainSize*g),a&&a.debug("phse3: Reading QC4");const n=new fe(4*l.domainSize*g);await r.readToBuffer(n,0,l.domainSize*g*4,c[11][0].p+l.domainSize*g);const s=await Aa(r,c,13),f=new Uint8Array(2*u.F.n8);u.toRprUncompressed(f,0,B.Z),z.alpha=k(f),a&&a.debug("alpha: "+d.toString(z.alpha));const _=[d.zero,d.add(d.e(-1),d.w[2]),d.e(-2),d.sub(d.e(-1),d.w[2])],h=[d.zero,d.add(d.zero,d.mul(d.e(-2),d.w[2])),d.e(4),d.sub(d.zero,d.mul(d.e(-2),d.w[2]))],m=[d.zero,d.add(d.e(2),d.mul(d.e(2),d.w[2])),d.e(-8),d.sub(d.e(2),d.mul(d.e(2),d.w[2]))],L=new fe(4*l.domainSize*g),I=new fe(4*l.domainSize*g);let C=d.one;for(let r=0;r<4*l.domainSize;r++){r%4096==0&&a&&a.debug(`calculating t ${r}/${4*l.domainSize}`);const c=w.slice(r*g,r*g+g),u=A.slice(r*g,r*g+g),f=b.slice(r*g,r*g+g),_=y.slice(r*g,r*g+g),h=y.slice((r+4*l.domainSize+4)%(4*l.domainSize)*g,(r+4*l.domainSize+4)%(4*l.domainSize)*g+g),m=t.slice(r*g,r*g+g),F=e.slice(r*g,r*g+g),x=i.slice(r*g,r*g+g),v=o.slice(r*g,r*g+g),B=n.slice(r*g,r*g+g),P=S.slice(r*g,r*g+g),O=S.slice((r+4*l.domainSize)*g,(r+4*l.domainSize)*g+g),U=S.slice((r+8*l.domainSize)*g,(r+8*l.domainSize)*g+g),q=d.add(z.b[2],d.mul(z.b[1],C)),Q=d.add(z.b[4],d.mul(z.b[3],C)),M=d.add(z.b[6],d.mul(z.b[5],C)),k=d.square(C),R=d.add(d.add(d.mul(z.b[7],k),d.mul(z.b[8],C)),z.b[9]),N=d.mul(C,d.w[l.power]),T=d.square(N),D=d.add(d.add(d.mul(z.b[7],T),d.mul(z.b[8],N)),z.b[9]);let K=d.zero;for(let t=0;t<l.nPublic;t++)K=d.sub(K,d.mul(s.slice((5*t*l.domainSize+l.domainSize+r)*g,(5*t*l.domainSize+l.domainSize+r+1)*g),p.slice(t*g,(t+1)*g)));let[V,j]=E(c,u,q,Q,r%4);V=d.mul(V,m),j=d.mul(j,m),V=d.add(V,d.mul(c,F)),j=d.add(j,d.mul(q,F)),V=d.add(V,d.mul(u,x)),j=d.add(j,d.mul(Q,x)),V=d.add(V,d.mul(f,v)),j=d.add(j,d.mul(M,v)),V=d.add(V,K),V=d.add(V,B);const H=d.mul(z.beta,C);let $=c;$=d.add($,H),$=d.add($,z.gamma);let Z=u;Z=d.add(Z,d.mul(H,l.k1)),Z=d.add(Z,z.gamma);let Y=f;Y=d.add(Y,d.mul(H,l.k2)),Y=d.add(Y,z.gamma);let J=_,[W,X]=G($,Z,Y,J,q,Q,M,R,r%4);W=d.mul(W,z.alpha),X=d.mul(X,z.alpha);let tt=c;tt=d.add(tt,d.mul(z.beta,P)),tt=d.add(tt,z.gamma);let et=u;et=d.add(et,d.mul(z.beta,O)),et=d.add(et,z.gamma);let at=f;at=d.add(at,d.mul(z.beta,U)),at=d.add(at,z.gamma);let it=h,[ot,nt]=G(tt,et,at,it,q,Q,M,D,r%4);ot=d.mul(ot,z.alpha),nt=d.mul(nt,z.alpha);let rt=d.sub(_,d.one);rt=d.mul(rt,s.slice((l.domainSize+r)*g,(l.domainSize+r+1)*g)),rt=d.mul(rt,d.mul(z.alpha,z.alpha));let ct=d.mul(R,s.slice((l.domainSize+r)*g,(l.domainSize+r+1)*g));ct=d.mul(ct,d.mul(z.alpha,z.alpha));let lt=d.add(d.sub(d.add(V,W),ot),rt),st=d.add(d.sub(d.add(j,X),nt),ct);L.set(lt,r*g),I.set(st,r*g),C=d.mul(C,d.w[l.power+2])}a&&a.debug("ifft T");let F=await d.ifft(L);a&&a.debug("dividing T/Z");for(let t=0;t<l.domainSize;t++)F.set(d.neg(F.slice(t*g,t*g+g)),t*g);for(let t=l.domainSize;t<4*l.domainSize;t++){const e=d.sub(F.slice((t-l.domainSize)*g,(t-l.domainSize)*g+g),F.slice(t*g,t*g+g));if(F.set(e,t*g),t>3*l.domainSize-4&&!d.isZero(e))throw new Error("T Polynomial is not divisible")}a&&a.debug("ifft Tz");const x=await d.ifft(I);for(let t=0;t<4*l.domainSize;t++){const e=x.slice(t*g,(t+1)*g);if(t>3*l.domainSize+5){if(!d.isZero(e))throw new Error("Tz Polynomial is not well calculated")}else F.set(d.add(F.slice(t*g,(t+1)*g),e),t*g)}function E(t,e,a,i,o){let n,r;const c=d.mul(t,e),l=d.mul(t,i),s=d.mul(a,e);n=c;let u=d.mul(a,i);return r=d.add(l,s),o&&(r=d.add(r,d.mul(_[o],u))),[n,r]}function G(t,e,a,i,o,n,r,c,l){let s,u;const g=d.mul(t,e),f=d.mul(t,n),p=d.mul(o,e),L=d.mul(o,n),w=d.mul(a,i),A=d.mul(a,c),b=d.mul(r,i),y=d.mul(r,c);s=d.mul(g,w);let I=d.mul(p,w);I=d.add(I,d.mul(f,w)),I=d.add(I,d.mul(g,b)),I=d.add(I,d.mul(g,A));let C=d.mul(L,w);C=d.add(C,d.mul(p,b)),C=d.add(C,d.mul(p,A)),C=d.add(C,d.mul(f,b)),C=d.add(C,d.mul(f,A)),C=d.add(C,d.mul(g,y));let F=d.mul(f,y);F=d.add(F,d.mul(p,y)),F=d.add(F,d.mul(L,A)),F=d.add(F,d.mul(L,b));let x=d.mul(L,y);return u=I,l&&(u=d.add(u,d.mul(_[l],C)),u=d.add(u,d.mul(h[l],F)),u=d.add(u,d.mul(m[l],x))),[s,u]}v=F.slice(0,(3*l.domainSize+6)*g),B.T1=await T(F.slice(0,l.domainSize*g),"multiexp T1"),B.T2=await T(F.slice(l.domainSize*g,2*l.domainSize*g),"multiexp T2"),B.T3=await T(F.slice(2*l.domainSize*g,(3*l.domainSize+6)*g),"multiexp T3")}(),await async function(){const t=new fe(l.domainSize*g);await r.readToBuffer(t,0,l.domainSize*g,c[7][0].p);const e=new fe(l.domainSize*g);await r.readToBuffer(e,0,l.domainSize*g,c[8][0].p);const i=new fe(l.domainSize*g);await r.readToBuffer(i,0,l.domainSize*g,c[9][0].p);const o=new fe(l.domainSize*g);await r.readToBuffer(o,0,l.domainSize*g,c[10][0].p);const n=new fe(l.domainSize*g);await r.readToBuffer(n,0,l.domainSize*g,c[11][0].p);const s=new fe(l.domainSize*g);await r.readToBuffer(s,0,l.domainSize*g,c[12][0].p+10*l.domainSize*g);const f=new Uint8Array(2*u.F.n8*3);u.toRprUncompressed(f,0,B.T1),u.toRprUncompressed(f,2*u.F.n8,B.T2),u.toRprUncompressed(f,4*u.F.n8,B.T3),z.xi=k(f),a&&a.debug("xi: "+d.toString(z.xi));B.eval_a=R(I,z.xi),B.eval_b=R(C,z.xi),B.eval_c=R(F,z.xi),B.eval_s1=R(P,z.xi),B.eval_s2=R(O,z.xi),B.eval_t=R(v,z.xi),B.eval_zw=R(x,d.mul(z.xi,d.w[l.power]));const _=d.mul(B.eval_a,B.eval_b);let p=B.eval_a;const h=d.mul(z.beta,z.xi);p=d.add(p,h),p=d.add(p,z.gamma);let m=B.eval_b;m=d.add(m,d.mul(h,l.k1)),m=d.add(m,z.gamma);let L=B.eval_c;L=d.add(L,d.mul(h,l.k2)),L=d.add(L,z.gamma);const w=d.mul(d.mul(d.mul(p,m),L),z.alpha);let A=B.eval_a;A=d.add(A,d.mul(z.beta,B.eval_s1)),A=d.add(A,z.gamma);let b=B.eval_b;b=d.add(b,d.mul(z.beta,B.eval_s2)),b=d.add(b,z.gamma);let y=d.mul(A,b);y=d.mul(y,z.beta),y=d.mul(y,B.eval_zw),y=d.mul(y,z.alpha),z.xim=z.xi;for(let t=0;t<l.power;t++)z.xim=d.mul(z.xim,z.xim);const S=d.div(d.sub(z.xim,d.one),d.mul(d.sub(z.xi,d.one),d.e(l.domainSize))),G=d.mul(S,d.mul(z.alpha,z.alpha)),U=y,q=d.add(w,G);E=new fe((l.domainSize+3)*g);for(let a=0;a<l.domainSize+3;a++){let r=d.mul(q,x.slice(a*g,(a+1)*g));a<l.domainSize&&(r=d.add(r,d.mul(_,t.slice(a*g,(a+1)*g))),r=d.add(r,d.mul(B.eval_a,e.slice(a*g,(a+1)*g))),r=d.add(r,d.mul(B.eval_b,i.slice(a*g,(a+1)*g))),r=d.add(r,d.mul(B.eval_c,o.slice(a*g,(a+1)*g))),r=d.add(r,n.slice(a*g,(a+1)*g)),r=d.sub(r,d.mul(U,s.slice(a*g,(a+1)*g)))),E.set(r,a*g)}B.eval_r=R(E,z.xi)}(),await async function(){const t=new Uint8Array(7*g);d.toRprBE(t,0,B.eval_a),d.toRprBE(t,g,B.eval_b),d.toRprBE(t,2*g,B.eval_c),d.toRprBE(t,3*g,B.eval_s1),d.toRprBE(t,4*g,B.eval_s2),d.toRprBE(t,5*g,B.eval_zw),d.toRprBE(t,6*g,B.eval_r),z.v=[],z.v[1]=k(t),a&&a.debug("v: "+d.toString(z.v[1]));for(let t=2;t<=6;t++)z.v[t]=d.mul(z.v[t-1],z.v[1]);let e=new fe((l.domainSize+6)*g);const i=d.mul(z.xim,z.xim);for(let t=0;t<l.domainSize+6;t++){let a=d.zero;a=d.add(a,d.mul(i,v.slice((2*l.domainSize+t)*g,(2*l.domainSize+t+1)*g))),t<l.domainSize+3&&(a=d.add(a,d.mul(z.v[1],E.slice(t*g,(t+1)*g)))),t<l.domainSize+2&&(a=d.add(a,d.mul(z.v[2],I.slice(t*g,(t+1)*g))),a=d.add(a,d.mul(z.v[3],C.slice(t*g,(t+1)*g))),a=d.add(a,d.mul(z.v[4],F.slice(t*g,(t+1)*g)))),t<l.domainSize&&(a=d.add(a,v.slice(t*g,(t+1)*g)),a=d.add(a,d.mul(z.xim,v.slice((l.domainSize+t)*g,(l.domainSize+t+1)*g))),a=d.add(a,d.mul(z.v[5],P.slice(t*g,(t+1)*g))),a=d.add(a,d.mul(z.v[6],O.slice(t*g,(t+1)*g)))),e.set(a,t*g)}let o=e.slice(0,g);o=d.sub(o,B.eval_t),o=d.sub(o,d.mul(z.v[1],B.eval_r)),o=d.sub(o,d.mul(z.v[2],B.eval_a)),o=d.sub(o,d.mul(z.v[3],B.eval_b)),o=d.sub(o,d.mul(z.v[4],B.eval_c)),o=d.sub(o,d.mul(z.v[5],B.eval_s1)),o=d.sub(o,d.mul(z.v[6],B.eval_s2)),e.set(o,0),e=N(e,z.xi),B.Wxi=await T(e,"multiexp Wxi");let n=new fe((l.domainSize+3)*g);for(let t=0;t<l.domainSize+3;t++){const e=x.slice(t*g,(t+1)*g);n.set(e,t*g)}o=n.slice(0,g),o=d.sub(o,B.eval_zw),n.set(o,0),n=N(n,d.mul(z.xi,d.w[l.power])),B.Wxiw=await T(n,"multiexp Wxiw")}(),B.protocol="plonk",B.curve=s.name,await r.close(),await i.close();let q=[];for(let t=1;t<=l.nPublic;t++){const e=f.slice(t*d.n8,t*d.n8+d.n8);q.push(He.fromRprLE(e))}return B.A=u.toObject(B.A),B.B=u.toObject(B.B),B.C=u.toObject(B.C),B.Z=u.toObject(B.Z),B.T1=u.toObject(B.T1),B.T2=u.toObject(B.T2),B.T3=u.toObject(B.T3),B.eval_a=d.toObject(B.eval_a),B.eval_b=d.toObject(B.eval_b),B.eval_c=d.toObject(B.eval_c),B.eval_s1=d.toObject(B.eval_s1),B.eval_s2=d.toObject(B.eval_s2),B.eval_zw=d.toObject(B.eval_zw),B.eval_t=d.toObject(B.eval_t),B.eval_r=d.toObject(B.eval_r),B.Wxi=u.toObject(B.Wxi),B.Wxiw=u.toObject(B.Wxiw),delete B.eval_t,B=Fo(B),q=Fo(q),{proof:B,publicSignals:q};function Q(t,e){const a=t.slice(e,e+4);return new DataView(a.buffer,a.byteOffset,a.byteLength).getUint32(0,!0)}function M(t){return t<l.nVars-l.nAdditions?f.slice(t*g,t*g+g):t<l.nVars?_.slice((t-(l.nVars-l.nAdditions))*g,(t-(l.nVars-l.nAdditions))*g+g):s.Fr.zero}function k(t){const e=He.fromRprBE(new Uint8Array(xo.arrayBuffer(t)));return d.e(e)}function R(t,e){const a=t.byteLength/g;if(0==a)return d.zero;let i=t.slice((a-1)*g,a*g);for(let o=a-2;o>=0;o--)i=d.add(d.mul(i,e),t.slice(o*g,(o+1)*g));return i}function N(t,e){const a=t.byteLength/g,i=new fe(a*g);i.set(d.zero,(a-1)*g),i.set(t.slice((a-1)*g,a*g),(a-2)*g);for(let o=a-3;o>=0;o--)i.set(d.add(t.slice((o+1)*g,(o+2)*g),d.mul(e,i.slice((o+1)*g,(o+2)*g))),o*g);if(!d.eq(t.slice(0,g),d.mul(d.neg(e),i.slice(0,g))))throw new Error("Polinomial does not divide");return i}async function T(t,e){const i=t.byteLength/g,o=U.slice(0,i*s.G1.F.n8*2),n=await s.Fr.batchFromMontgomery(t);let r=await s.G1.multiExpAffine(o,n,a,e);return r=s.G1.toAffine(r),r}async function D(t,e){e=e||[];let a=await d.ifft(t);const i=new fe(g*l.domainSize*4);i.set(a,0);const o=new fe(g*(l.domainSize+e.length));o.set(a,0);for(let t=0;t<e.length;t++)o.set(d.add(o.slice((l.domainSize+t)*g,(l.domainSize+t+1)*g),e[t]),(l.domainSize+t)*g),o.set(d.sub(o.slice(t*g,(t+1)*g),e[t]),t*g);return[o,await d.fft(i)]}}const{unstringifyBigInts:Eo}=$e,{keccak256:Bo}=Co;function So(t,e){const a=He.fromRprBE(new Uint8Array(Bo.arrayBuffer(e)));return t.Fr.e(a)}function Go(t){return("0"+t.toString(16)).slice(-2)}function Po(t){let e=t.toString(16);for(;e.length<64;)e="0"+e;return e=`"0x${e}"`,e}var Oo=Object.freeze({__proto__:null,setup:async function(t,e,a,i){await Wa.ready();const{fd:o,sections:n}=await ua(e,"ptau",1),{curve:r,power:c}=await Ri(o,n),{fd:l,sections:s}=await ua(t,"r1cs",1),d=await oo(l,s,!1),u=2*r.G1.F.n8,g=r.G1,f=2*r.G2.F.n8,_=r.Fr,p=r.Fr.n8;i&&i.info("Reading r1cs");let h=await Aa(l,s,2);const m=new ho,L=new ho;let w=d.nVars;const A=d.nOutputs+d.nPubInputs;await async function(){let t=0;function e(){const e=h.slice(t,t+4);t+=4;return new DataView(e.buffer).getUint32(0,!0)}function a(){const e=_.fromRprLE(h.slice(t,t+r.Fr.n8));return t+=r.Fr.n8,e}function o(){const t=[],i={k:r.Fr.zero},o=e();for(let n=0;n<o;n++){const o=e(),n=a();0==o?i.k=n:t.push([o,n])}const c=n(t);return i.s=c[0],i.coef=c[1],i}function n(t){if(0==t.length)return[0,r.Fr.zero];if(1==t.length)return t[0];const e=t.slice(0,t.length>>1),a=t.slice(t.length>>1),i=n(e),o=n(a),c=i[0],l=o[0],s=w++,d=r.Fr.zero,u=_.neg(i[1]),g=_.neg(o[1]),f=r.Fr.one,p=r.Fr.zero;return m.push([c,l,s,d,u,g,f,p]),L.push([c,l,i[1],o[1]]),[s,r.Fr.one]}for(let t=1;t<=A;t++){const e=t,a=0,i=0,o=r.Fr.zero,n=r.Fr.one,c=r.Fr.zero,l=r.Fr.zero,s=r.Fr.zero;m.push([e,a,i,o,n,c,l,s])}for(let t=0;t<d.nConstraints;t++){i&&t%1e4==0&&i.debug(`processing constraints: ${t}/${d.nConstraints}`);const e=o(),a=o(),n=o(),c=e.s,l=a.s,s=n.s,u=r.Fr.mul(e.coef,a.coef),g=r.Fr.mul(e.coef,a.k),f=r.Fr.mul(e.k,a.coef),_=r.Fr.neg(n.coef),p=r.Fr.sub(r.Fr.mul(e.k,a.k),n.k);m.push([c,l,s,u,g,f,_,p])}}();const b=await ga(a,"zkey",1,14,1<<22,1<<24);if(d.prime!=r.r)return i&&i.error("r1cs curve does not match powers of tau ceremony curve"),-1;let y=ei(m.length-1)+1;y<3&&(y=3);const I=2**y;if(i&&i.info("Plonk constraints: "+m.length),y>c)return i&&i.error(`circuit too big for this power of tau ceremony. ${m.length} > 2**${c}`),-1;if(!n[12])return i&&i.error("Powers of tau is not prepared."),-1;const C=new fe(I*u),F=n[12][0].p+(2**y-1)*u;await o.readToBuffer(C,0,I*u,F);const[x,v]=function(){let t=_.two;for(;a(t,[],y);)_.add(t,_.one);let e=_.add(t,_.one);for(;a(e,[t],y);)_.add(e,_.one);return[t,e];function a(t,e,a){const i=2**a;let o=_.one;for(let n=0;n<i;n++){if(_.eq(t,o))return!0;for(let a=0;a<e.length;a++)if(_.eq(t,_.mul(e[a],o)))return!0;o=_.mul(o,_.w[a])}return!1}}(),E={};await async function(t,e){await fa(b,t);const a=new Uint8Array(8+2*p),o=new DataView(a.buffer);for(let t=0;t<L.length;t++){const n=L[t];let r=0;o.setUint32(r,n[0],!0),r+=4,o.setUint32(r,n[1],!0),r+=4,a.set(n[2],r),r+=p,a.set(n[3],r),r+=p,await b.write(a),i&&t%1e6==0&&i.debug(`writing ${e}: ${t}/${L.length}`)}await _a(b)}(3,"Additions"),await S(4,0,"Amap"),await S(5,1,"Bmap"),await S(6,2,"Cmap"),await G(7,3,"Qm"),await G(8,4,"Ql"),await G(9,5,"Qr"),await G(10,6,"Qo"),await G(11,7,"Qc"),await async function(t,e){const a=new fe(p*I*3),o=new ho(w),n=new ho(w);let c=_.one;for(let t=0;t<I;t++)t<m.length?(u(m[t][0],t),u(m[t][1],I+t),u(m[t][2],2*I+t)):(u(0,t),u(0,I+t),u(0,2*I+t)),c=_.mul(c,_.w[y]),i&&t%1e6==0&&i.debug(`writing ${e} phase1: ${t}/${m.length}`);for(let t=0;t<w;t++){if(void 0===n[t])throw new Error("Variable not used");a.set(o[t],n[t]*p),i&&t%1e6==0&&i.debug(`writing ${e} phase2: ${t}/${w}`)}await fa(b,t);let l=a.slice(0,I*p);await P(l);let s=a.slice(I*p,I*p*2);await P(s);let d=a.slice(I*p*2,I*p*3);function u(t,e){let i;void 0===o[t]?n[t]=e:a.set(o[t],e*p),i=e<I?c:e<2*I?_.mul(c,x):_.mul(c,v),o[t]=i}await P(d),await _a(b),l=await _.batchFromMontgomery(l),s=await _.batchFromMontgomery(s),d=await _.batchFromMontgomery(d),E.S1=await r.G1.multiExpAffine(C,l,i,"multiexp S1"),E.S2=await r.G1.multiExpAffine(C,s,i,"multiexp S2"),E.S3=await r.G1.multiExpAffine(C,d,i,"multiexp S3")}(12,"sigma"),await async function(t,e){await fa(b,t);const a=Math.max(A,1);for(let t=0;t<a;t++){let o=new fe(I*p);o.set(_.one,t*p),await P(o),i&&i.debug(`writing ${e} ${t}/${a}`)}await _a(b)}(13,"lagrange polynomials"),await fa(b,14);const B=new fe((I+6)*u);return await o.readToBuffer(B,0,(I+6)*u,n[2][0].p),await b.write(B),await _a(b),await async function(){await fa(b,1),await b.writeULE32(2),await _a(b),await fa(b,2);const t=r.q,e=8*(Math.floor((He.bitLength(t)-1)/64)+1),a=r.r,i=8*(Math.floor((He.bitLength(a)-1)/64)+1);let c;await b.writeULE32(e),await ma(b,t,e),await b.writeULE32(i),await ma(b,a,i),await b.writeULE32(w),await b.writeULE32(A),await b.writeULE32(I),await b.writeULE32(L.length),await b.writeULE32(m.length),await b.write(x),await b.write(v),await b.write(g.toAffine(E.Qm)),await b.write(g.toAffine(E.Ql)),await b.write(g.toAffine(E.Qr)),await b.write(g.toAffine(E.Qo)),await b.write(g.toAffine(E.Qc)),await b.write(g.toAffine(E.S1)),await b.write(g.toAffine(E.S2)),await b.write(g.toAffine(E.S3)),c=await o.read(f,n[3][0].p+f),await b.write(c),await _a(b)}(),await b.close(),await l.close(),await o.close(),void(i&&i.info("Setup Finished"));async function S(t,e,a){await fa(b,t);for(let t=0;t<m.length;t++)await b.writeULE32(m[t][e]),i&&t%1e6==0&&i.debug(`writing ${a}: ${t}/${m.length}`);await _a(b)}async function G(t,e,a){let o=new fe(I*p);for(let t=0;t<m.length;t++)o.set(m[t][e],t*p),i&&t%1e6==0&&i.debug(`writing ${a}: ${t}/${m.length}`);await fa(b,t),await P(o),await _a(b),o=await _.batchFromMontgomery(o),E[a]=await r.G1.multiExpAffine(C,o,i,"multiexp "+a)}async function P(t){const e=await _.ifft(t),a=new fe(I*p*4);a.set(e,0);const i=await _.fft(a);await b.write(e),await b.write(i)}},fullProve:async function(t,e,a,i){const o={type:"mem"};return await Gi(t,e,o),await vo(a,o,i)},prove:vo,verify:async function(t,e,a,i){t=Eo(t),a=Eo(a),e=Eo(e);const o=await Fa(t.curve),n=o.Fr,r=o.G1;if(a=function(t,e){const a=t.G1,i=t.Fr,o={};return o.A=a.fromObject(e.A),o.B=a.fromObject(e.B),o.C=a.fromObject(e.C),o.Z=a.fromObject(e.Z),o.T1=a.fromObject(e.T1),o.T2=a.fromObject(e.T2),o.T3=a.fromObject(e.T3),o.eval_a=i.fromObject(e.eval_a),o.eval_b=i.fromObject(e.eval_b),o.eval_c=i.fromObject(e.eval_c),o.eval_zw=i.fromObject(e.eval_zw),o.eval_s1=i.fromObject(e.eval_s1),o.eval_s2=i.fromObject(e.eval_s2),o.eval_r=i.fromObject(e.eval_r),o.Wxi=a.fromObject(e.Wxi),o.Wxiw=a.fromObject(e.Wxiw),o}(o,a),t=function(t,e){const a=t.G1,i=t.G2,o=t.Fr,n=e;return n.Qm=a.fromObject(e.Qm),n.Ql=a.fromObject(e.Ql),n.Qr=a.fromObject(e.Qr),n.Qo=a.fromObject(e.Qo),n.Qc=a.fromObject(e.Qc),n.S1=a.fromObject(e.S1),n.S2=a.fromObject(e.S2),n.S3=a.fromObject(e.S3),n.k1=o.fromObject(e.k1),n.k2=o.fromObject(e.k2),n.X_2=i.fromObject(e.X_2),n}(o,t),!function(t,e){const a=t.G1;return!!a.isValid(e.A)&&(!!a.isValid(e.B)&&(!!a.isValid(e.C)&&(!!a.isValid(e.Z)&&(!!a.isValid(e.T1)&&(!!a.isValid(e.T2)&&(!!a.isValid(e.T3)&&(!!a.isValid(e.Wxi)&&!!a.isValid(e.Wxiw))))))))}(o,a))return i.error("Proof is not well constructed"),!1;const c=function(t,e){const a=t.G1,i=t.Fr,o=t.Fr.n8,n={},r=new Uint8Array(2*a.F.n8*3);a.toRprUncompressed(r,0,e.A),a.toRprUncompressed(r,2*a.F.n8,e.B),a.toRprUncompressed(r,4*a.F.n8,e.C),n.beta=So(t,r);const c=new Uint8Array(o);i.toRprBE(c,0,n.beta),n.gamma=So(t,c);const l=new Uint8Array(2*a.F.n8);a.toRprUncompressed(l,0,e.Z),n.alpha=So(t,l);const s=new Uint8Array(2*a.F.n8*3);a.toRprUncompressed(s,0,e.T1),a.toRprUncompressed(s,2*a.F.n8,e.T2),a.toRprUncompressed(s,4*a.F.n8,e.T3),n.xi=So(t,s);const d=new Uint8Array(7*o);i.toRprBE(d,0,e.eval_a),i.toRprBE(d,o,e.eval_b),i.toRprBE(d,2*o,e.eval_c),i.toRprBE(d,3*o,e.eval_s1),i.toRprBE(d,4*o,e.eval_s2),i.toRprBE(d,5*o,e.eval_zw),i.toRprBE(d,6*o,e.eval_r),n.v=[],n.v[1]=So(t,d);for(let t=2;t<=6;t++)n.v[t]=i.mul(n.v[t-1],n.v[1]);const u=new Uint8Array(2*a.F.n8*2);return a.toRprUncompressed(u,0,e.Wxi),a.toRprUncompressed(u,2*a.F.n8,e.Wxiw),n.u=So(t,u),n}(o,a);i&&(i.debug("beta: "+n.toString(c.beta,16)),i.debug("gamma: "+n.toString(c.gamma,16)),i.debug("alpha: "+n.toString(c.alpha,16)),i.debug("xi: "+n.toString(c.xi,16)),i.debug("v1: "+n.toString(c.v[1],16)),i.debug("v6: "+n.toString(c.v[6],16)),i.debug("u: "+n.toString(c.u,16)));const l=function(t,e,a){const i=t.Fr;let o=e.xi,n=1;for(let t=0;t<a.power;t++)o=i.square(o),n*=2;e.xin=o,e.zh=i.sub(o,i.one);const r=[],c=i.e(n);let l=i.one;for(let t=1;t<=Math.max(1,a.nPublic);t++)r[t]=i.div(i.mul(l,e.zh),i.mul(c,i.sub(e.xi,l))),l=i.mul(l,i.w[a.power]);return r}(o,c,t);if(i){i.debug("Lagrange Evaluations: ");for(let t=1;t<l.length;t++)i.debug(`L${t}(xi)=`+n.toString(l[t],16))}if(e.length!=t.nPublic)return i.error("Number of public signals does not match with vk"),!1;const s=function(t,e,a){const i=t.Fr;let o=i.zero;for(let t=0;t<e.length;t++){const n=i.e(e[t]);o=i.sub(o,i.mul(n,a[t+1]))}return o}(o,e,l);i&&i.debug("Pl: "+n.toString(s,16));const d=function(t,e,a,i,o){const n=t.Fr;let r=e.eval_r;r=n.add(r,i);let c=e.eval_a;c=n.add(c,n.mul(a.beta,e.eval_s1)),c=n.add(c,a.gamma);let l=e.eval_b;l=n.add(l,n.mul(a.beta,e.eval_s2)),l=n.add(l,a.gamma);let s=e.eval_c;s=n.add(s,a.gamma);let d=n.mul(n.mul(c,l),s);d=n.mul(d,e.eval_zw),d=n.mul(d,a.alpha),r=n.sub(r,d),r=n.sub(r,n.mul(o,n.square(a.alpha)));return n.div(r,a.zh)}(o,a,c,s,l[1]);i&&i.debug("t: "+n.toString(d,16));const u=function(t,e,a,i,o){const n=t.G1,r=t.Fr;let c=r.mul(r.mul(e.eval_a,e.eval_b),a.v[1]),l=n.timesFr(i.Qm,c),s=r.mul(e.eval_a,a.v[1]);l=n.add(l,n.timesFr(i.Ql,s));let d=r.mul(e.eval_b,a.v[1]);l=n.add(l,n.timesFr(i.Qr,d));let u=r.mul(e.eval_c,a.v[1]);l=n.add(l,n.timesFr(i.Qo,u)),l=n.add(l,n.timesFr(i.Qc,a.v[1]));const g=r.mul(a.beta,a.xi);let f=e.eval_a;f=r.add(f,g),f=r.add(f,a.gamma);let _=e.eval_b;_=r.add(_,r.mul(g,i.k1)),_=r.add(_,a.gamma);let p=e.eval_c;p=r.add(p,r.mul(g,i.k2)),p=r.add(p,a.gamma);let h=r.mul(r.mul(f,_),p);h=r.mul(h,r.mul(a.alpha,a.v[1]));let m=r.mul(r.mul(o,r.square(a.alpha)),a.v[1]);h=r.add(h,m),h=r.add(h,a.u),l=n.add(l,n.timesFr(e.Z,h));let L=e.eval_a;L=r.add(L,r.mul(a.beta,e.eval_s1)),L=r.add(L,a.gamma);let w=e.eval_b;w=r.add(w,r.mul(a.beta,e.eval_s2)),w=r.add(w,a.gamma);let A=r.mul(L,w);return A=r.mul(A,a.alpha),A=r.mul(A,a.v[1]),A=r.mul(A,a.beta),A=r.mul(A,e.eval_zw),l=n.sub(l,n.timesFr(i.S3,A)),l}(o,a,c,t,l[1]);i&&i.debug("D: "+r.toString(r.toAffine(u),16));const g=function(t,e,a,i,o){const n=t.G1,r=t.Fr;let c=e.T1;return c=n.add(c,n.timesFr(e.T2,a.xin)),c=n.add(c,n.timesFr(e.T3,r.square(a.xin))),c=n.add(c,o),c=n.add(c,n.timesFr(e.A,a.v[2])),c=n.add(c,n.timesFr(e.B,a.v[3])),c=n.add(c,n.timesFr(e.C,a.v[4])),c=n.add(c,n.timesFr(i.S1,a.v[5])),c=n.add(c,n.timesFr(i.S2,a.v[6])),c}(o,a,c,t,u);i&&i.debug("F: "+r.toString(r.toAffine(g),16));const f=function(t,e,a,i,o){const n=t.G1,r=t.Fr;let c=o;c=r.add(c,r.mul(a.v[1],e.eval_r)),c=r.add(c,r.mul(a.v[2],e.eval_a)),c=r.add(c,r.mul(a.v[3],e.eval_b)),c=r.add(c,r.mul(a.v[4],e.eval_c)),c=r.add(c,r.mul(a.v[5],e.eval_s1)),c=r.add(c,r.mul(a.v[6],e.eval_s2)),c=r.add(c,r.mul(a.u,e.eval_zw));return n.timesFr(n.one,c)}(o,a,c,0,d);i&&i.debug("E: "+r.toString(r.toAffine(f),16));const _=await async function(t,e,a,i,o,n){const r=t.G1,c=t.Fr;let l=e.Wxi;l=r.add(l,r.timesFr(e.Wxiw,a.u));let s=r.timesFr(e.Wxi,a.xi);const d=c.mul(c.mul(a.u,a.xi),c.w[i.power]);s=r.add(s,r.timesFr(e.Wxiw,d)),s=r.add(s,n),s=r.sub(s,o);return await t.pairingEq(r.neg(l),i.X_2,s,t.G2.one)}(o,a,c,t,f,g);return i&&(_?i.info("OK!"):i.warn("Invalid Proof")),_},exportSolidityCallData:async function(t,e){const a=await Fa(t.curve),i=a.G1,o=a.Fr;let n="";for(let t=0;t<e.length;t++)""!=n&&(n+=","),n+=Po(e[t]);const r=new Uint8Array(2*i.F.n8*9+7*o.n8);return i.toRprUncompressed(r,0,i.e(t.A)),i.toRprUncompressed(r,2*i.F.n8,i.e(t.B)),i.toRprUncompressed(r,4*i.F.n8,i.e(t.C)),i.toRprUncompressed(r,6*i.F.n8,i.e(t.Z)),i.toRprUncompressed(r,8*i.F.n8,i.e(t.T1)),i.toRprUncompressed(r,10*i.F.n8,i.e(t.T2)),i.toRprUncompressed(r,12*i.F.n8,i.e(t.T3)),i.toRprUncompressed(r,14*i.F.n8,i.e(t.Wxi)),i.toRprUncompressed(r,16*i.F.n8,i.e(t.Wxiw)),o.toRprBE(r,18*i.F.n8,o.e(t.eval_a)),o.toRprBE(r,18*i.F.n8+o.n8,o.e(t.eval_b)),o.toRprBE(r,18*i.F.n8+2*o.n8,o.e(t.eval_c)),o.toRprBE(r,18*i.F.n8+3*o.n8,o.e(t.eval_s1)),o.toRprBE(r,18*i.F.n8+4*o.n8,o.e(t.eval_s2)),o.toRprBE(r,18*i.F.n8+5*o.n8,o.e(t.eval_zw)),o.toRprBE(r,18*i.F.n8+6*o.n8,o.e(t.eval_r)),"0x"+Array.from(r).map(Go).join("")+",["+n+"]"}});return t.groth16=Ui,t.plonk=Oo,t.powersOfTau=Xi,t.r1cs=so,t.wtns=go,t.zKey=Io,Object.defineProperty(t,"__esModule",{value:!0}),t}({});