digiid-ts 2.0.4 → 3.0.0

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.
@@ -1,3 +1,3 @@
1
- (function(T,K){typeof exports=="object"&&typeof module<"u"?K(exports,require("crypto")):typeof define=="function"&&define.amd?define(["exports","crypto"],K):(T=typeof globalThis<"u"?globalThis:T||self,K(T.DigiIDTs={},T.crypto))})(this,function(T,K){"use strict";var sr=Object.defineProperty;var or=(T,K,D)=>K in T?sr(T,K,{enumerable:!0,configurable:!0,writable:!0,value:D}):T[K]=D;var x=(T,K,D)=>or(T,typeof K!="symbol"?K+"":K,D);class D extends Error{constructor(t){super(t),this.name="DigiIDError"}}/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Ht(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function ut(e,t=""){if(!Number.isSafeInteger(e)||e<0){const r=t&&`"${t}" `;throw new Error(`${r}expected integer >= 0, got ${e}`)}}function q(e,t,r=""){const n=Ht(e),s=e==null?void 0:e.length,o=t!==void 0;if(!n||o&&s!==t){const i=r&&`"${r}" `,c=o?` of length ${t}`:"",f=n?`length=${s}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+c+", got "+f)}return e}function Pt(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash must wrapped by utils.createHasher");ut(e.outputLen),ut(e.blockLen)}function yt(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Ye(e,t){q(e,void 0,"digestInto() output");const r=t.outputLen;if(e.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function mt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Dt(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Q(e,t){return e<<32-t|e>>>t}const Wt=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Ke=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function xt(e){if(q(e),Wt)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Ke[e[r]];return t}const et={_0:48,_9:57,A:65,F:70,a:97,f:102};function Qt(e){if(e>=et._0&&e<=et._9)return e-et._0;if(e>=et.A&&e<=et.F)return e-(et.A-10);if(e>=et.a&&e<=et.f)return e-(et.a-10)}function Et(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Wt)return Uint8Array.fromHex(e);const t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(r);for(let s=0,o=0;s<r;s++,o+=2){const i=Qt(e.charCodeAt(o)),c=Qt(e.charCodeAt(o+1));if(i===void 0||c===void 0){const f=e[o]+e[o+1];throw new Error('hex string expected, got non-hex character "'+f+'" at index '+o)}n[s]=i*16+c}return n}function rt(...e){let t=0;for(let n=0;n<e.length;n++){const s=e[n];q(s),t+=s.length}const r=new Uint8Array(t);for(let n=0,s=0;n<e.length;n++){const o=e[n];r.set(o,s),s+=o.length}return r}function Ge(e,t={}){const r=(s,o)=>e(o).update(s).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=s=>e(s),Object.assign(r,t),Object.freeze(r)}function Jt(e=32){const t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof(t==null?void 0:t.getRandomValues)!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(e))}const Xe=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function ze(e,t,r){return e&t^~e&r}function Fe(e,t,r){return e&t^e&r^t&r}let Pe=class{constructor(t,r,n,s){x(this,"blockLen");x(this,"outputLen");x(this,"padOffset");x(this,"isLE");x(this,"buffer");x(this,"view");x(this,"finished",!1);x(this,"length",0);x(this,"pos",0);x(this,"destroyed",!1);this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(t),this.view=Dt(this.buffer)}update(t){yt(this),q(t);const{view:r,buffer:n,blockLen:s}=this,o=t.length;for(let i=0;i<o;){const c=Math.min(s-this.pos,o-i);if(c===s){const f=Dt(t);for(;s<=o-i;i+=s)this.process(f,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===s&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){yt(this),Ye(t,this),this.finished=!0;const{buffer:r,view:n,blockLen:s,isLE:o}=this;let{pos:i}=this;r[i++]=128,mt(this.buffer.subarray(i)),this.padOffset>s-i&&(this.process(n,0),i=0);for(let d=i;d<s;d++)r[d]=0;n.setBigUint64(s-8,BigInt(this.length*8),o),this.process(n,0);const c=Dt(t),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen must be aligned to 32bit");const u=f/4,h=this.get();if(u>h.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<u;d++)c.setUint32(4*d,h[d],o)}digest(){const{buffer:t,outputLen:r}=this;this.digestInto(t);const n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:r,buffer:n,length:s,finished:o,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=o,t.length=s,t.pos=c,s%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}};const st=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),We=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),ot=new Uint32Array(64);class Qe extends Pe{constructor(t){super(64,t,8,!1)}get(){const{A:t,B:r,C:n,D:s,E:o,F:i,G:c,H:f}=this;return[t,r,n,s,o,i,c,f]}set(t,r,n,s,o,i,c,f){this.A=t|0,this.B=r|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=c|0,this.H=f|0}process(t,r){for(let d=0;d<16;d++,r+=4)ot[d]=t.getUint32(r,!1);for(let d=16;d<64;d++){const m=ot[d-15],g=ot[d-2],y=Q(m,7)^Q(m,18)^m>>>3,U=Q(g,17)^Q(g,19)^g>>>10;ot[d]=U+ot[d-7]+y+ot[d-16]|0}let{A:n,B:s,C:o,D:i,E:c,F:f,G:u,H:h}=this;for(let d=0;d<64;d++){const m=Q(c,6)^Q(c,11)^Q(c,25),g=h+m+ze(c,f,u)+We[d]+ot[d]|0,U=(Q(n,2)^Q(n,13)^Q(n,22))+Fe(n,s,o)|0;h=u,u=f,f=c,c=i+g|0,i=o,o=s,s=n,n=g+U|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,c=c+this.E|0,f=f+this.F|0,u=u+this.G|0,h=h+this.H|0,this.set(n,s,o,i,c,f,u,h)}roundClean(){mt(ot)}destroy(){this.set(0,0,0,0,0,0,0,0),mt(this.buffer)}}class Je extends Qe{constructor(){super(32);x(this,"A",st[0]|0);x(this,"B",st[1]|0);x(this,"C",st[2]|0);x(this,"D",st[3]|0);x(this,"E",st[4]|0);x(this,"F",st[5]|0);x(this,"G",st[6]|0);x(this,"H",st[7]|0)}}const tn=Ge(()=>new Je,Xe(1));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const qt=BigInt(0),Nt=BigInt(1);function Bt(e,t=""){if(typeof e!="boolean"){const r=t&&`"${t}" `;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function te(e){if(typeof e=="bigint"){if(!At(e))throw new Error("positive bigint expected, got "+e)}else ut(e);return e}function vt(e){const t=te(e).toString(16);return t.length&1?"0"+t:t}function ee(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?qt:BigInt("0x"+e)}function Rt(e){return ee(xt(e))}function ne(e){return ee(xt(en(q(e)).reverse()))}function kt(e,t){ut(t),e=te(e);const r=Et(e.toString(16).padStart(t*2,"0"));if(r.length!==t)throw new Error("number too large");return r}function re(e,t){return kt(e,t).reverse()}function en(e){return Uint8Array.from(e)}const At=e=>typeof e=="bigint"&&qt<=e;function nn(e,t,r){return At(e)&&At(t)&&At(r)&&t<=e&&e<r}function rn(e,t,r,n){if(!nn(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function sn(e){let t;for(t=0;e>qt;e>>=Nt,t+=1);return t}const $t=e=>(Nt<<BigInt(e))-Nt;function on(e,t,r){if(ut(e,"hashLen"),ut(t,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");const n=I=>new Uint8Array(I),s=Uint8Array.of(),o=Uint8Array.of(0),i=Uint8Array.of(1),c=1e3;let f=n(e),u=n(e),h=0;const d=()=>{f.fill(1),u.fill(0),h=0},m=(...I)=>r(u,rt(f,...I)),g=(I=s)=>{u=m(o,I),f=m(),I.length!==0&&(u=m(i,I),f=m())},y=()=>{if(h++>=c)throw new Error("drbg: tried max amount of iterations");let I=0;const O=[];for(;I<t;){f=m();const G=f.slice();O.push(G),I+=f.length}return rt(...O)};return(I,O)=>{d(),g(I);let G;for(;!(G=O(y()));)g();return d(),G}}function Zt(e,t={},r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,i,c){const f=e[o];if(c&&f===void 0)return;const u=typeof f;if(u!==i||f===null)throw new Error(`param "${o}" is invalid: expected ${i}, got ${u}`)}const s=(o,i)=>Object.entries(o).forEach(([c,f])=>n(c,f,i));s(t,!1),s(r,!0)}function se(e){const t=new WeakMap;return(r,...n)=>{const s=t.get(r);if(s!==void 0)return s;const o=e(r,...n);return t.set(r,o),o}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Y=BigInt(0),V=BigInt(1),at=BigInt(2),oe=BigInt(3),ie=BigInt(4),ce=BigInt(5),cn=BigInt(7),fe=BigInt(8),fn=BigInt(9),ue=BigInt(16);function P(e,t){const r=e%t;return r>=Y?r:t+r}function z(e,t,r){let n=e;for(;t-- >Y;)n*=n,n%=r;return n}function ae(e,t){if(e===Y)throw new Error("invert: expected non-zero number");if(t<=Y)throw new Error("invert: expected positive modulus, got "+t);let r=P(e,t),n=t,s=Y,o=V;for(;r!==Y;){const c=n/r,f=n%r,u=s-o*c;n=r,r=f,s=o,o=u}if(n!==V)throw new Error("invert: does not exist");return P(s,t)}function Tt(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function le(e,t){const r=(e.ORDER+V)/ie,n=e.pow(t,r);return Tt(e,n,t),n}function un(e,t){const r=(e.ORDER-ce)/fe,n=e.mul(t,at),s=e.pow(n,r),o=e.mul(t,s),i=e.mul(e.mul(o,at),s),c=e.mul(o,e.sub(i,e.ONE));return Tt(e,c,t),c}function an(e){const t=It(e),r=de(e),n=r(t,t.neg(t.ONE)),s=r(t,n),o=r(t,t.neg(n)),i=(e+cn)/ue;return(c,f)=>{let u=c.pow(f,i),h=c.mul(u,n);const d=c.mul(u,s),m=c.mul(u,o),g=c.eql(c.sqr(h),f),y=c.eql(c.sqr(d),f);u=c.cmov(u,h,g),h=c.cmov(m,d,y);const U=c.eql(c.sqr(h),f),I=c.cmov(u,h,U);return Tt(c,I,f),I}}function de(e){if(e<oe)throw new Error("sqrt is not defined for small field");let t=e-V,r=0;for(;t%at===Y;)t/=at,r++;let n=at;const s=It(e);for(;ge(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return le;let o=s.pow(n,t);const i=(t+V)/at;return function(f,u){if(f.is0(u))return u;if(ge(f,u)!==1)throw new Error("Cannot find square root");let h=r,d=f.mul(f.ONE,o),m=f.pow(u,t),g=f.pow(u,i);for(;!f.eql(m,f.ONE);){if(f.is0(m))return f.ZERO;let y=1,U=f.sqr(m);for(;!f.eql(U,f.ONE);)if(y++,U=f.sqr(U),y===h)throw new Error("Cannot find square root");const I=V<<BigInt(h-y-1),O=f.pow(d,I);h=y,d=f.sqr(O),m=f.mul(m,d),g=f.mul(g,O)}return g}}function ln(e){return e%ie===oe?le:e%fe===ce?un:e%ue===fn?an(e):de(e)}const dn=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function hn(e){const t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=dn.reduce((n,s)=>(n[s]="function",n),t);return Zt(e,r),e}function gn(e,t,r){if(r<Y)throw new Error("invalid exponent, negatives unsupported");if(r===Y)return e.ONE;if(r===V)return t;let n=e.ONE,s=t;for(;r>Y;)r&V&&(n=e.mul(n,s)),s=e.sqr(s),r>>=V;return n}function he(e,t,r=!1){const n=new Array(t.length).fill(r?e.ZERO:void 0),s=t.reduce((i,c,f)=>e.is0(c)?i:(n[f]=i,e.mul(i,c)),e.ONE),o=e.inv(s);return t.reduceRight((i,c,f)=>e.is0(c)?i:(n[f]=e.mul(i,n[f]),e.mul(i,c)),o),n}function ge(e,t){const r=(e.ORDER-V)/at,n=e.pow(t,r),s=e.eql(n,e.ONE),o=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!s&&!o&&!i)throw new Error("invalid Legendre symbol result");return s?1:o?0:-1}function wn(e,t){t!==void 0&&ut(t);const r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}class bn{constructor(t,r={}){x(this,"ORDER");x(this,"BITS");x(this,"BYTES");x(this,"isLE");x(this,"ZERO",Y);x(this,"ONE",V);x(this,"_lengths");x(this,"_sqrt");x(this,"_mod");var i;if(t<=Y)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&(this.sqrt=r.sqrt),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=(i=r.allowedLengths)==null?void 0:i.slice()),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));const{nBitLength:s,nByteLength:o}=wn(t,n);if(o>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=s,this.BYTES=o,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return P(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return Y<=t&&t<this.ORDER}is0(t){return t===Y}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&V)===V}neg(t){return P(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return P(t*t,this.ORDER)}add(t,r){return P(t+r,this.ORDER)}sub(t,r){return P(t-r,this.ORDER)}mul(t,r){return P(t*r,this.ORDER)}pow(t,r){return gn(this,t,r)}div(t,r){return P(t*ae(r,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,r){return t+r}subN(t,r){return t-r}mulN(t,r){return t*r}inv(t){return ae(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=ln(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?re(t,this.BYTES):kt(t,this.BYTES)}fromBytes(t,r=!1){q(t);const{_lengths:n,BYTES:s,isLE:o,ORDER:i,_mod:c}=this;if(n){if(!n.includes(t.length)||t.length>s)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);const u=new Uint8Array(s);u.set(t,o?0:u.length-t.length),t=u}if(t.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+t.length);let f=o?ne(t):Rt(t);if(c&&(f=P(f,i)),!r&&!this.isValid(f))throw new Error("invalid field element: outside of range 0..ORDER");return f}invertBatch(t){return he(this,t)}cmov(t,r,n){return n?r:t}}function It(e,t={}){return new bn(e,t)}function we(e){if(typeof e!="bigint")throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function be(e){const t=we(e);return t+Math.ceil(t/2)}function pn(e,t,r=!1){q(e);const n=e.length,s=we(t),o=be(t);if(n<16||n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);const i=r?ne(e):Rt(e),c=P(i,t-V)+V;return r?re(c,s):kt(c,s)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ht=BigInt(0),lt=BigInt(1);function St(e,t){const r=t.negate();return e?r:t}function pe(e,t){const r=he(e.Fp,t.map(n=>n.Z));return t.map((n,s)=>e.fromAffine(n.toAffine(r[s])))}function ye(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Ct(e,t){ye(e,t);const r=Math.ceil(t/e)+1,n=2**(e-1),s=2**e,o=$t(e),i=BigInt(e);return{windows:r,windowSize:n,mask:o,maxNumber:s,shiftBy:i}}function me(e,t,r){const{windowSize:n,mask:s,maxNumber:o,shiftBy:i}=r;let c=Number(e&s),f=e>>i;c>n&&(c-=o,f+=lt);const u=t*n,h=u+Math.abs(c)-1,d=c===0,m=c<0,g=t%2!==0;return{nextN:f,offset:h,isZero:d,isNeg:m,isNegF:g,offsetF:u}}const Vt=new WeakMap,xe=new WeakMap;function Mt(e){return xe.get(e)||1}function Ee(e){if(e!==ht)throw new Error("invalid wNAF")}class yn{constructor(t,r){x(this,"BASE");x(this,"ZERO");x(this,"Fn");x(this,"bits");this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let s=t;for(;r>ht;)r&lt&&(n=n.add(s)),s=s.double(),r>>=lt;return n}precomputeWindow(t,r){const{windows:n,windowSize:s}=Ct(r,this.bits),o=[];let i=t,c=i;for(let f=0;f<n;f++){c=i,o.push(c);for(let u=1;u<s;u++)c=c.add(i),o.push(c);i=c.double()}return o}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let s=this.ZERO,o=this.BASE;const i=Ct(t,this.bits);for(let c=0;c<i.windows;c++){const{nextN:f,offset:u,isZero:h,isNeg:d,isNegF:m,offsetF:g}=me(n,c,i);n=f,h?o=o.add(St(m,r[g])):s=s.add(St(d,r[u]))}return Ee(n),{p:s,f:o}}wNAFUnsafe(t,r,n,s=this.ZERO){const o=Ct(t,this.bits);for(let i=0;i<o.windows&&n!==ht;i++){const{nextN:c,offset:f,isZero:u,isNeg:h}=me(n,i,o);if(n=c,!u){const d=r[f];s=s.add(h?d.negate():d)}}return Ee(n),s}getPrecomputes(t,r,n){let s=Vt.get(r);return s||(s=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(s=n(s)),Vt.set(r,s))),s}cached(t,r,n){const s=Mt(t);return this.wNAF(s,this.getPrecomputes(s,t,n),r)}unsafe(t,r,n,s){const o=Mt(t);return o===1?this._unsafeLadder(t,r,s):this.wNAFUnsafe(o,this.getPrecomputes(o,t,n),r,s)}createCache(t,r){ye(r,this.bits),xe.set(t,r),Vt.delete(t)}hasCache(t){return Mt(t)!==1}}function mn(e,t,r,n){let s=t,o=e.ZERO,i=e.ZERO;for(;r>ht||n>ht;)r&lt&&(o=o.add(s)),n&lt&&(i=i.add(s)),s=s.double(),r>>=lt,n>>=lt;return{p1:o,p2:i}}function Be(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return hn(t),t}else return It(e,{isLE:r})}function xn(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(const f of["p","n","h"]){const u=t[f];if(!(typeof u=="bigint"&&u>ht))throw new Error(`CURVE.${f} must be positive bigint`)}const s=Be(t.p,r.Fp,n),o=Be(t.n,r.Fn,n),c=["Gx","Gy","a","b"];for(const f of c)if(!s.isValid(t[f]))throw new Error(`CURVE.${f} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:s,Fn:o}}function En(e,t){return function(n){const s=e(n);return{secretKey:s,publicKey:t(s)}}}class ve{constructor(t,r){x(this,"oHash");x(this,"iHash");x(this,"blockLen");x(this,"outputLen");x(this,"finished",!1);x(this,"destroyed",!1);if(Pt(t),q(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const n=this.blockLen,s=new Uint8Array(n);s.set(r.length>n?t.create().update(r).digest():r);for(let o=0;o<s.length;o++)s[o]^=54;this.iHash.update(s),this.oHash=t.create();for(let o=0;o<s.length;o++)s[o]^=106;this.oHash.update(s),mt(s)}update(t){return yt(this),this.iHash.update(t),this}digestInto(t){yt(this),q(t,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){const t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));const{oHash:r,iHash:n,finished:s,destroyed:o,blockLen:i,outputLen:c}=this;return t=t,t.finished=s,t.destroyed=o,t.blockLen=i,t.outputLen=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const Re=(e,t,r)=>new ve(e,t).update(r).digest();Re.create=(e,t)=>new ve(e,t);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Ae=(e,t)=>(e+(e>=0?t:-t)/Ie)/t;function Bn(e,t,r){const[[n,s],[o,i]]=t,c=Ae(i*e,r),f=Ae(-s*e,r);let u=e-c*n-f*o,h=-c*s-f*i;const d=u<nt,m=h<nt;d&&(u=-u),m&&(h=-h);const g=$t(Math.ceil(sn(r)/2))+gt;if(u<nt||u>=g||h<nt||h>=g)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:d,k1:u,k2neg:m,k2:h}}function jt(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Yt(e,t){const r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return Bt(r.lowS,"lowS"),Bt(r.prehash,"prehash"),r.format!==void 0&&jt(r.format),r}class vn extends Error{constructor(t=""){super(t)}}const it={Err:vn,_tlv:{encode:(e,t)=>{const{Err:r}=it;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");const n=t.length/2,s=vt(n);if(s.length/2&128)throw new r("tlv.encode: long form length too big");const o=n>127?vt(s.length/2|128):"";return vt(e)+o+s+t},decode(e,t){const{Err:r}=it;let n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");const s=t[n++],o=!!(s&128);let i=0;if(!o)i=s;else{const f=s&127;if(!f)throw new r("tlv.decode(long): indefinite length not supported");if(f>4)throw new r("tlv.decode(long): byte length is too big");const u=t.subarray(n,n+f);if(u.length!==f)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(const h of u)i=i<<8|h;if(n+=f,i<128)throw new r("tlv.decode(long): not minimal encoding")}const c=t.subarray(n,n+i);if(c.length!==i)throw new r("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(e){const{Err:t}=it;if(e<nt)throw new t("integer: negative integers are not allowed");let r=vt(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){const{Err:t}=it;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Rt(e)}},toSig(e){const{Err:t,_int:r,_tlv:n}=it,s=q(e,void 0,"signature"),{v:o,l:i}=n.decode(48,s);if(i.length)throw new t("invalid signature: left bytes after parsing");const{v:c,l:f}=n.decode(2,o),{v:u,l:h}=n.decode(2,f);if(h.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(u)}},hexFromSig(e){const{_tlv:t,_int:r}=it,n=t.encode(2,r.encode(e.r)),s=t.encode(2,r.encode(e.s)),o=n+s;return t.encode(48,o)}},nt=BigInt(0),gt=BigInt(1),Ie=BigInt(2),Ut=BigInt(3),Rn=BigInt(4);function An(e,t={}){const r=xn("weierstrass",e,t),{Fp:n,Fn:s}=r;let o=r.CURVE;const{h:i,n:c}=o;Zt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});const{endo:f}=t;if(f&&(!n.is0(o.a)||typeof f.beta!="bigint"||!Array.isArray(f.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const u=Ue(n,s);function h(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function d(L,l,a){const{x:w,y:p}=l.toAffine(),B=n.toBytes(w);if(Bt(a,"isCompressed"),a){h();const E=!n.isOdd(p);return rt(Se(E),B)}else return rt(Uint8Array.of(4),B,n.toBytes(p))}function m(L){q(L,void 0,"Point");const{publicKey:l,publicKeyUncompressed:a}=u,w=L.length,p=L[0],B=L.subarray(1);if(w===l&&(p===2||p===3)){const E=n.fromBytes(B);if(!n.isValid(E))throw new Error("bad point: is not on curve, wrong x");const v=U(E);let b;try{b=n.sqrt(v)}catch(k){const H=k instanceof Error?": "+k.message:"";throw new Error("bad point: is not on curve, sqrt error"+H)}h();const R=n.isOdd(b);return(p&1)===1!==R&&(b=n.neg(b)),{x:E,y:b}}else if(w===a&&p===4){const E=n.BYTES,v=n.fromBytes(B.subarray(0,E)),b=n.fromBytes(B.subarray(E,E*2));if(!I(v,b))throw new Error("bad point: is not on curve");return{x:v,y:b}}else throw new Error(`bad point: got length ${w}, expected compressed=${l} or uncompressed=${a}`)}const g=t.toBytes||d,y=t.fromBytes||m;function U(L){const l=n.sqr(L),a=n.mul(l,L);return n.add(n.add(a,n.mul(L,o.a)),o.b)}function I(L,l){const a=n.sqr(l),w=U(L);return n.eql(a,w)}if(!I(o.Gx,o.Gy))throw new Error("bad curve params: generator point");const O=n.mul(n.pow(o.a,Ut),Rn),G=n.mul(n.sqr(o.b),BigInt(27));if(n.is0(n.add(O,G)))throw new Error("bad curve params: a or b");function tt(L,l,a=!1){if(!n.isValid(l)||a&&n.is0(l))throw new Error(`bad point coordinate ${L}`);return l}function C(L){if(!(L instanceof W))throw new Error("Weierstrass Point expected")}function $(L){if(!f||!f.basises)throw new Error("no endo");return Bn(L,f.basises,s.ORDER)}const F=se((L,l)=>{const{X:a,Y:w,Z:p}=L;if(n.eql(p,n.ONE))return{x:a,y:w};const B=L.is0();l==null&&(l=B?n.ONE:n.inv(p));const E=n.mul(a,l),v=n.mul(w,l),b=n.mul(p,l);if(B)return{x:n.ZERO,y:n.ZERO};if(!n.eql(b,n.ONE))throw new Error("invZ was invalid");return{x:E,y:v}}),Ft=se(L=>{if(L.is0()){if(t.allowInfinityPoint&&!n.is0(L.Y))return;throw new Error("bad point: ZERO")}const{x:l,y:a}=L.toAffine();if(!n.isValid(l)||!n.isValid(a))throw new Error("bad point: x or y not field elements");if(!I(l,a))throw new Error("bad point: equation left != right");if(!L.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function pt(L,l,a,w,p){return a=new W(n.mul(a.X,L),a.Y,a.Z),l=St(w,l),a=St(p,a),l.add(a)}const _=class _{constructor(l,a,w){x(this,"X");x(this,"Y");x(this,"Z");this.X=tt("x",l),this.Y=tt("y",a,!0),this.Z=tt("z",w),Object.freeze(this)}static CURVE(){return o}static fromAffine(l){const{x:a,y:w}=l||{};if(!l||!n.isValid(a)||!n.isValid(w))throw new Error("invalid affine point");if(l instanceof _)throw new Error("projective point not allowed");return n.is0(a)&&n.is0(w)?_.ZERO:new _(a,w,n.ONE)}static fromBytes(l){const a=_.fromAffine(y(q(l,void 0,"point")));return a.assertValidity(),a}static fromHex(l){return _.fromBytes(Et(l))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(l=8,a=!0){return dt.createCache(this,l),a||this.multiply(Ut),this}assertValidity(){Ft(this)}hasEvenY(){const{y:l}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(l)}equals(l){C(l);const{X:a,Y:w,Z:p}=this,{X:B,Y:E,Z:v}=l,b=n.eql(n.mul(a,v),n.mul(B,p)),R=n.eql(n.mul(w,v),n.mul(E,p));return b&&R}negate(){return new _(this.X,n.neg(this.Y),this.Z)}double(){const{a:l,b:a}=o,w=n.mul(a,Ut),{X:p,Y:B,Z:E}=this;let v=n.ZERO,b=n.ZERO,R=n.ZERO,S=n.mul(p,p),k=n.mul(B,B),H=n.mul(E,E),A=n.mul(p,B);return A=n.add(A,A),R=n.mul(p,E),R=n.add(R,R),v=n.mul(l,R),b=n.mul(w,H),b=n.add(v,b),v=n.sub(k,b),b=n.add(k,b),b=n.mul(v,b),v=n.mul(A,v),R=n.mul(w,R),H=n.mul(l,H),A=n.sub(S,H),A=n.mul(l,A),A=n.add(A,R),R=n.add(S,S),S=n.add(R,S),S=n.add(S,H),S=n.mul(S,A),b=n.add(b,S),H=n.mul(B,E),H=n.add(H,H),S=n.mul(H,A),v=n.sub(v,S),R=n.mul(H,k),R=n.add(R,R),R=n.add(R,R),new _(v,b,R)}add(l){C(l);const{X:a,Y:w,Z:p}=this,{X:B,Y:E,Z:v}=l;let b=n.ZERO,R=n.ZERO,S=n.ZERO;const k=o.a,H=n.mul(o.b,Ut);let A=n.mul(a,B),Z=n.mul(w,E),M=n.mul(p,v),X=n.add(a,w),N=n.add(B,E);X=n.mul(X,N),N=n.add(A,Z),X=n.sub(X,N),N=n.add(a,p);let j=n.add(B,v);return N=n.mul(N,j),j=n.add(A,M),N=n.sub(N,j),j=n.add(w,p),b=n.add(E,v),j=n.mul(j,b),b=n.add(Z,M),j=n.sub(j,b),S=n.mul(k,N),b=n.mul(H,M),S=n.add(b,S),b=n.sub(Z,S),S=n.add(Z,S),R=n.mul(b,S),Z=n.add(A,A),Z=n.add(Z,A),M=n.mul(k,M),N=n.mul(H,N),Z=n.add(Z,M),M=n.sub(A,M),M=n.mul(k,M),N=n.add(N,M),A=n.mul(Z,N),R=n.add(R,A),A=n.mul(j,N),b=n.mul(X,b),b=n.sub(b,A),A=n.mul(X,Z),S=n.mul(j,S),S=n.add(S,A),new _(b,R,S)}subtract(l){return this.add(l.negate())}is0(){return this.equals(_.ZERO)}multiply(l){const{endo:a}=t;if(!s.isValidNot0(l))throw new Error("invalid scalar: out of range");let w,p;const B=E=>dt.cached(this,E,v=>pe(_,v));if(a){const{k1neg:E,k1:v,k2neg:b,k2:R}=$(l),{p:S,f:k}=B(v),{p:H,f:A}=B(R);p=k.add(A),w=pt(a.beta,S,H,E,b)}else{const{p:E,f:v}=B(l);w=E,p=v}return pe(_,[w,p])[0]}multiplyUnsafe(l){const{endo:a}=t,w=this;if(!s.isValid(l))throw new Error("invalid scalar: out of range");if(l===nt||w.is0())return _.ZERO;if(l===gt)return w;if(dt.hasCache(this))return this.multiply(l);if(a){const{k1neg:p,k1:B,k2neg:E,k2:v}=$(l),{p1:b,p2:R}=mn(_,w,B,v);return pt(a.beta,b,R,p,E)}else return dt.unsafe(w,l)}toAffine(l){return F(this,l)}isTorsionFree(){const{isTorsionFree:l}=t;return i===gt?!0:l?l(_,this):dt.unsafe(this,c).is0()}clearCofactor(){const{clearCofactor:l}=t;return i===gt?this:l?l(_,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(l=!0){return Bt(l,"isCompressed"),this.assertValidity(),g(_,this,l)}toHex(l=!0){return xt(this.toBytes(l))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}};x(_,"BASE",new _(o.Gx,o.Gy,n.ONE)),x(_,"ZERO",new _(n.ZERO,n.ONE,n.ZERO)),x(_,"Fp",n),x(_,"Fn",s);let W=_;const Ot=s.BITS,dt=new yn(W,t.endo?Math.ceil(Ot/2):Ot);return W.BASE.precompute(8),W}function Se(e){return Uint8Array.of(e?2:3)}function Ue(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function In(e,t={}){const{Fn:r}=e,n=t.randomBytes||Jt,s=Object.assign(Ue(e.Fp,r),{seed:be(r.ORDER)});function o(g){try{const y=r.fromBytes(g);return r.isValidNot0(y)}catch{return!1}}function i(g,y){const{publicKey:U,publicKeyUncompressed:I}=s;try{const O=g.length;return y===!0&&O!==U||y===!1&&O!==I?!1:!!e.fromBytes(g)}catch{return!1}}function c(g=n(s.seed)){return pn(q(g,s.seed,"seed"),r.ORDER)}function f(g,y=!0){return e.BASE.multiply(r.fromBytes(g)).toBytes(y)}function u(g){const{secretKey:y,publicKey:U,publicKeyUncompressed:I}=s;if(!Ht(g)||"_lengths"in r&&r._lengths||y===U)return;const O=q(g,void 0,"key").length;return O===U||O===I}function h(g,y,U=!0){if(u(g)===!0)throw new Error("first arg must be private key");if(u(y)===!1)throw new Error("second arg must be public key");const I=r.fromBytes(g);return e.fromBytes(y).multiply(I).toBytes(U)}const d={isValidSecretKey:o,isValidPublicKey:i,randomSecretKey:c},m=En(c,f);return Object.freeze({getPublicKey:f,getSharedSecret:h,keygen:m,Point:e,utils:d,lengths:s})}function Sn(e,t,r={}){Pt(t),Zt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);const n=r.randomBytes||Jt,s=r.hmac||((l,a)=>Re(t,l,a)),{Fp:o,Fn:i}=e,{ORDER:c,BITS:f}=i,{keygen:u,getPublicKey:h,getSharedSecret:d,utils:m,lengths:g}=In(e,r),y={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},U=c*Ie<o.ORDER;function I(l){const a=c>>gt;return l>a}function O(l,a){if(!i.isValidNot0(a))throw new Error(`invalid signature ${l}: out of range 1..Point.Fn.ORDER`);return a}function G(){if(U)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function tt(l,a){jt(a);const w=g.signature,p=a==="compact"?w:a==="recovered"?w+1:void 0;return q(l,p)}class C{constructor(a,w,p){x(this,"r");x(this,"s");x(this,"recovery");if(this.r=O("r",a),this.s=O("s",w),p!=null){if(G(),![0,1,2,3].includes(p))throw new Error("invalid recovery id");this.recovery=p}Object.freeze(this)}static fromBytes(a,w=y.format){tt(a,w);let p;if(w==="der"){const{r:b,s:R}=it.toSig(q(a));return new C(b,R)}w==="recovered"&&(p=a[0],w="compact",a=a.subarray(1));const B=g.signature/2,E=a.subarray(0,B),v=a.subarray(B,B*2);return new C(i.fromBytes(E),i.fromBytes(v),p)}static fromHex(a,w){return this.fromBytes(Et(a),w)}assertRecovery(){const{recovery:a}=this;if(a==null)throw new Error("invalid recovery id: must be present");return a}addRecoveryBit(a){return new C(this.r,this.s,a)}recoverPublicKey(a){const{r:w,s:p}=this,B=this.assertRecovery(),E=B===2||B===3?w+c:w;if(!o.isValid(E))throw new Error("invalid recovery id: sig.r+curve.n != R.x");const v=o.toBytes(E),b=e.fromBytes(rt(Se((B&1)===0),v)),R=i.inv(E),S=F(q(a,void 0,"msgHash")),k=i.create(-S*R),H=i.create(p*R),A=e.BASE.multiplyUnsafe(k).add(b.multiplyUnsafe(H));if(A.is0())throw new Error("invalid recovery: point at infinify");return A.assertValidity(),A}hasHighS(){return I(this.s)}toBytes(a=y.format){if(jt(a),a==="der")return Et(it.hexFromSig(this));const{r:w,s:p}=this,B=i.toBytes(w),E=i.toBytes(p);return a==="recovered"?(G(),rt(Uint8Array.of(this.assertRecovery()),B,E)):rt(B,E)}toHex(a){return xt(this.toBytes(a))}}const $=r.bits2int||function(a){if(a.length>8192)throw new Error("input is too large");const w=Rt(a),p=a.length*8-f;return p>0?w>>BigInt(p):w},F=r.bits2int_modN||function(a){return i.create($(a))},Ft=$t(f);function pt(l){return rn("num < 2^"+f,l,nt,Ft),i.toBytes(l)}function W(l,a){return q(l,void 0,"message"),a?q(t(l),void 0,"prehashed message"):l}function Ot(l,a,w){const{lowS:p,prehash:B,extraEntropy:E}=Yt(w,y);l=W(l,B);const v=F(l),b=i.fromBytes(a);if(!i.isValidNot0(b))throw new Error("invalid private key");const R=[pt(b),pt(v)];if(E!=null&&E!==!1){const A=E===!0?n(g.secretKey):E;R.push(q(A,void 0,"extraEntropy"))}const S=rt(...R),k=v;function H(A){const Z=$(A);if(!i.isValidNot0(Z))return;const M=i.inv(Z),X=e.BASE.multiply(Z).toAffine(),N=i.create(X.x);if(N===nt)return;const j=i.create(M*i.create(k+N*b));if(j===nt)return;let Me=(X.x===N?0:2)|Number(X.y&gt),je=j;return p&&I(j)&&(je=i.neg(j),Me^=1),new C(N,je,U?void 0:Me)}return{seed:S,k2sig:H}}function dt(l,a,w={}){const{seed:p,k2sig:B}=Ot(l,a,w);return on(t.outputLen,i.BYTES,s)(p,B).toBytes(w.format)}function _(l,a,w,p={}){const{lowS:B,prehash:E,format:v}=Yt(p,y);if(w=q(w,void 0,"publicKey"),a=W(a,E),!Ht(l)){const b=l instanceof C?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+b)}tt(l,v);try{const b=C.fromBytes(l,v),R=e.fromBytes(w);if(B&&b.hasHighS())return!1;const{r:S,s:k}=b,H=F(a),A=i.inv(k),Z=i.create(H*A),M=i.create(S*A),X=e.BASE.multiplyUnsafe(Z).add(R.multiplyUnsafe(M));return X.is0()?!1:i.create(X.x)===S}catch{return!1}}function L(l,a,w={}){const{prehash:p}=Yt(w,y);return a=W(a,p),C.fromBytes(l,"recovered").recoverPublicKey(a).toBytes()}return Object.freeze({keygen:u,getPublicKey:h,getSharedSecret:d,utils:m,lengths:g,Point:e,sign:dt,verify:_,recoverPublicKey:L,Signature:C,hash:t})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Kt={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Un={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},Le=BigInt(2);function Ln(e){const t=Kt.p,r=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),c=BigInt(44),f=BigInt(88),u=e*e*e%t,h=u*u*e%t,d=z(h,r,t)*h%t,m=z(d,r,t)*h%t,g=z(m,Le,t)*u%t,y=z(g,s,t)*g%t,U=z(y,o,t)*y%t,I=z(U,c,t)*U%t,O=z(I,f,t)*I%t,G=z(O,c,t)*U%t,tt=z(G,r,t)*h%t,C=z(tt,i,t)*y%t,$=z(C,n,t)*u%t,F=z($,Le,t);if(!Gt.eql(Gt.sqr(F),e))throw new Error("Cannot find square root");return F}const Gt=It(Kt.p,{sqrt:Ln}),_n=Sn(An(Kt,{Fp:Gt,endo:Un}),tn);/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function On(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Xt(e,...t){if(!On(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function _e(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Hn(e,t){Xt(e);const r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function wt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function zt(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function J(e,t){return e<<32-t|e>>>t}function Lt(e,t){return e<<t|e>>>32-t>>>0}function Dn(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function Oe(e){return typeof e=="string"&&(e=Dn(e)),Xt(e),e}class qn{}function He(e){const t=n=>e().update(Oe(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Nn(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);const s=BigInt(32),o=BigInt(4294967295),i=Number(r>>s&o),c=Number(r&o),f=n?4:0,u=n?0:4;e.setUint32(t+f,i,n),e.setUint32(t+u,c,n)}function kn(e,t,r){return e&t^~e&r}function $n(e,t,r){return e&t^e&r^t&r}class De extends qn{constructor(t,r,n,s){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(t),this.view=zt(this.buffer)}update(t){_e(this),t=Oe(t),Xt(t);const{view:r,buffer:n,blockLen:s}=this,o=t.length;for(let i=0;i<o;){const c=Math.min(s-this.pos,o-i);if(c===s){const f=zt(t);for(;s<=o-i;i+=s)this.process(f,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===s&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){_e(this),Hn(t,this),this.finished=!0;const{buffer:r,view:n,blockLen:s,isLE:o}=this;let{pos:i}=this;r[i++]=128,wt(this.buffer.subarray(i)),this.padOffset>s-i&&(this.process(n,0),i=0);for(let d=i;d<s;d++)r[d]=0;Nn(n,s-8,BigInt(this.length*8),o),this.process(n,0);const c=zt(t),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const u=f/4,h=this.get();if(u>h.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<u;d++)c.setUint32(4*d,h[d],o)}digest(){const{buffer:t,outputLen:r}=this;this.digestInto(t);const n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:r,buffer:n,length:s,finished:o,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=o,t.length=s,t.pos=c,s%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}}const ct=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Zn=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),qe=Uint8Array.from(new Array(16).fill(0).map((e,t)=>t)),Tn=qe.map(e=>(9*e+5)%16),Ne=(()=>{const r=[[qe],[Tn]];for(let n=0;n<4;n++)for(let s of r)s.push(s[n].map(o=>Zn[o]));return r})(),ke=Ne[0],$e=Ne[1],Ze=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(e=>Uint8Array.from(e)),Cn=ke.map((e,t)=>e.map(r=>Ze[t][r])),Vn=$e.map((e,t)=>e.map(r=>Ze[t][r])),Mn=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),jn=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function Te(e,t,r,n){return e===0?t^r^n:e===1?t&r|~t&n:e===2?(t|~r)^n:e===3?t&n|r&~n:t^(r|~n)}const _t=new Uint32Array(16);class Yn extends De{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:t,h1:r,h2:n,h3:s,h4:o}=this;return[t,r,n,s,o]}set(t,r,n,s,o){this.h0=t|0,this.h1=r|0,this.h2=n|0,this.h3=s|0,this.h4=o|0}process(t,r){for(let g=0;g<16;g++,r+=4)_t[g]=t.getUint32(r,!0);let n=this.h0|0,s=n,o=this.h1|0,i=o,c=this.h2|0,f=c,u=this.h3|0,h=u,d=this.h4|0,m=d;for(let g=0;g<5;g++){const y=4-g,U=Mn[g],I=jn[g],O=ke[g],G=$e[g],tt=Cn[g],C=Vn[g];for(let $=0;$<16;$++){const F=Lt(n+Te(g,o,c,u)+_t[O[$]]+U,tt[$])+d|0;n=d,d=u,u=Lt(c,10)|0,c=o,o=F}for(let $=0;$<16;$++){const F=Lt(s+Te(y,i,f,h)+_t[G[$]]+I,C[$])+m|0;s=m,m=h,h=Lt(f,10)|0,f=i,i=F}}this.set(this.h1+c+h|0,this.h2+u+m|0,this.h3+d+s|0,this.h4+n+i|0,this.h0+o+f|0)}roundClean(){wt(_t)}destroy(){this.destroyed=!0,wt(this.buffer),this.set(0,0,0,0,0)}}const Kn=He(()=>new Yn),Gn=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),ft=new Uint32Array(64);class Xn extends De{constructor(t=32){super(64,t,8,!1),this.A=ct[0]|0,this.B=ct[1]|0,this.C=ct[2]|0,this.D=ct[3]|0,this.E=ct[4]|0,this.F=ct[5]|0,this.G=ct[6]|0,this.H=ct[7]|0}get(){const{A:t,B:r,C:n,D:s,E:o,F:i,G:c,H:f}=this;return[t,r,n,s,o,i,c,f]}set(t,r,n,s,o,i,c,f){this.A=t|0,this.B=r|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=c|0,this.H=f|0}process(t,r){for(let d=0;d<16;d++,r+=4)ft[d]=t.getUint32(r,!1);for(let d=16;d<64;d++){const m=ft[d-15],g=ft[d-2],y=J(m,7)^J(m,18)^m>>>3,U=J(g,17)^J(g,19)^g>>>10;ft[d]=U+ft[d-7]+y+ft[d-16]|0}let{A:n,B:s,C:o,D:i,E:c,F:f,G:u,H:h}=this;for(let d=0;d<64;d++){const m=J(c,6)^J(c,11)^J(c,25),g=h+m+kn(c,f,u)+Gn[d]+ft[d]|0,U=(J(n,2)^J(n,13)^J(n,22))+$n(n,s,o)|0;h=u,u=f,f=c,c=i+g|0,i=o,o=s,s=n,n=g+U|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,c=c+this.E|0,f=f+this.F|0,u=u+this.G|0,h=h+this.H|0,this.set(n,s,o,i,c,f,u,h)}roundClean(){wt(ft)}destroy(){this.set(0,0,0,0,0,0,0,0),wt(this.buffer)}}const bt=He(()=>new Xn),zn="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";function Fn(e){const t=[0];for(let r=0;r<e.length;r++){const n=e[r];if(!n)continue;const s=zn.indexOf(n);if(s===-1)throw new Error("Invalid base58 character");for(let i=0;i<t.length;i++)t[i]*=58;t[0]+=s;let o=0;for(let i=0;i<t.length;i++){const c=t[i];t[i]=c+o,o=t[i]>>8,t[i]&=255}for(;o>0;)t.push(o&255),o>>=8}for(let r=0;r<e.length&&e[r]==="1";r++)t.push(0);return new Uint8Array(t.reverse())}function Pn(e){const t="qpzry9x8gf2tvdw0s3jn54khce6mua7l",n=e.toLowerCase().split("1");if(n.length!==2)return null;const s=n[0],o=n[1];if(!s||!o||s!=="dgb")return null;const i=[];for(const h of o){const d=t.indexOf(h);if(d===-1)return null;i.push(d)}const c=i.slice(0,-6);if(c.length<1)return null;const f=c[0];if(f===void 0)return null;const u=Wn(c.slice(1),5,8);return u?{version:f,program:new Uint8Array(u)}:null}function Wn(e,t,r,n){let s=0,o=0;const i=[],c=(1<<r)-1;for(const f of e){if(f<0||f>>t!==0)return null;for(s=s<<t|f,o+=t;o>=r;)o-=r,i.push(s>>o&c)}return o>=t||s<<r-o&c?null:i}function Qn(e,t){const r=new TextEncoder().encode(t),n=new TextEncoder().encode(e),s=[];let o=n.length;if(o<253)s.push(o);else if(o<=65535)s.push(253,o&255,o>>8&255);else if(o<=4294967295)s.push(254,o&255,o>>8&255,o>>16&255,o>>24&255);else throw new Error("Message too long");const i=new Uint8Array(s),c=r.length+i.length+n.length,f=new Uint8Array(c);let u=0;return f.set(r,u),u+=r.length,f.set(i,u),u+=i.length,f.set(n,u),bt(bt(f))}function Jn(e,t){if(t.length!==65)throw new Error("Invalid signature length");if(t[0]===void 0)throw new Error("Invalid signature");const n=t.slice(1,33),s=t.slice(33,65),o=[];for(let i=0;i<4;i++)try{const f=new _n.Signature(BigInt("0x"+Array.from(n).map(d=>d.toString(16).padStart(2,"0")).join("")),BigInt("0x"+Array.from(s).map(d=>d.toString(16).padStart(2,"0")).join(""))).addRecoveryBit(i).recoverPublicKey(e),u=f.toBytes(!0),h=f.toBytes(!1);o.push(u),o.push(h)}catch{continue}if(o.length===0)throw new Error("Failed to recover any public keys");return o}function Ce(e){return Kn(bt(e))}function tr(e,t){if(e.startsWith("D")||e.startsWith("S"))try{const r=Fn(e);if(r.length<25)return!1;const n=r.slice(0,-4),s=r.slice(-4),i=bt(bt(n)).slice(0,4);if(!s.every((u,h)=>u===i[h]))return!1;const c=n.slice(1),f=Ce(t);return c.every((u,h)=>u===f[h])}catch{return!1}if(e.toLowerCase().startsWith("dgb1"))try{const r=Pn(e);if(!r)return!1;const{version:n,program:s}=r;if(n===0){let o=t;if(t.length===65){const c=t[64]%2===0;o=new Uint8Array(33),o[0]=c?2:3,o.set(t.slice(1,33),1)}const i=Ce(o);return s.every((c,f)=>c===i[f])}return!1}catch{return!1}return!1}async function Ve(e,t,r){const n=`DigiByte Signed Message:
2
- `;try{const s=Uint8Array.from(atob(r),c=>c.charCodeAt(0));if(s.length!==65)throw new Error("Invalid signature length");const o=Qn(e,n),i=Jn(o,s);for(const c of i)if(tr(t,c))return!0;return!1}catch(s){const o=s instanceof Error?s.message:String(s);throw new D(`Signature verification failed: ${o}`)}}function er(e=16){return K.randomBytes(e).toString("hex")}function nr(e){if(!e.callbackUrl)throw new D("Callback URL is required.");let t;try{t=new URL(e.callbackUrl)}catch(i){throw new D(`Invalid callback URL: ${i.message}`)}const r=t.host+t.pathname,n=e.nonce||er(),s=e.unsecure?"1":"0";if(e.unsecure&&t.protocol!=="http:")throw new D("Unsecure flag is true, but callback URL does not use http protocol.");if(!e.unsecure&&t.protocol!=="https:")throw new D("Callback URL must use https protocol unless unsecure flag is set to true.");return`digiid://${r}?x=${n}&u=${s}`}async function rr(e,t){const{address:r,uri:n,signature:s}=e,{expectedCallbackUrl:o,expectedNonce:i}=t;if(!r||!n||!s)throw new D("Missing required callback data: address, uri, or signature.");let c;try{const y=n.replace(/^digiid:/,"http:");c=new URL(y)}catch(y){throw new D(`Invalid URI received in callback: ${y.message}`)}const f=c.searchParams.get("x"),u=c.searchParams.get("u"),h=c.host+c.pathname;if(f===null||u===null)throw new D("URI missing nonce (x) or unsecure (u) parameter.");let d;try{d=typeof o=="string"?new URL(o):o}catch(y){throw new D(`Invalid expectedCallbackUrl provided: ${y.message}`)}const m=d.host+d.pathname;if(h!==m)throw new D(`Callback URL mismatch: URI contained "${h}", expected "${m}"`);const g=d.protocol;if(u==="1"&&g!=="http:")throw new D("URI indicates unsecure (u=1), but expectedCallbackUrl is not http.");if(u==="0"&&g!=="https:")throw new D("URI indicates secure (u=0), but expectedCallbackUrl is not https.");if(i&&f!==i)throw new D(`Nonce mismatch: URI contained "${f}", expected "${i}". Possible replay attack.`);try{if(!await Ve(n,r,s))throw new D("Invalid signature.")}catch(y){throw y instanceof D?y:new D(`Unexpected error during signature verification: ${y.message}`)}return{isValid:!0,address:r,nonce:f}}T.DigiIDError=D,T._internalVerifySignature=Ve,T.generateDigiIDUri=nr,T.verifyDigiIDCallback=rr,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})});
3
- //# sourceMappingURL=digiid-ts.umd.js.map
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("crypto")):typeof define==`function`&&define.amd?define([`exports`,`crypto`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.DigiIDTs={},e.crypto))})(this,function(e,t){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var n=class extends Error{constructor(e){super(e),this.name=`DigiIDError`}};function r(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`&&`BYTES_PER_ELEMENT`in e&&e.BYTES_PER_ELEMENT===1}function i(e,t=``){if(typeof e!=`number`){let n=t&&`"${t}" `;throw TypeError(`${n}expected number, got ${typeof e}`)}if(!Number.isSafeInteger(e)||e<0){let n=t&&`"${t}" `;throw RangeError(`${n}expected integer >= 0, got ${e}`)}}function a(e,t,n=``){let i=r(e),a=e?.length,o=t!==void 0;if(!i||o&&a!==t){let r=n&&`"${n}" `,s=o?` of length ${t}`:``,c=i?`length=${a}`:`type=${typeof e}`,l=r+`expected Uint8Array`+s+`, got `+c;throw i?RangeError(l):TypeError(l)}return e}function o(e){if(typeof e!=`function`||typeof e.create!=`function`)throw TypeError(`Hash must wrapped by utils.createHasher`);if(i(e.outputLen),i(e.blockLen),e.outputLen<1)throw Error(`"outputLen" must be >= 1`);if(e.blockLen<1)throw Error(`"blockLen" must be >= 1`)}function s(e,t=!0){if(e.destroyed)throw Error(`Hash instance has been destroyed`);if(t&&e.finished)throw Error(`Hash#digest() has already been called`)}function c(e,t){a(e,void 0,`digestInto() output`);let n=t.outputLen;if(e.length<n)throw RangeError(`"digestInto() output" expected to be of length >=`+n)}function l(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function u(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function d(e,t){return e<<32-t|e>>>t}function f(e,t){return e<<t|e>>>32-t>>>0}var p=typeof Uint8Array.from([]).toHex==`function`&&typeof Uint8Array.fromHex==`function`,m=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function h(e){if(a(e),p)return e.toHex();let t=``;for(let n=0;n<e.length;n++)t+=m[e[n]];return t}var g={_0:48,_9:57,A:65,F:70,a:97,f:102};function _(e){if(e>=g._0&&e<=g._9)return e-g._0;if(e>=g.A&&e<=g.F)return e-(g.A-10);if(e>=g.a&&e<=g.f)return e-(g.a-10)}function v(e){if(typeof e!=`string`)throw TypeError(`hex string expected, got `+typeof e);if(p)try{return Uint8Array.fromHex(e)}catch(e){throw e instanceof SyntaxError?RangeError(e.message):e}let t=e.length,n=t/2;if(t%2)throw RangeError(`hex string expected, got unpadded hex of length `+t);let r=new Uint8Array(n);for(let t=0,i=0;t<n;t++,i+=2){let n=_(e.charCodeAt(i)),a=_(e.charCodeAt(i+1));if(n===void 0||a===void 0){let t=e[i]+e[i+1];throw RangeError(`hex string expected, got non-hex character "`+t+`" at index `+i)}r[t]=n*16+a}return r}function y(...e){let t=0;for(let n=0;n<e.length;n++){let r=e[n];a(r),t+=r.length}let n=new Uint8Array(t);for(let t=0,r=0;t<e.length;t++){let i=e[t];n.set(i,r),r+=i.length}return n}function b(e,t={}){let n=(t,n)=>e(n).update(t).digest(),r=e(void 0);return n.outputLen=r.outputLen,n.blockLen=r.blockLen,n.canXOF=r.canXOF,n.create=t=>e(t),Object.assign(n,t),Object.freeze(n)}function x(e=32){i(e,`bytesLength`);let t=typeof globalThis==`object`?globalThis.crypto:null;if(typeof t?.getRandomValues!=`function`)throw Error(`crypto.getRandomValues must be defined`);if(e>65536)throw RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}var S=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function C(e,t,n){return e&t^~e&n}function w(e,t,n){return e&t^e&n^t&n}var T=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,n,r){this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=u(this.buffer)}update(e){s(this),a(e);let{view:t,buffer:n,blockLen:r}=this,i=e.length;for(let a=0;a<i;){let o=Math.min(r-this.pos,i-a);if(o===r){let t=u(e);for(;r<=i-a;a+=r)this.process(t,a);continue}n.set(e.subarray(a,a+o),this.pos),this.pos+=o,a+=o,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){s(this),c(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:r,isLE:i}=this,{pos:a}=this;t[a++]=128,l(this.buffer.subarray(a)),this.padOffset>r-a&&(this.process(n,0),a=0);for(let e=a;e<r;e++)t[e]=0;n.setBigUint64(r-8,BigInt(this.length*8),i),this.process(n,0);let o=u(e),d=this.outputLen;if(d%4)throw Error(`_sha2: outputLen must be aligned to 32bit`);let f=d/4,p=this.get();if(f>p.length)throw Error(`_sha2: outputLen bigger than state`);for(let e=0;e<f;e++)o.setUint32(4*e,p[e],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:t,buffer:n,length:r,finished:i,destroyed:a,pos:o}=this;return e.destroyed=a,e.finished=i,e.length=r,e.pos=o,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}},E=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),D=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),O=new Uint32Array(64),ee=class extends T{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return[e,t,n,r,i,a,o,s]}set(e,t,n,r,i,a,o,s){this.A=e|0,this.B=t|0,this.C=n|0,this.D=r|0,this.E=i|0,this.F=a|0,this.G=o|0,this.H=s|0}process(e,t){for(let n=0;n<16;n++,t+=4)O[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=O[e-15],n=O[e-2],r=d(t,7)^d(t,18)^t>>>3;O[e]=(d(n,17)^d(n,19)^n>>>10)+O[e-7]+r+O[e-16]|0}let{A:n,B:r,C:i,D:a,E:o,F:s,G:c,H:l}=this;for(let e=0;e<64;e++){let t=d(o,6)^d(o,11)^d(o,25),u=l+t+C(o,s,c)+D[e]+O[e]|0,f=(d(n,2)^d(n,13)^d(n,22))+w(n,r,i)|0;l=c,c=s,s=o,o=a+u|0,a=i,i=r,r=n,n=u+f|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,a=a+this.D|0,o=o+this.E|0,s=s+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,r,i,a,o,s,c,l)}roundClean(){l(O)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),l(this.buffer)}},te=class extends ee{A=E[0]|0;B=E[1]|0;C=E[2]|0;D=E[3]|0;E=E[4]|0;F=E[5]|0;G=E[6]|0;H=E[7]|0;constructor(){super(32)}},k=b(()=>new te,S(1)),A=(e,t,n)=>a(e,t,n),ne=i,re=h,j=(...e)=>y(...e),M=e=>v(e),ie=r,ae=e=>x(e),N=BigInt(0),P=BigInt(1);function F(e,t=``){if(typeof e!=`boolean`){let n=t&&`"${t}" `;throw TypeError(n+`expected boolean, got type=`+typeof e)}return e}function oe(e){if(typeof e==`bigint`){if(!R(e))throw RangeError(`positive bigint expected, got `+e)}else ne(e);return e}function se(e,t=``){if(typeof e!=`number`){let n=t&&`"${t}" `;throw TypeError(n+`expected number, got type=`+typeof e)}if(!Number.isSafeInteger(e)){let n=t&&`"${t}" `;throw RangeError(n+`expected safe integer, got `+e)}}function I(e){let t=oe(e).toString(16);return t.length&1?`0`+t:t}function ce(e){if(typeof e!=`string`)throw TypeError(`hex string expected, got `+typeof e);return e===``?N:BigInt(`0x`+e)}function L(e){return ce(h(e))}function le(e){return ce(h(fe(a(e)).reverse()))}function ue(e,t){if(i(t),t===0)throw RangeError(`zero length`);e=oe(e);let n=e.toString(16);if(n.length>t*2)throw RangeError(`number too large`);return v(n.padStart(t*2,`0`))}function de(e,t){return ue(e,t).reverse()}function fe(e){return Uint8Array.from(A(e))}var R=e=>typeof e==`bigint`&&N<=e;function pe(e,t,n){return R(e)&&R(t)&&R(n)&&t<=e&&e<n}function me(e,t,n,r){if(!pe(t,n,r))throw RangeError(`expected valid `+e+`: `+n+` <= n < `+r+`, got `+t)}function he(e){if(e<N)throw Error(`expected non-negative bigint, got `+e);let t;for(t=0;e>N;e>>=P,t+=1);return t}var ge=e=>(P<<BigInt(e))-P;function _e(e,t,n){if(i(e,`hashLen`),i(t,`qByteLen`),typeof n!=`function`)throw TypeError(`hmacFn must be a function`);let r=e=>new Uint8Array(e),a=Uint8Array.of(),o=Uint8Array.of(0),s=Uint8Array.of(1),c=r(e),l=r(e),u=0,d=()=>{c.fill(1),l.fill(0),u=0},f=(...e)=>n(l,j(c,...e)),p=(e=a)=>{l=f(o,e),c=f(),e.length!==0&&(l=f(s,e),c=f())},m=()=>{if(u++>=1e3)throw Error(`drbg: tried max amount of iterations`);let e=0,n=[];for(;e<t;){c=f();let t=c.slice();n.push(t),e+=c.length}return j(...n)};return(e,t)=>{d(),p(e);let n;for(;(n=t(m()))===void 0;)p();return d(),n}}function z(e,t={},n={}){if(Object.prototype.toString.call(e)!==`[object Object]`)throw TypeError(`expected valid options object`);function r(t,n,r){if(!r&&n!==`function`&&!Object.hasOwn(e,t))throw TypeError(`param "${t}" is invalid: expected own property`);let i=e[t];if(r&&i===void 0)return;let a=typeof i;if(a!==n||i===null)throw TypeError(`param "${t}" is invalid: expected ${n}, got ${a}`)}let i=(e,t)=>Object.entries(e).forEach(([e,n])=>r(e,n,t));i(t,!1),i(n,!0)}var B=BigInt(0),V=BigInt(1),H=BigInt(2),ve=BigInt(3),ye=BigInt(4),be=BigInt(5),xe=BigInt(7),Se=BigInt(8),Ce=BigInt(9),we=BigInt(16);function U(e,t){if(t<=B)throw Error(`mod: expected positive modulus, got `+t);let n=e%t;return n>=B?n:t+n}function W(e,t,n){if(t<B)throw Error(`pow2: expected non-negative exponent, got `+t);let r=e;for(;t-- >B;)r*=r,r%=n;return r}function Te(e,t){if(e===B)throw Error(`invert: expected non-zero number`);if(t<=B)throw Error(`invert: expected positive modulus, got `+t);let n=U(e,t),r=t,i=B,a=V,o=V,s=B;for(;n!==B;){let e=r/n,t=r-n*e,c=i-o*e,l=a-s*e;r=n,n=t,i=o,a=s,o=c,s=l}if(r!==V)throw Error(`invert: does not exist`);return U(i,t)}function Ee(e,t,n){let r=e;if(!r.eql(r.sqr(t),n))throw Error(`Cannot find square root`)}function De(e,t){let n=e,r=(n.ORDER+V)/ye,i=n.pow(t,r);return Ee(n,i,t),i}function Oe(e,t){let n=e,r=(n.ORDER-be)/Se,i=n.mul(t,H),a=n.pow(i,r),o=n.mul(t,a),s=n.mul(n.mul(o,H),a),c=n.mul(o,n.sub(s,n.ONE));return Ee(n,c,t),c}function ke(e){let t=G(e),n=Ae(e),r=n(t,t.neg(t.ONE)),i=n(t,r),a=n(t,t.neg(r)),o=(e+xe)/we;return((e,t)=>{let n=e,s=n.pow(t,o),c=n.mul(s,r),l=n.mul(s,i),u=n.mul(s,a),d=n.eql(n.sqr(c),t),f=n.eql(n.sqr(l),t);s=n.cmov(s,c,d),c=n.cmov(u,l,f);let p=n.eql(n.sqr(c),t),m=n.cmov(s,c,p);return Ee(n,m,t),m})}function Ae(e){if(e<ve)throw Error(`sqrt is not defined for small field`);let t=e-V,n=0;for(;t%H===B;)t/=H,n++;let r=H,i=G(e);for(;Ie(i,r)===1;)if(r++>1e3)throw Error(`Cannot find square root: probably non-prime P`);if(n===1)return De;let a=i.pow(r,t),o=(t+V)/H;return function(e,r){let i=e;if(i.is0(r))return r;if(Ie(i,r)!==1)throw Error(`Cannot find square root`);let s=n,c=i.mul(i.ONE,a),l=i.pow(r,t),u=i.pow(r,o);for(;!i.eql(l,i.ONE);){if(i.is0(l))return i.ZERO;let e=1,t=i.sqr(l);for(;!i.eql(t,i.ONE);)if(e++,t=i.sqr(t),e===s)throw Error(`Cannot find square root`);let n=V<<BigInt(s-e-1),r=i.pow(c,n);s=e,c=i.sqr(r),l=i.mul(l,c),u=i.mul(u,r)}return u}}function je(e){return e%ye===ve?De:e%Se===be?Oe:e%we===Ce?ke(e):Ae(e)}var Me=[`create`,`isValid`,`is0`,`neg`,`inv`,`sqrt`,`sqr`,`eql`,`add`,`sub`,`mul`,`pow`,`div`,`addN`,`subN`,`mulN`,`sqrN`];function Ne(e){if(z(e,Me.reduce((e,t)=>(e[t]=`function`,e),{ORDER:`bigint`,BYTES:`number`,BITS:`number`})),se(e.BYTES,`BYTES`),se(e.BITS,`BITS`),e.BYTES<1||e.BITS<1)throw Error(`invalid field: expected BYTES/BITS > 0`);if(e.ORDER<=V)throw Error(`invalid field: expected ORDER > 1, got `+e.ORDER);return e}function Pe(e,t,n){let r=e;if(n<B)throw Error(`invalid exponent, negatives unsupported`);if(n===B)return r.ONE;if(n===V)return t;let i=r.ONE,a=t;for(;n>B;)n&V&&(i=r.mul(i,a)),a=r.sqr(a),n>>=V;return i}function Fe(e,t,n=!1){let r=e,i=Array(t.length).fill(n?r.ZERO:void 0),a=t.reduce((e,t,n)=>r.is0(t)?e:(i[n]=e,r.mul(e,t)),r.ONE),o=r.inv(a);return t.reduceRight((e,t,n)=>r.is0(t)?e:(i[n]=r.mul(e,i[n]),r.mul(e,t)),o),i}function Ie(e,t){let n=e,r=(n.ORDER-V)/H,i=n.pow(t,r),a=n.eql(i,n.ONE),o=n.eql(i,n.ZERO),s=n.eql(i,n.neg(n.ONE));if(!a&&!o&&!s)throw Error(`invalid Legendre symbol result`);return a?1:o?0:-1}function Le(e,t){if(t!==void 0&&ne(t),e<=B)throw Error(`invalid n length: expected positive n, got `+e);if(t!==void 0&&t<1)throw Error(`invalid n length: expected positive bit length, got `+t);let n=he(e);if(t!==void 0&&t<n)throw Error(`invalid n length: expected bit length (${n}) >= n.length (${t})`);let r=t===void 0?n:t;return{nBitLength:r,nByteLength:Math.ceil(r/8)}}var Re=new WeakMap,ze=class{ORDER;BITS;BYTES;isLE;ZERO=B;ONE=V;_lengths;_mod;constructor(e,t={}){if(e<=V)throw Error(`invalid field: expected ORDER > 1, got `+e);let n;this.isLE=!1,typeof t==`object`&&t&&(typeof t.BITS==`number`&&(n=t.BITS),typeof t.sqrt==`function`&&Object.defineProperty(this,"sqrt",{value:t.sqrt,enumerable:!0}),typeof t.isLE==`boolean`&&(this.isLE=t.isLE),t.allowedLengths&&(this._lengths=Object.freeze(t.allowedLengths.slice())),typeof t.modFromBytes==`boolean`&&(this._mod=t.modFromBytes));let{nBitLength:r,nByteLength:i}=Le(e,n);if(i>2048)throw Error(`invalid field: expected ORDER of <= 2048 bytes`);this.ORDER=e,this.BITS=r,this.BYTES=i,Object.freeze(this)}create(e){return U(e,this.ORDER)}isValid(e){if(typeof e!=`bigint`)throw TypeError(`invalid field element: expected bigint, got `+typeof e);return B<=e&&e<this.ORDER}is0(e){return e===B}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&V)===V}neg(e){return U(-e,this.ORDER)}eql(e,t){return e===t}sqr(e){return U(e*e,this.ORDER)}add(e,t){return U(e+t,this.ORDER)}sub(e,t){return U(e-t,this.ORDER)}mul(e,t){return U(e*t,this.ORDER)}pow(e,t){return Pe(this,e,t)}div(e,t){return U(e*Te(t,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,t){return e+t}subN(e,t){return e-t}mulN(e,t){return e*t}inv(e){return Te(e,this.ORDER)}sqrt(e){let t=Re.get(this);return t||Re.set(this,t=je(this.ORDER)),t(this,e)}toBytes(e){return this.isLE?de(e,this.BYTES):ue(e,this.BYTES)}fromBytes(e,t=!1){A(e);let{_lengths:n,BYTES:r,isLE:i,ORDER:a,_mod:o}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>r)throw Error(`Field.fromBytes: expected `+n+` bytes, got `+e.length);let t=new Uint8Array(r);t.set(e,i?0:t.length-e.length),e=t}if(e.length!==r)throw Error(`Field.fromBytes: expected `+r+` bytes, got `+e.length);let s=i?le(e):L(e);if(o&&(s=U(s,a)),!t&&!this.isValid(s))throw Error(`invalid field element: outside of range 0..ORDER`);return s}invertBatch(e){return Fe(this,e)}cmov(e,t,n){return F(n,`condition`),n?t:e}};Object.freeze(ze.prototype);function G(e,t={}){return new ze(e,t)}function Be(e){if(typeof e!=`bigint`)throw Error(`field order must be bigint`);if(e<=V)throw Error(`field order must be greater than 1`);let t=he(e-V);return Math.ceil(t/8)}function Ve(e){let t=Be(e);return t+Math.ceil(t/2)}function He(e,t,n=!1){A(e);let r=e.length,i=Be(t),a=Math.max(Ve(t),16);if(r<a||r>1024)throw Error(`expected `+a+`-1024 bytes of input, got `+r);let o=U(n?le(e):L(e),t-V)+V;return n?de(o,i):ue(o,i)}var K=BigInt(0),q=BigInt(1);function J(e,t){let n=t.negate();return e?n:t}function Ue(e,t){let n=Fe(e.Fp,t.map(e=>e.Z));return t.map((t,r)=>e.fromAffine(t.toAffine(n[r])))}function We(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw Error(`invalid window size, expected [1..`+t+`], got W=`+e)}function Ge(e,t){We(e,t);let n=Math.ceil(t/e)+1,r=2**(e-1),i=2**e;return{windows:n,windowSize:r,mask:ge(e),maxNumber:i,shiftBy:BigInt(e)}}function Ke(e,t,n){let{windowSize:r,mask:i,maxNumber:a,shiftBy:o}=n,s=Number(e&i),c=e>>o;s>r&&(s-=a,c+=q);let l=t*r,u=l+Math.abs(s)-1,d=s===0,f=s<0,p=t%2!=0;return{nextN:c,offset:u,isZero:d,isNeg:f,isNegF:p,offsetF:l}}var qe=new WeakMap,Je=new WeakMap;function Ye(e){return Je.get(e)||1}function Xe(e){if(e!==K)throw Error(`invalid wNAF`)}var Ze=class{BASE;ZERO;Fn;bits;constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,n=this.ZERO){let r=e;for(;t>K;)t&q&&(n=n.add(r)),r=r.double(),t>>=q;return n}precomputeWindow(e,t){let{windows:n,windowSize:r}=Ge(t,this.bits),i=[],a=e,o=a;for(let e=0;e<n;e++){o=a,i.push(o);for(let e=1;e<r;e++)o=o.add(a),i.push(o);a=o.double()}return i}wNAF(e,t,n){if(!this.Fn.isValid(n))throw Error(`invalid scalar`);let r=this.ZERO,i=this.BASE,a=Ge(e,this.bits);for(let e=0;e<a.windows;e++){let{nextN:o,offset:s,isZero:c,isNeg:l,isNegF:u,offsetF:d}=Ke(n,e,a);n=o,c?i=i.add(J(u,t[d])):r=r.add(J(l,t[s]))}return Xe(n),{p:r,f:i}}wNAFUnsafe(e,t,n,r=this.ZERO){let i=Ge(e,this.bits);for(let e=0;e<i.windows&&n!==K;e++){let{nextN:a,offset:o,isZero:s,isNeg:c}=Ke(n,e,i);if(n=a,!s){let e=t[o];r=r.add(c?e.negate():e)}}return Xe(n),r}getPrecomputes(e,t,n){let r=qe.get(t);return r||(r=this.precomputeWindow(t,e),e!==1&&(typeof n==`function`&&(r=n(r)),qe.set(t,r))),r}cached(e,t,n){let r=Ye(e);return this.wNAF(r,this.getPrecomputes(r,e,n),t)}unsafe(e,t,n,r){let i=Ye(e);return i===1?this._unsafeLadder(e,t,r):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),t,r)}createCache(e,t){We(t,this.bits),Je.set(e,t),qe.delete(e)}hasCache(e){return Ye(e)!==1}};function Qe(e,t,n,r){let i=t,a=e.ZERO,o=e.ZERO;for(;n>K||r>K;)n&q&&(a=a.add(i)),r&q&&(o=o.add(i)),i=i.double(),n>>=q,r>>=q;return{p1:a,p2:o}}function $e(e,t,n){if(t){if(t.ORDER!==e)throw Error(`Field.ORDER must match order: Fp == p, Fn == n`);return Ne(t),t}else return G(e,{isLE:n})}function et(e,t,n={},r){if(r===void 0&&(r=e===`edwards`),!t||typeof t!=`object`)throw Error(`expected valid ${e} CURVE object`);for(let e of[`p`,`n`,`h`]){let n=t[e];if(!(typeof n==`bigint`&&n>K))throw Error(`CURVE.${e} must be positive bigint`)}let i=$e(t.p,n.Fp,r),a=$e(t.n,n.Fn,r),o=[`Gx`,`Gy`,`a`,e===`weierstrass`?`b`:`d`];for(let e of o)if(!i.isValid(t[e]))throw Error(`CURVE.${e} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:i,Fn:a}}function tt(e,t){return function(n){let r=e(n);return{secretKey:r,publicKey:t(r)}}}var nt=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,t){if(o(e),a(t,void 0,`key`),this.iHash=e.create(),typeof this.iHash.update!=`function`)throw Error(`Expected instance of class which extends utils.Hash`);this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,r=new Uint8Array(n);r.set(t.length>n?e.create().update(t).digest():t);for(let e=0;e<r.length;e++)r[e]^=54;this.iHash.update(r),this.oHash=e.create();for(let e=0;e<r.length;e++)r[e]^=106;this.oHash.update(r),l(r)}update(e){return s(this),this.iHash.update(e),this}digestInto(e){s(this),c(e,this),this.finished=!0;let t=e.subarray(0,this.outputLen);this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:t,iHash:n,finished:r,destroyed:i,blockLen:a,outputLen:o}=this;return e=e,e.finished=r,e.destroyed=i,e.blockLen=a,e.outputLen=o,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},rt=(()=>{let e=((e,t,n)=>new nt(e,t).update(n).digest());return e.create=(e,t)=>new nt(e,t),e})(),it=(e,t)=>(e+(e>=0?t:-t)/ct)/t;function at(e,t,n){me(`scalar`,e,X,n);let[[r,i],[a,o]]=t,s=it(o*e,n),c=it(-i*e,n),l=e-s*r-c*a,u=-s*i-c*o,d=l<X,f=u<X;d&&(l=-l),f&&(u=-u);let p=ge(Math.ceil(he(n)/2))+Z;if(l<X||l>=p||u<X||u>=p)throw Error(`splitScalar (endomorphism): failed for k`);return{k1neg:d,k1:l,k2neg:f,k2:u}}function ot(e){if(![`compact`,`recovered`,`der`].includes(e))throw Error(`Signature format must be "compact", "recovered", or "der"`);return e}function st(e,t){z(e);let n={};for(let r of Object.keys(t))n[r]=e[r]===void 0?t[r]:e[r];return F(n.lowS,`lowS`),F(n.prehash,`prehash`),n.format!==void 0&&ot(n.format),n}var Y={Err:class extends Error{constructor(e=``){super(e)}},_tlv:{encode:(e,t)=>{let{Err:n}=Y;if(se(e,`tag`),e<0||e>255)throw new n(`tlv.encode: wrong tag`);if(typeof t!=`string`)throw TypeError(`"data" expected string, got type=`+typeof t);if(t.length&1)throw new n(`tlv.encode: unpadded data`);let r=t.length/2,i=I(r);if(i.length/2&128)throw new n(`tlv.encode: long form length too big`);let a=r>127?I(i.length/2|128):``;return I(e)+a+i+t},decode(e,t){let{Err:n}=Y;t=A(t,void 0,`DER data`);let r=0;if(e<0||e>255)throw new n(`tlv.encode: wrong tag`);if(t.length<2||t[r++]!==e)throw new n(`tlv.decode: wrong tlv`);let i=t[r++],a=!!(i&128),o=0;if(!a)o=i;else{let e=i&127;if(!e)throw new n(`tlv.decode(long): indefinite length not supported`);if(e>4)throw new n(`tlv.decode(long): byte length is too big`);let a=t.subarray(r,r+e);if(a.length!==e)throw new n(`tlv.decode: length bytes not complete`);if(a[0]===0)throw new n(`tlv.decode(long): zero leftmost byte`);for(let e of a)o=o<<8|e;if(r+=e,o<128)throw new n(`tlv.decode(long): not minimal encoding`)}let s=t.subarray(r,r+o);if(s.length!==o)throw new n(`tlv.decode: wrong value length`);return{v:s,l:t.subarray(r+o)}}},_int:{encode(e){let{Err:t}=Y;if(oe(e),e<X)throw new t(`integer: negative integers are not allowed`);let n=I(e);if(Number.parseInt(n[0],16)&8&&(n=`00`+n),n.length&1)throw new t(`unexpected DER parsing assertion: unpadded hex`);return n},decode(e){let{Err:t}=Y;if(e.length<1)throw new t(`invalid signature integer: empty`);if(e[0]&128)throw new t(`invalid signature integer: negative`);if(e.length>1&&e[0]===0&&!(e[1]&128))throw new t(`invalid signature integer: unnecessary leading zero`);return L(e)}},toSig(e){let{Err:t,_int:n,_tlv:r}=Y,i=A(e,void 0,`signature`),{v:a,l:o}=r.decode(48,i);if(o.length)throw new t(`invalid signature: left bytes after parsing`);let{v:s,l:c}=r.decode(2,a),{v:l,l:u}=r.decode(2,c);if(u.length)throw new t(`invalid signature: left bytes after parsing`);return{r:n.decode(s),s:n.decode(l)}},hexFromSig(e){let{_tlv:t,_int:n}=Y,r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)}};Object.freeze(Y._tlv),Object.freeze(Y._int),Object.freeze(Y);var X=BigInt(0),Z=BigInt(1),ct=BigInt(2),Q=BigInt(3),lt=BigInt(4);function ut(e,t={}){let n=et(`weierstrass`,e,t),r=n.Fp,i=n.Fn,a=n.CURVE,{h:o,n:s}=a;z(t,{},{allowInfinityPoint:`boolean`,clearCofactor:`function`,isTorsionFree:`function`,fromBytes:`function`,toBytes:`function`,endo:`object`});let{endo:c,allowInfinityPoint:l}=t;if(c&&(!r.is0(a.a)||typeof c.beta!=`bigint`||!Array.isArray(c.basises)))throw Error(`invalid endo: expected "beta": bigint and "basises": array`);let u=ft(r,i);function d(){if(!r.isOdd)throw Error(`compression is not supported: Field does not have .isOdd()`)}function f(e,t,n){if(l&&t.is0())return Uint8Array.of(0);let{x:i,y:a}=t.toAffine(),o=r.toBytes(i);return F(n,`isCompressed`),n?(d(),j(dt(!r.isOdd(a)),o)):j(Uint8Array.of(4),o,r.toBytes(a))}function p(e){A(e,void 0,`Point`);let{publicKey:t,publicKeyUncompressed:n}=u,i=e.length,a=e[0],o=e.subarray(1);if(l&&i===1&&a===0)return{x:r.ZERO,y:r.ZERO};if(i===t&&(a===2||a===3)){let e=r.fromBytes(o);if(!r.isValid(e))throw Error(`bad point: is not on curve, wrong x`);let t=g(e),n;try{n=r.sqrt(t)}catch(e){let t=e instanceof Error?`: `+e.message:``;throw Error(`bad point: is not on curve, sqrt error`+t)}d();let i=r.isOdd(n);return(a&1)==1!==i&&(n=r.neg(n)),{x:e,y:n}}else if(i===n&&a===4){let e=r.BYTES,t=r.fromBytes(o.subarray(0,e)),n=r.fromBytes(o.subarray(e,e*2));if(!_(t,n))throw Error(`bad point: is not on curve`);return{x:t,y:n}}else throw Error(`bad point: got length ${i}, expected compressed=${t} or uncompressed=${n}`)}let m=t.toBytes===void 0?f:t.toBytes,h=t.fromBytes===void 0?p:t.fromBytes;function g(e){let t=r.sqr(e),n=r.mul(t,e);return r.add(r.add(n,r.mul(e,a.a)),a.b)}function _(e,t){let n=r.sqr(t),i=g(e);return r.eql(n,i)}if(!_(a.Gx,a.Gy))throw Error(`bad curve params: generator point`);let v=r.mul(r.pow(a.a,Q),lt),y=r.mul(r.sqr(a.b),BigInt(27));if(r.is0(r.add(v,y)))throw Error(`bad curve params: a or b`);function b(e,t,n=!1){if(!r.isValid(t)||n&&r.is0(t))throw Error(`bad point coordinate ${e}`);return t}function x(e){if(!(e instanceof w))throw Error(`Weierstrass Point expected`)}function S(e){if(!c||!c.basises)throw Error(`no endo`);return at(e,c.basises,i.ORDER)}function C(e,t,n,i,a){return n=new w(r.mul(n.X,e),n.Y,n.Z),t=J(i,t),n=J(a,n),t.add(n)}class w{static BASE=new w(a.Gx,a.Gy,r.ONE);static ZERO=new w(r.ZERO,r.ONE,r.ZERO);static Fp=r;static Fn=i;X;Y;Z;constructor(e,t,n){this.X=b(`x`,e),this.Y=b(`y`,t,!0),this.Z=b(`z`,n),Object.freeze(this)}static CURVE(){return a}static fromAffine(e){let{x:t,y:n}=e||{};if(!e||!r.isValid(t)||!r.isValid(n))throw Error(`invalid affine point`);if(e instanceof w)throw Error(`projective point not allowed`);return r.is0(t)&&r.is0(n)?w.ZERO:new w(t,n,r.ONE)}static fromBytes(e){let t=w.fromAffine(h(A(e,void 0,`point`)));return t.assertValidity(),t}static fromHex(e){return w.fromBytes(M(e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=8,t=!0){return E.createCache(this,e),t||this.multiply(Q),this}assertValidity(){let e=this;if(e.is0()){if(t.allowInfinityPoint&&r.is0(e.X)&&r.eql(e.Y,r.ONE)&&r.is0(e.Z))return;throw Error(`bad point: ZERO`)}let{x:n,y:i}=e.toAffine();if(!r.isValid(n)||!r.isValid(i))throw Error(`bad point: x or y not field elements`);if(!_(n,i))throw Error(`bad point: equation left != right`);if(!e.isTorsionFree())throw Error(`bad point: not in prime-order subgroup`)}hasEvenY(){let{y:e}=this.toAffine();if(!r.isOdd)throw Error(`Field doesn't support isOdd`);return!r.isOdd(e)}equals(e){x(e);let{X:t,Y:n,Z:i}=this,{X:a,Y:o,Z:s}=e,c=r.eql(r.mul(t,s),r.mul(a,i)),l=r.eql(r.mul(n,s),r.mul(o,i));return c&&l}negate(){return new w(this.X,r.neg(this.Y),this.Z)}double(){let{a:e,b:t}=a,n=r.mul(t,Q),{X:i,Y:o,Z:s}=this,c=r.ZERO,l=r.ZERO,u=r.ZERO,d=r.mul(i,i),f=r.mul(o,o),p=r.mul(s,s),m=r.mul(i,o);return m=r.add(m,m),u=r.mul(i,s),u=r.add(u,u),c=r.mul(e,u),l=r.mul(n,p),l=r.add(c,l),c=r.sub(f,l),l=r.add(f,l),l=r.mul(c,l),c=r.mul(m,c),u=r.mul(n,u),p=r.mul(e,p),m=r.sub(d,p),m=r.mul(e,m),m=r.add(m,u),u=r.add(d,d),d=r.add(u,d),d=r.add(d,p),d=r.mul(d,m),l=r.add(l,d),p=r.mul(o,s),p=r.add(p,p),d=r.mul(p,m),c=r.sub(c,d),u=r.mul(p,f),u=r.add(u,u),u=r.add(u,u),new w(c,l,u)}add(e){x(e);let{X:t,Y:n,Z:i}=this,{X:o,Y:s,Z:c}=e,l=r.ZERO,u=r.ZERO,d=r.ZERO,f=a.a,p=r.mul(a.b,Q),m=r.mul(t,o),h=r.mul(n,s),g=r.mul(i,c),_=r.add(t,n),v=r.add(o,s);_=r.mul(_,v),v=r.add(m,h),_=r.sub(_,v),v=r.add(t,i);let y=r.add(o,c);return v=r.mul(v,y),y=r.add(m,g),v=r.sub(v,y),y=r.add(n,i),l=r.add(s,c),y=r.mul(y,l),l=r.add(h,g),y=r.sub(y,l),d=r.mul(f,v),l=r.mul(p,g),d=r.add(l,d),l=r.sub(h,d),d=r.add(h,d),u=r.mul(l,d),h=r.add(m,m),h=r.add(h,m),g=r.mul(f,g),v=r.mul(p,v),h=r.add(h,g),g=r.sub(m,g),g=r.mul(f,g),v=r.add(v,g),m=r.mul(h,v),u=r.add(u,m),m=r.mul(y,v),l=r.mul(_,l),l=r.sub(l,m),m=r.mul(_,h),d=r.mul(y,d),d=r.add(d,m),new w(l,u,d)}subtract(e){return x(e),this.add(e.negate())}is0(){return this.equals(w.ZERO)}multiply(e){let{endo:n}=t;if(!i.isValidNot0(e))throw RangeError(`invalid scalar: out of range`);let r,a,o=e=>E.cached(this,e,e=>Ue(w,e));if(n){let{k1neg:t,k1:i,k2neg:s,k2:c}=S(e),{p:l,f:u}=o(i),{p:d,f}=o(c);a=u.add(f),r=C(n.beta,l,d,t,s)}else{let{p:t,f:n}=o(e);r=t,a=n}return Ue(w,[r,a])[0]}multiplyUnsafe(e){let{endo:n}=t,r=this,a=e;if(!i.isValid(a))throw RangeError(`invalid scalar: out of range`);if(a===X||r.is0())return w.ZERO;if(a===Z)return r;if(E.hasCache(this))return this.multiply(a);if(n){let{k1neg:e,k1:t,k2neg:i,k2:o}=S(a),{p1:s,p2:c}=Qe(w,r,t,o);return C(n.beta,s,c,e,i)}else return E.unsafe(r,a)}toAffine(e){let t=this,n=e,{X:i,Y:a,Z:o}=t;if(r.eql(o,r.ONE))return{x:i,y:a};let s=t.is0();n??=s?r.ONE:r.inv(o);let c=r.mul(i,n),l=r.mul(a,n),u=r.mul(o,n);if(s)return{x:r.ZERO,y:r.ZERO};if(!r.eql(u,r.ONE))throw Error(`invZ was invalid`);return{x:c,y:l}}isTorsionFree(){let{isTorsionFree:e}=t;return o===Z?!0:e?e(w,this):E.unsafe(this,s).is0()}clearCofactor(){let{clearCofactor:e}=t;return o===Z?this:e?e(w,this):this.multiplyUnsafe(o)}isSmallOrder(){return o===Z?this.is0():this.clearCofactor().is0()}toBytes(e=!0){return F(e,`isCompressed`),this.assertValidity(),m(w,this,e)}toHex(e=!0){return re(this.toBytes(e))}toString(){return`<Point ${this.is0()?`ZERO`:this.toHex()}>`}}let T=i.BITS,E=new Ze(w,t.endo?Math.ceil(T/2):T);return T>=8&&w.BASE.precompute(8),Object.freeze(w.prototype),Object.freeze(w),w}function dt(e){return Uint8Array.of(e?2:3)}function ft(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function pt(e,t={}){let{Fn:n}=e,r=t.randomBytes===void 0?ae:t.randomBytes,i=Object.assign(ft(e.Fp,n),{seed:Math.max(Ve(n.ORDER),16)});function a(e){try{let t=n.fromBytes(e);return n.isValidNot0(t)}catch{return!1}}function o(t,n){let{publicKey:r,publicKeyUncompressed:a}=i;try{let i=t.length;return n===!0&&i!==r||n===!1&&i!==a?!1:!!e.fromBytes(t)}catch{return!1}}function s(e){return e=e===void 0?r(i.seed):e,He(A(e,i.seed,`seed`),n.ORDER)}function c(t,r=!0){return e.BASE.multiply(n.fromBytes(t)).toBytes(r)}function l(e){let{secretKey:t,publicKey:r,publicKeyUncompressed:a}=i,o=n._lengths;if(!ie(e))return;let s=A(e,void 0,`key`).length,c=s===r||s===a,l=s===t||!!o?.includes(s);if(!(c&&l))return c}function u(t,r,i=!0){if(l(t)===!0)throw Error(`first arg must be private key`);if(l(r)===!1)throw Error(`second arg must be public key`);let a=n.fromBytes(t);return e.fromBytes(r).multiply(a).toBytes(i)}let d={isValidSecretKey:a,isValidPublicKey:o,randomSecretKey:s},f=tt(s,c);return Object.freeze(d),Object.freeze(i),Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:f,Point:e,utils:d,lengths:i})}function mt(e,t,n={}){let r=t;o(r),z(n,{},{hmac:`function`,lowS:`boolean`,randomBytes:`function`,bits2int:`function`,bits2int_modN:`function`}),n=Object.assign({},n);let i=n.randomBytes===void 0?ae:n.randomBytes,a=n.hmac===void 0?(e,t)=>rt(r,e,t):n.hmac,{Fp:s,Fn:c}=e,{ORDER:l,BITS:u}=c,{keygen:d,getPublicKey:f,getSharedSecret:p,utils:m,lengths:h}=pt(e,n),g={prehash:!0,lowS:typeof n.lowS==`boolean`?n.lowS:!0,format:`compact`,extraEntropy:!1},_=l*ct+Z<s.ORDER;function v(e){return e>l>>Z}function y(e,t){if(!c.isValidNot0(t))throw Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);return t}function b(){if(_)throw Error(`"recovered" sig type is not supported for cofactor >2 curves`)}function x(e,t){ot(t);let n=h.signature;return A(e,t===`compact`?n:t===`recovered`?n+1:void 0)}class S{r;s;recovery;constructor(e,t,n){if(this.r=y(`r`,e),this.s=y(`s`,t),n!=null){if(b(),![0,1,2,3].includes(n))throw Error(`invalid recovery id`);this.recovery=n}Object.freeze(this)}static fromBytes(e,t=g.format){x(e,t);let n;if(t===`der`){let{r:t,s:n}=Y.toSig(A(e));return new S(t,n)}t===`recovered`&&(n=e[0],t=`compact`,e=e.subarray(1));let r=h.signature/2,i=e.subarray(0,r),a=e.subarray(r,r*2);return new S(c.fromBytes(i),c.fromBytes(a),n)}static fromHex(e,t){return this.fromBytes(M(e),t)}assertRecovery(){let{recovery:e}=this;if(e==null)throw Error(`invalid recovery id: must be present`);return e}addRecoveryBit(e){return new S(this.r,this.s,e)}recoverPublicKey(t){let{r:n,s:r}=this,i=this.assertRecovery(),a=i===2||i===3?n+l:n;if(!s.isValid(a))throw Error(`invalid recovery id: sig.r+curve.n != R.x`);let o=s.toBytes(a),u=e.fromBytes(j(dt((i&1)==0),o)),d=c.inv(a),f=w(A(t,void 0,`msgHash`)),p=c.create(-f*d),m=c.create(r*d),h=e.BASE.multiplyUnsafe(p).add(u.multiplyUnsafe(m));if(h.is0())throw Error(`invalid recovery: point at infinify`);return h.assertValidity(),h}hasHighS(){return v(this.s)}toBytes(e=g.format){if(ot(e),e===`der`)return M(Y.hexFromSig(this));let{r:t,s:n}=this,r=c.toBytes(t),i=c.toBytes(n);return e===`recovered`?(b(),j(Uint8Array.of(this.assertRecovery()),r,i)):j(r,i)}toHex(e){return re(this.toBytes(e))}}Object.freeze(S.prototype),Object.freeze(S);let C=n.bits2int===void 0?function(e){if(e.length>8192)throw Error(`input is too large`);let t=L(e),n=e.length*8-u;return n>0?t>>BigInt(n):t}:n.bits2int,w=n.bits2int_modN===void 0?function(e){return c.create(C(e))}:n.bits2int_modN,T=ge(u);function E(e){return me(`num < 2^`+u,e,X,T),c.toBytes(e)}function D(e,t){return A(e,void 0,`message`),t?A(r(e),void 0,`prehashed message`):e}function O(t,n,r){let{lowS:a,prehash:o,extraEntropy:s}=st(r,g);t=D(t,o);let l=w(t),u=c.fromBytes(n);if(!c.isValidNot0(u))throw Error(`invalid private key`);let d=[E(u),E(l)];if(s!=null&&s!==!1){let e=s===!0?i(h.secretKey):s;d.push(A(e,void 0,`extraEntropy`))}let f=j(...d),p=l;function m(t){let n=C(t);if(!c.isValidNot0(n))return;let r=c.inv(n),i=e.BASE.multiply(n).toAffine(),o=c.create(i.x);if(o===X)return;let s=c.create(r*c.create(p+o*u));if(s===X)return;let l=(i.x===o?0:2)|Number(i.y&Z),d=s;return a&&v(s)&&(d=c.neg(s),l^=1),new S(o,d,_?void 0:l)}return{seed:f,k2sig:m}}function ee(e,t,n={}){let{seed:i,k2sig:o}=O(e,t,n);return _e(r.outputLen,c.BYTES,a)(i,o).toBytes(n.format)}function te(t,n,r,i={}){let{lowS:a,prehash:o,format:s}=st(i,g);if(r=A(r,void 0,`publicKey`),n=D(n,o),!ie(t)){let e=t instanceof S?`, use sig.toBytes()`:``;throw Error(`verify expects Uint8Array signature`+e)}x(t,s);try{let i=S.fromBytes(t,s),o=e.fromBytes(r);if(a&&i.hasHighS())return!1;let{r:l,s:u}=i,d=w(n),f=c.inv(u),p=c.create(d*f),m=c.create(l*f),h=e.BASE.multiplyUnsafe(p).add(o.multiplyUnsafe(m));return h.is0()?!1:c.create(h.x)===l}catch{return!1}}function k(e,t,n={}){let{prehash:r}=st(n,g);return t=D(t,r),S.fromBytes(e,`recovered`).recoverPublicKey(t).toBytes()}return Object.freeze({keygen:d,getPublicKey:f,getSharedSecret:p,utils:m,lengths:h,Point:e,sign:ee,verify:te,recoverPublicKey:k,Signature:S,hash:r})}var ht={p:BigInt(`0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f`),n:BigInt(`0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141`),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt(`0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798`),Gy:BigInt(`0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8`)},gt={beta:BigInt(`0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee`),basises:[[BigInt(`0x3086d221a7d46bcde86c90e49284eb15`),-BigInt(`0xe4437ed6010e88286f547fa90abfe4c3`)],[BigInt(`0x114ca50f7a8e2f3f657c1108d9d44cfd8`),BigInt(`0x3086d221a7d46bcde86c90e49284eb15`)]]},_t=BigInt(2);function vt(e){let t=ht.p,n=BigInt(3),r=BigInt(6),i=BigInt(11),a=BigInt(22),o=BigInt(23),s=BigInt(44),c=BigInt(88),l=e*e*e%t,u=l*l*e%t,d=W(W(W(u,n,t)*u%t,n,t)*u%t,_t,t)*l%t,f=W(d,i,t)*d%t,p=W(f,a,t)*f%t,m=W(p,s,t)*p%t,h=W(W(W(W(W(W(m,c,t)*m%t,s,t)*p%t,n,t)*u%t,o,t)*f%t,r,t)*l%t,_t,t);if(!yt.eql(yt.sqr(h),e))throw Error(`Cannot find square root`);return h}var yt=G(ht.p,{sqrt:vt}),bt=mt(ut(ht,{Fp:yt,endo:gt}),k),xt=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),St=Uint8Array.from(Array(16).fill(0).map((e,t)=>t)),Ct=St.map(e=>(9*e+5)%16),wt=(()=>{let e=[[St],[Ct]];for(let t=0;t<4;t++)for(let n of e)n.push(n[t].map(e=>xt[e]));return e})(),Tt=wt[0],Et=wt[1],Dt=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(e=>Uint8Array.from(e)),Ot=Tt.map((e,t)=>e.map(e=>Dt[t][e])),kt=Et.map((e,t)=>e.map(e=>Dt[t][e])),At=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),jt=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function Mt(e,t,n,r){return e===0?t^n^r:e===1?t&n|~t&r:e===2?(t|~n)^r:e===3?t&r|n&~r:t^(n|~r)}var $=new Uint32Array(16),Nt=class extends T{h0=1732584193;h1=-271733879;h2=-1732584194;h3=271733878;h4=-1009589776;constructor(){super(64,20,8,!0)}get(){let{h0:e,h1:t,h2:n,h3:r,h4:i}=this;return[e,t,n,r,i]}set(e,t,n,r,i){this.h0=e|0,this.h1=t|0,this.h2=n|0,this.h3=r|0,this.h4=i|0}process(e,t){for(let n=0;n<16;n++,t+=4)$[n]=e.getUint32(t,!0);let n=this.h0|0,r=n,i=this.h1|0,a=i,o=this.h2|0,s=o,c=this.h3|0,l=c,u=this.h4|0,d=u;for(let e=0;e<5;e++){let t=4-e,p=At[e],m=jt[e],h=Tt[e],g=Et[e],_=Ot[e],v=kt[e];for(let t=0;t<16;t++){let r=f(n+Mt(e,i,o,c)+$[h[t]]+p,_[t])+u|0;n=u,u=c,c=f(o,10)|0,o=i,i=r}for(let e=0;e<16;e++){let n=f(r+Mt(t,a,s,l)+$[g[e]]+m,v[e])+d|0;r=d,d=l,l=f(s,10)|0,s=a,a=n}}this.set(this.h1+o+l|0,this.h2+c+d|0,this.h3+u+r|0,this.h4+n+a|0,this.h0+i+s|0)}roundClean(){l($)}destroy(){this.destroyed=!0,l(this.buffer),this.set(0,0,0,0,0)}},Pt=b(()=>new Nt),Ft=`123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz`;function It(e){let t=[0];for(let n=0;n<e.length;n++){let r=e[n];if(!r)continue;let i=Ft.indexOf(r);if(i===-1)throw Error(`Invalid base58 character`);for(let e=0;e<t.length;e++)t[e]*=58;t[0]+=i;let a=0;for(let e=0;e<t.length;e++)t[e]=t[e]+a,a=t[e]>>8,t[e]&=255;for(;a>0;)t.push(a&255),a>>=8}for(let n=0;n<e.length&&e[n]===`1`;n++)t.push(0);return new Uint8Array(t.reverse())}function Lt(e){let t=e.toLowerCase().split(`1`);if(t.length!==2)return null;let n=t[0],r=t[1];if(!n||!r||n!==`dgb`)return null;let i=[];for(let e of r){let t=`qpzry9x8gf2tvdw0s3jn54khce6mua7l`.indexOf(e);if(t===-1)return null;i.push(t)}let a=i.slice(0,-6);if(a.length<1)return null;let o=a[0];if(o===void 0)return null;let s=Rt(a.slice(1),5,8,!1);return s?{version:o,program:new Uint8Array(s)}:null}function Rt(e,t,n,r){let i=0,a=0,o=[],s=(1<<n)-1;for(let r of e){if(r<0||r>>t!==0)return null;for(i=i<<t|r,a+=t;a>=n;)a-=n,o.push(i>>a&s)}if(r)a>0&&o.push(i<<n-a&s);else if(a>=t||i<<n-a&s)return null;return o}function zt(e,t){let n=new TextEncoder().encode(t),r=new TextEncoder().encode(e),i=[],a=r.length;if(a<253)i.push(a);else if(a<=65535)i.push(253,a&255,a>>8&255);else if(a<=4294967295)i.push(254,a&255,a>>8&255,a>>16&255,a>>24&255);else throw Error(`Message too long`);let o=new Uint8Array(i),s=n.length+o.length+r.length,c=new Uint8Array(s),l=0;return c.set(n,l),l+=n.length,c.set(o,l),l+=o.length,c.set(r,l),k(k(c))}function Bt(e,t){if(t.length!==65)throw Error(`Invalid signature length`);if(t[0]===void 0)throw Error(`Invalid signature`);let n=t.slice(1,33),r=t.slice(33,65),i=[];for(let t=0;t<4;t++)try{let a=new bt.Signature(BigInt(`0x`+Array.from(n).map(e=>e.toString(16).padStart(2,`0`)).join(``)),BigInt(`0x`+Array.from(r).map(e=>e.toString(16).padStart(2,`0`)).join(``))).addRecoveryBit(t).recoverPublicKey(e),o=a.toBytes(!0),s=a.toBytes(!1);i.push(o),i.push(s)}catch{continue}if(i.length===0)throw Error(`Failed to recover any public keys`);return i}function Vt(e){return Pt(k(e))}function Ht(e,t){if(e.startsWith(`D`)||e.startsWith(`S`))try{let n=It(e);if(n.length<25)return!1;let r=n.slice(0,-4),i=n.slice(-4),a=k(k(r)).slice(0,4);if(!i.every((e,t)=>e===a[t]))return!1;let o=r.slice(1),s=Vt(t);return o.every((e,t)=>e===s[t])}catch{return!1}if(e.toLowerCase().startsWith(`dgb1`))try{let n=Lt(e);if(!n)return!1;let{version:r,program:i}=n;if(r===0){let e=t;if(t.length===65){let n=t[64]%2==0;e=new Uint8Array(33),e[0]=n?2:3,e.set(t.slice(1,33),1)}let n=Vt(e);return i.every((e,t)=>e===n[t])}return!1}catch{return!1}return!1}async function Ut(e,t,r){try{let n=Uint8Array.from(globalThis.atob(r),e=>e.charCodeAt(0));if(n.length!==65)throw Error(`Invalid signature length`);let i=Bt(zt(e,`DigiByte Signed Message:
2
+ `),n);for(let e of i)if(Ht(t,e))return!0;return!1}catch(e){throw new n(`Signature verification failed: ${e instanceof Error?e.message:String(e)}`)}}function Wt(e=16){return(0,t.randomBytes)(e).toString(`hex`)}function Gt(e){if(!e.callbackUrl)throw new n(`Callback URL is required.`);let t;try{t=new URL(e.callbackUrl)}catch(e){throw new n(`Invalid callback URL: ${e.message}`)}let r=t.host+t.pathname,i=e.nonce||Wt(),a=e.unsecure?`1`:`0`;if(e.unsecure&&t.protocol!==`http:`)throw new n(`Unsecure flag is true, but callback URL does not use http protocol.`);if(!e.unsecure&&t.protocol!==`https:`)throw new n(`Callback URL must use https protocol unless unsecure flag is set to true.`);return`digiid://${r}?x=${i}&u=${a}`}async function Kt(e,t){let{address:r,uri:i,signature:a}=e,{expectedCallbackUrl:o,expectedNonce:s}=t;if(!r||!i||!a)throw new n(`Missing required callback data: address, uri, or signature.`);let c;try{let e=i.replace(/^digiid:/,`http:`);c=new URL(e)}catch(e){throw new n(`Invalid URI received in callback: ${e.message}`)}let l=c.searchParams.get(`x`),u=c.searchParams.get(`u`),d=c.host+c.pathname;if(l===null||u===null)throw new n(`URI missing nonce (x) or unsecure (u) parameter.`);let f;try{f=typeof o==`string`?new URL(o):o}catch(e){throw new n(`Invalid expectedCallbackUrl provided: ${e.message}`)}let p=f.host+f.pathname;if(d!==p)throw new n(`Callback URL mismatch: URI contained "${d}", expected "${p}"`);let m=f.protocol;if(u===`1`&&m!==`http:`)throw new n(`URI indicates unsecure (u=1), but expectedCallbackUrl is not http.`);if(u===`0`&&m!==`https:`)throw new n(`URI indicates secure (u=0), but expectedCallbackUrl is not https.`);if(s&&l!==s)throw new n(`Nonce mismatch: URI contained "${l}", expected "${s}". Possible replay attack.`);try{if(!await Ut(i,r,a))throw new n(`Invalid signature.`)}catch(e){throw e instanceof n?e:new n(`Unexpected error during signature verification: ${e.message}`)}return{isValid:!0,address:r,nonce:l}}e.DigiIDError=n,e._internalVerifySignature=Ut,e.generateDigiIDUri=Gt,e.verifyDigiIDCallback=Kt});
3
+ //# sourceMappingURL=digiid-ts.umd.js.map