nostrCryptoJs top-level constant

String const nostrCryptoJs

Bundled nostr-crypto-bundle JS code. Generated from lib/assets/nostr_crypto.src.js using esbuild. To regenerate: cd lib/assets && ./build.sh

Implementation

const String nostrCryptoJs = r'''
var NostrCryptoModule=(()=>{function fe(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}function ct(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(`${r}expected number, got ${typeof e}`)}if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new RangeError(`${r}expected integer >= 0, got ${e}`)}}function et(e,t,r=""){let n=fe(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let c=r&&`"${r}" `,i=s?` of length ${t}`:"",f=n?`length=${o}`:`type=${typeof e}`,a=c+"expected Uint8Array"+i+", got "+f;throw n?new RangeError(a):new TypeError(a)}return e}function qt(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(ct(e.outputLen),ct(e.blockLen),e.outputLen<1)throw new Error('"outputLen" must be >= 1');if(e.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Bt(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 Ct(e,t){et(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function dt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function jt(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Q(e,t){return e<<32-t|e>>>t}var Ve=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",kn=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function ht(e){if(et(e),Ve)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=kn[e[r]];return t}var st={_0:48,_9:57,A:65,F:70,a:97,f:102};function De(e){if(e>=st._0&&e<=st._9)return e-st._0;if(e>=st.A&&e<=st.F)return e-(st.A-10);if(e>=st.a&&e<=st.f)return e-(st.a-10)}function ae(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(Ve)try{return Uint8Array.fromHex(e)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let t=e.length,r=t/2;if(t%2)throw new RangeError("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let c=De(e.charCodeAt(s)),i=De(e.charCodeAt(s+1));if(c===void 0||i===void 0){let f=e[s]+e[s+1];throw new RangeError('hex string expected, got non-hex character "'+f+'" at index '+s)}n[o]=c*16+i}return n}function Me(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];et(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}function Ze(e,t={}){let r=(o,s)=>e(s).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function Tt(e=32){ct(e,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(e>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}var Ke=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 Ye(e,t,r){return e&t^e&r^t&r}var Dt=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,o){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=jt(this.buffer)}update(t){Bt(this),et(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let c=0;c<s;){let i=Math.min(o-this.pos,s-c);if(i===o){let f=jt(t);for(;o<=s-c;c+=o)this.process(f,c);continue}n.set(t.subarray(c,c+i),this.pos),this.pos+=i,c+=i,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Bt(this),Ct(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:c}=this;r[c++]=128,dt(this.buffer.subarray(c)),this.padOffset>o-c&&(this.process(n,0),c=0);for(let h=c;h<o;h++)r[h]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let i=jt(t),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let a=f/4,l=this.get();if(a>l.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<a;h++)i.setUint32(4*h,l[h],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:c,pos:i}=this;return t.destroyed=c,t.finished=s,t.length=o,t.pos=i,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},it=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var qn=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),ue=class extends Dt{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:o,E:s,F:c,G:i,H:f}=this;return[t,r,n,o,s,c,i,f]}set(t,r,n,o,s,c,i,f){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=c|0,this.G=i|0,this.H=f|0}process(t,r){for(let h=0;h<16;h++,r+=4)ft[h]=t.getUint32(r,!1);for(let h=16;h<64;h++){let R=ft[h-15],g=ft[h-2],E=Q(R,7)^Q(R,18)^R>>>3,S=Q(g,17)^Q(g,19)^g>>>10;ft[h]=S+ft[h-7]+E+ft[h-16]|0}let{A:n,B:o,C:s,D:c,E:i,F:f,G:a,H:l}=this;for(let h=0;h<64;h++){let R=Q(i,6)^Q(i,11)^Q(i,25),g=l+R+ze(i,f,a)+qn[h]+ft[h]|0,S=(Q(n,2)^Q(n,13)^Q(n,22))+Ye(n,o,s)|0;l=a,a=f,f=i,i=c+g|0,c=s,s=o,o=n,n=g+S|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,c=c+this.D|0,i=i+this.E|0,f=f+this.F|0,a=a+this.G|0,l=l+this.H|0,this.set(n,o,s,c,i,f,a,l)}roundClean(){dt(ft)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),dt(this.buffer)}},le=class extends ue{A=it[0]|0;B=it[1]|0;C=it[2]|0;D=it[3]|0;E=it[4]|0;F=it[5]|0;G=it[6]|0;H=it[7]|0;constructor(){super(32)}};var vt=Ze(()=>new le,Ke(1));var N=(e,t,r)=>et(e,t,r),he=ct,pe=ht,W=(...e)=>Me(...e),Zt=e=>ae(e),ye=fe,be=e=>Tt(e),Mt=BigInt(0),de=BigInt(1);function pt(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new TypeError(r+"expected boolean, got type="+typeof e)}return e}function Kt(e){if(typeof e=="bigint"){if(!Vt(e))throw new RangeError("positive bigint expected, got "+e)}else he(e);return e}function Ft(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(r+"expected number, got type="+typeof e)}if(!Number.isSafeInteger(e)){let r=t&&`"${t}" `;throw new RangeError(r+"expected safe integer, got "+e)}}function It(e){let t=Kt(e).toString(16);return t.length&1?"0"+t:t}function $e(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?Mt:BigInt("0x"+e)}function at(e){return $e(ht(e))}function ge(e){return $e(ht(Cn(et(e)).reverse()))}function zt(e,t){if(ct(t),t===0)throw new RangeError("zero length");e=Kt(e);let r=e.toString(16);if(r.length>t*2)throw new RangeError("number too large");return ae(r.padStart(t*2,"0"))}function xe(e,t){return zt(e,t).reverse()}function Cn(e){return Uint8Array.from(N(e))}function Ge(e){if(typeof e!="string")throw new TypeError("ascii string expected, got "+typeof e);return Uint8Array.from(e,(t,r)=>{let n=t.charCodeAt(0);if(t.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${e[r]}" with code ${n} at position ${r}`);return n})}var Vt=e=>typeof e=="bigint"&&Mt<=e;function jn(e,t,r){return Vt(e)&&Vt(t)&&Vt(r)&&t<=e&&e<r}function we(e,t,r,n){if(!jn(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function St(e){if(e<Mt)throw new Error("expected non-negative bigint, got "+e);let t;for(t=0;e>Mt;e>>=de,t+=1);return t}var Ut=e=>(de<<BigInt(e))-de;function Pe(e,t,r){if(ct(e,"hashLen"),ct(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=B=>new Uint8Array(B),o=Uint8Array.of(),s=Uint8Array.of(0),c=Uint8Array.of(1),i=1e3,f=n(e),a=n(e),l=0,h=()=>{f.fill(1),a.fill(0),l=0},R=(...B)=>r(a,W(f,...B)),g=(B=o)=>{a=R(s,B),f=R(),B.length!==0&&(a=R(c,B),f=R())},E=()=>{if(l++>=i)throw new Error("drbg: tried max amount of iterations");let B=0,L=[];for(;B<t;){f=R();let H=f.slice();L.push(H),B+=f.length}return W(...L)};return(B,L)=>{h(),g(B);let H;for(;(H=L(E()))===void 0;)g();return h(),H}}function yt(e,t={},r={}){if(Object.prototype.toString.call(e)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,c,i){if(!i&&c!=="function"&&!Object.hasOwn(e,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let f=e[s];if(i&&f===void 0)return;let a=typeof f;if(a!==c||f===null)throw new TypeError(`param "${s}" is invalid: expected ${c}, got ${a}`)}let o=(s,c)=>Object.entries(s).forEach(([i,f])=>n(i,f,c));o(t,!1),o(r,!0)}var $=BigInt(0),M=BigInt(1),bt=BigInt(2),Je=BigInt(3),tn=BigInt(4),en=BigInt(5),Dn=BigInt(7),nn=BigInt(8),Vn=BigInt(9),rn=BigInt(16);function J(e,t){if(t<=$)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=$?r:t+r}function X(e,t,r){if(t<$)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >$;)n*=n,n%=r;return n}function Xe(e,t){if(e===$)throw new Error("invert: expected non-zero number");if(t<=$)throw new Error("invert: expected positive modulus, got "+t);let r=J(e,t),n=t,o=$,s=M,c=M,i=$;for(;r!==$;){let a=n/r,l=n-r*a,h=o-c*a,R=s-i*a;n=r,r=l,o=c,s=i,c=h,i=R}if(n!==M)throw new Error("invert: does not exist");return J(o,t)}function me(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function on(e,t){let r=e,n=(r.ORDER+M)/tn,o=r.pow(t,n);return me(r,o,t),o}function Mn(e,t){let r=e,n=(r.ORDER-en)/nn,o=r.mul(t,bt),s=r.pow(o,n),c=r.mul(t,s),i=r.mul(r.mul(c,bt),s),f=r.mul(c,r.sub(i,r.ONE));return me(r,f,t),f}function Zn(e){let t=At(e),r=sn(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),c=(e+Dn)/rn;return((i,f)=>{let a=i,l=a.pow(f,c),h=a.mul(l,n),R=a.mul(l,o),g=a.mul(l,s),E=a.eql(a.sqr(h),f),S=a.eql(a.sqr(R),f);l=a.cmov(l,h,E),h=a.cmov(g,R,S);let B=a.eql(a.sqr(h),f),L=a.cmov(l,h,B);return me(a,L,f),L})}function sn(e){if(e<Je)throw new Error("sqrt is not defined for small field");let t=e-M,r=0;for(;t%bt===$;)t/=bt,r++;let n=bt,o=At(e);for(;We(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return on;let s=o.pow(n,t),c=(t+M)/bt;return function(f,a){let l=f;if(l.is0(a))return a;if(We(l,a)!==1)throw new Error("Cannot find square root");let h=r,R=l.mul(l.ONE,s),g=l.pow(a,t),E=l.pow(a,c);for(;!l.eql(g,l.ONE);){if(l.is0(g))return l.ZERO;let S=1,B=l.sqr(g);for(;!l.eql(B,l.ONE);)if(S++,B=l.sqr(B),S===h)throw new Error("Cannot find square root");let L=M<<BigInt(h-S-1),H=l.pow(R,L);h=S,R=l.sqr(H),g=l.mul(g,R),E=l.mul(E,H)}return E}}function Kn(e){return e%tn===Je?on:e%nn===en?Mn:e%rn===Vn?Zn(e):sn(e)}var zn=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ee(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=zn.reduce((n,o)=>(n[o]="function",n),t);if(yt(e,r),Ft(e.BYTES,"BYTES"),Ft(e.BITS,"BITS"),e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=M)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function Yn(e,t,r){let n=e;if(r<$)throw new Error("invalid exponent, negatives unsupported");if(r===$)return n.ONE;if(r===M)return t;let o=n.ONE,s=t;for(;r>$;)r&M&&(o=n.mul(o,s)),s=n.sqr(s),r>>=M;return o}function $t(e,t,r=!1){let n=e,o=new Array(t.length).fill(r?n.ZERO:void 0),s=t.reduce((i,f,a)=>n.is0(f)?i:(o[a]=i,n.mul(i,f)),n.ONE),c=n.inv(s);return t.reduceRight((i,f,a)=>n.is0(f)?i:(o[a]=n.mul(i,o[a]),n.mul(i,f)),c),o}function We(e,t){let r=e,n=(r.ORDER-M)/bt,o=r.pow(t,n),s=r.eql(o,r.ONE),c=r.eql(o,r.ZERO),i=r.eql(o,r.neg(r.ONE));if(!s&&!c&&!i)throw new Error("invalid Legendre symbol result");return s?1:c?0:-1}function $n(e,t){if(t!==void 0&&he(t),e<=$)throw new Error("invalid n length: expected positive n, got "+e);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let r=St(e);if(t!==void 0&&t<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${t})`);let n=t!==void 0?t:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var Qe=new WeakMap,Yt=class{ORDER;BITS;BYTES;isLE;ZERO=$;ONE=M;_lengths;_mod;constructor(t,r={}){if(t<=M)throw new Error("invalid field: expected ORDER > 1, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=$n(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(t){return J(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return $<=t&&t<this.ORDER}is0(t){return t===$}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&M)===M}neg(t){return J(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return J(t*t,this.ORDER)}add(t,r){return J(t+r,this.ORDER)}sub(t,r){return J(t-r,this.ORDER)}mul(t,r){return J(t*r,this.ORDER)}pow(t,r){return Yn(this,t,r)}div(t,r){return J(t*Xe(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 Xe(t,this.ORDER)}sqrt(t){let r=Qe.get(this);return r||Qe.set(this,r=Kn(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?xe(t,this.BYTES):zt(t,this.BYTES)}fromBytes(t,r=!1){N(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:c,_mod:i}=this;if(n){if(t.length<1||!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let a=new Uint8Array(o);a.set(t,s?0:a.length-t.length),t=a}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let f=s?ge(t):at(t);if(i&&(f=J(f,c)),!r&&!this.isValid(f))throw new Error("invalid field element: outside of range 0..ORDER");return f}invertBatch(t){return $t(this,t)}cmov(t,r,n){return pt(n,"condition"),n?r:t}};Object.freeze(Yt.prototype);function At(e,t={}){return new Yt(e,t)}function cn(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=M)throw new Error("field order must be greater than 1");let t=St(e-M);return Math.ceil(t/8)}function Be(e){let t=cn(e);return t+Math.ceil(t/2)}function Gt(e,t,r=!1){N(e);let n=e.length,o=cn(t),s=Math.max(Be(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let c=r?ge(e):at(e),i=J(c,t-M)+M;return r?xe(i,o):zt(i,o)}var Rt=BigInt(0),gt=BigInt(1);function _t(e,t){let r=t.negate();return e?r:t}function Re(e,t){let r=$t(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function ln(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function ve(e,t){ln(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=Ut(e),c=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:c}}function fn(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:c}=r,i=Number(e&o),f=e>>c;i>n&&(i-=s,f+=gt);let a=t*n,l=a+Math.abs(i)-1,h=i===0,R=i<0,g=t%2!==0;return{nextN:f,offset:l,isZero:h,isNeg:R,isNegF:g,offsetF:a}}var Se=new WeakMap,dn=new WeakMap;function Ae(e){return dn.get(e)||1}function an(e){if(e!==Rt)throw new Error("invalid wNAF")}var Pt=class{BASE;ZERO;Fn;bits;constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>Rt;)r&gt&&(n=n.add(o)),o=o.double(),r>>=gt;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=ve(r,this.bits),s=[],c=t,i=c;for(let f=0;f<n;f++){i=c,s.push(i);for(let a=1;a<o;a++)i=i.add(c),s.push(i);c=i.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,c=ve(t,this.bits);for(let i=0;i<c.windows;i++){let{nextN:f,offset:a,isZero:l,isNeg:h,isNegF:R,offsetF:g}=fn(n,i,c);n=f,l?s=s.add(_t(R,r[g])):o=o.add(_t(h,r[a]))}return an(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=ve(t,this.bits);for(let c=0;c<s.windows&&n!==Rt;c++){let{nextN:i,offset:f,isZero:a,isNeg:l}=fn(n,c,s);if(n=i,!a){let h=r[f];o=o.add(l?h.negate():h)}}return an(n),o}getPrecomputes(t,r,n){let o=Se.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),Se.set(r,o))),o}cached(t,r,n){let o=Ae(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=Ae(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){ln(r,this.bits),dn.set(t,r),Se.delete(t)}hasCache(t){return Ae(t)!==1}};function hn(e,t,r,n){let o=t,s=e.ZERO,c=e.ZERO;for(;r>Rt||n>Rt;)r&gt&&(s=s.add(o)),n&gt&&(c=c.add(o)),o=o.double(),r>>=gt,n>>=gt;return{p1:s,p2:c}}function un(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Ee(t),t}else return At(e,{isLE:r})}function pn(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let f of["p","n","h"]){let a=t[f];if(!(typeof a=="bigint"&&a>Rt))throw new Error(`CURVE.${f} must be positive bigint`)}let o=un(t.p,r.Fp,n),s=un(t.n,r.Fn,n),i=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let f of i)if(!o.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:o,Fn:s}}function Xt(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var Wt=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(qt(t),et(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;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),dt(o)}update(t){return Bt(this),this.iHash.update(t),this}digestInto(t){Bt(this),Ct(t,this),this.finished=!0;let r=t.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:c,outputLen:i}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=c,t.outputLen=i,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()}},yn=(()=>{let e=((t,r,n)=>new Wt(t,r).update(n).digest());return e.create=(t,r)=>new Wt(t,r),e})();var bn=(e,t)=>(e+(e>=0?t:-t)/gn)/t;function Gn(e,t,r){we("scalar",e,nt,r);let[[n,o],[s,c]]=t,i=bn(c*e,r),f=bn(-o*e,r),a=e-i*n-f*s,l=-i*o-f*c,h=a<nt,R=l<nt;h&&(a=-a),R&&(l=-l);let g=Ut(Math.ceil(St(r)/2))+ut;if(a<nt||a>=g||l<nt||l>=g)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:h,k1:a,k2neg:R,k2:l}}function Oe(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Le(e,t){yt(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return pt(r.lowS,"lowS"),pt(r.prehash,"prehash"),r.format!==void 0&&Oe(r.format),r}var Te=class extends Error{constructor(t=""){super(t)}},tt={Err:Te,_tlv:{encode:(e,t)=>{let{Err:r}=tt;if(Ft(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(typeof t!="string")throw new TypeError('"data" expected string, got type='+typeof t);if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=It(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?It(o.length/2|128):"";return It(e)+s+o+t},decode(e,t){let{Err:r}=tt;t=N(t,void 0,"DER data");let n=0;if(e<0||e>255)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),c=0;if(!s)c=o;else{let f=o&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");let a=t.subarray(n,n+f);if(a.length!==f)throw new r("tlv.decode: length bytes not complete");if(a[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let l of a)c=c<<8|l;if(n+=f,c<128)throw new r("tlv.decode(long): not minimal encoding")}let i=t.subarray(n,n+c);if(i.length!==c)throw new r("tlv.decode: wrong value length");return{v:i,l:t.subarray(n+c)}}},_int:{encode(e){let{Err:t}=tt;if(Kt(e),e<nt)throw new t("integer: negative integers are not allowed");let r=It(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){let{Err:t}=tt;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 at(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=tt,o=N(e,void 0,"signature"),{v:s,l:c}=n.decode(48,o);if(c.length)throw new t("invalid signature: left bytes after parsing");let{v:i,l:f}=n.decode(2,s),{v:a,l}=n.decode(2,f);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(i),s:r.decode(a)}},hexFromSig(e){let{_tlv:t,_int:r}=tt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}};Object.freeze(tt._tlv);Object.freeze(tt._int);Object.freeze(tt);var nt=BigInt(0),ut=BigInt(1),gn=BigInt(2),Qt=BigInt(3),Pn=BigInt(4);function xn(e,t={}){let r=pn("weierstrass",e,t),n=r.Fp,o=r.Fn,s=r.CURVE,{h:c,n:i}=s;yt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:f,allowInfinityPoint:a}=t;if(f&&(!n.is0(s.a)||typeof f.beta!="bigint"||!Array.isArray(f.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let l=mn(n,o);function h(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function R(F,d,w){if(a&&d.is0())return Uint8Array.of(0);let{x:v,y:p}=d.toAffine(),u=n.toBytes(v);if(pt(w,"isCompressed"),w){h();let y=!n.isOdd(p);return W(wn(y),u)}else return W(Uint8Array.of(4),u,n.toBytes(p))}function g(F){N(F,void 0,"Point");let{publicKey:d,publicKeyUncompressed:w}=l,v=F.length,p=F[0],u=F.subarray(1);if(a&&v===1&&p===0)return{x:n.ZERO,y:n.ZERO};if(v===d&&(p===2||p===3)){let y=n.fromBytes(u);if(!n.isValid(y))throw new Error("bad point: is not on curve, wrong x");let x=B(y),b;try{b=n.sqrt(x)}catch(O){let _=O instanceof Error?": "+O.message:"";throw new Error("bad point: is not on curve, sqrt error"+_)}h();let m=n.isOdd(b);return(p&1)===1!==m&&(b=n.neg(b)),{x:y,y:b}}else if(v===w&&p===4){let y=n.BYTES,x=n.fromBytes(u.subarray(0,y)),b=n.fromBytes(u.subarray(y,y*2));if(!L(x,b))throw new Error("bad point: is not on curve");return{x,y:b}}else throw new Error(`bad point: got length ${v}, expected compressed=${d} or uncompressed=${w}`)}let E=t.toBytes===void 0?R:t.toBytes,S=t.fromBytes===void 0?g:t.fromBytes;function B(F){let d=n.sqr(F),w=n.mul(d,F);return n.add(n.add(w,n.mul(F,s.a)),s.b)}function L(F,d){let w=n.sqr(d),v=B(F);return n.eql(w,v)}if(!L(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let H=n.mul(n.pow(s.a,Qt),Pn),G=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(H,G)))throw new Error("bad curve params: a or b");function Z(F,d,w=!1){if(!n.isValid(d)||w&&n.is0(d))throw new Error(`bad point coordinate ${F}`);return d}function k(F){if(!(F instanceof T))throw new Error("Weierstrass Point expected")}function C(F){if(!f||!f.basises)throw new Error("no endo");return Gn(F,f.basises,o.ORDER)}function D(F,d,w,v,p){return w=new T(n.mul(w.X,F),w.Y,w.Z),d=_t(v,d),w=_t(p,w),d.add(w)}class T{static BASE=new T(s.Gx,s.Gy,n.ONE);static ZERO=new T(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(d,w,v){this.X=Z("x",d),this.Y=Z("y",w,!0),this.Z=Z("z",v),Object.freeze(this)}static CURVE(){return s}static fromAffine(d){let{x:w,y:v}=d||{};if(!d||!n.isValid(w)||!n.isValid(v))throw new Error("invalid affine point");if(d instanceof T)throw new Error("projective point not allowed");return n.is0(w)&&n.is0(v)?T.ZERO:new T(w,v,n.ONE)}static fromBytes(d){let w=T.fromAffine(S(N(d,void 0,"point")));return w.assertValidity(),w}static fromHex(d){return T.fromBytes(Zt(d))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(d=8,w=!0){return q.createCache(this,d),w||this.multiply(Qt),this}assertValidity(){let d=this;if(d.is0()){if(t.allowInfinityPoint&&n.is0(d.X)&&n.eql(d.Y,n.ONE)&&n.is0(d.Z))return;throw new Error("bad point: ZERO")}let{x:w,y:v}=d.toAffine();if(!n.isValid(w)||!n.isValid(v))throw new Error("bad point: x or y not field elements");if(!L(w,v))throw new Error("bad point: equation left != right");if(!d.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:d}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(d)}equals(d){k(d);let{X:w,Y:v,Z:p}=this,{X:u,Y:y,Z:x}=d,b=n.eql(n.mul(w,x),n.mul(u,p)),m=n.eql(n.mul(v,x),n.mul(y,p));return b&&m}negate(){return new T(this.X,n.neg(this.Y),this.Z)}double(){let{a:d,b:w}=s,v=n.mul(w,Qt),{X:p,Y:u,Z:y}=this,x=n.ZERO,b=n.ZERO,m=n.ZERO,A=n.mul(p,p),O=n.mul(u,u),_=n.mul(y,y),I=n.mul(p,u);return I=n.add(I,I),m=n.mul(p,y),m=n.add(m,m),x=n.mul(d,m),b=n.mul(v,_),b=n.add(x,b),x=n.sub(O,b),b=n.add(O,b),b=n.mul(x,b),x=n.mul(I,x),m=n.mul(v,m),_=n.mul(d,_),I=n.sub(A,_),I=n.mul(d,I),I=n.add(I,m),m=n.add(A,A),A=n.add(m,A),A=n.add(A,_),A=n.mul(A,I),b=n.add(b,A),_=n.mul(u,y),_=n.add(_,_),A=n.mul(_,I),x=n.sub(x,A),m=n.mul(_,O),m=n.add(m,m),m=n.add(m,m),new T(x,b,m)}add(d){k(d);let{X:w,Y:v,Z:p}=this,{X:u,Y:y,Z:x}=d,b=n.ZERO,m=n.ZERO,A=n.ZERO,O=s.a,_=n.mul(s.b,Qt),I=n.mul(w,u),K=n.mul(v,y),z=n.mul(p,x),Y=n.add(w,v),j=n.add(u,y);Y=n.mul(Y,j),j=n.add(I,K),Y=n.sub(Y,j),j=n.add(w,p);let P=n.add(u,x);return j=n.mul(j,P),P=n.add(I,z),j=n.sub(j,P),P=n.add(v,p),b=n.add(y,x),P=n.mul(P,b),b=n.add(K,z),P=n.sub(P,b),A=n.mul(O,j),b=n.mul(_,z),A=n.add(b,A),b=n.sub(K,A),A=n.add(K,A),m=n.mul(b,A),K=n.add(I,I),K=n.add(K,I),z=n.mul(O,z),j=n.mul(_,j),K=n.add(K,z),z=n.sub(I,z),z=n.mul(O,z),j=n.add(j,z),I=n.mul(K,j),m=n.add(m,I),I=n.mul(P,j),b=n.mul(Y,b),b=n.sub(b,I),I=n.mul(Y,K),A=n.mul(P,A),A=n.add(A,I),new T(b,m,A)}subtract(d){return k(d),this.add(d.negate())}is0(){return this.equals(T.ZERO)}multiply(d){let{endo:w}=t;if(!o.isValidNot0(d))throw new RangeError("invalid scalar: out of range");let v,p,u=y=>q.cached(this,y,x=>Re(T,x));if(w){let{k1neg:y,k1:x,k2neg:b,k2:m}=C(d),{p:A,f:O}=u(x),{p:_,f:I}=u(m);p=O.add(I),v=D(w.beta,A,_,y,b)}else{let{p:y,f:x}=u(d);v=y,p=x}return Re(T,[v,p])[0]}multiplyUnsafe(d){let{endo:w}=t,v=this,p=d;if(!o.isValid(p))throw new RangeError("invalid scalar: out of range");if(p===nt||v.is0())return T.ZERO;if(p===ut)return v;if(q.hasCache(this))return this.multiply(p);if(w){let{k1neg:u,k1:y,k2neg:x,k2:b}=C(p),{p1:m,p2:A}=hn(T,v,y,b);return D(w.beta,m,A,u,x)}else return q.unsafe(v,p)}toAffine(d){let w=this,v=d,{X:p,Y:u,Z:y}=w;if(n.eql(y,n.ONE))return{x:p,y:u};let x=w.is0();v==null&&(v=x?n.ONE:n.inv(y));let b=n.mul(p,v),m=n.mul(u,v),A=n.mul(y,v);if(x)return{x:n.ZERO,y:n.ZERO};if(!n.eql(A,n.ONE))throw new Error("invZ was invalid");return{x:b,y:m}}isTorsionFree(){let{isTorsionFree:d}=t;return c===ut?!0:d?d(T,this):q.unsafe(this,i).is0()}clearCofactor(){let{clearCofactor:d}=t;return c===ut?this:d?d(T,this):this.multiplyUnsafe(c)}isSmallOrder(){return c===ut?this.is0():this.clearCofactor().is0()}toBytes(d=!0){return pt(d,"isCompressed"),this.assertValidity(),E(T,this,d)}toHex(d=!0){return pe(this.toBytes(d))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let V=o.BITS,q=new Pt(T,t.endo?Math.ceil(V/2):V);return V>=8&&T.BASE.precompute(8),Object.freeze(T.prototype),Object.freeze(T),T}function wn(e){return Uint8Array.of(e?2:3)}function mn(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Xn(e,t={}){let{Fn:r}=e,n=t.randomBytes===void 0?be:t.randomBytes,o=Object.assign(mn(e.Fp,r),{seed:Math.max(Be(r.ORDER),16)});function s(g){try{let E=r.fromBytes(g);return r.isValidNot0(E)}catch{return!1}}function c(g,E){let{publicKey:S,publicKeyUncompressed:B}=o;try{let L=g.length;return E===!0&&L!==S||E===!1&&L!==B?!1:!!e.fromBytes(g)}catch{return!1}}function i(g){return g=g===void 0?n(o.seed):g,Gt(N(g,o.seed,"seed"),r.ORDER)}function f(g,E=!0){return e.BASE.multiply(r.fromBytes(g)).toBytes(E)}function a(g){let{secretKey:E,publicKey:S,publicKeyUncompressed:B}=o,L=r._lengths;if(!ye(g))return;let H=N(g,void 0,"key").length,G=H===S||H===B,Z=H===E||!!L?.includes(H);if(!(G&&Z))return G}function l(g,E,S=!0){if(a(g)===!0)throw new Error("first arg must be private key");if(a(E)===!1)throw new Error("second arg must be public key");let B=r.fromBytes(g);return e.fromBytes(E).multiply(B).toBytes(S)}let h={isValidSecretKey:s,isValidPublicKey:c,randomSecretKey:i},R=Xt(i,f);return Object.freeze(h),Object.freeze(o),Object.freeze({getPublicKey:f,getSharedSecret:l,keygen:R,Point:e,utils:h,lengths:o})}function En(e,t,r={}){let n=t;qt(n),yt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?be:r.randomBytes,s=r.hmac===void 0?(p,u)=>yn(n,p,u):r.hmac,{Fp:c,Fn:i}=e,{ORDER:f,BITS:a}=i,{keygen:l,getPublicKey:h,getSharedSecret:R,utils:g,lengths:E}=Xn(e,r),S={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},B=f*gn+ut<c.ORDER;function L(p){let u=f>>ut;return p>u}function H(p,u){if(!i.isValidNot0(u))throw new Error(`invalid signature ${p}: out of range 1..Point.Fn.ORDER`);return u}function G(){if(B)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function Z(p,u){Oe(u);let y=E.signature,x=u==="compact"?y:u==="recovered"?y+1:void 0;return N(p,x)}class k{r;s;recovery;constructor(u,y,x){if(this.r=H("r",u),this.s=H("s",y),x!=null){if(G(),![0,1,2,3].includes(x))throw new Error("invalid recovery id");this.recovery=x}Object.freeze(this)}static fromBytes(u,y=S.format){Z(u,y);let x;if(y==="der"){let{r:O,s:_}=tt.toSig(N(u));return new k(O,_)}y==="recovered"&&(x=u[0],y="compact",u=u.subarray(1));let b=E.signature/2,m=u.subarray(0,b),A=u.subarray(b,b*2);return new k(i.fromBytes(m),i.fromBytes(A),x)}static fromHex(u,y){return this.fromBytes(Zt(u),y)}assertRecovery(){let{recovery:u}=this;if(u==null)throw new Error("invalid recovery id: must be present");return u}addRecoveryBit(u){return new k(this.r,this.s,u)}recoverPublicKey(u){let{r:y,s:x}=this,b=this.assertRecovery(),m=b===2||b===3?y+f:y;if(!c.isValid(m))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let A=c.toBytes(m),O=e.fromBytes(W(wn((b&1)===0),A)),_=i.inv(m),I=D(N(u,void 0,"msgHash")),K=i.create(-I*_),z=i.create(x*_),Y=e.BASE.multiplyUnsafe(K).add(O.multiplyUnsafe(z));if(Y.is0())throw new Error("invalid recovery: point at infinify");return Y.assertValidity(),Y}hasHighS(){return L(this.s)}toBytes(u=S.format){if(Oe(u),u==="der")return Zt(tt.hexFromSig(this));let{r:y,s:x}=this,b=i.toBytes(y),m=i.toBytes(x);return u==="recovered"?(G(),W(Uint8Array.of(this.assertRecovery()),b,m)):W(b,m)}toHex(u){return pe(this.toBytes(u))}}Object.freeze(k.prototype),Object.freeze(k);let C=r.bits2int===void 0?function(u){if(u.length>8192)throw new Error("input is too large");let y=at(u),x=u.length*8-a;return x>0?y>>BigInt(x):y}:r.bits2int,D=r.bits2int_modN===void 0?function(u){return i.create(C(u))}:r.bits2int_modN,T=Ut(a);function V(p){return we("num < 2^"+a,p,nt,T),i.toBytes(p)}function q(p,u){return N(p,void 0,"message"),u?N(n(p),void 0,"prehashed message"):p}function F(p,u,y){let{lowS:x,prehash:b,extraEntropy:m}=Le(y,S);p=q(p,b);let A=D(p),O=i.fromBytes(u);if(!i.isValidNot0(O))throw new Error("invalid private key");let _=[V(O),V(A)];if(m!=null&&m!==!1){let Y=m===!0?o(E.secretKey):m;_.push(N(Y,void 0,"extraEntropy"))}let I=W(..._),K=A;function z(Y){let j=C(Y);if(!i.isValidNot0(j))return;let P=i.inv(j),Et=e.BASE.multiply(j).toAffine(),Ot=i.create(Et.x);if(Ot===nt)return;let kt=i.create(P*i.create(K+Ot*O));if(kt===nt)return;let Ce=(Et.x===Ot?0:2)|Number(Et.y&ut),je=kt;return x&&L(kt)&&(je=i.neg(kt),Ce^=1),new k(Ot,je,B?void 0:Ce)}return{seed:I,k2sig:z}}function d(p,u,y={}){let{seed:x,k2sig:b}=F(p,u,y);return Pe(n.outputLen,i.BYTES,s)(x,b).toBytes(y.format)}function w(p,u,y,x={}){let{lowS:b,prehash:m,format:A}=Le(x,S);if(y=N(y,void 0,"publicKey"),u=q(u,m),!ye(p)){let O=p instanceof k?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+O)}Z(p,A);try{let O=k.fromBytes(p,A),_=e.fromBytes(y);if(b&&O.hasHighS())return!1;let{r:I,s:K}=O,z=D(u),Y=i.inv(K),j=i.create(z*Y),P=i.create(I*Y),Et=e.BASE.multiplyUnsafe(j).add(_.multiplyUnsafe(P));return Et.is0()?!1:i.create(Et.x)===I}catch{return!1}}function v(p,u,y={}){let{prehash:x}=Le(y,S);return u=q(u,x),k.fromBytes(p,"recovered").recoverPublicKey(u).toBytes()}return Object.freeze({keygen:l,getPublicKey:h,getSharedSecret:R,utils:g,lengths:E,Point:e,sign:d,verify:w,recoverPublicKey:v,Signature:k,hash:n})}var ee={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Wn={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},Qn=BigInt(0),Fe=BigInt(2);function Jn(e){let t=ee.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),c=BigInt(23),i=BigInt(44),f=BigInt(88),a=e*e*e%t,l=a*a*e%t,h=X(l,r,t)*l%t,R=X(h,r,t)*l%t,g=X(R,Fe,t)*a%t,E=X(g,o,t)*g%t,S=X(E,s,t)*E%t,B=X(S,i,t)*S%t,L=X(B,f,t)*B%t,H=X(L,i,t)*S%t,G=X(H,r,t)*l%t,Z=X(G,c,t)*E%t,k=X(Z,n,t)*a%t,C=X(k,Fe,t);if(!Jt.eql(Jt.sqr(C),e))throw new Error("Cannot find square root");return C}var Jt=At(ee.p,{sqrt:Jn}),xt=xn(ee,{Fp:Jt,endo:Wn}),Sn=En(xt,vt),Bn={};function te(e,...t){let r=Bn[e];if(r===void 0){let n=vt(Ge(e));r=W(n,n),Bn[e]=r}return vt(W(r,...t))}var ne=e=>e.toBytes(!0).slice(1),re=e=>e%Fe===Qn;function An(e){let{Fn:t,BASE:r}=xt,n=t.fromBytes(e),o=r.multiply(n);return{scalar:re(o.y)?n:t.neg(n),bytes:ne(o)}}function Rn(e){let t=Jt;if(!t.isValidNot0(e))throw new Error("invalid x: Fail if x \u2265 p");let r=t.create(e*e),n=t.create(r*e+BigInt(7)),o=t.sqrt(n);re(o)||(o=t.neg(o));let s=xt.fromAffine({x:e,y:o});return s.assertValidity(),s}var Lt=at;function Ln(...e){return xt.Fn.create(Lt(te("BIP0340/challenge",...e)))}function vn(e){return An(e).bytes}function tr(e,t,r=Tt(32)){let{Fn:n,BASE:o}=xt,s=N(e,void 0,"message"),{bytes:c,scalar:i}=An(t),f=N(r,32,"auxRand"),a=n.toBytes(i^Lt(te("BIP0340/aux",f))),l=te("BIP0340/nonce",a,c,s),h=n.create(Lt(l));if(h===0n)throw new Error("sign failed: k is zero");let R=o.multiply(h),g=re(R.y)?h:n.neg(h),E=ne(R),S=Ln(E,c,s),B=new Uint8Array(64);if(B.set(E,0),B.set(n.toBytes(n.create(g+S*i)),32),!On(B,s,c))throw new Error("sign: Invalid signature produced");return B}function On(e,t,r){let{Fp:n,Fn:o,BASE:s}=xt,c=N(e,64,"signature"),i=N(t,void 0,"message"),f=N(r,32,"publicKey");try{let a=Rn(Lt(f)),l=Lt(c.subarray(0,32));if(!n.isValidNot0(l))return!1;let h=Lt(c.subarray(32,64));if(!o.isValidNot0(h))return!1;let R=Ln(o.toBytes(l),ne(a),i),g=s.multiplyUnsafe(h).add(a.multiplyUnsafe(o.neg(R))),{x:E,y:S}=g.toAffine();return!(g.is0()||!re(S)||E!==l)}catch{return!1}}var oe=(()=>{let r=n=>(n=n===void 0?Tt(48):n,Gt(n,ee.n));return Object.freeze({keygen:Xt(r,vn),getPublicKey:vn,sign:tr,verify:On,Point:xt,utils:Object.freeze({randomSecretKey:r,taggedHash:te,lift_x:Rn,pointToBytes:ne}),lengths:Object.freeze({secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48})})})();function er(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}function Ie(e){if(typeof e!="boolean")throw new TypeError(`boolean expected, not ${e}`)}function se(e){if(typeof e!="number")throw new TypeError("number expected, got "+typeof e);if(!Number.isSafeInteger(e)||e<0)throw new RangeError("positive integer expected, got "+e)}function wt(e,t,r=""){let n=er(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let c=r&&`"${r}" `,i=s?` of length ${t}`:"",f=n?`length=${o}`:`type=${typeof e}`,a=c+"expected Uint8Array"+i+", got "+f;throw n?new RangeError(a):new TypeError(a)}return e}function rt(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function Ue(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}var mt=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68,nr=e=>e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255;var rr=e=>{for(let t=0;t<e.length;t++)e[t]=nr(e[t]);return e},lt=mt?e=>e:rr;function Tn(e,t){if(t==null||typeof t!="object")throw new Error("options must be defined");return Object.assign(e,t)}function Fn(e,t,r=!0){if(t===void 0)return new Uint8Array(e);if(wt(t,void 0,"output"),t.length!==e)throw new Error('"output" expected Uint8Array of length '+e+", got: "+t.length);if(r&&!Ht(t))throw new Error("invalid output, must be aligned");return t}function Ht(e){return e.byteOffset%4===0}function _e(e){return Uint8Array.from(wt(e))}var Un=e=>Uint8Array.from(e.split(""),t=>t.charCodeAt(0)),or=lt(rt(Un("expand 16-byte k"))),sr=lt(rt(Un("expand 32-byte k")));function U(e,t){return e<<t|e>>>32-t}var Nt=64,ir=16,He=2**32-1,In=Uint32Array.of();function cr(e,t,r,n,o,s,c,i){let f=o.length,a=new Uint8Array(Nt),l=rt(a),h=mt&&Ht(o)&&Ht(s),R=h?rt(o):In,g=h?rt(s):In;if(!mt){for(let E=0;E<f;c++){if(e(t,r,n,l,c,i),lt(l),c>=He)throw new Error("arx: counter overflow");let S=Math.min(Nt,f-E);for(let B=0,L;B<S;B++)L=E+B,s[L]=o[L]^a[B];E+=S}return}for(let E=0;E<f;c++){if(e(t,r,n,l,c,i),c>=He)throw new Error("arx: counter overflow");let S=Math.min(Nt,f-E);if(h&&S===Nt){let B=E/4;if(E%4!==0)throw new Error("arx: invalid block position");for(let L=0,H;L<ir;L++)H=B+L,g[H]=R[H]^l[L];E+=Nt;continue}for(let B=0,L;B<S;B++)L=E+B,s[L]=o[L]^a[B];E+=S}}function _n(e,t){let{allowShortKeys:r,extendNonceFn:n,counterLength:o,counterRight:s,rounds:c}=Tn({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof e!="function")throw new Error("core must be a function");return se(o),se(c),Ie(s),Ie(r),(i,f,a,l,h=0)=>{wt(i,void 0,"key"),wt(f,void 0,"nonce"),wt(a,void 0,"data");let R=a.length;if(l=Fn(R,l,!1),se(h),h<0||h>=He)throw new Error("arx: counter overflow");let g=[],E=i.length,S,B;if(E===32)g.push(S=_e(i)),B=sr;else if(E===16&&r)S=new Uint8Array(32),S.set(i),S.set(i,16),B=or,g.push(S);else throw wt(i,32,"arx key"),new Error("invalid key size");(!mt||!Ht(f))&&g.push(f=_e(f));let L=rt(S);if(n){if(f.length!==24)throw new Error("arx: extended nonce must be 24 bytes");let Z=f.subarray(0,16);if(mt)n(B,L,rt(Z),L);else{let k=lt(Uint32Array.from(B));n(k,L,rt(Z),L),Ue(k),lt(L)}f=f.subarray(16)}else mt||lt(L);let H=16-o;if(H!==f.length)throw new Error(`arx: nonce must be ${H} or 16 bytes`);if(H!==12){let Z=new Uint8Array(12);Z.set(f,s?0:12-f.length),f=Z,g.push(f)}let G=lt(rt(f));try{return cr(e,B,L,G,a,l,h,c),l}finally{Ue(...g)}}}function fr(e,t,r,n,o,s=20){let c=e[0],i=e[1],f=e[2],a=e[3],l=t[0],h=t[1],R=t[2],g=t[3],E=t[4],S=t[5],B=t[6],L=t[7],H=o,G=r[0],Z=r[1],k=r[2],C=c,D=i,T=f,V=a,q=l,F=h,d=R,w=g,v=E,p=S,u=B,y=L,x=H,b=G,m=Z,A=k;for(let _=0;_<s;_+=2)C=C+q|0,x=U(x^C,16),v=v+x|0,q=U(q^v,12),C=C+q|0,x=U(x^C,8),v=v+x|0,q=U(q^v,7),D=D+F|0,b=U(b^D,16),p=p+b|0,F=U(F^p,12),D=D+F|0,b=U(b^D,8),p=p+b|0,F=U(F^p,7),T=T+d|0,m=U(m^T,16),u=u+m|0,d=U(d^u,12),T=T+d|0,m=U(m^T,8),u=u+m|0,d=U(d^u,7),V=V+w|0,A=U(A^V,16),y=y+A|0,w=U(w^y,12),V=V+w|0,A=U(A^V,8),y=y+A|0,w=U(w^y,7),C=C+F|0,A=U(A^C,16),u=u+A|0,F=U(F^u,12),C=C+F|0,A=U(A^C,8),u=u+A|0,F=U(F^u,7),D=D+d|0,x=U(x^D,16),y=y+x|0,d=U(d^y,12),D=D+d|0,x=U(x^D,8),y=y+x|0,d=U(d^y,7),T=T+w|0,b=U(b^T,16),v=v+b|0,w=U(w^v,12),T=T+w|0,b=U(b^T,8),v=v+b|0,w=U(w^v,7),V=V+q|0,m=U(m^V,16),p=p+m|0,q=U(q^p,12),V=V+q|0,m=U(m^V,8),p=p+m|0,q=U(q^p,7);let O=0;n[O++]=c+C|0,n[O++]=i+D|0,n[O++]=f+T|0,n[O++]=a+V|0,n[O++]=l+q|0,n[O++]=h+F|0,n[O++]=R+d|0,n[O++]=g+w|0,n[O++]=E+v|0,n[O++]=S+p|0,n[O++]=B+u|0,n[O++]=L+y|0,n[O++]=H+x|0,n[O++]=G+b|0,n[O++]=Z+m|0,n[O++]=k+A|0}var Ne=_n(fr,{counterRight:!1,counterLength:4,allowShortKeys:!1});function ar(e){return JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content])}function ur(e){let t=ar(e),n=new TextEncoder().encode(t);return ht(vt(n))}async function lr(e){try{let t=ur(e);if(e.id!==t)return!1;let r=ot(e.sig),n=ot(e.id),o=ot(e.pubkey);return oe.verify(r,n,o)}catch(t){return console.error("Event verification error:",t),!1}}async function dr(e,t,r){try{let n=ot(e),o=ot(t),s=ot(r);return oe.verify(n,o,s)}catch(n){return console.error("Signature verification error:",n),!1}}async function hr(e,t){try{let r=ot(e),n=ot(t),o=oe.sign(n,r);return ht(o)}catch(r){throw console.error("Event signing error:",r),r}}function ot(e){let t=new Uint8Array(e.length/2);for(let r=0;r<t.length;r++)t[r]=parseInt(e.substr(r*2,2),16);return t}function ke(e){let t="";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return btoa(t)}function qe(e){let t=atob(e),r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t.charCodeAt(n);return r}function ie(e,t){let r=ot(e),n=t;t.length===64&&(n="02"+t);let o=ot(n);return Sn.getSharedSecret(r,o,!0).slice(1,33)}async function ce(e,t){let r=await crypto.subtle.importKey("raw",e,{name:"HMAC",hash:"SHA-256"},!1,["sign"]),n=await crypto.subtle.sign("HMAC",r,t);return new Uint8Array(n)}async function Hn(e,t){return ce(t,e)}async function Nn(e,t,r){let o=Math.ceil(r/32),s=new Uint8Array(0),c=new Uint8Array(0);for(let i=1;i<=o;i++){let f=new Uint8Array(c.length+t.length+1);f.set(c,0),f.set(t,c.length),f[f.length-1]=i,c=await ce(e,f);let a=new Uint8Array(s.length+c.length);a.set(s,0),a.set(c,s.length),s=a}return s.slice(0,r)}function pr(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}async function yr(e,t,r){let n=ie(e,t),o=await crypto.subtle.importKey("raw",n,{name:"AES-CBC"},!1,["encrypt"]),s=crypto.getRandomValues(new Uint8Array(16)),c=new TextEncoder,i=await crypto.subtle.encrypt({name:"AES-CBC",iv:s},o,c.encode(r)),f=new Uint8Array(i);return`${ke(f)}?iv=${ke(s)}`}async function br(e,t,r){let[n,o]=r.split("?iv=");if(!o)throw new Error("Invalid NIP-04 ciphertext");let s=ie(e,t),c=await crypto.subtle.importKey("raw",s,{name:"AES-CBC"},!1,["decrypt"]),i=qe(o),f=qe(n),a=await crypto.subtle.decrypt({name:"AES-CBC",iv:i},c,f);return new TextDecoder().decode(a)}function gr(e){if(e<1||e>65535)throw new Error("Invalid plaintext length");let t=2**(e-1).toString(2).length,r=t<=256?32:t/8;return e<=32?32:r*Math.ceil(e/r)}function xr(e){let t=e.length,r=gr(t),n=new Uint8Array(r+2);return n[0]=t>>8&255,n[1]=t&255,n.set(e,2),n}function wr(e){let t=(e[0]<<8)+e[1];if(t===0||t>e.length-2)throw new Error("Invalid padding");return e.slice(2,2+t)}async function mr(e,t,r){let n=ie(e,t),o=new TextEncoder().encode("nip44-v2"),s=await Hn(n,o),c=crypto.getRandomValues(new Uint8Array(32)),i=await Nn(s,c,76),f=i.slice(0,32),a=i.slice(32,44),l=i.slice(44,76),h=new TextEncoder,R=xr(h.encode(r)),g=Ne(f,a,R),E=await ce(l,new Uint8Array([...c,...g])),S=new Uint8Array(33+g.length+32);return S[0]=2,S.set(c,1),S.set(g,33),S.set(E,33+g.length),ke(S)}async function Er(e,t,r){let n=qe(r);if(n.length<65||n.length>87472)throw new Error("Invalid payload size");if(n[0]!==2)throw new Error("Unsupported version");let o=n.slice(1,33),s=n.slice(n.length-32),c=n.slice(33,n.length-32),i=ie(e,t),f=new TextEncoder().encode("nip44-v2"),a=await Hn(i,f),l=await Nn(a,o,76),h=l.slice(0,32),R=l.slice(32,44),g=l.slice(44,76),E=await ce(g,new Uint8Array([...o,...c]));if(!pr(E,s))throw new Error("Invalid MAC");let S=Ne(h,R,c),B=wr(S);return new TextDecoder().decode(B)}window.NostrCrypto={verifyEvent:lr,verifySignature:dr,signEvent:hr,nip04Encrypt:yr,nip04Decrypt:br,nip44Encrypt:mr,nip44Decrypt:Er};})();
/*! Bundled license information:

@noble/curves/utils.js:
@noble/curves/abstract/modular.js:
@noble/curves/abstract/curve.js:
@noble/curves/abstract/weierstrass.js:
@noble/curves/secp256k1.js:
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)

@noble/ciphers/utils.js:
  (*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) *)
*/
''';