UNPKG

@walletconnect/relay-auth

Version:
3 lines (2 loc) 40.6 kB
(function(x,Dt){typeof exports=="object"&&typeof module<"u"?Dt(exports):typeof define=="function"&&define.amd?define(["exports"],Dt):(x=typeof globalThis<"u"?globalThis:x||self,Dt(x["@walletconnect/relay-auth"]={}))})(this,function(x){"use strict";function Dt(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function re(t,...e){if(!Dt(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function oe(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 an(t,e){re(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}const st=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const mt=t=>new DataView(t.buffer,t.byteOffset,t.byteLength);function Dn(t){if(typeof t!="string")throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array(new TextEncoder().encode(t))}function se(t){return typeof t=="string"&&(t=Dn(t)),re(t),t}class fn{clone(){return this._cloneInto()}}function dn(t){const e=r=>t().update(se(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function ie(t=32){if(st&&typeof st.getRandomValues=="function")return st.getRandomValues(new Uint8Array(t));if(st&&typeof st.randomBytes=="function")return st.randomBytes(t);throw new Error("crypto.getRandomValues must be defined")}function ln(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);const o=BigInt(32),s=BigInt(4294967295),a=Number(n>>o&s),u=Number(n&s),i=r?4:0,f=r?0:4;t.setUint32(e+i,a,r),t.setUint32(e+f,u,r)}class hn extends fn{constructor(e,n,r,o){super(),this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=mt(this.buffer)}update(e){oe(this);const{view:n,buffer:r,blockLen:o}=this;e=se(e);const s=e.length;for(let a=0;a<s;){const u=Math.min(o-this.pos,s-a);if(u===o){const i=mt(e);for(;o<=s-a;a+=o)this.process(i,a);continue}r.set(e.subarray(a,a+u),this.pos),this.pos+=u,a+=u,this.pos===o&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){oe(this),an(e,this),this.finished=!0;const{buffer:n,view:r,blockLen:o,isLE:s}=this;let{pos:a}=this;n[a++]=128,this.buffer.subarray(a).fill(0),this.padOffset>o-a&&(this.process(r,0),a=0);for(let h=a;h<o;h++)n[h]=0;ln(r,o-8,BigInt(this.length*8),s),this.process(r,0);const u=mt(e),i=this.outputLen;if(i%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const f=i/4,c=this.get();if(f>c.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)u.setUint32(4*h,c[h],s)}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:n,buffer:r,length:o,finished:s,destroyed:a,pos:u}=this;return e.length=o,e.pos=u,e.finished=s,e.destroyed=a,o%n&&e.buffer.set(r),e}}const pt=BigInt(2**32-1),_t=BigInt(32);function ue(t,e=!1){return e?{h:Number(t&pt),l:Number(t>>_t&pt)}:{h:Number(t>>_t&pt)|0,l:Number(t&pt)|0}}function bn(t,e=!1){let n=new Uint32Array(t.length),r=new Uint32Array(t.length);for(let o=0;o<t.length;o++){const{h:s,l:a}=ue(t[o],e);[n[o],r[o]]=[s,a]}return[n,r]}const En=(t,e)=>BigInt(t>>>0)<<_t|BigInt(e>>>0),wn=(t,e,n)=>t>>>n,pn=(t,e,n)=>t<<32-n|e>>>n,gn=(t,e,n)=>t>>>n|e<<32-n,yn=(t,e,n)=>t<<32-n|e>>>n,Cn=(t,e,n)=>t<<64-n|e>>>n-32,xn=(t,e,n)=>t>>>n-32|e<<64-n,Bn=(t,e)=>e,An=(t,e)=>t,mn=(t,e,n)=>t<<n|e>>>32-n,_n=(t,e,n)=>e<<n|t>>>32-n,In=(t,e,n)=>e<<n-32|t>>>64-n,Sn=(t,e,n)=>t<<n-32|e>>>64-n;function vn(t,e,n,r){const o=(e>>>0)+(r>>>0);return{h:t+n+(o/2**32|0)|0,l:o|0}}const C={fromBig:ue,split:bn,toBig:En,shrSH:wn,shrSL:pn,rotrSH:gn,rotrSL:yn,rotrBH:Cn,rotrBL:xn,rotr32H:Bn,rotr32L:An,rotlSH:mn,rotlSL:_n,rotlBH:In,rotlBL:Sn,add:vn,add3L:(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),add3H:(t,e,n,r)=>e+n+r+(t/2**32|0)|0,add4L:(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0),add4H:(t,e,n,r,o)=>e+n+r+o+(t/2**32|0)|0,add5H:(t,e,n,r,o,s)=>e+n+r+o+s+(t/2**32|0)|0,add5L:(t,e,n,r,o)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(o>>>0)},[Tn,Un]=(()=>C.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))))(),X=new Uint32Array(80),Q=new Uint32Array(80);class Nn extends hn{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){const{Ah:e,Al:n,Bh:r,Bl:o,Ch:s,Cl:a,Dh:u,Dl:i,Eh:f,El:c,Fh:h,Fl:E,Gh:w,Gl:l,Hh:g,Hl:S}=this;return[e,n,r,o,s,a,u,i,f,c,h,E,w,l,g,S]}set(e,n,r,o,s,a,u,i,f,c,h,E,w,l,g,S){this.Ah=e|0,this.Al=n|0,this.Bh=r|0,this.Bl=o|0,this.Ch=s|0,this.Cl=a|0,this.Dh=u|0,this.Dl=i|0,this.Eh=f|0,this.El=c|0,this.Fh=h|0,this.Fl=E|0,this.Gh=w|0,this.Gl=l|0,this.Hh=g|0,this.Hl=S|0}process(e,n){for(let d=0;d<16;d++,n+=4)X[d]=e.getUint32(n),Q[d]=e.getUint32(n+=4);for(let d=16;d<80;d++){const _=X[d-15]|0,F=Q[d-15]|0,q=C.rotrSH(_,F,1)^C.rotrSH(_,F,8)^C.shrSH(_,F,7),R=C.rotrSL(_,F,1)^C.rotrSL(_,F,8)^C.shrSL(_,F,7),T=X[d-2]|0,M=Q[d-2]|0,ct=C.rotrSH(T,M,19)^C.rotrBH(T,M,61)^C.shrSH(T,M,6),rt=C.rotrSL(T,M,19)^C.rotrBL(T,M,61)^C.shrSL(T,M,6),at=C.add4L(R,rt,Q[d-7],Q[d-16]),wt=C.add4H(at,q,ct,X[d-7],X[d-16]);X[d]=wt|0,Q[d]=at|0}let{Ah:r,Al:o,Bh:s,Bl:a,Ch:u,Cl:i,Dh:f,Dl:c,Eh:h,El:E,Fh:w,Fl:l,Gh:g,Gl:S,Hh:v,Hl:O}=this;for(let d=0;d<80;d++){const _=C.rotrSH(h,E,14)^C.rotrSH(h,E,18)^C.rotrBH(h,E,41),F=C.rotrSL(h,E,14)^C.rotrSL(h,E,18)^C.rotrBL(h,E,41),q=h&w^~h&g,R=E&l^~E&S,T=C.add5L(O,F,R,Un[d],Q[d]),M=C.add5H(T,v,_,q,Tn[d],X[d]),ct=T|0,rt=C.rotrSH(r,o,28)^C.rotrBH(r,o,34)^C.rotrBH(r,o,39),at=C.rotrSL(r,o,28)^C.rotrBL(r,o,34)^C.rotrBL(r,o,39),wt=r&s^r&u^s&u,te=o&a^o&i^a&i;v=g|0,O=S|0,g=w|0,S=l|0,w=h|0,l=E|0,{h,l:E}=C.add(f|0,c|0,M|0,ct|0),f=u|0,c=i|0,u=s|0,i=a|0,s=r|0,a=o|0;const ee=C.add3L(ct,at,te);r=C.add3H(ee,M,rt,wt),o=ee|0}({h:r,l:o}=C.add(this.Ah|0,this.Al|0,r|0,o|0)),{h:s,l:a}=C.add(this.Bh|0,this.Bl|0,s|0,a|0),{h:u,l:i}=C.add(this.Ch|0,this.Cl|0,u|0,i|0),{h:f,l:c}=C.add(this.Dh|0,this.Dl|0,f|0,c|0),{h,l:E}=C.add(this.Eh|0,this.El|0,h|0,E|0),{h:w,l}=C.add(this.Fh|0,this.Fl|0,w|0,l|0),{h:g,l:S}=C.add(this.Gh|0,this.Gl|0,g|0,S|0),{h:v,l:O}=C.add(this.Hh|0,this.Hl|0,v|0,O|0),this.set(r,o,s,a,u,i,f,c,h,E,w,l,g,S,v,O)}roundClean(){X.fill(0),Q.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const Ln=dn(()=>new Nn);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const It=BigInt(0),ce=BigInt(1),Fn=BigInt(2);function St(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function vt(t){if(!St(t))throw new Error("Uint8Array expected")}function Tt(t,e){if(typeof e!="boolean")throw new Error(t+" boolean expected, got "+e)}const On=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Ut(t){vt(t);let e="";for(let n=0;n<t.length;n++)e+=On[t[n]];return e}function ae(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?It:BigInt("0x"+t)}const K={_0:48,_9:57,A:65,F:70,a:97,f:102};function De(t){if(t>=K._0&&t<=K._9)return t-K._0;if(t>=K.A&&t<=K.F)return t-(K.A-10);if(t>=K.a&&t<=K.f)return t-(K.a-10)}function fe(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);const e=t.length,n=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);const r=new Uint8Array(n);for(let o=0,s=0;o<n;o++,s+=2){const a=De(t.charCodeAt(s)),u=De(t.charCodeAt(s+1));if(a===void 0||u===void 0){const i=t[s]+t[s+1];throw new Error('hex string expected, got non-hex character "'+i+'" at index '+s)}r[o]=a*16+u}return r}function Hn(t){return ae(Ut(t))}function gt(t){return vt(t),ae(Ut(Uint8Array.from(t).reverse()))}function de(t,e){return fe(t.toString(16).padStart(e*2,"0"))}function Nt(t,e){return de(t,e).reverse()}function P(t,e,n){let r;if(typeof e=="string")try{r=fe(e)}catch(s){throw new Error(t+" must be hex string or Uint8Array, cause: "+s)}else if(St(e))r=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");const o=r.length;if(typeof n=="number"&&o!==n)throw new Error(t+" of length "+n+" expected, got "+o);return r}function le(...t){let e=0;for(let r=0;r<t.length;r++){const o=t[r];vt(o),e+=o.length}const n=new Uint8Array(e);for(let r=0,o=0;r<t.length;r++){const s=t[r];n.set(s,o),o+=s.length}return n}const Lt=t=>typeof t=="bigint"&&It<=t;function Mn(t,e,n){return Lt(t)&&Lt(e)&&Lt(n)&&e<=t&&t<n}function ft(t,e,n,r){if(!Mn(e,n,r))throw new Error("expected valid "+t+": "+n+" <= n < "+r+", got "+e)}function zn(t){let e;for(e=0;t>It;t>>=ce,e+=1);return e}const Rn=t=>(Fn<<BigInt(t-1))-ce,$n={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",stringOrUint8Array:t=>typeof t=="string"||St(t),isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};function Ft(t,e,n={}){const r=(o,s,a)=>{const u=$n[s];if(typeof u!="function")throw new Error("invalid validator function");const i=t[o];if(!(a&&i===void 0)&&!u(i,t))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+i)};for(const[o,s]of Object.entries(e))r(o,s,!1);for(const[o,s]of Object.entries(n))r(o,s,!0);return t}function he(t){const e=new WeakMap;return(n,...r)=>{const o=e.get(n);if(o!==void 0)return o;const s=t(n,...r);return e.set(n,s),s}}const z=BigInt(0),L=BigInt(1),et=BigInt(2),qn=BigInt(3),Ot=BigInt(4),be=BigInt(5),Ee=BigInt(8);function H(t,e){const n=t%e;return n>=z?n:e+n}function jn(t,e,n){if(e<z)throw new Error("invalid exponent, negatives unsupported");if(n<=z)throw new Error("invalid modulus");if(n===L)return z;let r=L;for(;e>z;)e&L&&(r=r*t%n),t=t*t%n,e>>=L;return r}function W(t,e,n){let r=t;for(;e-- >z;)r*=r,r%=n;return r}function we(t,e){if(t===z)throw new Error("invert: expected non-zero number");if(e<=z)throw new Error("invert: expected positive modulus, got "+e);let n=H(t,e),r=e,o=z,s=L;for(;n!==z;){const u=r/n,i=r%n,f=o-s*u;r=n,n=i,o=s,s=f}if(r!==L)throw new Error("invert: does not exist");return H(o,e)}function kn(t){const e=(t-L)/et;let n,r,o;for(n=t-L,r=0;n%et===z;n/=et,r++);for(o=et;o<t&&jn(o,e,t)!==t-L;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(r===1){const a=(t+L)/Ot;return function(i,f){const c=i.pow(f,a);if(!i.eql(i.sqr(c),f))throw new Error("Cannot find square root");return c}}const s=(n+L)/et;return function(u,i){if(u.pow(i,e)===u.neg(u.ONE))throw new Error("Cannot find square root");let f=r,c=u.pow(u.mul(u.ONE,o),n),h=u.pow(i,s),E=u.pow(i,n);for(;!u.eql(E,u.ONE);){if(u.eql(E,u.ZERO))return u.ZERO;let w=1;for(let g=u.sqr(E);w<f&&!u.eql(g,u.ONE);w++)g=u.sqr(g);const l=u.pow(c,L<<BigInt(f-w-1));c=u.sqr(l),h=u.mul(h,l),E=u.mul(E,c),f=w}return h}}function Gn(t){if(t%Ot===qn){const e=(t+L)/Ot;return function(r,o){const s=r.pow(o,e);if(!r.eql(r.sqr(s),o))throw new Error("Cannot find square root");return s}}if(t%Ee===be){const e=(t-be)/Ee;return function(r,o){const s=r.mul(o,et),a=r.pow(s,e),u=r.mul(o,a),i=r.mul(r.mul(u,et),a),f=r.mul(u,r.sub(i,r.ONE));if(!r.eql(r.sqr(f),o))throw new Error("Cannot find square root");return f}}return kn(t)}const Zn=(t,e)=>(H(t,e)&L)===L,Jn=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Wn(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=Jn.reduce((r,o)=>(r[o]="function",r),e);return Ft(t,n)}function Vn(t,e,n){if(n<z)throw new Error("invalid exponent, negatives unsupported");if(n===z)return t.ONE;if(n===L)return e;let r=t.ONE,o=e;for(;n>z;)n&L&&(r=t.mul(r,o)),o=t.sqr(o),n>>=L;return r}function Yn(t,e){const n=new Array(e.length),r=e.reduce((s,a,u)=>t.is0(a)?s:(n[u]=s,t.mul(s,a)),t.ONE),o=t.inv(r);return e.reduceRight((s,a,u)=>t.is0(a)?s:(n[u]=t.mul(s,n[u]),t.mul(s,a)),o),n}function pe(t,e){const n=e!==void 0?e:t.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function ge(t,e,n=!1,r={}){if(t<=z)throw new Error("invalid field: expected ORDER > 0, got "+t);const{nBitLength:o,nByteLength:s}=pe(t,e);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let a;const u=Object.freeze({ORDER:t,isLE:n,BITS:o,BYTES:s,MASK:Rn(o),ZERO:z,ONE:L,create:i=>H(i,t),isValid:i=>{if(typeof i!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof i);return z<=i&&i<t},is0:i=>i===z,isOdd:i=>(i&L)===L,neg:i=>H(-i,t),eql:(i,f)=>i===f,sqr:i=>H(i*i,t),add:(i,f)=>H(i+f,t),sub:(i,f)=>H(i-f,t),mul:(i,f)=>H(i*f,t),pow:(i,f)=>Vn(u,i,f),div:(i,f)=>H(i*we(f,t),t),sqrN:i=>i*i,addN:(i,f)=>i+f,subN:(i,f)=>i-f,mulN:(i,f)=>i*f,inv:i=>we(i,t),sqrt:r.sqrt||(i=>(a||(a=Gn(t)),a(u,i))),invertBatch:i=>Yn(u,i),cmov:(i,f,c)=>c?f:i,toBytes:i=>n?Nt(i,s):de(i,s),fromBytes:i=>{if(i.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+i.length);return n?gt(i):Hn(i)}});return Object.freeze(u)}const ye=BigInt(0),yt=BigInt(1);function Ht(t,e){const n=e.negate();return t?n:e}function Ce(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Mt(t,e){Ce(t,e);const n=Math.ceil(e/t)+1,r=2**(t-1);return{windows:n,windowSize:r}}function Kn(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((n,r)=>{if(!(n instanceof e))throw new Error("invalid point at index "+r)})}function Pn(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,r)=>{if(!e.isValid(n))throw new Error("invalid scalar at index "+r)})}const zt=new WeakMap,xe=new WeakMap;function Rt(t){return xe.get(t)||1}function Xn(t,e){return{constTimeNegate:Ht,hasPrecomputes(n){return Rt(n)!==1},unsafeLadder(n,r,o=t.ZERO){let s=n;for(;r>ye;)r&yt&&(o=o.add(s)),s=s.double(),r>>=yt;return o},precomputeWindow(n,r){const{windows:o,windowSize:s}=Mt(r,e),a=[];let u=n,i=u;for(let f=0;f<o;f++){i=u,a.push(i);for(let c=1;c<s;c++)i=i.add(u),a.push(i);u=i.double()}return a},wNAF(n,r,o){const{windows:s,windowSize:a}=Mt(n,e);let u=t.ZERO,i=t.BASE;const f=BigInt(2**n-1),c=2**n,h=BigInt(n);for(let E=0;E<s;E++){const w=E*a;let l=Number(o&f);o>>=h,l>a&&(l-=c,o+=yt);const g=w,S=w+Math.abs(l)-1,v=E%2!==0,O=l<0;l===0?i=i.add(Ht(v,r[g])):u=u.add(Ht(O,r[S]))}return{p:u,f:i}},wNAFUnsafe(n,r,o,s=t.ZERO){const{windows:a,windowSize:u}=Mt(n,e),i=BigInt(2**n-1),f=2**n,c=BigInt(n);for(let h=0;h<a;h++){const E=h*u;if(o===ye)break;let w=Number(o&i);if(o>>=c,w>u&&(w-=f,o+=yt),w===0)continue;let l=r[E+Math.abs(w)-1];w<0&&(l=l.negate()),s=s.add(l)}return s},getPrecomputes(n,r,o){let s=zt.get(r);return s||(s=this.precomputeWindow(r,n),n!==1&&zt.set(r,o(s))),s},wNAFCached(n,r,o){const s=Rt(n);return this.wNAF(s,this.getPrecomputes(s,n,o),r)},wNAFCachedUnsafe(n,r,o,s){const a=Rt(n);return a===1?this.unsafeLadder(n,r,s):this.wNAFUnsafe(a,this.getPrecomputes(a,n,o),r,s)},setWindowSize(n,r){Ce(r,e),xe.set(n,r),zt.delete(n)}}}function Qn(t,e,n,r){if(Kn(n,t),Pn(r,e),n.length!==r.length)throw new Error("arrays of points and scalars must have equal length");const o=t.ZERO,s=zn(BigInt(n.length)),a=s>12?s-3:s>4?s-2:s?2:1,u=(1<<a)-1,i=new Array(u+1).fill(o),f=Math.floor((e.BITS-1)/a)*a;let c=o;for(let h=f;h>=0;h-=a){i.fill(o);for(let w=0;w<r.length;w++){const l=r[w],g=Number(l>>BigInt(h)&BigInt(u));i[g]=i[g].add(n[w])}let E=o;for(let w=i.length-1,l=o;w>0;w--)l=l.add(i[w]),E=E.add(l);if(c=c.add(E),h!==0)for(let w=0;w<a;w++)c=c.double()}return c}function tr(t){return Wn(t.Fp),Ft(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...pe(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}const J=BigInt(0),k=BigInt(1),Ct=BigInt(2),er=BigInt(8),nr={zip215:!0};function rr(t){const e=tr(t);return Ft(t,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function or(t){const e=rr(t),{Fp:n,n:r,prehash:o,hash:s,randomBytes:a,nByteLength:u,h:i}=e,f=Ct<<BigInt(u*8)-k,c=n.create,h=ge(e.n,e.nBitLength),E=e.uvRatio||((y,D)=>{try{return{isValid:!0,value:n.sqrt(y*n.inv(D))}}catch{return{isValid:!1,value:J}}}),w=e.adjustScalarBytes||(y=>y),l=e.domain||((y,D,b)=>{if(Tt("phflag",b),D.length||b)throw new Error("Contexts/pre-hash are not supported");return y});function g(y,D){ft("coordinate "+y,D,J,f)}function S(y){if(!(y instanceof d))throw new Error("ExtendedPoint expected")}const v=he((y,D)=>{const{ex:b,ey:p,ez:B}=y,A=y.is0();D==null&&(D=A?er:n.inv(B));const m=c(b*D),U=c(p*D),I=c(B*D);if(A)return{x:J,y:k};if(I!==k)throw new Error("invZ was invalid");return{x:m,y:U}}),O=he(y=>{const{a:D,d:b}=e;if(y.is0())throw new Error("bad point: ZERO");const{ex:p,ey:B,ez:A,et:m}=y,U=c(p*p),I=c(B*B),N=c(A*A),j=c(N*N),G=c(U*D),V=c(N*c(G+I)),Y=c(j+c(b*c(U*I)));if(V!==Y)throw new Error("bad point: equation left != right (1)");const Z=c(p*B),tt=c(A*m);if(Z!==tt)throw new Error("bad point: equation left != right (2)");return!0});class d{constructor(D,b,p,B){this.ex=D,this.ey=b,this.ez=p,this.et=B,g("x",D),g("y",b),g("z",p),g("t",B),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(D){if(D instanceof d)throw new Error("extended point not allowed");const{x:b,y:p}=D||{};return g("x",b),g("y",p),new d(b,p,k,c(b*p))}static normalizeZ(D){const b=n.invertBatch(D.map(p=>p.ez));return D.map((p,B)=>p.toAffine(b[B])).map(d.fromAffine)}static msm(D,b){return Qn(d,h,D,b)}_setWindowSize(D){q.setWindowSize(this,D)}assertValidity(){O(this)}equals(D){S(D);const{ex:b,ey:p,ez:B}=this,{ex:A,ey:m,ez:U}=D,I=c(b*U),N=c(A*B),j=c(p*U),G=c(m*B);return I===N&&j===G}is0(){return this.equals(d.ZERO)}negate(){return new d(c(-this.ex),this.ey,this.ez,c(-this.et))}double(){const{a:D}=e,{ex:b,ey:p,ez:B}=this,A=c(b*b),m=c(p*p),U=c(Ct*c(B*B)),I=c(D*A),N=b+p,j=c(c(N*N)-A-m),G=I+m,V=G-U,Y=I-m,Z=c(j*V),tt=c(G*Y),ot=c(j*Y),At=c(V*G);return new d(Z,tt,At,ot)}add(D){S(D);const{a:b,d:p}=e,{ex:B,ey:A,ez:m,et:U}=this,{ex:I,ey:N,ez:j,et:G}=D;if(b===BigInt(-1)){const en=c((A-B)*(N+I)),nn=c((A+B)*(N-I)),ne=c(nn-en);if(ne===J)return this.double();const rn=c(m*Ct*G),on=c(U*Ct*j),sn=on+rn,un=nn+en,cn=on-rn,Wo=c(sn*ne),Vo=c(un*cn),Yo=c(sn*cn),Ko=c(ne*un);return new d(Wo,Vo,Ko,Yo)}const V=c(B*I),Y=c(A*N),Z=c(U*p*G),tt=c(m*j),ot=c((B+A)*(I+N)-V-Y),At=tt-Z,Qe=tt+Z,tn=c(Y-b*V),ko=c(ot*At),Go=c(Qe*tn),Zo=c(ot*tn),Jo=c(At*Qe);return new d(ko,Go,Jo,Zo)}subtract(D){return this.add(D.negate())}wNAF(D){return q.wNAFCached(this,D,d.normalizeZ)}multiply(D){const b=D;ft("scalar",b,k,r);const{p,f:B}=this.wNAF(b);return d.normalizeZ([p,B])[0]}multiplyUnsafe(D,b=d.ZERO){const p=D;return ft("scalar",p,J,r),p===J?F:this.is0()||p===k?this:q.wNAFCachedUnsafe(this,p,d.normalizeZ,b)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return q.unsafeLadder(this,r).is0()}toAffine(D){return v(this,D)}clearCofactor(){const{h:D}=e;return D===k?this:this.multiplyUnsafe(D)}static fromHex(D,b=!1){const{d:p,a:B}=e,A=n.BYTES;D=P("pointHex",D,A),Tt("zip215",b);const m=D.slice(),U=D[A-1];m[A-1]=U&-129;const I=gt(m),N=b?f:n.ORDER;ft("pointHex.y",I,J,N);const j=c(I*I),G=c(j-k),V=c(p*j-B);let{isValid:Y,value:Z}=E(G,V);if(!Y)throw new Error("Point.fromHex: invalid y coordinate");const tt=(Z&k)===k,ot=(U&128)!==0;if(!b&&Z===J&&ot)throw new Error("Point.fromHex: x=0 and x_0=1");return ot!==tt&&(Z=c(-Z)),d.fromAffine({x:Z,y:I})}static fromPrivateKey(D){return M(D).point}toRawBytes(){const{x:D,y:b}=this.toAffine(),p=Nt(b,n.BYTES);return p[p.length-1]|=D&k?128:0,p}toHex(){return Ut(this.toRawBytes())}}d.BASE=new d(e.Gx,e.Gy,k,c(e.Gx*e.Gy)),d.ZERO=new d(J,k,k,J);const{BASE:_,ZERO:F}=d,q=Xn(d,u*8);function R(y){return H(y,r)}function T(y){return R(gt(y))}function M(y){const D=n.BYTES;y=P("private key",y,D);const b=P("hashed private key",s(y),2*D),p=w(b.slice(0,D)),B=b.slice(D,2*D),A=T(p),m=_.multiply(A),U=m.toRawBytes();return{head:p,prefix:B,scalar:A,point:m,pointBytes:U}}function ct(y){return M(y).pointBytes}function rt(y=new Uint8Array,...D){const b=le(...D);return T(s(l(b,P("context",y),!!o)))}function at(y,D,b={}){y=P("message",y),o&&(y=o(y));const{prefix:p,scalar:B,pointBytes:A}=M(D),m=rt(b.context,p,y),U=_.multiply(m).toRawBytes(),I=rt(b.context,U,A,y),N=R(m+I*B);ft("signature.s",N,J,r);const j=le(U,Nt(N,n.BYTES));return P("result",j,n.BYTES*2)}const wt=nr;function te(y,D,b,p=wt){const{context:B,zip215:A}=p,m=n.BYTES;y=P("signature",y,2*m),D=P("message",D),b=P("publicKey",b,m),A!==void 0&&Tt("zip215",A),o&&(D=o(D));const U=gt(y.slice(m,2*m));let I,N,j;try{I=d.fromHex(b,A),N=d.fromHex(y.slice(0,m),A),j=_.multiplyUnsafe(U)}catch{return!1}if(!A&&I.isSmallOrder())return!1;const G=rt(B,N.toRawBytes(),I.toRawBytes(),D);return N.add(I.multiplyUnsafe(G)).subtract(j).clearCofactor().equals(d.ZERO)}return _._setWindowSize(8),{CURVE:e,getPublicKey:ct,sign:at,verify:te,ExtendedPoint:d,utils:{getExtendedPublicKey:M,randomPrivateKey:()=>a(n.BYTES),precompute(y=8,D=d.BASE){return D._setWindowSize(y),D.multiply(BigInt(3)),D}}}}BigInt(0),BigInt(1);const $t=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Be=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");BigInt(0);const sr=BigInt(1),Ae=BigInt(2);BigInt(3);const ir=BigInt(5),ur=BigInt(8);function cr(t){const e=BigInt(10),n=BigInt(20),r=BigInt(40),o=BigInt(80),s=$t,u=t*t%s*t%s,i=W(u,Ae,s)*u%s,f=W(i,sr,s)*t%s,c=W(f,ir,s)*f%s,h=W(c,e,s)*c%s,E=W(h,n,s)*h%s,w=W(E,r,s)*E%s,l=W(w,o,s)*w%s,g=W(l,o,s)*w%s,S=W(g,e,s)*c%s;return{pow_p_5_8:W(S,Ae,s)*t%s,b2:u}}function ar(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}function Dr(t,e){const n=$t,r=H(e*e*e,n),o=H(r*r*e,n),s=cr(t*o).pow_p_5_8;let a=H(t*r*s,n);const u=H(e*a*a,n),i=a,f=H(a*Be,n),c=u===t,h=u===H(-t,n),E=u===H(-t*Be,n);return c&&(a=i),(h||E)&&(a=f),Zn(a,n)&&(a=H(-a,n)),{isValid:c||h,value:a}}const fr=(()=>ge($t,void 0,!0))(),dr=(()=>({a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:fr,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:ur,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Ln,randomBytes:ie,adjustScalarBytes:ar,uvRatio:Dr}))(),qt=(()=>or(dr))(),lr=1e3;function hr(t){return Math.floor(t/lr)}const jt="EdDSA",kt="JWT",it=".",dt="base64url",Gt="utf8",xt="utf8",Zt=":",Jt="did",Wt="key",lt="base58btc",Vt="z",Yt="K36",me=32,_e=32;function Kt(t){return globalThis.Buffer!=null?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t}function Ie(t=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?Kt(globalThis.Buffer.allocUnsafe(t)):new Uint8Array(t)}function Se(t,e){e||(e=t.reduce((o,s)=>o+s.length,0));const n=Ie(e);let r=0;for(const o of t)n.set(o,r),r+=o.length;return Kt(n)}function br(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),r=0;r<n.length;r++)n[r]=255;for(var o=0;o<t.length;o++){var s=t.charAt(o),a=s.charCodeAt(0);if(n[a]!==255)throw new TypeError(s+" is ambiguous");n[a]=o}var u=t.length,i=t.charAt(0),f=Math.log(u)/Math.log(256),c=Math.log(256)/Math.log(u);function h(l){if(l instanceof Uint8Array||(ArrayBuffer.isView(l)?l=new Uint8Array(l.buffer,l.byteOffset,l.byteLength):Array.isArray(l)&&(l=Uint8Array.from(l))),!(l instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(l.length===0)return"";for(var g=0,S=0,v=0,O=l.length;v!==O&&l[v]===0;)v++,g++;for(var d=(O-v)*c+1>>>0,_=new Uint8Array(d);v!==O;){for(var F=l[v],q=0,R=d-1;(F!==0||q<S)&&R!==-1;R--,q++)F+=256*_[R]>>>0,_[R]=F%u>>>0,F=F/u>>>0;if(F!==0)throw new Error("Non-zero carry");S=q,v++}for(var T=d-S;T!==d&&_[T]===0;)T++;for(var M=i.repeat(g);T<d;++T)M+=t.charAt(_[T]);return M}function E(l){if(typeof l!="string")throw new TypeError("Expected String");if(l.length===0)return new Uint8Array;var g=0;if(l[g]!==" "){for(var S=0,v=0;l[g]===i;)S++,g++;for(var O=(l.length-g)*f+1>>>0,d=new Uint8Array(O);l[g];){var _=n[l.charCodeAt(g)];if(_===255)return;for(var F=0,q=O-1;(_!==0||F<v)&&q!==-1;q--,F++)_+=u*d[q]>>>0,d[q]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");v=F,g++}if(l[g]!==" "){for(var R=O-v;R!==O&&d[R]===0;)R++;for(var T=new Uint8Array(S+(O-R)),M=S;R!==O;)T[M++]=d[R++];return T}}}function w(l){var g=E(l);if(g)return g;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:E,decode:w}}var Er=br,wr=Er;const ve=t=>{if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")},pr=t=>new TextEncoder().encode(t),gr=t=>new TextDecoder().decode(t);class yr{constructor(e,n,r){this.name=e,this.prefix=n,this.baseEncode=r}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}}class Cr{constructor(e,n,r){if(this.name=e,this.prefix=n,n.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=n.codePointAt(0),this.baseDecode=r}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Te(this,e)}}class xr{constructor(e){this.decoders=e}or(e){return Te(this,e)}decode(e){const n=e[0],r=this.decoders[n];if(r)return r.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}}const Te=(t,e)=>new xr({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}});class Br{constructor(e,n,r,o){this.name=e,this.prefix=n,this.baseEncode=r,this.baseDecode=o,this.encoder=new yr(e,n,r),this.decoder=new Cr(e,n,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}}const Bt=({name:t,prefix:e,encode:n,decode:r})=>new Br(t,e,n,r),ht=({prefix:t,name:e,alphabet:n})=>{const{encode:r,decode:o}=wr(n,e);return Bt({prefix:t,name:e,encode:r,decode:s=>ve(o(s))})},Ar=(t,e,n,r)=>{const o={};for(let c=0;c<e.length;++c)o[e[c]]=c;let s=t.length;for(;t[s-1]==="=";)--s;const a=new Uint8Array(s*n/8|0);let u=0,i=0,f=0;for(let c=0;c<s;++c){const h=o[t[c]];if(h===void 0)throw new SyntaxError(`Non-${r} character`);i=i<<n|h,u+=n,u>=8&&(u-=8,a[f++]=255&i>>u)}if(u>=n||255&i<<8-u)throw new SyntaxError("Unexpected end of data");return a},mr=(t,e,n)=>{const r=e[e.length-1]==="=",o=(1<<n)-1;let s="",a=0,u=0;for(let i=0;i<t.length;++i)for(u=u<<8|t[i],a+=8;a>n;)a-=n,s+=e[o&u>>a];if(a&&(s+=e[o&u<<n-a]),r)for(;s.length*n&7;)s+="=";return s},$=({name:t,prefix:e,bitsPerChar:n,alphabet:r})=>Bt({prefix:e,name:t,encode(o){return mr(o,r,n)},decode(o){return Ar(o,r,n,t)}}),_r=Bt({prefix:"\0",name:"identity",encode:t=>gr(t),decode:t=>pr(t)});var Ir=Object.freeze({__proto__:null,identity:_r});const Sr=$({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var vr=Object.freeze({__proto__:null,base2:Sr});const Tr=$({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ur=Object.freeze({__proto__:null,base8:Tr});const Nr=ht({prefix:"9",name:"base10",alphabet:"0123456789"});var Lr=Object.freeze({__proto__:null,base10:Nr});const Fr=$({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Or=$({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Hr=Object.freeze({__proto__:null,base16:Fr,base16upper:Or});const Mr=$({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),zr=$({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Rr=$({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),$r=$({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),qr=$({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),jr=$({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),kr=$({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Gr=$({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Zr=$({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Jr=Object.freeze({__proto__:null,base32:Mr,base32upper:zr,base32pad:Rr,base32padupper:$r,base32hex:qr,base32hexupper:jr,base32hexpad:kr,base32hexpadupper:Gr,base32z:Zr});const Wr=ht({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Vr=ht({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Yr=Object.freeze({__proto__:null,base36:Wr,base36upper:Vr});const Kr=ht({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Pr=ht({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Xr=Object.freeze({__proto__:null,base58btc:Kr,base58flickr:Pr});const Qr=$({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),to=$({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),eo=$({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),no=$({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ro=Object.freeze({__proto__:null,base64:Qr,base64pad:to,base64url:eo,base64urlpad:no});const Ue=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),oo=Ue.reduce((t,e,n)=>(t[n]=e,t),[]),so=Ue.reduce((t,e,n)=>(t[e.codePointAt(0)]=n,t),[]);function io(t){return t.reduce((e,n)=>(e+=oo[n],e),"")}function uo(t){const e=[];for(const n of t){const r=so[n.codePointAt(0)];if(r===void 0)throw new Error(`Non-base256emoji character: ${n}`);e.push(r)}return new Uint8Array(e)}const co=Bt({prefix:"\u{1F680}",name:"base256emoji",encode:io,decode:uo});var ao=Object.freeze({__proto__:null,base256emoji:co}),Do=Le,Ne=128,fo=127,lo=~fo,ho=Math.pow(2,31);function Le(t,e,n){e=e||[],n=n||0;for(var r=n;t>=ho;)e[n++]=t&255|Ne,t/=128;for(;t&lo;)e[n++]=t&255|Ne,t>>>=7;return e[n]=t|0,Le.bytes=n-r+1,e}var bo=Pt,Eo=128,Fe=127;function Pt(t,r){var n=0,r=r||0,o=0,s=r,a,u=t.length;do{if(s>=u)throw Pt.bytes=0,new RangeError("Could not decode varint");a=t[s++],n+=o<28?(a&Fe)<<o:(a&Fe)*Math.pow(2,o),o+=7}while(a>=Eo);return Pt.bytes=s-r,n}var wo=Math.pow(2,7),po=Math.pow(2,14),go=Math.pow(2,21),yo=Math.pow(2,28),Co=Math.pow(2,35),xo=Math.pow(2,42),Bo=Math.pow(2,49),Ao=Math.pow(2,56),mo=Math.pow(2,63),_o=function(t){return t<wo?1:t<po?2:t<go?3:t<yo?4:t<Co?5:t<xo?6:t<Bo?7:t<Ao?8:t<mo?9:10},Io={encode:Do,decode:bo,encodingLength:_o},Oe=Io;const He=(t,e,n=0)=>(Oe.encode(t,e,n),e),Me=t=>Oe.encodingLength(t),Xt=(t,e)=>{const n=e.byteLength,r=Me(t),o=r+Me(n),s=new Uint8Array(o+n);return He(t,s,0),He(n,s,r),s.set(e,o),new So(t,n,e,s)};class So{constructor(e,n,r,o){this.code=e,this.size=n,this.digest=r,this.bytes=o}}const ze=({name:t,code:e,encode:n})=>new vo(t,e,n);class vo{constructor(e,n,r){this.name=e,this.code=n,this.encode=r}digest(e){if(e instanceof Uint8Array){const n=this.encode(e);return n instanceof Uint8Array?Xt(this.code,n):n.then(r=>Xt(this.code,r))}else throw Error("Unknown type, must be binary type")}}const Re=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),To=ze({name:"sha2-256",code:18,encode:Re("SHA-256")}),Uo=ze({name:"sha2-512",code:19,encode:Re("SHA-512")});var No=Object.freeze({__proto__:null,sha256:To,sha512:Uo});const $e=0,Lo="identity",qe=ve;var Fo=Object.freeze({__proto__:null,identity:{code:$e,name:Lo,encode:qe,digest:t=>Xt($e,qe(t))}});new TextEncoder,new TextDecoder;const je={...Ir,...vr,...Ur,...Lr,...Hr,...Jr,...Yr,...Xr,...ro,...ao};({...No,...Fo});function ke(t,e,n,r){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:n},decoder:{decode:r}}}const Ge=ke("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Qt=ke("ascii","a",t=>{let e="a";for(let n=0;n<t.length;n++)e+=String.fromCharCode(t[n]);return e},t=>{t=t.substring(1);const e=Ie(t.length);for(let n=0;n<t.length;n++)e[n]=t.charCodeAt(n);return e}),Ze={utf8:Ge,"utf-8":Ge,hex:je.base16,latin1:Qt,ascii:Qt,binary:Qt,...je};function ut(t,e="utf8"){const n=Ze[e];if(!n)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("utf8"):n.encoder.encode(t).substring(1)}function nt(t,e="utf8"){const n=Ze[e];if(!n)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?Kt(globalThis.Buffer.from(t,"utf-8")):n.decoder.decode(`${n.prefix}${t}`)}const Oo=t=>JSON.stringify(t,(e,n)=>typeof n=="bigint"?n.toString()+"n":n),Ho=t=>{const e=new RegExp('(?<!")(?<=:)\\b(\\d{17,}|(?:[9](?:[1-9]07199254740991|0[1-9]7199254740991|00[8-9]199254740991|007[2-9]99254740991|007199[3-9]54740991|0071992[6-9]4740991|00719925[5-9]740991|007199254[8-9]40991|0071992547[5-9]0991|00719925474[1-9]991|00719925474099[2-9])))(?=[,\\}\\]]|$)',"g"),n=t.replace(e,r=>`"${r}n"`);return JSON.parse(n,(r,o)=>typeof o=="string"&&o.match(/^\d+n$/)?BigInt(o.substring(0,o.length-1)):o)};function Mo(t){if(typeof t!="string")throw new Error(`Cannot safe json parse value of type ${typeof t}`);try{return Ho(t)}catch(e){return console.error("safeJsonParse error:",e),t}}function zo(t){return typeof t=="string"?t:Oo(t)||""}function bt(t){return Mo(ut(nt(t,dt),Gt))}function Et(t){return ut(nt(zo(t),Gt),dt)}function Je(t){const e=nt(Yt,lt),n=Vt+ut(Se([e,t]),lt);return[Jt,Wt,n].join(Zt)}function We(t){const[e,n,r]=t.split(Zt);if(e!==Jt||n!==Wt)throw new Error('Issuer must be a DID with method "key"');if(r.slice(0,1)!==Vt)throw new Error("Issuer must be a key in mulicodec format");const o=nt(r.slice(1),lt);if(ut(o.slice(0,2),lt)!==Yt)throw new Error('Issuer must be a public key with type "Ed25519"');const s=o.slice(2);if(s.length!==me)throw new Error("Issuer must be a public key with length 32 bytes");return s}function Ve(t){return ut(t,dt)}function Ye(t){return nt(t,dt)}function Ke(t){return nt([Et(t.header),Et(t.payload)].join(it),xt)}function Ro(t){const e=ut(t,xt).split(it),n=bt(e[0]),r=bt(e[1]);return{header:n,payload:r}}function Pe(t){return[Et(t.header),Et(t.payload),Ve(t.signature)].join(it)}function Xe(t){const e=t.split(it),n=bt(e[0]),r=bt(e[1]),o=Ye(e[2]),s=nt(e.slice(0,2).join(it),xt);return{header:n,payload:r,signature:o,data:s}}function $o(t=ie(_e)){const e=qt.getPublicKey(t);return{secretKey:Se([t,e]),publicKey:e}}async function qo(t,e,n,r,o=hr(Date.now())){const s={alg:jt,typ:kt},a=Je(r.publicKey),u=o+n,i={iss:a,sub:t,aud:e,iat:o,exp:u},f=Ke({header:s,payload:i}),c=qt.sign(f,r.secretKey.slice(0,32));return Pe({header:s,payload:i,signature:c})}async function jo(t){const{header:e,payload:n,data:r,signature:o}=Xe(t);if(e.alg!==jt||e.typ!==kt)throw new Error("JWT must use EdDSA algorithm");const s=We(n.iss);return qt.verify(o,r,s)}x.DATA_ENCODING=xt,x.DID_DELIMITER=Zt,x.DID_METHOD=Wt,x.DID_PREFIX=Jt,x.JSON_ENCODING=Gt,x.JWT_DELIMITER=it,x.JWT_ENCODING=dt,x.JWT_IRIDIUM_ALG=jt,x.JWT_IRIDIUM_TYP=kt,x.KEY_PAIR_SEED_LENGTH=_e,x.MULTICODEC_ED25519_BASE=Vt,x.MULTICODEC_ED25519_ENCODING=lt,x.MULTICODEC_ED25519_HEADER=Yt,x.MULTICODEC_ED25519_LENGTH=me,x.decodeData=Ro,x.decodeIss=We,x.decodeJSON=bt,x.decodeJWT=Xe,x.decodeSig=Ye,x.encodeData=Ke,x.encodeIss=Je,x.encodeJSON=Et,x.encodeJWT=Pe,x.encodeSig=Ve,x.generateKeyPair=$o,x.signJWT=qo,x.verifyJWT=jo,Object.defineProperty(x,"__esModule",{value:!0})}); //# sourceMappingURL=index.umd.js.map