varbigintCryptoUtils=function(exports){"use strict";const_ZERO=BigInt(0);const_ONE=BigInt(1);const_TWO=BigInt(2);functionabs(a){a=BigInt(a);returna>=_ZERO?a:-a}functionbitLength(a){a=BigInt(a);if(a===_ONE){return1}letbits=1;do{bits++}while((a>>=_ONE)>_ONE);returnbits}functioneGcd(a,b){a=BigInt(a);b=BigInt(b);if(a<=_ZERO|b<=_ZERO){returnNaN}letx=_ZERO;lety=_ONE;letu=_ONE;letv=_ZERO;while(a!==_ZERO){constq=b/a;constr=b%a;constm=x-u*q;constn=y-v*q;b=a;a=r;x=u;y=v;u=m;v=n}return{b:b,x:x,y:y}}functiongcd(a,b){a=abs(a);b=abs(b);if(a===_ZERO){returnb}elseif(b===_ZERO){returna}letshift=_ZERO;while(!((a|b)&_ONE)){a>>=_ONE;b>>=_ONE;shift++}while(!(a&_ONE))a>>=_ONE;do{while(!(b&_ONE))b>>=_ONE;if(a>b){constx=a;a=b;b=x}b-=a}while(b);returna<<shift}asyncfunctionisProbablyPrime(w,iterations=16){if(typeofw==="number"){w=BigInt(w)}{returnnewPromise((resolve,reject)=>{constworker=newWorker(_isProbablyPrimeWorkerUrl());worker.onmessage=event=>{worker.terminate();resolve(event.data.isPrime)};worker.onmessageerror=event=>{reject(event)};worker.postMessage({rnd:w,iterations:iterations,id:0})})}}functionlcm(a,b){a=BigInt(a);b=BigInt(b);if(a===_ZERO&&b===_ZERO){return_ZERO}returnabs(a*b)/gcd(a,b)}functionmax(a,b){a=BigInt(a);b=BigInt(b);returna>=b?a:b}functionmin(a,b){a=BigInt(a);b=BigInt(b);returna>=b?b:a}functionmodInv(a,n){constegcd=eGcd(toZn(a,n),n);if(egcd.b!==_ONE){returnNaN}else{returntoZn(egcd.x,n)}}functionmodPow(b,e,n){n=BigInt(n);if(n===_ZERO){returnNaN}elseif(n===_ONE){return_ZERO}b=toZn(b,n);e=BigInt(e);if(e<_ZERO){returnmodInv(modPow(b,abs(e),n),n)}letr=_ONE;while(e>0){if(e%_TWO===_ONE){r=r*b%n}e=e/_TWO;b=b**_TWO%n}returnr}functionprime(bitLength,iterations=16){if(bitLength<1){thrownewRangeError(`bitLength MUST be > 0 and it is ${bitLength}`)}returnnewPromise(resolve=>{constworkerList=[];const_onmessage=(msg,newWorker)=>{if(msg.isPrime){for(letj=0;j<workerList.length;j++){workerList[j].terminate()}while(workerList.length){workerList.pop()}resolve(msg.value)}else{constbuf=randBits(bitLength,true);constrnd=fromBuffer(buf);try{newWorker.postMessage({rnd:rnd,iterations:iterations,id:msg.id})}catch(error){}}};{constworkerURL=_isProbablyPrimeWorkerUrl();for(leti=0;i<self.navigator.hardwareConcurrency;i++){constnewWorker=newWorker(workerURL);newWorker.onmessage=event=>_onmessage(event.data,newWorker);workerList.push(newWorker)}}for(leti=0;i<workerList.length;i++){constbuf=randBits(bitLength,true);constrnd=fromBuffer(buf);workerList[i].postMessage({rnd:rnd,iterations:iterations,id:i})}})}functionprimeSync(bitLength,iterations=16){if(bitLength<1){thrownewRangeError(`bitLength MUST be > 0 and it is ${bitLength}`)}letrnd=_ZERO;do{rnd=fromBuffer(randBytesSync(bitLength/8,true))}while(!_isProbablyPrime(rnd,iterations));returnrnd}functionrandBetween(max,min=_ONE){if(max<=min)thrownewError("max must be > min");constinterval=max-min;constbitLen=bitLength(interval);letrnd;do{constbuf=randBits(bitLen);rnd=fromBuffer(buf)}while(rnd>interval);returnrnd+min}functionrandBits(bitLength,forceLength=false){if(bitLength<1){thrownewRangeError(`bitLength MUST be > 0 and it is ${bitLength}`)}constbyteLength=Math.ceil(bitLength/8);constrndBytes=randBytesSync(byteLength,false);constbitLengthMod8=bitLength%8;if(bitLengthMod8){rndBytes[0]=rndBytes[0]&2**bitLengthMod8-1}if(forceLength){constmask=bitLengthMod8?2**(bitLengthMod8-1):128;rndBytes[0]=rndBytes[0]|mask}returnrndBytes}functionrandBytes(byteLength,forceLength=false){if(byteLength<1){thrownewRangeError(`byteLength MUST be > 0 and it is ${byteLength}`)}letbuf;{returnnewPromise((function(resolve){buf=newUint8Array(byteLength);self.crypto.getRandomValues(buf);if(forceLength){buf[0]=buf[0]|128}resolve(buf)}))}}functionrandBytesSync(byteLength,forceLength=false){if(byteLength<1){thrownewRangeError(`byteLength MUST be > 0 and it is ${byteLength}`)}letbuf;{buf=newUint8Array(byteLength);self.crypto.getRandomValues(buf)}if(forceLength){buf[0]=buf[0]|128}returnbuf}functiontoZn(a,n){n=BigInt(n);if(n<=0){returnNaN}