nostr-crypto-utils 0.5.1 → 0.5.2

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.
Files changed (41) hide show
  1. package/dist/browser/crypto.nostr-crypto-utils.min.js +15 -1
  2. package/dist/browser/crypto.nostr-crypto-utils.min.js.map +7 -0
  3. package/dist/browser/main.nostr-crypto-utils.min.js +32 -0
  4. package/dist/browser/main.nostr-crypto-utils.min.js.map +7 -0
  5. package/dist/browser/nip-44.nostr-crypto-utils.min.js +21 -2
  6. package/dist/browser/nip-44.nostr-crypto-utils.min.js.map +7 -0
  7. package/dist/browser/nip-46.nostr-crypto-utils.min.js +21 -2
  8. package/dist/browser/nip-46.nostr-crypto-utils.min.js.map +7 -0
  9. package/dist/browser/nip-49.nostr-crypto-utils.min.js +13 -1
  10. package/dist/browser/nip-49.nostr-crypto-utils.min.js.map +7 -0
  11. package/dist/browser/protocol.nostr-crypto-utils.min.js +2 -1
  12. package/dist/browser/protocol.nostr-crypto-utils.min.js.map +7 -0
  13. package/dist/browser/validation.nostr-crypto-utils.min.js +15 -1
  14. package/dist/browser/validation.nostr-crypto-utils.min.js.map +7 -0
  15. package/package.json +4 -7
  16. package/dist/browser/116.nostr-crypto-utils.min.js +0 -2
  17. package/dist/browser/116.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
  18. package/dist/browser/126.nostr-crypto-utils.min.js +0 -2
  19. package/dist/browser/126.nostr-crypto-utils.min.js.LICENSE.txt +0 -3
  20. package/dist/browser/287.nostr-crypto-utils.min.js +0 -2
  21. package/dist/browser/287.nostr-crypto-utils.min.js.LICENSE.txt +0 -6
  22. package/dist/browser/343.nostr-crypto-utils.min.js +0 -1
  23. package/dist/browser/348.nostr-crypto-utils.min.js +0 -2
  24. package/dist/browser/348.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
  25. package/dist/browser/524.nostr-crypto-utils.min.js +0 -1
  26. package/dist/browser/575.nostr-crypto-utils.min.js +0 -2
  27. package/dist/browser/575.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
  28. package/dist/browser/615.nostr-crypto-utils.min.js +0 -2
  29. package/dist/browser/615.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
  30. package/dist/browser/668.nostr-crypto-utils.min.js +0 -2
  31. package/dist/browser/668.nostr-crypto-utils.min.js.LICENSE.txt +0 -6
  32. package/dist/browser/705.nostr-crypto-utils.min.js +0 -2
  33. package/dist/browser/705.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
  34. package/dist/browser/732.nostr-crypto-utils.min.js +0 -1
  35. package/dist/browser/843.nostr-crypto-utils.min.js +0 -2
  36. package/dist/browser/843.nostr-crypto-utils.min.js.LICENSE.txt +0 -3
  37. package/dist/browser/main-31743c5a.nostr-crypto-utils.min.js +0 -1
  38. package/dist/browser/main-96d4916e.nostr-crypto-utils.min.js +0 -1
  39. package/dist/browser/main-9fdc67c2.nostr-crypto-utils.min.js +0 -1
  40. package/dist/browser/nip-44.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
  41. package/dist/browser/nip-46.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
@@ -1,2 +1,21 @@
1
- /*! For license information please see nip-44.nostr-crypto-utils.min.js.LICENSE.txt */
2
- !function(f,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.NostrCryptoUtils=e():(f.NostrCryptoUtils=f.NostrCryptoUtils||{},f.NostrCryptoUtils["nip-44"]=e())}(this,()=>(()=>{"use strict";var f,e={510(f,e,a){e.ND=e.bI=void 0;const d=a(76),t=(a(175),a(562)),c=a(761),o=a(967),b=a(705),r=a(627),n={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},i={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},p=BigInt(2),s=(0,o.Field)(n.p,{sqrt:function(f){const e=n.p,a=BigInt(3),d=BigInt(6),t=BigInt(11),c=BigInt(22),b=BigInt(23),r=BigInt(44),i=BigInt(88),x=f*f*f%e,u=x*x*f%e,g=(0,o.pow2)(u,a,e)*u%e,B=(0,o.pow2)(g,a,e)*u%e,I=(0,o.pow2)(B,p,e)*x%e,l=(0,o.pow2)(I,t,e)*I%e,h=(0,o.pow2)(l,c,e)*l%e,v=(0,o.pow2)(h,r,e)*h%e,y=(0,o.pow2)(v,i,e)*v%e,w=(0,o.pow2)(y,r,e)*h%e,m=(0,o.pow2)(w,a,e)*u%e,C=(0,o.pow2)(m,b,e)*l%e,N=(0,o.pow2)(C,d,e)*x%e,O=(0,o.pow2)(N,p,e);if(!s.eql(s.sqr(O),f))throw new Error("Cannot find square root");return O}});e.bI=(0,t.createCurve)({...n,Fp:s,lowS:!0,endo:i},d.sha256);r.bytesToNumberBE;e.bI.utils.randomSecretKey,r.numberToBytesBE,r.bytesToNumberBE,o.mod;const x=(()=>(0,c.isogenyMap)(s,[["0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7","0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581","0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262","0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"],["0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b","0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14","0x0000000000000000000000000000000000000000000000000000000000000001"],["0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c","0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3","0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931","0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"],["0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b","0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573","0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f","0x0000000000000000000000000000000000000000000000000000000000000001"]].map(f=>f.map(f=>BigInt(f)))))(),u=(()=>(0,b.mapToCurveSimpleSWU)(s,{A:BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),B:BigInt("1771"),Z:s.create(BigInt("-11"))}))();e.ND=(0,c.createHasher)(e.bI.Point,f=>{const{x:e,y:a}=u(s.create(f[0]));return x(e,a)},{DST:"secp256k1_XMD:SHA-256_SSWU_RO_",encodeDST:"secp256k1_XMD:SHA-256_SSWU_NU_",p:s.ORDER,m:1,k:128,expand:"xmd",hash:d.sha256}),e.ND.hashToCurve,e.ND.encodeToCurve},298(f,e,a){a(732),a(246),a(510),a(139),a(615),a(623),a(175),a(116),new TextEncoder,new TextDecoder}},a={};function d(f){var t=a[f];if(void 0!==t)return t.exports;var c=a[f]={exports:{}};return e[f](c,c.exports,d),c.exports}d.m=e,f=[],d.O=(e,a,t,c)=>{if(!a){var o=1/0;for(i=0;i<f.length;i++){for(var[a,t,c]=f[i],b=!0,r=0;r<a.length;r++)(!1&c||o>=c)&&Object.keys(d.O).every(f=>d.O[f](a[r]))?a.splice(r--,1):(b=!1,c<o&&(o=c));if(b){f.splice(i--,1);var n=t();void 0!==n&&(e=n)}}return e}c=c||0;for(var i=f.length;i>0&&f[i-1][2]>c;i--)f[i]=f[i-1];f[i]=[a,t,c]},d.d=(f,e)=>{for(var a in e)d.o(e,a)&&!d.o(f,a)&&Object.defineProperty(f,a,{enumerable:!0,get:e[a]})},d.o=(f,e)=>Object.prototype.hasOwnProperty.call(f,e),(()=>{var f={869:0};d.O.j=e=>0===f[e];var e=(e,a)=>{var t,c,[o,b,r]=a,n=0;if(o.some(e=>0!==f[e])){for(t in b)d.o(b,t)&&(d.m[t]=b[t]);if(r)var i=r(d)}for(e&&e(a);n<o.length;n++)c=o[n],d.o(f,c)&&f[c]&&f[c][0](),f[c]=0;return d.O(i)},a=this.webpackChunkNostrCryptoUtils=this.webpackChunkNostrCryptoUtils||[];a.forEach(e.bind(null,0)),a.push=e.bind(null,a.push.bind(a))})();var t=d.O(void 0,[575,348,705,524,732,126,116],()=>d(298));return(t=d.O(t)).default})());
1
+ "use strict";var NostrCryptoUtils=NostrCryptoUtils||{};NostrCryptoUtils.NIP44=(()=>{var Kt=Object.defineProperty;var Yn=Object.getOwnPropertyDescriptor;var Wn=Object.getOwnPropertyNames;var Xn=Object.prototype.hasOwnProperty;var Qn=(e,t,r)=>t in e?Kt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var Jn=(e,t)=>{for(var r in t)Kt(e,r,{get:t[r],enumerable:!0})},Fn=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Wn(t))!Xn.call(e,o)&&o!==r&&Kt(e,o,{get:()=>t[o],enumerable:!(n=Yn(t,o))||n.enumerable});return e};var tr=e=>Fn(Kt({},"__esModule",{value:!0}),e);var ot=(e,t,r)=>Qn(e,typeof t!="symbol"?t+"":t,r);var Qr={};Jn(Qr,{calcPaddedLen:()=>ce,decrypt:()=>zn,encrypt:()=>Pn,getConversationKey:()=>$n,v2:()=>Xr});function er(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Zt(e){if(typeof e!="boolean")throw new Error(`boolean expected, not ${e}`)}function jt(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function z(e,t,r=""){let n=er(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,c=s?` of length ${t}`:"",f=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+c+", got "+f)}return e}function fe(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 Me(e,t){z(e,void 0,"output");let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function st(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function it(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function nr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}var rr=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function De(e,t){if(t==null||typeof t!="object")throw new Error("options must be defined");return Object.assign(e,t)}function $t(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}var ae=(e,t)=>{function r(n,...o){if(z(n,void 0,"key"),!rr)throw new Error("Non little-endian hardware is not yet supported");if(e.nonceLength!==void 0){let l=o[0];z(l,e.varSizeNonce?void 0:e.nonceLength,"nonce")}let s=e.tagLength;s&&o[1]!==void 0&&z(o[1],void 0,"AAD");let i=t(n,...o),c=(l,b)=>{if(b!==void 0){if(l!==2)throw new Error("cipher output not supported");z(b,void 0,"output")}},f=!1;return{encrypt(l,b){if(f)throw new Error("cannot encrypt() twice with same key + nonce");return f=!0,z(l),c(i.encrypt.length,b),i.encrypt(l,b)},decrypt(l,b){if(z(l),s&&l.length<s)throw new Error('"ciphertext" expected length bigger than tagLength='+s);return c(i.decrypt.length,b),i.decrypt(l,b)}}}return Object.assign(r,e),r};function ue(e,t,r=!0){if(t===void 0)return new Uint8Array(e);if(t.length!==e)throw new Error('"output" expected Uint8Array of length '+e+", got: "+t.length);if(r&&!or(t))throw new Error("invalid output, must be aligned");return t}function Ke(e,t,r){Zt(r);let n=new Uint8Array(16),o=nr(n);return o.setBigUint64(0,BigInt(t),r),o.setBigUint64(8,BigInt(e),r),n}function or(e){return e.byteOffset%4===0}function Ut(e){return Uint8Array.from(e)}var je=e=>Uint8Array.from(e.split(""),t=>t.charCodeAt(0)),sr=je("expand 16-byte k"),ir=je("expand 32-byte k"),cr=st(sr),fr=st(ir);function U(e,t){return e<<t|e>>>32-t}function le(e){return e.byteOffset%4===0}var Gt=64,ar=16,$e=2**32-1,Ze=Uint32Array.of();function ur(e,t,r,n,o,s,i,c){let f=o.length,u=new Uint8Array(Gt),l=st(u),b=le(o)&&le(s),a=b?st(o):Ze,h=b?st(s):Ze;for(let w=0;w<f;i++){if(e(t,r,n,l,i,c),i>=$e)throw new Error("arx: counter overflow");let m=Math.min(Gt,f-w);if(b&&m===Gt){let A=w/4;if(w%4!==0)throw new Error("arx: invalid block position");for(let H=0,R;H<ar;H++)R=A+H,h[R]=a[R]^l[H];w+=Gt;continue}for(let A=0,H;A<m;A++)H=w+A,s[H]=o[H]^u[A];w+=m}}function de(e,t){let{allowShortKeys:r,extendNonceFn:n,counterLength:o,counterRight:s,rounds:i}=De({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof e!="function")throw new Error("core must be a function");return jt(o),jt(i),Zt(s),Zt(r),(c,f,u,l,b=0)=>{z(c,void 0,"key"),z(f,void 0,"nonce"),z(u,void 0,"data");let a=u.length;if(l===void 0&&(l=new Uint8Array(a)),z(l,void 0,"output"),jt(b),b<0||b>=$e)throw new Error("arx: counter overflow");if(l.length<a)throw new Error(`arx: output (${l.length}) is shorter than data (${a})`);let h=[],w=c.length,m,A;if(w===32)h.push(m=Ut(c)),A=fr;else if(w===16&&r)m=new Uint8Array(32),m.set(c),m.set(c,16),A=cr,h.push(m);else throw z(c,32,"arx key"),new Error("invalid key size");le(f)||h.push(f=Ut(f));let H=st(m);if(n){if(f.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(A,H,st(f.subarray(0,16)),H),f=f.subarray(16)}let R=16-o;if(R!==f.length)throw new Error(`arx: nonce must be ${R} or 16 bytes`);if(R!==12){let K=new Uint8Array(12);K.set(f,s?0:12-f.length),f=K,h.push(f)}let O=st(f);return ur(e,A,H,O,u,l,b,i),it(...h),l}}function Y(e,t){return e[t++]&255|(e[t++]&255)<<8}var he=class{constructor(t){ot(this,"blockLen",16);ot(this,"outputLen",16);ot(this,"buffer",new Uint8Array(16));ot(this,"r",new Uint16Array(10));ot(this,"h",new Uint16Array(10));ot(this,"pad",new Uint16Array(8));ot(this,"pos",0);ot(this,"finished",!1);t=Ut(z(t,32,"key"));let r=Y(t,0),n=Y(t,2),o=Y(t,4),s=Y(t,6),i=Y(t,8),c=Y(t,10),f=Y(t,12),u=Y(t,14);this.r[0]=r&8191,this.r[1]=(r>>>13|n<<3)&8191,this.r[2]=(n>>>10|o<<6)&7939,this.r[3]=(o>>>7|s<<9)&8191,this.r[4]=(s>>>4|i<<12)&255,this.r[5]=i>>>1&8190,this.r[6]=(i>>>14|c<<2)&8191,this.r[7]=(c>>>11|f<<5)&8065,this.r[8]=(f>>>8|u<<8)&8191,this.r[9]=u>>>5&127;for(let l=0;l<8;l++)this.pad[l]=Y(t,16+2*l)}process(t,r,n=!1){let o=n?0:2048,{h:s,r:i}=this,c=i[0],f=i[1],u=i[2],l=i[3],b=i[4],a=i[5],h=i[6],w=i[7],m=i[8],A=i[9],H=Y(t,r+0),R=Y(t,r+2),O=Y(t,r+4),K=Y(t,r+6),P=Y(t,r+8),Z=Y(t,r+10),$=Y(t,r+12),j=Y(t,r+14),_=s[0]+(H&8191),k=s[1]+((H>>>13|R<<3)&8191),C=s[2]+((R>>>10|O<<6)&8191),I=s[3]+((O>>>7|K<<9)&8191),x=s[4]+((K>>>4|P<<12)&8191),p=s[5]+(P>>>1&8191),d=s[6]+((P>>>14|Z<<2)&8191),g=s[7]+((Z>>>11|$<<5)&8191),E=s[8]+(($>>>8|j<<8)&8191),v=s[9]+(j>>>5|o),y=0,B=y+_*c+k*(5*A)+C*(5*m)+I*(5*w)+x*(5*h);y=B>>>13,B&=8191,B+=p*(5*a)+d*(5*b)+g*(5*l)+E*(5*u)+v*(5*f),y+=B>>>13,B&=8191;let S=y+_*f+k*c+C*(5*A)+I*(5*m)+x*(5*w);y=S>>>13,S&=8191,S+=p*(5*h)+d*(5*a)+g*(5*b)+E*(5*l)+v*(5*u),y+=S>>>13,S&=8191;let L=y+_*u+k*f+C*c+I*(5*A)+x*(5*m);y=L>>>13,L&=8191,L+=p*(5*w)+d*(5*h)+g*(5*a)+E*(5*b)+v*(5*l),y+=L>>>13,L&=8191;let q=y+_*l+k*u+C*f+I*c+x*(5*A);y=q>>>13,q&=8191,q+=p*(5*m)+d*(5*w)+g*(5*h)+E*(5*a)+v*(5*b),y+=q>>>13,q&=8191;let N=y+_*b+k*l+C*u+I*f+x*c;y=N>>>13,N&=8191,N+=p*(5*A)+d*(5*m)+g*(5*w)+E*(5*h)+v*(5*a),y+=N>>>13,N&=8191;let T=y+_*a+k*b+C*l+I*u+x*f;y=T>>>13,T&=8191,T+=p*c+d*(5*A)+g*(5*m)+E*(5*w)+v*(5*h),y+=T>>>13,T&=8191;let V=y+_*h+k*a+C*b+I*l+x*u;y=V>>>13,V&=8191,V+=p*f+d*c+g*(5*A)+E*(5*m)+v*(5*w),y+=V>>>13,V&=8191;let D=y+_*w+k*h+C*a+I*b+x*l;y=D>>>13,D&=8191,D+=p*u+d*f+g*c+E*(5*A)+v*(5*m),y+=D>>>13,D&=8191;let G=y+_*m+k*w+C*h+I*a+x*b;y=G>>>13,G&=8191,G+=p*l+d*u+g*f+E*c+v*(5*A),y+=G>>>13,G&=8191;let M=y+_*A+k*m+C*w+I*h+x*a;y=M>>>13,M&=8191,M+=p*b+d*l+g*u+E*f+v*c,y+=M>>>13,M&=8191,y=(y<<2)+y|0,y=y+B|0,B=y&8191,y=y>>>13,S+=y,s[0]=B,s[1]=S,s[2]=L,s[3]=q,s[4]=N,s[5]=T,s[6]=V,s[7]=D,s[8]=G,s[9]=M}finalize(){let{h:t,pad:r}=this,n=new Uint16Array(10),o=t[1]>>>13;t[1]&=8191;for(let c=2;c<10;c++)t[c]+=o,o=t[c]>>>13,t[c]&=8191;t[0]+=o*5,o=t[0]>>>13,t[0]&=8191,t[1]+=o,o=t[1]>>>13,t[1]&=8191,t[2]+=o,n[0]=t[0]+5,o=n[0]>>>13,n[0]&=8191;for(let c=1;c<10;c++)n[c]=t[c]+o,o=n[c]>>>13,n[c]&=8191;n[9]-=8192;let s=(o^1)-1;for(let c=0;c<10;c++)n[c]&=s;s=~s;for(let c=0;c<10;c++)t[c]=t[c]&s|n[c];t[0]=(t[0]|t[1]<<13)&65535,t[1]=(t[1]>>>3|t[2]<<10)&65535,t[2]=(t[2]>>>6|t[3]<<7)&65535,t[3]=(t[3]>>>9|t[4]<<4)&65535,t[4]=(t[4]>>>12|t[5]<<1|t[6]<<14)&65535,t[5]=(t[6]>>>2|t[7]<<11)&65535,t[6]=(t[7]>>>5|t[8]<<8)&65535,t[7]=(t[8]>>>8|t[9]<<5)&65535;let i=t[0]+r[0];t[0]=i&65535;for(let c=1;c<8;c++)i=(t[c]+r[c]|0)+(i>>>16)|0,t[c]=i&65535;it(n)}update(t){fe(this),z(t),t=Ut(t);let{buffer:r,blockLen:n}=this,o=t.length;for(let s=0;s<o;){let i=Math.min(n-this.pos,o-s);if(i===n){for(;n<=o-s;s+=n)this.process(t,s);continue}r.set(t.subarray(s,s+i),this.pos),this.pos+=i,s+=i,this.pos===n&&(this.process(r,0,!1),this.pos=0)}return this}destroy(){it(this.h,this.r,this.buffer,this.pad)}digestInto(t){fe(this),Me(t,this),this.finished=!0;let{buffer:r,h:n}=this,{pos:o}=this;if(o){for(r[o++]=1;o<16;o++)r[o]=0;this.process(r,0,!0)}this.finalize();let s=0;for(let i=0;i<8;i++)t[s++]=n[i]>>>0,t[s++]=n[i]>>>8;return t}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}};function lr(e){let t=(n,o)=>e(o).update(n).digest(),r=e(new Uint8Array(32));return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=n=>e(n),t}var Ge=lr(e=>new he(e));function Ye(e,t,r,n,o,s=20){let i=e[0],c=e[1],f=e[2],u=e[3],l=t[0],b=t[1],a=t[2],h=t[3],w=t[4],m=t[5],A=t[6],H=t[7],R=o,O=r[0],K=r[1],P=r[2],Z=i,$=c,j=f,_=u,k=l,C=b,I=a,x=h,p=w,d=m,g=A,E=H,v=R,y=O,B=K,S=P;for(let q=0;q<s;q+=2)Z=Z+k|0,v=U(v^Z,16),p=p+v|0,k=U(k^p,12),Z=Z+k|0,v=U(v^Z,8),p=p+v|0,k=U(k^p,7),$=$+C|0,y=U(y^$,16),d=d+y|0,C=U(C^d,12),$=$+C|0,y=U(y^$,8),d=d+y|0,C=U(C^d,7),j=j+I|0,B=U(B^j,16),g=g+B|0,I=U(I^g,12),j=j+I|0,B=U(B^j,8),g=g+B|0,I=U(I^g,7),_=_+x|0,S=U(S^_,16),E=E+S|0,x=U(x^E,12),_=_+x|0,S=U(S^_,8),E=E+S|0,x=U(x^E,7),Z=Z+C|0,S=U(S^Z,16),g=g+S|0,C=U(C^g,12),Z=Z+C|0,S=U(S^Z,8),g=g+S|0,C=U(C^g,7),$=$+I|0,v=U(v^$,16),E=E+v|0,I=U(I^E,12),$=$+I|0,v=U(v^$,8),E=E+v|0,I=U(I^E,7),j=j+x|0,y=U(y^j,16),p=p+y|0,x=U(x^p,12),j=j+x|0,y=U(y^j,8),p=p+y|0,x=U(x^p,7),_=_+k|0,B=U(B^_,16),d=d+B|0,k=U(k^d,12),_=_+k|0,B=U(B^_,8),d=d+B|0,k=U(k^d,7);let L=0;n[L++]=i+Z|0,n[L++]=c+$|0,n[L++]=f+j|0,n[L++]=u+_|0,n[L++]=l+k|0,n[L++]=b+C|0,n[L++]=a+I|0,n[L++]=h+x|0,n[L++]=w+p|0,n[L++]=m+d|0,n[L++]=A+g|0,n[L++]=H+E|0,n[L++]=R+v|0,n[L++]=O+y|0,n[L++]=K+B|0,n[L++]=P+S|0}function dr(e,t,r,n){let o=e[0],s=e[1],i=e[2],c=e[3],f=t[0],u=t[1],l=t[2],b=t[3],a=t[4],h=t[5],w=t[6],m=t[7],A=r[0],H=r[1],R=r[2],O=r[3];for(let P=0;P<20;P+=2)o=o+f|0,A=U(A^o,16),a=a+A|0,f=U(f^a,12),o=o+f|0,A=U(A^o,8),a=a+A|0,f=U(f^a,7),s=s+u|0,H=U(H^s,16),h=h+H|0,u=U(u^h,12),s=s+u|0,H=U(H^s,8),h=h+H|0,u=U(u^h,7),i=i+l|0,R=U(R^i,16),w=w+R|0,l=U(l^w,12),i=i+l|0,R=U(R^i,8),w=w+R|0,l=U(l^w,7),c=c+b|0,O=U(O^c,16),m=m+O|0,b=U(b^m,12),c=c+b|0,O=U(O^c,8),m=m+O|0,b=U(b^m,7),o=o+u|0,O=U(O^o,16),w=w+O|0,u=U(u^w,12),o=o+u|0,O=U(O^o,8),w=w+O|0,u=U(u^w,7),s=s+l|0,A=U(A^s,16),m=m+A|0,l=U(l^m,12),s=s+l|0,A=U(A^s,8),m=m+A|0,l=U(l^m,7),i=i+b|0,H=U(H^i,16),a=a+H|0,b=U(b^a,12),i=i+b|0,H=U(H^i,8),a=a+H|0,b=U(b^a,7),c=c+f|0,R=U(R^c,16),h=h+R|0,f=U(f^h,12),c=c+f|0,R=U(R^c,8),h=h+R|0,f=U(f^h,7);let K=0;n[K++]=o,n[K++]=s,n[K++]=i,n[K++]=c,n[K++]=A,n[K++]=H,n[K++]=R,n[K++]=O}var Pt=de(Ye,{counterRight:!1,counterLength:4,allowShortKeys:!1}),hr=de(Ye,{counterRight:!1,counterLength:8,extendNonceFn:dr,allowShortKeys:!1});var pr=new Uint8Array(16),Pe=(e,t)=>{e.update(t);let r=t.length%16;r&&e.update(pr.subarray(r))},xr=new Uint8Array(32);function ze(e,t,r,n,o){o!==void 0&&z(o,void 0,"AAD");let s=e(t,r,xr),i=Ke(n.length,o?o.length:0,!0),c=Ge.create(s);o&&Pe(c,o),Pe(c,n),c.update(i);let f=c.digest();return it(s,i),f}var We=e=>(t,r,n)=>({encrypt(s,i){let c=s.length;i=ue(c+16,i,!1),i.set(s);let f=i.subarray(0,-16);e(t,r,f,f,1);let u=ze(e,t,r,f,n);return i.set(u,c),it(u),i},decrypt(s,i){i=ue(s.length-16,i,!1);let c=s.subarray(0,-16),f=s.subarray(-16),u=ze(e,t,r,c,n);if(!$t(f,u))throw new Error("invalid tag");return i.set(s.subarray(0,-16)),e(t,r,i,i,1),it(u),i}}),bo=ae({blockSize:64,nonceLength:12,tagLength:16},We(Pt)),yo=ae({blockSize:64,nonceLength:24,tagLength:16},We(hr));var wt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Et(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function mt(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function nt(e,...t){if(!Et(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 Bt(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");mt(e.outputLen),mt(e.blockLen)}function _t(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 Qe(e,t){nt(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function ft(...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 rt(e,t){return e<<32-t|e>>>t}var Je=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",br=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function at(e){if(nt(e),Je)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=br[e[r]];return t}var ct={_0:48,_9:57,A:65,F:70,a:97,f:102};function Xe(e){if(e>=ct._0&&e<=ct._9)return e-ct._0;if(e>=ct.A&&e<=ct.F)return e-(ct.A-10);if(e>=ct.a&&e<=ct.f)return e-(ct.a-10)}function vt(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Je)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("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 i=Xe(e.charCodeAt(s)),c=Xe(e.charCodeAt(s+1));if(i===void 0||c===void 0){let f=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+f+'" at index '+s)}n[o]=i*16+c}return n}function Fe(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function pt(e){return typeof e=="string"&&(e=Fe(e)),nt(e),e}function X(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];nt(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}var Lt=class{};function tn(e){let t=n=>e().update(pt(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function It(e=32){if(wt&&typeof wt.getRandomValues=="function")return wt.getRandomValues(new Uint8Array(e));if(wt&&typeof wt.randomBytes=="function")return Uint8Array.from(wt.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function yr(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),c=Number(r&s),f=n?4:0,u=n?0:4;e.setUint32(t+f,i,n),e.setUint32(t+u,c,n)}function en(e,t,r){return e&t^~e&r}function nn(e,t,r){return e&t^e&r^t&r}var Yt=class extends Lt{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=zt(this.buffer)}update(t){_t(this),t=pt(t),nt(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let f=zt(t);for(;o<=s-i;i+=o)this.process(f,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){_t(this),Qe(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,ft(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let b=i;b<o;b++)r[b]=0;yr(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=zt(t),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=f/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let b=0;b<u;b++)c.setUint32(4*b,l[b],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},ut=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var gr=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]),xt=new Uint32Array(64),Wt=class extends Yt{constructor(t=32){super(64,t,8,!1),this.A=ut[0]|0,this.B=ut[1]|0,this.C=ut[2]|0,this.D=ut[3]|0,this.E=ut[4]|0,this.F=ut[5]|0,this.G=ut[6]|0,this.H=ut[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:c,H:f}=this;return[t,r,n,o,s,i,c,f]}set(t,r,n,o,s,i,c,f){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=f|0}process(t,r){for(let b=0;b<16;b++,r+=4)xt[b]=t.getUint32(r,!1);for(let b=16;b<64;b++){let a=xt[b-15],h=xt[b-2],w=rt(a,7)^rt(a,18)^a>>>3,m=rt(h,17)^rt(h,19)^h>>>10;xt[b]=m+xt[b-7]+w+xt[b-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:f,G:u,H:l}=this;for(let b=0;b<64;b++){let a=rt(c,6)^rt(c,11)^rt(c,25),h=l+a+en(c,f,u)+gr[b]+xt[b]|0,m=(rt(n,2)^rt(n,13)^rt(n,22))+nn(n,o,s)|0;l=u,u=f,f=c,c=i+h|0,i=s,s=o,o=n,n=h+m|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,f=f+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,o,s,i,c,f,u,l)}roundClean(){ft(xt)}destroy(){this.set(0,0,0,0,0,0,0,0),ft(this.buffer)}};var Xt=tn(()=>new Wt);var Qt=class extends Lt{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,Bt(t);let n=pt(r);if(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 o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),ft(s)}update(t){return _t(this),this.iHash.update(t),this}digestInto(t){_t(this),nt(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=s,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()}},lt=(e,t,r)=>new Qt(e,t).update(r).digest();lt.create=(e,t)=>new Qt(e,t);var be=BigInt(0),xe=BigInt(1);function Ct(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function bt(e,t,r=""){let n=Et(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,c=s?` of length ${t}`:"",f=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+c+", got "+f)}return e}function Nt(e){let t=e.toString(16);return t.length&1?"0"+t:t}function rn(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?be:BigInt("0x"+e)}function Ht(e){return rn(at(e))}function ye(e){return nt(e),rn(at(Uint8Array.from(e).reverse()))}function Jt(e,t){return vt(e.toString(16).padStart(t*2,"0"))}function ge(e,t){return Jt(e,t).reverse()}function Q(e,t,r){let n;if(typeof t=="string")try{n=vt(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(Et(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}var pe=e=>typeof e=="bigint"&&be<=e;function on(e,t,r){return pe(e)&&pe(t)&&pe(r)&&t<=e&&e<r}function sn(e,t,r,n){if(!on(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Ft(e){let t;for(t=0;e>be;e>>=xe,t+=1);return t}var yt=e=>(xe<<BigInt(e))-xe;function cn(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=h=>new Uint8Array(h),o=h=>Uint8Array.of(h),s=n(e),i=n(e),c=0,f=()=>{s.fill(1),i.fill(0),c=0},u=(...h)=>r(i,s,...h),l=(h=n(0))=>{i=u(o(0),h),s=u(),h.length!==0&&(i=u(o(1),h),s=u())},b=()=>{if(c++>=1e3)throw new Error("drbg: tried 1000 values");let h=0,w=[];for(;h<t;){s=u();let m=s.slice();w.push(m),h+=s.length}return X(...w)};return(h,w)=>{f(),l(h);let m;for(;!(m=w(b()));)l();return f(),m}}function kt(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let c=e[o];if(i&&c===void 0)return;let f=typeof c;if(f!==s||c===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${f}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}function we(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var F=BigInt(0),J=BigInt(1),At=BigInt(2),un=BigInt(3),ln=BigInt(4),dn=BigInt(5),wr=BigInt(7),hn=BigInt(8),mr=BigInt(9),pn=BigInt(16);function et(e,t){let r=e%t;return r>=F?r:t+r}function tt(e,t,r){let n=e;for(;t-- >F;)n*=n,n%=r;return n}function fn(e,t){if(e===F)throw new Error("invert: expected non-zero number");if(t<=F)throw new Error("invert: expected positive modulus, got "+t);let r=et(e,t),n=t,o=F,s=J,i=J,c=F;for(;r!==F;){let u=n/r,l=n%r,b=o-i*u,a=s-c*u;n=r,r=l,o=i,s=c,i=b,c=a}if(n!==J)throw new Error("invert: does not exist");return et(o,t)}function me(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function xn(e,t){let r=(e.ORDER+J)/ln,n=e.pow(t,r);return me(e,n,t),n}function Er(e,t){let r=(e.ORDER-dn)/hn,n=e.mul(t,At),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,At),o),c=e.mul(s,e.sub(i,e.ONE));return me(e,c,t),c}function Br(e){let t=gt(e),r=bn(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+wr)/pn;return(c,f)=>{let u=c.pow(f,i),l=c.mul(u,n),b=c.mul(u,o),a=c.mul(u,s),h=c.eql(c.sqr(l),f),w=c.eql(c.sqr(b),f);u=c.cmov(u,l,h),l=c.cmov(a,b,w);let m=c.eql(c.sqr(l),f),A=c.cmov(u,l,m);return me(c,A,f),A}}function bn(e){if(e<un)throw new Error("sqrt is not defined for small field");let t=e-J,r=0;for(;t%At===F;)t/=At,r++;let n=At,o=gt(e);for(;an(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return xn;let s=o.pow(n,t),i=(t+J)/At;return function(f,u){if(f.is0(u))return u;if(an(f,u)!==1)throw new Error("Cannot find square root");let l=r,b=f.mul(f.ONE,s),a=f.pow(u,t),h=f.pow(u,i);for(;!f.eql(a,f.ONE);){if(f.is0(a))return f.ZERO;let w=1,m=f.sqr(a);for(;!f.eql(m,f.ONE);)if(w++,m=f.sqr(m),w===l)throw new Error("Cannot find square root");let A=J<<BigInt(l-w-1),H=f.pow(b,A);l=w,b=f.sqr(H),a=f.mul(a,b),h=f.mul(h,H)}return h}}function vr(e){return e%ln===un?xn:e%hn===dn?Er:e%pn===mr?Br(e):bn(e)}var Ar=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ee(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=Ar.reduce((n,o)=>(n[o]="function",n),t);return kt(e,r),e}function Sr(e,t,r){if(r<F)throw new Error("invalid exponent, negatives unsupported");if(r===F)return e.ONE;if(r===J)return t;let n=e.ONE,o=t;for(;r>F;)r&J&&(n=e.mul(n,o)),o=e.sqr(o),r>>=J;return n}function te(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,c,f)=>e.is0(c)?i:(n[f]=i,e.mul(i,c)),e.ONE),s=e.inv(o);return t.reduceRight((i,c,f)=>e.is0(c)?i:(n[f]=e.mul(i,n[f]),e.mul(i,c)),s),n}function an(e,t){let r=(e.ORDER-J)/At,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function ee(e,t){t!==void 0&&mt(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function gt(e,t,r=!1,n={}){if(e<=F)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s,i=!1,c;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let a=t;a.BITS&&(o=a.BITS),a.sqrt&&(s=a.sqrt),typeof a.isLE=="boolean"&&(r=a.isLE),typeof a.modFromBytes=="boolean"&&(i=a.modFromBytes),c=a.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:f,nByteLength:u}=ee(e,o);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let l,b=Object.freeze({ORDER:e,isLE:r,BITS:f,BYTES:u,MASK:yt(f),ZERO:F,ONE:J,allowedLengths:c,create:a=>et(a,e),isValid:a=>{if(typeof a!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof a);return F<=a&&a<e},is0:a=>a===F,isValidNot0:a=>!b.is0(a)&&b.isValid(a),isOdd:a=>(a&J)===J,neg:a=>et(-a,e),eql:(a,h)=>a===h,sqr:a=>et(a*a,e),add:(a,h)=>et(a+h,e),sub:(a,h)=>et(a-h,e),mul:(a,h)=>et(a*h,e),pow:(a,h)=>Sr(b,a,h),div:(a,h)=>et(a*fn(h,e),e),sqrN:a=>a*a,addN:(a,h)=>a+h,subN:(a,h)=>a-h,mulN:(a,h)=>a*h,inv:a=>fn(a,e),sqrt:s||(a=>(l||(l=vr(e)),l(b,a))),toBytes:a=>r?ge(a,u):Jt(a,u),fromBytes:(a,h=!0)=>{if(c){if(!c.includes(a.length)||a.length>u)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+a.length);let m=new Uint8Array(u);m.set(a,r?0:m.length-a.length),a=m}if(a.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+a.length);let w=r?ye(a):Ht(a);if(i&&(w=et(w,e)),!h&&!b.isValid(w))throw new Error("invalid field element: outside of range 0..ORDER");return w},invertBatch:a=>te(b,a),cmov:(a,h,w)=>w?h:a});return Object.freeze(b)}function yn(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function Be(e){let t=yn(e);return t+Math.ceil(t/2)}function ve(e,t,r=!1){let n=e.length,o=yn(t),s=Be(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?ye(e):Ht(e),c=et(i,t-J)+J;return r?ge(c,o):Jt(c,o)}var Ot=BigInt(0),St=BigInt(1);function qt(e,t){let r=t.negate();return e?r:t}function re(e,t){let r=te(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function En(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Ae(e,t){En(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=yt(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function gn(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,c=Number(e&o),f=e>>i;c>n&&(c-=s,f+=St);let u=t*n,l=u+Math.abs(c)-1,b=c===0,a=c<0,h=t%2!==0;return{nextN:f,offset:l,isZero:b,isNeg:a,isNegF:h,offsetF:u}}function Ur(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Lr(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var Se=new WeakMap,Bn=new WeakMap;function Ue(e){return Bn.get(e)||1}function wn(e){if(e!==Ot)throw new Error("invalid wNAF")}var ne=class{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>Ot;)r&St&&(n=n.add(o)),o=o.double(),r>>=St;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=Ae(r,this.bits),s=[],i=t,c=i;for(let f=0;f<n;f++){c=i,s.push(c);for(let u=1;u<o;u++)c=c.add(i),s.push(c);i=c.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Ae(t,this.bits);for(let c=0;c<i.windows;c++){let{nextN:f,offset:u,isZero:l,isNeg:b,isNegF:a,offsetF:h}=gn(n,c,i);n=f,l?s=s.add(qt(a,r[h])):o=o.add(qt(b,r[u]))}return wn(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=Ae(t,this.bits);for(let i=0;i<s.windows&&n!==Ot;i++){let{nextN:c,offset:f,isZero:u,isNeg:l}=gn(n,i,s);if(n=c,!u){let b=r[f];o=o.add(l?b.negate():b)}}return wn(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=Ue(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=Ue(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){En(r,this.bits),Bn.set(t,r),Se.delete(t)}hasCache(t){return Ue(t)!==1}};function vn(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Ot||n>Ot;)r&St&&(s=s.add(o)),n&St&&(i=i.add(o)),o=o.double(),r>>=St,n>>=St;return{p1:s,p2:i}}function An(e,t,r,n){Ur(r,e),Lr(n,t);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,c=Ft(BigInt(o)),f=1;c>12?f=c-3:c>4?f=c-2:c>0&&(f=2);let u=yt(f),l=new Array(Number(u)+1).fill(i),b=Math.floor((t.BITS-1)/f)*f,a=i;for(let h=b;h>=0;h-=f){l.fill(i);for(let m=0;m<s;m++){let A=n[m],H=Number(A>>BigInt(h)&u);l[H]=l[H].add(r[m])}let w=i;for(let m=l.length-1,A=i;m>0;m--)A=A.add(l[m]),w=w.add(A);if(a=a.add(w),h!==0)for(let m=0;m<f;m++)a=a.double()}return a}function mn(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 gt(e,{isLE:r})}function Sn(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 u=t[f];if(!(typeof u=="bigint"&&u>Ot))throw new Error(`CURVE.${f} must be positive bigint`)}let o=mn(t.p,r.Fp,n),s=mn(t.n,r.Fn,n),c=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let f of c)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}}var Un=(e,t)=>(e+(e>=0?t:-t)/Ln)/t;function _r(e,t,r){let[[n,o],[s,i]]=t,c=Un(i*e,r),f=Un(-o*e,r),u=e-c*n-f*s,l=-c*o-f*i,b=u<ht,a=l<ht;b&&(u=-u),a&&(l=-l);let h=yt(Math.ceil(Ft(r)/2))+Rt;if(u<ht||u>=h||l<ht||l>=h)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:b,k1:u,k2neg:a,k2:l}}function _e(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Le(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return Ct(r.lowS,"lowS"),Ct(r.prehash,"prehash"),r.format!==void 0&&_e(r.format),r}var Ie=class extends Error{constructor(t=""){super(t)}},dt={Err:Ie,_tlv:{encode:(e,t)=>{let{Err:r}=dt;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=Nt(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Nt(o.length/2|128):"";return Nt(e)+s+o+t},decode(e,t){let{Err:r}=dt,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");let o=t[n++],s=!!(o&128),i=0;if(!s)i=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 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(let l of u)i=i<<8|l;if(n+=f,i<128)throw new r("tlv.decode(long): not minimal encoding")}let 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){let{Err:t}=dt;if(e<ht)throw new t("integer: negative integers are not allowed");let r=Nt(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}=dt;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 Ht(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=dt,o=Q("signature",e),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:f}=n.decode(2,s),{v:u,l}=n.decode(2,f);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=dt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},ht=BigInt(0),Rt=BigInt(1),Ln=BigInt(2),oe=BigInt(3),Ir=BigInt(4);function Tt(e,t){let{BYTES:r}=e,n;if(typeof t=="bigint")n=t;else{let o=Q("private key",t);try{n=e.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof t}`)}}if(!e.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function Hr(e,t={}){let r=Sn("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:c}=s;kt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:f}=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 u=In(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function b(I,x,p){let{x:d,y:g}=x.toAffine(),E=n.toBytes(d);if(Ct(p,"isCompressed"),p){l();let v=!n.isOdd(g);return X(_n(v),E)}else return X(Uint8Array.of(4),E,n.toBytes(g))}function a(I){bt(I,void 0,"Point");let{publicKey:x,publicKeyUncompressed:p}=u,d=I.length,g=I[0],E=I.subarray(1);if(d===x&&(g===2||g===3)){let v=n.fromBytes(E);if(!n.isValid(v))throw new Error("bad point: is not on curve, wrong x");let y=m(v),B;try{B=n.sqrt(y)}catch(q){let N=q instanceof Error?": "+q.message:"";throw new Error("bad point: is not on curve, sqrt error"+N)}l();let S=n.isOdd(B);return(g&1)===1!==S&&(B=n.neg(B)),{x:v,y:B}}else if(d===p&&g===4){let v=n.BYTES,y=n.fromBytes(E.subarray(0,v)),B=n.fromBytes(E.subarray(v,v*2));if(!A(y,B))throw new Error("bad point: is not on curve");return{x:y,y:B}}else throw new Error(`bad point: got length ${d}, expected compressed=${x} or uncompressed=${p}`)}let h=t.toBytes||b,w=t.fromBytes||a;function m(I){let x=n.sqr(I),p=n.mul(x,I);return n.add(n.add(p,n.mul(I,s.a)),s.b)}function A(I,x){let p=n.sqr(x),d=m(I);return n.eql(p,d)}if(!A(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let H=n.mul(n.pow(s.a,oe),Ir),R=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(H,R)))throw new Error("bad curve params: a or b");function O(I,x,p=!1){if(!n.isValid(x)||p&&n.is0(x))throw new Error(`bad point coordinate ${I}`);return x}function K(I){if(!(I instanceof _))throw new Error("ProjectivePoint expected")}function P(I){if(!f||!f.basises)throw new Error("no endo");return _r(I,f.basises,o.ORDER)}let Z=we((I,x)=>{let{X:p,Y:d,Z:g}=I;if(n.eql(g,n.ONE))return{x:p,y:d};let E=I.is0();x==null&&(x=E?n.ONE:n.inv(g));let v=n.mul(p,x),y=n.mul(d,x),B=n.mul(g,x);if(E)return{x:n.ZERO,y:n.ZERO};if(!n.eql(B,n.ONE))throw new Error("invZ was invalid");return{x:v,y}}),$=we(I=>{if(I.is0()){if(t.allowInfinityPoint&&!n.is0(I.Y))return;throw new Error("bad point: ZERO")}let{x,y:p}=I.toAffine();if(!n.isValid(x)||!n.isValid(p))throw new Error("bad point: x or y not field elements");if(!A(x,p))throw new Error("bad point: equation left != right");if(!I.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function j(I,x,p,d,g){return p=new _(n.mul(p.X,I),p.Y,p.Z),x=qt(d,x),p=qt(g,p),x.add(p)}class _{constructor(x,p,d){this.X=O("x",x),this.Y=O("y",p,!0),this.Z=O("z",d),Object.freeze(this)}static CURVE(){return s}static fromAffine(x){let{x:p,y:d}=x||{};if(!x||!n.isValid(p)||!n.isValid(d))throw new Error("invalid affine point");if(x instanceof _)throw new Error("projective point not allowed");return n.is0(p)&&n.is0(d)?_.ZERO:new _(p,d,n.ONE)}static fromBytes(x){let p=_.fromAffine(w(bt(x,void 0,"point")));return p.assertValidity(),p}static fromHex(x){return _.fromBytes(Q("pointHex",x))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(x=8,p=!0){return C.createCache(this,x),p||this.multiply(oe),this}assertValidity(){$(this)}hasEvenY(){let{y:x}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(x)}equals(x){K(x);let{X:p,Y:d,Z:g}=this,{X:E,Y:v,Z:y}=x,B=n.eql(n.mul(p,y),n.mul(E,g)),S=n.eql(n.mul(d,y),n.mul(v,g));return B&&S}negate(){return new _(this.X,n.neg(this.Y),this.Z)}double(){let{a:x,b:p}=s,d=n.mul(p,oe),{X:g,Y:E,Z:v}=this,y=n.ZERO,B=n.ZERO,S=n.ZERO,L=n.mul(g,g),q=n.mul(E,E),N=n.mul(v,v),T=n.mul(g,E);return T=n.add(T,T),S=n.mul(g,v),S=n.add(S,S),y=n.mul(x,S),B=n.mul(d,N),B=n.add(y,B),y=n.sub(q,B),B=n.add(q,B),B=n.mul(y,B),y=n.mul(T,y),S=n.mul(d,S),N=n.mul(x,N),T=n.sub(L,N),T=n.mul(x,T),T=n.add(T,S),S=n.add(L,L),L=n.add(S,L),L=n.add(L,N),L=n.mul(L,T),B=n.add(B,L),N=n.mul(E,v),N=n.add(N,N),L=n.mul(N,T),y=n.sub(y,L),S=n.mul(N,q),S=n.add(S,S),S=n.add(S,S),new _(y,B,S)}add(x){K(x);let{X:p,Y:d,Z:g}=this,{X:E,Y:v,Z:y}=x,B=n.ZERO,S=n.ZERO,L=n.ZERO,q=s.a,N=n.mul(s.b,oe),T=n.mul(p,E),V=n.mul(d,v),D=n.mul(g,y),G=n.add(p,d),M=n.add(E,v);G=n.mul(G,M),M=n.add(T,V),G=n.sub(G,M),M=n.add(p,g);let W=n.add(E,y);return M=n.mul(M,W),W=n.add(T,D),M=n.sub(M,W),W=n.add(d,g),B=n.add(v,y),W=n.mul(W,B),B=n.add(V,D),W=n.sub(W,B),L=n.mul(q,M),B=n.mul(N,D),L=n.add(B,L),B=n.sub(V,L),L=n.add(V,L),S=n.mul(B,L),V=n.add(T,T),V=n.add(V,T),D=n.mul(q,D),M=n.mul(N,M),V=n.add(V,D),D=n.sub(T,D),D=n.mul(q,D),M=n.add(M,D),T=n.mul(V,M),S=n.add(S,T),T=n.mul(W,M),B=n.mul(G,B),B=n.sub(B,T),T=n.mul(G,V),L=n.mul(W,L),L=n.add(L,T),new _(B,S,L)}subtract(x){return this.add(x.negate())}is0(){return this.equals(_.ZERO)}multiply(x){let{endo:p}=t;if(!o.isValidNot0(x))throw new Error("invalid scalar: out of range");let d,g,E=v=>C.cached(this,v,y=>re(_,y));if(p){let{k1neg:v,k1:y,k2neg:B,k2:S}=P(x),{p:L,f:q}=E(y),{p:N,f:T}=E(S);g=q.add(T),d=j(p.beta,L,N,v,B)}else{let{p:v,f:y}=E(x);d=v,g=y}return re(_,[d,g])[0]}multiplyUnsafe(x){let{endo:p}=t,d=this;if(!o.isValid(x))throw new Error("invalid scalar: out of range");if(x===ht||d.is0())return _.ZERO;if(x===Rt)return d;if(C.hasCache(this))return this.multiply(x);if(p){let{k1neg:g,k1:E,k2neg:v,k2:y}=P(x),{p1:B,p2:S}=vn(_,d,E,y);return j(p.beta,B,S,g,v)}else return C.unsafe(d,x)}multiplyAndAddUnsafe(x,p,d){let g=this.multiplyUnsafe(p).add(x.multiplyUnsafe(d));return g.is0()?void 0:g}toAffine(x){return Z(this,x)}isTorsionFree(){let{isTorsionFree:x}=t;return i===Rt?!0:x?x(_,this):C.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:x}=t;return i===Rt?this:x?x(_,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(x=!0){return Ct(x,"isCompressed"),this.assertValidity(),h(_,this,x)}toHex(x=!0){return at(this.toBytes(x))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(x=!0){return this.toBytes(x)}_setWindowSize(x){this.precompute(x)}static normalizeZ(x){return re(_,x)}static msm(x,p){return An(_,o,x,p)}static fromPrivateKey(x){return _.BASE.multiply(Tt(o,x))}}_.BASE=new _(s.Gx,s.Gy,n.ONE),_.ZERO=new _(n.ZERO,n.ONE,n.ZERO),_.Fp=n,_.Fn=o;let k=o.BITS,C=new ne(_,t.endo?Math.ceil(k/2):k);return _.BASE.precompute(8),_}function _n(e){return Uint8Array.of(e?2:3)}function In(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Or(e,t={}){let{Fn:r}=e,n=t.randomBytes||It,o=Object.assign(In(e.Fp,r),{seed:Be(r.ORDER)});function s(h){try{return!!Tt(r,h)}catch{return!1}}function i(h,w){let{publicKey:m,publicKeyUncompressed:A}=o;try{let H=h.length;return w===!0&&H!==m||w===!1&&H!==A?!1:!!e.fromBytes(h)}catch{return!1}}function c(h=n(o.seed)){return ve(bt(h,o.seed,"seed"),r.ORDER)}function f(h,w=!0){return e.BASE.multiply(Tt(r,h)).toBytes(w)}function u(h){let w=c(h);return{secretKey:w,publicKey:f(w)}}function l(h){if(typeof h=="bigint")return!1;if(h instanceof e)return!0;let{secretKey:w,publicKey:m,publicKeyUncompressed:A}=o;if(r.allowedLengths||w===m)return;let H=Q("key",h).length;return H===m||H===A}function b(h,w,m=!0){if(l(h)===!0)throw new Error("first arg must be private key");if(l(w)===!1)throw new Error("second arg must be public key");let A=Tt(r,h);return e.fromHex(w).multiply(A).toBytes(m)}return Object.freeze({getPublicKey:f,getSharedSecret:b,keygen:u,Point:e,utils:{isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c,isValidPrivateKey:s,randomPrivateKey:c,normPrivateKeyToScalar:h=>Tt(r,h),precompute(h=8,w=e.BASE){return w.precompute(h,!1)}},lengths:o})}function Tr(e,t,r={}){Bt(t),kt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||It,o=r.hmac||((p,...d)=>lt(t,p,X(...d))),{Fp:s,Fn:i}=e,{ORDER:c,BITS:f}=i,{keygen:u,getPublicKey:l,getSharedSecret:b,utils:a,lengths:h}=Or(e,r),w={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},m="compact";function A(p){let d=c>>Rt;return p>d}function H(p,d){if(!i.isValidNot0(d))throw new Error(`invalid signature ${p}: out of range 1..Point.Fn.ORDER`);return d}function R(p,d){_e(d);let g=h.signature,E=d==="compact"?g:d==="recovered"?g+1:void 0;return bt(p,E,`${d} signature`)}class O{constructor(d,g,E){this.r=H("r",d),this.s=H("s",g),E!=null&&(this.recovery=E),Object.freeze(this)}static fromBytes(d,g=m){R(d,g);let E;if(g==="der"){let{r:S,s:L}=dt.toSig(bt(d));return new O(S,L)}g==="recovered"&&(E=d[0],g="compact",d=d.subarray(1));let v=i.BYTES,y=d.subarray(0,v),B=d.subarray(v,v*2);return new O(i.fromBytes(y),i.fromBytes(B),E)}static fromHex(d,g){return this.fromBytes(vt(d),g)}addRecoveryBit(d){return new O(this.r,this.s,d)}recoverPublicKey(d){let g=s.ORDER,{r:E,s:v,recovery:y}=this;if(y==null||![0,1,2,3].includes(y))throw new Error("recovery id invalid");if(c*Ln<g&&y>1)throw new Error("recovery id is ambiguous for h>1 curve");let S=y===2||y===3?E+c:E;if(!s.isValid(S))throw new Error("recovery id 2 or 3 invalid");let L=s.toBytes(S),q=e.fromBytes(X(_n((y&1)===0),L)),N=i.inv(S),T=P(Q("msgHash",d)),V=i.create(-T*N),D=i.create(v*N),G=e.BASE.multiplyUnsafe(V).add(q.multiplyUnsafe(D));if(G.is0())throw new Error("point at infinify");return G.assertValidity(),G}hasHighS(){return A(this.s)}toBytes(d=m){if(_e(d),d==="der")return vt(dt.hexFromSig(this));let g=i.toBytes(this.r),E=i.toBytes(this.s);if(d==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return X(Uint8Array.of(this.recovery),g,E)}return X(g,E)}toHex(d){return at(this.toBytes(d))}assertValidity(){}static fromCompact(d){return O.fromBytes(Q("sig",d),"compact")}static fromDER(d){return O.fromBytes(Q("sig",d),"der")}normalizeS(){return this.hasHighS()?new O(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return at(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return at(this.toBytes("compact"))}}let K=r.bits2int||function(d){if(d.length>8192)throw new Error("input is too large");let g=Ht(d),E=d.length*8-f;return E>0?g>>BigInt(E):g},P=r.bits2int_modN||function(d){return i.create(K(d))},Z=yt(f);function $(p){return sn("num < 2^"+f,p,ht,Z),i.toBytes(p)}function j(p,d){return bt(p,void 0,"message"),d?bt(t(p),void 0,"prehashed message"):p}function _(p,d,g){if(["recovered","canonical"].some(V=>V in g))throw new Error("sign() legacy options not supported");let{lowS:E,prehash:v,extraEntropy:y}=Le(g,w);p=j(p,v);let B=P(p),S=Tt(i,d),L=[$(S),$(B)];if(y!=null&&y!==!1){let V=y===!0?n(h.secretKey):y;L.push(Q("extraEntropy",V))}let q=X(...L),N=B;function T(V){let D=K(V);if(!i.isValidNot0(D))return;let G=i.inv(D),M=e.BASE.multiply(D).toAffine(),W=i.create(M.x);if(W===ht)return;let Dt=i.create(G*i.create(N+W*S));if(Dt===ht)return;let qe=(M.x===W?0:2)|Number(M.y&Rt),Ve=Dt;return E&&A(Dt)&&(Ve=i.neg(Dt),qe^=1),new O(W,Ve,qe)}return{seed:q,k2sig:T}}function k(p,d,g={}){p=Q("message",p);let{seed:E,k2sig:v}=_(p,d,g);return cn(t.outputLen,i.BYTES,o)(E,v)}function C(p){let d,g=typeof p=="string"||Et(p),E=!g&&p!==null&&typeof p=="object"&&typeof p.r=="bigint"&&typeof p.s=="bigint";if(!g&&!E)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(E)d=new O(p.r,p.s);else if(g){try{d=O.fromBytes(Q("sig",p),"der")}catch(v){if(!(v instanceof dt.Err))throw v}if(!d)try{d=O.fromBytes(Q("sig",p),"compact")}catch{return!1}}return d||!1}function I(p,d,g,E={}){let{lowS:v,prehash:y,format:B}=Le(E,w);if(g=Q("publicKey",g),d=j(Q("message",d),y),"strict"in E)throw new Error("options.strict was renamed to lowS");let S=B===void 0?C(p):O.fromBytes(Q("sig",p),B);if(S===!1)return!1;try{let L=e.fromBytes(g);if(v&&S.hasHighS())return!1;let{r:q,s:N}=S,T=P(d),V=i.inv(N),D=i.create(T*V),G=i.create(q*V),M=e.BASE.multiplyUnsafe(D).add(L.multiplyUnsafe(G));return M.is0()?!1:i.create(M.x)===q}catch{return!1}}function x(p,d,g={}){let{prehash:E}=Le(g,w);return d=j(d,E),O.fromBytes(p,"recovered").recoverPublicKey(d).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:b,utils:a,lengths:h,Point:e,sign:k,verify:I,recoverPublicKey:x,Signature:O,hash:t})}function Rr(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,o=gt(t.n,{BITS:e.nBitLength,allowedLengths:n,modFromBytes:e.wrapPrivateKey}),s={Fp:r,Fn:o,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:s}}function Cr(e){let{CURVE:t,curveOpts:r}=Rr(e),n={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,hash:e.hash,ecdsaOpts:n}}function Nr(e,t){let r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,ee(r.Fn.ORDER,r.Fn.BITS))})}function Hn(e){let{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:o}=Cr(e),s=Hr(t,r),i=Tr(s,n,o);return Nr(e,i)}function On(e,t){let r=n=>Hn({...e,hash:n});return{...r(t),create:r}}var Oe={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},kr={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Tn=BigInt(2);function qr(e){let t=Oe.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),f=BigInt(88),u=e*e*e%t,l=u*u*e%t,b=tt(l,r,t)*l%t,a=tt(b,r,t)*l%t,h=tt(a,Tn,t)*u%t,w=tt(h,o,t)*h%t,m=tt(w,s,t)*w%t,A=tt(m,c,t)*m%t,H=tt(A,f,t)*A%t,R=tt(H,c,t)*m%t,O=tt(R,r,t)*l%t,K=tt(O,i,t)*w%t,P=tt(K,n,t)*u%t,Z=tt(P,Tn,t);if(!He.eql(He.sqr(Z),e))throw new Error("Cannot find square root");return Z}var He=gt(Oe.p,{sqrt:qr}),Rn=On({...Oe,Fp:He,lowS:!0,endo:kr},Xt);function Nn(e,t,r){return Bt(e),r===void 0&&(r=new Uint8Array(e.outputLen)),lt(e,pt(r),pt(t))}var Te=Uint8Array.from([0]),Cn=Uint8Array.of();function kn(e,t,r,n=32){Bt(e),mt(n);let o=e.outputLen;if(n>255*o)throw new Error("Length should be <= 255*HashLen");let s=Math.ceil(n/o);r===void 0&&(r=Cn);let i=new Uint8Array(s*o),c=lt.create(e,t),f=c._cloneInto(),u=new Uint8Array(c.outputLen);for(let l=0;l<s;l++)Te[0]=l+1,f.update(l===0?Cn:u).update(r).update(Te).digestInto(u),i.set(u,o*l),c._cloneInto(f);return c.destroy(),f.destroy(),ft(u,Te),i.slice(0,n)}var Vt=Xt;function Vn(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Vr(e){if(!Vn(e))throw new Error("Uint8Array expected")}function Mn(e,t){return Array.isArray(t)?t.length===0?!0:e?t.every(r=>typeof r=="string"):t.every(r=>Number.isSafeInteger(r)):!1}function Mt(e,t){if(typeof t!="string")throw new Error(`${e}: string expected`);return!0}function Ne(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function Ce(e){if(!Array.isArray(e))throw new Error("array expected")}function se(e,t){if(!Mn(!0,t))throw new Error(`${e}: array of strings expected`)}function Mr(e,t){if(!Mn(!1,t))throw new Error(`${e}: array of numbers expected`)}function Dr(...e){let t=s=>s,r=(s,i)=>c=>s(i(c)),n=e.map(s=>s.encode).reduceRight(r,t),o=e.map(s=>s.decode).reduce(r,t);return{encode:n,decode:o}}function Kr(e){let t=typeof e=="string"?e.split(""):e,r=t.length;se("alphabet",t);let n=new Map(t.map((o,s)=>[o,s]));return{encode:o=>(Ce(o),o.map(s=>{if(!Number.isSafeInteger(s)||s<0||s>=r)throw new Error(`alphabet.encode: digit index outside alphabet "${s}". Allowed: ${e}`);return t[s]})),decode:o=>(Ce(o),o.map(s=>{Mt("alphabet.decode",s);let i=n.get(s);if(i===void 0)throw new Error(`Unknown letter: "${s}". Allowed: ${e}`);return i}))}}function Zr(e=""){return Mt("join",e),{encode:t=>(se("join.decode",t),t.join(e)),decode:t=>(Mt("join.decode",t),t.split(e))}}function jr(e,t="="){return Ne(e),Mt("padding",t),{encode(r){for(se("padding.encode",r);r.length*e%8;)r.push(t);return r},decode(r){se("padding.decode",r);let n=r.length;if(n*e%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;n>0&&r[n-1]===t;n--)if((n-1)*e%8===0)throw new Error("padding: invalid, string has too much padding");return r.slice(0,n)}}}var Dn=(e,t)=>t===0?e:Dn(t,e%t),ie=(e,t)=>e+(t-Dn(e,t)),Re=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function qn(e,t,r,n){if(Ce(e),t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(r<=0||r>32)throw new Error(`convertRadix2: wrong to=${r}`);if(ie(t,r)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${r} carryBits=${ie(t,r)}`);let o=0,s=0,i=Re[t],c=Re[r]-1,f=[];for(let u of e){if(Ne(u),u>=i)throw new Error(`convertRadix2: invalid data word=${u} from=${t}`);if(o=o<<t|u,s+t>32)throw new Error(`convertRadix2: carry overflow pos=${s} from=${t}`);for(s+=t;s>=r;s-=r)f.push((o>>s-r&c)>>>0);let l=Re[s];if(l===void 0)throw new Error("invalid carry");o&=l-1}if(o=o<<r-s&c,!n&&s>=t)throw new Error("Excess padding");if(!n&&o>0)throw new Error(`Non-zero padding: ${o}`);return n&&s>0&&f.push(o>>>0),f}function $r(e,t=!1){if(Ne(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(ie(8,e)>32||ie(e,8)>32)throw new Error("radix2: carry overflow");return{encode:r=>{if(!Vn(r))throw new Error("radix2.encode input should be Uint8Array");return qn(Array.from(r),8,e,!t)},decode:r=>(Mr("radix2.decode",r),Uint8Array.from(qn(r,e,8,t)))}}var Gr=typeof Uint8Array.from([]).toBase64=="function"&&typeof Uint8Array.fromBase64=="function",Pr=(e,t)=>{Mt("base64",e);let r=t?/^[A-Za-z0-9=_-]+$/:/^[A-Za-z0-9=+/]+$/,n=t?"base64url":"base64";if(e.length>0&&!r.test(e))throw new Error("invalid base64");return Uint8Array.fromBase64(e,{alphabet:n,lastChunkHandling:"strict"})},ke=Gr?{encode(e){return Vr(e),e.toBase64()},decode(e){return Pr(e,!1)}}:Dr($r(6),Kr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),jr(6),Zr(""));var Kn=new TextEncoder,zr=new TextDecoder,Zn=1,jn=65535;function ce(e){if(!Number.isSafeInteger(e)||e<1)throw new Error("expected positive integer");if(e<=32)return 32;let t=1<<Math.floor(Math.log2(e-1))+1,r=t<=256?32:t/8;return r*(Math.floor((e-1)/r)+1)}function Yr(e){let t=Kn.encode(e),r=t.length;if(r<Zn||r>jn)throw new Error("invalid plaintext length: must be between 1 and 65535 bytes");let n=new Uint8Array(2);new DataView(n.buffer).setUint16(0,r,!1);let o=new Uint8Array(ce(r)-r);return X(n,t,o)}function Wr(e){let t=new DataView(e.buffer,e.byteOffset).getUint16(0,!1),r=e.subarray(2,2+t);if(t<Zn||t>jn||r.length!==t||e.length!==2+ce(t))throw new Error("invalid padding");return zr.decode(r)}function $n(e,t){let n=Rn.getSharedSecret(e,"02"+t).subarray(1,33);return Nn(Vt,n,Kn.encode("nip44-v2"))}function Gn(e,t){let r=kn(Vt,e,t,76);return{chacha_key:r.subarray(0,32),chacha_nonce:r.subarray(32,44),hmac_key:r.subarray(44,76)}}function Pn(e,t,r=It(32)){let{chacha_key:n,chacha_nonce:o,hmac_key:s}=Gn(t,r),i=Yr(e),c=Pt(n,o,i),f=lt(Vt,s,X(r,c));return ke.encode(X(new Uint8Array([2]),r,c,f))}function zn(e,t){let r=ke.decode(e),n=r[0];if(n!==2)throw new Error(`unknown encryption version: ${n}`);if(r.length<99||r.length>65603)throw new Error("invalid payload size");let o=r.subarray(1,33),s=r.subarray(33,r.length-32),i=r.subarray(r.length-32),{chacha_key:c,chacha_nonce:f,hmac_key:u}=Gn(t,o),l=lt(Vt,u,X(o,s));if(!$t(i,l))throw new Error("invalid MAC");let b=Pt(c,f,s);return Wr(b)}var Xr={utils:{getConversationKey:$n,calcPaddedLen:ce},encrypt:Pn,decrypt:zn};return tr(Qr);})();
2
+ /*! Bundled license information:
3
+
4
+ @noble/ciphers/utils.js:
5
+ (*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) *)
6
+
7
+ @noble/hashes/esm/utils.js:
8
+ (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
9
+
10
+ @noble/curves/esm/utils.js:
11
+ @noble/curves/esm/abstract/modular.js:
12
+ @noble/curves/esm/abstract/curve.js:
13
+ @noble/curves/esm/abstract/weierstrass.js:
14
+ @noble/curves/esm/_shortw_utils.js:
15
+ @noble/curves/esm/secp256k1.js:
16
+ (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
17
+
18
+ @scure/base/index.js:
19
+ (*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
20
+ */
21
+ //# sourceMappingURL=nip-44.nostr-crypto-utils.min.js.map