UNPKG

@unique-nft/api

Version:

Definitely typed JS API for the Unique Network blockchain

3 lines 21.8 kB
var UniqueAddress=(()=>{var Qt=Object.create;var q=Object.defineProperty;var Yt=Object.getOwnPropertyDescriptor;var Zt=Object.getOwnPropertyNames;var te=Object.getPrototypeOf,ee=Object.prototype.hasOwnProperty;var re=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Q=(t,e)=>{for(var r in e)q(t,r,{get:e[r],enumerable:!0})},mt=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Zt(e))!ee.call(t,s)&&s!==r&&q(t,s,{get:()=>e[s],enumerable:!(n=Yt(e,s))||n.enumerable});return t};var ne=(t,e,r)=>(r=t!=null?Qt(te(t)):{},mt(e||!t||!t.__esModule?q(r,"default",{value:t,enumerable:!0}):r,t)),se=t=>mt(q({},"__esModule",{value:!0}),t);var yt=re((nr,At)=>{"use strict";function ie(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),r=0;r<e.length;r++)e[r]=255;for(var n=0;n<t.length;n++){var s=t.charAt(n),c=s.charCodeAt(0);if(e[c]!==255)throw new TypeError(s+" is ambiguous");e[c]=n}var o=t.length,a=t.charAt(0),f=Math.log(o)/Math.log(256),p=Math.log(256)/Math.log(o);function h(u){if(u instanceof Uint8Array||(ArrayBuffer.isView(u)?u=new Uint8Array(u.buffer,u.byteOffset,u.byteLength):Array.isArray(u)&&(u=Uint8Array.from(u))),!(u instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(u.length===0)return"";for(var l=0,g=0,A=0,I=u.length;A!==I&&u[A]===0;)A++,l++;for(var S=(I-A)*p+1>>>0,E=new Uint8Array(S);A!==I;){for(var O=u[A],L=0,v=S-1;(O!==0||L<g)&&v!==-1;v--,L++)O+=256*E[v]>>>0,E[v]=O%o>>>0,O=O/o>>>0;if(O!==0)throw new Error("Non-zero carry");g=L,A++}for(var k=S-g;k!==S&&E[k]===0;)k++;for(var K=a.repeat(l);k<S;++k)K+=t.charAt(E[k]);return K}function b(u){if(typeof u!="string")throw new TypeError("Expected String");if(u.length===0)return new Uint8Array;for(var l=0,g=0,A=0;u[l]===a;)g++,l++;for(var I=(u.length-l)*f+1>>>0,S=new Uint8Array(I);u[l];){var E=e[u.charCodeAt(l)];if(E===255)return;for(var O=0,L=I-1;(E!==0||O<A)&&L!==-1;L--,O++)E+=o*S[L]>>>0,S[L]=E%256>>>0,E=E/256>>>0;if(E!==0)throw new Error("Non-zero carry");A=O,l++}for(var v=I-A;v!==I&&S[v]===0;)v++;for(var k=new Uint8Array(g+(I-v)),K=g;v!==I;)k[K++]=S[v++];return k}function x(u){var l=b(u);if(l)return l;throw new Error("Non-base"+o+" character")}return{encode:h,decodeUnsafe:b,decode:x}}At.exports=ie});var er={};Q(er,{Address:()=>tr,StringUtils:()=>V,algorithms:()=>it,collection:()=>Mt,compare:()=>Kt,constants:()=>Y,extract:()=>Jt,is:()=>d,mirror:()=>ht,nesting:()=>Vt,normalize:()=>H,substrate:()=>qt,to:()=>Gt,validate:()=>T});var Y={};Q(Y,{COLLECTION_ADDRESS_PREFIX:()=>W,NESTING_PREFIX:()=>F,STATIC_ADDRESSES:()=>oe});var oe={contractHelpers:"0x842899ECF380553E8a4de75bF534cdf6fBF64049",collectionHelpers:"0x6C4E9fE1AE37a41E93CEE429e8E1881aBdcbb54F"},F="0xf8238ccfff8ed887463fd5e0",W="0x17c4e6453cc49aaaaeaca894e6d9683e";var it={};Q(it,{base58:()=>ot,base64:()=>Ve,basex:()=>st.default,blake2b:()=>nt,keccak_256:()=>et});var st=ne(yt());function lt(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function ce(t){if(typeof t!="boolean")throw new Error(`Expected boolean, not ${t}`)}function xt(t,...e){if(!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new TypeError(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}function ae(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");lt(t.outputLen),lt(t.blockLen)}function ue(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function he(t,e){xt(t);let r=e.outputLen;if(t.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}var le={number:lt,bool:ce,bytes:xt,hash:ae,exists:ue,output:he},w=le;var Z=BigInt(4294967295),dt=BigInt(32);function wt(t,e=!1){return e?{h:Number(t&Z),l:Number(t>>dt&Z)}:{h:Number(t>>dt&Z)|0,l:Number(t&Z)|0}}function de(t,e=!1){let r=new Uint32Array(t.length),n=new Uint32Array(t.length);for(let s=0;s<t.length;s++){let{h:c,l:o}=wt(t[s],e);[r[s],n[s]]=[c,o]}return[r,n]}var fe=(t,e)=>BigInt(t>>>0)<<dt|BigInt(e>>>0),pe=(t,e,r)=>t>>>r,be=(t,e,r)=>t<<32-r|e>>>r,ge=(t,e,r)=>t>>>r|e<<32-r,me=(t,e,r)=>t<<32-r|e>>>r,Ae=(t,e,r)=>t<<64-r|e>>>r-32,ye=(t,e,r)=>t>>>r-32|e<<64-r,xe=(t,e)=>e,we=(t,e)=>t,Ee=(t,e,r)=>t<<r|e>>>32-r,ve=(t,e,r)=>e<<r|t>>>32-r,Te=(t,e,r)=>e<<r-32|t>>>64-r,Ie=(t,e,r)=>t<<r-32|e>>>64-r;function Se(t,e,r,n){let s=(e>>>0)+(n>>>0);return{h:t+r+(s/2**32|0)|0,l:s|0}}var Oe=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Ue=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,ke=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Le=(t,e,r,n,s)=>e+r+n+s+(t/2**32|0)|0,Be=(t,e,r,n,s)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(s>>>0),je=(t,e,r,n,s,c)=>e+r+n+s+c+(t/2**32|0)|0,Ne={fromBig:wt,split:de,toBig:fe,shrSH:pe,shrSL:be,rotrSH:ge,rotrSL:me,rotrBH:Ae,rotrBL:ye,rotr32H:xe,rotr32L:we,rotlSH:Ee,rotlSL:ve,rotlBH:Te,rotlBL:Ie,add:Se,add3L:Oe,add3H:Ue,add4L:ke,add4H:Le,add5H:je,add5L:Be},m=Ne;var B=t=>new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4));var Ce=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Ce)throw new Error("Non little-endian hardware is not supported");var ur=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function De(t){if(typeof t!="string")throw new TypeError(`utf8ToBytes expected string, got ${typeof t}`);return new TextEncoder().encode(t)}function U(t){if(typeof t=="string"&&(t=De(t)),!(t instanceof Uint8Array))throw new TypeError(`Expected input type is Uint8Array (got ${typeof t})`);return t}var R=class{clone(){return this._cloneInto()}};function Et(t){let e=n=>t().update(U(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function tt(t){let e=(n,s)=>t(s).update(U(n)).digest(),r=t({});return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=n=>t(n),e}var[It,St,Ot]=[[],[],[]],ze=BigInt(0),X=BigInt(1),_e=BigInt(2),He=BigInt(7),Re=BigInt(256),$e=BigInt(113);for(let t=0,e=X,r=1,n=0;t<24;t++){[r,n]=[n,(2*r+3*n)%5],It.push(2*(5*n+r)),St.push((t+1)*(t+2)/2%64);let s=ze;for(let c=0;c<7;c++)e=(e<<X^(e>>He)*$e)%Re,e&_e&&(s^=X<<(X<<BigInt(c))-X);Ot.push(s)}var[Pe,Fe]=m.split(Ot,!0),vt=(t,e,r)=>r>32?m.rotlBH(t,e,r):m.rotlSH(t,e,r),Tt=(t,e,r)=>r>32?m.rotlBL(t,e,r):m.rotlSL(t,e,r);function We(t,e=24){let r=new Uint32Array(10);for(let n=24-e;n<24;n++){for(let o=0;o<10;o++)r[o]=t[o]^t[o+10]^t[o+20]^t[o+30]^t[o+40];for(let o=0;o<10;o+=2){let a=(o+8)%10,f=(o+2)%10,p=r[f],h=r[f+1],b=vt(p,h,1)^r[a],x=Tt(p,h,1)^r[a+1];for(let u=0;u<50;u+=10)t[o+u]^=b,t[o+u+1]^=x}let s=t[2],c=t[3];for(let o=0;o<24;o++){let a=St[o],f=vt(s,c,a),p=Tt(s,c,a),h=It[o];s=t[h],c=t[h+1],t[h]=f,t[h+1]=p}for(let o=0;o<50;o+=10){for(let a=0;a<10;a++)r[a]=t[o+a];for(let a=0;a<10;a++)t[o+a]^=~r[(a+2)%10]&r[(a+4)%10]}t[0]^=Pe[n],t[1]^=Fe[n]}r.fill(0)}var $=class extends R{constructor(e,r,n,s=!1,c=24){if(super(),this.blockLen=e,this.suffix=r,this.outputLen=n,this.enableXOF=s,this.rounds=c,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,w.number(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=B(this.state)}keccak(){We(this.state32,this.rounds),this.posOut=0,this.pos=0}update(e){w.exists(this);let{blockLen:r,state:n}=this;e=U(e);let s=e.length;for(let c=0;c<s;){let o=Math.min(r-this.pos,s-c);for(let a=0;a<o;a++)n[this.pos++]^=e[c++];this.pos===r&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:e,suffix:r,pos:n,blockLen:s}=this;e[n]^=r,(r&128)!==0&&n===s-1&&this.keccak(),e[s-1]^=128,this.keccak()}writeInto(e){w.exists(this,!1),w.bytes(e),this.finish();let r=this.state,{blockLen:n}=this;for(let s=0,c=e.length;s<c;){this.posOut>=n&&this.keccak();let o=Math.min(n-this.posOut,c-s);e.set(r.subarray(this.posOut,this.posOut+o),s),this.posOut+=o,s+=o}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return w.number(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(w.output(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(e){let{blockLen:r,suffix:n,outputLen:s,rounds:c,enableXOF:o}=this;return e||(e=new $(r,n,s,o,c)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=c,e.suffix=n,e.outputLen=s,e.enableXOF=o,e.destroyed=this.destroyed,e}},j=(t,e,r)=>Et(()=>new $(e,t,r)),pr=j(6,144,224/8),br=j(6,136,256/8),gr=j(6,104,384/8),mr=j(6,72,512/8),Ar=j(1,144,224/8),et=j(1,136,256/8),yr=j(1,104,384/8),xr=j(1,72,512/8),Ut=(t,e,r)=>tt((n={})=>new $(e,t,n.dkLen===void 0?r:n.dkLen,!0)),wr=Ut(31,168,128/8),Er=Ut(31,136,256/8);var kt=new Uint8Array([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3]),rt=class extends R{constructor(e,r,n={},s,c,o){if(super(),this.blockLen=e,this.outputLen=r,this.length=0,this.pos=0,this.finished=!1,this.destroyed=!1,w.number(e),w.number(r),w.number(s),r<0||r>s)throw new Error("Blake2: outputLen bigger than keyLen");if(n.key!==void 0&&(n.key.length<1||n.key.length>s))throw new Error(`Key should be up 1..${s} byte long or undefined`);if(n.salt!==void 0&&n.salt.length!==c)throw new Error(`Salt should be ${c} byte long or undefined`);if(n.personalization!==void 0&&n.personalization.length!==o)throw new Error(`Personalization should be ${o} byte long or undefined`);this.buffer32=B(this.buffer=new Uint8Array(e))}update(e){w.exists(this);let{blockLen:r,buffer:n,buffer32:s}=this;e=U(e);let c=e.length;for(let o=0;o<c;){this.pos===r&&(this.compress(s,0,!1),this.pos=0);let a=Math.min(r-this.pos,c-o),f=e.byteOffset+o;if(a===r&&!(f%4)&&o+a<c){let p=new Uint32Array(e.buffer,f,Math.floor((c-o)/4));for(let h=0;o+r<c;h+=s.length,o+=r)this.length+=r,this.compress(p,h,!1);continue}n.set(e.subarray(o,o+a),this.pos),this.pos+=a,this.length+=a,o+=a}return this}digestInto(e){w.exists(this),w.output(e,this);let{pos:r,buffer32:n}=this;this.finished=!0,this.buffer.subarray(r).fill(0),this.compress(n,0,!0);let s=B(e);this.get().forEach((c,o)=>s[o]=c)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){let{buffer:r,length:n,finished:s,destroyed:c,outputLen:o,pos:a}=this;return e||(e=new this.constructor({dkLen:o})),e.set(...this.get()),e.length=n,e.finished=s,e.destroyed=c,e.outputLen=o,e.buffer.set(r),e.pos=a,e}};var y=new Uint32Array([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),i=new Uint32Array(32);function N(t,e,r,n,s,c){let o=s[c],a=s[c+1],f=i[2*t],p=i[2*t+1],h=i[2*e],b=i[2*e+1],x=i[2*r],u=i[2*r+1],l=i[2*n],g=i[2*n+1],A=m.add3L(f,h,o);p=m.add3H(A,p,b,a),f=A|0,{Dh:g,Dl:l}={Dh:g^p,Dl:l^f},{Dh:g,Dl:l}={Dh:m.rotr32H(g,l),Dl:m.rotr32L(g,l)},{h:u,l:x}=m.add(u,x,g,l),{Bh:b,Bl:h}={Bh:b^u,Bl:h^x},{Bh:b,Bl:h}={Bh:m.rotrSH(b,h,24),Bl:m.rotrSL(b,h,24)},i[2*t]=f,i[2*t+1]=p,i[2*e]=h,i[2*e+1]=b,i[2*r]=x,i[2*r+1]=u,i[2*n]=l,i[2*n+1]=g}function C(t,e,r,n,s,c){let o=s[c],a=s[c+1],f=i[2*t],p=i[2*t+1],h=i[2*e],b=i[2*e+1],x=i[2*r],u=i[2*r+1],l=i[2*n],g=i[2*n+1],A=m.add3L(f,h,o);p=m.add3H(A,p,b,a),f=A|0,{Dh:g,Dl:l}={Dh:g^p,Dl:l^f},{Dh:g,Dl:l}={Dh:m.rotrSH(g,l,16),Dl:m.rotrSL(g,l,16)},{h:u,l:x}=m.add(u,x,g,l),{Bh:b,Bl:h}={Bh:b^u,Bl:h^x},{Bh:b,Bl:h}={Bh:m.rotrBH(b,h,63),Bl:m.rotrBL(b,h,63)},i[2*t]=f,i[2*t+1]=p,i[2*e]=h,i[2*e+1]=b,i[2*r]=x,i[2*r+1]=u,i[2*n]=l,i[2*n+1]=g}var ft=class extends rt{constructor(e={}){super(128,e.dkLen===void 0?64:e.dkLen,e,64,16,16),this.v0l=y[0]|0,this.v0h=y[1]|0,this.v1l=y[2]|0,this.v1h=y[3]|0,this.v2l=y[4]|0,this.v2h=y[5]|0,this.v3l=y[6]|0,this.v3h=y[7]|0,this.v4l=y[8]|0,this.v4h=y[9]|0,this.v5l=y[10]|0,this.v5h=y[11]|0,this.v6l=y[12]|0,this.v6h=y[13]|0,this.v7l=y[14]|0,this.v7h=y[15]|0;let r=e.key?e.key.length:0;if(this.v0l^=this.outputLen|r<<8|1<<16|1<<24,e.salt){let n=B(U(e.salt));this.v4l^=n[0],this.v4h^=n[1],this.v5l^=n[2],this.v5h^=n[3]}if(e.personalization){let n=B(U(e.personalization));this.v6l^=n[0],this.v6h^=n[1],this.v7l^=n[2],this.v7h^=n[3]}if(e.key){let n=new Uint8Array(this.blockLen);n.set(U(e.key)),this.update(n)}}get(){let{v0l:e,v0h:r,v1l:n,v1h:s,v2l:c,v2h:o,v3l:a,v3h:f,v4l:p,v4h:h,v5l:b,v5h:x,v6l:u,v6h:l,v7l:g,v7h:A}=this;return[e,r,n,s,c,o,a,f,p,h,b,x,u,l,g,A]}set(e,r,n,s,c,o,a,f,p,h,b,x,u,l,g,A){this.v0l=e|0,this.v0h=r|0,this.v1l=n|0,this.v1h=s|0,this.v2l=c|0,this.v2h=o|0,this.v3l=a|0,this.v3h=f|0,this.v4l=p|0,this.v4h=h|0,this.v5l=b|0,this.v5h=x|0,this.v6l=u|0,this.v6h=l|0,this.v7l=g|0,this.v7h=A|0}compress(e,r,n){this.get().forEach((f,p)=>i[p]=f),i.set(y,16);let{h:s,l:c}=m.fromBig(BigInt(this.length));i[24]=y[8]^c,i[25]=y[9]^s,n&&(i[28]=~i[28],i[29]=~i[29]);let o=0,a=kt;for(let f=0;f<12;f++)N(0,4,8,12,e,r+2*a[o++]),C(0,4,8,12,e,r+2*a[o++]),N(1,5,9,13,e,r+2*a[o++]),C(1,5,9,13,e,r+2*a[o++]),N(2,6,10,14,e,r+2*a[o++]),C(2,6,10,14,e,r+2*a[o++]),N(3,7,11,15,e,r+2*a[o++]),C(3,7,11,15,e,r+2*a[o++]),N(0,5,10,15,e,r+2*a[o++]),C(0,5,10,15,e,r+2*a[o++]),N(1,6,11,12,e,r+2*a[o++]),C(1,6,11,12,e,r+2*a[o++]),N(2,7,8,13,e,r+2*a[o++]),C(2,7,8,13,e,r+2*a[o++]),N(3,4,9,14,e,r+2*a[o++]),C(3,4,9,14,e,r+2*a[o++]);this.v0l^=i[0]^i[16],this.v0h^=i[1]^i[17],this.v1l^=i[2]^i[18],this.v1h^=i[3]^i[19],this.v2l^=i[4]^i[20],this.v2h^=i[5]^i[21],this.v3l^=i[6]^i[22],this.v3h^=i[7]^i[23],this.v4l^=i[8]^i[24],this.v4h^=i[9]^i[25],this.v5l^=i[10]^i[26],this.v5h^=i[11]^i[27],this.v6l^=i[12]^i[28],this.v6h^=i[13]^i[29],this.v7l^=i[14]^i[30],this.v7h^=i[15]^i[31],i.fill(0)}destroy(){this.destroyed=!0,this.buffer32.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},nt=tt(t=>new ft(t));var Xe="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",Me="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",ot=(0,st.default)(Xe),Ve=(0,st.default)(Me);var V={};Q(V,{DWORDHexString:()=>D,hexStringToString:()=>jt,hexToU8a:()=>M,parseAndCheckTheNumberIsDWORD:()=>Nt,safeJsonParseStringOrHexString:()=>Ke,str2vec:()=>Bt,strToU8a:()=>Je,u8aToHex:()=>P,vec2str:()=>Ge});var Lt=t=>{try{return JSON.parse(t)}catch{return t}};var Ge=t=>t.map(e=>String.fromCharCode(typeof e=="number"?e:parseInt(e,10))).join(""),Bt=t=>typeof t!="string"?t:t.split("").map(e=>e.charCodeAt(0)),Je=t=>new Uint8Array(Bt(t)),M=t=>Uint8Array.from(((t.startsWith("0x")?t.slice(2):t).match(/.{1,2}/g)||[]).map(e=>parseInt(e,16))),P=t=>{let e=t instanceof Uint8Array?Array.from(t):t;return"0x"+e.reduce((r,n)=>r+n.toString(16).padStart(2,"0"),"")},jt=t=>((t.startsWith("0x")?t.slice(2):t).match(/.{1,2}/g)||[]).map(e=>String.fromCharCode(parseInt(e,16))).join(""),Ke=t=>{try{return JSON.parse(t)}catch{return Lt(jt(t))}},Nt=t=>{let e=typeof t=="string"?parseInt(t,10):t;if(isNaN(e))throw new Error(`Passed number is NaN: ${t}`);if(e<0)throw new Error(`Passed number is less than 0: ${t}`);if(e>4294967295)throw new Error(`Passed number is more than 2**32: ${t}`);return e},D={fromNumber:t=>Nt(t).toString(16).padStart(8,"0"),toNumber:t=>{let e=parseInt(t,16);if(isNaN(e))throw new Error(`Passed string is not hexadecimal: ${t}`);return e}};var pt=t=>{let e=t.toLowerCase().replace(/^0x/i,""),r=P(et(e)).replace(/^0x/i,""),n="0x";for(let s=0;s<e.length;s++)n+=parseInt(r[s],16)>7?e[s].toUpperCase():e[s];return n},z=t=>(T.ethereumAddress(t),pt(t)),Ct=(t,e)=>{let r=typeof t=="string"?t:t.Ethereum||t.ethereum,n=typeof e=="string"?e:e.Ethereum||e.ethereum;return!r||!n||!d.ethereumAddress(r)||!d.ethereumAddress(n)?!1:r.toLowerCase()===n.toLowerCase()},Dt=t=>(T.collectionId(t),pt(W+D.fromNumber(t))),zt=t=>(T.collectionAddress(t),D.toNumber(t.slice(-8))),_t=(t,e)=>(T.collectionId(t),T.tokenId(e),pt(F+D.fromNumber(t)+D.fromNumber(e))),Ht=t=>(T.nestingAddress(t),{collectionId:D.toNumber(t.slice(-16,-8)),tokenId:D.toNumber(t.slice(-8))});var Rt=(t,e=32)=>nt(t,{dkLen:e}),ct=t=>{let e=0,r=0;for(let s=0;s<t.length;s++)r+=t[s].length;let n=new Uint8Array(r);for(let s=0;s<t.length;s++)n.set(t[s],e),e+=t[s].length;return n},qe=new Uint8Array([83,83,53,56,80,82,69]),$t=t=>Rt(ct([qe,t]),64),Qe=t=>{let e=t[0]&64?2:1,r=e===1?t[0]:(t[0]&63)<<2|t[1]>>6|(t[1]&63)<<8,n=[34+e,35+e].includes(t.length),s=t.length-(n?2:1),c=$t(t.subarray(0,s));return[(t[0]&128)===0&&![46,47].includes(t[0])&&(n?t[t.length-2]===c[0]&&t[t.length-1]===c[1]:t[t.length-1]===c[0]),s,e,r]},G=(t,e=42)=>at(_(t).u8a,e);function at(t,e=42){let r=typeof t=="string"?M(t):typeof t=="bigint"?M(t.toString(16)):t;if(e<0||e>16383||[46,47].includes(e))throw new Error(`ss58Format is not valid, received ${typeof e} "${e}"`);let n=[1,2,4,8,32,33];if(!n.includes(r.length))throw new Error(`key length is not valid, received ${r.length}, valid values are ${n.join(", ")}`);let s=e<64?new Uint8Array([e]):new Uint8Array([(e&252)>>2|64,e>>8|(e&3)<<6]),c=ct([s,r]);return ot.encode(ct([c,$t(c).subarray(0,[32,33].includes(r.length)?2:1)]))}function _(t,e,r=-1){let n=null;try{let s=ot.decode(t),c=[3,4,6,10,35,36,37,38];if(!c.includes(s.length))throw n=new Error(`key length is not valid, decoded key length is ${s.length}, valid values are ${c.join(", ")}`),n;let[o,a,f,p]=Qe(s);if(!e&&!o)throw n=new Error("Invalid decoded address checksum"),n;if(![-1,p].includes(r))throw n=new Error(`Expected ss58Format ${r}, received ${p}`),n;let h=s.slice(f,a),b=P(h);return{u8a:h,hex:b,bigint:BigInt(b)}}catch(s){throw n||new Error(`Decoding ${t}: ${s.message}`)}}var bt=(t,e)=>{let r=typeof t=="string"?t:t.Substrate||t.substrate,n=typeof e=="string"?e:e.Substrate||e.substrate;if(!r||!n)return!1;try{let s=_(r),c=_(n);return s.bigint===c.bigint}catch{return!1}},Pt=(t,e)=>{let r=_(t,e).u8a.subarray(0,20);return z(P(r))},Ye=new Uint8Array([101,118,109,58]),Ft=(t,e=42)=>{T.ethereumAddress(t);let r=ct([Ye,M(t)]);return at(Rt(r),e)};var gt=t=>typeof t=="object"?d.substrateAddressObject(t)?H.substrateAddress(t.Substrate):d.substrateAddressObjectUncapitalized(t)?H.substrateAddress(t.substrate):d.ethereumAddressObject(t)?z(t.Ethereum):d.ethereumAddressObjectUncapitalized(t)?z(t.ethereum):null:typeof t=="string"?d.substrateAddress(t)?G(t):d.ethereumAddress(t)?z(t):null:null,ut=t=>{let e=gt(t);if(!e)throw new Error(`Passed address is not a valid address string or object: ${JSON.stringify(t).slice(0,100)}`);return e},J=t=>{if(d.substrateAddress(t))return{Substrate:t};if(d.ethereumAddress(t))return{Ethereum:t};throw new Error(`Passed address ${t} is not substrate nor ethereum address`)},Wt=t=>{if(d.substrateAddress(t))return{Substrate:H.substrateAddress(t)};if(d.ethereumAddress(t))return{Ethereum:H.ethereumAddress(t)};throw new Error(`Passed address ${t} is not substrate nor ethereum address`)},Xt=t=>{let e=J(t);return e.Substrate?G(e.Substrate):ht.ethereumToSubstrate(e.Ethereum)};var Ze=/^0x[a-fA-F0-9]{40}$/,T={substrateAddress:t=>(_(t),!0),ethereumAddress:t=>{if(!d.ethereumAddress(t))throw new Error(`address "${t}" is not valid ethereum address`);return!0},collectionAddress:t=>{if(!d.collectionAddress(t))throw new Error(`address ${t} is not a collection address`);return!0},nestingAddress:t=>{if(!d.nestingAddress(t))throw new Error(`address ${t} is not a nesting address`);return!0},collectionId:t=>{if(!d.collectionId(t))throw new Error("collectionId should be a number between 0 and 0xffffffff");return!0},tokenId:t=>{if(!d.tokenId(t))throw new Error("collectionId should be a number between 0 and 0xffffffff");return!0}},d={substrateAddress:t=>{try{return _(t),!0}catch{return!1}},ethereumAddress:t=>typeof t=="string"&&t.length===42&&!!t.match(Ze),collectionAddress:t=>d.ethereumAddress(t)&&t.toLowerCase().startsWith(W),nestingAddress:t=>d.ethereumAddress(t)&&t.toLowerCase().startsWith(F),collectionId:t=>!(typeof t!="number"||isNaN(t)||t<0||t>4294967295),tokenId:t=>!(typeof t!="number"||isNaN(t)||t<0||t>4294967295),crossAccountId(t){return d.substrateAddressObject(t)||d.ethereumAddressObject(t)},crossAccountIdUncapitalized(t){return d.substrateAddressObjectUncapitalized(t)||d.ethereumAddressObjectUncapitalized(t)},substrateAddressObject(t){return typeof t=="object"&&typeof t?.Substrate=="string"&&d.substrateAddress(t.Substrate)},ethereumAddressObject(t){return typeof t=="object"&&typeof t?.Ethereum=="string"&&d.ethereumAddress(t.Ethereum)},substrateAddressObjectUncapitalized(t){return typeof t=="object"&&typeof t?.substrate=="string"&&d.substrateAddress(t.substrate)},ethereumAddressObjectUncapitalized(t){return typeof t=="object"&&typeof t?.ethereum=="string"&&d.ethereumAddress(t.ethereum)}},Mt={idToAddress:Dt,addressToId:zt},Vt={idsToAddress:_t,addressToIds:Ht},Gt={crossAccountId:J,crossAccountIdNormalized:Wt,substrateNormalizedOrMirrorIfEthereum:Xt},Jt={normalizedAddressFromObject:ut,normalizedAddressFromObjectSafe:gt,crossAccountIdFromObject:t=>J(ut(t)),crossAccountIdFromObjectNormalized:t=>J(ut(t))},ht={substrateToEthereum:Pt,ethereumToSubstrate:Ft},H={substrateAddress:G,ethereumAddress:z},Kt={substrateAddresses:bt,ethereumAddresses:Ct},qt={encode:at,decode:_,compare:bt},tr={constants:Y,is:d,validate:T,collection:Mt,nesting:Vt,to:Gt,extract:Jt,mirror:ht,normalize:H,compare:Kt,substrate:qt,algorithms:it,StringUtils:V};return se(er);})(); /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */ //# sourceMappingURL=address.global.js.map