@libp2p/crypto 5.1.18 → 5.1.19-5e07d5963

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 (75) hide show
  1. package/dist/index.min.js +1 -1
  2. package/dist/index.min.js.map +4 -4
  3. package/dist/src/ciphers/aes-gcm.browser.d.ts.map +1 -1
  4. package/dist/src/ciphers/aes-gcm.browser.js +8 -7
  5. package/dist/src/ciphers/aes-gcm.browser.js.map +1 -1
  6. package/dist/src/hmac/index.browser.d.ts.map +1 -1
  7. package/dist/src/hmac/index.browser.js +4 -3
  8. package/dist/src/hmac/index.browser.js.map +1 -1
  9. package/dist/src/keys/ecdh/index.browser.d.ts +1 -1
  10. package/dist/src/keys/ecdh/index.browser.js +2 -2
  11. package/dist/src/keys/ecdh/index.d.ts +1 -1
  12. package/dist/src/keys/ecdsa/ecdsa.js +1 -1
  13. package/dist/src/keys/ecdsa/index.d.ts +1 -1
  14. package/dist/src/keys/ecdsa/index.d.ts.map +1 -1
  15. package/dist/src/keys/ecdsa/index.js +3 -2
  16. package/dist/src/keys/ecdsa/index.js.map +1 -1
  17. package/dist/src/keys/ecdsa/utils.d.ts +1 -1
  18. package/dist/src/keys/ecdsa/utils.js +1 -1
  19. package/dist/src/keys/ed25519/ed25519.js +1 -1
  20. package/dist/src/keys/ed25519/index.browser.d.ts +1 -1
  21. package/dist/src/keys/ed25519/index.browser.d.ts.map +1 -1
  22. package/dist/src/keys/ed25519/index.browser.js +4 -3
  23. package/dist/src/keys/ed25519/index.browser.js.map +1 -1
  24. package/dist/src/keys/ed25519/index.d.ts +1 -1
  25. package/dist/src/keys/key-stretcher.js +1 -1
  26. package/dist/src/keys/rsa/index.browser.d.ts +2 -2
  27. package/dist/src/keys/rsa/index.browser.d.ts.map +1 -1
  28. package/dist/src/keys/rsa/index.browser.js +5 -4
  29. package/dist/src/keys/rsa/index.browser.js.map +1 -1
  30. package/dist/src/keys/rsa/index.d.ts +2 -2
  31. package/dist/src/keys/rsa/index.js +1 -1
  32. package/dist/src/keys/rsa/utils.d.ts +1 -1
  33. package/dist/src/keys/rsa/utils.js +1 -1
  34. package/dist/src/keys/secp256k1/index.browser.js +2 -2
  35. package/dist/src/keys/secp256k1/index.js +1 -1
  36. package/dist/src/keys/secp256k1/secp256k1.js +1 -1
  37. package/dist/src/random-bytes.d.ts +2 -0
  38. package/dist/src/random-bytes.d.ts.map +1 -1
  39. package/dist/src/random-bytes.js +3 -2
  40. package/dist/src/random-bytes.js.map +1 -1
  41. package/dist/src/webcrypto/index.d.ts +4 -2
  42. package/dist/src/webcrypto/index.d.ts.map +1 -1
  43. package/dist/src/webcrypto/index.js +16 -2
  44. package/dist/src/webcrypto/index.js.map +1 -1
  45. package/package.json +9 -10
  46. package/src/ciphers/aes-gcm.browser.ts +8 -7
  47. package/src/hmac/index.browser.ts +4 -3
  48. package/src/keys/ecdh/index.browser.ts +3 -3
  49. package/src/keys/ecdh/index.ts +1 -1
  50. package/src/keys/ecdsa/ecdsa.ts +1 -1
  51. package/src/keys/ecdsa/index.ts +4 -3
  52. package/src/keys/ecdsa/utils.ts +2 -2
  53. package/src/keys/ed25519/ed25519.ts +1 -1
  54. package/src/keys/ed25519/index.browser.ts +5 -4
  55. package/src/keys/ed25519/index.ts +1 -1
  56. package/src/keys/key-stretcher.ts +1 -1
  57. package/src/keys/rsa/index.browser.ts +7 -6
  58. package/src/keys/rsa/index.ts +2 -2
  59. package/src/keys/rsa/utils.ts +2 -2
  60. package/src/keys/secp256k1/index.browser.ts +2 -2
  61. package/src/keys/secp256k1/index.ts +1 -1
  62. package/src/keys/secp256k1/secp256k1.ts +1 -1
  63. package/src/random-bytes.ts +3 -2
  64. package/src/webcrypto/index.ts +20 -2
  65. package/dist/src/webcrypto/webcrypto.browser.d.ts +0 -5
  66. package/dist/src/webcrypto/webcrypto.browser.d.ts.map +0 -1
  67. package/dist/src/webcrypto/webcrypto.browser.js +0 -18
  68. package/dist/src/webcrypto/webcrypto.browser.js.map +0 -1
  69. package/dist/src/webcrypto/webcrypto.d.ts +0 -6
  70. package/dist/src/webcrypto/webcrypto.d.ts.map +0 -1
  71. package/dist/src/webcrypto/webcrypto.js +0 -10
  72. package/dist/src/webcrypto/webcrypto.js.map +0 -1
  73. package/dist/typedoc-urls.json +0 -40
  74. package/src/webcrypto/webcrypto.browser.ts +0 -23
  75. package/src/webcrypto/webcrypto.ts +0 -11
package/dist/index.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PCrypto = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PCrypto=(()=>{var dn=Object.defineProperty;var Aa=Object.getOwnPropertyDescriptor;var va=Object.getOwnPropertyNames;var Ba=Object.prototype.hasOwnProperty;var it=(e,t)=>{for(var r in t)dn(e,r,{get:t[r],enumerable:!0})},_a=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of va(t))!Ba.call(e,o)&&o!==r&&dn(e,o,{get:()=>t[o],enumerable:!(n=Aa(t,o))||n.enumerable});return e};var Ia=e=>_a(dn({},"__esModule",{value:!0}),e);var xu={};it(xu,{hmac:()=>_r,keys:()=>Xo,pbkdf2:()=>Jo,randomBytes:()=>Uo});var _r={};it(_r,{create:()=>pn});var ze=class extends Error{constructor(t="An error occurred while signing a message"){super(t),this.name="SigningError"}},Ze=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Br=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var es={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Br("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var Y=es;var rs={SHA1:20,SHA256:32,SHA512:64};var Ta={SHA1:"SHA-1",SHA256:"SHA-256",SHA512:"SHA-512"},La=async(e,t)=>{let r=await Y.get().subtle.sign({name:"HMAC"},e,t);return new Uint8Array(r,0,r.byteLength)};async function pn(e,t){let r=Ta[e],n=await Y.get().subtle.importKey("raw",t,{name:"HMAC",hash:{name:r}},!1,["sign"]);return{async digest(o){return La(n,o)},length:rs[e]}}var Xo={};it(Xo,{generateEphemeralKeyPair:()=>ba,generateKeyPair:()=>ou,generateKeyPairFromSeed:()=>su,keyStretcher:()=>ga,privateKeyFromCryptoKeyPair:()=>mu,privateKeyFromProtobuf:()=>fu,privateKeyFromRaw:()=>uu,privateKeyToCryptoKeyPair:()=>pu,privateKeyToProtobuf:()=>lu,publicKeyFromMultihash:()=>cu,publicKeyFromProtobuf:()=>iu,publicKeyFromRaw:()=>au,publicKeyToProtobuf:()=>se});var k=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},xe=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}},Ye=class extends Error{static name="InvalidPrivateKeyError";constructor(t="Invalid private key"){super(t),this.name="InvalidPrivateKeyError"}};var qt=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var gn={};it(gn,{base58btc:()=>rt,base58flickr:()=>Oa});var Lu=new Uint8Array(0);function ns(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Ft(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function os(e){return new TextEncoder().encode(e)}function ss(e){return new TextDecoder().decode(e)}function Ra(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=e.length,f=e.charAt(0),c=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var E=0,d=0,y=0,S=m.length;y!==S&&m[y]===0;)y++,E++;for(var B=(S-y)*u+1>>>0,D=new Uint8Array(B);y!==S;){for(var L=m[y],U=0,K=B-1;(L!==0||U<d)&&K!==-1;K--,U++)L+=256*D[K]>>>0,D[K]=L%a>>>0,L=L/a>>>0;if(L!==0)throw new Error("Non-zero carry");d=U,y++}for(var I=B-d;I!==B&&D[I]===0;)I++;for(var F=f.repeat(E);I<B;++I)F+=e.charAt(D[I]);return F}function b(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var E=0;if(m[E]!==" "){for(var d=0,y=0;m[E]===f;)d++,E++;for(var S=(m.length-E)*c+1>>>0,B=new Uint8Array(S);m[E];){var D=r[m.charCodeAt(E)];if(D===255)return;for(var L=0,U=S-1;(D!==0||L<y)&&U!==-1;U--,L++)D+=a*B[U]>>>0,B[U]=D%256>>>0,D=D/256>>>0;if(D!==0)throw new Error("Non-zero carry");y=L,E++}if(m[E]!==" "){for(var K=S-y;K!==S&&B[K]===0;)K++;for(var I=new Uint8Array(d+(S-K)),F=d;K!==S;)I[F++]=B[K++];return I}}}function p(m){var E=b(m);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:b,decode:p}}var Da=Ra,Ka=Da,as=Ka;var mn=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},yn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return cs(this,t)}},bn=class{decoders;constructor(t){this.decoders=t}or(t){return cs(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function cs(e,t){return new bn({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var xn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new mn(t,r,n),this.decoder=new yn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ge({name:e,prefix:t,encode:r,decode:n}){return new xn(e,t,r,n)}function Vt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=as(r,e);return ge({prefix:t,name:e,encode:n,decode:s=>Ft(o(s))})}function Ca(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,f=0;for(let c=0;c<o;++c){let u=t[e[c]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,i+=r,i>=8&&(i-=8,s[f++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Ua(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let f=0;f<e.length;++f)for(a=a<<8|e[f],i+=8;i>r;)i-=r,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Fa(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function $({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Fa(n);return ge({prefix:t,name:e,encode(s){return Ua(s,n,r)},decode(s){return Ca(s,o,r,e)}})}var rt=Vt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Oa=Vt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var wn={};it(wn,{base32:()=>we,base32hex:()=>Ha,base32hexpad:()=>qa,base32hexpadupper:()=>Va,base32hexupper:()=>Ma,base32pad:()=>Pa,base32padupper:()=>Na,base32upper:()=>ka,base32z:()=>ja});var we=$({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ka=$({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Pa=$({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Na=$({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ha=$({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ma=$({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),qa=$({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Va=$({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ja=$({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var En={};it(En,{base36:()=>$e,base36upper:()=>za});var $e=Vt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),za=Vt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Za=ls,fs=128,Ya=127,$a=~Ya,Ga=Math.pow(2,31);function ls(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Ga;)t[r++]=e&255|fs,e/=128;for(;e&$a;)t[r++]=e&255|fs,e>>>=7;return t[r]=e|0,ls.bytes=r-n+1,t}var Xa=Sn,Wa=128,us=127;function Sn(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw Sn.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&us)<<o:(i&us)*Math.pow(2,o),o+=7}while(i>=Wa);return Sn.bytes=s-n,r}var Ja=Math.pow(2,7),Qa=Math.pow(2,14),tc=Math.pow(2,21),ec=Math.pow(2,28),rc=Math.pow(2,35),nc=Math.pow(2,42),oc=Math.pow(2,49),sc=Math.pow(2,56),ic=Math.pow(2,63),ac=function(e){return e<Ja?1:e<Qa?2:e<tc?3:e<ec?4:e<rc?5:e<nc?6:e<oc?7:e<sc?8:e<ic?9:10},cc={encode:Za,decode:Xa,encodingLength:ac},fc=cc,Ge=fc;function Xe(e,t=0){return[Ge.decode(e,t),Ge.decode.bytes]}function Ee(e,t,r=0){return Ge.encode(e,t,r),t}function Se(e){return Ge.encodingLength(e)}function Lt(e,t){let r=t.byteLength,n=Se(e),o=n+Se(r),s=new Uint8Array(o+r);return Ee(e,s,0),Ee(r,s,n),s.set(t,o),new Ae(e,r,t,s)}function hs(e){let t=Ft(e),[r,n]=Xe(t),[o,s]=Xe(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ae(r,o,i,t)}function ds(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&ns(e.bytes,r.bytes)}}var Ae=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function ps(e,t){let{bytes:r,version:n}=e;return n===0?lc(r,An(e),t??rt.encoder):hc(r,An(e),t??we.encoder)}var ms=new WeakMap;function An(e){let t=ms.get(e);if(t==null){let r=new Map;return ms.set(e,r),r}return t}var gt=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==Je)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==dc)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=Lt(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&ds(t.multihash,n.multihash)}toString(t){return ps(this,t)}toJSON(){return{"/":ps(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??ys(n,o,s.bytes))}else if(r[pc]===!0){let{version:n,multihash:o,code:s}=r,i=hs(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==Je)throw new Error(`Version 0 CID must use dag-pb (code: ${Je}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=ys(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Je,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Ft(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Ae(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,b]=Xe(t.subarray(r));return r+=b,l},o=n(),s=Je;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),f=n(),c=r+f,u=c-i;return{version:o,codec:s,multihashCode:a,digestSize:f,multihashSize:u,size:c}}static parse(t,r){let[n,o]=uc(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return An(s).set(n,t),s}};function uc(e,t){switch(e[0]){case"Q":{let r=t??rt;return[rt.prefix,r.decode(`${rt.prefix}${e}`)]}case rt.prefix:{let r=t??rt;return[rt.prefix,r.decode(e)]}case we.prefix:{let r=t??we;return[we.prefix,r.decode(e)]}case $e.prefix:{let r=t??$e;return[$e.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function lc(e,t,r){let{prefix:n}=r;if(n!==rt.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function hc(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var Je=112,dc=18;function ys(e,t,r){let n=Se(e),o=n+Se(t),s=new Uint8Array(o+r.byteLength);return Ee(e,s,0),Ee(t,s,n),s.set(r,o),s}var pc=Symbol.for("@ipld/js-cid/CID");var vn={};it(vn,{identity:()=>ne});var bs=0,mc="identity",xs=Ft;function yc(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Lt(bs,xs(e))}var ne={code:bs,name:mc,encode:xs,digest:yc};function at(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}var Bn="1.2.840.10045.3.1.7",_n="1.3.132.0.34",In="1.3.132.0.35";async function gs(e="P-256"){let t=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:e},!0,["sign","verify"]);return{publicKey:await crypto.subtle.exportKey("jwk",t.publicKey),privateKey:await crypto.subtle.exportKey("jwk",t.privateKey)}}async function ws(e,t,r){let n=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["sign"]);r?.signal?.throwIfAborted();let o=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},n,t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Es(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),s}function Ot(e=0){return new Uint8Array(e)}function mt(e=0){return new Uint8Array(e)}function Rt(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=mt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var As=Symbol.for("@achingbrain/uint8arraylist");function Ss(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function Tr(e){return!!e?.[As]}var ft=class e{bufs;length;[As]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Tr(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Tr(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=Ss(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Ss(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(Tr(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return Rt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Rt(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=n,s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,f=a+i.byteLength;if(o=f,t>=f)continue;let c=t>=a&&t<f,u=r>a&&r<=f;if(c&&u){if(t===a&&r===f){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(r-t)));break}if(c){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){if(r===f){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Tr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,f=this.byteLength-n.byteLength,c=n.byteLength-1,u;for(let l=r;l<=f;l+=u){u=0;for(let b=c;b>=0;b--){let p=this.get(l+b);if(n[b]!==p){u=Math.max(1,b-a[p]);break}}if(u===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=mt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=Ot(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=Ot(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=Ot(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=mt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=Ot(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=Ot(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=Ot(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=Ot(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=Ot(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!at(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var Tn={};it(Tn,{base10:()=>bc});var bc=Vt({prefix:"9",name:"base10",alphabet:"0123456789"});var Ln={};it(Ln,{base16:()=>xc,base16upper:()=>gc});var xc=$({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),gc=$({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Rn={};it(Rn,{base2:()=>wc});var wc=$({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Dn={};it(Dn,{base256emoji:()=>Bc});var vs=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Ec=vs.reduce((e,t,r)=>(e[r]=t,e),[]),Sc=vs.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Ac(e){return e.reduce((t,r)=>(t+=Ec[r],t),"")}function vc(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Sc[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Bc=ge({prefix:"\u{1F680}",name:"base256emoji",encode:Ac,decode:vc});var Cn={};it(Cn,{base64:()=>Kn,base64pad:()=>_c,base64url:()=>Ic,base64urlpad:()=>Tc});var Kn=$({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),_c=$({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ic=$({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Tc=$({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Un={};it(Un,{base8:()=>Lc});var Lc=$({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Fn={};it(Fn,{identity:()=>Rc});var Rc=ge({prefix:"\0",name:"identity",encode:e=>ss(e),decode:e=>os(e)});var dl=new TextEncoder,pl=new TextDecoder;var Pn={};it(Pn,{sha256:()=>Lr,sha512:()=>Uc});var Cc=20;function kn({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new On(e,t,r,n,o)}var On=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Cc,this.maxDigestLength=s}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Bs(n,this.code,r?.truncate):n.then(o=>Bs(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Bs(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Lt(t,e)}function Is(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Lr=kn({name:"sha2-256",code:18,encode:Is("SHA-256")}),Uc=kn({name:"sha2-512",code:19,encode:Is("SHA-512")});var Nn={...Fn,...Rn,...Un,...Tn,...Ln,...wn,...En,...gn,...Cn,...Dn},_l={...Pn,...vn};function Ls(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Ts=Ls("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Hn=Ls("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=mt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Fc={utf8:Ts,"utf-8":Ts,hex:Nn.base16,latin1:Hn,ascii:Hn,binary:Hn,...Nn},Rr=Fc;function z(e,t="utf8"){let r=Rr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function M(e,t="utf8"){let r=Rr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Oc=parseInt("11111",2),Mn=parseInt("10000000",2),kc=parseInt("01111111",2),Rs={0:Qe,1:Qe,2:Pc,3:Mc,4:qc,5:Hc,6:Nc,16:Qe,22:Qe,48:Qe};function yt(e,t={offset:0}){let r=e[t.offset]&Oc;if(t.offset++,Rs[r]!=null)return Rs[r](e,t);throw new Error("No decoder for tag "+r)}function tr(e,t){let r=0;if((e[t.offset]&Mn)===Mn){let n=e[t.offset]&kc,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function Qe(e,t){tr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=yt(e,t);if(n===null)break;r.push(n)}return r}function Pc(e,t){let r=tr(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function Nc(e,t){let r=tr(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,f=[];for(;t.offset<n;){let c=e[t.offset];if(t.offset++,f.push(c&127),c<128){f.reverse();let u=0;for(let l=0;l<f.length;l++)u+=f[l]<<l*7;a+=`.${u}`,f=[]}}return a}function Hc(e,t){return t.offset++,null}function Mc(e,t){let r=tr(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function qc(e,t){let r=tr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Vc(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new ft;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Dr(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Vc(e.byteLength);return new ft(Uint8Array.from([t.byteLength|Mn]),t)}function ut(e){let t=new ft,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new ft(Uint8Array.from([2]),Dr(t),t)}function er(e){let t=Uint8Array.from([0]),r=new ft(t,e);return new ft(Uint8Array.from([3]),Dr(r),r)}function Ds(e){return new ft(Uint8Array.from([4]),Dr(e),e)}function Et(e,t=48){let r=new ft;for(let n of e)r.append(n);return new ft(Uint8Array.from([t]),Dr(r),r)}var jc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),zc=Uint8Array.from([6,5,43,129,4,0,34]),Zc=Uint8Array.from([6,5,43,129,4,0,35]),Ks={ext:!0,kty:"EC",crv:"P-256"},Cs={ext:!0,kty:"EC",crv:"P-384"},Us={ext:!0,kty:"EC",crv:"P-521"},ve=32,Be=48,_e=66;function Fs(e){let t=yt(e);return qn(t)}function qn(e){let t=e[1],r=M(t,"base64url"),n=e[2][1][0],o=1,s,i;if(t.byteLength===ve)return s=M(n.subarray(o,o+ve),"base64url"),i=M(n.subarray(o+ve),"base64url"),new kt({...Ks,key_ops:["sign"],d:r,x:s,y:i});if(t.byteLength===Be)return s=M(n.subarray(o,o+Be),"base64url"),i=M(n.subarray(o+Be),"base64url"),new kt({...Cs,key_ops:["sign"],d:r,x:s,y:i});if(t.byteLength===_e)return s=M(n.subarray(o,o+_e),"base64url"),i=M(n.subarray(o+_e),"base64url"),new kt({...Us,key_ops:["sign"],d:r,x:s,y:i});throw new k(`Private key length was wrong length, got ${t.byteLength}, expected 32, 48 or 66`)}function Vn(e){let t=yt(e);return jn(t)}function jn(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===ve*2+1)return n=M(t.subarray(r,r+ve),"base64url"),o=M(t.subarray(r+ve),"base64url"),new oe({...Ks,key_ops:["verify"],x:n,y:o});if(t.byteLength===Be*2+1)return n=M(t.subarray(r,r+Be),"base64url"),o=M(t.subarray(r+Be),"base64url"),new oe({...Cs,key_ops:["verify"],x:n,y:o});if(t.byteLength===_e*2+1)return n=M(t.subarray(r,r+_e),"base64url"),o=M(t.subarray(r+_e),"base64url"),new oe({...Us,key_ops:["verify"],x:n,y:o});throw new k(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Os(e){return Et([ut(Uint8Array.from([1])),Ds(z(e.d??"","base64url")),Et([Ps(e.crv)],160),Et([er(new ft(Uint8Array.from([4]),z(e.x??"","base64url"),z(e.y??"","base64url")))],161)]).subarray()}function ks(e){return Et([ut(Uint8Array.from([1])),Et([Ps(e.crv)],160),Et([er(new ft(Uint8Array.from([4]),z(e.x??"","base64url"),z(e.y??"","base64url")))],161)]).subarray()}function Ps(e){if(e==="P-256")return jc;if(e==="P-384")return zc;if(e==="P-521")return Zc;throw new k(`Invalid curve ${e}`)}async function Ns(e="P-256"){let t=await gs(e);return new kt(t.privateKey)}var oe=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=ks(this.jwk)),this._raw}toMultihash(){return ne.digest(se(this))}toCID(){return gt.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}async verify(t,r,n){return Es(this.jwk,r,t,n)}},kt=class{type="ECDSA";jwk;publicKey;_raw;constructor(t){this.jwk=t,this.publicKey=new oe({crv:t.crv,ext:t.ext,key_ops:["verify"],kty:"EC",x:t.x,y:t.y})}get raw(){return this._raw==null&&(this._raw=Os(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}async sign(t,r){return ws(this.jwk,t,r)}};function zn(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}function wt(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(`${r}expected number, got ${typeof e}`)}if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new RangeError(`${r}expected integer >= 0, got ${e}`)}}function dt(e,t,r=""){let n=zn(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,a=s?` of length ${t}`:"",f=n?`length=${o}`:`type=${typeof e}`,c=i+"expected Uint8Array"+a+", got "+f;throw n?new RangeError(c):new TypeError(c)}return e}function Ie(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(wt(e.outputLen),wt(e.blockLen),e.outputLen<1)throw new Error('"outputLen" must be >= 1');if(e.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Te(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 Kr(e,t){dt(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function pt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Le(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function St(e,t){return e<<32-t|e>>>t}function Cr(e,t){return e<<t|e>>>32-t>>>0}var Ms=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Yc=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Ur(e){if(dt(e),Ms)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Yc[e[r]];return t}var Pt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Hs(e){if(e>=Pt._0&&e<=Pt._9)return e-Pt._0;if(e>=Pt.A&&e<=Pt.F)return e-(Pt.A-10);if(e>=Pt.a&&e<=Pt.f)return e-(Pt.a-10)}function rr(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(Ms)try{return Uint8Array.fromHex(e)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let t=e.length,r=t/2;if(t%2)throw new RangeError("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=Hs(e.charCodeAt(s)),a=Hs(e.charCodeAt(s+1));if(i===void 0||a===void 0){let f=e[s]+e[s+1];throw new RangeError('hex string expected, got non-hex character "'+f+'" at index '+s)}n[o]=i*16+a}return n}function $c(e){if(typeof e!="string")throw new TypeError("string expected");return new Uint8Array(new TextEncoder().encode(e))}function Zn(e,t=""){return typeof e=="string"?$c(e):dt(e,void 0,t)}function Yn(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];dt(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}function qs(e,t){if(t!==void 0&&{}.toString.call(t)!=="[object Object]")throw new TypeError("options must be object or undefined");return Object.assign(e,t)}function nr(e,t={}){let r=(o,s)=>e(s).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function Fr(e=32){wt(e,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(e>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}var $n=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function Or(e,t,r){return e&t^~e&r}function kr(e,t,r){return e&t^e&r^t&r}var ie=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,o){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Le(this.buffer)}update(t){Te(this),dt(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let f=Le(t);for(;o<=s-i;i+=o)this.process(f,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Te(this),Kr(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,pt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=Le(t),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let c=f/4,u=this.get();if(c>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<c;l++)a.setUint32(4*l,u[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Nt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ot=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Pr=BigInt(4294967295),Vs=BigInt(32);function Gc(e,t=!1){return t?{h:Number(e&Pr),l:Number(e>>Vs&Pr)}:{h:Number(e>>Vs&Pr)|0,l:Number(e&Pr)|0}}function js(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=Gc(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Gn=(e,t,r)=>e>>>r,Xn=(e,t,r)=>e<<32-r|t>>>r,ae=(e,t,r)=>e>>>r|t<<32-r,ce=(e,t,r)=>e<<32-r|t>>>r,or=(e,t,r)=>e<<64-r|t>>>r-32,sr=(e,t,r)=>e>>>r-32|t<<64-r;function Dt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var zs=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Zs=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Ys=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),$s=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Gs=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Xs=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var Wc=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]),jt=new Uint32Array(64),Wn=class extends ie{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:f}=this;return[t,r,n,o,s,i,a,f]}set(t,r,n,o,s,i,a,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=a|0,this.H=f|0}process(t,r){for(let l=0;l<16;l++,r+=4)jt[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let b=jt[l-15],p=jt[l-2],m=St(b,7)^St(b,18)^b>>>3,E=St(p,17)^St(p,19)^p>>>10;jt[l]=E+jt[l-7]+m+jt[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:f,G:c,H:u}=this;for(let l=0;l<64;l++){let b=St(a,6)^St(a,11)^St(a,25),p=u+b+Or(a,f,c)+Wc[l]+jt[l]|0,E=(St(n,2)^St(n,13)^St(n,22))+kr(n,o,s)|0;u=c,c=f,f=a,a=i+p|0,i=s,s=o,o=n,n=p+E|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,f=f+this.F|0,c=c+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,f,c,u)}roundClean(){pt(jt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),pt(this.buffer)}},Jn=class extends Wn{A=Nt[0]|0;B=Nt[1]|0;C=Nt[2]|0;D=Nt[3]|0;E=Nt[4]|0;F=Nt[5]|0;G=Nt[6]|0;H=Nt[7]|0;constructor(){super(32)}};var Ws=js(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),Jc=Ws[0],Qc=Ws[1],zt=new Uint32Array(80),Zt=new Uint32Array(80),Qn=class extends ie{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:f,Eh:c,El:u,Fh:l,Fl:b,Gh:p,Gl:m,Hh:E,Hl:d}=this;return[t,r,n,o,s,i,a,f,c,u,l,b,p,m,E,d]}set(t,r,n,o,s,i,a,f,c,u,l,b,p,m,E,d){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=f|0,this.Eh=c|0,this.El=u|0,this.Fh=l|0,this.Fl=b|0,this.Gh=p|0,this.Gl=m|0,this.Hh=E|0,this.Hl=d|0}process(t,r){for(let B=0;B<16;B++,r+=4)zt[B]=t.getUint32(r),Zt[B]=t.getUint32(r+=4);for(let B=16;B<80;B++){let D=zt[B-15]|0,L=Zt[B-15]|0,U=ae(D,L,1)^ae(D,L,8)^Gn(D,L,7),K=ce(D,L,1)^ce(D,L,8)^Xn(D,L,7),I=zt[B-2]|0,F=Zt[B-2]|0,V=ae(I,F,19)^or(I,F,61)^Gn(I,F,6),O=ce(I,F,19)^sr(I,F,61)^Xn(I,F,6),h=Ys(K,O,Zt[B-7],Zt[B-16]),x=$s(h,U,V,zt[B-7],zt[B-16]);zt[B]=x|0,Zt[B]=h|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:f,Dh:c,Dl:u,Eh:l,El:b,Fh:p,Fl:m,Gh:E,Gl:d,Hh:y,Hl:S}=this;for(let B=0;B<80;B++){let D=ae(l,b,14)^ae(l,b,18)^or(l,b,41),L=ce(l,b,14)^ce(l,b,18)^sr(l,b,41),U=l&p^~l&E,K=b&m^~b&d,I=Gs(S,L,K,Qc[B],Zt[B]),F=Xs(I,y,D,U,Jc[B],zt[B]),V=I|0,O=ae(n,o,28)^or(n,o,34)^or(n,o,39),h=ce(n,o,28)^sr(n,o,34)^sr(n,o,39),x=n&s^n&a^s&a,A=o&i^o&f^i&f;y=E|0,S=d|0,E=p|0,d=m|0,p=l|0,m=b|0,{h:l,l:b}=Dt(c|0,u|0,F|0,V|0),c=a|0,u=f|0,a=s|0,f=i|0,s=n|0,i=o|0;let w=zs(V,h,A);n=Zs(w,F,O,x),o=w|0}({h:n,l:o}=Dt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Dt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:f}=Dt(this.Ch|0,this.Cl|0,a|0,f|0),{h:c,l:u}=Dt(this.Dh|0,this.Dl|0,c|0,u|0),{h:l,l:b}=Dt(this.Eh|0,this.El|0,l|0,b|0),{h:p,l:m}=Dt(this.Fh|0,this.Fl|0,p|0,m|0),{h:E,l:d}=Dt(this.Gh|0,this.Gl|0,E|0,d|0),{h:y,l:S}=Dt(this.Hh|0,this.Hl|0,y|0,S|0),this.set(n,o,s,i,a,f,c,u,l,b,p,m,E,d,y,S)}roundClean(){pt(zt,Zt)}destroy(){this.destroyed=!0,pt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},to=class extends Qn{Ah=ot[0]|0;Al=ot[1]|0;Bh=ot[2]|0;Bl=ot[3]|0;Ch=ot[4]|0;Cl=ot[5]|0;Dh=ot[6]|0;Dl=ot[7]|0;Eh=ot[8]|0;El=ot[9]|0;Fh=ot[10]|0;Fl=ot[11]|0;Gh=ot[12]|0;Gl=ot[13]|0;Hh=ot[14]|0;Hl=ot[15]|0;constructor(){super(64)}};var Yt=nr(()=>new Jn,$n(1));var Re=nr(()=>new to,$n(3));var H=(e,t,r)=>dt(e,t,r),ro=wt,De=Ur,Q=(...e)=>Yn(...e),Ke=e=>rr(e),fe=zn,ir=e=>Fr(e),Hr=BigInt(0),eo=BigInt(1);function At(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new TypeError(r+"expected boolean, got type="+typeof e)}return e}function Mr(e){if(typeof e=="bigint"){if(!Nr(e))throw new RangeError("positive bigint expected, got "+e)}else ro(e);return e}function vt(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(r+"expected number, got type="+typeof e)}if(!Number.isSafeInteger(e)){let r=t&&`"${t}" `;throw new RangeError(r+"expected safe integer, got "+e)}}function ar(e){let t=Mr(e).toString(16);return t.length&1?"0"+t:t}function Js(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?Hr:BigInt("0x"+e)}function ue(e){return Js(Ur(e))}function Kt(e){return Js(Ur(cr(dt(e)).reverse()))}function qr(e,t){if(wt(t),t===0)throw new RangeError("zero length");e=Mr(e);let r=e.toString(16);if(r.length>t*2)throw new RangeError("number too large");return rr(r.padStart(t*2,"0"))}function no(e,t){return qr(e,t).reverse()}function Qs(e,t){if(e=H(e),t=H(t),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}function cr(e){return Uint8Array.from(H(e))}function Vr(e){if(typeof e!="string")throw new TypeError("ascii string expected, got "+typeof e);return Uint8Array.from(e,(t,r)=>{let n=t.charCodeAt(0);if(t.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${e[r]}" with code ${n} at position ${r}`);return n})}var Nr=e=>typeof e=="bigint"&&Hr<=e;function tf(e,t,r){return Nr(e)&&Nr(t)&&Nr(r)&&t<=e&&e<r}function Ce(e,t,r,n){if(!tf(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Ue(e){if(e<Hr)throw new Error("expected non-negative bigint, got "+e);let t;for(t=0;e>Hr;e>>=eo,t+=1);return t}var fr=e=>(eo<<BigInt(e))-eo;function ti(e,t,r){if(wt(e,"hashLen"),wt(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=d=>new Uint8Array(d),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,f=n(e),c=n(e),u=0,l=()=>{f.fill(1),c.fill(0),u=0},b=(...d)=>r(c,Q(f,...d)),p=(d=o)=>{c=b(s,d),f=b(),d.length!==0&&(c=b(i,d),f=b())},m=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let d=0,y=[];for(;d<t;){f=b();let S=f.slice();y.push(S),d+=f.length}return Q(...y)};return(d,y)=>{l(),p(d);let S;for(;(S=y(m()))===void 0;)p();return l(),S}}function Bt(e,t={},r={}){if(Object.prototype.toString.call(e)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,i,a){if(!a&&i!=="function"&&!Object.hasOwn(e,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let f=e[s];if(a&&f===void 0)return;let c=typeof f;if(c!==i||f===null)throw new TypeError(`param "${s}" is invalid: expected ${i}, got ${c}`)}let o=(s,i)=>Object.entries(s).forEach(([a,f])=>n(a,f,i));o(t,!1),o(r,!0)}var oo=()=>{throw new Error("not implemented")};var st=BigInt(0),G=BigInt(1),le=BigInt(2),oi=BigInt(3),si=BigInt(4),ii=BigInt(5),ef=BigInt(7),ai=BigInt(8),rf=BigInt(9),ci=BigInt(16);function W(e,t){if(t<=st)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=st?r:t+r}function Z(e,t,r){if(t<st)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >st;)n*=n,n%=r;return n}function ei(e,t){if(e===st)throw new Error("invert: expected non-zero number");if(t<=st)throw new Error("invert: expected positive modulus, got "+t);let r=W(e,t),n=t,o=st,s=G,i=G,a=st;for(;r!==st;){let c=n/r,u=n-r*c,l=o-i*c,b=s-a*c;n=r,r=u,o=i,s=a,i=l,a=b}if(n!==G)throw new Error("invert: does not exist");return W(o,t)}function so(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function fi(e,t){let r=e,n=(r.ORDER+G)/si,o=r.pow(t,n);return so(r,o,t),o}function nf(e,t){let r=e,n=(r.ORDER-ii)/ai,o=r.mul(t,le),s=r.pow(o,n),i=r.mul(t,s),a=r.mul(r.mul(i,le),s),f=r.mul(i,r.sub(a,r.ONE));return so(r,f,t),f}function of(e){let t=Fe(e),r=ui(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+ef)/ci;return((a,f)=>{let c=a,u=c.pow(f,i),l=c.mul(u,n),b=c.mul(u,o),p=c.mul(u,s),m=c.eql(c.sqr(l),f),E=c.eql(c.sqr(b),f);u=c.cmov(u,l,m),l=c.cmov(p,b,E);let d=c.eql(c.sqr(l),f),y=c.cmov(u,l,d);return so(c,y,f),y})}function ui(e){if(e<oi)throw new Error("sqrt is not defined for small field");let t=e-G,r=0;for(;t%le===st;)t/=le,r++;let n=le,o=Fe(e);for(;ri(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return fi;let s=o.pow(n,t),i=(t+G)/le;return function(f,c){let u=f;if(u.is0(c))return c;if(ri(u,c)!==1)throw new Error("Cannot find square root");let l=r,b=u.mul(u.ONE,s),p=u.pow(c,t),m=u.pow(c,i);for(;!u.eql(p,u.ONE);){if(u.is0(p))return u.ZERO;let E=1,d=u.sqr(p);for(;!u.eql(d,u.ONE);)if(E++,d=u.sqr(d),E===l)throw new Error("Cannot find square root");let y=G<<BigInt(l-E-1),S=u.pow(b,y);l=E,b=u.sqr(S),p=u.mul(p,b),m=u.mul(m,S)}return m}}function sf(e){return e%si===oi?fi:e%ai===ii?nf:e%ci===rf?of(e):ui(e)}var Ht=(e,t)=>(W(e,t)&G)===G,af=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function io(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=af.reduce((n,o)=>(n[o]="function",n),t);if(Bt(e,r),vt(e.BYTES,"BYTES"),vt(e.BITS,"BITS"),e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=G)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function cf(e,t,r){let n=e;if(r<st)throw new Error("invalid exponent, negatives unsupported");if(r===st)return n.ONE;if(r===G)return t;let o=n.ONE,s=t;for(;r>st;)r&G&&(o=n.mul(o,s)),s=n.sqr(s),r>>=G;return o}function ur(e,t,r=!1){let n=e,o=new Array(t.length).fill(r?n.ZERO:void 0),s=t.reduce((a,f,c)=>n.is0(f)?a:(o[c]=a,n.mul(a,f)),n.ONE),i=n.inv(s);return t.reduceRight((a,f,c)=>n.is0(f)?a:(o[c]=n.mul(a,o[c]),n.mul(a,f)),i),o}function ri(e,t){let r=e,n=(r.ORDER-G)/le,o=r.pow(t,n),s=r.eql(o,r.ONE),i=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function ff(e,t){if(t!==void 0&&ro(t),e<=st)throw new Error("invalid n length: expected positive n, got "+e);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let r=Ue(e);if(t!==void 0&&t<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${t})`);let n=t!==void 0?t:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var ni=new WeakMap,jr=class{ORDER;BITS;BYTES;isLE;ZERO=st;ONE=G;_lengths;_mod;constructor(t,r={}){if(t<=G)throw new Error("invalid field: expected ORDER > 1, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=ff(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(t){return W(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return st<=t&&t<this.ORDER}is0(t){return t===st}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&G)===G}neg(t){return W(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return W(t*t,this.ORDER)}add(t,r){return W(t+r,this.ORDER)}sub(t,r){return W(t-r,this.ORDER)}mul(t,r){return W(t*r,this.ORDER)}pow(t,r){return cf(this,t,r)}div(t,r){return W(t*ei(r,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,r){return t+r}subN(t,r){return t-r}mulN(t,r){return t*r}inv(t){return ei(t,this.ORDER)}sqrt(t){let r=ni.get(this);return r||ni.set(this,r=sf(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?no(t,this.BYTES):qr(t,this.BYTES)}fromBytes(t,r=!1){H(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(t.length<1||!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let c=new Uint8Array(o);c.set(t,s?0:c.length-t.length),t=c}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let f=s?Kt(t):ue(t);if(a&&(f=W(f,i)),!r&&!this.isValid(f))throw new Error("invalid field element: outside of range 0..ORDER");return f}invertBatch(t){return ur(this,t)}cmov(t,r,n){return At(n,"condition"),n?r:t}};Object.freeze(jr.prototype);function Fe(e,t={}){return new jr(e,t)}function li(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=G)throw new Error("field order must be greater than 1");let t=Ue(e-G);return Math.ceil(t/8)}function ao(e){let t=li(e);return t+Math.ceil(t/2)}function co(e,t,r=!1){H(e);let n=e.length,o=li(t),s=Math.max(ao(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Kt(e):ue(e),a=W(i,t-G)+G;return r?no(a,o):qr(a,o)}var Oe=BigInt(0),he=BigInt(1);function lr(e,t){let r=t.negate();return e?r:t}function de(e,t){let r=ur(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function mi(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function fo(e,t){mi(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=fr(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function hi(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(e&o),f=e>>i;a>n&&(a-=s,f+=he);let c=t*n,u=c+Math.abs(a)-1,l=a===0,b=a<0,p=t%2!==0;return{nextN:f,offset:u,isZero:l,isNeg:b,isNegF:p,offsetF:c}}var uo=new WeakMap,yi=new WeakMap;function lo(e){return yi.get(e)||1}function di(e){if(e!==Oe)throw new Error("invalid wNAF")}var ke=class{BASE;ZERO;Fn;bits;constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>Oe;)r&he&&(n=n.add(o)),o=o.double(),r>>=he;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=fo(r,this.bits),s=[],i=t,a=i;for(let f=0;f<n;f++){a=i,s.push(a);for(let c=1;c<o;c++)a=a.add(i),s.push(a);i=a.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=fo(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:f,offset:c,isZero:u,isNeg:l,isNegF:b,offsetF:p}=hi(n,a,i);n=f,u?s=s.add(lr(b,r[p])):o=o.add(lr(l,r[c]))}return di(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=fo(t,this.bits);for(let i=0;i<s.windows&&n!==Oe;i++){let{nextN:a,offset:f,isZero:c,isNeg:u}=hi(n,i,s);if(n=a,!c){let l=r[f];o=o.add(u?l.negate():l)}}return di(n),o}getPrecomputes(t,r,n){let o=uo.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),uo.set(r,o))),o}cached(t,r,n){let o=lo(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=lo(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){mi(r,this.bits),yi.set(t,r),uo.delete(t)}hasCache(t){return lo(t)!==1}};function bi(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Oe||n>Oe;)r&he&&(s=s.add(o)),n&he&&(i=i.add(o)),o=o.double(),r>>=he,n>>=he;return{p1:s,p2:i}}function pi(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return io(t),t}else return Fe(e,{isLE:r})}function zr(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 c=t[f];if(!(typeof c=="bigint"&&c>Oe))throw new Error(`CURVE.${f} must be positive bigint`)}let o=pi(t.p,r.Fp,n),s=pi(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let f of a)if(!o.isValid(t[f]))throw new Error(`CURVE.${f} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function Zr(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var $t=BigInt(0),nt=BigInt(1),ho=BigInt(2),uf=BigInt(8);function lf(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),a=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,a)}function xi(e,t={}){let r=t,n=zr("edwards",e,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;Bt(r,{},{uvRatio:"function"});let f=ho<<BigInt(s.BYTES*8)-nt,c=E=>o.create(E),u=r.uvRatio===void 0?(E,d)=>{try{return{isValid:!0,value:o.sqrt(o.div(E,d))}}catch{return{isValid:!1,value:$t}}}:r.uvRatio;if(!lf(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function l(E,d,y=!1){let S=y?nt:$t;return Ce("coordinate "+E,d,S,f),d}function b(E){if(!(E instanceof p))throw new Error("EdwardsPoint expected")}class p{static BASE=new p(i.Gx,i.Gy,nt,c(i.Gx*i.Gy));static ZERO=new p($t,nt,nt,$t);static Fp=o;static Fn=s;X;Y;Z;T;constructor(d,y,S,B){this.X=l("x",d),this.Y=l("y",y),this.Z=l("z",S,!0),this.T=l("t",B),Object.freeze(this)}static CURVE(){return i}static fromAffine(d){if(d instanceof p)throw new Error("extended point not allowed");let{x:y,y:S}=d||{};return l("x",y),l("y",S),new p(y,S,nt,c(y*S))}static fromBytes(d,y=!1){let S=o.BYTES,{a:B,d:D}=i;d=cr(H(d,S,"point")),At(y,"zip215");let L=cr(d),U=d[S-1];L[S-1]=U&-129;let K=Kt(L),I=y?f:o.ORDER;Ce("point.y",K,$t,I);let F=c(K*K),V=c(F-nt),O=c(D*F-B),{isValid:h,value:x}=u(V,O);if(!h)throw new Error("bad point: invalid y coordinate");let A=(x&nt)===nt,w=(U&128)!==0;if(!y&&x===$t&&w)throw new Error("bad point: x=0 and x_0=1");return w!==A&&(x=c(-x)),p.fromAffine({x,y:K})}static fromHex(d,y=!1){return p.fromBytes(Ke(d),y)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(d=8,y=!0){return m.createCache(this,d),y||this.multiply(ho),this}assertValidity(){let d=this,{a:y,d:S}=i;if(d.is0())throw new Error("bad point: ZERO");let{X:B,Y:D,Z:L,T:U}=d,K=c(B*B),I=c(D*D),F=c(L*L),V=c(F*F),O=c(K*y),h=c(F*c(O+I)),x=c(V+c(S*c(K*I)));if(h!==x)throw new Error("bad point: equation left != right (1)");let A=c(B*D),w=c(L*U);if(A!==w)throw new Error("bad point: equation left != right (2)")}equals(d){b(d);let{X:y,Y:S,Z:B}=this,{X:D,Y:L,Z:U}=d,K=c(y*U),I=c(D*B),F=c(S*U),V=c(L*B);return K===I&&F===V}is0(){return this.equals(p.ZERO)}negate(){return new p(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:d}=i,{X:y,Y:S,Z:B}=this,D=c(y*y),L=c(S*S),U=c(ho*c(B*B)),K=c(d*D),I=y+S,F=c(c(I*I)-D-L),V=K+L,O=V-U,h=K-L,x=c(F*O),A=c(V*h),w=c(F*h),g=c(O*V);return new p(x,A,g,w)}add(d){b(d);let{a:y,d:S}=i,{X:B,Y:D,Z:L,T:U}=this,{X:K,Y:I,Z:F,T:V}=d,O=c(B*K),h=c(D*I),x=c(U*S*V),A=c(L*F),w=c((B+D)*(K+I)-O-h),g=A-x,v=A+x,T=c(h-y*O),_=c(w*g),R=c(v*T),C=c(w*T),N=c(g*v);return new p(_,R,N,C)}subtract(d){return b(d),this.add(d.negate())}multiply(d){if(!s.isValidNot0(d))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:y,f:S}=m.cached(this,d,B=>de(p,B));return de(p,[y,S])[0]}multiplyUnsafe(d){if(!s.isValid(d))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return d===$t?p.ZERO:this.is0()||d===nt?this:m.unsafe(this,d,y=>de(p,y))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return m.unsafe(this,i.n).is0()}toAffine(d){let y=this,S=d,{X:B,Y:D,Z:L}=y,U=y.is0();S==null&&(S=U?uf:o.inv(L));let K=c(B*S),I=c(D*S),F=o.mul(L,S);if(U)return{x:$t,y:nt};if(F!==nt)throw new Error("invZ was invalid");return{x:K,y:I}}clearCofactor(){return a===nt?this:this.multiplyUnsafe(a)}toBytes(){let{x:d,y}=this.toAffine(),S=o.toBytes(y);return S[S.length-1]|=d&nt?128:0,S}toHex(){return De(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let m=new ke(p,s.BITS);return s.BITS>=8&&p.BASE.precompute(8),Object.freeze(p.prototype),Object.freeze(p),p}var Yr=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(t){this.ep=t}static fromBytes(t){oo()}static fromHex(t){oo()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return De(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.ep.precompute(t,r),this}};function gi(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=r;Bt(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:f}=e,c=n.outputLen,u=2*a.BYTES;if(c!==void 0&&(vt(c,"hash.outputLen"),c!==u))throw new Error(`hash.outputLen must be ${u}, got ${c}`);let l=o.randomBytes===void 0?ir:o.randomBytes,b=o.adjustScalarBytes===void 0?h=>h:o.adjustScalarBytes,p=o.domain===void 0?(h,x,A)=>{if(At(A,"phflag"),x.length||A)throw new Error("Contexts/pre-hash are not supported");return h}:o.domain;function m(h){return f.create(Kt(h))}function E(h){let x=K.secretKey;H(h,K.secretKey,"secretKey");let A=H(n(h),2*x,"hashedSecretKey"),w=b(A.slice(0,x)),g=A.slice(x,2*x),v=m(w);return{head:w,prefix:g,scalar:v}}function d(h){let{head:x,prefix:A,scalar:w}=E(h),g=i.multiply(w),v=g.toBytes();return{head:x,prefix:A,scalar:w,point:g,pointBytes:v}}function y(h){return d(h).pointBytes}function S(h=Uint8Array.of(),...x){let A=Q(...x);return m(n(p(A,H(h,void 0,"context"),!!s)))}function B(h,x,A={}){h=H(h,void 0,"message"),s&&(h=s(h));let{prefix:w,scalar:g,pointBytes:v}=d(x),T=S(A.context,w,h),_=i.multiply(T).toBytes(),R=S(A.context,_,v,h),C=f.create(T+R*g);if(!f.isValid(C))throw new Error("sign failed: invalid s");let N=Q(_,f.toBytes(C));return H(N,K.signature,"result")}let D={zip215:o.zip215};function L(h,x,A,w=D){let{context:g}=w,v=w.zip215===void 0?!!D.zip215:w.zip215,T=K.signature;h=H(h,T,"signature"),x=H(x,void 0,"message"),A=H(A,K.publicKey,"publicKey"),v!==void 0&&At(v,"zip215"),s&&(x=s(x));let _=T/2,R=h.subarray(0,_),C=Kt(h.subarray(_,T)),N,q,P;try{N=e.fromBytes(A,v),q=e.fromBytes(R,v),P=i.multiplyUnsafe(C)}catch{return!1}if(!v&&N.isSmallOrder())return!1;let J=S(g,R,A,x);return q.add(N.multiplyUnsafe(J)).subtract(P).clearCofactor().is0()}let U=a.BYTES,K={secretKey:U,publicKey:U,signature:2*U,seed:U};function I(h){return h=h===void 0?l(K.seed):h,H(h,K.seed,"seed")}function F(h){return fe(h)&&h.length===K.secretKey}function V(h,x){try{return!!e.fromBytes(h,x===void 0?D.zip215:x)}catch{return!1}}let O={getExtendedPublicKey:d,randomSecretKey:I,isValidSecretKey:F,isValidPublicKey:V,toMontgomery(h){let{y:x}=e.fromBytes(h),A=K.publicKey,w=A===32;if(!w&&A!==57)throw new Error("only defined for 25519 and 448");let g=w?a.div(nt+x,nt-x):a.div(x-nt,x+nt);return a.toBytes(g)},toMontgomerySecret(h){let x=K.secretKey;H(h,x);let A=n(h.subarray(0,x));return b(A).subarray(0,x)}};return Object.freeze(K),Object.freeze(O),Object.freeze({keygen:Zr(I,y),getPublicKey:y,sign:B,verify:L,utils:O,Point:e,lengths:K})}function hr(e,t){if(vt(e),vt(t),t<0||t>4)throw new Error("invalid I2OSP length: "+t);if(e<0||e>2**(8*t)-1)throw new Error("invalid I2OSP input: "+e);let r=Array.from({length:t}).fill(0);for(let n=t-1;n>=0;n--)r[n]=e&255,e>>>=8;return new Uint8Array(r)}function hf(e,t){let r=new Uint8Array(e.length);for(let n=0;n<e.length;n++)r[n]=e[n]^t[n];return r}function df(e){if(!fe(e)&&typeof e!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof e=="string"?Vr(e):e;if(t.length===0)throw new Error("DST must be non-empty");return t}function po(e,t,r,n){H(e),vt(r),t=df(t),t.length>255&&(t=n(Q(Vr("H2C-OVERSIZE-DST-"),t)));let{outputLen:o,blockLen:s}=n,i=Math.ceil(r/o);if(r>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=Q(t,hr(t.length,1)),f=new Uint8Array(s),c=hr(r,2),u=new Array(i),l=n(Q(f,e,c,hr(0,1),a));u[0]=n(Q(l,hr(1,1),a));for(let p=1;p<i;p++){let m=[hf(l,u[p-1]),hr(p+1,1),a];u[p]=n(Q(...m))}return Q(...u).slice(0,r)}var wi="HashToScalar-";var pf=BigInt(0),Mt=BigInt(1),Ei=BigInt(2);var mf=BigInt(5),yf=BigInt(8),Pe=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),xo={p:Pe,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:yf,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function bf(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Pe,a=e*e%s*e%s,f=Z(a,Ei,s)*a%s,c=Z(f,Mt,s)*e%s,u=Z(c,mf,s)*c%s,l=Z(u,t,s)*u%s,b=Z(l,r,s)*l%s,p=Z(b,n,s)*b%s,m=Z(p,o,s)*p%s,E=Z(m,o,s)*p%s,d=Z(E,t,s)*u%s;return{pow_p_5_8:Z(d,Ei,s)*e%s,b2:a}}function xf(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var mo=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function go(e,t){let r=Pe,n=W(t*t*t,r),o=W(n*n*t,r),s=bf(e*o).pow_p_5_8,i=W(e*n*s,r),a=W(t*i*i,r),f=i,c=W(i*mo,r),u=a===e,l=a===W(-e,r),b=a===W(-e*mo,r);return u&&(i=f),(l||b)&&(i=c),Ht(i,r)&&(i=W(-i,r)),{isValid:u||l,value:i}}var Xt=xi(xo,{uvRatio:go}),Gt=Xt.Fp,vi=Xt.Fn;function gf(e){return gi(Xt,Re,Object.assign({adjustScalarBytes:xf,zip215:!0},e))}var Ne=gf({});var yo=mo,wf=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Ef=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Sf=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Af=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Si=e=>go(Mt,e),vf=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),bo=e=>Gt.create(Kt(e)&vf);function Ai(e){let{d:t}=xo,r=Pe,n=y=>Gt.create(y),o=n(yo*e*e),s=n((o+Mt)*Sf),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:f,value:c}=go(s,a),u=n(c*e);Ht(u,r)||(u=n(-u)),f||(c=u),f||(i=o);let l=n(i*(o-Mt)*Af-a),b=c*c,p=n((c+c)*a),m=n(l*wf),E=n(Mt-b),d=n(Mt+b);return new Xt(n(p*d),n(E*m),n(m*d),n(p*E))}var Wt=class e extends Yr{static BASE=new e(Xt.BASE);static ZERO=new e(Xt.ZERO);static Fp=Gt;static Fn=vi;constructor(t){super(t)}static fromAffine(t){return new e(Xt.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static fromBytes(t){dt(t,32);let{a:r,d:n}=xo,o=Pe,s=D=>Gt.create(D),i=bo(t);if(!Qs(Gt.toBytes(i),t)||Ht(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),f=s(Mt+r*a),c=s(Mt-r*a),u=s(f*f),l=s(c*c),b=s(r*n*u-l),{isValid:p,value:m}=Si(s(b*l)),E=s(m*c),d=s(m*E*b),y=s((i+i)*E);Ht(y,o)&&(y=s(-y));let S=s(f*d),B=s(y*S);if(!p||Ht(B,o)||S===pf)throw new Error("invalid ristretto255 encoding 2");return new e(new Xt(y,S,Mt,B))}static fromHex(t){return e.fromBytes(rr(t))}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=Pe,i=d=>Gt.create(d),a=i(i(n+r)*i(n-r)),f=i(t*r),c=i(f*f),{value:u}=Si(i(a*c)),l=i(u*a),b=i(u*f),p=i(l*b*o),m;if(Ht(o*p,s)){let d=i(r*yo),y=i(t*yo);t=d,r=y,m=i(l*Ef)}else m=b;Ht(t*p,s)&&(r=i(-r));let E=i((n-r)*m);return Ht(E,s)&&(E=i(-E)),Gt.toBytes(E)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=c=>Gt.create(c),a=i(r*s)===i(n*o),f=i(n*s)===i(r*o);return a||f}is0(){return this.equals(e.ZERO)}};Object.freeze(Wt.BASE);Object.freeze(Wt.ZERO);Object.freeze(Wt.prototype);Object.freeze(Wt);var Bf=Object.freeze({Point:Wt,hashToCurve(e,t){let r=t?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":t.DST,n=po(e,r,64,Re);return Bf.deriveToCurve(n)},hashToScalar(e,t={DST:wi}){let r=po(e,t.DST,64,Re);return vi.create(Kt(r))},deriveToCurve(e){dt(e,64);let t=bo(e.subarray(0,32)),r=Ai(t),n=bo(e.subarray(32,64)),o=Ai(n);return new Wt(r.add(o))}});var Jt=32,bt=64,$r=32;var He,Bi=(async()=>{try{return await Y.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function _i(){let e=Ne.utils.randomSecretKey(),t=Ne.getPublicKey(e);return{privateKey:Ri(e,t),publicKey:t}}function Ii(e){if(e.length!==$r)throw new TypeError('"seed" must be 32 bytes in length.');if(!(e instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, or Uint8Array.');let t=e,r=Ne.getPublicKey(t);return{privateKey:Ri(t,r),publicKey:r}}async function _f(e,t){let r;e.length===bt?r=e.subarray(0,32):r=e;let n={crv:"Ed25519",kty:"OKP",x:M(e.subarray(32),"base64url"),d:M(r,"base64url"),ext:!0,key_ops:["sign"]},o=await Y.get().subtle.importKey("jwk",n,{name:"Ed25519"},!0,["sign"]),s=await Y.get().subtle.sign({name:"Ed25519"},o,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(s,0,s.byteLength)}function If(e,t){let r=e.subarray(0,$r);return Ne.sign(t instanceof Uint8Array?t:t.subarray(),r)}async function Ti(e,t){return He==null&&(He=await Bi),He?_f(e,t):If(e,t)}async function Tf(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Y.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Y.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Lf(e,t,r){return Ne.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Li(e,t,r){return He==null&&(He=await Bi),He?Tf(e,t,r):Lf(e,t,r)}function Ri(e,t){let r=new Uint8Array(bt);for(let n=0;n<$r;n++)r[n]=e[n],r[$r+n]=t[n];return r}function wo(e,t){let r=z(e,"base64urlpad");if(t!=null){if(r.length>t)throw new Error("byte array longer than desired length");r=Rt([new Uint8Array(t-r.length),r])}return r}function Me(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var dr=class{type="Ed25519";raw;constructor(t){this.raw=qe(t,Jt)}toMultihash(){return ne.digest(se(this))}toCID(){return gt.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Li(this.raw,r,t);return Me(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}},pe=class{type="Ed25519";raw;publicKey;constructor(t,r){this.raw=qe(t,bt),this.publicKey=new dr(r)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}sign(t,r){r?.signal?.throwIfAborted();let n=Ti(this.raw,t);return Me(n)?n.then(o=>(r?.signal?.throwIfAborted(),o)):(r?.signal?.throwIfAborted(),n)}};function Eo(e){if(e.length>bt){e=qe(e,bt+Jt);let n=e.subarray(0,bt),o=e.subarray(bt,e.length);return new pe(n,o)}e=qe(e,bt);let t=e.subarray(0,bt),r=e.subarray(Jt);return new pe(t,r)}function Gr(e){return e=qe(e,Jt),new dr(e)}async function Ki(){let{privateKey:e,publicKey:t}=_i();return new pe(e,t)}async function Ci(e){let{privateKey:t,publicKey:r}=Ii(e);return new pe(t,r)}function qe(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new k(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Rf=Math.pow(2,7),Df=Math.pow(2,14),Kf=Math.pow(2,21),Ui=Math.pow(2,28),Fi=Math.pow(2,35),Oi=Math.pow(2,42),ki=Math.pow(2,49),lt=128,Qt=127;function pr(e){if(e<Rf)return 1;if(e<Df)return 2;if(e<Kf)return 3;if(e<Ui)return 4;if(e<Fi)return 5;if(e<Oi)return 6;if(e<ki)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Pi(e,t,r=0){switch(pr(e)){case 8:t[r++]=e&255|lt,e/=128;case 7:t[r++]=e&255|lt,e/=128;case 6:t[r++]=e&255|lt,e/=128;case 5:t[r++]=e&255|lt,e/=128;case 4:t[r++]=e&255|lt,e>>>=7;case 3:t[r++]=e&255|lt,e>>>=7;case 2:t[r++]=e&255|lt,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Ni(e,t){let r=e[t],n=0;if(n+=r&Qt,r<lt||(r=e[t+1],n+=(r&Qt)<<7,r<lt)||(r=e[t+2],n+=(r&Qt)<<14,r<lt)||(r=e[t+3],n+=(r&Qt)<<21,r<lt)||(r=e[t+4],n+=(r&Qt)*Ui,r<lt)||(r=e[t+5],n+=(r&Qt)*Fi,r<lt)||(r=e[t+6],n+=(r&Qt)*Oi,r<lt)||(r=e[t+7],n+=(r&Qt)*ki,r<lt))return n;throw new RangeError("Could not decode varint")}var So=new Float32Array([-0]),te=new Uint8Array(So.buffer);function Hi(e,t,r){So[0]=e,t[r]=te[0],t[r+1]=te[1],t[r+2]=te[2],t[r+3]=te[3]}function Mi(e,t){return te[0]=e[t],te[1]=e[t+1],te[2]=e[t+2],te[3]=e[t+3],So[0]}var Ao=new Float64Array([-0]),ct=new Uint8Array(Ao.buffer);function qi(e,t,r){Ao[0]=e,t[r]=ct[0],t[r+1]=ct[1],t[r+2]=ct[2],t[r+3]=ct[3],t[r+4]=ct[4],t[r+5]=ct[5],t[r+6]=ct[6],t[r+7]=ct[7]}function Vi(e,t){return ct[0]=e[t],ct[1]=e[t+1],ct[2]=e[t+2],ct[3]=e[t+3],ct[4]=e[t+4],ct[5]=e[t+5],ct[6]=e[t+6],ct[7]=e[t+7],Ao[0]}var Cf=BigInt(Number.MAX_SAFE_INTEGER),Uf=BigInt(Number.MIN_SAFE_INTEGER),xt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return me;if(t<Cf&&t>Uf)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>ji&&(o=0n,++n>ji&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return me;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):me}},me=new xt(0,0);me.toBigInt=function(){return 0n};me.zzEncode=me.zzDecode=function(){return this};me.length=function(){return 1};var ji=4294967296n;function zi(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Zi(e,t,r){if(r-t<1)return"";let o,s=[],i=0,a;for(;t<r;)a=e[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function vo(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function _t(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Xr(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Bo=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,_t(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw _t(this,4);return Xr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw _t(this,4);return Xr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw _t(this,4);let t=Mi(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw _t(this,4);let t=Vi(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw _t(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Zi(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw _t(this,t);this.pos+=t}else do if(this.pos>=this.len)throw _t(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new xt(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw _t(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw _t(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw _t(this,8);let t=Xr(this.buf,this.pos+=4),r=Xr(this.buf,this.pos+=4);return new xt(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Ni(this.buf,this.pos);return this.pos+=pr(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function mr(e){return new Bo(e instanceof Uint8Array?e:e.subarray())}function Wr(e,t,r){let n=mr(e);return t.decode(n,void 0,r)}function _o(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return mt(i);o+i>t&&(n=mt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var ye=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Io(){}var Lo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Ff=_o();function Of(e){return globalThis.Buffer!=null?mt(e):Ff(e)}var br=class{len;head;tail;states;constructor(){this.len=0,this.head=new ye(Io,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ye(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Ro((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Jr,10,xt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=xt.fromBigInt(t);return this._push(Jr,r.length(),r)}uint64Number(t){return this._push(Pi,pr(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=xt.fromBigInt(t).zzEncode();return this._push(Jr,r.length(),r)}sint64Number(t){let r=xt.fromNumber(t).zzEncode();return this._push(Jr,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(To,1,t?1:0)}fixed32(t){return this._push(yr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=xt.fromBigInt(t);return this._push(yr,4,r.lo)._push(yr,4,r.hi)}fixed64Number(t){let r=xt.fromNumber(t);return this._push(yr,4,r.lo)._push(yr,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Hi,4,t)}double(t){return this._push(qi,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(To,1,0):this.uint32(r)._push(Pf,r,t)}string(t){let r=zi(t);return r!==0?this.uint32(r)._push(vo,r,t):this._push(To,1,0)}fork(){return this.states=new Lo(this),this.head=this.tail=new ye(Io,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new ye(Io,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=Of(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function To(e,t,r){t[r]=e&255}function kf(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Ro=class extends ye{next;constructor(t,r){super(kf,t,r),this.next=void 0}};function Jr(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function yr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function Pf(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(br.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Nf,t,e),this},br.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Hf,t,e),this});function Nf(e,t,r){t.set(e,r)}function Hf(e,t,r){e.length<40?vo(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(z(e),r)}function Do(){return new br}function Qr(e,t){let r=Do();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*tn(e,t,r){let n=mr(e);yield*t.stream(n,void 0,"$",r)}var en={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function rn(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function Ko(e){function t(s){if(e[s.toString()]==null)throw new Error("Invalid enum value");return e[s]}let r=function(i,a){let f=t(i);a.int32(f)},n=function(i){let a=i.int32();return t(a)},o=function*(i){let a=i.int32();yield t(a)};return rn("enum",en.VARINT,r,n,o)}function nn(e,t,r){return rn("message",en.LENGTH_DELIMITED,e,t,r)}var j;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(j||(j={}));var Co;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Co||(Co={}));(function(e){e.codec=()=>Ko(Co)})(j||(j={}));var Ct;(function(e){let t;e.codec=()=>(t==null&&(t=nn((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),j.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let f={},c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{f.Type=j.codec().decode(s);break}case 2:{f.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return f},function*(s,i,a,f={}){let c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:j.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return Qr(s,e.codec())}e.encode=r;function n(s,i){return Wr(s,e.codec(),i)}e.decode=n;function o(s,i){return tn(s,e.codec(),i)}e.stream=o})(Ct||(Ct={}));var xr;(function(e){let t;e.codec=()=>(t==null&&(t=nn((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),j.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let f={},c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{f.Type=j.codec().decode(s);break}case 2:{f.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return f},function*(s,i,a,f={}){let c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:j.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return Qr(s,e.codec())}e.encode=r;function n(s,i){return Wr(s,e.codec(),i)}e.decode=n;function o(s,i){return tn(s,e.codec(),i)}e.stream=o})(xr||(xr={}));function Uo(e){if(isNaN(e)||e<=0)throw new k("random bytes length must be a Number bigger than 0");return Fr(e)}var wr={};it(wr,{MAX_RSA_KEY_SIZE:()=>Fo,generateRSAKeyPair:()=>qo,jwkToJWKKeyPair:()=>Wi,jwkToPkcs1:()=>jf,jwkToPkix:()=>No,jwkToRSAPrivateKey:()=>an,pkcs1MessageToJwk:()=>ko,pkcs1MessageToRSAPrivateKey:()=>on,pkcs1ToJwk:()=>Vf,pkcs1ToRSAPrivateKey:()=>Ho,pkixMessageToJwk:()=>Po,pkixMessageToRSAPublicKey:()=>sn,pkixToJwk:()=>zf,pkixToRSAPublicKey:()=>Mo});var Ve=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=wr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return gt.createV1(114,this._multihash)}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}verify(t,r,n){return Xi(this.jwk,r,t,n)}},gr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=wr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}sign(t,r){return Gi(this.jwk,t,r)}};var Fo=8192,Oo=18,Mf=1062,qf=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Vf(e){let t=yt(e);return ko(t)}function ko(e){return{n:M(e[1],"base64url"),e:M(e[2],"base64url"),d:M(e[3],"base64url"),p:M(e[4],"base64url"),q:M(e[5],"base64url"),dp:M(e[6],"base64url"),dq:M(e[7],"base64url"),qi:M(e[8],"base64url"),kty:"RSA"}}function jf(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new k("JWK was missing components");return Et([ut(Uint8Array.from([0])),ut(z(e.n,"base64url")),ut(z(e.e,"base64url")),ut(z(e.d,"base64url")),ut(z(e.p,"base64url")),ut(z(e.q,"base64url")),ut(z(e.dp,"base64url")),ut(z(e.dq,"base64url")),ut(z(e.qi,"base64url"))]).subarray()}function zf(e){let t=yt(e,{offset:0});return Po(t)}function Po(e){let t=yt(e[1],{offset:0});return{kty:"RSA",n:M(t[0],"base64url"),e:M(t[1],"base64url")}}function No(e){if(e.n==null||e.e==null)throw new k("JWK was missing components");return Et([qf,er(Et([ut(z(e.n,"base64url")),ut(z(e.e,"base64url"))]))]).subarray()}function Ho(e){let t=yt(e);return on(t)}function on(e){let t=ko(e);return an(t)}function Mo(e,t){if(e.byteLength>=Mf)throw new xe("Key size is too large");let r=yt(e,{offset:0});return sn(r,e,t)}function sn(e,t,r){let n=Po(e);if(r==null){let o=Yt(Ct.encode({Type:j.RSA,Data:t}));r=Lt(Oo,o)}return new Ve(n,r)}function an(e){if(Qi(e)>Fo)throw new k("Key size is too large");let t=Wi(e),r=Yt(Ct.encode({Type:j.RSA,Data:No(t.publicKey)})),n=Lt(Oo,r);return new gr(t.privateKey,new Ve(t.publicKey,n))}async function qo(e){if(e>Fo)throw new k("Key size is too large");let t=await Ji(e),r=Yt(Ct.encode({Type:j.RSA,Data:No(t.publicKey)})),n=Lt(Oo,r);return new gr(t.privateKey,new Ve(t.publicKey,n))}function Wi(e){if(e==null)throw new k("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}var ta="1.2.840.113549.1.1.1";async function Ji(e,t){let r=await Y.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Zf(r,t);return{privateKey:n[0],publicKey:n[1]}}async function Gi(e,t,r){let n=await Y.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Y.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Xi(e,t,r,n){let o=await Y.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Y.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function Zf(e,t){if(e.privateKey==null||e.publicKey==null)throw new k("Private and public key are required");let r=await Promise.all([Y.get().subtle.exportKey("jwk",e.privateKey),Y.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function Qi(e){if(e.kty!=="RSA")throw new k("invalid key type");if(e.n==null)throw new k("invalid key modulus");return z(e.n,"base64url").length*8}var cn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(Ie(t),dt(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),pt(o)}update(t){return Te(this),this.iHash.update(t),this}digestInto(t){Te(this),Kr(t,this),this.finished=!0;let r=t.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,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()}},fn=(()=>{let e=((t,r,n)=>new cn(t,r).update(n).digest());return e.create=(t,r)=>new cn(t,r),e})();var ea=(e,t)=>(e+(e>=0?t:-t)/ra)/t;function Yf(e,t,r){Ce("scalar",e,Ut,r);let[[n,o],[s,i]]=t,a=ea(i*e,r),f=ea(-o*e,r),c=e-a*n-f*s,u=-a*o-f*i,l=c<Ut,b=u<Ut;l&&(c=-c),b&&(u=-u);let p=fr(Math.ceil(Ue(r)/2))+ee;if(c<Ut||c>=p||u<Ut||u>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:c,k2neg:b,k2:u}}function jo(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Vo(e,t){Bt(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return At(r.lowS,"lowS"),At(r.prehash,"prehash"),r.format!==void 0&&jo(r.format),r}var zo=class extends Error{constructor(t=""){super(t)}},It={Err:zo,_tlv:{encode:(e,t)=>{let{Err:r}=It;if(vt(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(typeof t!="string")throw new TypeError('"data" expected string, got type='+typeof t);if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=ar(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?ar(o.length/2|128):"";return ar(e)+s+o+t},decode(e,t){let{Err:r}=It;t=H(t,void 0,"DER data");let n=0;if(e<0||e>255)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),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 c=t.subarray(n,n+f);if(c.length!==f)throw new r("tlv.decode: length bytes not complete");if(c[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of c)i=i<<8|u;if(n+=f,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=It;if(Mr(e),e<Ut)throw new t("integer: negative integers are not allowed");let r=ar(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}=It;if(e.length<1)throw new t("invalid signature integer: empty");if(e[0]&128)throw new t("invalid signature integer: negative");if(e.length>1&&e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return ue(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=It,o=H(e,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:f}=n.decode(2,s),{v:c,l:u}=n.decode(2,f);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(c)}},hexFromSig(e){let{_tlv:t,_int:r}=It,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}};Object.freeze(It._tlv);Object.freeze(It._int);Object.freeze(It);var Ut=BigInt(0),ee=BigInt(1),ra=BigInt(2),un=BigInt(3),$f=BigInt(4);function na(e,t={}){let r=zr("weierstrass",e,t),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;Bt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:f,allowInfinityPoint:c}=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=sa(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function b(O,h,x){if(c&&h.is0())return Uint8Array.of(0);let{x:A,y:w}=h.toAffine(),g=n.toBytes(A);if(At(x,"isCompressed"),x){l();let v=!n.isOdd(w);return Q(oa(v),g)}else return Q(Uint8Array.of(4),g,n.toBytes(w))}function p(O){H(O,void 0,"Point");let{publicKey:h,publicKeyUncompressed:x}=u,A=O.length,w=O[0],g=O.subarray(1);if(c&&A===1&&w===0)return{x:n.ZERO,y:n.ZERO};if(A===h&&(w===2||w===3)){let v=n.fromBytes(g);if(!n.isValid(v))throw new Error("bad point: is not on curve, wrong x");let T=d(v),_;try{_=n.sqrt(T)}catch(N){let q=N instanceof Error?": "+N.message:"";throw new Error("bad point: is not on curve, sqrt error"+q)}l();let R=n.isOdd(_);return(w&1)===1!==R&&(_=n.neg(_)),{x:v,y:_}}else if(A===x&&w===4){let v=n.BYTES,T=n.fromBytes(g.subarray(0,v)),_=n.fromBytes(g.subarray(v,v*2));if(!y(T,_))throw new Error("bad point: is not on curve");return{x:T,y:_}}else throw new Error(`bad point: got length ${A}, expected compressed=${h} or uncompressed=${x}`)}let m=t.toBytes===void 0?b:t.toBytes,E=t.fromBytes===void 0?p:t.fromBytes;function d(O){let h=n.sqr(O),x=n.mul(h,O);return n.add(n.add(x,n.mul(O,s.a)),s.b)}function y(O,h){let x=n.sqr(h),A=d(O);return n.eql(x,A)}if(!y(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let S=n.mul(n.pow(s.a,un),$f),B=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(S,B)))throw new Error("bad curve params: a or b");function D(O,h,x=!1){if(!n.isValid(h)||x&&n.is0(h))throw new Error(`bad point coordinate ${O}`);return h}function L(O){if(!(O instanceof I))throw new Error("Weierstrass Point expected")}function U(O){if(!f||!f.basises)throw new Error("no endo");return Yf(O,f.basises,o.ORDER)}function K(O,h,x,A,w){return x=new I(n.mul(x.X,O),x.Y,x.Z),h=lr(A,h),x=lr(w,x),h.add(x)}class I{static BASE=new I(s.Gx,s.Gy,n.ONE);static ZERO=new I(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(h,x,A){this.X=D("x",h),this.Y=D("y",x,!0),this.Z=D("z",A),Object.freeze(this)}static CURVE(){return s}static fromAffine(h){let{x,y:A}=h||{};if(!h||!n.isValid(x)||!n.isValid(A))throw new Error("invalid affine point");if(h instanceof I)throw new Error("projective point not allowed");return n.is0(x)&&n.is0(A)?I.ZERO:new I(x,A,n.ONE)}static fromBytes(h){let x=I.fromAffine(E(H(h,void 0,"point")));return x.assertValidity(),x}static fromHex(h){return I.fromBytes(Ke(h))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=8,x=!0){return V.createCache(this,h),x||this.multiply(un),this}assertValidity(){let h=this;if(h.is0()){if(t.allowInfinityPoint&&n.is0(h.X)&&n.eql(h.Y,n.ONE)&&n.is0(h.Z))return;throw new Error("bad point: ZERO")}let{x,y:A}=h.toAffine();if(!n.isValid(x)||!n.isValid(A))throw new Error("bad point: x or y not field elements");if(!y(x,A))throw new Error("bad point: equation left != right");if(!h.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:h}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(h)}equals(h){L(h);let{X:x,Y:A,Z:w}=this,{X:g,Y:v,Z:T}=h,_=n.eql(n.mul(x,T),n.mul(g,w)),R=n.eql(n.mul(A,T),n.mul(v,w));return _&&R}negate(){return new I(this.X,n.neg(this.Y),this.Z)}double(){let{a:h,b:x}=s,A=n.mul(x,un),{X:w,Y:g,Z:v}=this,T=n.ZERO,_=n.ZERO,R=n.ZERO,C=n.mul(w,w),N=n.mul(g,g),q=n.mul(v,v),P=n.mul(w,g);return P=n.add(P,P),R=n.mul(w,v),R=n.add(R,R),T=n.mul(h,R),_=n.mul(A,q),_=n.add(T,_),T=n.sub(N,_),_=n.add(N,_),_=n.mul(T,_),T=n.mul(P,T),R=n.mul(A,R),q=n.mul(h,q),P=n.sub(C,q),P=n.mul(h,P),P=n.add(P,R),R=n.add(C,C),C=n.add(R,C),C=n.add(C,q),C=n.mul(C,P),_=n.add(_,C),q=n.mul(g,v),q=n.add(q,q),C=n.mul(q,P),T=n.sub(T,C),R=n.mul(q,N),R=n.add(R,R),R=n.add(R,R),new I(T,_,R)}add(h){L(h);let{X:x,Y:A,Z:w}=this,{X:g,Y:v,Z:T}=h,_=n.ZERO,R=n.ZERO,C=n.ZERO,N=s.a,q=n.mul(s.b,un),P=n.mul(x,g),J=n.mul(A,v),tt=n.mul(w,T),et=n.add(x,A),X=n.add(g,v);et=n.mul(et,X),X=n.add(P,J),et=n.sub(et,X),X=n.add(x,w);let ht=n.add(g,T);return X=n.mul(X,ht),ht=n.add(P,tt),X=n.sub(X,ht),ht=n.add(A,w),_=n.add(v,T),ht=n.mul(ht,_),_=n.add(J,tt),ht=n.sub(ht,_),C=n.mul(N,X),_=n.mul(q,tt),C=n.add(_,C),_=n.sub(J,C),C=n.add(J,C),R=n.mul(_,C),J=n.add(P,P),J=n.add(J,P),tt=n.mul(N,tt),X=n.mul(q,X),J=n.add(J,tt),tt=n.sub(P,tt),tt=n.mul(N,tt),X=n.add(X,tt),P=n.mul(J,X),R=n.add(R,P),P=n.mul(ht,X),_=n.mul(et,_),_=n.sub(_,P),P=n.mul(et,J),C=n.mul(ht,C),C=n.add(C,P),new I(_,R,C)}subtract(h){return L(h),this.add(h.negate())}is0(){return this.equals(I.ZERO)}multiply(h){let{endo:x}=t;if(!o.isValidNot0(h))throw new RangeError("invalid scalar: out of range");let A,w,g=v=>V.cached(this,v,T=>de(I,T));if(x){let{k1neg:v,k1:T,k2neg:_,k2:R}=U(h),{p:C,f:N}=g(T),{p:q,f:P}=g(R);w=N.add(P),A=K(x.beta,C,q,v,_)}else{let{p:v,f:T}=g(h);A=v,w=T}return de(I,[A,w])[0]}multiplyUnsafe(h){let{endo:x}=t,A=this,w=h;if(!o.isValid(w))throw new RangeError("invalid scalar: out of range");if(w===Ut||A.is0())return I.ZERO;if(w===ee)return A;if(V.hasCache(this))return this.multiply(w);if(x){let{k1neg:g,k1:v,k2neg:T,k2:_}=U(w),{p1:R,p2:C}=bi(I,A,v,_);return K(x.beta,R,C,g,T)}else return V.unsafe(A,w)}toAffine(h){let x=this,A=h,{X:w,Y:g,Z:v}=x;if(n.eql(v,n.ONE))return{x:w,y:g};let T=x.is0();A==null&&(A=T?n.ONE:n.inv(v));let _=n.mul(w,A),R=n.mul(g,A),C=n.mul(v,A);if(T)return{x:n.ZERO,y:n.ZERO};if(!n.eql(C,n.ONE))throw new Error("invZ was invalid");return{x:_,y:R}}isTorsionFree(){let{isTorsionFree:h}=t;return i===ee?!0:h?h(I,this):V.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:h}=t;return i===ee?this:h?h(I,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===ee?this.is0():this.clearCofactor().is0()}toBytes(h=!0){return At(h,"isCompressed"),this.assertValidity(),m(I,this,h)}toHex(h=!0){return De(this.toBytes(h))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let F=o.BITS,V=new ke(I,t.endo?Math.ceil(F/2):F);return F>=8&&I.BASE.precompute(8),Object.freeze(I.prototype),Object.freeze(I),I}function oa(e){return Uint8Array.of(e?2:3)}function sa(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Gf(e,t={}){let{Fn:r}=e,n=t.randomBytes===void 0?ir:t.randomBytes,o=Object.assign(sa(e.Fp,r),{seed:Math.max(ao(r.ORDER),16)});function s(p){try{let m=r.fromBytes(p);return r.isValidNot0(m)}catch{return!1}}function i(p,m){let{publicKey:E,publicKeyUncompressed:d}=o;try{let y=p.length;return m===!0&&y!==E||m===!1&&y!==d?!1:!!e.fromBytes(p)}catch{return!1}}function a(p){return p=p===void 0?n(o.seed):p,co(H(p,o.seed,"seed"),r.ORDER)}function f(p,m=!0){return e.BASE.multiply(r.fromBytes(p)).toBytes(m)}function c(p){let{secretKey:m,publicKey:E,publicKeyUncompressed:d}=o,y=r._lengths;if(!fe(p))return;let S=H(p,void 0,"key").length,B=S===E||S===d,D=S===m||!!y?.includes(S);if(!(B&&D))return B}function u(p,m,E=!0){if(c(p)===!0)throw new Error("first arg must be private key");if(c(m)===!1)throw new Error("second arg must be public key");let d=r.fromBytes(p);return e.fromBytes(m).multiply(d).toBytes(E)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},b=Zr(a,f);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:f,getSharedSecret:u,keygen:b,Point:e,utils:l,lengths:o})}function ia(e,t,r={}){let n=t;Ie(n),Bt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?ir:r.randomBytes,s=r.hmac===void 0?(w,g)=>fn(n,w,g):r.hmac,{Fp:i,Fn:a}=e,{ORDER:f,BITS:c}=a,{keygen:u,getPublicKey:l,getSharedSecret:b,utils:p,lengths:m}=Gf(e,r),E={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},d=f*ra+ee<i.ORDER;function y(w){let g=f>>ee;return w>g}function S(w,g){if(!a.isValidNot0(g))throw new Error(`invalid signature ${w}: out of range 1..Point.Fn.ORDER`);return g}function B(){if(d)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function D(w,g){jo(g);let v=m.signature,T=g==="compact"?v:g==="recovered"?v+1:void 0;return H(w,T)}class L{r;s;recovery;constructor(g,v,T){if(this.r=S("r",g),this.s=S("s",v),T!=null){if(B(),![0,1,2,3].includes(T))throw new Error("invalid recovery id");this.recovery=T}Object.freeze(this)}static fromBytes(g,v=E.format){D(g,v);let T;if(v==="der"){let{r:N,s:q}=It.toSig(H(g));return new L(N,q)}v==="recovered"&&(T=g[0],v="compact",g=g.subarray(1));let _=m.signature/2,R=g.subarray(0,_),C=g.subarray(_,_*2);return new L(a.fromBytes(R),a.fromBytes(C),T)}static fromHex(g,v){return this.fromBytes(Ke(g),v)}assertRecovery(){let{recovery:g}=this;if(g==null)throw new Error("invalid recovery id: must be present");return g}addRecoveryBit(g){return new L(this.r,this.s,g)}recoverPublicKey(g){let{r:v,s:T}=this,_=this.assertRecovery(),R=_===2||_===3?v+f:v;if(!i.isValid(R))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let C=i.toBytes(R),N=e.fromBytes(Q(oa((_&1)===0),C)),q=a.inv(R),P=K(H(g,void 0,"msgHash")),J=a.create(-P*q),tt=a.create(T*q),et=e.BASE.multiplyUnsafe(J).add(N.multiplyUnsafe(tt));if(et.is0())throw new Error("invalid recovery: point at infinify");return et.assertValidity(),et}hasHighS(){return y(this.s)}toBytes(g=E.format){if(jo(g),g==="der")return Ke(It.hexFromSig(this));let{r:v,s:T}=this,_=a.toBytes(v),R=a.toBytes(T);return g==="recovered"?(B(),Q(Uint8Array.of(this.assertRecovery()),_,R)):Q(_,R)}toHex(g){return De(this.toBytes(g))}}Object.freeze(L.prototype),Object.freeze(L);let U=r.bits2int===void 0?function(g){if(g.length>8192)throw new Error("input is too large");let v=ue(g),T=g.length*8-c;return T>0?v>>BigInt(T):v}:r.bits2int,K=r.bits2int_modN===void 0?function(g){return a.create(U(g))}:r.bits2int_modN,I=fr(c);function F(w){return Ce("num < 2^"+c,w,Ut,I),a.toBytes(w)}function V(w,g){return H(w,void 0,"message"),g?H(n(w),void 0,"prehashed message"):w}function O(w,g,v){let{lowS:T,prehash:_,extraEntropy:R}=Vo(v,E);w=V(w,_);let C=K(w),N=a.fromBytes(g);if(!a.isValidNot0(N))throw new Error("invalid private key");let q=[F(N),F(C)];if(R!=null&&R!==!1){let et=R===!0?o(m.secretKey):R;q.push(H(et,void 0,"extraEntropy"))}let P=Q(...q),J=C;function tt(et){let X=U(et);if(!a.isValidNot0(X))return;let ht=a.inv(X),be=e.BASE.multiply(X).toAffine(),je=a.create(be.x);if(je===Ut)return;let vr=a.create(ht*a.create(J+je*N));if(vr===Ut)return;let Qo=(be.x===je?0:2)|Number(be.y&ee),ts=vr;return T&&y(vr)&&(ts=a.neg(vr),Qo^=1),new L(je,ts,d?void 0:Qo)}return{seed:P,k2sig:tt}}function h(w,g,v={}){let{seed:T,k2sig:_}=O(w,g,v);return ti(n.outputLen,a.BYTES,s)(T,_).toBytes(v.format)}function x(w,g,v,T={}){let{lowS:_,prehash:R,format:C}=Vo(T,E);if(v=H(v,void 0,"publicKey"),g=V(g,R),!fe(w)){let N=w instanceof L?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+N)}D(w,C);try{let N=L.fromBytes(w,C),q=e.fromBytes(v);if(_&&N.hasHighS())return!1;let{r:P,s:J}=N,tt=K(g),et=a.inv(J),X=a.create(tt*et),ht=a.create(P*et),be=e.BASE.multiplyUnsafe(X).add(q.multiplyUnsafe(ht));return be.is0()?!1:a.create(be.x)===P}catch{return!1}}function A(w,g,v={}){let{prehash:T}=Vo(v,E);return g=V(g,T),L.fromBytes(w,"recovered").recoverPublicKey(g).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:b,utils:p,lengths:m,Point:e,sign:h,verify:x,recoverPublicKey:A,Signature:L,hash:n})}var Yo={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Xf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var aa=BigInt(2);function Wf(e){let t=Yo.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),f=BigInt(88),c=e*e*e%t,u=c*c*e%t,l=Z(u,r,t)*u%t,b=Z(l,r,t)*u%t,p=Z(b,aa,t)*c%t,m=Z(p,o,t)*p%t,E=Z(m,s,t)*m%t,d=Z(E,a,t)*E%t,y=Z(d,f,t)*d%t,S=Z(y,a,t)*E%t,B=Z(S,r,t)*u%t,D=Z(B,i,t)*m%t,L=Z(D,n,t)*c%t,U=Z(L,aa,t);if(!Zo.eql(Zo.sqr(U),e))throw new Error("Cannot find square root");return U}var Zo=Fe(Yo.p,{sqrt:Wf}),Jf=na(Yo,{Fp:Zo,endo:Xf}),Tt=ia(Jf,Yt);var ca=33,fa=32;function ua(e,t,r){let n=Lr.digest(t instanceof Uint8Array?t:t.subarray());if(Me(n))return n.then(({digest:o})=>(r?.signal?.throwIfAborted(),Tt.sign(o,e,{prehash:!1,format:"der"}))).catch(o=>{throw o.name==="AbortError"?o:new ze(String(o))});try{return Tt.sign(n.digest,e,{prehash:!1,format:"der"})}catch(o){throw new ze(String(o))}}function la(e,t,r,n){let o=Lr.digest(r instanceof Uint8Array?r:r.subarray());if(Me(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Tt.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Ze(String(s))});try{return n?.signal?.throwIfAborted(),Tt.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new Ze(String(s))}}var Er=class{type="secp256k1";raw;_key;constructor(t){this._key=pa(t),this.raw=ha(this._key)}toMultihash(){return ne.digest(se(this))}toCID(){return gt.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}verify(t,r,n){return la(this._key,r,t,n)}},Sr=class{type="secp256k1";raw;publicKey;constructor(t,r){this.raw=da(t),this.publicKey=new Er(r??ma(t))}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}sign(t,r){return ua(this.raw,t,r)}};function $o(e){return new Sr(e)}function ln(e){return new Er(e)}async function ya(){let e=Qf();return new Sr(e)}function ha(e){return Tt.Point.fromBytes(e).toBytes()}function da(e){try{return Tt.getPublicKey(e,!0),e}catch(t){throw new Ye(String(t))}}function pa(e){try{return Tt.Point.fromBytes(e),e}catch(t){throw new xe(String(t))}}function ma(e){try{return Tt.getPublicKey(e,!0)}catch(t){throw new Ye(String(t))}}function Qf(){return Tt.utils.randomSecretKey()}var hn={"P-256":32,"P-384":48,"P-521":66},tu=Object.keys(hn),Go=tu.join(" / ");async function ba(e){if(e!=="P-256"&&e!=="P-384"&&e!=="P-521")throw new k(`Unknown curve: ${e}. Must be ${Go}`);let t=await Y.get().subtle.generateKey({name:"ECDH",namedCurve:e},!0,["deriveBits"]),r=async(s,i)=>{let a;i!=null?a=await Y.get().subtle.importKey("jwk",ru(e,i),{name:"ECDH",namedCurve:e},!1,["deriveBits"]):a=t.privateKey;let f=await Y.get().subtle.importKey("jwk",xa(e,s),{name:"ECDH",namedCurve:e},!1,[]),c=await Y.get().subtle.deriveBits({name:"ECDH",public:f},a,hn[e]*8);return new Uint8Array(c,0,c.byteLength)},n=await Y.get().subtle.exportKey("jwk",t.publicKey);return{key:eu(n),genSharedKey:r}}function eu(e){if(e.crv==null||e.x==null||e.y==null)throw new k("JWK was missing components");if(e.crv!=="P-256"&&e.crv!=="P-384"&&e.crv!=="P-521")throw new k(`Unknown curve: ${e.crv}. Must be ${Go}`);let t=hn[e.crv];return Rt([Uint8Array.from([4]),wo(e.x,t),wo(e.y,t)],1+t*2)}function xa(e,t){if(e!=="P-256"&&e!=="P-384"&&e!=="P-521")throw new k(`Unknown curve: ${e}. Must be ${Go}`);let r=hn[e];if(!at(t.subarray(0,1),Uint8Array.from([4])))throw new k("Cannot unmarshal public key - invalid key format");return{kty:"EC",crv:e,x:M(t.subarray(1,r+1),"base64url"),y:M(t.subarray(1+r),"base64url"),ext:!0}}var ru=(e,t)=>({...xa(e,t.public),d:M(t.private,"base64url")});var nu={"AES-128":{ivSize:16,keySize:16},"AES-256":{ivSize:16,keySize:32},Blowfish:{ivSize:8,keySize:32}};async function ga(e,t,r){if(e!=="AES-128"&&e!=="AES-256"&&e!=="Blowfish")throw new k("Cipher type was missing or unsupported");if(t!=="SHA1"&&t!=="SHA256"&&t!=="SHA512")throw new k("Hash type was missing or unsupported");if(r==null||!(r instanceof Uint8Array))throw new k("Secret was missing or an incorrect type");let n=nu[e],o=n.keySize,s=n.ivSize,i=20,a=z("key expansion"),f=2*(s+o+i),c=await pn(t,r),u=await c.digest(a),l=[],b=0;for(;b<f;){let S=await c.digest(Rt([u,a])),B=S.length;b+B>f&&(B=f-b),l.push(S),b+=B,u=await c.digest(u)}let p=f/2,m=Rt(l),E=m.subarray(0,p),d=m.subarray(p,f),y=S=>({iv:S.subarray(0,s),cipherKey:S.subarray(s,s+o),macKey:S.subarray(s+o)});return{k1:y(E),k2:y(d)}}async function ou(e,t){if(e==="Ed25519")return Ki();if(e==="secp256k1")return ya();if(e==="RSA")return qo(hu(t));if(e==="ECDSA")return Ns(du(t));throw new qt}async function su(e,t){if(e!=="Ed25519")throw new qt("Seed key derivation only supported for Ed25519 keys");return Ci(t)}function iu(e,t){let{Type:r,Data:n}=Ct.decode(e),o=n??new Uint8Array;switch(r){case j.RSA:return Mo(o,t);case j.Ed25519:return Gr(o);case j.secp256k1:return ln(o);case j.ECDSA:return Vn(o);default:throw new qt}}function au(e){if(e.byteLength===Jt)return Gr(e);if(e.byteLength===ca)return ln(e);let t=yt(e),r=t[1]?.[0];if(r===Bn||r===_n||r===In)return jn(t);if(t[0]?.[0]===ta)return sn(t,e);throw new k("Could not extract public key from raw bytes")}function cu(e){let{Type:t,Data:r}=Ct.decode(e.digest),n=r??new Uint8Array;switch(t){case j.Ed25519:return Gr(n);case j.secp256k1:return ln(n);case j.ECDSA:return Vn(n);default:throw new qt}}function se(e){return Ct.encode({Type:j[e.type],Data:e.raw})}function fu(e){let t=xr.decode(e),r=t.Data??new Uint8Array;switch(t.Type){case j.RSA:return Ho(r);case j.Ed25519:return Eo(r);case j.secp256k1:return $o(r);case j.ECDSA:return Fs(r);default:throw new qt}}function uu(e){if(e.byteLength===bt)return Eo(e);if(e.byteLength===fa)return $o(e);let t=yt(e),r=t[2]?.[0];if(r===Bn||r===_n||r===In)return qn(t);if(t.length>8)return on(t);throw new k("Could not extract private key from raw bytes")}function lu(e){return xr.encode({Type:j[e.type],Data:e.raw})}function hu(e){return e==null?2048:parseInt(e,10)}function du(e){if(e==="P-256"||e==null)return"P-256";if(e==="P-384")return"P-384";if(e==="P-521")return"P-521";throw new k("Unsupported curve, should be P-256, P-384 or P-521")}async function pu(e){if(e.type==="RSA")return{privateKey:await crypto.subtle.importKey("jwk",e.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",e.publicKey.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])};if(e.type==="ECDSA")return{privateKey:await crypto.subtle.importKey("jwk",e.jwk,{name:"ECDSA",namedCurve:e.jwk.crv??"P-256"},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",e.publicKey.jwk,{name:"ECDSA",namedCurve:e.publicKey.jwk.crv??"P-256"},!0,["verify"])};throw new k("Only RSA and ECDSA keys are supported")}async function mu(e){if(e.privateKey.algorithm.name==="RSASSA-PKCS1-v1_5"){let t=await crypto.subtle.exportKey("jwk",e.privateKey);return an(t)}if(e.privateKey.algorithm.name==="ECDSA"){let t=await crypto.subtle.exportKey("jwk",e.privateKey);return new kt(t)}throw new k("Only RSA and ECDSA keys are supported")}var Ar=Uint32Array.from([1732584193,4023233417,2562383102,271733878,3285377520]),re=new Uint32Array(80),Wo=class extends ie{A=Ar[0]|0;B=Ar[1]|0;C=Ar[2]|0;D=Ar[3]|0;E=Ar[4]|0;constructor(){super(64,20,8,!1)}get(){let{A:t,B:r,C:n,D:o,E:s}=this;return[t,r,n,o,s]}set(t,r,n,o,s){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0}process(t,r){for(let f=0;f<16;f++,r+=4)re[f]=t.getUint32(r,!1);for(let f=16;f<80;f++)re[f]=Cr(re[f-3]^re[f-8]^re[f-14]^re[f-16],1);let{A:n,B:o,C:s,D:i,E:a}=this;for(let f=0;f<80;f++){let c,u;f<20?(c=Or(o,s,i),u=1518500249):f<40?(c=o^s^i,u=1859775393):f<60?(c=kr(o,s,i),u=2400959708):(c=o^s^i,u=3395469782);let l=Cr(n,5)+c+a+u+re[f]|0;a=i,i=s,s=Cr(o,30),o=n,n=l}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,this.set(n,o,s,i,a)}roundClean(){pt(re)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0),pt(this.buffer)}},wa=nr(()=>new Wo);function yu(e,t,r,n){Ie(e);let o=qs({dkLen:32,asyncTick:10},n),{c:s,dkLen:i,asyncTick:a}=o;if(wt(s,"c"),wt(i,"dkLen"),wt(a,"asyncTick"),s<1)throw new Error("iterations (c) must be >= 1");if(i<1)throw new Error('"dkLen" must be >= 1');if(i>(2**32-1)*e.outputLen)throw new Error("derived key too long");let f=Zn(t,"password"),c=Zn(r,"salt"),u=new Uint8Array(i),l=fn.create(e,f),b=l._cloneInto().update(c);return{c:s,dkLen:i,asyncTick:a,DK:u,PRF:l,PRFSalt:b}}function bu(e,t,r,n,o){return e.destroy(),t.destroy(),n&&n.destroy(),pt(o),r}function Ea(e,t,r,n){let{c:o,dkLen:s,DK:i,PRF:a,PRFSalt:f}=yu(e,t,r,n),c,u=new Uint8Array(4),l=Le(u),b=new Uint8Array(a.outputLen);for(let p=1,m=0;m<s;p++,m+=a.outputLen){let E=i.subarray(m,m+a.outputLen);l.setInt32(0,p,!1),(c=f._cloneInto(c)).update(u).digestInto(b),E.set(b.subarray(0,E.length));for(let d=1;d<o;d++){a._cloneInto(c).update(b).digestInto(b);for(let y=0;y<E.length;y++)E[y]^=b[y]}}return bu(a,f,i,c,b)}var Sa={sha1:wa,"sha2-256":Yt,"sha2-512":Re};function Jo(e,t,r,n,o){if(o!=="sha1"&&o!=="sha2-256"&&o!=="sha2-512"){let a=Object.keys(Sa).join(" / ");throw new k(`Hash '${o}' is unknown or not supported. Must be ${a}`)}let s=Sa[o],i=Ea(s,e,t,{c:r,dkLen:n});return Kn.encode(i).substring(1)}return Ia(xu);})();
2
+ "use strict";var Libp2PCrypto=(()=>{var pn=Object.defineProperty;var va=Object.getOwnPropertyDescriptor;var _a=Object.getOwnPropertyNames;var Ia=Object.prototype.hasOwnProperty;var at=(e,t)=>{for(var r in t)pn(e,r,{get:t[r],enumerable:!0})},Ta=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of _a(t))!Ia.call(e,o)&&o!==r&&pn(e,o,{get:()=>t[o],enumerable:!(n=va(t,o))||n.enumerable});return e};var La=e=>Ta(pn({},"__esModule",{value:!0}),e);var Au={};at(Au,{hmac:()=>Tr,keys:()=>Wo,pbkdf2:()=>Qo,randomBytes:()=>Fo});var Tr={};at(Tr,{create:()=>mn});function Ra(e){return e.buffer instanceof ArrayBuffer}function ot(e){return Ra(e)?e:e.slice()}var Ye=class extends Error{constructor(t="An error occurred while signing a message"){super(t),this.name="SigningError"}},$e=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Ir=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Y={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Ir("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var rs={SHA1:20,SHA256:32,SHA512:64};var Da={SHA1:"SHA-1",SHA256:"SHA-256",SHA512:"SHA-512"},Ka=async(e,t)=>{let r=await Y.get().subtle.sign({name:"HMAC"},e,ot(t));return new Uint8Array(r,0,r.byteLength)};async function mn(e,t){let r=Da[e],n=await Y.get().subtle.importKey("raw",ot(t),{name:"HMAC",hash:{name:r}},!1,["sign"]);return{async digest(o){return Ka(n,o)},length:rs[e]}}var Wo={};at(Wo,{generateEphemeralKeyPair:()=>ga,generateKeyPair:()=>fu,generateKeyPairFromSeed:()=>uu,keyStretcher:()=>Ea,privateKeyFromCryptoKeyPair:()=>wu,privateKeyFromProtobuf:()=>pu,privateKeyFromRaw:()=>mu,privateKeyToCryptoKeyPair:()=>gu,privateKeyToProtobuf:()=>yu,publicKeyFromMultihash:()=>du,publicKeyFromProtobuf:()=>lu,publicKeyFromRaw:()=>hu,publicKeyToProtobuf:()=>ae});var k=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},we=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}},Ge=class extends Error{static name="InvalidPrivateKeyError";constructor(t="Invalid private key"){super(t),this.name="InvalidPrivateKeyError"}};var Vt=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var wn={};at(wn,{base58btc:()=>rt,base58flickr:()=>Ha});var Uu=new Uint8Array(0);function ns(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Ot(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return oe(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return oe(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));throw new Error("Unknown type, must be binary type")}function os(e){return new TextEncoder().encode(e)}function ss(e){return new TextDecoder().decode(e)}function Ca(e){return e?.buffer instanceof ArrayBuffer}function oe(e){return Ca(e)?e:e.slice()}function Ua(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=e.length,f=e.charAt(0),c=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var E=0,d=0,y=0,S=m.length;y!==S&&m[y]===0;)y++,E++;for(var v=(S-y)*u+1>>>0,D=new Uint8Array(v);y!==S;){for(var L=m[y],U=0,K=v-1;(L!==0||U<d)&&K!==-1;K--,U++)L+=256*D[K]>>>0,D[K]=L%a>>>0,L=L/a>>>0;if(L!==0)throw new Error("Non-zero carry");d=U,y++}for(var I=v-d;I!==v&&D[I]===0;)I++;for(var F=f.repeat(E);I<v;++I)F+=e.charAt(D[I]);return F}function b(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var E=0;if(m[E]!==" "){for(var d=0,y=0;m[E]===f;)d++,E++;for(var S=(m.length-E)*c+1>>>0,v=new Uint8Array(S);m[E];){var D=r[m.charCodeAt(E)];if(D===255)return;for(var L=0,U=S-1;(D!==0||L<y)&&U!==-1;U--,L++)D+=a*v[U]>>>0,v[U]=D%256>>>0,D=D/256>>>0;if(D!==0)throw new Error("Non-zero carry");y=L,E++}if(m[E]!==" "){for(var K=S-y;K!==S&&v[K]===0;)K++;for(var I=new Uint8Array(d+(S-K)),F=d;K!==S;)I[F++]=v[K++];return I}}}function p(m){var E=b(m);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:b,decode:p}}var Fa=Ua,Oa=Fa,as=Oa;var yn=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},bn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return cs(this,t)}},xn=class{decoders;constructor(t){this.decoders=t}or(t){return cs(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function cs(e,t){return new xn({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var gn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new yn(t,r,n),this.decoder=new bn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ee({name:e,prefix:t,encode:r,decode:n}){return new gn(e,t,r,n)}function jt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=as(r,e);return Ee({prefix:t,name:e,encode:n,decode:s=>Ot(o(s))})}function ka(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,f=0;for(let c=0;c<o;++c){let u=t[e[c]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,i+=r,i>=8&&(i-=8,s[f++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Pa(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let f=0;f<e.length;++f)for(a=a<<8|e[f],i+=8;i>r;)i-=r,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Na(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function $({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Na(n);return Ee({prefix:t,name:e,encode(s){return Pa(s,n,r)},decode(s){return ka(s,o,r,e)}})}var rt=jt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ha=jt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var En={};at(En,{base32:()=>Se,base32hex:()=>ja,base32hexpad:()=>Za,base32hexpadupper:()=>Ya,base32hexupper:()=>za,base32pad:()=>qa,base32padupper:()=>Va,base32upper:()=>Ma,base32z:()=>$a});var Se=$({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ma=$({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),qa=$({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Va=$({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ja=$({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),za=$({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Za=$({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ya=$({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),$a=$({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Sn={};at(Sn,{base36:()=>Xe,base36upper:()=>Ga});var Xe=jt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ga=jt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Xa=ls,fs=128,Wa=127,Ja=~Wa,Qa=Math.pow(2,31);function ls(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Qa;)t[r++]=e&255|fs,e/=128;for(;e&Ja;)t[r++]=e&255|fs,e>>>=7;return t[r]=e|0,ls.bytes=r-n+1,t}var tc=An,ec=128,us=127;function An(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw An.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&us)<<o:(i&us)*Math.pow(2,o),o+=7}while(i>=ec);return An.bytes=s-n,r}var rc=Math.pow(2,7),nc=Math.pow(2,14),oc=Math.pow(2,21),sc=Math.pow(2,28),ic=Math.pow(2,35),ac=Math.pow(2,42),cc=Math.pow(2,49),fc=Math.pow(2,56),uc=Math.pow(2,63),lc=function(e){return e<rc?1:e<nc?2:e<oc?3:e<sc?4:e<ic?5:e<ac?6:e<cc?7:e<fc?8:e<uc?9:10},hc={encode:Xa,decode:tc,encodingLength:lc},dc=hc,We=dc;function Je(e,t=0){return[We.decode(e,t),We.decode.bytes]}function Ae(e,t,r=0){return We.encode(e,t,r),t}function Be(e){return We.encodingLength(e)}function Rt(e,t){let r=t.byteLength,n=Be(e),o=n+Be(r),s=new Uint8Array(o+r);return Ae(e,s,0),Ae(r,s,n),s.set(t,o),new ve(e,r,t,s)}function hs(e){let t=Ot(e),[r,n]=Je(t),[o,s]=Je(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ve(r,o,i,t)}function ds(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&ns(e.bytes,r.bytes)}}var ve=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=oe(n),this.bytes=oe(o)}};function ps(e,t){let{bytes:r,version:n}=e;return n===0?mc(r,Bn(e),t??rt.encoder):yc(r,Bn(e),t??Se.encoder)}var ms=new WeakMap;function Bn(e){let t=ms.get(e);if(t==null){let r=new Map;return ms.set(e,r),r}return t}var wt=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=oe(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==tr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==bc)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=Rt(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&ds(t.multihash,n.multihash)}toString(t){return ps(this,t)}toJSON(){return{"/":ps(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??ys(n,o,s.bytes))}else if(r[xc]===!0){let{version:n,multihash:o,code:s}=r,i=hs(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==tr)throw new Error(`Version 0 CID must use dag-pb (code: ${tr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=ys(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,tr,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Ot(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new ve(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,b]=Je(t.subarray(r));return r+=b,l},o=n(),s=tr;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),f=n(),c=r+f,u=c-i;return{version:o,codec:s,multihashCode:a,digestSize:f,multihashSize:u,size:c}}static parse(t,r){let[n,o]=pc(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Bn(s).set(n,t),s}};function pc(e,t){switch(e[0]){case"Q":{let r=t??rt;return[rt.prefix,r.decode(`${rt.prefix}${e}`)]}case rt.prefix:{let r=t??rt;return[rt.prefix,r.decode(e)]}case Se.prefix:{let r=t??Se;return[Se.prefix,r.decode(e)]}case Xe.prefix:{let r=t??Xe;return[Xe.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function mc(e,t,r){let{prefix:n}=r;if(n!==rt.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function yc(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var tr=112,bc=18;function ys(e,t,r){let n=Be(e),o=n+Be(t),s=new Uint8Array(o+r.byteLength);return Ae(e,s,0),Ae(t,s,n),s.set(r,o),s}var xc=Symbol.for("@ipld/js-cid/CID");var vn={};at(vn,{identity:()=>se});var bs=0,gc="identity",xs=Ot;function wc(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Rt(bs,xs(e))}var se={code:bs,name:gc,encode:xs,digest:wc};function ct(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}var _n="1.2.840.10045.3.1.7",In="1.3.132.0.34",Tn="1.3.132.0.35";async function gs(e="P-256"){let t=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:e},!0,["sign","verify"]);return{publicKey:await crypto.subtle.exportKey("jwk",t.publicKey),privateKey:await crypto.subtle.exportKey("jwk",t.privateKey)}}async function ws(e,t,r){let n=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["sign"]);r?.signal?.throwIfAborted();let o=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},n,ot(t.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Es(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,ot(t),ot(r.subarray()));return n?.signal?.throwIfAborted(),s}function kt(e=0){return new Uint8Array(e)}function yt(e=0){return new Uint8Array(e)}function Ec(e){return e?.buffer instanceof ArrayBuffer}function Ss(e){if(Ec(e))return e;let t=e.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function Dt(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=yt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return Ss(r)}var Bs=Symbol.for("@achingbrain/uint8arraylist");function As(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function Rr(e){return!!e?.[Bs]}var ut=class e{bufs;length;[Bs]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Rr(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Rr(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=As(this.bufs,t);return r.buf[r.index]}set(t,r){let n=As(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(Rr(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return Dt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Dt(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=n,s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,f=a+i.byteLength;if(o=f,t>=f)continue;let c=t>=a&&t<f,u=r>a&&r<=f;if(c&&u){if(t===a&&r===f){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(r-t)));break}if(c){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){if(r===f){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Rr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,f=this.byteLength-n.byteLength,c=n.byteLength-1,u;for(let l=r;l<=f;l+=u){u=0;for(let b=c;b>=0;b--){let p=this.get(l+b);if(n[b]!==p){u=Math.max(1,b-a[p]);break}}if(u===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=yt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=kt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=kt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=kt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=yt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=kt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=kt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=kt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=kt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=kt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!ct(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var Ln={};at(Ln,{base10:()=>Sc});var Sc=jt({prefix:"9",name:"base10",alphabet:"0123456789"});var Rn={};at(Rn,{base16:()=>Ac,base16upper:()=>Bc});var Ac=$({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Bc=$({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Dn={};at(Dn,{base2:()=>vc});var vc=$({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Kn={};at(Kn,{base256emoji:()=>Rc});var vs=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),_c=vs.reduce((e,t,r)=>(e[r]=t,e),[]),Ic=vs.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Tc(e){return e.reduce((t,r)=>(t+=_c[r],t),"")}function Lc(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Ic[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Rc=Ee({prefix:"\u{1F680}",name:"base256emoji",encode:Tc,decode:Lc});var Un={};at(Un,{base64:()=>Cn,base64pad:()=>Dc,base64url:()=>Kc,base64urlpad:()=>Cc});var Cn=$({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Dc=$({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Kc=$({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Cc=$({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Fn={};at(Fn,{base8:()=>Uc});var Uc=$({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var On={};at(On,{identity:()=>Fc});var Fc=Ee({prefix:"\0",name:"identity",encode:e=>ss(e),decode:e=>os(e)});var xl=new TextEncoder,gl=new TextDecoder;var Nn={};at(Nn,{sha256:()=>Dr,sha512:()=>Nc});var Pc=20;function Pn({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new kn(e,t,r,n,o)}var kn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Pc,this.maxDigestLength=s}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?_s(n,this.code,r?.truncate):n.then(o=>_s(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function _s(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Rt(t,e)}function Ts(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Dr=Pn({name:"sha2-256",code:18,encode:Ts("SHA-256")}),Nc=Pn({name:"sha2-512",code:19,encode:Ts("SHA-512")});var Hn={...On,...Dn,...Fn,...Ln,...Rn,...En,...Sn,...wn,...Un,...Kn},Dl={...Nn,...vn};function Rs(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Ls=Rs("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Mn=Rs("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=yt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Hc={utf8:Ls,"utf-8":Ls,hex:Hn.base16,latin1:Mn,ascii:Mn,binary:Mn,...Hn},Kr=Hc;function z(e,t="utf8"){let r=Kr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function M(e,t="utf8"){let r=Kr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Mc=parseInt("11111",2),qn=parseInt("10000000",2),qc=parseInt("01111111",2),Ds={0:er,1:er,2:Vc,3:Zc,4:Yc,5:zc,6:jc,16:er,22:er,48:er};function bt(e,t={offset:0}){let r=e[t.offset]&Mc;if(t.offset++,Ds[r]!=null)return Ds[r](e,t);throw new Error("No decoder for tag "+r)}function rr(e,t){let r=0;if((e[t.offset]&qn)===qn){let n=e[t.offset]&qc,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function er(e,t){rr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=bt(e,t);if(n===null)break;r.push(n)}return r}function Vc(e,t){let r=rr(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function jc(e,t){let r=rr(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,f=[];for(;t.offset<n;){let c=e[t.offset];if(t.offset++,f.push(c&127),c<128){f.reverse();let u=0;for(let l=0;l<f.length;l++)u+=f[l]<<l*7;a+=`.${u}`,f=[]}}return a}function zc(e,t){return t.offset++,null}function Zc(e,t){let r=rr(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Yc(e,t){let r=rr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function $c(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new ut;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Cr(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=$c(e.byteLength);return new ut(Uint8Array.from([t.byteLength|qn]),t)}function lt(e){let t=new ut,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new ut(Uint8Array.from([2]),Cr(t),t)}function nr(e){let t=Uint8Array.from([0]),r=new ut(t,e);return new ut(Uint8Array.from([3]),Cr(r),r)}function Ks(e){return new ut(Uint8Array.from([4]),Cr(e),e)}function St(e,t=48){let r=new ut;for(let n of e)r.append(n);return new ut(Uint8Array.from([t]),Cr(r),r)}var Gc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Xc=Uint8Array.from([6,5,43,129,4,0,34]),Wc=Uint8Array.from([6,5,43,129,4,0,35]),Cs={ext:!0,kty:"EC",crv:"P-256"},Us={ext:!0,kty:"EC",crv:"P-384"},Fs={ext:!0,kty:"EC",crv:"P-521"},_e=32,Ie=48,Te=66;function Os(e){let t=bt(e);return Vn(t)}function Vn(e){let t=e[1],r=M(t,"base64url"),n=e[2][1][0],o=1,s,i;if(t.byteLength===_e)return s=M(n.subarray(o,o+_e),"base64url"),i=M(n.subarray(o+_e),"base64url"),new Pt({...Cs,key_ops:["sign"],d:r,x:s,y:i});if(t.byteLength===Ie)return s=M(n.subarray(o,o+Ie),"base64url"),i=M(n.subarray(o+Ie),"base64url"),new Pt({...Us,key_ops:["sign"],d:r,x:s,y:i});if(t.byteLength===Te)return s=M(n.subarray(o,o+Te),"base64url"),i=M(n.subarray(o+Te),"base64url"),new Pt({...Fs,key_ops:["sign"],d:r,x:s,y:i});throw new k(`Private key length was wrong length, got ${t.byteLength}, expected 32, 48 or 66`)}function jn(e){let t=bt(e);return zn(t)}function zn(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===_e*2+1)return n=M(t.subarray(r,r+_e),"base64url"),o=M(t.subarray(r+_e),"base64url"),new ie({...Cs,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ie*2+1)return n=M(t.subarray(r,r+Ie),"base64url"),o=M(t.subarray(r+Ie),"base64url"),new ie({...Us,key_ops:["verify"],x:n,y:o});if(t.byteLength===Te*2+1)return n=M(t.subarray(r,r+Te),"base64url"),o=M(t.subarray(r+Te),"base64url"),new ie({...Fs,key_ops:["verify"],x:n,y:o});throw new k(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function ks(e){return St([lt(Uint8Array.from([1])),Ks(z(e.d??"","base64url")),St([Ns(e.crv)],160),St([nr(new ut(Uint8Array.from([4]),z(e.x??"","base64url"),z(e.y??"","base64url")))],161)]).subarray()}function Ps(e){return St([lt(Uint8Array.from([1])),St([Ns(e.crv)],160),St([nr(new ut(Uint8Array.from([4]),z(e.x??"","base64url"),z(e.y??"","base64url")))],161)]).subarray()}function Ns(e){if(e==="P-256")return Gc;if(e==="P-384")return Xc;if(e==="P-521")return Wc;throw new k(`Invalid curve ${e}`)}async function Hs(e="P-256"){let t=await gs(e);return new Pt(t.privateKey)}var ie=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Ps(this.jwk)),this._raw}toMultihash(){return se.digest(ae(this))}toCID(){return wt.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}async verify(t,r,n){return Es(this.jwk,r,t,n)}},Pt=class{type="ECDSA";jwk;publicKey;_raw;constructor(t){this.jwk=t,this.publicKey=new ie({crv:t.crv,ext:t.ext,key_ops:["verify"],kty:"EC",x:t.x,y:t.y})}get raw(){return this._raw==null&&(this._raw=ks(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}async sign(t,r){return ws(this.jwk,t,r)}};function Zn(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}function Et(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(`${r}expected number, got ${typeof e}`)}if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new RangeError(`${r}expected integer >= 0, got ${e}`)}}function pt(e,t,r=""){let n=Zn(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,a=s?` of length ${t}`:"",f=n?`length=${o}`:`type=${typeof e}`,c=i+"expected Uint8Array"+a+", got "+f;throw n?new RangeError(c):new TypeError(c)}return e}function Le(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(Et(e.outputLen),Et(e.blockLen),e.outputLen<1)throw new Error('"outputLen" must be >= 1');if(e.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Re(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 Ur(e,t){pt(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function mt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function De(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function At(e,t){return e<<32-t|e>>>t}function Fr(e,t){return e<<t|e>>>32-t>>>0}var qs=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Jc=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Or(e){if(pt(e),qs)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Jc[e[r]];return t}var Nt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ms(e){if(e>=Nt._0&&e<=Nt._9)return e-Nt._0;if(e>=Nt.A&&e<=Nt.F)return e-(Nt.A-10);if(e>=Nt.a&&e<=Nt.f)return e-(Nt.a-10)}function or(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(qs)try{return Uint8Array.fromHex(e)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let t=e.length,r=t/2;if(t%2)throw new RangeError("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=Ms(e.charCodeAt(s)),a=Ms(e.charCodeAt(s+1));if(i===void 0||a===void 0){let f=e[s]+e[s+1];throw new RangeError('hex string expected, got non-hex character "'+f+'" at index '+s)}n[o]=i*16+a}return n}function Qc(e){if(typeof e!="string")throw new TypeError("string expected");return new Uint8Array(new TextEncoder().encode(e))}function Yn(e,t=""){return typeof e=="string"?Qc(e):pt(e,void 0,t)}function $n(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];pt(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}function Vs(e,t){if(t!==void 0&&{}.toString.call(t)!=="[object Object]")throw new TypeError("options must be object or undefined");return Object.assign(e,t)}function sr(e,t={}){let r=(o,s)=>e(s).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function js(e=32){Et(e,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(e>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}var Gn=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function kr(e,t,r){return e&t^~e&r}function Pr(e,t,r){return e&t^e&r^t&r}var ce=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,o){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=De(this.buffer)}update(t){Re(this),pt(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let f=De(t);for(;o<=s-i;i+=o)this.process(f,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Re(this),Ur(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,mt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=De(t),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let c=f/4,u=this.get();if(c>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<c;l++)a.setUint32(4*l,u[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Ht=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var st=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Nr=BigInt(4294967295),zs=BigInt(32);function tf(e,t=!1){return t?{h:Number(e&Nr),l:Number(e>>zs&Nr)}:{h:Number(e>>zs&Nr)|0,l:Number(e&Nr)|0}}function Zs(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=tf(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Xn=(e,t,r)=>e>>>r,Wn=(e,t,r)=>e<<32-r|t>>>r,fe=(e,t,r)=>e>>>r|t<<32-r,ue=(e,t,r)=>e<<32-r|t>>>r,ir=(e,t,r)=>e<<64-r|t>>>r-32,ar=(e,t,r)=>e>>>r-32|t<<64-r;function Kt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Ys=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),$s=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Gs=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Xs=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Ws=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Js=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var rf=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]),zt=new Uint32Array(64),Jn=class extends ce{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:f}=this;return[t,r,n,o,s,i,a,f]}set(t,r,n,o,s,i,a,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=a|0,this.H=f|0}process(t,r){for(let l=0;l<16;l++,r+=4)zt[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let b=zt[l-15],p=zt[l-2],m=At(b,7)^At(b,18)^b>>>3,E=At(p,17)^At(p,19)^p>>>10;zt[l]=E+zt[l-7]+m+zt[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:f,G:c,H:u}=this;for(let l=0;l<64;l++){let b=At(a,6)^At(a,11)^At(a,25),p=u+b+kr(a,f,c)+rf[l]+zt[l]|0,E=(At(n,2)^At(n,13)^At(n,22))+Pr(n,o,s)|0;u=c,c=f,f=a,a=i+p|0,i=s,s=o,o=n,n=p+E|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,f=f+this.F|0,c=c+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,f,c,u)}roundClean(){mt(zt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),mt(this.buffer)}},Qn=class extends Jn{A=Ht[0]|0;B=Ht[1]|0;C=Ht[2]|0;D=Ht[3]|0;E=Ht[4]|0;F=Ht[5]|0;G=Ht[6]|0;H=Ht[7]|0;constructor(){super(32)}};var Qs=Zs(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),nf=Qs[0],of=Qs[1],Zt=new Uint32Array(80),Yt=new Uint32Array(80),to=class extends ce{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:f,Eh:c,El:u,Fh:l,Fl:b,Gh:p,Gl:m,Hh:E,Hl:d}=this;return[t,r,n,o,s,i,a,f,c,u,l,b,p,m,E,d]}set(t,r,n,o,s,i,a,f,c,u,l,b,p,m,E,d){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=f|0,this.Eh=c|0,this.El=u|0,this.Fh=l|0,this.Fl=b|0,this.Gh=p|0,this.Gl=m|0,this.Hh=E|0,this.Hl=d|0}process(t,r){for(let v=0;v<16;v++,r+=4)Zt[v]=t.getUint32(r),Yt[v]=t.getUint32(r+=4);for(let v=16;v<80;v++){let D=Zt[v-15]|0,L=Yt[v-15]|0,U=fe(D,L,1)^fe(D,L,8)^Xn(D,L,7),K=ue(D,L,1)^ue(D,L,8)^Wn(D,L,7),I=Zt[v-2]|0,F=Yt[v-2]|0,V=fe(I,F,19)^ir(I,F,61)^Xn(I,F,6),O=ue(I,F,19)^ar(I,F,61)^Wn(I,F,6),h=Gs(K,O,Yt[v-7],Yt[v-16]),x=Xs(h,U,V,Zt[v-7],Zt[v-16]);Zt[v]=x|0,Yt[v]=h|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:f,Dh:c,Dl:u,Eh:l,El:b,Fh:p,Fl:m,Gh:E,Gl:d,Hh:y,Hl:S}=this;for(let v=0;v<80;v++){let D=fe(l,b,14)^fe(l,b,18)^ir(l,b,41),L=ue(l,b,14)^ue(l,b,18)^ar(l,b,41),U=l&p^~l&E,K=b&m^~b&d,I=Ws(S,L,K,of[v],Yt[v]),F=Js(I,y,D,U,nf[v],Zt[v]),V=I|0,O=fe(n,o,28)^ir(n,o,34)^ir(n,o,39),h=ue(n,o,28)^ar(n,o,34)^ar(n,o,39),x=n&s^n&a^s&a,A=o&i^o&f^i&f;y=E|0,S=d|0,E=p|0,d=m|0,p=l|0,m=b|0,{h:l,l:b}=Kt(c|0,u|0,F|0,V|0),c=a|0,u=f|0,a=s|0,f=i|0,s=n|0,i=o|0;let w=Ys(V,h,A);n=$s(w,F,O,x),o=w|0}({h:n,l:o}=Kt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Kt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:f}=Kt(this.Ch|0,this.Cl|0,a|0,f|0),{h:c,l:u}=Kt(this.Dh|0,this.Dl|0,c|0,u|0),{h:l,l:b}=Kt(this.Eh|0,this.El|0,l|0,b|0),{h:p,l:m}=Kt(this.Fh|0,this.Fl|0,p|0,m|0),{h:E,l:d}=Kt(this.Gh|0,this.Gl|0,E|0,d|0),{h:y,l:S}=Kt(this.Hh|0,this.Hl|0,y|0,S|0),this.set(n,o,s,i,a,f,c,u,l,b,p,m,E,d,y,S)}roundClean(){mt(Zt,Yt)}destroy(){this.destroyed=!0,mt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},eo=class extends to{Ah=st[0]|0;Al=st[1]|0;Bh=st[2]|0;Bl=st[3]|0;Ch=st[4]|0;Cl=st[5]|0;Dh=st[6]|0;Dl=st[7]|0;Eh=st[8]|0;El=st[9]|0;Fh=st[10]|0;Fl=st[11]|0;Gh=st[12]|0;Gl=st[13]|0;Hh=st[14]|0;Hl=st[15]|0;constructor(){super(64)}};var $t=sr(()=>new Qn,Gn(1));var Ke=sr(()=>new eo,Gn(3));var H=(e,t,r)=>pt(e,t,r),no=Et,Ce=Or,Q=(...e)=>$n(...e),Ue=e=>or(e),le=Zn,cr=e=>js(e),Mr=BigInt(0),ro=BigInt(1);function Bt(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new TypeError(r+"expected boolean, got type="+typeof e)}return e}function qr(e){if(typeof e=="bigint"){if(!Hr(e))throw new RangeError("positive bigint expected, got "+e)}else no(e);return e}function vt(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(r+"expected number, got type="+typeof e)}if(!Number.isSafeInteger(e)){let r=t&&`"${t}" `;throw new RangeError(r+"expected safe integer, got "+e)}}function fr(e){let t=qr(e).toString(16);return t.length&1?"0"+t:t}function ti(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?Mr:BigInt("0x"+e)}function he(e){return ti(Or(e))}function Ct(e){return ti(Or(ur(pt(e)).reverse()))}function Vr(e,t){if(Et(t),t===0)throw new RangeError("zero length");e=qr(e);let r=e.toString(16);if(r.length>t*2)throw new RangeError("number too large");return or(r.padStart(t*2,"0"))}function oo(e,t){return Vr(e,t).reverse()}function ei(e,t){if(e=H(e),t=H(t),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}function ur(e){return Uint8Array.from(H(e))}function jr(e){if(typeof e!="string")throw new TypeError("ascii string expected, got "+typeof e);return Uint8Array.from(e,(t,r)=>{let n=t.charCodeAt(0);if(t.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${e[r]}" with code ${n} at position ${r}`);return n})}var Hr=e=>typeof e=="bigint"&&Mr<=e;function sf(e,t,r){return Hr(e)&&Hr(t)&&Hr(r)&&t<=e&&e<r}function Fe(e,t,r,n){if(!sf(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Oe(e){if(e<Mr)throw new Error("expected non-negative bigint, got "+e);let t;for(t=0;e>Mr;e>>=ro,t+=1);return t}var lr=e=>(ro<<BigInt(e))-ro;function ri(e,t,r){if(Et(e,"hashLen"),Et(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=d=>new Uint8Array(d),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,f=n(e),c=n(e),u=0,l=()=>{f.fill(1),c.fill(0),u=0},b=(...d)=>r(c,Q(f,...d)),p=(d=o)=>{c=b(s,d),f=b(),d.length!==0&&(c=b(i,d),f=b())},m=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let d=0,y=[];for(;d<t;){f=b();let S=f.slice();y.push(S),d+=f.length}return Q(...y)};return(d,y)=>{l(),p(d);let S;for(;(S=y(m()))===void 0;)p();return l(),S}}function _t(e,t={},r={}){if(Object.prototype.toString.call(e)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,i,a){if(!a&&i!=="function"&&!Object.hasOwn(e,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let f=e[s];if(a&&f===void 0)return;let c=typeof f;if(c!==i||f===null)throw new TypeError(`param "${s}" is invalid: expected ${i}, got ${c}`)}let o=(s,i)=>Object.entries(s).forEach(([a,f])=>n(a,f,i));o(t,!1),o(r,!0)}var so=()=>{throw new Error("not implemented")};var it=BigInt(0),G=BigInt(1),de=BigInt(2),ii=BigInt(3),ai=BigInt(4),ci=BigInt(5),af=BigInt(7),fi=BigInt(8),cf=BigInt(9),ui=BigInt(16);function W(e,t){if(t<=it)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=it?r:t+r}function Z(e,t,r){if(t<it)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >it;)n*=n,n%=r;return n}function ni(e,t){if(e===it)throw new Error("invert: expected non-zero number");if(t<=it)throw new Error("invert: expected positive modulus, got "+t);let r=W(e,t),n=t,o=it,s=G,i=G,a=it;for(;r!==it;){let c=n/r,u=n-r*c,l=o-i*c,b=s-a*c;n=r,r=u,o=i,s=a,i=l,a=b}if(n!==G)throw new Error("invert: does not exist");return W(o,t)}function io(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function li(e,t){let r=e,n=(r.ORDER+G)/ai,o=r.pow(t,n);return io(r,o,t),o}function ff(e,t){let r=e,n=(r.ORDER-ci)/fi,o=r.mul(t,de),s=r.pow(o,n),i=r.mul(t,s),a=r.mul(r.mul(i,de),s),f=r.mul(i,r.sub(a,r.ONE));return io(r,f,t),f}function uf(e){let t=ke(e),r=hi(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+af)/ui;return((a,f)=>{let c=a,u=c.pow(f,i),l=c.mul(u,n),b=c.mul(u,o),p=c.mul(u,s),m=c.eql(c.sqr(l),f),E=c.eql(c.sqr(b),f);u=c.cmov(u,l,m),l=c.cmov(p,b,E);let d=c.eql(c.sqr(l),f),y=c.cmov(u,l,d);return io(c,y,f),y})}function hi(e){if(e<ii)throw new Error("sqrt is not defined for small field");let t=e-G,r=0;for(;t%de===it;)t/=de,r++;let n=de,o=ke(e);for(;oi(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return li;let s=o.pow(n,t),i=(t+G)/de;return function(f,c){let u=f;if(u.is0(c))return c;if(oi(u,c)!==1)throw new Error("Cannot find square root");let l=r,b=u.mul(u.ONE,s),p=u.pow(c,t),m=u.pow(c,i);for(;!u.eql(p,u.ONE);){if(u.is0(p))return u.ZERO;let E=1,d=u.sqr(p);for(;!u.eql(d,u.ONE);)if(E++,d=u.sqr(d),E===l)throw new Error("Cannot find square root");let y=G<<BigInt(l-E-1),S=u.pow(b,y);l=E,b=u.sqr(S),p=u.mul(p,b),m=u.mul(m,S)}return m}}function lf(e){return e%ai===ii?li:e%fi===ci?ff:e%ui===cf?uf(e):hi(e)}var Mt=(e,t)=>(W(e,t)&G)===G,hf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ao(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=hf.reduce((n,o)=>(n[o]="function",n),t);if(_t(e,r),vt(e.BYTES,"BYTES"),vt(e.BITS,"BITS"),e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=G)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function df(e,t,r){let n=e;if(r<it)throw new Error("invalid exponent, negatives unsupported");if(r===it)return n.ONE;if(r===G)return t;let o=n.ONE,s=t;for(;r>it;)r&G&&(o=n.mul(o,s)),s=n.sqr(s),r>>=G;return o}function hr(e,t,r=!1){let n=e,o=new Array(t.length).fill(r?n.ZERO:void 0),s=t.reduce((a,f,c)=>n.is0(f)?a:(o[c]=a,n.mul(a,f)),n.ONE),i=n.inv(s);return t.reduceRight((a,f,c)=>n.is0(f)?a:(o[c]=n.mul(a,o[c]),n.mul(a,f)),i),o}function oi(e,t){let r=e,n=(r.ORDER-G)/de,o=r.pow(t,n),s=r.eql(o,r.ONE),i=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function pf(e,t){if(t!==void 0&&no(t),e<=it)throw new Error("invalid n length: expected positive n, got "+e);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let r=Oe(e);if(t!==void 0&&t<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${t})`);let n=t!==void 0?t:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var si=new WeakMap,zr=class{ORDER;BITS;BYTES;isLE;ZERO=it;ONE=G;_lengths;_mod;constructor(t,r={}){if(t<=G)throw new Error("invalid field: expected ORDER > 1, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=pf(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(t){return W(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return it<=t&&t<this.ORDER}is0(t){return t===it}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&G)===G}neg(t){return W(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return W(t*t,this.ORDER)}add(t,r){return W(t+r,this.ORDER)}sub(t,r){return W(t-r,this.ORDER)}mul(t,r){return W(t*r,this.ORDER)}pow(t,r){return df(this,t,r)}div(t,r){return W(t*ni(r,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,r){return t+r}subN(t,r){return t-r}mulN(t,r){return t*r}inv(t){return ni(t,this.ORDER)}sqrt(t){let r=si.get(this);return r||si.set(this,r=lf(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?oo(t,this.BYTES):Vr(t,this.BYTES)}fromBytes(t,r=!1){H(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(t.length<1||!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let c=new Uint8Array(o);c.set(t,s?0:c.length-t.length),t=c}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let f=s?Ct(t):he(t);if(a&&(f=W(f,i)),!r&&!this.isValid(f))throw new Error("invalid field element: outside of range 0..ORDER");return f}invertBatch(t){return hr(this,t)}cmov(t,r,n){return Bt(n,"condition"),n?r:t}};Object.freeze(zr.prototype);function ke(e,t={}){return new zr(e,t)}function di(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=G)throw new Error("field order must be greater than 1");let t=Oe(e-G);return Math.ceil(t/8)}function co(e){let t=di(e);return t+Math.ceil(t/2)}function fo(e,t,r=!1){H(e);let n=e.length,o=di(t),s=Math.max(co(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Ct(e):he(e),a=W(i,t-G)+G;return r?oo(a,o):Vr(a,o)}var Pe=BigInt(0),pe=BigInt(1);function dr(e,t){let r=t.negate();return e?r:t}function me(e,t){let r=hr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function bi(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function uo(e,t){bi(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=lr(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function pi(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(e&o),f=e>>i;a>n&&(a-=s,f+=pe);let c=t*n,u=c+Math.abs(a)-1,l=a===0,b=a<0,p=t%2!==0;return{nextN:f,offset:u,isZero:l,isNeg:b,isNegF:p,offsetF:c}}var lo=new WeakMap,xi=new WeakMap;function ho(e){return xi.get(e)||1}function mi(e){if(e!==Pe)throw new Error("invalid wNAF")}var Ne=class{BASE;ZERO;Fn;bits;constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>Pe;)r&pe&&(n=n.add(o)),o=o.double(),r>>=pe;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=uo(r,this.bits),s=[],i=t,a=i;for(let f=0;f<n;f++){a=i,s.push(a);for(let c=1;c<o;c++)a=a.add(i),s.push(a);i=a.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=uo(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:f,offset:c,isZero:u,isNeg:l,isNegF:b,offsetF:p}=pi(n,a,i);n=f,u?s=s.add(dr(b,r[p])):o=o.add(dr(l,r[c]))}return mi(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=uo(t,this.bits);for(let i=0;i<s.windows&&n!==Pe;i++){let{nextN:a,offset:f,isZero:c,isNeg:u}=pi(n,i,s);if(n=a,!c){let l=r[f];o=o.add(u?l.negate():l)}}return mi(n),o}getPrecomputes(t,r,n){let o=lo.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),lo.set(r,o))),o}cached(t,r,n){let o=ho(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=ho(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){bi(r,this.bits),xi.set(t,r),lo.delete(t)}hasCache(t){return ho(t)!==1}};function gi(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Pe||n>Pe;)r&pe&&(s=s.add(o)),n&pe&&(i=i.add(o)),o=o.double(),r>>=pe,n>>=pe;return{p1:s,p2:i}}function yi(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ao(t),t}else return ke(e,{isLE:r})}function Zr(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 c=t[f];if(!(typeof c=="bigint"&&c>Pe))throw new Error(`CURVE.${f} must be positive bigint`)}let o=yi(t.p,r.Fp,n),s=yi(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let f of a)if(!o.isValid(t[f]))throw new Error(`CURVE.${f} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function Yr(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var Gt=BigInt(0),nt=BigInt(1),po=BigInt(2),mf=BigInt(8);function yf(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),a=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,a)}function wi(e,t={}){let r=t,n=Zr("edwards",e,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;_t(r,{},{uvRatio:"function"});let f=po<<BigInt(s.BYTES*8)-nt,c=E=>o.create(E),u=r.uvRatio===void 0?(E,d)=>{try{return{isValid:!0,value:o.sqrt(o.div(E,d))}}catch{return{isValid:!1,value:Gt}}}:r.uvRatio;if(!yf(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function l(E,d,y=!1){let S=y?nt:Gt;return Fe("coordinate "+E,d,S,f),d}function b(E){if(!(E instanceof p))throw new Error("EdwardsPoint expected")}class p{static BASE=new p(i.Gx,i.Gy,nt,c(i.Gx*i.Gy));static ZERO=new p(Gt,nt,nt,Gt);static Fp=o;static Fn=s;X;Y;Z;T;constructor(d,y,S,v){this.X=l("x",d),this.Y=l("y",y),this.Z=l("z",S,!0),this.T=l("t",v),Object.freeze(this)}static CURVE(){return i}static fromAffine(d){if(d instanceof p)throw new Error("extended point not allowed");let{x:y,y:S}=d||{};return l("x",y),l("y",S),new p(y,S,nt,c(y*S))}static fromBytes(d,y=!1){let S=o.BYTES,{a:v,d:D}=i;d=ur(H(d,S,"point")),Bt(y,"zip215");let L=ur(d),U=d[S-1];L[S-1]=U&-129;let K=Ct(L),I=y?f:o.ORDER;Fe("point.y",K,Gt,I);let F=c(K*K),V=c(F-nt),O=c(D*F-v),{isValid:h,value:x}=u(V,O);if(!h)throw new Error("bad point: invalid y coordinate");let A=(x&nt)===nt,w=(U&128)!==0;if(!y&&x===Gt&&w)throw new Error("bad point: x=0 and x_0=1");return w!==A&&(x=c(-x)),p.fromAffine({x,y:K})}static fromHex(d,y=!1){return p.fromBytes(Ue(d),y)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(d=8,y=!0){return m.createCache(this,d),y||this.multiply(po),this}assertValidity(){let d=this,{a:y,d:S}=i;if(d.is0())throw new Error("bad point: ZERO");let{X:v,Y:D,Z:L,T:U}=d,K=c(v*v),I=c(D*D),F=c(L*L),V=c(F*F),O=c(K*y),h=c(F*c(O+I)),x=c(V+c(S*c(K*I)));if(h!==x)throw new Error("bad point: equation left != right (1)");let A=c(v*D),w=c(L*U);if(A!==w)throw new Error("bad point: equation left != right (2)")}equals(d){b(d);let{X:y,Y:S,Z:v}=this,{X:D,Y:L,Z:U}=d,K=c(y*U),I=c(D*v),F=c(S*U),V=c(L*v);return K===I&&F===V}is0(){return this.equals(p.ZERO)}negate(){return new p(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:d}=i,{X:y,Y:S,Z:v}=this,D=c(y*y),L=c(S*S),U=c(po*c(v*v)),K=c(d*D),I=y+S,F=c(c(I*I)-D-L),V=K+L,O=V-U,h=K-L,x=c(F*O),A=c(V*h),w=c(F*h),g=c(O*V);return new p(x,A,g,w)}add(d){b(d);let{a:y,d:S}=i,{X:v,Y:D,Z:L,T:U}=this,{X:K,Y:I,Z:F,T:V}=d,O=c(v*K),h=c(D*I),x=c(U*S*V),A=c(L*F),w=c((v+D)*(K+I)-O-h),g=A-x,B=A+x,T=c(h-y*O),_=c(w*g),R=c(B*T),C=c(w*T),N=c(g*B);return new p(_,R,N,C)}subtract(d){return b(d),this.add(d.negate())}multiply(d){if(!s.isValidNot0(d))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:y,f:S}=m.cached(this,d,v=>me(p,v));return me(p,[y,S])[0]}multiplyUnsafe(d){if(!s.isValid(d))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return d===Gt?p.ZERO:this.is0()||d===nt?this:m.unsafe(this,d,y=>me(p,y))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return m.unsafe(this,i.n).is0()}toAffine(d){let y=this,S=d,{X:v,Y:D,Z:L}=y,U=y.is0();S==null&&(S=U?mf:o.inv(L));let K=c(v*S),I=c(D*S),F=o.mul(L,S);if(U)return{x:Gt,y:nt};if(F!==nt)throw new Error("invZ was invalid");return{x:K,y:I}}clearCofactor(){return a===nt?this:this.multiplyUnsafe(a)}toBytes(){let{x:d,y}=this.toAffine(),S=o.toBytes(y);return S[S.length-1]|=d&nt?128:0,S}toHex(){return Ce(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let m=new Ne(p,s.BITS);return s.BITS>=8&&p.BASE.precompute(8),Object.freeze(p.prototype),Object.freeze(p),p}var $r=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(t){this.ep=t}static fromBytes(t){so()}static fromHex(t){so()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return Ce(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.ep.precompute(t,r),this}};function Ei(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=r;_t(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:f}=e,c=n.outputLen,u=2*a.BYTES;if(c!==void 0&&(vt(c,"hash.outputLen"),c!==u))throw new Error(`hash.outputLen must be ${u}, got ${c}`);let l=o.randomBytes===void 0?cr:o.randomBytes,b=o.adjustScalarBytes===void 0?h=>h:o.adjustScalarBytes,p=o.domain===void 0?(h,x,A)=>{if(Bt(A,"phflag"),x.length||A)throw new Error("Contexts/pre-hash are not supported");return h}:o.domain;function m(h){return f.create(Ct(h))}function E(h){let x=K.secretKey;H(h,K.secretKey,"secretKey");let A=H(n(h),2*x,"hashedSecretKey"),w=b(A.slice(0,x)),g=A.slice(x,2*x),B=m(w);return{head:w,prefix:g,scalar:B}}function d(h){let{head:x,prefix:A,scalar:w}=E(h),g=i.multiply(w),B=g.toBytes();return{head:x,prefix:A,scalar:w,point:g,pointBytes:B}}function y(h){return d(h).pointBytes}function S(h=Uint8Array.of(),...x){let A=Q(...x);return m(n(p(A,H(h,void 0,"context"),!!s)))}function v(h,x,A={}){h=H(h,void 0,"message"),s&&(h=s(h));let{prefix:w,scalar:g,pointBytes:B}=d(x),T=S(A.context,w,h),_=i.multiply(T).toBytes(),R=S(A.context,_,B,h),C=f.create(T+R*g);if(!f.isValid(C))throw new Error("sign failed: invalid s");let N=Q(_,f.toBytes(C));return H(N,K.signature,"result")}let D={zip215:o.zip215};function L(h,x,A,w=D){let{context:g}=w,B=w.zip215===void 0?!!D.zip215:w.zip215,T=K.signature;h=H(h,T,"signature"),x=H(x,void 0,"message"),A=H(A,K.publicKey,"publicKey"),B!==void 0&&Bt(B,"zip215"),s&&(x=s(x));let _=T/2,R=h.subarray(0,_),C=Ct(h.subarray(_,T)),N,q,P;try{N=e.fromBytes(A,B),q=e.fromBytes(R,B),P=i.multiplyUnsafe(C)}catch{return!1}if(!B&&N.isSmallOrder())return!1;let J=S(g,R,A,x);return q.add(N.multiplyUnsafe(J)).subtract(P).clearCofactor().is0()}let U=a.BYTES,K={secretKey:U,publicKey:U,signature:2*U,seed:U};function I(h){return h=h===void 0?l(K.seed):h,H(h,K.seed,"seed")}function F(h){return le(h)&&h.length===K.secretKey}function V(h,x){try{return!!e.fromBytes(h,x===void 0?D.zip215:x)}catch{return!1}}let O={getExtendedPublicKey:d,randomSecretKey:I,isValidSecretKey:F,isValidPublicKey:V,toMontgomery(h){let{y:x}=e.fromBytes(h),A=K.publicKey,w=A===32;if(!w&&A!==57)throw new Error("only defined for 25519 and 448");let g=w?a.div(nt+x,nt-x):a.div(x-nt,x+nt);return a.toBytes(g)},toMontgomerySecret(h){let x=K.secretKey;H(h,x);let A=n(h.subarray(0,x));return b(A).subarray(0,x)}};return Object.freeze(K),Object.freeze(O),Object.freeze({keygen:Yr(I,y),getPublicKey:y,sign:v,verify:L,utils:O,Point:e,lengths:K})}function pr(e,t){if(vt(e),vt(t),t<0||t>4)throw new Error("invalid I2OSP length: "+t);if(e<0||e>2**(8*t)-1)throw new Error("invalid I2OSP input: "+e);let r=Array.from({length:t}).fill(0);for(let n=t-1;n>=0;n--)r[n]=e&255,e>>>=8;return new Uint8Array(r)}function bf(e,t){let r=new Uint8Array(e.length);for(let n=0;n<e.length;n++)r[n]=e[n]^t[n];return r}function xf(e){if(!le(e)&&typeof e!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof e=="string"?jr(e):e;if(t.length===0)throw new Error("DST must be non-empty");return t}function mo(e,t,r,n){H(e),vt(r),t=xf(t),t.length>255&&(t=n(Q(jr("H2C-OVERSIZE-DST-"),t)));let{outputLen:o,blockLen:s}=n,i=Math.ceil(r/o);if(r>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=Q(t,pr(t.length,1)),f=new Uint8Array(s),c=pr(r,2),u=new Array(i),l=n(Q(f,e,c,pr(0,1),a));u[0]=n(Q(l,pr(1,1),a));for(let p=1;p<i;p++){let m=[bf(l,u[p-1]),pr(p+1,1),a];u[p]=n(Q(...m))}return Q(...u).slice(0,r)}var Si="HashToScalar-";var gf=BigInt(0),qt=BigInt(1),Ai=BigInt(2);var wf=BigInt(5),Ef=BigInt(8),He=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),go={p:He,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Ef,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Sf(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=He,a=e*e%s*e%s,f=Z(a,Ai,s)*a%s,c=Z(f,qt,s)*e%s,u=Z(c,wf,s)*c%s,l=Z(u,t,s)*u%s,b=Z(l,r,s)*l%s,p=Z(b,n,s)*b%s,m=Z(p,o,s)*p%s,E=Z(m,o,s)*p%s,d=Z(E,t,s)*u%s;return{pow_p_5_8:Z(d,Ai,s)*e%s,b2:a}}function Af(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var yo=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function wo(e,t){let r=He,n=W(t*t*t,r),o=W(n*n*t,r),s=Sf(e*o).pow_p_5_8,i=W(e*n*s,r),a=W(t*i*i,r),f=i,c=W(i*yo,r),u=a===e,l=a===W(-e,r),b=a===W(-e*yo,r);return u&&(i=f),(l||b)&&(i=c),Mt(i,r)&&(i=W(-i,r)),{isValid:u||l,value:i}}var Wt=wi(go,{uvRatio:wo}),Xt=Wt.Fp,_i=Wt.Fn;function Bf(e){return Ei(Wt,Ke,Object.assign({adjustScalarBytes:Af,zip215:!0},e))}var Me=Bf({});var bo=yo,vf=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),_f=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),If=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Tf=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Bi=e=>wo(qt,e),Lf=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),xo=e=>Xt.create(Ct(e)&Lf);function vi(e){let{d:t}=go,r=He,n=y=>Xt.create(y),o=n(bo*e*e),s=n((o+qt)*If),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:f,value:c}=wo(s,a),u=n(c*e);Mt(u,r)||(u=n(-u)),f||(c=u),f||(i=o);let l=n(i*(o-qt)*Tf-a),b=c*c,p=n((c+c)*a),m=n(l*vf),E=n(qt-b),d=n(qt+b);return new Wt(n(p*d),n(E*m),n(m*d),n(p*E))}var Jt=class e extends $r{static BASE=new e(Wt.BASE);static ZERO=new e(Wt.ZERO);static Fp=Xt;static Fn=_i;constructor(t){super(t)}static fromAffine(t){return new e(Wt.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static fromBytes(t){pt(t,32);let{a:r,d:n}=go,o=He,s=D=>Xt.create(D),i=xo(t);if(!ei(Xt.toBytes(i),t)||Mt(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),f=s(qt+r*a),c=s(qt-r*a),u=s(f*f),l=s(c*c),b=s(r*n*u-l),{isValid:p,value:m}=Bi(s(b*l)),E=s(m*c),d=s(m*E*b),y=s((i+i)*E);Mt(y,o)&&(y=s(-y));let S=s(f*d),v=s(y*S);if(!p||Mt(v,o)||S===gf)throw new Error("invalid ristretto255 encoding 2");return new e(new Wt(y,S,qt,v))}static fromHex(t){return e.fromBytes(or(t))}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=He,i=d=>Xt.create(d),a=i(i(n+r)*i(n-r)),f=i(t*r),c=i(f*f),{value:u}=Bi(i(a*c)),l=i(u*a),b=i(u*f),p=i(l*b*o),m;if(Mt(o*p,s)){let d=i(r*bo),y=i(t*bo);t=d,r=y,m=i(l*_f)}else m=b;Mt(t*p,s)&&(r=i(-r));let E=i((n-r)*m);return Mt(E,s)&&(E=i(-E)),Xt.toBytes(E)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=c=>Xt.create(c),a=i(r*s)===i(n*o),f=i(n*s)===i(r*o);return a||f}is0(){return this.equals(e.ZERO)}};Object.freeze(Jt.BASE);Object.freeze(Jt.ZERO);Object.freeze(Jt.prototype);Object.freeze(Jt);var Rf=Object.freeze({Point:Jt,hashToCurve(e,t){let r=t?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":t.DST,n=mo(e,r,64,Ke);return Rf.deriveToCurve(n)},hashToScalar(e,t={DST:Si}){let r=mo(e,t.DST,64,Ke);return _i.create(Ct(r))},deriveToCurve(e){pt(e,64);let t=xo(e.subarray(0,32)),r=vi(t),n=xo(e.subarray(32,64)),o=vi(n);return new Jt(r.add(o))}});var Qt=32,xt=64,Gr=32;var qe,Ii=(async()=>{try{return await Y.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function Ti(){let e=Me.utils.randomSecretKey(),t=Me.getPublicKey(e);return{privateKey:Ki(e,t),publicKey:t}}function Li(e){if(e.length!==Gr)throw new TypeError('"seed" must be 32 bytes in length.');if(!(e instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, or Uint8Array.');let t=e,r=Me.getPublicKey(t);return{privateKey:Ki(t,r),publicKey:r}}async function Df(e,t){let r;e.length===xt?r=e.subarray(0,32):r=e;let n={crv:"Ed25519",kty:"OKP",x:M(e.subarray(32),"base64url"),d:M(r,"base64url"),ext:!0,key_ops:["sign"]},o=await Y.get().subtle.importKey("jwk",n,{name:"Ed25519"},!0,["sign"]),s=await Y.get().subtle.sign({name:"Ed25519"},o,ot(t instanceof Uint8Array?t:t.subarray()));return new Uint8Array(s,0,s.byteLength)}function Kf(e,t){let r=e.subarray(0,Gr);return Me.sign(t instanceof Uint8Array?t:t.subarray(),r)}async function Ri(e,t){return qe==null&&(qe=await Ii),qe?Df(e,t):Kf(e,t)}async function Cf(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Y.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Y.get().subtle.verify({name:"Ed25519"},n,ot(t),ot(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Uf(e,t,r){return Me.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Di(e,t,r){return qe==null&&(qe=await Ii),qe?Cf(e,t,r):Uf(e,t,r)}function Ki(e,t){let r=new Uint8Array(xt);for(let n=0;n<Gr;n++)r[n]=e[n],r[Gr+n]=t[n];return r}function Eo(e,t){let r=z(e,"base64urlpad");if(t!=null){if(r.length>t)throw new Error("byte array longer than desired length");r=Dt([new Uint8Array(t-r.length),r])}return r}function Ve(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var mr=class{type="Ed25519";raw;constructor(t){this.raw=je(t,Qt)}toMultihash(){return se.digest(ae(this))}toCID(){return wt.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Di(this.raw,r,t);return Ve(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}},ye=class{type="Ed25519";raw;publicKey;constructor(t,r){this.raw=je(t,xt),this.publicKey=new mr(r)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}sign(t,r){r?.signal?.throwIfAborted();let n=Ri(this.raw,t);return Ve(n)?n.then(o=>(r?.signal?.throwIfAborted(),o)):(r?.signal?.throwIfAborted(),n)}};function So(e){if(e.length>xt){e=je(e,xt+Qt);let n=e.subarray(0,xt),o=e.subarray(xt,e.length);return new ye(n,o)}e=je(e,xt);let t=e.subarray(0,xt),r=e.subarray(Qt);return new ye(t,r)}function Xr(e){return e=je(e,Qt),new mr(e)}async function Ui(){let{privateKey:e,publicKey:t}=Ti();return new ye(e,t)}async function Fi(e){let{privateKey:t,publicKey:r}=Li(e);return new ye(t,r)}function je(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new k(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Ff=Math.pow(2,7),Of=Math.pow(2,14),kf=Math.pow(2,21),Oi=Math.pow(2,28),ki=Math.pow(2,35),Pi=Math.pow(2,42),Ni=Math.pow(2,49),ht=128,te=127;function yr(e){if(e<Ff)return 1;if(e<Of)return 2;if(e<kf)return 3;if(e<Oi)return 4;if(e<ki)return 5;if(e<Pi)return 6;if(e<Ni)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Hi(e,t,r=0){switch(yr(e)){case 8:t[r++]=e&255|ht,e/=128;case 7:t[r++]=e&255|ht,e/=128;case 6:t[r++]=e&255|ht,e/=128;case 5:t[r++]=e&255|ht,e/=128;case 4:t[r++]=e&255|ht,e>>>=7;case 3:t[r++]=e&255|ht,e>>>=7;case 2:t[r++]=e&255|ht,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Mi(e,t){let r=e[t],n=0;if(n+=r&te,r<ht||(r=e[t+1],n+=(r&te)<<7,r<ht)||(r=e[t+2],n+=(r&te)<<14,r<ht)||(r=e[t+3],n+=(r&te)<<21,r<ht)||(r=e[t+4],n+=(r&te)*Oi,r<ht)||(r=e[t+5],n+=(r&te)*ki,r<ht)||(r=e[t+6],n+=(r&te)*Pi,r<ht)||(r=e[t+7],n+=(r&te)*Ni,r<ht))return n;throw new RangeError("Could not decode varint")}var Ao=new Float32Array([-0]),ee=new Uint8Array(Ao.buffer);function qi(e,t,r){Ao[0]=e,t[r]=ee[0],t[r+1]=ee[1],t[r+2]=ee[2],t[r+3]=ee[3]}function Vi(e,t){return ee[0]=e[t],ee[1]=e[t+1],ee[2]=e[t+2],ee[3]=e[t+3],Ao[0]}var Bo=new Float64Array([-0]),ft=new Uint8Array(Bo.buffer);function ji(e,t,r){Bo[0]=e,t[r]=ft[0],t[r+1]=ft[1],t[r+2]=ft[2],t[r+3]=ft[3],t[r+4]=ft[4],t[r+5]=ft[5],t[r+6]=ft[6],t[r+7]=ft[7]}function zi(e,t){return ft[0]=e[t],ft[1]=e[t+1],ft[2]=e[t+2],ft[3]=e[t+3],ft[4]=e[t+4],ft[5]=e[t+5],ft[6]=e[t+6],ft[7]=e[t+7],Bo[0]}var Pf=BigInt(Number.MAX_SAFE_INTEGER),Nf=BigInt(Number.MIN_SAFE_INTEGER),gt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return be;if(t<Pf&&t>Nf)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Zi&&(o=0n,++n>Zi&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return be;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):be}},be=new gt(0,0);be.toBigInt=function(){return 0n};be.zzEncode=be.zzDecode=function(){return this};be.length=function(){return 1};var Zi=4294967296n;function Yi(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function $i(e,t,r){if(r-t<1)return"";let o,s=[],i=0,a;for(;t<r;)a=e[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function vo(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function It(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Wr(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var _o=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=ot(t),this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,It(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw It(this,4);return Wr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw It(this,4);return Wr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw It(this,4);let t=Vi(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw It(this,4);let t=zi(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw It(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return $i(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw It(this,t);this.pos+=t}else do if(this.pos>=this.len)throw It(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new gt(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw It(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw It(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw It(this,8);let t=Wr(this.buf,this.pos+=4),r=Wr(this.buf,this.pos+=4);return new gt(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Mi(this.buf,this.pos);return this.pos+=yr(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function br(e){return new _o(e instanceof Uint8Array?e:e.subarray())}function Jr(e,t,r){let n=br(e);return t.decode(n,void 0,r)}function Io(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return yt(i);o+i>t&&(n=yt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var xe=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function To(){}var Ro=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Hf=Io();function Mf(e){return globalThis.Buffer!=null?yt(e):Hf(e)}var gr=class{len;head;tail;states;constructor(){this.len=0,this.head=new xe(To,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new xe(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Do((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Qr,10,gt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=gt.fromBigInt(t);return this._push(Qr,r.length(),r)}uint64Number(t){return this._push(Hi,yr(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=gt.fromBigInt(t).zzEncode();return this._push(Qr,r.length(),r)}sint64Number(t){let r=gt.fromNumber(t).zzEncode();return this._push(Qr,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Lo,1,t?1:0)}fixed32(t){return this._push(xr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=gt.fromBigInt(t);return this._push(xr,4,r.lo)._push(xr,4,r.hi)}fixed64Number(t){let r=gt.fromNumber(t);return this._push(xr,4,r.lo)._push(xr,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(qi,4,t)}double(t){return this._push(ji,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Lo,1,0):this.uint32(r)._push(Vf,r,t)}string(t){let r=Yi(t);return r!==0?this.uint32(r)._push(vo,r,t):this._push(Lo,1,0)}fork(){return this.states=new Ro(this),this.head=this.tail=new xe(To,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new xe(To,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=Mf(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Lo(e,t,r){t[r]=e&255}function qf(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Do=class extends xe{next;constructor(t,r){super(qf,t,r),this.next=void 0}};function Qr(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function xr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function Vf(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(gr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(jf,t,e),this},gr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(zf,t,e),this});function jf(e,t,r){t.set(e,r)}function zf(e,t,r){e.length<40?vo(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(z(e),r)}function Ko(){return new gr}function tn(e,t){let r=Ko();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*en(e,t,r){let n=br(e);yield*t.stream(n,void 0,"$",r)}var rn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function nn(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function Co(e){function t(s){if(e[s.toString()]==null)throw new Error("Invalid enum value");return e[s]}let r=function(i,a){let f=t(i);a.int32(f)},n=function(i){let a=i.int32();return t(a)},o=function*(i){let a=i.int32();yield t(a)};return nn("enum",rn.VARINT,r,n,o)}function on(e,t,r){return nn("message",rn.LENGTH_DELIMITED,e,t,r)}var j;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(j||(j={}));var Uo;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Uo||(Uo={}));(function(e){e.codec=()=>Co(Uo)})(j||(j={}));var Ut;(function(e){let t;e.codec=()=>(t==null&&(t=on((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),j.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let f={},c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{f.Type=j.codec().decode(s);break}case 2:{f.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return f},function*(s,i,a,f={}){let c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:j.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return tn(s,e.codec())}e.encode=r;function n(s,i){return Jr(s,e.codec(),i)}e.decode=n;function o(s,i){return en(s,e.codec(),i)}e.stream=o})(Ut||(Ut={}));var wr;(function(e){let t;e.codec=()=>(t==null&&(t=on((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),j.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let f={},c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{f.Type=j.codec().decode(s);break}case 2:{f.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return f},function*(s,i,a,f={}){let c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:j.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return tn(s,e.codec())}e.encode=r;function n(s,i){return Jr(s,e.codec(),i)}e.decode=n;function o(s,i){return en(s,e.codec(),i)}e.stream=o})(wr||(wr={}));function Fo(e){if(isNaN(e)||e<=0)throw new k("random bytes length must be a Number bigger than 0");return crypto.getRandomValues(new Uint8Array(e))}var Sr={};at(Sr,{MAX_RSA_KEY_SIZE:()=>Oo,generateRSAKeyPair:()=>Vo,jwkToJWKKeyPair:()=>Qi,jwkToPkcs1:()=>Gf,jwkToPkix:()=>Ho,jwkToRSAPrivateKey:()=>cn,pkcs1MessageToJwk:()=>Po,pkcs1MessageToRSAPrivateKey:()=>sn,pkcs1ToJwk:()=>$f,pkcs1ToRSAPrivateKey:()=>Mo,pkixMessageToJwk:()=>No,pkixMessageToRSAPublicKey:()=>an,pkixToJwk:()=>Xf,pkixToRSAPublicKey:()=>qo});var ze=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Sr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return wt.createV1(114,this._multihash)}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,r,n){return Ji(this.jwk,r,t,n)}},Er=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Sr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}sign(t,r){return Wi(this.jwk,t,r)}};var Oo=8192,ko=18,Zf=1062,Yf=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function $f(e){let t=bt(e);return Po(t)}function Po(e){return{n:M(e[1],"base64url"),e:M(e[2],"base64url"),d:M(e[3],"base64url"),p:M(e[4],"base64url"),q:M(e[5],"base64url"),dp:M(e[6],"base64url"),dq:M(e[7],"base64url"),qi:M(e[8],"base64url"),kty:"RSA"}}function Gf(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new k("JWK was missing components");return St([lt(Uint8Array.from([0])),lt(z(e.n,"base64url")),lt(z(e.e,"base64url")),lt(z(e.d,"base64url")),lt(z(e.p,"base64url")),lt(z(e.q,"base64url")),lt(z(e.dp,"base64url")),lt(z(e.dq,"base64url")),lt(z(e.qi,"base64url"))]).subarray()}function Xf(e){let t=bt(e,{offset:0});return No(t)}function No(e){let t=bt(e[1],{offset:0});return{kty:"RSA",n:M(t[0],"base64url"),e:M(t[1],"base64url")}}function Ho(e){if(e.n==null||e.e==null)throw new k("JWK was missing components");return St([Yf,nr(St([lt(z(e.n,"base64url")),lt(z(e.e,"base64url"))]))]).subarray()}function Mo(e){let t=bt(e);return sn(t)}function sn(e){let t=Po(e);return cn(t)}function qo(e,t){if(e.byteLength>=Zf)throw new we("Key size is too large");let r=bt(e,{offset:0});return an(r,e,t)}function an(e,t,r){let n=No(e);if(r==null){let o=$t(Ut.encode({Type:j.RSA,Data:t}));r=Rt(ko,o)}return new ze(n,r)}function cn(e){if(ea(e)>Oo)throw new k("Key size is too large");let t=Qi(e),r=$t(Ut.encode({Type:j.RSA,Data:Ho(t.publicKey)})),n=Rt(ko,r);return new Er(t.privateKey,new ze(t.publicKey,n))}async function Vo(e){if(e>Oo)throw new k("Key size is too large");let t=await ta(e),r=$t(Ut.encode({Type:j.RSA,Data:Ho(t.publicKey)})),n=Rt(ko,r);return new Er(t.privateKey,new ze(t.publicKey,n))}function Qi(e){if(e==null)throw new k("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}var ra="1.2.840.113549.1.1.1";async function ta(e,t){let r=await Y.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Wf(r,t);return{privateKey:n[0],publicKey:n[1]}}async function Wi(e,t,r){let n=await Y.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Y.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,ot(t instanceof Uint8Array?t:t.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Ji(e,t,r,n){let o=await Y.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Y.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,ot(t),ot(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),s}async function Wf(e,t){if(e.privateKey==null||e.publicKey==null)throw new k("Private and public key are required");let r=await Promise.all([Y.get().subtle.exportKey("jwk",e.privateKey),Y.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function ea(e){if(e.kty!=="RSA")throw new k("invalid key type");if(e.n==null)throw new k("invalid key modulus");return z(e.n,"base64url").length*8}var fn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(Le(t),pt(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),mt(o)}update(t){return Re(this),this.iHash.update(t),this}digestInto(t){Re(this),Ur(t,this),this.finished=!0;let r=t.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,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()}},un=(()=>{let e=((t,r,n)=>new fn(t,r).update(n).digest());return e.create=(t,r)=>new fn(t,r),e})();var na=(e,t)=>(e+(e>=0?t:-t)/oa)/t;function Jf(e,t,r){Fe("scalar",e,Ft,r);let[[n,o],[s,i]]=t,a=na(i*e,r),f=na(-o*e,r),c=e-a*n-f*s,u=-a*o-f*i,l=c<Ft,b=u<Ft;l&&(c=-c),b&&(u=-u);let p=lr(Math.ceil(Oe(r)/2))+re;if(c<Ft||c>=p||u<Ft||u>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:c,k2neg:b,k2:u}}function zo(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function jo(e,t){_t(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return Bt(r.lowS,"lowS"),Bt(r.prehash,"prehash"),r.format!==void 0&&zo(r.format),r}var Zo=class extends Error{constructor(t=""){super(t)}},Tt={Err:Zo,_tlv:{encode:(e,t)=>{let{Err:r}=Tt;if(vt(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(typeof t!="string")throw new TypeError('"data" expected string, got type='+typeof t);if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=fr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?fr(o.length/2|128):"";return fr(e)+s+o+t},decode(e,t){let{Err:r}=Tt;t=H(t,void 0,"DER data");let n=0;if(e<0||e>255)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),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 c=t.subarray(n,n+f);if(c.length!==f)throw new r("tlv.decode: length bytes not complete");if(c[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of c)i=i<<8|u;if(n+=f,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Tt;if(qr(e),e<Ft)throw new t("integer: negative integers are not allowed");let r=fr(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=Tt;if(e.length<1)throw new t("invalid signature integer: empty");if(e[0]&128)throw new t("invalid signature integer: negative");if(e.length>1&&e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return he(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Tt,o=H(e,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:f}=n.decode(2,s),{v:c,l:u}=n.decode(2,f);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(c)}},hexFromSig(e){let{_tlv:t,_int:r}=Tt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}};Object.freeze(Tt._tlv);Object.freeze(Tt._int);Object.freeze(Tt);var Ft=BigInt(0),re=BigInt(1),oa=BigInt(2),ln=BigInt(3),Qf=BigInt(4);function sa(e,t={}){let r=Zr("weierstrass",e,t),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;_t(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:f,allowInfinityPoint:c}=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=aa(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function b(O,h,x){if(c&&h.is0())return Uint8Array.of(0);let{x:A,y:w}=h.toAffine(),g=n.toBytes(A);if(Bt(x,"isCompressed"),x){l();let B=!n.isOdd(w);return Q(ia(B),g)}else return Q(Uint8Array.of(4),g,n.toBytes(w))}function p(O){H(O,void 0,"Point");let{publicKey:h,publicKeyUncompressed:x}=u,A=O.length,w=O[0],g=O.subarray(1);if(c&&A===1&&w===0)return{x:n.ZERO,y:n.ZERO};if(A===h&&(w===2||w===3)){let B=n.fromBytes(g);if(!n.isValid(B))throw new Error("bad point: is not on curve, wrong x");let T=d(B),_;try{_=n.sqrt(T)}catch(N){let q=N instanceof Error?": "+N.message:"";throw new Error("bad point: is not on curve, sqrt error"+q)}l();let R=n.isOdd(_);return(w&1)===1!==R&&(_=n.neg(_)),{x:B,y:_}}else if(A===x&&w===4){let B=n.BYTES,T=n.fromBytes(g.subarray(0,B)),_=n.fromBytes(g.subarray(B,B*2));if(!y(T,_))throw new Error("bad point: is not on curve");return{x:T,y:_}}else throw new Error(`bad point: got length ${A}, expected compressed=${h} or uncompressed=${x}`)}let m=t.toBytes===void 0?b:t.toBytes,E=t.fromBytes===void 0?p:t.fromBytes;function d(O){let h=n.sqr(O),x=n.mul(h,O);return n.add(n.add(x,n.mul(O,s.a)),s.b)}function y(O,h){let x=n.sqr(h),A=d(O);return n.eql(x,A)}if(!y(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let S=n.mul(n.pow(s.a,ln),Qf),v=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(S,v)))throw new Error("bad curve params: a or b");function D(O,h,x=!1){if(!n.isValid(h)||x&&n.is0(h))throw new Error(`bad point coordinate ${O}`);return h}function L(O){if(!(O instanceof I))throw new Error("Weierstrass Point expected")}function U(O){if(!f||!f.basises)throw new Error("no endo");return Jf(O,f.basises,o.ORDER)}function K(O,h,x,A,w){return x=new I(n.mul(x.X,O),x.Y,x.Z),h=dr(A,h),x=dr(w,x),h.add(x)}class I{static BASE=new I(s.Gx,s.Gy,n.ONE);static ZERO=new I(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(h,x,A){this.X=D("x",h),this.Y=D("y",x,!0),this.Z=D("z",A),Object.freeze(this)}static CURVE(){return s}static fromAffine(h){let{x,y:A}=h||{};if(!h||!n.isValid(x)||!n.isValid(A))throw new Error("invalid affine point");if(h instanceof I)throw new Error("projective point not allowed");return n.is0(x)&&n.is0(A)?I.ZERO:new I(x,A,n.ONE)}static fromBytes(h){let x=I.fromAffine(E(H(h,void 0,"point")));return x.assertValidity(),x}static fromHex(h){return I.fromBytes(Ue(h))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=8,x=!0){return V.createCache(this,h),x||this.multiply(ln),this}assertValidity(){let h=this;if(h.is0()){if(t.allowInfinityPoint&&n.is0(h.X)&&n.eql(h.Y,n.ONE)&&n.is0(h.Z))return;throw new Error("bad point: ZERO")}let{x,y:A}=h.toAffine();if(!n.isValid(x)||!n.isValid(A))throw new Error("bad point: x or y not field elements");if(!y(x,A))throw new Error("bad point: equation left != right");if(!h.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:h}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(h)}equals(h){L(h);let{X:x,Y:A,Z:w}=this,{X:g,Y:B,Z:T}=h,_=n.eql(n.mul(x,T),n.mul(g,w)),R=n.eql(n.mul(A,T),n.mul(B,w));return _&&R}negate(){return new I(this.X,n.neg(this.Y),this.Z)}double(){let{a:h,b:x}=s,A=n.mul(x,ln),{X:w,Y:g,Z:B}=this,T=n.ZERO,_=n.ZERO,R=n.ZERO,C=n.mul(w,w),N=n.mul(g,g),q=n.mul(B,B),P=n.mul(w,g);return P=n.add(P,P),R=n.mul(w,B),R=n.add(R,R),T=n.mul(h,R),_=n.mul(A,q),_=n.add(T,_),T=n.sub(N,_),_=n.add(N,_),_=n.mul(T,_),T=n.mul(P,T),R=n.mul(A,R),q=n.mul(h,q),P=n.sub(C,q),P=n.mul(h,P),P=n.add(P,R),R=n.add(C,C),C=n.add(R,C),C=n.add(C,q),C=n.mul(C,P),_=n.add(_,C),q=n.mul(g,B),q=n.add(q,q),C=n.mul(q,P),T=n.sub(T,C),R=n.mul(q,N),R=n.add(R,R),R=n.add(R,R),new I(T,_,R)}add(h){L(h);let{X:x,Y:A,Z:w}=this,{X:g,Y:B,Z:T}=h,_=n.ZERO,R=n.ZERO,C=n.ZERO,N=s.a,q=n.mul(s.b,ln),P=n.mul(x,g),J=n.mul(A,B),tt=n.mul(w,T),et=n.add(x,A),X=n.add(g,B);et=n.mul(et,X),X=n.add(P,J),et=n.sub(et,X),X=n.add(x,w);let dt=n.add(g,T);return X=n.mul(X,dt),dt=n.add(P,tt),X=n.sub(X,dt),dt=n.add(A,w),_=n.add(B,T),dt=n.mul(dt,_),_=n.add(J,tt),dt=n.sub(dt,_),C=n.mul(N,X),_=n.mul(q,tt),C=n.add(_,C),_=n.sub(J,C),C=n.add(J,C),R=n.mul(_,C),J=n.add(P,P),J=n.add(J,P),tt=n.mul(N,tt),X=n.mul(q,X),J=n.add(J,tt),tt=n.sub(P,tt),tt=n.mul(N,tt),X=n.add(X,tt),P=n.mul(J,X),R=n.add(R,P),P=n.mul(dt,X),_=n.mul(et,_),_=n.sub(_,P),P=n.mul(et,J),C=n.mul(dt,C),C=n.add(C,P),new I(_,R,C)}subtract(h){return L(h),this.add(h.negate())}is0(){return this.equals(I.ZERO)}multiply(h){let{endo:x}=t;if(!o.isValidNot0(h))throw new RangeError("invalid scalar: out of range");let A,w,g=B=>V.cached(this,B,T=>me(I,T));if(x){let{k1neg:B,k1:T,k2neg:_,k2:R}=U(h),{p:C,f:N}=g(T),{p:q,f:P}=g(R);w=N.add(P),A=K(x.beta,C,q,B,_)}else{let{p:B,f:T}=g(h);A=B,w=T}return me(I,[A,w])[0]}multiplyUnsafe(h){let{endo:x}=t,A=this,w=h;if(!o.isValid(w))throw new RangeError("invalid scalar: out of range");if(w===Ft||A.is0())return I.ZERO;if(w===re)return A;if(V.hasCache(this))return this.multiply(w);if(x){let{k1neg:g,k1:B,k2neg:T,k2:_}=U(w),{p1:R,p2:C}=gi(I,A,B,_);return K(x.beta,R,C,g,T)}else return V.unsafe(A,w)}toAffine(h){let x=this,A=h,{X:w,Y:g,Z:B}=x;if(n.eql(B,n.ONE))return{x:w,y:g};let T=x.is0();A==null&&(A=T?n.ONE:n.inv(B));let _=n.mul(w,A),R=n.mul(g,A),C=n.mul(B,A);if(T)return{x:n.ZERO,y:n.ZERO};if(!n.eql(C,n.ONE))throw new Error("invZ was invalid");return{x:_,y:R}}isTorsionFree(){let{isTorsionFree:h}=t;return i===re?!0:h?h(I,this):V.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:h}=t;return i===re?this:h?h(I,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===re?this.is0():this.clearCofactor().is0()}toBytes(h=!0){return Bt(h,"isCompressed"),this.assertValidity(),m(I,this,h)}toHex(h=!0){return Ce(this.toBytes(h))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let F=o.BITS,V=new Ne(I,t.endo?Math.ceil(F/2):F);return F>=8&&I.BASE.precompute(8),Object.freeze(I.prototype),Object.freeze(I),I}function ia(e){return Uint8Array.of(e?2:3)}function aa(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function tu(e,t={}){let{Fn:r}=e,n=t.randomBytes===void 0?cr:t.randomBytes,o=Object.assign(aa(e.Fp,r),{seed:Math.max(co(r.ORDER),16)});function s(p){try{let m=r.fromBytes(p);return r.isValidNot0(m)}catch{return!1}}function i(p,m){let{publicKey:E,publicKeyUncompressed:d}=o;try{let y=p.length;return m===!0&&y!==E||m===!1&&y!==d?!1:!!e.fromBytes(p)}catch{return!1}}function a(p){return p=p===void 0?n(o.seed):p,fo(H(p,o.seed,"seed"),r.ORDER)}function f(p,m=!0){return e.BASE.multiply(r.fromBytes(p)).toBytes(m)}function c(p){let{secretKey:m,publicKey:E,publicKeyUncompressed:d}=o,y=r._lengths;if(!le(p))return;let S=H(p,void 0,"key").length,v=S===E||S===d,D=S===m||!!y?.includes(S);if(!(v&&D))return v}function u(p,m,E=!0){if(c(p)===!0)throw new Error("first arg must be private key");if(c(m)===!1)throw new Error("second arg must be public key");let d=r.fromBytes(p);return e.fromBytes(m).multiply(d).toBytes(E)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},b=Yr(a,f);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:f,getSharedSecret:u,keygen:b,Point:e,utils:l,lengths:o})}function ca(e,t,r={}){let n=t;Le(n),_t(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?cr:r.randomBytes,s=r.hmac===void 0?(w,g)=>un(n,w,g):r.hmac,{Fp:i,Fn:a}=e,{ORDER:f,BITS:c}=a,{keygen:u,getPublicKey:l,getSharedSecret:b,utils:p,lengths:m}=tu(e,r),E={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},d=f*oa+re<i.ORDER;function y(w){let g=f>>re;return w>g}function S(w,g){if(!a.isValidNot0(g))throw new Error(`invalid signature ${w}: out of range 1..Point.Fn.ORDER`);return g}function v(){if(d)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function D(w,g){zo(g);let B=m.signature,T=g==="compact"?B:g==="recovered"?B+1:void 0;return H(w,T)}class L{r;s;recovery;constructor(g,B,T){if(this.r=S("r",g),this.s=S("s",B),T!=null){if(v(),![0,1,2,3].includes(T))throw new Error("invalid recovery id");this.recovery=T}Object.freeze(this)}static fromBytes(g,B=E.format){D(g,B);let T;if(B==="der"){let{r:N,s:q}=Tt.toSig(H(g));return new L(N,q)}B==="recovered"&&(T=g[0],B="compact",g=g.subarray(1));let _=m.signature/2,R=g.subarray(0,_),C=g.subarray(_,_*2);return new L(a.fromBytes(R),a.fromBytes(C),T)}static fromHex(g,B){return this.fromBytes(Ue(g),B)}assertRecovery(){let{recovery:g}=this;if(g==null)throw new Error("invalid recovery id: must be present");return g}addRecoveryBit(g){return new L(this.r,this.s,g)}recoverPublicKey(g){let{r:B,s:T}=this,_=this.assertRecovery(),R=_===2||_===3?B+f:B;if(!i.isValid(R))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let C=i.toBytes(R),N=e.fromBytes(Q(ia((_&1)===0),C)),q=a.inv(R),P=K(H(g,void 0,"msgHash")),J=a.create(-P*q),tt=a.create(T*q),et=e.BASE.multiplyUnsafe(J).add(N.multiplyUnsafe(tt));if(et.is0())throw new Error("invalid recovery: point at infinify");return et.assertValidity(),et}hasHighS(){return y(this.s)}toBytes(g=E.format){if(zo(g),g==="der")return Ue(Tt.hexFromSig(this));let{r:B,s:T}=this,_=a.toBytes(B),R=a.toBytes(T);return g==="recovered"?(v(),Q(Uint8Array.of(this.assertRecovery()),_,R)):Q(_,R)}toHex(g){return Ce(this.toBytes(g))}}Object.freeze(L.prototype),Object.freeze(L);let U=r.bits2int===void 0?function(g){if(g.length>8192)throw new Error("input is too large");let B=he(g),T=g.length*8-c;return T>0?B>>BigInt(T):B}:r.bits2int,K=r.bits2int_modN===void 0?function(g){return a.create(U(g))}:r.bits2int_modN,I=lr(c);function F(w){return Fe("num < 2^"+c,w,Ft,I),a.toBytes(w)}function V(w,g){return H(w,void 0,"message"),g?H(n(w),void 0,"prehashed message"):w}function O(w,g,B){let{lowS:T,prehash:_,extraEntropy:R}=jo(B,E);w=V(w,_);let C=K(w),N=a.fromBytes(g);if(!a.isValidNot0(N))throw new Error("invalid private key");let q=[F(N),F(C)];if(R!=null&&R!==!1){let et=R===!0?o(m.secretKey):R;q.push(H(et,void 0,"extraEntropy"))}let P=Q(...q),J=C;function tt(et){let X=U(et);if(!a.isValidNot0(X))return;let dt=a.inv(X),ge=e.BASE.multiply(X).toAffine(),Ze=a.create(ge.x);if(Ze===Ft)return;let _r=a.create(dt*a.create(J+Ze*N));if(_r===Ft)return;let ts=(ge.x===Ze?0:2)|Number(ge.y&re),es=_r;return T&&y(_r)&&(es=a.neg(_r),ts^=1),new L(Ze,es,d?void 0:ts)}return{seed:P,k2sig:tt}}function h(w,g,B={}){let{seed:T,k2sig:_}=O(w,g,B);return ri(n.outputLen,a.BYTES,s)(T,_).toBytes(B.format)}function x(w,g,B,T={}){let{lowS:_,prehash:R,format:C}=jo(T,E);if(B=H(B,void 0,"publicKey"),g=V(g,R),!le(w)){let N=w instanceof L?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+N)}D(w,C);try{let N=L.fromBytes(w,C),q=e.fromBytes(B);if(_&&N.hasHighS())return!1;let{r:P,s:J}=N,tt=K(g),et=a.inv(J),X=a.create(tt*et),dt=a.create(P*et),ge=e.BASE.multiplyUnsafe(X).add(q.multiplyUnsafe(dt));return ge.is0()?!1:a.create(ge.x)===P}catch{return!1}}function A(w,g,B={}){let{prehash:T}=jo(B,E);return g=V(g,T),L.fromBytes(w,"recovered").recoverPublicKey(g).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:b,utils:p,lengths:m,Point:e,sign:h,verify:x,recoverPublicKey:A,Signature:L,hash:n})}var $o={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},eu={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var fa=BigInt(2);function ru(e){let t=$o.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),f=BigInt(88),c=e*e*e%t,u=c*c*e%t,l=Z(u,r,t)*u%t,b=Z(l,r,t)*u%t,p=Z(b,fa,t)*c%t,m=Z(p,o,t)*p%t,E=Z(m,s,t)*m%t,d=Z(E,a,t)*E%t,y=Z(d,f,t)*d%t,S=Z(y,a,t)*E%t,v=Z(S,r,t)*u%t,D=Z(v,i,t)*m%t,L=Z(D,n,t)*c%t,U=Z(L,fa,t);if(!Yo.eql(Yo.sqr(U),e))throw new Error("Cannot find square root");return U}var Yo=ke($o.p,{sqrt:ru}),nu=sa($o,{Fp:Yo,endo:eu}),Lt=ca(nu,$t);var ua=33,la=32;function ha(e,t,r){let n=Dr.digest(t instanceof Uint8Array?t:t.subarray());if(Ve(n))return n.then(({digest:o})=>(r?.signal?.throwIfAborted(),Lt.sign(o,e,{prehash:!1,format:"der"}))).catch(o=>{throw o.name==="AbortError"?o:new Ye(String(o))});try{return Lt.sign(n.digest,e,{prehash:!1,format:"der"})}catch(o){throw new Ye(String(o))}}function da(e,t,r,n){let o=Dr.digest(r instanceof Uint8Array?r:r.subarray());if(Ve(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Lt.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new $e(String(s))});try{return n?.signal?.throwIfAborted(),Lt.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new $e(String(s))}}var Ar=class{type="secp256k1";raw;_key;constructor(t){this._key=ya(t),this.raw=pa(this._key)}toMultihash(){return se.digest(ae(this))}toCID(){return wt.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,r,n){return da(this._key,r,t,n)}},Br=class{type="secp256k1";raw;publicKey;constructor(t,r){this.raw=ma(t),this.publicKey=new Ar(r??ba(t))}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}sign(t,r){return ha(this.raw,t,r)}};function Go(e){return new Br(e)}function hn(e){return new Ar(e)}async function xa(){let e=ou();return new Br(e)}function pa(e){return Lt.Point.fromBytes(e).toBytes()}function ma(e){try{return Lt.getPublicKey(e,!0),e}catch(t){throw new Ge(String(t))}}function ya(e){try{return Lt.Point.fromBytes(e),e}catch(t){throw new we(String(t))}}function ba(e){try{return Lt.getPublicKey(e,!0)}catch(t){throw new Ge(String(t))}}function ou(){return Lt.utils.randomSecretKey()}var dn={"P-256":32,"P-384":48,"P-521":66},su=Object.keys(dn),Xo=su.join(" / ");async function ga(e){if(e!=="P-256"&&e!=="P-384"&&e!=="P-521")throw new k(`Unknown curve: ${e}. Must be ${Xo}`);let t=await Y.get().subtle.generateKey({name:"ECDH",namedCurve:e},!0,["deriveBits"]),r=async(s,i)=>{let a;i!=null?a=await Y.get().subtle.importKey("jwk",au(e,i),{name:"ECDH",namedCurve:e},!1,["deriveBits"]):a=t.privateKey;let f=await Y.get().subtle.importKey("jwk",wa(e,s),{name:"ECDH",namedCurve:e},!1,[]),c=await Y.get().subtle.deriveBits({name:"ECDH",public:f},a,dn[e]*8);return new Uint8Array(c,0,c.byteLength)},n=await Y.get().subtle.exportKey("jwk",t.publicKey);return{key:iu(n),genSharedKey:r}}function iu(e){if(e.crv==null||e.x==null||e.y==null)throw new k("JWK was missing components");if(e.crv!=="P-256"&&e.crv!=="P-384"&&e.crv!=="P-521")throw new k(`Unknown curve: ${e.crv}. Must be ${Xo}`);let t=dn[e.crv];return Dt([Uint8Array.from([4]),Eo(e.x,t),Eo(e.y,t)],1+t*2)}function wa(e,t){if(e!=="P-256"&&e!=="P-384"&&e!=="P-521")throw new k(`Unknown curve: ${e}. Must be ${Xo}`);let r=dn[e];if(!ct(t.subarray(0,1),Uint8Array.from([4])))throw new k("Cannot unmarshal public key - invalid key format");return{kty:"EC",crv:e,x:M(t.subarray(1,r+1),"base64url"),y:M(t.subarray(1+r),"base64url"),ext:!0}}var au=(e,t)=>({...wa(e,t.public),d:M(t.private,"base64url")});var cu={"AES-128":{ivSize:16,keySize:16},"AES-256":{ivSize:16,keySize:32},Blowfish:{ivSize:8,keySize:32}};async function Ea(e,t,r){if(e!=="AES-128"&&e!=="AES-256"&&e!=="Blowfish")throw new k("Cipher type was missing or unsupported");if(t!=="SHA1"&&t!=="SHA256"&&t!=="SHA512")throw new k("Hash type was missing or unsupported");if(r==null||!(r instanceof Uint8Array))throw new k("Secret was missing or an incorrect type");let n=cu[e],o=n.keySize,s=n.ivSize,i=20,a=z("key expansion"),f=2*(s+o+i),c=await mn(t,r),u=await c.digest(a),l=[],b=0;for(;b<f;){let S=await c.digest(Dt([u,a])),v=S.length;b+v>f&&(v=f-b),l.push(S),b+=v,u=await c.digest(u)}let p=f/2,m=Dt(l),E=m.subarray(0,p),d=m.subarray(p,f),y=S=>({iv:S.subarray(0,s),cipherKey:S.subarray(s,s+o),macKey:S.subarray(s+o)});return{k1:y(E),k2:y(d)}}async function fu(e,t){if(e==="Ed25519")return Ui();if(e==="secp256k1")return xa();if(e==="RSA")return Vo(bu(t));if(e==="ECDSA")return Hs(xu(t));throw new Vt}async function uu(e,t){if(e!=="Ed25519")throw new Vt("Seed key derivation only supported for Ed25519 keys");return Fi(t)}function lu(e,t){let{Type:r,Data:n}=Ut.decode(e),o=n??new Uint8Array;switch(r){case j.RSA:return qo(o,t);case j.Ed25519:return Xr(o);case j.secp256k1:return hn(o);case j.ECDSA:return jn(o);default:throw new Vt}}function hu(e){if(e.byteLength===Qt)return Xr(e);if(e.byteLength===ua)return hn(e);let t=bt(e),r=t[1]?.[0];if(r===_n||r===In||r===Tn)return zn(t);if(t[0]?.[0]===ra)return an(t,e);throw new k("Could not extract public key from raw bytes")}function du(e){let{Type:t,Data:r}=Ut.decode(e.digest),n=r??new Uint8Array;switch(t){case j.Ed25519:return Xr(n);case j.secp256k1:return hn(n);case j.ECDSA:return jn(n);default:throw new Vt}}function ae(e){return Ut.encode({Type:j[e.type],Data:e.raw})}function pu(e){let t=wr.decode(e),r=t.Data??new Uint8Array;switch(t.Type){case j.RSA:return Mo(r);case j.Ed25519:return So(r);case j.secp256k1:return Go(r);case j.ECDSA:return Os(r);default:throw new Vt}}function mu(e){if(e.byteLength===xt)return So(e);if(e.byteLength===la)return Go(e);let t=bt(e),r=t[2]?.[0];if(r===_n||r===In||r===Tn)return Vn(t);if(t.length>8)return sn(t);throw new k("Could not extract private key from raw bytes")}function yu(e){return wr.encode({Type:j[e.type],Data:e.raw})}function bu(e){return e==null?2048:parseInt(e,10)}function xu(e){if(e==="P-256"||e==null)return"P-256";if(e==="P-384")return"P-384";if(e==="P-521")return"P-521";throw new k("Unsupported curve, should be P-256, P-384 or P-521")}async function gu(e){if(e.type==="RSA")return{privateKey:await crypto.subtle.importKey("jwk",e.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",e.publicKey.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])};if(e.type==="ECDSA")return{privateKey:await crypto.subtle.importKey("jwk",e.jwk,{name:"ECDSA",namedCurve:e.jwk.crv??"P-256"},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",e.publicKey.jwk,{name:"ECDSA",namedCurve:e.publicKey.jwk.crv??"P-256"},!0,["verify"])};throw new k("Only RSA and ECDSA keys are supported")}async function wu(e){if(e.privateKey.algorithm.name==="RSASSA-PKCS1-v1_5"){let t=await crypto.subtle.exportKey("jwk",e.privateKey);return cn(t)}if(e.privateKey.algorithm.name==="ECDSA"){let t=await crypto.subtle.exportKey("jwk",e.privateKey);return new Pt(t)}throw new k("Only RSA and ECDSA keys are supported")}var vr=Uint32Array.from([1732584193,4023233417,2562383102,271733878,3285377520]),ne=new Uint32Array(80),Jo=class extends ce{A=vr[0]|0;B=vr[1]|0;C=vr[2]|0;D=vr[3]|0;E=vr[4]|0;constructor(){super(64,20,8,!1)}get(){let{A:t,B:r,C:n,D:o,E:s}=this;return[t,r,n,o,s]}set(t,r,n,o,s){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0}process(t,r){for(let f=0;f<16;f++,r+=4)ne[f]=t.getUint32(r,!1);for(let f=16;f<80;f++)ne[f]=Fr(ne[f-3]^ne[f-8]^ne[f-14]^ne[f-16],1);let{A:n,B:o,C:s,D:i,E:a}=this;for(let f=0;f<80;f++){let c,u;f<20?(c=kr(o,s,i),u=1518500249):f<40?(c=o^s^i,u=1859775393):f<60?(c=Pr(o,s,i),u=2400959708):(c=o^s^i,u=3395469782);let l=Fr(n,5)+c+a+u+ne[f]|0;a=i,i=s,s=Fr(o,30),o=n,n=l}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,this.set(n,o,s,i,a)}roundClean(){mt(ne)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0),mt(this.buffer)}},Sa=sr(()=>new Jo);function Eu(e,t,r,n){Le(e);let o=Vs({dkLen:32,asyncTick:10},n),{c:s,dkLen:i,asyncTick:a}=o;if(Et(s,"c"),Et(i,"dkLen"),Et(a,"asyncTick"),s<1)throw new Error("iterations (c) must be >= 1");if(i<1)throw new Error('"dkLen" must be >= 1');if(i>(2**32-1)*e.outputLen)throw new Error("derived key too long");let f=Yn(t,"password"),c=Yn(r,"salt"),u=new Uint8Array(i),l=un.create(e,f),b=l._cloneInto().update(c);return{c:s,dkLen:i,asyncTick:a,DK:u,PRF:l,PRFSalt:b}}function Su(e,t,r,n,o){return e.destroy(),t.destroy(),n&&n.destroy(),mt(o),r}function Aa(e,t,r,n){let{c:o,dkLen:s,DK:i,PRF:a,PRFSalt:f}=Eu(e,t,r,n),c,u=new Uint8Array(4),l=De(u),b=new Uint8Array(a.outputLen);for(let p=1,m=0;m<s;p++,m+=a.outputLen){let E=i.subarray(m,m+a.outputLen);l.setInt32(0,p,!1),(c=f._cloneInto(c)).update(u).digestInto(b),E.set(b.subarray(0,E.length));for(let d=1;d<o;d++){a._cloneInto(c).update(b).digestInto(b);for(let y=0;y<E.length;y++)E[y]^=b[y]}}return Su(a,f,i,c,b)}var Ba={sha1:Sa,"sha2-256":$t,"sha2-512":Ke};function Qo(e,t,r,n,o){if(o!=="sha1"&&o!=="sha2-256"&&o!=="sha2-512"){let a=Object.keys(Ba).join(" / ");throw new k(`Hash '${o}' is unknown or not supported. Must be ${a}`)}let s=Ba[o],i=Aa(s,e,t,{c:r,dkLen:n});return Cn.encode(i).substring(1)}return La(Au);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/curves/utils.js: