@libp2p/crypto 5.1.8-da78fa851 → 5.1.8-e8398d97e

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.
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 un=Object.defineProperty;var da=Object.getOwnPropertyDescriptor;var pa=Object.getOwnPropertyNames;var ma=Object.prototype.hasOwnProperty;var st=(e,t)=>{for(var r in t)un(e,r,{get:t[r],enumerable:!0})},ya=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of pa(t))!ma.call(e,o)&&o!==r&&un(e,o,{get:()=>t[o],enumerable:!(n=da(t,o))||n.enumerable});return e};var ba=e=>ya(un({},"__esModule",{value:!0}),e);var mu={};st(mu,{hmac:()=>Ir,keys:()=>qo,pbkdf2:()=>Vo,randomBytes:()=>vo});var Ir={};st(Ir,{create:()=>hn});var Ye=class extends Error{constructor(t="An error occurred while signing a message"){super(t),this.name="SigningError"}},Xe=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},_r=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Zo={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new _r("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 G=Zo;var zo={SHA1:20,SHA256:32,SHA512:64};var xa={SHA1:"SHA-1",SHA256:"SHA-256",SHA512:"SHA-512"},ga=async(e,t)=>{let r=await G.get().subtle.sign({name:"HMAC"},e,t);return new Uint8Array(r,0,r.byteLength)};async function hn(e,t){let r=xa[e],n=await G.get().subtle.importKey("raw",t,{name:"HMAC",hash:{name:r}},!1,["sign"]);return{async digest(o){return ga(n,o)},length:zo[e]}}var qo={};st(qo,{generateEphemeralKeyPair:()=>sa,generateKeyPair:()=>eu,generateKeyPairFromSeed:()=>ru,keyStretcher:()=>aa,privateKeyFromCryptoKeyPair:()=>lu,privateKeyFromProtobuf:()=>iu,privateKeyFromRaw:()=>au,privateKeyToCryptoKeyPair:()=>hu,privateKeyToProtobuf:()=>cu,publicKeyFromMultihash:()=>su,publicKeyFromProtobuf:()=>nu,publicKeyFromRaw:()=>ou,publicKeyToProtobuf:()=>ue});var N=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Ee=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}},$e=class extends Error{static name="InvalidPrivateKeyError";constructor(t="Invalid private key"){super(t),this.name="InvalidPrivateKeyError"}};var Yt=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var yn={};st(yn,{base58btc:()=>tt,base58flickr:()=>_a});var _u=new Uint8Array(0);function Go(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 Dt(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 Yo(e){return new TextEncoder().encode(e)}function Xo(e){return new TextDecoder().decode(e)}function wa(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 c=e.length,a=e.charAt(0),u=Math.log(c)/Math.log(256),d=Math.log(256)/Math.log(c);function l(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var E=0,A=0,b=0,B=h.length;b!==B&&h[b]===0;)b++,E++;for(var g=(B-b)*d+1>>>0,U=new Uint8Array(g);b!==B;){for(var D=h[b],O=0,H=g-1;(D!==0||O<A)&&H!==-1;H--,O++)D+=256*U[H]>>>0,U[H]=D%c>>>0,D=D/c>>>0;if(D!==0)throw new Error("Non-zero carry");A=O,b++}for(var R=g-A;R!==g&&U[R]===0;)R++;for(var w=a.repeat(E);R<g;++R)w+=e.charAt(U[R]);return w}function f(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var E=0;if(h[E]!==" "){for(var A=0,b=0;h[E]===a;)A++,E++;for(var B=(h.length-E)*u+1>>>0,g=new Uint8Array(B);h[E];){var U=r[h.charCodeAt(E)];if(U===255)return;for(var D=0,O=B-1;(U!==0||D<b)&&O!==-1;O--,D++)U+=c*g[O]>>>0,g[O]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");b=D,E++}if(h[E]!==" "){for(var H=B-b;H!==B&&g[H]===0;)H++;for(var R=new Uint8Array(A+(B-H)),w=A;H!==B;)R[w++]=g[H++];return R}}}function p(h){var E=f(h);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:f,decode:p}}var Ea=wa,Sa=Ea,Wo=Sa;var ln=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")}},dn=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 Jo(this,t)}},pn=class{decoders;constructor(t){this.decoders=t}or(t){return Jo(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 Jo(e,t){return new pn({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var mn=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 ln(t,r,n),this.decoder=new dn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Se({name:e,prefix:t,encode:r,decode:n}){return new mn(e,t,r,n)}function Xt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Wo(r,e);return Se({prefix:t,name:e,encode:n,decode:s=>Dt(o(s))})}function Aa(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,c=0,a=0;for(let u=0;u<o;++u){let d=t[e[u]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|d,i+=r,i>=8&&(i-=8,s[a++]=255&c>>i)}if(i>=r||(255&c<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Ba(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,c=0;for(let a=0;a<e.length;++a)for(c=c<<8|e[a],i+=8;i>r;)i-=r,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function va(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function W({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=va(n);return Se({prefix:t,name:e,encode(s){return Ba(s,n,r)},decode(s){return Aa(s,o,r,e)}})}var tt=Xt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),_a=Xt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var bn={};st(bn,{base32:()=>Ae,base32hex:()=>Ua,base32hexpad:()=>Ca,base32hexpadupper:()=>Da,base32hexupper:()=>Ta,base32pad:()=>Ka,base32padupper:()=>La,base32upper:()=>Ia,base32z:()=>Ra});var Ae=W({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ia=W({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ka=W({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),La=W({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ua=W({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ta=W({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ca=W({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Da=W({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ra=W({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var xn={};st(xn,{base36:()=>We,base36upper:()=>Pa});var We=Xt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Pa=Xt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ka=es,Qo=128,Na=127,Ha=~Na,Oa=Math.pow(2,31);function es(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Oa;)t[r++]=e&255|Qo,e/=128;for(;e&Ha;)t[r++]=e&255|Qo,e>>>=7;return t[r]=e|0,es.bytes=r-n+1,t}var Ma=gn,qa=128,ts=127;function gn(e,n){var r=0,n=n||0,o=0,s=n,i,c=e.length;do{if(s>=c)throw gn.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&ts)<<o:(i&ts)*Math.pow(2,o),o+=7}while(i>=qa);return gn.bytes=s-n,r}var Va=Math.pow(2,7),Fa=Math.pow(2,14),ja=Math.pow(2,21),Za=Math.pow(2,28),za=Math.pow(2,35),Ga=Math.pow(2,42),Ya=Math.pow(2,49),Xa=Math.pow(2,56),$a=Math.pow(2,63),Wa=function(e){return e<Va?1:e<Fa?2:e<ja?3:e<Za?4:e<za?5:e<Ga?6:e<Ya?7:e<Xa?8:e<$a?9:10},Ja={encode:ka,decode:Ma,encodingLength:Wa},Qa=Ja,Je=Qa;function Qe(e,t=0){return[Je.decode(e,t),Je.decode.bytes]}function Be(e,t,r=0){return Je.encode(e,t,r),t}function ve(e){return Je.encodingLength(e)}function Lt(e,t){let r=t.byteLength,n=ve(e),o=n+ve(r),s=new Uint8Array(o+r);return Be(e,s,0),Be(r,s,n),s.set(t,o),new _e(e,r,t,s)}function rs(e){let t=Dt(e),[r,n]=Qe(t),[o,s]=Qe(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new _e(r,o,i,t)}function ns(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Go(e.bytes,r.bytes)}}var _e=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function os(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return ec(r,wn(e),t??tt.encoder);default:return rc(r,wn(e),t??Ae.encoder)}}var ss=new WeakMap;function wn(e){let t=ss.get(e);if(t==null){let r=new Map;return ss.set(e,r),r}return t}var At=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!==er)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==nc)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&&ns(t.multihash,n.multihash)}toString(t){return os(this,t)}toJSON(){return{"/":os(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??is(n,o,s.bytes))}else if(r[oc]===!0){let{version:n,multihash:o,code:s}=r,i=rs(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!==er)throw new Error(`Version 0 CID must use dag-pb (code: ${er}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=is(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,er,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=Dt(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 _e(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,f]=Qe(t.subarray(r));return r+=f,l},o=n(),s=er;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,c=n(),a=n(),u=r+a,d=u-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:d,size:u}}static parse(t,r){let[n,o]=tc(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 wn(s).set(n,t),s}};function tc(e,t){switch(e[0]){case"Q":{let r=t??tt;return[tt.prefix,r.decode(`${tt.prefix}${e}`)]}case tt.prefix:{let r=t??tt;return[tt.prefix,r.decode(e)]}case Ae.prefix:{let r=t??Ae;return[Ae.prefix,r.decode(e)]}case We.prefix:{let r=t??We;return[We.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 ec(e,t,r){let{prefix:n}=r;if(n!==tt.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 rc(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 er=112,nc=18;function is(e,t,r){let n=ve(e),o=n+ve(t),s=new Uint8Array(o+r.byteLength);return Be(e,s,0),Be(t,s,n),s.set(r,o),s}var oc=Symbol.for("@ipld/js-cid/CID");var En={};st(En,{identity:()=>ce});var as=0,sc="identity",cs=Dt;function ic(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(as,cs(e))}var ce={code:as,name:sc,encode:cs,digest:ic};function it(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 Rt(e=0){return new Uint8Array(e)}function yt(e=0){return new Uint8Array(e)}function Ut(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 r}var us=Symbol.for("@achingbrain/uint8arraylist");function fs(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 Lr(e){return!!e?.[us]}var ct=class e{bufs;length;[us]=!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(Lr(n))r+=n.byteLength,this.bufs.push(...n.bufs);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(Lr(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=fs(this.bufs,t);return r.buf[r.index]}set(t,r){let n=fs(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(Lr(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 Ut(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Ut(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],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let u=t>=c&&t<a,d=r>c&&r<=a;if(u&&d){if(t===c&&r===a){n.push(i);break}let l=t-c;n.push(i.subarray(l,l+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(d){if(r===a){n.push(i);break}n.push(i.subarray(0,r-c));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Lr(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 c=i,a=this.byteLength-n.byteLength,u=n.byteLength-1,d;for(let l=r;l<=a;l+=d){d=0;for(let f=u;f>=0;f--){let p=this.get(l+f);if(n[f]!==p){d=Math.max(1,f-c[p]);break}}if(d===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=Rt(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=Rt(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=Rt(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=Rt(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=Rt(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=Rt(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=Rt(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=Rt(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(!it(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 Sn={};st(Sn,{base10:()=>ac});var ac=Xt({prefix:"9",name:"base10",alphabet:"0123456789"});var An={};st(An,{base16:()=>cc,base16upper:()=>fc});var cc=W({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),fc=W({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Bn={};st(Bn,{base2:()=>uc});var uc=W({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var vn={};st(vn,{base256emoji:()=>mc});var hs=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}"),hc=hs.reduce((e,t,r)=>(e[r]=t,e),[]),lc=hs.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function dc(e){return e.reduce((t,r)=>(t+=hc[r],t),"")}function pc(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=lc[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var mc=Se({prefix:"\u{1F680}",name:"base256emoji",encode:dc,decode:pc});var In={};st(In,{base64:()=>_n,base64pad:()=>yc,base64url:()=>bc,base64urlpad:()=>xc});var _n=W({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),yc=W({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),bc=W({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),xc=W({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Kn={};st(Kn,{base8:()=>gc});var gc=W({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ln={};st(Ln,{identity:()=>wc});var wc=Se({prefix:"\0",name:"identity",encode:e=>Xo(e),decode:e=>Yo(e)});var fh=new TextEncoder,uh=new TextDecoder;var Cn={};st(Cn,{sha256:()=>Ur,sha512:()=>Bc});var Ac=20;function Tn({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Un(e,t,r,n,o)}var Un=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Ac,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?ls(n,this.code,r?.truncate):n.then(o=>ls(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function ls(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 ps(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Ur=Tn({name:"sha2-256",code:18,encode:ps("SHA-256")}),Bc=Tn({name:"sha2-512",code:19,encode:ps("SHA-512")});var Dn={...Ln,...Bn,...Kn,...Sn,...An,...bn,...xn,...yn,...In,...vn},Sh={...Cn,...En};function ys(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var ms=ys("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Rn=ys("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}),vc={utf8:ms,"utf-8":ms,hex:Dn.base16,latin1:Rn,ascii:Rn,binary:Rn,...Dn},Tr=vc;function Z(e,t="utf8"){let r=Tr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function q(e,t="utf8"){let r=Tr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var _c=parseInt("11111",2),Pn=parseInt("10000000",2),Ic=parseInt("01111111",2),bs={0:rr,1:rr,2:Kc,3:Tc,4:Cc,5:Uc,6:Lc,16:rr,22:rr,48:rr};function bt(e,t={offset:0}){let r=e[t.offset]&_c;if(t.offset++,bs[r]!=null)return bs[r](e,t);throw new Error("No decoder for tag "+r)}function nr(e,t){let r=0;if((e[t.offset]&Pn)===Pn){let n=e[t.offset]&Ic,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 rr(e,t){nr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=bt(e,t);if(n===null)break;r.push(n)}return r}function Kc(e,t){let r=nr(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 Lc(e,t){let r=nr(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 c=`${s}.${i}`,a=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,a.push(u&127),u<128){a.reverse();let d=0;for(let l=0;l<a.length;l++)d+=a[l]<<l*7;c+=`.${d}`,a=[]}}return c}function Uc(e,t){return t.offset++,null}function Tc(e,t){let r=nr(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 Cc(e,t){let r=nr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Dc(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new ct;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=Dc(e.byteLength);return new ct(Uint8Array.from([t.byteLength|Pn]),t)}function ft(e){let t=new ct,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new ct(Uint8Array.from([2]),Cr(t),t)}function or(e){let t=Uint8Array.from([0]),r=new ct(t,e);return new ct(Uint8Array.from([3]),Cr(r),r)}function xs(e){return new ct(Uint8Array.from([4]),Cr(e),e)}function vt(e,t=48){let r=new ct;for(let n of e)r.append(n);return new ct(Uint8Array.from([t]),Cr(r),r)}var kn="1.2.840.10045.3.1.7",Nn="1.3.132.0.34",Hn="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}var Rc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Pc=Uint8Array.from([6,5,43,129,4,0,34]),kc=Uint8Array.from([6,5,43,129,4,0,35]),Ss={ext:!0,kty:"EC",crv:"P-256"},As={ext:!0,kty:"EC",crv:"P-384"},Bs={ext:!0,kty:"EC",crv:"P-521"},Ie=32,Ke=48,Le=66;function vs(e){let t=bt(e);return On(t)}function On(e){let t=e[1],r=q(t,"base64url"),n=e[2][1][0],o=1,s,i;if(t.byteLength===Ie)return s=q(n.subarray(o,o+Ie),"base64url"),i=q(n.subarray(o+Ie),"base64url"),new Pt({...Ss,key_ops:["sign"],d:r,x:s,y:i});if(t.byteLength===Ke)return s=q(n.subarray(o,o+Ke),"base64url"),i=q(n.subarray(o+Ke),"base64url"),new Pt({...As,key_ops:["sign"],d:r,x:s,y:i});if(t.byteLength===Le)return s=q(n.subarray(o,o+Le),"base64url"),i=q(n.subarray(o+Le),"base64url"),new Pt({...Bs,key_ops:["sign"],d:r,x:s,y:i});throw new N(`Private key length was wrong length, got ${t.byteLength}, expected 32, 48 or 66`)}function Mn(e){let t=bt(e);return qn(t)}function qn(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Ie*2+1)return n=q(t.subarray(r,r+Ie),"base64url"),o=q(t.subarray(r+Ie),"base64url"),new fe({...Ss,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ke*2+1)return n=q(t.subarray(r,r+Ke),"base64url"),o=q(t.subarray(r+Ke),"base64url"),new fe({...As,key_ops:["verify"],x:n,y:o});if(t.byteLength===Le*2+1)return n=q(t.subarray(r,r+Le),"base64url"),o=q(t.subarray(r+Le),"base64url"),new fe({...Bs,key_ops:["verify"],x:n,y:o});throw new N(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function _s(e){return vt([ft(Uint8Array.from([1])),xs(Z(e.d??"","base64url")),vt([Ks(e.crv)],160),vt([or(new ct(Uint8Array.from([4]),Z(e.x??"","base64url"),Z(e.y??"","base64url")))],161)]).subarray()}function Is(e){return vt([ft(Uint8Array.from([1])),vt([Ks(e.crv)],160),vt([or(new ct(Uint8Array.from([4]),Z(e.x??"","base64url"),Z(e.y??"","base64url")))],161)]).subarray()}function Ks(e){if(e==="P-256")return Rc;if(e==="P-384")return Pc;if(e==="P-521")return kc;throw new N(`Invalid curve ${e}`)}async function Ls(e="P-256"){let t=await gs(e);return new Pt(t.privateKey)}var fe=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Is(this.jwk)),this._raw}toMultihash(){return ce.digest(ue(this))}toCID(){return At.createV1(114,this.toMultihash())}toString(){return tt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:it(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 fe({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=_s(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:it(this.raw,t.raw)}async sign(t,r){return ws(this.jwk,t,r)}};var he=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Ht(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Nt(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function ut(e,...t){if(!Ht(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Te(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Nt(e.outputLen),Nt(e.blockLen)}function Ce(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 Ts(e,t){ut(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+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 _t(e,t){return e<<32-t|e>>>t}function Dr(e,t){return e<<t|e>>>32-t>>>0}var Cs=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Nc=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Bt(e){if(ut(e),Cs)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Nc[e[r]];return t}var kt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Us(e){if(e>=kt._0&&e<=kt._9)return e-kt._0;if(e>=kt.A&&e<=kt.F)return e-(kt.A-10);if(e>=kt.a&&e<=kt.f)return e-(kt.a-10)}function le(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Cs)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=Us(e.charCodeAt(s)),c=Us(e.charCodeAt(s+1));if(i===void 0||c===void 0){let a=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function Rr(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function sr(e){return typeof e=="string"&&(e=Rr(e)),ut(e),e}function Vn(e){return typeof e=="string"&&(e=Rr(e)),ut(e),e}function ht(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];ut(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 Ds(e,t){if(t!==void 0&&{}.toString.call(t)!=="[object Object]")throw new Error("options should be object or undefined");return Object.assign(e,t)}var Ue=class{};function ir(e){let t=n=>e().update(sr(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function $t(e=32){if(he&&typeof he.getRandomValues=="function")return he.getRandomValues(new Uint8Array(e));if(he&&typeof he.randomBytes=="function")return Uint8Array.from(he.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function Hc(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),c=Number(r&s),a=n?4:0,u=n?0:4;e.setUint32(t+a,i,n),e.setUint32(t+u,c,n)}function Pr(e,t,r){return e&t^~e&r}function kr(e,t,r){return e&t^e&r^t&r}var de=class extends Ue{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=De(this.buffer)}update(t){Ce(this),t=sr(t),ut(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=De(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ce(this),Ts(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;Hc(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=De(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=a/4,d=this.get();if(u>d.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)c.setUint32(4*l,d[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||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Ot=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var nt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Nr=BigInt(4294967295),Rs=BigInt(32);function Oc(e,t=!1){return t?{h:Number(e&Nr),l:Number(e>>Rs&Nr)}:{h:Number(e>>Rs&Nr)|0,l:Number(e&Nr)|0}}function Ps(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:c}=Oc(e[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var Fn=(e,t,r)=>e>>>r,jn=(e,t,r)=>e<<32-r|t>>>r,pe=(e,t,r)=>e>>>r|t<<32-r,me=(e,t,r)=>e<<32-r|t>>>r,ar=(e,t,r)=>e<<64-r|t>>>r-32,cr=(e,t,r)=>e>>>r-32|t<<64-r;function Tt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var ks=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Ns=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Hs=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Os=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Ms=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),qs=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var qc=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]),Wt=new Uint32Array(64),Hr=class extends de{constructor(t=32){super(64,t,8,!1),this.A=Ot[0]|0,this.B=Ot[1]|0,this.C=Ot[2]|0,this.D=Ot[3]|0,this.E=Ot[4]|0,this.F=Ot[5]|0,this.G=Ot[6]|0,this.H=Ot[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,r,n,o,s,i,c,a]}set(t,r,n,o,s,i,c,a){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(t,r){for(let l=0;l<16;l++,r+=4)Wt[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let f=Wt[l-15],p=Wt[l-2],h=_t(f,7)^_t(f,18)^f>>>3,E=_t(p,17)^_t(p,19)^p>>>10;Wt[l]=E+Wt[l-7]+h+Wt[l-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:u,H:d}=this;for(let l=0;l<64;l++){let f=_t(c,6)^_t(c,11)^_t(c,25),p=d+f+Pr(c,a,u)+qc[l]+Wt[l]|0,E=(_t(n,2)^_t(n,13)^_t(n,22))+kr(n,o,s)|0;d=u,u=a,a=c,c=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,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,d=d+this.H|0,this.set(n,o,s,i,c,a,u,d)}roundClean(){mt(Wt)}destroy(){this.set(0,0,0,0,0,0,0,0),mt(this.buffer)}};var Vs=Ps(["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))),Vc=Vs[0],Fc=Vs[1],Jt=new Uint32Array(80),Qt=new Uint32Array(80),Or=class extends de{constructor(t=64){super(128,t,16,!1),this.Ah=nt[0]|0,this.Al=nt[1]|0,this.Bh=nt[2]|0,this.Bl=nt[3]|0,this.Ch=nt[4]|0,this.Cl=nt[5]|0,this.Dh=nt[6]|0,this.Dl=nt[7]|0,this.Eh=nt[8]|0,this.El=nt[9]|0,this.Fh=nt[10]|0,this.Fl=nt[11]|0,this.Gh=nt[12]|0,this.Gl=nt[13]|0,this.Hh=nt[14]|0,this.Hl=nt[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:u,El:d,Fh:l,Fl:f,Gh:p,Gl:h,Hh:E,Hl:A}=this;return[t,r,n,o,s,i,c,a,u,d,l,f,p,h,E,A]}set(t,r,n,o,s,i,c,a,u,d,l,f,p,h,E,A){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=c|0,this.Dl=a|0,this.Eh=u|0,this.El=d|0,this.Fh=l|0,this.Fl=f|0,this.Gh=p|0,this.Gl=h|0,this.Hh=E|0,this.Hl=A|0}process(t,r){for(let g=0;g<16;g++,r+=4)Jt[g]=t.getUint32(r),Qt[g]=t.getUint32(r+=4);for(let g=16;g<80;g++){let U=Jt[g-15]|0,D=Qt[g-15]|0,O=pe(U,D,1)^pe(U,D,8)^Fn(U,D,7),H=me(U,D,1)^me(U,D,8)^jn(U,D,7),R=Jt[g-2]|0,w=Qt[g-2]|0,K=pe(R,w,19)^ar(R,w,61)^Fn(R,w,6),P=me(R,w,19)^cr(R,w,61)^jn(R,w,6),L=Hs(H,P,Qt[g-7],Qt[g-16]),x=Os(L,O,K,Jt[g-7],Jt[g-16]);Jt[g]=x|0,Qt[g]=L|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:u,Dl:d,Eh:l,El:f,Fh:p,Fl:h,Gh:E,Gl:A,Hh:b,Hl:B}=this;for(let g=0;g<80;g++){let U=pe(l,f,14)^pe(l,f,18)^ar(l,f,41),D=me(l,f,14)^me(l,f,18)^cr(l,f,41),O=l&p^~l&E,H=f&h^~f&A,R=Ms(B,D,H,Fc[g],Qt[g]),w=qs(R,b,U,O,Vc[g],Jt[g]),K=R|0,P=pe(n,o,28)^ar(n,o,34)^ar(n,o,39),L=me(n,o,28)^cr(n,o,34)^cr(n,o,39),x=n&s^n&c^s&c,m=o&i^o&a^i&a;b=E|0,B=A|0,E=p|0,A=h|0,p=l|0,h=f|0,{h:l,l:f}=Tt(u|0,d|0,w|0,K|0),u=c|0,d=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let y=ks(K,L,m);n=Ns(y,w,P,x),o=y|0}({h:n,l:o}=Tt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Tt(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=Tt(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l:d}=Tt(this.Dh|0,this.Dl|0,u|0,d|0),{h:l,l:f}=Tt(this.Eh|0,this.El|0,l|0,f|0),{h:p,l:h}=Tt(this.Fh|0,this.Fl|0,p|0,h|0),{h:E,l:A}=Tt(this.Gh|0,this.Gl|0,E|0,A|0),{h:b,l:B}=Tt(this.Hh|0,this.Hl|0,b|0,B|0),this.set(n,o,s,i,c,a,u,d,l,f,p,h,E,A,b,B)}roundClean(){mt(Jt,Qt)}destroy(){mt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Mr=ir(()=>new Hr);var qr=ir(()=>new Or);var Gn=BigInt(0),zn=BigInt(1);function Mt(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function xt(e,t,r=""){let n=Ht(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,c=s?` of length ${t}`:"",a=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+c+", got "+a)}return e}function fr(e){let t=e.toString(16);return t.length&1?"0"+t:t}function Fs(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Gn:BigInt("0x"+e)}function Re(e){return Fs(Bt(e))}function qt(e){return ut(e),Fs(Bt(Uint8Array.from(e).reverse()))}function Vr(e,t){return le(e.toString(16).padStart(t*2,"0"))}function Yn(e,t){return Vr(e,t).reverse()}function V(e,t,r){let n;if(typeof t=="string")try{n=le(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(Ht(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}function js(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function Xn(e){return Uint8Array.from(e)}var Zn=e=>typeof e=="bigint"&&Gn<=e;function Zs(e,t,r){return Zn(e)&&Zn(t)&&Zn(r)&&t<=e&&e<r}function ur(e,t,r,n){if(!Zs(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Fr(e){let t;for(t=0;e>Gn;e>>=zn,t+=1);return t}var te=e=>(zn<<BigInt(e))-zn;function zs(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=p=>new Uint8Array(p),o=p=>Uint8Array.of(p),s=n(e),i=n(e),c=0,a=()=>{s.fill(1),i.fill(0),c=0},u=(...p)=>r(i,s,...p),d=(p=n(0))=>{i=u(o(0),p),s=u(),p.length!==0&&(i=u(o(1),p),s=u())},l=()=>{if(c++>=1e3)throw new Error("drbg: tried 1000 values");let p=0,h=[];for(;p<t;){s=u();let E=s.slice();h.push(E),p+=s.length}return ht(...h)};return(p,h)=>{a(),d(p);let E;for(;!(E=h(l()));)d();return a(),E}}function ee(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let c=e[o];if(i&&c===void 0)return;let a=typeof c;if(a!==s||c===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${a}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}var $n=()=>{throw new Error("not implemented")};function Pe(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var lt=BigInt(0),et=BigInt(1),ye=BigInt(2),Xs=BigInt(3),$s=BigInt(4),Ws=BigInt(5),jc=BigInt(7),Js=BigInt(8),Zc=BigInt(9),Qs=BigInt(16);function J(e,t){let r=e%t;return r>=lt?r:t+r}function z(e,t,r){let n=e;for(;t-- >lt;)n*=n,n%=r;return n}function Gs(e,t){if(e===lt)throw new Error("invert: expected non-zero number");if(t<=lt)throw new Error("invert: expected positive modulus, got "+t);let r=J(e,t),n=t,o=lt,s=et,i=et,c=lt;for(;r!==lt;){let u=n/r,d=n%r,l=o-i*u,f=s-c*u;n=r,r=d,o=i,s=c,i=l,c=f}if(n!==et)throw new Error("invert: does not exist");return J(o,t)}function Wn(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function ti(e,t){let r=(e.ORDER+et)/$s,n=e.pow(t,r);return Wn(e,n,t),n}function zc(e,t){let r=(e.ORDER-Ws)/Js,n=e.mul(t,ye),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,ye),o),c=e.mul(s,e.sub(i,e.ONE));return Wn(e,c,t),c}function Gc(e){let t=gt(e),r=ei(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+jc)/Qs;return(c,a)=>{let u=c.pow(a,i),d=c.mul(u,n),l=c.mul(u,o),f=c.mul(u,s),p=c.eql(c.sqr(d),a),h=c.eql(c.sqr(l),a);u=c.cmov(u,d,p),d=c.cmov(f,l,h);let E=c.eql(c.sqr(d),a),A=c.cmov(u,d,E);return Wn(c,A,a),A}}function ei(e){if(e<Xs)throw new Error("sqrt is not defined for small field");let t=e-et,r=0;for(;t%ye===lt;)t/=ye,r++;let n=ye,o=gt(e);for(;Ys(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return ti;let s=o.pow(n,t),i=(t+et)/ye;return function(a,u){if(a.is0(u))return u;if(Ys(a,u)!==1)throw new Error("Cannot find square root");let d=r,l=a.mul(a.ONE,s),f=a.pow(u,t),p=a.pow(u,i);for(;!a.eql(f,a.ONE);){if(a.is0(f))return a.ZERO;let h=1,E=a.sqr(f);for(;!a.eql(E,a.ONE);)if(h++,E=a.sqr(E),h===d)throw new Error("Cannot find square root");let A=et<<BigInt(d-h-1),b=a.pow(l,A);d=h,l=a.sqr(b),f=a.mul(f,l),p=a.mul(p,b)}return p}}function Yc(e){return e%$s===Xs?ti:e%Js===Ws?zc:e%Qs===Zc?Gc(e):ei(e)}var Vt=(e,t)=>(J(e,t)&et)===et,Xc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Jn(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=Xc.reduce((n,o)=>(n[o]="function",n),t);return ee(e,r),e}function $c(e,t,r){if(r<lt)throw new Error("invalid exponent, negatives unsupported");if(r===lt)return e.ONE;if(r===et)return t;let n=e.ONE,o=t;for(;r>lt;)r&et&&(n=e.mul(n,o)),o=e.sqr(o),r>>=et;return n}function hr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,c,a)=>e.is0(c)?i:(n[a]=i,e.mul(i,c)),e.ONE),s=e.inv(o);return t.reduceRight((i,c,a)=>e.is0(c)?i:(n[a]=e.mul(i,n[a]),e.mul(i,c)),s),n}function Ys(e,t){let r=(e.ORDER-et)/ye,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function jr(e,t){t!==void 0&&Nt(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function gt(e,t,r=!1,n={}){if(e<=lt)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s,i=!1,c;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let f=t;f.BITS&&(o=f.BITS),f.sqrt&&(s=f.sqrt),typeof f.isLE=="boolean"&&(r=f.isLE),typeof f.modFromBytes=="boolean"&&(i=f.modFromBytes),c=f.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:a,nByteLength:u}=jr(e,o);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let d,l=Object.freeze({ORDER:e,isLE:r,BITS:a,BYTES:u,MASK:te(a),ZERO:lt,ONE:et,allowedLengths:c,create:f=>J(f,e),isValid:f=>{if(typeof f!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof f);return lt<=f&&f<e},is0:f=>f===lt,isValidNot0:f=>!l.is0(f)&&l.isValid(f),isOdd:f=>(f&et)===et,neg:f=>J(-f,e),eql:(f,p)=>f===p,sqr:f=>J(f*f,e),add:(f,p)=>J(f+p,e),sub:(f,p)=>J(f-p,e),mul:(f,p)=>J(f*p,e),pow:(f,p)=>$c(l,f,p),div:(f,p)=>J(f*Gs(p,e),e),sqrN:f=>f*f,addN:(f,p)=>f+p,subN:(f,p)=>f-p,mulN:(f,p)=>f*p,inv:f=>Gs(f,e),sqrt:s||(f=>(d||(d=Yc(e)),d(l,f))),toBytes:f=>r?Yn(f,u):Vr(f,u),fromBytes:(f,p=!0)=>{if(c){if(!c.includes(f.length)||f.length>u)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+f.length);let E=new Uint8Array(u);E.set(f,r?0:E.length-f.length),f=E}if(f.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+f.length);let h=r?qt(f):Re(f);if(i&&(h=J(h,e)),!p&&!l.isValid(h))throw new Error("invalid field element: outside of range 0..ORDER");return h},invertBatch:f=>hr(l,f),cmov:(f,p,h)=>h?p:f});return Object.freeze(l)}function ri(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function Qn(e){let t=ri(e);return t+Math.ceil(t/2)}function to(e,t,r=!1){let n=e.length,o=ri(t),s=Qn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?qt(e):Re(e),c=J(i,t-et)+et;return r?Yn(c,o):Vr(c,o)}var ke=BigInt(0),be=BigInt(1);function lr(e,t){let r=t.negate();return e?r:t}function Ft(e,t){let r=hr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function ii(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function eo(e,t){ii(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=te(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function ni(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,c=Number(e&o),a=e>>i;c>n&&(c-=s,a+=be);let u=t*n,d=u+Math.abs(c)-1,l=c===0,f=c<0,p=t%2!==0;return{nextN:a,offset:d,isZero:l,isNeg:f,isNegF:p,offsetF:u}}function Wc(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Jc(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var ro=new WeakMap,ai=new WeakMap;function no(e){return ai.get(e)||1}function oi(e){if(e!==ke)throw new Error("invalid wNAF")}var Ne=class{constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>ke;)r&be&&(n=n.add(o)),o=o.double(),r>>=be;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=eo(r,this.bits),s=[],i=t,c=i;for(let a=0;a<n;a++){c=i,s.push(c);for(let u=1;u<o;u++)c=c.add(i),s.push(c);i=c.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=eo(t,this.bits);for(let c=0;c<i.windows;c++){let{nextN:a,offset:u,isZero:d,isNeg:l,isNegF:f,offsetF:p}=ni(n,c,i);n=a,d?s=s.add(lr(f,r[p])):o=o.add(lr(l,r[u]))}return oi(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=eo(t,this.bits);for(let i=0;i<s.windows&&n!==ke;i++){let{nextN:c,offset:a,isZero:u,isNeg:d}=ni(n,i,s);if(n=c,!u){let l=r[a];o=o.add(d?l.negate():l)}}return oi(n),o}getPrecomputes(t,r,n){let o=ro.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),ro.set(r,o))),o}cached(t,r,n){let o=no(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=no(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){ii(r,this.bits),ai.set(t,r),ro.delete(t)}hasCache(t){return no(t)!==1}};function ci(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>ke||n>ke;)r&be&&(s=s.add(o)),n&be&&(i=i.add(o)),o=o.double(),r>>=be,n>>=be;return{p1:s,p2:i}}function He(e,t,r,n){Wc(r,e),Jc(n,t);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,c=Fr(BigInt(o)),a=1;c>12?a=c-3:c>4?a=c-2:c>0&&(a=2);let u=te(a),d=new Array(Number(u)+1).fill(i),l=Math.floor((t.BITS-1)/a)*a,f=i;for(let p=l;p>=0;p-=a){d.fill(i);for(let E=0;E<s;E++){let A=n[E],b=Number(A>>BigInt(p)&u);d[b]=d[b].add(r[E])}let h=i;for(let E=d.length-1,A=i;E>0;E--)A=A.add(d[E]),h=h.add(A);if(f=f.add(h),p!==0)for(let E=0;E<a;E++)f=f.double()}return f}function si(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Jn(t),t}else return gt(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 a of["p","n","h"]){let u=t[a];if(!(typeof u=="bigint"&&u>ke))throw new Error(`CURVE.${a} must be positive bigint`)}let o=si(t.p,r.Fp,n),s=si(t.n,r.Fn,n),c=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of c)if(!o.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}var re=BigInt(0),rt=BigInt(1),oo=BigInt(2),Qc=BigInt(8);function tf(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),c=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,c)}function ef(e,t={}){let r=Zr("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;ee(t,{},{uvRatio:"function"});let c=oo<<BigInt(o.BYTES*8)-rt,a=A=>n.create(A),u=t.uvRatio||((A,b)=>{try{return{isValid:!0,value:n.sqrt(n.div(A,b))}}catch{return{isValid:!1,value:re}}});if(!tf(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function d(A,b,B=!1){let g=B?rt:re;return ur("coordinate "+A,b,g,c),b}function l(A){if(!(A instanceof h))throw new Error("ExtendedPoint expected")}let f=Pe((A,b)=>{let{X:B,Y:g,Z:U}=A,D=A.is0();b==null&&(b=D?Qc:n.inv(U));let O=a(B*b),H=a(g*b),R=n.mul(U,b);if(D)return{x:re,y:rt};if(R!==rt)throw new Error("invZ was invalid");return{x:O,y:H}}),p=Pe(A=>{let{a:b,d:B}=s;if(A.is0())throw new Error("bad point: ZERO");let{X:g,Y:U,Z:D,T:O}=A,H=a(g*g),R=a(U*U),w=a(D*D),K=a(w*w),P=a(H*b),L=a(w*a(P+R)),x=a(K+a(B*a(H*R)));if(L!==x)throw new Error("bad point: equation left != right (1)");let m=a(g*U),y=a(D*O);if(m!==y)throw new Error("bad point: equation left != right (2)");return!0});class h{constructor(b,B,g,U){this.X=d("x",b),this.Y=d("y",B),this.Z=d("z",g,!0),this.T=d("t",U),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){if(b instanceof h)throw new Error("extended point not allowed");let{x:B,y:g}=b||{};return d("x",B),d("y",g),new h(B,g,rt,a(B*g))}static fromBytes(b,B=!1){let g=n.BYTES,{a:U,d:D}=s;b=Xn(xt(b,g,"point")),Mt(B,"zip215");let O=Xn(b),H=b[g-1];O[g-1]=H&-129;let R=qt(O),w=B?c:n.ORDER;ur("point.y",R,re,w);let K=a(R*R),P=a(K-rt),L=a(D*K-U),{isValid:x,value:m}=u(P,L);if(!x)throw new Error("bad point: invalid y coordinate");let y=(m&rt)===rt,S=(H&128)!==0;if(!B&&m===re&&S)throw new Error("bad point: x=0 and x_0=1");return S!==y&&(m=a(-m)),h.fromAffine({x:m,y:R})}static fromHex(b,B=!1){return h.fromBytes(V("point",b),B)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,B=!0){return E.createCache(this,b),B||this.multiply(oo),this}assertValidity(){p(this)}equals(b){l(b);let{X:B,Y:g,Z:U}=this,{X:D,Y:O,Z:H}=b,R=a(B*H),w=a(D*U),K=a(g*H),P=a(O*U);return R===w&&K===P}is0(){return this.equals(h.ZERO)}negate(){return new h(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:b}=s,{X:B,Y:g,Z:U}=this,D=a(B*B),O=a(g*g),H=a(oo*a(U*U)),R=a(b*D),w=B+g,K=a(a(w*w)-D-O),P=R+O,L=P-H,x=R-O,m=a(K*L),y=a(P*x),S=a(K*x),v=a(L*P);return new h(m,y,v,S)}add(b){l(b);let{a:B,d:g}=s,{X:U,Y:D,Z:O,T:H}=this,{X:R,Y:w,Z:K,T:P}=b,L=a(U*R),x=a(D*w),m=a(H*g*P),y=a(O*K),S=a((U+D)*(R+w)-L-x),v=y-m,T=y+m,_=a(x-B*L),I=a(S*v),C=a(T*_),k=a(S*_),Y=a(v*T);return new h(I,C,Y,k)}subtract(b){return this.add(b.negate())}multiply(b){if(!o.isValidNot0(b))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:B,f:g}=E.cached(this,b,U=>Ft(h,U));return Ft(h,[B,g])[0]}multiplyUnsafe(b,B=h.ZERO){if(!o.isValid(b))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return b===re?h.ZERO:this.is0()||b===rt?this:E.unsafe(this,b,g=>Ft(h,g),B)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return E.unsafe(this,s.n).is0()}toAffine(b){return f(this,b)}clearCofactor(){return i===rt?this:this.multiplyUnsafe(i)}toBytes(){let{x:b,y:B}=this.toAffine(),g=n.toBytes(B);return g[g.length-1]|=b&rt?128:0,g}toHex(){return Bt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(b){return Ft(h,b)}static msm(b,B){return He(h,o,b,B)}_setWindowSize(b){this.precompute(b)}toRawBytes(){return this.toBytes()}}h.BASE=new h(s.Gx,s.Gy,rt,a(s.Gx*s.Gy)),h.ZERO=new h(re,rt,rt,re),h.Fp=n,h.Fn=o;let E=new Ne(h,o.BITS);return h.BASE.precompute(8),h}var zr=class{constructor(t){this.ep=t}static fromBytes(t){$n()}static fromHex(t){$n()}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 Bt(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.init(this.ep.precompute(t,r))}toRawBytes(){return this.toBytes()}};function rf(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');ee(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=e,c=r.randomBytes||$t,a=r.adjustScalarBytes||(w=>w),u=r.domain||((w,K,P)=>{if(Mt(P,"phflag"),K.length||P)throw new Error("Contexts/pre-hash are not supported");return w});function d(w){return i.create(qt(w))}function l(w){let K=g.secretKey;w=V("private key",w,K);let P=V("hashed private key",t(w),2*K),L=a(P.slice(0,K)),x=P.slice(K,2*K),m=d(L);return{head:L,prefix:x,scalar:m}}function f(w){let{head:K,prefix:P,scalar:L}=l(w),x=o.multiply(L),m=x.toBytes();return{head:K,prefix:P,scalar:L,point:x,pointBytes:m}}function p(w){return f(w).pointBytes}function h(w=Uint8Array.of(),...K){let P=ht(...K);return d(t(u(P,V("context",w),!!n)))}function E(w,K,P={}){w=V("message",w),n&&(w=n(w));let{prefix:L,scalar:x,pointBytes:m}=f(K),y=h(P.context,L,w),S=o.multiply(y).toBytes(),v=h(P.context,S,m,w),T=i.create(y+v*x);if(!i.isValid(T))throw new Error("sign failed: invalid s");let _=ht(S,i.toBytes(T));return xt(_,g.signature,"result")}let A={zip215:!0};function b(w,K,P,L=A){let{context:x,zip215:m}=L,y=g.signature;w=V("signature",w,y),K=V("message",K),P=V("publicKey",P,g.publicKey),m!==void 0&&Mt(m,"zip215"),n&&(K=n(K));let S=y/2,v=w.subarray(0,S),T=qt(w.subarray(S,y)),_,I,C;try{_=e.fromBytes(P,m),I=e.fromBytes(v,m),C=o.multiplyUnsafe(T)}catch{return!1}if(!m&&_.isSmallOrder())return!1;let k=h(x,I.toBytes(),_.toBytes(),K);return I.add(_.multiplyUnsafe(k)).subtract(C).clearCofactor().is0()}let B=s.BYTES,g={secretKey:B,publicKey:B,signature:2*B,seed:B};function U(w=c(g.seed)){return xt(w,g.seed,"seed")}function D(w){let K=R.randomSecretKey(w);return{secretKey:K,publicKey:p(K)}}function O(w){return Ht(w)&&w.length===i.BYTES}function H(w,K){try{return!!e.fromBytes(w,K)}catch{return!1}}let R={getExtendedPublicKey:f,randomSecretKey:U,isValidSecretKey:O,isValidPublicKey:H,toMontgomery(w){let{y:K}=e.fromBytes(w),P=g.publicKey,L=P===32;if(!L&&P!==57)throw new Error("only defined for 25519 and 448");let x=L?s.div(rt+K,rt-K):s.div(K-rt,K+rt);return s.toBytes(x)},toMontgomerySecret(w){let K=g.secretKey;xt(w,K);let P=t(w.subarray(0,K));return a(P).subarray(0,K)},randomPrivateKey:U,precompute(w=8,K=e.BASE){return K.precompute(w,!1)}};return Object.freeze({keygen:D,getPublicKey:p,sign:E,verify:b,utils:R,Point:e,lengths:g})}function nf(e){let t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=gt(t.n,e.nBitLength,!0),o={Fp:r,Fn:n,uvRatio:e.uvRatio},s={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:o,hash:e.hash,eddsaOpts:s}}function of(e,t){let r=t.Point;return Object.assign({},t,{ExtendedPoint:r,CURVE:e,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function fi(e){let{CURVE:t,curveOpts:r,hash:n,eddsaOpts:o}=nf(e),s=ef(t,r),i=rf(s,n,o);return of(e,i)}var sf=BigInt(0),jt=BigInt(1),ui=BigInt(2),Il=BigInt(3),af=BigInt(5),cf=BigInt(8),Oe=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),dr={p:Oe,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:cf,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function ff(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Oe,c=e*e%s*e%s,a=z(c,ui,s)*c%s,u=z(a,jt,s)*e%s,d=z(u,af,s)*u%s,l=z(d,t,s)*d%s,f=z(l,r,s)*l%s,p=z(f,n,s)*f%s,h=z(p,o,s)*p%s,E=z(h,o,s)*p%s,A=z(E,t,s)*d%s;return{pow_p_5_8:z(A,ui,s)*e%s,b2:c}}function uf(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var so=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function co(e,t){let r=Oe,n=J(t*t*t,r),o=J(n*n*t,r),s=ff(e*o).pow_p_5_8,i=J(e*n*s,r),c=J(t*i*i,r),a=i,u=J(i*so,r),d=c===e,l=c===J(-e,r),f=c===J(-e*so,r);return d&&(i=a),(l||f)&&(i=u),Vt(i,r)&&(i=J(-i,r)),{isValid:d||l,value:i}}var ne=gt(dr.p,{isLE:!0}),hf=gt(dr.n,{isLE:!0}),lf={...dr,Fp:ne,hash:qr,adjustScalarBytes:uf,uvRatio:co},wt=fi(lf);var io=so,df=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),pf=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),mf=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),yf=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),hi=e=>co(jt,e),bf=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),ao=e=>wt.Point.Fp.create(qt(e)&bf);function li(e){let{d:t}=dr,r=Oe,n=b=>ne.create(b),o=n(io*e*e),s=n((o+jt)*mf),i=BigInt(-1),c=n((i-t*o)*n(o+t)),{isValid:a,value:u}=co(s,c),d=n(u*e);Vt(d,r)||(d=n(-d)),a||(u=d),a||(i=o);let l=n(i*(o-jt)*yf-c),f=u*u,p=n((u+u)*c),h=n(l*df),E=n(jt-f),A=n(jt+f);return new wt.Point(n(p*A),n(E*h),n(h*A),n(p*E))}function xf(e){ut(e,64);let t=ao(e.subarray(0,32)),r=li(t),n=ao(e.subarray(32,64)),o=li(n);return new Zt(r.add(o))}var Zt=class e extends zr{constructor(t){super(t)}static fromAffine(t){return new e(wt.Point.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static hashToCurve(t){return xf(V("ristrettoHash",t,64))}static fromBytes(t){ut(t,32);let{a:r,d:n}=dr,o=Oe,s=U=>ne.create(U),i=ao(t);if(!js(ne.toBytes(i),t)||Vt(i,o))throw new Error("invalid ristretto255 encoding 1");let c=s(i*i),a=s(jt+r*c),u=s(jt-r*c),d=s(a*a),l=s(u*u),f=s(r*n*d-l),{isValid:p,value:h}=hi(s(f*l)),E=s(h*u),A=s(h*E*f),b=s((i+i)*E);Vt(b,o)&&(b=s(-b));let B=s(a*A),g=s(b*B);if(!p||Vt(g,o)||B===sf)throw new Error("invalid ristretto255 encoding 2");return new e(new wt.Point(b,B,jt,g))}static fromHex(t){return e.fromBytes(V("ristrettoHex",t,32))}static msm(t,r){return He(e,wt.Point.Fn,t,r)}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=Oe,i=A=>ne.create(A),c=i(i(n+r)*i(n-r)),a=i(t*r),u=i(a*a),{value:d}=hi(i(c*u)),l=i(d*c),f=i(d*a),p=i(l*f*o),h;if(Vt(o*p,s)){let A=i(r*io),b=i(t*io);t=A,r=b,h=i(l*pf)}else h=f;Vt(t*p,s)&&(r=i(-r));let E=i((n-r)*h);return Vt(E,s)&&(E=i(-E)),ne.toBytes(E)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=u=>ne.create(u),c=i(r*s)===i(n*o),a=i(n*s)===i(r*o);return c||a}is0(){return this.equals(e.ZERO)}};Zt.BASE=new Zt(wt.Point.BASE);Zt.ZERO=new Zt(wt.Point.ZERO);Zt.Fp=ne;Zt.Fn=hf;var oe=32,Et=64,Gr=32;var Me,di=(async()=>{try{return await G.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function pi(){let e=wt.utils.randomPrivateKey(),t=wt.getPublicKey(e);return{privateKey:xi(e,t),publicKey:t}}function mi(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=wt.getPublicKey(t);return{privateKey:xi(t,r),publicKey:r}}async function gf(e,t){let r;e.length===Et?r=e.subarray(0,32):r=e;let n={crv:"Ed25519",kty:"OKP",x:q(e.subarray(32),"base64url"),d:q(r,"base64url"),ext:!0,key_ops:["sign"]},o=await G.get().subtle.importKey("jwk",n,{name:"Ed25519"},!0,["sign"]),s=await G.get().subtle.sign({name:"Ed25519"},o,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(s,0,s.byteLength)}function wf(e,t){let r=e.subarray(0,Gr);return wt.sign(t instanceof Uint8Array?t:t.subarray(),r)}async function yi(e,t){return Me==null&&(Me=await di),Me?gf(e,t):wf(e,t)}async function Ef(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await G.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await G.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 Sf(e,t,r){return wt.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function bi(e,t,r){return Me==null&&(Me=await di),Me?Ef(e,t,r):Sf(e,t,r)}function xi(e,t){let r=new Uint8Array(Et);for(let n=0;n<Gr;n++)r[n]=e[n],r[Gr+n]=t[n];return r}function fo(e,t){let r=Z(e,"base64urlpad");if(t!=null){if(r.length>t)throw new Error("byte array longer than desired length");r=Ut([new Uint8Array(t-r.length),r])}return r}function qe(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var pr=class{type="Ed25519";raw;constructor(t){this.raw=Ve(t,oe)}toMultihash(){return ce.digest(ue(this))}toCID(){return At.createV1(114,this.toMultihash())}toString(){return tt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:it(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=bi(this.raw,r,t);return qe(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}},xe=class{type="Ed25519";raw;publicKey;constructor(t,r){this.raw=Ve(t,Et),this.publicKey=new pr(r)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:it(this.raw,t.raw)}sign(t,r){r?.signal?.throwIfAborted();let n=yi(this.raw,t);return qe(n)?n.then(o=>(r?.signal?.throwIfAborted(),o)):(r?.signal?.throwIfAborted(),n)}};function uo(e){if(e.length>Et){e=Ve(e,Et+oe);let n=e.subarray(0,Et),o=e.subarray(Et,e.length);return new xe(n,o)}e=Ve(e,Et);let t=e.subarray(0,Et),r=e.subarray(oe);return new xe(t,r)}function Yr(e){return e=Ve(e,oe),new pr(e)}async function wi(){let{privateKey:e,publicKey:t}=pi();return new xe(e,t)}async function Ei(e){let{privateKey:t,publicKey:r}=mi(e);return new xe(t,r)}function Ve(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new N(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Af=Math.pow(2,7),Bf=Math.pow(2,14),vf=Math.pow(2,21),Si=Math.pow(2,28),Ai=Math.pow(2,35),Bi=Math.pow(2,42),vi=Math.pow(2,49),dt=128,se=127;function mr(e){if(e<Af)return 1;if(e<Bf)return 2;if(e<vf)return 3;if(e<Si)return 4;if(e<Ai)return 5;if(e<Bi)return 6;if(e<vi)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function _i(e,t,r=0){switch(mr(e)){case 8:t[r++]=e&255|dt,e/=128;case 7:t[r++]=e&255|dt,e/=128;case 6:t[r++]=e&255|dt,e/=128;case 5:t[r++]=e&255|dt,e/=128;case 4:t[r++]=e&255|dt,e>>>=7;case 3:t[r++]=e&255|dt,e>>>=7;case 2:t[r++]=e&255|dt,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Ii(e,t){let r=e[t],n=0;if(n+=r&se,r<dt||(r=e[t+1],n+=(r&se)<<7,r<dt)||(r=e[t+2],n+=(r&se)<<14,r<dt)||(r=e[t+3],n+=(r&se)<<21,r<dt)||(r=e[t+4],n+=(r&se)*Si,r<dt)||(r=e[t+5],n+=(r&se)*Ai,r<dt)||(r=e[t+6],n+=(r&se)*Bi,r<dt)||(r=e[t+7],n+=(r&se)*vi,r<dt))return n;throw new RangeError("Could not decode varint")}var ho=new Float32Array([-0]),ie=new Uint8Array(ho.buffer);function Ki(e,t,r){ho[0]=e,t[r]=ie[0],t[r+1]=ie[1],t[r+2]=ie[2],t[r+3]=ie[3]}function Li(e,t){return ie[0]=e[t],ie[1]=e[t+1],ie[2]=e[t+2],ie[3]=e[t+3],ho[0]}var lo=new Float64Array([-0]),at=new Uint8Array(lo.buffer);function Ui(e,t,r){lo[0]=e,t[r]=at[0],t[r+1]=at[1],t[r+2]=at[2],t[r+3]=at[3],t[r+4]=at[4],t[r+5]=at[5],t[r+6]=at[6],t[r+7]=at[7]}function Ti(e,t){return at[0]=e[t],at[1]=e[t+1],at[2]=e[t+2],at[3]=e[t+3],at[4]=e[t+4],at[5]=e[t+5],at[6]=e[t+6],at[7]=e[t+7],lo[0]}var _f=BigInt(Number.MAX_SAFE_INTEGER),If=BigInt(Number.MIN_SAFE_INTEGER),St=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 ge;if(t<_f&&t>If)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>Ci&&(o=0n,++n>Ci&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return ge;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):ge}},ge=new St(0,0);ge.toBigInt=function(){return 0n};ge.zzEncode=ge.zzDecode=function(){return this};ge.length=function(){return 1};var Ci=4294967296n;function Di(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 Ri(e,t,r){if(r-t<1)return"";let o,s=[],i=0,c;for(;t<r;)c=e[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|e[t++]&63:c>239&&c<365?(c=((c&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&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 po(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 Xr(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var mo=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,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 Xr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw It(this,4);return Xr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw It(this,4);let t=Li(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw It(this,4);let t=Ti(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 Ri(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 St(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=Xr(this.buf,this.pos+=4),r=Xr(this.buf,this.pos+=4);return new St(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=Ii(this.buf,this.pos);return this.pos+=mr(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 yo(e){return new mo(e instanceof Uint8Array?e:e.subarray())}function $r(e,t,r){let n=yo(e);return t.decode(n,void 0,r)}function bo(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 c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var we=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function xo(){}var wo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Kf=bo();function Lf(e){return globalThis.Buffer!=null?yt(e):Kf(e)}var br=class{len;head;tail;states;constructor(){this.len=0,this.head=new we(xo,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new we(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Eo((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(Wr,10,St.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=St.fromBigInt(t);return this._push(Wr,r.length(),r)}uint64Number(t){return this._push(_i,mr(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=St.fromBigInt(t).zzEncode();return this._push(Wr,r.length(),r)}sint64Number(t){let r=St.fromNumber(t).zzEncode();return this._push(Wr,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(go,1,t?1:0)}fixed32(t){return this._push(yr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=St.fromBigInt(t);return this._push(yr,4,r.lo)._push(yr,4,r.hi)}fixed64Number(t){let r=St.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(Ki,4,t)}double(t){return this._push(Ui,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(go,1,0):this.uint32(r)._push(Tf,r,t)}string(t){let r=Di(t);return r!==0?this.uint32(r)._push(po,r,t):this._push(go,1,0)}fork(){return this.states=new wo(this),this.head=this.tail=new we(xo,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 we(xo,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=Lf(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function go(e,t,r){t[r]=e&255}function Uf(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Eo=class extends we{next;constructor(t,r){super(Uf,t,r),this.next=void 0}};function Wr(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 Tf(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(Cf,t,e),this},br.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Df,t,e),this});function Cf(e,t,r){t.set(e,r)}function Df(e,t,r){e.length<40?po(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(Z(e),r)}function So(){return new br}function Jr(e,t){let r=So();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var Fe;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(Fe||(Fe={}));function Qr(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function Ao(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(s,i){let c=t(s);i.int32(c)},n=function(s){let i=s.int32();return t(i)};return Qr("enum",Fe.VARINT,r,n)}function tn(e,t){return Qr("message",Fe.LENGTH_DELIMITED,e,t)}var j;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(j||(j={}));var Bo;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Bo||(Bo={}));(function(e){e.codec=()=>Ao(Bo)})(j||(j={}));var Ct;(function(e){let t;e.codec=()=>(t==null&&(t=tn((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),j.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=j.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>Jr(r,e.codec()),e.decode=(r,n)=>$r(r,e.codec(),n)})(Ct||(Ct={}));var xr;(function(e){let t;e.codec=()=>(t==null&&(t=tn((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),j.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=j.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>Jr(r,e.codec()),e.decode=(r,n)=>$r(r,e.codec(),n)})(xr||(xr={}));function vo(e){if(isNaN(e)||e<=0)throw new N("random bytes length must be a Number bigger than 0");return $t(e)}var wr={};st(wr,{MAX_RSA_KEY_SIZE:()=>_o,generateRSAKeyPair:()=>Do,jwkToJWKKeyPair:()=>Oi,jwkToPkcs1:()=>Nf,jwkToPkix:()=>Uo,jwkToRSAPrivateKey:()=>nn,pkcs1MessageToJwk:()=>Ko,pkcs1MessageToRSAPrivateKey:()=>en,pkcs1ToJwk:()=>kf,pkcs1ToRSAPrivateKey:()=>To,pkixMessageToJwk:()=>Lo,pkixMessageToRSAPublicKey:()=>rn,pkixToJwk:()=>Hf,pkixToRSAPublicKey:()=>Co});var je=Mr;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=wr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return At.createV1(114,this._multihash)}toString(){return tt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:it(this.raw,t.raw)}verify(t,r,n){return Hi(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:it(this.raw,t.raw)}sign(t,r){return Ni(this.jwk,t,r)}};var _o=8192,Io=18,Rf=1062,Pf=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function kf(e){let t=bt(e);return Ko(t)}function Ko(e){return{n:q(e[1],"base64url"),e:q(e[2],"base64url"),d:q(e[3],"base64url"),p:q(e[4],"base64url"),q:q(e[5],"base64url"),dp:q(e[6],"base64url"),dq:q(e[7],"base64url"),qi:q(e[8],"base64url"),kty:"RSA"}}function Nf(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 N("JWK was missing components");return vt([ft(Uint8Array.from([0])),ft(Z(e.n,"base64url")),ft(Z(e.e,"base64url")),ft(Z(e.d,"base64url")),ft(Z(e.p,"base64url")),ft(Z(e.q,"base64url")),ft(Z(e.dp,"base64url")),ft(Z(e.dq,"base64url")),ft(Z(e.qi,"base64url"))]).subarray()}function Hf(e){let t=bt(e,{offset:0});return Lo(t)}function Lo(e){let t=bt(e[1],{offset:0});return{kty:"RSA",n:q(t[0],"base64url"),e:q(t[1],"base64url")}}function Uo(e){if(e.n==null||e.e==null)throw new N("JWK was missing components");return vt([Pf,or(vt([ft(Z(e.n,"base64url")),ft(Z(e.e,"base64url"))]))]).subarray()}function To(e){let t=bt(e);return en(t)}function en(e){let t=Ko(e);return nn(t)}function Co(e,t){if(e.byteLength>=Rf)throw new Ee("Key size is too large");let r=bt(e,{offset:0});return rn(r,e,t)}function rn(e,t,r){let n=Lo(e);if(r==null){let o=je(Ct.encode({Type:j.RSA,Data:t}));r=Lt(Io,o)}return new Ze(n,r)}function nn(e){if(qi(e)>_o)throw new N("Key size is too large");let t=Oi(e),r=je(Ct.encode({Type:j.RSA,Data:Uo(t.publicKey)})),n=Lt(Io,r);return new gr(t.privateKey,new Ze(t.publicKey,n))}async function Do(e){if(e>_o)throw new N("Key size is too large");let t=await Mi(e),r=je(Ct.encode({Type:j.RSA,Data:Uo(t.publicKey)})),n=Lt(Io,r);return new gr(t.privateKey,new Ze(t.publicKey,n))}function Oi(e){if(e==null)throw new N("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}var Vi="1.2.840.113549.1.1.1";async function Mi(e,t){let r=await G.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 Of(r,t);return{privateKey:n[0],publicKey:n[1]}}async function Ni(e,t,r){let n=await G.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await G.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 Hi(e,t,r,n){let o=await G.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await G.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function Of(e,t){if(e.privateKey==null||e.publicKey==null)throw new N("Private and public key are required");let r=await Promise.all([G.get().subtle.exportKey("jwk",e.privateKey),G.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function qi(e){if(e.kty!=="RSA")throw new N("invalid key type");if(e.n==null)throw new N("invalid key modulus");return Z(e.n,"base64url").length*8}var on=class extends Ue{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,Te(t);let n=sr(r);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),mt(s)}update(t){return Ce(this),this.iHash.update(t),this}digestInto(t){Ce(this),ut(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Er=(e,t,r)=>new on(e,t).update(r).digest();Er.create=(e,t)=>new on(e,t);var Fi=(e,t)=>(e+(e>=0?t:-t)/ji)/t;function Mf(e,t,r){let[[n,o],[s,i]]=t,c=Fi(i*e,r),a=Fi(-o*e,r),u=e-c*n-a*s,d=-c*o-a*i,l=u<Gt,f=d<Gt;l&&(u=-u),f&&(d=-d);let p=te(Math.ceil(Fr(r)/2))+Ge;if(u<Gt||u>=p||d<Gt||d>=p)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:u,k2neg:f,k2:d}}function Po(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Ro(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return Mt(r.lowS,"lowS"),Mt(r.prehash,"prehash"),r.format!==void 0&&Po(r.format),r}var ko=class extends Error{constructor(t=""){super(t)}},zt={Err:ko,_tlv:{encode:(e,t)=>{let{Err:r}=zt;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=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}=zt,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let a=o&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+a);if(u.length!==a)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let d of u)i=i<<8|d;if(n+=a,i<128)throw new r("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new r("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=zt;if(e<Gt)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}=zt;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Re(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=zt,o=V("signature",e),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,s),{v:u,l:d}=n.decode(2,a);if(d.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=zt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},Gt=BigInt(0),Ge=BigInt(1),ji=BigInt(2),sn=BigInt(3),qf=BigInt(4);function ze(e,t){let{BYTES:r}=e,n;if(typeof t=="bigint")n=t;else{let o=V("private key",t);try{n=e.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof t}`)}}if(!e.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function Vf(e,t={}){let r=Zr("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:c}=s;ee(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:a}=t;if(a&&(!n.is0(s.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=zi(n,o);function d(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(L,x,m){let{x:y,y:S}=x.toAffine(),v=n.toBytes(y);if(Mt(m,"isCompressed"),m){d();let T=!n.isOdd(S);return ht(Zi(T),v)}else return ht(Uint8Array.of(4),v,n.toBytes(S))}function f(L){xt(L,void 0,"Point");let{publicKey:x,publicKeyUncompressed:m}=u,y=L.length,S=L[0],v=L.subarray(1);if(y===x&&(S===2||S===3)){let T=n.fromBytes(v);if(!n.isValid(T))throw new Error("bad point: is not on curve, wrong x");let _=E(T),I;try{I=n.sqrt(_)}catch(Y){let F=Y instanceof Error?": "+Y.message:"";throw new Error("bad point: is not on curve, sqrt error"+F)}d();let C=n.isOdd(I);return(S&1)===1!==C&&(I=n.neg(I)),{x:T,y:I}}else if(y===m&&S===4){let T=n.BYTES,_=n.fromBytes(v.subarray(0,T)),I=n.fromBytes(v.subarray(T,T*2));if(!A(_,I))throw new Error("bad point: is not on curve");return{x:_,y:I}}else throw new Error(`bad point: got length ${y}, expected compressed=${x} or uncompressed=${m}`)}let p=t.toBytes||l,h=t.fromBytes||f;function E(L){let x=n.sqr(L),m=n.mul(x,L);return n.add(n.add(m,n.mul(L,s.a)),s.b)}function A(L,x){let m=n.sqr(x),y=E(L);return n.eql(m,y)}if(!A(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let b=n.mul(n.pow(s.a,sn),qf),B=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(b,B)))throw new Error("bad curve params: a or b");function g(L,x,m=!1){if(!n.isValid(x)||m&&n.is0(x))throw new Error(`bad point coordinate ${L}`);return x}function U(L){if(!(L instanceof w))throw new Error("ProjectivePoint expected")}function D(L){if(!a||!a.basises)throw new Error("no endo");return Mf(L,a.basises,o.ORDER)}let O=Pe((L,x)=>{let{X:m,Y:y,Z:S}=L;if(n.eql(S,n.ONE))return{x:m,y};let v=L.is0();x==null&&(x=v?n.ONE:n.inv(S));let T=n.mul(m,x),_=n.mul(y,x),I=n.mul(S,x);if(v)return{x:n.ZERO,y:n.ZERO};if(!n.eql(I,n.ONE))throw new Error("invZ was invalid");return{x:T,y:_}}),H=Pe(L=>{if(L.is0()){if(t.allowInfinityPoint&&!n.is0(L.Y))return;throw new Error("bad point: ZERO")}let{x,y:m}=L.toAffine();if(!n.isValid(x)||!n.isValid(m))throw new Error("bad point: x or y not field elements");if(!A(x,m))throw new Error("bad point: equation left != right");if(!L.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function R(L,x,m,y,S){return m=new w(n.mul(m.X,L),m.Y,m.Z),x=lr(y,x),m=lr(S,m),x.add(m)}class w{constructor(x,m,y){this.X=g("x",x),this.Y=g("y",m,!0),this.Z=g("z",y),Object.freeze(this)}static CURVE(){return s}static fromAffine(x){let{x:m,y}=x||{};if(!x||!n.isValid(m)||!n.isValid(y))throw new Error("invalid affine point");if(x instanceof w)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(y)?w.ZERO:new w(m,y,n.ONE)}static fromBytes(x){let m=w.fromAffine(h(xt(x,void 0,"point")));return m.assertValidity(),m}static fromHex(x){return w.fromBytes(V("pointHex",x))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(x=8,m=!0){return P.createCache(this,x),m||this.multiply(sn),this}assertValidity(){H(this)}hasEvenY(){let{y:x}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(x)}equals(x){U(x);let{X:m,Y:y,Z:S}=this,{X:v,Y:T,Z:_}=x,I=n.eql(n.mul(m,_),n.mul(v,S)),C=n.eql(n.mul(y,_),n.mul(T,S));return I&&C}negate(){return new w(this.X,n.neg(this.Y),this.Z)}double(){let{a:x,b:m}=s,y=n.mul(m,sn),{X:S,Y:v,Z:T}=this,_=n.ZERO,I=n.ZERO,C=n.ZERO,k=n.mul(S,S),Y=n.mul(v,v),F=n.mul(T,T),M=n.mul(S,v);return M=n.add(M,M),C=n.mul(S,T),C=n.add(C,C),_=n.mul(x,C),I=n.mul(y,F),I=n.add(_,I),_=n.sub(Y,I),I=n.add(Y,I),I=n.mul(_,I),_=n.mul(M,_),C=n.mul(y,C),F=n.mul(x,F),M=n.sub(k,F),M=n.mul(x,M),M=n.add(M,C),C=n.add(k,k),k=n.add(C,k),k=n.add(k,F),k=n.mul(k,M),I=n.add(I,k),F=n.mul(v,T),F=n.add(F,F),k=n.mul(F,M),_=n.sub(_,k),C=n.mul(F,Y),C=n.add(C,C),C=n.add(C,C),new w(_,I,C)}add(x){U(x);let{X:m,Y:y,Z:S}=this,{X:v,Y:T,Z:_}=x,I=n.ZERO,C=n.ZERO,k=n.ZERO,Y=s.a,F=n.mul(s.b,sn),M=n.mul(m,v),X=n.mul(y,T),Q=n.mul(S,_),pt=n.add(m,y),$=n.add(v,T);pt=n.mul(pt,$),$=n.add(M,X),pt=n.sub(pt,$),$=n.add(m,S);let ot=n.add(v,_);return $=n.mul($,ot),ot=n.add(M,Q),$=n.sub($,ot),ot=n.add(y,S),I=n.add(T,_),ot=n.mul(ot,I),I=n.add(X,Q),ot=n.sub(ot,I),k=n.mul(Y,$),I=n.mul(F,Q),k=n.add(I,k),I=n.sub(X,k),k=n.add(X,k),C=n.mul(I,k),X=n.add(M,M),X=n.add(X,M),Q=n.mul(Y,Q),$=n.mul(F,$),X=n.add(X,Q),Q=n.sub(M,Q),Q=n.mul(Y,Q),$=n.add($,Q),M=n.mul(X,$),C=n.add(C,M),M=n.mul(ot,$),I=n.mul(pt,I),I=n.sub(I,M),M=n.mul(pt,X),k=n.mul(ot,k),k=n.add(k,M),new w(I,C,k)}subtract(x){return this.add(x.negate())}is0(){return this.equals(w.ZERO)}multiply(x){let{endo:m}=t;if(!o.isValidNot0(x))throw new Error("invalid scalar: out of range");let y,S,v=T=>P.cached(this,T,_=>Ft(w,_));if(m){let{k1neg:T,k1:_,k2neg:I,k2:C}=D(x),{p:k,f:Y}=v(_),{p:F,f:M}=v(C);S=Y.add(M),y=R(m.beta,k,F,T,I)}else{let{p:T,f:_}=v(x);y=T,S=_}return Ft(w,[y,S])[0]}multiplyUnsafe(x){let{endo:m}=t,y=this;if(!o.isValid(x))throw new Error("invalid scalar: out of range");if(x===Gt||y.is0())return w.ZERO;if(x===Ge)return y;if(P.hasCache(this))return this.multiply(x);if(m){let{k1neg:S,k1:v,k2neg:T,k2:_}=D(x),{p1:I,p2:C}=ci(w,y,v,_);return R(m.beta,I,C,S,T)}else return P.unsafe(y,x)}multiplyAndAddUnsafe(x,m,y){let S=this.multiplyUnsafe(m).add(x.multiplyUnsafe(y));return S.is0()?void 0:S}toAffine(x){return O(this,x)}isTorsionFree(){let{isTorsionFree:x}=t;return i===Ge?!0:x?x(w,this):P.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:x}=t;return i===Ge?this:x?x(w,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(x=!0){return Mt(x,"isCompressed"),this.assertValidity(),p(w,this,x)}toHex(x=!0){return Bt(this.toBytes(x))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(x=!0){return this.toBytes(x)}_setWindowSize(x){this.precompute(x)}static normalizeZ(x){return Ft(w,x)}static msm(x,m){return He(w,o,x,m)}static fromPrivateKey(x){return w.BASE.multiply(ze(o,x))}}w.BASE=new w(s.Gx,s.Gy,n.ONE),w.ZERO=new w(n.ZERO,n.ONE,n.ZERO),w.Fp=n,w.Fn=o;let K=o.BITS,P=new Ne(w,t.endo?Math.ceil(K/2):K);return w.BASE.precompute(8),w}function Zi(e){return Uint8Array.of(e?2:3)}function zi(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Ff(e,t={}){let{Fn:r}=e,n=t.randomBytes||$t,o=Object.assign(zi(e.Fp,r),{seed:Qn(r.ORDER)});function s(p){try{return!!ze(r,p)}catch{return!1}}function i(p,h){let{publicKey:E,publicKeyUncompressed:A}=o;try{let b=p.length;return h===!0&&b!==E||h===!1&&b!==A?!1:!!e.fromBytes(p)}catch{return!1}}function c(p=n(o.seed)){return to(xt(p,o.seed,"seed"),r.ORDER)}function a(p,h=!0){return e.BASE.multiply(ze(r,p)).toBytes(h)}function u(p){let h=c(p);return{secretKey:h,publicKey:a(h)}}function d(p){if(typeof p=="bigint")return!1;if(p instanceof e)return!0;let{secretKey:h,publicKey:E,publicKeyUncompressed:A}=o;if(r.allowedLengths||h===E)return;let b=V("key",p).length;return b===E||b===A}function l(p,h,E=!0){if(d(p)===!0)throw new Error("first arg must be private key");if(d(h)===!1)throw new Error("second arg must be public key");let A=ze(r,p);return e.fromHex(h).multiply(A).toBytes(E)}return Object.freeze({getPublicKey:a,getSharedSecret:l,keygen:u,Point:e,utils:{isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c,isValidPrivateKey:s,randomPrivateKey:c,normPrivateKeyToScalar:p=>ze(r,p),precompute(p=8,h=e.BASE){return h.precompute(p,!1)}},lengths:o})}function jf(e,t,r={}){Te(t),ee(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||$t,o=r.hmac||((m,...y)=>Er(t,m,ht(...y))),{Fp:s,Fn:i}=e,{ORDER:c,BITS:a}=i,{keygen:u,getPublicKey:d,getSharedSecret:l,utils:f,lengths:p}=Ff(e,r),h={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},E="compact";function A(m){let y=c>>Ge;return m>y}function b(m,y){if(!i.isValidNot0(y))throw new Error(`invalid signature ${m}: out of range 1..Point.Fn.ORDER`);return y}function B(m,y){Po(y);let S=p.signature,v=y==="compact"?S:y==="recovered"?S+1:void 0;return xt(m,v,`${y} signature`)}class g{constructor(y,S,v){this.r=b("r",y),this.s=b("s",S),v!=null&&(this.recovery=v),Object.freeze(this)}static fromBytes(y,S=E){B(y,S);let v;if(S==="der"){let{r:C,s:k}=zt.toSig(xt(y));return new g(C,k)}S==="recovered"&&(v=y[0],S="compact",y=y.subarray(1));let T=i.BYTES,_=y.subarray(0,T),I=y.subarray(T,T*2);return new g(i.fromBytes(_),i.fromBytes(I),v)}static fromHex(y,S){return this.fromBytes(le(y),S)}addRecoveryBit(y){return new g(this.r,this.s,y)}recoverPublicKey(y){let S=s.ORDER,{r:v,s:T,recovery:_}=this;if(_==null||![0,1,2,3].includes(_))throw new Error("recovery id invalid");if(c*ji<S&&_>1)throw new Error("recovery id is ambiguous for h>1 curve");let C=_===2||_===3?v+c:v;if(!s.isValid(C))throw new Error("recovery id 2 or 3 invalid");let k=s.toBytes(C),Y=e.fromBytes(ht(Zi((_&1)===0),k)),F=i.inv(C),M=D(V("msgHash",y)),X=i.create(-M*F),Q=i.create(T*F),pt=e.BASE.multiplyUnsafe(X).add(Y.multiplyUnsafe(Q));if(pt.is0())throw new Error("point at infinify");return pt.assertValidity(),pt}hasHighS(){return A(this.s)}toBytes(y=E){if(Po(y),y==="der")return le(zt.hexFromSig(this));let S=i.toBytes(this.r),v=i.toBytes(this.s);if(y==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return ht(Uint8Array.of(this.recovery),S,v)}return ht(S,v)}toHex(y){return Bt(this.toBytes(y))}assertValidity(){}static fromCompact(y){return g.fromBytes(V("sig",y),"compact")}static fromDER(y){return g.fromBytes(V("sig",y),"der")}normalizeS(){return this.hasHighS()?new g(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Bt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Bt(this.toBytes("compact"))}}let U=r.bits2int||function(y){if(y.length>8192)throw new Error("input is too large");let S=Re(y),v=y.length*8-a;return v>0?S>>BigInt(v):S},D=r.bits2int_modN||function(y){return i.create(U(y))},O=te(a);function H(m){return ur("num < 2^"+a,m,Gt,O),i.toBytes(m)}function R(m,y){return xt(m,void 0,"message"),y?xt(t(m),void 0,"prehashed message"):m}function w(m,y,S){if(["recovered","canonical"].some(X=>X in S))throw new Error("sign() legacy options not supported");let{lowS:v,prehash:T,extraEntropy:_}=Ro(S,h);m=R(m,T);let I=D(m),C=ze(i,y),k=[H(C),H(I)];if(_!=null&&_!==!1){let X=_===!0?n(p.secretKey):_;k.push(V("extraEntropy",X))}let Y=ht(...k),F=I;function M(X){let Q=U(X);if(!i.isValidNot0(Q))return;let pt=i.inv(Q),$=e.BASE.multiply(Q).toAffine(),ot=i.create($.x);if(ot===Gt)return;let vr=i.create(pt*i.create(F+ot*C));if(vr===Gt)return;let Fo=($.x===ot?0:2)|Number($.y&Ge),jo=vr;return v&&A(vr)&&(jo=i.neg(vr),Fo^=1),new g(ot,jo,Fo)}return{seed:Y,k2sig:M}}function K(m,y,S={}){m=V("message",m);let{seed:v,k2sig:T}=w(m,y,S);return zs(t.outputLen,i.BYTES,o)(v,T)}function P(m){let y,S=typeof m=="string"||Ht(m),v=!S&&m!==null&&typeof m=="object"&&typeof m.r=="bigint"&&typeof m.s=="bigint";if(!S&&!v)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(v)y=new g(m.r,m.s);else if(S){try{y=g.fromBytes(V("sig",m),"der")}catch(T){if(!(T instanceof zt.Err))throw T}if(!y)try{y=g.fromBytes(V("sig",m),"compact")}catch{return!1}}return y||!1}function L(m,y,S,v={}){let{lowS:T,prehash:_,format:I}=Ro(v,h);if(S=V("publicKey",S),y=R(V("message",y),_),"strict"in v)throw new Error("options.strict was renamed to lowS");let C=I===void 0?P(m):g.fromBytes(V("sig",m),I);if(C===!1)return!1;try{let k=e.fromBytes(S);if(T&&C.hasHighS())return!1;let{r:Y,s:F}=C,M=D(y),X=i.inv(F),Q=i.create(M*X),pt=i.create(Y*X),$=e.BASE.multiplyUnsafe(Q).add(k.multiplyUnsafe(pt));return $.is0()?!1:i.create($.x)===Y}catch{return!1}}function x(m,y,S={}){let{prehash:v}=Ro(S,h);return y=R(y,v),g.fromBytes(m,"recovered").recoverPublicKey(y).toBytes()}return Object.freeze({keygen:u,getPublicKey:d,getSharedSecret:l,utils:f,lengths:p,Point:e,sign:K,verify:L,recoverPublicKey:x,Signature:g,hash:t})}function Zf(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,o=gt(t.n,{BITS:e.nBitLength,allowedLengths:n,modFromBytes:e.wrapPrivateKey}),s={Fp:r,Fn:o,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:s}}function zf(e){let{CURVE:t,curveOpts:r}=Zf(e),n={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,hash:e.hash,ecdsaOpts:n}}function Gf(e,t){let r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,jr(r.Fn.ORDER,r.Fn.BITS))})}function Gi(e){let{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:o}=zf(e),s=Vf(t,r),i=jf(s,n,o);return Gf(e,i)}function Yi(e,t){let r=n=>Gi({...e,hash:n});return{...r(t),create:r}}var Ho={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Yf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Xi=BigInt(2);function Xf(e){let t=Ho.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),u=e*e*e%t,d=u*u*e%t,l=z(d,r,t)*d%t,f=z(l,r,t)*d%t,p=z(f,Xi,t)*u%t,h=z(p,o,t)*p%t,E=z(h,s,t)*h%t,A=z(E,c,t)*E%t,b=z(A,a,t)*A%t,B=z(b,c,t)*E%t,g=z(B,r,t)*d%t,U=z(g,i,t)*h%t,D=z(U,n,t)*u%t,O=z(D,Xi,t);if(!No.eql(No.sqr(O),e))throw new Error("Cannot find square root");return O}var No=gt(Ho.p,{sqrt:Xf}),Kt=Yi({...Ho,Fp:No,lowS:!0,endo:Yf},Mr);var $i=33,Wi=32;function Ji(e,t,r){let n=Ur.digest(t instanceof Uint8Array?t:t.subarray());if(qe(n))return n.then(({digest:o})=>(r?.signal?.throwIfAborted(),Kt.sign(o,e).toDERRawBytes())).catch(o=>{throw o.name==="AbortError"?o:new Ye(String(o))});try{return Kt.sign(n.digest,e).toDERRawBytes()}catch(o){throw new Ye(String(o))}}function Qi(e,t,r,n){let o=Ur.digest(r instanceof Uint8Array?r:r.subarray());if(qe(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Kt.verify(t,s,e))).catch(s=>{throw s.name==="AbortError"?s:new Xe(String(s))});try{return n?.signal?.throwIfAborted(),Kt.verify(t,o.digest,e)}catch(s){throw new Xe(String(s))}}var Sr=class{type="secp256k1";raw;_key;constructor(t){this._key=ra(t),this.raw=ta(this._key)}toMultihash(){return ce.digest(ue(this))}toCID(){return At.createV1(114,this.toMultihash())}toString(){return tt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:it(this.raw,t.raw)}verify(t,r,n){return Qi(this._key,r,t,n)}},Ar=class{type="secp256k1";raw;publicKey;constructor(t,r){this.raw=ea(t),this.publicKey=new Sr(r??na(t))}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:it(this.raw,t.raw)}sign(t,r){return Ji(this.raw,t,r)}};function Oo(e){return new Ar(e)}function an(e){return new Sr(e)}async function oa(){let e=$f();return new Ar(e)}function ta(e){return Kt.ProjectivePoint.fromHex(e).toRawBytes(!0)}function ea(e){try{return Kt.getPublicKey(e,!0),e}catch(t){throw new $e(String(t))}}function ra(e){try{return Kt.ProjectivePoint.fromHex(e),e}catch(t){throw new Ee(String(t))}}function na(e){try{return Kt.getPublicKey(e,!0)}catch(t){throw new $e(String(t))}}function $f(){return Kt.utils.randomPrivateKey()}var cn={"P-256":32,"P-384":48,"P-521":66},Wf=Object.keys(cn),Mo=Wf.join(" / ");async function sa(e){if(e!=="P-256"&&e!=="P-384"&&e!=="P-521")throw new N(`Unknown curve: ${e}. Must be ${Mo}`);let t=await G.get().subtle.generateKey({name:"ECDH",namedCurve:e},!0,["deriveBits"]),r=async(s,i)=>{let c;i!=null?c=await G.get().subtle.importKey("jwk",Qf(e,i),{name:"ECDH",namedCurve:e},!1,["deriveBits"]):c=t.privateKey;let a=await G.get().subtle.importKey("jwk",ia(e,s),{name:"ECDH",namedCurve:e},!1,[]),u=await G.get().subtle.deriveBits({name:"ECDH",public:a},c,cn[e]*8);return new Uint8Array(u,0,u.byteLength)},n=await G.get().subtle.exportKey("jwk",t.publicKey);return{key:Jf(n),genSharedKey:r}}function Jf(e){if(e.crv==null||e.x==null||e.y==null)throw new N("JWK was missing components");if(e.crv!=="P-256"&&e.crv!=="P-384"&&e.crv!=="P-521")throw new N(`Unknown curve: ${e.crv}. Must be ${Mo}`);let t=cn[e.crv];return Ut([Uint8Array.from([4]),fo(e.x,t),fo(e.y,t)],1+t*2)}function ia(e,t){if(e!=="P-256"&&e!=="P-384"&&e!=="P-521")throw new N(`Unknown curve: ${e}. Must be ${Mo}`);let r=cn[e];if(!it(t.subarray(0,1),Uint8Array.from([4])))throw new N("Cannot unmarshal public key - invalid key format");return{kty:"EC",crv:e,x:q(t.subarray(1,r+1),"base64url"),y:q(t.subarray(1+r),"base64url"),ext:!0}}var Qf=(e,t)=>({...ia(e,t.public),d:q(t.private,"base64url")});var tu={"AES-128":{ivSize:16,keySize:16},"AES-256":{ivSize:16,keySize:32},Blowfish:{ivSize:8,keySize:32}};async function aa(e,t,r){if(e!=="AES-128"&&e!=="AES-256"&&e!=="Blowfish")throw new N("Cipher type was missing or unsupported");if(t!=="SHA1"&&t!=="SHA256"&&t!=="SHA512")throw new N("Hash type was missing or unsupported");if(r==null||!(r instanceof Uint8Array))throw new N("Secret was missing or an incorrect type");let n=tu[e],o=n.keySize,s=n.ivSize,i=20,c=Z("key expansion"),a=2*(s+o+i),u=await hn(t,r),d=await u.digest(c),l=[],f=0;for(;f<a;){let B=await u.digest(Ut([d,c])),g=B.length;f+g>a&&(g=a-f),l.push(B),f+=g,d=await u.digest(d)}let p=a/2,h=Ut(l),E=h.subarray(0,p),A=h.subarray(p,a),b=B=>({iv:B.subarray(0,s),cipherKey:B.subarray(s,s+o),macKey:B.subarray(s+o)});return{k1:b(E),k2:b(A)}}async function eu(e,t){if(e==="Ed25519")return wi();if(e==="secp256k1")return oa();if(e==="RSA")return Do(fu(t));if(e==="ECDSA")return Ls(uu(t));throw new Yt}async function ru(e,t){if(e!=="Ed25519")throw new Yt("Seed key derivation only supported for Ed25519 keys");return Ei(t)}function nu(e,t){let{Type:r,Data:n}=Ct.decode(e),o=n??new Uint8Array;switch(r){case j.RSA:return Co(o,t);case j.Ed25519:return Yr(o);case j.secp256k1:return an(o);case j.ECDSA:return Mn(o);default:throw new Yt}}function ou(e){if(e.byteLength===oe)return Yr(e);if(e.byteLength===$i)return an(e);let t=bt(e),r=t[1]?.[0];if(r===kn||r===Nn||r===Hn)return qn(t);if(t[0]?.[0]===Vi)return rn(t,e);throw new N("Could not extract public key from raw bytes")}function su(e){let{Type:t,Data:r}=Ct.decode(e.digest),n=r??new Uint8Array;switch(t){case j.Ed25519:return Yr(n);case j.secp256k1:return an(n);case j.ECDSA:return Mn(n);default:throw new Yt}}function ue(e){return Ct.encode({Type:j[e.type],Data:e.raw})}function iu(e){let t=xr.decode(e),r=t.Data??new Uint8Array;switch(t.Type){case j.RSA:return To(r);case j.Ed25519:return uo(r);case j.secp256k1:return Oo(r);case j.ECDSA:return vs(r);default:throw new Yt}}function au(e){if(e.byteLength===Et)return uo(e);if(e.byteLength===Wi)return Oo(e);let t=bt(e),r=t[2]?.[0];if(r===kn||r===Nn||r===Hn)return On(t);if(t.length>8)return en(t);throw new N("Could not extract private key from raw bytes")}function cu(e){return xr.encode({Type:j[e.type],Data:e.raw})}function fu(e){return e==null?2048:parseInt(e,10)}function uu(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 N("Unsupported curve, should be P-256, P-384 or P-521")}async function hu(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 N("Only RSA and ECDSA keys are supported")}async function lu(e){if(e.privateKey.algorithm.name==="RSASSA-PKCS1-v1_5"){let t=await crypto.subtle.exportKey("jwk",e.privateKey);return nn(t)}if(e.privateKey.algorithm.name==="ECDSA"){let t=await crypto.subtle.exportKey("jwk",e.privateKey);return new Pt(t)}throw new N("Only RSA and ECDSA keys are supported")}function du(e,t,r,n){Te(e);let o=Ds({dkLen:32,asyncTick:10},n),{c:s,dkLen:i,asyncTick:c}=o;if(Nt(s),Nt(i),Nt(c),s<1)throw new Error("iterations (c) should be >= 1");let a=Vn(t),u=Vn(r),d=new Uint8Array(i),l=Er.create(e,a),f=l._cloneInto().update(u);return{c:s,dkLen:i,asyncTick:c,DK:d,PRF:l,PRFSalt:f}}function pu(e,t,r,n,o){return e.destroy(),t.destroy(),n&&n.destroy(),mt(o),r}function ca(e,t,r,n){let{c:o,dkLen:s,DK:i,PRF:c,PRFSalt:a}=du(e,t,r,n),u,d=new Uint8Array(4),l=De(d),f=new Uint8Array(c.outputLen);for(let p=1,h=0;h<s;p++,h+=c.outputLen){let E=i.subarray(h,h+c.outputLen);l.setInt32(0,p,!1),(u=a._cloneInto(u)).update(d).digestInto(f),E.set(f.subarray(0,E.length));for(let A=1;A<o;A++){c._cloneInto(u).update(f).digestInto(f);for(let b=0;b<E.length;b++)E[b]^=f[b]}}return pu(c,a,i,u,f)}var Br=Uint32Array.from([1732584193,4023233417,2562383102,271733878,3285377520]),ae=new Uint32Array(80),fn=class extends de{constructor(){super(64,20,8,!1),this.A=Br[0]|0,this.B=Br[1]|0,this.C=Br[2]|0,this.D=Br[3]|0,this.E=Br[4]|0}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 a=0;a<16;a++,r+=4)ae[a]=t.getUint32(r,!1);for(let a=16;a<80;a++)ae[a]=Dr(ae[a-3]^ae[a-8]^ae[a-14]^ae[a-16],1);let{A:n,B:o,C:s,D:i,E:c}=this;for(let a=0;a<80;a++){let u,d;a<20?(u=Pr(o,s,i),d=1518500249):a<40?(u=o^s^i,d=1859775393):a<60?(u=kr(o,s,i),d=2400959708):(u=o^s^i,d=3395469782);let l=Dr(n,5)+u+c+d+ae[a]|0;c=i,i=s,s=Dr(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,c=c+this.E|0,this.set(n,o,s,i,c)}roundClean(){mt(ae)}destroy(){this.set(0,0,0,0,0),mt(this.buffer)}},fa=ir(()=>new fn);var ua=fa;var ha=qr;var la={sha1:ua,"sha2-256":je,"sha2-512":ha};function Vo(e,t,r,n,o){if(o!=="sha1"&&o!=="sha2-256"&&o!=="sha2-512"){let c=Object.keys(la).join(" / ");throw new N(`Hash '${o}' is unknown or not supported. Must be ${c}`)}let s=la[o],i=ca(s,e,t,{c:r,dkLen:n});return _n.encode(i).substring(1)}return ba(mu);})();
2
+ "use strict";var Libp2PCrypto=(()=>{var un=Object.defineProperty;var da=Object.getOwnPropertyDescriptor;var pa=Object.getOwnPropertyNames;var ma=Object.prototype.hasOwnProperty;var st=(e,t)=>{for(var r in t)un(e,r,{get:t[r],enumerable:!0})},ya=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of pa(t))!ma.call(e,o)&&o!==r&&un(e,o,{get:()=>t[o],enumerable:!(n=da(t,o))||n.enumerable});return e};var ba=e=>ya(un({},"__esModule",{value:!0}),e);var mu={};st(mu,{hmac:()=>Ir,keys:()=>qo,pbkdf2:()=>Vo,randomBytes:()=>vo});var Ir={};st(Ir,{create:()=>hn});var Ye=class extends Error{constructor(t="An error occurred while signing a message"){super(t),this.name="SigningError"}},Xe=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},_r=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Zo={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new _r("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 G=Zo;var zo={SHA1:20,SHA256:32,SHA512:64};var xa={SHA1:"SHA-1",SHA256:"SHA-256",SHA512:"SHA-512"},ga=async(e,t)=>{let r=await G.get().subtle.sign({name:"HMAC"},e,t);return new Uint8Array(r,0,r.byteLength)};async function hn(e,t){let r=xa[e],n=await G.get().subtle.importKey("raw",t,{name:"HMAC",hash:{name:r}},!1,["sign"]);return{async digest(o){return ga(n,o)},length:zo[e]}}var qo={};st(qo,{generateEphemeralKeyPair:()=>sa,generateKeyPair:()=>eu,generateKeyPairFromSeed:()=>ru,keyStretcher:()=>aa,privateKeyFromCryptoKeyPair:()=>lu,privateKeyFromProtobuf:()=>iu,privateKeyFromRaw:()=>au,privateKeyToCryptoKeyPair:()=>hu,privateKeyToProtobuf:()=>cu,publicKeyFromMultihash:()=>su,publicKeyFromProtobuf:()=>nu,publicKeyFromRaw:()=>ou,publicKeyToProtobuf:()=>ue});var N=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Ee=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}},$e=class extends Error{static name="InvalidPrivateKeyError";constructor(t="Invalid private key"){super(t),this.name="InvalidPrivateKeyError"}};var Yt=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var yn={};st(yn,{base58btc:()=>tt,base58flickr:()=>_a});var _u=new Uint8Array(0);function Go(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 Dt(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 Yo(e){return new TextEncoder().encode(e)}function Xo(e){return new TextDecoder().decode(e)}function wa(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 c=e.length,a=e.charAt(0),u=Math.log(c)/Math.log(256),d=Math.log(256)/Math.log(c);function l(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var E=0,S=0,b=0,B=h.length;b!==B&&h[b]===0;)b++,E++;for(var g=(B-b)*d+1>>>0,U=new Uint8Array(g);b!==B;){for(var D=h[b],O=0,H=g-1;(D!==0||O<S)&&H!==-1;H--,O++)D+=256*U[H]>>>0,U[H]=D%c>>>0,D=D/c>>>0;if(D!==0)throw new Error("Non-zero carry");S=O,b++}for(var R=g-S;R!==g&&U[R]===0;)R++;for(var w=a.repeat(E);R<g;++R)w+=e.charAt(U[R]);return w}function f(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var E=0;if(h[E]!==" "){for(var S=0,b=0;h[E]===a;)S++,E++;for(var B=(h.length-E)*u+1>>>0,g=new Uint8Array(B);h[E];){var U=r[h.charCodeAt(E)];if(U===255)return;for(var D=0,O=B-1;(U!==0||D<b)&&O!==-1;O--,D++)U+=c*g[O]>>>0,g[O]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");b=D,E++}if(h[E]!==" "){for(var H=B-b;H!==B&&g[H]===0;)H++;for(var R=new Uint8Array(S+(B-H)),w=S;H!==B;)R[w++]=g[H++];return R}}}function p(h){var E=f(h);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:f,decode:p}}var Ea=wa,Aa=Ea,Wo=Aa;var ln=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")}},dn=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 Jo(this,t)}},pn=class{decoders;constructor(t){this.decoders=t}or(t){return Jo(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 Jo(e,t){return new pn({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var mn=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 ln(t,r,n),this.decoder=new dn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ae({name:e,prefix:t,encode:r,decode:n}){return new mn(e,t,r,n)}function Xt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Wo(r,e);return Ae({prefix:t,name:e,encode:n,decode:s=>Dt(o(s))})}function Sa(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,c=0,a=0;for(let u=0;u<o;++u){let d=t[e[u]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|d,i+=r,i>=8&&(i-=8,s[a++]=255&c>>i)}if(i>=r||(255&c<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Ba(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,c=0;for(let a=0;a<e.length;++a)for(c=c<<8|e[a],i+=8;i>r;)i-=r,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function va(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function W({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=va(n);return Ae({prefix:t,name:e,encode(s){return Ba(s,n,r)},decode(s){return Sa(s,o,r,e)}})}var tt=Xt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),_a=Xt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var bn={};st(bn,{base32:()=>Se,base32hex:()=>Ua,base32hexpad:()=>Ca,base32hexpadupper:()=>Da,base32hexupper:()=>Ta,base32pad:()=>Ka,base32padupper:()=>La,base32upper:()=>Ia,base32z:()=>Ra});var Se=W({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ia=W({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ka=W({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),La=W({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ua=W({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ta=W({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ca=W({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Da=W({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ra=W({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var xn={};st(xn,{base36:()=>We,base36upper:()=>Pa});var We=Xt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Pa=Xt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ka=es,Qo=128,Na=127,Ha=~Na,Oa=Math.pow(2,31);function es(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Oa;)t[r++]=e&255|Qo,e/=128;for(;e&Ha;)t[r++]=e&255|Qo,e>>>=7;return t[r]=e|0,es.bytes=r-n+1,t}var Ma=gn,qa=128,ts=127;function gn(e,n){var r=0,n=n||0,o=0,s=n,i,c=e.length;do{if(s>=c)throw gn.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&ts)<<o:(i&ts)*Math.pow(2,o),o+=7}while(i>=qa);return gn.bytes=s-n,r}var Va=Math.pow(2,7),Fa=Math.pow(2,14),ja=Math.pow(2,21),Za=Math.pow(2,28),za=Math.pow(2,35),Ga=Math.pow(2,42),Ya=Math.pow(2,49),Xa=Math.pow(2,56),$a=Math.pow(2,63),Wa=function(e){return e<Va?1:e<Fa?2:e<ja?3:e<Za?4:e<za?5:e<Ga?6:e<Ya?7:e<Xa?8:e<$a?9:10},Ja={encode:ka,decode:Ma,encodingLength:Wa},Qa=Ja,Je=Qa;function Qe(e,t=0){return[Je.decode(e,t),Je.decode.bytes]}function Be(e,t,r=0){return Je.encode(e,t,r),t}function ve(e){return Je.encodingLength(e)}function Lt(e,t){let r=t.byteLength,n=ve(e),o=n+ve(r),s=new Uint8Array(o+r);return Be(e,s,0),Be(r,s,n),s.set(t,o),new _e(e,r,t,s)}function rs(e){let t=Dt(e),[r,n]=Qe(t),[o,s]=Qe(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new _e(r,o,i,t)}function ns(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Go(e.bytes,r.bytes)}}var _e=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function os(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return ec(r,wn(e),t??tt.encoder);default:return rc(r,wn(e),t??Se.encoder)}}var ss=new WeakMap;function wn(e){let t=ss.get(e);if(t==null){let r=new Map;return ss.set(e,r),r}return t}var St=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!==er)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==nc)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&&ns(t.multihash,n.multihash)}toString(t){return os(this,t)}toJSON(){return{"/":os(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??is(n,o,s.bytes))}else if(r[oc]===!0){let{version:n,multihash:o,code:s}=r,i=rs(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!==er)throw new Error(`Version 0 CID must use dag-pb (code: ${er}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=is(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,er,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=Dt(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 _e(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,f]=Qe(t.subarray(r));return r+=f,l},o=n(),s=er;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,c=n(),a=n(),u=r+a,d=u-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:d,size:u}}static parse(t,r){let[n,o]=tc(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 wn(s).set(n,t),s}};function tc(e,t){switch(e[0]){case"Q":{let r=t??tt;return[tt.prefix,r.decode(`${tt.prefix}${e}`)]}case tt.prefix:{let r=t??tt;return[tt.prefix,r.decode(e)]}case Se.prefix:{let r=t??Se;return[Se.prefix,r.decode(e)]}case We.prefix:{let r=t??We;return[We.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 ec(e,t,r){let{prefix:n}=r;if(n!==tt.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 rc(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 er=112,nc=18;function is(e,t,r){let n=ve(e),o=n+ve(t),s=new Uint8Array(o+r.byteLength);return Be(e,s,0),Be(t,s,n),s.set(r,o),s}var oc=Symbol.for("@ipld/js-cid/CID");var En={};st(En,{identity:()=>ce});var as=0,sc="identity",cs=Dt;function ic(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(as,cs(e))}var ce={code:as,name:sc,encode:cs,digest:ic};function it(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 Rt(e=0){return new Uint8Array(e)}function yt(e=0){return new Uint8Array(e)}function Ut(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 r}var us=Symbol.for("@achingbrain/uint8arraylist");function fs(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 Lr(e){return!!e?.[us]}var ct=class e{bufs;length;[us]=!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(Lr(n))r+=n.byteLength,this.bufs.push(...n.bufs);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(Lr(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=fs(this.bufs,t);return r.buf[r.index]}set(t,r){let n=fs(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(Lr(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 Ut(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Ut(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],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let u=t>=c&&t<a,d=r>c&&r<=a;if(u&&d){if(t===c&&r===a){n.push(i);break}let l=t-c;n.push(i.subarray(l,l+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(d){if(r===a){n.push(i);break}n.push(i.subarray(0,r-c));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Lr(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 c=i,a=this.byteLength-n.byteLength,u=n.byteLength-1,d;for(let l=r;l<=a;l+=d){d=0;for(let f=u;f>=0;f--){let p=this.get(l+f);if(n[f]!==p){d=Math.max(1,f-c[p]);break}}if(d===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=Rt(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=Rt(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=Rt(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=Rt(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=Rt(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=Rt(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=Rt(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=Rt(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(!it(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 An={};st(An,{base10:()=>ac});var ac=Xt({prefix:"9",name:"base10",alphabet:"0123456789"});var Sn={};st(Sn,{base16:()=>cc,base16upper:()=>fc});var cc=W({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),fc=W({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Bn={};st(Bn,{base2:()=>uc});var uc=W({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var vn={};st(vn,{base256emoji:()=>mc});var hs=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}"),hc=hs.reduce((e,t,r)=>(e[r]=t,e),[]),lc=hs.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function dc(e){return e.reduce((t,r)=>(t+=hc[r],t),"")}function pc(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=lc[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var mc=Ae({prefix:"\u{1F680}",name:"base256emoji",encode:dc,decode:pc});var In={};st(In,{base64:()=>_n,base64pad:()=>yc,base64url:()=>bc,base64urlpad:()=>xc});var _n=W({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),yc=W({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),bc=W({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),xc=W({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Kn={};st(Kn,{base8:()=>gc});var gc=W({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ln={};st(Ln,{identity:()=>wc});var wc=Ae({prefix:"\0",name:"identity",encode:e=>Xo(e),decode:e=>Yo(e)});var fh=new TextEncoder,uh=new TextDecoder;var Cn={};st(Cn,{sha256:()=>Ur,sha512:()=>Bc});var Sc=20;function Tn({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Un(e,t,r,n,o)}var Un=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Sc,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?ls(n,this.code,r?.truncate):n.then(o=>ls(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function ls(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 ps(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Ur=Tn({name:"sha2-256",code:18,encode:ps("SHA-256")}),Bc=Tn({name:"sha2-512",code:19,encode:ps("SHA-512")});var Dn={...Ln,...Bn,...Kn,...An,...Sn,...bn,...xn,...yn,...In,...vn},Ah={...Cn,...En};function ys(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var ms=ys("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Rn=ys("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}),vc={utf8:ms,"utf-8":ms,hex:Dn.base16,latin1:Rn,ascii:Rn,binary:Rn,...Dn},Tr=vc;function Z(e,t="utf8"){let r=Tr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function q(e,t="utf8"){let r=Tr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var _c=parseInt("11111",2),Pn=parseInt("10000000",2),Ic=parseInt("01111111",2),bs={0:rr,1:rr,2:Kc,3:Tc,4:Cc,5:Uc,6:Lc,16:rr,22:rr,48:rr};function bt(e,t={offset:0}){let r=e[t.offset]&_c;if(t.offset++,bs[r]!=null)return bs[r](e,t);throw new Error("No decoder for tag "+r)}function nr(e,t){let r=0;if((e[t.offset]&Pn)===Pn){let n=e[t.offset]&Ic,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 rr(e,t){nr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=bt(e,t);if(n===null)break;r.push(n)}return r}function Kc(e,t){let r=nr(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 Lc(e,t){let r=nr(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 c=`${s}.${i}`,a=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,a.push(u&127),u<128){a.reverse();let d=0;for(let l=0;l<a.length;l++)d+=a[l]<<l*7;c+=`.${d}`,a=[]}}return c}function Uc(e,t){return t.offset++,null}function Tc(e,t){let r=nr(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 Cc(e,t){let r=nr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Dc(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new ct;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=Dc(e.byteLength);return new ct(Uint8Array.from([t.byteLength|Pn]),t)}function ft(e){let t=new ct,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new ct(Uint8Array.from([2]),Cr(t),t)}function or(e){let t=Uint8Array.from([0]),r=new ct(t,e);return new ct(Uint8Array.from([3]),Cr(r),r)}function xs(e){return new ct(Uint8Array.from([4]),Cr(e),e)}function vt(e,t=48){let r=new ct;for(let n of e)r.append(n);return new ct(Uint8Array.from([t]),Cr(r),r)}var kn="1.2.840.10045.3.1.7",Nn="1.3.132.0.34",Hn="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}var Rc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Pc=Uint8Array.from([6,5,43,129,4,0,34]),kc=Uint8Array.from([6,5,43,129,4,0,35]),As={ext:!0,kty:"EC",crv:"P-256"},Ss={ext:!0,kty:"EC",crv:"P-384"},Bs={ext:!0,kty:"EC",crv:"P-521"},Ie=32,Ke=48,Le=66;function vs(e){let t=bt(e);return On(t)}function On(e){let t=e[1],r=q(t,"base64url"),n=e[2][1][0],o=1,s,i;if(t.byteLength===Ie)return s=q(n.subarray(o,o+Ie),"base64url"),i=q(n.subarray(o+Ie),"base64url"),new Pt({...As,key_ops:["sign"],d:r,x:s,y:i});if(t.byteLength===Ke)return s=q(n.subarray(o,o+Ke),"base64url"),i=q(n.subarray(o+Ke),"base64url"),new Pt({...Ss,key_ops:["sign"],d:r,x:s,y:i});if(t.byteLength===Le)return s=q(n.subarray(o,o+Le),"base64url"),i=q(n.subarray(o+Le),"base64url"),new Pt({...Bs,key_ops:["sign"],d:r,x:s,y:i});throw new N(`Private key length was wrong length, got ${t.byteLength}, expected 32, 48 or 66`)}function Mn(e){let t=bt(e);return qn(t)}function qn(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Ie*2+1)return n=q(t.subarray(r,r+Ie),"base64url"),o=q(t.subarray(r+Ie),"base64url"),new fe({...As,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ke*2+1)return n=q(t.subarray(r,r+Ke),"base64url"),o=q(t.subarray(r+Ke),"base64url"),new fe({...Ss,key_ops:["verify"],x:n,y:o});if(t.byteLength===Le*2+1)return n=q(t.subarray(r,r+Le),"base64url"),o=q(t.subarray(r+Le),"base64url"),new fe({...Bs,key_ops:["verify"],x:n,y:o});throw new N(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function _s(e){return vt([ft(Uint8Array.from([1])),xs(Z(e.d??"","base64url")),vt([Ks(e.crv)],160),vt([or(new ct(Uint8Array.from([4]),Z(e.x??"","base64url"),Z(e.y??"","base64url")))],161)]).subarray()}function Is(e){return vt([ft(Uint8Array.from([1])),vt([Ks(e.crv)],160),vt([or(new ct(Uint8Array.from([4]),Z(e.x??"","base64url"),Z(e.y??"","base64url")))],161)]).subarray()}function Ks(e){if(e==="P-256")return Rc;if(e==="P-384")return Pc;if(e==="P-521")return kc;throw new N(`Invalid curve ${e}`)}async function Ls(e="P-256"){let t=await gs(e);return new Pt(t.privateKey)}var fe=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Is(this.jwk)),this._raw}toMultihash(){return ce.digest(ue(this))}toCID(){return St.createV1(114,this.toMultihash())}toString(){return tt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:it(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 fe({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=_s(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:it(this.raw,t.raw)}async sign(t,r){return ws(this.jwk,t,r)}};var he=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Ht(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Nt(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function ut(e,...t){if(!Ht(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Te(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Nt(e.outputLen),Nt(e.blockLen)}function Ce(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 Ts(e,t){ut(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+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 _t(e,t){return e<<32-t|e>>>t}function Dr(e,t){return e<<t|e>>>32-t>>>0}var Cs=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Nc=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Bt(e){if(ut(e),Cs)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Nc[e[r]];return t}var kt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Us(e){if(e>=kt._0&&e<=kt._9)return e-kt._0;if(e>=kt.A&&e<=kt.F)return e-(kt.A-10);if(e>=kt.a&&e<=kt.f)return e-(kt.a-10)}function le(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Cs)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=Us(e.charCodeAt(s)),c=Us(e.charCodeAt(s+1));if(i===void 0||c===void 0){let a=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function Rr(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function sr(e){return typeof e=="string"&&(e=Rr(e)),ut(e),e}function Vn(e){return typeof e=="string"&&(e=Rr(e)),ut(e),e}function ht(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];ut(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 Ds(e,t){if(t!==void 0&&{}.toString.call(t)!=="[object Object]")throw new Error("options should be object or undefined");return Object.assign(e,t)}var Ue=class{};function ir(e){let t=n=>e().update(sr(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function $t(e=32){if(he&&typeof he.getRandomValues=="function")return he.getRandomValues(new Uint8Array(e));if(he&&typeof he.randomBytes=="function")return Uint8Array.from(he.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function Hc(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),c=Number(r&s),a=n?4:0,u=n?0:4;e.setUint32(t+a,i,n),e.setUint32(t+u,c,n)}function Pr(e,t,r){return e&t^~e&r}function kr(e,t,r){return e&t^e&r^t&r}var de=class extends Ue{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=De(this.buffer)}update(t){Ce(this),t=sr(t),ut(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=De(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ce(this),Ts(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;Hc(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=De(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=a/4,d=this.get();if(u>d.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)c.setUint32(4*l,d[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||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Ot=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var nt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Nr=BigInt(4294967295),Rs=BigInt(32);function Oc(e,t=!1){return t?{h:Number(e&Nr),l:Number(e>>Rs&Nr)}:{h:Number(e>>Rs&Nr)|0,l:Number(e&Nr)|0}}function Ps(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:c}=Oc(e[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var Fn=(e,t,r)=>e>>>r,jn=(e,t,r)=>e<<32-r|t>>>r,pe=(e,t,r)=>e>>>r|t<<32-r,me=(e,t,r)=>e<<32-r|t>>>r,ar=(e,t,r)=>e<<64-r|t>>>r-32,cr=(e,t,r)=>e>>>r-32|t<<64-r;function Tt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var ks=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Ns=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Hs=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Os=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Ms=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),qs=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var qc=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]),Wt=new Uint32Array(64),Hr=class extends de{constructor(t=32){super(64,t,8,!1),this.A=Ot[0]|0,this.B=Ot[1]|0,this.C=Ot[2]|0,this.D=Ot[3]|0,this.E=Ot[4]|0,this.F=Ot[5]|0,this.G=Ot[6]|0,this.H=Ot[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,r,n,o,s,i,c,a]}set(t,r,n,o,s,i,c,a){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(t,r){for(let l=0;l<16;l++,r+=4)Wt[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let f=Wt[l-15],p=Wt[l-2],h=_t(f,7)^_t(f,18)^f>>>3,E=_t(p,17)^_t(p,19)^p>>>10;Wt[l]=E+Wt[l-7]+h+Wt[l-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:u,H:d}=this;for(let l=0;l<64;l++){let f=_t(c,6)^_t(c,11)^_t(c,25),p=d+f+Pr(c,a,u)+qc[l]+Wt[l]|0,E=(_t(n,2)^_t(n,13)^_t(n,22))+kr(n,o,s)|0;d=u,u=a,a=c,c=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,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,d=d+this.H|0,this.set(n,o,s,i,c,a,u,d)}roundClean(){mt(Wt)}destroy(){this.set(0,0,0,0,0,0,0,0),mt(this.buffer)}};var Vs=Ps(["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))),Vc=Vs[0],Fc=Vs[1],Jt=new Uint32Array(80),Qt=new Uint32Array(80),Or=class extends de{constructor(t=64){super(128,t,16,!1),this.Ah=nt[0]|0,this.Al=nt[1]|0,this.Bh=nt[2]|0,this.Bl=nt[3]|0,this.Ch=nt[4]|0,this.Cl=nt[5]|0,this.Dh=nt[6]|0,this.Dl=nt[7]|0,this.Eh=nt[8]|0,this.El=nt[9]|0,this.Fh=nt[10]|0,this.Fl=nt[11]|0,this.Gh=nt[12]|0,this.Gl=nt[13]|0,this.Hh=nt[14]|0,this.Hl=nt[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:u,El:d,Fh:l,Fl:f,Gh:p,Gl:h,Hh:E,Hl:S}=this;return[t,r,n,o,s,i,c,a,u,d,l,f,p,h,E,S]}set(t,r,n,o,s,i,c,a,u,d,l,f,p,h,E,S){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=c|0,this.Dl=a|0,this.Eh=u|0,this.El=d|0,this.Fh=l|0,this.Fl=f|0,this.Gh=p|0,this.Gl=h|0,this.Hh=E|0,this.Hl=S|0}process(t,r){for(let g=0;g<16;g++,r+=4)Jt[g]=t.getUint32(r),Qt[g]=t.getUint32(r+=4);for(let g=16;g<80;g++){let U=Jt[g-15]|0,D=Qt[g-15]|0,O=pe(U,D,1)^pe(U,D,8)^Fn(U,D,7),H=me(U,D,1)^me(U,D,8)^jn(U,D,7),R=Jt[g-2]|0,w=Qt[g-2]|0,K=pe(R,w,19)^ar(R,w,61)^Fn(R,w,6),P=me(R,w,19)^cr(R,w,61)^jn(R,w,6),L=Hs(H,P,Qt[g-7],Qt[g-16]),x=Os(L,O,K,Jt[g-7],Jt[g-16]);Jt[g]=x|0,Qt[g]=L|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:u,Dl:d,Eh:l,El:f,Fh:p,Fl:h,Gh:E,Gl:S,Hh:b,Hl:B}=this;for(let g=0;g<80;g++){let U=pe(l,f,14)^pe(l,f,18)^ar(l,f,41),D=me(l,f,14)^me(l,f,18)^cr(l,f,41),O=l&p^~l&E,H=f&h^~f&S,R=Ms(B,D,H,Fc[g],Qt[g]),w=qs(R,b,U,O,Vc[g],Jt[g]),K=R|0,P=pe(n,o,28)^ar(n,o,34)^ar(n,o,39),L=me(n,o,28)^cr(n,o,34)^cr(n,o,39),x=n&s^n&c^s&c,m=o&i^o&a^i&a;b=E|0,B=S|0,E=p|0,S=h|0,p=l|0,h=f|0,{h:l,l:f}=Tt(u|0,d|0,w|0,K|0),u=c|0,d=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let y=ks(K,L,m);n=Ns(y,w,P,x),o=y|0}({h:n,l:o}=Tt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Tt(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=Tt(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l:d}=Tt(this.Dh|0,this.Dl|0,u|0,d|0),{h:l,l:f}=Tt(this.Eh|0,this.El|0,l|0,f|0),{h:p,l:h}=Tt(this.Fh|0,this.Fl|0,p|0,h|0),{h:E,l:S}=Tt(this.Gh|0,this.Gl|0,E|0,S|0),{h:b,l:B}=Tt(this.Hh|0,this.Hl|0,b|0,B|0),this.set(n,o,s,i,c,a,u,d,l,f,p,h,E,S,b,B)}roundClean(){mt(Jt,Qt)}destroy(){mt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Mr=ir(()=>new Hr);var qr=ir(()=>new Or);var Gn=BigInt(0),zn=BigInt(1);function Mt(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function xt(e,t,r=""){let n=Ht(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,c=s?` of length ${t}`:"",a=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+c+", got "+a)}return e}function fr(e){let t=e.toString(16);return t.length&1?"0"+t:t}function Fs(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Gn:BigInt("0x"+e)}function Re(e){return Fs(Bt(e))}function qt(e){return ut(e),Fs(Bt(Uint8Array.from(e).reverse()))}function Vr(e,t){return le(e.toString(16).padStart(t*2,"0"))}function Yn(e,t){return Vr(e,t).reverse()}function V(e,t,r){let n;if(typeof t=="string")try{n=le(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(Ht(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}function js(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function Xn(e){return Uint8Array.from(e)}var Zn=e=>typeof e=="bigint"&&Gn<=e;function Zs(e,t,r){return Zn(e)&&Zn(t)&&Zn(r)&&t<=e&&e<r}function ur(e,t,r,n){if(!Zs(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Fr(e){let t;for(t=0;e>Gn;e>>=zn,t+=1);return t}var te=e=>(zn<<BigInt(e))-zn;function zs(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=p=>new Uint8Array(p),o=p=>Uint8Array.of(p),s=n(e),i=n(e),c=0,a=()=>{s.fill(1),i.fill(0),c=0},u=(...p)=>r(i,s,...p),d=(p=n(0))=>{i=u(o(0),p),s=u(),p.length!==0&&(i=u(o(1),p),s=u())},l=()=>{if(c++>=1e3)throw new Error("drbg: tried 1000 values");let p=0,h=[];for(;p<t;){s=u();let E=s.slice();h.push(E),p+=s.length}return ht(...h)};return(p,h)=>{a(),d(p);let E;for(;!(E=h(l()));)d();return a(),E}}function ee(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let c=e[o];if(i&&c===void 0)return;let a=typeof c;if(a!==s||c===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${a}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}var $n=()=>{throw new Error("not implemented")};function Pe(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var lt=BigInt(0),et=BigInt(1),ye=BigInt(2),Xs=BigInt(3),$s=BigInt(4),Ws=BigInt(5),jc=BigInt(7),Js=BigInt(8),Zc=BigInt(9),Qs=BigInt(16);function J(e,t){let r=e%t;return r>=lt?r:t+r}function z(e,t,r){let n=e;for(;t-- >lt;)n*=n,n%=r;return n}function Gs(e,t){if(e===lt)throw new Error("invert: expected non-zero number");if(t<=lt)throw new Error("invert: expected positive modulus, got "+t);let r=J(e,t),n=t,o=lt,s=et,i=et,c=lt;for(;r!==lt;){let u=n/r,d=n%r,l=o-i*u,f=s-c*u;n=r,r=d,o=i,s=c,i=l,c=f}if(n!==et)throw new Error("invert: does not exist");return J(o,t)}function Wn(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function ti(e,t){let r=(e.ORDER+et)/$s,n=e.pow(t,r);return Wn(e,n,t),n}function zc(e,t){let r=(e.ORDER-Ws)/Js,n=e.mul(t,ye),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,ye),o),c=e.mul(s,e.sub(i,e.ONE));return Wn(e,c,t),c}function Gc(e){let t=gt(e),r=ei(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+jc)/Qs;return(c,a)=>{let u=c.pow(a,i),d=c.mul(u,n),l=c.mul(u,o),f=c.mul(u,s),p=c.eql(c.sqr(d),a),h=c.eql(c.sqr(l),a);u=c.cmov(u,d,p),d=c.cmov(f,l,h);let E=c.eql(c.sqr(d),a),S=c.cmov(u,d,E);return Wn(c,S,a),S}}function ei(e){if(e<Xs)throw new Error("sqrt is not defined for small field");let t=e-et,r=0;for(;t%ye===lt;)t/=ye,r++;let n=ye,o=gt(e);for(;Ys(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return ti;let s=o.pow(n,t),i=(t+et)/ye;return function(a,u){if(a.is0(u))return u;if(Ys(a,u)!==1)throw new Error("Cannot find square root");let d=r,l=a.mul(a.ONE,s),f=a.pow(u,t),p=a.pow(u,i);for(;!a.eql(f,a.ONE);){if(a.is0(f))return a.ZERO;let h=1,E=a.sqr(f);for(;!a.eql(E,a.ONE);)if(h++,E=a.sqr(E),h===d)throw new Error("Cannot find square root");let S=et<<BigInt(d-h-1),b=a.pow(l,S);d=h,l=a.sqr(b),f=a.mul(f,l),p=a.mul(p,b)}return p}}function Yc(e){return e%$s===Xs?ti:e%Js===Ws?zc:e%Qs===Zc?Gc(e):ei(e)}var Vt=(e,t)=>(J(e,t)&et)===et,Xc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Jn(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=Xc.reduce((n,o)=>(n[o]="function",n),t);return ee(e,r),e}function $c(e,t,r){if(r<lt)throw new Error("invalid exponent, negatives unsupported");if(r===lt)return e.ONE;if(r===et)return t;let n=e.ONE,o=t;for(;r>lt;)r&et&&(n=e.mul(n,o)),o=e.sqr(o),r>>=et;return n}function hr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,c,a)=>e.is0(c)?i:(n[a]=i,e.mul(i,c)),e.ONE),s=e.inv(o);return t.reduceRight((i,c,a)=>e.is0(c)?i:(n[a]=e.mul(i,n[a]),e.mul(i,c)),s),n}function Ys(e,t){let r=(e.ORDER-et)/ye,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function jr(e,t){t!==void 0&&Nt(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function gt(e,t,r=!1,n={}){if(e<=lt)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s,i=!1,c;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let f=t;f.BITS&&(o=f.BITS),f.sqrt&&(s=f.sqrt),typeof f.isLE=="boolean"&&(r=f.isLE),typeof f.modFromBytes=="boolean"&&(i=f.modFromBytes),c=f.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:a,nByteLength:u}=jr(e,o);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let d,l=Object.freeze({ORDER:e,isLE:r,BITS:a,BYTES:u,MASK:te(a),ZERO:lt,ONE:et,allowedLengths:c,create:f=>J(f,e),isValid:f=>{if(typeof f!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof f);return lt<=f&&f<e},is0:f=>f===lt,isValidNot0:f=>!l.is0(f)&&l.isValid(f),isOdd:f=>(f&et)===et,neg:f=>J(-f,e),eql:(f,p)=>f===p,sqr:f=>J(f*f,e),add:(f,p)=>J(f+p,e),sub:(f,p)=>J(f-p,e),mul:(f,p)=>J(f*p,e),pow:(f,p)=>$c(l,f,p),div:(f,p)=>J(f*Gs(p,e),e),sqrN:f=>f*f,addN:(f,p)=>f+p,subN:(f,p)=>f-p,mulN:(f,p)=>f*p,inv:f=>Gs(f,e),sqrt:s||(f=>(d||(d=Yc(e)),d(l,f))),toBytes:f=>r?Yn(f,u):Vr(f,u),fromBytes:(f,p=!0)=>{if(c){if(!c.includes(f.length)||f.length>u)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+f.length);let E=new Uint8Array(u);E.set(f,r?0:E.length-f.length),f=E}if(f.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+f.length);let h=r?qt(f):Re(f);if(i&&(h=J(h,e)),!p&&!l.isValid(h))throw new Error("invalid field element: outside of range 0..ORDER");return h},invertBatch:f=>hr(l,f),cmov:(f,p,h)=>h?p:f});return Object.freeze(l)}function ri(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function Qn(e){let t=ri(e);return t+Math.ceil(t/2)}function to(e,t,r=!1){let n=e.length,o=ri(t),s=Qn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?qt(e):Re(e),c=J(i,t-et)+et;return r?Yn(c,o):Vr(c,o)}var ke=BigInt(0),be=BigInt(1);function lr(e,t){let r=t.negate();return e?r:t}function Ft(e,t){let r=hr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function ii(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function eo(e,t){ii(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=te(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function ni(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,c=Number(e&o),a=e>>i;c>n&&(c-=s,a+=be);let u=t*n,d=u+Math.abs(c)-1,l=c===0,f=c<0,p=t%2!==0;return{nextN:a,offset:d,isZero:l,isNeg:f,isNegF:p,offsetF:u}}function Wc(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Jc(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var ro=new WeakMap,ai=new WeakMap;function no(e){return ai.get(e)||1}function oi(e){if(e!==ke)throw new Error("invalid wNAF")}var Ne=class{constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>ke;)r&be&&(n=n.add(o)),o=o.double(),r>>=be;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=eo(r,this.bits),s=[],i=t,c=i;for(let a=0;a<n;a++){c=i,s.push(c);for(let u=1;u<o;u++)c=c.add(i),s.push(c);i=c.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=eo(t,this.bits);for(let c=0;c<i.windows;c++){let{nextN:a,offset:u,isZero:d,isNeg:l,isNegF:f,offsetF:p}=ni(n,c,i);n=a,d?s=s.add(lr(f,r[p])):o=o.add(lr(l,r[u]))}return oi(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=eo(t,this.bits);for(let i=0;i<s.windows&&n!==ke;i++){let{nextN:c,offset:a,isZero:u,isNeg:d}=ni(n,i,s);if(n=c,!u){let l=r[a];o=o.add(d?l.negate():l)}}return oi(n),o}getPrecomputes(t,r,n){let o=ro.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),ro.set(r,o))),o}cached(t,r,n){let o=no(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=no(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){ii(r,this.bits),ai.set(t,r),ro.delete(t)}hasCache(t){return no(t)!==1}};function ci(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>ke||n>ke;)r&be&&(s=s.add(o)),n&be&&(i=i.add(o)),o=o.double(),r>>=be,n>>=be;return{p1:s,p2:i}}function He(e,t,r,n){Wc(r,e),Jc(n,t);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,c=Fr(BigInt(o)),a=1;c>12?a=c-3:c>4?a=c-2:c>0&&(a=2);let u=te(a),d=new Array(Number(u)+1).fill(i),l=Math.floor((t.BITS-1)/a)*a,f=i;for(let p=l;p>=0;p-=a){d.fill(i);for(let E=0;E<s;E++){let S=n[E],b=Number(S>>BigInt(p)&u);d[b]=d[b].add(r[E])}let h=i;for(let E=d.length-1,S=i;E>0;E--)S=S.add(d[E]),h=h.add(S);if(f=f.add(h),p!==0)for(let E=0;E<a;E++)f=f.double()}return f}function si(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Jn(t),t}else return gt(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 a of["p","n","h"]){let u=t[a];if(!(typeof u=="bigint"&&u>ke))throw new Error(`CURVE.${a} must be positive bigint`)}let o=si(t.p,r.Fp,n),s=si(t.n,r.Fn,n),c=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of c)if(!o.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}var re=BigInt(0),rt=BigInt(1),oo=BigInt(2),Qc=BigInt(8);function tf(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),c=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,c)}function ef(e,t={}){let r=Zr("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;ee(t,{},{uvRatio:"function"});let c=oo<<BigInt(o.BYTES*8)-rt,a=S=>n.create(S),u=t.uvRatio||((S,b)=>{try{return{isValid:!0,value:n.sqrt(n.div(S,b))}}catch{return{isValid:!1,value:re}}});if(!tf(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function d(S,b,B=!1){let g=B?rt:re;return ur("coordinate "+S,b,g,c),b}function l(S){if(!(S instanceof h))throw new Error("ExtendedPoint expected")}let f=Pe((S,b)=>{let{X:B,Y:g,Z:U}=S,D=S.is0();b==null&&(b=D?Qc:n.inv(U));let O=a(B*b),H=a(g*b),R=n.mul(U,b);if(D)return{x:re,y:rt};if(R!==rt)throw new Error("invZ was invalid");return{x:O,y:H}}),p=Pe(S=>{let{a:b,d:B}=s;if(S.is0())throw new Error("bad point: ZERO");let{X:g,Y:U,Z:D,T:O}=S,H=a(g*g),R=a(U*U),w=a(D*D),K=a(w*w),P=a(H*b),L=a(w*a(P+R)),x=a(K+a(B*a(H*R)));if(L!==x)throw new Error("bad point: equation left != right (1)");let m=a(g*U),y=a(D*O);if(m!==y)throw new Error("bad point: equation left != right (2)");return!0});class h{constructor(b,B,g,U){this.X=d("x",b),this.Y=d("y",B),this.Z=d("z",g,!0),this.T=d("t",U),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){if(b instanceof h)throw new Error("extended point not allowed");let{x:B,y:g}=b||{};return d("x",B),d("y",g),new h(B,g,rt,a(B*g))}static fromBytes(b,B=!1){let g=n.BYTES,{a:U,d:D}=s;b=Xn(xt(b,g,"point")),Mt(B,"zip215");let O=Xn(b),H=b[g-1];O[g-1]=H&-129;let R=qt(O),w=B?c:n.ORDER;ur("point.y",R,re,w);let K=a(R*R),P=a(K-rt),L=a(D*K-U),{isValid:x,value:m}=u(P,L);if(!x)throw new Error("bad point: invalid y coordinate");let y=(m&rt)===rt,A=(H&128)!==0;if(!B&&m===re&&A)throw new Error("bad point: x=0 and x_0=1");return A!==y&&(m=a(-m)),h.fromAffine({x:m,y:R})}static fromHex(b,B=!1){return h.fromBytes(V("point",b),B)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,B=!0){return E.createCache(this,b),B||this.multiply(oo),this}assertValidity(){p(this)}equals(b){l(b);let{X:B,Y:g,Z:U}=this,{X:D,Y:O,Z:H}=b,R=a(B*H),w=a(D*U),K=a(g*H),P=a(O*U);return R===w&&K===P}is0(){return this.equals(h.ZERO)}negate(){return new h(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:b}=s,{X:B,Y:g,Z:U}=this,D=a(B*B),O=a(g*g),H=a(oo*a(U*U)),R=a(b*D),w=B+g,K=a(a(w*w)-D-O),P=R+O,L=P-H,x=R-O,m=a(K*L),y=a(P*x),A=a(K*x),v=a(L*P);return new h(m,y,v,A)}add(b){l(b);let{a:B,d:g}=s,{X:U,Y:D,Z:O,T:H}=this,{X:R,Y:w,Z:K,T:P}=b,L=a(U*R),x=a(D*w),m=a(H*g*P),y=a(O*K),A=a((U+D)*(R+w)-L-x),v=y-m,T=y+m,_=a(x-B*L),I=a(A*v),C=a(T*_),k=a(A*_),Y=a(v*T);return new h(I,C,Y,k)}subtract(b){return this.add(b.negate())}multiply(b){if(!o.isValidNot0(b))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:B,f:g}=E.cached(this,b,U=>Ft(h,U));return Ft(h,[B,g])[0]}multiplyUnsafe(b,B=h.ZERO){if(!o.isValid(b))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return b===re?h.ZERO:this.is0()||b===rt?this:E.unsafe(this,b,g=>Ft(h,g),B)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return E.unsafe(this,s.n).is0()}toAffine(b){return f(this,b)}clearCofactor(){return i===rt?this:this.multiplyUnsafe(i)}toBytes(){let{x:b,y:B}=this.toAffine(),g=n.toBytes(B);return g[g.length-1]|=b&rt?128:0,g}toHex(){return Bt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(b){return Ft(h,b)}static msm(b,B){return He(h,o,b,B)}_setWindowSize(b){this.precompute(b)}toRawBytes(){return this.toBytes()}}h.BASE=new h(s.Gx,s.Gy,rt,a(s.Gx*s.Gy)),h.ZERO=new h(re,rt,rt,re),h.Fp=n,h.Fn=o;let E=new Ne(h,o.BITS);return h.BASE.precompute(8),h}var zr=class{constructor(t){this.ep=t}static fromBytes(t){$n()}static fromHex(t){$n()}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 Bt(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.init(this.ep.precompute(t,r))}toRawBytes(){return this.toBytes()}};function rf(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');ee(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=e,c=r.randomBytes||$t,a=r.adjustScalarBytes||(w=>w),u=r.domain||((w,K,P)=>{if(Mt(P,"phflag"),K.length||P)throw new Error("Contexts/pre-hash are not supported");return w});function d(w){return i.create(qt(w))}function l(w){let K=g.secretKey;w=V("private key",w,K);let P=V("hashed private key",t(w),2*K),L=a(P.slice(0,K)),x=P.slice(K,2*K),m=d(L);return{head:L,prefix:x,scalar:m}}function f(w){let{head:K,prefix:P,scalar:L}=l(w),x=o.multiply(L),m=x.toBytes();return{head:K,prefix:P,scalar:L,point:x,pointBytes:m}}function p(w){return f(w).pointBytes}function h(w=Uint8Array.of(),...K){let P=ht(...K);return d(t(u(P,V("context",w),!!n)))}function E(w,K,P={}){w=V("message",w),n&&(w=n(w));let{prefix:L,scalar:x,pointBytes:m}=f(K),y=h(P.context,L,w),A=o.multiply(y).toBytes(),v=h(P.context,A,m,w),T=i.create(y+v*x);if(!i.isValid(T))throw new Error("sign failed: invalid s");let _=ht(A,i.toBytes(T));return xt(_,g.signature,"result")}let S={zip215:!0};function b(w,K,P,L=S){let{context:x,zip215:m}=L,y=g.signature;w=V("signature",w,y),K=V("message",K),P=V("publicKey",P,g.publicKey),m!==void 0&&Mt(m,"zip215"),n&&(K=n(K));let A=y/2,v=w.subarray(0,A),T=qt(w.subarray(A,y)),_,I,C;try{_=e.fromBytes(P,m),I=e.fromBytes(v,m),C=o.multiplyUnsafe(T)}catch{return!1}if(!m&&_.isSmallOrder())return!1;let k=h(x,I.toBytes(),_.toBytes(),K);return I.add(_.multiplyUnsafe(k)).subtract(C).clearCofactor().is0()}let B=s.BYTES,g={secretKey:B,publicKey:B,signature:2*B,seed:B};function U(w=c(g.seed)){return xt(w,g.seed,"seed")}function D(w){let K=R.randomSecretKey(w);return{secretKey:K,publicKey:p(K)}}function O(w){return Ht(w)&&w.length===i.BYTES}function H(w,K){try{return!!e.fromBytes(w,K)}catch{return!1}}let R={getExtendedPublicKey:f,randomSecretKey:U,isValidSecretKey:O,isValidPublicKey:H,toMontgomery(w){let{y:K}=e.fromBytes(w),P=g.publicKey,L=P===32;if(!L&&P!==57)throw new Error("only defined for 25519 and 448");let x=L?s.div(rt+K,rt-K):s.div(K-rt,K+rt);return s.toBytes(x)},toMontgomerySecret(w){let K=g.secretKey;xt(w,K);let P=t(w.subarray(0,K));return a(P).subarray(0,K)},randomPrivateKey:U,precompute(w=8,K=e.BASE){return K.precompute(w,!1)}};return Object.freeze({keygen:D,getPublicKey:p,sign:E,verify:b,utils:R,Point:e,lengths:g})}function nf(e){let t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=gt(t.n,e.nBitLength,!0),o={Fp:r,Fn:n,uvRatio:e.uvRatio},s={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:o,hash:e.hash,eddsaOpts:s}}function of(e,t){let r=t.Point;return Object.assign({},t,{ExtendedPoint:r,CURVE:e,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function fi(e){let{CURVE:t,curveOpts:r,hash:n,eddsaOpts:o}=nf(e),s=ef(t,r),i=rf(s,n,o);return of(e,i)}var sf=BigInt(0),jt=BigInt(1),ui=BigInt(2),Il=BigInt(3),af=BigInt(5),cf=BigInt(8),Oe=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),dr={p:Oe,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:cf,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function ff(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Oe,c=e*e%s*e%s,a=z(c,ui,s)*c%s,u=z(a,jt,s)*e%s,d=z(u,af,s)*u%s,l=z(d,t,s)*d%s,f=z(l,r,s)*l%s,p=z(f,n,s)*f%s,h=z(p,o,s)*p%s,E=z(h,o,s)*p%s,S=z(E,t,s)*d%s;return{pow_p_5_8:z(S,ui,s)*e%s,b2:c}}function uf(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var so=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function co(e,t){let r=Oe,n=J(t*t*t,r),o=J(n*n*t,r),s=ff(e*o).pow_p_5_8,i=J(e*n*s,r),c=J(t*i*i,r),a=i,u=J(i*so,r),d=c===e,l=c===J(-e,r),f=c===J(-e*so,r);return d&&(i=a),(l||f)&&(i=u),Vt(i,r)&&(i=J(-i,r)),{isValid:d||l,value:i}}var ne=gt(dr.p,{isLE:!0}),hf=gt(dr.n,{isLE:!0}),lf={...dr,Fp:ne,hash:qr,adjustScalarBytes:uf,uvRatio:co},wt=fi(lf);var io=so,df=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),pf=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),mf=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),yf=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),hi=e=>co(jt,e),bf=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),ao=e=>wt.Point.Fp.create(qt(e)&bf);function li(e){let{d:t}=dr,r=Oe,n=b=>ne.create(b),o=n(io*e*e),s=n((o+jt)*mf),i=BigInt(-1),c=n((i-t*o)*n(o+t)),{isValid:a,value:u}=co(s,c),d=n(u*e);Vt(d,r)||(d=n(-d)),a||(u=d),a||(i=o);let l=n(i*(o-jt)*yf-c),f=u*u,p=n((u+u)*c),h=n(l*df),E=n(jt-f),S=n(jt+f);return new wt.Point(n(p*S),n(E*h),n(h*S),n(p*E))}function xf(e){ut(e,64);let t=ao(e.subarray(0,32)),r=li(t),n=ao(e.subarray(32,64)),o=li(n);return new Zt(r.add(o))}var Zt=class e extends zr{constructor(t){super(t)}static fromAffine(t){return new e(wt.Point.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static hashToCurve(t){return xf(V("ristrettoHash",t,64))}static fromBytes(t){ut(t,32);let{a:r,d:n}=dr,o=Oe,s=U=>ne.create(U),i=ao(t);if(!js(ne.toBytes(i),t)||Vt(i,o))throw new Error("invalid ristretto255 encoding 1");let c=s(i*i),a=s(jt+r*c),u=s(jt-r*c),d=s(a*a),l=s(u*u),f=s(r*n*d-l),{isValid:p,value:h}=hi(s(f*l)),E=s(h*u),S=s(h*E*f),b=s((i+i)*E);Vt(b,o)&&(b=s(-b));let B=s(a*S),g=s(b*B);if(!p||Vt(g,o)||B===sf)throw new Error("invalid ristretto255 encoding 2");return new e(new wt.Point(b,B,jt,g))}static fromHex(t){return e.fromBytes(V("ristrettoHex",t,32))}static msm(t,r){return He(e,wt.Point.Fn,t,r)}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=Oe,i=S=>ne.create(S),c=i(i(n+r)*i(n-r)),a=i(t*r),u=i(a*a),{value:d}=hi(i(c*u)),l=i(d*c),f=i(d*a),p=i(l*f*o),h;if(Vt(o*p,s)){let S=i(r*io),b=i(t*io);t=S,r=b,h=i(l*pf)}else h=f;Vt(t*p,s)&&(r=i(-r));let E=i((n-r)*h);return Vt(E,s)&&(E=i(-E)),ne.toBytes(E)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=u=>ne.create(u),c=i(r*s)===i(n*o),a=i(n*s)===i(r*o);return c||a}is0(){return this.equals(e.ZERO)}};Zt.BASE=new Zt(wt.Point.BASE);Zt.ZERO=new Zt(wt.Point.ZERO);Zt.Fp=ne;Zt.Fn=hf;var oe=32,Et=64,Gr=32;var Me,di=(async()=>{try{return await G.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function pi(){let e=wt.utils.randomPrivateKey(),t=wt.getPublicKey(e);return{privateKey:xi(e,t),publicKey:t}}function mi(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=wt.getPublicKey(t);return{privateKey:xi(t,r),publicKey:r}}async function gf(e,t){let r;e.length===Et?r=e.subarray(0,32):r=e;let n={crv:"Ed25519",kty:"OKP",x:q(e.subarray(32),"base64url"),d:q(r,"base64url"),ext:!0,key_ops:["sign"]},o=await G.get().subtle.importKey("jwk",n,{name:"Ed25519"},!0,["sign"]),s=await G.get().subtle.sign({name:"Ed25519"},o,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(s,0,s.byteLength)}function wf(e,t){let r=e.subarray(0,Gr);return wt.sign(t instanceof Uint8Array?t:t.subarray(),r)}async function yi(e,t){return Me==null&&(Me=await di),Me?gf(e,t):wf(e,t)}async function Ef(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await G.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await G.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 Af(e,t,r){return wt.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function bi(e,t,r){return Me==null&&(Me=await di),Me?Ef(e,t,r):Af(e,t,r)}function xi(e,t){let r=new Uint8Array(Et);for(let n=0;n<Gr;n++)r[n]=e[n],r[Gr+n]=t[n];return r}function fo(e,t){let r=Z(e,"base64urlpad");if(t!=null){if(r.length>t)throw new Error("byte array longer than desired length");r=Ut([new Uint8Array(t-r.length),r])}return r}function qe(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var pr=class{type="Ed25519";raw;constructor(t){this.raw=Ve(t,oe)}toMultihash(){return ce.digest(ue(this))}toCID(){return St.createV1(114,this.toMultihash())}toString(){return tt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:it(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=bi(this.raw,r,t);return qe(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}},xe=class{type="Ed25519";raw;publicKey;constructor(t,r){this.raw=Ve(t,Et),this.publicKey=new pr(r)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:it(this.raw,t.raw)}sign(t,r){r?.signal?.throwIfAborted();let n=yi(this.raw,t);return qe(n)?n.then(o=>(r?.signal?.throwIfAborted(),o)):(r?.signal?.throwIfAborted(),n)}};function uo(e){if(e.length>Et){e=Ve(e,Et+oe);let n=e.subarray(0,Et),o=e.subarray(Et,e.length);return new xe(n,o)}e=Ve(e,Et);let t=e.subarray(0,Et),r=e.subarray(oe);return new xe(t,r)}function Yr(e){return e=Ve(e,oe),new pr(e)}async function wi(){let{privateKey:e,publicKey:t}=pi();return new xe(e,t)}async function Ei(e){let{privateKey:t,publicKey:r}=mi(e);return new xe(t,r)}function Ve(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new N(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Sf=Math.pow(2,7),Bf=Math.pow(2,14),vf=Math.pow(2,21),Ai=Math.pow(2,28),Si=Math.pow(2,35),Bi=Math.pow(2,42),vi=Math.pow(2,49),dt=128,se=127;function mr(e){if(e<Sf)return 1;if(e<Bf)return 2;if(e<vf)return 3;if(e<Ai)return 4;if(e<Si)return 5;if(e<Bi)return 6;if(e<vi)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function _i(e,t,r=0){switch(mr(e)){case 8:t[r++]=e&255|dt,e/=128;case 7:t[r++]=e&255|dt,e/=128;case 6:t[r++]=e&255|dt,e/=128;case 5:t[r++]=e&255|dt,e/=128;case 4:t[r++]=e&255|dt,e>>>=7;case 3:t[r++]=e&255|dt,e>>>=7;case 2:t[r++]=e&255|dt,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Ii(e,t){let r=e[t],n=0;if(n+=r&se,r<dt||(r=e[t+1],n+=(r&se)<<7,r<dt)||(r=e[t+2],n+=(r&se)<<14,r<dt)||(r=e[t+3],n+=(r&se)<<21,r<dt)||(r=e[t+4],n+=(r&se)*Ai,r<dt)||(r=e[t+5],n+=(r&se)*Si,r<dt)||(r=e[t+6],n+=(r&se)*Bi,r<dt)||(r=e[t+7],n+=(r&se)*vi,r<dt))return n;throw new RangeError("Could not decode varint")}var ho=new Float32Array([-0]),ie=new Uint8Array(ho.buffer);function Ki(e,t,r){ho[0]=e,t[r]=ie[0],t[r+1]=ie[1],t[r+2]=ie[2],t[r+3]=ie[3]}function Li(e,t){return ie[0]=e[t],ie[1]=e[t+1],ie[2]=e[t+2],ie[3]=e[t+3],ho[0]}var lo=new Float64Array([-0]),at=new Uint8Array(lo.buffer);function Ui(e,t,r){lo[0]=e,t[r]=at[0],t[r+1]=at[1],t[r+2]=at[2],t[r+3]=at[3],t[r+4]=at[4],t[r+5]=at[5],t[r+6]=at[6],t[r+7]=at[7]}function Ti(e,t){return at[0]=e[t],at[1]=e[t+1],at[2]=e[t+2],at[3]=e[t+3],at[4]=e[t+4],at[5]=e[t+5],at[6]=e[t+6],at[7]=e[t+7],lo[0]}var _f=BigInt(Number.MAX_SAFE_INTEGER),If=BigInt(Number.MIN_SAFE_INTEGER),At=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 ge;if(t<_f&&t>If)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>Ci&&(o=0n,++n>Ci&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return ge;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):ge}},ge=new At(0,0);ge.toBigInt=function(){return 0n};ge.zzEncode=ge.zzDecode=function(){return this};ge.length=function(){return 1};var Ci=4294967296n;function Di(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 Ri(e,t,r){if(r-t<1)return"";let o,s=[],i=0,c;for(;t<r;)c=e[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|e[t++]&63:c>239&&c<365?(c=((c&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&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 po(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 Xr(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var mo=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,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 Xr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw It(this,4);return Xr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw It(this,4);let t=Li(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw It(this,4);let t=Ti(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 Ri(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 At(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=Xr(this.buf,this.pos+=4),r=Xr(this.buf,this.pos+=4);return new At(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=Ii(this.buf,this.pos);return this.pos+=mr(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 yo(e){return new mo(e instanceof Uint8Array?e:e.subarray())}function $r(e,t,r){let n=yo(e);return t.decode(n,void 0,r)}function bo(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 c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var we=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function xo(){}var wo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Kf=bo();function Lf(e){return globalThis.Buffer!=null?yt(e):Kf(e)}var br=class{len;head;tail;states;constructor(){this.len=0,this.head=new we(xo,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new we(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Eo((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(Wr,10,At.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=At.fromBigInt(t);return this._push(Wr,r.length(),r)}uint64Number(t){return this._push(_i,mr(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=At.fromBigInt(t).zzEncode();return this._push(Wr,r.length(),r)}sint64Number(t){let r=At.fromNumber(t).zzEncode();return this._push(Wr,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(go,1,t?1:0)}fixed32(t){return this._push(yr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=At.fromBigInt(t);return this._push(yr,4,r.lo)._push(yr,4,r.hi)}fixed64Number(t){let r=At.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(Ki,4,t)}double(t){return this._push(Ui,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(go,1,0):this.uint32(r)._push(Tf,r,t)}string(t){let r=Di(t);return r!==0?this.uint32(r)._push(po,r,t):this._push(go,1,0)}fork(){return this.states=new wo(this),this.head=this.tail=new we(xo,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 we(xo,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=Lf(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function go(e,t,r){t[r]=e&255}function Uf(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Eo=class extends we{next;constructor(t,r){super(Uf,t,r),this.next=void 0}};function Wr(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 Tf(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(Cf,t,e),this},br.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Df,t,e),this});function Cf(e,t,r){t.set(e,r)}function Df(e,t,r){e.length<40?po(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(Z(e),r)}function Ao(){return new br}function Jr(e,t){let r=Ao();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var Fe;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(Fe||(Fe={}));function Qr(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function So(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(s,i){let c=t(s);i.int32(c)},n=function(s){let i=s.int32();return t(i)};return Qr("enum",Fe.VARINT,r,n)}function tn(e,t){return Qr("message",Fe.LENGTH_DELIMITED,e,t)}var j;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(j||(j={}));var Bo;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Bo||(Bo={}));(function(e){e.codec=()=>So(Bo)})(j||(j={}));var Ct;(function(e){let t;e.codec=()=>(t==null&&(t=tn((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),j.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=j.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>Jr(r,e.codec()),e.decode=(r,n)=>$r(r,e.codec(),n)})(Ct||(Ct={}));var xr;(function(e){let t;e.codec=()=>(t==null&&(t=tn((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),j.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=j.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>Jr(r,e.codec()),e.decode=(r,n)=>$r(r,e.codec(),n)})(xr||(xr={}));function vo(e){if(isNaN(e)||e<=0)throw new N("random bytes length must be a Number bigger than 0");return $t(e)}var wr={};st(wr,{MAX_RSA_KEY_SIZE:()=>_o,generateRSAKeyPair:()=>Do,jwkToJWKKeyPair:()=>Oi,jwkToPkcs1:()=>Nf,jwkToPkix:()=>Uo,jwkToRSAPrivateKey:()=>nn,pkcs1MessageToJwk:()=>Ko,pkcs1MessageToRSAPrivateKey:()=>en,pkcs1ToJwk:()=>kf,pkcs1ToRSAPrivateKey:()=>To,pkixMessageToJwk:()=>Lo,pkixMessageToRSAPublicKey:()=>rn,pkixToJwk:()=>Hf,pkixToRSAPublicKey:()=>Co});var je=Mr;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=wr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return St.createV1(114,this._multihash)}toString(){return tt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:it(this.raw,t.raw)}verify(t,r,n){return Hi(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:it(this.raw,t.raw)}sign(t,r){return Ni(this.jwk,t,r)}};var _o=8192,Io=18,Rf=1062,Pf=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function kf(e){let t=bt(e);return Ko(t)}function Ko(e){return{n:q(e[1],"base64url"),e:q(e[2],"base64url"),d:q(e[3],"base64url"),p:q(e[4],"base64url"),q:q(e[5],"base64url"),dp:q(e[6],"base64url"),dq:q(e[7],"base64url"),qi:q(e[8],"base64url"),kty:"RSA"}}function Nf(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 N("JWK was missing components");return vt([ft(Uint8Array.from([0])),ft(Z(e.n,"base64url")),ft(Z(e.e,"base64url")),ft(Z(e.d,"base64url")),ft(Z(e.p,"base64url")),ft(Z(e.q,"base64url")),ft(Z(e.dp,"base64url")),ft(Z(e.dq,"base64url")),ft(Z(e.qi,"base64url"))]).subarray()}function Hf(e){let t=bt(e,{offset:0});return Lo(t)}function Lo(e){let t=bt(e[1],{offset:0});return{kty:"RSA",n:q(t[0],"base64url"),e:q(t[1],"base64url")}}function Uo(e){if(e.n==null||e.e==null)throw new N("JWK was missing components");return vt([Pf,or(vt([ft(Z(e.n,"base64url")),ft(Z(e.e,"base64url"))]))]).subarray()}function To(e){let t=bt(e);return en(t)}function en(e){let t=Ko(e);return nn(t)}function Co(e,t){if(e.byteLength>=Rf)throw new Ee("Key size is too large");let r=bt(e,{offset:0});return rn(r,e,t)}function rn(e,t,r){let n=Lo(e);if(r==null){let o=je(Ct.encode({Type:j.RSA,Data:t}));r=Lt(Io,o)}return new Ze(n,r)}function nn(e){if(qi(e)>_o)throw new N("Key size is too large");let t=Oi(e),r=je(Ct.encode({Type:j.RSA,Data:Uo(t.publicKey)})),n=Lt(Io,r);return new gr(t.privateKey,new Ze(t.publicKey,n))}async function Do(e){if(e>_o)throw new N("Key size is too large");let t=await Mi(e),r=je(Ct.encode({Type:j.RSA,Data:Uo(t.publicKey)})),n=Lt(Io,r);return new gr(t.privateKey,new Ze(t.publicKey,n))}function Oi(e){if(e==null)throw new N("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}var Vi="1.2.840.113549.1.1.1";async function Mi(e,t){let r=await G.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 Of(r,t);return{privateKey:n[0],publicKey:n[1]}}async function Ni(e,t,r){let n=await G.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await G.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 Hi(e,t,r,n){let o=await G.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await G.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function Of(e,t){if(e.privateKey==null||e.publicKey==null)throw new N("Private and public key are required");let r=await Promise.all([G.get().subtle.exportKey("jwk",e.privateKey),G.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function qi(e){if(e.kty!=="RSA")throw new N("invalid key type");if(e.n==null)throw new N("invalid key modulus");return Z(e.n,"base64url").length*8}var on=class extends Ue{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,Te(t);let n=sr(r);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),mt(s)}update(t){return Ce(this),this.iHash.update(t),this}digestInto(t){Ce(this),ut(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Er=(e,t,r)=>new on(e,t).update(r).digest();Er.create=(e,t)=>new on(e,t);var Fi=(e,t)=>(e+(e>=0?t:-t)/ji)/t;function Mf(e,t,r){let[[n,o],[s,i]]=t,c=Fi(i*e,r),a=Fi(-o*e,r),u=e-c*n-a*s,d=-c*o-a*i,l=u<Gt,f=d<Gt;l&&(u=-u),f&&(d=-d);let p=te(Math.ceil(Fr(r)/2))+Ge;if(u<Gt||u>=p||d<Gt||d>=p)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:u,k2neg:f,k2:d}}function Po(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Ro(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return Mt(r.lowS,"lowS"),Mt(r.prehash,"prehash"),r.format!==void 0&&Po(r.format),r}var ko=class extends Error{constructor(t=""){super(t)}},zt={Err:ko,_tlv:{encode:(e,t)=>{let{Err:r}=zt;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=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}=zt,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let a=o&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+a);if(u.length!==a)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let d of u)i=i<<8|d;if(n+=a,i<128)throw new r("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new r("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=zt;if(e<Gt)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}=zt;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Re(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=zt,o=V("signature",e),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,s),{v:u,l:d}=n.decode(2,a);if(d.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=zt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},Gt=BigInt(0),Ge=BigInt(1),ji=BigInt(2),sn=BigInt(3),qf=BigInt(4);function ze(e,t){let{BYTES:r}=e,n;if(typeof t=="bigint")n=t;else{let o=V("private key",t);try{n=e.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof t}`)}}if(!e.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function Vf(e,t={}){let r=Zr("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:c}=s;ee(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:a}=t;if(a&&(!n.is0(s.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=zi(n,o);function d(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(L,x,m){let{x:y,y:A}=x.toAffine(),v=n.toBytes(y);if(Mt(m,"isCompressed"),m){d();let T=!n.isOdd(A);return ht(Zi(T),v)}else return ht(Uint8Array.of(4),v,n.toBytes(A))}function f(L){xt(L,void 0,"Point");let{publicKey:x,publicKeyUncompressed:m}=u,y=L.length,A=L[0],v=L.subarray(1);if(y===x&&(A===2||A===3)){let T=n.fromBytes(v);if(!n.isValid(T))throw new Error("bad point: is not on curve, wrong x");let _=E(T),I;try{I=n.sqrt(_)}catch(Y){let F=Y instanceof Error?": "+Y.message:"";throw new Error("bad point: is not on curve, sqrt error"+F)}d();let C=n.isOdd(I);return(A&1)===1!==C&&(I=n.neg(I)),{x:T,y:I}}else if(y===m&&A===4){let T=n.BYTES,_=n.fromBytes(v.subarray(0,T)),I=n.fromBytes(v.subarray(T,T*2));if(!S(_,I))throw new Error("bad point: is not on curve");return{x:_,y:I}}else throw new Error(`bad point: got length ${y}, expected compressed=${x} or uncompressed=${m}`)}let p=t.toBytes||l,h=t.fromBytes||f;function E(L){let x=n.sqr(L),m=n.mul(x,L);return n.add(n.add(m,n.mul(L,s.a)),s.b)}function S(L,x){let m=n.sqr(x),y=E(L);return n.eql(m,y)}if(!S(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let b=n.mul(n.pow(s.a,sn),qf),B=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(b,B)))throw new Error("bad curve params: a or b");function g(L,x,m=!1){if(!n.isValid(x)||m&&n.is0(x))throw new Error(`bad point coordinate ${L}`);return x}function U(L){if(!(L instanceof w))throw new Error("ProjectivePoint expected")}function D(L){if(!a||!a.basises)throw new Error("no endo");return Mf(L,a.basises,o.ORDER)}let O=Pe((L,x)=>{let{X:m,Y:y,Z:A}=L;if(n.eql(A,n.ONE))return{x:m,y};let v=L.is0();x==null&&(x=v?n.ONE:n.inv(A));let T=n.mul(m,x),_=n.mul(y,x),I=n.mul(A,x);if(v)return{x:n.ZERO,y:n.ZERO};if(!n.eql(I,n.ONE))throw new Error("invZ was invalid");return{x:T,y:_}}),H=Pe(L=>{if(L.is0()){if(t.allowInfinityPoint&&!n.is0(L.Y))return;throw new Error("bad point: ZERO")}let{x,y:m}=L.toAffine();if(!n.isValid(x)||!n.isValid(m))throw new Error("bad point: x or y not field elements");if(!S(x,m))throw new Error("bad point: equation left != right");if(!L.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function R(L,x,m,y,A){return m=new w(n.mul(m.X,L),m.Y,m.Z),x=lr(y,x),m=lr(A,m),x.add(m)}class w{constructor(x,m,y){this.X=g("x",x),this.Y=g("y",m,!0),this.Z=g("z",y),Object.freeze(this)}static CURVE(){return s}static fromAffine(x){let{x:m,y}=x||{};if(!x||!n.isValid(m)||!n.isValid(y))throw new Error("invalid affine point");if(x instanceof w)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(y)?w.ZERO:new w(m,y,n.ONE)}static fromBytes(x){let m=w.fromAffine(h(xt(x,void 0,"point")));return m.assertValidity(),m}static fromHex(x){return w.fromBytes(V("pointHex",x))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(x=8,m=!0){return P.createCache(this,x),m||this.multiply(sn),this}assertValidity(){H(this)}hasEvenY(){let{y:x}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(x)}equals(x){U(x);let{X:m,Y:y,Z:A}=this,{X:v,Y:T,Z:_}=x,I=n.eql(n.mul(m,_),n.mul(v,A)),C=n.eql(n.mul(y,_),n.mul(T,A));return I&&C}negate(){return new w(this.X,n.neg(this.Y),this.Z)}double(){let{a:x,b:m}=s,y=n.mul(m,sn),{X:A,Y:v,Z:T}=this,_=n.ZERO,I=n.ZERO,C=n.ZERO,k=n.mul(A,A),Y=n.mul(v,v),F=n.mul(T,T),M=n.mul(A,v);return M=n.add(M,M),C=n.mul(A,T),C=n.add(C,C),_=n.mul(x,C),I=n.mul(y,F),I=n.add(_,I),_=n.sub(Y,I),I=n.add(Y,I),I=n.mul(_,I),_=n.mul(M,_),C=n.mul(y,C),F=n.mul(x,F),M=n.sub(k,F),M=n.mul(x,M),M=n.add(M,C),C=n.add(k,k),k=n.add(C,k),k=n.add(k,F),k=n.mul(k,M),I=n.add(I,k),F=n.mul(v,T),F=n.add(F,F),k=n.mul(F,M),_=n.sub(_,k),C=n.mul(F,Y),C=n.add(C,C),C=n.add(C,C),new w(_,I,C)}add(x){U(x);let{X:m,Y:y,Z:A}=this,{X:v,Y:T,Z:_}=x,I=n.ZERO,C=n.ZERO,k=n.ZERO,Y=s.a,F=n.mul(s.b,sn),M=n.mul(m,v),X=n.mul(y,T),Q=n.mul(A,_),pt=n.add(m,y),$=n.add(v,T);pt=n.mul(pt,$),$=n.add(M,X),pt=n.sub(pt,$),$=n.add(m,A);let ot=n.add(v,_);return $=n.mul($,ot),ot=n.add(M,Q),$=n.sub($,ot),ot=n.add(y,A),I=n.add(T,_),ot=n.mul(ot,I),I=n.add(X,Q),ot=n.sub(ot,I),k=n.mul(Y,$),I=n.mul(F,Q),k=n.add(I,k),I=n.sub(X,k),k=n.add(X,k),C=n.mul(I,k),X=n.add(M,M),X=n.add(X,M),Q=n.mul(Y,Q),$=n.mul(F,$),X=n.add(X,Q),Q=n.sub(M,Q),Q=n.mul(Y,Q),$=n.add($,Q),M=n.mul(X,$),C=n.add(C,M),M=n.mul(ot,$),I=n.mul(pt,I),I=n.sub(I,M),M=n.mul(pt,X),k=n.mul(ot,k),k=n.add(k,M),new w(I,C,k)}subtract(x){return this.add(x.negate())}is0(){return this.equals(w.ZERO)}multiply(x){let{endo:m}=t;if(!o.isValidNot0(x))throw new Error("invalid scalar: out of range");let y,A,v=T=>P.cached(this,T,_=>Ft(w,_));if(m){let{k1neg:T,k1:_,k2neg:I,k2:C}=D(x),{p:k,f:Y}=v(_),{p:F,f:M}=v(C);A=Y.add(M),y=R(m.beta,k,F,T,I)}else{let{p:T,f:_}=v(x);y=T,A=_}return Ft(w,[y,A])[0]}multiplyUnsafe(x){let{endo:m}=t,y=this;if(!o.isValid(x))throw new Error("invalid scalar: out of range");if(x===Gt||y.is0())return w.ZERO;if(x===Ge)return y;if(P.hasCache(this))return this.multiply(x);if(m){let{k1neg:A,k1:v,k2neg:T,k2:_}=D(x),{p1:I,p2:C}=ci(w,y,v,_);return R(m.beta,I,C,A,T)}else return P.unsafe(y,x)}multiplyAndAddUnsafe(x,m,y){let A=this.multiplyUnsafe(m).add(x.multiplyUnsafe(y));return A.is0()?void 0:A}toAffine(x){return O(this,x)}isTorsionFree(){let{isTorsionFree:x}=t;return i===Ge?!0:x?x(w,this):P.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:x}=t;return i===Ge?this:x?x(w,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(x=!0){return Mt(x,"isCompressed"),this.assertValidity(),p(w,this,x)}toHex(x=!0){return Bt(this.toBytes(x))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(x=!0){return this.toBytes(x)}_setWindowSize(x){this.precompute(x)}static normalizeZ(x){return Ft(w,x)}static msm(x,m){return He(w,o,x,m)}static fromPrivateKey(x){return w.BASE.multiply(ze(o,x))}}w.BASE=new w(s.Gx,s.Gy,n.ONE),w.ZERO=new w(n.ZERO,n.ONE,n.ZERO),w.Fp=n,w.Fn=o;let K=o.BITS,P=new Ne(w,t.endo?Math.ceil(K/2):K);return w.BASE.precompute(8),w}function Zi(e){return Uint8Array.of(e?2:3)}function zi(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Ff(e,t={}){let{Fn:r}=e,n=t.randomBytes||$t,o=Object.assign(zi(e.Fp,r),{seed:Qn(r.ORDER)});function s(p){try{return!!ze(r,p)}catch{return!1}}function i(p,h){let{publicKey:E,publicKeyUncompressed:S}=o;try{let b=p.length;return h===!0&&b!==E||h===!1&&b!==S?!1:!!e.fromBytes(p)}catch{return!1}}function c(p=n(o.seed)){return to(xt(p,o.seed,"seed"),r.ORDER)}function a(p,h=!0){return e.BASE.multiply(ze(r,p)).toBytes(h)}function u(p){let h=c(p);return{secretKey:h,publicKey:a(h)}}function d(p){if(typeof p=="bigint")return!1;if(p instanceof e)return!0;let{secretKey:h,publicKey:E,publicKeyUncompressed:S}=o;if(r.allowedLengths||h===E)return;let b=V("key",p).length;return b===E||b===S}function l(p,h,E=!0){if(d(p)===!0)throw new Error("first arg must be private key");if(d(h)===!1)throw new Error("second arg must be public key");let S=ze(r,p);return e.fromHex(h).multiply(S).toBytes(E)}return Object.freeze({getPublicKey:a,getSharedSecret:l,keygen:u,Point:e,utils:{isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c,isValidPrivateKey:s,randomPrivateKey:c,normPrivateKeyToScalar:p=>ze(r,p),precompute(p=8,h=e.BASE){return h.precompute(p,!1)}},lengths:o})}function jf(e,t,r={}){Te(t),ee(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||$t,o=r.hmac||((m,...y)=>Er(t,m,ht(...y))),{Fp:s,Fn:i}=e,{ORDER:c,BITS:a}=i,{keygen:u,getPublicKey:d,getSharedSecret:l,utils:f,lengths:p}=Ff(e,r),h={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},E="compact";function S(m){let y=c>>Ge;return m>y}function b(m,y){if(!i.isValidNot0(y))throw new Error(`invalid signature ${m}: out of range 1..Point.Fn.ORDER`);return y}function B(m,y){Po(y);let A=p.signature,v=y==="compact"?A:y==="recovered"?A+1:void 0;return xt(m,v,`${y} signature`)}class g{constructor(y,A,v){this.r=b("r",y),this.s=b("s",A),v!=null&&(this.recovery=v),Object.freeze(this)}static fromBytes(y,A=E){B(y,A);let v;if(A==="der"){let{r:C,s:k}=zt.toSig(xt(y));return new g(C,k)}A==="recovered"&&(v=y[0],A="compact",y=y.subarray(1));let T=i.BYTES,_=y.subarray(0,T),I=y.subarray(T,T*2);return new g(i.fromBytes(_),i.fromBytes(I),v)}static fromHex(y,A){return this.fromBytes(le(y),A)}addRecoveryBit(y){return new g(this.r,this.s,y)}recoverPublicKey(y){let A=s.ORDER,{r:v,s:T,recovery:_}=this;if(_==null||![0,1,2,3].includes(_))throw new Error("recovery id invalid");if(c*ji<A&&_>1)throw new Error("recovery id is ambiguous for h>1 curve");let C=_===2||_===3?v+c:v;if(!s.isValid(C))throw new Error("recovery id 2 or 3 invalid");let k=s.toBytes(C),Y=e.fromBytes(ht(Zi((_&1)===0),k)),F=i.inv(C),M=D(V("msgHash",y)),X=i.create(-M*F),Q=i.create(T*F),pt=e.BASE.multiplyUnsafe(X).add(Y.multiplyUnsafe(Q));if(pt.is0())throw new Error("point at infinify");return pt.assertValidity(),pt}hasHighS(){return S(this.s)}toBytes(y=E){if(Po(y),y==="der")return le(zt.hexFromSig(this));let A=i.toBytes(this.r),v=i.toBytes(this.s);if(y==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return ht(Uint8Array.of(this.recovery),A,v)}return ht(A,v)}toHex(y){return Bt(this.toBytes(y))}assertValidity(){}static fromCompact(y){return g.fromBytes(V("sig",y),"compact")}static fromDER(y){return g.fromBytes(V("sig",y),"der")}normalizeS(){return this.hasHighS()?new g(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Bt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Bt(this.toBytes("compact"))}}let U=r.bits2int||function(y){if(y.length>8192)throw new Error("input is too large");let A=Re(y),v=y.length*8-a;return v>0?A>>BigInt(v):A},D=r.bits2int_modN||function(y){return i.create(U(y))},O=te(a);function H(m){return ur("num < 2^"+a,m,Gt,O),i.toBytes(m)}function R(m,y){return xt(m,void 0,"message"),y?xt(t(m),void 0,"prehashed message"):m}function w(m,y,A){if(["recovered","canonical"].some(X=>X in A))throw new Error("sign() legacy options not supported");let{lowS:v,prehash:T,extraEntropy:_}=Ro(A,h);m=R(m,T);let I=D(m),C=ze(i,y),k=[H(C),H(I)];if(_!=null&&_!==!1){let X=_===!0?n(p.secretKey):_;k.push(V("extraEntropy",X))}let Y=ht(...k),F=I;function M(X){let Q=U(X);if(!i.isValidNot0(Q))return;let pt=i.inv(Q),$=e.BASE.multiply(Q).toAffine(),ot=i.create($.x);if(ot===Gt)return;let vr=i.create(pt*i.create(F+ot*C));if(vr===Gt)return;let Fo=($.x===ot?0:2)|Number($.y&Ge),jo=vr;return v&&S(vr)&&(jo=i.neg(vr),Fo^=1),new g(ot,jo,Fo)}return{seed:Y,k2sig:M}}function K(m,y,A={}){m=V("message",m);let{seed:v,k2sig:T}=w(m,y,A);return zs(t.outputLen,i.BYTES,o)(v,T)}function P(m){let y,A=typeof m=="string"||Ht(m),v=!A&&m!==null&&typeof m=="object"&&typeof m.r=="bigint"&&typeof m.s=="bigint";if(!A&&!v)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(v)y=new g(m.r,m.s);else if(A){try{y=g.fromBytes(V("sig",m),"der")}catch(T){if(!(T instanceof zt.Err))throw T}if(!y)try{y=g.fromBytes(V("sig",m),"compact")}catch{return!1}}return y||!1}function L(m,y,A,v={}){let{lowS:T,prehash:_,format:I}=Ro(v,h);if(A=V("publicKey",A),y=R(V("message",y),_),"strict"in v)throw new Error("options.strict was renamed to lowS");let C=I===void 0?P(m):g.fromBytes(V("sig",m),I);if(C===!1)return!1;try{let k=e.fromBytes(A);if(T&&C.hasHighS())return!1;let{r:Y,s:F}=C,M=D(y),X=i.inv(F),Q=i.create(M*X),pt=i.create(Y*X),$=e.BASE.multiplyUnsafe(Q).add(k.multiplyUnsafe(pt));return $.is0()?!1:i.create($.x)===Y}catch{return!1}}function x(m,y,A={}){let{prehash:v}=Ro(A,h);return y=R(y,v),g.fromBytes(m,"recovered").recoverPublicKey(y).toBytes()}return Object.freeze({keygen:u,getPublicKey:d,getSharedSecret:l,utils:f,lengths:p,Point:e,sign:K,verify:L,recoverPublicKey:x,Signature:g,hash:t})}function Zf(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,o=gt(t.n,{BITS:e.nBitLength,allowedLengths:n,modFromBytes:e.wrapPrivateKey}),s={Fp:r,Fn:o,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:s}}function zf(e){let{CURVE:t,curveOpts:r}=Zf(e),n={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,hash:e.hash,ecdsaOpts:n}}function Gf(e,t){let r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,jr(r.Fn.ORDER,r.Fn.BITS))})}function Gi(e){let{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:o}=zf(e),s=Vf(t,r),i=jf(s,n,o);return Gf(e,i)}function Yi(e,t){let r=n=>Gi({...e,hash:n});return{...r(t),create:r}}var Ho={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Yf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Xi=BigInt(2);function Xf(e){let t=Ho.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),u=e*e*e%t,d=u*u*e%t,l=z(d,r,t)*d%t,f=z(l,r,t)*d%t,p=z(f,Xi,t)*u%t,h=z(p,o,t)*p%t,E=z(h,s,t)*h%t,S=z(E,c,t)*E%t,b=z(S,a,t)*S%t,B=z(b,c,t)*E%t,g=z(B,r,t)*d%t,U=z(g,i,t)*h%t,D=z(U,n,t)*u%t,O=z(D,Xi,t);if(!No.eql(No.sqr(O),e))throw new Error("Cannot find square root");return O}var No=gt(Ho.p,{sqrt:Xf}),Kt=Yi({...Ho,Fp:No,lowS:!0,endo:Yf},Mr);var $i=33,Wi=32;function Ji(e,t,r){let n=Ur.digest(t instanceof Uint8Array?t:t.subarray());if(qe(n))return n.then(({digest:o})=>(r?.signal?.throwIfAborted(),Kt.sign(o,e).toDERRawBytes())).catch(o=>{throw o.name==="AbortError"?o:new Ye(String(o))});try{return Kt.sign(n.digest,e).toDERRawBytes()}catch(o){throw new Ye(String(o))}}function Qi(e,t,r,n){let o=Ur.digest(r instanceof Uint8Array?r:r.subarray());if(qe(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Kt.verify(t,s,e))).catch(s=>{throw s.name==="AbortError"?s:new Xe(String(s))});try{return n?.signal?.throwIfAborted(),Kt.verify(t,o.digest,e)}catch(s){throw new Xe(String(s))}}var Ar=class{type="secp256k1";raw;_key;constructor(t){this._key=ra(t),this.raw=ta(this._key)}toMultihash(){return ce.digest(ue(this))}toCID(){return St.createV1(114,this.toMultihash())}toString(){return tt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:it(this.raw,t.raw)}verify(t,r,n){return Qi(this._key,r,t,n)}},Sr=class{type="secp256k1";raw;publicKey;constructor(t,r){this.raw=ea(t),this.publicKey=new Ar(r??na(t))}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:it(this.raw,t.raw)}sign(t,r){return Ji(this.raw,t,r)}};function Oo(e){return new Sr(e)}function an(e){return new Ar(e)}async function oa(){let e=$f();return new Sr(e)}function ta(e){return Kt.ProjectivePoint.fromHex(e).toRawBytes(!0)}function ea(e){try{return Kt.getPublicKey(e,!0),e}catch(t){throw new $e(String(t))}}function ra(e){try{return Kt.ProjectivePoint.fromHex(e),e}catch(t){throw new Ee(String(t))}}function na(e){try{return Kt.getPublicKey(e,!0)}catch(t){throw new $e(String(t))}}function $f(){return Kt.utils.randomPrivateKey()}var cn={"P-256":32,"P-384":48,"P-521":66},Wf=Object.keys(cn),Mo=Wf.join(" / ");async function sa(e){if(e!=="P-256"&&e!=="P-384"&&e!=="P-521")throw new N(`Unknown curve: ${e}. Must be ${Mo}`);let t=await G.get().subtle.generateKey({name:"ECDH",namedCurve:e},!0,["deriveBits"]),r=async(s,i)=>{let c;i!=null?c=await G.get().subtle.importKey("jwk",Qf(e,i),{name:"ECDH",namedCurve:e},!1,["deriveBits"]):c=t.privateKey;let a=await G.get().subtle.importKey("jwk",ia(e,s),{name:"ECDH",namedCurve:e},!1,[]),u=await G.get().subtle.deriveBits({name:"ECDH",public:a},c,cn[e]*8);return new Uint8Array(u,0,u.byteLength)},n=await G.get().subtle.exportKey("jwk",t.publicKey);return{key:Jf(n),genSharedKey:r}}function Jf(e){if(e.crv==null||e.x==null||e.y==null)throw new N("JWK was missing components");if(e.crv!=="P-256"&&e.crv!=="P-384"&&e.crv!=="P-521")throw new N(`Unknown curve: ${e.crv}. Must be ${Mo}`);let t=cn[e.crv];return Ut([Uint8Array.from([4]),fo(e.x,t),fo(e.y,t)],1+t*2)}function ia(e,t){if(e!=="P-256"&&e!=="P-384"&&e!=="P-521")throw new N(`Unknown curve: ${e}. Must be ${Mo}`);let r=cn[e];if(!it(t.subarray(0,1),Uint8Array.from([4])))throw new N("Cannot unmarshal public key - invalid key format");return{kty:"EC",crv:e,x:q(t.subarray(1,r+1),"base64url"),y:q(t.subarray(1+r),"base64url"),ext:!0}}var Qf=(e,t)=>({...ia(e,t.public),d:q(t.private,"base64url")});var tu={"AES-128":{ivSize:16,keySize:16},"AES-256":{ivSize:16,keySize:32},Blowfish:{ivSize:8,keySize:32}};async function aa(e,t,r){if(e!=="AES-128"&&e!=="AES-256"&&e!=="Blowfish")throw new N("Cipher type was missing or unsupported");if(t!=="SHA1"&&t!=="SHA256"&&t!=="SHA512")throw new N("Hash type was missing or unsupported");if(r==null||!(r instanceof Uint8Array))throw new N("Secret was missing or an incorrect type");let n=tu[e],o=n.keySize,s=n.ivSize,i=20,c=Z("key expansion"),a=2*(s+o+i),u=await hn(t,r),d=await u.digest(c),l=[],f=0;for(;f<a;){let B=await u.digest(Ut([d,c])),g=B.length;f+g>a&&(g=a-f),l.push(B),f+=g,d=await u.digest(d)}let p=a/2,h=Ut(l),E=h.subarray(0,p),S=h.subarray(p,a),b=B=>({iv:B.subarray(0,s),cipherKey:B.subarray(s,s+o),macKey:B.subarray(s+o)});return{k1:b(E),k2:b(S)}}async function eu(e,t){if(e==="Ed25519")return wi();if(e==="secp256k1")return oa();if(e==="RSA")return Do(fu(t));if(e==="ECDSA")return Ls(uu(t));throw new Yt}async function ru(e,t){if(e!=="Ed25519")throw new Yt("Seed key derivation only supported for Ed25519 keys");return Ei(t)}function nu(e,t){let{Type:r,Data:n}=Ct.decode(e),o=n??new Uint8Array;switch(r){case j.RSA:return Co(o,t);case j.Ed25519:return Yr(o);case j.secp256k1:return an(o);case j.ECDSA:return Mn(o);default:throw new Yt}}function ou(e){if(e.byteLength===oe)return Yr(e);if(e.byteLength===$i)return an(e);let t=bt(e),r=t[1]?.[0];if(r===kn||r===Nn||r===Hn)return qn(t);if(t[0]?.[0]===Vi)return rn(t,e);throw new N("Could not extract public key from raw bytes")}function su(e){let{Type:t,Data:r}=Ct.decode(e.digest),n=r??new Uint8Array;switch(t){case j.Ed25519:return Yr(n);case j.secp256k1:return an(n);case j.ECDSA:return Mn(n);default:throw new Yt}}function ue(e){return Ct.encode({Type:j[e.type],Data:e.raw})}function iu(e){let t=xr.decode(e),r=t.Data??new Uint8Array;switch(t.Type){case j.RSA:return To(r);case j.Ed25519:return uo(r);case j.secp256k1:return Oo(r);case j.ECDSA:return vs(r);default:throw new Yt}}function au(e){if(e.byteLength===Et)return uo(e);if(e.byteLength===Wi)return Oo(e);let t=bt(e),r=t[2]?.[0];if(r===kn||r===Nn||r===Hn)return On(t);if(t.length>8)return en(t);throw new N("Could not extract private key from raw bytes")}function cu(e){return xr.encode({Type:j[e.type],Data:e.raw})}function fu(e){return e==null?2048:parseInt(e,10)}function uu(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 N("Unsupported curve, should be P-256, P-384 or P-521")}async function hu(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 N("Only RSA and ECDSA keys are supported")}async function lu(e){if(e.privateKey.algorithm.name==="RSASSA-PKCS1-v1_5"){let t=await crypto.subtle.exportKey("jwk",e.privateKey);return nn(t)}if(e.privateKey.algorithm.name==="ECDSA"){let t=await crypto.subtle.exportKey("jwk",e.privateKey);return new Pt(t)}throw new N("Only RSA and ECDSA keys are supported")}function du(e,t,r,n){Te(e);let o=Ds({dkLen:32,asyncTick:10},n),{c:s,dkLen:i,asyncTick:c}=o;if(Nt(s),Nt(i),Nt(c),s<1)throw new Error("iterations (c) should be >= 1");let a=Vn(t),u=Vn(r),d=new Uint8Array(i),l=Er.create(e,a),f=l._cloneInto().update(u);return{c:s,dkLen:i,asyncTick:c,DK:d,PRF:l,PRFSalt:f}}function pu(e,t,r,n,o){return e.destroy(),t.destroy(),n&&n.destroy(),mt(o),r}function ca(e,t,r,n){let{c:o,dkLen:s,DK:i,PRF:c,PRFSalt:a}=du(e,t,r,n),u,d=new Uint8Array(4),l=De(d),f=new Uint8Array(c.outputLen);for(let p=1,h=0;h<s;p++,h+=c.outputLen){let E=i.subarray(h,h+c.outputLen);l.setInt32(0,p,!1),(u=a._cloneInto(u)).update(d).digestInto(f),E.set(f.subarray(0,E.length));for(let S=1;S<o;S++){c._cloneInto(u).update(f).digestInto(f);for(let b=0;b<E.length;b++)E[b]^=f[b]}}return pu(c,a,i,u,f)}var Br=Uint32Array.from([1732584193,4023233417,2562383102,271733878,3285377520]),ae=new Uint32Array(80),fn=class extends de{constructor(){super(64,20,8,!1),this.A=Br[0]|0,this.B=Br[1]|0,this.C=Br[2]|0,this.D=Br[3]|0,this.E=Br[4]|0}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 a=0;a<16;a++,r+=4)ae[a]=t.getUint32(r,!1);for(let a=16;a<80;a++)ae[a]=Dr(ae[a-3]^ae[a-8]^ae[a-14]^ae[a-16],1);let{A:n,B:o,C:s,D:i,E:c}=this;for(let a=0;a<80;a++){let u,d;a<20?(u=Pr(o,s,i),d=1518500249):a<40?(u=o^s^i,d=1859775393):a<60?(u=kr(o,s,i),d=2400959708):(u=o^s^i,d=3395469782);let l=Dr(n,5)+u+c+d+ae[a]|0;c=i,i=s,s=Dr(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,c=c+this.E|0,this.set(n,o,s,i,c)}roundClean(){mt(ae)}destroy(){this.set(0,0,0,0,0),mt(this.buffer)}},fa=ir(()=>new fn);var ua=fa;var ha=qr;var la={sha1:ua,"sha2-256":je,"sha2-512":ha};function Vo(e,t,r,n,o){if(o!=="sha1"&&o!=="sha2-256"&&o!=="sha2-512"){let c=Object.keys(la).join(" / ");throw new N(`Hash '${o}' is unknown or not supported. Must be ${c}`)}let s=la[o],i=ca(s,e,t,{c:r,dkLen:n});return _n.encode(i).substring(1)}return ba(mu);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/hashes/esm/utils.js: