@permaweb/libs 0.0.45 → 0.0.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  var V3=Object.create;var iu=Object.defineProperty;var j3=Object.getOwnPropertyDescriptor;var Q3=Object.getOwnPropertyNames;var W3=Object.getPrototypeOf,Y3=Object.prototype.hasOwnProperty;var rt=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var V=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),i1=(t,e)=>{for(var r in e)iu(t,r,{get:e[r],enumerable:!0})},$3=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Q3(e))!Y3.call(t,i)&&i!==r&&iu(t,i,{get:()=>e[i],enumerable:!(n=j3(e,i))||n.enumerable});return t};var A=(t,e,r)=>(r=t!=null?V3(W3(t)):{},$3(e||!t||!t.__esModule?iu(r,"default",{value:t,enumerable:!0}):r,t));var M=V((o_,f1)=>{var vt=f1.exports={},_n,Bn;function au(){throw new Error("setTimeout has not been defined")}function ou(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?_n=setTimeout:_n=au}catch{_n=au}try{typeof clearTimeout=="function"?Bn=clearTimeout:Bn=ou}catch{Bn=ou}})();function a1(t){if(_n===setTimeout)return setTimeout(t,0);if((_n===au||!_n)&&setTimeout)return _n=setTimeout,setTimeout(t,0);try{return _n(t,0)}catch{try{return _n.call(null,t,0)}catch{return _n.call(this,t,0)}}}function e8(t){if(Bn===clearTimeout)return clearTimeout(t);if((Bn===ou||!Bn)&&clearTimeout)return Bn=clearTimeout,clearTimeout(t);try{return Bn(t)}catch{try{return Bn.call(null,t)}catch{return Bn.call(this,t)}}}var oi=[],Wa=!1,aa,Bf=-1;function t8(){!Wa||!aa||(Wa=!1,aa.length?oi=aa.concat(oi):Bf=-1,oi.length&&o1())}function o1(){if(!Wa){var t=a1(t8);Wa=!0;for(var e=oi.length;e;){for(aa=oi,oi=[];++Bf<e;)aa&&aa[Bf].run();Bf=-1,e=oi.length}aa=null,Wa=!1,e8(t)}}vt.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)e[r-1]=arguments[r];oi.push(new s1(t,e)),oi.length===1&&!Wa&&a1(o1)};function s1(t,e){this.fun=t,this.array=e}s1.prototype.run=function(){this.fun.apply(null,this.array)};vt.title="browser";vt.browser=!0;vt.env={};vt.argv=[];vt.version="";vt.versions={};function si(){}vt.on=si;vt.addListener=si;vt.once=si;vt.off=si;vt.removeListener=si;vt.removeAllListeners=si;vt.emit=si;vt.prependListener=si;vt.prependOnceListener=si;vt.listeners=function(t){return[]};vt.binding=function(t){throw new Error("process.binding is not supported")};vt.cwd=function(){return"/"};vt.chdir=function(t){throw new Error("process.chdir is not supported")};vt.umask=function(){return 0}});var y1=V(du=>{"use strict";var B_=A(M());Object.defineProperty(du,"__esModule",{value:!0});function u8(t){var e=4,r=t.length,n=r%e;if(!n)return t;var i=r,a=e-n,d=r+a,v=Buffer.alloc(d);for(v.write(t);a--;)v.write("=",i++);return v.toString()}du.default=u8});var A1=V(bu=>{"use strict";var P_=A(M());Object.defineProperty(bu,"__esModule",{value:!0});var l8=y1();function w1(t,e){return e===void 0&&(e="utf8"),Buffer.isBuffer(t)?hu(t.toString("base64")):hu(Buffer.from(t,e).toString("base64"))}function d8(t,e){return e===void 0&&(e="utf8"),Buffer.from(pu(t),"base64").toString(e)}function pu(t){return t=t.toString(),l8.default(t).replace(/\-/g,"+").replace(/_/g,"/")}function hu(t){return t.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function h8(t){return Buffer.from(pu(t),"base64")}var eo=w1;eo.encode=w1;eo.decode=d8;eo.toBase64=pu;eo.fromBase64=hu;eo.toBuffer=h8;bu.default=eo});var Nr=V((L_,Lf)=>{var R_=A(M());Lf.exports=A1().default;Lf.exports.default=Lf.exports});var I1=V(Of=>{"use strict";var G_=A(M());Of.byteLength=L8;Of.toByteArray=F8;Of.fromByteArray=I8;var Rn=[],Jr=[],P8=typeof Uint8Array<"u"?Uint8Array:Array,Tu="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(ca=0,D1=Tu.length;ca<D1;++ca)Rn[ca]=Tu[ca],Jr[Tu.charCodeAt(ca)]=ca;var ca,D1;Jr[45]=62;Jr[95]=63;function O1(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");r===-1&&(r=e);var n=r===e?0:4-r%4;return[r,n]}function L8(t){var e=O1(t),r=e[0],n=e[1];return(r+n)*3/4-n}function R8(t,e,r){return(e+r)*3/4-r}function F8(t){var e,r=O1(t),n=r[0],i=r[1],a=new P8(R8(t,n,i)),d=0,v=i>0?n-4:n,y;for(y=0;y<v;y+=4)e=Jr[t.charCodeAt(y)]<<18|Jr[t.charCodeAt(y+1)]<<12|Jr[t.charCodeAt(y+2)]<<6|Jr[t.charCodeAt(y+3)],a[d++]=e>>16&255,a[d++]=e>>8&255,a[d++]=e&255;return i===2&&(e=Jr[t.charCodeAt(y)]<<2|Jr[t.charCodeAt(y+1)]>>4,a[d++]=e&255),i===1&&(e=Jr[t.charCodeAt(y)]<<10|Jr[t.charCodeAt(y+1)]<<4|Jr[t.charCodeAt(y+2)]>>2,a[d++]=e>>8&255,a[d++]=e&255),a}function D8(t){return Rn[t>>18&63]+Rn[t>>12&63]+Rn[t>>6&63]+Rn[t&63]}function O8(t,e,r){for(var n,i=[],a=e;a<r;a+=3)n=(t[a]<<16&16711680)+(t[a+1]<<8&65280)+(t[a+2]&255),i.push(D8(n));return i.join("")}function I8(t){for(var e,r=t.length,n=r%3,i=[],a=16383,d=0,v=r-n;d<v;d+=a)i.push(O8(t,d,d+a>v?v:d+a));return n===1?(e=t[r-1],i.push(Rn[e>>2]+Rn[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],i.push(Rn[e>>10]+Rn[e>>4&63]+Rn[e<<2&63]+"=")),i.join("")}});var bn=V(Ur=>{"use strict";var z_=A(M());Object.defineProperty(Ur,"__esModule",{value:!0});Ur.concatBuffers=k8;Ur.b64UrlToString=N8;Ur.bufferToString=N1;Ur.stringToBuffer=J1;Ur.stringToB64Url=J8;Ur.b64UrlToBuffer=U1;Ur.bufferTob64=H1;Ur.bufferTob64Url=q1;Ur.b64UrlEncode=G1;Ur.b64UrlDecode=X1;var k1=I1();function k8(t){let e=0;for(let i=0;i<t.length;i++)e+=t[i].byteLength;let r=new Uint8Array(e),n=0;r.set(new Uint8Array(t[0]),n),n+=t[0].byteLength;for(let i=1;i<t.length;i++)r.set(new Uint8Array(t[i]),n),n+=t[i].byteLength;return r}function N8(t){let e=U1(t);return N1(e)}function N1(t){return new TextDecoder("utf-8",{fatal:!0}).decode(t)}function J1(t){return new TextEncoder().encode(t)}function J8(t){return q1(J1(t))}function U1(t){return new Uint8Array(k1.toByteArray(X1(t)))}function H1(t){return k1.fromByteArray(new Uint8Array(t))}function q1(t){return G1(H1(t))}function G1(t){try{return t.replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}catch(e){throw new Error("Failed to encode string",{cause:e})}}function X1(t){try{t=t.replace(/\-/g,"+").replace(/\_/g,"/");let e;return t.length%4==0?e=0:e=4-t.length%4,t.concat("=".repeat(e))}catch(e){throw new Error("Failed to decode string",{cause:e})}}});var Bu=V(_u=>{"use strict";var W_=A(M());Object.defineProperty(_u,"__esModule",{value:!0});var Li=bn(),Eu=class{keyLength=4096;publicExponent=65537;hashAlgorithm="sha256";driver;constructor(){if(!this.detectWebCrypto())throw new Error("SubtleCrypto not available!");this.driver=crypto.subtle}async generateJWK(){let e=await this.driver.generateKey({name:"RSA-PSS",modulusLength:4096,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign"]),r=await this.driver.exportKey("jwk",e.privateKey);return{kty:r.kty,e:r.e,n:r.n,d:r.d,p:r.p,q:r.q,dp:r.dp,dq:r.dq,qi:r.qi}}async sign(e,r,{saltLength:n}={}){let i=await this.driver.sign({name:"RSA-PSS",saltLength:n??32},await this.jwkToCryptoKey(e),r);return new Uint8Array(i)}async hash(e,r="SHA-256"){let n=await this.driver.digest(r,e);return new Uint8Array(n)}async verify(e,r,n){let i={kty:"RSA",e:"AQAB",n:e},a=await this.jwkToPublicCryptoKey(i),d=await this.driver.digest("SHA-256",r),v=await this.driver.verify({name:"RSA-PSS",saltLength:0},a,n,r),y=await this.driver.verify({name:"RSA-PSS",saltLength:32},a,n,r),m=Math.ceil((a.algorithm.modulusLength-1)/8)-d.byteLength-2,B=await this.driver.verify({name:"RSA-PSS",saltLength:m},a,n,r),P=v||y||B;if(!P){let D={algorithm:a.algorithm.name,modulusLength:a.algorithm.modulusLength,keyUsages:a.usages,saltLengthsAttempted:`0, 32, ${m}`};console.warn(`Transaction Verification Failed!
2
2
  `,`Details: ${JSON.stringify(D,null,2)}
3
- `,"N.B. ArweaveJS is only guaranteed to verify txs created using ArweaveJS.")}return P}async jwkToCryptoKey(e){return this.driver.importKey("jwk",e,{name:"RSA-PSS",hash:{name:"SHA-256"}},!1,["sign"])}async jwkToPublicCryptoKey(e){return this.driver.importKey("jwk",e,{name:"RSA-PSS",hash:{name:"SHA-256"}},!1,["verify"])}detectWebCrypto(){if(typeof crypto>"u")return!1;let e=crypto?.subtle;return e===void 0?!1:["generateKey","importKey","exportKey","digest","sign"].every(n=>typeof e[n]=="function")}async encrypt(e,r,n){let i=await this.driver.importKey("raw",typeof r=="string"?Li.stringToBuffer(r):r,{name:"PBKDF2",length:32},!1,["deriveKey"]),a=await this.driver.deriveKey({name:"PBKDF2",salt:n?Li.stringToBuffer(n):Li.stringToBuffer("salt"),iterations:1e5,hash:"SHA-256"},i,{name:"AES-CBC",length:256},!1,["encrypt","decrypt"]),d=new Uint8Array(16);crypto.getRandomValues(d);let v=await this.driver.encrypt({name:"AES-CBC",iv:d},a,e);return Li.concatBuffers([d,v])}async decrypt(e,r,n){let i=await this.driver.importKey("raw",typeof r=="string"?Li.stringToBuffer(r):r,{name:"PBKDF2",length:32},!1,["deriveKey"]),a=await this.driver.deriveKey({name:"PBKDF2",salt:n?Li.stringToBuffer(n):Li.stringToBuffer("salt"),iterations:1e5,hash:"SHA-256"},i,{name:"AES-CBC",length:256},!1,["encrypt","decrypt"]),d=e.slice(0,16),v=await this.driver.decrypt({name:"AES-CBC",iv:d},a,e.slice(16));return Li.concatBuffers([v])}};_u.default=Eu});var Z1=V((K1,If)=>{var Y_=A(M());(function(t){"use strict";var e,r=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,n=Math.ceil,i=Math.floor,a="[BigNumber Error] ",d=a+"Number primitive has more than 15 significant digits: ",v=1e14,y=14,m=9007199254740991,B=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],P=1e7,D=1e9;function F(ie){var ee,ce,te,Y=w.prototype={constructor:w,toString:null,valueOf:null},S=new w(1),s=20,u=4,l=-7,f=21,c=-1e7,g=1e7,x=!1,h=1,o=0,p={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:"\xA0",suffix:""},E="0123456789abcdefghijklmnopqrstuvwxyz",b=!0;function w(_,R){var L,O,G,I,J,z,N,U,Q=this;if(!(Q instanceof w))return new w(_,R);if(R==null){if(_&&_._isBigNumber===!0){Q.s=_.s,!_.c||_.e>g?Q.c=Q.e=null:_.e<c?Q.c=[Q.e=0]:(Q.e=_.e,Q.c=_.c.slice());return}if((z=typeof _=="number")&&_*0==0){if(Q.s=1/_<0?(_=-_,-1):1,_===~~_){for(I=0,J=_;J>=10;J/=10,I++);I>g?Q.c=Q.e=null:(Q.e=I,Q.c=[_]);return}U=String(_)}else{if(!r.test(U=String(_)))return te(Q,U,z);Q.s=U.charCodeAt(0)==45?(U=U.slice(1),-1):1}(I=U.indexOf("."))>-1&&(U=U.replace(".","")),(J=U.search(/e/i))>0?(I<0&&(I=J),I+=+U.slice(J+1),U=U.substring(0,J)):I<0&&(I=U.length)}else{if(K(R,2,E.length,"Base"),R==10&&b)return Q=new w(_),X(Q,s+Q.e+1,u);if(U=String(_),z=typeof _=="number"){if(_*0!=0)return te(Q,U,z,R);if(Q.s=1/_<0?(U=U.slice(1),-1):1,w.DEBUG&&U.replace(/^0\.0*|\./,"").length>15)throw Error(d+_)}else Q.s=U.charCodeAt(0)===45?(U=U.slice(1),-1):1;for(L=E.slice(0,R),I=J=0,N=U.length;J<N;J++)if(L.indexOf(O=U.charAt(J))<0){if(O=="."){if(J>I){I=N;continue}}else if(!G&&(U==U.toUpperCase()&&(U=U.toLowerCase())||U==U.toLowerCase()&&(U=U.toUpperCase()))){G=!0,J=-1,I=0;continue}return te(Q,String(_),z,R)}z=!1,U=ce(U,R,10,Q.s),(I=U.indexOf("."))>-1?U=U.replace(".",""):I=U.length}for(J=0;U.charCodeAt(J)===48;J++);for(N=U.length;U.charCodeAt(--N)===48;);if(U=U.slice(J,++N)){if(N-=J,z&&w.DEBUG&&N>15&&(_>m||_!==i(_)))throw Error(d+Q.s*_);if((I=I-J-1)>g)Q.c=Q.e=null;else if(I<c)Q.c=[Q.e=0];else{if(Q.e=I,Q.c=[],J=(I+1)%y,I<0&&(J+=y),J<N){for(J&&Q.c.push(+U.slice(0,J)),N-=y;J<N;)Q.c.push(+U.slice(J,J+=y));J=y-(U=U.slice(J)).length}else J-=N;for(;J--;U+="0");Q.c.push(+U)}}else Q.c=[Q.e=0]}w.clone=F,w.ROUND_UP=0,w.ROUND_DOWN=1,w.ROUND_CEIL=2,w.ROUND_FLOOR=3,w.ROUND_HALF_UP=4,w.ROUND_HALF_DOWN=5,w.ROUND_HALF_EVEN=6,w.ROUND_HALF_CEIL=7,w.ROUND_HALF_FLOOR=8,w.EUCLID=9,w.config=w.set=function(_){var R,L;if(_!=null)if(typeof _=="object"){if(_.hasOwnProperty(R="DECIMAL_PLACES")&&(L=_[R],K(L,0,D,R),s=L),_.hasOwnProperty(R="ROUNDING_MODE")&&(L=_[R],K(L,0,8,R),u=L),_.hasOwnProperty(R="EXPONENTIAL_AT")&&(L=_[R],L&&L.pop?(K(L[0],-D,0,R),K(L[1],0,D,R),l=L[0],f=L[1]):(K(L,-D,D,R),l=-(f=L<0?-L:L))),_.hasOwnProperty(R="RANGE"))if(L=_[R],L&&L.pop)K(L[0],-D,-1,R),K(L[1],1,D,R),c=L[0],g=L[1];else if(K(L,-D,D,R),L)c=-(g=L<0?-L:L);else throw Error(a+R+" cannot be zero: "+L);if(_.hasOwnProperty(R="CRYPTO"))if(L=_[R],L===!!L)if(L)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))x=L;else throw x=!L,Error(a+"crypto unavailable");else x=L;else throw Error(a+R+" not true or false: "+L);if(_.hasOwnProperty(R="MODULO_MODE")&&(L=_[R],K(L,0,9,R),h=L),_.hasOwnProperty(R="POW_PRECISION")&&(L=_[R],K(L,0,D,R),o=L),_.hasOwnProperty(R="FORMAT"))if(L=_[R],typeof L=="object")p=L;else throw Error(a+R+" not an object: "+L);if(_.hasOwnProperty(R="ALPHABET"))if(L=_[R],typeof L=="string"&&!/^.?$|[+\-.\s]|(.).*\1/.test(L))b=L.slice(0,10)=="0123456789",E=L;else throw Error(a+R+" invalid: "+L)}else throw Error(a+"Object expected: "+_);return{DECIMAL_PLACES:s,ROUNDING_MODE:u,EXPONENTIAL_AT:[l,f],RANGE:[c,g],CRYPTO:x,MODULO_MODE:h,POW_PRECISION:o,FORMAT:p,ALPHABET:E}},w.isBigNumber=function(_){if(!_||_._isBigNumber!==!0)return!1;if(!w.DEBUG)return!0;var R,L,O=_.c,G=_.e,I=_.s;e:if({}.toString.call(O)=="[object Array]"){if((I===1||I===-1)&&G>=-D&&G<=D&&G===i(G)){if(O[0]===0){if(G===0&&O.length===1)return!0;break e}if(R=(G+1)%y,R<1&&(R+=y),String(O[0]).length==R){for(R=0;R<O.length;R++)if(L=O[R],L<0||L>=v||L!==i(L))break e;if(L!==0)return!0}}}else if(O===null&&G===null&&(I===null||I===1||I===-1))return!0;throw Error(a+"Invalid BigNumber: "+_)},w.maximum=w.max=function(){return T(arguments,-1)},w.minimum=w.min=function(){return T(arguments,1)},w.random=function(){var _=9007199254740992,R=Math.random()*_&2097151?function(){return i(Math.random()*_)}:function(){return(Math.random()*1073741824|0)*8388608+(Math.random()*8388608|0)};return function(L){var O,G,I,J,z,N=0,U=[],Q=new w(S);if(L==null?L=s:K(L,0,D),J=n(L/y),x)if(crypto.getRandomValues){for(O=crypto.getRandomValues(new Uint32Array(J*=2));N<J;)z=O[N]*131072+(O[N+1]>>>11),z>=9e15?(G=crypto.getRandomValues(new Uint32Array(2)),O[N]=G[0],O[N+1]=G[1]):(U.push(z%1e14),N+=2);N=J/2}else if(crypto.randomBytes){for(O=crypto.randomBytes(J*=7);N<J;)z=(O[N]&31)*281474976710656+O[N+1]*1099511627776+O[N+2]*4294967296+O[N+3]*16777216+(O[N+4]<<16)+(O[N+5]<<8)+O[N+6],z>=9e15?crypto.randomBytes(7).copy(O,N):(U.push(z%1e14),N+=7);N=J/7}else throw x=!1,Error(a+"crypto unavailable");if(!x)for(;N<J;)z=R(),z<9e15&&(U[N++]=z%1e14);for(J=U[--N],L%=y,J&&L&&(z=B[y-L],U[N]=i(J/z)*z);U[N]===0;U.pop(),N--);if(N<0)U=[I=0];else{for(I=-1;U[0]===0;U.splice(0,1),I-=y);for(N=1,z=U[0];z>=10;z/=10,N++);N<y&&(I-=y-N)}return Q.e=I,Q.c=U,Q}}(),w.sum=function(){for(var _=1,R=arguments,L=new w(R[0]);_<R.length;)L=L.plus(R[_++]);return L},ce=function(){var _="0123456789";function R(L,O,G,I){for(var J,z=[0],N,U=0,Q=L.length;U<Q;){for(N=z.length;N--;z[N]*=O);for(z[0]+=I.indexOf(L.charAt(U++)),J=0;J<z.length;J++)z[J]>G-1&&(z[J+1]==null&&(z[J+1]=0),z[J+1]+=z[J]/G|0,z[J]%=G)}return z.reverse()}return function(L,O,G,I,J){var z,N,U,Q,j,re,De,se,le=L.indexOf("."),Ue=s,oe=u;for(le>=0&&(Q=o,o=0,L=L.replace(".",""),se=new w(O),re=se.pow(L.length-le),o=Q,se.c=R(ae(q(re.c),re.e,"0"),10,G,_),se.e=se.c.length),De=R(L,O,G,J?(z=E,_):(z=_,E)),U=Q=De.length;De[--Q]==0;De.pop());if(!De[0])return z.charAt(0);if(le<0?--U:(re.c=De,re.e=U,re.s=I,re=ee(re,se,Ue,oe,G),De=re.c,j=re.r,U=re.e),N=U+Ue+1,le=De[N],Q=G/2,j=j||N<0||De[N+1]!=null,j=oe<4?(le!=null||j)&&(oe==0||oe==(re.s<0?3:2)):le>Q||le==Q&&(oe==4||j||oe==6&&De[N-1]&1||oe==(re.s<0?8:7)),N<1||!De[0])L=j?ae(z.charAt(1),-Ue,z.charAt(0)):z.charAt(0);else{if(De.length=N,j)for(--G;++De[--N]>G;)De[N]=0,N||(++U,De=[1].concat(De));for(Q=De.length;!De[--Q];);for(le=0,L="";le<=Q;L+=z.charAt(De[le++]));L=ae(L,U,z.charAt(0))}return L}}(),ee=function(){function _(O,G,I){var J,z,N,U,Q=0,j=O.length,re=G%P,De=G/P|0;for(O=O.slice();j--;)N=O[j]%P,U=O[j]/P|0,J=De*N+U*re,z=re*N+J%P*P+Q,Q=(z/I|0)+(J/P|0)+De*U,O[j]=z%I;return Q&&(O=[Q].concat(O)),O}function R(O,G,I,J){var z,N;if(I!=J)N=I>J?1:-1;else for(z=N=0;z<I;z++)if(O[z]!=G[z]){N=O[z]>G[z]?1:-1;break}return N}function L(O,G,I,J){for(var z=0;I--;)O[I]-=z,z=O[I]<G[I]?1:0,O[I]=z*J+O[I]-G[I];for(;!O[0]&&O.length>1;O.splice(0,1));}return function(O,G,I,J,z){var N,U,Q,j,re,De,se,le,Ue,oe,fe,Xe,ge,ve,gt,pe,be,Ye=O.s==G.s?1:-1,de=O.c,ue=G.c;if(!de||!de[0]||!ue||!ue[0])return new w(!O.s||!G.s||(de?ue&&de[0]==ue[0]:!ue)?NaN:de&&de[0]==0||!ue?Ye*0:Ye/0);for(le=new w(Ye),Ue=le.c=[],U=O.e-G.e,Ye=I+U+1,z||(z=v,U=C(O.e/y)-C(G.e/y),Ye=Ye/y|0),Q=0;ue[Q]==(de[Q]||0);Q++);if(ue[Q]>(de[Q]||0)&&U--,Ye<0)Ue.push(1),j=!0;else{for(ve=de.length,pe=ue.length,Q=0,Ye+=2,re=i(z/(ue[0]+1)),re>1&&(ue=_(ue,re,z),de=_(de,re,z),pe=ue.length,ve=de.length),ge=pe,oe=de.slice(0,pe),fe=oe.length;fe<pe;oe[fe++]=0);be=ue.slice(),be=[0].concat(be),gt=ue[0],ue[1]>=z/2&&gt++;do{if(re=0,N=R(ue,oe,pe,fe),N<0){if(Xe=oe[0],pe!=fe&&(Xe=Xe*z+(oe[1]||0)),re=i(Xe/gt),re>1)for(re>=z&&(re=z-1),De=_(ue,re,z),se=De.length,fe=oe.length;R(De,oe,se,fe)==1;)re--,L(De,pe<se?be:ue,se,z),se=De.length,N=1;else re==0&&(N=re=1),De=ue.slice(),se=De.length;if(se<fe&&(De=[0].concat(De)),L(oe,De,fe,z),fe=oe.length,N==-1)for(;R(ue,oe,pe,fe)<1;)re++,L(oe,pe<fe?be:ue,fe,z),fe=oe.length}else N===0&&(re++,oe=[0]);Ue[Q++]=re,oe[0]?oe[fe++]=de[ge]||0:(oe=[de[ge]],fe=1)}while((ge++<ve||oe[0]!=null)&&Ye--);j=oe[0]!=null,Ue[0]||Ue.splice(0,1)}if(z==v){for(Q=1,Ye=Ue[0];Ye>=10;Ye/=10,Q++);X(le,I+(le.e=Q+U*y-1)+1,J,j)}else le.e=U,le.r=+j;return le}}();function H(_,R,L,O){var G,I,J,z,N;if(L==null?L=u:K(L,0,8),!_.c)return _.toString();if(G=_.c[0],J=_.e,R==null)N=q(_.c),N=O==1||O==2&&(J<=l||J>=f)?$(N,J):ae(N,J,"0");else if(_=X(new w(_),R,L),I=_.e,N=q(_.c),z=N.length,O==1||O==2&&(R<=I||I<=l)){for(;z<R;N+="0",z++);N=$(N,I)}else if(R-=J,N=ae(N,I,"0"),I+1>z){if(--R>0)for(N+=".";R--;N+="0");}else if(R+=I-z,R>0)for(I+1==z&&(N+=".");R--;N+="0");return _.s<0&&G?"-"+N:N}function T(_,R){for(var L,O,G=1,I=new w(_[0]);G<_.length;G++)O=new w(_[G]),(!O.s||(L=W(I,O))===R||L===0&&I.s===R)&&(I=O);return I}function k(_,R,L){for(var O=1,G=R.length;!R[--G];R.pop());for(G=R[0];G>=10;G/=10,O++);return(L=O+L*y-1)>g?_.c=_.e=null:L<c?_.c=[_.e=0]:(_.e=L,_.c=R),_}te=function(){var _=/^(-?)0([xbo])(?=\w[\w.]*$)/i,R=/^([^.]+)\.$/,L=/^\.([^.]+)$/,O=/^-?(Infinity|NaN)$/,G=/^\s*\+(?=[\w.])|^\s+|\s+$/g;return function(I,J,z,N){var U,Q=z?J:J.replace(G,"");if(O.test(Q))I.s=isNaN(Q)?null:Q<0?-1:1;else{if(!z&&(Q=Q.replace(_,function(j,re,De){return U=(De=De.toLowerCase())=="x"?16:De=="b"?2:8,!N||N==U?re:j}),N&&(U=N,Q=Q.replace(R,"$1").replace(L,"0.$1")),J!=Q))return new w(Q,U);if(w.DEBUG)throw Error(a+"Not a"+(N?" base "+N:"")+" number: "+J);I.s=null}I.c=I.e=null}}();function X(_,R,L,O){var G,I,J,z,N,U,Q,j=_.c,re=B;if(j){e:{for(G=1,z=j[0];z>=10;z/=10,G++);if(I=R-G,I<0)I+=y,J=R,N=j[U=0],Q=i(N/re[G-J-1]%10);else if(U=n((I+1)/y),U>=j.length)if(O){for(;j.length<=U;j.push(0));N=Q=0,G=1,I%=y,J=I-y+1}else break e;else{for(N=z=j[U],G=1;z>=10;z/=10,G++);I%=y,J=I-y+G,Q=J<0?0:i(N/re[G-J-1]%10)}if(O=O||R<0||j[U+1]!=null||(J<0?N:N%re[G-J-1]),O=L<4?(Q||O)&&(L==0||L==(_.s<0?3:2)):Q>5||Q==5&&(L==4||O||L==6&&(I>0?J>0?N/re[G-J]:0:j[U-1])%10&1||L==(_.s<0?8:7)),R<1||!j[0])return j.length=0,O?(R-=_.e+1,j[0]=re[(y-R%y)%y],_.e=-R||0):j[0]=_.e=0,_;if(I==0?(j.length=U,z=1,U--):(j.length=U+1,z=re[y-I],j[U]=J>0?i(N/re[G-J]%re[J])*z:0),O)for(;;)if(U==0){for(I=1,J=j[0];J>=10;J/=10,I++);for(J=j[0]+=z,z=1;J>=10;J/=10,z++);I!=z&&(_.e++,j[0]==v&&(j[0]=1));break}else{if(j[U]+=z,j[U]!=v)break;j[U--]=0,z=1}for(I=j.length;j[--I]===0;j.pop());}_.e>g?_.c=_.e=null:_.e<c&&(_.c=[_.e=0])}return _}function Z(_){var R,L=_.e;return L===null?_.toString():(R=q(_.c),R=L<=l||L>=f?$(R,L):ae(R,L,"0"),_.s<0?"-"+R:R)}return Y.absoluteValue=Y.abs=function(){var _=new w(this);return _.s<0&&(_.s=1),_},Y.comparedTo=function(_,R){return W(this,new w(_,R))},Y.decimalPlaces=Y.dp=function(_,R){var L,O,G,I=this;if(_!=null)return K(_,0,D),R==null?R=u:K(R,0,8),X(new w(I),_+I.e+1,R);if(!(L=I.c))return null;if(O=((G=L.length-1)-C(this.e/y))*y,G=L[G])for(;G%10==0;G/=10,O--);return O<0&&(O=0),O},Y.dividedBy=Y.div=function(_,R){return ee(this,new w(_,R),s,u)},Y.dividedToIntegerBy=Y.idiv=function(_,R){return ee(this,new w(_,R),0,1)},Y.exponentiatedBy=Y.pow=function(_,R){var L,O,G,I,J,z,N,U,Q,j=this;if(_=new w(_),_.c&&!_.isInteger())throw Error(a+"Exponent not an integer: "+Z(_));if(R!=null&&(R=new w(R)),z=_.e>14,!j.c||!j.c[0]||j.c[0]==1&&!j.e&&j.c.length==1||!_.c||!_.c[0])return Q=new w(Math.pow(+Z(j),z?_.s*(2-ne(_)):+Z(_))),R?Q.mod(R):Q;if(N=_.s<0,R){if(R.c?!R.c[0]:!R.s)return new w(NaN);O=!N&&j.isInteger()&&R.isInteger(),O&&(j=j.mod(R))}else{if(_.e>9&&(j.e>0||j.e<-1||(j.e==0?j.c[0]>1||z&&j.c[1]>=24e7:j.c[0]<8e13||z&&j.c[0]<=9999975e7)))return I=j.s<0&&ne(_)?-0:0,j.e>-1&&(I=1/I),new w(N?1/I:I);o&&(I=n(o/y+2))}for(z?(L=new w(.5),N&&(_.s=1),U=ne(_)):(G=Math.abs(+Z(_)),U=G%2),Q=new w(S);;){if(U){if(Q=Q.times(j),!Q.c)break;I?Q.c.length>I&&(Q.c.length=I):O&&(Q=Q.mod(R))}if(G){if(G=i(G/2),G===0)break;U=G%2}else if(_=_.times(L),X(_,_.e+1,1),_.e>14)U=ne(_);else{if(G=+Z(_),G===0)break;U=G%2}j=j.times(j),I?j.c&&j.c.length>I&&(j.c.length=I):O&&(j=j.mod(R))}return O?Q:(N&&(Q=S.div(Q)),R?Q.mod(R):I?X(Q,o,u,J):Q)},Y.integerValue=function(_){var R=new w(this);return _==null?_=u:K(_,0,8),X(R,R.e+1,_)},Y.isEqualTo=Y.eq=function(_,R){return W(this,new w(_,R))===0},Y.isFinite=function(){return!!this.c},Y.isGreaterThan=Y.gt=function(_,R){return W(this,new w(_,R))>0},Y.isGreaterThanOrEqualTo=Y.gte=function(_,R){return(R=W(this,new w(_,R)))===1||R===0},Y.isInteger=function(){return!!this.c&&C(this.e/y)>this.c.length-2},Y.isLessThan=Y.lt=function(_,R){return W(this,new w(_,R))<0},Y.isLessThanOrEqualTo=Y.lte=function(_,R){return(R=W(this,new w(_,R)))===-1||R===0},Y.isNaN=function(){return!this.s},Y.isNegative=function(){return this.s<0},Y.isPositive=function(){return this.s>0},Y.isZero=function(){return!!this.c&&this.c[0]==0},Y.minus=function(_,R){var L,O,G,I,J=this,z=J.s;if(_=new w(_,R),R=_.s,!z||!R)return new w(NaN);if(z!=R)return _.s=-R,J.plus(_);var N=J.e/y,U=_.e/y,Q=J.c,j=_.c;if(!N||!U){if(!Q||!j)return Q?(_.s=-R,_):new w(j?J:NaN);if(!Q[0]||!j[0])return j[0]?(_.s=-R,_):new w(Q[0]?J:u==3?-0:0)}if(N=C(N),U=C(U),Q=Q.slice(),z=N-U){for((I=z<0)?(z=-z,G=Q):(U=N,G=j),G.reverse(),R=z;R--;G.push(0));G.reverse()}else for(O=(I=(z=Q.length)<(R=j.length))?z:R,z=R=0;R<O;R++)if(Q[R]!=j[R]){I=Q[R]<j[R];break}if(I&&(G=Q,Q=j,j=G,_.s=-_.s),R=(O=j.length)-(L=Q.length),R>0)for(;R--;Q[L++]=0);for(R=v-1;O>z;){if(Q[--O]<j[O]){for(L=O;L&&!Q[--L];Q[L]=R);--Q[L],Q[O]+=v}Q[O]-=j[O]}for(;Q[0]==0;Q.splice(0,1),--U);return Q[0]?k(_,Q,U):(_.s=u==3?-1:1,_.c=[_.e=0],_)},Y.modulo=Y.mod=function(_,R){var L,O,G=this;return _=new w(_,R),!G.c||!_.s||_.c&&!_.c[0]?new w(NaN):!_.c||G.c&&!G.c[0]?new w(G):(h==9?(O=_.s,_.s=1,L=ee(G,_,0,3),_.s=O,L.s*=O):L=ee(G,_,0,h),_=G.minus(L.times(_)),!_.c[0]&&h==1&&(_.s=G.s),_)},Y.multipliedBy=Y.times=function(_,R){var L,O,G,I,J,z,N,U,Q,j,re,De,se,le,Ue,oe=this,fe=oe.c,Xe=(_=new w(_,R)).c;if(!fe||!Xe||!fe[0]||!Xe[0])return!oe.s||!_.s||fe&&!fe[0]&&!Xe||Xe&&!Xe[0]&&!fe?_.c=_.e=_.s=null:(_.s*=oe.s,!fe||!Xe?_.c=_.e=null:(_.c=[0],_.e=0)),_;for(O=C(oe.e/y)+C(_.e/y),_.s*=oe.s,N=fe.length,j=Xe.length,N<j&&(se=fe,fe=Xe,Xe=se,G=N,N=j,j=G),G=N+j,se=[];G--;se.push(0));for(le=v,Ue=P,G=j;--G>=0;){for(L=0,re=Xe[G]%Ue,De=Xe[G]/Ue|0,J=N,I=G+J;I>G;)U=fe[--J]%Ue,Q=fe[J]/Ue|0,z=De*U+Q*re,U=re*U+z%Ue*Ue+se[I]+L,L=(U/le|0)+(z/Ue|0)+De*Q,se[I--]=U%le;se[I]=L}return L?++O:se.splice(0,1),k(_,se,O)},Y.negated=function(){var _=new w(this);return _.s=-_.s||null,_},Y.plus=function(_,R){var L,O=this,G=O.s;if(_=new w(_,R),R=_.s,!G||!R)return new w(NaN);if(G!=R)return _.s=-R,O.minus(_);var I=O.e/y,J=_.e/y,z=O.c,N=_.c;if(!I||!J){if(!z||!N)return new w(G/0);if(!z[0]||!N[0])return N[0]?_:new w(z[0]?O:G*0)}if(I=C(I),J=C(J),z=z.slice(),G=I-J){for(G>0?(J=I,L=N):(G=-G,L=z),L.reverse();G--;L.push(0));L.reverse()}for(G=z.length,R=N.length,G-R<0&&(L=N,N=z,z=L,R=G),G=0;R;)G=(z[--R]=z[R]+N[R]+G)/v|0,z[R]=v===z[R]?0:z[R]%v;return G&&(z=[G].concat(z),++J),k(_,z,J)},Y.precision=Y.sd=function(_,R){var L,O,G,I=this;if(_!=null&&_!==!!_)return K(_,1,D),R==null?R=u:K(R,0,8),X(new w(I),_,R);if(!(L=I.c))return null;if(G=L.length-1,O=G*y+1,G=L[G]){for(;G%10==0;G/=10,O--);for(G=L[0];G>=10;G/=10,O++);}return _&&I.e+1>O&&(O=I.e+1),O},Y.shiftedBy=function(_){return K(_,-m,m),this.times("1e"+_)},Y.squareRoot=Y.sqrt=function(){var _,R,L,O,G,I=this,J=I.c,z=I.s,N=I.e,U=s+4,Q=new w("0.5");if(z!==1||!J||!J[0])return new w(!z||z<0&&(!J||J[0])?NaN:J?I:1/0);if(z=Math.sqrt(+Z(I)),z==0||z==1/0?(R=q(J),(R.length+N)%2==0&&(R+="0"),z=Math.sqrt(+R),N=C((N+1)/2)-(N<0||N%2),z==1/0?R="5e"+N:(R=z.toExponential(),R=R.slice(0,R.indexOf("e")+1)+N),L=new w(R)):L=new w(z+""),L.c[0]){for(N=L.e,z=N+U,z<3&&(z=0);;)if(G=L,L=Q.times(G.plus(ee(I,G,U,1))),q(G.c).slice(0,z)===(R=q(L.c)).slice(0,z))if(L.e<N&&--z,R=R.slice(z-3,z+1),R=="9999"||!O&&R=="4999"){if(!O&&(X(G,G.e+s+2,0),G.times(G).eq(I))){L=G;break}U+=4,z+=4,O=1}else{(!+R||!+R.slice(1)&&R.charAt(0)=="5")&&(X(L,L.e+s+2,1),_=!L.times(L).eq(I));break}}return X(L,L.e+s+1,u,_)},Y.toExponential=function(_,R){return _!=null&&(K(_,0,D),_++),H(this,_,R,1)},Y.toFixed=function(_,R){return _!=null&&(K(_,0,D),_=_+this.e+1),H(this,_,R)},Y.toFormat=function(_,R,L){var O,G=this;if(L==null)_!=null&&R&&typeof R=="object"?(L=R,R=null):_&&typeof _=="object"?(L=_,_=R=null):L=p;else if(typeof L!="object")throw Error(a+"Argument not an object: "+L);if(O=G.toFixed(_,R),G.c){var I,J=O.split("."),z=+L.groupSize,N=+L.secondaryGroupSize,U=L.groupSeparator||"",Q=J[0],j=J[1],re=G.s<0,De=re?Q.slice(1):Q,se=De.length;if(N&&(I=z,z=N,N=I,se-=I),z>0&&se>0){for(I=se%z||z,Q=De.substr(0,I);I<se;I+=z)Q+=U+De.substr(I,z);N>0&&(Q+=U+De.slice(I)),re&&(Q="-"+Q)}O=j?Q+(L.decimalSeparator||"")+((N=+L.fractionGroupSize)?j.replace(new RegExp("\\d{"+N+"}\\B","g"),"$&"+(L.fractionGroupSeparator||"")):j):Q}return(L.prefix||"")+O+(L.suffix||"")},Y.toFraction=function(_){var R,L,O,G,I,J,z,N,U,Q,j,re,De=this,se=De.c;if(_!=null&&(z=new w(_),!z.isInteger()&&(z.c||z.s!==1)||z.lt(S)))throw Error(a+"Argument "+(z.isInteger()?"out of range: ":"not an integer: ")+Z(z));if(!se)return new w(De);for(R=new w(S),U=L=new w(S),O=N=new w(S),re=q(se),I=R.e=re.length-De.e-1,R.c[0]=B[(J=I%y)<0?y+J:J],_=!_||z.comparedTo(R)>0?I>0?R:U:z,J=g,g=1/0,z=new w(re),N.c[0]=0;Q=ee(z,R,0,1),G=L.plus(Q.times(O)),G.comparedTo(_)!=1;)L=O,O=G,U=N.plus(Q.times(G=U)),N=G,R=z.minus(Q.times(G=R)),z=G;return G=ee(_.minus(L),O,0,1),N=N.plus(G.times(U)),L=L.plus(G.times(O)),N.s=U.s=De.s,I=I*2,j=ee(U,O,I,u).minus(De).abs().comparedTo(ee(N,L,I,u).minus(De).abs())<1?[U,O]:[N,L],g=J,j},Y.toNumber=function(){return+Z(this)},Y.toPrecision=function(_,R){return _!=null&&K(_,1,D),H(this,_,R,2)},Y.toString=function(_){var R,L=this,O=L.s,G=L.e;return G===null?O?(R="Infinity",O<0&&(R="-"+R)):R="NaN":(_==null?R=G<=l||G>=f?$(q(L.c),G):ae(q(L.c),G,"0"):_===10&&b?(L=X(new w(L),s+G+1,u),R=ae(q(L.c),L.e,"0")):(K(_,2,E.length,"Base"),R=ce(ae(q(L.c),G,"0"),10,_,O,!0)),O<0&&L.c[0]&&(R="-"+R)),R},Y.valueOf=Y.toJSON=function(){return Z(this)},Y._isBigNumber=!0,ie!=null&&w.set(ie),w}function C(ie){var ee=ie|0;return ie>0||ie===ee?ee:ee-1}function q(ie){for(var ee,ce,te=1,Y=ie.length,S=ie[0]+"";te<Y;){for(ee=ie[te++]+"",ce=y-ee.length;ce--;ee="0"+ee);S+=ee}for(Y=S.length;S.charCodeAt(--Y)===48;);return S.slice(0,Y+1||1)}function W(ie,ee){var ce,te,Y=ie.c,S=ee.c,s=ie.s,u=ee.s,l=ie.e,f=ee.e;if(!s||!u)return null;if(ce=Y&&!Y[0],te=S&&!S[0],ce||te)return ce?te?0:-u:s;if(s!=u)return s;if(ce=s<0,te=l==f,!Y||!S)return te?0:!Y^ce?1:-1;if(!te)return l>f^ce?1:-1;for(u=(l=Y.length)<(f=S.length)?l:f,s=0;s<u;s++)if(Y[s]!=S[s])return Y[s]>S[s]^ce?1:-1;return l==f?0:l>f^ce?1:-1}function K(ie,ee,ce,te){if(ie<ee||ie>ce||ie!==i(ie))throw Error(a+(te||"Argument")+(typeof ie=="number"?ie<ee||ie>ce?" out of range: ":" not an integer: ":" not a primitive number: ")+String(ie))}function ne(ie){var ee=ie.c.length-1;return C(ie.e/y)==ee&&ie.c[ee]%2!=0}function $(ie,ee){return(ie.length>1?ie.charAt(0)+"."+ie.slice(1):ie)+(ee<0?"e":"e+")+ee}function ae(ie,ee,ce){var te,Y;if(ee<0){for(Y=ce+".";++ee;Y+=ce);ie=Y+ie}else if(te=ie.length,++ee>te){for(Y=ce,ee-=te;--ee;Y+=ce);ie+=Y}else ee<te&&(ie=ie.slice(0,ee)+"."+ie.slice(ee));return ie}e=F(),e.default=e.BigNumber=e,typeof define=="function"&&define.amd?define(function(){return e}):typeof If<"u"&&If.exports?If.exports=e:(t||(t=typeof self<"u"&&self?self:window),t.BigNumber=e)})(K1)});var V1=V(Pu=>{"use strict";var eB=A(M());Object.defineProperty(Pu,"__esModule",{value:!0});var H8=Z1(),Cu=class{BigNum;constructor(){this.BigNum=(e,r)=>{let n=H8.BigNumber.clone({DECIMAL_PLACES:r});return new n(e)}}winstonToAr(e,{formatted:r=!1,decimals:n=12,trim:i=!0}={}){let a=this.stringToBigNum(e,n).shiftedBy(-12);return r?a.toFormat(n):a.toFixed(n)}arToWinston(e,{formatted:r=!1}={}){let n=this.stringToBigNum(e).shiftedBy(12);return r?n.toFormat():n.toFixed(0)}compare(e,r){let n=this.stringToBigNum(e),i=this.stringToBigNum(r);return n.comparedTo(i)}isEqual(e,r){return this.compare(e,r)===0}isLessThan(e,r){let n=this.stringToBigNum(e),i=this.stringToBigNum(r);return n.isLessThan(i)}isGreaterThan(e,r){let n=this.stringToBigNum(e),i=this.stringToBigNum(r);return n.isGreaterThan(i)}add(e,r){let n=this.stringToBigNum(e),i=this.stringToBigNum(r);return n.plus(r).toFixed(0)}sub(e,r){let n=this.stringToBigNum(e),i=this.stringToBigNum(r);return n.minus(r).toFixed(0)}stringToBigNum(e,r=12){return this.BigNum(e,r)}};Pu.default=Cu});var j1=V(Ru=>{"use strict";var rB=A(M());Object.defineProperty(Ru,"__esModule",{value:!0});var Lu=class{METHOD_GET="GET";METHOD_POST="POST";config;constructor(e){this.applyConfig(e)}applyConfig(e){this.config=this.mergeDefaults(e)}getConfig(){return this.config}mergeDefaults(e){let r=e.protocol||"http",n=e.port||(r==="https"?443:80);return{host:e.host||"127.0.0.1",protocol:r,port:n,timeout:e.timeout||2e4,logging:e.logging||!1,logger:e.logger||console.log,network:e.network}}async get(e,r){return await this.request(e,{...r,method:this.METHOD_GET})}async post(e,r,n){let i=new Headers(n?.headers||{});return i.get("content-type")?.includes("application/json")||i.append("content-type","application/json"),i.append("accept","application/json, text/plain, */*"),await this.request(e,{...n,method:this.METHOD_POST,body:typeof r!="string"?JSON.stringify(r):r,headers:i})}async request(e,r){let n=new Headers(r?.headers||{}),i=`${this.config.protocol}://${this.config.host}:${this.config.port}`,a=r?.responseType;delete r?.responseType,e.startsWith("/")&&(e=e.slice(1)),this.config.network&&n.append("x-network",this.config.network),this.config.logging&&this.config.logger(`Requesting: ${i}/${e}`);let d=await fetch(`${i}/${e}`,{...r||{},headers:n});this.config.logging&&this.config.logger(`Response: ${d.url} - ${d.status}`);let y=d.headers.get("content-type")?.match(/charset=([^()<>@,;:\"/[\]?.=\s]*)/i)?.[1],m=d,B=async()=>{if(y)try{m.data=new TextDecoder(y).decode(await d.arrayBuffer())}catch{m.data=await d.text()}else m.data=await d.text()};if(a==="arraybuffer")m.data=await d.arrayBuffer();else if(a==="text")await B();else if(a==="webstream")m.data=q8(d.body);else try{let P=await d.clone().json();typeof P!="object"?await B():m.data=await d.json(),P=null}catch{await B()}return m}};Ru.default=Lu;var q8=t=>{let e=t;return typeof e[Symbol.asyncIterator]>"u"&&(e[Symbol.asyncIterator]=G8(t)),e},G8=function(t){return async function*(){let r=t.getReader();try{for(;;){let{done:n,value:i}=await r.read();if(n)return;yield i}}finally{r.releaseLock()}}}});var Q1=V(Du=>{"use strict";var iB=A(M());Object.defineProperty(Du,"__esModule",{value:!0});var Fu=class{api;constructor(e){this.api=e}getInfo(){return this.api.get("info").then(e=>e.data)}getPeers(){return this.api.get("peers").then(e=>e.data)}};Du.default=Fu});var hs=V(kf=>{"use strict";var oB=A(M());Object.defineProperty(kf,"__esModule",{value:!0});kf.getError=X8;var Ou=class extends Error{type;response;constructor(e,r={}){r.message?super(r.message):super(),this.type=e,this.response=r.response}getType(){return this.type}};kf.default=Ou;function X8(t){let e=t.data;if(typeof t.data=="string")try{e=JSON.parse(t.data)}catch{}if(t.data instanceof ArrayBuffer||t.data instanceof Uint8Array)try{e=JSON.parse(e.toString())}catch{}return e?e.error||e:t.statusText||"unknown"}});var Hu=V(st=>{"use strict";var fB=A(M());Object.defineProperty(st,"__esModule",{value:!0});st.arrayCompare=st.MIN_CHUNK_SIZE=st.MAX_CHUNK_SIZE=void 0;st.chunkData=ku;st.generateLeaves=Nu;st.computeRootHash=z8;st.generateTree=Y1;st.generateTransactionChunks=K8;st.buildLayers=Jf;st.generateProofs=$1;st.arrayFlatten=Ju;st.intToBuffer=gs;st.bufferToInt=Uu;st.validatePath=ps;st.debug=ep;var Nf=vs(),W1=bn();st.MAX_CHUNK_SIZE=256*1024;st.MIN_CHUNK_SIZE=32*1024;var bs=32,no=32;async function ku(t){let e=[],r=t,n=0;for(;r.byteLength>=st.MAX_CHUNK_SIZE;){let i=st.MAX_CHUNK_SIZE,a=r.byteLength-st.MAX_CHUNK_SIZE;a>0&&a<st.MIN_CHUNK_SIZE&&(i=Math.ceil(r.byteLength/2));let d=r.slice(0,i),v=await Nf.default.crypto.hash(d);n+=d.byteLength,e.push({dataHash:v,minByteRange:n-d.byteLength,maxByteRange:n}),r=r.slice(i)}return e.push({dataHash:await Nf.default.crypto.hash(r),minByteRange:n,maxByteRange:n+r.byteLength}),e}async function Nu(t){return Promise.all(t.map(async({dataHash:e,minByteRange:r,maxByteRange:n})=>({type:"leaf",id:await It(await Promise.all([It(e),It(gs(n))])),dataHash:e,minByteRange:r,maxByteRange:n})))}async function z8(t){return(await Y1(t)).id}async function Y1(t){return await Jf(await Nu(await ku(t)))}async function K8(t){let e=await ku(t),r=await Nu(e),n=await Jf(r),i=await $1(n),a=e.slice(-1)[0];return a.maxByteRange-a.minByteRange===0&&(e.splice(e.length-1,1),i.splice(i.length-1,1)),{data_root:n.id,chunks:e,proofs:i}}async function Jf(t,e=0){if(t.length<2)return t[0];let r=[];for(let n=0;n<t.length;n+=2)r.push(await Z8(t[n],t[n+1]));return Jf(r,e+1)}function $1(t){let e=Iu(t);return Array.isArray(e)?Ju(e):[e]}function Iu(t,e=new Uint8Array,r=0){if(t.type=="leaf")return{offset:t.maxByteRange-1,proof:(0,W1.concatBuffers)([e,t.dataHash,gs(t.maxByteRange)])};if(t.type=="branch"){let n=(0,W1.concatBuffers)([e,t.leftChild.id,t.rightChild.id,gs(t.byteRange)]);return[Iu(t.leftChild,n,r+1),Iu(t.rightChild,n,r+1)]}throw new Error("Unexpected node type")}function Ju(t){let e=[];return t.forEach(r=>{Array.isArray(r)?e.push(...Ju(r)):e.push(r)}),e}async function Z8(t,e){return e?{type:"branch",id:await It([await It(t.id),await It(e.id),await It(gs(t.maxByteRange))]),byteRange:t.maxByteRange,maxByteRange:e.maxByteRange,leftChild:t,rightChild:e}:t}async function It(t){return Array.isArray(t)&&(t=Nf.default.utils.concatBuffers(t)),new Uint8Array(await Nf.default.crypto.hash(t))}function gs(t){let e=new Uint8Array(bs);for(var r=e.length-1;r>=0;r--){var n=t%256;e[r]=n,t=(t-n)/256}return e}function Uu(t){let e=0;for(var r=0;r<t.length;r++)e*=256,e+=t[r];return e}var V8=(t,e)=>t.every((r,n)=>e[n]===r);st.arrayCompare=V8;async function ps(t,e,r,n,i){if(n<=0)return!1;if(e>=n)return ps(t,0,n-1,n,i);if(e<0)return ps(t,0,0,n,i);if(i.length==no+bs){let P=i.slice(0,no),D=i.slice(P.length,P.length+bs),F=await It([await It(P),await It(D)]);return(0,st.arrayCompare)(t,F)?{offset:n-1,leftBound:r,rightBound:n,chunkSize:n-r}:!1}let a=i.slice(0,no),d=i.slice(a.length,a.length+no),v=i.slice(a.length+d.length,a.length+d.length+bs),y=Uu(v),m=i.slice(a.length+d.length+v.length),B=await It([await It(a),await It(d),await It(v)]);return(0,st.arrayCompare)(t,B)?e<y?await ps(a,e,r,Math.min(n,y),m):await ps(d,e,Math.max(r,y),n,m):!1}async function ep(t,e=""){if(t.byteLength<1)return e;let r=t.slice(0,no),n=t.slice(r.length,r.length+no),i=t.slice(r.length+n.length,r.length+n.length+bs),a=Uu(i),d=t.slice(r.length+n.length+i.length),v=await It([await It(r),await It(n),await It(i)]),y=`${e}
3
+ `,"N.B. ArweaveJS is only guaranteed to verify txs created using ArweaveJS.")}return P}async jwkToCryptoKey(e){return this.driver.importKey("jwk",e,{name:"RSA-PSS",hash:{name:"SHA-256"}},!1,["sign"])}async jwkToPublicCryptoKey(e){return this.driver.importKey("jwk",e,{name:"RSA-PSS",hash:{name:"SHA-256"}},!1,["verify"])}detectWebCrypto(){if(typeof crypto>"u")return!1;let e=crypto?.subtle;return e===void 0?!1:["generateKey","importKey","exportKey","digest","sign"].every(n=>typeof e[n]=="function")}async encrypt(e,r,n){let i=await this.driver.importKey("raw",typeof r=="string"?Li.stringToBuffer(r):r,{name:"PBKDF2",length:32},!1,["deriveKey"]),a=await this.driver.deriveKey({name:"PBKDF2",salt:n?Li.stringToBuffer(n):Li.stringToBuffer("salt"),iterations:1e5,hash:"SHA-256"},i,{name:"AES-CBC",length:256},!1,["encrypt","decrypt"]),d=new Uint8Array(16);crypto.getRandomValues(d);let v=await this.driver.encrypt({name:"AES-CBC",iv:d},a,e);return Li.concatBuffers([d,v])}async decrypt(e,r,n){let i=await this.driver.importKey("raw",typeof r=="string"?Li.stringToBuffer(r):r,{name:"PBKDF2",length:32},!1,["deriveKey"]),a=await this.driver.deriveKey({name:"PBKDF2",salt:n?Li.stringToBuffer(n):Li.stringToBuffer("salt"),iterations:1e5,hash:"SHA-256"},i,{name:"AES-CBC",length:256},!1,["encrypt","decrypt"]),d=e.slice(0,16),v=await this.driver.decrypt({name:"AES-CBC",iv:d},a,e.slice(16));return Li.concatBuffers([v])}};_u.default=Eu});var Z1=V((K1,If)=>{var Y_=A(M());(function(t){"use strict";var e,r=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,n=Math.ceil,i=Math.floor,a="[BigNumber Error] ",d=a+"Number primitive has more than 15 significant digits: ",v=1e14,y=14,m=9007199254740991,B=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],P=1e7,D=1e9;function F(ie){var ee,ce,te,Y=w.prototype={constructor:w,toString:null,valueOf:null},S=new w(1),s=20,u=4,l=-7,f=21,c=-1e7,g=1e7,x=!1,h=1,o=0,p={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:"\xA0",suffix:""},E="0123456789abcdefghijklmnopqrstuvwxyz",b=!0;function w(_,R){var L,O,G,I,J,z,N,U,Q=this;if(!(Q instanceof w))return new w(_,R);if(R==null){if(_&&_._isBigNumber===!0){Q.s=_.s,!_.c||_.e>g?Q.c=Q.e=null:_.e<c?Q.c=[Q.e=0]:(Q.e=_.e,Q.c=_.c.slice());return}if((z=typeof _=="number")&&_*0==0){if(Q.s=1/_<0?(_=-_,-1):1,_===~~_){for(I=0,J=_;J>=10;J/=10,I++);I>g?Q.c=Q.e=null:(Q.e=I,Q.c=[_]);return}U=String(_)}else{if(!r.test(U=String(_)))return te(Q,U,z);Q.s=U.charCodeAt(0)==45?(U=U.slice(1),-1):1}(I=U.indexOf("."))>-1&&(U=U.replace(".","")),(J=U.search(/e/i))>0?(I<0&&(I=J),I+=+U.slice(J+1),U=U.substring(0,J)):I<0&&(I=U.length)}else{if(K(R,2,E.length,"Base"),R==10&&b)return Q=new w(_),X(Q,s+Q.e+1,u);if(U=String(_),z=typeof _=="number"){if(_*0!=0)return te(Q,U,z,R);if(Q.s=1/_<0?(U=U.slice(1),-1):1,w.DEBUG&&U.replace(/^0\.0*|\./,"").length>15)throw Error(d+_)}else Q.s=U.charCodeAt(0)===45?(U=U.slice(1),-1):1;for(L=E.slice(0,R),I=J=0,N=U.length;J<N;J++)if(L.indexOf(O=U.charAt(J))<0){if(O=="."){if(J>I){I=N;continue}}else if(!G&&(U==U.toUpperCase()&&(U=U.toLowerCase())||U==U.toLowerCase()&&(U=U.toUpperCase()))){G=!0,J=-1,I=0;continue}return te(Q,String(_),z,R)}z=!1,U=ce(U,R,10,Q.s),(I=U.indexOf("."))>-1?U=U.replace(".",""):I=U.length}for(J=0;U.charCodeAt(J)===48;J++);for(N=U.length;U.charCodeAt(--N)===48;);if(U=U.slice(J,++N)){if(N-=J,z&&w.DEBUG&&N>15&&(_>m||_!==i(_)))throw Error(d+Q.s*_);if((I=I-J-1)>g)Q.c=Q.e=null;else if(I<c)Q.c=[Q.e=0];else{if(Q.e=I,Q.c=[],J=(I+1)%y,I<0&&(J+=y),J<N){for(J&&Q.c.push(+U.slice(0,J)),N-=y;J<N;)Q.c.push(+U.slice(J,J+=y));J=y-(U=U.slice(J)).length}else J-=N;for(;J--;U+="0");Q.c.push(+U)}}else Q.c=[Q.e=0]}w.clone=F,w.ROUND_UP=0,w.ROUND_DOWN=1,w.ROUND_CEIL=2,w.ROUND_FLOOR=3,w.ROUND_HALF_UP=4,w.ROUND_HALF_DOWN=5,w.ROUND_HALF_EVEN=6,w.ROUND_HALF_CEIL=7,w.ROUND_HALF_FLOOR=8,w.EUCLID=9,w.config=w.set=function(_){var R,L;if(_!=null)if(typeof _=="object"){if(_.hasOwnProperty(R="DECIMAL_PLACES")&&(L=_[R],K(L,0,D,R),s=L),_.hasOwnProperty(R="ROUNDING_MODE")&&(L=_[R],K(L,0,8,R),u=L),_.hasOwnProperty(R="EXPONENTIAL_AT")&&(L=_[R],L&&L.pop?(K(L[0],-D,0,R),K(L[1],0,D,R),l=L[0],f=L[1]):(K(L,-D,D,R),l=-(f=L<0?-L:L))),_.hasOwnProperty(R="RANGE"))if(L=_[R],L&&L.pop)K(L[0],-D,-1,R),K(L[1],1,D,R),c=L[0],g=L[1];else if(K(L,-D,D,R),L)c=-(g=L<0?-L:L);else throw Error(a+R+" cannot be zero: "+L);if(_.hasOwnProperty(R="CRYPTO"))if(L=_[R],L===!!L)if(L)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))x=L;else throw x=!L,Error(a+"crypto unavailable");else x=L;else throw Error(a+R+" not true or false: "+L);if(_.hasOwnProperty(R="MODULO_MODE")&&(L=_[R],K(L,0,9,R),h=L),_.hasOwnProperty(R="POW_PRECISION")&&(L=_[R],K(L,0,D,R),o=L),_.hasOwnProperty(R="FORMAT"))if(L=_[R],typeof L=="object")p=L;else throw Error(a+R+" not an object: "+L);if(_.hasOwnProperty(R="ALPHABET"))if(L=_[R],typeof L=="string"&&!/^.?$|[+\-.\s]|(.).*\1/.test(L))b=L.slice(0,10)=="0123456789",E=L;else throw Error(a+R+" invalid: "+L)}else throw Error(a+"Object expected: "+_);return{DECIMAL_PLACES:s,ROUNDING_MODE:u,EXPONENTIAL_AT:[l,f],RANGE:[c,g],CRYPTO:x,MODULO_MODE:h,POW_PRECISION:o,FORMAT:p,ALPHABET:E}},w.isBigNumber=function(_){if(!_||_._isBigNumber!==!0)return!1;if(!w.DEBUG)return!0;var R,L,O=_.c,G=_.e,I=_.s;e:if({}.toString.call(O)=="[object Array]"){if((I===1||I===-1)&&G>=-D&&G<=D&&G===i(G)){if(O[0]===0){if(G===0&&O.length===1)return!0;break e}if(R=(G+1)%y,R<1&&(R+=y),String(O[0]).length==R){for(R=0;R<O.length;R++)if(L=O[R],L<0||L>=v||L!==i(L))break e;if(L!==0)return!0}}}else if(O===null&&G===null&&(I===null||I===1||I===-1))return!0;throw Error(a+"Invalid BigNumber: "+_)},w.maximum=w.max=function(){return T(arguments,-1)},w.minimum=w.min=function(){return T(arguments,1)},w.random=function(){var _=9007199254740992,R=Math.random()*_&2097151?function(){return i(Math.random()*_)}:function(){return(Math.random()*1073741824|0)*8388608+(Math.random()*8388608|0)};return function(L){var O,G,I,J,z,N=0,U=[],Q=new w(S);if(L==null?L=s:K(L,0,D),J=n(L/y),x)if(crypto.getRandomValues){for(O=crypto.getRandomValues(new Uint32Array(J*=2));N<J;)z=O[N]*131072+(O[N+1]>>>11),z>=9e15?(G=crypto.getRandomValues(new Uint32Array(2)),O[N]=G[0],O[N+1]=G[1]):(U.push(z%1e14),N+=2);N=J/2}else if(crypto.randomBytes){for(O=crypto.randomBytes(J*=7);N<J;)z=(O[N]&31)*281474976710656+O[N+1]*1099511627776+O[N+2]*4294967296+O[N+3]*16777216+(O[N+4]<<16)+(O[N+5]<<8)+O[N+6],z>=9e15?crypto.randomBytes(7).copy(O,N):(U.push(z%1e14),N+=7);N=J/7}else throw x=!1,Error(a+"crypto unavailable");if(!x)for(;N<J;)z=R(),z<9e15&&(U[N++]=z%1e14);for(J=U[--N],L%=y,J&&L&&(z=B[y-L],U[N]=i(J/z)*z);U[N]===0;U.pop(),N--);if(N<0)U=[I=0];else{for(I=-1;U[0]===0;U.splice(0,1),I-=y);for(N=1,z=U[0];z>=10;z/=10,N++);N<y&&(I-=y-N)}return Q.e=I,Q.c=U,Q}}(),w.sum=function(){for(var _=1,R=arguments,L=new w(R[0]);_<R.length;)L=L.plus(R[_++]);return L},ce=function(){var _="0123456789";function R(L,O,G,I){for(var J,z=[0],N,U=0,Q=L.length;U<Q;){for(N=z.length;N--;z[N]*=O);for(z[0]+=I.indexOf(L.charAt(U++)),J=0;J<z.length;J++)z[J]>G-1&&(z[J+1]==null&&(z[J+1]=0),z[J+1]+=z[J]/G|0,z[J]%=G)}return z.reverse()}return function(L,O,G,I,J){var z,N,U,Q,j,re,De,se,le=L.indexOf("."),Ue=s,oe=u;for(le>=0&&(Q=o,o=0,L=L.replace(".",""),se=new w(O),re=se.pow(L.length-le),o=Q,se.c=R(ae(q(re.c),re.e,"0"),10,G,_),se.e=se.c.length),De=R(L,O,G,J?(z=E,_):(z=_,E)),U=Q=De.length;De[--Q]==0;De.pop());if(!De[0])return z.charAt(0);if(le<0?--U:(re.c=De,re.e=U,re.s=I,re=ee(re,se,Ue,oe,G),De=re.c,j=re.r,U=re.e),N=U+Ue+1,le=De[N],Q=G/2,j=j||N<0||De[N+1]!=null,j=oe<4?(le!=null||j)&&(oe==0||oe==(re.s<0?3:2)):le>Q||le==Q&&(oe==4||j||oe==6&&De[N-1]&1||oe==(re.s<0?8:7)),N<1||!De[0])L=j?ae(z.charAt(1),-Ue,z.charAt(0)):z.charAt(0);else{if(De.length=N,j)for(--G;++De[--N]>G;)De[N]=0,N||(++U,De=[1].concat(De));for(Q=De.length;!De[--Q];);for(le=0,L="";le<=Q;L+=z.charAt(De[le++]));L=ae(L,U,z.charAt(0))}return L}}(),ee=function(){function _(O,G,I){var J,z,N,U,Q=0,j=O.length,re=G%P,De=G/P|0;for(O=O.slice();j--;)N=O[j]%P,U=O[j]/P|0,J=De*N+U*re,z=re*N+J%P*P+Q,Q=(z/I|0)+(J/P|0)+De*U,O[j]=z%I;return Q&&(O=[Q].concat(O)),O}function R(O,G,I,J){var z,N;if(I!=J)N=I>J?1:-1;else for(z=N=0;z<I;z++)if(O[z]!=G[z]){N=O[z]>G[z]?1:-1;break}return N}function L(O,G,I,J){for(var z=0;I--;)O[I]-=z,z=O[I]<G[I]?1:0,O[I]=z*J+O[I]-G[I];for(;!O[0]&&O.length>1;O.splice(0,1));}return function(O,G,I,J,z){var N,U,Q,j,re,De,se,le,Ue,oe,fe,Xe,ge,ve,gt,pe,be,Ye=O.s==G.s?1:-1,de=O.c,ue=G.c;if(!de||!de[0]||!ue||!ue[0])return new w(!O.s||!G.s||(de?ue&&de[0]==ue[0]:!ue)?NaN:de&&de[0]==0||!ue?Ye*0:Ye/0);for(le=new w(Ye),Ue=le.c=[],U=O.e-G.e,Ye=I+U+1,z||(z=v,U=C(O.e/y)-C(G.e/y),Ye=Ye/y|0),Q=0;ue[Q]==(de[Q]||0);Q++);if(ue[Q]>(de[Q]||0)&&U--,Ye<0)Ue.push(1),j=!0;else{for(ve=de.length,pe=ue.length,Q=0,Ye+=2,re=i(z/(ue[0]+1)),re>1&&(ue=_(ue,re,z),de=_(de,re,z),pe=ue.length,ve=de.length),ge=pe,oe=de.slice(0,pe),fe=oe.length;fe<pe;oe[fe++]=0);be=ue.slice(),be=[0].concat(be),gt=ue[0],ue[1]>=z/2&&gt++;do{if(re=0,N=R(ue,oe,pe,fe),N<0){if(Xe=oe[0],pe!=fe&&(Xe=Xe*z+(oe[1]||0)),re=i(Xe/gt),re>1)for(re>=z&&(re=z-1),De=_(ue,re,z),se=De.length,fe=oe.length;R(De,oe,se,fe)==1;)re--,L(De,pe<se?be:ue,se,z),se=De.length,N=1;else re==0&&(N=re=1),De=ue.slice(),se=De.length;if(se<fe&&(De=[0].concat(De)),L(oe,De,fe,z),fe=oe.length,N==-1)for(;R(ue,oe,pe,fe)<1;)re++,L(oe,pe<fe?be:ue,fe,z),fe=oe.length}else N===0&&(re++,oe=[0]);Ue[Q++]=re,oe[0]?oe[fe++]=de[ge]||0:(oe=[de[ge]],fe=1)}while((ge++<ve||oe[0]!=null)&&Ye--);j=oe[0]!=null,Ue[0]||Ue.splice(0,1)}if(z==v){for(Q=1,Ye=Ue[0];Ye>=10;Ye/=10,Q++);X(le,I+(le.e=Q+U*y-1)+1,J,j)}else le.e=U,le.r=+j;return le}}();function H(_,R,L,O){var G,I,J,z,N;if(L==null?L=u:K(L,0,8),!_.c)return _.toString();if(G=_.c[0],J=_.e,R==null)N=q(_.c),N=O==1||O==2&&(J<=l||J>=f)?$(N,J):ae(N,J,"0");else if(_=X(new w(_),R,L),I=_.e,N=q(_.c),z=N.length,O==1||O==2&&(R<=I||I<=l)){for(;z<R;N+="0",z++);N=$(N,I)}else if(R-=J+(O===2&&I>J),N=ae(N,I,"0"),I+1>z){if(--R>0)for(N+=".";R--;N+="0");}else if(R+=I-z,R>0)for(I+1==z&&(N+=".");R--;N+="0");return _.s<0&&G?"-"+N:N}function T(_,R){for(var L,O,G=1,I=new w(_[0]);G<_.length;G++)O=new w(_[G]),(!O.s||(L=W(I,O))===R||L===0&&I.s===R)&&(I=O);return I}function k(_,R,L){for(var O=1,G=R.length;!R[--G];R.pop());for(G=R[0];G>=10;G/=10,O++);return(L=O+L*y-1)>g?_.c=_.e=null:L<c?_.c=[_.e=0]:(_.e=L,_.c=R),_}te=function(){var _=/^(-?)0([xbo])(?=\w[\w.]*$)/i,R=/^([^.]+)\.$/,L=/^\.([^.]+)$/,O=/^-?(Infinity|NaN)$/,G=/^\s*\+(?=[\w.])|^\s+|\s+$/g;return function(I,J,z,N){var U,Q=z?J:J.replace(G,"");if(O.test(Q))I.s=isNaN(Q)?null:Q<0?-1:1;else{if(!z&&(Q=Q.replace(_,function(j,re,De){return U=(De=De.toLowerCase())=="x"?16:De=="b"?2:8,!N||N==U?re:j}),N&&(U=N,Q=Q.replace(R,"$1").replace(L,"0.$1")),J!=Q))return new w(Q,U);if(w.DEBUG)throw Error(a+"Not a"+(N?" base "+N:"")+" number: "+J);I.s=null}I.c=I.e=null}}();function X(_,R,L,O){var G,I,J,z,N,U,Q,j=_.c,re=B;if(j){e:{for(G=1,z=j[0];z>=10;z/=10,G++);if(I=R-G,I<0)I+=y,J=R,N=j[U=0],Q=i(N/re[G-J-1]%10);else if(U=n((I+1)/y),U>=j.length)if(O){for(;j.length<=U;j.push(0));N=Q=0,G=1,I%=y,J=I-y+1}else break e;else{for(N=z=j[U],G=1;z>=10;z/=10,G++);I%=y,J=I-y+G,Q=J<0?0:i(N/re[G-J-1]%10)}if(O=O||R<0||j[U+1]!=null||(J<0?N:N%re[G-J-1]),O=L<4?(Q||O)&&(L==0||L==(_.s<0?3:2)):Q>5||Q==5&&(L==4||O||L==6&&(I>0?J>0?N/re[G-J]:0:j[U-1])%10&1||L==(_.s<0?8:7)),R<1||!j[0])return j.length=0,O?(R-=_.e+1,j[0]=re[(y-R%y)%y],_.e=-R||0):j[0]=_.e=0,_;if(I==0?(j.length=U,z=1,U--):(j.length=U+1,z=re[y-I],j[U]=J>0?i(N/re[G-J]%re[J])*z:0),O)for(;;)if(U==0){for(I=1,J=j[0];J>=10;J/=10,I++);for(J=j[0]+=z,z=1;J>=10;J/=10,z++);I!=z&&(_.e++,j[0]==v&&(j[0]=1));break}else{if(j[U]+=z,j[U]!=v)break;j[U--]=0,z=1}for(I=j.length;j[--I]===0;j.pop());}_.e>g?_.c=_.e=null:_.e<c&&(_.c=[_.e=0])}return _}function Z(_){var R,L=_.e;return L===null?_.toString():(R=q(_.c),R=L<=l||L>=f?$(R,L):ae(R,L,"0"),_.s<0?"-"+R:R)}return Y.absoluteValue=Y.abs=function(){var _=new w(this);return _.s<0&&(_.s=1),_},Y.comparedTo=function(_,R){return W(this,new w(_,R))},Y.decimalPlaces=Y.dp=function(_,R){var L,O,G,I=this;if(_!=null)return K(_,0,D),R==null?R=u:K(R,0,8),X(new w(I),_+I.e+1,R);if(!(L=I.c))return null;if(O=((G=L.length-1)-C(this.e/y))*y,G=L[G])for(;G%10==0;G/=10,O--);return O<0&&(O=0),O},Y.dividedBy=Y.div=function(_,R){return ee(this,new w(_,R),s,u)},Y.dividedToIntegerBy=Y.idiv=function(_,R){return ee(this,new w(_,R),0,1)},Y.exponentiatedBy=Y.pow=function(_,R){var L,O,G,I,J,z,N,U,Q,j=this;if(_=new w(_),_.c&&!_.isInteger())throw Error(a+"Exponent not an integer: "+Z(_));if(R!=null&&(R=new w(R)),z=_.e>14,!j.c||!j.c[0]||j.c[0]==1&&!j.e&&j.c.length==1||!_.c||!_.c[0])return Q=new w(Math.pow(+Z(j),z?_.s*(2-ne(_)):+Z(_))),R?Q.mod(R):Q;if(N=_.s<0,R){if(R.c?!R.c[0]:!R.s)return new w(NaN);O=!N&&j.isInteger()&&R.isInteger(),O&&(j=j.mod(R))}else{if(_.e>9&&(j.e>0||j.e<-1||(j.e==0?j.c[0]>1||z&&j.c[1]>=24e7:j.c[0]<8e13||z&&j.c[0]<=9999975e7)))return I=j.s<0&&ne(_)?-0:0,j.e>-1&&(I=1/I),new w(N?1/I:I);o&&(I=n(o/y+2))}for(z?(L=new w(.5),N&&(_.s=1),U=ne(_)):(G=Math.abs(+Z(_)),U=G%2),Q=new w(S);;){if(U){if(Q=Q.times(j),!Q.c)break;I?Q.c.length>I&&(Q.c.length=I):O&&(Q=Q.mod(R))}if(G){if(G=i(G/2),G===0)break;U=G%2}else if(_=_.times(L),X(_,_.e+1,1),_.e>14)U=ne(_);else{if(G=+Z(_),G===0)break;U=G%2}j=j.times(j),I?j.c&&j.c.length>I&&(j.c.length=I):O&&(j=j.mod(R))}return O?Q:(N&&(Q=S.div(Q)),R?Q.mod(R):I?X(Q,o,u,J):Q)},Y.integerValue=function(_){var R=new w(this);return _==null?_=u:K(_,0,8),X(R,R.e+1,_)},Y.isEqualTo=Y.eq=function(_,R){return W(this,new w(_,R))===0},Y.isFinite=function(){return!!this.c},Y.isGreaterThan=Y.gt=function(_,R){return W(this,new w(_,R))>0},Y.isGreaterThanOrEqualTo=Y.gte=function(_,R){return(R=W(this,new w(_,R)))===1||R===0},Y.isInteger=function(){return!!this.c&&C(this.e/y)>this.c.length-2},Y.isLessThan=Y.lt=function(_,R){return W(this,new w(_,R))<0},Y.isLessThanOrEqualTo=Y.lte=function(_,R){return(R=W(this,new w(_,R)))===-1||R===0},Y.isNaN=function(){return!this.s},Y.isNegative=function(){return this.s<0},Y.isPositive=function(){return this.s>0},Y.isZero=function(){return!!this.c&&this.c[0]==0},Y.minus=function(_,R){var L,O,G,I,J=this,z=J.s;if(_=new w(_,R),R=_.s,!z||!R)return new w(NaN);if(z!=R)return _.s=-R,J.plus(_);var N=J.e/y,U=_.e/y,Q=J.c,j=_.c;if(!N||!U){if(!Q||!j)return Q?(_.s=-R,_):new w(j?J:NaN);if(!Q[0]||!j[0])return j[0]?(_.s=-R,_):new w(Q[0]?J:u==3?-0:0)}if(N=C(N),U=C(U),Q=Q.slice(),z=N-U){for((I=z<0)?(z=-z,G=Q):(U=N,G=j),G.reverse(),R=z;R--;G.push(0));G.reverse()}else for(O=(I=(z=Q.length)<(R=j.length))?z:R,z=R=0;R<O;R++)if(Q[R]!=j[R]){I=Q[R]<j[R];break}if(I&&(G=Q,Q=j,j=G,_.s=-_.s),R=(O=j.length)-(L=Q.length),R>0)for(;R--;Q[L++]=0);for(R=v-1;O>z;){if(Q[--O]<j[O]){for(L=O;L&&!Q[--L];Q[L]=R);--Q[L],Q[O]+=v}Q[O]-=j[O]}for(;Q[0]==0;Q.splice(0,1),--U);return Q[0]?k(_,Q,U):(_.s=u==3?-1:1,_.c=[_.e=0],_)},Y.modulo=Y.mod=function(_,R){var L,O,G=this;return _=new w(_,R),!G.c||!_.s||_.c&&!_.c[0]?new w(NaN):!_.c||G.c&&!G.c[0]?new w(G):(h==9?(O=_.s,_.s=1,L=ee(G,_,0,3),_.s=O,L.s*=O):L=ee(G,_,0,h),_=G.minus(L.times(_)),!_.c[0]&&h==1&&(_.s=G.s),_)},Y.multipliedBy=Y.times=function(_,R){var L,O,G,I,J,z,N,U,Q,j,re,De,se,le,Ue,oe=this,fe=oe.c,Xe=(_=new w(_,R)).c;if(!fe||!Xe||!fe[0]||!Xe[0])return!oe.s||!_.s||fe&&!fe[0]&&!Xe||Xe&&!Xe[0]&&!fe?_.c=_.e=_.s=null:(_.s*=oe.s,!fe||!Xe?_.c=_.e=null:(_.c=[0],_.e=0)),_;for(O=C(oe.e/y)+C(_.e/y),_.s*=oe.s,N=fe.length,j=Xe.length,N<j&&(se=fe,fe=Xe,Xe=se,G=N,N=j,j=G),G=N+j,se=[];G--;se.push(0));for(le=v,Ue=P,G=j;--G>=0;){for(L=0,re=Xe[G]%Ue,De=Xe[G]/Ue|0,J=N,I=G+J;I>G;)U=fe[--J]%Ue,Q=fe[J]/Ue|0,z=De*U+Q*re,U=re*U+z%Ue*Ue+se[I]+L,L=(U/le|0)+(z/Ue|0)+De*Q,se[I--]=U%le;se[I]=L}return L?++O:se.splice(0,1),k(_,se,O)},Y.negated=function(){var _=new w(this);return _.s=-_.s||null,_},Y.plus=function(_,R){var L,O=this,G=O.s;if(_=new w(_,R),R=_.s,!G||!R)return new w(NaN);if(G!=R)return _.s=-R,O.minus(_);var I=O.e/y,J=_.e/y,z=O.c,N=_.c;if(!I||!J){if(!z||!N)return new w(G/0);if(!z[0]||!N[0])return N[0]?_:new w(z[0]?O:G*0)}if(I=C(I),J=C(J),z=z.slice(),G=I-J){for(G>0?(J=I,L=N):(G=-G,L=z),L.reverse();G--;L.push(0));L.reverse()}for(G=z.length,R=N.length,G-R<0&&(L=N,N=z,z=L,R=G),G=0;R;)G=(z[--R]=z[R]+N[R]+G)/v|0,z[R]=v===z[R]?0:z[R]%v;return G&&(z=[G].concat(z),++J),k(_,z,J)},Y.precision=Y.sd=function(_,R){var L,O,G,I=this;if(_!=null&&_!==!!_)return K(_,1,D),R==null?R=u:K(R,0,8),X(new w(I),_,R);if(!(L=I.c))return null;if(G=L.length-1,O=G*y+1,G=L[G]){for(;G%10==0;G/=10,O--);for(G=L[0];G>=10;G/=10,O++);}return _&&I.e+1>O&&(O=I.e+1),O},Y.shiftedBy=function(_){return K(_,-m,m),this.times("1e"+_)},Y.squareRoot=Y.sqrt=function(){var _,R,L,O,G,I=this,J=I.c,z=I.s,N=I.e,U=s+4,Q=new w("0.5");if(z!==1||!J||!J[0])return new w(!z||z<0&&(!J||J[0])?NaN:J?I:1/0);if(z=Math.sqrt(+Z(I)),z==0||z==1/0?(R=q(J),(R.length+N)%2==0&&(R+="0"),z=Math.sqrt(+R),N=C((N+1)/2)-(N<0||N%2),z==1/0?R="5e"+N:(R=z.toExponential(),R=R.slice(0,R.indexOf("e")+1)+N),L=new w(R)):L=new w(z+""),L.c[0]){for(N=L.e,z=N+U,z<3&&(z=0);;)if(G=L,L=Q.times(G.plus(ee(I,G,U,1))),q(G.c).slice(0,z)===(R=q(L.c)).slice(0,z))if(L.e<N&&--z,R=R.slice(z-3,z+1),R=="9999"||!O&&R=="4999"){if(!O&&(X(G,G.e+s+2,0),G.times(G).eq(I))){L=G;break}U+=4,z+=4,O=1}else{(!+R||!+R.slice(1)&&R.charAt(0)=="5")&&(X(L,L.e+s+2,1),_=!L.times(L).eq(I));break}}return X(L,L.e+s+1,u,_)},Y.toExponential=function(_,R){return _!=null&&(K(_,0,D),_++),H(this,_,R,1)},Y.toFixed=function(_,R){return _!=null&&(K(_,0,D),_=_+this.e+1),H(this,_,R)},Y.toFormat=function(_,R,L){var O,G=this;if(L==null)_!=null&&R&&typeof R=="object"?(L=R,R=null):_&&typeof _=="object"?(L=_,_=R=null):L=p;else if(typeof L!="object")throw Error(a+"Argument not an object: "+L);if(O=G.toFixed(_,R),G.c){var I,J=O.split("."),z=+L.groupSize,N=+L.secondaryGroupSize,U=L.groupSeparator||"",Q=J[0],j=J[1],re=G.s<0,De=re?Q.slice(1):Q,se=De.length;if(N&&(I=z,z=N,N=I,se-=I),z>0&&se>0){for(I=se%z||z,Q=De.substr(0,I);I<se;I+=z)Q+=U+De.substr(I,z);N>0&&(Q+=U+De.slice(I)),re&&(Q="-"+Q)}O=j?Q+(L.decimalSeparator||"")+((N=+L.fractionGroupSize)?j.replace(new RegExp("\\d{"+N+"}\\B","g"),"$&"+(L.fractionGroupSeparator||"")):j):Q}return(L.prefix||"")+O+(L.suffix||"")},Y.toFraction=function(_){var R,L,O,G,I,J,z,N,U,Q,j,re,De=this,se=De.c;if(_!=null&&(z=new w(_),!z.isInteger()&&(z.c||z.s!==1)||z.lt(S)))throw Error(a+"Argument "+(z.isInteger()?"out of range: ":"not an integer: ")+Z(z));if(!se)return new w(De);for(R=new w(S),U=L=new w(S),O=N=new w(S),re=q(se),I=R.e=re.length-De.e-1,R.c[0]=B[(J=I%y)<0?y+J:J],_=!_||z.comparedTo(R)>0?I>0?R:U:z,J=g,g=1/0,z=new w(re),N.c[0]=0;Q=ee(z,R,0,1),G=L.plus(Q.times(O)),G.comparedTo(_)!=1;)L=O,O=G,U=N.plus(Q.times(G=U)),N=G,R=z.minus(Q.times(G=R)),z=G;return G=ee(_.minus(L),O,0,1),N=N.plus(G.times(U)),L=L.plus(G.times(O)),N.s=U.s=De.s,I=I*2,j=ee(U,O,I,u).minus(De).abs().comparedTo(ee(N,L,I,u).minus(De).abs())<1?[U,O]:[N,L],g=J,j},Y.toNumber=function(){return+Z(this)},Y.toPrecision=function(_,R){return _!=null&&K(_,1,D),H(this,_,R,2)},Y.toString=function(_){var R,L=this,O=L.s,G=L.e;return G===null?O?(R="Infinity",O<0&&(R="-"+R)):R="NaN":(_==null?R=G<=l||G>=f?$(q(L.c),G):ae(q(L.c),G,"0"):_===10&&b?(L=X(new w(L),s+G+1,u),R=ae(q(L.c),L.e,"0")):(K(_,2,E.length,"Base"),R=ce(ae(q(L.c),G,"0"),10,_,O,!0)),O<0&&L.c[0]&&(R="-"+R)),R},Y.valueOf=Y.toJSON=function(){return Z(this)},Y._isBigNumber=!0,ie!=null&&w.set(ie),w}function C(ie){var ee=ie|0;return ie>0||ie===ee?ee:ee-1}function q(ie){for(var ee,ce,te=1,Y=ie.length,S=ie[0]+"";te<Y;){for(ee=ie[te++]+"",ce=y-ee.length;ce--;ee="0"+ee);S+=ee}for(Y=S.length;S.charCodeAt(--Y)===48;);return S.slice(0,Y+1||1)}function W(ie,ee){var ce,te,Y=ie.c,S=ee.c,s=ie.s,u=ee.s,l=ie.e,f=ee.e;if(!s||!u)return null;if(ce=Y&&!Y[0],te=S&&!S[0],ce||te)return ce?te?0:-u:s;if(s!=u)return s;if(ce=s<0,te=l==f,!Y||!S)return te?0:!Y^ce?1:-1;if(!te)return l>f^ce?1:-1;for(u=(l=Y.length)<(f=S.length)?l:f,s=0;s<u;s++)if(Y[s]!=S[s])return Y[s]>S[s]^ce?1:-1;return l==f?0:l>f^ce?1:-1}function K(ie,ee,ce,te){if(ie<ee||ie>ce||ie!==i(ie))throw Error(a+(te||"Argument")+(typeof ie=="number"?ie<ee||ie>ce?" out of range: ":" not an integer: ":" not a primitive number: ")+String(ie))}function ne(ie){var ee=ie.c.length-1;return C(ie.e/y)==ee&&ie.c[ee]%2!=0}function $(ie,ee){return(ie.length>1?ie.charAt(0)+"."+ie.slice(1):ie)+(ee<0?"e":"e+")+ee}function ae(ie,ee,ce){var te,Y;if(ee<0){for(Y=ce+".";++ee;Y+=ce);ie=Y+ie}else if(te=ie.length,++ee>te){for(Y=ce,ee-=te;--ee;Y+=ce);ie+=Y}else ee<te&&(ie=ie.slice(0,ee)+"."+ie.slice(ee));return ie}e=F(),e.default=e.BigNumber=e,typeof define=="function"&&define.amd?define(function(){return e}):typeof If<"u"&&If.exports?If.exports=e:(t||(t=typeof self<"u"&&self?self:window),t.BigNumber=e)})(K1)});var V1=V(Pu=>{"use strict";var eB=A(M());Object.defineProperty(Pu,"__esModule",{value:!0});var H8=Z1(),Cu=class{BigNum;constructor(){this.BigNum=(e,r)=>{let n=H8.BigNumber.clone({DECIMAL_PLACES:r});return new n(e)}}winstonToAr(e,{formatted:r=!1,decimals:n=12,trim:i=!0}={}){let a=this.stringToBigNum(e,n).shiftedBy(-12);return r?a.toFormat(n):a.toFixed(n)}arToWinston(e,{formatted:r=!1}={}){let n=this.stringToBigNum(e).shiftedBy(12);return r?n.toFormat():n.toFixed(0)}compare(e,r){let n=this.stringToBigNum(e),i=this.stringToBigNum(r);return n.comparedTo(i)}isEqual(e,r){return this.compare(e,r)===0}isLessThan(e,r){let n=this.stringToBigNum(e),i=this.stringToBigNum(r);return n.isLessThan(i)}isGreaterThan(e,r){let n=this.stringToBigNum(e),i=this.stringToBigNum(r);return n.isGreaterThan(i)}add(e,r){let n=this.stringToBigNum(e),i=this.stringToBigNum(r);return n.plus(r).toFixed(0)}sub(e,r){let n=this.stringToBigNum(e),i=this.stringToBigNum(r);return n.minus(r).toFixed(0)}stringToBigNum(e,r=12){return this.BigNum(e,r)}};Pu.default=Cu});var j1=V(Ru=>{"use strict";var rB=A(M());Object.defineProperty(Ru,"__esModule",{value:!0});var Lu=class{METHOD_GET="GET";METHOD_POST="POST";config;constructor(e){this.applyConfig(e)}applyConfig(e){this.config=this.mergeDefaults(e)}getConfig(){return this.config}mergeDefaults(e){let r=e.protocol||"http",n=e.port||(r==="https"?443:80);return{host:e.host||"127.0.0.1",protocol:r,port:n,timeout:e.timeout||2e4,logging:e.logging||!1,logger:e.logger||console.log,network:e.network}}async get(e,r){return await this.request(e,{...r,method:this.METHOD_GET})}async post(e,r,n){let i=new Headers(n?.headers||{});return i.get("content-type")?.includes("application/json")||i.append("content-type","application/json"),i.append("accept","application/json, text/plain, */*"),await this.request(e,{...n,method:this.METHOD_POST,body:typeof r!="string"?JSON.stringify(r):r,headers:i})}async request(e,r){let n=new Headers(r?.headers||{}),i=`${this.config.protocol}://${this.config.host}:${this.config.port}`,a=r?.responseType;delete r?.responseType,e.startsWith("/")&&(e=e.slice(1)),this.config.network&&n.append("x-network",this.config.network),this.config.logging&&this.config.logger(`Requesting: ${i}/${e}`);let d=await fetch(`${i}/${e}`,{...r||{},headers:n});this.config.logging&&this.config.logger(`Response: ${d.url} - ${d.status}`);let y=d.headers.get("content-type")?.match(/charset=([^()<>@,;:\"/[\]?.=\s]*)/i)?.[1],m=d,B=async()=>{if(y)try{m.data=new TextDecoder(y).decode(await d.arrayBuffer())}catch{m.data=await d.text()}else m.data=await d.text()};if(a==="arraybuffer")m.data=await d.arrayBuffer();else if(a==="text")await B();else if(a==="webstream")m.data=q8(d.body);else try{let P=await d.clone().json();typeof P!="object"?await B():m.data=await d.json(),P=null}catch{await B()}return m}};Ru.default=Lu;var q8=t=>{let e=t;return typeof e[Symbol.asyncIterator]>"u"&&(e[Symbol.asyncIterator]=G8(t)),e},G8=function(t){return async function*(){let r=t.getReader();try{for(;;){let{done:n,value:i}=await r.read();if(n)return;yield i}}finally{r.releaseLock()}}}});var Q1=V(Du=>{"use strict";var iB=A(M());Object.defineProperty(Du,"__esModule",{value:!0});var Fu=class{api;constructor(e){this.api=e}getInfo(){return this.api.get("info").then(e=>e.data)}getPeers(){return this.api.get("peers").then(e=>e.data)}};Du.default=Fu});var hs=V(kf=>{"use strict";var oB=A(M());Object.defineProperty(kf,"__esModule",{value:!0});kf.getError=X8;var Ou=class extends Error{type;response;constructor(e,r={}){r.message?super(r.message):super(),this.type=e,this.response=r.response}getType(){return this.type}};kf.default=Ou;function X8(t){let e=t.data;if(typeof t.data=="string")try{e=JSON.parse(t.data)}catch{}if(t.data instanceof ArrayBuffer||t.data instanceof Uint8Array)try{e=JSON.parse(e.toString())}catch{}return e?e.error||e:t.statusText||"unknown"}});var Hu=V(st=>{"use strict";var fB=A(M());Object.defineProperty(st,"__esModule",{value:!0});st.arrayCompare=st.MIN_CHUNK_SIZE=st.MAX_CHUNK_SIZE=void 0;st.chunkData=ku;st.generateLeaves=Nu;st.computeRootHash=z8;st.generateTree=Y1;st.generateTransactionChunks=K8;st.buildLayers=Jf;st.generateProofs=$1;st.arrayFlatten=Ju;st.intToBuffer=gs;st.bufferToInt=Uu;st.validatePath=ps;st.debug=ep;var Nf=vs(),W1=bn();st.MAX_CHUNK_SIZE=256*1024;st.MIN_CHUNK_SIZE=32*1024;var bs=32,no=32;async function ku(t){let e=[],r=t,n=0;for(;r.byteLength>=st.MAX_CHUNK_SIZE;){let i=st.MAX_CHUNK_SIZE,a=r.byteLength-st.MAX_CHUNK_SIZE;a>0&&a<st.MIN_CHUNK_SIZE&&(i=Math.ceil(r.byteLength/2));let d=r.slice(0,i),v=await Nf.default.crypto.hash(d);n+=d.byteLength,e.push({dataHash:v,minByteRange:n-d.byteLength,maxByteRange:n}),r=r.slice(i)}return e.push({dataHash:await Nf.default.crypto.hash(r),minByteRange:n,maxByteRange:n+r.byteLength}),e}async function Nu(t){return Promise.all(t.map(async({dataHash:e,minByteRange:r,maxByteRange:n})=>({type:"leaf",id:await It(await Promise.all([It(e),It(gs(n))])),dataHash:e,minByteRange:r,maxByteRange:n})))}async function z8(t){return(await Y1(t)).id}async function Y1(t){return await Jf(await Nu(await ku(t)))}async function K8(t){let e=await ku(t),r=await Nu(e),n=await Jf(r),i=await $1(n),a=e.slice(-1)[0];return a.maxByteRange-a.minByteRange===0&&(e.splice(e.length-1,1),i.splice(i.length-1,1)),{data_root:n.id,chunks:e,proofs:i}}async function Jf(t,e=0){if(t.length<2)return t[0];let r=[];for(let n=0;n<t.length;n+=2)r.push(await Z8(t[n],t[n+1]));return Jf(r,e+1)}function $1(t){let e=Iu(t);return Array.isArray(e)?Ju(e):[e]}function Iu(t,e=new Uint8Array,r=0){if(t.type=="leaf")return{offset:t.maxByteRange-1,proof:(0,W1.concatBuffers)([e,t.dataHash,gs(t.maxByteRange)])};if(t.type=="branch"){let n=(0,W1.concatBuffers)([e,t.leftChild.id,t.rightChild.id,gs(t.byteRange)]);return[Iu(t.leftChild,n,r+1),Iu(t.rightChild,n,r+1)]}throw new Error("Unexpected node type")}function Ju(t){let e=[];return t.forEach(r=>{Array.isArray(r)?e.push(...Ju(r)):e.push(r)}),e}async function Z8(t,e){return e?{type:"branch",id:await It([await It(t.id),await It(e.id),await It(gs(t.maxByteRange))]),byteRange:t.maxByteRange,maxByteRange:e.maxByteRange,leftChild:t,rightChild:e}:t}async function It(t){return Array.isArray(t)&&(t=Nf.default.utils.concatBuffers(t)),new Uint8Array(await Nf.default.crypto.hash(t))}function gs(t){let e=new Uint8Array(bs);for(var r=e.length-1;r>=0;r--){var n=t%256;e[r]=n,t=(t-n)/256}return e}function Uu(t){let e=0;for(var r=0;r<t.length;r++)e*=256,e+=t[r];return e}var V8=(t,e)=>t.every((r,n)=>e[n]===r);st.arrayCompare=V8;async function ps(t,e,r,n,i){if(n<=0)return!1;if(e>=n)return ps(t,0,n-1,n,i);if(e<0)return ps(t,0,0,n,i);if(i.length==no+bs){let P=i.slice(0,no),D=i.slice(P.length,P.length+bs),F=await It([await It(P),await It(D)]);return(0,st.arrayCompare)(t,F)?{offset:n-1,leftBound:r,rightBound:n,chunkSize:n-r}:!1}let a=i.slice(0,no),d=i.slice(a.length,a.length+no),v=i.slice(a.length+d.length,a.length+d.length+bs),y=Uu(v),m=i.slice(a.length+d.length+v.length),B=await It([await It(a),await It(d),await It(v)]);return(0,st.arrayCompare)(t,B)?e<y?await ps(a,e,r,Math.min(n,y),m):await ps(d,e,Math.max(r,y),n,m):!1}async function ep(t,e=""){if(t.byteLength<1)return e;let r=t.slice(0,no),n=t.slice(r.length,r.length+no),i=t.slice(r.length+n.length,r.length+n.length+bs),a=Uu(i),d=t.slice(r.length+n.length+i.length),v=await It([await It(r),await It(n),await It(i)]),y=`${e}
4
4
  ${JSON.stringify(Buffer.from(r))},${JSON.stringify(Buffer.from(n))},${a} => ${JSON.stringify(v)}`;return ep(d,y)}});var ip=V(Uf=>{"use strict";var uB=A(M());Object.defineProperty(Uf,"__esModule",{value:!0});Uf.TransactionUploader=void 0;var tp=xs(),j8=bn(),qu=hs(),Q8=Hu(),rp=1,W8=["invalid_json","chunk_too_big","data_path_too_big","offset_too_big","data_size_too_big","chunk_proof_ratio_not_attractive","invalid_proof"],np=1e3*40,Gu=class t{api;chunkIndex=0;txPosted=!1;transaction;lastRequestTimeEnd=0;totalErrors=0;data;lastResponseStatus=0;lastResponseError="";get isComplete(){return this.txPosted&&this.chunkIndex===this.transaction.chunks.chunks.length}get totalChunks(){return this.transaction.chunks.chunks.length}get uploadedChunks(){return this.chunkIndex}get pctComplete(){return Math.trunc(this.uploadedChunks/this.totalChunks*100)}constructor(e,r){if(this.api=e,!r.id)throw new Error("Transaction is not signed");if(!r.chunks)throw new Error("Transaction chunks not prepared");this.data=r.data,this.transaction=new tp.default(Object.assign({},r,{data:new Uint8Array(0)}))}async uploadChunk(e){if(this.isComplete)throw new Error("Upload is already complete");if(this.lastResponseError!==""?this.totalErrors++:this.totalErrors=0,this.totalErrors===100)throw new Error(`Unable to complete upload: ${this.lastResponseStatus}: ${this.lastResponseError}`);let r=this.lastResponseError===""?0:Math.max(this.lastRequestTimeEnd+np-Date.now(),np);if(r>0&&(r=r-r*Math.random()*.3,await new Promise(d=>setTimeout(d,r))),this.lastResponseError="",!this.txPosted){await this.postTransaction();return}e&&(this.chunkIndex=e);let n=this.transaction.getChunk(e||this.chunkIndex,this.data);if(!await(0,Q8.validatePath)(this.transaction.chunks.data_root,parseInt(n.offset),0,parseInt(n.data_size),j8.b64UrlToBuffer(n.data_path)))throw new Error(`Unable to validate chunk ${this.chunkIndex}`);let a=await this.api.post("chunk",this.transaction.getChunk(this.chunkIndex,this.data)).catch(d=>(console.error(d.message),{status:-1,data:{error:d.message}}));if(this.lastRequestTimeEnd=Date.now(),this.lastResponseStatus=a.status,this.lastResponseStatus==200)this.chunkIndex++;else if(this.lastResponseError=(0,qu.getError)(a),W8.includes(this.lastResponseError))throw new Error(`Fatal error uploading chunk ${this.chunkIndex}: ${this.lastResponseError}`)}static async fromSerialized(e,r,n){if(!r||typeof r.chunkIndex!="number"||typeof r.transaction!="object")throw new Error("Serialized object does not match expected format.");var i=new tp.default(r.transaction);i.chunks||await i.prepareChunks(n);let a=new t(e,i);if(a.chunkIndex=r.chunkIndex,a.lastRequestTimeEnd=r.lastRequestTimeEnd,a.lastResponseError=r.lastResponseError,a.lastResponseStatus=r.lastResponseStatus,a.txPosted=r.txPosted,a.data=n,a.transaction.data_root!==r.transaction.data_root)throw new Error("Data mismatch: Uploader doesn't match provided data.");return a}static async fromTransactionId(e,r){let n=await e.get(`tx/${r}`);if(n.status!==200)throw new Error(`Tx ${r} not found: ${n.status}`);let i=n.data;return i.data=new Uint8Array(0),{txPosted:!0,chunkIndex:0,lastResponseError:"",lastRequestTimeEnd:0,lastResponseStatus:0,transaction:i}}toJSON(){return{chunkIndex:this.chunkIndex,transaction:this.transaction,lastRequestTimeEnd:this.lastRequestTimeEnd,lastResponseStatus:this.lastResponseStatus,lastResponseError:this.lastResponseError,txPosted:this.txPosted}}async postTransaction(){if(this.totalChunks<=rp){this.transaction.data=this.data;let n=await this.api.post("tx",this.transaction).catch(i=>(console.error(i),{status:-1,data:{error:i.message}}));if(this.lastRequestTimeEnd=Date.now(),this.lastResponseStatus=n.status,this.transaction.data=new Uint8Array(0),n.status>=200&&n.status<300){this.txPosted=!0,this.chunkIndex=rp;return}throw this.lastResponseError=(0,qu.getError)(n),new Error(`Unable to upload transaction: ${n.status}, ${this.lastResponseError}`)}let r=await this.api.post("tx",this.transaction);if(this.lastRequestTimeEnd=Date.now(),this.lastResponseStatus=r.status,!(r.status>=200&&r.status<300))throw this.lastResponseError=(0,qu.getError)(r),new Error(`Unable to upload transaction: ${r.status}, ${this.lastResponseError}`);this.txPosted=!0}};Uf.TransactionUploader=Gu});var Hf=V((lB,ap)=>{var dB=A(M());ap.exports={}});var op=V(Zu=>{"use strict";var pB=A(M());Object.defineProperty(Zu,"__esModule",{value:!0});var Xu=hs(),ci=xs(),ms=bn(),zu=ip();Hf();var Ku=class{api;crypto;chunks;constructor(e,r,n){this.api=e,this.crypto=r,this.chunks=n}async getTransactionAnchor(){let e=await this.api.get("tx_anchor");if(!e.data.match(/^[a-z0-9_-]{43,}/i)||!e.ok)throw new Error(`Could not getTransactionAnchor. Received: ${e.data}. Status: ${e.status}, ${e.statusText}`);return e.data}async getPrice(e,r){let n=r?`price/${e}/${r}`:`price/${e}`,i=await this.api.get(n);if(!/^\d+$/.test(i.data)||!i.ok)throw new Error(`Could not getPrice. Received: ${i.data}. Status: ${i.status}, ${i.statusText}`);return i.data}async get(e){let r=await this.api.get(`tx/${e}`);if(r.status==200){let n=parseInt(r.data.data_size);if(r.data.format>=2&&n>0&&n<=1024*1024*12){let i=await this.getData(e);return new ci.default({...r.data,data:i})}return new ci.default({...r.data,format:r.data.format||1})}throw r.status==404?new Xu.default("TX_NOT_FOUND"):r.status==410?new Xu.default("TX_FAILED"):new Xu.default("TX_INVALID")}fromRaw(e){return new ci.default(e)}async search(e,r){return this.api.post("arql",{op:"equals",expr1:e,expr2:r}).then(n=>n.data?n.data:[])}getStatus(e){return this.api.get(`tx/${e}/status`).then(r=>r.status==200?{status:200,confirmed:r.data}:{status:r.status,confirmed:null})}async getData(e,r){let n;try{n=await this.chunks.downloadChunkedData(e)}catch(i){console.error(`Error while trying to download chunked data for ${e}`),console.error(i)}if(!n){console.warn(`Falling back to gateway cache for ${e}`);try{let{data:i,ok:a,status:d,statusText:v}=await this.api.get(`/${e}`,{responseType:"arraybuffer"});if(!a)throw new Error("Bad http status code",{cause:{status:d,statusText:v}});n=i}catch(i){console.error(`Error while trying to download contiguous data from gateway cache for ${e}`),console.error(i)}}if(!n)throw new Error(`${e} data was not found!`);return r&&r.decode&&!r.string?n:r&&r.decode&&r.string?ms.bufferToString(n):ms.bufferTob64Url(n)}async sign(e,r,n){let a=typeof r=="object"&&(v=>{let y=!0;return["n","e","d","p","q","dp","dq","qi"].map(m=>!(m in v)&&(y=!1)),y})(r),d=typeof arweaveWallet=="object";if(!a&&!d)throw new Error("No valid JWK or external wallet found to sign transaction.");if(a){e.setOwner(r.n);let v=await e.getSignatureData(),y=await this.crypto.sign(r,v,n),m=await this.crypto.hash(y);e.setSignature({id:ms.bufferTob64Url(m),owner:r.n,signature:ms.bufferTob64Url(y)})}else if(d){try{(await arweaveWallet.getPermissions()).includes("SIGN_TRANSACTION")||await arweaveWallet.connect(["SIGN_TRANSACTION"])}catch{}let v=await arweaveWallet.sign(e,n);e.setSignature({id:v.id,owner:v.owner,reward:v.reward,tags:v.tags,signature:v.signature})}else throw new Error("An error occurred while signing. Check wallet is valid")}async verify(e){let r=await e.getSignatureData(),n=e.get("signature",{decode:!0,string:!1}),i=ms.bufferTob64Url(await this.crypto.hash(n));if(e.id!==i)throw new Error("Invalid transaction signature or ID! The transaction ID doesn't match the expected SHA-256 hash of the signature.");return this.crypto.verify(e.owner,r,n)}async post(e){if(typeof e=="string"?e=new ci.default(JSON.parse(e)):typeof e.readInt32BE=="function"?e=new ci.default(JSON.parse(e.toString())):typeof e=="object"&&!(e instanceof ci.default)&&(e=new ci.default(e)),!(e instanceof ci.default))throw new Error("Must be Transaction object");e.chunks||await e.prepareChunks(e.data);let r=await this.getUploader(e,e.data);try{for(;!r.isComplete;)await r.uploadChunk()}catch(n){if(r.lastResponseStatus>0)return{status:r.lastResponseStatus,statusText:r.lastResponseError,data:{error:r.lastResponseError}};throw n}return{status:200,statusText:"OK",data:{}}}async getUploader(e,r){let n;if(r instanceof ArrayBuffer&&(r=new Uint8Array(r)),e instanceof ci.default){if(r||(r=e.data),!(r instanceof Uint8Array))throw new Error("Data format is invalid");e.chunks||await e.prepareChunks(r),n=new zu.TransactionUploader(this.api,e),(!n.data||n.data.length===0)&&(n.data=r)}else{if(typeof e=="string"&&(e=await zu.TransactionUploader.fromTransactionId(this.api,e)),!r||!(r instanceof Uint8Array))throw new Error("Must provide data when resuming upload");n=await zu.TransactionUploader.fromSerialized(this.api,e,r)}return n}async*upload(e,r){let n=await this.getUploader(e,r);for(;!n.isComplete;)await n.uploadChunk(),yield n;return n}};Zu.default=Ku});var fp=V(ju=>{"use strict";var gB=A(M());Object.defineProperty(ju,"__esModule",{value:!0});var sp=bn();Hf();var Vu=class{api;crypto;constructor(e,r){this.api=e,this.crypto=r}getBalance(e){return this.api.get(`wallet/${e}/balance`).then(r=>r.data)}getLastTransactionID(e){return this.api.get(`wallet/${e}/last_tx`).then(r=>r.data)}generate(){return this.crypto.generateJWK()}async jwkToAddress(e){return!e||e==="use_wallet"?this.getAddress():this.getAddress(e)}async getAddress(e){if(!e||e==="use_wallet"){try{await arweaveWallet.connect(["ACCESS_ADDRESS"])}catch{}return arweaveWallet.getActiveAddress()}else return this.ownerToAddress(e.n)}async ownerToAddress(e){return sp.bufferTob64Url(await this.crypto.hash(sp.b64UrlToBuffer(e)))}};ju.default=Vu});var up=V(ys=>{"use strict";var xB=A(M());Object.defineProperty(ys,"__esModule",{value:!0});ys.SiloResource=void 0;var cp=bn(),Qu=class{api;crypto;transactions;constructor(e,r,n){this.api=e,this.crypto=r,this.transactions=n}async get(e){if(!e)throw new Error("No Silo URI specified");let r=await this.parseUri(e),n=await this.transactions.search("Silo-Name",r.getAccessKey());if(n.length==0)throw new Error(`No data could be found for the Silo URI: ${e}`);let i=await this.transactions.get(n[0]);if(!i)throw new Error(`No data could be found for the Silo URI: ${e}`);let a=i.get("data",{decode:!0,string:!1});return this.crypto.decrypt(a,r.getEncryptionKey())}async readTransactionData(e,r){if(!r)throw new Error("No Silo URI specified");let n=await this.parseUri(r),i=e.get("data",{decode:!0,string:!1});return this.crypto.decrypt(i,n.getEncryptionKey())}async parseUri(e){let r=e.match(/^([a-z0-9-_]+)\.([0-9]+)/i);if(!r)throw new Error("Invalid Silo name, must be a name in the format of [a-z0-9]+.[0-9]+, e.g. 'bubble.7'");let n=r[1],i=Math.pow(2,parseInt(r[2])),a=await this.hash(cp.stringToBuffer(n),i),d=cp.bufferTob64(a.slice(0,15)),v=await this.hash(a.slice(16,31),1);return new qf(e,d,v)}async hash(e,r){let n=await this.crypto.hash(e);for(let i=0;i<r-1;i++)n=await this.crypto.hash(n);return n}};ys.default=Qu;var qf=class{uri;accessKey;encryptionKey;constructor(e,r,n){this.uri=e,this.accessKey=r,this.encryptionKey=n}getUri(){return this.uri}getAccessKey(){return this.accessKey}getEncryptionKey(){return this.encryptionKey}};ys.SiloResource=qf});var dp=V(Yu=>{"use strict";var yB=A(M());Object.defineProperty(Yu,"__esModule",{value:!0});var lp=hs(),Y8=bn(),Wu=class{api;constructor(e){this.api=e}async getTransactionOffset(e){let r=await this.api.get(`tx/${e}/offset`);if(r.status===200)return r.data;throw new Error(`Unable to get transaction offset: ${(0,lp.getError)(r)}`)}async getChunk(e){let r=await this.api.get(`chunk/${e}`);if(r.status===200)return r.data;throw new Error(`Unable to get chunk: ${(0,lp.getError)(r)}`)}async getChunkData(e){let r=await this.getChunk(e);return Y8.b64UrlToBuffer(r.chunk)}firstChunkOffset(e){return parseInt(e.offset)-parseInt(e.size)+1}async downloadChunkedData(e){let r=await this.getTransactionOffset(e),n=parseInt(r.size),a=parseInt(r.offset)-n+1,d=new Uint8Array(n),v=0;for(;v<n;){this.api.config.logging&&console.log(`[chunk] ${v}/${n}`);let y;try{y=await this.getChunkData(a+v)}catch{console.error(`[chunk] Failed to fetch chunk at offset ${a+v}`),console.error("[chunk] This could indicate that the chunk wasn't uploaded or hasn't yet seeded properly to a particular gateway/node")}if(y)d.set(y,v),v+=y.length;else throw new Error(`Couldn't complete data download at ${v}/${n}`)}return d}};Yu.default=Wu});var pp=V(el=>{"use strict";var AB=A(M());Object.defineProperty(el,"__esModule",{value:!0});var hp=hs();Hf();var $u=class t{api;network;static HASH_ENDPOINT="block/hash/";static HEIGHT_ENDPOINT="block/height/";constructor(e,r){this.api=e,this.network=r}async get(e){let r=await this.api.get(`${t.HASH_ENDPOINT}${e}`);if(r.status===200)return r.data;throw r.status===404?new hp.default("BLOCK_NOT_FOUND"):new Error(`Error while loading block data: ${r}`)}async getByHeight(e){let r=await this.api.get(`${t.HEIGHT_ENDPOINT}${e}`);if(r.status===200)return r.data;throw r.status===404?new hp.default("BLOCK_NOT_FOUND"):new Error(`Error while loading block data: ${r}`)}async getCurrent(){let{current:e}=await this.network.getInfo();return await this.get(e)}};el.default=$u});var vs=V(rl=>{"use strict";var MB=A(M());Object.defineProperty(rl,"__esModule",{value:!0});var $8=V1(),e6=j1(),t6=Bu(),r6=Q1(),n6=op(),i6=fp(),bp=xs(),ws=bn(),a6=up(),o6=dp(),s6=pp(),tl=class t{api;wallets;transactions;network;blocks;ar;silo;chunks;static init;static crypto=new t6.default;static utils=ws;constructor(e){this.api=new e6.default(e),this.wallets=new i6.default(this.api,t.crypto),this.chunks=new o6.default(this.api),this.transactions=new n6.default(this.api,t.crypto,this.chunks),this.silo=new a6.default(this.api,this.crypto,this.transactions),this.network=new r6.default(this.api),this.blocks=new s6.default(this.api,this.network),this.ar=new $8.default}get crypto(){return t.crypto}get utils(){return t.utils}getConfig(){return{api:this.api.getConfig(),crypto:null}}async createTransaction(e,r){let n={};if(Object.assign(n,e),!e.data&&!(e.target&&e.quantity))throw new Error("A new Arweave transaction must have a 'data' value, or 'target' and 'quantity' values.");if(e.owner==null&&r&&r!=="use_wallet"&&(n.owner=r.n),e.last_tx==null&&(n.last_tx=await this.transactions.getTransactionAnchor()),typeof e.data=="string"&&(e.data=ws.stringToBuffer(e.data)),e.data instanceof ArrayBuffer&&(e.data=new Uint8Array(e.data)),e.data&&!(e.data instanceof Uint8Array))throw new Error("Expected data to be a string, Uint8Array or ArrayBuffer");if(e.reward==null){let a=e.data?e.data.byteLength:0;n.reward=await this.transactions.getPrice(a,n.target)}n.data_root="",n.data_size=e.data?e.data.byteLength.toString():"0",n.data=e.data||new Uint8Array(0);let i=new bp.default(n);return await i.getSignatureData(),i}async createSiloTransaction(e,r,n){let i={};if(Object.assign(i,e),!e.data)throw new Error("Silo transactions must have a 'data' value");if(!n)throw new Error("No Silo URI specified.");if(e.target||e.quantity)throw new Error("Silo transactions can only be used for storing data, sending AR to other wallets isn't supported.");if(e.owner==null){if(!r||!r.n)throw new Error("A new Arweave transaction must either have an 'owner' attribute, or you must provide the jwk parameter.");i.owner=r.n}e.last_tx==null&&(i.last_tx=await this.transactions.getTransactionAnchor());let a=await this.silo.parseUri(n);if(typeof e.data=="string"){let v=await this.crypto.encrypt(ws.stringToBuffer(e.data),a.getEncryptionKey());i.reward=await this.transactions.getPrice(v.byteLength),i.data=ws.bufferTob64Url(v)}if(e.data instanceof Uint8Array){let v=await this.crypto.encrypt(e.data,a.getEncryptionKey());i.reward=await this.transactions.getPrice(v.byteLength),i.data=ws.bufferTob64Url(v)}let d=new bp.default(i);return d.addTag("Silo-Name",a.getAccessKey()),d.addTag("Silo-Version","0.1.0"),d}arql(e){return this.api.post("/arql",e).then(r=>r.data||[])}};rl.default=tl});var xp=V(nl=>{"use strict";var EB=A(M());Object.defineProperty(nl,"__esModule",{value:!0});nl.default=gp;var Pr=vs();async function gp(t){if(Array.isArray(t)){let n=Pr.default.utils.concatBuffers([Pr.default.utils.stringToBuffer("list"),Pr.default.utils.stringToBuffer(t.length.toString())]);return await vp(t,await Pr.default.crypto.hash(n,"SHA-384"))}let e=Pr.default.utils.concatBuffers([Pr.default.utils.stringToBuffer("blob"),Pr.default.utils.stringToBuffer(t.byteLength.toString())]),r=Pr.default.utils.concatBuffers([await Pr.default.crypto.hash(e,"SHA-384"),await Pr.default.crypto.hash(t,"SHA-384")]);return await Pr.default.crypto.hash(r,"SHA-384")}async function vp(t,e){if(t.length<1)return e;let r=Pr.default.utils.concatBuffers([e,await gp(t[0])]),n=await Pr.default.crypto.hash(r,"SHA-384");return await vp(t.slice(1),n)}});var xs=V(Ss=>{"use strict";var BB=A(M());Object.defineProperty(Ss,"__esModule",{value:!0});Ss.Tag=void 0;var Ot=bn(),f6=xp(),c6=Hu(),Gf=class{get(e,r){if(!Object.getOwnPropertyNames(this).includes(e))throw new Error(`Field "${e}" is not a property of the Arweave Transaction class.`);if(this[e]instanceof Uint8Array)return r&&r.decode&&r.string?Ot.bufferToString(this[e]):r&&r.decode&&!r.string?this[e]:Ot.bufferTob64Url(this[e]);if(this[e]instanceof Array){if(r?.decode!==void 0||r?.string!==void 0)throw e==="tags"&&console.warn(`Did you mean to use 'transaction["tags"]' ?`),new Error("Cannot decode or stringify an array.");return this[e]}return r&&r.decode==!0?r&&r.string?Ot.b64UrlToString(this[e]):Ot.b64UrlToBuffer(this[e]):this[e]}},As=class extends Gf{name;value;constructor(e,r,n=!1){super(),this.name=e,this.value=r}};Ss.Tag=As;var il=class extends Gf{format=2;id="";last_tx="";owner="";tags=[];target="";quantity="0";data_size="0";data=new Uint8Array;data_root="";reward="0";signature="";chunks;constructor(e={}){super(),Object.assign(this,e),typeof this.data=="string"&&(this.data=Ot.b64UrlToBuffer(this.data)),e.tags&&(this.tags=e.tags.map(r=>new As(r.name,r.value)))}addTag(e,r){this.tags.push(new As(Ot.stringToB64Url(e),Ot.stringToB64Url(r)))}toJSON(){return{format:this.format,id:this.id,last_tx:this.last_tx,owner:this.owner,tags:this.tags,target:this.target,quantity:this.quantity,data:Ot.bufferTob64Url(this.data),data_size:this.data_size,data_root:this.data_root,data_tree:this.data_tree,reward:this.reward,signature:this.signature}}setOwner(e){this.owner=e}setSignature({id:e,owner:r,reward:n,tags:i,signature:a}){this.id=e,this.owner=r,n&&(this.reward=n),i&&(this.tags=i),this.signature=a}async prepareChunks(e){!this.chunks&&e.byteLength>0&&(this.chunks=await(0,c6.generateTransactionChunks)(e),this.data_root=Ot.bufferTob64Url(this.chunks.data_root)),!this.chunks&&e.byteLength===0&&(this.chunks={chunks:[],data_root:new Uint8Array,proofs:[]},this.data_root="")}getChunk(e,r){if(!this.chunks)throw new Error("Chunks have not been prepared");let n=this.chunks.proofs[e],i=this.chunks.chunks[e];return{data_root:this.data_root,data_size:this.data_size,data_path:Ot.bufferTob64Url(n.proof),offset:n.offset.toString(),chunk:Ot.bufferTob64Url(r.slice(i.minByteRange,i.maxByteRange))}}async getSignatureData(){switch(this.format){case 1:let e=this.tags.reduce((n,i)=>Ot.concatBuffers([n,i.get("name",{decode:!0,string:!1}),i.get("value",{decode:!0,string:!1})]),new Uint8Array);return Ot.concatBuffers([this.get("owner",{decode:!0,string:!1}),this.get("target",{decode:!0,string:!1}),this.get("data",{decode:!0,string:!1}),Ot.stringToBuffer(this.quantity),Ot.stringToBuffer(this.reward),this.get("last_tx",{decode:!0,string:!1}),e]);case 2:this.data_root||await this.prepareChunks(this.data);let r=this.tags.map(n=>[n.get("name",{decode:!0,string:!1}),n.get("value",{decode:!0,string:!1})]);return await(0,f6.default)([Ot.stringToBuffer(this.format.toString()),this.get("owner",{decode:!0,string:!1}),this.get("target",{decode:!0,string:!1}),Ot.stringToBuffer(this.quantity),Ot.stringToBuffer(this.reward),this.get("last_tx",{decode:!0,string:!1}),r,Ot.stringToBuffer(this.data_size),this.get("data_root",{decode:!0,string:!1})]);default:throw new Error(`Unexpected transaction format: ${this.format}`)}}};Ss.default=il});var mp=V(Xf=>{"use strict";var PB=A(M());Object.defineProperty(Xf,"__esModule",{value:!0});Xf.getDefaultConfig=void 0;var u6=(t,e)=>{let r=/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/,n=e.split("."),i=n[n.length-1],a=["localhost","[::1]"];return a.includes(e)||t=="file"||a.includes(i)||!!e.match(r)||!!i.match(r)},l6=t=>{let e=t.charAt(0)==="[",r=/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/;return!!t.match(r)||e},d6=(t,e)=>{if(u6(t,e))return{protocol:"https",host:"arweave.net",port:443};if(!l6(e)){let r=e.split(".");if(r.length>=3){r.shift();let n=r.join(".");return{protocol:t,host:n}}}return{protocol:t,host:e}};Xf.getDefaultConfig=d6});var yp=V(Ri=>{"use strict";var RB=A(M()),h6=Ri&&Ri.__createBinding||(Object.create?function(t,e,r,n){n===void 0&&(n=r);var i=Object.getOwnPropertyDescriptor(e,r);(!i||("get"in i?!e.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,i)}:function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]}),p6=Ri&&Ri.__exportStar||function(t,e){for(var r in t)r!=="default"&&!Object.prototype.hasOwnProperty.call(e,r)&&h6(e,t,r)};Object.defineProperty(Ri,"__esModule",{value:!0});var io=vs(),b6=mp();io.default.init=function(t={}){let e={host:"arweave.net",port:443,protocol:"https"};if(typeof location!="object"||!location.protocol||!location.hostname)return new io.default({...t,...e});let r=location.protocol.replace(":",""),n=location.hostname,i=location.port?parseInt(location.port):r=="https"?443:80,a=(0,b6.getDefaultConfig)(r,n),d=t.protocol||a.protocol,v=t.host||a.host,y=t.port||a.port||i;return new io.default({...t,host:v,protocol:d,port:y})};typeof globalThis=="object"?globalThis.Arweave=io.default:typeof self=="object"&&(self.Arweave=io.default);p6(vs(),Ri);Ri.default=io.default});var ol=V((Mp,al)=>{var HB=A(M());(function(t,e){"use strict";function r(S,s){if(!S)throw new Error(s||"Assertion failed")}function n(S,s){S.super_=s;var u=function(){};u.prototype=s.prototype,S.prototype=new u,S.prototype.constructor=S}function i(S,s,u){if(i.isBN(S))return S;this.negative=0,this.words=null,this.length=0,this.red=null,S!==null&&((s==="le"||s==="be")&&(u=s,s=10),this._init(S||0,s||10,u||"be"))}typeof t=="object"?t.exports=i:e.BN=i,i.BN=i,i.wordSize=26;var a;try{typeof window<"u"&&typeof window.Buffer<"u"?a=window.Buffer:a=rt("buffer").Buffer}catch{}i.isBN=function(s){return s instanceof i?!0:s!==null&&typeof s=="object"&&s.constructor.wordSize===i.wordSize&&Array.isArray(s.words)},i.max=function(s,u){return s.cmp(u)>0?s:u},i.min=function(s,u){return s.cmp(u)<0?s:u},i.prototype._init=function(s,u,l){if(typeof s=="number")return this._initNumber(s,u,l);if(typeof s=="object")return this._initArray(s,u,l);u==="hex"&&(u=16),r(u===(u|0)&&u>=2&&u<=36),s=s.toString().replace(/\s+/g,"");var f=0;s[0]==="-"&&(f++,this.negative=1),f<s.length&&(u===16?this._parseHex(s,f,l):(this._parseBase(s,u,f),l==="le"&&this._initArray(this.toArray(),u,l)))},i.prototype._initNumber=function(s,u,l){s<0&&(this.negative=1,s=-s),s<67108864?(this.words=[s&67108863],this.length=1):s<4503599627370496?(this.words=[s&67108863,s/67108864&67108863],this.length=2):(r(s<9007199254740992),this.words=[s&67108863,s/67108864&67108863,1],this.length=3),l==="le"&&this._initArray(this.toArray(),u,l)},i.prototype._initArray=function(s,u,l){if(r(typeof s.length=="number"),s.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(s.length/3),this.words=new Array(this.length);for(var f=0;f<this.length;f++)this.words[f]=0;var c,g,x=0;if(l==="be")for(f=s.length-1,c=0;f>=0;f-=3)g=s[f]|s[f-1]<<8|s[f-2]<<16,this.words[c]|=g<<x&67108863,this.words[c+1]=g>>>26-x&67108863,x+=24,x>=26&&(x-=26,c++);else if(l==="le")for(f=0,c=0;f<s.length;f+=3)g=s[f]|s[f+1]<<8|s[f+2]<<16,this.words[c]|=g<<x&67108863,this.words[c+1]=g>>>26-x&67108863,x+=24,x>=26&&(x-=26,c++);return this.strip()};function d(S,s){var u=S.charCodeAt(s);return u>=65&&u<=70?u-55:u>=97&&u<=102?u-87:u-48&15}function v(S,s,u){var l=d(S,u);return u-1>=s&&(l|=d(S,u-1)<<4),l}i.prototype._parseHex=function(s,u,l){this.length=Math.ceil((s.length-u)/6),this.words=new Array(this.length);for(var f=0;f<this.length;f++)this.words[f]=0;var c=0,g=0,x;if(l==="be")for(f=s.length-1;f>=u;f-=2)x=v(s,u,f)<<c,this.words[g]|=x&67108863,c>=18?(c-=18,g+=1,this.words[g]|=x>>>26):c+=8;else{var h=s.length-u;for(f=h%2===0?u+1:u;f<s.length;f+=2)x=v(s,u,f)<<c,this.words[g]|=x&67108863,c>=18?(c-=18,g+=1,this.words[g]|=x>>>26):c+=8}this.strip()};function y(S,s,u,l){for(var f=0,c=Math.min(S.length,u),g=s;g<c;g++){var x=S.charCodeAt(g)-48;f*=l,x>=49?f+=x-49+10:x>=17?f+=x-17+10:f+=x}return f}i.prototype._parseBase=function(s,u,l){this.words=[0],this.length=1;for(var f=0,c=1;c<=67108863;c*=u)f++;f--,c=c/u|0;for(var g=s.length-l,x=g%f,h=Math.min(g,g-x)+l,o=0,p=l;p<h;p+=f)o=y(s,p,p+f,u),this.imuln(c),this.words[0]+o<67108864?this.words[0]+=o:this._iaddn(o);if(x!==0){var E=1;for(o=y(s,p,s.length,u),p=0;p<x;p++)E*=u;this.imuln(E),this.words[0]+o<67108864?this.words[0]+=o:this._iaddn(o)}this.strip()},i.prototype.copy=function(s){s.words=new Array(this.length);for(var u=0;u<this.length;u++)s.words[u]=this.words[u];s.length=this.length,s.negative=this.negative,s.red=this.red},i.prototype.clone=function(){var s=new i(null);return this.copy(s),s},i.prototype._expand=function(s){for(;this.length<s;)this.words[this.length++]=0;return this},i.prototype.strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},i.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},i.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var m=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],B=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],P=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];i.prototype.toString=function(s,u){s=s||10,u=u|0||1;var l;if(s===16||s==="hex"){l="";for(var f=0,c=0,g=0;g<this.length;g++){var x=this.words[g],h=((x<<f|c)&16777215).toString(16);c=x>>>24-f&16777215,f+=2,f>=26&&(f-=26,g--),c!==0||g!==this.length-1?l=m[6-h.length]+h+l:l=h+l}for(c!==0&&(l=c.toString(16)+l);l.length%u!==0;)l="0"+l;return this.negative!==0&&(l="-"+l),l}if(s===(s|0)&&s>=2&&s<=36){var o=B[s],p=P[s];l="";var E=this.clone();for(E.negative=0;!E.isZero();){var b=E.modn(p).toString(s);E=E.idivn(p),E.isZero()?l=b+l:l=m[o-b.length]+b+l}for(this.isZero()&&(l="0"+l);l.length%u!==0;)l="0"+l;return this.negative!==0&&(l="-"+l),l}r(!1,"Base should be between 2 and 36")},i.prototype.toNumber=function(){var s=this.words[0];return this.length===2?s+=this.words[1]*67108864:this.length===3&&this.words[2]===1?s+=4503599627370496+this.words[1]*67108864:this.length>2&&r(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-s:s},i.prototype.toJSON=function(){return this.toString(16)},i.prototype.toBuffer=function(s,u){return r(typeof a<"u"),this.toArrayLike(a,s,u)},i.prototype.toArray=function(s,u){return this.toArrayLike(Array,s,u)},i.prototype.toArrayLike=function(s,u,l){var f=this.byteLength(),c=l||Math.max(1,f);r(f<=c,"byte array longer than desired length"),r(c>0,"Requested array length <= 0"),this.strip();var g=u==="le",x=new s(c),h,o,p=this.clone();if(g){for(o=0;!p.isZero();o++)h=p.andln(255),p.iushrn(8),x[o]=h;for(;o<c;o++)x[o]=0}else{for(o=0;o<c-f;o++)x[o]=0;for(o=0;!p.isZero();o++)h=p.andln(255),p.iushrn(8),x[c-o-1]=h}return x},Math.clz32?i.prototype._countBits=function(s){return 32-Math.clz32(s)}:i.prototype._countBits=function(s){var u=s,l=0;return u>=4096&&(l+=13,u>>>=13),u>=64&&(l+=7,u>>>=7),u>=8&&(l+=4,u>>>=4),u>=2&&(l+=2,u>>>=2),l+u},i.prototype._zeroBits=function(s){if(s===0)return 26;var u=s,l=0;return u&8191||(l+=13,u>>>=13),u&127||(l+=7,u>>>=7),u&15||(l+=4,u>>>=4),u&3||(l+=2,u>>>=2),u&1||l++,l},i.prototype.bitLength=function(){var s=this.words[this.length-1],u=this._countBits(s);return(this.length-1)*26+u};function D(S){for(var s=new Array(S.bitLength()),u=0;u<s.length;u++){var l=u/26|0,f=u%26;s[u]=(S.words[l]&1<<f)>>>f}return s}i.prototype.zeroBits=function(){if(this.isZero())return 0;for(var s=0,u=0;u<this.length;u++){var l=this._zeroBits(this.words[u]);if(s+=l,l!==26)break}return s},i.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},i.prototype.toTwos=function(s){return this.negative!==0?this.abs().inotn(s).iaddn(1):this.clone()},i.prototype.fromTwos=function(s){return this.testn(s-1)?this.notn(s).iaddn(1).ineg():this.clone()},i.prototype.isNeg=function(){return this.negative!==0},i.prototype.neg=function(){return this.clone().ineg()},i.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},i.prototype.iuor=function(s){for(;this.length<s.length;)this.words[this.length++]=0;for(var u=0;u<s.length;u++)this.words[u]=this.words[u]|s.words[u];return this.strip()},i.prototype.ior=function(s){return r((this.negative|s.negative)===0),this.iuor(s)},i.prototype.or=function(s){return this.length>s.length?this.clone().ior(s):s.clone().ior(this)},i.prototype.uor=function(s){return this.length>s.length?this.clone().iuor(s):s.clone().iuor(this)},i.prototype.iuand=function(s){var u;this.length>s.length?u=s:u=this;for(var l=0;l<u.length;l++)this.words[l]=this.words[l]&s.words[l];return this.length=u.length,this.strip()},i.prototype.iand=function(s){return r((this.negative|s.negative)===0),this.iuand(s)},i.prototype.and=function(s){return this.length>s.length?this.clone().iand(s):s.clone().iand(this)},i.prototype.uand=function(s){return this.length>s.length?this.clone().iuand(s):s.clone().iuand(this)},i.prototype.iuxor=function(s){var u,l;this.length>s.length?(u=this,l=s):(u=s,l=this);for(var f=0;f<l.length;f++)this.words[f]=u.words[f]^l.words[f];if(this!==u)for(;f<u.length;f++)this.words[f]=u.words[f];return this.length=u.length,this.strip()},i.prototype.ixor=function(s){return r((this.negative|s.negative)===0),this.iuxor(s)},i.prototype.xor=function(s){return this.length>s.length?this.clone().ixor(s):s.clone().ixor(this)},i.prototype.uxor=function(s){return this.length>s.length?this.clone().iuxor(s):s.clone().iuxor(this)},i.prototype.inotn=function(s){r(typeof s=="number"&&s>=0);var u=Math.ceil(s/26)|0,l=s%26;this._expand(u),l>0&&u--;for(var f=0;f<u;f++)this.words[f]=~this.words[f]&67108863;return l>0&&(this.words[f]=~this.words[f]&67108863>>26-l),this.strip()},i.prototype.notn=function(s){return this.clone().inotn(s)},i.prototype.setn=function(s,u){r(typeof s=="number"&&s>=0);var l=s/26|0,f=s%26;return this._expand(l+1),u?this.words[l]=this.words[l]|1<<f:this.words[l]=this.words[l]&~(1<<f),this.strip()},i.prototype.iadd=function(s){var u;if(this.negative!==0&&s.negative===0)return this.negative=0,u=this.isub(s),this.negative^=1,this._normSign();if(this.negative===0&&s.negative!==0)return s.negative=0,u=this.isub(s),s.negative=1,u._normSign();var l,f;this.length>s.length?(l=this,f=s):(l=s,f=this);for(var c=0,g=0;g<f.length;g++)u=(l.words[g]|0)+(f.words[g]|0)+c,this.words[g]=u&67108863,c=u>>>26;for(;c!==0&&g<l.length;g++)u=(l.words[g]|0)+c,this.words[g]=u&67108863,c=u>>>26;if(this.length=l.length,c!==0)this.words[this.length]=c,this.length++;else if(l!==this)for(;g<l.length;g++)this.words[g]=l.words[g];return this},i.prototype.add=function(s){var u;return s.negative!==0&&this.negative===0?(s.negative=0,u=this.sub(s),s.negative^=1,u):s.negative===0&&this.negative!==0?(this.negative=0,u=s.sub(this),this.negative=1,u):this.length>s.length?this.clone().iadd(s):s.clone().iadd(this)},i.prototype.isub=function(s){if(s.negative!==0){s.negative=0;var u=this.iadd(s);return s.negative=1,u._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(s),this.negative=1,this._normSign();var l=this.cmp(s);if(l===0)return this.negative=0,this.length=1,this.words[0]=0,this;var f,c;l>0?(f=this,c=s):(f=s,c=this);for(var g=0,x=0;x<c.length;x++)u=(f.words[x]|0)-(c.words[x]|0)+g,g=u>>26,this.words[x]=u&67108863;for(;g!==0&&x<f.length;x++)u=(f.words[x]|0)+g,g=u>>26,this.words[x]=u&67108863;if(g===0&&x<f.length&&f!==this)for(;x<f.length;x++)this.words[x]=f.words[x];return this.length=Math.max(this.length,x),f!==this&&(this.negative=1),this.strip()},i.prototype.sub=function(s){return this.clone().isub(s)};function F(S,s,u){u.negative=s.negative^S.negative;var l=S.length+s.length|0;u.length=l,l=l-1|0;var f=S.words[0]|0,c=s.words[0]|0,g=f*c,x=g&67108863,h=g/67108864|0;u.words[0]=x;for(var o=1;o<l;o++){for(var p=h>>>26,E=h&67108863,b=Math.min(o,s.length-1),w=Math.max(0,o-S.length+1);w<=b;w++){var H=o-w|0;f=S.words[H]|0,c=s.words[w]|0,g=f*c+E,p+=g/67108864|0,E=g&67108863}u.words[o]=E|0,h=p|0}return h!==0?u.words[o]=h|0:u.length--,u.strip()}var C=function(s,u,l){var f=s.words,c=u.words,g=l.words,x=0,h,o,p,E=f[0]|0,b=E&8191,w=E>>>13,H=f[1]|0,T=H&8191,k=H>>>13,X=f[2]|0,Z=X&8191,_=X>>>13,R=f[3]|0,L=R&8191,O=R>>>13,G=f[4]|0,I=G&8191,J=G>>>13,z=f[5]|0,N=z&8191,U=z>>>13,Q=f[6]|0,j=Q&8191,re=Q>>>13,De=f[7]|0,se=De&8191,le=De>>>13,Ue=f[8]|0,oe=Ue&8191,fe=Ue>>>13,Xe=f[9]|0,ge=Xe&8191,ve=Xe>>>13,gt=c[0]|0,pe=gt&8191,be=gt>>>13,Ye=c[1]|0,de=Ye&8191,ue=Ye>>>13,zt=c[2]|0,xe=zt&8191,me=zt>>>13,Kt=c[3]|0,ye=Kt&8191,we=Kt>>>13,Zt=c[4]|0,Ae=Zt&8191,Se=Zt>>>13,Vt=c[5]|0,Me=Vt&8191,Te=Vt>>>13,jt=c[6]|0,Ee=jt&8191,_e=jt>>>13,Qt=c[7]|0,Be=Qt&8191,Ce=Qt>>>13,Wt=c[8]|0,Pe=Wt&8191,Le=Wt>>>13,Yt=c[9]|0,Re=Yt&8191,Fe=Yt>>>13;l.negative=s.negative^u.negative,l.length=19,h=Math.imul(b,pe),o=Math.imul(b,be),o=o+Math.imul(w,pe)|0,p=Math.imul(w,be);var Ft=(x+h|0)+((o&8191)<<13)|0;x=(p+(o>>>13)|0)+(Ft>>>26)|0,Ft&=67108863,h=Math.imul(T,pe),o=Math.imul(T,be),o=o+Math.imul(k,pe)|0,p=Math.imul(k,be),h=h+Math.imul(b,de)|0,o=o+Math.imul(b,ue)|0,o=o+Math.imul(w,de)|0,p=p+Math.imul(w,ue)|0;var ke=(x+h|0)+((o&8191)<<13)|0;x=(p+(o>>>13)|0)+(ke>>>26)|0,ke&=67108863,h=Math.imul(Z,pe),o=Math.imul(Z,be),o=o+Math.imul(_,pe)|0,p=Math.imul(_,be),h=h+Math.imul(T,de)|0,o=o+Math.imul(T,ue)|0,o=o+Math.imul(k,de)|0,p=p+Math.imul(k,ue)|0,h=h+Math.imul(b,xe)|0,o=o+Math.imul(b,me)|0,o=o+Math.imul(w,xe)|0,p=p+Math.imul(w,me)|0;var Ne=(x+h|0)+((o&8191)<<13)|0;x=(p+(o>>>13)|0)+(Ne>>>26)|0,Ne&=67108863,h=Math.imul(L,pe),o=Math.imul(L,be),o=o+Math.imul(O,pe)|0,p=Math.imul(O,be),h=h+Math.imul(Z,de)|0,o=o+Math.imul(Z,ue)|0,o=o+Math.imul(_,de)|0,p=p+Math.imul(_,ue)|0,h=h+Math.imul(T,xe)|0,o=o+Math.imul(T,me)|0,o=o+Math.imul(k,xe)|0,p=p+Math.imul(k,me)|0,h=h+Math.imul(b,ye)|0,o=o+Math.imul(b,we)|0,o=o+Math.imul(w,ye)|0,p=p+Math.imul(w,we)|0;var St=(x+h|0)+((o&8191)<<13)|0;x=(p+(o>>>13)|0)+(St>>>26)|0,St&=67108863,h=Math.imul(I,pe),o=Math.imul(I,be),o=o+Math.imul(J,pe)|0,p=Math.imul(J,be),h=h+Math.imul(L,de)|0,o=o+Math.imul(L,ue)|0,o=o+Math.imul(O,de)|0,p=p+Math.imul(O,ue)|0,h=h+Math.imul(Z,xe)|0,o=o+Math.imul(Z,me)|0,o=o+Math.imul(_,xe)|0,p=p+Math.imul(_,me)|0,h=h+Math.imul(T,ye)|0,o=o+Math.imul(T,we)|0,o=o+Math.imul(k,ye)|0,p=p+Math.imul(k,we)|0,h=h+Math.imul(b,Ae)|0,o=o+Math.imul(b,Se)|0,o=o+Math.imul(w,Ae)|0,p=p+Math.imul(w,Se)|0;var Mt=(x+h|0)+((o&8191)<<13)|0;x=(p+(o>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,h=Math.imul(N,pe),o=Math.imul(N,be),o=o+Math.imul(U,pe)|0,p=Math.imul(U,be),h=h+Math.imul(I,de)|0,o=o+Math.imul(I,ue)|0,o=o+Math.imul(J,de)|0,p=p+Math.imul(J,ue)|0,h=h+Math.imul(L,xe)|0,o=o+Math.imul(L,me)|0,o=o+Math.imul(O,xe)|0,p=p+Math.imul(O,me)|0,h=h+Math.imul(Z,ye)|0,o=o+Math.imul(Z,we)|0,o=o+Math.imul(_,ye)|0,p=p+Math.imul(_,we)|0,h=h+Math.imul(T,Ae)|0,o=o+Math.imul(T,Se)|0,o=o+Math.imul(k,Ae)|0,p=p+Math.imul(k,Se)|0,h=h+Math.imul(b,Me)|0,o=o+Math.imul(b,Te)|0,o=o+Math.imul(w,Me)|0,p=p+Math.imul(w,Te)|0;var Tt=(x+h|0)+((o&8191)<<13)|0;x=(p+(o>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,h=Math.imul(j,pe),o=Math.imul(j,be),o=o+Math.imul(re,pe)|0,p=Math.imul(re,be),h=h+Math.imul(N,de)|0,o=o+Math.imul(N,ue)|0,o=o+Math.imul(U,de)|0,p=p+Math.imul(U,ue)|0,h=h+Math.imul(I,xe)|0,o=o+Math.imul(I,me)|0,o=o+Math.imul(J,xe)|0,p=p+Math.imul(J,me)|0,h=h+Math.imul(L,ye)|0,o=o+Math.imul(L,we)|0,o=o+Math.imul(O,ye)|0,p=p+Math.imul(O,we)|0,h=h+Math.imul(Z,Ae)|0,o=o+Math.imul(Z,Se)|0,o=o+Math.imul(_,Ae)|0,p=p+Math.imul(_,Se)|0,h=h+Math.imul(T,Me)|0,o=o+Math.imul(T,Te)|0,o=o+Math.imul(k,Me)|0,p=p+Math.imul(k,Te)|0,h=h+Math.imul(b,Ee)|0,o=o+Math.imul(b,_e)|0,o=o+Math.imul(w,Ee)|0,p=p+Math.imul(w,_e)|0;var Et=(x+h|0)+((o&8191)<<13)|0;x=(p+(o>>>13)|0)+(Et>>>26)|0,Et&=67108863,h=Math.imul(se,pe),o=Math.imul(se,be),o=o+Math.imul(le,pe)|0,p=Math.imul(le,be),h=h+Math.imul(j,de)|0,o=o+Math.imul(j,ue)|0,o=o+Math.imul(re,de)|0,p=p+Math.imul(re,ue)|0,h=h+Math.imul(N,xe)|0,o=o+Math.imul(N,me)|0,o=o+Math.imul(U,xe)|0,p=p+Math.imul(U,me)|0,h=h+Math.imul(I,ye)|0,o=o+Math.imul(I,we)|0,o=o+Math.imul(J,ye)|0,p=p+Math.imul(J,we)|0,h=h+Math.imul(L,Ae)|0,o=o+Math.imul(L,Se)|0,o=o+Math.imul(O,Ae)|0,p=p+Math.imul(O,Se)|0,h=h+Math.imul(Z,Me)|0,o=o+Math.imul(Z,Te)|0,o=o+Math.imul(_,Me)|0,p=p+Math.imul(_,Te)|0,h=h+Math.imul(T,Ee)|0,o=o+Math.imul(T,_e)|0,o=o+Math.imul(k,Ee)|0,p=p+Math.imul(k,_e)|0,h=h+Math.imul(b,Be)|0,o=o+Math.imul(b,Ce)|0,o=o+Math.imul(w,Be)|0,p=p+Math.imul(w,Ce)|0;var _t=(x+h|0)+((o&8191)<<13)|0;x=(p+(o>>>13)|0)+(_t>>>26)|0,_t&=67108863,h=Math.imul(oe,pe),o=Math.imul(oe,be),o=o+Math.imul(fe,pe)|0,p=Math.imul(fe,be),h=h+Math.imul(se,de)|0,o=o+Math.imul(se,ue)|0,o=o+Math.imul(le,de)|0,p=p+Math.imul(le,ue)|0,h=h+Math.imul(j,xe)|0,o=o+Math.imul(j,me)|0,o=o+Math.imul(re,xe)|0,p=p+Math.imul(re,me)|0,h=h+Math.imul(N,ye)|0,o=o+Math.imul(N,we)|0,o=o+Math.imul(U,ye)|0,p=p+Math.imul(U,we)|0,h=h+Math.imul(I,Ae)|0,o=o+Math.imul(I,Se)|0,o=o+Math.imul(J,Ae)|0,p=p+Math.imul(J,Se)|0,h=h+Math.imul(L,Me)|0,o=o+Math.imul(L,Te)|0,o=o+Math.imul(O,Me)|0,p=p+Math.imul(O,Te)|0,h=h+Math.imul(Z,Ee)|0,o=o+Math.imul(Z,_e)|0,o=o+Math.imul(_,Ee)|0,p=p+Math.imul(_,_e)|0,h=h+Math.imul(T,Be)|0,o=o+Math.imul(T,Ce)|0,o=o+Math.imul(k,Be)|0,p=p+Math.imul(k,Ce)|0,h=h+Math.imul(b,Pe)|0,o=o+Math.imul(b,Le)|0,o=o+Math.imul(w,Pe)|0,p=p+Math.imul(w,Le)|0;var lr=(x+h|0)+((o&8191)<<13)|0;x=(p+(o>>>13)|0)+(lr>>>26)|0,lr&=67108863,h=Math.imul(ge,pe),o=Math.imul(ge,be),o=o+Math.imul(ve,pe)|0,p=Math.imul(ve,be),h=h+Math.imul(oe,de)|0,o=o+Math.imul(oe,ue)|0,o=o+Math.imul(fe,de)|0,p=p+Math.imul(fe,ue)|0,h=h+Math.imul(se,xe)|0,o=o+Math.imul(se,me)|0,o=o+Math.imul(le,xe)|0,p=p+Math.imul(le,me)|0,h=h+Math.imul(j,ye)|0,o=o+Math.imul(j,we)|0,o=o+Math.imul(re,ye)|0,p=p+Math.imul(re,we)|0,h=h+Math.imul(N,Ae)|0,o=o+Math.imul(N,Se)|0,o=o+Math.imul(U,Ae)|0,p=p+Math.imul(U,Se)|0,h=h+Math.imul(I,Me)|0,o=o+Math.imul(I,Te)|0,o=o+Math.imul(J,Me)|0,p=p+Math.imul(J,Te)|0,h=h+Math.imul(L,Ee)|0,o=o+Math.imul(L,_e)|0,o=o+Math.imul(O,Ee)|0,p=p+Math.imul(O,_e)|0,h=h+Math.imul(Z,Be)|0,o=o+Math.imul(Z,Ce)|0,o=o+Math.imul(_,Be)|0,p=p+Math.imul(_,Ce)|0,h=h+Math.imul(T,Pe)|0,o=o+Math.imul(T,Le)|0,o=o+Math.imul(k,Pe)|0,p=p+Math.imul(k,Le)|0,h=h+Math.imul(b,Re)|0,o=o+Math.imul(b,Fe)|0,o=o+Math.imul(w,Re)|0,p=p+Math.imul(w,Fe)|0;var dr=(x+h|0)+((o&8191)<<13)|0;x=(p+(o>>>13)|0)+(dr>>>26)|0,dr&=67108863,h=Math.imul(ge,de),o=Math.imul(ge,ue),o=o+Math.imul(ve,de)|0,p=Math.imul(ve,ue),h=h+Math.imul(oe,xe)|0,o=o+Math.imul(oe,me)|0,o=o+Math.imul(fe,xe)|0,p=p+Math.imul(fe,me)|0,h=h+Math.imul(se,ye)|0,o=o+Math.imul(se,we)|0,o=o+Math.imul(le,ye)|0,p=p+Math.imul(le,we)|0,h=h+Math.imul(j,Ae)|0,o=o+Math.imul(j,Se)|0,o=o+Math.imul(re,Ae)|0,p=p+Math.imul(re,Se)|0,h=h+Math.imul(N,Me)|0,o=o+Math.imul(N,Te)|0,o=o+Math.imul(U,Me)|0,p=p+Math.imul(U,Te)|0,h=h+Math.imul(I,Ee)|0,o=o+Math.imul(I,_e)|0,o=o+Math.imul(J,Ee)|0,p=p+Math.imul(J,_e)|0,h=h+Math.imul(L,Be)|0,o=o+Math.imul(L,Ce)|0,o=o+Math.imul(O,Be)|0,p=p+Math.imul(O,Ce)|0,h=h+Math.imul(Z,Pe)|0,o=o+Math.imul(Z,Le)|0,o=o+Math.imul(_,Pe)|0,p=p+Math.imul(_,Le)|0,h=h+Math.imul(T,Re)|0,o=o+Math.imul(T,Fe)|0,o=o+Math.imul(k,Re)|0,p=p+Math.imul(k,Fe)|0;var hr=(x+h|0)+((o&8191)<<13)|0;x=(p+(o>>>13)|0)+(hr>>>26)|0,hr&=67108863,h=Math.imul(ge,xe),o=Math.imul(ge,me),o=o+Math.imul(ve,xe)|0,p=Math.imul(ve,me),h=h+Math.imul(oe,ye)|0,o=o+Math.imul(oe,we)|0,o=o+Math.imul(fe,ye)|0,p=p+Math.imul(fe,we)|0,h=h+Math.imul(se,Ae)|0,o=o+Math.imul(se,Se)|0,o=o+Math.imul(le,Ae)|0,p=p+Math.imul(le,Se)|0,h=h+Math.imul(j,Me)|0,o=o+Math.imul(j,Te)|0,o=o+Math.imul(re,Me)|0,p=p+Math.imul(re,Te)|0,h=h+Math.imul(N,Ee)|0,o=o+Math.imul(N,_e)|0,o=o+Math.imul(U,Ee)|0,p=p+Math.imul(U,_e)|0,h=h+Math.imul(I,Be)|0,o=o+Math.imul(I,Ce)|0,o=o+Math.imul(J,Be)|0,p=p+Math.imul(J,Ce)|0,h=h+Math.imul(L,Pe)|0,o=o+Math.imul(L,Le)|0,o=o+Math.imul(O,Pe)|0,p=p+Math.imul(O,Le)|0,h=h+Math.imul(Z,Re)|0,o=o+Math.imul(Z,Fe)|0,o=o+Math.imul(_,Re)|0,p=p+Math.imul(_,Fe)|0;var pr=(x+h|0)+((o&8191)<<13)|0;x=(p+(o>>>13)|0)+(pr>>>26)|0,pr&=67108863,h=Math.imul(ge,ye),o=Math.imul(ge,we),o=o+Math.imul(ve,ye)|0,p=Math.imul(ve,we),h=h+Math.imul(oe,Ae)|0,o=o+Math.imul(oe,Se)|0,o=o+Math.imul(fe,Ae)|0,p=p+Math.imul(fe,Se)|0,h=h+Math.imul(se,Me)|0,o=o+Math.imul(se,Te)|0,o=o+Math.imul(le,Me)|0,p=p+Math.imul(le,Te)|0,h=h+Math.imul(j,Ee)|0,o=o+Math.imul(j,_e)|0,o=o+Math.imul(re,Ee)|0,p=p+Math.imul(re,_e)|0,h=h+Math.imul(N,Be)|0,o=o+Math.imul(N,Ce)|0,o=o+Math.imul(U,Be)|0,p=p+Math.imul(U,Ce)|0,h=h+Math.imul(I,Pe)|0,o=o+Math.imul(I,Le)|0,o=o+Math.imul(J,Pe)|0,p=p+Math.imul(J,Le)|0,h=h+Math.imul(L,Re)|0,o=o+Math.imul(L,Fe)|0,o=o+Math.imul(O,Re)|0,p=p+Math.imul(O,Fe)|0;var br=(x+h|0)+((o&8191)<<13)|0;x=(p+(o>>>13)|0)+(br>>>26)|0,br&=67108863,h=Math.imul(ge,Ae),o=Math.imul(ge,Se),o=o+Math.imul(ve,Ae)|0,p=Math.imul(ve,Se),h=h+Math.imul(oe,Me)|0,o=o+Math.imul(oe,Te)|0,o=o+Math.imul(fe,Me)|0,p=p+Math.imul(fe,Te)|0,h=h+Math.imul(se,Ee)|0,o=o+Math.imul(se,_e)|0,o=o+Math.imul(le,Ee)|0,p=p+Math.imul(le,_e)|0,h=h+Math.imul(j,Be)|0,o=o+Math.imul(j,Ce)|0,o=o+Math.imul(re,Be)|0,p=p+Math.imul(re,Ce)|0,h=h+Math.imul(N,Pe)|0,o=o+Math.imul(N,Le)|0,o=o+Math.imul(U,Pe)|0,p=p+Math.imul(U,Le)|0,h=h+Math.imul(I,Re)|0,o=o+Math.imul(I,Fe)|0,o=o+Math.imul(J,Re)|0,p=p+Math.imul(J,Fe)|0;var gr=(x+h|0)+((o&8191)<<13)|0;x=(p+(o>>>13)|0)+(gr>>>26)|0,gr&=67108863,h=Math.imul(ge,Me),o=Math.imul(ge,Te),o=o+Math.imul(ve,Me)|0,p=Math.imul(ve,Te),h=h+Math.imul(oe,Ee)|0,o=o+Math.imul(oe,_e)|0,o=o+Math.imul(fe,Ee)|0,p=p+Math.imul(fe,_e)|0,h=h+Math.imul(se,Be)|0,o=o+Math.imul(se,Ce)|0,o=o+Math.imul(le,Be)|0,p=p+Math.imul(le,Ce)|0,h=h+Math.imul(j,Pe)|0,o=o+Math.imul(j,Le)|0,o=o+Math.imul(re,Pe)|0,p=p+Math.imul(re,Le)|0,h=h+Math.imul(N,Re)|0,o=o+Math.imul(N,Fe)|0,o=o+Math.imul(U,Re)|0,p=p+Math.imul(U,Fe)|0;var vr=(x+h|0)+((o&8191)<<13)|0;x=(p+(o>>>13)|0)+(vr>>>26)|0,vr&=67108863,h=Math.imul(ge,Ee),o=Math.imul(ge,_e),o=o+Math.imul(ve,Ee)|0,p=Math.imul(ve,_e),h=h+Math.imul(oe,Be)|0,o=o+Math.imul(oe,Ce)|0,o=o+Math.imul(fe,Be)|0,p=p+Math.imul(fe,Ce)|0,h=h+Math.imul(se,Pe)|0,o=o+Math.imul(se,Le)|0,o=o+Math.imul(le,Pe)|0,p=p+Math.imul(le,Le)|0,h=h+Math.imul(j,Re)|0,o=o+Math.imul(j,Fe)|0,o=o+Math.imul(re,Re)|0,p=p+Math.imul(re,Fe)|0;var xr=(x+h|0)+((o&8191)<<13)|0;x=(p+(o>>>13)|0)+(xr>>>26)|0,xr&=67108863,h=Math.imul(ge,Be),o=Math.imul(ge,Ce),o=o+Math.imul(ve,Be)|0,p=Math.imul(ve,Ce),h=h+Math.imul(oe,Pe)|0,o=o+Math.imul(oe,Le)|0,o=o+Math.imul(fe,Pe)|0,p=p+Math.imul(fe,Le)|0,h=h+Math.imul(se,Re)|0,o=o+Math.imul(se,Fe)|0,o=o+Math.imul(le,Re)|0,p=p+Math.imul(le,Fe)|0;var mr=(x+h|0)+((o&8191)<<13)|0;x=(p+(o>>>13)|0)+(mr>>>26)|0,mr&=67108863,h=Math.imul(ge,Pe),o=Math.imul(ge,Le),o=o+Math.imul(ve,Pe)|0,p=Math.imul(ve,Le),h=h+Math.imul(oe,Re)|0,o=o+Math.imul(oe,Fe)|0,o=o+Math.imul(fe,Re)|0,p=p+Math.imul(fe,Fe)|0;var ln=(x+h|0)+((o&8191)<<13)|0;x=(p+(o>>>13)|0)+(ln>>>26)|0,ln&=67108863,h=Math.imul(ge,Re),o=Math.imul(ge,Fe),o=o+Math.imul(ve,Re)|0,p=Math.imul(ve,Fe);var dn=(x+h|0)+((o&8191)<<13)|0;return x=(p+(o>>>13)|0)+(dn>>>26)|0,dn&=67108863,g[0]=Ft,g[1]=ke,g[2]=Ne,g[3]=St,g[4]=Mt,g[5]=Tt,g[6]=Et,g[7]=_t,g[8]=lr,g[9]=dr,g[10]=hr,g[11]=pr,g[12]=br,g[13]=gr,g[14]=vr,g[15]=xr,g[16]=mr,g[17]=ln,g[18]=dn,x!==0&&(g[19]=x,l.length++),l};Math.imul||(C=F);function q(S,s,u){u.negative=s.negative^S.negative,u.length=S.length+s.length;for(var l=0,f=0,c=0;c<u.length-1;c++){var g=f;f=0;for(var x=l&67108863,h=Math.min(c,s.length-1),o=Math.max(0,c-S.length+1);o<=h;o++){var p=c-o,E=S.words[p]|0,b=s.words[o]|0,w=E*b,H=w&67108863;g=g+(w/67108864|0)|0,H=H+x|0,x=H&67108863,g=g+(H>>>26)|0,f+=g>>>26,g&=67108863}u.words[c]=x,l=g,g=f}return l!==0?u.words[c]=l:u.length--,u.strip()}function W(S,s,u){var l=new K;return l.mulp(S,s,u)}i.prototype.mulTo=function(s,u){var l,f=this.length+s.length;return this.length===10&&s.length===10?l=C(this,s,u):f<63?l=F(this,s,u):f<1024?l=q(this,s,u):l=W(this,s,u),l};function K(S,s){this.x=S,this.y=s}K.prototype.makeRBT=function(s){for(var u=new Array(s),l=i.prototype._countBits(s)-1,f=0;f<s;f++)u[f]=this.revBin(f,l,s);return u},K.prototype.revBin=function(s,u,l){if(s===0||s===l-1)return s;for(var f=0,c=0;c<u;c++)f|=(s&1)<<u-c-1,s>>=1;return f},K.prototype.permute=function(s,u,l,f,c,g){for(var x=0;x<g;x++)f[x]=u[s[x]],c[x]=l[s[x]]},K.prototype.transform=function(s,u,l,f,c,g){this.permute(g,s,u,l,f,c);for(var x=1;x<c;x<<=1)for(var h=x<<1,o=Math.cos(2*Math.PI/h),p=Math.sin(2*Math.PI/h),E=0;E<c;E+=h)for(var b=o,w=p,H=0;H<x;H++){var T=l[E+H],k=f[E+H],X=l[E+H+x],Z=f[E+H+x],_=b*X-w*Z;Z=b*Z+w*X,X=_,l[E+H]=T+X,f[E+H]=k+Z,l[E+H+x]=T-X,f[E+H+x]=k-Z,H!==h&&(_=o*b-p*w,w=o*w+p*b,b=_)}},K.prototype.guessLen13b=function(s,u){var l=Math.max(u,s)|1,f=l&1,c=0;for(l=l/2|0;l;l=l>>>1)c++;return 1<<c+1+f},K.prototype.conjugate=function(s,u,l){if(!(l<=1))for(var f=0;f<l/2;f++){var c=s[f];s[f]=s[l-f-1],s[l-f-1]=c,c=u[f],u[f]=-u[l-f-1],u[l-f-1]=-c}},K.prototype.normalize13b=function(s,u){for(var l=0,f=0;f<u/2;f++){var c=Math.round(s[2*f+1]/u)*8192+Math.round(s[2*f]/u)+l;s[f]=c&67108863,c<67108864?l=0:l=c/67108864|0}return s},K.prototype.convert13b=function(s,u,l,f){for(var c=0,g=0;g<u;g++)c=c+(s[g]|0),l[2*g]=c&8191,c=c>>>13,l[2*g+1]=c&8191,c=c>>>13;for(g=2*u;g<f;++g)l[g]=0;r(c===0),r((c&-8192)===0)},K.prototype.stub=function(s){for(var u=new Array(s),l=0;l<s;l++)u[l]=0;return u},K.prototype.mulp=function(s,u,l){var f=2*this.guessLen13b(s.length,u.length),c=this.makeRBT(f),g=this.stub(f),x=new Array(f),h=new Array(f),o=new Array(f),p=new Array(f),E=new Array(f),b=new Array(f),w=l.words;w.length=f,this.convert13b(s.words,s.length,x,f),this.convert13b(u.words,u.length,p,f),this.transform(x,g,h,o,f,c),this.transform(p,g,E,b,f,c);for(var H=0;H<f;H++){var T=h[H]*E[H]-o[H]*b[H];o[H]=h[H]*b[H]+o[H]*E[H],h[H]=T}return this.conjugate(h,o,f),this.transform(h,o,w,g,f,c),this.conjugate(w,g,f),this.normalize13b(w,f),l.negative=s.negative^u.negative,l.length=s.length+u.length,l.strip()},i.prototype.mul=function(s){var u=new i(null);return u.words=new Array(this.length+s.length),this.mulTo(s,u)},i.prototype.mulf=function(s){var u=new i(null);return u.words=new Array(this.length+s.length),W(this,s,u)},i.prototype.imul=function(s){return this.clone().mulTo(s,this)},i.prototype.imuln=function(s){r(typeof s=="number"),r(s<67108864);for(var u=0,l=0;l<this.length;l++){var f=(this.words[l]|0)*s,c=(f&67108863)+(u&67108863);u>>=26,u+=f/67108864|0,u+=c>>>26,this.words[l]=c&67108863}return u!==0&&(this.words[l]=u,this.length++),this.length=s===0?1:this.length,this},i.prototype.muln=function(s){return this.clone().imuln(s)},i.prototype.sqr=function(){return this.mul(this)},i.prototype.isqr=function(){return this.imul(this.clone())},i.prototype.pow=function(s){var u=D(s);if(u.length===0)return new i(1);for(var l=this,f=0;f<u.length&&u[f]===0;f++,l=l.sqr());if(++f<u.length)for(var c=l.sqr();f<u.length;f++,c=c.sqr())u[f]!==0&&(l=l.mul(c));return l},i.prototype.iushln=function(s){r(typeof s=="number"&&s>=0);var u=s%26,l=(s-u)/26,f=67108863>>>26-u<<26-u,c;if(u!==0){var g=0;for(c=0;c<this.length;c++){var x=this.words[c]&f,h=(this.words[c]|0)-x<<u;this.words[c]=h|g,g=x>>>26-u}g&&(this.words[c]=g,this.length++)}if(l!==0){for(c=this.length-1;c>=0;c--)this.words[c+l]=this.words[c];for(c=0;c<l;c++)this.words[c]=0;this.length+=l}return this.strip()},i.prototype.ishln=function(s){return r(this.negative===0),this.iushln(s)},i.prototype.iushrn=function(s,u,l){r(typeof s=="number"&&s>=0);var f;u?f=(u-u%26)/26:f=0;var c=s%26,g=Math.min((s-c)/26,this.length),x=67108863^67108863>>>c<<c,h=l;if(f-=g,f=Math.max(0,f),h){for(var o=0;o<g;o++)h.words[o]=this.words[o];h.length=g}if(g!==0)if(this.length>g)for(this.length-=g,o=0;o<this.length;o++)this.words[o]=this.words[o+g];else this.words[0]=0,this.length=1;var p=0;for(o=this.length-1;o>=0&&(p!==0||o>=f);o--){var E=this.words[o]|0;this.words[o]=p<<26-c|E>>>c,p=E&x}return h&&p!==0&&(h.words[h.length++]=p),this.length===0&&(this.words[0]=0,this.length=1),this.strip()},i.prototype.ishrn=function(s,u,l){return r(this.negative===0),this.iushrn(s,u,l)},i.prototype.shln=function(s){return this.clone().ishln(s)},i.prototype.ushln=function(s){return this.clone().iushln(s)},i.prototype.shrn=function(s){return this.clone().ishrn(s)},i.prototype.ushrn=function(s){return this.clone().iushrn(s)},i.prototype.testn=function(s){r(typeof s=="number"&&s>=0);var u=s%26,l=(s-u)/26,f=1<<u;if(this.length<=l)return!1;var c=this.words[l];return!!(c&f)},i.prototype.imaskn=function(s){r(typeof s=="number"&&s>=0);var u=s%26,l=(s-u)/26;if(r(this.negative===0,"imaskn works only with positive numbers"),this.length<=l)return this;if(u!==0&&l++,this.length=Math.min(l,this.length),u!==0){var f=67108863^67108863>>>u<<u;this.words[this.length-1]&=f}return this.strip()},i.prototype.maskn=function(s){return this.clone().imaskn(s)},i.prototype.iaddn=function(s){return r(typeof s=="number"),r(s<67108864),s<0?this.isubn(-s):this.negative!==0?this.length===1&&(this.words[0]|0)<s?(this.words[0]=s-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(s),this.negative=1,this):this._iaddn(s)},i.prototype._iaddn=function(s){this.words[0]+=s;for(var u=0;u<this.length&&this.words[u]>=67108864;u++)this.words[u]-=67108864,u===this.length-1?this.words[u+1]=1:this.words[u+1]++;return this.length=Math.max(this.length,u+1),this},i.prototype.isubn=function(s){if(r(typeof s=="number"),r(s<67108864),s<0)return this.iaddn(-s);if(this.negative!==0)return this.negative=0,this.iaddn(s),this.negative=1,this;if(this.words[0]-=s,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var u=0;u<this.length&&this.words[u]<0;u++)this.words[u]+=67108864,this.words[u+1]-=1;return this.strip()},i.prototype.addn=function(s){return this.clone().iaddn(s)},i.prototype.subn=function(s){return this.clone().isubn(s)},i.prototype.iabs=function(){return this.negative=0,this},i.prototype.abs=function(){return this.clone().iabs()},i.prototype._ishlnsubmul=function(s,u,l){var f=s.length+l,c;this._expand(f);var g,x=0;for(c=0;c<s.length;c++){g=(this.words[c+l]|0)+x;var h=(s.words[c]|0)*u;g-=h&67108863,x=(g>>26)-(h/67108864|0),this.words[c+l]=g&67108863}for(;c<this.length-l;c++)g=(this.words[c+l]|0)+x,x=g>>26,this.words[c+l]=g&67108863;if(x===0)return this.strip();for(r(x===-1),x=0,c=0;c<this.length;c++)g=-(this.words[c]|0)+x,x=g>>26,this.words[c]=g&67108863;return this.negative=1,this.strip()},i.prototype._wordDiv=function(s,u){var l=this.length-s.length,f=this.clone(),c=s,g=c.words[c.length-1]|0,x=this._countBits(g);l=26-x,l!==0&&(c=c.ushln(l),f.iushln(l),g=c.words[c.length-1]|0);var h=f.length-c.length,o;if(u!=="mod"){o=new i(null),o.length=h+1,o.words=new Array(o.length);for(var p=0;p<o.length;p++)o.words[p]=0}var E=f.clone()._ishlnsubmul(c,1,h);E.negative===0&&(f=E,o&&(o.words[h]=1));for(var b=h-1;b>=0;b--){var w=(f.words[c.length+b]|0)*67108864+(f.words[c.length+b-1]|0);for(w=Math.min(w/g|0,67108863),f._ishlnsubmul(c,w,b);f.negative!==0;)w--,f.negative=0,f._ishlnsubmul(c,1,b),f.isZero()||(f.negative^=1);o&&(o.words[b]=w)}return o&&o.strip(),f.strip(),u!=="div"&&l!==0&&f.iushrn(l),{div:o||null,mod:f}},i.prototype.divmod=function(s,u,l){if(r(!s.isZero()),this.isZero())return{div:new i(0),mod:new i(0)};var f,c,g;return this.negative!==0&&s.negative===0?(g=this.neg().divmod(s,u),u!=="mod"&&(f=g.div.neg()),u!=="div"&&(c=g.mod.neg(),l&&c.negative!==0&&c.iadd(s)),{div:f,mod:c}):this.negative===0&&s.negative!==0?(g=this.divmod(s.neg(),u),u!=="mod"&&(f=g.div.neg()),{div:f,mod:g.mod}):this.negative&s.negative?(g=this.neg().divmod(s.neg(),u),u!=="div"&&(c=g.mod.neg(),l&&c.negative!==0&&c.isub(s)),{div:g.div,mod:c}):s.length>this.length||this.cmp(s)<0?{div:new i(0),mod:this}:s.length===1?u==="div"?{div:this.divn(s.words[0]),mod:null}:u==="mod"?{div:null,mod:new i(this.modn(s.words[0]))}:{div:this.divn(s.words[0]),mod:new i(this.modn(s.words[0]))}:this._wordDiv(s,u)},i.prototype.div=function(s){return this.divmod(s,"div",!1).div},i.prototype.mod=function(s){return this.divmod(s,"mod",!1).mod},i.prototype.umod=function(s){return this.divmod(s,"mod",!0).mod},i.prototype.divRound=function(s){var u=this.divmod(s);if(u.mod.isZero())return u.div;var l=u.div.negative!==0?u.mod.isub(s):u.mod,f=s.ushrn(1),c=s.andln(1),g=l.cmp(f);return g<0||c===1&&g===0?u.div:u.div.negative!==0?u.div.isubn(1):u.div.iaddn(1)},i.prototype.modn=function(s){r(s<=67108863);for(var u=(1<<26)%s,l=0,f=this.length-1;f>=0;f--)l=(u*l+(this.words[f]|0))%s;return l},i.prototype.idivn=function(s){r(s<=67108863);for(var u=0,l=this.length-1;l>=0;l--){var f=(this.words[l]|0)+u*67108864;this.words[l]=f/s|0,u=f%s}return this.strip()},i.prototype.divn=function(s){return this.clone().idivn(s)},i.prototype.egcd=function(s){r(s.negative===0),r(!s.isZero());var u=this,l=s.clone();u.negative!==0?u=u.umod(s):u=u.clone();for(var f=new i(1),c=new i(0),g=new i(0),x=new i(1),h=0;u.isEven()&&l.isEven();)u.iushrn(1),l.iushrn(1),++h;for(var o=l.clone(),p=u.clone();!u.isZero();){for(var E=0,b=1;!(u.words[0]&b)&&E<26;++E,b<<=1);if(E>0)for(u.iushrn(E);E-- >0;)(f.isOdd()||c.isOdd())&&(f.iadd(o),c.isub(p)),f.iushrn(1),c.iushrn(1);for(var w=0,H=1;!(l.words[0]&H)&&w<26;++w,H<<=1);if(w>0)for(l.iushrn(w);w-- >0;)(g.isOdd()||x.isOdd())&&(g.iadd(o),x.isub(p)),g.iushrn(1),x.iushrn(1);u.cmp(l)>=0?(u.isub(l),f.isub(g),c.isub(x)):(l.isub(u),g.isub(f),x.isub(c))}return{a:g,b:x,gcd:l.iushln(h)}},i.prototype._invmp=function(s){r(s.negative===0),r(!s.isZero());var u=this,l=s.clone();u.negative!==0?u=u.umod(s):u=u.clone();for(var f=new i(1),c=new i(0),g=l.clone();u.cmpn(1)>0&&l.cmpn(1)>0;){for(var x=0,h=1;!(u.words[0]&h)&&x<26;++x,h<<=1);if(x>0)for(u.iushrn(x);x-- >0;)f.isOdd()&&f.iadd(g),f.iushrn(1);for(var o=0,p=1;!(l.words[0]&p)&&o<26;++o,p<<=1);if(o>0)for(l.iushrn(o);o-- >0;)c.isOdd()&&c.iadd(g),c.iushrn(1);u.cmp(l)>=0?(u.isub(l),f.isub(c)):(l.isub(u),c.isub(f))}var E;return u.cmpn(1)===0?E=f:E=c,E.cmpn(0)<0&&E.iadd(s),E},i.prototype.gcd=function(s){if(this.isZero())return s.abs();if(s.isZero())return this.abs();var u=this.clone(),l=s.clone();u.negative=0,l.negative=0;for(var f=0;u.isEven()&&l.isEven();f++)u.iushrn(1),l.iushrn(1);do{for(;u.isEven();)u.iushrn(1);for(;l.isEven();)l.iushrn(1);var c=u.cmp(l);if(c<0){var g=u;u=l,l=g}else if(c===0||l.cmpn(1)===0)break;u.isub(l)}while(!0);return l.iushln(f)},i.prototype.invm=function(s){return this.egcd(s).a.umod(s)},i.prototype.isEven=function(){return(this.words[0]&1)===0},i.prototype.isOdd=function(){return(this.words[0]&1)===1},i.prototype.andln=function(s){return this.words[0]&s},i.prototype.bincn=function(s){r(typeof s=="number");var u=s%26,l=(s-u)/26,f=1<<u;if(this.length<=l)return this._expand(l+1),this.words[l]|=f,this;for(var c=f,g=l;c!==0&&g<this.length;g++){var x=this.words[g]|0;x+=c,c=x>>>26,x&=67108863,this.words[g]=x}return c!==0&&(this.words[g]=c,this.length++),this},i.prototype.isZero=function(){return this.length===1&&this.words[0]===0},i.prototype.cmpn=function(s){var u=s<0;if(this.negative!==0&&!u)return-1;if(this.negative===0&&u)return 1;this.strip();var l;if(this.length>1)l=1;else{u&&(s=-s),r(s<=67108863,"Number is too big");var f=this.words[0]|0;l=f===s?0:f<s?-1:1}return this.negative!==0?-l|0:l},i.prototype.cmp=function(s){if(this.negative!==0&&s.negative===0)return-1;if(this.negative===0&&s.negative!==0)return 1;var u=this.ucmp(s);return this.negative!==0?-u|0:u},i.prototype.ucmp=function(s){if(this.length>s.length)return 1;if(this.length<s.length)return-1;for(var u=0,l=this.length-1;l>=0;l--){var f=this.words[l]|0,c=s.words[l]|0;if(f!==c){f<c?u=-1:f>c&&(u=1);break}}return u},i.prototype.gtn=function(s){return this.cmpn(s)===1},i.prototype.gt=function(s){return this.cmp(s)===1},i.prototype.gten=function(s){return this.cmpn(s)>=0},i.prototype.gte=function(s){return this.cmp(s)>=0},i.prototype.ltn=function(s){return this.cmpn(s)===-1},i.prototype.lt=function(s){return this.cmp(s)===-1},i.prototype.lten=function(s){return this.cmpn(s)<=0},i.prototype.lte=function(s){return this.cmp(s)<=0},i.prototype.eqn=function(s){return this.cmpn(s)===0},i.prototype.eq=function(s){return this.cmp(s)===0},i.red=function(s){return new te(s)},i.prototype.toRed=function(s){return r(!this.red,"Already a number in reduction context"),r(this.negative===0,"red works only with positives"),s.convertTo(this)._forceRed(s)},i.prototype.fromRed=function(){return r(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},i.prototype._forceRed=function(s){return this.red=s,this},i.prototype.forceRed=function(s){return r(!this.red,"Already a number in reduction context"),this._forceRed(s)},i.prototype.redAdd=function(s){return r(this.red,"redAdd works only with red numbers"),this.red.add(this,s)},i.prototype.redIAdd=function(s){return r(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,s)},i.prototype.redSub=function(s){return r(this.red,"redSub works only with red numbers"),this.red.sub(this,s)},i.prototype.redISub=function(s){return r(this.red,"redISub works only with red numbers"),this.red.isub(this,s)},i.prototype.redShl=function(s){return r(this.red,"redShl works only with red numbers"),this.red.shl(this,s)},i.prototype.redMul=function(s){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,s),this.red.mul(this,s)},i.prototype.redIMul=function(s){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,s),this.red.imul(this,s)},i.prototype.redSqr=function(){return r(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},i.prototype.redISqr=function(){return r(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},i.prototype.redSqrt=function(){return r(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},i.prototype.redInvm=function(){return r(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},i.prototype.redNeg=function(){return r(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},i.prototype.redPow=function(s){return r(this.red&&!s.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,s)};var ne={k256:null,p224:null,p192:null,p25519:null};function $(S,s){this.name=S,this.p=new i(s,16),this.n=this.p.bitLength(),this.k=new i(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}$.prototype._tmp=function(){var s=new i(null);return s.words=new Array(Math.ceil(this.n/13)),s},$.prototype.ireduce=function(s){var u=s,l;do this.split(u,this.tmp),u=this.imulK(u),u=u.iadd(this.tmp),l=u.bitLength();while(l>this.n);var f=l<this.n?-1:u.ucmp(this.p);return f===0?(u.words[0]=0,u.length=1):f>0?u.isub(this.p):u.strip!==void 0?u.strip():u._strip(),u},$.prototype.split=function(s,u){s.iushrn(this.n,0,u)},$.prototype.imulK=function(s){return s.imul(this.k)};function ae(){$.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}n(ae,$),ae.prototype.split=function(s,u){for(var l=4194303,f=Math.min(s.length,9),c=0;c<f;c++)u.words[c]=s.words[c];if(u.length=f,s.length<=9){s.words[0]=0,s.length=1;return}var g=s.words[9];for(u.words[u.length++]=g&l,c=10;c<s.length;c++){var x=s.words[c]|0;s.words[c-10]=(x&l)<<4|g>>>22,g=x}g>>>=22,s.words[c-10]=g,g===0&&s.length>10?s.length-=10:s.length-=9},ae.prototype.imulK=function(s){s.words[s.length]=0,s.words[s.length+1]=0,s.length+=2;for(var u=0,l=0;l<s.length;l++){var f=s.words[l]|0;u+=f*977,s.words[l]=u&67108863,u=f*64+(u/67108864|0)}return s.words[s.length-1]===0&&(s.length--,s.words[s.length-1]===0&&s.length--),s};function ie(){$.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}n(ie,$);function ee(){$.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}n(ee,$);function ce(){$.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}n(ce,$),ce.prototype.imulK=function(s){for(var u=0,l=0;l<s.length;l++){var f=(s.words[l]|0)*19+u,c=f&67108863;f>>>=26,s.words[l]=c,u=f}return u!==0&&(s.words[s.length++]=u),s},i._prime=function(s){if(ne[s])return ne[s];var u;if(s==="k256")u=new ae;else if(s==="p224")u=new ie;else if(s==="p192")u=new ee;else if(s==="p25519")u=new ce;else throw new Error("Unknown prime "+s);return ne[s]=u,u};function te(S){if(typeof S=="string"){var s=i._prime(S);this.m=s.p,this.prime=s}else r(S.gtn(1),"modulus must be greater than 1"),this.m=S,this.prime=null}te.prototype._verify1=function(s){r(s.negative===0,"red works only with positives"),r(s.red,"red works only with red numbers")},te.prototype._verify2=function(s,u){r((s.negative|u.negative)===0,"red works only with positives"),r(s.red&&s.red===u.red,"red works only with red numbers")},te.prototype.imod=function(s){return this.prime?this.prime.ireduce(s)._forceRed(this):s.umod(this.m)._forceRed(this)},te.prototype.neg=function(s){return s.isZero()?s.clone():this.m.sub(s)._forceRed(this)},te.prototype.add=function(s,u){this._verify2(s,u);var l=s.add(u);return l.cmp(this.m)>=0&&l.isub(this.m),l._forceRed(this)},te.prototype.iadd=function(s,u){this._verify2(s,u);var l=s.iadd(u);return l.cmp(this.m)>=0&&l.isub(this.m),l},te.prototype.sub=function(s,u){this._verify2(s,u);var l=s.sub(u);return l.cmpn(0)<0&&l.iadd(this.m),l._forceRed(this)},te.prototype.isub=function(s,u){this._verify2(s,u);var l=s.isub(u);return l.cmpn(0)<0&&l.iadd(this.m),l},te.prototype.shl=function(s,u){return this._verify1(s),this.imod(s.ushln(u))},te.prototype.imul=function(s,u){return this._verify2(s,u),this.imod(s.imul(u))},te.prototype.mul=function(s,u){return this._verify2(s,u),this.imod(s.mul(u))},te.prototype.isqr=function(s){return this.imul(s,s.clone())},te.prototype.sqr=function(s){return this.mul(s,s)},te.prototype.sqrt=function(s){if(s.isZero())return s.clone();var u=this.m.andln(3);if(r(u%2===1),u===3){var l=this.m.add(new i(1)).iushrn(2);return this.pow(s,l)}for(var f=this.m.subn(1),c=0;!f.isZero()&&f.andln(1)===0;)c++,f.iushrn(1);r(!f.isZero());var g=new i(1).toRed(this),x=g.redNeg(),h=this.m.subn(1).iushrn(1),o=this.m.bitLength();for(o=new i(2*o*o).toRed(this);this.pow(o,h).cmp(x)!==0;)o.redIAdd(x);for(var p=this.pow(o,f),E=this.pow(s,f.addn(1).iushrn(1)),b=this.pow(s,f),w=c;b.cmp(g)!==0;){for(var H=b,T=0;H.cmp(g)!==0;T++)H=H.redSqr();r(T<w);var k=this.pow(p,new i(1).iushln(w-T-1));E=E.redMul(k),p=k.redSqr(),b=b.redMul(p),w=T}return E},te.prototype.invm=function(s){var u=s._invmp(this.m);return u.negative!==0?(u.negative=0,this.imod(u).redNeg()):this.imod(u)},te.prototype.pow=function(s,u){if(u.isZero())return new i(1).toRed(this);if(u.cmpn(1)===0)return s.clone();var l=4,f=new Array(1<<l);f[0]=new i(1).toRed(this),f[1]=s;for(var c=2;c<f.length;c++)f[c]=this.mul(f[c-1],s);var g=f[0],x=0,h=0,o=u.bitLength()%26;for(o===0&&(o=26),c=u.length-1;c>=0;c--){for(var p=u.words[c],E=o-1;E>=0;E--){var b=p>>E&1;if(g!==f[0]&&(g=this.sqr(g)),b===0&&x===0){h=0;continue}x<<=1,x|=b,h++,!(h!==l&&(c!==0||E!==0))&&(g=this.mul(g,f[x]),h=0,x=0)}o=26}return g},te.prototype.convertTo=function(s){var u=s.umod(this.m);return u===s?u.clone():u},te.prototype.convertFrom=function(s){var u=s.clone();return u.red=null,u},i.mont=function(s){return new Y(s)};function Y(S){te.call(this,S),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new i(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}n(Y,te),Y.prototype.convertTo=function(s){return this.imod(s.ushln(this.shift))},Y.prototype.convertFrom=function(s){var u=this.imod(s.mul(this.rinv));return u.red=null,u},Y.prototype.imul=function(s,u){if(s.isZero()||u.isZero())return s.words[0]=0,s.length=1,s;var l=s.imul(u),f=l.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),c=l.isub(f).iushrn(this.shift),g=c;return c.cmp(this.m)>=0?g=c.isub(this.m):c.cmpn(0)<0&&(g=c.iadd(this.m)),g._forceRed(this)},Y.prototype.mul=function(s,u){if(s.isZero()||u.isZero())return new i(0)._forceRed(this);var l=s.mul(u),f=l.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),c=l.isub(f).iushrn(this.shift),g=c;return c.cmp(this.m)>=0?g=c.isub(this.m):c.cmpn(0)<0&&(g=c.iadd(this.m)),g._forceRed(this)},Y.prototype.invm=function(s){var u=this.imod(s._invmp(this.m).mul(this.r2));return u._forceRed(this)}})(typeof al>"u"||al,Mp)});var Tp=V((qB,sl)=>{var GB=A(M());typeof Object.create=="function"?sl.exports=function(e,r){r&&(e.super_=r,e.prototype=Object.create(r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}))}:sl.exports=function(e,r){if(r){e.super_=r;var n=function(){};n.prototype=r.prototype,e.prototype=new n,e.prototype.constructor=e}}});var er=V((XB,cl)=>{var zB=A(M());try{if(fl=rt("util"),typeof fl.inherits!="function")throw"";cl.exports=fl.inherits}catch{cl.exports=Tp()}var fl});var Vf=V((KB,Ep)=>{"use strict";var ZB=A(M()),Zf=rt("buffer"),ao=Zf.Buffer,Hr={},qr;for(qr in Zf)Zf.hasOwnProperty(qr)&&(qr==="SlowBuffer"||qr==="Buffer"||(Hr[qr]=Zf[qr]));var oo=Hr.Buffer={};for(qr in ao)ao.hasOwnProperty(qr)&&(qr==="allocUnsafe"||qr==="allocUnsafeSlow"||(oo[qr]=ao[qr]));Hr.Buffer.prototype=ao.prototype;(!oo.from||oo.from===Uint8Array.from)&&(oo.from=function(t,e,r){if(typeof t=="number")throw new TypeError('The "value" argument must not be of type number. Received type '+typeof t);if(t&&typeof t.length>"u")throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);return ao(t,e,r)});oo.alloc||(oo.alloc=function(t,e,r){if(typeof t!="number")throw new TypeError('The "size" argument must be of type number. Received type '+typeof t);if(t<0||t>=2*(1<<30))throw new RangeError('The value "'+t+'" is invalid for option "size"');var n=ao(t);return!e||e.length===0?n.fill(0):typeof r=="string"?n.fill(e,r):n.fill(e),n});if(!Hr.kStringMaxLength)try{Hr.kStringMaxLength=process.binding("buffer").kStringMaxLength}catch{}Hr.constants||(Hr.constants={MAX_LENGTH:Hr.kMaxLength},Hr.kStringMaxLength&&(Hr.constants.MAX_STRING_LENGTH=Hr.kStringMaxLength));Ep.exports=Hr});var jf=V(_p=>{"use strict";var jB=A(M()),y6=er();function Gr(t){this._reporterState={obj:null,path:[],options:t||{},errors:[]}}_p.Reporter=Gr;Gr.prototype.isError=function(e){return e instanceof so};Gr.prototype.save=function(){let e=this._reporterState;return{obj:e.obj,pathLen:e.path.length}};Gr.prototype.restore=function(e){let r=this._reporterState;r.obj=e.obj,r.path=r.path.slice(0,e.pathLen)};Gr.prototype.enterKey=function(e){return this._reporterState.path.push(e)};Gr.prototype.exitKey=function(e){let r=this._reporterState;r.path=r.path.slice(0,e-1)};Gr.prototype.leaveKey=function(e,r,n){let i=this._reporterState;this.exitKey(e),i.obj!==null&&(i.obj[r]=n)};Gr.prototype.path=function(){return this._reporterState.path.join("/")};Gr.prototype.enterObject=function(){let e=this._reporterState,r=e.obj;return e.obj={},r};Gr.prototype.leaveObject=function(e){let r=this._reporterState,n=r.obj;return r.obj=e,n};Gr.prototype.error=function(e){let r,n=this._reporterState,i=e instanceof so;if(i?r=e:r=new so(n.path.map(function(a){return"["+JSON.stringify(a)+"]"}).join(""),e.message||e,e.stack),!n.options.partial)throw r;return i||n.errors.push(r),r};Gr.prototype.wrapResult=function(e){let r=this._reporterState;return r.options.partial?{result:this.isError(e)?null:e,errors:r.errors}:e};function so(t,e){this.path=t,this.rethrow(e)}y6(so,Error);so.prototype.rethrow=function(e){if(this.message=e+" at: "+(this.path||"(shallow)"),Error.captureStackTrace&&Error.captureStackTrace(this,so),!this.stack)try{throw new Error(this.message)}catch(r){this.stack=r.stack}return this}});var uo=V(ul=>{"use strict";var WB=A(M()),w6=er(),Qf=jf().Reporter,fo=Vf().Buffer;function Xr(t,e){if(Qf.call(this,e),!fo.isBuffer(t)){this.error("Input not Buffer");return}this.base=t,this.offset=0,this.length=t.length}w6(Xr,Qf);ul.DecoderBuffer=Xr;Xr.isDecoderBuffer=function(e){return e instanceof Xr?!0:typeof e=="object"&&fo.isBuffer(e.base)&&e.constructor.name==="DecoderBuffer"&&typeof e.offset=="number"&&typeof e.length=="number"&&typeof e.save=="function"&&typeof e.restore=="function"&&typeof e.isEmpty=="function"&&typeof e.readUInt8=="function"&&typeof e.skip=="function"&&typeof e.raw=="function"};Xr.prototype.save=function(){return{offset:this.offset,reporter:Qf.prototype.save.call(this)}};Xr.prototype.restore=function(e){let r=new Xr(this.base);return r.offset=e.offset,r.length=this.offset,this.offset=e.offset,Qf.prototype.restore.call(this,e.reporter),r};Xr.prototype.isEmpty=function(){return this.offset===this.length};Xr.prototype.readUInt8=function(e){return this.offset+1<=this.length?this.base.readUInt8(this.offset++,!0):this.error(e||"DecoderBuffer overrun")};Xr.prototype.skip=function(e,r){if(!(this.offset+e<=this.length))return this.error(r||"DecoderBuffer overrun");let n=new Xr(this.base);return n._reporterState=this._reporterState,n.offset=this.offset,n.length=this.offset+e,this.offset+=e,n};Xr.prototype.raw=function(e){return this.base.slice(e?e.offset:this.offset,this.length)};function co(t,e){if(Array.isArray(t))this.length=0,this.value=t.map(function(r){return co.isEncoderBuffer(r)||(r=new co(r,e)),this.length+=r.length,r},this);else if(typeof t=="number"){if(!(0<=t&&t<=255))return e.error("non-byte EncoderBuffer value");this.value=t,this.length=1}else if(typeof t=="string")this.value=t,this.length=fo.byteLength(t);else if(fo.isBuffer(t))this.value=t,this.length=t.length;else return e.error("Unsupported type: "+typeof t)}ul.EncoderBuffer=co;co.isEncoderBuffer=function(e){return e instanceof co?!0:typeof e=="object"&&e.constructor.name==="EncoderBuffer"&&typeof e.length=="number"&&typeof e.join=="function"};co.prototype.join=function(e,r){return e||(e=fo.alloc(this.length)),r||(r=0),this.length===0||(Array.isArray(this.value)?this.value.forEach(function(n){n.join(e,r),r+=n.length}):(typeof this.value=="number"?e[r]=this.value:typeof this.value=="string"?e.write(this.value,r):fo.isBuffer(this.value)&&this.value.copy(e,r),r+=this.length)),e}});var ui=V((YB,Cp)=>{var $B=A(M());Cp.exports=Bp;function Bp(t,e){if(!t)throw new Error(e||"Assertion failed")}Bp.equal=function(e,r,n){if(e!=r)throw new Error(n||"Assertion failed: "+e+" != "+r)}});var Wf=V((eC,Lp)=>{"use strict";var tC=A(M()),A6=jf().Reporter,S6=uo().EncoderBuffer,M6=uo().DecoderBuffer,wr=ui(),Pp=["seq","seqof","set","setof","objid","bool","gentime","utctime","null_","enum","int","objDesc","bitstr","bmpstr","charstr","genstr","graphstr","ia5str","iso646str","numstr","octstr","printstr","t61str","unistr","utf8str","videostr"],T6=["key","obj","use","optional","explicit","implicit","def","choice","any","contains"].concat(Pp),E6=["_peekTag","_decodeTag","_use","_decodeStr","_decodeObjid","_decodeTime","_decodeNull","_decodeInt","_decodeBool","_decodeList","_encodeComposite","_encodeStr","_encodeObjid","_encodeTime","_encodeNull","_encodeInt","_encodeBool"];function et(t,e,r){let n={};this._baseState=n,n.name=r,n.enc=t,n.parent=e||null,n.children=null,n.tag=null,n.args=null,n.reverseArgs=null,n.choice=null,n.optional=!1,n.any=!1,n.obj=!1,n.use=null,n.useDecoder=null,n.key=null,n.default=null,n.explicit=null,n.implicit=null,n.contains=null,n.parent||(n.children=[],this._wrap())}Lp.exports=et;var _6=["enc","parent","children","tag","args","reverseArgs","choice","optional","any","obj","use","alteredUse","key","default","explicit","implicit","contains"];et.prototype.clone=function(){let e=this._baseState,r={};_6.forEach(function(i){r[i]=e[i]});let n=new this.constructor(r.parent);return n._baseState=r,n};et.prototype._wrap=function(){let e=this._baseState;T6.forEach(function(r){this[r]=function(){let i=new this.constructor(this);return e.children.push(i),i[r].apply(i,arguments)}},this)};et.prototype._init=function(e){let r=this._baseState;wr(r.parent===null),e.call(this),r.children=r.children.filter(function(n){return n._baseState.parent===this},this),wr.equal(r.children.length,1,"Root node can have only one child")};et.prototype._useArgs=function(e){let r=this._baseState,n=e.filter(function(i){return i instanceof this.constructor},this);e=e.filter(function(i){return!(i instanceof this.constructor)},this),n.length!==0&&(wr(r.children===null),r.children=n,n.forEach(function(i){i._baseState.parent=this},this)),e.length!==0&&(wr(r.args===null),r.args=e,r.reverseArgs=e.map(function(i){if(typeof i!="object"||i.constructor!==Object)return i;let a={};return Object.keys(i).forEach(function(d){d==(d|0)&&(d|=0);let v=i[d];a[v]=d}),a}))};E6.forEach(function(t){et.prototype[t]=function(){let r=this._baseState;throw new Error(t+" not implemented for encoding: "+r.enc)}});Pp.forEach(function(t){et.prototype[t]=function(){let r=this._baseState,n=Array.prototype.slice.call(arguments);return wr(r.tag===null),r.tag=t,this._useArgs(n),this}});et.prototype.use=function(e){wr(e);let r=this._baseState;return wr(r.use===null),r.use=e,this};et.prototype.optional=function(){let e=this._baseState;return e.optional=!0,this};et.prototype.def=function(e){let r=this._baseState;return wr(r.default===null),r.default=e,r.optional=!0,this};et.prototype.explicit=function(e){let r=this._baseState;return wr(r.explicit===null&&r.implicit===null),r.explicit=e,this};et.prototype.implicit=function(e){let r=this._baseState;return wr(r.explicit===null&&r.implicit===null),r.implicit=e,this};et.prototype.obj=function(){let e=this._baseState,r=Array.prototype.slice.call(arguments);return e.obj=!0,r.length!==0&&this._useArgs(r),this};et.prototype.key=function(e){let r=this._baseState;return wr(r.key===null),r.key=e,this};et.prototype.any=function(){let e=this._baseState;return e.any=!0,this};et.prototype.choice=function(e){let r=this._baseState;return wr(r.choice===null),r.choice=e,this._useArgs(Object.keys(e).map(function(n){return e[n]})),this};et.prototype.contains=function(e){let r=this._baseState;return wr(r.use===null),r.contains=e,this};et.prototype._decode=function(e,r){let n=this._baseState;if(n.parent===null)return e.wrapResult(n.children[0]._decode(e,r));let i=n.default,a=!0,d=null;if(n.key!==null&&(d=e.enterKey(n.key)),n.optional){let y=null;if(n.explicit!==null?y=n.explicit:n.implicit!==null?y=n.implicit:n.tag!==null&&(y=n.tag),y===null&&!n.any){let m=e.save();try{n.choice===null?this._decodeGeneric(n.tag,e,r):this._decodeChoice(e,r),a=!0}catch{a=!1}e.restore(m)}else if(a=this._peekTag(e,y,n.any),e.isError(a))return a}let v;if(n.obj&&a&&(v=e.enterObject()),a){if(n.explicit!==null){let m=this._decodeTag(e,n.explicit);if(e.isError(m))return m;e=m}let y=e.offset;if(n.use===null&&n.choice===null){let m;n.any&&(m=e.save());let B=this._decodeTag(e,n.implicit!==null?n.implicit:n.tag,n.any);if(e.isError(B))return B;n.any?i=e.raw(m):e=B}if(r&&r.track&&n.tag!==null&&r.track(e.path(),y,e.length,"tagged"),r&&r.track&&n.tag!==null&&r.track(e.path(),e.offset,e.length,"content"),n.any||(n.choice===null?i=this._decodeGeneric(n.tag,e,r):i=this._decodeChoice(e,r)),e.isError(i))return i;if(!n.any&&n.choice===null&&n.children!==null&&n.children.forEach(function(B){B._decode(e,r)}),n.contains&&(n.tag==="octstr"||n.tag==="bitstr")){let m=new M6(i);i=this._getUse(n.contains,e._reporterState.obj)._decode(m,r)}}return n.obj&&a&&(i=e.leaveObject(v)),n.key!==null&&(i!==null||a===!0)?e.leaveKey(d,n.key,i):d!==null&&e.exitKey(d),i};et.prototype._decodeGeneric=function(e,r,n){let i=this._baseState;return e==="seq"||e==="set"?null:e==="seqof"||e==="setof"?this._decodeList(r,e,i.args[0],n):/str$/.test(e)?this._decodeStr(r,e,n):e==="objid"&&i.args?this._decodeObjid(r,i.args[0],i.args[1],n):e==="objid"?this._decodeObjid(r,null,null,n):e==="gentime"||e==="utctime"?this._decodeTime(r,e,n):e==="null_"?this._decodeNull(r,n):e==="bool"?this._decodeBool(r,n):e==="objDesc"?this._decodeStr(r,e,n):e==="int"||e==="enum"?this._decodeInt(r,i.args&&i.args[0],n):i.use!==null?this._getUse(i.use,r._reporterState.obj)._decode(r,n):r.error("unknown tag: "+e)};et.prototype._getUse=function(e,r){let n=this._baseState;return n.useDecoder=this._use(e,r),wr(n.useDecoder._baseState.parent===null),n.useDecoder=n.useDecoder._baseState.children[0],n.implicit!==n.useDecoder._baseState.implicit&&(n.useDecoder=n.useDecoder.clone(),n.useDecoder._baseState.implicit=n.implicit),n.useDecoder};et.prototype._decodeChoice=function(e,r){let n=this._baseState,i=null,a=!1;return Object.keys(n.choice).some(function(d){let v=e.save(),y=n.choice[d];try{let m=y._decode(e,r);if(e.isError(m))return!1;i={type:d,value:m},a=!0}catch{return e.restore(v),!1}return!0},this),a?i:e.error("Choice not matched")};et.prototype._createEncoderBuffer=function(e){return new S6(e,this.reporter)};et.prototype._encode=function(e,r,n){let i=this._baseState;if(i.default!==null&&i.default===e)return;let a=this._encodeValue(e,r,n);if(a!==void 0&&!this._skipDefault(a,r,n))return a};et.prototype._encodeValue=function(e,r,n){let i=this._baseState;if(i.parent===null)return i.children[0]._encode(e,r||new A6);let a=null;if(this.reporter=r,i.optional&&e===void 0)if(i.default!==null)e=i.default;else return;let d=null,v=!1;if(i.any)a=this._createEncoderBuffer(e);else if(i.choice)a=this._encodeChoice(e,r);else if(i.contains)d=this._getUse(i.contains,n)._encode(e,r),v=!0;else if(i.children)d=i.children.map(function(y){if(y._baseState.tag==="null_")return y._encode(null,r,e);if(y._baseState.key===null)return r.error("Child should have a key");let m=r.enterKey(y._baseState.key);if(typeof e!="object")return r.error("Child expected, but input is not object");let B=y._encode(e[y._baseState.key],r,e);return r.leaveKey(m),B},this).filter(function(y){return y}),d=this._createEncoderBuffer(d);else if(i.tag==="seqof"||i.tag==="setof"){if(!(i.args&&i.args.length===1))return r.error("Too many args for : "+i.tag);if(!Array.isArray(e))return r.error("seqof/setof, but data is not Array");let y=this.clone();y._baseState.implicit=null,d=this._createEncoderBuffer(e.map(function(m){let B=this._baseState;return this._getUse(B.args[0],e)._encode(m,r)},y))}else i.use!==null?a=this._getUse(i.use,n)._encode(e,r):(d=this._encodePrimitive(i.tag,e),v=!0);if(!i.any&&i.choice===null){let y=i.implicit!==null?i.implicit:i.tag,m=i.implicit===null?"universal":"context";y===null?i.use===null&&r.error("Tag could be omitted only for .use()"):i.use===null&&(a=this._encodeComposite(y,v,m,d))}return i.explicit!==null&&(a=this._encodeComposite(i.explicit,!1,"context",a)),a};et.prototype._encodeChoice=function(e,r){let n=this._baseState,i=n.choice[e.type];return i||wr(!1,e.type+" not found in "+JSON.stringify(Object.keys(n.choice))),i._encode(e.value,r)};et.prototype._encodePrimitive=function(e,r){let n=this._baseState;if(/str$/.test(e))return this._encodeStr(r,e);if(e==="objid"&&n.args)return this._encodeObjid(r,n.reverseArgs[0],n.args[1]);if(e==="objid")return this._encodeObjid(r,null,null);if(e==="gentime"||e==="utctime")return this._encodeTime(r,e);if(e==="null_")return this._encodeNull();if(e==="int"||e==="enum")return this._encodeInt(r,n.args&&n.reverseArgs[0]);if(e==="bool")return this._encodeBool(r);if(e==="objDesc")return this._encodeStr(r,e);throw new Error("Unsupported tag: "+e)};et.prototype._isNumstr=function(e){return/^[0-9 ]*$/.test(e)};et.prototype._isPrintstr=function(e){return/^[A-Za-z0-9 '()+,-./:=?]*$/.test(e)}});var Yf=V(la=>{"use strict";var nC=A(M());function Rp(t){let e={};return Object.keys(t).forEach(function(r){(r|0)==r&&(r=r|0);let n=t[r];e[n]=r}),e}la.tagClass={0:"universal",1:"application",2:"context",3:"private"};la.tagClassByName=Rp(la.tagClass);la.tag={0:"end",1:"bool",2:"int",3:"bitstr",4:"octstr",5:"null_",6:"objid",7:"objDesc",8:"external",9:"real",10:"enum",11:"embed",12:"utf8str",13:"relativeOid",16:"seq",17:"set",18:"numstr",19:"printstr",20:"t61str",21:"videostr",22:"ia5str",23:"utctime",24:"gentime",25:"graphstr",26:"iso646str",27:"genstr",28:"unistr",29:"charstr",30:"bmpstr"};la.tagByName=Rp(la.tag)});var dl=V((iC,Op)=>{"use strict";var aC=A(M()),B6=er(),li=Vf().Buffer,Fp=Wf(),ll=Yf();function Dp(t){this.enc="der",this.name=t.name,this.entity=t,this.tree=new gn,this.tree._init(t.body)}Op.exports=Dp;Dp.prototype.encode=function(e,r){return this.tree._encode(e,r).join()};function gn(t){Fp.call(this,"der",t)}B6(gn,Fp);gn.prototype._encodeComposite=function(e,r,n,i){let a=C6(e,r,n,this.reporter);if(i.length<128){let y=li.alloc(2);return y[0]=a,y[1]=i.length,this._createEncoderBuffer([y,i])}let d=1;for(let y=i.length;y>=256;y>>=8)d++;let v=li.alloc(2+d);v[0]=a,v[1]=128|d;for(let y=1+d,m=i.length;m>0;y--,m>>=8)v[y]=m&255;return this._createEncoderBuffer([v,i])};gn.prototype._encodeStr=function(e,r){if(r==="bitstr")return this._createEncoderBuffer([e.unused|0,e.data]);if(r==="bmpstr"){let n=li.alloc(e.length*2);for(let i=0;i<e.length;i++)n.writeUInt16BE(e.charCodeAt(i),i*2);return this._createEncoderBuffer(n)}else return r==="numstr"?this._isNumstr(e)?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: numstr supports only digits and space"):r==="printstr"?this._isPrintstr(e)?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: printstr supports only latin upper and lower case letters, digits, space, apostrophe, left and rigth parenthesis, plus sign, comma, hyphen, dot, slash, colon, equal sign, question mark"):/str$/.test(r)?this._createEncoderBuffer(e):r==="objDesc"?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: "+r+" unsupported")};gn.prototype._encodeObjid=function(e,r,n){if(typeof e=="string"){if(!r)return this.reporter.error("string objid given, but no values map found");if(!r.hasOwnProperty(e))return this.reporter.error("objid not found in values map");e=r[e].split(/[\s.]+/g);for(let v=0;v<e.length;v++)e[v]|=0}else if(Array.isArray(e)){e=e.slice();for(let v=0;v<e.length;v++)e[v]|=0}if(!Array.isArray(e))return this.reporter.error("objid() should be either array or string, got: "+JSON.stringify(e));if(!n){if(e[1]>=40)return this.reporter.error("Second objid identifier OOB");e.splice(0,2,e[0]*40+e[1])}let i=0;for(let v=0;v<e.length;v++){let y=e[v];for(i++;y>=128;y>>=7)i++}let a=li.alloc(i),d=a.length-1;for(let v=e.length-1;v>=0;v--){let y=e[v];for(a[d--]=y&127;(y>>=7)>0;)a[d--]=128|y&127}return this._createEncoderBuffer(a)};function zr(t){return t<10?"0"+t:t}gn.prototype._encodeTime=function(e,r){let n,i=new Date(e);return r==="gentime"?n=[zr(i.getUTCFullYear()),zr(i.getUTCMonth()+1),zr(i.getUTCDate()),zr(i.getUTCHours()),zr(i.getUTCMinutes()),zr(i.getUTCSeconds()),"Z"].join(""):r==="utctime"?n=[zr(i.getUTCFullYear()%100),zr(i.getUTCMonth()+1),zr(i.getUTCDate()),zr(i.getUTCHours()),zr(i.getUTCMinutes()),zr(i.getUTCSeconds()),"Z"].join(""):this.reporter.error("Encoding "+r+" time is not supported yet"),this._encodeStr(n,"octstr")};gn.prototype._encodeNull=function(){return this._createEncoderBuffer("")};gn.prototype._encodeInt=function(e,r){if(typeof e=="string"){if(!r)return this.reporter.error("String int or enum given, but no values map");if(!r.hasOwnProperty(e))return this.reporter.error("Values map doesn't contain: "+JSON.stringify(e));e=r[e]}if(typeof e!="number"&&!li.isBuffer(e)){let a=e.toArray();!e.sign&&a[0]&128&&a.unshift(0),e=li.from(a)}if(li.isBuffer(e)){let a=e.length;e.length===0&&a++;let d=li.alloc(a);return e.copy(d),e.length===0&&(d[0]=0),this._createEncoderBuffer(d)}if(e<128)return this._createEncoderBuffer(e);if(e<256)return this._createEncoderBuffer([0,e]);let n=1;for(let a=e;a>=256;a>>=8)n++;let i=new Array(n);for(let a=i.length-1;a>=0;a--)i[a]=e&255,e>>=8;return i[0]&128&&i.unshift(0),this._createEncoderBuffer(li.from(i))};gn.prototype._encodeBool=function(e){return this._createEncoderBuffer(e?255:0)};gn.prototype._use=function(e,r){return typeof e=="function"&&(e=e(r)),e._getEncoder("der").tree};gn.prototype._skipDefault=function(e,r,n){let i=this._baseState,a;if(i.default===null)return!1;let d=e.join();if(i.defaultBuffer===void 0&&(i.defaultBuffer=this._encodeValue(i.default,r,n).join()),d.length!==i.defaultBuffer.length)return!1;for(a=0;a<d.length;a++)if(d[a]!==i.defaultBuffer[a])return!1;return!0};function C6(t,e,r,n){let i;if(t==="seqof"?t="seq":t==="setof"&&(t="set"),ll.tagByName.hasOwnProperty(t))i=ll.tagByName[t];else if(typeof t=="number"&&(t|0)===t)i=t;else return n.error("Unknown tag: "+t);return i>=31?n.error("Multi-octet tag encoding unsupported"):(e||(i|=32),i|=ll.tagClassByName[r||"universal"]<<6,i)}});var kp=V((oC,Ip)=>{"use strict";var sC=A(M()),P6=er(),hl=dl();function pl(t){hl.call(this,t),this.enc="pem"}P6(pl,hl);Ip.exports=pl;pl.prototype.encode=function(e,r){let i=hl.prototype.encode.call(this,e).toString("base64"),a=["-----BEGIN "+r.label+"-----"];for(let d=0;d<i.length;d+=64)a.push(i.slice(d,d+64));return a.push("-----END "+r.label+"-----"),a.join(`
5
5
  `)}});var bl=V(Jp=>{"use strict";var cC=A(M()),Np=Jp;Np.der=dl();Np.pem=kp()});var vl=V((uC,zp)=>{"use strict";var lC=A(M()),L6=er(),R6=ol(),Up=uo().DecoderBuffer,qp=Wf(),Hp=Yf();function Gp(t){this.enc="der",this.name=t.name,this.entity=t,this.tree=new Lr,this.tree._init(t.body)}zp.exports=Gp;Gp.prototype.decode=function(e,r){return Up.isDecoderBuffer(e)||(e=new Up(e,r)),this.tree._decode(e,r)};function Lr(t){qp.call(this,"der",t)}L6(Lr,qp);Lr.prototype._peekTag=function(e,r,n){if(e.isEmpty())return!1;let i=e.save(),a=gl(e,'Failed to peek tag: "'+r+'"');return e.isError(a)?a:(e.restore(i),a.tag===r||a.tagStr===r||a.tagStr+"of"===r||n)};Lr.prototype._decodeTag=function(e,r,n){let i=gl(e,'Failed to decode tag of "'+r+'"');if(e.isError(i))return i;let a=Xp(e,i.primitive,'Failed to get length of "'+r+'"');if(e.isError(a))return a;if(!n&&i.tag!==r&&i.tagStr!==r&&i.tagStr+"of"!==r)return e.error('Failed to match tag: "'+r+'"');if(i.primitive||a!==null)return e.skip(a,'Failed to match body of: "'+r+'"');let d=e.save(),v=this._skipUntilEnd(e,'Failed to skip indefinite length body: "'+this.tag+'"');return e.isError(v)?v:(a=e.offset-d.offset,e.restore(d),e.skip(a,'Failed to match body of: "'+r+'"'))};Lr.prototype._skipUntilEnd=function(e,r){for(;;){let n=gl(e,r);if(e.isError(n))return n;let i=Xp(e,n.primitive,r);if(e.isError(i))return i;let a;if(n.primitive||i!==null?a=e.skip(i):a=this._skipUntilEnd(e,r),e.isError(a))return a;if(n.tagStr==="end")break}};Lr.prototype._decodeList=function(e,r,n,i){let a=[];for(;!e.isEmpty();){let d=this._peekTag(e,"end");if(e.isError(d))return d;let v=n.decode(e,"der",i);if(e.isError(v)&&d)break;a.push(v)}return a};Lr.prototype._decodeStr=function(e,r){if(r==="bitstr"){let n=e.readUInt8();return e.isError(n)?n:{unused:n,data:e.raw()}}else if(r==="bmpstr"){let n=e.raw();if(n.length%2===1)return e.error("Decoding of string type: bmpstr length mismatch");let i="";for(let a=0;a<n.length/2;a++)i+=String.fromCharCode(n.readUInt16BE(a*2));return i}else if(r==="numstr"){let n=e.raw().toString("ascii");return this._isNumstr(n)?n:e.error("Decoding of string type: numstr unsupported characters")}else{if(r==="octstr")return e.raw();if(r==="objDesc")return e.raw();if(r==="printstr"){let n=e.raw().toString("ascii");return this._isPrintstr(n)?n:e.error("Decoding of string type: printstr unsupported characters")}else return/str$/.test(r)?e.raw().toString():e.error("Decoding of string type: "+r+" unsupported")}};Lr.prototype._decodeObjid=function(e,r,n){let i,a=[],d=0,v=0;for(;!e.isEmpty();)v=e.readUInt8(),d<<=7,d|=v&127,v&128||(a.push(d),d=0);v&128&&a.push(d);let y=a[0]/40|0,m=a[0]%40;if(n?i=a:i=[y,m].concat(a.slice(1)),r){let B=r[i.join(" ")];B===void 0&&(B=r[i.join(".")]),B!==void 0&&(i=B)}return i};Lr.prototype._decodeTime=function(e,r){let n=e.raw().toString(),i,a,d,v,y,m;if(r==="gentime")i=n.slice(0,4)|0,a=n.slice(4,6)|0,d=n.slice(6,8)|0,v=n.slice(8,10)|0,y=n.slice(10,12)|0,m=n.slice(12,14)|0;else if(r==="utctime")i=n.slice(0,2)|0,a=n.slice(2,4)|0,d=n.slice(4,6)|0,v=n.slice(6,8)|0,y=n.slice(8,10)|0,m=n.slice(10,12)|0,i<70?i=2e3+i:i=1900+i;else return e.error("Decoding "+r+" time is not supported yet");return Date.UTC(i,a-1,d,v,y,m,0)};Lr.prototype._decodeNull=function(){return null};Lr.prototype._decodeBool=function(e){let r=e.readUInt8();return e.isError(r)?r:r!==0};Lr.prototype._decodeInt=function(e,r){let n=e.raw(),i=new R6(n);return r&&(i=r[i.toString(10)]||i),i};Lr.prototype._use=function(e,r){return typeof e=="function"&&(e=e(r)),e._getDecoder("der").tree};function gl(t,e){let r=t.readUInt8(e);if(t.isError(r))return r;let n=Hp.tagClass[r>>6],i=(r&32)===0;if((r&31)===31){let d=r;for(r=0;(d&128)===128;){if(d=t.readUInt8(e),t.isError(d))return d;r<<=7,r|=d&127}}else r&=31;let a=Hp.tag[r];return{cls:n,primitive:i,tag:r,tagStr:a}}function Xp(t,e,r){let n=t.readUInt8(r);if(t.isError(n))return n;if(!e&&n===128)return null;if(!(n&128))return n;let i=n&127;if(i>4)return t.error("length octect is too long");n=0;for(let a=0;a<i;a++){n<<=8;let d=t.readUInt8(r);if(t.isError(d))return d;n|=d}return n}});var Zp=V((dC,Kp)=>{"use strict";var hC=A(M()),F6=er(),D6=Vf().Buffer,xl=vl();function ml(t){xl.call(this,t),this.enc="pem"}F6(ml,xl);Kp.exports=ml;ml.prototype.decode=function(e,r){let n=e.toString().split(/[\r\n]+/g),i=r.label.toUpperCase(),a=/^-----(BEGIN|END) ([^-]+)-----$/,d=-1,v=-1;for(let B=0;B<n.length;B++){let P=n[B].match(a);if(P!==null&&P[2]===i)if(d===-1){if(P[1]!=="BEGIN")break;d=B}else{if(P[1]!=="END")break;v=B;break}}if(d===-1||v===-1)throw new Error("PEM section not found for: "+i);let y=n.slice(d+1,v).join("");y.replace(/[^a-z0-9+/=]+/gi,"");let m=D6.from(y,"base64");return xl.prototype.decode.call(this,m,r)}});var yl=V(jp=>{"use strict";var bC=A(M()),Vp=jp;Vp.der=vl();Vp.pem=Zp()});var Wp=V(Qp=>{"use strict";var vC=A(M()),O6=bl(),I6=yl(),k6=er(),N6=Qp;N6.define=function(e,r){return new lo(e,r)};function lo(t,e){this.name=t,this.body=e,this.decoders={},this.encoders={}}lo.prototype._createNamed=function(e){let r=this.name;function n(i){this._initNamed(i,r)}return k6(n,e),n.prototype._initNamed=function(a,d){e.call(this,a,d)},new n(this)};lo.prototype._getDecoder=function(e){return e=e||"der",this.decoders.hasOwnProperty(e)||(this.decoders[e]=this._createNamed(I6[e])),this.decoders[e]};lo.prototype.decode=function(e,r,n){return this._getDecoder(r).decode(e,n)};lo.prototype._getEncoder=function(e){return e=e||"der",this.encoders.hasOwnProperty(e)||(this.encoders[e]=this._createNamed(O6[e])),this.encoders[e]};lo.prototype.encode=function(e,r,n){return this._getEncoder(r).encode(e,n)}});var $p=V(Yp=>{"use strict";var mC=A(M()),$f=Yp;$f.Reporter=jf().Reporter;$f.DecoderBuffer=uo().DecoderBuffer;$f.EncoderBuffer=uo().EncoderBuffer;$f.Node=Wf()});var rb=V(tb=>{"use strict";var wC=A(M()),eb=tb;eb._reverse=function(e){let r={};return Object.keys(e).forEach(function(n){(n|0)==n&&(n=n|0);let i=e[n];r[i]=n}),r};eb.der=Yf()});var ib=V(nb=>{"use strict";var SC=A(M()),ho=nb;ho.bignum=ol();ho.define=Wp().define;ho.base=$p();ho.constants=rb();ho.decoders=yl();ho.encoders=bl()});var db=V(Fn=>{"use strict";var TC=A(M()),J6=Fn&&Fn.__createBinding||(Object.create?function(t,e,r,n){n===void 0&&(n=r);var i=Object.getOwnPropertyDescriptor(e,r);(!i||("get"in i?!e.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,i)}:function(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]}),U6=Fn&&Fn.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),H6=Fn&&Fn.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&J6(e,t,r);return U6(e,t),e};Object.defineProperty(Fn,"__esModule",{value:!0});Fn.pemTojwk=W6;Fn.jwkTopem=Y6;var di=H6(ib());function q6(t){return t.replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function wl(t){return q6(Buffer.from(t,"hex").toString("base64"))}var ab=di.define("RSAPublicKey",function(){this.seq().obj(this.key("n").int(),this.key("e").int())}),ob=di.define("AlgorithmIdentifier",function(){this.seq().obj(this.key("algorithm").objid(),this.key("parameters").optional().any())}),G6=di.define("PublicKeyInfo",function(){this.seq().obj(this.key("algorithm").use(ob),this.key("publicKey").bitstr())}),sb=di.define("Version",function(){this.int({0:"two-prime",1:"multi"})}),X6=di.define("OtherPrimeInfos",function(){this.seq().obj(this.key("ri").int(),this.key("di").int(),this.key("ti").int())}),fb=di.define("RSAPrivateKey",function(){this.seq().obj(this.key("version").use(sb),this.key("n").int(),this.key("e").int(),this.key("d").int(),this.key("p").int(),this.key("q").int(),this.key("dp").int(),this.key("dq").int(),this.key("qi").int(),this.key("other").optional().use(X6))}),z6=di.define("PrivateKeyInfo",function(){this.seq().obj(this.key("version").use(sb),this.key("algorithm").use(ob),this.key("privateKey").bitstr())});function cb(t,e){return e=e||{},Object.keys(e).forEach(function(r){t[r]=e[r]}),t}function Al(t){return t.length%2===1?"0"+t:t}function ub(t,e){var r=ab.decode(t,"der"),n=Al(r.e.toString(16)),i={kty:"RSA",n:Di(r.n),e:wl(n)};return cb(i,e)}function lb(t,e){var r=fb.decode(t,"der"),n=Al(r.e.toString(16)),i={kty:"RSA",n:Di(r.n),e:wl(n),d:Di(r.d),p:Di(r.p),q:Di(r.q),dp:Di(r.dp),dq:Di(r.dq),qi:Di(r.qi)};return cb(i,e)}function K6(t,e){var r=G6.decode(t,"der");return ub(r.publicKey.data,e)}function Z6(t,e){var r=z6.decode(t,"der");return lb(r.privateKey.data,e)}function V6(t){var e=/^-----BEGIN (RSA )?(PUBLIC|PRIVATE) KEY-----$/.exec(t);if(!e)return null;var r=!!e[1],n=e[2]==="PRIVATE";return n?r?lb:Z6:r?ub:K6}function j6(t){return{n:Fi(t.n),e:Fi(t.e),d:t.d&&Fi(t.d),p:t.p&&Fi(t.p),q:t.q&&Fi(t.q),dp:t.dp&&Fi(t.dp),dq:t.dq&&Fi(t.dq),qi:t.qi&&Fi(t.qi)}}function Di(t){return wl(Al(t.toString(16)))}function Q6(t){return new di.bignum(Buffer.from(t,"base64"))}function Fi(t){return/^[0-9]+$/.test(t)?new di.bignum(t,10):Q6(t)}function W6(t,e){var r=t.toString().split(/(\r\n|\r|\n)+/g);r=r.filter(function(i){return i.trim().length!==0});var n=V6(r[0]);return r=r.slice(1,-1).join(""),n(Buffer.from(r.replace(/[^\w\d\+\/=]+/g,""),"base64"),e)}function Y6(t){var e=j6(t),r=!!e.d,n=r?"PRIVATE":"PUBLIC",i="-----BEGIN RSA "+n+` KEY-----
6
6
  `,a=`
@@ -39,7 +39,7 @@ ${JSON.stringify(Buffer.from(r))},${JSON.stringify(Buffer.from(n))},${a} => ${JS
39
39
  }
40
40
  }`;return t.queryKey&&(q=`${t.queryKey}: ${q}`),q}async function s8(t){try{return await(await fetch(`https://${t.gateway}/graphql`,{method:"POST",headers:{"Content-Type":"application/json"},body:t.query})).json()}catch(e){throw e}}var A_=Mr.goldsky;async function b1(t,e){let r=[{name:"Authority",value:xt.mu}];e.tags&&e.tags.length>0&&e.tags.forEach(n=>r.push(n));try{let n=await t.ao.spawn({module:e.module,scheduler:e.scheduler,signer:t.signer,tags:r,data:e.data});return pn(`Process ID: ${n}`),pn("Sending initial message..."),await Pn(t,{processId:n,action:"Init"}),n}catch(n){throw console.log(n),new Error(n.message??"Error spawning process")}}function g1(t){return async e=>await Pn(t,e)}async function Pn(t,e){try{let r=[{name:"Action",value:e.action}];e.tags&&r.push(...e.tags);let n=e.useRawData?e.data:JSON.stringify(e.data);return await t.ao.message({process:e.processId,signer:t.signer,tags:r,data:n})}catch(r){throw new Error(r)}}function v1(t){return async e=>await oa(t,e)}async function oa(t,e){let n=`${e.node??c1.defaultNode}/${e.processId}~process@1.0/now/${e.path}`;e.serialize&&(n+="/serialize~json@1.0"),console.log("Getting state from HyperBEAM:",n);try{let i=await fetch(n);if(i.ok)return console.log("Returning state from HyperBEAM."),i.json();throw new Error("Error getting state from HyperBEAM.")}catch(i){if(e.fallbackAction){console.log("State not found, dryrunning...");let a=await Pf(t,{processId:e.processId,action:e.fallbackAction});return console.log("Returning state from dryrun."),a}throw i}}function x1(t){return async e=>await Pf(t,e)}async function Pf(t,e){try{let r=[{name:"Action",value:e.action}];e.tags&&r.push(...e.tags);let n;if(typeof e.data=="object")n=JSON.stringify(e.data||{});else if(typeof e.data=="string"){try{JSON.parse(e.data)}catch(a){throw console.error(a),new Error("Invalid JSON data")}n=e.data}let i=await t.ao.dryrun({process:e.processId,tags:r,data:n});if(i.Messages&&i.Messages.length){if(i.Messages[0].Data)return JSON.parse(i.Messages[0].Data);if(i.Messages[0].Tags)return i.Messages[0].Tags.reduce((a,d)=>(a[d.name]=d.value,a),{})}}catch(r){throw new Error(r.message??"Error dryrunning process")}}async function f8(t,e){try{let{Messages:r}=await t.ao.result({message:e.messageId,process:e.processId});if(r&&r.length){let n={};return r.forEach(i=>{let a=Cf(i.Tags,"Action")||e.action,d=null,v=i.Data;if(v)try{d=JSON.parse(v)}catch{d=v}let y=Cf(i.Tags,"Status"),m=Cf(i.Tags,"Message");n[a]={id:e.messageId,status:y,message:m,data:d}}),n}else return null}catch(r){console.error(r)}}async function ss(t,e){let r=null;if(e.evalSrc?r=e.evalSrc:e.evalTxId&&(r=await c8(e.evalTxId)),r)try{let n=await Pn(t,{processId:e.processId,action:"Eval",data:r,tags:e.evalTags||null,useRawData:!0});return pn(`Eval: ${n}`),await f8(t,{processId:e.processId,messageId:n,action:"Eval"})}catch(n){throw new Error(n.message??"Error sending process eval")}return null}function m1(t){return async(e,r)=>{try{let n={module:e.module||xt.module,scheduler:e.scheduler||xt.scheduler};e.data&&(n.data=e.data),e.tags&&(n.tags=e.tags),r&&r("Spawning process...");let i=await b1(t,n);if(e.evalTxId||e.evalSrc){r&&r("Process retrieved!"),r&&r("Sending eval...");try{await ss(t,{processId:i,evalTxId:e.evalTxId||null,evalSrc:e.evalSrc||null,evalTags:e.evalTags})&&r&&r("Eval complete")}catch(a){throw new Error(a.message??"Error creating process")}}return i}catch(n){throw new Error(n.message??"Error creating process")}}}async function sa(t,e,r){try{let n={module:e.module||xt.module,scheduler:e.scheduler||xt.scheduler};e.data&&(n.data=e.data),e.tags&&(n.tags=e.tags),r&&r("Spawning process...");let i=await b1(t,n);if(e.evalTxId||e.evalSrc){r&&r("Process retrieved!"),r&&r("Sending eval...");try{await ss(t,{processId:i,evalTxId:e.evalTxId||null,evalSrc:e.evalSrc||null,evalTags:e.evalTags})&&r&&r("Eval complete")}catch(a){throw new Error(a.message??"Error creating process")}}return i}catch(n){throw new Error(n.message??"Error creating process")}}async function c8(t){try{return await(await fetch($a(t))).text()}catch(e){throw new Error(e)}}var cN=A(M(),1);var rN=A(M(),1);var $h={};i1($h,{AVSCTap:()=>Mf,AlgorandSigner:()=>bf,AptosSigner:()=>vf,ArconnectSigner:()=>Va,Arweave:()=>Ap.default,ArweaveSigner:()=>da,Bundle:()=>Vc,BundleItem:()=>Yh,CryptoDriver:()=>Kf,Curve25519:()=>Cr,DataItem:()=>zc,EthereumSigner:()=>Ir,HexInjectedSolanaSigner:()=>Xa,HexSolanaSigner:()=>gf,InjectedAptosSigner:()=>za,InjectedEthereumSigner:()=>rh,InjectedSolanaSigner:()=>ha,InjectedTypedEthereumSigner:()=>Vh,KyveSigner:()=>yf,MAX_TAG_BYTES:()=>Xc,MIN_BINARY_SIZE:()=>Kc,MultiSignatureAptosSigner:()=>Ka,NearSigner:()=>pf,PolygonSigner:()=>hf,Rsa4096:()=>ua,SIG_CONFIG:()=>Je,SignatureConfig:()=>Oe,Signer:()=>lu,SolanaSigner:()=>Ai,Transaction:()=>wp.default,TypedEthereumSigner:()=>Za,bundleAndSignData:()=>HE,byteArrayToLong:()=>bt,concatBuffers:()=>$e.concatBuffers,createData:()=>_f,deepHash:()=>Pi,deserializeTags:()=>is,exportForTesting:()=>OE,getCryptoDriver:()=>yt,getSignatureAndId:()=>_3,indexToType:()=>wf,keccak256:()=>zh,longTo16ByteArray:()=>kE,longTo32ByteArray:()=>Gc,longTo8ByteArray:()=>qc,longToNByteArray:()=>Sf,secp256k1:()=>Ga,serializeTags:()=>Qh,shortTo2ByteArray:()=>jh,sign:()=>Zc,stringToBuffer:()=>$e.stringToBuffer,unbundleData:()=>UE});var Pk=A(M(),1);var kI=A(M(),1);var E_=A(M(),1),lu=class{publicKey;signatureType;signatureLength;ownerLength;pem;static verify(e,r,n,i){throw new Error("You must implement verify method on child")}};var PI=A(M(),1);var H_=A(M(),1),F1=A(Nr(),1);var D_=A(M(),1),Oe;(function(t){t[t.ARWEAVE=1]="ARWEAVE",t[t.ED25519=2]="ED25519",t[t.ETHEREUM=3]="ETHEREUM",t[t.SOLANA=4]="SOLANA",t[t.INJECTEDAPTOS=5]="INJECTEDAPTOS",t[t.MULTIAPTOS=6]="MULTIAPTOS",t[t.TYPEDETHEREUM=7]="TYPEDETHEREUM",t[t.KYVE=101]="KYVE"})(Oe||(Oe={}));var Je={[Oe.ARWEAVE]:{sigLength:512,pubLength:512,sigName:"arweave"},[Oe.ED25519]:{sigLength:64,pubLength:32,sigName:"ed25519"},[Oe.ETHEREUM]:{sigLength:65,pubLength:65,sigName:"ethereum"},[Oe.SOLANA]:{sigLength:64,pubLength:32,sigName:"solana"},[Oe.INJECTEDAPTOS]:{sigLength:64,pubLength:32,sigName:"injectedAptos"},[Oe.MULTIAPTOS]:{sigLength:64*32+4,pubLength:32*32+1,sigName:"multiAptos"},[Oe.TYPEDETHEREUM]:{sigLength:65,pubLength:42,sigName:"typedEthereum"},[Oe.KYVE]:{sigLength:65,pubLength:65,sigName:"kyve"}};var k_=A(M(),1);import*as p8 from"crypto";var $t=BigInt(0),ze=BigInt(1),to=BigInt(2),b8=BigInt(8),S1=BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),ot=Object.freeze({a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),P:BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),l:S1,n:S1,h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960")});var C1=BigInt("0x10000000000000000000000000000000000000000000000000000000000000000"),fs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),O_=BigInt("6853475219497561581579357271197624642482790079785650197046958215289687604742"),g8=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),v8=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),x8=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),m8=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Dt=class t{constructor(e,r,n,i){this.x=e,this.y=r,this.z=n,this.t=i}static fromAffine(e){if(!(e instanceof mt))throw new TypeError("ExtendedPoint#fromAffine: expected Point");return e.equals(mt.ZERO)?t.ZERO:new t(e.x,e.y,ze,he(e.x*e.y))}static toAffineBatch(e){let r=A8(e.map(n=>n.z));return e.map((n,i)=>n.toAffine(r[i]))}static normalizeZ(e){return this.toAffineBatch(e).map(this.fromAffine)}equals(e){T1(e);let{x:r,y:n,z:i}=this,{x:a,y:d,z:v}=e,y=he(r*v),m=he(a*i),B=he(n*v),P=he(d*i);return y===m&&B===P}negate(){return new t(he(-this.x),this.y,this.z,he(-this.t))}double(){let{x:e,y:r,z:n}=this,{a:i}=ot,a=he,d=a(e*e),v=a(r*r),y=a(to*a(n*n)),m=a(i*d),B=e+r,P=a(a(B*B)-d-v),D=m+v,F=D-y,C=m-v,q=a(P*F),W=a(D*C),K=a(P*C),ne=a(F*D);return new t(q,W,ne,K)}add(e){let{x:r,y:n,z:i,t:a}=this;T1(e);let{x:d,y:v,z:y,t:m}=e,{a:B,d:P}=ot,D=he,F=D(r*d),C=D(n*v),q=D(a*P*m),W=D(i*y),K=D((r+n)*(d+v)-F-C),ne=D(W-q),$=D(W+q),ae=D(C-B*F),ie=D(K*ne),ee=D($*ae),ce=D(K*ae),te=D(ne*$);return new t(ie,ee,te,ce)}subtract(e){return this.add(e.negate())}precomputeWindow(e){let r=1+256/e,n=[],i=this,a=i;for(let d=0;d<r;d++){a=i,n.push(a);for(let v=1;v<2**(e-1);v++)a=a.add(i),n.push(a);i=a.double()}return n}wNAF(e,r){!r&&this.equals(t.BASE)&&(r=mt.BASE);let n=r&&r._WINDOW_SIZE||1;if(256%n)throw new Error("Point#wNAF: Invalid precomputation window, must be power of 2");let i=r&&yu.get(r);i||(i=this.precomputeWindow(n),r&&n!==1&&(i=t.normalizeZ(i),yu.set(r,i)));let a=t.ZERO,d=t.BASE,v=1+256/n,y=2**(n-1),m=BigInt(2**n-1),B=2**n,P=BigInt(n);for(let D=0;D<v;D++){let F=D*y,C=Number(e&m);e>>=P,C>y&&(C-=B,e+=ze);let q=F,W=F+Math.abs(C)-1,K=D%2!==0,ne=C<0;C===0?d=d.add(M1(K,i[q])):a=a.add(M1(ne,i[W]))}return t.normalizeZ([a,d])[0]}multiply(e,r){return this.wNAF(Ff(e,ot.l),r)}multiplyUnsafe(e){let r=Ff(e,ot.l,!1),n=t.BASE,i=t.ZERO;if(r===$t)return i;if(this.equals(i)||r===ze)return this;if(this.equals(n))return this.wNAF(r);let a=i,d=this;for(;r>$t;)r&ze&&(a=a.add(d)),d=d.double(),r>>=ze;return a}isSmallOrder(){return this.multiplyUnsafe(ot.h).equals(t.ZERO)}isTorsionFree(){let e=this.multiplyUnsafe(ot.l/to).double();return ot.l%to&&(e=e.add(this)),e.equals(t.ZERO)}toAffine(e){let{x:r,y:n,z:i}=this,a=this.equals(t.ZERO);e==null&&(e=a?b8:Df(i));let d=he(r*e),v=he(n*e),y=he(i*e);if(a)return mt.ZERO;if(y!==ze)throw new Error("invZ was invalid");return new mt(d,v)}fromRistrettoBytes(){vu()}toRistrettoBytes(){vu()}fromRistrettoHash(){vu()}};Dt.BASE=new Dt(ot.Gx,ot.Gy,ze,he(ot.Gx*ot.Gy));Dt.ZERO=new Dt($t,ze,ze,$t);function M1(t,e){let r=e.negate();return t?r:e}function T1(t){if(!(t instanceof Dt))throw new TypeError("ExtendedPoint expected")}function gu(t){if(!(t instanceof fa))throw new TypeError("RistrettoPoint expected")}function vu(){throw new Error("Legacy method: switch to RistrettoPoint")}var fa=class t{constructor(e){this.ep=e}static calcElligatorRistrettoMap(e){let{d:r}=ot,n=he(fs*e*e),i=he((n+ze)*x8),a=BigInt(-1),d=he((a-r*n)*he(n+r)),{isValid:v,value:y}=Su(i,d),m=he(y*e);_i(m)||(m=he(-m)),v||(y=m),v||(a=n);let B=he(a*(n-ze)*m8-d),P=y*y,D=he((y+y)*d),F=he(B*g8),C=he(ze-P),q=he(ze+P);return new Dt(he(D*q),he(C*F),he(F*q),he(D*C))}static hashToCurve(e){e=Bi(e,64);let r=xu(e.slice(0,32)),n=this.calcElligatorRistrettoMap(r),i=xu(e.slice(32,64)),a=this.calcElligatorRistrettoMap(i);return new t(n.add(a))}static fromHex(e){e=Bi(e,32);let{a:r,d:n}=ot,i="RistrettoPoint.fromHex: the hex is not valid encoding of RistrettoPoint",a=xu(e);if(!M8(us(a),e)||_i(a))throw new Error(i);let d=he(a*a),v=he(ze+r*d),y=he(ze-r*d),m=he(v*v),B=he(y*y),P=he(r*n*m-B),{isValid:D,value:F}=B1(he(P*B)),C=he(F*y),q=he(F*C*P),W=he((a+a)*C);_i(W)&&(W=he(-W));let K=he(v*q),ne=he(W*K);if(!D||_i(ne)||K===$t)throw new Error(i);return new t(new Dt(W,K,ze,ne))}toRawBytes(){let{x:e,y:r,z:n,t:i}=this.ep,a=he(he(n+r)*he(n-r)),d=he(e*r),v=he(d*d),{value:y}=B1(he(a*v)),m=he(y*a),B=he(y*d),P=he(m*B*i),D;if(_i(i*P)){let C=he(r*fs),q=he(e*fs);e=C,r=q,D=he(m*v8)}else D=B;_i(e*P)&&(r=he(-r));let F=he((n-r)*D);return _i(F)&&(F=he(-F)),us(F)}toHex(){return ls(this.toRawBytes())}toString(){return this.toHex()}equals(e){gu(e);let r=this.ep,n=e.ep,i=he(r.x*n.y)===he(r.y*n.x),a=he(r.y*n.y)===he(r.x*n.x);return i||a}add(e){return gu(e),new t(this.ep.add(e.ep))}subtract(e){return gu(e),new t(this.ep.subtract(e.ep))}multiply(e){return new t(this.ep.multiply(e))}multiplyUnsafe(e){return new t(this.ep.multiplyUnsafe(e))}};fa.BASE=new fa(Dt.BASE);fa.ZERO=new fa(Dt.ZERO);var yu=new WeakMap,mt=class t{constructor(e,r){this.x=e,this.y=r}_setWindowSize(e){this._WINDOW_SIZE=e,yu.delete(this)}static fromHex(e,r=!0){let{d:n,P:i}=ot;e=Bi(e,32);let a=e.slice();a[31]=e[31]&-129;let d=ds(a);if(r&&d>=i)throw new Error("Expected 0 < hex < P");if(!r&&d>=C1)throw new Error("Expected 0 < hex < 2**256");let v=he(d*d),y=he(v-ze),m=he(n*v+ze),{isValid:B,value:P}=Su(y,m);if(!B)throw new Error("Point.fromHex: invalid y coordinate");let D=(P&ze)===ze;return(e[31]&128)!==0!==D&&(P=he(-P)),new t(P,d)}static async fromPrivateKey(e){return(await Mu(e)).point}toRawBytes(){let e=us(this.y);return e[31]|=this.x&ze?128:0,e}toHex(){return ls(this.toRawBytes())}toX25519(){let{y:e}=this,r=he((ze+e)*Df(ze-e));return us(r)}isTorsionFree(){return Dt.fromAffine(this).isTorsionFree()}equals(e){return this.x===e.x&&this.y===e.y}negate(){return new t(he(-this.x),this.y)}add(e){return Dt.fromAffine(this).add(Dt.fromAffine(e)).toAffine()}subtract(e){return this.add(e.negate())}multiply(e){return Dt.fromAffine(this).multiply(e,this).toAffine()}};mt.BASE=new mt(ot.Gx,ot.Gy);mt.ZERO=new mt($t,ze);var cs=class t{constructor(e,r){this.r=e,this.s=r,this.assertValidity()}static fromHex(e){let r=Bi(e,64),n=mt.fromHex(r.slice(0,32),!1),i=ds(r.slice(32,64));return new t(n,i)}assertValidity(){let{r:e,s:r}=this;if(!(e instanceof mt))throw new Error("Expected Point instance");return Ff(r,ot.l,!1),this}toRawBytes(){let e=new Uint8Array(64);return e.set(this.r.toRawBytes()),e.set(us(this.s),32),e}toHex(){return ls(this.toRawBytes())}};function P1(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function wu(t){if(!P1(t))throw new Error("Uint8Array expected")}function E1(...t){if(t.every(wu),t.length===1)return t[0];let e=t.reduce((n,i)=>n+i.length,0),r=new Uint8Array(e);for(let n=0,i=0;n<t.length;n++){let a=t[n];r.set(a,i),i+=a.length}return r}var y8=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function ls(t){wu(t);let e="";for(let r=0;r<t.length;r++)e+=y8[t[r]];return e}var fi={_0:48,_9:57,A:65,F:70,a:97,f:102};function _1(t){if(t>=fi._0&&t<=fi._9)return t-fi._0;if(t>=fi.A&&t<=fi.F)return t-(fi.A-10);if(t>=fi.a&&t<=fi.f)return t-(fi.a-10)}function Au(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);let e=t.length,r=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let i=0,a=0;i<r;i++,a+=2){let d=_1(t.charCodeAt(a)),v=_1(t.charCodeAt(a+1));if(d===void 0||v===void 0){let y=t[a]+t[a+1];throw new Error('hex string expected, got non-hex character "'+y+'" at index '+a)}n[i]=d*16+v}return n}function L1(t){let r=t.toString(16).padStart(64,"0");return Au(r)}function us(t){return L1(t).reverse()}function _i(t){return(he(t)&ze)===ze}function ds(t){return wu(t),BigInt("0x"+ls(Uint8Array.from(t).reverse()))}var w8=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");function xu(t){return he(ds(t)&w8)}function he(t,e=ot.P){let r=t%e;return r>=$t?r:e+r}function Df(t,e=ot.P){if(t===$t||e<=$t)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let r=he(t,e),n=e,i=$t,a=ze,d=ze,v=$t;for(;r!==$t;){let m=n/r,B=n%r,P=i-d*m,D=a-v*m;n=r,r=B,i=d,a=v,d=P,v=D}if(n!==ze)throw new Error("invert: does not exist");return he(i,e)}function A8(t,e=ot.P){let r=new Array(t.length),n=t.reduce((a,d,v)=>d===$t?a:(r[v]=a,he(a*d,e)),ze),i=Df(n,e);return t.reduceRight((a,d,v)=>d===$t?a:(r[v]=he(a*r[v],e),he(a*d,e)),i),r}function Ln(t,e){let{P:r}=ot,n=t;for(;e-- >$t;)n*=n,n%=r;return n}function S8(t){let{P:e}=ot,r=BigInt(5),n=BigInt(10),i=BigInt(20),a=BigInt(40),d=BigInt(80),y=t*t%e*t%e,m=Ln(y,to)*y%e,B=Ln(m,ze)*t%e,P=Ln(B,r)*B%e,D=Ln(P,n)*P%e,F=Ln(D,i)*D%e,C=Ln(F,a)*F%e,q=Ln(C,d)*C%e,W=Ln(q,d)*C%e,K=Ln(W,n)*P%e;return{pow_p_5_8:Ln(K,to)*t%e,b2:y}}function Su(t,e){let r=he(e*e*e),n=he(r*r*e),i=S8(t*n).pow_p_5_8,a=he(t*r*i),d=he(e*a*a),v=a,y=he(a*fs),m=d===t,B=d===he(-t),P=d===he(-t*fs);return m&&(a=v),(B||P)&&(a=y),_i(a)&&(a=he(-a)),{isValid:m||B,value:a}}function B1(t){return Su(ze,t)}function Rf(t){return he(ds(t),ot.l)}function M8(t,e){if(t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(t[r]!==e[r])return!1;return!0}function Bi(t,e){let r=P1(t)?Uint8Array.from(t):Au(t);if(typeof e=="number"&&r.length!==e)throw new Error(`Expected ${e} bytes`);return r}function Ff(t,e,r=!0){if(!e)throw new TypeError("Specify max value");if(typeof t=="number"&&Number.isSafeInteger(t)&&(t=BigInt(t)),typeof t=="bigint"&&t<e){if(r){if($t<t)return t}else if($t<=t)return t}throw new TypeError("Expected valid scalar: 0 < scalar < max")}function T8(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}function E8(t){if(t=typeof t=="bigint"||typeof t=="number"?L1(Ff(t,C1)):Bi(t),t.length!==32)throw new Error("Expected 32 bytes");return t}function _8(t){let e=T8(t.slice(0,32)),r=t.slice(32,64),n=Rf(e),i=mt.BASE.multiply(n),a=i.toRawBytes();return{head:e,prefix:r,scalar:n,point:i,pointBytes:a}}var mu;async function Mu(t){return _8(await ro.sha512(E8(t)))}async function R1(t,e){t=Bi(t);let{prefix:r,scalar:n,pointBytes:i}=await Mu(e),a=Rf(await ro.sha512(r,t)),d=mt.BASE.multiply(a),v=Rf(await ro.sha512(d.toRawBytes(),i,t)),y=he(a+v*n,ot.l);return new cs(d,y).toRawBytes()}function B8(t,e,r){e=Bi(e),r instanceof mt||(r=mt.fromHex(r,!1));let{r:n,s:i}=t instanceof cs?t.assertValidity():cs.fromHex(t),a=Dt.BASE.multiplyUnsafe(i);return{r:n,s:i,SB:a,pub:r,msg:e}}function C8(t,e,r,n){let i=Rf(n),a=Dt.fromAffine(t).multiplyUnsafe(i);return Dt.fromAffine(e).add(a).subtract(r).multiplyUnsafe(ot.h).equals(Dt.ZERO)}async function Ci(t,e,r){let{r:n,SB:i,msg:a,pub:d}=B8(t,e,r),v=await ro.sha512(n.toRawBytes(),d.toRawBytes(),a);return C8(d,n,i,v)}mt.BASE._setWindowSize(8);var Ei={node:p8,web:typeof self=="object"&&"crypto"in self?self.crypto:void 0},ro={bytesToHex:ls,hexToBytes:Au,concatBytes:E1,getExtendedPublicKey:Mu,mod:he,invert:Df,TORSION_SUBGROUP:["0100000000000000000000000000000000000000000000000000000000000000","c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a","0000000000000000000000000000000000000000000000000000000000000080","26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc05","ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f","26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc85","0000000000000000000000000000000000000000000000000000000000000000","c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac03fa"],hashToPrivateScalar:t=>{if(t=Bi(t),t.length<40||t.length>1024)throw new Error("Expected 40-1024 bytes of private key as per FIPS 186");return he(ds(t),ot.l-ze)+ze},randomBytes:(t=32)=>{if(Ei.web)return Ei.web.getRandomValues(new Uint8Array(t));if(Ei.node){let{randomBytes:e}=Ei.node;return new Uint8Array(e(t).buffer)}else throw new Error("The environment doesn't have randomBytes function")},randomPrivateKey:()=>ro.randomBytes(32),sha512:async(...t)=>{let e=E1(...t);if(Ei.web){let r=await Ei.web.subtle.digest("SHA-512",e.buffer);return new Uint8Array(r)}else{if(Ei.node)return Uint8Array.from(Ei.node.createHash("sha512").update(e).digest());throw new Error("The environment doesn't have sha512 function")}},precompute(t=8,e=mt.BASE){let r=e.equals(mt.BASE)?e:new mt(e.x,e.y);return r._setWindowSize(t),r.multiply(to),r},sha512Sync:void 0};Object.defineProperties(ro,{sha512Sync:{configurable:!1,get(){return mu},set(t){mu||(mu=t)}}});var Cr=class{_key;pk;ownerLength=Je[2].pubLength;signatureLength=Je[2].sigLength;_publicKey;get publicKey(){return this._publicKey}signatureType=2;constructor(e,r){this._key=e,this.pk=r}get key(){throw new Error("You must implement `key`")}sign(e){return R1(Buffer.from(e),Buffer.from(this.key))}static async verify(e,r,n){let i=e;return typeof e=="string"&&(i=F1.default.toBuffer(e)),Ci(Buffer.from(n),Buffer.from(r),Buffer.from(i))}};var cI=A(M(),1);var CC=A(M(),1);var UB=A(M(),1);var DB=A(M(),1),$e=A(bn(),1);var j_=A(M(),1);import{createHash as U8}from"crypto";async function Pi(t){if(typeof t[Symbol.asyncIterator]=="function"){let i=t,a=U8("sha384"),d=0;for await(let m of i)d+=m.byteLength,a.update(m);let v=(0,$e.concatBuffers)([(0,$e.stringToBuffer)("blob"),(0,$e.stringToBuffer)(d.toString())]),y=(0,$e.concatBuffers)([await yt().hash(v,"SHA-384"),a.digest()]);return await yt().hash(y,"SHA-384")}else if(Array.isArray(t)){let i=(0,$e.concatBuffers)([(0,$e.stringToBuffer)("list"),(0,$e.stringToBuffer)(t.length.toString())]);return await z1(t,await yt().hash(i,"SHA-384"))}let e=t,r=(0,$e.concatBuffers)([(0,$e.stringToBuffer)("blob"),(0,$e.stringToBuffer)(e.byteLength.toString())]),n=(0,$e.concatBuffers)([await yt().hash(r,"SHA-384"),await yt().hash(e,"SHA-384")]);return await yt().hash(n,"SHA-384")}async function z1(t,e){if(t.length<1)return e;let r=(0,$e.concatBuffers)([e,await Pi(t[0])]),n=await yt().hash(r,"SHA-384");return await z1(t.slice(1),n)}var zf=A(Bu(),1),wp=A(xs(),1),Ap=A(yp(),1),g6=zf.default.default?zf.default.default:zf.default,Kf=class extends g6{getPublicKey(e){throw new Error("Unimplemented")}},v6;function yt(){return v6??=new Kf}var Sp=A(Nr(),1);import{constants as x6,createSign as m6}from"crypto";var ua=class{_key;pk;signatureType=1;ownerLength=Je[1].pubLength;signatureLength=Je[1].sigLength;_publicKey;get publicKey(){return this._publicKey}constructor(e,r){this._key=e,this.pk=r,r||(this.pk=yt().getPublicKey(JSON.parse(e)))}sign(e){return m6("sha256").update(e).sign({key:this._key,padding:x6.RSA_PKCS1_PSS_PADDING})}static async verify(e,r,n){return await yt().verify(Buffer.isBuffer(e)?Sp.default.encode(e):e,r,n)}};var hb=A(db(),1),pb=A(Nr(),1);var da=class extends ua{jwk;constructor(e){super((0,hb.jwkTopem)(e),e.n),this.jwk=e}get publicKey(){if(!this.pk)throw new Error("ArweaveSigner - pk is undefined");return pb.default.toBuffer(this.pk)}sign(e){return yt().sign(this.jwk,e)}static async verify(e,r,n){return await yt().verify(e,r,n)}};var FC=A(M(),1),bb=A(Nr(),1);var ha=class{_publicKey;ownerLength=Je[2].pubLength;signatureLength=Je[2].sigLength;signatureType=2;pem;provider;constructor(e){if(this.provider=e,!this.provider.publicKey)throw new Error("InjectedSolanaSigner - provider.publicKey is undefined");this._publicKey=this.provider.publicKey.toBuffer()}get publicKey(){return this._publicKey}async sign(e){if(!this.provider.signMessage)throw new Error("Selected Wallet does not support message signing");return await this.provider.signMessage(e)}static async verify(e,r,n){let i=e;return typeof e=="string"&&(i=bb.default.toBuffer(e)),Ci(Buffer.from(n),Buffer.from(r),Buffer.from(i))}};var HF=A(M(),1),dm=A(Ps(),1),hm=A(Ns(),1);var th=A(nt(),1),pm=A(Us(),1),bm=A(tf(),1),rh=class{signer;publicKey;ownerLength=Je[Oe.ETHEREUM].pubLength;signatureLength=Je[Oe.ETHEREUM].sigLength;signatureType=Oe.ETHEREUM;constructor(e){this.signer=e.getSigner()}async setPublicKey(){let e="sign this message to connect to Bundlr.Network",r=await this.signer.signMessage(e),n=await(0,dm.hashMessage)(e),i=(0,hm.recoverPublicKey)((0,th.arrayify)(n),r);this.publicKey=Buffer.from((0,th.arrayify)(i))}async sign(e){this.publicKey||await this.setPublicKey();let r=await this.signer.signMessage(e);return Buffer.from(r.slice(2),"hex")}static verify(e,r,n){let i=(0,pm.computeAddress)(e);return(0,bm.verifyMessage)(r,n)===i}};var jF=A(M(),1);var Qo=A(Am(),1),Ai=class extends Cr{get publicKey(){return Qo.default.decode(this.pk)}get key(){return Qo.default.decode(this._key)}constructor(e){let r=Qo.default.decode(e);super(Qo.default.encode(r.subarray(0,32)),Qo.default.encode(r.subarray(32,64)))}};var wO=A(M(),1);var xO=A(M(),1);var bO=A(M(),1),y3=A(Nr(),1),Kh=A(ph(),1);var lO=A(M(),1),h3=A(d3(),1);import{Buffer as qa}from"buffer";function zh(t){return t=p3(t),(0,h3.default)("keccak256").update(t).digest()}function p3(t){if(!qa.isBuffer(t))if(Array.isArray(t))t=qa.from(t);else if(typeof t=="string")b3(t)?t=qa.from(Uc(g3(t)),"hex"):t=qa.from(t);else if(typeof t=="number")t=x3(t);else if(typeof t=="bigint")t=DE(t);else if(t==null)t=qa.allocUnsafe(0);else throw new Error("invalid type");return t}function b3(t,e){return!(typeof t!="string"||!t.match(/^0x[0-9A-Fa-f]*$/)||e&&t.length!==2+2*e)}function Uc(t){if(typeof t!="string")throw new Error(`while padding to even, value must be string, is currently ${typeof t}, while padToEven.`);return t.length%2&&(t=`0${t}`),t}function g3(t){return typeof t!="string"?t:v3(t)?t.slice(2):t}function v3(t){if(typeof t!="string")throw new Error("value must be type 'string', is currently type "+typeof t+", while checking isHexPrefixed.");return t.startsWith("0x")}function x3(t){let e=m3(t);return qa.from(Uc(e.slice(2)),"hex")}function m3(t){return`0x${t.toString(16)}`}function DE(t){let e=t.toString(16);return qa.from(Uc(e),"hex")}typeof window<"u"&&(window.keccak256=zh);var df=zh,OE={intToBuffer:x3,intToHex:m3,isHexPrefixed:v3,stripHexPrefix:g3,padToEven:Uc,isHexString:b3,toBuffer:p3};var Ga=class{_key;ownerLength=Je[Oe.ETHEREUM].pubLength;signatureLength=Je[Oe.ETHEREUM].sigLength;signatureType=Oe.ETHEREUM;pk;constructor(e,r){this._key=e,this.pk=r.toString("hex")}get publicKey(){throw new Error("You must implement `publicKey`")}get key(){return Buffer.from(this._key,"hex")}static async verify(e,r,n){let i=e;typeof e=="string"&&(i=y3.default.toBuffer(e));let a=!1;try{a=Kh.default.ecdsaVerify(n,df(Buffer.from(r)),i)}catch{}return a}async sign(e){return Kh.default.ecdsaSign(df(Buffer.from(e)),Buffer.from(this.key)).signature}};var Zh=A(ph(),1),w3=A(Nr(),1),A3=A(nt(),1),S3=A(tf(),1),M3=A(Ps(),1),Ir=class extends Ga{get publicKey(){return Buffer.from(this.pk,"hex")}constructor(e){e.startsWith("0x")&&(e=e.slice(2));let r=Buffer.from(e,"hex"),n=Zh.default.publicKeyCreate(r,!1);super(e,Buffer.from(n))}async sign(e){return new S3.Wallet(this._key).signMessage(e).then(n=>Buffer.from(n.slice(2),"hex"))}static async verify(e,r,n){return Zh.default.ecdsaVerify(n.length===65?n.slice(0,-1):n,(0,A3.arrayify)((0,M3.hashMessage)(r)),typeof e=="string"?w3.default.toBuffer(e):e)}};var hf=class extends Ir{};var MO=A(M(),1);var pf=class extends Ai{constructor(e){super(e.replace("ed25519:",""))}};var _O=A(M(),1);var bf=class extends Cr{get publicKey(){return Buffer.from(this.pk)}get key(){return Buffer.from(this._key)}constructor(e,r){super(e.subarray(0,32),r)}};var PO=A(M(),1);var Xa=class extends ha{signatureType=4;constructor(e){super(e)}async sign(e){return super.sign(Buffer.from(Buffer.from(e).toString("hex")))}static async verify(e,r,n){return super.verify(e,Buffer.from(Buffer.from(r).toString("hex")),n)}};var FO=A(M(),1);var gf=class extends Ai{signatureType=4;constructor(e){super(e)}async sign(e){return super.sign(Buffer.from(Buffer.from(e).toString("hex")))}static async verify(e,r,n){return super.verify(e,Buffer.from(Buffer.from(r).toString("hex")),n)}};var IO=A(M(),1);var vf=class extends Cr{constructor(e,r){super(e,r)}get publicKey(){return Buffer.from(this.pk.slice(2),"hex")}get key(){return Buffer.from(this._key.slice(2),"hex")}};var UO=A(M(),1);var za=class{_publicKey;ownerLength=Je[Oe.INJECTEDAPTOS].pubLength;signatureLength=Je[Oe.INJECTEDAPTOS].sigLength;signatureType=Oe.INJECTEDAPTOS;pem;provider;constructor(e,r){this.provider=e,this._publicKey=r}get publicKey(){return this._publicKey}async sign(e){if(!this.provider.signMessage)throw new Error("Selected Wallet does not support message signing");let n=(await this.provider.signMessage({message:Buffer.from(e).toString("hex"),nonce:"bundlr"})).signature;return typeof n=="string"?Buffer.from(n,"hex"):n.data.toUint8Array()}static async verify(e,r,n){let i=e;return Ci(Buffer.from(n),Buffer.from(`APTOS
41
41
  message: ${Buffer.from(r).toString("hex")}
42
- nonce: bundlr`),Buffer.from(i))}};var XO=A(M(),1);var Ka=class{_publicKey;ownerLength=Je[Oe.MULTIAPTOS].pubLength;signatureLength=Je[Oe.MULTIAPTOS].sigLength;signatureType=Oe.MULTIAPTOS;collectSignatures;provider;constructor(e,r){this._publicKey=e,this.collectSignatures=r}get publicKey(){return this._publicKey}async sign(e){let{signatures:r,bitmap:n}=await this.collectSignatures(e),i=128,a=new Uint8Array([0,0,0,0]),d=new Set;n.forEach(m=>{if(m>=32)throw new Error(`Invalid bit value ${m}.`);if(d.has(m))throw new Error("Duplicated bits detected.");d.add(m);let B=Math.floor(m/8),P=a[B];P|=i>>m%8,a[B]=P});let v=Buffer.alloc(this.signatureLength),y=0;for(let m=0;m<32;m++)n.includes(m)&&v.set(r[y++],m*64);return v.set(a,this.signatureLength-4),v}static async verify(e,r,n){let a=Je[Oe.MULTIAPTOS].sigLength-4,d=n.slice(0,a),v=n.slice(a),y=!1;for(let m=0;m<32;m++){let B=Math.floor(m/8),P=m-B*8;if((v[B]&128>>P)!==0){let F=d.slice(m*64,(m+1)*64),C=e.slice(m*32,(m+1)*32);await Ci(Buffer.from(F),Buffer.from(r),Buffer.from(C))||(y=!0)}}return!y}};var jO=A(M(),1),Hc=A(tf(),1);var Za=class extends Ir{ownerLength=Je[Oe.TYPEDETHEREUM].pubLength;signatureLength=Je[Oe.TYPEDETHEREUM].sigLength;signatureType=Oe.TYPEDETHEREUM;address;signer;constructor(e){super(e),this.address="0x"+df(super.publicKey.slice(1)).slice(-20).toString("hex"),this.signer=new Hc.Wallet(e)}get publicKey(){return Buffer.from(this.address)}async sign(e){let r=await this.signer._signTypedData(xf,mf,{address:this.address,"Transaction hash":e});return Buffer.from(r.slice(2),"hex")}static async verify(e,r,n){let i=e.toString(),a=(0,Hc.verifyTypedData)(xf,mf,{address:i,"Transaction hash":r},n);return i.toLowerCase()===a.toLowerCase()}},xf={name:"Bundlr",version:"1"},mf={Bundlr:[{name:"Transaction hash",type:"bytes"},{name:"address",type:"address"}]};var $O=A(M(),1);var T3=A(tf(),1);var Vh=class{ownerLength=Je[Oe.TYPEDETHEREUM].pubLength;signatureLength=Je[Oe.TYPEDETHEREUM].sigLength;signatureType=Oe.TYPEDETHEREUM;address;signer;publicKey;constructor(e){this.signer=e.getSigner()}async ready(){this.address=(await this.signer.getAddress()).toString().toLowerCase(),this.publicKey=Buffer.from(this.address)}async sign(e){let r=await this.signer._signTypedData(xf,mf,{address:this.address,"Transaction hash":e});return Buffer.from(r.slice(2),"hex")}static verify(e,r,n){let i=e.toString(),a=(0,T3.verifyTypedData)(xf,mf,{address:i,"Transaction hash":r},n);return i.toLowerCase()===a.toLowerCase()}};var nI=A(M(),1);var E3=A(Nr(),1);var Va=class{signer;publicKey;ownerLength=Je[Oe.ARWEAVE].pubLength;signatureLength=Je[Oe.ARWEAVE].sigLength;signatureType=Oe.ARWEAVE;constructor(e){this.signer=e}async setPublicKey(){let e=await this.signer.getActivePublicKey();this.publicKey=E3.default.toBuffer(e)}async sign(e){this.publicKey||await this.setPublicKey();let r={name:"RSA-PSS",saltLength:32},n=await this.signer.signature(e,r);return new Uint8Array(Object.values(n).map(a=>+a))}static async verify(e,r,n){return await yt().verify(e,r,n)}};var sI=A(M(),1);var yf=class extends Ir{signatureType=Oe.KYVE};var wf={1:da,2:Cr,3:Ir,4:Xa,5:za,6:Ka,7:Za};var RI=A(M(),1);var zI=A(M(),1);async function IE(t){return Pi([(0,$e.stringToBuffer)("dataitem"),(0,$e.stringToBuffer)("1"),(0,$e.stringToBuffer)(t.signatureType.toString()),t.rawOwner,t.rawTarget,t.rawAnchor,t.rawTags,t.rawData])}var Af=IE;var xk=A(M(),1);var ZI=A(M(),1);function Sf(t,e){let r=new Uint8Array(t);if(e<0)throw new Error("Array is unsigned, cannot represent -ve numbers");if(e>2**(t*8)-1)throw new Error(`Number ${e} is too large for an array of ${t} bytes`);for(let n=0;n<r.length;n++){let i=e&255;r[n]=i,e=(e-i)/256}return r}function qc(t){return Sf(8,t)}function jh(t){return Sf(2,t)}function kE(t){return Sf(16,t)}function Gc(t){return Sf(32,t)}function bt(t){let e=0;for(let r=t.length-1;r>=0;r--)e=e*256+t[r];return e}var dk=A(M(),1),Ef=A(Nr(),1);var sk=A(M(),1);var un=A(Nr(),1);import{Buffer as Tf}from"buffer";var QI=A(M(),1);var Mf=class{buf;pos;constructor(e=Buffer.alloc(Xc),r=0){this.buf=e,this.pos=r}writeTags(e){if(!Array.isArray(e))throw new Error("input must be array");let r=e.length,n;if(r)for(this.writeLong(r),n=0;n<r;n++){let i=e[n];if(typeof i?.name!="string"||typeof i?.value!="string")throw new Error(`Invalid tag format for ${i}, expected {name:string, value: string}`);this.writeString(i.name),this.writeString(i.value)}this.writeLong(0)}toBuffer(){let e=Buffer.alloc(this.pos);if(this.pos>this.buf.length)throw new Error(`Too many tag bytes (${this.pos} > ${this.buf.length})`);return this.buf.copy(e,0,0,this.pos),e}writeLong(e){let r=this.buf,n,i;if(e>=-1073741824&&e<1073741824){i=e>=0?e<<1:~e<<1|1;do r[this.pos]=i&127,i>>=7;while(i&&(r[this.pos++]|=128))}else{n=e>=0?e*2:-e*2-1;do r[this.pos]=n&127,n/=128;while(n>=1&&(r[this.pos++]|=128))}this.pos++,this.buf=r}writeString(e){let r=Buffer.byteLength(e),n=this.buf;this.writeLong(r);let i=this.pos;if(this.pos+=r,!(this.pos>n.length)){if(r>64)this.buf.write(e,this.pos-r,r,"utf8");else{let a,d,v,y;for(a=0,d=r;a<d;a++)v=e.charCodeAt(a),v<128?n[i++]=v:v<2048?(n[i++]=v>>6|192,n[i++]=v&63|128):(v&64512)===55296&&((y=e.charCodeAt(a+1))&64512)===56320?(v=65536+((v&1023)<<10)+(y&1023),a++,n[i++]=v>>18|240,n[i++]=v>>12&63|128,n[i++]=v>>6&63|128,n[i++]=v&63|128):(n[i++]=v>>12|224,n[i++]=v>>6&63|128,n[i++]=v&63|128)}this.buf=n}}readLong(){let e=0,r=0,n=this.buf,i,a,d,v;do i=n[this.pos++],a=i&128,e|=(i&127)<<r,r+=7;while(a&&r<28);if(a){d=e,v=268435456;do i=n[this.pos++],d+=(i&127)*v,v*=128;while(i&128);return(d%2?-(d+1):d)/2}return e>>1^-(e&1)}skipLong(){let e=this.buf;for(;e[this.pos++]&128;);}readTags(){let e=[],r;for(;r=this.readLong();)for(r<0&&(r=-r,this.skipLong());r--;){let n=this.readString(),i=this.readString();e.push({name:n,value:i})}return e}readString(){let e=this.readLong(),r=this.pos,n=this.buf;if(this.pos+=e,this.pos>n.length)throw new Error("TAP Position out of range");return this.buf.slice(r,r+e).toString()}};function Qh(t){if(t?.length===0)return Buffer.allocUnsafe(0);let e=new Mf;return e.writeTags(t),e.toBuffer()}function is(t){return new Mf(t).readTags()}import{createHash as NE}from"crypto";var Kc=80,Xc=4096,zc=class t{binary;_id;constructor(e){this.binary=e}static isDataItem(e){return e.binary!==void 0}get signatureType(){let e=bt(this.binary.subarray(0,2));if(Oe?.[e]!==void 0)return e;throw new Error("Unknown signature type: "+e)}async isValid(){return t.verify(this.binary)}get id(){return un.default.encode(this.rawId)}set id(e){this._id=un.default.toBuffer(e)}get rawId(){return NE("sha256").update(this.rawSignature).digest()}set rawId(e){this._id=e}get rawSignature(){return this.binary.subarray(2,2+this.signatureLength)}get signature(){return un.default.encode(this.rawSignature)}set rawOwner(e){if(e.byteLength!=this.ownerLength)throw new Error(`Expected raw owner (pubkey) to be ${this.ownerLength} bytes, got ${e.byteLength} bytes.`);this.binary.set(e,2+this.signatureLength)}get rawOwner(){return this.binary.subarray(2+this.signatureLength,2+this.signatureLength+this.ownerLength)}get signatureLength(){return Je[this.signatureType].sigLength}get owner(){return un.default.encode(this.rawOwner)}get ownerLength(){return Je[this.signatureType].pubLength}get rawTarget(){let e=this.getTargetStart();return this.binary[e]==1?this.binary.subarray(e+1,e+33):Tf.alloc(0)}get target(){return un.default.encode(this.rawTarget)}get rawAnchor(){let e=this.getAnchorStart();return this.binary[e]==1?this.binary.subarray(e+1,e+33):Tf.alloc(0)}get anchor(){return un.default.encode(this.rawAnchor)}get rawTags(){let e=this.getTagsStart(),r=bt(this.binary.subarray(e+8,e+16));return this.binary.subarray(e+16,e+16+r)}get tags(){let e=this.getTagsStart();if(bt(this.binary.subarray(e,e+8))==0)return[];let n=bt(this.binary.subarray(e+8,e+16));return is(Tf.from(this.binary.subarray(e+16,e+16+n)))}get tagsB64Url(){return this.tags.map(r=>({name:un.default.encode(r.name),value:un.default.encode(r.value)}))}getStartOfData(){let e=this.getTagsStart(),r=this.binary.subarray(e+8,e+16),n=bt(r);return e+16+n}get rawData(){let e=this.getTagsStart(),r=this.binary.subarray(e+8,e+16),n=bt(r),i=e+16+n;return this.binary.subarray(i,this.binary.length)}get data(){return un.default.encode(this.rawData)}getRaw(){return this.binary}async sign(e){return this._id=await Zc(this,e),this.rawId}async setSignature(e){this.binary.set(e,2),this._id=Tf.from(await yt().hash(e))}isSigned(){return(this._id?.length??0)>0}toJSON(){return{signature:this.signature,owner:this.owner,target:this.target,tags:this.tags.map(e=>({name:un.default.encode(e.name),value:un.default.encode(e.value)})),data:this.data}}static async verify(e){if(e.byteLength<Kc)return!1;let r=new t(e),n=r.signatureType,i=r.getTagsStart(),a=bt(e.subarray(i,i+8)),d=e.subarray(i+8,i+16),v=bt(d);if(v>Xc)return!1;if(a>0)try{if(is(Tf.from(e.subarray(i+16,i+16+v))).length!==a)return!1}catch{return!1}let y=wf[n],m=await Af(r);return await y.verify(r.rawOwner,m,r.rawSignature)}async getSignatureData(){return Af(this)}getTagsStart(){let e=this.getTargetStart(),r=this.binary[e]==1,n=e+(r?33:1),i=this.binary[n]==1;return n+=i?33:1,n}getTargetStart(){return 2+this.signatureLength+this.ownerLength}getAnchorStart(){let e=this.getTargetStart()+1,r=this.binary[this.getTargetStart()]==1;return e+=r?32:0,e}},as=zc;import{createHash as JE}from"crypto";var ai=32,Vc=class{length;items;binary;constructor(e){this.binary=e,this.length=this.getDataItemCount(),this.items=this.getItems()}getRaw(){return this.binary}get(e){if(typeof e=="number"){if(e>=this.length)throw new RangeError("Index out of range");return this.getByIndex(e)}else return this.getById(e)}getSizes(){let e=[];for(let r=ai;r<ai+64*this.length;r+=64)e.push(bt(this.binary.subarray(r,r+32)));return e}getIds(){let e=[];for(let r=ai;r<ai+64*this.length;r+=64){let n=this.binary.subarray(r+32,r+64);if(n.length===0)throw new Error("Invalid bundle, id specified in headers doesn't exist");e.push(Ef.default.encode(n))}return e}getIdBy(e){if(e>this.length-1)throw new RangeError("Index of bundle out of range");let r=64+64*e;return Ef.default.encode(this.binary.subarray(r,r+32))}async toTransaction(e,r,n){let i=await r.createTransaction({data:this.binary,...e},n);return i.addTag("Bundle-Format","binary"),i.addTag("Bundle-Version","2.0.0"),i}async verify(){for(let e of this.items){let r=await e.isValid(),n=(0,Ef.default)(JE("sha256").update(e.rawSignature).digest());if(!(r&&e.id===n))return!1}return!0}getOffset(e){let r=0;for(let n=ai;n<ai+64*this.length;n+=64){let i=bt(this.binary.subarray(n,n+32));r+=i;let a=this.binary.subarray(n+32,n+64);if(Buffer.compare(a,e)===0)return{startOffset:r,size:i}}return{startOffset:-1,size:-1}}getByIndex(e){let r=0,n=this.getBundleStart(),i=0,a,d;for(let B=ai;B<ai+64*this.length;B+=64){if(a=bt(this.binary.subarray(B,B+32)),i++===e){d=this.binary.subarray(B+32,B+64);break}r+=a}let v=n+r,y=this.binary.subarray(v,v+a),m=new as(y);return m.rawId=d,m}getById(e){let r=Ef.default.toBuffer(e),n=this.getOffset(r);if(n.startOffset===-1)throw new Error("Transaction not found");let a=this.getBundleStart()+n.startOffset;return new as(this.binary.subarray(a,a+n.size))}getDataItemCount(){return bt(this.binary.subarray(0,32))}getBundleStart(){return 32+64*this.length}getItems(){let e=new Array(this.length),r=0,n=this.getBundleStart(),i=0;for(let a=ai;a<ai+64*this.length;a+=64){let d=bt(this.binary.subarray(a,a+32)),v=this.binary.subarray(a+32,a+64);if(v.length===0)throw new Error("Invalid bundle, id specified in headers doesn't exist");let y=n+r,m=this.binary.subarray(y,y+d);r+=d;let B=new as(m);B.rawId=v,e[i]=B,i++}return e}},Wh=Vc;function UE(t){return new Wh(t)}async function HE(t,e){let r=new Uint8Array(64*t.length),n=await Promise.all(t.map(async(a,d)=>{let v=a.isSigned()?a.rawId:await Zc(a,e),y=new Uint8Array(64);return y.set(Gc(a.getRaw().byteLength),0),y.set(v,32),r.set(y,64*d),a.getRaw()})).then(a=>Buffer.concat(a)),i=Buffer.concat([Buffer.from(Gc(t.length)),Buffer.from(r),n]);return new Wh(i)}async function _3(t,e){let r=await Af(t),n=await e.sign(r),i=await yt().hash(n);return{signature:Buffer.from(n),id:Buffer.from(i)}}async function Zc(t,e){let{signature:r,id:n}=await _3(t,e);return t.getRaw().set(r,2),n}var Sk=A(M(),1),B3=A(Nr(),1);function _f(t,e,r){let n=e.publicKey,i=r?.target?B3.default.toBuffer(r.target):null,a=1+(i?.byteLength??0),d=r?.anchor?Buffer.from(r.anchor):null,v=1+(d?.byteLength??0),y=(r?.tags?.length??0)>0?Qh(r?.tags):null,m=16+(y?y.byteLength:0),B=Buffer.from(t),P=B.byteLength,D=2+e.signatureLength+e.ownerLength+a+v+m+P,F=Buffer.alloc(D);if(F.set(jh(e.signatureType),0),F.set(new Uint8Array(e.signatureLength).fill(0),2),n.byteLength!==e.ownerLength)throw new Error(`Owner must be ${e.ownerLength} bytes, but was incorrectly ${n.byteLength}`);F.set(n,2+e.signatureLength);let C=2+e.signatureLength+e.ownerLength;if(F[C]=i?1:0,i){if(i.byteLength!==32)throw new Error(`Target must be 32 bytes but was incorrectly ${i.byteLength}`);F.set(i,C+1)}let q=C+a,W=q+1;if(F[q]=d?1:0,d){if(W+=d.byteLength,d.byteLength!==32)throw new Error("Anchor must be 32 bytes");F.set(d,q+1)}F.set(qc(r?.tags?.length??0),W);let K=qc(y?.byteLength??0);F.set(K,W+8),y&&F.set(y,W+16);let ne=W+m;return F.set(B,ne),new as(F)}var Mk=A(M(),1);var Ek=A(M(),1),Yh=class{signatureType;rawSignature;signature;signatureLength;rawOwner;owner;ownerLength;rawTarget;target;rawAnchor;anchor;rawTags;tags;rawData;data;static async verify(...e){throw new Error("You must implement `verify`")}};var Bk=A(M(),1);var Ck=A(M(),1);var e1={};i1(e1,{default:()=>KE,processStream:()=>C3,streamExportForTesting:()=>ZE,streamSigner:()=>zE});var eN=A(M(),1);import{PassThrough as qE,Transform as GE}from"stream";var ja=A(Nr(),1);import{createHash as XE}from"crypto";async function C3(t){let e=P3(t),r=(await e.next()).value;r=await Sr(e,r,32);let n=bt(r.subarray(0,32));r=r.subarray(32);let i=64*n;r=await Sr(e,r,i);let a=new Array(n);for(let y=0;y<i;y+=64)a[y/64]=[bt(r.subarray(y,y+32)),(0,ja.default)(Buffer.from(r.subarray(y+32,y+64)))];r=r.subarray(i);let d=32+i,v=[];for(let[y,m]of a){r=await Sr(e,r,Kc),r=await Sr(e,r,2);let B=bt(r.subarray(0,2));r=r.subarray(2);let{sigLength:P,pubLength:D,sigName:F}=Je[B];r=await Sr(e,r,P);let C=r.subarray(0,P);r=r.subarray(P),r=await Sr(e,r,D);let q=r.subarray(0,D);r=r.subarray(D),r=await Sr(e,r,1);let W=r[0]===1;W&&(r=await Sr(e,r,33));let K=W?r.subarray(1,33):Buffer.allocUnsafe(0);r=r.subarray(W?33:1),r=await Sr(e,r,1);let ne=r[0]===1;ne&&(r=await Sr(e,r,33));let $=ne?r.subarray(1,33):Buffer.allocUnsafe(0);r=r.subarray(ne?33:1),r=await Sr(e,r,8);let ae=bt(r.subarray(0,8));r=r.subarray(8),r=await Sr(e,r,8);let ie=bt(r.subarray(0,8));r=r.subarray(8),r=await Sr(e,r,ie);let ee=r.subarray(0,ie),ce=ae!==0&&ie!==0?is(Buffer.from(ee)):[];if(ce.length!==ae)throw new Error("Tags lengths don't match");r=r.subarray(ie);let te=new GE;te._transform=function(l,f,c){this.push(l),c()};let Y=Pi([(0,$e.stringToBuffer)("dataitem"),(0,$e.stringToBuffer)("1"),(0,$e.stringToBuffer)(B.toString()),q,K,$,ee,te]),S=2+P+D+(W?33:1)+(ne?33:1)+16+ie,s=y-S;if(r.byteLength>s)te.write(r.subarray(0,s)),r=r.subarray(s);else{let l=r.byteLength;for(te.write(r);s>l;){if(r=(await e.next()).value,!r)throw new Error(`Not enough data bytes expected: ${s} received: ${l}`);l+=r.byteLength,l>s?te.write(r.subarray(0,r.byteLength-(l-s))):te.write(r)}r=r.subarray(r.byteLength-(l-s))}if(te.end(),m!==(0,ja.default)(XE("sha256").update(C).digest()))throw new Error("ID doesn't match signature");if(!await wf[B].verify(q,await Y,C))throw new Error("Invalid signature");v.push({id:m,sigName:F,signature:(0,ja.default)(Buffer.from(C)),target:(0,ja.default)(Buffer.from(K)),anchor:(0,ja.default)(Buffer.from($)),owner:(0,ja.default)(Buffer.from(q)),tags:ce,dataOffset:d+S,dataSize:s}),d+=S+s}return v}async function zE(t,e,r,n){let i=_f("",r,n),a=new qE,d=[(0,$e.stringToBuffer)("dataitem"),(0,$e.stringToBuffer)("1"),(0,$e.stringToBuffer)(i.signatureType.toString()),i.rawOwner,i.rawTarget,i.rawAnchor,i.rawTags,t],v=await Pi(d),y=Buffer.from(await r.sign(v));return i.setSignature(y),a.write(i.getRaw()),e.pipe(a)}async function Sr(t,e,r){if(e.byteLength>=r)return e;let{done:n,value:i}=await t.next();if(n&&!i)throw new Error("Invalid buffer");return Sr(t,Buffer.concat([Buffer.from(e),Buffer.from(i)]),r)}async function*P3(t){for await(let e of t)yield e}var KE=C3,ZE={readBytes:Sr,getReader:P3};var VE={...$h,stream:e1};globalThis.arbundles??=VE;function Qa(t){return async e=>{if(hn(e))return e;if(!t.arweave)throw new Error("Must initialize with Arweave in order to create transactions");try{return await jE(t,{data:e})}catch(r){throw new Error(r.message??"Error resolving transaction")}}}async function jE(t,e){let r=null,n=null,i=null;if(typeof e.data=="string"&&(r=Buffer.from(d1(e.data),"base64"),n=l1(e.data),i=h1(r)),e.data instanceof File&&(r=new Uint8Array(await e.data.arrayBuffer()),n=e.data.type,i=e.data.size),r&&n&&i)if(i<Number(su.dispatchUploadSize))try{let a=await t.arweave.createTransaction({data:r},"use_wallet");return a.addTag(We.keys.contentType,n),e.tags&&e.tags.length>0&&e.tags.forEach(v=>a.addTag(v.name,v.value)),(await global.window.arweaveWallet.dispatch(a)).id}catch(a){throw new Error(a.message??"Error dispatching transaction")}else try{let a=await QE(e.data,{tags:[{name:"Content-Type",value:n},{name:"App-Name",value:"@permaweb/libs"}]},{apiUrl:su.node1,token:"arweave",chunkSize:5242880,batchSize:3});return console.log(a),console.log("Uploaded dataItem ID:",a.id),a.id}catch(a){throw new Error(a.message??"Error uploading transaction")}else throw new Error("Error preparing transaction data")}async function QE(t,e,r){let{apiUrl:n,token:i,chunkSize:a,batchSize:d=3}=r,v=new Va(window.arweaveWallet),y=await v.signer.getActivePublicKey();v.publicKey=Buffer.from(y,"base64");let m=new Uint8Array(await t.arrayBuffer()),B=_f(m,v,{...e,anchor:e.anchor||(()=>{let S=new Uint8Array(32);return crypto.getRandomValues(S),btoa(String.fromCharCode(...S)).replace(/\+/g,"-").replace(/\//g,"_").slice(0,32)})()});await B.sign(v);let P=B.getRaw(),D=new Blob([P],{type:"application/octet-stream"}),F={"x-chunking-version":"2"},C=await fetch(`${n}/chunks/${i}/-1/-1`,{headers:F});if(!C.ok)throw new Error(`Failed to get upload ID: ${C.status} ${await C.text()}`);let q=await C.json(),W=q.id;if(a<q.min||a>q.max)throw new Error(`Configured chunkSize ${a} is out of allowed range ${q.min}-${q.max}`);let K=D.size,ne=[];for(let S=0;S<K;S+=a)ne.push(S);let $=new Set;(q.chunks??[]).forEach(([S])=>$.add(Number(S)));let ae=ne.filter(S=>S>0&&!$.has(S)),ie=$.has(0)?[]:[0],ee=ae.concat(ie),ce=S=>new Promise(s=>setTimeout(s,S));for(let S=0;S<ee.length;S+=d){let s=ee.slice(S,S+d);await Promise.all(s.map(async u=>{let f=await D.slice(u,u+a).arrayBuffer(),c=null;for(let g=1;g<=3;g++)try{let x=await fetch(`${n}/chunks/${i}/${W}/${u}`,{method:"POST",headers:{"Content-Type":"application/octet-stream",...F},body:f});if(!x.ok){let h=await x.text();throw x.status===402?new Error(`402 payment required: ${h}`):new Error(`Chunk upload error ${x.status}: ${h}`)}return}catch(x){if(c=x,g<3){await ce(1e3*g);continue}}throw c}))}let te={"Content-Type":"application/octet-stream",...F},Y=await fetch(`${n}/chunks/${i}/${W}/-1`,{method:"POST",headers:te});if(!Y.ok){let S=await Y.text();throw new Error(`Finalizing upload failed ${Y.status}: ${S}`)}return Y.json()}var bN=A(M(),1);var YE={},pN=A(M(),1);var $N=A(M(),1);var EN=A(M(),1);function jc(t){return async(e,r)=>{let n=t_(e);if(n)throw new Error(n);let i=u1[e.contentType]?.serialize(e.data)??e.data,a=e_(e);try{return await sa(t,{tags:a,data:i},r?v=>r(v):void 0)}catch(d){throw new Error(d.message??"Error creating asset")}}}async function t1(t,e,r){try{let n=Cn(await oa(t,{processId:e,path:"asset",fallbackAction:"Info"}));if(r?.useGateway){let i=await kr({gateway:Mr.goldsky,ids:[e],tags:null,owners:null,cursor:null});return{...i?.data?.[0]?Qc(i.data[0]):{},...n}}return{id:e,...n}}catch(n){throw new Error(n.message||"Error fetching atomic asset")}}function L3(t){return async(e,r)=>await t1(t,e,r)}async function R3(t){try{let e=await kr({gateway:Mr.arweave,ids:t??null,tags:null,owners:null,cursor:null});return e&&e.data.length?e.data.map(r=>Qc(r)):null}catch(e){throw new Error(e)}}function Qc(t){let e={id:t.node.id,owner:t.node.owner.address};for(let r of t.node.tags){let n=r.name,a=(n.startsWith(`${We.keys.bootloader}-`)?n.slice(`${We.keys.bootloader}-`.length):n).split("-").map((v,y)=>y===0?v.toLowerCase():v.charAt(0).toUpperCase()+v.slice(1).toLowerCase()).join(""),d;try{d=JSON.parse(r.value)}catch{d=r.value.toString()}e[a]=d}return e}function e_(t){let e=[{name:We.keys.onBoot,value:t.src??xt.src.asset},{name:We.keys.creator,value:t.creator},{name:We.keys.assetType,value:t.assetType},{name:We.keys.contentType,value:t.contentType},{name:We.keys.implements,value:"ANS-110"},{name:We.keys.dateCreated,value:new Date().getTime().toString()},yr("Name",t.name),yr("Description",t.description),yr("Topics",JSON.stringify(t.topics)),yr("Ticker","ATOMIC"),yr("Denomination",t.denomination?.toString()??"1"),yr("TotalSupply",t.supply?.toString()??"1"),yr("Transferable",t.transferable?.toString()??"true"),yr("Creator",t.creator)];if(t.metadata)for(let r in t.metadata)e.push(yr(Ya(r),t.metadata[r].toString()));if(t.users)for(let r of t.users)e.push({name:"Auth-User",value:r});return t.tags&&t.tags.forEach(r=>e.push(r)),e}function t_(t){if(typeof t!="object"||t===null)return"The provided arguments are invalid or empty.";let e=["name","description","topics","creator","data","contentType","assetType"];for(let r of e)if(!(r in t))return`Missing field '${r}'`;return typeof t.name!="string"||t.name.trim()===""?"Name is required":typeof t.description!="string"?"The description must be a valid string":!Array.isArray(t.topics)||t.topics.length===0?"Topics are required":typeof t.creator!="string"||t.creator.trim()===""?"Creator is required":t.data===void 0||t.data===null?"Data field is required":typeof t.contentType!="string"||t.contentType.trim()===""?"Content type must be a non-empty string":typeof t.assetType!="string"||t.assetType.trim()===""?"Type must be a non-empty string":"supply"in t&&(typeof t.supply!="number"||t.supply<=0)?"Supply must be a positive number":"denomination"in t&&(typeof t.denomination!="number"||t.denomination<=0)?"Denomination must be a positive number":"transferable"in t&&typeof t.transferable!="boolean"?"Transferable must be a boolean value":"metadata"in t&&typeof t.metadata!="object"?"Metadata must be an object":"tags"in t&&(!Array.isArray(t.tags)||t.tags.some(r=>typeof r!="object"))?"Tags must be an array of objects":"src"in t&&typeof t.src!="string"?"Source must be a valid string":null}var FN=A(M(),1);var r_="eXCtpVbcd_jZ0dmU2PZ8focaKxBGECBQ8wMib7sIVPo",r1="lJovHqM9hwNjHV5JoY9NGWtt0WD-5D4gOqNL2VWW5jk";function F3(t){return async(e,r)=>{if(!t.signer)throw new Error("No signer provided");let n=Qa(t),i=new Date().getTime().toString(),a=[{name:We.keys.creator,value:e.creator},{name:We.keys.ans110.title,value:os(e.title)},{name:We.keys.name,value:os(e.title)},{name:We.keys.ans110.description,value:os(e.description)}],d=null,v=null;try{d=e.banner?await n(e.thumbnail):r1,v=e.banner?await n(e.banner):r_,e.thumbnail&&a.push({name:We.keys.thumbnail,value:d}),e.banner&&a.push({name:We.keys.banner,value:v})}catch(B){console.error(B)}let y=await fetch($a(xt.src.collection));if(!y.ok)throw new Error("Unable to fetch process src");let m=await y.text();m=m.replace(/'<NAME>'/g,fu(e.title)),m=m.replace(/'<DESCRIPTION>'/g,fu(e.description)),m=m.replace(/<CREATOR>/g,e.creator),m=m.replace(/<THUMBNAIL>/g,d||r1),m=m.replace(/<BANNER>/g,v||r1),m=m.replace(/<DATECREATED>/g,i),m=m.replace(/<LASTUPDATE>/g,i);try{let B=await sa(t,{tags:a},r?P=>r(P):void 0);if(pn("Sending eval message to collection..."),r&&r("Sending eval message to collection..."),await t.ao.message({process:B,signer:t.signer,tags:[{name:"Action",value:"Eval"}],data:m}),!e.skipRegistry){pn("Sending collection to registry..."),r&&r("Sending collection to registry...");let P=[{name:"Action",value:"Add-Collection"},{name:"CollectionId",value:B},{name:"Name",value:os(e.title)},{name:"Creator",value:e.creator},{name:"DateCreated",value:i}];v&&P.push({name:"Banner",value:v}),d&&P.push({name:"Thumbnail",value:d}),await t.ao.message({process:xt.collectionRegistry,signer:t.signer,tags:P})}if(!e.skipActivity){pn("Creating collection activity process..."),r&&r("Creating collection activity process...");let P=[{name:"CollectionId",value:B},{name:"DateCreated",value:i},{name:"UCM-Process",value:"Collection-Activity"},{name:"On-Boot",value:xt.src.collectionActivity}],D=await sa(t,{tags:P},r?F=>r(F):void 0);pn("Adding activity to collection process..."),r&&r("Adding activity to collection process..."),await t.ao.message({process:B,signer:t.signer,tags:[{name:"Action",value:"Eval"}],data:`ActivityProcess = '${D}'`})}return B}catch(B){throw new Error(B.message??"Error creating collection")}}}function D3(t){return async e=>await Pn(t,{processId:e.creator,action:"Run-Action",tags:[{name:"ForwardTo",value:e.collectionId},{name:"ForwardAction",value:"Update-Assets"}],data:{Target:e.collectionId,Action:"Update-Assets",Input:{AssetIds:e.assetIds,UpdateType:e.updateType}}})}function O3(t){return async e=>{let r=await oa(t,{processId:e,path:"collection",fallbackAction:"Info"});return r?Cn(r):null}}function I3(t){return async e=>{let r=e.creator?"Get-Collections-By-User":"Get-Collections",n=await Pf(t,{processId:xt.collectionRegistry,action:r,tags:e.creator?[{name:"Creator",value:e.creator}]:null});return n&&n.Collections&&n.Collections.length?n.Collections.map(a=>({id:a.Id,title:a.Name.replace(/\[|\]/g,""),description:a.Description,creator:a.Creator,dateCreated:a.DateCreated,banner:a.Banner,thumbnail:a.Thumbnail})):null}}var JN=A(M(),1);function k3(t){let e=jc(t);return async(r,n)=>{let i=r.tags?r.tags:[];i.push({name:"Data-Source",value:r.parentId}),i.push({name:"Root-Source",value:r.rootId??r.parentId});let a={name:`Comment on ${r.parentId}`,description:`Comment on ${r.parentId}`,topics:["comment"],creator:r.creator,data:r.content,contentType:"text/plain",assetType:"comment",tags:i};return e(a,n)}}function N3(t){return async e=>{try{let r=await t1(t,e,{useGateway:!0}),n=r?.dataSource,i=r?.rootSource;if(!n||!i)throw new Error("dataSource and rootSource must be present on a comment");return{content:await U3(e),parentId:n,rootId:i}}catch(r){throw new Error(r.message??"Error getting comment")}}}function J3(t){return async e=>{if(!e.parentId&&!e.rootId)throw new Error("Must provide either parentId or rootId");let r=[];e.parentId&&r.push({name:"Data-Source",values:[e.parentId??""]}),e.rootId&&r.push({name:"Root-Source",values:[e.rootId??""]});let n=await kr({gateway:Mr.goldsky,ids:null,tags:r,owners:null,cursor:null}),i=[];n&&n.data.length&&(i=n.data.map(d=>Qc(d)));let a=[];for(let d of i){let v=d?.dataSource,y=d?.rootSource;if(!v||!y)throw new Error("dataSource and rootSource must be present on a comment");a.push({id:d.id,content:await U3(d.id),parentId:v,rootId:y})}return a}}async function U3(t){try{return await(await fetch($a(t))).text()}catch(e){throw new Error(e.message??"Error getting comment data")}}var YN=A(M(),1);var zN=A(M(),1);function Wc(t){return async(e,r)=>{try{let n=[{name:We.keys.onBoot,value:xt.src.zone.id}];return e.tags&&e.tags.length&&e.tags.forEach(a=>n.push(a)),await sa(t,{data:e.data,tags:n},r?a=>r(a):void 0)}catch(n){throw new Error(n.message??"Error creating zone")}}}function Yc(t){return async(e,r)=>{try{let n=Object.entries(e).map(([a,d])=>({key:a,value:d}));return await Pn(t,{processId:r,action:"Zone-Update",data:n})}catch(n){throw new Error(n)}}}function H3(t){return async(e,r)=>{try{return await Pn(t,{processId:r,action:"Zone-Append",tags:[{name:"Path",value:e.path}],data:e.data})}catch(n){throw new Error(n)}}}function q3(t){return async(e,r)=>{if(!hn(r))throw new Error("Invalid zone address");let i=[];for(let a of e){if(!hn(a.granteeId))throw new Error("Invalid granteeId address");if(a.type!=="wallet"&&a.type!=="process")throw new Error("Invalid role type");i.push({Id:a.granteeId,Roles:a.roles,Type:a.type,SendInvite:a.sendInvite})}try{return await Pn(t,{processId:r,action:"Role-Set",tags:[],data:i})}catch(a){throw new Error(a)}}}function G3(t){return async(e,r)=>{if(!(hn(r)&&hn(e.zoneToJoinId)))throw new Error("Invalid zone address");let i=[{name:"ZoneId",value:e.zoneToJoinId}];e.path&&i.push({name:"Path",value:e.path});try{return await Pn(t,{processId:r,action:"Zone-Join",tags:i})}catch(a){throw new Error(a)}}}function $c(t){return async e=>{try{return pn(`Updating zone to version ${xt.src.zone.version} with source ${xt.src.zone.id}`),await ss(t,{processId:e.zoneId,evalTxId:xt.src.zone.id}),await ss(t,{processId:e.zoneId,evalSrc:`Zone.Version = '${xt.src.zone.version}'; SyncState()`})}catch(r){throw new Error(r)}}}function eu(t){return async e=>{try{let r=await oa(t,{processId:e,path:"zone",fallbackAction:"Info"});return Cn(r)}catch(r){throw new Error(r.message??"Error getting zone")}}}function X3(t){let e=Wc(t),r=Qa(t);return async(n,i)=>{let a=null,d=[{name:We.keys.dataProtocol,value:We.values.zone},{name:We.keys.zoneType,value:We.values.user}],v=async y=>{let m=y.toLowerCase();if(n[m])try{let B=await r(n[m]);d.push(yr(y,B))}catch(B){i?i(`Failed to resolve ${y}: ${B.message}`):console.error(B)}};n.username&&d.push(yr("Username",n.username)),n.displayName&&d.push(yr("DisplayName",n.displayName)),n.description&&d.push(yr("Description",n.description)),await Promise.all([v("Thumbnail"),v("Banner")]);try{a=await e({tags:d},i)}catch(y){throw new Error(y.message??"Error creating profile")}return a}}function z3(t){let e=Yc(t),r=Qa(t);return async(n,i,a)=>{if(i){let d={Username:n.username,DisplayName:n.displayName,Description:n.description};if(n.thumbnail)try{d.Thumbnail=await r(n.thumbnail)}catch(v){a&&a(`Failed to resolve thumbnail: ${v.message}`)}if(n.banner)try{d.Banner=await r(n.banner)}catch(v){a&&a(`Failed to resolve banner: ${v.message}`)}try{return await e(d,i)}catch(v){throw new Error(v.message??"Error creating profile")}}else throw new Error("No profile provided")}}function K3(t){let e=$c(t);return async r=>{try{return await e({zoneId:r.profileId})}catch(n){throw new Error(n)}}}function n1(t){let e=eu(t);return async r=>{try{let n=await e(r);if(!n)throw new Error("Error fetching profile - Not found");return{id:r,owner:n.owner,assets:n.assets,roles:n.roles,invites:n.invites,version:n.version,...n.store}}catch(n){throw new Error(n.message??"Error fetching profile")}}}function Z3(t){let e=n1(t);return async r=>{try{let n=await kr({gateway:Mr.goldsky,tags:[{name:We.keys.dataProtocol,values:[We.values.zone]},{name:We.keys.zoneType,values:[We.values.user]}],owners:[r]});return n?.data?.length>0?(n.data.sort((i,a)=>{let d=i.node.block?.timestamp??0;return(a.node.block?.timestamp??0)-d}),await e(n.data[0].node.id)):{id:null}}catch(n){throw new Error(n.message??"Error fetching profile")}}}var aJ=xt.src.zone.version;function i_(t){return{createZone:Wc(t),updateZone:Yc(t),addToZone:H3(t),getZone:eu(t),setZoneRoles:q3(t),joinZone:G3(t),updateZoneVersion:$c(t),createProfile:X3(t),updateProfile:z3(t),updateProfileVersion:K3(t),getProfileById:n1(t),getProfileByWalletAddress:Z3(t),createAtomicAsset:jc(t),getAtomicAsset:L3(t),getAtomicAssets:R3,createComment:k3(t),getComment:N3(t),getComments:J3(t),createCollection:F3(t),updateCollectionAssets:D3(t),getCollection:O3(t),getCollections:I3(t),resolveTransaction:Qa(t),getGQLData:kr,getAggregatedGQLData:p1,createProcess:m1(t),readProcess:x1(t),readState:v1(t),sendMessage:g1(t),mapFromProcessCase:Cn,mapToProcessCase:Ya}}var oJ={init:i_};export{aJ as CurrentZoneVersion,YE as Types,oJ as default};
42
+ nonce: bundlr`),Buffer.from(i))}};var XO=A(M(),1);var Ka=class{_publicKey;ownerLength=Je[Oe.MULTIAPTOS].pubLength;signatureLength=Je[Oe.MULTIAPTOS].sigLength;signatureType=Oe.MULTIAPTOS;collectSignatures;provider;constructor(e,r){this._publicKey=e,this.collectSignatures=r}get publicKey(){return this._publicKey}async sign(e){let{signatures:r,bitmap:n}=await this.collectSignatures(e),i=128,a=new Uint8Array([0,0,0,0]),d=new Set;n.forEach(m=>{if(m>=32)throw new Error(`Invalid bit value ${m}.`);if(d.has(m))throw new Error("Duplicated bits detected.");d.add(m);let B=Math.floor(m/8),P=a[B];P|=i>>m%8,a[B]=P});let v=Buffer.alloc(this.signatureLength),y=0;for(let m=0;m<32;m++)n.includes(m)&&v.set(r[y++],m*64);return v.set(a,this.signatureLength-4),v}static async verify(e,r,n){let a=Je[Oe.MULTIAPTOS].sigLength-4,d=n.slice(0,a),v=n.slice(a),y=!1;for(let m=0;m<32;m++){let B=Math.floor(m/8),P=m-B*8;if((v[B]&128>>P)!==0){let F=d.slice(m*64,(m+1)*64),C=e.slice(m*32,(m+1)*32);await Ci(Buffer.from(F),Buffer.from(r),Buffer.from(C))||(y=!0)}}return!y}};var jO=A(M(),1),Hc=A(tf(),1);var Za=class extends Ir{ownerLength=Je[Oe.TYPEDETHEREUM].pubLength;signatureLength=Je[Oe.TYPEDETHEREUM].sigLength;signatureType=Oe.TYPEDETHEREUM;address;signer;constructor(e){super(e),this.address="0x"+df(super.publicKey.slice(1)).slice(-20).toString("hex"),this.signer=new Hc.Wallet(e)}get publicKey(){return Buffer.from(this.address)}async sign(e){let r=await this.signer._signTypedData(xf,mf,{address:this.address,"Transaction hash":e});return Buffer.from(r.slice(2),"hex")}static async verify(e,r,n){let i=e.toString(),a=(0,Hc.verifyTypedData)(xf,mf,{address:i,"Transaction hash":r},n);return i.toLowerCase()===a.toLowerCase()}},xf={name:"Bundlr",version:"1"},mf={Bundlr:[{name:"Transaction hash",type:"bytes"},{name:"address",type:"address"}]};var $O=A(M(),1);var T3=A(tf(),1);var Vh=class{ownerLength=Je[Oe.TYPEDETHEREUM].pubLength;signatureLength=Je[Oe.TYPEDETHEREUM].sigLength;signatureType=Oe.TYPEDETHEREUM;address;signer;publicKey;constructor(e){this.signer=e.getSigner()}async ready(){this.address=(await this.signer.getAddress()).toString().toLowerCase(),this.publicKey=Buffer.from(this.address)}async sign(e){let r=await this.signer._signTypedData(xf,mf,{address:this.address,"Transaction hash":e});return Buffer.from(r.slice(2),"hex")}static verify(e,r,n){let i=e.toString(),a=(0,T3.verifyTypedData)(xf,mf,{address:i,"Transaction hash":r},n);return i.toLowerCase()===a.toLowerCase()}};var nI=A(M(),1);var E3=A(Nr(),1);var Va=class{signer;publicKey;ownerLength=Je[Oe.ARWEAVE].pubLength;signatureLength=Je[Oe.ARWEAVE].sigLength;signatureType=Oe.ARWEAVE;constructor(e){this.signer=e}async setPublicKey(){let e=await this.signer.getActivePublicKey();this.publicKey=E3.default.toBuffer(e)}async sign(e){this.publicKey||await this.setPublicKey();let r={name:"RSA-PSS",saltLength:32},n=await this.signer.signature(e,r);return new Uint8Array(Object.values(n).map(a=>+a))}static async verify(e,r,n){return await yt().verify(e,r,n)}};var sI=A(M(),1);var yf=class extends Ir{signatureType=Oe.KYVE};var wf={1:da,2:Cr,3:Ir,4:Xa,5:za,6:Ka,7:Za};var RI=A(M(),1);var zI=A(M(),1);async function IE(t){return Pi([(0,$e.stringToBuffer)("dataitem"),(0,$e.stringToBuffer)("1"),(0,$e.stringToBuffer)(t.signatureType.toString()),t.rawOwner,t.rawTarget,t.rawAnchor,t.rawTags,t.rawData])}var Af=IE;var xk=A(M(),1);var ZI=A(M(),1);function Sf(t,e){let r=new Uint8Array(t);if(e<0)throw new Error("Array is unsigned, cannot represent -ve numbers");if(e>2**(t*8)-1)throw new Error(`Number ${e} is too large for an array of ${t} bytes`);for(let n=0;n<r.length;n++){let i=e&255;r[n]=i,e=(e-i)/256}return r}function qc(t){return Sf(8,t)}function jh(t){return Sf(2,t)}function kE(t){return Sf(16,t)}function Gc(t){return Sf(32,t)}function bt(t){let e=0;for(let r=t.length-1;r>=0;r--)e=e*256+t[r];return e}var dk=A(M(),1),Ef=A(Nr(),1);var sk=A(M(),1);var un=A(Nr(),1);import{Buffer as Tf}from"buffer";var QI=A(M(),1);var Mf=class{buf;pos;constructor(e=Buffer.alloc(Xc),r=0){this.buf=e,this.pos=r}writeTags(e){if(!Array.isArray(e))throw new Error("input must be array");let r=e.length,n;if(r)for(this.writeLong(r),n=0;n<r;n++){let i=e[n];if(typeof i?.name!="string"||typeof i?.value!="string")throw new Error(`Invalid tag format for ${i}, expected {name:string, value: string}`);this.writeString(i.name),this.writeString(i.value)}this.writeLong(0)}toBuffer(){let e=Buffer.alloc(this.pos);if(this.pos>this.buf.length)throw new Error(`Too many tag bytes (${this.pos} > ${this.buf.length})`);return this.buf.copy(e,0,0,this.pos),e}writeLong(e){let r=this.buf,n,i;if(e>=-1073741824&&e<1073741824){i=e>=0?e<<1:~e<<1|1;do r[this.pos]=i&127,i>>=7;while(i&&(r[this.pos++]|=128))}else{n=e>=0?e*2:-e*2-1;do r[this.pos]=n&127,n/=128;while(n>=1&&(r[this.pos++]|=128))}this.pos++,this.buf=r}writeString(e){let r=Buffer.byteLength(e),n=this.buf;this.writeLong(r);let i=this.pos;if(this.pos+=r,!(this.pos>n.length)){if(r>64)this.buf.write(e,this.pos-r,r,"utf8");else{let a,d,v,y;for(a=0,d=r;a<d;a++)v=e.charCodeAt(a),v<128?n[i++]=v:v<2048?(n[i++]=v>>6|192,n[i++]=v&63|128):(v&64512)===55296&&((y=e.charCodeAt(a+1))&64512)===56320?(v=65536+((v&1023)<<10)+(y&1023),a++,n[i++]=v>>18|240,n[i++]=v>>12&63|128,n[i++]=v>>6&63|128,n[i++]=v&63|128):(n[i++]=v>>12|224,n[i++]=v>>6&63|128,n[i++]=v&63|128)}this.buf=n}}readLong(){let e=0,r=0,n=this.buf,i,a,d,v;do i=n[this.pos++],a=i&128,e|=(i&127)<<r,r+=7;while(a&&r<28);if(a){d=e,v=268435456;do i=n[this.pos++],d+=(i&127)*v,v*=128;while(i&128);return(d%2?-(d+1):d)/2}return e>>1^-(e&1)}skipLong(){let e=this.buf;for(;e[this.pos++]&128;);}readTags(){let e=[],r;for(;r=this.readLong();)for(r<0&&(r=-r,this.skipLong());r--;){let n=this.readString(),i=this.readString();e.push({name:n,value:i})}return e}readString(){let e=this.readLong(),r=this.pos,n=this.buf;if(this.pos+=e,this.pos>n.length)throw new Error("TAP Position out of range");return this.buf.slice(r,r+e).toString()}};function Qh(t){if(t?.length===0)return Buffer.allocUnsafe(0);let e=new Mf;return e.writeTags(t),e.toBuffer()}function is(t){return new Mf(t).readTags()}import{createHash as NE}from"crypto";var Kc=80,Xc=4096,zc=class t{binary;_id;constructor(e){this.binary=e}static isDataItem(e){return e.binary!==void 0}get signatureType(){let e=bt(this.binary.subarray(0,2));if(Oe?.[e]!==void 0)return e;throw new Error("Unknown signature type: "+e)}async isValid(){return t.verify(this.binary)}get id(){return un.default.encode(this.rawId)}set id(e){this._id=un.default.toBuffer(e)}get rawId(){return NE("sha256").update(this.rawSignature).digest()}set rawId(e){this._id=e}get rawSignature(){return this.binary.subarray(2,2+this.signatureLength)}get signature(){return un.default.encode(this.rawSignature)}set rawOwner(e){if(e.byteLength!=this.ownerLength)throw new Error(`Expected raw owner (pubkey) to be ${this.ownerLength} bytes, got ${e.byteLength} bytes.`);this.binary.set(e,2+this.signatureLength)}get rawOwner(){return this.binary.subarray(2+this.signatureLength,2+this.signatureLength+this.ownerLength)}get signatureLength(){return Je[this.signatureType].sigLength}get owner(){return un.default.encode(this.rawOwner)}get ownerLength(){return Je[this.signatureType].pubLength}get rawTarget(){let e=this.getTargetStart();return this.binary[e]==1?this.binary.subarray(e+1,e+33):Tf.alloc(0)}get target(){return un.default.encode(this.rawTarget)}get rawAnchor(){let e=this.getAnchorStart();return this.binary[e]==1?this.binary.subarray(e+1,e+33):Tf.alloc(0)}get anchor(){return un.default.encode(this.rawAnchor)}get rawTags(){let e=this.getTagsStart(),r=bt(this.binary.subarray(e+8,e+16));return this.binary.subarray(e+16,e+16+r)}get tags(){let e=this.getTagsStart();if(bt(this.binary.subarray(e,e+8))==0)return[];let n=bt(this.binary.subarray(e+8,e+16));return is(Tf.from(this.binary.subarray(e+16,e+16+n)))}get tagsB64Url(){return this.tags.map(r=>({name:un.default.encode(r.name),value:un.default.encode(r.value)}))}getStartOfData(){let e=this.getTagsStart(),r=this.binary.subarray(e+8,e+16),n=bt(r);return e+16+n}get rawData(){let e=this.getTagsStart(),r=this.binary.subarray(e+8,e+16),n=bt(r),i=e+16+n;return this.binary.subarray(i,this.binary.length)}get data(){return un.default.encode(this.rawData)}getRaw(){return this.binary}async sign(e){return this._id=await Zc(this,e),this.rawId}async setSignature(e){this.binary.set(e,2),this._id=Tf.from(await yt().hash(e))}isSigned(){return(this._id?.length??0)>0}toJSON(){return{signature:this.signature,owner:this.owner,target:this.target,tags:this.tags.map(e=>({name:un.default.encode(e.name),value:un.default.encode(e.value)})),data:this.data}}static async verify(e){if(e.byteLength<Kc)return!1;let r=new t(e),n=r.signatureType,i=r.getTagsStart(),a=bt(e.subarray(i,i+8)),d=e.subarray(i+8,i+16),v=bt(d);if(v>Xc)return!1;if(a>0)try{if(is(Tf.from(e.subarray(i+16,i+16+v))).length!==a)return!1}catch{return!1}let y=wf[n],m=await Af(r);return await y.verify(r.rawOwner,m,r.rawSignature)}async getSignatureData(){return Af(this)}getTagsStart(){let e=this.getTargetStart(),r=this.binary[e]==1,n=e+(r?33:1),i=this.binary[n]==1;return n+=i?33:1,n}getTargetStart(){return 2+this.signatureLength+this.ownerLength}getAnchorStart(){let e=this.getTargetStart()+1,r=this.binary[this.getTargetStart()]==1;return e+=r?32:0,e}},as=zc;import{createHash as JE}from"crypto";var ai=32,Vc=class{length;items;binary;constructor(e){this.binary=e,this.length=this.getDataItemCount(),this.items=this.getItems()}getRaw(){return this.binary}get(e){if(typeof e=="number"){if(e>=this.length)throw new RangeError("Index out of range");return this.getByIndex(e)}else return this.getById(e)}getSizes(){let e=[];for(let r=ai;r<ai+64*this.length;r+=64)e.push(bt(this.binary.subarray(r,r+32)));return e}getIds(){let e=[];for(let r=ai;r<ai+64*this.length;r+=64){let n=this.binary.subarray(r+32,r+64);if(n.length===0)throw new Error("Invalid bundle, id specified in headers doesn't exist");e.push(Ef.default.encode(n))}return e}getIdBy(e){if(e>this.length-1)throw new RangeError("Index of bundle out of range");let r=64+64*e;return Ef.default.encode(this.binary.subarray(r,r+32))}async toTransaction(e,r,n){let i=await r.createTransaction({data:this.binary,...e},n);return i.addTag("Bundle-Format","binary"),i.addTag("Bundle-Version","2.0.0"),i}async verify(){for(let e of this.items){let r=await e.isValid(),n=(0,Ef.default)(JE("sha256").update(e.rawSignature).digest());if(!(r&&e.id===n))return!1}return!0}getOffset(e){let r=0;for(let n=ai;n<ai+64*this.length;n+=64){let i=bt(this.binary.subarray(n,n+32));r+=i;let a=this.binary.subarray(n+32,n+64);if(Buffer.compare(a,e)===0)return{startOffset:r,size:i}}return{startOffset:-1,size:-1}}getByIndex(e){let r=0,n=this.getBundleStart(),i=0,a,d;for(let B=ai;B<ai+64*this.length;B+=64){if(a=bt(this.binary.subarray(B,B+32)),i++===e){d=this.binary.subarray(B+32,B+64);break}r+=a}let v=n+r,y=this.binary.subarray(v,v+a),m=new as(y);return m.rawId=d,m}getById(e){let r=Ef.default.toBuffer(e),n=this.getOffset(r);if(n.startOffset===-1)throw new Error("Transaction not found");let a=this.getBundleStart()+n.startOffset;return new as(this.binary.subarray(a,a+n.size))}getDataItemCount(){return bt(this.binary.subarray(0,32))}getBundleStart(){return 32+64*this.length}getItems(){let e=new Array(this.length),r=0,n=this.getBundleStart(),i=0;for(let a=ai;a<ai+64*this.length;a+=64){let d=bt(this.binary.subarray(a,a+32)),v=this.binary.subarray(a+32,a+64);if(v.length===0)throw new Error("Invalid bundle, id specified in headers doesn't exist");let y=n+r,m=this.binary.subarray(y,y+d);r+=d;let B=new as(m);B.rawId=v,e[i]=B,i++}return e}},Wh=Vc;function UE(t){return new Wh(t)}async function HE(t,e){let r=new Uint8Array(64*t.length),n=await Promise.all(t.map(async(a,d)=>{let v=a.isSigned()?a.rawId:await Zc(a,e),y=new Uint8Array(64);return y.set(Gc(a.getRaw().byteLength),0),y.set(v,32),r.set(y,64*d),a.getRaw()})).then(a=>Buffer.concat(a)),i=Buffer.concat([Buffer.from(Gc(t.length)),Buffer.from(r),n]);return new Wh(i)}async function _3(t,e){let r=await Af(t),n=await e.sign(r),i=await yt().hash(n);return{signature:Buffer.from(n),id:Buffer.from(i)}}async function Zc(t,e){let{signature:r,id:n}=await _3(t,e);return t.getRaw().set(r,2),n}var Sk=A(M(),1),B3=A(Nr(),1);function _f(t,e,r){let n=e.publicKey,i=r?.target?B3.default.toBuffer(r.target):null,a=1+(i?.byteLength??0),d=r?.anchor?Buffer.from(r.anchor):null,v=1+(d?.byteLength??0),y=(r?.tags?.length??0)>0?Qh(r?.tags):null,m=16+(y?y.byteLength:0),B=Buffer.from(t),P=B.byteLength,D=2+e.signatureLength+e.ownerLength+a+v+m+P,F=Buffer.alloc(D);if(F.set(jh(e.signatureType),0),F.set(new Uint8Array(e.signatureLength).fill(0),2),n.byteLength!==e.ownerLength)throw new Error(`Owner must be ${e.ownerLength} bytes, but was incorrectly ${n.byteLength}`);F.set(n,2+e.signatureLength);let C=2+e.signatureLength+e.ownerLength;if(F[C]=i?1:0,i){if(i.byteLength!==32)throw new Error(`Target must be 32 bytes but was incorrectly ${i.byteLength}`);F.set(i,C+1)}let q=C+a,W=q+1;if(F[q]=d?1:0,d){if(W+=d.byteLength,d.byteLength!==32)throw new Error("Anchor must be 32 bytes");F.set(d,q+1)}F.set(qc(r?.tags?.length??0),W);let K=qc(y?.byteLength??0);F.set(K,W+8),y&&F.set(y,W+16);let ne=W+m;return F.set(B,ne),new as(F)}var Mk=A(M(),1);var Ek=A(M(),1),Yh=class{signatureType;rawSignature;signature;signatureLength;rawOwner;owner;ownerLength;rawTarget;target;rawAnchor;anchor;rawTags;tags;rawData;data;static async verify(...e){throw new Error("You must implement `verify`")}};var Bk=A(M(),1);var Ck=A(M(),1);var e1={};i1(e1,{default:()=>KE,processStream:()=>C3,streamExportForTesting:()=>ZE,streamSigner:()=>zE});var eN=A(M(),1);import{PassThrough as qE,Transform as GE}from"stream";var ja=A(Nr(),1);import{createHash as XE}from"crypto";async function C3(t){let e=P3(t),r=(await e.next()).value;r=await Sr(e,r,32);let n=bt(r.subarray(0,32));r=r.subarray(32);let i=64*n;r=await Sr(e,r,i);let a=new Array(n);for(let y=0;y<i;y+=64)a[y/64]=[bt(r.subarray(y,y+32)),(0,ja.default)(Buffer.from(r.subarray(y+32,y+64)))];r=r.subarray(i);let d=32+i,v=[];for(let[y,m]of a){r=await Sr(e,r,Kc),r=await Sr(e,r,2);let B=bt(r.subarray(0,2));r=r.subarray(2);let{sigLength:P,pubLength:D,sigName:F}=Je[B];r=await Sr(e,r,P);let C=r.subarray(0,P);r=r.subarray(P),r=await Sr(e,r,D);let q=r.subarray(0,D);r=r.subarray(D),r=await Sr(e,r,1);let W=r[0]===1;W&&(r=await Sr(e,r,33));let K=W?r.subarray(1,33):Buffer.allocUnsafe(0);r=r.subarray(W?33:1),r=await Sr(e,r,1);let ne=r[0]===1;ne&&(r=await Sr(e,r,33));let $=ne?r.subarray(1,33):Buffer.allocUnsafe(0);r=r.subarray(ne?33:1),r=await Sr(e,r,8);let ae=bt(r.subarray(0,8));r=r.subarray(8),r=await Sr(e,r,8);let ie=bt(r.subarray(0,8));r=r.subarray(8),r=await Sr(e,r,ie);let ee=r.subarray(0,ie),ce=ae!==0&&ie!==0?is(Buffer.from(ee)):[];if(ce.length!==ae)throw new Error("Tags lengths don't match");r=r.subarray(ie);let te=new GE;te._transform=function(l,f,c){this.push(l),c()};let Y=Pi([(0,$e.stringToBuffer)("dataitem"),(0,$e.stringToBuffer)("1"),(0,$e.stringToBuffer)(B.toString()),q,K,$,ee,te]),S=2+P+D+(W?33:1)+(ne?33:1)+16+ie,s=y-S;if(r.byteLength>s)te.write(r.subarray(0,s)),r=r.subarray(s);else{let l=r.byteLength;for(te.write(r);s>l;){if(r=(await e.next()).value,!r)throw new Error(`Not enough data bytes expected: ${s} received: ${l}`);l+=r.byteLength,l>s?te.write(r.subarray(0,r.byteLength-(l-s))):te.write(r)}r=r.subarray(r.byteLength-(l-s))}if(te.end(),m!==(0,ja.default)(XE("sha256").update(C).digest()))throw new Error("ID doesn't match signature");if(!await wf[B].verify(q,await Y,C))throw new Error("Invalid signature");v.push({id:m,sigName:F,signature:(0,ja.default)(Buffer.from(C)),target:(0,ja.default)(Buffer.from(K)),anchor:(0,ja.default)(Buffer.from($)),owner:(0,ja.default)(Buffer.from(q)),tags:ce,dataOffset:d+S,dataSize:s}),d+=S+s}return v}async function zE(t,e,r,n){let i=_f("",r,n),a=new qE,d=[(0,$e.stringToBuffer)("dataitem"),(0,$e.stringToBuffer)("1"),(0,$e.stringToBuffer)(i.signatureType.toString()),i.rawOwner,i.rawTarget,i.rawAnchor,i.rawTags,t],v=await Pi(d),y=Buffer.from(await r.sign(v));return i.setSignature(y),a.write(i.getRaw()),e.pipe(a)}async function Sr(t,e,r){if(e.byteLength>=r)return e;let{done:n,value:i}=await t.next();if(n&&!i)throw new Error("Invalid buffer");return Sr(t,Buffer.concat([Buffer.from(e),Buffer.from(i)]),r)}async function*P3(t){for await(let e of t)yield e}var KE=C3,ZE={readBytes:Sr,getReader:P3};var VE={...$h,stream:e1};globalThis.arbundles??=VE;function Qa(t){return async e=>{if(hn(e))return e;if(!t.arweave)throw new Error("Must initialize with Arweave in order to create transactions");try{return await jE(t,{data:e})}catch(r){throw new Error(r.message??"Error resolving transaction")}}}async function jE(t,e){let r=null,n=null,i=null;if(typeof e.data=="string"&&(r=Buffer.from(d1(e.data),"base64"),n=l1(e.data),i=h1(r)),e.data instanceof File&&(r=new Uint8Array(await e.data.arrayBuffer()),n=e.data.type,i=e.data.size),r&&n&&i)if(i<Number(su.dispatchUploadSize))try{let a=await t.arweave.createTransaction({data:r},"use_wallet");return a.addTag(We.keys.contentType,n),e.tags&&e.tags.length>0&&e.tags.forEach(v=>a.addTag(v.name,v.value)),(await global.window.arweaveWallet.dispatch(a)).id}catch(a){throw new Error(a.message??"Error dispatching transaction")}else try{let a=await QE(e.data,{tags:[{name:"Content-Type",value:n},{name:"App-Name",value:"@permaweb/libs"}]},{apiUrl:su.node1,token:"arweave",chunkSize:5242880,batchSize:3});return console.log(a),console.log("Uploaded dataItem ID:",a.id),a.id}catch(a){throw new Error(a.message??"Error uploading transaction")}else throw new Error("Error preparing transaction data")}async function QE(t,e,r){let{apiUrl:n,token:i,chunkSize:a,batchSize:d=3}=r,v=new Va(window.arweaveWallet),y=await v.signer.getActivePublicKey();v.publicKey=Buffer.from(y,"base64");let m=new Uint8Array(await t.arrayBuffer()),B=_f(m,v,{...e,anchor:e.anchor||(()=>{let S=new Uint8Array(32);return crypto.getRandomValues(S),btoa(String.fromCharCode(...S)).replace(/\+/g,"-").replace(/\//g,"_").slice(0,32)})()});await B.sign(v);let P=B.getRaw(),D=new Blob([new Uint8Array(P)],{type:"application/octet-stream"}),F={"x-chunking-version":"2"},C=await fetch(`${n}/chunks/${i}/-1/-1`,{headers:F});if(!C.ok)throw new Error(`Failed to get upload ID: ${C.status} ${await C.text()}`);let q=await C.json(),W=q.id;if(a<q.min||a>q.max)throw new Error(`Configured chunkSize ${a} is out of allowed range ${q.min}-${q.max}`);let K=D.size,ne=[];for(let S=0;S<K;S+=a)ne.push(S);let $=new Set;(q.chunks??[]).forEach(([S])=>$.add(Number(S)));let ae=ne.filter(S=>S>0&&!$.has(S)),ie=$.has(0)?[]:[0],ee=ae.concat(ie),ce=S=>new Promise(s=>setTimeout(s,S));for(let S=0;S<ee.length;S+=d){let s=ee.slice(S,S+d);await Promise.all(s.map(async u=>{let f=await D.slice(u,u+a).arrayBuffer(),c=null;for(let g=1;g<=3;g++)try{let x=await fetch(`${n}/chunks/${i}/${W}/${u}`,{method:"POST",headers:{"Content-Type":"application/octet-stream",...F},body:f});if(!x.ok){let h=await x.text();throw x.status===402?new Error(`402 payment required: ${h}`):new Error(`Chunk upload error ${x.status}: ${h}`)}return}catch(x){if(c=x,g<3){await ce(1e3*g);continue}}throw c}))}let te={"Content-Type":"application/octet-stream",...F},Y=await fetch(`${n}/chunks/${i}/${W}/-1`,{method:"POST",headers:te});if(!Y.ok){let S=await Y.text();throw new Error(`Finalizing upload failed ${Y.status}: ${S}`)}return Y.json()}var bN=A(M(),1);var YE={},pN=A(M(),1);var $N=A(M(),1);var EN=A(M(),1);function jc(t){return async(e,r)=>{let n=t_(e);if(n)throw new Error(n);let i=u1[e.contentType]?.serialize(e.data)??e.data,a=e_(e);try{return await sa(t,{tags:a,data:i},r?v=>r(v):void 0)}catch(d){throw new Error(d.message??"Error creating asset")}}}async function t1(t,e,r){try{let n=Cn(await oa(t,{processId:e,path:"asset",fallbackAction:"Info"}));if(r?.useGateway){let i=await kr({gateway:Mr.goldsky,ids:[e],tags:null,owners:null,cursor:null});return{...i?.data?.[0]?Qc(i.data[0]):{},...n}}return{id:e,...n}}catch(n){throw new Error(n.message||"Error fetching atomic asset")}}function L3(t){return async(e,r)=>await t1(t,e,r)}async function R3(t){try{let e=await kr({gateway:Mr.arweave,ids:t??null,tags:null,owners:null,cursor:null});return e&&e.data.length?e.data.map(r=>Qc(r)):null}catch(e){throw new Error(e)}}function Qc(t){let e={id:t.node.id,owner:t.node.owner.address};for(let r of t.node.tags){let n=r.name,a=(n.startsWith(`${We.keys.bootloader}-`)?n.slice(`${We.keys.bootloader}-`.length):n).split("-").map((v,y)=>y===0?v.toLowerCase():v.charAt(0).toUpperCase()+v.slice(1).toLowerCase()).join(""),d;try{d=JSON.parse(r.value)}catch{d=r.value.toString()}e[a]=d}return e}function e_(t){let e=[{name:We.keys.onBoot,value:t.src??xt.src.asset},{name:We.keys.creator,value:t.creator},{name:We.keys.assetType,value:t.assetType},{name:We.keys.contentType,value:t.contentType},{name:We.keys.implements,value:"ANS-110"},{name:We.keys.dateCreated,value:new Date().getTime().toString()},yr("Name",t.name),yr("Description",t.description),yr("Topics",JSON.stringify(t.topics)),yr("Ticker","ATOMIC"),yr("Denomination",t.denomination?.toString()??"1"),yr("TotalSupply",t.supply?.toString()??"1"),yr("Transferable",t.transferable?.toString()??"true"),yr("Creator",t.creator)];if(t.metadata)for(let r in t.metadata)e.push(yr(Ya(r),t.metadata[r].toString()));if(t.users)for(let r of t.users)e.push({name:"Auth-User",value:r});return t.tags&&t.tags.forEach(r=>e.push(r)),e}function t_(t){if(typeof t!="object"||t===null)return"The provided arguments are invalid or empty.";let e=["name","description","topics","creator","data","contentType","assetType"];for(let r of e)if(!(r in t))return`Missing field '${r}'`;return typeof t.name!="string"||t.name.trim()===""?"Name is required":typeof t.description!="string"?"The description must be a valid string":!Array.isArray(t.topics)||t.topics.length===0?"Topics are required":typeof t.creator!="string"||t.creator.trim()===""?"Creator is required":t.data===void 0||t.data===null?"Data field is required":typeof t.contentType!="string"||t.contentType.trim()===""?"Content type must be a non-empty string":typeof t.assetType!="string"||t.assetType.trim()===""?"Type must be a non-empty string":"supply"in t&&(typeof t.supply!="number"||t.supply<=0)?"Supply must be a positive number":"denomination"in t&&(typeof t.denomination!="number"||t.denomination<=0)?"Denomination must be a positive number":"transferable"in t&&typeof t.transferable!="boolean"?"Transferable must be a boolean value":"metadata"in t&&typeof t.metadata!="object"?"Metadata must be an object":"tags"in t&&(!Array.isArray(t.tags)||t.tags.some(r=>typeof r!="object"))?"Tags must be an array of objects":"src"in t&&typeof t.src!="string"?"Source must be a valid string":null}var FN=A(M(),1);var r_="eXCtpVbcd_jZ0dmU2PZ8focaKxBGECBQ8wMib7sIVPo",r1="lJovHqM9hwNjHV5JoY9NGWtt0WD-5D4gOqNL2VWW5jk";function F3(t){return async(e,r)=>{if(!t.signer)throw new Error("No signer provided");let n=Qa(t),i=new Date().getTime().toString(),a=[{name:We.keys.creator,value:e.creator},{name:We.keys.ans110.title,value:os(e.title)},{name:We.keys.name,value:os(e.title)},{name:We.keys.ans110.description,value:os(e.description)}],d=null,v=null;try{d=e.banner?await n(e.thumbnail):r1,v=e.banner?await n(e.banner):r_,e.thumbnail&&a.push({name:We.keys.thumbnail,value:d}),e.banner&&a.push({name:We.keys.banner,value:v})}catch(B){console.error(B)}let y=await fetch($a(xt.src.collection));if(!y.ok)throw new Error("Unable to fetch process src");let m=await y.text();m=m.replace(/'<NAME>'/g,fu(e.title)),m=m.replace(/'<DESCRIPTION>'/g,fu(e.description)),m=m.replace(/<CREATOR>/g,e.creator),m=m.replace(/<THUMBNAIL>/g,d||r1),m=m.replace(/<BANNER>/g,v||r1),m=m.replace(/<DATECREATED>/g,i),m=m.replace(/<LASTUPDATE>/g,i);try{let B=await sa(t,{tags:a},r?P=>r(P):void 0);if(pn("Sending eval message to collection..."),r&&r("Sending eval message to collection..."),await t.ao.message({process:B,signer:t.signer,tags:[{name:"Action",value:"Eval"}],data:m}),!e.skipRegistry){pn("Sending collection to registry..."),r&&r("Sending collection to registry...");let P=[{name:"Action",value:"Add-Collection"},{name:"CollectionId",value:B},{name:"Name",value:os(e.title)},{name:"Creator",value:e.creator},{name:"DateCreated",value:i}];v&&P.push({name:"Banner",value:v}),d&&P.push({name:"Thumbnail",value:d}),await t.ao.message({process:xt.collectionRegistry,signer:t.signer,tags:P})}if(!e.skipActivity){pn("Creating collection activity process..."),r&&r("Creating collection activity process...");let P=[{name:"CollectionId",value:B},{name:"DateCreated",value:i},{name:"UCM-Process",value:"Collection-Activity"},{name:"On-Boot",value:xt.src.collectionActivity}],D=await sa(t,{tags:P},r?F=>r(F):void 0);pn("Adding activity to collection process..."),r&&r("Adding activity to collection process..."),await t.ao.message({process:B,signer:t.signer,tags:[{name:"Action",value:"Eval"}],data:`ActivityProcess = '${D}'`})}return B}catch(B){throw new Error(B.message??"Error creating collection")}}}function D3(t){return async e=>await Pn(t,{processId:e.creator,action:"Run-Action",tags:[{name:"ForwardTo",value:e.collectionId},{name:"ForwardAction",value:"Update-Assets"}],data:{Target:e.collectionId,Action:"Update-Assets",Input:{AssetIds:e.assetIds,UpdateType:e.updateType}}})}function O3(t){return async e=>{let r=await oa(t,{processId:e,path:"collection",fallbackAction:"Info"});return r?Cn(r):null}}function I3(t){return async e=>{let r=e.creator?"Get-Collections-By-User":"Get-Collections",n=await Pf(t,{processId:xt.collectionRegistry,action:r,tags:e.creator?[{name:"Creator",value:e.creator}]:null});return n&&n.Collections&&n.Collections.length?n.Collections.map(a=>({id:a.Id,title:a.Name.replace(/\[|\]/g,""),description:a.Description,creator:a.Creator,dateCreated:a.DateCreated,banner:a.Banner,thumbnail:a.Thumbnail})):null}}var JN=A(M(),1);function k3(t){let e=jc(t);return async(r,n)=>{let i=r.tags?r.tags:[];i.push({name:"Data-Source",value:r.parentId}),i.push({name:"Root-Source",value:r.rootId??r.parentId});let a={name:`Comment on ${r.parentId}`,description:`Comment on ${r.parentId}`,topics:["comment"],creator:r.creator,data:r.content,contentType:"text/plain",assetType:"comment",tags:i};return e(a,n)}}function N3(t){return async e=>{try{let r=await t1(t,e,{useGateway:!0}),n=r?.dataSource,i=r?.rootSource;if(!n||!i)throw new Error("dataSource and rootSource must be present on a comment");return{content:await U3(e),parentId:n,rootId:i}}catch(r){throw new Error(r.message??"Error getting comment")}}}function J3(t){return async e=>{if(!e.parentId&&!e.rootId)throw new Error("Must provide either parentId or rootId");let r=[];e.parentId&&r.push({name:"Data-Source",values:[e.parentId??""]}),e.rootId&&r.push({name:"Root-Source",values:[e.rootId??""]});let n=await kr({gateway:Mr.goldsky,ids:null,tags:r,owners:null,cursor:null}),i=[];n&&n.data.length&&(i=n.data.map(d=>Qc(d)));let a=[];for(let d of i){let v=d?.dataSource,y=d?.rootSource;if(!v||!y)throw new Error("dataSource and rootSource must be present on a comment");a.push({id:d.id,content:await U3(d.id),parentId:v,rootId:y})}return a}}async function U3(t){try{return await(await fetch($a(t))).text()}catch(e){throw new Error(e.message??"Error getting comment data")}}var YN=A(M(),1);var zN=A(M(),1);function Wc(t){return async(e,r)=>{try{let n=[{name:We.keys.onBoot,value:xt.src.zone.id}];return e.tags&&e.tags.length&&e.tags.forEach(a=>n.push(a)),await sa(t,{data:e.data,tags:n},r?a=>r(a):void 0)}catch(n){throw new Error(n.message??"Error creating zone")}}}function Yc(t){return async(e,r)=>{try{let n=Object.entries(e).map(([a,d])=>({key:a,value:d}));return await Pn(t,{processId:r,action:"Zone-Update",data:n})}catch(n){throw new Error(n)}}}function H3(t){return async(e,r)=>{try{return await Pn(t,{processId:r,action:"Zone-Append",tags:[{name:"Path",value:e.path}],data:e.data})}catch(n){throw new Error(n)}}}function q3(t){return async(e,r)=>{if(!hn(r))throw new Error("Invalid zone address");let i=[];for(let a of e){if(!hn(a.granteeId))throw new Error("Invalid granteeId address");if(a.type!=="wallet"&&a.type!=="process")throw new Error("Invalid role type");i.push({Id:a.granteeId,Roles:a.roles,Type:a.type,SendInvite:a.sendInvite})}try{return await Pn(t,{processId:r,action:"Role-Set",tags:[],data:i})}catch(a){throw new Error(a)}}}function G3(t){return async(e,r)=>{if(!(hn(r)&&hn(e.zoneToJoinId)))throw new Error("Invalid zone address");let i=[{name:"ZoneId",value:e.zoneToJoinId}];e.path&&i.push({name:"Path",value:e.path});try{return await Pn(t,{processId:r,action:"Zone-Join",tags:i})}catch(a){throw new Error(a)}}}function $c(t){return async e=>{try{return pn(`Updating zone to version ${xt.src.zone.version} with source ${xt.src.zone.id}`),await ss(t,{processId:e.zoneId,evalTxId:xt.src.zone.id}),await ss(t,{processId:e.zoneId,evalSrc:`Zone.Version = '${xt.src.zone.version}'; SyncState()`})}catch(r){throw new Error(r)}}}function eu(t){return async e=>{try{let r=await oa(t,{processId:e,path:"zone",fallbackAction:"Info"});return Cn(r)}catch(r){throw new Error(r.message??"Error getting zone")}}}function X3(t){let e=Wc(t),r=Qa(t);return async(n,i)=>{let a=null,d=[{name:We.keys.dataProtocol,value:We.values.zone},{name:We.keys.zoneType,value:We.values.user}],v=async y=>{let m=y.toLowerCase();if(n[m])try{let B=await r(n[m]);d.push(yr(y,B))}catch(B){i?i(`Failed to resolve ${y}: ${B.message}`):console.error(B)}};n.username&&d.push(yr("Username",n.username)),n.displayName&&d.push(yr("DisplayName",n.displayName)),n.description&&d.push(yr("Description",n.description)),await Promise.all([v("Thumbnail"),v("Banner")]);try{a=await e({tags:d},i)}catch(y){throw new Error(y.message??"Error creating profile")}return a}}function z3(t){let e=Yc(t),r=Qa(t);return async(n,i,a)=>{if(i){let d={Username:n.username,DisplayName:n.displayName,Description:n.description};if(n.thumbnail)try{d.Thumbnail=await r(n.thumbnail)}catch(v){a&&a(`Failed to resolve thumbnail: ${v.message}`)}if(n.banner)try{d.Banner=await r(n.banner)}catch(v){a&&a(`Failed to resolve banner: ${v.message}`)}try{return await e(d,i)}catch(v){throw new Error(v.message??"Error creating profile")}}else throw new Error("No profile provided")}}function K3(t){let e=$c(t);return async r=>{try{return await e({zoneId:r.profileId})}catch(n){throw new Error(n)}}}function n1(t){let e=eu(t);return async r=>{try{let n=await e(r);if(!n)throw new Error("Error fetching profile - Not found");return{id:r,owner:n.owner,assets:n.assets,roles:n.roles,invites:n.invites,version:n.version,...n.store}}catch(n){throw new Error(n.message??"Error fetching profile")}}}function Z3(t){let e=n1(t);return async r=>{try{let n=await kr({gateway:Mr.goldsky,tags:[{name:We.keys.dataProtocol,values:[We.values.zone]},{name:We.keys.zoneType,values:[We.values.user]}],owners:[r]});return n?.data?.length>0?(n.data.sort((i,a)=>{let d=i.node.block?.timestamp??0;return(a.node.block?.timestamp??0)-d}),await e(n.data[0].node.id)):{id:null}}catch(n){throw new Error(n.message??"Error fetching profile")}}}var aJ=xt.src.zone.version;function i_(t){return{createZone:Wc(t),updateZone:Yc(t),addToZone:H3(t),getZone:eu(t),setZoneRoles:q3(t),joinZone:G3(t),updateZoneVersion:$c(t),createProfile:X3(t),updateProfile:z3(t),updateProfileVersion:K3(t),getProfileById:n1(t),getProfileByWalletAddress:Z3(t),createAtomicAsset:jc(t),getAtomicAsset:L3(t),getAtomicAssets:R3,createComment:k3(t),getComment:N3(t),getComments:J3(t),createCollection:F3(t),updateCollectionAssets:D3(t),getCollection:O3(t),getCollections:I3(t),resolveTransaction:Qa(t),getGQLData:kr,getAggregatedGQLData:p1,createProcess:m1(t),readProcess:x1(t),readState:v1(t),sendMessage:g1(t),mapFromProcessCase:Cn,mapToProcessCase:Ya}}var oJ={init:i_};export{aJ as CurrentZoneVersion,YE as Types,oJ as default};
43
43
  /*! Bundled license information:
44
44
 
45
45
  js-sha3/src/sha3.js: