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-46.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-46"]=E())}(this,()=>(()=>{"use strict";var f,E={510(f,E,e){E.ND=E.bI=void 0;const T=e(76),N=(e(175),e(562)),a=e(761),t=e(967),A=e(705),d=e(627),_={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},c={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},n=BigInt(2),o=(0,t.Field)(_.p,{sqrt:function(f){const E=_.p,e=BigInt(3),T=BigInt(6),N=BigInt(11),a=BigInt(22),A=BigInt(23),d=BigInt(44),c=BigInt(88),r=f*f*f%E,b=r*r*f%E,C=(0,t.pow2)(b,e,E)*b%E,S=(0,t.pow2)(C,e,E)*b%E,I=(0,t.pow2)(S,n,E)*r%E,i=(0,t.pow2)(I,N,E)*I%E,O=(0,t.pow2)(i,a,E)*i%E,R=(0,t.pow2)(O,d,E)*O%E,p=(0,t.pow2)(R,c,E)*R%E,s=(0,t.pow2)(p,d,E)*O%E,D=(0,t.pow2)(s,e,E)*b%E,L=(0,t.pow2)(D,A,E)*i%E,P=(0,t.pow2)(L,T,E)*r%E,M=(0,t.pow2)(P,n,E);if(!o.eql(o.sqr(M),f))throw new Error("Cannot find square root");return M}});E.bI=(0,N.createCurve)({..._,Fp:o,lowS:!0,endo:c},T.sha256);d.bytesToNumberBE;E.bI.utils.randomSecretKey,d.numberToBytesBE,d.bytesToNumberBE,t.mod;const r=(()=>(0,a.isogenyMap)(o,[["0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7","0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581","0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262","0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"],["0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b","0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14","0x0000000000000000000000000000000000000000000000000000000000000001"],["0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c","0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3","0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931","0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"],["0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b","0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573","0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f","0x0000000000000000000000000000000000000000000000000000000000000001"]].map(f=>f.map(f=>BigInt(f)))))(),b=(()=>(0,A.mapToCurveSimpleSWU)(o,{A:BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),B:BigInt("1771"),Z:o.create(BigInt("-11"))}))();E.ND=(0,a.createHasher)(E.bI.Point,f=>{const{x:E,y:e}=b(o.create(f[0]));return r(E,e)},{DST:"secp256k1_XMD:SHA-256_SSWU_RO_",encodeDST:"secp256k1_XMD:SHA-256_SSWU_NU_",p:o.ORDER,m:1,k:128,expand:"xmd",hash:T.sha256}),E.ND.hashToCurve,E.ND.encodeToCurve},298(f,E,e){e(732),e(246),e(510),e(139),e(615),e(623),e(175),e(116),new TextEncoder,new TextDecoder},696(f,E,e){e(298),e(247)},247(){var f,E,e,T;!function(f){f[f.SET_METADATA=0]="SET_METADATA",f[f.TEXT_NOTE=1]="TEXT_NOTE",f[f.RECOMMEND_SERVER=2]="RECOMMEND_SERVER",f[f.CONTACTS=3]="CONTACTS",f[f.ENCRYPTED_DIRECT_MESSAGE=4]="ENCRYPTED_DIRECT_MESSAGE",f[f.EVENT_DELETION=5]="EVENT_DELETION",f[f.REPOST=6]="REPOST",f[f.REACTION=7]="REACTION",f[f.CHANNEL_CREATION=40]="CHANNEL_CREATION",f[f.CHANNEL_METADATA=41]="CHANNEL_METADATA",f[f.CHANNEL_MESSAGE=42]="CHANNEL_MESSAGE",f[f.CHANNEL_HIDE_MESSAGE=43]="CHANNEL_HIDE_MESSAGE",f[f.CHANNEL_MUTE_USER=44]="CHANNEL_MUTE_USER",f[f.AUTH=22242]="AUTH",f[f.AUTH_RESPONSE=22243]="AUTH_RESPONSE"}(f||(f={})),function(f){f.EVENT="EVENT",f.NOTICE="NOTICE",f.OK="OK",f.EOSE="EOSE",f.REQ="REQ",f.CLOSE="CLOSE",f.AUTH="AUTH"}(E||(E={})),function(f){f.CONNECT="connect",f.PING="ping",f.GET_PUBLIC_KEY="get_public_key",f.SIGN_EVENT="sign_event",f.NIP04_ENCRYPT="nip04_encrypt",f.NIP04_DECRYPT="nip04_decrypt",f.NIP44_ENCRYPT="nip44_encrypt",f.NIP44_DECRYPT="nip44_decrypt",f.GET_RELAYS="get_relays"}(e||(e={})),function(f){f[f.SET_METADATA=0]="SET_METADATA",f[f.TEXT_NOTE=1]="TEXT_NOTE",f[f.RECOMMEND_SERVER=2]="RECOMMEND_SERVER",f[f.CONTACT_LIST=3]="CONTACT_LIST",f[f.ENCRYPTED_DIRECT_MESSAGE=4]="ENCRYPTED_DIRECT_MESSAGE",f[f.DELETE=5]="DELETE",f[f.REPOST=6]="REPOST",f[f.REACTION=7]="REACTION",f[f.BADGE_AWARD=8]="BADGE_AWARD",f[f.CHANNEL_CREATE=40]="CHANNEL_CREATE",f[f.CHANNEL_METADATA=41]="CHANNEL_METADATA",f[f.CHANNEL_MESSAGE=42]="CHANNEL_MESSAGE",f[f.CHANNEL_HIDE_MESSAGE=43]="CHANNEL_HIDE_MESSAGE",f[f.CHANNEL_MUTE_USER=44]="CHANNEL_MUTE_USER",f[f.CHANNEL_RESERVE=45]="CHANNEL_RESERVE",f[f.REPORTING=1984]="REPORTING",f[f.ZAP_REQUEST=9734]="ZAP_REQUEST",f[f.ZAP=9735]="ZAP",f[f.MUTE_LIST=1e4]="MUTE_LIST",f[f.PIN_LIST=10001]="PIN_LIST",f[f.RELAY_LIST_METADATA=10002]="RELAY_LIST_METADATA",f[f.CLIENT_AUTH=22242]="CLIENT_AUTH",f[f.AUTH_RESPONSE=22243]="AUTH_RESPONSE",f[f.NOSTR_CONNECT=24133]="NOSTR_CONNECT",f[f.CATEGORIZED_PEOPLE=3e4]="CATEGORIZED_PEOPLE",f[f.CATEGORIZED_BOOKMARKS=30001]="CATEGORIZED_BOOKMARKS",f[f.PROFILE_BADGES=30008]="PROFILE_BADGES",f[f.BADGE_DEFINITION=30009]="BADGE_DEFINITION",f[f.LONG_FORM=30023]="LONG_FORM",f[f.APPLICATION_SPECIFIC=30078]="APPLICATION_SPECIFIC"}(T||(T={}))}},e={};function T(f){var N=e[f];if(void 0!==N)return N.exports;var a=e[f]={exports:{}};return E[f](a,a.exports,T),a.exports}T.m=E,f=[],T.O=(E,e,N,a)=>{if(!e){var t=1/0;for(c=0;c<f.length;c++){for(var[e,N,a]=f[c],A=!0,d=0;d<e.length;d++)(!1&a||t>=a)&&Object.keys(T.O).every(f=>T.O[f](e[d]))?e.splice(d--,1):(A=!1,a<t&&(t=a));if(A){f.splice(c--,1);var _=N();void 0!==_&&(E=_)}}return E}a=a||0;for(var c=f.length;c>0&&f[c-1][2]>a;c--)f[c]=f[c-1];f[c]=[e,N,a]},T.d=(f,E)=>{for(var e in E)T.o(E,e)&&!T.o(f,e)&&Object.defineProperty(f,e,{enumerable:!0,get:E[e]})},T.o=(f,E)=>Object.prototype.hasOwnProperty.call(f,E),(()=>{var f={263:0,869:0};T.O.j=E=>0===f[E];var E=(E,e)=>{var N,a,[t,A,d]=e,_=0;if(t.some(E=>0!==f[E])){for(N in A)T.o(A,N)&&(T.m[N]=A[N]);if(d)var c=d(T)}for(E&&E(e);_<t.length;_++)a=t[_],T.o(f,a)&&f[a]&&f[a][0](),f[a]=0;return T.O(c)},e=this.webpackChunkNostrCryptoUtils=this.webpackChunkNostrCryptoUtils||[];e.forEach(E.bind(null,0)),e.push=E.bind(null,e.push.bind(e))})();var N=T.O(void 0,[575,348,705,524,732,126,116],()=>T(696));return(N=T.O(N)).default})());
1
+ "use strict";var NostrCryptoUtils=NostrCryptoUtils||{};NostrCryptoUtils.NIP46=(()=>{var Qe=Object.defineProperty;var dr=Object.getOwnPropertyDescriptor;var hr=Object.getOwnPropertyNames;var pr=Object.prototype.hasOwnProperty;var yr=(t,e,r)=>e in t?Qe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var xr=(t,e)=>{for(var r in e)Qe(t,r,{get:e[r],enumerable:!0})},br=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of hr(e))!pr.call(t,o)&&o!==r&&Qe(t,o,{get:()=>e[o],enumerable:!(n=dr(e,o))||n.enumerable});return t};var gr=t=>br(Qe({},"__esModule",{value:!0}),t);var ie=(t,e,r)=>yr(t,typeof e!="symbol"?e+"":e,r);var Vo={};xr(Vo,{connectRequest:()=>Uo,createBunkerURI:()=>mo,createRequest:()=>fe,createResponse:()=>Ro,createResponseFilter:()=>Do,createSession:()=>Bo,getPublicKeyRequest:()=>Oo,getRelaysRequest:()=>Po,getSessionInfo:()=>So,isRequest:()=>vo,isResponse:()=>_o,nip04DecryptRequest:()=>No,nip04EncryptRequest:()=>ko,nip44DecryptRequest:()=>qo,nip44EncryptRequest:()=>Co,parseBunkerURI:()=>ur,parsePayload:()=>lr,pingRequest:()=>Lo,restoreSession:()=>Ao,signEventRequest:()=>Ho,unwrapEvent:()=>Io,validateBunkerURI:()=>Eo,wrapEvent:()=>To});var ve=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function me(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function we(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function re(t,...e){if(!me(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function _e(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");we(t.outputLen),we(t.blockLen)}function ke(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function rn(t,e){re(t);let r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function ue(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Je(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function oe(t,e){return t<<32-e|t>>>e}var on=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",wr=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function se(t){if(re(t),on)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=wr[t[r]];return e}var ae={_0:48,_9:57,A:65,F:70,a:97,f:102};function nn(t){if(t>=ae._0&&t<=ae._9)return t-ae._0;if(t>=ae.A&&t<=ae.F)return t-(ae.A-10);if(t>=ae.a&&t<=ae.f)return t-(ae.a-10)}function le(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(on)return Uint8Array.fromHex(t);let e=t.length,r=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=nn(t.charCodeAt(s)),c=nn(t.charCodeAt(s+1));if(i===void 0||c===void 0){let f=t[s]+t[s+1];throw new Error('hex string expected, got non-hex character "'+f+'" at index '+s)}n[o]=i*16+c}return n}function Ge(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function Ee(t){return typeof t=="string"&&(t=Ge(t)),re(t),t}function z(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];re(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let s=t[n];r.set(s,o),o+=s.length}return r}var He=class{};function sn(t){let e=n=>t().update(Ee(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function ee(t=32){if(ve&&typeof ve.getRandomValues=="function")return ve.getRandomValues(new Uint8Array(t));if(ve&&typeof ve.randomBytes=="function")return Uint8Array.from(ve.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}function mr(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),c=Number(r&s),f=n?4:0,a=n?0:4;t.setUint32(e+f,i,n),t.setUint32(e+a,c,n)}function cn(t,e,r){return t&e^~t&r}function fn(t,e,r){return t&e^t&r^e&r}var Fe=class extends He{constructor(e,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=Je(this.buffer)}update(e){ke(this),e=Ee(e),re(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let f=Je(e);for(;o<=s-i;i+=o)this.process(f,i);continue}n.set(e.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){ke(this),rn(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,ue(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let y=i;y<o;y++)r[y]=0;mr(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=Je(e),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen should 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 y=0;y<a;y++)c.setUint32(4*y,l[y],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return e.destroyed=i,e.finished=s,e.length=o,e.pos=c,o%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},de=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Er=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]),Be=new Uint32Array(64),et=class extends Fe{constructor(e=32){super(64,e,8,!1),this.A=de[0]|0,this.B=de[1]|0,this.C=de[2]|0,this.D=de[3]|0,this.E=de[4]|0,this.F=de[5]|0,this.G=de[6]|0,this.H=de[7]|0}get(){let{A:e,B:r,C:n,D:o,E:s,F:i,G:c,H:f}=this;return[e,r,n,o,s,i,c,f]}set(e,r,n,o,s,i,c,f){this.A=e|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(e,r){for(let y=0;y<16;y++,r+=4)Be[y]=e.getUint32(r,!1);for(let y=16;y<64;y++){let u=Be[y-15],d=Be[y-2],w=oe(u,7)^oe(u,18)^u>>>3,m=oe(d,17)^oe(d,19)^d>>>10;Be[y]=m+Be[y-7]+w+Be[y-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:f,G:a,H:l}=this;for(let y=0;y<64;y++){let u=oe(c,6)^oe(c,11)^oe(c,25),d=l+u+cn(c,f,a)+Er[y]+Be[y]|0,m=(oe(n,2)^oe(n,13)^oe(n,22))+fn(n,o,s)|0;l=a,a=f,f=c,c=i+d|0,i=s,s=o,o=n,n=d+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,a=a+this.G|0,l=l+this.H|0,this.set(n,o,s,i,c,f,a,l)}roundClean(){ue(Be)}destroy(){this.set(0,0,0,0,0,0,0,0),ue(this.buffer)}};var Ne=sn(()=>new et);var tt=class extends He{constructor(e,r){super(),this.finished=!1,this.destroyed=!1,_e(e);let n=Ee(r);if(this.iHash=e.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?e.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=e.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),ue(s)}update(e){return ke(this),this.iHash.update(e),this}digestInto(e){ke(this),re(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=c,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},he=(t,e,r)=>new tt(t,e).update(r).digest();he.create=(t,e)=>new tt(t,e);var St=BigInt(0),At=BigInt(1);function $e(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}"`;throw new Error(r+"expected boolean, got type="+typeof t)}return t}function Ae(t,e,r=""){let n=me(t),o=t?.length,s=e!==void 0;if(!n||s&&o!==e){let i=r&&`"${r}" `,c=s?` of length ${e}`:"",f=n?`length=${o}`:`type=${typeof t}`;throw new Error(i+"expected Uint8Array"+c+", got "+f)}return t}function Ce(t){let e=t.toString(16);return e.length&1?"0"+e:e}function Rt(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?St:BigInt("0x"+t)}function ce(t){return Rt(se(t))}function nt(t){return re(t),Rt(se(Uint8Array.from(t).reverse()))}function Te(t,e){return le(t.toString(16).padStart(e*2,"0"))}function rt(t,e){return Te(t,e).reverse()}function $(t,e,r){let n;if(typeof e=="string")try{n=le(e)}catch(s){throw new Error(t+" must be hex string or Uint8Array, cause: "+s)}else if(me(e))n=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(t+" of length "+r+" expected, got "+o);return n}var Bt=t=>typeof t=="bigint"&&St<=t;function qe(t,e,r){return Bt(t)&&Bt(e)&&Bt(r)&&e<=t&&t<r}function vt(t,e,r,n){if(!qe(e,r,n))throw new Error("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Ze(t){let e;for(e=0;t>St;t>>=At,e+=1);return e}var pe=t=>(At<<BigInt(t))-At;function _t(t,e,r){if(typeof t!="number"||t<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=d=>new Uint8Array(d),o=d=>Uint8Array.of(d),s=n(t),i=n(t),c=0,f=()=>{s.fill(1),i.fill(0),c=0},a=(...d)=>r(i,s,...d),l=(d=n(0))=>{i=a(o(0),d),s=a(),d.length!==0&&(i=a(o(1),d),s=a())},y=()=>{if(c++>=1e3)throw new Error("drbg: tried 1000 values");let d=0,w=[];for(;d<e;){s=a();let m=s.slice();w.push(m),d+=s.length}return z(...w)};return(d,w)=>{f(),l(d);let m;for(;!(m=w(y()));)l();return f(),m}}function Ye(t,e,r={}){if(!t||typeof t!="object")throw new Error("expected valid options object");function n(o,s,i){let c=t[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(e).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}function ot(t){let e=new WeakMap;return(r,...n)=>{let o=e.get(r);if(o!==void 0)return o;let s=t(r,...n);return e.set(r,s),s}}var F=BigInt(0),J=BigInt(1),Ie=BigInt(2),ln=BigInt(3),dn=BigInt(4),hn=BigInt(5),Sr=BigInt(7),pn=BigInt(8),Rr=BigInt(9),yn=BigInt(16);function te(t,e){let r=t%e;return r>=F?r:e+r}function ne(t,e,r){let n=t;for(;e-- >F;)n*=n,n%=r;return n}function an(t,e){if(t===F)throw new Error("invert: expected non-zero number");if(e<=F)throw new Error("invert: expected positive modulus, got "+e);let r=te(t,e),n=e,o=F,s=J,i=J,c=F;for(;r!==F;){let a=n/r,l=n%r,y=o-i*a,u=s-c*a;n=r,r=l,o=i,s=c,i=y,c=u}if(n!==J)throw new Error("invert: does not exist");return te(o,e)}function Tt(t,e,r){if(!t.eql(t.sqr(e),r))throw new Error("Cannot find square root")}function xn(t,e){let r=(t.ORDER+J)/dn,n=t.pow(e,r);return Tt(t,n,e),n}function vr(t,e){let r=(t.ORDER-hn)/pn,n=t.mul(e,Ie),o=t.pow(n,r),s=t.mul(e,o),i=t.mul(t.mul(s,Ie),o),c=t.mul(s,t.sub(i,t.ONE));return Tt(t,c,e),c}function _r(t){let e=Se(t),r=bn(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+Sr)/yn;return(c,f)=>{let a=c.pow(f,i),l=c.mul(a,n),y=c.mul(a,o),u=c.mul(a,s),d=c.eql(c.sqr(l),f),w=c.eql(c.sqr(y),f);a=c.cmov(a,l,d),l=c.cmov(u,y,w);let m=c.eql(c.sqr(l),f),S=c.cmov(a,l,m);return Tt(c,S,f),S}}function bn(t){if(t<ln)throw new Error("sqrt is not defined for small field");let e=t-J,r=0;for(;e%Ie===F;)e/=Ie,r++;let n=Ie,o=Se(t);for(;un(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,e),i=(e+J)/Ie;return function(f,a){if(f.is0(a))return a;if(un(f,a)!==1)throw new Error("Cannot find square root");let l=r,y=f.mul(f.ONE,s),u=f.pow(a,e),d=f.pow(a,i);for(;!f.eql(u,f.ONE);){if(f.is0(u))return f.ZERO;let w=1,m=f.sqr(u);for(;!f.eql(m,f.ONE);)if(w++,m=f.sqr(m),w===l)throw new Error("Cannot find square root");let S=J<<BigInt(l-w-1),U=f.pow(y,S);l=w,y=f.sqr(U),u=f.mul(u,y),d=f.mul(d,U)}return d}}function Tr(t){return t%dn===ln?xn:t%pn===hn?vr:t%yn===Rr?_r(t):bn(t)}var Ir=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function It(t){let e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=Ir.reduce((n,o)=>(n[o]="function",n),e);return Ye(t,r),t}function Ur(t,e,r){if(r<F)throw new Error("invalid exponent, negatives unsupported");if(r===F)return t.ONE;if(r===J)return e;let n=t.ONE,o=e;for(;r>F;)r&J&&(n=t.mul(n,o)),o=t.sqr(o),r>>=J;return n}function st(t,e,r=!1){let n=new Array(e.length).fill(r?t.ZERO:void 0),o=e.reduce((i,c,f)=>t.is0(c)?i:(n[f]=i,t.mul(i,c)),t.ONE),s=t.inv(o);return e.reduceRight((i,c,f)=>t.is0(c)?i:(n[f]=t.mul(i,n[f]),t.mul(i,c)),s),n}function un(t,e){let r=(t.ORDER-J)/Ie,n=t.pow(e,r),o=t.eql(n,t.ONE),s=t.eql(n,t.ZERO),i=t.eql(n,t.neg(t.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function it(t,e){e!==void 0&&we(e);let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function Se(t,e,r=!1,n={}){if(t<=F)throw new Error("invalid field: expected ORDER > 0, got "+t);let o,s,i=!1,c;if(typeof e=="object"&&e!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let u=e;u.BITS&&(o=u.BITS),u.sqrt&&(s=u.sqrt),typeof u.isLE=="boolean"&&(r=u.isLE),typeof u.modFromBytes=="boolean"&&(i=u.modFromBytes),c=u.allowedLengths}else typeof e=="number"&&(o=e),n.sqrt&&(s=n.sqrt);let{nBitLength:f,nByteLength:a}=it(t,o);if(a>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let l,y=Object.freeze({ORDER:t,isLE:r,BITS:f,BYTES:a,MASK:pe(f),ZERO:F,ONE:J,allowedLengths:c,create:u=>te(u,t),isValid:u=>{if(typeof u!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof u);return F<=u&&u<t},is0:u=>u===F,isValidNot0:u=>!y.is0(u)&&y.isValid(u),isOdd:u=>(u&J)===J,neg:u=>te(-u,t),eql:(u,d)=>u===d,sqr:u=>te(u*u,t),add:(u,d)=>te(u+d,t),sub:(u,d)=>te(u-d,t),mul:(u,d)=>te(u*d,t),pow:(u,d)=>Ur(y,u,d),div:(u,d)=>te(u*an(d,t),t),sqrN:u=>u*u,addN:(u,d)=>u+d,subN:(u,d)=>u-d,mulN:(u,d)=>u*d,inv:u=>an(u,t),sqrt:s||(u=>(l||(l=Tr(t)),l(y,u))),toBytes:u=>r?rt(u,a):Te(u,a),fromBytes:(u,d=!0)=>{if(c){if(!c.includes(u.length)||u.length>a)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+u.length);let m=new Uint8Array(a);m.set(u,r?0:m.length-u.length),u=m}if(u.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+u.length);let w=r?nt(u):ce(u);if(i&&(w=te(w,t)),!d&&!y.isValid(w))throw new Error("invalid field element: outside of range 0..ORDER");return w},invertBatch:u=>st(y,u),cmov:(u,d,w)=>w?d:u});return Object.freeze(y)}function gn(t){if(typeof t!="bigint")throw new Error("field order must be bigint");let e=t.toString(2).length;return Math.ceil(e/8)}function Ut(t){let e=gn(t);return e+Math.ceil(e/2)}function ct(t,e,r=!1){let n=t.length,o=gn(e),s=Ut(e);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?nt(t):ce(t),c=te(i,e-J)+J;return r?rt(c,o):Te(c,o)}var Pe=BigInt(0),Ue=BigInt(1);function ze(t,e){let r=e.negate();return t?r:e}function at(t,e){let r=st(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function Bn(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Lt(t,e){Bn(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),o=2**t,s=pe(t),i=BigInt(t);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function wn(t,e,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,c=Number(t&o),f=t>>i;c>n&&(c-=s,f+=Ue);let a=e*n,l=a+Math.abs(c)-1,y=c===0,u=c<0,d=e%2!==0;return{nextN:f,offset:l,isZero:y,isNeg:u,isNegF:d,offsetF:a}}function Or(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function Hr(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((r,n)=>{if(!e.isValid(r))throw new Error("invalid scalar at index "+n)})}var Ot=new WeakMap,An=new WeakMap;function Ht(t){return An.get(t)||1}function mn(t){if(t!==Pe)throw new Error("invalid wNAF")}var ft=class{constructor(e,r){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let o=e;for(;r>Pe;)r&Ue&&(n=n.add(o)),o=o.double(),r>>=Ue;return n}precomputeWindow(e,r){let{windows:n,windowSize:o}=Lt(r,this.bits),s=[],i=e,c=i;for(let f=0;f<n;f++){c=i,s.push(c);for(let a=1;a<o;a++)c=c.add(i),s.push(c);i=c.double()}return s}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Lt(e,this.bits);for(let c=0;c<i.windows;c++){let{nextN:f,offset:a,isZero:l,isNeg:y,isNegF:u,offsetF:d}=wn(n,c,i);n=f,l?s=s.add(ze(u,r[d])):o=o.add(ze(y,r[a]))}return mn(n),{p:o,f:s}}wNAFUnsafe(e,r,n,o=this.ZERO){let s=Lt(e,this.bits);for(let i=0;i<s.windows&&n!==Pe;i++){let{nextN:c,offset:f,isZero:a,isNeg:l}=wn(n,i,s);if(n=c,!a){let y=r[f];o=o.add(l?y.negate():y)}}return mn(n),o}getPrecomputes(e,r,n){let o=Ot.get(r);return o||(o=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(o=n(o)),Ot.set(r,o))),o}cached(e,r,n){let o=Ht(e);return this.wNAF(o,this.getPrecomputes(o,e,n),r)}unsafe(e,r,n,o){let s=Ht(e);return s===1?this._unsafeLadder(e,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,e,n),r,o)}createCache(e,r){Bn(r,this.bits),An.set(e,r),Ot.delete(e)}hasCache(e){return Ht(e)!==1}};function Sn(t,e,r,n){let o=e,s=t.ZERO,i=t.ZERO;for(;r>Pe||n>Pe;)r&Ue&&(s=s.add(o)),n&Ue&&(i=i.add(o)),o=o.double(),r>>=Ue,n>>=Ue;return{p1:s,p2:i}}function Rn(t,e,r,n){Or(r,t),Hr(n,e);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=t.ZERO,c=Ze(BigInt(o)),f=1;c>12?f=c-3:c>4?f=c-2:c>0&&(f=2);let a=pe(f),l=new Array(Number(a)+1).fill(i),y=Math.floor((e.BITS-1)/f)*f,u=i;for(let d=y;d>=0;d-=f){l.fill(i);for(let m=0;m<s;m++){let S=n[m],U=Number(S>>BigInt(d)&a);l[U]=l[U].add(r[m])}let w=i;for(let m=l.length-1,S=i;m>0;m--)S=S.add(l[m]),w=w.add(S);if(u=u.add(w),d!==0)for(let m=0;m<f;m++)u=u.double()}return u}function En(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return It(e),e}else return Se(t,{isLE:r})}function vn(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let f of["p","n","h"]){let a=e[f];if(!(typeof a=="bigint"&&a>Pe))throw new Error(`CURVE.${f} must be positive bigint`)}let o=En(e.p,r.Fp,n),s=En(e.n,r.Fn,n),c=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let f of c)if(!o.isValid(e[f]))throw new Error(`CURVE.${f} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:s}}var _n=(t,e)=>(t+(t>=0?e:-e)/Tn)/e;function kr(t,e,r){let[[n,o],[s,i]]=e,c=_n(i*t,r),f=_n(-o*t,r),a=t-c*n-f*s,l=-c*o-f*i,y=a<xe,u=l<xe;y&&(a=-a),u&&(l=-l);let d=pe(Math.ceil(Ze(r)/2))+De;if(a<xe||a>=d||l<xe||l>=d)throw new Error("splitScalar (endomorphism): failed, k="+t);return{k1neg:y,k1:a,k2neg:u,k2:l}}function Nt(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function kt(t,e){let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return $e(r.lowS,"lowS"),$e(r.prehash,"prehash"),r.format!==void 0&&Nt(r.format),r}var Ct=class extends Error{constructor(e=""){super(e)}},ye={Err:Ct,_tlv:{encode:(t,e)=>{let{Err:r}=ye;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=Ce(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Ce(o.length/2|128):"";return Ce(t)+s+o+e},decode(t,e){let{Err:r}=ye,n=0;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[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 a=e.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)i=i<<8|l;if(n+=f,i<128)throw new r("tlv.decode(long): not minimal encoding")}let c=e.subarray(n,n+i);if(c.length!==i)throw new r("tlv.decode: wrong value length");return{v:c,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=ye;if(t<xe)throw new e("integer: negative integers are not allowed");let r=Ce(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=ye;if(t[0]&128)throw new e("invalid signature integer: negative");if(t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return ce(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=ye,o=$("signature",t),{v:s,l:i}=n.decode(48,o);if(i.length)throw new e("invalid signature: left bytes after parsing");let{v:c,l:f}=n.decode(2,s),{v:a,l}=n.decode(2,f);if(l.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(a)}},hexFromSig(t){let{_tlv:e,_int:r}=ye,n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),s=n+o;return e.encode(48,s)}},xe=BigInt(0),De=BigInt(1),Tn=BigInt(2),ut=BigInt(3),Nr=BigInt(4);function Re(t,e){let{BYTES:r}=t,n;if(typeof e=="bigint")n=e;else{let o=$("private key",e);try{n=t.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof e}`)}}if(!t.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function Cr(t,e={}){let r=vn("weierstrass",t,e),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:c}=s;Ye(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:f}=e;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 a=Un(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function y(I,x,p){let{x:h,y:g}=x.toAffine(),E=n.toBytes(h);if($e(p,"isCompressed"),p){l();let A=!n.isOdd(g);return z(In(A),E)}else return z(Uint8Array.of(4),E,n.toBytes(g))}function u(I){Ae(I,void 0,"Point");let{publicKey:x,publicKeyUncompressed:p}=a,h=I.length,g=I[0],E=I.subarray(1);if(h===x&&(g===2||g===3)){let A=n.fromBytes(E);if(!n.isValid(A))throw new Error("bad point: is not on curve, wrong x");let b=m(A),B;try{B=n.sqrt(b)}catch(q){let N=q instanceof Error?": "+q.message:"";throw new Error("bad point: is not on curve, sqrt error"+N)}l();let R=n.isOdd(B);return(g&1)===1!==R&&(B=n.neg(B)),{x:A,y:B}}else if(h===p&&g===4){let A=n.BYTES,b=n.fromBytes(E.subarray(0,A)),B=n.fromBytes(E.subarray(A,A*2));if(!S(b,B))throw new Error("bad point: is not on curve");return{x:b,y:B}}else throw new Error(`bad point: got length ${h}, expected compressed=${x} or uncompressed=${p}`)}let d=e.toBytes||y,w=e.fromBytes||u;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 S(I,x){let p=n.sqr(x),h=m(I);return n.eql(p,h)}if(!S(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let U=n.mul(n.pow(s.a,ut),Nr),H=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(U,H)))throw new Error("bad curve params: a or b");function L(I,x,p=!1){if(!n.isValid(x)||p&&n.is0(x))throw new Error(`bad point coordinate ${I}`);return x}function M(I){if(!(I instanceof T))throw new Error("ProjectivePoint expected")}function W(I){if(!f||!f.basises)throw new Error("no endo");return kr(I,f.basises,o.ORDER)}let j=ot((I,x)=>{let{X:p,Y:h,Z:g}=I;if(n.eql(g,n.ONE))return{x:p,y:h};let E=I.is0();x==null&&(x=E?n.ONE:n.inv(g));let A=n.mul(p,x),b=n.mul(h,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:A,y:b}}),Z=ot(I=>{if(I.is0()){if(e.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(!S(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 G(I,x,p,h,g){return p=new T(n.mul(p.X,I),p.Y,p.Z),x=ze(h,x),p=ze(g,p),x.add(p)}class T{constructor(x,p,h){this.X=L("x",x),this.Y=L("y",p,!0),this.Z=L("z",h),Object.freeze(this)}static CURVE(){return s}static fromAffine(x){let{x:p,y:h}=x||{};if(!x||!n.isValid(p)||!n.isValid(h))throw new Error("invalid affine point");if(x instanceof T)throw new Error("projective point not allowed");return n.is0(p)&&n.is0(h)?T.ZERO:new T(p,h,n.ONE)}static fromBytes(x){let p=T.fromAffine(w(Ae(x,void 0,"point")));return p.assertValidity(),p}static fromHex(x){return T.fromBytes($("pointHex",x))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(x=8,p=!0){return k.createCache(this,x),p||this.multiply(ut),this}assertValidity(){Z(this)}hasEvenY(){let{y:x}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(x)}equals(x){M(x);let{X:p,Y:h,Z:g}=this,{X:E,Y:A,Z:b}=x,B=n.eql(n.mul(p,b),n.mul(E,g)),R=n.eql(n.mul(h,b),n.mul(A,g));return B&&R}negate(){return new T(this.X,n.neg(this.Y),this.Z)}double(){let{a:x,b:p}=s,h=n.mul(p,ut),{X:g,Y:E,Z:A}=this,b=n.ZERO,B=n.ZERO,R=n.ZERO,_=n.mul(g,g),q=n.mul(E,E),N=n.mul(A,A),O=n.mul(g,E);return O=n.add(O,O),R=n.mul(g,A),R=n.add(R,R),b=n.mul(x,R),B=n.mul(h,N),B=n.add(b,B),b=n.sub(q,B),B=n.add(q,B),B=n.mul(b,B),b=n.mul(O,b),R=n.mul(h,R),N=n.mul(x,N),O=n.sub(_,N),O=n.mul(x,O),O=n.add(O,R),R=n.add(_,_),_=n.add(R,_),_=n.add(_,N),_=n.mul(_,O),B=n.add(B,_),N=n.mul(E,A),N=n.add(N,N),_=n.mul(N,O),b=n.sub(b,_),R=n.mul(N,q),R=n.add(R,R),R=n.add(R,R),new T(b,B,R)}add(x){M(x);let{X:p,Y:h,Z:g}=this,{X:E,Y:A,Z:b}=x,B=n.ZERO,R=n.ZERO,_=n.ZERO,q=s.a,N=n.mul(s.b,ut),O=n.mul(p,E),P=n.mul(h,A),V=n.mul(g,b),Y=n.add(p,h),D=n.add(E,A);Y=n.mul(Y,D),D=n.add(O,P),Y=n.sub(Y,D),D=n.add(p,g);let Q=n.add(E,b);return D=n.mul(D,Q),Q=n.add(O,V),D=n.sub(D,Q),Q=n.add(h,g),B=n.add(A,b),Q=n.mul(Q,B),B=n.add(P,V),Q=n.sub(Q,B),_=n.mul(q,D),B=n.mul(N,V),_=n.add(B,_),B=n.sub(P,_),_=n.add(P,_),R=n.mul(B,_),P=n.add(O,O),P=n.add(P,O),V=n.mul(q,V),D=n.mul(N,D),P=n.add(P,V),V=n.sub(O,V),V=n.mul(q,V),D=n.add(D,V),O=n.mul(P,D),R=n.add(R,O),O=n.mul(Q,D),B=n.mul(Y,B),B=n.sub(B,O),O=n.mul(Y,P),_=n.mul(Q,_),_=n.add(_,O),new T(B,R,_)}subtract(x){return this.add(x.negate())}is0(){return this.equals(T.ZERO)}multiply(x){let{endo:p}=e;if(!o.isValidNot0(x))throw new Error("invalid scalar: out of range");let h,g,E=A=>k.cached(this,A,b=>at(T,b));if(p){let{k1neg:A,k1:b,k2neg:B,k2:R}=W(x),{p:_,f:q}=E(b),{p:N,f:O}=E(R);g=q.add(O),h=G(p.beta,_,N,A,B)}else{let{p:A,f:b}=E(x);h=A,g=b}return at(T,[h,g])[0]}multiplyUnsafe(x){let{endo:p}=e,h=this;if(!o.isValid(x))throw new Error("invalid scalar: out of range");if(x===xe||h.is0())return T.ZERO;if(x===De)return h;if(k.hasCache(this))return this.multiply(x);if(p){let{k1neg:g,k1:E,k2neg:A,k2:b}=W(x),{p1:B,p2:R}=Sn(T,h,E,b);return G(p.beta,B,R,g,A)}else return k.unsafe(h,x)}multiplyAndAddUnsafe(x,p,h){let g=this.multiplyUnsafe(p).add(x.multiplyUnsafe(h));return g.is0()?void 0:g}toAffine(x){return j(this,x)}isTorsionFree(){let{isTorsionFree:x}=e;return i===De?!0:x?x(T,this):k.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:x}=e;return i===De?this:x?x(T,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(x=!0){return $e(x,"isCompressed"),this.assertValidity(),d(T,this,x)}toHex(x=!0){return se(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 at(T,x)}static msm(x,p){return Rn(T,o,x,p)}static fromPrivateKey(x){return T.BASE.multiply(Re(o,x))}}T.BASE=new T(s.Gx,s.Gy,n.ONE),T.ZERO=new T(n.ZERO,n.ONE,n.ZERO),T.Fp=n,T.Fn=o;let C=o.BITS,k=new ft(T,e.endo?Math.ceil(C/2):C);return T.BASE.precompute(8),T}function In(t){return Uint8Array.of(t?2:3)}function Un(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function qr(t,e={}){let{Fn:r}=t,n=e.randomBytes||ee,o=Object.assign(Un(t.Fp,r),{seed:Ut(r.ORDER)});function s(d){try{return!!Re(r,d)}catch{return!1}}function i(d,w){let{publicKey:m,publicKeyUncompressed:S}=o;try{let U=d.length;return w===!0&&U!==m||w===!1&&U!==S?!1:!!t.fromBytes(d)}catch{return!1}}function c(d=n(o.seed)){return ct(Ae(d,o.seed,"seed"),r.ORDER)}function f(d,w=!0){return t.BASE.multiply(Re(r,d)).toBytes(w)}function a(d){let w=c(d);return{secretKey:w,publicKey:f(w)}}function l(d){if(typeof d=="bigint")return!1;if(d instanceof t)return!0;let{secretKey:w,publicKey:m,publicKeyUncompressed:S}=o;if(r.allowedLengths||w===m)return;let U=$("key",d).length;return U===m||U===S}function y(d,w,m=!0){if(l(d)===!0)throw new Error("first arg must be private key");if(l(w)===!1)throw new Error("second arg must be public key");let S=Re(r,d);return t.fromHex(w).multiply(S).toBytes(m)}return Object.freeze({getPublicKey:f,getSharedSecret:y,keygen:a,Point:t,utils:{isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c,isValidPrivateKey:s,randomPrivateKey:c,normPrivateKeyToScalar:d=>Re(r,d),precompute(d=8,w=t.BASE){return w.precompute(d,!1)}},lengths:o})}function Pr(t,e,r={}){_e(e),Ye(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||ee,o=r.hmac||((p,...h)=>he(e,p,z(...h))),{Fp:s,Fn:i}=t,{ORDER:c,BITS:f}=i,{keygen:a,getPublicKey:l,getSharedSecret:y,utils:u,lengths:d}=qr(t,r),w={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},m="compact";function S(p){let h=c>>De;return p>h}function U(p,h){if(!i.isValidNot0(h))throw new Error(`invalid signature ${p}: out of range 1..Point.Fn.ORDER`);return h}function H(p,h){Nt(h);let g=d.signature,E=h==="compact"?g:h==="recovered"?g+1:void 0;return Ae(p,E,`${h} signature`)}class L{constructor(h,g,E){this.r=U("r",h),this.s=U("s",g),E!=null&&(this.recovery=E),Object.freeze(this)}static fromBytes(h,g=m){H(h,g);let E;if(g==="der"){let{r:R,s:_}=ye.toSig(Ae(h));return new L(R,_)}g==="recovered"&&(E=h[0],g="compact",h=h.subarray(1));let A=i.BYTES,b=h.subarray(0,A),B=h.subarray(A,A*2);return new L(i.fromBytes(b),i.fromBytes(B),E)}static fromHex(h,g){return this.fromBytes(le(h),g)}addRecoveryBit(h){return new L(this.r,this.s,h)}recoverPublicKey(h){let g=s.ORDER,{r:E,s:A,recovery:b}=this;if(b==null||![0,1,2,3].includes(b))throw new Error("recovery id invalid");if(c*Tn<g&&b>1)throw new Error("recovery id is ambiguous for h>1 curve");let R=b===2||b===3?E+c:E;if(!s.isValid(R))throw new Error("recovery id 2 or 3 invalid");let _=s.toBytes(R),q=t.fromBytes(z(In((b&1)===0),_)),N=i.inv(R),O=W($("msgHash",h)),P=i.create(-O*N),V=i.create(A*N),Y=t.BASE.multiplyUnsafe(P).add(q.multiplyUnsafe(V));if(Y.is0())throw new Error("point at infinify");return Y.assertValidity(),Y}hasHighS(){return S(this.s)}toBytes(h=m){if(Nt(h),h==="der")return le(ye.hexFromSig(this));let g=i.toBytes(this.r),E=i.toBytes(this.s);if(h==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return z(Uint8Array.of(this.recovery),g,E)}return z(g,E)}toHex(h){return se(this.toBytes(h))}assertValidity(){}static fromCompact(h){return L.fromBytes($("sig",h),"compact")}static fromDER(h){return L.fromBytes($("sig",h),"der")}normalizeS(){return this.hasHighS()?new L(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return se(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return se(this.toBytes("compact"))}}let M=r.bits2int||function(h){if(h.length>8192)throw new Error("input is too large");let g=ce(h),E=h.length*8-f;return E>0?g>>BigInt(E):g},W=r.bits2int_modN||function(h){return i.create(M(h))},j=pe(f);function Z(p){return vt("num < 2^"+f,p,xe,j),i.toBytes(p)}function G(p,h){return Ae(p,void 0,"message"),h?Ae(e(p),void 0,"prehashed message"):p}function T(p,h,g){if(["recovered","canonical"].some(P=>P in g))throw new Error("sign() legacy options not supported");let{lowS:E,prehash:A,extraEntropy:b}=kt(g,w);p=G(p,A);let B=W(p),R=Re(i,h),_=[Z(R),Z(B)];if(b!=null&&b!==!1){let P=b===!0?n(d.secretKey):b;_.push($("extraEntropy",P))}let q=z(..._),N=B;function O(P){let V=M(P);if(!i.isValidNot0(V))return;let Y=i.inv(V),D=t.BASE.multiply(V).toAffine(),Q=i.create(D.x);if(Q===xe)return;let Ke=i.create(Y*i.create(N+Q*R));if(Ke===xe)return;let en=(D.x===Q?0:2)|Number(D.y&De),tn=Ke;return E&&S(Ke)&&(tn=i.neg(Ke),en^=1),new L(Q,tn,en)}return{seed:q,k2sig:O}}function C(p,h,g={}){p=$("message",p);let{seed:E,k2sig:A}=T(p,h,g);return _t(e.outputLen,i.BYTES,o)(E,A)}function k(p){let h,g=typeof p=="string"||me(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)h=new L(p.r,p.s);else if(g){try{h=L.fromBytes($("sig",p),"der")}catch(A){if(!(A instanceof ye.Err))throw A}if(!h)try{h=L.fromBytes($("sig",p),"compact")}catch{return!1}}return h||!1}function I(p,h,g,E={}){let{lowS:A,prehash:b,format:B}=kt(E,w);if(g=$("publicKey",g),h=G($("message",h),b),"strict"in E)throw new Error("options.strict was renamed to lowS");let R=B===void 0?k(p):L.fromBytes($("sig",p),B);if(R===!1)return!1;try{let _=t.fromBytes(g);if(A&&R.hasHighS())return!1;let{r:q,s:N}=R,O=W(h),P=i.inv(N),V=i.create(O*P),Y=i.create(q*P),D=t.BASE.multiplyUnsafe(V).add(_.multiplyUnsafe(Y));return D.is0()?!1:i.create(D.x)===q}catch{return!1}}function x(p,h,g={}){let{prehash:E}=kt(g,w);return h=G(h,E),L.fromBytes(p,"recovered").recoverPublicKey(h).toBytes()}return Object.freeze({keygen:a,getPublicKey:l,getSharedSecret:y,utils:u,lengths:d,Point:t,sign:C,verify:I,recoverPublicKey:x,Signature:L,hash:e})}function Dr(t){let e={a:t.a,b:t.b,p:t.Fp.ORDER,n:t.n,h:t.h,Gx:t.Gx,Gy:t.Gy},r=t.Fp,n=t.allowedPrivateKeyLengths?Array.from(new Set(t.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,o=Se(e.n,{BITS:t.nBitLength,allowedLengths:n,modFromBytes:t.wrapPrivateKey}),s={Fp:r,Fn:o,allowInfinityPoint:t.allowInfinityPoint,endo:t.endo,isTorsionFree:t.isTorsionFree,clearCofactor:t.clearCofactor,fromBytes:t.fromBytes,toBytes:t.toBytes};return{CURVE:e,curveOpts:s}}function Vr(t){let{CURVE:e,curveOpts:r}=Dr(t),n={hmac:t.hmac,randomBytes:t.randomBytes,lowS:t.lowS,bits2int:t.bits2int,bits2int_modN:t.bits2int_modN};return{CURVE:e,curveOpts:r,hash:t.hash,ecdsaOpts:n}}function Mr(t,e){let r=e.Point;return Object.assign({},e,{ProjectivePoint:r,CURVE:Object.assign({},t,it(r.Fn.ORDER,r.Fn.BITS))})}function Ln(t){let{CURVE:e,curveOpts:r,hash:n,ecdsaOpts:o}=Vr(t),s=Cr(e,r),i=Pr(s,n,o);return Mr(t,i)}function On(t,e){let r=n=>Ln({...t,hash:n});return{...r(e),create:r}}var Ve={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},jr={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},Gr=BigInt(0),Hn=BigInt(1),qt=BigInt(2);function $r(t){let e=Ve.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),f=BigInt(88),a=t*t*t%e,l=a*a*t%e,y=ne(l,r,e)*l%e,u=ne(y,r,e)*l%e,d=ne(u,qt,e)*a%e,w=ne(d,o,e)*d%e,m=ne(w,s,e)*w%e,S=ne(m,c,e)*m%e,U=ne(S,f,e)*S%e,H=ne(U,c,e)*m%e,L=ne(H,r,e)*l%e,M=ne(L,i,e)*w%e,W=ne(M,n,e)*a%e,j=ne(W,qt,e);if(!lt.eql(lt.sqr(j),t))throw new Error("Cannot find square root");return j}var lt=Se(Ve.p,{sqrt:$r}),ht=On({...Ve,Fp:lt,lowS:!0,endo:jr},Ne),kn={};function dt(t,...e){let r=kn[t];if(r===void 0){let n=Ne(Ge(t));r=z(n,n),kn[t]=r}return Ne(z(r,...e))}var Dt=t=>t.toBytes(!0).slice(1),Me=ht.Point,Vt=t=>t%qt===Gr;function Pt(t){let{Fn:e,BASE:r}=Me,n=Re(e,t),o=r.multiply(n);return{scalar:Vt(o.y)?n:e.neg(n),bytes:Dt(o)}}function Cn(t){let e=lt;if(!e.isValidNot0(t))throw new Error("invalid x: Fail if x \u2265 p");let r=e.create(t*t),n=e.create(r*t+BigInt(7)),o=e.sqrt(n);Vt(o)||(o=e.neg(o));let s=Me.fromAffine({x:t,y:o});return s.assertValidity(),s}var We=ce;function qn(...t){return Me.Fn.create(We(dt("BIP0340/challenge",...t)))}function Nn(t){return Pt(t).bytes}function Zr(t,e,r=ee(32)){let{Fn:n}=Me,o=$("message",t),{bytes:s,scalar:i}=Pt(e),c=$("auxRand",r,32),f=n.toBytes(i^We(dt("BIP0340/aux",c))),a=dt("BIP0340/nonce",f,s,o),{bytes:l,scalar:y}=Pt(a),u=qn(l,s,o),d=new Uint8Array(64);if(d.set(l,0),d.set(n.toBytes(n.create(y+u*i)),32),!Pn(d,o,s))throw new Error("sign: Invalid signature produced");return d}function Pn(t,e,r){let{Fn:n,BASE:o}=Me,s=$("signature",t,64),i=$("message",e),c=$("publicKey",r,32);try{let f=Cn(We(c)),a=We(s.subarray(0,32));if(!qe(a,Hn,Ve.p))return!1;let l=We(s.subarray(32,64));if(!qe(l,Hn,Ve.n))return!1;let y=qn(n.toBytes(a),Dt(f),i),u=o.multiplyUnsafe(l).add(f.multiplyUnsafe(n.neg(y))),{x:d,y:w}=u.toAffine();return!(u.is0()||!Vt(w)||d!==a)}catch{return!1}}var pt=(()=>{let r=(o=ee(48))=>ct(o,Ve.n);ht.utils.randomSecretKey;function n(o){let s=r(o);return{secretKey:s,publicKey:Nn(s)}}return{keygen:n,getPublicKey:Nn,sign:Zr,verify:Pn,Point:Me,utils:{randomSecretKey:r,randomPrivateKey:r,taggedHash:dt,lift_x:Cn,pointToBytes:Dt,numberToBytesBE:Te,bytesToNumberBE:ce,mod:te},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})();var Le=se;var Mt=le;var Oe=Ne;function Yr(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function yt(t){if(typeof t!="boolean")throw new Error(`boolean expected, not ${t}`)}function xt(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function X(t,e,r=""){let n=Yr(t),o=t?.length,s=e!==void 0;if(!n||s&&o!==e){let i=r&&`"${r}" `,c=s?` of length ${e}`:"",f=n?`length=${o}`:`type=${typeof t}`;throw new Error(i+"expected Uint8Array"+c+", got "+f)}return t}function jt(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function Dn(t,e){X(t,void 0,"output");let r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function be(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function ge(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function zr(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}var Wr=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Vn(t,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(t,e)}function bt(t,e){if(t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}var Gt=(t,e)=>{function r(n,...o){if(X(n,void 0,"key"),!Wr)throw new Error("Non little-endian hardware is not yet supported");if(t.nonceLength!==void 0){let l=o[0];X(l,t.varSizeNonce?void 0:t.nonceLength,"nonce")}let s=t.tagLength;s&&o[1]!==void 0&&X(o[1],void 0,"AAD");let i=e(n,...o),c=(l,y)=>{if(y!==void 0){if(l!==2)throw new Error("cipher output not supported");X(y,void 0,"output")}},f=!1;return{encrypt(l,y){if(f)throw new Error("cannot encrypt() twice with same key + nonce");return f=!0,X(l),c(i.encrypt.length,y),i.encrypt(l,y)},decrypt(l,y){if(X(l),s&&l.length<s)throw new Error('"ciphertext" expected length bigger than tagLength='+s);return c(i.decrypt.length,y),i.decrypt(l,y)}}}return Object.assign(r,t),r};function $t(t,e,r=!0){if(e===void 0)return new Uint8Array(t);if(e.length!==t)throw new Error('"output" expected Uint8Array of length '+t+", got: "+e.length);if(r&&!Xr(e))throw new Error("invalid output, must be aligned");return e}function Mn(t,e,r){yt(r);let n=new Uint8Array(16),o=zr(n);return o.setBigUint64(0,BigInt(e),r),o.setBigUint64(8,BigInt(t),r),n}function Xr(t){return t.byteOffset%4===0}function je(t){return Uint8Array.from(t)}var Gn=t=>Uint8Array.from(t.split(""),e=>e.charCodeAt(0)),Kr=Gn("expand 16-byte k"),Qr=Gn("expand 32-byte k"),Jr=be(Kr),Fr=be(Qr);function v(t,e){return t<<e|t>>>32-e}function Zt(t){return t.byteOffset%4===0}var gt=64,eo=16,$n=2**32-1,jn=Uint32Array.of();function to(t,e,r,n,o,s,i,c){let f=o.length,a=new Uint8Array(gt),l=be(a),y=Zt(o)&&Zt(s),u=y?be(o):jn,d=y?be(s):jn;for(let w=0;w<f;i++){if(t(e,r,n,l,i,c),i>=$n)throw new Error("arx: counter overflow");let m=Math.min(gt,f-w);if(y&&m===gt){let S=w/4;if(w%4!==0)throw new Error("arx: invalid block position");for(let U=0,H;U<eo;U++)H=S+U,d[H]=u[H]^l[U];w+=gt;continue}for(let S=0,U;S<m;S++)U=w+S,s[U]=o[U]^a[S];w+=m}}function Yt(t,e){let{allowShortKeys:r,extendNonceFn:n,counterLength:o,counterRight:s,rounds:i}=Vn({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof t!="function")throw new Error("core must be a function");return xt(o),xt(i),yt(s),yt(r),(c,f,a,l,y=0)=>{X(c,void 0,"key"),X(f,void 0,"nonce"),X(a,void 0,"data");let u=a.length;if(l===void 0&&(l=new Uint8Array(u)),X(l,void 0,"output"),xt(y),y<0||y>=$n)throw new Error("arx: counter overflow");if(l.length<u)throw new Error(`arx: output (${l.length}) is shorter than data (${u})`);let d=[],w=c.length,m,S;if(w===32)d.push(m=je(c)),S=Fr;else if(w===16&&r)m=new Uint8Array(32),m.set(c),m.set(c,16),S=Jr,d.push(m);else throw X(c,32,"arx key"),new Error("invalid key size");Zt(f)||d.push(f=je(f));let U=be(m);if(n){if(f.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(S,U,be(f.subarray(0,16)),U),f=f.subarray(16)}let H=16-o;if(H!==f.length)throw new Error(`arx: nonce must be ${H} or 16 bytes`);if(H!==12){let M=new Uint8Array(12);M.set(f,s?0:12-f.length),f=M,d.push(f)}let L=be(f);return to(t,S,U,L,a,l,y,i),ge(...d),l}}function K(t,e){return t[e++]&255|(t[e++]&255)<<8}var zt=class{constructor(e){ie(this,"blockLen",16);ie(this,"outputLen",16);ie(this,"buffer",new Uint8Array(16));ie(this,"r",new Uint16Array(10));ie(this,"h",new Uint16Array(10));ie(this,"pad",new Uint16Array(8));ie(this,"pos",0);ie(this,"finished",!1);e=je(X(e,32,"key"));let r=K(e,0),n=K(e,2),o=K(e,4),s=K(e,6),i=K(e,8),c=K(e,10),f=K(e,12),a=K(e,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|a<<8)&8191,this.r[9]=a>>>5&127;for(let l=0;l<8;l++)this.pad[l]=K(e,16+2*l)}process(e,r,n=!1){let o=n?0:2048,{h:s,r:i}=this,c=i[0],f=i[1],a=i[2],l=i[3],y=i[4],u=i[5],d=i[6],w=i[7],m=i[8],S=i[9],U=K(e,r+0),H=K(e,r+2),L=K(e,r+4),M=K(e,r+6),W=K(e,r+8),j=K(e,r+10),Z=K(e,r+12),G=K(e,r+14),T=s[0]+(U&8191),C=s[1]+((U>>>13|H<<3)&8191),k=s[2]+((H>>>10|L<<6)&8191),I=s[3]+((L>>>7|M<<9)&8191),x=s[4]+((M>>>4|W<<12)&8191),p=s[5]+(W>>>1&8191),h=s[6]+((W>>>14|j<<2)&8191),g=s[7]+((j>>>11|Z<<5)&8191),E=s[8]+((Z>>>8|G<<8)&8191),A=s[9]+(G>>>5|o),b=0,B=b+T*c+C*(5*S)+k*(5*m)+I*(5*w)+x*(5*d);b=B>>>13,B&=8191,B+=p*(5*u)+h*(5*y)+g*(5*l)+E*(5*a)+A*(5*f),b+=B>>>13,B&=8191;let R=b+T*f+C*c+k*(5*S)+I*(5*m)+x*(5*w);b=R>>>13,R&=8191,R+=p*(5*d)+h*(5*u)+g*(5*y)+E*(5*l)+A*(5*a),b+=R>>>13,R&=8191;let _=b+T*a+C*f+k*c+I*(5*S)+x*(5*m);b=_>>>13,_&=8191,_+=p*(5*w)+h*(5*d)+g*(5*u)+E*(5*y)+A*(5*l),b+=_>>>13,_&=8191;let q=b+T*l+C*a+k*f+I*c+x*(5*S);b=q>>>13,q&=8191,q+=p*(5*m)+h*(5*w)+g*(5*d)+E*(5*u)+A*(5*y),b+=q>>>13,q&=8191;let N=b+T*y+C*l+k*a+I*f+x*c;b=N>>>13,N&=8191,N+=p*(5*S)+h*(5*m)+g*(5*w)+E*(5*d)+A*(5*u),b+=N>>>13,N&=8191;let O=b+T*u+C*y+k*l+I*a+x*f;b=O>>>13,O&=8191,O+=p*c+h*(5*S)+g*(5*m)+E*(5*w)+A*(5*d),b+=O>>>13,O&=8191;let P=b+T*d+C*u+k*y+I*l+x*a;b=P>>>13,P&=8191,P+=p*f+h*c+g*(5*S)+E*(5*m)+A*(5*w),b+=P>>>13,P&=8191;let V=b+T*w+C*d+k*u+I*y+x*l;b=V>>>13,V&=8191,V+=p*a+h*f+g*c+E*(5*S)+A*(5*m),b+=V>>>13,V&=8191;let Y=b+T*m+C*w+k*d+I*u+x*y;b=Y>>>13,Y&=8191,Y+=p*l+h*a+g*f+E*c+A*(5*S),b+=Y>>>13,Y&=8191;let D=b+T*S+C*m+k*w+I*d+x*u;b=D>>>13,D&=8191,D+=p*y+h*l+g*a+E*f+A*c,b+=D>>>13,D&=8191,b=(b<<2)+b|0,b=b+B|0,B=b&8191,b=b>>>13,R+=b,s[0]=B,s[1]=R,s[2]=_,s[3]=q,s[4]=N,s[5]=O,s[6]=P,s[7]=V,s[8]=Y,s[9]=D}finalize(){let{h:e,pad:r}=this,n=new Uint16Array(10),o=e[1]>>>13;e[1]&=8191;for(let c=2;c<10;c++)e[c]+=o,o=e[c]>>>13,e[c]&=8191;e[0]+=o*5,o=e[0]>>>13,e[0]&=8191,e[1]+=o,o=e[1]>>>13,e[1]&=8191,e[2]+=o,n[0]=e[0]+5,o=n[0]>>>13,n[0]&=8191;for(let c=1;c<10;c++)n[c]=e[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++)e[c]=e[c]&s|n[c];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let i=e[0]+r[0];e[0]=i&65535;for(let c=1;c<8;c++)i=(e[c]+r[c]|0)+(i>>>16)|0,e[c]=i&65535;ge(n)}update(e){jt(this),X(e),e=je(e);let{buffer:r,blockLen:n}=this,o=e.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(e,s);continue}r.set(e.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(){ge(this.h,this.r,this.buffer,this.pad)}digestInto(e){jt(this),Dn(e,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++)e[s++]=n[i]>>>0,e[s++]=n[i]>>>8;return e}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}};function no(t){let e=(n,o)=>t(o).update(n).digest(),r=t(new Uint8Array(32));return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=n=>t(n),e}var Zn=no(t=>new zt(t));function Wn(t,e,r,n,o,s=20){let i=t[0],c=t[1],f=t[2],a=t[3],l=e[0],y=e[1],u=e[2],d=e[3],w=e[4],m=e[5],S=e[6],U=e[7],H=o,L=r[0],M=r[1],W=r[2],j=i,Z=c,G=f,T=a,C=l,k=y,I=u,x=d,p=w,h=m,g=S,E=U,A=H,b=L,B=M,R=W;for(let q=0;q<s;q+=2)j=j+C|0,A=v(A^j,16),p=p+A|0,C=v(C^p,12),j=j+C|0,A=v(A^j,8),p=p+A|0,C=v(C^p,7),Z=Z+k|0,b=v(b^Z,16),h=h+b|0,k=v(k^h,12),Z=Z+k|0,b=v(b^Z,8),h=h+b|0,k=v(k^h,7),G=G+I|0,B=v(B^G,16),g=g+B|0,I=v(I^g,12),G=G+I|0,B=v(B^G,8),g=g+B|0,I=v(I^g,7),T=T+x|0,R=v(R^T,16),E=E+R|0,x=v(x^E,12),T=T+x|0,R=v(R^T,8),E=E+R|0,x=v(x^E,7),j=j+k|0,R=v(R^j,16),g=g+R|0,k=v(k^g,12),j=j+k|0,R=v(R^j,8),g=g+R|0,k=v(k^g,7),Z=Z+I|0,A=v(A^Z,16),E=E+A|0,I=v(I^E,12),Z=Z+I|0,A=v(A^Z,8),E=E+A|0,I=v(I^E,7),G=G+x|0,b=v(b^G,16),p=p+b|0,x=v(x^p,12),G=G+x|0,b=v(b^G,8),p=p+b|0,x=v(x^p,7),T=T+C|0,B=v(B^T,16),h=h+B|0,C=v(C^h,12),T=T+C|0,B=v(B^T,8),h=h+B|0,C=v(C^h,7);let _=0;n[_++]=i+j|0,n[_++]=c+Z|0,n[_++]=f+G|0,n[_++]=a+T|0,n[_++]=l+C|0,n[_++]=y+k|0,n[_++]=u+I|0,n[_++]=d+x|0,n[_++]=w+p|0,n[_++]=m+h|0,n[_++]=S+g|0,n[_++]=U+E|0,n[_++]=H+A|0,n[_++]=L+b|0,n[_++]=M+B|0,n[_++]=W+R|0}function ro(t,e,r,n){let o=t[0],s=t[1],i=t[2],c=t[3],f=e[0],a=e[1],l=e[2],y=e[3],u=e[4],d=e[5],w=e[6],m=e[7],S=r[0],U=r[1],H=r[2],L=r[3];for(let W=0;W<20;W+=2)o=o+f|0,S=v(S^o,16),u=u+S|0,f=v(f^u,12),o=o+f|0,S=v(S^o,8),u=u+S|0,f=v(f^u,7),s=s+a|0,U=v(U^s,16),d=d+U|0,a=v(a^d,12),s=s+a|0,U=v(U^s,8),d=d+U|0,a=v(a^d,7),i=i+l|0,H=v(H^i,16),w=w+H|0,l=v(l^w,12),i=i+l|0,H=v(H^i,8),w=w+H|0,l=v(l^w,7),c=c+y|0,L=v(L^c,16),m=m+L|0,y=v(y^m,12),c=c+y|0,L=v(L^c,8),m=m+L|0,y=v(y^m,7),o=o+a|0,L=v(L^o,16),w=w+L|0,a=v(a^w,12),o=o+a|0,L=v(L^o,8),w=w+L|0,a=v(a^w,7),s=s+l|0,S=v(S^s,16),m=m+S|0,l=v(l^m,12),s=s+l|0,S=v(S^s,8),m=m+S|0,l=v(l^m,7),i=i+y|0,U=v(U^i,16),u=u+U|0,y=v(y^u,12),i=i+y|0,U=v(U^i,8),u=u+U|0,y=v(y^u,7),c=c+f|0,H=v(H^c,16),d=d+H|0,f=v(f^d,12),c=c+f|0,H=v(H^c,8),d=d+H|0,f=v(f^d,7);let M=0;n[M++]=o,n[M++]=s,n[M++]=i,n[M++]=c,n[M++]=S,n[M++]=U,n[M++]=H,n[M++]=L}var wt=Yt(Wn,{counterRight:!1,counterLength:4,allowShortKeys:!1}),oo=Yt(Wn,{counterRight:!1,counterLength:8,extendNonceFn:ro,allowShortKeys:!1});var so=new Uint8Array(16),Yn=(t,e)=>{t.update(e);let r=e.length%16;r&&t.update(so.subarray(r))},io=new Uint8Array(32);function zn(t,e,r,n,o){o!==void 0&&X(o,void 0,"AAD");let s=t(e,r,io),i=Mn(n.length,o?o.length:0,!0),c=Zn.create(s);o&&Yn(c,o),Yn(c,n),c.update(i);let f=c.digest();return ge(s,i),f}var Xn=t=>(e,r,n)=>({encrypt(s,i){let c=s.length;i=$t(c+16,i,!1),i.set(s);let f=i.subarray(0,-16);t(e,r,f,f,1);let a=zn(t,e,r,f,n);return i.set(a,c),ge(a),i},decrypt(s,i){i=$t(s.length-16,i,!1);let c=s.subarray(0,-16),f=s.subarray(-16),a=zn(t,e,r,c,n);if(!bt(f,a))throw new Error("invalid tag");return i.set(s.subarray(0,-16)),t(e,r,i,i,1),ge(a),i}}),ei=Gt({blockSize:64,nonceLength:12,tagLength:16},Xn(wt)),ti=Gt({blockSize:64,nonceLength:24,tagLength:16},Xn(oo));function Qn(t,e,r){return _e(t),r===void 0&&(r=new Uint8Array(t.outputLen)),he(t,Ee(r),Ee(e))}var Wt=Uint8Array.from([0]),Kn=Uint8Array.of();function Jn(t,e,r,n=32){_e(t),we(n);let o=t.outputLen;if(n>255*o)throw new Error("Length should be <= 255*HashLen");let s=Math.ceil(n/o);r===void 0&&(r=Kn);let i=new Uint8Array(s*o),c=he.create(t,e),f=c._cloneInto(),a=new Uint8Array(c.outputLen);for(let l=0;l<s;l++)Wt[0]=l+1,f.update(l===0?Kn:a).update(r).update(Wt).digestInto(a),i.set(a,o*l),c._cloneInto(f);return c.destroy(),f.destroy(),ue(a,Wt),i.slice(0,n)}function er(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function co(t){if(!er(t))throw new Error("Uint8Array expected")}function tr(t,e){return Array.isArray(e)?e.length===0?!0:t?e.every(r=>typeof r=="string"):e.every(r=>Number.isSafeInteger(r)):!1}function Xe(t,e){if(typeof e!="string")throw new Error(`${t}: string expected`);return!0}function Qt(t){if(!Number.isSafeInteger(t))throw new Error(`invalid integer: ${t}`)}function Kt(t){if(!Array.isArray(t))throw new Error("array expected")}function mt(t,e){if(!tr(!0,e))throw new Error(`${t}: array of strings expected`)}function fo(t,e){if(!tr(!1,e))throw new Error(`${t}: array of numbers expected`)}function ao(...t){let e=s=>s,r=(s,i)=>c=>s(i(c)),n=t.map(s=>s.encode).reduceRight(r,e),o=t.map(s=>s.decode).reduce(r,e);return{encode:n,decode:o}}function uo(t){let e=typeof t=="string"?t.split(""):t,r=e.length;mt("alphabet",e);let n=new Map(e.map((o,s)=>[o,s]));return{encode:o=>(Kt(o),o.map(s=>{if(!Number.isSafeInteger(s)||s<0||s>=r)throw new Error(`alphabet.encode: digit index outside alphabet "${s}". Allowed: ${t}`);return e[s]})),decode:o=>(Kt(o),o.map(s=>{Xe("alphabet.decode",s);let i=n.get(s);if(i===void 0)throw new Error(`Unknown letter: "${s}". Allowed: ${t}`);return i}))}}function lo(t=""){return Xe("join",t),{encode:e=>(mt("join.decode",e),e.join(t)),decode:e=>(Xe("join.decode",e),e.split(t))}}function ho(t,e="="){return Qt(t),Xe("padding",e),{encode(r){for(mt("padding.encode",r);r.length*t%8;)r.push(e);return r},decode(r){mt("padding.decode",r);let n=r.length;if(n*t%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;n>0&&r[n-1]===e;n--)if((n-1)*t%8===0)throw new Error("padding: invalid, string has too much padding");return r.slice(0,n)}}}var nr=(t,e)=>e===0?t:nr(e,t%e),Et=(t,e)=>t+(e-nr(t,e)),Xt=(()=>{let t=[];for(let e=0;e<40;e++)t.push(2**e);return t})();function Fn(t,e,r,n){if(Kt(t),e<=0||e>32)throw new Error(`convertRadix2: wrong from=${e}`);if(r<=0||r>32)throw new Error(`convertRadix2: wrong to=${r}`);if(Et(e,r)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${r} carryBits=${Et(e,r)}`);let o=0,s=0,i=Xt[e],c=Xt[r]-1,f=[];for(let a of t){if(Qt(a),a>=i)throw new Error(`convertRadix2: invalid data word=${a} from=${e}`);if(o=o<<e|a,s+e>32)throw new Error(`convertRadix2: carry overflow pos=${s} from=${e}`);for(s+=e;s>=r;s-=r)f.push((o>>s-r&c)>>>0);let l=Xt[s];if(l===void 0)throw new Error("invalid carry");o&=l-1}if(o=o<<r-s&c,!n&&s>=e)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 po(t,e=!1){if(Qt(t),t<=0||t>32)throw new Error("radix2: bits should be in (0..32]");if(Et(8,t)>32||Et(t,8)>32)throw new Error("radix2: carry overflow");return{encode:r=>{if(!er(r))throw new Error("radix2.encode input should be Uint8Array");return Fn(Array.from(r),8,t,!e)},decode:r=>(fo("radix2.decode",r),Uint8Array.from(Fn(r,t,8,e)))}}var yo=typeof Uint8Array.from([]).toBase64=="function"&&typeof Uint8Array.fromBase64=="function",xo=(t,e)=>{Xe("base64",t);let r=e?/^[A-Za-z0-9=_-]+$/:/^[A-Za-z0-9=+/]+$/,n=e?"base64url":"base64";if(t.length>0&&!r.test(t))throw new Error("invalid base64");return Uint8Array.fromBase64(t,{alphabet:n,lastChunkHandling:"strict"})},Jt=yo?{encode(t){return co(t),t.toBase64()},decode(t){return xo(t,!1)}}:ao(po(6),uo("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),ho(6),lo(""));var rr=new TextEncoder,bo=new TextDecoder,or=1,sr=65535;function ir(t){if(!Number.isSafeInteger(t)||t<1)throw new Error("expected positive integer");if(t<=32)return 32;let e=1<<Math.floor(Math.log2(t-1))+1,r=e<=256?32:e/8;return r*(Math.floor((t-1)/r)+1)}function go(t){let e=rr.encode(t),r=e.length;if(r<or||r>sr)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(ir(r)-r);return z(n,e,o)}function wo(t){let e=new DataView(t.buffer,t.byteOffset).getUint16(0,!1),r=t.subarray(2,2+e);if(e<or||e>sr||r.length!==e||t.length!==2+ir(e))throw new Error("invalid padding");return bo.decode(r)}function Ft(t,e){let n=ht.getSharedSecret(t,"02"+e).subarray(1,33);return Qn(Oe,n,rr.encode("nip44-v2"))}function cr(t,e){let r=Jn(Oe,t,e,76);return{chacha_key:r.subarray(0,32),chacha_nonce:r.subarray(32,44),hmac_key:r.subarray(44,76)}}function fr(t,e,r=ee(32)){let{chacha_key:n,chacha_nonce:o,hmac_key:s}=cr(e,r),i=go(t),c=wt(n,o,i),f=he(Oe,s,z(r,c));return Jt.encode(z(new Uint8Array([2]),r,c,f))}function ar(t,e){let r=Jt.decode(t),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:a}=cr(e,o),l=he(Oe,a,z(o,s));if(!bt(i,l))throw new Error("invalid MAC");let y=wt(c,f,s);return wo(y)}function ur(t){if(!t.startsWith("bunker://"))throw new Error("invalid bunker URI: must start with bunker://");let e=new URL(t.replace("bunker://","https://")),r=e.hostname;if(!/^[0-9a-f]{64}$/.test(r))throw new Error("invalid bunker URI: remote pubkey must be 64 hex characters");let n=e.searchParams.getAll("relay");if(n.length===0)throw new Error("invalid bunker URI: at least one relay is required");let o=e.searchParams.get("secret")||void 0;return{remotePubkey:r,relays:n,secret:o}}function mo(t,e,r){if(!/^[0-9a-f]{64}$/.test(t))throw new Error("remotePubkey must be 64 hex characters");if(e.length===0)throw new Error("at least one relay is required");let n=e.map(o=>`relay=${encodeURIComponent(o)}`);return r&&n.push(`secret=${encodeURIComponent(r)}`),`bunker://${t}?${n.join("&")}`}function Eo(t){try{return{isValid:!0,uri:ur(t)}}catch(e){return{isValid:!1,error:e.message}}}function Bo(t){if(!/^[0-9a-f]{64}$/.test(t))throw new Error("remotePubkey must be 64 hex characters");let e=ee(32),r=Le(e),n=pt.getPublicKey(e),o=Le(n),s=Ft(e,t);return{clientSecretKey:r,clientPubkey:o,remotePubkey:t,conversationKey:s}}function Ao(t,e){let r=Mt(t),n=pt.getPublicKey(r),o=Le(n),s=Ft(r,e);return{clientSecretKey:t,clientPubkey:o,remotePubkey:e,conversationKey:s}}function So(t){return{clientPubkey:t.clientPubkey,remotePubkey:t.remotePubkey}}function fe(t,e,r){return{id:r||Le(ee(16)),method:t,params:e}}function Ro(t,e,r){let n={id:t};return e!==void 0&&(n.result=e),r!==void 0&&(n.error=r),n}function lr(t){let e=JSON.parse(t);if(typeof e.id!="string")throw new Error("invalid NIP-46 payload: missing id");return e}function vo(t){return"method"in t&&"params"in t}function _o(t){return"result"in t||"error"in t}async function To(t,e,r){let n=JSON.stringify(t),o=fr(n,e.conversationKey),i={kind:24133,created_at:Math.floor(Date.now()/1e3),tags:[["p",r]],content:o,pubkey:e.clientPubkey},c=JSON.stringify([0,i.pubkey,i.created_at,i.kind,i.tags,i.content]),f=Oe(new TextEncoder().encode(c)),a=Mt(e.clientSecretKey),l=pt.sign(f,a);return{...i,id:Le(f),sig:Le(l)}}function Io(t,e){if(t.kind!==24133)throw new Error(`expected kind 24133, got ${t.kind}`);let r=ar(t.content,e.conversationKey);return lr(r)}function Uo(t,e,r){let n=[t];return e?n.push(e):r&&n.push(""),r&&n.push(r),fe("connect",n)}function Lo(){return fe("ping",[])}function Oo(){return fe("get_public_key",[])}function Ho(t){return fe("sign_event",[t])}function ko(t,e){return fe("nip04_encrypt",[t,e])}function No(t,e){return fe("nip04_decrypt",[t,e])}function Co(t,e){return fe("nip44_encrypt",[t,e])}function qo(t,e){return fe("nip44_decrypt",[t,e])}function Po(){return fe("get_relays",[])}function Do(t,e){let r={kinds:[24133],"#p":[t]};return e!==void 0&&(r.since=e),r}return gr(Vo);})();
2
+ /*! Bundled license information:
3
+
4
+ @noble/hashes/esm/utils.js:
5
+ (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
6
+
7
+ @noble/curves/esm/utils.js:
8
+ @noble/curves/esm/abstract/modular.js:
9
+ @noble/curves/esm/abstract/curve.js:
10
+ @noble/curves/esm/abstract/weierstrass.js:
11
+ @noble/curves/esm/_shortw_utils.js:
12
+ @noble/curves/esm/secp256k1.js:
13
+ (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
14
+
15
+ @noble/ciphers/utils.js:
16
+ (*! noble-ciphers - MIT License (c) 2023 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-46.nostr-crypto-utils.min.js.map