@libp2p/peer-store 12.0.20-29797a5bb → 12.0.20-5b8813abc
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 +1 -1
- package/dist/index.min.js.map +4 -4
- package/package.json +9 -9
package/dist/index.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PPeerStore = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PPeerStore=(()=>{var Lo=Object.defineProperty;var Cf=Object.getOwnPropertyDescriptor;var Bf=Object.getOwnPropertyNames;var Df=Object.prototype.hasOwnProperty;var H=(t,e)=>{for(var r in e)Lo(t,r,{get:e[r],enumerable:!0})},Rf=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Bf(e))!Df.call(t,o)&&o!==r&&Lo(t,o,{get:()=>e[o],enumerable:!(n=Cf(e,o))||n.enumerable});return t};var Lf=t=>Rf(Lo({},"__esModule",{value:!0}),t);var zm={};H(zm,{persistentPeerStore:()=>qm});var F=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Kt=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var mr=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var ln=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},dn=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var gt=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var hn=Symbol.for("@libp2p/peer-id");function Ut(t){return!!t?.[hn]}function Of(t){return typeof t?.handleEvent=="function"}function kf(t){return(t!==!0&&t!==!1&&t?.once)??!1}var Nt=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){let o=kf(n);super.addEventListener(e,i=>{if(o){let a=this.#e.get(i.type);a!=null&&(a=a.filter(({callback:c})=>c!==r),this.#e.set(i.type,a))}Of(r)?r.handleEvent(i):r(i)},n);let s=this.#e.get(e);s==null&&(s=[],this.#e.set(e,s)),s.push({callback:r,once:o})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==r),this.#e.set(e,o))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var Uo={};H(Uo,{base58btc:()=>Y,base58flickr:()=>qf});var Wm=new Uint8Array(0);function ha(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function $e(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function pa(t){return new TextEncoder().encode(t)}function ma(t){return new TextDecoder().decode(t)}function Pf(t,e){if(t.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<t.length;o++){var s=t.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function d(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var g=0,p=0,b=0,E=m.length;b!==E&&m[b]===0;)b++,g++;for(var S=(E-b)*f+1>>>0,C=new Uint8Array(S);b!==E;){for(var I=m[b],O=0,R=S-1;(I!==0||O<p)&&R!==-1;R--,O++)I+=256*C[R]>>>0,C[R]=I%a>>>0,I=I/a>>>0;if(I!==0)throw new Error("Non-zero carry");p=O,b++}for(var _=S-p;_!==S&&C[_]===0;)_++;for(var P=c.repeat(g);_<S;++_)P+=t.charAt(C[_]);return P}function l(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var g=0;if(m[g]!==" "){for(var p=0,b=0;m[g]===c;)p++,g++;for(var E=(m.length-g)*u+1>>>0,S=new Uint8Array(E);m[g];){var C=r[m.charCodeAt(g)];if(C===255)return;for(var I=0,O=E-1;(C!==0||I<b)&&O!==-1;O--,I++)C+=a*S[O]>>>0,S[O]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");b=I,g++}if(m[g]!==" "){for(var R=E-b;R!==E&&S[R]===0;)R++;for(var _=new Uint8Array(p+(E-R)),P=p;R!==E;)_[P++]=S[R++];return _}}}function h(m){var g=l(m);if(g)return g;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:l,decode:h}}var Kf=Pf,Uf=Kf,ba=Uf;var Oo=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},ko=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,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(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return ga(this,e)}},Po=class{decoders;constructor(e){this.decoders=e}or(e){return ga(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ga(t,e){return new Po({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Ko=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Oo(e,r,n),this.decoder=new ko(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Ft({name:t,prefix:e,encode:r,decode:n}){return new Ko(t,e,r,n)}function ot({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=ba(r,t);return Ft({prefix:e,name:t,encode:n,decode:s=>$e(o(s))})}function Nf(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Ff(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Mf(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function Z({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=Mf(n);return Ft({prefix:e,name:t,encode(s){return Ff(s,n,r)},decode(s){return Nf(s,o,r,t)}})}var Y=ot({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),qf=ot({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var No={};H(No,{base32:()=>Ue,base32hex:()=>$f,base32hexpad:()=>Wf,base32hexpadupper:()=>Zf,base32hexupper:()=>jf,base32pad:()=>Vf,base32padupper:()=>Hf,base32upper:()=>zf,base32z:()=>Yf});var Ue=Z({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),zf=Z({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Vf=Z({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Hf=Z({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),$f=Z({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),jf=Z({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Wf=Z({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Zf=Z({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Yf=Z({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Fo={};H(Fo,{base36:()=>yr,base36upper:()=>Gf});var yr=ot({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Gf=ot({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Xf=Ea,xa=128,Qf=127,Jf=~Qf,el=Math.pow(2,31);function Ea(t,e,r){e=e||[],r=r||0;for(var n=r;t>=el;)e[r++]=t&255|xa,t/=128;for(;t&Jf;)e[r++]=t&255|xa,t>>>=7;return e[r]=t|0,Ea.bytes=r-n+1,e}var tl=Mo,rl=128,wa=127;function Mo(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw Mo.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&wa)<<o:(i&wa)*Math.pow(2,o),o+=7}while(i>=rl);return Mo.bytes=s-n,r}var nl=Math.pow(2,7),ol=Math.pow(2,14),sl=Math.pow(2,21),il=Math.pow(2,28),al=Math.pow(2,35),cl=Math.pow(2,42),ul=Math.pow(2,49),fl=Math.pow(2,56),ll=Math.pow(2,63),dl=function(t){return t<nl?1:t<ol?2:t<sl?3:t<il?4:t<al?5:t<cl?6:t<ul?7:t<fl?8:t<ll?9:10},hl={encode:Xf,decode:tl,encodingLength:dl},pl=hl,br=pl;function gr(t,e=0){return[br.decode(t,e),br.decode.bytes]}function Mt(t,e,r=0){return br.encode(t,e,r),e}function qt(t){return br.encodingLength(t)}function Ne(t,e){let r=e.byteLength,n=qt(t),o=n+qt(r),s=new Uint8Array(o+r);return Mt(t,s,0),Mt(r,s,n),s.set(e,o),new zt(t,r,e,s)}function Vt(t){let e=$e(t),[r,n]=gr(e),[o,s]=gr(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new zt(r,o,i,e)}function va(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&ha(t.bytes,r.bytes)}}var zt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};function Sa(t,e){let{bytes:r,version:n}=t;return n===0?yl(r,qo(t),e??Y.encoder):bl(r,qo(t),e??Ue.encoder)}var Aa=new WeakMap;function qo(t){let e=Aa.get(t);if(e==null){let r=new Map;return Aa.set(t,r),r}return e}var te=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,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:e,multihash:r}=this;if(e!==xr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==gl)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.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:e,digest:r}=this.multihash,n=Ne(e,r);return t.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(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&va(e.multihash,n.multihash)}toString(e){return Sa(this,e)}toJSON(){return{"/":Sa(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new t(n,o,s,i??Ta(n,o,s.bytes))}else if(r[xl]===!0){let{version:n,multihash:o,code:s}=r,i=Vt(o);return t.create(n,s,i)}else return null}static create(e,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(e){case 0:{if(r!==xr)throw new Error(`Version 0 CID must use dag-pb (code: ${xr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=Ta(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,xr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=$e(e.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 zt(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[d,l]=gr(e.subarray(r));return r+=l,d},o=n(),s=xr;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,o]=ml(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return qo(s).set(n,e),s}};function ml(t,e){switch(t[0]){case"Q":{let r=e??Y;return[Y.prefix,r.decode(`${Y.prefix}${t}`)]}case Y.prefix:{let r=e??Y;return[Y.prefix,r.decode(t)]}case Ue.prefix:{let r=e??Ue;return[Ue.prefix,r.decode(t)]}case yr.prefix:{let r=e??yr;return[yr.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function yl(t,e,r){let{prefix:n}=r;if(n!==Y.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function bl(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var xr=112,gl=18;function Ta(t,e,r){let n=qt(t),o=n+qt(e),s=new Uint8Array(o+r.byteLength);return Mt(t,s,0),Mt(e,s,n),s.set(r,o),s}var xl=Symbol.for("@ipld/js-cid/CID");var zo={};H(zo,{identity:()=>Ce});var _a=0,wl="identity",Ia=$e;function El(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return Ne(_a,Ia(t))}var Ce={code:_a,name:wl,encode:Ia,digest:El};function re(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function vl(t){return t.buffer instanceof ArrayBuffer}function Fe(t){return vl(t)?t:t.slice()}async function Ca(t,e,r,n){let o=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,Fe(e),Fe(r.subarray()));return n?.signal?.throwIfAborted(),s}function je(t=0){return new Uint8Array(t)}function wr(t=0){return new Uint8Array(t)}function Vo(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=wr(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}function Ba(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}var Ra=Symbol.for("@achingbrain/uint8arraylist");function Da(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let o=r+n.byteLength;if(e<o)return{buf:n,index:e-r};r=o}throw new RangeError("index is out of bounds")}function mn(t){return!!t?.[Ra]}var pe=class t{bufs;length;[Ra]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(mn(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(mn(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(e){let r=Da(this.bufs,e);return r.buf[r.index]}set(e,r){let n=Da(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(mn(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:o}=this._subList(e,r);return Vo(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:Vo(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),s=new t;return s.length=o,s.bufs=n,s}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,e>=c)continue;let u=e>=a&&e<c,f=r>a&&r<=c;if(u&&f){if(e===a&&r===c){n.push(i);break}let d=e-a;n.push(i.subarray(d,d+(r-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!mn(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.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 d=0;d<s;d++)i[d]=-1;for(let d=0;d<o;d++)i[n[d]]=d;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let d=r;d<=c;d+=f){f=0;for(let l=u;l>=0;l--){let h=this.get(d+l);if(n[l]!==h){f=Math.max(1,l-a[h]);break}}if(f===0)return d}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=wr(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let o=je(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let o=je(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let o=je(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=wr(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let o=je(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let o=je(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let o=je(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let o=je(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let o=je(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!Ba(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var Zo={};H(Zo,{base10:()=>Dl});var _0=new Uint8Array(0);function La(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function We(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return xt(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return xt(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function Oa(t){return new TextEncoder().encode(t)}function ka(t){return new TextDecoder().decode(t)}function Sl(t){return t?.buffer instanceof ArrayBuffer}function xt(t){return Sl(t)?t:t.slice()}function Al(t,e){if(t.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<t.length;o++){var s=t.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function d(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var g=0,p=0,b=0,E=m.length;b!==E&&m[b]===0;)b++,g++;for(var S=(E-b)*f+1>>>0,C=new Uint8Array(S);b!==E;){for(var I=m[b],O=0,R=S-1;(I!==0||O<p)&&R!==-1;R--,O++)I+=256*C[R]>>>0,C[R]=I%a>>>0,I=I/a>>>0;if(I!==0)throw new Error("Non-zero carry");p=O,b++}for(var _=S-p;_!==S&&C[_]===0;)_++;for(var P=c.repeat(g);_<S;++_)P+=t.charAt(C[_]);return P}function l(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var g=0;if(m[g]!==" "){for(var p=0,b=0;m[g]===c;)p++,g++;for(var E=(m.length-g)*u+1>>>0,S=new Uint8Array(E);m[g];){var C=r[m.charCodeAt(g)];if(C===255)return;for(var I=0,O=E-1;(C!==0||I<b)&&O!==-1;O--,I++)C+=a*S[O]>>>0,S[O]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");b=I,g++}if(m[g]!==" "){for(var R=E-b;R!==E&&S[R]===0;)R++;for(var _=new Uint8Array(p+(E-R)),P=p;R!==E;)_[P++]=S[R++];return _}}}function h(m){var g=l(m);if(g)return g;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:l,decode:h}}var Tl=Al,_l=Tl,Ka=_l;var Ho=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},$o=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,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(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Ua(this,e)}},jo=class{decoders;constructor(e){this.decoders=e}or(e){return Ua(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ua(t,e){return new jo({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Wo=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Ho(e,r,n),this.decoder=new $o(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Ht({name:t,prefix:e,encode:r,decode:n}){return new Wo(t,e,r,n)}function it({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=Ka(r,t);return Ht({prefix:e,name:t,encode:n,decode:s=>We(o(s))})}function Il(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Cl(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Bl(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function G({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=Bl(n);return Ht({prefix:e,name:t,encode(s){return Cl(s,n,r)},decode(s){return Il(s,o,r,t)}})}var Dl=it({prefix:"9",name:"base10",alphabet:"0123456789"});var Yo={};H(Yo,{base16:()=>Rl,base16upper:()=>Ll});var Rl=G({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ll=G({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Go={};H(Go,{base2:()=>Ol});var Ol=G({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Xo={};H(Xo,{base256emoji:()=>Nl});var Na=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}"),kl=Na.reduce((t,e,r)=>(t[r]=e,t),[]),Pl=Na.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Kl(t){return t.reduce((e,r)=>(e+=kl[r],e),"")}function Ul(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Pl[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Nl=Ht({prefix:"\u{1F680}",name:"base256emoji",encode:Kl,decode:Ul});var Qo={};H(Qo,{base32:()=>$t,base32hex:()=>zl,base32hexpad:()=>Hl,base32hexpadupper:()=>$l,base32hexupper:()=>Vl,base32pad:()=>Ml,base32padupper:()=>ql,base32upper:()=>Fl,base32z:()=>jl});var $t=G({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Fl=G({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ml=G({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ql=G({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),zl=G({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Vl=G({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Hl=G({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),$l=G({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),jl=G({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Jo={};H(Jo,{base36:()=>Er,base36upper:()=>Wl});var Er=it({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Wl=it({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var es={};H(es,{base58btc:()=>Me,base58flickr:()=>Zl});var Me=it({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Zl=it({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ts={};H(ts,{base64:()=>Yl,base64pad:()=>Gl,base64url:()=>Xl,base64urlpad:()=>Ql});var Yl=G({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Gl=G({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Xl=G({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ql=G({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var rs={};H(rs,{base8:()=>Jl});var Jl=G({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ns={};H(ns,{identity:()=>ed});var ed=Ht({prefix:"\0",name:"identity",encode:t=>ka(t),decode:t=>Oa(t)});var z0=new TextEncoder,V0=new TextDecoder;var ss={};H(ss,{identity:()=>Sd});var nd=qa,Fa=128,od=127,sd=~od,id=Math.pow(2,31);function qa(t,e,r){e=e||[],r=r||0;for(var n=r;t>=id;)e[r++]=t&255|Fa,t/=128;for(;t&sd;)e[r++]=t&255|Fa,t>>>=7;return e[r]=t|0,qa.bytes=r-n+1,e}var ad=os,cd=128,Ma=127;function os(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw os.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&Ma)<<o:(i&Ma)*Math.pow(2,o),o+=7}while(i>=cd);return os.bytes=s-n,r}var ud=Math.pow(2,7),fd=Math.pow(2,14),ld=Math.pow(2,21),dd=Math.pow(2,28),hd=Math.pow(2,35),pd=Math.pow(2,42),md=Math.pow(2,49),yd=Math.pow(2,56),bd=Math.pow(2,63),gd=function(t){return t<ud?1:t<fd?2:t<ld?3:t<dd?4:t<hd?5:t<pd?6:t<md?7:t<yd?8:t<bd?9:10},xd={encode:nd,decode:ad,encodingLength:gd},wd=xd,vr=wd;function Sr(t,e=0){return[vr.decode(t,e),vr.decode.bytes]}function jt(t,e,r=0){return vr.encode(t,e,r),e}function Wt(t){return vr.encodingLength(t)}function Yt(t,e){let r=e.byteLength,n=Wt(t),o=n+Wt(r),s=new Uint8Array(o+r);return jt(t,s,0),jt(r,s,n),s.set(e,o),new Zt(t,r,e,s)}function za(t){let e=We(t),[r,n]=Sr(e),[o,s]=Sr(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Zt(r,o,i,e)}function Va(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&La(t.bytes,r.bytes)}}var Zt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=xt(n),this.bytes=xt(o)}};var Ha=0,Ed="identity",$a=We;function vd(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return Yt(Ha,$a(t))}var Sd={code:Ha,name:Ed,encode:$a,digest:vd};var cs={};H(cs,{sha256:()=>Td,sha512:()=>_d});var Ad=20;function as({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new is(t,e,r,n,o)}var is=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Ad,this.maxDigestLength=s}digest(e,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(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?ja(n,this.code,r?.truncate):n.then(o=>ja(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function ja(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return Yt(e,t)}function Za(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Td=as({name:"sha2-256",code:18,encode:Za("SHA-256")}),_d=as({name:"sha2-512",code:19,encode:Za("SHA-512")});function Ya(t,e){let{bytes:r,version:n}=t;return n===0?Cd(r,us(t),e??Me.encoder):Bd(r,us(t),e??$t.encoder)}var Ga=new WeakMap;function us(t){let e=Ga.get(t);if(e==null){let r=new Map;return Ga.set(t,r),r}return e}var bn=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=xt(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==Tr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Dd)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.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:e,digest:r}=this.multihash,n=Yt(e,r);return t.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(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&Va(e.multihash,n.multihash)}toString(e){return Ya(this,e)}toJSON(){return{"/":Ya(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new t(n,o,s,i??Xa(n,o,s.bytes))}else if(r[Rd]===!0){let{version:n,multihash:o,code:s}=r,i=za(o);return t.create(n,s,i)}else return null}static create(e,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(e){case 0:{if(r!==Tr)throw new Error(`Version 0 CID must use dag-pb (code: ${Tr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=Xa(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Tr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=We(e.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 Zt(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[d,l]=Sr(e.subarray(r));return r+=l,d},o=n(),s=Tr;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,o]=Id(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return us(s).set(n,e),s}};function Id(t,e){switch(t[0]){case"Q":{let r=e??Me;return[Me.prefix,r.decode(`${Me.prefix}${t}`)]}case Me.prefix:{let r=e??Me;return[Me.prefix,r.decode(t)]}case $t.prefix:{let r=e??$t;return[$t.prefix,r.decode(t)]}case Er.prefix:{let r=e??Er;return[Er.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function Cd(t,e,r){let{prefix:n}=r;if(n!==Me.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function Bd(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var Tr=112,Dd=18;function Xa(t,e,r){let n=Wt(t),o=n+Wt(e),s=new Uint8Array(o+r.byteLength);return jt(t,s,0),jt(e,s,n),s.set(r,o),s}var Rd=Symbol.for("@ipld/js-cid/CID");var fs={...ns,...Go,...rs,...Zo,...Yo,...Qo,...Jo,...es,...ts,...Xo},ly={...cs,...ss};function Be(t=0){return new Uint8Array(t)}function ls(t=0){return new Uint8Array(t)}function Ja(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Qa=Ja("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),ds=Ja("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=ls(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Ld={utf8:Qa,"utf-8":Qa,hex:fs.base16,latin1:ds,ascii:ds,binary:ds,...fs},gn=Ld;function J(t,e="utf8"){let r=gn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function $(t,e="utf8"){let r=gn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var Od=parseInt("11111",2),hs=parseInt("10000000",2),kd=parseInt("01111111",2),ec={0:_r,1:_r,2:Pd,3:Nd,4:Fd,5:Ud,6:Kd,16:_r,22:_r,48:_r};function Ze(t,e={offset:0}){let r=t[e.offset]&Od;if(e.offset++,ec[r]!=null)return ec[r](t,e);throw new Error("No decoder for tag "+r)}function Ir(t,e){let r=0;if((t[e.offset]&hs)===hs){let n=t[e.offset]&kd,o="0x";e.offset++;for(let s=0;s<n;s++,e.offset++)o+=t[e.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=t[e.offset],e.offset++;return r}function _r(t,e){Ir(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=Ze(t,e);if(n===null)break;r.push(n)}return r}function Pd(t,e){let r=Ir(t,e),n=e.offset,o=e.offset+r,s=[];for(let i=n;i<o;i++)i===n&&t[i]===0||s.push(t[i]);return e.offset+=r,Uint8Array.from(s)}function Kd(t,e){let r=Ir(t,e),n=e.offset+r,o=t[e.offset];e.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;e.offset<n;){let u=t[e.offset];if(e.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let d=0;d<c.length;d++)f+=c[d]<<d*7;a+=`.${f}`,c=[]}}return a}function Ud(t,e){return e.offset++,null}function Nd(t,e){let r=Ir(t,e),n=t[e.offset];e.offset++;let o=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Fd(t,e){let r=Ir(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function Md(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new pe;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function ps(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=Md(t.byteLength);return new pe(Uint8Array.from([e.byteLength|hs]),e)}function we(t){let e=new pe,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new pe(Uint8Array.from([2]),ps(e),e)}function xn(t){let e=Uint8Array.from([0]),r=new pe(e,t);return new pe(Uint8Array.from([3]),ps(r),r)}function at(t,e=48){let r=new pe;for(let n of t)r.append(n);return new pe(Uint8Array.from([e]),ps(r),r)}var qd=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),zd=Uint8Array.from([6,5,43,129,4,0,34]),Vd=Uint8Array.from([6,5,43,129,4,0,35]),Hd={ext:!0,kty:"EC",crv:"P-256"},$d={ext:!0,kty:"EC",crv:"P-384"},jd={ext:!0,kty:"EC",crv:"P-521"},ms=32,ys=48,bs=66;function gs(t){let e=Ze(t);return tc(e)}function tc(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===ms*2+1)return n=$(e.subarray(r,r+ms),"base64url"),o=$(e.subarray(r+ms),"base64url"),new Gt({...Hd,key_ops:["verify"],x:n,y:o});if(e.byteLength===ys*2+1)return n=$(e.subarray(r,r+ys),"base64url"),o=$(e.subarray(r+ys),"base64url"),new Gt({...$d,key_ops:["verify"],x:n,y:o});if(e.byteLength===bs*2+1)return n=$(e.subarray(r,r+bs),"base64url"),o=$(e.subarray(r+bs),"base64url"),new Gt({...jd,key_ops:["verify"],x:n,y:o});throw new F(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function rc(t){return at([we(Uint8Array.from([1])),at([Wd(t.crv)],160),at([xn(new pe(Uint8Array.from([4]),J(t.x??"","base64url"),J(t.y??"","base64url")))],161)]).subarray()}function Wd(t){if(t==="P-256")return qd;if(t==="P-384")return zd;if(t==="P-521")return Vd;throw new F(`Invalid curve ${t}`)}var Gt=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=rc(this.jwk)),this._raw}toMultihash(){return Ce.digest(Ae(this))}toCID(){return te.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:re(this.raw,e.raw)}async verify(e,r,n){return Ca(this.jwk,r,e,n)}};function xs(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function ct(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(`${r}expected number, got ${typeof t}`)}if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new RangeError(`${r}expected integer >= 0, got ${t}`)}}function Ee(t,e,r=""){let n=xs(t),o=t?.length,s=e!==void 0;if(!n||s&&o!==e){let i=r&&`"${r}" `,a=s?` of length ${e}`:"",c=n?`length=${o}`:`type=${typeof t}`,u=i+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(u):new TypeError(u)}return t}function wn(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(ct(t.outputLen),ct(t.blockLen),t.outputLen<1)throw new Error('"outputLen" must be >= 1');if(t.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Xt(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function En(t,e){Ee(t,void 0,"digestInto() output");let r=e.outputLen;if(t.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function Ge(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function vn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function De(t,e){return t<<32-e|t>>>e}var oc=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Zd=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Sn(t){if(Ee(t),oc)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=Zd[t[r]];return e}var Ye={_0:48,_9:57,A:65,F:70,a:97,f:102};function nc(t){if(t>=Ye._0&&t<=Ye._9)return t-Ye._0;if(t>=Ye.A&&t<=Ye.F)return t-(Ye.A-10);if(t>=Ye.a&&t<=Ye.f)return t-(Ye.a-10)}function Cr(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(oc)try{return Uint8Array.fromHex(t)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=nc(t.charCodeAt(s)),a=nc(t.charCodeAt(s+1));if(i===void 0||a===void 0){let c=t[s]+t[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function ws(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];Ee(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let s=t[n];r.set(s,o),o+=s.length}return r}function Es(t,e={}){let r=(o,s)=>t(s).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function sc(t=32){ct(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var vs=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function ic(t,e,r){return t&e^~t&r}function ac(t,e,r){return t&e^t&r^e&r}var Br=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,o){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=vn(this.buffer)}update(e){Xt(this),Ee(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=vn(e);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Xt(this),En(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Ge(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let d=i;d<o;d++)r[d]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=vn(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<u;d++)a.setUint32(4*d,f[d],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=s,e.length=o,e.pos=a,o%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},Xe=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ue=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var An=BigInt(4294967295),cc=BigInt(32);function Yd(t,e=!1){return e?{h:Number(t&An),l:Number(t>>cc&An)}:{h:Number(t>>cc&An)|0,l:Number(t&An)|0}}function uc(t,e=!1){let r=t.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=Yd(t[s],e);[n[s],o[s]]=[i,a]}return[n,o]}var Ss=(t,e,r)=>t>>>r,As=(t,e,r)=>t<<32-r|e>>>r,wt=(t,e,r)=>t>>>r|e<<32-r,Et=(t,e,r)=>t<<32-r|e>>>r,Dr=(t,e,r)=>t<<64-r|e>>>r-32,Rr=(t,e,r)=>t>>>r-32|e<<64-r;function qe(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var fc=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),lc=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,dc=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),hc=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,pc=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),mc=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;var Xd=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]),ut=new Uint32Array(64),Ts=class extends Br{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[e,r,n,o,s,i,a,c]}set(e,r,n,o,s,i,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(e,r){for(let d=0;d<16;d++,r+=4)ut[d]=e.getUint32(r,!1);for(let d=16;d<64;d++){let l=ut[d-15],h=ut[d-2],m=De(l,7)^De(l,18)^l>>>3,g=De(h,17)^De(h,19)^h>>>10;ut[d]=g+ut[d-7]+m+ut[d-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let d=0;d<64;d++){let l=De(a,6)^De(a,11)^De(a,25),h=f+l+ic(a,c,u)+Xd[d]+ut[d]|0,g=(De(n,2)^De(n,13)^De(n,22))+ac(n,o,s)|0;f=u,u=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+g|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,u,f)}roundClean(){Ge(ut)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Ge(this.buffer)}},_s=class extends Ts{A=Xe[0]|0;B=Xe[1]|0;C=Xe[2]|0;D=Xe[3]|0;E=Xe[4]|0;F=Xe[5]|0;G=Xe[6]|0;H=Xe[7]|0;constructor(){super(32)}};var yc=uc(["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(t=>BigInt(t))),Qd=yc[0],Jd=yc[1],ft=new Uint32Array(80),lt=new Uint32Array(80),Is=class extends Br{constructor(e){super(128,e,16,!1)}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:d,Fl:l,Gh:h,Gl:m,Hh:g,Hl:p}=this;return[e,r,n,o,s,i,a,c,u,f,d,l,h,m,g,p]}set(e,r,n,o,s,i,a,c,u,f,d,l,h,m,g,p){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=d|0,this.Fl=l|0,this.Gh=h|0,this.Gl=m|0,this.Hh=g|0,this.Hl=p|0}process(e,r){for(let S=0;S<16;S++,r+=4)ft[S]=e.getUint32(r),lt[S]=e.getUint32(r+=4);for(let S=16;S<80;S++){let C=ft[S-15]|0,I=lt[S-15]|0,O=wt(C,I,1)^wt(C,I,8)^Ss(C,I,7),R=Et(C,I,1)^Et(C,I,8)^As(C,I,7),_=ft[S-2]|0,P=lt[S-2]|0,V=wt(_,P,19)^Dr(_,P,61)^Ss(_,P,6),K=Et(_,P,19)^Rr(_,P,61)^As(_,P,6),y=dc(R,K,lt[S-7],lt[S-16]),x=hc(y,O,V,ft[S-7],ft[S-16]);ft[S]=x|0,lt[S]=y|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:d,El:l,Fh:h,Fl:m,Gh:g,Gl:p,Hh:b,Hl:E}=this;for(let S=0;S<80;S++){let C=wt(d,l,14)^wt(d,l,18)^Dr(d,l,41),I=Et(d,l,14)^Et(d,l,18)^Rr(d,l,41),O=d&h^~d&g,R=l&m^~l&p,_=pc(E,I,R,Jd[S],lt[S]),P=mc(_,b,C,O,Qd[S],ft[S]),V=_|0,K=wt(n,o,28)^Dr(n,o,34)^Dr(n,o,39),y=Et(n,o,28)^Rr(n,o,34)^Rr(n,o,39),x=n&s^n&a^s&a,A=o&i^o&c^i&c;b=g|0,E=p|0,g=h|0,p=m|0,h=d|0,m=l|0,{h:d,l}=qe(u|0,f|0,P|0,V|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let v=fc(V,y,A);n=lc(v,P,K,x),o=v|0}({h:n,l:o}=qe(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=qe(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=qe(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=qe(this.Dh|0,this.Dl|0,u|0,f|0),{h:d,l}=qe(this.Eh|0,this.El|0,d|0,l|0),{h,l:m}=qe(this.Fh|0,this.Fl|0,h|0,m|0),{h:g,l:p}=qe(this.Gh|0,this.Gl|0,g|0,p|0),{h:b,l:E}=qe(this.Hh|0,this.Hl|0,b|0,E|0),this.set(n,o,s,i,a,c,u,f,d,l,h,m,g,p,b,E)}roundClean(){Ge(ft,lt)}destroy(){this.destroyed=!0,Ge(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Cs=class extends Is{Ah=ue[0]|0;Al=ue[1]|0;Bh=ue[2]|0;Bl=ue[3]|0;Ch=ue[4]|0;Cl=ue[5]|0;Dh=ue[6]|0;Dl=ue[7]|0;Eh=ue[8]|0;El=ue[9]|0;Fh=ue[10]|0;Fl=ue[11]|0;Gh=ue[12]|0;Gl=ue[13]|0;Hh=ue[14]|0;Hl=ue[15]|0;constructor(){super(64)}};var Qt=Es(()=>new _s,vs(1));var Tn=Es(()=>new Cs,vs(3));var M=(t,e,r)=>Ee(t,e,r),Ds=ct,Jt=Sn,oe=(...t)=>ws(...t),er=t=>Cr(t),vt=xs,Lr=t=>sc(t),In=BigInt(0),Bs=BigInt(1);function Re(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new TypeError(r+"expected boolean, got type="+typeof t)}return t}function Cn(t){if(typeof t=="bigint"){if(!_n(t))throw new RangeError("positive bigint expected, got "+t)}else Ds(t);return t}function Le(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function Or(t){let e=Cn(t).toString(16);return e.length&1?"0"+e:e}function bc(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?In:BigInt("0x"+t)}function St(t){return bc(Sn(t))}function ze(t){return bc(Sn(kr(Ee(t)).reverse()))}function Bn(t,e){if(ct(e),e===0)throw new RangeError("zero length");t=Cn(t);let r=t.toString(16);if(r.length>e*2)throw new RangeError("number too large");return Cr(r.padStart(e*2,"0"))}function Rs(t,e){return Bn(t,e).reverse()}function gc(t,e){if(t=M(t),e=M(e),t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function kr(t){return Uint8Array.from(M(t))}function Dn(t){if(typeof t!="string")throw new TypeError("ascii string expected, got "+typeof t);return Uint8Array.from(t,(e,r)=>{let n=e.charCodeAt(0);if(e.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${t[r]}" with code ${n} at position ${r}`);return n})}var _n=t=>typeof t=="bigint"&&In<=t;function eh(t,e,r){return _n(t)&&_n(e)&&_n(r)&&e<=t&&t<r}function tr(t,e,r,n){if(!eh(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function rr(t){if(t<In)throw new Error("expected non-negative bigint, got "+t);let e;for(e=0;t>In;t>>=Bs,e+=1);return e}var Pr=t=>(Bs<<BigInt(t))-Bs;function xc(t,e,r){if(ct(t,"hashLen"),ct(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=p=>new Uint8Array(p),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(t),u=n(t),f=0,d=()=>{c.fill(1),u.fill(0),f=0},l=(...p)=>r(u,oe(c,...p)),h=(p=o)=>{u=l(s,p),c=l(),p.length!==0&&(u=l(i,p),c=l())},m=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let p=0,b=[];for(;p<e;){c=l();let E=c.slice();b.push(E),p+=c.length}return oe(...b)};return(p,b)=>{d(),h(p);let E;for(;(E=b(m()))===void 0;)h();return d(),E}}function Oe(t,e={},r={}){if(Object.prototype.toString.call(t)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,i,a){if(!a&&i!=="function"&&!Object.hasOwn(t,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let c=t[s];if(a&&c===void 0)return;let u=typeof c;if(u!==i||c===null)throw new TypeError(`param "${s}" is invalid: expected ${i}, got ${u}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(e,!1),o(r,!0)}var Ls=()=>{throw new Error("not implemented")};var fe=BigInt(0),X=BigInt(1),At=BigInt(2),Sc=BigInt(3),Ac=BigInt(4),Tc=BigInt(5),th=BigInt(7),_c=BigInt(8),rh=BigInt(9),Ic=BigInt(16);function ee(t,e){if(e<=fe)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=fe?r:e+r}function j(t,e,r){if(e<fe)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >fe;)n*=n,n%=r;return n}function wc(t,e){if(t===fe)throw new Error("invert: expected non-zero number");if(e<=fe)throw new Error("invert: expected positive modulus, got "+e);let r=ee(t,e),n=e,o=fe,s=X,i=X,a=fe;for(;r!==fe;){let u=n/r,f=n-r*u,d=o-i*u,l=s-a*u;n=r,r=f,o=i,s=a,i=d,a=l}if(n!==X)throw new Error("invert: does not exist");return ee(o,e)}function Os(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function Cc(t,e){let r=t,n=(r.ORDER+X)/Ac,o=r.pow(e,n);return Os(r,o,e),o}function nh(t,e){let r=t,n=(r.ORDER-Tc)/_c,o=r.mul(e,At),s=r.pow(o,n),i=r.mul(e,s),a=r.mul(r.mul(i,At),s),c=r.mul(i,r.sub(a,r.ONE));return Os(r,c,e),c}function oh(t){let e=nr(t),r=Bc(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+th)/Ic;return((a,c)=>{let u=a,f=u.pow(c,i),d=u.mul(f,n),l=u.mul(f,o),h=u.mul(f,s),m=u.eql(u.sqr(d),c),g=u.eql(u.sqr(l),c);f=u.cmov(f,d,m),d=u.cmov(h,l,g);let p=u.eql(u.sqr(d),c),b=u.cmov(f,d,p);return Os(u,b,c),b})}function Bc(t){if(t<Sc)throw new Error("sqrt is not defined for small field");let e=t-X,r=0;for(;e%At===fe;)e/=At,r++;let n=At,o=nr(t);for(;Ec(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Cc;let s=o.pow(n,e),i=(e+X)/At;return function(c,u){let f=c;if(f.is0(u))return u;if(Ec(f,u)!==1)throw new Error("Cannot find square root");let d=r,l=f.mul(f.ONE,s),h=f.pow(u,e),m=f.pow(u,i);for(;!f.eql(h,f.ONE);){if(f.is0(h))return f.ZERO;let g=1,p=f.sqr(h);for(;!f.eql(p,f.ONE);)if(g++,p=f.sqr(p),g===d)throw new Error("Cannot find square root");let b=X<<BigInt(d-g-1),E=f.pow(l,b);d=g,l=f.sqr(E),h=f.mul(h,l),m=f.mul(m,E)}return m}}function sh(t){return t%Ac===Sc?Cc:t%_c===Tc?nh:t%Ic===rh?oh(t):Bc(t)}var Qe=(t,e)=>(ee(t,e)&X)===X,ih=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ks(t){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=ih.reduce((n,o)=>(n[o]="function",n),e);if(Oe(t,r),Le(t.BYTES,"BYTES"),Le(t.BITS,"BITS"),t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=X)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function ah(t,e,r){let n=t;if(r<fe)throw new Error("invalid exponent, negatives unsupported");if(r===fe)return n.ONE;if(r===X)return e;let o=n.ONE,s=e;for(;r>fe;)r&X&&(o=n.mul(o,s)),s=n.sqr(s),r>>=X;return o}function Kr(t,e,r=!1){let n=t,o=new Array(e.length).fill(r?n.ZERO:void 0),s=e.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return e.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),i),o}function Ec(t,e){let r=t,n=(r.ORDER-X)/At,o=r.pow(e,n),s=r.eql(o,r.ONE),i=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function ch(t,e){if(e!==void 0&&Ds(e),t<=fe)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=rr(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${e})`);let n=e!==void 0?e:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var vc=new WeakMap,Rn=class{ORDER;BITS;BYTES;isLE;ZERO=fe;ONE=X;_lengths;_mod;constructor(e,r={}){if(e<=X)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=ch(e,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(e){return ee(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return fe<=e&&e<this.ORDER}is0(e){return e===fe}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&X)===X}neg(e){return ee(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return ee(e*e,this.ORDER)}add(e,r){return ee(e+r,this.ORDER)}sub(e,r){return ee(e-r,this.ORDER)}mul(e,r){return ee(e*r,this.ORDER)}pow(e,r){return ah(this,e,r)}div(e,r){return ee(e*wc(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return wc(e,this.ORDER)}sqrt(e){let r=vc.get(this);return r||vc.set(this,r=sh(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?Rs(e,this.BYTES):Bn(e,this.BYTES)}fromBytes(e,r=!1){M(e);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(o);u.set(e,s?0:u.length-e.length),e=u}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=s?ze(e):St(e);if(a&&(c=ee(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return Kr(this,e)}cmov(e,r,n){return Re(n,"condition"),n?r:e}};Object.freeze(Rn.prototype);function nr(t,e={}){return new Rn(t,e)}function Dc(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=X)throw new Error("field order must be greater than 1");let e=rr(t-X);return Math.ceil(e/8)}function Ps(t){let e=Dc(t);return e+Math.ceil(e/2)}function Ks(t,e,r=!1){M(t);let n=t.length,o=Dc(e),s=Math.max(Ps(e),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?ze(t):St(t),a=ee(i,e-X)+X;return r?Rs(a,o):Bn(a,o)}var or=BigInt(0),Tt=BigInt(1);function Ur(t,e){let r=e.negate();return t?r:e}function _t(t,e){let r=Kr(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function kc(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Us(t,e){kc(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),o=2**t,s=Pr(t),i=BigInt(t);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Rc(t,e,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(t&o),c=t>>i;a>n&&(a-=s,c+=Tt);let u=e*n,f=u+Math.abs(a)-1,d=a===0,l=a<0,h=e%2!==0;return{nextN:c,offset:f,isZero:d,isNeg:l,isNegF:h,offsetF:u}}var Ns=new WeakMap,Pc=new WeakMap;function Fs(t){return Pc.get(t)||1}function Lc(t){if(t!==or)throw new Error("invalid wNAF")}var sr=class{BASE;ZERO;Fn;bits;constructor(e,r){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let o=e;for(;r>or;)r&Tt&&(n=n.add(o)),o=o.double(),r>>=Tt;return n}precomputeWindow(e,r){let{windows:n,windowSize:o}=Us(r,this.bits),s=[],i=e,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let u=1;u<o;u++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Us(e,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:d,isNegF:l,offsetF:h}=Rc(n,a,i);n=c,f?s=s.add(Ur(l,r[h])):o=o.add(Ur(d,r[u]))}return Lc(n),{p:o,f:s}}wNAFUnsafe(e,r,n,o=this.ZERO){let s=Us(e,this.bits);for(let i=0;i<s.windows&&n!==or;i++){let{nextN:a,offset:c,isZero:u,isNeg:f}=Rc(n,i,s);if(n=a,!u){let d=r[c];o=o.add(f?d.negate():d)}}return Lc(n),o}getPrecomputes(e,r,n){let o=Ns.get(r);return o||(o=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(o=n(o)),Ns.set(r,o))),o}cached(e,r,n){let o=Fs(e);return this.wNAF(o,this.getPrecomputes(o,e,n),r)}unsafe(e,r,n,o){let s=Fs(e);return s===1?this._unsafeLadder(e,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,e,n),r,o)}createCache(e,r){kc(r,this.bits),Pc.set(e,r),Ns.delete(e)}hasCache(e){return Fs(e)!==1}};function Kc(t,e,r,n){let o=e,s=t.ZERO,i=t.ZERO;for(;r>or||n>or;)r&Tt&&(s=s.add(o)),n&Tt&&(i=i.add(o)),o=o.double(),r>>=Tt,n>>=Tt;return{p1:s,p2:i}}function Oc(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ks(e),e}else return nr(t,{isLE:r})}function Ln(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let c of["p","n","h"]){let u=e[c];if(!(typeof u=="bigint"&&u>or))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Oc(e.p,r.Fp,n),s=Oc(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:s}}function On(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var dt=BigInt(0),ae=BigInt(1),Ms=BigInt(2),uh=BigInt(8);function fh(t,e,r,n){let o=t.sqr(r),s=t.sqr(n),i=t.add(t.mul(e.a,o),s),a=t.add(t.ONE,t.mul(e.d,t.mul(o,s)));return t.eql(i,a)}function Uc(t,e={}){let r=e,n=Ln("edwards",t,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;Oe(r,{},{uvRatio:"function"});let c=Ms<<BigInt(s.BYTES*8)-ae,u=g=>o.create(g),f=r.uvRatio===void 0?(g,p)=>{try{return{isValid:!0,value:o.sqrt(o.div(g,p))}}catch{return{isValid:!1,value:dt}}}:r.uvRatio;if(!fh(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function d(g,p,b=!1){let E=b?ae:dt;return tr("coordinate "+g,p,E,c),p}function l(g){if(!(g instanceof h))throw new Error("EdwardsPoint expected")}class h{static BASE=new h(i.Gx,i.Gy,ae,u(i.Gx*i.Gy));static ZERO=new h(dt,ae,ae,dt);static Fp=o;static Fn=s;X;Y;Z;T;constructor(p,b,E,S){this.X=d("x",p),this.Y=d("y",b),this.Z=d("z",E,!0),this.T=d("t",S),Object.freeze(this)}static CURVE(){return i}static fromAffine(p){if(p instanceof h)throw new Error("extended point not allowed");let{x:b,y:E}=p||{};return d("x",b),d("y",E),new h(b,E,ae,u(b*E))}static fromBytes(p,b=!1){let E=o.BYTES,{a:S,d:C}=i;p=kr(M(p,E,"point")),Re(b,"zip215");let I=kr(p),O=p[E-1];I[E-1]=O&-129;let R=ze(I),_=b?c:o.ORDER;tr("point.y",R,dt,_);let P=u(R*R),V=u(P-ae),K=u(C*P-S),{isValid:y,value:x}=f(V,K);if(!y)throw new Error("bad point: invalid y coordinate");let A=(x&ae)===ae,v=(O&128)!==0;if(!b&&x===dt&&v)throw new Error("bad point: x=0 and x_0=1");return v!==A&&(x=u(-x)),h.fromAffine({x,y:R})}static fromHex(p,b=!1){return h.fromBytes(er(p),b)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=8,b=!0){return m.createCache(this,p),b||this.multiply(Ms),this}assertValidity(){let p=this,{a:b,d:E}=i;if(p.is0())throw new Error("bad point: ZERO");let{X:S,Y:C,Z:I,T:O}=p,R=u(S*S),_=u(C*C),P=u(I*I),V=u(P*P),K=u(R*b),y=u(P*u(K+_)),x=u(V+u(E*u(R*_)));if(y!==x)throw new Error("bad point: equation left != right (1)");let A=u(S*C),v=u(I*O);if(A!==v)throw new Error("bad point: equation left != right (2)")}equals(p){l(p);let{X:b,Y:E,Z:S}=this,{X:C,Y:I,Z:O}=p,R=u(b*O),_=u(C*S),P=u(E*O),V=u(I*S);return R===_&&P===V}is0(){return this.equals(h.ZERO)}negate(){return new h(u(-this.X),this.Y,this.Z,u(-this.T))}double(){let{a:p}=i,{X:b,Y:E,Z:S}=this,C=u(b*b),I=u(E*E),O=u(Ms*u(S*S)),R=u(p*C),_=b+E,P=u(u(_*_)-C-I),V=R+I,K=V-O,y=R-I,x=u(P*K),A=u(V*y),v=u(P*y),w=u(K*V);return new h(x,A,w,v)}add(p){l(p);let{a:b,d:E}=i,{X:S,Y:C,Z:I,T:O}=this,{X:R,Y:_,Z:P,T:V}=p,K=u(S*R),y=u(C*_),x=u(O*E*V),A=u(I*P),v=u((S+C)*(R+_)-K-y),w=A-x,T=A+x,D=u(y-b*K),B=u(v*w),L=u(T*D),k=u(v*D),N=u(w*T);return new h(B,L,N,k)}subtract(p){return l(p),this.add(p.negate())}multiply(p){if(!s.isValidNot0(p))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:b,f:E}=m.cached(this,p,S=>_t(h,S));return _t(h,[b,E])[0]}multiplyUnsafe(p){if(!s.isValid(p))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return p===dt?h.ZERO:this.is0()||p===ae?this:m.unsafe(this,p,b=>_t(h,b))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return m.unsafe(this,i.n).is0()}toAffine(p){let b=this,E=p,{X:S,Y:C,Z:I}=b,O=b.is0();E==null&&(E=O?uh:o.inv(I));let R=u(S*E),_=u(C*E),P=o.mul(I,E);if(O)return{x:dt,y:ae};if(P!==ae)throw new Error("invZ was invalid");return{x:R,y:_}}clearCofactor(){return a===ae?this:this.multiplyUnsafe(a)}toBytes(){let{x:p,y:b}=this.toAffine(),E=o.toBytes(b);return E[E.length-1]|=p&ae?128:0,E}toHex(){return Jt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let m=new sr(h,s.BITS);return s.BITS>=8&&h.BASE.precompute(8),Object.freeze(h.prototype),Object.freeze(h),h}var kn=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(e){this.ep=e}static fromBytes(e){Ls()}static fromHex(e){Ls()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(e){return this.ep.toAffine(e)}toHex(){return Jt(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(e){return this.assertSame(e),this.init(this.ep.add(e.ep))}subtract(e){return this.assertSame(e),this.init(this.ep.subtract(e.ep))}multiply(e){return this.init(this.ep.multiply(e))}multiplyUnsafe(e){return this.init(this.ep.multiplyUnsafe(e))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(e,r){return this.ep.precompute(e,r),this}};function Nc(t,e,r={}){if(typeof e!="function")throw new Error('"hash" function param is required');let n=e,o=r;Oe(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=t,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(Le(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let d=o.randomBytes===void 0?Lr:o.randomBytes,l=o.adjustScalarBytes===void 0?y=>y:o.adjustScalarBytes,h=o.domain===void 0?(y,x,A)=>{if(Re(A,"phflag"),x.length||A)throw new Error("Contexts/pre-hash are not supported");return y}:o.domain;function m(y){return c.create(ze(y))}function g(y){let x=R.secretKey;M(y,R.secretKey,"secretKey");let A=M(n(y),2*x,"hashedSecretKey"),v=l(A.slice(0,x)),w=A.slice(x,2*x),T=m(v);return{head:v,prefix:w,scalar:T}}function p(y){let{head:x,prefix:A,scalar:v}=g(y),w=i.multiply(v),T=w.toBytes();return{head:x,prefix:A,scalar:v,point:w,pointBytes:T}}function b(y){return p(y).pointBytes}function E(y=Uint8Array.of(),...x){let A=oe(...x);return m(n(h(A,M(y,void 0,"context"),!!s)))}function S(y,x,A={}){y=M(y,void 0,"message"),s&&(y=s(y));let{prefix:v,scalar:w,pointBytes:T}=p(x),D=E(A.context,v,y),B=i.multiply(D).toBytes(),L=E(A.context,B,T,y),k=c.create(D+L*w);if(!c.isValid(k))throw new Error("sign failed: invalid s");let N=oe(B,c.toBytes(k));return M(N,R.signature,"result")}let C={zip215:o.zip215};function I(y,x,A,v=C){let{context:w}=v,T=v.zip215===void 0?!!C.zip215:v.zip215,D=R.signature;y=M(y,D,"signature"),x=M(x,void 0,"message"),A=M(A,R.publicKey,"publicKey"),T!==void 0&&Re(T,"zip215"),s&&(x=s(x));let B=D/2,L=y.subarray(0,B),k=ze(y.subarray(B,D)),N,q,U;try{N=t.fromBytes(A,T),q=t.fromBytes(L,T),U=i.multiplyUnsafe(k)}catch{return!1}if(!T&&N.isSmallOrder())return!1;let ne=E(w,L,A,x);return q.add(N.multiplyUnsafe(ne)).subtract(U).clearCofactor().is0()}let O=a.BYTES,R={secretKey:O,publicKey:O,signature:2*O,seed:O};function _(y){return y=y===void 0?d(R.seed):y,M(y,R.seed,"seed")}function P(y){return vt(y)&&y.length===R.secretKey}function V(y,x){try{return!!t.fromBytes(y,x===void 0?C.zip215:x)}catch{return!1}}let K={getExtendedPublicKey:p,randomSecretKey:_,isValidSecretKey:P,isValidPublicKey:V,toMontgomery(y){let{y:x}=t.fromBytes(y),A=R.publicKey,v=A===32;if(!v&&A!==57)throw new Error("only defined for 25519 and 448");let w=v?a.div(ae+x,ae-x):a.div(x-ae,x+ae);return a.toBytes(w)},toMontgomerySecret(y){let x=R.secretKey;M(y,x);let A=n(y.subarray(0,x));return l(A).subarray(0,x)}};return Object.freeze(R),Object.freeze(K),Object.freeze({keygen:On(_,b),getPublicKey:b,sign:S,verify:I,utils:K,Point:t,lengths:R})}function Nr(t,e){if(Le(t),Le(e),e<0||e>4)throw new Error("invalid I2OSP length: "+e);if(t<0||t>2**(8*e)-1)throw new Error("invalid I2OSP input: "+t);let r=Array.from({length:e}).fill(0);for(let n=e-1;n>=0;n--)r[n]=t&255,t>>>=8;return new Uint8Array(r)}function lh(t,e){let r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t[n]^e[n];return r}function dh(t){if(!vt(t)&&typeof t!="string")throw new Error("DST must be Uint8Array or ascii string");let e=typeof t=="string"?Dn(t):t;if(e.length===0)throw new Error("DST must be non-empty");return e}function qs(t,e,r,n){M(t),Le(r),e=dh(e),e.length>255&&(e=n(oe(Dn("H2C-OVERSIZE-DST-"),e)));let{outputLen:o,blockLen:s}=n,i=Math.ceil(r/o);if(r>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=oe(e,Nr(e.length,1)),c=new Uint8Array(s),u=Nr(r,2),f=new Array(i),d=n(oe(c,t,u,Nr(0,1),a));f[0]=n(oe(d,Nr(1,1),a));for(let h=1;h<i;h++){let m=[lh(d,f[h-1]),Nr(h+1,1),a];f[h]=n(oe(...m))}return oe(...f).slice(0,r)}var Fc="HashToScalar-";var hh=BigInt(0),Je=BigInt(1),Mc=BigInt(2);var ph=BigInt(5),mh=BigInt(8),ir=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),$s={p:ir,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:mh,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function yh(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=ir,a=t*t%s*t%s,c=j(a,Mc,s)*a%s,u=j(c,Je,s)*t%s,f=j(u,ph,s)*u%s,d=j(f,e,s)*f%s,l=j(d,r,s)*d%s,h=j(l,n,s)*l%s,m=j(h,o,s)*h%s,g=j(m,o,s)*h%s,p=j(g,e,s)*f%s;return{pow_p_5_8:j(p,Mc,s)*t%s,b2:a}}function bh(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var zs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function js(t,e){let r=ir,n=ee(e*e*e,r),o=ee(n*n*e,r),s=yh(t*o).pow_p_5_8,i=ee(t*n*s,r),a=ee(e*i*i,r),c=i,u=ee(i*zs,r),f=a===t,d=a===ee(-t,r),l=a===ee(-t*zs,r);return f&&(i=c),(d||l)&&(i=u),Qe(i,r)&&(i=ee(-i,r)),{isValid:f||d,value:i}}var pt=Uc($s,{uvRatio:js}),ht=pt.Fp,Vc=pt.Fn;function gh(t){return Nc(pt,Tn,Object.assign({adjustScalarBytes:bh,zip215:!0},t))}var Hc=gh({});var Vs=zs,xh=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),wh=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Eh=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),vh=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),qc=t=>js(Je,t),Sh=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Hs=t=>ht.create(ze(t)&Sh);function zc(t){let{d:e}=$s,r=ir,n=b=>ht.create(b),o=n(Vs*t*t),s=n((o+Je)*Eh),i=BigInt(-1),a=n((i-e*o)*n(o+e)),{isValid:c,value:u}=js(s,a),f=n(u*t);Qe(f,r)||(f=n(-f)),c||(u=f),c||(i=o);let d=n(i*(o-Je)*vh-a),l=u*u,h=n((u+u)*a),m=n(d*xh),g=n(Je-l),p=n(Je+l);return new pt(n(h*p),n(g*m),n(m*p),n(h*g))}var mt=class t extends kn{static BASE=new t(pt.BASE);static ZERO=new t(pt.ZERO);static Fp=ht;static Fn=Vc;constructor(e){super(e)}static fromAffine(e){return new t(pt.fromAffine(e))}assertSame(e){if(!(e instanceof t))throw new Error("RistrettoPoint expected")}init(e){return new t(e)}static fromBytes(e){Ee(e,32);let{a:r,d:n}=$s,o=ir,s=C=>ht.create(C),i=Hs(e);if(!gc(ht.toBytes(i),e)||Qe(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(Je+r*a),u=s(Je-r*a),f=s(c*c),d=s(u*u),l=s(r*n*f-d),{isValid:h,value:m}=qc(s(l*d)),g=s(m*u),p=s(m*g*l),b=s((i+i)*g);Qe(b,o)&&(b=s(-b));let E=s(c*p),S=s(b*E);if(!h||Qe(S,o)||E===hh)throw new Error("invalid ristretto255 encoding 2");return new t(new pt(b,E,Je,S))}static fromHex(e){return t.fromBytes(Cr(e))}toBytes(){let{X:e,Y:r,Z:n,T:o}=this.ep,s=ir,i=p=>ht.create(p),a=i(i(n+r)*i(n-r)),c=i(e*r),u=i(c*c),{value:f}=qc(i(a*u)),d=i(f*a),l=i(f*c),h=i(d*l*o),m;if(Qe(o*h,s)){let p=i(r*Vs),b=i(e*Vs);e=p,r=b,m=i(d*wh)}else m=l;Qe(e*h,s)&&(r=i(-r));let g=i((n-r)*m);return Qe(g,s)&&(g=i(-g)),ht.toBytes(g)}equals(e){this.assertSame(e);let{X:r,Y:n}=this.ep,{X:o,Y:s}=e.ep,i=u=>ht.create(u),a=i(r*s)===i(n*o),c=i(n*s)===i(r*o);return a||c}is0(){return this.equals(t.ZERO)}};Object.freeze(mt.BASE);Object.freeze(mt.ZERO);Object.freeze(mt.prototype);Object.freeze(mt);var Ah=Object.freeze({Point:mt,hashToCurve(t,e){let r=e?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":e.DST,n=qs(t,r,64,Tn);return Ah.deriveToCurve(n)},hashToScalar(t,e={DST:Fc}){let r=qs(t,e.DST,64,Tn);return Vc.create(ze(r))},deriveToCurve(t){Ee(t,64);let e=Hs(t.subarray(0,32)),r=zc(e),n=Hs(t.subarray(32,64)),o=zc(n);return new mt(r.add(o))}});var Fr=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},Pn=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var Te={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new Pn("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 e}};var Kn=32;var Ws,Th=(async()=>{try{return await Te.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function _h(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await Te.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await Te.get().subtle.verify({name:"Ed25519"},n,Fe(e),Fe(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Ih(t,e,r){return Hc.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function $c(t,e,r){return Ws==null&&(Ws=await Th),Ws?_h(t,e,r):Ih(t,e,r)}function Un(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Nn=class{type="Ed25519";raw;constructor(e){this.raw=Zs(e,Kn)}toMultihash(){return Ce.digest(Ae(this))}toCID(){return te.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:re(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let o=$c(this.raw,r,e);return Un(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Ys(t){return t=Zs(t,Kn),new Nn(t)}function Zs(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new F(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}function Wc(t=0){return new Uint8Array(t)}var Bh=Math.pow(2,7),Dh=Math.pow(2,14),Rh=Math.pow(2,21),Gs=Math.pow(2,28),Xs=Math.pow(2,35),Qs=Math.pow(2,42),Js=Math.pow(2,49),z=128,de=127;function _e(t){if(t<Bh)return 1;if(t<Dh)return 2;if(t<Rh)return 3;if(t<Gs)return 4;if(t<Xs)return 5;if(t<Qs)return 6;if(t<Js)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ar(t,e,r=0){switch(_e(t)){case 8:e[r++]=t&255|z,t/=128;case 7:e[r++]=t&255|z,t/=128;case 6:e[r++]=t&255|z,t/=128;case 5:e[r++]=t&255|z,t/=128;case 4:e[r++]=t&255|z,t>>>=7;case 3:e[r++]=t&255|z,t>>>=7;case 2:e[r++]=t&255|z,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Lh(t,e,r=0){switch(_e(t)){case 8:e.set(r++,t&255|z),t/=128;case 7:e.set(r++,t&255|z),t/=128;case 6:e.set(r++,t&255|z),t/=128;case 5:e.set(r++,t&255|z),t/=128;case 4:e.set(r++,t&255|z),t>>>=7;case 3:e.set(r++,t&255|z),t>>>=7;case 2:e.set(r++,t&255|z),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function ei(t,e){let r=t[e],n=0;if(n+=r&de,r<z||(r=t[e+1],n+=(r&de)<<7,r<z)||(r=t[e+2],n+=(r&de)<<14,r<z)||(r=t[e+3],n+=(r&de)<<21,r<z)||(r=t[e+4],n+=(r&de)*Gs,r<z)||(r=t[e+5],n+=(r&de)*Xs,r<z)||(r=t[e+6],n+=(r&de)*Qs,r<z)||(r=t[e+7],n+=(r&de)*Js,r<z))return n;throw new RangeError("Could not decode varint")}function Oh(t,e){let r=t.get(e),n=0;if(n+=r&de,r<z||(r=t.get(e+1),n+=(r&de)<<7,r<z)||(r=t.get(e+2),n+=(r&de)<<14,r<z)||(r=t.get(e+3),n+=(r&de)<<21,r<z)||(r=t.get(e+4),n+=(r&de)*Gs,r<z)||(r=t.get(e+5),n+=(r&de)*Xs,r<z)||(r=t.get(e+6),n+=(r&de)*Qs,r<z)||(r=t.get(e+7),n+=(r&de)*Js,r<z))return n;throw new RangeError("Could not decode varint")}function Fn(t,e,r=0){return e==null&&(e=Wc(_e(t))),e instanceof Uint8Array?ar(t,e,r):Lh(t,e,r)}function ti(t,e=0){return t instanceof Uint8Array?ei(t,e):Oh(t,e)}var ri=new Float32Array([-0]),yt=new Uint8Array(ri.buffer);function Yc(t,e,r){ri[0]=t,e[r]=yt[0],e[r+1]=yt[1],e[r+2]=yt[2],e[r+3]=yt[3]}function Gc(t,e){return yt[0]=t[e],yt[1]=t[e+1],yt[2]=t[e+2],yt[3]=t[e+3],ri[0]}var ni=new Float64Array([-0]),he=new Uint8Array(ni.buffer);function Xc(t,e,r){ni[0]=t,e[r]=he[0],e[r+1]=he[1],e[r+2]=he[2],e[r+3]=he[3],e[r+4]=he[4],e[r+5]=he[5],e[r+6]=he[6],e[r+7]=he[7]}function Qc(t,e){return he[0]=t[e],he[1]=t[e+1],he[2]=t[e+2],he[3]=t[e+3],he[4]=t[e+4],he[5]=t[e+5],he[6]=t[e+6],he[7]=t[e+7],ni[0]}var kh=BigInt(Number.MAX_SAFE_INTEGER),Ph=BigInt(Number.MIN_SAFE_INTEGER),ve=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&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(e=!1){if(e)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(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return It;if(e<kh&&e>Ph)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,o=e-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Jc&&(o=0n,++n>Jc&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return It;let r=e<0;r&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new t(n,o)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):It}},It=new ve(0,0);It.toBigInt=function(){return 0n};It.zzEncode=It.zzDecode=function(){return this};It.length=function(){return 1};var Jc=4294967296n;function eu(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function tu(t,e,r){if(r-e<1)return"";let o,s=[],i=0,a;for(;e<r;)a=t[e++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&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 oi(t,e,r){let n=r,o,s;for(let i=0;i<t.length;++i)o=t.charCodeAt(i),o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&((s=t.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128);return r-n}function ke(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function Mn(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var si=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,ke(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw ke(this,4);return Mn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw ke(this,4);return Mn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw ke(this,4);let e=Gc(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw ke(this,4);let e=Qc(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw ke(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return tu(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw ke(this,e);this.pos+=e}else do if(this.pos>=this.len)throw ke(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new ve(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw ke(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw ke(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw ke(this,8);let e=Mn(this.buf,this.pos+=4),r=Mn(this.buf,this.pos+=4);return new ve(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=ei(this.buf,this.pos);return this.pos+=_e(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Mr(t){return new si(t instanceof Uint8Array?t:t.subarray())}function me(t,e,r){let n=Mr(t);return e.decode(n,void 0,r)}function Ct(t=0){return new Uint8Array(t)}var ii={};H(ii,{base10:()=>Kh});var Kh=ot({prefix:"9",name:"base10",alphabet:"0123456789"});var ai={};H(ai,{base16:()=>Uh,base16upper:()=>Nh});var Uh=Z({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Nh=Z({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ci={};H(ci,{base2:()=>Fh});var Fh=Z({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ui={};H(ui,{base256emoji:()=>Hh});var nu=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}"),Mh=nu.reduce((t,e,r)=>(t[r]=e,t),[]),qh=nu.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function zh(t){return t.reduce((e,r)=>(e+=Mh[r],e),"")}function Vh(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=qh[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Hh=Ft({prefix:"\u{1F680}",name:"base256emoji",encode:zh,decode:Vh});var li={};H(li,{base64:()=>$h,base64pad:()=>jh,base64url:()=>fi,base64urlpad:()=>Wh});var $h=Z({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),jh=Z({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),fi=Z({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Wh=Z({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var di={};H(di,{base8:()=>Zh});var Zh=Z({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var hi={};H(hi,{identity:()=>Yh});var Yh=Ft({prefix:"\0",name:"identity",encode:t=>ma(t),decode:t=>pa(t)});var hg=new TextEncoder,pg=new TextDecoder;var yi={};H(yi,{sha256:()=>qr,sha512:()=>Jh});var Qh=20;function mi({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new pi(t,e,r,n,o)}var pi=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Qh,this.maxDigestLength=s}digest(e,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(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?ou(n,this.code,r?.truncate):n.then(o=>ou(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function ou(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return Ne(e,t)}function iu(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var qr=mi({name:"sha2-256",code:18,encode:iu("SHA-256")}),Jh=mi({name:"sha2-512",code:19,encode:iu("SHA-512")});var Pe={...hi,...ci,...di,...ii,...ai,...No,...Fo,...Uo,...li,...ui},_g={...yi,...zo};function cu(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var au=cu("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),bi=cu("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Ct(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),ep={utf8:au,"utf-8":au,hex:Pe.base16,latin1:bi,ascii:bi,binary:bi,...Pe},uu=ep;function fu(t,e="utf8"){let r=uu[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function gi(t){let e=t??8192,r=e>>>1,n,o=e;return function(i){if(i<1||i>r)return Ct(i);o+i>e&&(n=Ct(e),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Bt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function xi(){}var Ei=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},tp=gi();function rp(t){return globalThis.Buffer!=null?Ct(t):tp(t)}var Vr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Bt(xi,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Bt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new vi((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(qn,10,ve.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=ve.fromBigInt(e);return this._push(qn,r.length(),r)}uint64Number(e){return this._push(ar,_e(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=ve.fromBigInt(e).zzEncode();return this._push(qn,r.length(),r)}sint64Number(e){let r=ve.fromNumber(e).zzEncode();return this._push(qn,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(wi,1,e?1:0)}fixed32(e){return this._push(zr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=ve.fromBigInt(e);return this._push(zr,4,r.lo)._push(zr,4,r.hi)}fixed64Number(e){let r=ve.fromNumber(e);return this._push(zr,4,r.lo)._push(zr,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(Yc,4,e)}double(e){return this._push(Xc,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(wi,1,0):this.uint32(r)._push(op,r,e)}string(e){let r=eu(e);return r!==0?this.uint32(r)._push(oi,r,e):this._push(wi,1,0)}fork(){return this.states=new Ei(this),this.head=this.tail=new Bt(xi,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 Bt(xi,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=rp(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function wi(t,e,r){e[r]=t&255}function np(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var vi=class extends Bt{next;constructor(e,r){super(np,e,r),this.next=void 0}};function qn(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function zr(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function op(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(Vr.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(sp,e,t),this},Vr.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(ip,e,t),this});function sp(t,e,r){e.set(t,r)}function ip(t,e,r){t.length<40?oi(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(fu(t),r)}function Si(){return new Vr}function ye(t,e){let r=Si();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*be(t,e,r){let n=Mr(t);yield*e.stream(n,void 0,"$",r)}var zn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Vn(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function Ai(t){function e(s){if(t[s.toString()]==null)throw new Error("Invalid enum value");return t[s]}let r=function(i,a){let c=e(i);a.int32(c)},n=function(i){let a=i.int32();return e(a)},o=function*(i){let a=i.int32();yield e(a)};return Vn("enum",zn.VARINT,r,n,o)}function ge(t,e,r){return Vn("message",zn.LENGTH_DELIMITED,t,e,r)}var Ie=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},Hr=class extends Error{code="ERR_MAX_SIZE";name="MaxSizeError"};var W;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(W||(W={}));var Ti;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(Ti||(Ti={}));(function(t){t.codec=()=>Ai(Ti)})(W||(W={}));var Ve;(function(t){let e;t.codec=()=>(e==null&&(e=ge((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),W.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=W.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:W.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ye(s,t.codec())}t.encode=r;function n(s,i){return me(s,t.codec(),i)}t.decode=n;function o(s,i){return be(s,t.codec(),i)}t.stream=o})(Ve||(Ve={}));var _i;(function(t){let e;t.codec=()=>(e==null&&(e=ge((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),W.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=W.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:W.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ye(s,t.codec())}t.encode=r;function n(s,i){return me(s,t.codec(),i)}t.decode=n;function o(s,i){return be(s,t.codec(),i)}t.stream=o})(_i||(_i={}));var jr={};H(jr,{MAX_RSA_KEY_SIZE:()=>Ii,generateRSAKeyPair:()=>mu,jwkToJWKKeyPair:()=>yu,jwkToPkcs1:()=>fp,jwkToPkix:()=>Ri,jwkToRSAPrivateKey:()=>Pi,pkcs1MessageToJwk:()=>Bi,pkcs1MessageToRSAPrivateKey:()=>Li,pkcs1ToJwk:()=>up,pkcs1ToRSAPrivateKey:()=>pu,pkixMessageToJwk:()=>Di,pkixMessageToRSAPublicKey:()=>ki,pkixToJwk:()=>lp,pkixToRSAPublicKey:()=>Oi});var cr=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=jr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return te.createV1(114,this._multihash)}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:re(this.raw,e.raw)}verify(e,r,n){return hu(this.jwk,r,e,n)}},$r=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=jr.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:re(this.raw,e.raw)}sign(e,r){return du(this.jwk,e,r)}};var Ii=8192,Ci=18,ap=1062,cp=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function up(t){let e=Ze(t);return Bi(e)}function Bi(t){return{n:$(t[1],"base64url"),e:$(t[2],"base64url"),d:$(t[3],"base64url"),p:$(t[4],"base64url"),q:$(t[5],"base64url"),dp:$(t[6],"base64url"),dq:$(t[7],"base64url"),qi:$(t[8],"base64url"),kty:"RSA"}}function fp(t){if(t.n==null||t.e==null||t.d==null||t.p==null||t.q==null||t.dp==null||t.dq==null||t.qi==null)throw new F("JWK was missing components");return at([we(Uint8Array.from([0])),we(J(t.n,"base64url")),we(J(t.e,"base64url")),we(J(t.d,"base64url")),we(J(t.p,"base64url")),we(J(t.q,"base64url")),we(J(t.dp,"base64url")),we(J(t.dq,"base64url")),we(J(t.qi,"base64url"))]).subarray()}function lp(t){let e=Ze(t,{offset:0});return Di(e)}function Di(t){let e=Ze(t[1],{offset:0});return{kty:"RSA",n:$(e[0],"base64url"),e:$(e[1],"base64url")}}function Ri(t){if(t.n==null||t.e==null)throw new F("JWK was missing components");return at([cp,xn(at([we(J(t.n,"base64url")),we(J(t.e,"base64url"))]))]).subarray()}function pu(t){let e=Ze(t);return Li(e)}function Li(t){let e=Bi(t);return Pi(e)}function Oi(t,e){if(t.byteLength>=ap)throw new Kt("Key size is too large");let r=Ze(t,{offset:0});return ki(r,t,e)}function ki(t,e,r){let n=Di(t);if(r==null){let o=Qt(Ve.encode({Type:W.RSA,Data:e}));r=Ne(Ci,o)}return new cr(n,r)}function Pi(t){if(gu(t)>Ii)throw new F("Key size is too large");let e=yu(t),r=Qt(Ve.encode({Type:W.RSA,Data:Ri(e.publicKey)})),n=Ne(Ci,r);return new $r(e.privateKey,new cr(e.publicKey,n))}async function mu(t){if(t>Ii)throw new F("Key size is too large");let e=await bu(t),r=Qt(Ve.encode({Type:W.RSA,Data:Ri(e.publicKey)})),n=Ne(Ci,r);return new $r(e.privateKey,new cr(e.publicKey,n))}function yu(t){if(t==null)throw new F("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function bu(t,e){let r=await Te.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:t,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await dp(r,e);return{privateKey:n[0],publicKey:n[1]}}async function du(t,e,r){let n=await Te.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Te.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,Fe(e instanceof Uint8Array?e:e.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function hu(t,e,r,n){let o=await Te.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Te.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,Fe(e),Fe(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),s}async function dp(t,e){if(t.privateKey==null||t.publicKey==null)throw new F("Private and public key are required");let r=await Promise.all([Te.get().subtle.exportKey("jwk",t.privateKey),Te.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function gu(t){if(t.kty!=="RSA")throw new F("invalid key type");if(t.n==null)throw new F("invalid key modulus");return J(t.n,"base64url").length*8}var Hn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(wn(e),Ee(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Ge(o)}update(e){return Xt(this),this.iHash.update(e),this}digestInto(e){Xt(this),En(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},xu=(()=>{let t=((e,r,n)=>new Hn(e,r).update(n).digest());return t.create=(e,r)=>new Hn(e,r),t})();var wu=(t,e)=>(t+(t>=0?e:-e)/Eu)/e;function hp(t,e,r){tr("scalar",t,He,r);let[[n,o],[s,i]]=e,a=wu(i*t,r),c=wu(-o*t,r),u=t-a*n-c*s,f=-a*o-c*i,d=u<He,l=f<He;d&&(u=-u),l&&(f=-f);let h=Pr(Math.ceil(rr(r)/2))+bt;if(u<He||u>=h||f<He||f>=h)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:d,k1:u,k2neg:l,k2:f}}function Ui(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Ki(t,e){Oe(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Re(r.lowS,"lowS"),Re(r.prehash,"prehash"),r.format!==void 0&&Ui(r.format),r}var Ni=class extends Error{constructor(e=""){super(e)}},Ke={Err:Ni,_tlv:{encode:(t,e)=>{let{Err:r}=Ke;if(Le(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(typeof e!="string")throw new TypeError('"data" expected string, got type='+typeof e);if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=Or(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Or(o.length/2|128):"";return Or(t)+s+o+e},decode(t,e){let{Err:r}=Ke;e=M(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=Ke;if(Cn(t),t<He)throw new e("integer: negative integers are not allowed");let r=Or(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=Ke;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return St(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=Ke,o=M(t,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:u,l:f}=n.decode(2,c);if(f.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(t){let{_tlv:e,_int:r}=Ke,n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),s=n+o;return e.encode(48,s)}};Object.freeze(Ke._tlv);Object.freeze(Ke._int);Object.freeze(Ke);var He=BigInt(0),bt=BigInt(1),Eu=BigInt(2),$n=BigInt(3),pp=BigInt(4);function vu(t,e={}){let r=Ln("weierstrass",t,e),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;Oe(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c,allowInfinityPoint:u}=e;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=Au(n,o);function d(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(K,y,x){if(u&&y.is0())return Uint8Array.of(0);let{x:A,y:v}=y.toAffine(),w=n.toBytes(A);if(Re(x,"isCompressed"),x){d();let T=!n.isOdd(v);return oe(Su(T),w)}else return oe(Uint8Array.of(4),w,n.toBytes(v))}function h(K){M(K,void 0,"Point");let{publicKey:y,publicKeyUncompressed:x}=f,A=K.length,v=K[0],w=K.subarray(1);if(u&&A===1&&v===0)return{x:n.ZERO,y:n.ZERO};if(A===y&&(v===2||v===3)){let T=n.fromBytes(w);if(!n.isValid(T))throw new Error("bad point: is not on curve, wrong x");let D=p(T),B;try{B=n.sqrt(D)}catch(N){let q=N instanceof Error?": "+N.message:"";throw new Error("bad point: is not on curve, sqrt error"+q)}d();let L=n.isOdd(B);return(v&1)===1!==L&&(B=n.neg(B)),{x:T,y:B}}else if(A===x&&v===4){let T=n.BYTES,D=n.fromBytes(w.subarray(0,T)),B=n.fromBytes(w.subarray(T,T*2));if(!b(D,B))throw new Error("bad point: is not on curve");return{x:D,y:B}}else throw new Error(`bad point: got length ${A}, expected compressed=${y} or uncompressed=${x}`)}let m=e.toBytes===void 0?l:e.toBytes,g=e.fromBytes===void 0?h:e.fromBytes;function p(K){let y=n.sqr(K),x=n.mul(y,K);return n.add(n.add(x,n.mul(K,s.a)),s.b)}function b(K,y){let x=n.sqr(y),A=p(K);return n.eql(x,A)}if(!b(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let E=n.mul(n.pow(s.a,$n),pp),S=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(E,S)))throw new Error("bad curve params: a or b");function C(K,y,x=!1){if(!n.isValid(y)||x&&n.is0(y))throw new Error(`bad point coordinate ${K}`);return y}function I(K){if(!(K instanceof _))throw new Error("Weierstrass Point expected")}function O(K){if(!c||!c.basises)throw new Error("no endo");return hp(K,c.basises,o.ORDER)}function R(K,y,x,A,v){return x=new _(n.mul(x.X,K),x.Y,x.Z),y=Ur(A,y),x=Ur(v,x),y.add(x)}class _{static BASE=new _(s.Gx,s.Gy,n.ONE);static ZERO=new _(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(y,x,A){this.X=C("x",y),this.Y=C("y",x,!0),this.Z=C("z",A),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){let{x,y:A}=y||{};if(!y||!n.isValid(x)||!n.isValid(A))throw new Error("invalid affine point");if(y instanceof _)throw new Error("projective point not allowed");return n.is0(x)&&n.is0(A)?_.ZERO:new _(x,A,n.ONE)}static fromBytes(y){let x=_.fromAffine(g(M(y,void 0,"point")));return x.assertValidity(),x}static fromHex(y){return _.fromBytes(er(y))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,x=!0){return V.createCache(this,y),x||this.multiply($n),this}assertValidity(){let y=this;if(y.is0()){if(e.allowInfinityPoint&&n.is0(y.X)&&n.eql(y.Y,n.ONE)&&n.is0(y.Z))return;throw new Error("bad point: ZERO")}let{x,y:A}=y.toAffine();if(!n.isValid(x)||!n.isValid(A))throw new Error("bad point: x or y not field elements");if(!b(x,A))throw new Error("bad point: equation left != right");if(!y.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(y)}equals(y){I(y);let{X:x,Y:A,Z:v}=this,{X:w,Y:T,Z:D}=y,B=n.eql(n.mul(x,D),n.mul(w,v)),L=n.eql(n.mul(A,D),n.mul(T,v));return B&&L}negate(){return new _(this.X,n.neg(this.Y),this.Z)}double(){let{a:y,b:x}=s,A=n.mul(x,$n),{X:v,Y:w,Z:T}=this,D=n.ZERO,B=n.ZERO,L=n.ZERO,k=n.mul(v,v),N=n.mul(w,w),q=n.mul(T,T),U=n.mul(v,w);return U=n.add(U,U),L=n.mul(v,T),L=n.add(L,L),D=n.mul(y,L),B=n.mul(A,q),B=n.add(D,B),D=n.sub(N,B),B=n.add(N,B),B=n.mul(D,B),D=n.mul(U,D),L=n.mul(A,L),q=n.mul(y,q),U=n.sub(k,q),U=n.mul(y,U),U=n.add(U,L),L=n.add(k,k),k=n.add(L,k),k=n.add(k,q),k=n.mul(k,U),B=n.add(B,k),q=n.mul(w,T),q=n.add(q,q),k=n.mul(q,U),D=n.sub(D,k),L=n.mul(q,N),L=n.add(L,L),L=n.add(L,L),new _(D,B,L)}add(y){I(y);let{X:x,Y:A,Z:v}=this,{X:w,Y:T,Z:D}=y,B=n.ZERO,L=n.ZERO,k=n.ZERO,N=s.a,q=n.mul(s.b,$n),U=n.mul(x,w),ne=n.mul(A,T),se=n.mul(v,D),ie=n.add(x,A),Q=n.add(w,T);ie=n.mul(ie,Q),Q=n.add(U,ne),ie=n.sub(ie,Q),Q=n.add(x,v);let xe=n.add(w,D);return Q=n.mul(Q,xe),xe=n.add(U,se),Q=n.sub(Q,xe),xe=n.add(A,v),B=n.add(T,D),xe=n.mul(xe,B),B=n.add(ne,se),xe=n.sub(xe,B),k=n.mul(N,Q),B=n.mul(q,se),k=n.add(B,k),B=n.sub(ne,k),k=n.add(ne,k),L=n.mul(B,k),ne=n.add(U,U),ne=n.add(ne,U),se=n.mul(N,se),Q=n.mul(q,Q),ne=n.add(ne,se),se=n.sub(U,se),se=n.mul(N,se),Q=n.add(Q,se),U=n.mul(ne,Q),L=n.add(L,U),U=n.mul(xe,Q),B=n.mul(ie,B),B=n.sub(B,U),U=n.mul(ie,ne),k=n.mul(xe,k),k=n.add(k,U),new _(B,L,k)}subtract(y){return I(y),this.add(y.negate())}is0(){return this.equals(_.ZERO)}multiply(y){let{endo:x}=e;if(!o.isValidNot0(y))throw new RangeError("invalid scalar: out of range");let A,v,w=T=>V.cached(this,T,D=>_t(_,D));if(x){let{k1neg:T,k1:D,k2neg:B,k2:L}=O(y),{p:k,f:N}=w(D),{p:q,f:U}=w(L);v=N.add(U),A=R(x.beta,k,q,T,B)}else{let{p:T,f:D}=w(y);A=T,v=D}return _t(_,[A,v])[0]}multiplyUnsafe(y){let{endo:x}=e,A=this,v=y;if(!o.isValid(v))throw new RangeError("invalid scalar: out of range");if(v===He||A.is0())return _.ZERO;if(v===bt)return A;if(V.hasCache(this))return this.multiply(v);if(x){let{k1neg:w,k1:T,k2neg:D,k2:B}=O(v),{p1:L,p2:k}=Kc(_,A,T,B);return R(x.beta,L,k,w,D)}else return V.unsafe(A,v)}toAffine(y){let x=this,A=y,{X:v,Y:w,Z:T}=x;if(n.eql(T,n.ONE))return{x:v,y:w};let D=x.is0();A==null&&(A=D?n.ONE:n.inv(T));let B=n.mul(v,A),L=n.mul(w,A),k=n.mul(T,A);if(D)return{x:n.ZERO,y:n.ZERO};if(!n.eql(k,n.ONE))throw new Error("invZ was invalid");return{x:B,y:L}}isTorsionFree(){let{isTorsionFree:y}=e;return i===bt?!0:y?y(_,this):V.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:y}=e;return i===bt?this:y?y(_,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===bt?this.is0():this.clearCofactor().is0()}toBytes(y=!0){return Re(y,"isCompressed"),this.assertValidity(),m(_,this,y)}toHex(y=!0){return Jt(this.toBytes(y))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let P=o.BITS,V=new sr(_,e.endo?Math.ceil(P/2):P);return P>=8&&_.BASE.precompute(8),Object.freeze(_.prototype),Object.freeze(_),_}function Su(t){return Uint8Array.of(t?2:3)}function Au(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function mp(t,e={}){let{Fn:r}=t,n=e.randomBytes===void 0?Lr:e.randomBytes,o=Object.assign(Au(t.Fp,r),{seed:Math.max(Ps(r.ORDER),16)});function s(h){try{let m=r.fromBytes(h);return r.isValidNot0(m)}catch{return!1}}function i(h,m){let{publicKey:g,publicKeyUncompressed:p}=o;try{let b=h.length;return m===!0&&b!==g||m===!1&&b!==p?!1:!!t.fromBytes(h)}catch{return!1}}function a(h){return h=h===void 0?n(o.seed):h,Ks(M(h,o.seed,"seed"),r.ORDER)}function c(h,m=!0){return t.BASE.multiply(r.fromBytes(h)).toBytes(m)}function u(h){let{secretKey:m,publicKey:g,publicKeyUncompressed:p}=o,b=r._lengths;if(!vt(h))return;let E=M(h,void 0,"key").length,S=E===g||E===p,C=E===m||!!b?.includes(E);if(!(S&&C))return S}function f(h,m,g=!0){if(u(h)===!0)throw new Error("first arg must be private key");if(u(m)===!1)throw new Error("second arg must be public key");let p=r.fromBytes(h);return t.fromBytes(m).multiply(p).toBytes(g)}let d={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},l=On(a,c);return Object.freeze(d),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:l,Point:t,utils:d,lengths:o})}function Tu(t,e,r={}){let n=e;wn(n),Oe(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?Lr:r.randomBytes,s=r.hmac===void 0?(v,w)=>xu(n,v,w):r.hmac,{Fp:i,Fn:a}=t,{ORDER:c,BITS:u}=a,{keygen:f,getPublicKey:d,getSharedSecret:l,utils:h,lengths:m}=mp(t,r),g={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},p=c*Eu+bt<i.ORDER;function b(v){let w=c>>bt;return v>w}function E(v,w){if(!a.isValidNot0(w))throw new Error(`invalid signature ${v}: out of range 1..Point.Fn.ORDER`);return w}function S(){if(p)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function C(v,w){Ui(w);let T=m.signature,D=w==="compact"?T:w==="recovered"?T+1:void 0;return M(v,D)}class I{r;s;recovery;constructor(w,T,D){if(this.r=E("r",w),this.s=E("s",T),D!=null){if(S(),![0,1,2,3].includes(D))throw new Error("invalid recovery id");this.recovery=D}Object.freeze(this)}static fromBytes(w,T=g.format){C(w,T);let D;if(T==="der"){let{r:N,s:q}=Ke.toSig(M(w));return new I(N,q)}T==="recovered"&&(D=w[0],T="compact",w=w.subarray(1));let B=m.signature/2,L=w.subarray(0,B),k=w.subarray(B,B*2);return new I(a.fromBytes(L),a.fromBytes(k),D)}static fromHex(w,T){return this.fromBytes(er(w),T)}assertRecovery(){let{recovery:w}=this;if(w==null)throw new Error("invalid recovery id: must be present");return w}addRecoveryBit(w){return new I(this.r,this.s,w)}recoverPublicKey(w){let{r:T,s:D}=this,B=this.assertRecovery(),L=B===2||B===3?T+c:T;if(!i.isValid(L))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let k=i.toBytes(L),N=t.fromBytes(oe(Su((B&1)===0),k)),q=a.inv(L),U=R(M(w,void 0,"msgHash")),ne=a.create(-U*q),se=a.create(D*q),ie=t.BASE.multiplyUnsafe(ne).add(N.multiplyUnsafe(se));if(ie.is0())throw new Error("invalid recovery: point at infinify");return ie.assertValidity(),ie}hasHighS(){return b(this.s)}toBytes(w=g.format){if(Ui(w),w==="der")return er(Ke.hexFromSig(this));let{r:T,s:D}=this,B=a.toBytes(T),L=a.toBytes(D);return w==="recovered"?(S(),oe(Uint8Array.of(this.assertRecovery()),B,L)):oe(B,L)}toHex(w){return Jt(this.toBytes(w))}}Object.freeze(I.prototype),Object.freeze(I);let O=r.bits2int===void 0?function(w){if(w.length>8192)throw new Error("input is too large");let T=St(w),D=w.length*8-u;return D>0?T>>BigInt(D):T}:r.bits2int,R=r.bits2int_modN===void 0?function(w){return a.create(O(w))}:r.bits2int_modN,_=Pr(u);function P(v){return tr("num < 2^"+u,v,He,_),a.toBytes(v)}function V(v,w){return M(v,void 0,"message"),w?M(n(v),void 0,"prehashed message"):v}function K(v,w,T){let{lowS:D,prehash:B,extraEntropy:L}=Ki(T,g);v=V(v,B);let k=R(v),N=a.fromBytes(w);if(!a.isValidNot0(N))throw new Error("invalid private key");let q=[P(N),P(k)];if(L!=null&&L!==!1){let ie=L===!0?o(m.secretKey):L;q.push(M(ie,void 0,"extraEntropy"))}let U=oe(...q),ne=k;function se(ie){let Q=O(ie);if(!a.isValidNot0(Q))return;let xe=a.inv(Q),Pt=t.BASE.multiply(Q).toAffine(),pr=a.create(Pt.x);if(pr===He)return;let fn=a.create(xe*a.create(ne+pr*N));if(fn===He)return;let la=(Pt.x===pr?0:2)|Number(Pt.y&bt),da=fn;return D&&b(fn)&&(da=a.neg(fn),la^=1),new I(pr,da,p?void 0:la)}return{seed:U,k2sig:se}}function y(v,w,T={}){let{seed:D,k2sig:B}=K(v,w,T);return xc(n.outputLen,a.BYTES,s)(D,B).toBytes(T.format)}function x(v,w,T,D={}){let{lowS:B,prehash:L,format:k}=Ki(D,g);if(T=M(T,void 0,"publicKey"),w=V(w,L),!vt(v)){let N=v instanceof I?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+N)}C(v,k);try{let N=I.fromBytes(v,k),q=t.fromBytes(T);if(B&&N.hasHighS())return!1;let{r:U,s:ne}=N,se=R(w),ie=a.inv(ne),Q=a.create(se*ie),xe=a.create(U*ie),Pt=t.BASE.multiplyUnsafe(Q).add(q.multiplyUnsafe(xe));return Pt.is0()?!1:a.create(Pt.x)===U}catch{return!1}}function A(v,w,T={}){let{prehash:D}=Ki(T,g);return w=V(w,D),I.fromBytes(v,"recovered").recoverPublicKey(w).toBytes()}return Object.freeze({keygen:f,getPublicKey:d,getSharedSecret:l,utils:h,lengths:m,Point:t,sign:y,verify:x,recoverPublicKey:A,Signature:I,hash:n})}var Mi={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},yp={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var _u=BigInt(2);function bp(t){let e=Mi.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=t*t*t%e,f=u*u*t%e,d=j(f,r,e)*f%e,l=j(d,r,e)*f%e,h=j(l,_u,e)*u%e,m=j(h,o,e)*h%e,g=j(m,s,e)*m%e,p=j(g,a,e)*g%e,b=j(p,c,e)*p%e,E=j(b,a,e)*g%e,S=j(E,r,e)*f%e,C=j(S,i,e)*m%e,I=j(C,n,e)*u%e,O=j(I,_u,e);if(!Fi.eql(Fi.sqr(O),t))throw new Error("Cannot find square root");return O}var Fi=nr(Mi.p,{sqrt:bp}),gp=vu(Mi,{Fp:Fi,endo:yp}),ur=Tu(gp,Qt);function Iu(t,e,r,n){let o=qr.digest(r instanceof Uint8Array?r:r.subarray());if(Un(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),ur.verify(e,s,t,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Fr(String(s))});try{return n?.signal?.throwIfAborted(),ur.verify(e,o.digest,t,{prehash:!1,format:"der"})}catch(s){throw new Fr(String(s))}}var jn=class{type="secp256k1";raw;_key;constructor(e){this._key=Bu(e),this.raw=Cu(this._key)}toMultihash(){return Ce.digest(Ae(this))}toCID(){return te.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:re(this.raw,e.raw)}verify(e,r,n){return Iu(this._key,r,e,n)}};function qi(t){return new jn(t)}function Cu(t){return ur.Point.fromBytes(t).toBytes()}function Bu(t){try{return ur.Point.fromBytes(t),t}catch(e){throw new Kt(String(e))}}function Wn(t,e){let{Type:r,Data:n}=Ve.decode(t),o=n??new Uint8Array;switch(r){case W.RSA:return Oi(o,e);case W.Ed25519:return Ys(o);case W.secp256k1:return qi(o);case W.ECDSA:return gs(o);default:throw new gt}}function Du(t){let{Type:e,Data:r}=Ve.decode(t.digest),n=r??new Uint8Array;switch(e){case W.Ed25519:return Ys(n);case W.secp256k1:return qi(n);case W.ECDSA:return gs(n);default:throw new gt}}function Ae(t){return Ve.encode({Type:W[t.type],Data:t.raw})}var Ru=Symbol.for("nodejs.util.inspect.custom"),xp=114,Wr=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[hn]=!0;toString(){return this.string==null&&(this.string=Y.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return te.createV1(xp,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return re(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return re(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[Ru](){return`PeerId(${this.toString()})`}},Zr=class extends Wr{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Yr=class extends Wr{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Gr=class extends Wr{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},wp=2336,Xr=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Ce.digest(J(this.url))}[Ru](){return`PeerId(${this.url})`}[hn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return te.createV1(wp,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=$(e)),e.toString()===this.toString())}};var Ep=114,Lu=2336;function Ou(t){if(t.type==="Ed25519")return new Yr({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new Gr({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new Zr({multihash:t.toCID().multihash,publicKey:t});throw new gt}function zi(t){if(Sp(t))return new Zr({multihash:t});if(vp(t))try{let e=Du(t);if(e.type==="Ed25519")return new Yr({multihash:t,publicKey:e});if(e.type==="secp256k1")return new Gr({multihash:t,publicKey:e})}catch{let r=$(t.digest);return new Xr(new URL(r))}throw new dn("Supplied PeerID Multihash is invalid")}function Zn(t){if(t?.multihash==null||t.version==null||t.version===1&&t.code!==Ep&&t.code!==Lu)throw new ln("Supplied PeerID CID is invalid");if(t.code===Lu){let e=$(t.multihash.digest);return new Xr(new URL(e))}return zi(t.multihash)}function vp(t){return t.code===Ce.code}function Sp(t){return t.code===qr.code}var Qr;(function(t){let e;t.codec=()=>(e==null&&(e=ge((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.publicKey!=null&&s.publicKey.byteLength>0&&(i.uint32(10),i.bytes(s.publicKey)),s.payloadType!=null&&s.payloadType.byteLength>0&&(i.uint32(18),i.bytes(s.payloadType)),s.payload!=null&&s.payload.byteLength>0&&(i.uint32(26),i.bytes(s.payload)),s.signature!=null&&s.signature.byteLength>0&&(i.uint32(42),i.bytes(s.signature)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={publicKey:Be(0),payloadType:Be(0),payload:Be(0),signature:Be(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.publicKey=s.bytes();break}case 2:{c.payloadType=s.bytes();break}case 3:{c.payload=s.bytes();break}case 5:{c.signature=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.publicKey`,value:s.bytes()};break}case 2:{yield{field:`${a}.payloadType`,value:s.bytes()};break}case 3:{yield{field:`${a}.payload`,value:s.bytes()};break}case 5:{yield{field:`${a}.signature`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ye(s,t.codec())}t.encode=r;function n(s,i){return me(s,t.codec(),i)}t.decode=n;function o(s,i){return be(s,t.codec(),i)}t.stream=o})(Qr||(Qr={}));var Yn=class extends Error{constructor(e="Invalid signature"){super(e),this.name="InvalidSignatureError"}};var fr=class t{static createFromProtobuf=e=>{let r=Qr.decode(e),n=Wn(r.publicKey);return new t({publicKey:n,payloadType:r.payloadType,payload:r.payload,signature:r.signature})};static seal=async(e,r,n)=>{if(r==null)throw new Error("Missing private key");let o=e.domain,s=e.codec,i=e.marshal(),a=ku(o,s,i),c=await r.sign(a.subarray(),n);return new t({publicKey:r.publicKey,payloadType:s,payload:i,signature:c})};static openAndCertify=async(e,r,n)=>{let o=t.createFromProtobuf(e);if(!await o.validate(r,n))throw new Yn("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(e){let{publicKey:r,payloadType:n,payload:o,signature:s}=e;this.publicKey=r,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=Qr.encode({publicKey:Ae(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(e){return e==null?!1:re(this.marshal(),e.marshal())}async validate(e,r){let n=ku(e,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},ku=(t,e,r)=>{let n=J(t),o=Fn(n.byteLength),s=Fn(e.length),i=Fn(r.length);return new pe(o,n,s,e,i,r)};function Pu(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Gn(t=0){return new Uint8Array(t)}function Jr(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=Gn(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}function Uu(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Ku=Uu("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Vi=Uu("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Gn(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Ap={utf8:Ku,"utf-8":Ku,hex:Pe.base16,latin1:Vi,ascii:Vi,binary:Vi,...Pe},Xn=Ap;function en(t,e="utf8"){let r=Xn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Dt(t,e="utf8"){let r=Xn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var le=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},et=class extends Error{static name="ValidationError";name="ValidationError"},Qn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Jn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var eo=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let r=this.index,n=e();return n===void 0&&(this.index=r),n}parseWith(e){let r=e();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let r=this.readChar();if(r===e)return r})}readSeparator(e,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let d=this.readChar();if(d===void 0)return;let l=Number.parseInt(d,e);if(!Number.isNaN(l))return l});if(f===void 0)break;if(s*=e,s+=f,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let r=0;r<e.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[r]=n}return e})}readIPv6Addr(){let e=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=e(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Tp=45,_p=15,to=new eo;function Nu(t){if(!(t.length>_p))return to.new(t).parseWith(()=>to.readIPv4Addr())}function Fu(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>Tp))return to.new(t).parseWith(()=>to.readIPv6Addr())}function ro(t){return!!Nu(t)}function Mu(t){return!!Fu(t)}function $i(t){return e=>Dt(e,t)}function ji(t){return e=>en(e,t)}function lr(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Rt(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function qu(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let r=en(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Rt(n);return Jr([r,o],r.length+o.length)}function zu(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=Ue.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Rt(n);return Jr([r,o],r.length+o.length)}function Wi(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=Dt(e,"base32"),o=lr(r);return`${n}:${o}`}var Zi=function(t){t=t.toString().trim();let e=new Uint8Array(4);return t.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new le("Invalid byte value in IP address");e[n]=o}),e},Vu=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let s=ro(r[n]),i;s&&(i=Zi(r[n]),r[n]=Dt(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,Dt(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(e+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new le("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},Hu=function(t){if(t.byteLength!==4)throw new le("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},$u=function(t){if(t.byteLength!==16)throw new le("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let o=t[n],s=t[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let r=e.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new le(`Invalid IPv6 address "${r}"`)}};function ju(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new le(`Invalid IPv6 address "${t}"`)}}var Hi=Object.values(Pe).map(t=>t.decoder),Ip=(function(){let t=Hi[0].or(Hi[1]);return Hi.slice(2).forEach(e=>t=t.or(e)),t})();function Wu(t){return Ip.decode(t)}function Zu(t){return e=>t.encoder.encode(e)}function Cp(t){if(parseInt(t).toString()!==t)throw new et("Value must be an integer")}function Bp(t){if(t<0)throw new et("Value must be a positive integer, or zero")}function Dp(t){return e=>{if(e>t)throw new et(`Value must be smaller than or equal to ${t}`)}}function Rp(...t){return e=>{for(let r of t)r(e)}}var tn=Rp(Cp,Bp,Dp(65535));var ce=-1,Yi=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let r;if(typeof e=="string"?r=this.protocolsByName.get(e):r=this.protocolsByCode.get(e),r==null)throw new Jn(`Protocol ${e} was unknown`);return r}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(r=>{this.protocolsByName.set(r,e)})}removeProtocol(e){let r=this.protocolsByCode.get(e);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},tt=new Yi,bm=[{code:4,name:"ip4",size:32,valueToBytes:Zi,bytesToValue:Hu,validate:t=>{if(!ro(t))throw new et(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Rt,bytesToValue:lr,validate:tn},{code:273,name:"udp",size:16,valueToBytes:Rt,bytesToValue:lr,validate:tn},{code:33,name:"dccp",size:16,valueToBytes:Rt,bytesToValue:lr,validate:tn},{code:41,name:"ip6",size:128,valueToBytes:Vu,bytesToValue:$u,stringToValue:ju,validate:t=>{if(!Mu(t))throw new et(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:ce},{code:43,name:"ipcidr",size:8,bytesToValue:$i("base10"),valueToBytes:ji("base10")},{code:53,name:"dns",size:ce},{code:54,name:"dns4",size:ce},{code:55,name:"dns6",size:ce},{code:56,name:"dnsaddr",size:ce},{code:132,name:"sctp",size:16,valueToBytes:Rt,bytesToValue:lr,validate:tn},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ce,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:ce,bytesToValue:$i("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?ji("base58btc")(t):te.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Wi,valueToBytes:qu},{code:445,name:"onion3",size:296,bytesToValue:Wi,valueToBytes:zu},{code:446,name:"garlic64",size:ce},{code:447,name:"garlic32",size:ce},{code:448,name:"tls"},{code:449,name:"sni",size:ce},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ce,bytesToValue:Zu(fi),valueToBytes:Wu},{code:480,name:"http"},{code:481,name:"http-path",size:ce,stringToValue:t=>`/${decodeURIComponent(t)}`,valueToString:t=>encodeURIComponent(t.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:ce}];bm.forEach(t=>{tt.addProtocol(t)});function Yu(t){let e=[],r=0;for(;r<t.length;){let n=ti(t,r),o=tt.getProtocol(n),s=_e(n),i=gm(o,t,r+s),a=0;i>0&&o.size===ce&&(a=_e(i));let c=s+a+i,u={code:n,name:o.name,bytes:t.subarray(r,r+c)};if(i>0){let f=r+s+a,d=t.subarray(f,f+i);u.value=o.bytesToValue?.(d)??Dt(d)}e.push(u),r+=c}return e}function Gu(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=tt.getProtocol(n.code),s=_e(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??en(n.value),a=i.byteLength,o.size===ce&&(c=_e(a)));let u=new Uint8Array(s+c+a),f=0;ar(n.code,u,f),f+=s,i!=null&&(o.size===ce&&(ar(a,u,f),f+=c),u.set(i,f)),n.bytes=u}r.push(n.bytes),e+=n.bytes.byteLength}return Jr(r,e)}function Xu(t){if(t.charAt(0)!=="/")throw new le('String multiaddr must start with "/"');let e=[],r="protocol",n="",o="";for(let s=1;s<t.length;s++){let i=t.charAt(s);i!=="/"&&(r==="protocol"?o+=t.charAt(s):n+=t.charAt(s));let a=s===t.length-1;if(i==="/"||a){let c=tt.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new le(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new le(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}e.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new le("Incomplete multiaddr");return e}function Qu(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=tt.getProtocol(e.code);if(r==null)throw new le(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function gm(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:ti(e,r)}var xm=Symbol.for("nodejs.util.inspect.custom"),Xi=Symbol.for("@multiformats/multiaddr");function wm(t){if(t==null&&(t="/"),oo(t))return t.getComponents();if(t instanceof Uint8Array)return Yu(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),Xu(t);if(Array.isArray(t))return t;throw new le("Must be a string, Uint8Array, Component[], or another Multiaddr")}var no=class t{[Xi]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=wm(e),r.validate!==!1&&Em(this)}get bytes(){return this.#r==null&&(this.#r=Gu(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=Qu(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let r=new t(e);return new t([...this.#e,...r.getComponents()],{validate:!1})}decapsulate(e){let r=e.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new Qn(`Address ${this.toString()} does not contain subaddress: ${r}`);return new t(n.slice(0,o),{validate:!1})}decapsulateCode(e){let r;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){r=n;break}return new t(this.#e.slice(0,r),{validate:!1})}equals(e){return Pu(this.bytes,e.bytes)}[xm](){return`Multiaddr(${this.toString()})`}};function Em(t){t.getComponents().forEach(e=>{let r=tt.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function oo(t){return!!t?.[Xi]}function Lt(t){return new no(t)}var Ju="libp2p-peer-record",ef=Uint8Array.from([3,1]);var rn;(function(t){let e;(function(i){let a;i.codec=()=>(a==null&&(a=ge((d,l,h={})=>{h.lengthDelimited!==!1&&l.fork(),d.multiaddr!=null&&d.multiaddr.byteLength>0&&(l.uint32(10),l.bytes(d.multiaddr)),h.lengthDelimited!==!1&&l.ldelim()},(d,l,h={})=>{let m={multiaddr:Be(0)},g=l==null?d.len:d.pos+l;for(;d.pos<g;){let p=d.uint32();p>>>3===1?m.multiaddr=d.bytes():d.skipType(p&7)}return m},function*(d,l,h,m={}){let g=l==null?d.len:d.pos+l;for(;d.pos<g;){let p=d.uint32();p>>>3===1?yield{field:`${h}.multiaddr`,value:d.bytes()}:d.skipType(p&7)}})),a);function c(d){return ye(d,i.codec())}i.encode=c;function u(d,l){return me(d,i.codec(),l)}i.decode=u;function f(d,l){return be(d,i.codec(),l)}i.stream=f})(e=t.AddressInfo||(t.AddressInfo={}));let r;t.codec=()=>(r==null&&(r=ge((i,a,c={})=>{if(c.lengthDelimited!==!1&&a.fork(),i.peerId!=null&&i.peerId.byteLength>0&&(a.uint32(10),a.bytes(i.peerId)),i.seq!=null&&i.seq!==0n&&(a.uint32(16),a.uint64(i.seq)),i.addresses!=null&&i.addresses.length>0)for(let u of i.addresses)a.uint32(26),t.AddressInfo.codec().encode(u,a);c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let u={peerId:Be(0),seq:0n,addresses:[]},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{u.peerId=i.bytes();break}case 2:{u.seq=i.uint64();break}case 3:{if(c.limits?.addresses!=null&&u.addresses.length===c.limits.addresses)throw new Ie('Decode error - repeated field "addresses" had too many elements');u.addresses.push(t.AddressInfo.codec().decode(i,i.uint32(),{limits:c.limits?.addresses$}));break}default:{i.skipType(d&7);break}}}return u},function*(i,a,c,u={}){let f={addresses:0},d=a==null?i.len:i.pos+a;for(;i.pos<d;){let l=i.uint32();switch(l>>>3){case 1:{yield{field:`${c}.peerId`,value:i.bytes()};break}case 2:{yield{field:`${c}.seq`,value:i.uint64()};break}case 3:{if(u.limits?.addresses!=null&&f.addresses===u.limits.addresses)throw new Ie('Streaming decode error - repeated field "addresses" had too many elements');for(let h of t.AddressInfo.codec().stream(i,i.uint32(),`${c}.addresses[]`,{limits:u.limits?.addresses$}))yield{...h,index:f.addresses};f.addresses++;break}default:{i.skipType(l&7);break}}}})),r);function n(i){return ye(i,t.codec())}t.encode=n;function o(i,a){return me(i,t.codec(),a)}t.decode=o;function s(i,a){return be(i,t.codec(),a)}t.stream=s})(rn||(rn={}));function tf(t,e){let r=(n,o)=>n.toString().localeCompare(o.toString());return t.length!==e.length?!1:(e.sort(r),t.sort(r).every((n,o)=>e[o].equals(n)))}var Ot=class t{static createFromProtobuf=e=>{let r=rn.decode(e),n=zi(Vt(r.peerId)),o=(r.addresses??[]).map(i=>Lt(i.multiaddr)),s=r.seq;return new t({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Ju;static CODEC=ef;peerId;multiaddrs;seqNumber;domain=t.DOMAIN;codec=t.CODEC;marshaled;constructor(e){let{peerId:r,multiaddrs:n,seqNumber:o}=e;this.peerId=r,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=rn.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(e=>({multiaddr:e.bytes}))})),this.marshaled}equals(e){return!(!(e instanceof t)||!this.peerId.equals(e.peerId)||this.seqNumber!==e.seqNumber||!tf(this.multiaddrs,e.multiaddrs))}};function vm(t){return t[Symbol.asyncIterator]!=null}function Sm(t){if(vm(t))return(async()=>{let r=[];for await(let n of t)r.push(n);return r})();let e=[];for(let r of t)e.push(r);return e}var rf=Sm;function so(t,e){let r={[Symbol.iterator]:()=>r,next:()=>{let n=t.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:e(o)}}};return r}var nn=class{map;constructor(e){if(this.map=new Map,e!=null)for(let[r,n]of e.entries())this.map.set(r.toString(),{key:r,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(e){return this.map.delete(e.toString())}entries(){return so(this.map.entries(),e=>[e[1].key,e[1].value])}forEach(e){this.map.forEach((r,n)=>{e(r.value,r.key,this)})}get(e){return this.map.get(e.toString())?.value}has(e){return this.map.has(e.toString())}set(e,r){this.map.set(e.toString(),{key:e,value:r})}keys(){return so(this.map.values(),e=>e.key)}values(){return so(this.map.values(),e=>e.value)}get size(){return this.map.size}};function io(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var ao=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},dr=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new ao(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let r=this.head;this.head=r.next=new ao(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Qi=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function nf(t={}){return Am(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},t)}function Am(t,e){e=e??{};let r=e.onEnd,n=new dr,o,s,i,a=io(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,b)=>{s=E=>{s=null,n.push(E);try{p(t(n))}catch(S){b(S)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=io()})}},u=p=>s!=null?s(p):(n.push(p),o),f=p=>(n=new dr,s!=null?s({error:p}):(n.push({error:p}),o)),d=p=>{if(i)return o;if(e?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:p})},l=p=>i?o:(i=!0,p!=null?f(p):u({done:!0})),h=()=>(n=new dr,l(),{done:!0}),m=p=>(l(p),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:h,throw:m,push:d,end:l,get readableLength(){return n.size},onEmpty:async p=>{let b=p?.signal;if(b?.throwIfAborted(),n.isEmpty())return;let E,S;b!=null&&(E=new Promise((C,I)=>{S=()=>{I(new Qi)},b.addEventListener("abort",S)}));try{await Promise.race([a.promise,E])}finally{S!=null&&b!=null&&b?.removeEventListener("abort",S)}}},r==null)return o;let g=o;return o={[Symbol.asyncIterator](){return this},next(){return g.next()},throw(p){return g.throw(p),r!=null&&(r(p),r=void 0),{done:!0}},return(){return g.return(),r!=null&&(r(),r=void 0),{done:!0}},push:d,end(p){return g.end(p),r!=null&&(r(p),r=void 0),o},get readableLength(){return g.readableLength},onEmpty:p=>g.onEmpty(p)},o}function Tm(t){return t.reason}async function of(t,e,r){if(e==null)return t;let n=r?.translateError??Tm;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var Ji=class extends nn{metric;constructor(e){super();let{name:r,metrics:n}=e;this.metric=n.registerMetric(r),this.updateComponentMetric()}set(e,r){return super.set(e,r),this.updateComponentMetric(),this}delete(e){let r=super.delete(e);return this.updateComponentMetric(),r}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function ea(t){let{name:e,metrics:r}=t,n;return r!=null?n=new Ji({name:e,metrics:r}):n=new nn,n}var Se=class extends Error{static name="AbortError";name="AbortError";constructor(e="The operation was aborted",...r){super(e,...r)}};async function co(t,e,r,n){let o=new Se(n?.errorMessage);n?.errorCode!=null&&(o.code=n.errorCode);let s=n?.errorEvent??"error";return r?.aborted===!0?Promise.reject(o):new Promise((i,a)=>{function c(){ra(r,"abort",d),ra(t,e,u),ra(t,s,f)}let u=l=>{try{if(n?.filter?.(l)===!1)return}catch(h){c(),a(h);return}c(),i(l)},f=l=>{if(c(),l instanceof Error){a(l);return}a(l.detail??n?.error??new Error(`The "${n?.errorEvent}" event was emitted but the event had no '.detail' field. Pass an 'error' option to race-event to change this message.`))},d=()=>{c(),a(o)};ta(r,"abort",d),ta(t,e,u),ta(t,s,f)})}function ta(t,e,r){t!=null&&(sf(t)?t.addEventListener(e,r):t.addListener(e,r))}function ra(t,e,r){t!=null&&(sf(t)?t.removeEventListener(e,r):t.removeListener(e,r))}function sf(t){return typeof t.addEventListener=="function"&&typeof t.removeEventListener=="function"}var uo=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};var fo=class{deferred;signal;constructor(e){this.signal=e,this.deferred=Promise.withResolvers(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Se)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function _m(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var lo=class{id;fn;options;recipients;status;timeline;controller;constructor(e,r){this.id=_m(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Se),this.cleanup())}async join(e={}){let r=new fo(e.signal);return this.recipients.push(r),e.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await of(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(r=>{r.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};function na(t,e){let r,n=function(){let o=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var on=class extends Nt{concurrency;maxSize;queue;pending;sort;autoStart;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.maxSize=e.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.autoStart=e.autoStart??!0,this.sort=e.sort,this.queue=[],this.emitEmpty=na(this.emitEmpty.bind(this),1),this.emitIdle=na(this.emitIdle.bind(this),1)}[Symbol.asyncIterator](){return this.toGenerator()}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}tryToStartAnother(){if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let e;for(let r of this.queue)if(r.status==="queued"){e=r;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===e){this.queue.splice(r,1);break}this.pending--,this.safeDispatchEvent("next"),this.autoStart&&this.tryToStartAnother()}),!0)}return!1}enqueue(e){this.queue.push(e),this.sort!=null&&this.queue.sort(this.sort)}start(){this.autoStart===!1&&(this.autoStart=!0,this.tryToStartAnother())}pause(){this.autoStart=!1}async add(e,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new uo;let n=new lo(e,r);return this.enqueue(n),this.safeDispatchEvent("add"),this.autoStart&&this.tryToStartAnother(),n.join(r).then(o=>(this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new Se)}),this.clear()}async onEmpty(e){this.size!==0&&await co(this,"empty",e?.signal)}async onSizeLessThan(e,r){this.size<e||await co(this,"next",r?.signal,{filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await co(this,"idle",e?.signal)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let r=nf({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},o=c=>{c.detail!=null&&r.push(c.detail.result)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new Se("Queue aborted"))};this.addEventListener("success",o),this.addEventListener("failure",s),this.addEventListener("idle",i),e?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("success",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),e?.signal?.removeEventListener("abort",a),n()}}};var ho="lock:worker:request-read",po="lock:worker:abort-read-request",mo="lock:worker:release-read",yo="lock:master:grant-read",bo="lock:master:error-read",go="lock:worker:request-write",xo="lock:worker:abort-write-request",wo="lock:worker:release-write",Eo="lock:master:grant-write",vo="lock:master:error-write",So="lock:worker:finalize",Ao="mortice",af={singleProcess:!1};var oa=(t,e,r,n,o,s,i,a,c)=>u=>{if(u.data==null)return;let f={type:u.data.type,name:u.data.name,identifier:u.data.identifier};f.type===o&&t.safeDispatchEvent(r,{detail:{name:f.name,identifier:f.identifier,handler:async()=>{e.postMessage({type:c,name:f.name,identifier:f.identifier}),await new Promise(d=>{let l=h=>{if(h?.data==null)return;let m={type:h.data.type,name:h.data.name,identifier:h.data.identifier};m.type===a&&m.identifier===f.identifier&&(e.removeEventListener("message",l),d())};e.addEventListener("message",l)})},onError:d=>{e.postMessage({type:i,name:f.name,identifier:f.identifier,error:{message:d.message,name:d.name,stack:d.stack}})}}}),f.type===s&&t.safeDispatchEvent(n,{detail:{name:f.name,identifier:f.identifier}}),f.type===So&&t.safeDispatchEvent("finalizeRequest",{detail:{name:f.name}})};var cf=(t=10)=>Math.random().toString().substring(2,t+2);var To=class{name;channel;constructor(e){this.name=e,this.channel=new BroadcastChannel(Ao)}readLock(e){return this.sendRequest(ho,po,yo,bo,mo,e)}writeLock(e){return this.sendRequest(go,xo,Eo,vo,wo,e)}finalize(){this.channel.postMessage({type:So,name:this.name}),this.channel.close()}async sendRequest(e,r,n,o,s,i){i?.signal?.throwIfAborted();let a=cf();return this.channel.postMessage({type:e,identifier:a,name:this.name}),new Promise((c,u)=>{let f=()=>{this.channel.postMessage({type:r,identifier:a,name:this.name})};i?.signal?.addEventListener("abort",f,{once:!0});let d=l=>{if(l.data?.identifier===a&&(l.data?.type===n&&(this.channel.removeEventListener("message",d),i?.signal?.removeEventListener("abort",f),c(()=>{this.channel.postMessage({type:s,identifier:a,name:this.name})})),l.data.type===o)){this.channel.removeEventListener("message",d),i?.signal?.removeEventListener("abort",f);let h=new Error;l.data.error!=null&&(h.message=l.data.error.message,h.name=l.data.error.name,h.stack=l.data.error.stack),u(h)}};this.channel.addEventListener("message",d)})}};var uf=t=>{if(t=Object.assign({},af,t),!!globalThis.document||t.singleProcess){let r=new BroadcastChannel(Ao),n=new Nt;return r.addEventListener("message",oa(n,r,"requestReadLock","abortReadLockRequest",ho,po,bo,mo,yo)),r.addEventListener("message",oa(n,r,"requestWriteLock","abortWriteLockRequest",go,xo,vo,wo,Eo)),n}return new To(t.name)};var kt=new Map,sn;function ff(t){return typeof t?.readLock=="function"&&typeof t?.writeLock=="function"}function Im(t){if(sn==null&&(sn=uf(t),!ff(sn))){let e=sn;e.addEventListener("requestReadLock",r=>{let n=r.detail.name,o=r.detail.identifier,s=kt.get(n);if(s==null)return;let i=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==o||i.abort()};e.addEventListener("abortReadLockRequest",a),s.readLock({signal:i.signal}).then(async c=>{await r.detail.handler().finally(()=>{c()})}).catch(c=>{r.detail.onError(c)}).finally(()=>{e.removeEventListener("abortReadLockRequest",a)})}),e.addEventListener("requestWriteLock",r=>{let n=r.detail.name,o=r.detail.identifier,s=kt.get(n);if(s==null)return;let i=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==o||i.abort()};e.addEventListener("abortWriteLockRequest",a),s.writeLock({signal:i.signal}).then(async c=>{await r.detail.handler().finally(()=>{c()})}).catch(c=>{r.detail.onError(c)}).finally(()=>{e.removeEventListener("abortWriteLockRequest",a)})}),e.addEventListener("finalizeRequest",r=>{let n=r.detail.name,o=kt.get(n);o?.finalize()})}return sn}async function sa(t,e){let r,n,o=new Promise((i,a)=>{r=i,n=a}),s=()=>{n(new Se)};return e?.signal?.addEventListener("abort",s,{once:!0}),t.add(async()=>{await new Promise(i=>{r(()=>{e?.signal?.removeEventListener("abort",s),i()})})},{signal:e?.signal}).catch(i=>{n(i)}),o}var lf=(t,e)=>{let r=kt.get(t);if(r!=null)return r;let n=Im(e);if(ff(n))return r=n,kt.set(t,r),r;let o=new on({concurrency:1}),s;return r={async readLock(i){if(s!=null)return sa(s,i);s=new on({concurrency:e.concurrency,autoStart:!1});let a=s,c=sa(s,i);return o.add(async()=>{a.start(),await a.onIdle().then(()=>{s===a&&(s=null)})}),c},async writeLock(i){return s=null,sa(o,i)},finalize:()=>{kt.delete(t)},queue:o},kt.set(t,r),e.autoFinalize===!0&&o.addEventListener("idle",()=>{r.finalize()},{once:!0}),r};var Cm={name:"lock",concurrency:1/0,singleProcess:!1,autoFinalize:!1};function ia(t){let e=Object.assign({},Cm,t);return lf(e.name,e)}var rt;(function(t){let e;(function(a){let c;a.codec=()=>(c==null&&(c=ge((l,h,m={})=>{m.lengthDelimited!==!1&&h.fork(),l.key!=null&&l.key!==""&&(h.uint32(10),h.string(l.key)),l.value!=null&&l.value.byteLength>0&&(h.uint32(18),h.bytes(l.value)),m.lengthDelimited!==!1&&h.ldelim()},(l,h,m={})=>{let g={key:"",value:Be(0)},p=h==null?l.len:l.pos+h;for(;l.pos<p;){let b=l.uint32();switch(b>>>3){case 1:{g.key=l.string();break}case 2:{g.value=l.bytes();break}default:{l.skipType(b&7);break}}}return g},function*(l,h,m,g={}){let p=h==null?l.len:l.pos+h;for(;l.pos<p;){let b=l.uint32();switch(b>>>3){case 1:{yield{field:`${m}.key`,value:l.string()};break}case 2:{yield{field:`${m}.value`,value:l.bytes()};break}default:{l.skipType(b&7);break}}}})),c);function u(l){return ye(l,a.codec())}a.encode=u;function f(l,h){return me(l,a.codec(),h)}a.decode=f;function d(l,h){return be(l,a.codec(),h)}a.stream=d})(e=t.Peer$metadataEntry||(t.Peer$metadataEntry={}));let r;(function(a){let c;a.codec=()=>(c==null&&(c=ge((l,h,m={})=>{m.lengthDelimited!==!1&&h.fork(),l.key!=null&&l.key!==""&&(h.uint32(10),h.string(l.key)),l.value!=null&&(h.uint32(18),cn.codec().encode(l.value,h)),m.lengthDelimited!==!1&&h.ldelim()},(l,h,m={})=>{let g={key:""},p=h==null?l.len:l.pos+h;for(;l.pos<p;){let b=l.uint32();switch(b>>>3){case 1:{g.key=l.string();break}case 2:{g.value=cn.codec().decode(l,l.uint32(),{limits:m.limits?.value});break}default:{l.skipType(b&7);break}}}return g},function*(l,h,m,g={}){let p=h==null?l.len:l.pos+h;for(;l.pos<p;){let b=l.uint32();switch(b>>>3){case 1:{yield{field:`${m}.key`,value:l.string()};break}case 2:{yield*cn.codec().stream(l,l.uint32(),`${m}.value`,{limits:g.limits?.value});break}default:{l.skipType(b&7);break}}}})),c);function u(l){return ye(l,a.codec())}a.encode=u;function f(l,h){return me(l,a.codec(),h)}a.decode=f;function d(l,h){return be(l,a.codec(),h)}a.stream=d})(r=t.Peer$tagsEntry||(t.Peer$tagsEntry={}));let n;t.codec=()=>(n==null&&(n=ge((a,c,u={})=>{if(u.lengthDelimited!==!1&&c.fork(),a.addresses!=null&&a.addresses.length>0)for(let f of a.addresses)c.uint32(10),an.codec().encode(f,c);if(a.protocols!=null&&a.protocols.length>0)for(let f of a.protocols)c.uint32(18),c.string(f);if(a.publicKey!=null&&(c.uint32(34),c.bytes(a.publicKey)),a.peerRecordEnvelope!=null&&(c.uint32(42),c.bytes(a.peerRecordEnvelope)),a.metadata!=null&&a.metadata.size>0)for(let[f,d]of a.metadata.entries())c.uint32(50),t.Peer$metadataEntry.codec().encode({key:f,value:d},c);if(a.tags!=null&&a.tags.size>0)for(let[f,d]of a.tags.entries())c.uint32(58),t.Peer$tagsEntry.codec().encode({key:f,value:d},c);a.updated!=null&&(c.uint32(64),c.uint64Number(a.updated)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={addresses:[],protocols:[],metadata:new Map,tags:new Map},d=c==null?a.len:a.pos+c;for(;a.pos<d;){let l=a.uint32();switch(l>>>3){case 1:{if(u.limits?.addresses!=null&&f.addresses.length===u.limits.addresses)throw new Ie('Decode error - repeated field "addresses" had too many elements');f.addresses.push(an.codec().decode(a,a.uint32(),{limits:u.limits?.addresses$}));break}case 2:{if(u.limits?.protocols!=null&&f.protocols.length===u.limits.protocols)throw new Ie('Decode error - repeated field "protocols" had too many elements');f.protocols.push(a.string());break}case 4:{f.publicKey=a.bytes();break}case 5:{f.peerRecordEnvelope=a.bytes();break}case 6:{if(u.limits?.metadata!=null&&f.metadata.size===u.limits.metadata)throw new Hr('Decode error - map field "metadata" had too many elements');let h=t.Peer$metadataEntry.codec().decode(a,a.uint32(),{limits:{value:u.limits?.metadata$value}});f.metadata.set(h.key,h.value);break}case 7:{if(u.limits?.tags!=null&&f.tags.size===u.limits.tags)throw new Hr('Decode error - map field "tags" had too many elements');let h=t.Peer$tagsEntry.codec().decode(a,a.uint32(),{limits:{value:u.limits?.tags$value}});f.tags.set(h.key,h.value);break}case 8:{f.updated=a.uint64Number();break}default:{a.skipType(l&7);break}}}return f},function*(a,c,u,f={}){let d={addresses:0,protocols:0,metadata:0,tags:0},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let h=a.uint32();switch(h>>>3){case 1:{if(f.limits?.addresses!=null&&d.addresses===f.limits.addresses)throw new Ie('Streaming decode error - repeated field "addresses" had too many elements');for(let m of an.codec().stream(a,a.uint32(),`${u}.addresses[]`,{limits:f.limits?.addresses$}))yield{...m,index:d.addresses};d.addresses++;break}case 2:{if(f.limits?.protocols!=null&&d.protocols===f.limits.protocols)throw new Ie('Streaming decode error - repeated field "protocols" had too many elements');yield{field:`${u}.protocols[]`,index:d.protocols,value:a.string()},d.protocols++;break}case 4:{yield{field:`${u}.publicKey`,value:a.bytes()};break}case 5:{yield{field:`${u}.peerRecordEnvelope`,value:a.bytes()};break}case 6:{if(f.limits?.metadata!=null&&d.metadata===f.limits.metadata)throw new Ie('Decode error - map field "metadata" had too many elements');yield*t.Peer$metadataEntry.codec().stream(a,a.uint32(),`${u}.metadata{}`,{limits:{value:f.limits?.metadata$value}}),d.metadata++;break}case 7:{if(f.limits?.tags!=null&&d.tags===f.limits.tags)throw new Ie('Decode error - map field "tags" had too many elements');yield*t.Peer$tagsEntry.codec().stream(a,a.uint32(),`${u}.tags{}`,{limits:{value:f.limits?.tags$value}}),d.tags++;break}case 8:{yield{field:`${u}.updated`,value:a.uint64Number()};break}default:{a.skipType(h&7);break}}}})),n);function o(a){return ye(a,t.codec())}t.encode=o;function s(a,c){return me(a,t.codec(),c)}t.decode=s;function i(a,c){return be(a,t.codec(),c)}t.stream=i})(rt||(rt={}));var an;(function(t){let e;t.codec=()=>(e==null&&(e=ge((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.multiaddr!=null&&s.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(s.multiaddr)),s.isCertified!=null&&(i.uint32(16),i.bool(s.isCertified)),s.observed!=null&&(i.uint32(24),i.uint64Number(s.observed)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={multiaddr:Be(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.multiaddr=s.bytes();break}case 2:{c.isCertified=s.bool();break}case 3:{c.observed=s.uint64Number();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.multiaddr`,value:s.bytes()};break}case 2:{yield{field:`${a}.isCertified`,value:s.bool()};break}case 3:{yield{field:`${a}.observed`,value:s.uint64Number()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ye(s,t.codec())}t.encode=r;function n(s,i){return me(s,t.codec(),i)}t.decode=n;function o(s,i){return be(s,t.codec(),i)}t.stream=o})(an||(an={}));var cn;(function(t){let e;t.codec=()=>(e==null&&(e=ge((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.value!=null&&s.value!==0&&(i.uint32(8),i.uint32(s.value)),s.expiry!=null&&(i.uint32(16),i.uint64(s.expiry)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={value:0},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.value=s.uint32();break}case 2:{c.expiry=s.uint64();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.value`,value:s.uint32()};break}case 2:{yield{field:`${a}.expiry`,value:s.uint64()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ye(s,t.codec())}t.encode=r;function n(s,i){return me(s,t.codec(),i)}t.decode=n;function o(s,i){return be(s,t.codec(),i)}t.stream=o})(cn||(cn={}));function Bm(t,e){if(t.publicKey!=null||e.publicKey==null)return t;let r;t.type==="RSA"&&(r=t.toMultihash());let n=Wn(e.publicKey,r);return Ou(n)}function df(t,e,r){let n=rt.decode(e);return hr(t,n,r)}function hr(t,e,r){let n=new Map,o=BigInt(Date.now());for(let[s,i]of e.tags.entries())i.expiry!=null&&i.expiry<o||n.set(s,i);return{...e,id:Bm(t,e),addresses:e.addresses.filter(({observed:s})=>s!=null&&s>Date.now()-r).map(({multiaddr:s,isCertified:i})=>({multiaddr:Lt(s),isCertified:i??!1})),metadata:e.metadata,peerRecordEnvelope:e.peerRecordEnvelope??void 0,tags:n}}function hf(t,e){return Dm(t.addresses,e.addresses)&&Rm(t.protocols,e.protocols)&&Lm(t.publicKey,e.publicKey)&&Om(t.peerRecordEnvelope,e.peerRecordEnvelope)&&km(t.metadata,e.metadata)&&Pm(t.tags,e.tags)}function Dm(t,e){return mf(t,e,(r,n)=>!(r.isCertified!==n.isCertified||!re(r.multiaddr,n.multiaddr)))}function Rm(t,e){return mf(t,e,(r,n)=>r===n)}function Lm(t,e){return pf(t,e)}function Om(t,e){return pf(t,e)}function km(t,e){return yf(t,e,(r,n)=>re(r,n))}function Pm(t,e){return yf(t,e,(r,n)=>r.value===n.value&&r.expiry===n.expiry)}function pf(t,e){return t==null&&e==null?!0:t!=null&&e!=null?re(t,e):!1}function mf(t,e,r){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(!r(t[n],e[n]))return!1;return!0}function yf(t,e,r){if(t.size!==e.size)return!1;for(let[n,o]of t.entries()){let s=e.get(n);if(s==null||!r(o,s))return!1}return!0}function bf(t=0){return new Uint8Array(t)}function xf(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var gf=xf("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),aa=xf("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=bf(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Km={utf8:gf,"utf-8":gf,hex:Pe.base16,latin1:aa,ascii:aa,binary:aa,...Pe},_o=Km;function wf(t,e="utf8"){let r=_o[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Ef(t,e="utf8"){let r=_o[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var nt="/",vf=new TextEncoder().encode(nt),Io=vf[0],Co=class t{_buf;constructor(e,r){if(typeof e=="string")this._buf=wf(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(r==null&&(r=!0),r&&this.clean(),this._buf.byteLength===0||this._buf[0]!==Io)throw new Error("Invalid key")}toString(e="utf8"){return Ef(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new t(e.join(nt))}static random(){return new t(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new t(e):typeof e.uint8Array=="function"?new t(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=vf),this._buf[0]!==Io){let e=new Uint8Array(this._buf.byteLength+1);e.fill(Io,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Io;)this._buf=this._buf.subarray(0,-1)}less(e){let r=this.list(),n=e.list();for(let o=0;o<r.length;o++){if(n.length<o+1)return!1;let s=r[o],i=n[o];if(s<i)return!0;if(s>i)return!1}return r.length<n.length}reverse(){return t.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(nt).slice(1)}type(){return Um(this.baseNamespace())}name(){return Nm(this.baseNamespace())}instance(e){return new t(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(nt)||(e+=nt),e+=this.type(),new t(e)}parent(){let e=this.list();return e.length===1?new t(nt):new t(e.slice(0,-1).join(nt))}child(e){return this.toString()===nt?e:e.toString()===nt?this:new t(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return t.withNamespaces([...this.namespaces(),...Fm(e.map(r=>r.namespaces()))])}};function Um(t){let e=t.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function Nm(t){let e=t.split(":");return e[e.length-1]}function Fm(t){return[].concat(...t)}var ca="/peers/";function un(t){if(!Ut(t)||t.type==null)throw new F("Invalid PeerId");let e=t.toCID().toString();return new Co(`${ca}${e}`)}async function Sf(t,e,r,n,o){let s=new Map;for(let i of r){if(i==null)continue;if(i.multiaddr instanceof Uint8Array&&(i.multiaddr=Lt(i.multiaddr)),!oo(i.multiaddr))throw new F("Multiaddr was invalid");if(!await e(t,i.multiaddr,o))continue;let a=i.isCertified??!1,c=i.multiaddr.toString(),u=s.get(c);u!=null?i.isCertified=u.isCertified||a:s.set(c,{multiaddr:i.multiaddr,isCertified:a})}return[...s.values()].sort((i,a)=>i.multiaddr.toString().localeCompare(a.multiaddr.toString())).map(({isCertified:i,multiaddr:a})=>{let c=a.getComponents().find(u=>u.code===421)?.value;return t.equals(c)&&(a=a.decapsulate(Lt(`/p2p/${t}`))),{isCertified:i,multiaddr:a.bytes}})}async function Do(t,e,r,n){if(e==null)throw new F("Invalid PeerData");if(e.publicKey!=null&&t.publicKey!=null&&!e.publicKey.equals(t.publicKey))throw new F("publicKey bytes do not match peer id publicKey bytes");let o=n.existingPeer?.peer;if(o!=null&&!t.equals(o.id))throw new F("peer id did not match existing peer id");let s=o?.addresses??[],i=new Set(o?.protocols??[]),a=o?.metadata??new Map,c=o?.tags??new Map,u=o?.peerRecordEnvelope;if(r==="patch"){if((e.multiaddrs!=null||e.addresses!=null)&&(s=[],e.multiaddrs!=null&&s.push(...e.multiaddrs.map(l=>({isCertified:!1,multiaddr:l}))),e.addresses!=null&&s.push(...e.addresses)),e.protocols!=null&&(i=new Set(e.protocols)),e.metadata!=null){let l=e.metadata instanceof Map?[...e.metadata.entries()]:Object.entries(e.metadata);a=Bo(l,{validate:Af})}if(e.tags!=null){let l=e.tags instanceof Map?[...e.tags.entries()]:Object.entries(e.tags);c=Bo(l,{validate:Tf,map:_f})}e.peerRecordEnvelope!=null&&(u=e.peerRecordEnvelope)}if(r==="merge"){if(e.multiaddrs!=null&&s.push(...e.multiaddrs.map(l=>({isCertified:!1,multiaddr:l}))),e.addresses!=null&&s.push(...e.addresses),e.protocols!=null&&(i=new Set([...i,...e.protocols])),e.metadata!=null){let l=e.metadata instanceof Map?[...e.metadata.entries()]:Object.entries(e.metadata);for(let[h,m]of l)m==null?a.delete(h):a.set(h,m);a=Bo([...a.entries()],{validate:Af})}if(e.tags!=null){let l=e.tags instanceof Map?[...e.tags.entries()]:Object.entries(e.tags),h=new Map(c);for(let[m,g]of l)g==null?h.delete(m):h.set(m,g);c=Bo([...h.entries()],{validate:Tf,map:_f})}e.peerRecordEnvelope!=null&&(u=e.peerRecordEnvelope)}let f;o?.id.publicKey!=null?f=Ae(o.id.publicKey):e.publicKey!=null?f=Ae(e.publicKey):t.publicKey!=null&&(f=Ae(t.publicKey));let d={addresses:await Sf(t,n.addressFilter??(async()=>!0),s,n.existingPeer?.peerPB.addresses,n),protocols:[...i.values()].sort((l,h)=>l.localeCompare(h)),metadata:a,tags:c,publicKey:f,peerRecordEnvelope:u};return d.addresses.forEach(l=>{l.observed=n.existingPeer?.peerPB.addresses?.find(h=>re(h.multiaddr,h.multiaddr))?.observed??Date.now()}),t.type!=="RSA"&&delete d.publicKey,d}function Bo(t,e){let r=new Map;for(let[n,o]of t)o!=null&&e.validate(n,o);for(let[n,o]of t.sort(([s],[i])=>s.localeCompare(i)))o!=null&&r.set(n,e.map?.(n,o)??o);return r}function Af(t,e){if(typeof t!="string")throw new F("Metadata key must be a string");if(!(e instanceof Uint8Array))throw new F("Metadata value must be a Uint8Array")}function Tf(t,e){if(typeof t!="string")throw new F("Tag name must be a string");if(e.value!=null){if(parseInt(`${e.value}`,10)!==e.value)throw new F("Tag value must be an integer");if(e.value<0||e.value>100)throw new F("Tag value must be between 0-100")}if(e.ttl!=null){if(parseInt(`${e.ttl}`,10)!==e.ttl)throw new F("Tag ttl must be an integer");if(e.ttl<0)throw new F("Tag ttl must be between greater than 0")}}function _f(t,e){let r;e.expiry!=null&&(r=e.expiry),e.ttl!=null&&(r=BigInt(Date.now()+Number(e.ttl)));let n={value:e.value??0};return r!=null&&(n.expiry=r),n}function If(t){let e=t.toString().split("/")[2],r=te.parse(e,Ue);return Zn(r)}function ua(t,e,r){let n=If(t);return df(n,e,r)}function Mm(t,e){return{prefix:ca,filters:(t.filters??[]).map(r=>({key:n,value:o})=>r(ua(n,o,e))),orders:(t.orders??[]).map(r=>(n,o)=>r(ua(n.key,n.value,e),ua(o.key,o.value,e)))}}var Ro=class{peerId;datastore;locks;addressFilter;log;maxAddressAge;maxPeerAge;constructor(e,r={}){this.log=e.logger.forComponent("libp2p:peer-store"),this.peerId=e.peerId,this.datastore=e.datastore,this.addressFilter=r.addressFilter,this.locks=ea({name:"libp2p_peer_store_locks",metrics:e.metrics}),this.maxAddressAge=r.maxAddressAge??36e5,this.maxPeerAge=r.maxPeerAge??216e5}getLock(e){let r=this.locks.get(e);return r==null&&(r={refs:0,lock:ia({name:e.toString(),singleProcess:!0})},this.locks.set(e,r)),r.refs++,r}maybeRemoveLock(e,r){r.refs--,r.refs===0&&(r.lock.finalize(),this.locks.delete(e))}async getReadLock(e,r){let n=this.getLock(e);try{let o=await n.lock.readLock(r);return()=>{o(),this.maybeRemoveLock(e,n)}}catch(o){throw this.maybeRemoveLock(e,n),o}}async getWriteLock(e,r){let n=this.getLock(e);try{let o=await n.lock.writeLock(r);return()=>{o(),this.maybeRemoveLock(e,n)}}catch(o){throw this.maybeRemoveLock(e,n),o}}async has(e,r){try{return await this.load(e,r),!0}catch(n){if(n.name!=="NotFoundError")throw n}return!1}async delete(e,r){this.peerId.equals(e)||await this.datastore.delete(un(e),r)}async load(e,r){let n=un(e),o=await this.datastore.get(n,r),s=rt.decode(o);if(this.#r(e,s))throw await this.datastore.delete(n,r),new mr;return hr(e,s,this.peerId.equals(e)?1/0:this.maxAddressAge)}async save(e,r,n){let o=await this.#e(e,n),s=await Do(e,r,"patch",{...n,addressFilter:this.addressFilter});return this.#t(e,s,o)}async patch(e,r,n){let o=await this.#e(e,n),s=await Do(e,r,"patch",{...n,addressFilter:this.addressFilter,existingPeer:o});return this.#t(e,s,o)}async merge(e,r,n){let o=await this.#e(e,n),s=await Do(e,r,"merge",{addressFilter:this.addressFilter,existingPeer:o});return this.#t(e,s,o)}async*all(e){for await(let{key:r,value:n}of this.datastore.query(Mm(e??{},this.maxAddressAge),e)){let o=If(r);if(o.equals(this.peerId))continue;let s=rt.decode(n);if(this.#r(o,s)){await this.datastore.delete(r,e);continue}yield hr(o,s,this.peerId.equals(o)?1/0:this.maxAddressAge)}}async#e(e,r){try{let n=un(e),o=await this.datastore.get(n,r),s=rt.decode(o);if(this.#r(e,s))throw await this.datastore.delete(n,r),new mr;return{peerPB:s,peer:hr(e,s,this.maxAddressAge)}}catch(n){n.name!=="NotFoundError"&&this.log.error("invalid peer data found in peer store - %e",n)}}async#t(e,r,n,o){r.updated=Date.now();let s=rt.encode(r);return await this.datastore.put(un(e),s,o),{peer:hr(e,r,this.maxAddressAge),previous:n?.peer,updated:n==null||!hf(r,n.peerPB)}}#r(e,r){if(r.updated==null)return!0;if(this.peerId.equals(e))return!1;let n=r.updated<Date.now()-this.maxPeerAge,o=Date.now()-this.maxAddressAge,s=r.addresses.filter(i=>i.observed!=null&&i.observed>o);return n&&s.length===0}};var fa=class{store;events;peerId;log;constructor(e,r={}){this.log=e.logger.forComponent("libp2p:peer-store"),this.events=e.events,this.peerId=e.peerId,this.store=new Ro(e,r)}[Symbol.toStringTag]="@libp2p/peer-store";async forEach(e,r){for await(let n of this.store.all(r))e(n)}async all(e){return rf(this.store.all(e))}async delete(e,r){let n=await this.store.getReadLock(e,r);try{await this.store.delete(e,r)}finally{n()}}async has(e,r){let n=await this.store.getReadLock(e,r);try{return await this.store.has(e,r)}finally{this.log.trace("has release read lock"),n?.()}}async get(e,r){let n=await this.store.getReadLock(e,r);try{return await this.store.load(e,r)}finally{n?.()}}async getInfo(e,r){let n=await this.get(e,r);return{id:n.id,multiaddrs:n.addresses.map(({multiaddr:o})=>o)}}async save(e,r,n){let o=await this.store.getWriteLock(e,n);try{let s=await this.store.save(e,r,n);return this.#e(e,s),s.peer}finally{o?.()}}async patch(e,r,n){let o=await this.store.getWriteLock(e,n);try{let s=await this.store.patch(e,r,n);return this.#e(e,s),s.peer}finally{o?.()}}async merge(e,r,n){let o=await this.store.getWriteLock(e,n);try{let s=await this.store.merge(e,r,n);return this.#e(e,s),s.peer}finally{o?.()}}async consumePeerRecord(e,r,n){let o=Ut(r)?r:Ut(r?.expectedPeer)?r.expectedPeer:void 0,s=Ut(r)||r===void 0?n:r,i=await fr.openAndCertify(e,Ot.DOMAIN,s),a=Zn(i.publicKey.toCID());if(o?.equals(a)===!1)return this.log("envelope peer id was not the expected peer id - expected: %p received: %p",o,a),!1;let c=Ot.createFromProtobuf(i.payload),u;try{u=await this.get(a,s)}catch(f){if(f.name!=="NotFoundError")throw f}if(u?.peerRecordEnvelope!=null){let f=fr.createFromProtobuf(u.peerRecordEnvelope),d=Ot.createFromProtobuf(f.payload);if(d.seqNumber>=c.seqNumber)return this.log("sequence number was lower or equal to existing sequence number - stored: %d received: %d",d.seqNumber,c.seqNumber),!1}return await this.patch(c.peerId,{peerRecordEnvelope:e,addresses:c.multiaddrs.map(f=>({isCertified:!0,multiaddr:f}))},s),!0}#e(e,r){r.updated&&(this.peerId.equals(e)?this.events.safeDispatchEvent("self:peer:update",{detail:r}):this.events.safeDispatchEvent("peer:update",{detail:r}))}};function qm(t,e={}){return new fa(t,e)}return Lf(zm);})();
|
|
2
|
+
"use strict";var Libp2PPeerStore=(()=>{var Zo=Object.defineProperty;var kl=Object.getOwnPropertyDescriptor;var Pl=Object.getOwnPropertyNames;var Ul=Object.prototype.hasOwnProperty;var F=(t,e)=>{for(var r in e)Zo(t,r,{get:e[r],enumerable:!0})},Fl=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Pl(e))!Ul.call(t,o)&&o!==r&&Zo(t,o,{get:()=>e[o],enumerable:!(n=kl(e,o))||n.enumerable});return t};var Nl=t=>Fl(Zo({},"__esModule",{value:!0}),t);var yb={};F(yb,{persistentPeerStore:()=>mb});var M=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},zt=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var Tr=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var Dn=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},_n=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var At=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Bn=Symbol.for("@libp2p/peer-id");function Vt(t){return!!t?.[Bn]}function Kl(t){return typeof t?.handleEvent=="function"}function Ml(t){return(t!==!0&&t!==!1&&t?.once)??!1}var Ht=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){let o=Ml(n);super.addEventListener(e,i=>{if(o){let a=this.#e.get(i.type);a!=null&&(a=a.filter(({callback:c})=>c!==r),this.#e.set(i.type,a))}Kl(r)?r.handleEvent(i):r(i)},n);let s=this.#e.get(e);s==null&&(s=[],this.#e.set(e,s)),s.push({callback:r,once:o})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==r),this.#e.set(e,o))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var es={};F(es,{base58btc:()=>X,base58flickr:()=>Gl});var Eb=new Uint8Array(0);function Xa(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function We(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return Ct(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return Ct(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function Qa(t){return new TextEncoder().encode(t)}function Ja(t){return new TextDecoder().decode(t)}function ql(t){return t?.buffer instanceof ArrayBuffer}function Ct(t){return ql(t)?t:t.slice()}function zl(t,e){if(t.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<t.length;o++){var s=t.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function d(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var b=0,m=0,y=0,x=p.length;y!==x&&p[y]===0;)y++,b++;for(var w=(x-y)*f+1>>>0,C=new Uint8Array(w);y!==x;){for(var I=p[y],R=0,_=w-1;(I!==0||R<m)&&_!==-1;_--,R++)I+=256*C[_]>>>0,C[_]=I%a>>>0,I=I/a>>>0;if(I!==0)throw new Error("Non-zero carry");m=R,y++}for(var A=w-m;A!==w&&C[A]===0;)A++;for(var P=c.repeat(b);A<w;++A)P+=t.charAt(C[A]);return P}function l(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var b=0;if(p[b]!==" "){for(var m=0,y=0;p[b]===c;)m++,b++;for(var x=(p.length-b)*u+1>>>0,w=new Uint8Array(x);p[b];){var C=r[p.charCodeAt(b)];if(C===255)return;for(var I=0,R=x-1;(C!==0||I<y)&&R!==-1;R--,I++)C+=a*w[R]>>>0,w[R]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");y=I,b++}if(p[b]!==" "){for(var _=x-y;_!==x&&w[_]===0;)_++;for(var A=new Uint8Array(m+(x-_)),P=m;_!==x;)A[P++]=w[_++];return A}}}function h(p){var b=l(p);if(b)return b;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:l,decode:h}}var Vl=zl,Hl=Vl,tc=Hl;var Yo=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Xo=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,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(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return rc(this,e)}},Qo=class{decoders;constructor(e){this.decoders=e}or(e){return rc(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function rc(t,e){return new Qo({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Jo=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Yo(e,r,n),this.decoder=new Xo(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function $t({name:t,prefix:e,encode:r,decode:n}){return new Jo(t,e,r,n)}function at({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=tc(r,t);return $t({prefix:e,name:t,encode:n,decode:s=>We(o(s))})}function $l(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function jl(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Wl(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function Y({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=Wl(n);return $t({prefix:e,name:t,encode(s){return jl(s,n,r)},decode(s){return $l(s,o,r,t)}})}var X=at({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Gl=at({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ts={};F(ts,{base32:()=>Ke,base32hex:()=>Ql,base32hexpad:()=>ed,base32hexpadupper:()=>td,base32hexupper:()=>Jl,base32pad:()=>Yl,base32padupper:()=>Xl,base32upper:()=>Zl,base32z:()=>rd});var Ke=Y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Zl=Y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Yl=Y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Xl=Y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ql=Y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Jl=Y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ed=Y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),td=Y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),rd=Y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var rs={};F(rs,{base36:()=>Dr,base36upper:()=>nd});var Dr=at({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),nd=at({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var od=sc,nc=128,sd=127,id=~sd,ad=Math.pow(2,31);function sc(t,e,r){e=e||[],r=r||0;for(var n=r;t>=ad;)e[r++]=t&255|nc,t/=128;for(;t&id;)e[r++]=t&255|nc,t>>>=7;return e[r]=t|0,sc.bytes=r-n+1,e}var cd=ns,ud=128,oc=127;function ns(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw ns.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&oc)<<o:(i&oc)*Math.pow(2,o),o+=7}while(i>=ud);return ns.bytes=s-n,r}var fd=Math.pow(2,7),ld=Math.pow(2,14),dd=Math.pow(2,21),hd=Math.pow(2,28),pd=Math.pow(2,35),md=Math.pow(2,42),yd=Math.pow(2,49),bd=Math.pow(2,56),gd=Math.pow(2,63),xd=function(t){return t<fd?1:t<ld?2:t<dd?3:t<hd?4:t<pd?5:t<md?6:t<yd?7:t<bd?8:t<gd?9:10},wd={encode:od,decode:cd,encodingLength:xd},Ed=wd,_r=Ed;function Br(t,e=0){return[_r.decode(t,e),_r.decode.bytes]}function jt(t,e,r=0){return _r.encode(t,e,r),e}function Wt(t){return _r.encodingLength(t)}function Me(t,e){let r=e.byteLength,n=Wt(t),o=n+Wt(r),s=new Uint8Array(o+r);return jt(t,s,0),jt(r,s,n),s.set(e,o),new Gt(t,r,e,s)}function Zt(t){let e=We(t),[r,n]=Br(e),[o,s]=Br(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Gt(r,o,i,e)}function ic(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Xa(t.bytes,r.bytes)}}var Gt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=Ct(n),this.bytes=Ct(o)}};function ac(t,e){let{bytes:r,version:n}=t;return n===0?Sd(r,os(t),e??X.encoder):Ad(r,os(t),e??Ke.encoder)}var cc=new WeakMap;function os(t){let e=cc.get(t);if(e==null){let r=new Map;return cc.set(t,r),r}return e}var ne=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=Ct(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==Lr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Cd)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.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:e,digest:r}=this.multihash,n=Me(e,r);return t.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(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&ic(e.multihash,n.multihash)}toString(e){return ac(this,e)}toJSON(){return{"/":ac(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new t(n,o,s,i??uc(n,o,s.bytes))}else if(r[Id]===!0){let{version:n,multihash:o,code:s}=r,i=Zt(o);return t.create(n,s,i)}else return null}static create(e,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(e){case 0:{if(r!==Lr)throw new Error(`Version 0 CID must use dag-pb (code: ${Lr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=uc(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Lr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=We(e.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 Gt(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[d,l]=Br(e.subarray(r));return r+=l,d},o=n(),s=Lr;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,o]=vd(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return os(s).set(n,e),s}};function vd(t,e){switch(t[0]){case"Q":{let r=e??X;return[X.prefix,r.decode(`${X.prefix}${t}`)]}case X.prefix:{let r=e??X;return[X.prefix,r.decode(t)]}case Ke.prefix:{let r=e??Ke;return[Ke.prefix,r.decode(t)]}case Dr.prefix:{let r=e??Dr;return[Dr.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function Sd(t,e,r){let{prefix:n}=r;if(n!==X.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function Ad(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var Lr=112,Cd=18;function uc(t,e,r){let n=Wt(t),o=n+Wt(e),s=new Uint8Array(o+r.byteLength);return jt(t,s,0),jt(e,s,n),s.set(r,o),s}var Id=Symbol.for("@ipld/js-cid/CID");var ss={};F(ss,{identity:()=>Re});var fc=0,Td="identity",lc=We;function Dd(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return Me(fc,lc(t))}var Re={code:fc,name:Td,encode:lc,digest:Dd};function W(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function _d(t){return t.buffer instanceof ArrayBuffer}function Ae(t){return _d(t)?t:t.slice()}async function dc(t,e,r,n){let o=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,Ae(e),Ae(r.subarray()));return n?.signal?.throwIfAborted(),s}function Ge(t=0){return new Uint8Array(t)}function Rr(t=0){return new Uint8Array(t)}function is(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=Rr(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}function hc(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}var mc=Symbol.for("@achingbrain/uint8arraylist");function pc(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let o=r+n.byteLength;if(e<o)return{buf:n,index:e-r};r=o}throw new RangeError("index is out of bounds")}function Rn(t){return!!t?.[mc]}var me=class t{bufs;length;[mc]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Rn(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Rn(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(e){let r=pc(this.bufs,e);return r.buf[r.index]}set(e,r){let n=pc(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(Rn(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:o}=this._subList(e,r);return is(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:is(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),s=new t;return s.length=o,s.bufs=n,s}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,e>=c)continue;let u=e>=a&&e<c,f=r>a&&r<=c;if(u&&f){if(e===a&&r===c){n.push(i);break}let d=e-a;n.push(i.subarray(d,d+(r-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!Rn(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.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 d=0;d<s;d++)i[d]=-1;for(let d=0;d<o;d++)i[n[d]]=d;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let d=r;d<=c;d+=f){f=0;for(let l=u;l>=0;l--){let h=this.get(d+l);if(n[l]!==h){f=Math.max(1,l-a[h]);break}}if(f===0)return d}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=Rr(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let o=Ge(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let o=Ge(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let o=Ge(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=Rr(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let o=Ge(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let o=Ge(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let o=Ge(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let o=Ge(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let o=Ge(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!hc(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var as={};F(as,{base10:()=>Bd});var Bd=at({prefix:"9",name:"base10",alphabet:"0123456789"});var cs={};F(cs,{base16:()=>Ld,base16upper:()=>Rd});var Ld=Y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Rd=Y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var us={};F(us,{base2:()=>Od});var Od=Y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var fs={};F(fs,{base256emoji:()=>Nd});var yc=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}"),kd=yc.reduce((t,e,r)=>(t[r]=e,t),[]),Pd=yc.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Ud(t){return t.reduce((e,r)=>(e+=kd[r],e),"")}function Fd(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Pd[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Nd=$t({prefix:"\u{1F680}",name:"base256emoji",encode:Ud,decode:Fd});var ds={};F(ds,{base64:()=>Kd,base64pad:()=>Md,base64url:()=>ls,base64urlpad:()=>qd});var Kd=Y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Md=Y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ls=Y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),qd=Y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var hs={};F(hs,{base8:()=>zd});var zd=Y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ps={};F(ps,{identity:()=>Vd});var Vd=$t({prefix:"\0",name:"identity",encode:t=>Ja(t),decode:t=>Qa(t)});var cg=new TextEncoder,ug=new TextDecoder;var bs={};F(bs,{sha256:()=>Or,sha512:()=>Wd});var jd=20;function ys({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new ms(t,e,r,n,o)}var ms=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??jd,this.maxDigestLength=s}digest(e,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(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?bc(n,this.code,r?.truncate):n.then(o=>bc(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function bc(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return Me(e,t)}function xc(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Or=ys({name:"sha2-256",code:18,encode:xc("SHA-256")}),Wd=ys({name:"sha2-512",code:19,encode:xc("SHA-512")});var kr={...ps,...us,...hs,...as,...cs,...ts,...rs,...es,...ds,...fs},Eg={...bs,...ss};function De(t=0){return new Uint8Array(t)}function It(t=0){return new Uint8Array(t)}function Ec(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var wc=Ec("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),gs=Ec("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=It(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Gd={utf8:wc,"utf-8":wc,hex:kr.base16,latin1:gs,ascii:gs,binary:gs,...kr},On=Gd;function $(t,e="utf8"){let r=On[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function z(t,e="utf8"){let r=On[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var Zd=parseInt("11111",2),xs=parseInt("10000000",2),Yd=parseInt("01111111",2),vc={0:Pr,1:Pr,2:Xd,3:eh,4:th,5:Jd,6:Qd,16:Pr,22:Pr,48:Pr};function Ze(t,e={offset:0}){let r=t[e.offset]&Zd;if(e.offset++,vc[r]!=null)return vc[r](t,e);throw new Error("No decoder for tag "+r)}function Ur(t,e){let r=0;if((t[e.offset]&xs)===xs){let n=t[e.offset]&Yd,o="0x";e.offset++;for(let s=0;s<n;s++,e.offset++)o+=t[e.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=t[e.offset],e.offset++;return r}function Pr(t,e){Ur(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=Ze(t,e);if(n===null)break;r.push(n)}return r}function Xd(t,e){let r=Ur(t,e),n=e.offset,o=e.offset+r,s=[];for(let i=n;i<o;i++)i===n&&t[i]===0||s.push(t[i]);return e.offset+=r,Uint8Array.from(s)}function Qd(t,e){let r=Ur(t,e),n=e.offset+r,o=t[e.offset];e.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;e.offset<n;){let u=t[e.offset];if(e.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let d=0;d<c.length;d++)f+=c[d]<<d*7;a+=`.${f}`,c=[]}}return a}function Jd(t,e){return e.offset++,null}function eh(t,e){let r=Ur(t,e),n=t[e.offset];e.offset++;let o=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function th(t,e){let r=Ur(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function rh(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new me;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function ws(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=rh(t.byteLength);return new me(Uint8Array.from([e.byteLength|xs]),e)}function ve(t){let e=new me,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new me(Uint8Array.from([2]),ws(e),e)}function kn(t){let e=Uint8Array.from([0]),r=new me(e,t);return new me(Uint8Array.from([3]),ws(r),r)}function ut(t,e=48){let r=new me;for(let n of t)r.append(n);return new me(Uint8Array.from([e]),ws(r),r)}var nh=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),oh=Uint8Array.from([6,5,43,129,4,0,34]),sh=Uint8Array.from([6,5,43,129,4,0,35]),ih={ext:!0,kty:"EC",crv:"P-256"},ah={ext:!0,kty:"EC",crv:"P-384"},ch={ext:!0,kty:"EC",crv:"P-521"},Es=32,vs=48,Ss=66;function As(t){let e=Ze(t);return Sc(e)}function Sc(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===Es*2+1)return n=z(e.subarray(r,r+Es),"base64url"),o=z(e.subarray(r+Es),"base64url"),new Yt({...ih,key_ops:["verify"],x:n,y:o});if(e.byteLength===vs*2+1)return n=z(e.subarray(r,r+vs),"base64url"),o=z(e.subarray(r+vs),"base64url"),new Yt({...ah,key_ops:["verify"],x:n,y:o});if(e.byteLength===Ss*2+1)return n=z(e.subarray(r,r+Ss),"base64url"),o=z(e.subarray(r+Ss),"base64url"),new Yt({...ch,key_ops:["verify"],x:n,y:o});throw new M(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Ac(t){return ut([ve(Uint8Array.from([1])),ut([uh(t.crv)],160),ut([kn(new me(Uint8Array.from([4]),$(t.x??"","base64url"),$(t.y??"","base64url")))],161)]).subarray()}function uh(t){if(t==="P-256")return nh;if(t==="P-384")return oh;if(t==="P-521")return sh;throw new M(`Invalid curve ${t}`)}var Yt=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Ac(this.jwk)),this._raw}toMultihash(){return Re.digest(_e(this))}toCID(){return ne.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:W(this.raw,e.raw)}async verify(e,r,n){return dc(this.jwk,r,e,n)}};function Cs(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function ft(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(`${r}expected number, got ${typeof t}`)}if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new RangeError(`${r}expected integer >= 0, got ${t}`)}}function Ce(t,e,r=""){let n=Cs(t),o=t?.length,s=e!==void 0;if(!n||s&&o!==e){let i=r&&`"${r}" `,a=s?` of length ${e}`:"",c=n?`length=${o}`:`type=${typeof t}`,u=i+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(u):new TypeError(u)}return t}function Pn(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(ft(t.outputLen),ft(t.blockLen),t.outputLen<1)throw new Error('"outputLen" must be >= 1');if(t.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Xt(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function Un(t,e){Ce(t,void 0,"digestInto() output");let r=e.outputLen;if(t.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function Xe(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Fn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Oe(t,e){return t<<32-e|t>>>e}var Ic=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",fh=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Nn(t){if(Ce(t),Ic)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=fh[t[r]];return e}var Ye={_0:48,_9:57,A:65,F:70,a:97,f:102};function Cc(t){if(t>=Ye._0&&t<=Ye._9)return t-Ye._0;if(t>=Ye.A&&t<=Ye.F)return t-(Ye.A-10);if(t>=Ye.a&&t<=Ye.f)return t-(Ye.a-10)}function Fr(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Ic)try{return Uint8Array.fromHex(t)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=Cc(t.charCodeAt(s)),a=Cc(t.charCodeAt(s+1));if(i===void 0||a===void 0){let c=t[s]+t[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Is(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];Ce(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let s=t[n];r.set(s,o),o+=s.length}return r}function Ts(t,e={}){let r=(o,s)=>t(s).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function Tc(t=32){ft(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var Ds=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Dc(t,e,r){return t&e^~t&r}function _c(t,e,r){return t&e^t&r^e&r}var Nr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,o){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=Fn(this.buffer)}update(e){Xt(this),Ce(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Fn(e);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Xt(this),Un(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Xe(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let d=i;d<o;d++)r[d]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=Fn(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<u;d++)a.setUint32(4*d,f[d],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=s,e.length=o,e.pos=a,o%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},Qe=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var fe=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Kn=BigInt(4294967295),Bc=BigInt(32);function lh(t,e=!1){return e?{h:Number(t&Kn),l:Number(t>>Bc&Kn)}:{h:Number(t>>Bc&Kn)|0,l:Number(t&Kn)|0}}function Lc(t,e=!1){let r=t.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=lh(t[s],e);[n[s],o[s]]=[i,a]}return[n,o]}var _s=(t,e,r)=>t>>>r,Bs=(t,e,r)=>t<<32-r|e>>>r,Tt=(t,e,r)=>t>>>r|e<<32-r,Dt=(t,e,r)=>t<<32-r|e>>>r,Kr=(t,e,r)=>t<<64-r|e>>>r-32,Mr=(t,e,r)=>t>>>r-32|e<<64-r;function qe(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var Rc=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Oc=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,kc=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Pc=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,Uc=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Fc=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;var hh=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]),lt=new Uint32Array(64),Ls=class extends Nr{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[e,r,n,o,s,i,a,c]}set(e,r,n,o,s,i,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(e,r){for(let d=0;d<16;d++,r+=4)lt[d]=e.getUint32(r,!1);for(let d=16;d<64;d++){let l=lt[d-15],h=lt[d-2],p=Oe(l,7)^Oe(l,18)^l>>>3,b=Oe(h,17)^Oe(h,19)^h>>>10;lt[d]=b+lt[d-7]+p+lt[d-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let d=0;d<64;d++){let l=Oe(a,6)^Oe(a,11)^Oe(a,25),h=f+l+Dc(a,c,u)+hh[d]+lt[d]|0,b=(Oe(n,2)^Oe(n,13)^Oe(n,22))+_c(n,o,s)|0;f=u,u=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+b|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,u,f)}roundClean(){Xe(lt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Xe(this.buffer)}},Rs=class extends Ls{A=Qe[0]|0;B=Qe[1]|0;C=Qe[2]|0;D=Qe[3]|0;E=Qe[4]|0;F=Qe[5]|0;G=Qe[6]|0;H=Qe[7]|0;constructor(){super(32)}};var Nc=Lc(["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(t=>BigInt(t))),ph=Nc[0],mh=Nc[1],dt=new Uint32Array(80),ht=new Uint32Array(80),Os=class extends Nr{constructor(e){super(128,e,16,!1)}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:d,Fl:l,Gh:h,Gl:p,Hh:b,Hl:m}=this;return[e,r,n,o,s,i,a,c,u,f,d,l,h,p,b,m]}set(e,r,n,o,s,i,a,c,u,f,d,l,h,p,b,m){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=d|0,this.Fl=l|0,this.Gh=h|0,this.Gl=p|0,this.Hh=b|0,this.Hl=m|0}process(e,r){for(let w=0;w<16;w++,r+=4)dt[w]=e.getUint32(r),ht[w]=e.getUint32(r+=4);for(let w=16;w<80;w++){let C=dt[w-15]|0,I=ht[w-15]|0,R=Tt(C,I,1)^Tt(C,I,8)^_s(C,I,7),_=Dt(C,I,1)^Dt(C,I,8)^Bs(C,I,7),A=dt[w-2]|0,P=ht[w-2]|0,H=Tt(A,P,19)^Kr(A,P,61)^_s(A,P,6),U=Dt(A,P,19)^Mr(A,P,61)^Bs(A,P,6),g=kc(_,U,ht[w-7],ht[w-16]),E=Pc(g,R,H,dt[w-7],dt[w-16]);dt[w]=E|0,ht[w]=g|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:d,El:l,Fh:h,Fl:p,Gh:b,Gl:m,Hh:y,Hl:x}=this;for(let w=0;w<80;w++){let C=Tt(d,l,14)^Tt(d,l,18)^Kr(d,l,41),I=Dt(d,l,14)^Dt(d,l,18)^Mr(d,l,41),R=d&h^~d&b,_=l&p^~l&m,A=Uc(x,I,_,mh[w],ht[w]),P=Fc(A,y,C,R,ph[w],dt[w]),H=A|0,U=Tt(n,o,28)^Kr(n,o,34)^Kr(n,o,39),g=Dt(n,o,28)^Mr(n,o,34)^Mr(n,o,39),E=n&s^n&a^s&a,T=o&i^o&c^i&c;y=b|0,x=m|0,b=h|0,m=p|0,h=d|0,p=l|0,{h:d,l}=qe(u|0,f|0,P|0,H|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let S=Rc(H,g,T);n=Oc(S,P,U,E),o=S|0}({h:n,l:o}=qe(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=qe(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=qe(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=qe(this.Dh|0,this.Dl|0,u|0,f|0),{h:d,l}=qe(this.Eh|0,this.El|0,d|0,l|0),{h,l:p}=qe(this.Fh|0,this.Fl|0,h|0,p|0),{h:b,l:m}=qe(this.Gh|0,this.Gl|0,b|0,m|0),{h:y,l:x}=qe(this.Hh|0,this.Hl|0,y|0,x|0),this.set(n,o,s,i,a,c,u,f,d,l,h,p,b,m,y,x)}roundClean(){Xe(dt,ht)}destroy(){this.destroyed=!0,Xe(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},ks=class extends Os{Ah=fe[0]|0;Al=fe[1]|0;Bh=fe[2]|0;Bl=fe[3]|0;Ch=fe[4]|0;Cl=fe[5]|0;Dh=fe[6]|0;Dl=fe[7]|0;Eh=fe[8]|0;El=fe[9]|0;Fh=fe[10]|0;Fl=fe[11]|0;Gh=fe[12]|0;Gl=fe[13]|0;Hh=fe[14]|0;Hl=fe[15]|0;constructor(){super(64)}};var Qt=Ts(()=>new Rs,Ds(1));var Mn=Ts(()=>new ks,Ds(3));var q=(t,e,r)=>Ce(t,e,r),Us=ft,Jt=Nn,se=(...t)=>Is(...t),er=t=>Fr(t),_t=Cs,qr=t=>Tc(t),zn=BigInt(0),Ps=BigInt(1);function ke(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new TypeError(r+"expected boolean, got type="+typeof t)}return t}function Vn(t){if(typeof t=="bigint"){if(!qn(t))throw new RangeError("positive bigint expected, got "+t)}else Us(t);return t}function Pe(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function zr(t){let e=Vn(t).toString(16);return e.length&1?"0"+e:e}function Kc(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?zn:BigInt("0x"+t)}function Bt(t){return Kc(Nn(t))}function ze(t){return Kc(Nn(Vr(Ce(t)).reverse()))}function Hn(t,e){if(ft(e),e===0)throw new RangeError("zero length");t=Vn(t);let r=t.toString(16);if(r.length>e*2)throw new RangeError("number too large");return Fr(r.padStart(e*2,"0"))}function Fs(t,e){return Hn(t,e).reverse()}function Mc(t,e){if(t=q(t),e=q(e),t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function Vr(t){return Uint8Array.from(q(t))}function $n(t){if(typeof t!="string")throw new TypeError("ascii string expected, got "+typeof t);return Uint8Array.from(t,(e,r)=>{let n=e.charCodeAt(0);if(e.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${t[r]}" with code ${n} at position ${r}`);return n})}var qn=t=>typeof t=="bigint"&&zn<=t;function yh(t,e,r){return qn(t)&&qn(e)&&qn(r)&&e<=t&&t<r}function tr(t,e,r,n){if(!yh(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function rr(t){if(t<zn)throw new Error("expected non-negative bigint, got "+t);let e;for(e=0;t>zn;t>>=Ps,e+=1);return e}var Hr=t=>(Ps<<BigInt(t))-Ps;function qc(t,e,r){if(ft(t,"hashLen"),ft(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=m=>new Uint8Array(m),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(t),u=n(t),f=0,d=()=>{c.fill(1),u.fill(0),f=0},l=(...m)=>r(u,se(c,...m)),h=(m=o)=>{u=l(s,m),c=l(),m.length!==0&&(u=l(i,m),c=l())},p=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let m=0,y=[];for(;m<e;){c=l();let x=c.slice();y.push(x),m+=c.length}return se(...y)};return(m,y)=>{d(),h(m);let x;for(;(x=y(p()))===void 0;)h();return d(),x}}function Ue(t,e={},r={}){if(Object.prototype.toString.call(t)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,i,a){if(!a&&i!=="function"&&!Object.hasOwn(t,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let c=t[s];if(a&&c===void 0)return;let u=typeof c;if(u!==i||c===null)throw new TypeError(`param "${s}" is invalid: expected ${i}, got ${u}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(e,!1),o(r,!0)}var Ns=()=>{throw new Error("not implemented")};var le=BigInt(0),Q=BigInt(1),Lt=BigInt(2),$c=BigInt(3),jc=BigInt(4),Wc=BigInt(5),bh=BigInt(7),Gc=BigInt(8),gh=BigInt(9),Zc=BigInt(16);function re(t,e){if(e<=le)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=le?r:e+r}function j(t,e,r){if(e<le)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >le;)n*=n,n%=r;return n}function zc(t,e){if(t===le)throw new Error("invert: expected non-zero number");if(e<=le)throw new Error("invert: expected positive modulus, got "+e);let r=re(t,e),n=e,o=le,s=Q,i=Q,a=le;for(;r!==le;){let u=n/r,f=n-r*u,d=o-i*u,l=s-a*u;n=r,r=f,o=i,s=a,i=d,a=l}if(n!==Q)throw new Error("invert: does not exist");return re(o,e)}function Ks(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function Yc(t,e){let r=t,n=(r.ORDER+Q)/jc,o=r.pow(e,n);return Ks(r,o,e),o}function xh(t,e){let r=t,n=(r.ORDER-Wc)/Gc,o=r.mul(e,Lt),s=r.pow(o,n),i=r.mul(e,s),a=r.mul(r.mul(i,Lt),s),c=r.mul(i,r.sub(a,r.ONE));return Ks(r,c,e),c}function wh(t){let e=nr(t),r=Xc(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+bh)/Zc;return((a,c)=>{let u=a,f=u.pow(c,i),d=u.mul(f,n),l=u.mul(f,o),h=u.mul(f,s),p=u.eql(u.sqr(d),c),b=u.eql(u.sqr(l),c);f=u.cmov(f,d,p),d=u.cmov(h,l,b);let m=u.eql(u.sqr(d),c),y=u.cmov(f,d,m);return Ks(u,y,c),y})}function Xc(t){if(t<$c)throw new Error("sqrt is not defined for small field");let e=t-Q,r=0;for(;e%Lt===le;)e/=Lt,r++;let n=Lt,o=nr(t);for(;Vc(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Yc;let s=o.pow(n,e),i=(e+Q)/Lt;return function(c,u){let f=c;if(f.is0(u))return u;if(Vc(f,u)!==1)throw new Error("Cannot find square root");let d=r,l=f.mul(f.ONE,s),h=f.pow(u,e),p=f.pow(u,i);for(;!f.eql(h,f.ONE);){if(f.is0(h))return f.ZERO;let b=1,m=f.sqr(h);for(;!f.eql(m,f.ONE);)if(b++,m=f.sqr(m),b===d)throw new Error("Cannot find square root");let y=Q<<BigInt(d-b-1),x=f.pow(l,y);d=b,l=f.sqr(x),h=f.mul(h,l),p=f.mul(p,x)}return p}}function Eh(t){return t%jc===$c?Yc:t%Gc===Wc?xh:t%Zc===gh?wh(t):Xc(t)}var Je=(t,e)=>(re(t,e)&Q)===Q,vh=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ms(t){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=vh.reduce((n,o)=>(n[o]="function",n),e);if(Ue(t,r),Pe(t.BYTES,"BYTES"),Pe(t.BITS,"BITS"),t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=Q)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function Sh(t,e,r){let n=t;if(r<le)throw new Error("invalid exponent, negatives unsupported");if(r===le)return n.ONE;if(r===Q)return e;let o=n.ONE,s=e;for(;r>le;)r&Q&&(o=n.mul(o,s)),s=n.sqr(s),r>>=Q;return o}function $r(t,e,r=!1){let n=t,o=new Array(e.length).fill(r?n.ZERO:void 0),s=e.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return e.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),i),o}function Vc(t,e){let r=t,n=(r.ORDER-Q)/Lt,o=r.pow(e,n),s=r.eql(o,r.ONE),i=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function Ah(t,e){if(e!==void 0&&Us(e),t<=le)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=rr(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${e})`);let n=e!==void 0?e:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var Hc=new WeakMap,jn=class{ORDER;BITS;BYTES;isLE;ZERO=le;ONE=Q;_lengths;_mod;constructor(e,r={}){if(e<=Q)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=Ah(e,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(e){return re(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return le<=e&&e<this.ORDER}is0(e){return e===le}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&Q)===Q}neg(e){return re(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return re(e*e,this.ORDER)}add(e,r){return re(e+r,this.ORDER)}sub(e,r){return re(e-r,this.ORDER)}mul(e,r){return re(e*r,this.ORDER)}pow(e,r){return Sh(this,e,r)}div(e,r){return re(e*zc(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return zc(e,this.ORDER)}sqrt(e){let r=Hc.get(this);return r||Hc.set(this,r=Eh(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?Fs(e,this.BYTES):Hn(e,this.BYTES)}fromBytes(e,r=!1){q(e);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(o);u.set(e,s?0:u.length-e.length),e=u}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=s?ze(e):Bt(e);if(a&&(c=re(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return $r(this,e)}cmov(e,r,n){return ke(n,"condition"),n?r:e}};Object.freeze(jn.prototype);function nr(t,e={}){return new jn(t,e)}function Qc(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=Q)throw new Error("field order must be greater than 1");let e=rr(t-Q);return Math.ceil(e/8)}function qs(t){let e=Qc(t);return e+Math.ceil(e/2)}function zs(t,e,r=!1){q(t);let n=t.length,o=Qc(e),s=Math.max(qs(e),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?ze(t):Bt(t),a=re(i,e-Q)+Q;return r?Fs(a,o):Hn(a,o)}var or=BigInt(0),Rt=BigInt(1);function jr(t,e){let r=e.negate();return t?r:e}function Ot(t,e){let r=$r(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function ru(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Vs(t,e){ru(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),o=2**t,s=Hr(t),i=BigInt(t);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Jc(t,e,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(t&o),c=t>>i;a>n&&(a-=s,c+=Rt);let u=e*n,f=u+Math.abs(a)-1,d=a===0,l=a<0,h=e%2!==0;return{nextN:c,offset:f,isZero:d,isNeg:l,isNegF:h,offsetF:u}}var Hs=new WeakMap,nu=new WeakMap;function $s(t){return nu.get(t)||1}function eu(t){if(t!==or)throw new Error("invalid wNAF")}var sr=class{BASE;ZERO;Fn;bits;constructor(e,r){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let o=e;for(;r>or;)r&Rt&&(n=n.add(o)),o=o.double(),r>>=Rt;return n}precomputeWindow(e,r){let{windows:n,windowSize:o}=Vs(r,this.bits),s=[],i=e,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let u=1;u<o;u++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Vs(e,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:d,isNegF:l,offsetF:h}=Jc(n,a,i);n=c,f?s=s.add(jr(l,r[h])):o=o.add(jr(d,r[u]))}return eu(n),{p:o,f:s}}wNAFUnsafe(e,r,n,o=this.ZERO){let s=Vs(e,this.bits);for(let i=0;i<s.windows&&n!==or;i++){let{nextN:a,offset:c,isZero:u,isNeg:f}=Jc(n,i,s);if(n=a,!u){let d=r[c];o=o.add(f?d.negate():d)}}return eu(n),o}getPrecomputes(e,r,n){let o=Hs.get(r);return o||(o=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(o=n(o)),Hs.set(r,o))),o}cached(e,r,n){let o=$s(e);return this.wNAF(o,this.getPrecomputes(o,e,n),r)}unsafe(e,r,n,o){let s=$s(e);return s===1?this._unsafeLadder(e,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,e,n),r,o)}createCache(e,r){ru(r,this.bits),nu.set(e,r),Hs.delete(e)}hasCache(e){return $s(e)!==1}};function ou(t,e,r,n){let o=e,s=t.ZERO,i=t.ZERO;for(;r>or||n>or;)r&Rt&&(s=s.add(o)),n&Rt&&(i=i.add(o)),o=o.double(),r>>=Rt,n>>=Rt;return{p1:s,p2:i}}function tu(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Ms(e),e}else return nr(t,{isLE:r})}function Wn(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let c of["p","n","h"]){let u=e[c];if(!(typeof u=="bigint"&&u>or))throw new Error(`CURVE.${c} must be positive bigint`)}let o=tu(e.p,r.Fp,n),s=tu(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:s}}function Gn(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var pt=BigInt(0),ce=BigInt(1),js=BigInt(2),Ch=BigInt(8);function Ih(t,e,r,n){let o=t.sqr(r),s=t.sqr(n),i=t.add(t.mul(e.a,o),s),a=t.add(t.ONE,t.mul(e.d,t.mul(o,s)));return t.eql(i,a)}function su(t,e={}){let r=e,n=Wn("edwards",t,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;Ue(r,{},{uvRatio:"function"});let c=js<<BigInt(s.BYTES*8)-ce,u=b=>o.create(b),f=r.uvRatio===void 0?(b,m)=>{try{return{isValid:!0,value:o.sqrt(o.div(b,m))}}catch{return{isValid:!1,value:pt}}}:r.uvRatio;if(!Ih(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function d(b,m,y=!1){let x=y?ce:pt;return tr("coordinate "+b,m,x,c),m}function l(b){if(!(b instanceof h))throw new Error("EdwardsPoint expected")}class h{static BASE=new h(i.Gx,i.Gy,ce,u(i.Gx*i.Gy));static ZERO=new h(pt,ce,ce,pt);static Fp=o;static Fn=s;X;Y;Z;T;constructor(m,y,x,w){this.X=d("x",m),this.Y=d("y",y),this.Z=d("z",x,!0),this.T=d("t",w),Object.freeze(this)}static CURVE(){return i}static fromAffine(m){if(m instanceof h)throw new Error("extended point not allowed");let{x:y,y:x}=m||{};return d("x",y),d("y",x),new h(y,x,ce,u(y*x))}static fromBytes(m,y=!1){let x=o.BYTES,{a:w,d:C}=i;m=Vr(q(m,x,"point")),ke(y,"zip215");let I=Vr(m),R=m[x-1];I[x-1]=R&-129;let _=ze(I),A=y?c:o.ORDER;tr("point.y",_,pt,A);let P=u(_*_),H=u(P-ce),U=u(C*P-w),{isValid:g,value:E}=f(H,U);if(!g)throw new Error("bad point: invalid y coordinate");let T=(E&ce)===ce,S=(R&128)!==0;if(!y&&E===pt&&S)throw new Error("bad point: x=0 and x_0=1");return S!==T&&(E=u(-E)),h.fromAffine({x:E,y:_})}static fromHex(m,y=!1){return h.fromBytes(er(m),y)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,y=!0){return p.createCache(this,m),y||this.multiply(js),this}assertValidity(){let m=this,{a:y,d:x}=i;if(m.is0())throw new Error("bad point: ZERO");let{X:w,Y:C,Z:I,T:R}=m,_=u(w*w),A=u(C*C),P=u(I*I),H=u(P*P),U=u(_*y),g=u(P*u(U+A)),E=u(H+u(x*u(_*A)));if(g!==E)throw new Error("bad point: equation left != right (1)");let T=u(w*C),S=u(I*R);if(T!==S)throw new Error("bad point: equation left != right (2)")}equals(m){l(m);let{X:y,Y:x,Z:w}=this,{X:C,Y:I,Z:R}=m,_=u(y*R),A=u(C*w),P=u(x*R),H=u(I*w);return _===A&&P===H}is0(){return this.equals(h.ZERO)}negate(){return new h(u(-this.X),this.Y,this.Z,u(-this.T))}double(){let{a:m}=i,{X:y,Y:x,Z:w}=this,C=u(y*y),I=u(x*x),R=u(js*u(w*w)),_=u(m*C),A=y+x,P=u(u(A*A)-C-I),H=_+I,U=H-R,g=_-I,E=u(P*U),T=u(H*g),S=u(P*g),v=u(U*H);return new h(E,T,v,S)}add(m){l(m);let{a:y,d:x}=i,{X:w,Y:C,Z:I,T:R}=this,{X:_,Y:A,Z:P,T:H}=m,U=u(w*_),g=u(C*A),E=u(R*x*H),T=u(I*P),S=u((w+C)*(_+A)-U-g),v=T-E,D=T+E,L=u(g-y*U),B=u(S*v),O=u(D*L),k=u(S*L),K=u(v*D);return new h(B,O,K,k)}subtract(m){return l(m),this.add(m.negate())}multiply(m){if(!s.isValidNot0(m))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:y,f:x}=p.cached(this,m,w=>Ot(h,w));return Ot(h,[y,x])[0]}multiplyUnsafe(m){if(!s.isValid(m))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return m===pt?h.ZERO:this.is0()||m===ce?this:p.unsafe(this,m,y=>Ot(h,y))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return p.unsafe(this,i.n).is0()}toAffine(m){let y=this,x=m,{X:w,Y:C,Z:I}=y,R=y.is0();x==null&&(x=R?Ch:o.inv(I));let _=u(w*x),A=u(C*x),P=o.mul(I,x);if(R)return{x:pt,y:ce};if(P!==ce)throw new Error("invZ was invalid");return{x:_,y:A}}clearCofactor(){return a===ce?this:this.multiplyUnsafe(a)}toBytes(){let{x:m,y}=this.toAffine(),x=o.toBytes(y);return x[x.length-1]|=m&ce?128:0,x}toHex(){return Jt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let p=new sr(h,s.BITS);return s.BITS>=8&&h.BASE.precompute(8),Object.freeze(h.prototype),Object.freeze(h),h}var Zn=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(e){this.ep=e}static fromBytes(e){Ns()}static fromHex(e){Ns()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(e){return this.ep.toAffine(e)}toHex(){return Jt(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(e){return this.assertSame(e),this.init(this.ep.add(e.ep))}subtract(e){return this.assertSame(e),this.init(this.ep.subtract(e.ep))}multiply(e){return this.init(this.ep.multiply(e))}multiplyUnsafe(e){return this.init(this.ep.multiplyUnsafe(e))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(e,r){return this.ep.precompute(e,r),this}};function iu(t,e,r={}){if(typeof e!="function")throw new Error('"hash" function param is required');let n=e,o=r;Ue(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=t,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(Pe(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let d=o.randomBytes===void 0?qr:o.randomBytes,l=o.adjustScalarBytes===void 0?g=>g:o.adjustScalarBytes,h=o.domain===void 0?(g,E,T)=>{if(ke(T,"phflag"),E.length||T)throw new Error("Contexts/pre-hash are not supported");return g}:o.domain;function p(g){return c.create(ze(g))}function b(g){let E=_.secretKey;q(g,_.secretKey,"secretKey");let T=q(n(g),2*E,"hashedSecretKey"),S=l(T.slice(0,E)),v=T.slice(E,2*E),D=p(S);return{head:S,prefix:v,scalar:D}}function m(g){let{head:E,prefix:T,scalar:S}=b(g),v=i.multiply(S),D=v.toBytes();return{head:E,prefix:T,scalar:S,point:v,pointBytes:D}}function y(g){return m(g).pointBytes}function x(g=Uint8Array.of(),...E){let T=se(...E);return p(n(h(T,q(g,void 0,"context"),!!s)))}function w(g,E,T={}){g=q(g,void 0,"message"),s&&(g=s(g));let{prefix:S,scalar:v,pointBytes:D}=m(E),L=x(T.context,S,g),B=i.multiply(L).toBytes(),O=x(T.context,B,D,g),k=c.create(L+O*v);if(!c.isValid(k))throw new Error("sign failed: invalid s");let K=se(B,c.toBytes(k));return q(K,_.signature,"result")}let C={zip215:o.zip215};function I(g,E,T,S=C){let{context:v}=S,D=S.zip215===void 0?!!C.zip215:S.zip215,L=_.signature;g=q(g,L,"signature"),E=q(E,void 0,"message"),T=q(T,_.publicKey,"publicKey"),D!==void 0&&ke(D,"zip215"),s&&(E=s(E));let B=L/2,O=g.subarray(0,B),k=ze(g.subarray(B,L)),K,V,N;try{K=t.fromBytes(T,D),V=t.fromBytes(O,D),N=i.multiplyUnsafe(k)}catch{return!1}if(!D&&K.isSmallOrder())return!1;let oe=x(v,O,T,E);return V.add(K.multiplyUnsafe(oe)).subtract(N).clearCofactor().is0()}let R=a.BYTES,_={secretKey:R,publicKey:R,signature:2*R,seed:R};function A(g){return g=g===void 0?d(_.seed):g,q(g,_.seed,"seed")}function P(g){return _t(g)&&g.length===_.secretKey}function H(g,E){try{return!!t.fromBytes(g,E===void 0?C.zip215:E)}catch{return!1}}let U={getExtendedPublicKey:m,randomSecretKey:A,isValidSecretKey:P,isValidPublicKey:H,toMontgomery(g){let{y:E}=t.fromBytes(g),T=_.publicKey,S=T===32;if(!S&&T!==57)throw new Error("only defined for 25519 and 448");let v=S?a.div(ce+E,ce-E):a.div(E-ce,E+ce);return a.toBytes(v)},toMontgomerySecret(g){let E=_.secretKey;q(g,E);let T=n(g.subarray(0,E));return l(T).subarray(0,E)}};return Object.freeze(_),Object.freeze(U),Object.freeze({keygen:Gn(A,y),getPublicKey:y,sign:w,verify:I,utils:U,Point:t,lengths:_})}function Wr(t,e){if(Pe(t),Pe(e),e<0||e>4)throw new Error("invalid I2OSP length: "+e);if(t<0||t>2**(8*e)-1)throw new Error("invalid I2OSP input: "+t);let r=Array.from({length:e}).fill(0);for(let n=e-1;n>=0;n--)r[n]=t&255,t>>>=8;return new Uint8Array(r)}function Th(t,e){let r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t[n]^e[n];return r}function Dh(t){if(!_t(t)&&typeof t!="string")throw new Error("DST must be Uint8Array or ascii string");let e=typeof t=="string"?$n(t):t;if(e.length===0)throw new Error("DST must be non-empty");return e}function Ws(t,e,r,n){q(t),Pe(r),e=Dh(e),e.length>255&&(e=n(se($n("H2C-OVERSIZE-DST-"),e)));let{outputLen:o,blockLen:s}=n,i=Math.ceil(r/o);if(r>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=se(e,Wr(e.length,1)),c=new Uint8Array(s),u=Wr(r,2),f=new Array(i),d=n(se(c,t,u,Wr(0,1),a));f[0]=n(se(d,Wr(1,1),a));for(let h=1;h<i;h++){let p=[Th(d,f[h-1]),Wr(h+1,1),a];f[h]=n(se(...p))}return se(...f).slice(0,r)}var au="HashToScalar-";var _h=BigInt(0),et=BigInt(1),cu=BigInt(2);var Bh=BigInt(5),Lh=BigInt(8),ir=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Xs={p:ir,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Lh,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Rh(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=ir,a=t*t%s*t%s,c=j(a,cu,s)*a%s,u=j(c,et,s)*t%s,f=j(u,Bh,s)*u%s,d=j(f,e,s)*f%s,l=j(d,r,s)*d%s,h=j(l,n,s)*l%s,p=j(h,o,s)*h%s,b=j(p,o,s)*h%s,m=j(b,e,s)*f%s;return{pow_p_5_8:j(m,cu,s)*t%s,b2:a}}function Oh(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var Gs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Qs(t,e){let r=ir,n=re(e*e*e,r),o=re(n*n*e,r),s=Rh(t*o).pow_p_5_8,i=re(t*n*s,r),a=re(e*i*i,r),c=i,u=re(i*Gs,r),f=a===t,d=a===re(-t,r),l=a===re(-t*Gs,r);return f&&(i=c),(d||l)&&(i=u),Je(i,r)&&(i=re(-i,r)),{isValid:f||d,value:i}}var yt=su(Xs,{uvRatio:Qs}),mt=yt.Fp,lu=yt.Fn;function kh(t){return iu(yt,Mn,Object.assign({adjustScalarBytes:Oh,zip215:!0},t))}var du=kh({});var Zs=Gs,Ph=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Uh=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Fh=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Nh=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),uu=t=>Qs(et,t),Kh=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Ys=t=>mt.create(ze(t)&Kh);function fu(t){let{d:e}=Xs,r=ir,n=y=>mt.create(y),o=n(Zs*t*t),s=n((o+et)*Fh),i=BigInt(-1),a=n((i-e*o)*n(o+e)),{isValid:c,value:u}=Qs(s,a),f=n(u*t);Je(f,r)||(f=n(-f)),c||(u=f),c||(i=o);let d=n(i*(o-et)*Nh-a),l=u*u,h=n((u+u)*a),p=n(d*Ph),b=n(et-l),m=n(et+l);return new yt(n(h*m),n(b*p),n(p*m),n(h*b))}var bt=class t extends Zn{static BASE=new t(yt.BASE);static ZERO=new t(yt.ZERO);static Fp=mt;static Fn=lu;constructor(e){super(e)}static fromAffine(e){return new t(yt.fromAffine(e))}assertSame(e){if(!(e instanceof t))throw new Error("RistrettoPoint expected")}init(e){return new t(e)}static fromBytes(e){Ce(e,32);let{a:r,d:n}=Xs,o=ir,s=C=>mt.create(C),i=Ys(e);if(!Mc(mt.toBytes(i),e)||Je(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(et+r*a),u=s(et-r*a),f=s(c*c),d=s(u*u),l=s(r*n*f-d),{isValid:h,value:p}=uu(s(l*d)),b=s(p*u),m=s(p*b*l),y=s((i+i)*b);Je(y,o)&&(y=s(-y));let x=s(c*m),w=s(y*x);if(!h||Je(w,o)||x===_h)throw new Error("invalid ristretto255 encoding 2");return new t(new yt(y,x,et,w))}static fromHex(e){return t.fromBytes(Fr(e))}toBytes(){let{X:e,Y:r,Z:n,T:o}=this.ep,s=ir,i=m=>mt.create(m),a=i(i(n+r)*i(n-r)),c=i(e*r),u=i(c*c),{value:f}=uu(i(a*u)),d=i(f*a),l=i(f*c),h=i(d*l*o),p;if(Je(o*h,s)){let m=i(r*Zs),y=i(e*Zs);e=m,r=y,p=i(d*Uh)}else p=l;Je(e*h,s)&&(r=i(-r));let b=i((n-r)*p);return Je(b,s)&&(b=i(-b)),mt.toBytes(b)}equals(e){this.assertSame(e);let{X:r,Y:n}=this.ep,{X:o,Y:s}=e.ep,i=u=>mt.create(u),a=i(r*s)===i(n*o),c=i(n*s)===i(r*o);return a||c}is0(){return this.equals(t.ZERO)}};Object.freeze(bt.BASE);Object.freeze(bt.ZERO);Object.freeze(bt.prototype);Object.freeze(bt);var Mh=Object.freeze({Point:bt,hashToCurve(t,e){let r=e?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":e.DST,n=Ws(t,r,64,Mn);return Mh.deriveToCurve(n)},hashToScalar(t,e={DST:au}){let r=Ws(t,e.DST,64,Mn);return lu.create(ze(r))},deriveToCurve(t){Ce(t,64);let e=Ys(t.subarray(0,32)),r=fu(e),n=Ys(t.subarray(32,64)),o=fu(n);return new bt(r.add(o))}});var Gr=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},Yn=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var Be={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new Yn("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 e}};var Xn=32;var Js,qh=(async()=>{try{return await Be.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function zh(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await Be.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await Be.get().subtle.verify({name:"Ed25519"},n,Ae(e),Ae(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Vh(t,e,r){return du.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function hu(t,e,r){return Js==null&&(Js=await qh),Js?zh(t,e,r):Vh(t,e,r)}function Hh(t){return t?.buffer instanceof ArrayBuffer}function ei(t){if(Hh(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function kt(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=It(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return ei(r)}function Qn(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Jn=class{type="Ed25519";raw;constructor(e){this.raw=ti(e,Xn)}toMultihash(){return Re.digest(_e(this))}toCID(){return ne.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:W(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let o=hu(this.raw,r,e);return Qn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function ri(t){return t=ti(t,Xn),new Jn(t)}function ti(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new M(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}function gt(t=0){return new Uint8Array(t)}var jh=Math.pow(2,7),Wh=Math.pow(2,14),Gh=Math.pow(2,21),mu=Math.pow(2,28),yu=Math.pow(2,35),bu=Math.pow(2,42),gu=Math.pow(2,49),ye=128,xt=127;function Zr(t){if(t<jh)return 1;if(t<Wh)return 2;if(t<Gh)return 3;if(t<mu)return 4;if(t<yu)return 5;if(t<bu)return 6;if(t<gu)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function xu(t,e,r=0){switch(Zr(t)){case 8:e[r++]=t&255|ye,t/=128;case 7:e[r++]=t&255|ye,t/=128;case 6:e[r++]=t&255|ye,t/=128;case 5:e[r++]=t&255|ye,t/=128;case 4:e[r++]=t&255|ye,t>>>=7;case 3:e[r++]=t&255|ye,t>>>=7;case 2:e[r++]=t&255|ye,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function wu(t,e){let r=t[e],n=0;if(n+=r&xt,r<ye||(r=t[e+1],n+=(r&xt)<<7,r<ye)||(r=t[e+2],n+=(r&xt)<<14,r<ye)||(r=t[e+3],n+=(r&xt)<<21,r<ye)||(r=t[e+4],n+=(r&xt)*mu,r<ye)||(r=t[e+5],n+=(r&xt)*yu,r<ye)||(r=t[e+6],n+=(r&xt)*bu,r<ye)||(r=t[e+7],n+=(r&xt)*gu,r<ye))return n;throw new RangeError("Could not decode varint")}var ni=new Float32Array([-0]),wt=new Uint8Array(ni.buffer);function Eu(t,e,r){ni[0]=t,e[r]=wt[0],e[r+1]=wt[1],e[r+2]=wt[2],e[r+3]=wt[3]}function vu(t,e){return wt[0]=t[e],wt[1]=t[e+1],wt[2]=t[e+2],wt[3]=t[e+3],ni[0]}var oi=new Float64Array([-0]),he=new Uint8Array(oi.buffer);function Su(t,e,r){oi[0]=t,e[r]=he[0],e[r+1]=he[1],e[r+2]=he[2],e[r+3]=he[3],e[r+4]=he[4],e[r+5]=he[5],e[r+6]=he[6],e[r+7]=he[7]}function Au(t,e){return he[0]=t[e],he[1]=t[e+1],he[2]=t[e+2],he[3]=t[e+3],he[4]=t[e+4],he[5]=t[e+5],he[6]=t[e+6],he[7]=t[e+7],oi[0]}var Zh=BigInt(Number.MAX_SAFE_INTEGER),Yh=BigInt(Number.MIN_SAFE_INTEGER),Ie=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&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(e=!1){if(e)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(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Pt;if(e<Zh&&e>Yh)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,o=e-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Cu&&(o=0n,++n>Cu&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return Pt;let r=e<0;r&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new t(n,o)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):Pt}},Pt=new Ie(0,0);Pt.toBigInt=function(){return 0n};Pt.zzEncode=Pt.zzDecode=function(){return this};Pt.length=function(){return 1};var Cu=4294967296n;function Iu(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function Tu(t,e,r){if(r-e<1)return"";let o,s=[],i=0,a;for(;e<r;)a=t[e++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&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 si(t,e,r){let n=r,o,s;for(let i=0;i<t.length;++i)o=t.charCodeAt(i),o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&((s=t.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128);return r-n}function Fe(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function eo(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var ii=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Fe(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Fe(this,4);return eo(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Fe(this,4);return eo(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Fe(this,4);let e=vu(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Fe(this,4);let e=Au(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw Fe(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Tu(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Fe(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Fe(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Ie(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Fe(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw Fe(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Fe(this,8);let e=eo(this.buf,this.pos+=4),r=eo(this.buf,this.pos+=4);return new Ie(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=wu(this.buf,this.pos);return this.pos+=Zr(e),e}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 Yr(t){return new ii(t instanceof Uint8Array?t:t.subarray())}function be(t,e,r){let n=Yr(t);return e.decode(n,void 0,r)}var li={};F(li,{base10:()=>np});var hw=new Uint8Array(0);function _u(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function tt(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function Bu(t){return new TextEncoder().encode(t)}function Lu(t){return new TextDecoder().decode(t)}function Xh(t,e){if(t.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<t.length;o++){var s=t.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function d(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var b=0,m=0,y=0,x=p.length;y!==x&&p[y]===0;)y++,b++;for(var w=(x-y)*f+1>>>0,C=new Uint8Array(w);y!==x;){for(var I=p[y],R=0,_=w-1;(I!==0||R<m)&&_!==-1;_--,R++)I+=256*C[_]>>>0,C[_]=I%a>>>0,I=I/a>>>0;if(I!==0)throw new Error("Non-zero carry");m=R,y++}for(var A=w-m;A!==w&&C[A]===0;)A++;for(var P=c.repeat(b);A<w;++A)P+=t.charAt(C[A]);return P}function l(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var b=0;if(p[b]!==" "){for(var m=0,y=0;p[b]===c;)m++,b++;for(var x=(p.length-b)*u+1>>>0,w=new Uint8Array(x);p[b];){var C=r[p.charCodeAt(b)];if(C===255)return;for(var I=0,R=x-1;(C!==0||I<y)&&R!==-1;R--,I++)C+=a*w[R]>>>0,w[R]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");y=I,b++}if(p[b]!==" "){for(var _=x-y;_!==x&&w[_]===0;)_++;for(var A=new Uint8Array(m+(x-_)),P=m;_!==x;)A[P++]=w[_++];return A}}}function h(p){var b=l(p);if(b)return b;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:l,decode:h}}var Qh=Xh,Jh=Qh,Ou=Jh;var ai=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},ci=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,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(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return ku(this,e)}},ui=class{decoders;constructor(e){this.decoders=e}or(e){return ku(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ku(t,e){return new ui({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var fi=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new ai(e,r,n),this.decoder=new ci(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ar({name:t,prefix:e,encode:r,decode:n}){return new fi(t,e,r,n)}function Et({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=Ou(r,t);return ar({prefix:e,name:t,encode:n,decode:s=>tt(o(s))})}function ep(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function tp(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function rp(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function J({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=rp(n);return ar({prefix:e,name:t,encode(s){return tp(s,n,r)},decode(s){return ep(s,o,r,t)}})}var np=Et({prefix:"9",name:"base10",alphabet:"0123456789"});var di={};F(di,{base16:()=>op,base16upper:()=>sp});var op=J({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),sp=J({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var hi={};F(hi,{base2:()=>ip});var ip=J({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var pi={};F(pi,{base256emoji:()=>lp});var Pu=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}"),ap=Pu.reduce((t,e,r)=>(t[r]=e,t),[]),cp=Pu.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function up(t){return t.reduce((e,r)=>(e+=ap[r],e),"")}function fp(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=cp[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var lp=ar({prefix:"\u{1F680}",name:"base256emoji",encode:up,decode:fp});var mi={};F(mi,{base32:()=>cr,base32hex:()=>mp,base32hexpad:()=>bp,base32hexpadupper:()=>gp,base32hexupper:()=>yp,base32pad:()=>hp,base32padupper:()=>pp,base32upper:()=>dp,base32z:()=>xp});var cr=J({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),dp=J({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),hp=J({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),pp=J({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),mp=J({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),yp=J({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),bp=J({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),gp=J({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),xp=J({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var yi={};F(yi,{base36:()=>Xr,base36upper:()=>wp});var Xr=Et({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),wp=Et({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var bi={};F(bi,{base58btc:()=>Ve,base58flickr:()=>Ep});var Ve=Et({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ep=Et({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var gi={};F(gi,{base64:()=>vp,base64pad:()=>Sp,base64url:()=>Ap,base64urlpad:()=>Cp});var vp=J({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Sp=J({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ap=J({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Cp=J({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var xi={};F(xi,{base8:()=>Ip});var Ip=J({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var wi={};F(wi,{identity:()=>Tp});var Tp=ar({prefix:"\0",name:"identity",encode:t=>Lu(t),decode:t=>Bu(t)});var _w=new TextEncoder,Bw=new TextDecoder;var vi={};F(vi,{identity:()=>Yp});var Bp=Nu,Uu=128,Lp=127,Rp=~Lp,Op=Math.pow(2,31);function Nu(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Op;)e[r++]=t&255|Uu,t/=128;for(;t&Rp;)e[r++]=t&255|Uu,t>>>=7;return e[r]=t|0,Nu.bytes=r-n+1,e}var kp=Ei,Pp=128,Fu=127;function Ei(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw Ei.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&Fu)<<o:(i&Fu)*Math.pow(2,o),o+=7}while(i>=Pp);return Ei.bytes=s-n,r}var Up=Math.pow(2,7),Fp=Math.pow(2,14),Np=Math.pow(2,21),Kp=Math.pow(2,28),Mp=Math.pow(2,35),qp=Math.pow(2,42),zp=Math.pow(2,49),Vp=Math.pow(2,56),Hp=Math.pow(2,63),$p=function(t){return t<Up?1:t<Fp?2:t<Np?3:t<Kp?4:t<Mp?5:t<qp?6:t<zp?7:t<Vp?8:t<Hp?9:10},jp={encode:Bp,decode:kp,encodingLength:$p},Wp=jp,Qr=Wp;function Jr(t,e=0){return[Qr.decode(t,e),Qr.decode.bytes]}function ur(t,e,r=0){return Qr.encode(t,e,r),e}function fr(t){return Qr.encodingLength(t)}function dr(t,e){let r=e.byteLength,n=fr(t),o=n+fr(r),s=new Uint8Array(o+r);return ur(t,s,0),ur(r,s,n),s.set(e,o),new lr(t,r,e,s)}function Ku(t){let e=tt(t),[r,n]=Jr(e),[o,s]=Jr(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new lr(r,o,i,e)}function Mu(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&_u(t.bytes,r.bytes)}}var lr=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};var qu=0,Gp="identity",zu=tt;function Zp(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return dr(qu,zu(t))}var Yp={code:qu,name:Gp,encode:zu,digest:Zp};var Ci={};F(Ci,{sha256:()=>Qp,sha512:()=>Jp});var Xp=20;function Ai({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new Si(t,e,r,n,o)}var Si=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Xp,this.maxDigestLength=s}digest(e,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(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?Vu(n,this.code,r?.truncate):n.then(o=>Vu(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Vu(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return dr(e,t)}function $u(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Qp=Ai({name:"sha2-256",code:18,encode:$u("SHA-256")}),Jp=Ai({name:"sha2-512",code:19,encode:$u("SHA-512")});function ju(t,e){let{bytes:r,version:n}=t;return n===0?tm(r,Ii(t),e??Ve.encoder):rm(r,Ii(t),e??cr.encoder)}var Wu=new WeakMap;function Ii(t){let e=Wu.get(t);if(e==null){let r=new Map;return Wu.set(t,r),r}return e}var ro=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,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:e,multihash:r}=this;if(e!==tn)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==nm)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.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:e,digest:r}=this.multihash,n=dr(e,r);return t.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(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&Mu(e.multihash,n.multihash)}toString(e){return ju(this,e)}toJSON(){return{"/":ju(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new t(n,o,s,i??Gu(n,o,s.bytes))}else if(r[om]===!0){let{version:n,multihash:o,code:s}=r,i=Ku(o);return t.create(n,s,i)}else return null}static create(e,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(e){case 0:{if(r!==tn)throw new Error(`Version 0 CID must use dag-pb (code: ${tn}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=Gu(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,tn,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=tt(e.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 lr(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[d,l]=Jr(e.subarray(r));return r+=l,d},o=n(),s=tn;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,o]=em(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ii(s).set(n,e),s}};function em(t,e){switch(t[0]){case"Q":{let r=e??Ve;return[Ve.prefix,r.decode(`${Ve.prefix}${t}`)]}case Ve.prefix:{let r=e??Ve;return[Ve.prefix,r.decode(t)]}case cr.prefix:{let r=e??cr;return[cr.prefix,r.decode(t)]}case Xr.prefix:{let r=e??Xr;return[Xr.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function tm(t,e,r){let{prefix:n}=r;if(n!==Ve.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function rm(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var tn=112,nm=18;function Gu(t,e,r){let n=fr(t),o=n+fr(e),s=new Uint8Array(o+r.byteLength);return ur(t,s,0),ur(e,s,n),s.set(r,o),s}var om=Symbol.for("@ipld/js-cid/CID");var Ti={...wi,...hi,...xi,...li,...di,...mi,...yi,...bi,...gi,...pi},Qw={...Ci,...vi};function Yu(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Zu=Yu("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Di=Yu("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=gt(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),sm={utf8:Zu,"utf-8":Zu,hex:Ti.base16,latin1:Di,ascii:Di,binary:Di,...Ti},Xu=sm;function Qu(t,e="utf8"){let r=Xu[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function _i(t){let e=t??8192,r=e>>>1,n,o=e;return function(i){if(i<1||i>r)return gt(i);o+i>e&&(n=gt(e),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Ut=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Bi(){}var Ri=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},im=_i();function am(t){return globalThis.Buffer!=null?gt(t):im(t)}var nn=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ut(Bi,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Ut(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Oi((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(no,10,Ie.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Ie.fromBigInt(e);return this._push(no,r.length(),r)}uint64Number(e){return this._push(xu,Zr(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=Ie.fromBigInt(e).zzEncode();return this._push(no,r.length(),r)}sint64Number(e){let r=Ie.fromNumber(e).zzEncode();return this._push(no,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Li,1,e?1:0)}fixed32(e){return this._push(rn,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Ie.fromBigInt(e);return this._push(rn,4,r.lo)._push(rn,4,r.hi)}fixed64Number(e){let r=Ie.fromNumber(e);return this._push(rn,4,r.lo)._push(rn,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(Eu,4,e)}double(e){return this._push(Su,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Li,1,0):this.uint32(r)._push(um,r,e)}string(e){let r=Iu(e);return r!==0?this.uint32(r)._push(si,r,e):this._push(Li,1,0)}fork(){return this.states=new Ri(this),this.head=this.tail=new Ut(Bi,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 Ut(Bi,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=am(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Li(t,e,r){e[r]=t&255}function cm(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var Oi=class extends Ut{next;constructor(e,r){super(cm,e,r),this.next=void 0}};function no(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function rn(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function um(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(nn.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(fm,e,t),this},nn.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(lm,e,t),this});function fm(t,e,r){e.set(t,r)}function lm(t,e,r){t.length<40?si(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(Qu(t),r)}function ki(){return new nn}function ge(t,e){let r=ki();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*xe(t,e,r){let n=Yr(t);yield*e.stream(n,void 0,"$",r)}var oo={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function so(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function Pi(t){function e(s){if(t[s.toString()]==null)throw new Error("Invalid enum value");return t[s]}let r=function(i,a){let c=e(i);a.int32(c)},n=function(i){let a=i.int32();return e(a)},o=function*(i){let a=i.int32();yield e(a)};return so("enum",oo.VARINT,r,n,o)}function we(t,e,r){return so("message",oo.LENGTH_DELIMITED,t,e,r)}var Le=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},on=class extends Error{code="ERR_MAX_SIZE";name="MaxSizeError"};var G;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(G||(G={}));var Ui;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(Ui||(Ui={}));(function(t){t.codec=()=>Pi(Ui)})(G||(G={}));var He;(function(t){let e;t.codec=()=>(e==null&&(e=we((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),G.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=G.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:G.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ge(s,t.codec())}t.encode=r;function n(s,i){return be(s,t.codec(),i)}t.decode=n;function o(s,i){return xe(s,t.codec(),i)}t.stream=o})(He||(He={}));var Fi;(function(t){let e;t.codec=()=>(e==null&&(e=we((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),G.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=G.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:G.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ge(s,t.codec())}t.encode=r;function n(s,i){return be(s,t.codec(),i)}t.decode=n;function o(s,i){return xe(s,t.codec(),i)}t.stream=o})(Fi||(Fi={}));var an={};F(an,{MAX_RSA_KEY_SIZE:()=>Ni,generateRSAKeyPair:()=>nf,jwkToJWKKeyPair:()=>of,jwkToPkcs1:()=>mm,jwkToPkix:()=>zi,jwkToRSAPrivateKey:()=>ji,pkcs1MessageToJwk:()=>Mi,pkcs1MessageToRSAPrivateKey:()=>Vi,pkcs1ToJwk:()=>pm,pkcs1ToRSAPrivateKey:()=>rf,pkixMessageToJwk:()=>qi,pkixMessageToRSAPublicKey:()=>$i,pkixToJwk:()=>ym,pkixToRSAPublicKey:()=>Hi});var hr=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=an.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ne.createV1(114,this._multihash)}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:W(this.raw,e.raw)}verify(e,r,n){return tf(this.jwk,r,e,n)}},sn=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=an.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:W(this.raw,e.raw)}sign(e,r){return ef(this.jwk,e,r)}};var Ni=8192,Ki=18,dm=1062,hm=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function pm(t){let e=Ze(t);return Mi(e)}function Mi(t){return{n:z(t[1],"base64url"),e:z(t[2],"base64url"),d:z(t[3],"base64url"),p:z(t[4],"base64url"),q:z(t[5],"base64url"),dp:z(t[6],"base64url"),dq:z(t[7],"base64url"),qi:z(t[8],"base64url"),kty:"RSA"}}function mm(t){if(t.n==null||t.e==null||t.d==null||t.p==null||t.q==null||t.dp==null||t.dq==null||t.qi==null)throw new M("JWK was missing components");return ut([ve(Uint8Array.from([0])),ve($(t.n,"base64url")),ve($(t.e,"base64url")),ve($(t.d,"base64url")),ve($(t.p,"base64url")),ve($(t.q,"base64url")),ve($(t.dp,"base64url")),ve($(t.dq,"base64url")),ve($(t.qi,"base64url"))]).subarray()}function ym(t){let e=Ze(t,{offset:0});return qi(e)}function qi(t){let e=Ze(t[1],{offset:0});return{kty:"RSA",n:z(e[0],"base64url"),e:z(e[1],"base64url")}}function zi(t){if(t.n==null||t.e==null)throw new M("JWK was missing components");return ut([hm,kn(ut([ve($(t.n,"base64url")),ve($(t.e,"base64url"))]))]).subarray()}function rf(t){let e=Ze(t);return Vi(e)}function Vi(t){let e=Mi(t);return ji(e)}function Hi(t,e){if(t.byteLength>=dm)throw new zt("Key size is too large");let r=Ze(t,{offset:0});return $i(r,t,e)}function $i(t,e,r){let n=qi(t);if(r==null){let o=Qt(He.encode({Type:G.RSA,Data:e}));r=Me(Ki,o)}return new hr(n,r)}function ji(t){if(af(t)>Ni)throw new M("Key size is too large");let e=of(t),r=Qt(He.encode({Type:G.RSA,Data:zi(e.publicKey)})),n=Me(Ki,r);return new sn(e.privateKey,new hr(e.publicKey,n))}async function nf(t){if(t>Ni)throw new M("Key size is too large");let e=await sf(t),r=Qt(He.encode({Type:G.RSA,Data:zi(e.publicKey)})),n=Me(Ki,r);return new sn(e.privateKey,new hr(e.publicKey,n))}function of(t){if(t==null)throw new M("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function sf(t,e){let r=await Be.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:t,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await bm(r,e);return{privateKey:n[0],publicKey:n[1]}}async function ef(t,e,r){let n=await Be.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Be.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,Ae(e instanceof Uint8Array?e:e.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function tf(t,e,r,n){let o=await Be.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Be.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,Ae(e),Ae(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),s}async function bm(t,e){if(t.privateKey==null||t.publicKey==null)throw new M("Private and public key are required");let r=await Promise.all([Be.get().subtle.exportKey("jwk",t.privateKey),Be.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function af(t){if(t.kty!=="RSA")throw new M("invalid key type");if(t.n==null)throw new M("invalid key modulus");return $(t.n,"base64url").length*8}var io=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(Pn(e),Ce(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Xe(o)}update(e){return Xt(this),this.iHash.update(e),this}digestInto(e){Xt(this),Un(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},cf=(()=>{let t=((e,r,n)=>new io(e,r).update(n).digest());return t.create=(e,r)=>new io(e,r),t})();var uf=(t,e)=>(t+(t>=0?e:-e)/ff)/e;function gm(t,e,r){tr("scalar",t,$e,r);let[[n,o],[s,i]]=e,a=uf(i*t,r),c=uf(-o*t,r),u=t-a*n-c*s,f=-a*o-c*i,d=u<$e,l=f<$e;d&&(u=-u),l&&(f=-f);let h=Hr(Math.ceil(rr(r)/2))+vt;if(u<$e||u>=h||f<$e||f>=h)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:d,k1:u,k2neg:l,k2:f}}function Gi(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Wi(t,e){Ue(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return ke(r.lowS,"lowS"),ke(r.prehash,"prehash"),r.format!==void 0&&Gi(r.format),r}var Zi=class extends Error{constructor(e=""){super(e)}},Ne={Err:Zi,_tlv:{encode:(t,e)=>{let{Err:r}=Ne;if(Pe(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(typeof e!="string")throw new TypeError('"data" expected string, got type='+typeof e);if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=zr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?zr(o.length/2|128):"";return zr(t)+s+o+e},decode(t,e){let{Err:r}=Ne;e=q(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=Ne;if(Vn(t),t<$e)throw new e("integer: negative integers are not allowed");let r=zr(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=Ne;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return Bt(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=Ne,o=q(t,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:u,l:f}=n.decode(2,c);if(f.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(t){let{_tlv:e,_int:r}=Ne,n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),s=n+o;return e.encode(48,s)}};Object.freeze(Ne._tlv);Object.freeze(Ne._int);Object.freeze(Ne);var $e=BigInt(0),vt=BigInt(1),ff=BigInt(2),ao=BigInt(3),xm=BigInt(4);function lf(t,e={}){let r=Wn("weierstrass",t,e),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;Ue(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c,allowInfinityPoint:u}=e;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=hf(n,o);function d(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(U,g,E){if(u&&g.is0())return Uint8Array.of(0);let{x:T,y:S}=g.toAffine(),v=n.toBytes(T);if(ke(E,"isCompressed"),E){d();let D=!n.isOdd(S);return se(df(D),v)}else return se(Uint8Array.of(4),v,n.toBytes(S))}function h(U){q(U,void 0,"Point");let{publicKey:g,publicKeyUncompressed:E}=f,T=U.length,S=U[0],v=U.subarray(1);if(u&&T===1&&S===0)return{x:n.ZERO,y:n.ZERO};if(T===g&&(S===2||S===3)){let D=n.fromBytes(v);if(!n.isValid(D))throw new Error("bad point: is not on curve, wrong x");let L=m(D),B;try{B=n.sqrt(L)}catch(K){let V=K instanceof Error?": "+K.message:"";throw new Error("bad point: is not on curve, sqrt error"+V)}d();let O=n.isOdd(B);return(S&1)===1!==O&&(B=n.neg(B)),{x:D,y:B}}else if(T===E&&S===4){let D=n.BYTES,L=n.fromBytes(v.subarray(0,D)),B=n.fromBytes(v.subarray(D,D*2));if(!y(L,B))throw new Error("bad point: is not on curve");return{x:L,y:B}}else throw new Error(`bad point: got length ${T}, expected compressed=${g} or uncompressed=${E}`)}let p=e.toBytes===void 0?l:e.toBytes,b=e.fromBytes===void 0?h:e.fromBytes;function m(U){let g=n.sqr(U),E=n.mul(g,U);return n.add(n.add(E,n.mul(U,s.a)),s.b)}function y(U,g){let E=n.sqr(g),T=m(U);return n.eql(E,T)}if(!y(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let x=n.mul(n.pow(s.a,ao),xm),w=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(x,w)))throw new Error("bad curve params: a or b");function C(U,g,E=!1){if(!n.isValid(g)||E&&n.is0(g))throw new Error(`bad point coordinate ${U}`);return g}function I(U){if(!(U instanceof A))throw new Error("Weierstrass Point expected")}function R(U){if(!c||!c.basises)throw new Error("no endo");return gm(U,c.basises,o.ORDER)}function _(U,g,E,T,S){return E=new A(n.mul(E.X,U),E.Y,E.Z),g=jr(T,g),E=jr(S,E),g.add(E)}class A{static BASE=new A(s.Gx,s.Gy,n.ONE);static ZERO=new A(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(g,E,T){this.X=C("x",g),this.Y=C("y",E,!0),this.Z=C("z",T),Object.freeze(this)}static CURVE(){return s}static fromAffine(g){let{x:E,y:T}=g||{};if(!g||!n.isValid(E)||!n.isValid(T))throw new Error("invalid affine point");if(g instanceof A)throw new Error("projective point not allowed");return n.is0(E)&&n.is0(T)?A.ZERO:new A(E,T,n.ONE)}static fromBytes(g){let E=A.fromAffine(b(q(g,void 0,"point")));return E.assertValidity(),E}static fromHex(g){return A.fromBytes(er(g))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,E=!0){return H.createCache(this,g),E||this.multiply(ao),this}assertValidity(){let g=this;if(g.is0()){if(e.allowInfinityPoint&&n.is0(g.X)&&n.eql(g.Y,n.ONE)&&n.is0(g.Z))return;throw new Error("bad point: ZERO")}let{x:E,y:T}=g.toAffine();if(!n.isValid(E)||!n.isValid(T))throw new Error("bad point: x or y not field elements");if(!y(E,T))throw new Error("bad point: equation left != right");if(!g.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:g}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(g)}equals(g){I(g);let{X:E,Y:T,Z:S}=this,{X:v,Y:D,Z:L}=g,B=n.eql(n.mul(E,L),n.mul(v,S)),O=n.eql(n.mul(T,L),n.mul(D,S));return B&&O}negate(){return new A(this.X,n.neg(this.Y),this.Z)}double(){let{a:g,b:E}=s,T=n.mul(E,ao),{X:S,Y:v,Z:D}=this,L=n.ZERO,B=n.ZERO,O=n.ZERO,k=n.mul(S,S),K=n.mul(v,v),V=n.mul(D,D),N=n.mul(S,v);return N=n.add(N,N),O=n.mul(S,D),O=n.add(O,O),L=n.mul(g,O),B=n.mul(T,V),B=n.add(L,B),L=n.sub(K,B),B=n.add(K,B),B=n.mul(L,B),L=n.mul(N,L),O=n.mul(T,O),V=n.mul(g,V),N=n.sub(k,V),N=n.mul(g,N),N=n.add(N,O),O=n.add(k,k),k=n.add(O,k),k=n.add(k,V),k=n.mul(k,N),B=n.add(B,k),V=n.mul(v,D),V=n.add(V,V),k=n.mul(V,N),L=n.sub(L,k),O=n.mul(V,K),O=n.add(O,O),O=n.add(O,O),new A(L,B,O)}add(g){I(g);let{X:E,Y:T,Z:S}=this,{X:v,Y:D,Z:L}=g,B=n.ZERO,O=n.ZERO,k=n.ZERO,K=s.a,V=n.mul(s.b,ao),N=n.mul(E,v),oe=n.mul(T,D),ie=n.mul(S,L),ae=n.add(E,T),te=n.add(v,D);ae=n.mul(ae,te),te=n.add(N,oe),ae=n.sub(ae,te),te=n.add(E,S);let Ee=n.add(v,L);return te=n.mul(te,Ee),Ee=n.add(N,ie),te=n.sub(te,Ee),Ee=n.add(T,S),B=n.add(D,L),Ee=n.mul(Ee,B),B=n.add(oe,ie),Ee=n.sub(Ee,B),k=n.mul(K,te),B=n.mul(V,ie),k=n.add(B,k),B=n.sub(oe,k),k=n.add(oe,k),O=n.mul(B,k),oe=n.add(N,N),oe=n.add(oe,N),ie=n.mul(K,ie),te=n.mul(V,te),oe=n.add(oe,ie),ie=n.sub(N,ie),ie=n.mul(K,ie),te=n.add(te,ie),N=n.mul(oe,te),O=n.add(O,N),N=n.mul(Ee,te),B=n.mul(ae,B),B=n.sub(B,N),N=n.mul(ae,oe),k=n.mul(Ee,k),k=n.add(k,N),new A(B,O,k)}subtract(g){return I(g),this.add(g.negate())}is0(){return this.equals(A.ZERO)}multiply(g){let{endo:E}=e;if(!o.isValidNot0(g))throw new RangeError("invalid scalar: out of range");let T,S,v=D=>H.cached(this,D,L=>Ot(A,L));if(E){let{k1neg:D,k1:L,k2neg:B,k2:O}=R(g),{p:k,f:K}=v(L),{p:V,f:N}=v(O);S=K.add(N),T=_(E.beta,k,V,D,B)}else{let{p:D,f:L}=v(g);T=D,S=L}return Ot(A,[T,S])[0]}multiplyUnsafe(g){let{endo:E}=e,T=this,S=g;if(!o.isValid(S))throw new RangeError("invalid scalar: out of range");if(S===$e||T.is0())return A.ZERO;if(S===vt)return T;if(H.hasCache(this))return this.multiply(S);if(E){let{k1neg:v,k1:D,k2neg:L,k2:B}=R(S),{p1:O,p2:k}=ou(A,T,D,B);return _(E.beta,O,k,v,L)}else return H.unsafe(T,S)}toAffine(g){let E=this,T=g,{X:S,Y:v,Z:D}=E;if(n.eql(D,n.ONE))return{x:S,y:v};let L=E.is0();T==null&&(T=L?n.ONE:n.inv(D));let B=n.mul(S,T),O=n.mul(v,T),k=n.mul(D,T);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(k,n.ONE))throw new Error("invZ was invalid");return{x:B,y:O}}isTorsionFree(){let{isTorsionFree:g}=e;return i===vt?!0:g?g(A,this):H.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:g}=e;return i===vt?this:g?g(A,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===vt?this.is0():this.clearCofactor().is0()}toBytes(g=!0){return ke(g,"isCompressed"),this.assertValidity(),p(A,this,g)}toHex(g=!0){return Jt(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let P=o.BITS,H=new sr(A,e.endo?Math.ceil(P/2):P);return P>=8&&A.BASE.precompute(8),Object.freeze(A.prototype),Object.freeze(A),A}function df(t){return Uint8Array.of(t?2:3)}function hf(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function wm(t,e={}){let{Fn:r}=t,n=e.randomBytes===void 0?qr:e.randomBytes,o=Object.assign(hf(t.Fp,r),{seed:Math.max(qs(r.ORDER),16)});function s(h){try{let p=r.fromBytes(h);return r.isValidNot0(p)}catch{return!1}}function i(h,p){let{publicKey:b,publicKeyUncompressed:m}=o;try{let y=h.length;return p===!0&&y!==b||p===!1&&y!==m?!1:!!t.fromBytes(h)}catch{return!1}}function a(h){return h=h===void 0?n(o.seed):h,zs(q(h,o.seed,"seed"),r.ORDER)}function c(h,p=!0){return t.BASE.multiply(r.fromBytes(h)).toBytes(p)}function u(h){let{secretKey:p,publicKey:b,publicKeyUncompressed:m}=o,y=r._lengths;if(!_t(h))return;let x=q(h,void 0,"key").length,w=x===b||x===m,C=x===p||!!y?.includes(x);if(!(w&&C))return w}function f(h,p,b=!0){if(u(h)===!0)throw new Error("first arg must be private key");if(u(p)===!1)throw new Error("second arg must be public key");let m=r.fromBytes(h);return t.fromBytes(p).multiply(m).toBytes(b)}let d={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},l=Gn(a,c);return Object.freeze(d),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:l,Point:t,utils:d,lengths:o})}function pf(t,e,r={}){let n=e;Pn(n),Ue(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?qr:r.randomBytes,s=r.hmac===void 0?(S,v)=>cf(n,S,v):r.hmac,{Fp:i,Fn:a}=t,{ORDER:c,BITS:u}=a,{keygen:f,getPublicKey:d,getSharedSecret:l,utils:h,lengths:p}=wm(t,r),b={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},m=c*ff+vt<i.ORDER;function y(S){let v=c>>vt;return S>v}function x(S,v){if(!a.isValidNot0(v))throw new Error(`invalid signature ${S}: out of range 1..Point.Fn.ORDER`);return v}function w(){if(m)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function C(S,v){Gi(v);let D=p.signature,L=v==="compact"?D:v==="recovered"?D+1:void 0;return q(S,L)}class I{r;s;recovery;constructor(v,D,L){if(this.r=x("r",v),this.s=x("s",D),L!=null){if(w(),![0,1,2,3].includes(L))throw new Error("invalid recovery id");this.recovery=L}Object.freeze(this)}static fromBytes(v,D=b.format){C(v,D);let L;if(D==="der"){let{r:K,s:V}=Ne.toSig(q(v));return new I(K,V)}D==="recovered"&&(L=v[0],D="compact",v=v.subarray(1));let B=p.signature/2,O=v.subarray(0,B),k=v.subarray(B,B*2);return new I(a.fromBytes(O),a.fromBytes(k),L)}static fromHex(v,D){return this.fromBytes(er(v),D)}assertRecovery(){let{recovery:v}=this;if(v==null)throw new Error("invalid recovery id: must be present");return v}addRecoveryBit(v){return new I(this.r,this.s,v)}recoverPublicKey(v){let{r:D,s:L}=this,B=this.assertRecovery(),O=B===2||B===3?D+c:D;if(!i.isValid(O))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let k=i.toBytes(O),K=t.fromBytes(se(df((B&1)===0),k)),V=a.inv(O),N=_(q(v,void 0,"msgHash")),oe=a.create(-N*V),ie=a.create(L*V),ae=t.BASE.multiplyUnsafe(oe).add(K.multiplyUnsafe(ie));if(ae.is0())throw new Error("invalid recovery: point at infinify");return ae.assertValidity(),ae}hasHighS(){return y(this.s)}toBytes(v=b.format){if(Gi(v),v==="der")return er(Ne.hexFromSig(this));let{r:D,s:L}=this,B=a.toBytes(D),O=a.toBytes(L);return v==="recovered"?(w(),se(Uint8Array.of(this.assertRecovery()),B,O)):se(B,O)}toHex(v){return Jt(this.toBytes(v))}}Object.freeze(I.prototype),Object.freeze(I);let R=r.bits2int===void 0?function(v){if(v.length>8192)throw new Error("input is too large");let D=Bt(v),L=v.length*8-u;return L>0?D>>BigInt(L):D}:r.bits2int,_=r.bits2int_modN===void 0?function(v){return a.create(R(v))}:r.bits2int_modN,A=Hr(u);function P(S){return tr("num < 2^"+u,S,$e,A),a.toBytes(S)}function H(S,v){return q(S,void 0,"message"),v?q(n(S),void 0,"prehashed message"):S}function U(S,v,D){let{lowS:L,prehash:B,extraEntropy:O}=Wi(D,b);S=H(S,B);let k=_(S),K=a.fromBytes(v);if(!a.isValidNot0(K))throw new Error("invalid private key");let V=[P(K),P(k)];if(O!=null&&O!==!1){let ae=O===!0?o(p.secretKey):O;V.push(q(ae,void 0,"extraEntropy"))}let N=se(...V),oe=k;function ie(ae){let te=R(ae);if(!a.isValidNot0(te))return;let Ee=a.inv(te),qt=t.BASE.multiply(te).toAffine(),Ir=a.create(qt.x);if(Ir===$e)return;let Tn=a.create(Ee*a.create(oe+Ir*K));if(Tn===$e)return;let Za=(qt.x===Ir?0:2)|Number(qt.y&vt),Ya=Tn;return L&&y(Tn)&&(Ya=a.neg(Tn),Za^=1),new I(Ir,Ya,m?void 0:Za)}return{seed:N,k2sig:ie}}function g(S,v,D={}){let{seed:L,k2sig:B}=U(S,v,D);return qc(n.outputLen,a.BYTES,s)(L,B).toBytes(D.format)}function E(S,v,D,L={}){let{lowS:B,prehash:O,format:k}=Wi(L,b);if(D=q(D,void 0,"publicKey"),v=H(v,O),!_t(S)){let K=S instanceof I?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+K)}C(S,k);try{let K=I.fromBytes(S,k),V=t.fromBytes(D);if(B&&K.hasHighS())return!1;let{r:N,s:oe}=K,ie=_(v),ae=a.inv(oe),te=a.create(ie*ae),Ee=a.create(N*ae),qt=t.BASE.multiplyUnsafe(te).add(V.multiplyUnsafe(Ee));return qt.is0()?!1:a.create(qt.x)===N}catch{return!1}}function T(S,v,D={}){let{prehash:L}=Wi(D,b);return v=H(v,L),I.fromBytes(S,"recovered").recoverPublicKey(v).toBytes()}return Object.freeze({keygen:f,getPublicKey:d,getSharedSecret:l,utils:h,lengths:p,Point:t,sign:g,verify:E,recoverPublicKey:T,Signature:I,hash:n})}var Xi={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Em={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var mf=BigInt(2);function vm(t){let e=Xi.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=t*t*t%e,f=u*u*t%e,d=j(f,r,e)*f%e,l=j(d,r,e)*f%e,h=j(l,mf,e)*u%e,p=j(h,o,e)*h%e,b=j(p,s,e)*p%e,m=j(b,a,e)*b%e,y=j(m,c,e)*m%e,x=j(y,a,e)*b%e,w=j(x,r,e)*f%e,C=j(w,i,e)*p%e,I=j(C,n,e)*u%e,R=j(I,mf,e);if(!Yi.eql(Yi.sqr(R),t))throw new Error("Cannot find square root");return R}var Yi=nr(Xi.p,{sqrt:vm}),Sm=lf(Xi,{Fp:Yi,endo:Em}),pr=pf(Sm,Qt);function yf(t,e,r,n){let o=Or.digest(r instanceof Uint8Array?r:r.subarray());if(Qn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),pr.verify(e,s,t,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Gr(String(s))});try{return n?.signal?.throwIfAborted(),pr.verify(e,o.digest,t,{prehash:!1,format:"der"})}catch(s){throw new Gr(String(s))}}var co=class{type="secp256k1";raw;_key;constructor(e){this._key=gf(e),this.raw=bf(this._key)}toMultihash(){return Re.digest(_e(this))}toCID(){return ne.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:W(this.raw,e.raw)}verify(e,r,n){return yf(this._key,r,e,n)}};function Qi(t){return new co(t)}function bf(t){return pr.Point.fromBytes(t).toBytes()}function gf(t){try{return pr.Point.fromBytes(t),t}catch(e){throw new zt(String(e))}}function uo(t,e){let{Type:r,Data:n}=He.decode(t),o=n??new Uint8Array;switch(r){case G.RSA:return Hi(o,e);case G.Ed25519:return ri(o);case G.secp256k1:return Qi(o);case G.ECDSA:return As(o);default:throw new At}}function xf(t){let{Type:e,Data:r}=He.decode(t.digest),n=r??new Uint8Array;switch(e){case G.Ed25519:return ri(n);case G.secp256k1:return Qi(n);case G.ECDSA:return As(n);default:throw new At}}function _e(t){return He.encode({Type:G[t.type],Data:t.raw})}var wf=Symbol.for("nodejs.util.inspect.custom"),Am=114,cn=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Bn]=!0;toString(){return this.string==null&&(this.string=X.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ne.createV1(Am,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return W(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return W(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[wf](){return`PeerId(${this.toString()})`}},un=class extends cn{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},fn=class extends cn{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},ln=class extends cn{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Cm=2336,dn=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Re.digest($(this.url))}[wf](){return`PeerId(${this.url})`}[Bn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ne.createV1(Cm,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=z(e)),e.toString()===this.toString())}};var Im=114,Ef=2336;function vf(t){if(t.type==="Ed25519")return new fn({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new ln({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new un({multihash:t.toCID().multihash,publicKey:t});throw new At}function Ji(t){if(Dm(t))return new un({multihash:t});if(Tm(t))try{let e=xf(t);if(e.type==="Ed25519")return new fn({multihash:t,publicKey:e});if(e.type==="secp256k1")return new ln({multihash:t,publicKey:e})}catch{let r=z(t.digest);return new dn(new URL(r))}throw new _n("Supplied PeerID Multihash is invalid")}function fo(t){if(t?.multihash==null||t.version==null||t.version===1&&t.code!==Im&&t.code!==Ef)throw new Dn("Supplied PeerID CID is invalid");if(t.code===Ef){let e=z(t.multihash.digest);return new dn(new URL(e))}return Ji(t.multihash)}function Tm(t){return t.code===Re.code}function Dm(t){return t.code===Or.code}function Sf(t=0){return new Uint8Array(t)}var _m=Math.pow(2,7),Bm=Math.pow(2,14),Lm=Math.pow(2,21),Rm=Math.pow(2,28),Om=Math.pow(2,35),km=Math.pow(2,42),Pm=Math.pow(2,49),Se=128;function ea(t){if(t<_m)return 1;if(t<Bm)return 2;if(t<Lm)return 3;if(t<Rm)return 4;if(t<Om)return 5;if(t<km)return 6;if(t<Pm)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Um(t,e,r=0){switch(ea(t)){case 8:e[r++]=t&255|Se,t/=128;case 7:e[r++]=t&255|Se,t/=128;case 6:e[r++]=t&255|Se,t/=128;case 5:e[r++]=t&255|Se,t/=128;case 4:e[r++]=t&255|Se,t>>>=7;case 3:e[r++]=t&255|Se,t>>>=7;case 2:e[r++]=t&255|Se,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Fm(t,e,r=0){switch(ea(t)){case 8:e.set(r++,t&255|Se),t/=128;case 7:e.set(r++,t&255|Se),t/=128;case 6:e.set(r++,t&255|Se),t/=128;case 5:e.set(r++,t&255|Se),t/=128;case 4:e.set(r++,t&255|Se),t>>>=7;case 3:e.set(r++,t&255|Se),t>>>=7;case 2:e.set(r++,t&255|Se),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function lo(t,e,r=0){return e==null&&(e=Sf(ea(t))),e instanceof Uint8Array?Um(t,e,r):Fm(t,e,r)}var hn;(function(t){let e;t.codec=()=>(e==null&&(e=we((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.publicKey!=null&&s.publicKey.byteLength>0&&(i.uint32(10),i.bytes(s.publicKey)),s.payloadType!=null&&s.payloadType.byteLength>0&&(i.uint32(18),i.bytes(s.payloadType)),s.payload!=null&&s.payload.byteLength>0&&(i.uint32(26),i.bytes(s.payload)),s.signature!=null&&s.signature.byteLength>0&&(i.uint32(42),i.bytes(s.signature)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={publicKey:De(0),payloadType:De(0),payload:De(0),signature:De(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.publicKey=s.bytes();break}case 2:{c.payloadType=s.bytes();break}case 3:{c.payload=s.bytes();break}case 5:{c.signature=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.publicKey`,value:s.bytes()};break}case 2:{yield{field:`${a}.payloadType`,value:s.bytes()};break}case 3:{yield{field:`${a}.payload`,value:s.bytes()};break}case 5:{yield{field:`${a}.signature`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ge(s,t.codec())}t.encode=r;function n(s,i){return be(s,t.codec(),i)}t.decode=n;function o(s,i){return xe(s,t.codec(),i)}t.stream=o})(hn||(hn={}));var ho=class extends Error{constructor(e="Invalid signature"){super(e),this.name="InvalidSignatureError"}};var mr=class t{static createFromProtobuf=e=>{let r=hn.decode(e),n=uo(r.publicKey);return new t({publicKey:n,payloadType:r.payloadType,payload:r.payload,signature:r.signature})};static seal=async(e,r,n)=>{if(r==null)throw new Error("Missing private key");let o=e.domain,s=e.codec,i=e.marshal(),a=Af(o,s,i),c=await r.sign(a.subarray(),n);return new t({publicKey:r.publicKey,payloadType:s,payload:i,signature:c})};static openAndCertify=async(e,r,n)=>{let o=t.createFromProtobuf(e);if(!await o.validate(r,n))throw new ho("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(e){let{publicKey:r,payloadType:n,payload:o,signature:s}=e;this.publicKey=r,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=hn.encode({publicKey:_e(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(e){return e==null?!1:W(this.marshal(),e.marshal())}async validate(e,r){let n=Af(e,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},Af=(t,e,r)=>{let n=$(t),o=lo(n.byteLength),s=lo(e.length),i=lo(r.length);return new me(o,n,s,e,i,r)};var Km=Math.pow(2,7),Mm=Math.pow(2,14),qm=Math.pow(2,21),ta=Math.pow(2,28),ra=Math.pow(2,35),na=Math.pow(2,42),oa=Math.pow(2,49),Z=128,pe=127;function yr(t){if(t<Km)return 1;if(t<Mm)return 2;if(t<qm)return 3;if(t<ta)return 4;if(t<ra)return 5;if(t<na)return 6;if(t<oa)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function sa(t,e,r=0){switch(yr(t)){case 8:e[r++]=t&255|Z,t/=128;case 7:e[r++]=t&255|Z,t/=128;case 6:e[r++]=t&255|Z,t/=128;case 5:e[r++]=t&255|Z,t/=128;case 4:e[r++]=t&255|Z,t>>>=7;case 3:e[r++]=t&255|Z,t>>>=7;case 2:e[r++]=t&255|Z,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function zm(t,e){let r=t[e],n=0;if(n+=r&pe,r<Z||(r=t[e+1],n+=(r&pe)<<7,r<Z)||(r=t[e+2],n+=(r&pe)<<14,r<Z)||(r=t[e+3],n+=(r&pe)<<21,r<Z)||(r=t[e+4],n+=(r&pe)*ta,r<Z)||(r=t[e+5],n+=(r&pe)*ra,r<Z)||(r=t[e+6],n+=(r&pe)*na,r<Z)||(r=t[e+7],n+=(r&pe)*oa,r<Z))return n;throw new RangeError("Could not decode varint")}function Vm(t,e){let r=t.get(e),n=0;if(n+=r&pe,r<Z||(r=t.get(e+1),n+=(r&pe)<<7,r<Z)||(r=t.get(e+2),n+=(r&pe)<<14,r<Z)||(r=t.get(e+3),n+=(r&pe)<<21,r<Z)||(r=t.get(e+4),n+=(r&pe)*ta,r<Z)||(r=t.get(e+5),n+=(r&pe)*ra,r<Z)||(r=t.get(e+6),n+=(r&pe)*na,r<Z)||(r=t.get(e+7),n+=(r&pe)*oa,r<Z))return n;throw new RangeError("Could not decode varint")}function ia(t,e=0){return t instanceof Uint8Array?zm(t,e):Vm(t,e)}var de=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},rt=class extends Error{static name="ValidationError";name="ValidationError"},po=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},mo=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var yo=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let r=this.index,n=e();return n===void 0&&(this.index=r),n}parseWith(e){let r=e();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let r=this.readChar();if(r===e)return r})}readSeparator(e,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let d=this.readChar();if(d===void 0)return;let l=Number.parseInt(d,e);if(!Number.isNaN(l))return l});if(f===void 0)break;if(s*=e,s+=f,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let r=0;r<e.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[r]=n}return e})}readIPv6Addr(){let e=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=e(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var $m=45,jm=15,bo=new yo;function Cf(t){if(!(t.length>jm))return bo.new(t).parseWith(()=>bo.readIPv4Addr())}function If(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>$m))return bo.new(t).parseWith(()=>bo.readIPv6Addr())}function go(t){return!!Cf(t)}function Tf(t){return!!If(t)}function ca(t){return e=>z(e,t)}function ua(t){return e=>$(e,t)}function br(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Ft(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function Df(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let r=$(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ft(n);return kt([r,o],r.length+o.length)}function _f(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=Ke.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ft(n);return kt([r,o],r.length+o.length)}function fa(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=z(e,"base32"),o=br(r);return`${n}:${o}`}var la=function(t){t=t.toString().trim();let e=new Uint8Array(4);return t.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new de("Invalid byte value in IP address");e[n]=o}),e},Bf=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let s=go(r[n]),i;s&&(i=la(r[n]),r[n]=z(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,z(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(e+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new de("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},Lf=function(t){if(t.byteLength!==4)throw new de("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},Rf=function(t){if(t.byteLength!==16)throw new de("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let o=t[n],s=t[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let r=e.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new de(`Invalid IPv6 address "${r}"`)}};function Of(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new de(`Invalid IPv6 address "${t}"`)}}var aa=Object.values(kr).map(t=>t.decoder),Wm=(function(){let t=aa[0].or(aa[1]);return aa.slice(2).forEach(e=>t=t.or(e)),t})();function kf(t){return Wm.decode(t)}function Pf(t){return e=>t.encoder.encode(e)}function Gm(t){if(parseInt(t).toString()!==t)throw new rt("Value must be an integer")}function Zm(t){if(t<0)throw new rt("Value must be a positive integer, or zero")}function Ym(t){return e=>{if(e>t)throw new rt(`Value must be smaller than or equal to ${t}`)}}function Xm(...t){return e=>{for(let r of t)r(e)}}var pn=Xm(Gm,Zm,Ym(65535));var ue=-1,da=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let r;if(typeof e=="string"?r=this.protocolsByName.get(e):r=this.protocolsByCode.get(e),r==null)throw new mo(`Protocol ${e} was unknown`);return r}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(r=>{this.protocolsByName.set(r,e)})}removeProtocol(e){let r=this.protocolsByCode.get(e);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},nt=new da,F0=[{code:4,name:"ip4",size:32,valueToBytes:la,bytesToValue:Lf,validate:t=>{if(!go(t))throw new rt(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Ft,bytesToValue:br,validate:pn},{code:273,name:"udp",size:16,valueToBytes:Ft,bytesToValue:br,validate:pn},{code:33,name:"dccp",size:16,valueToBytes:Ft,bytesToValue:br,validate:pn},{code:41,name:"ip6",size:128,valueToBytes:Bf,bytesToValue:Rf,stringToValue:Of,validate:t=>{if(!Tf(t))throw new rt(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:ue},{code:43,name:"ipcidr",size:8,bytesToValue:ca("base10"),valueToBytes:ua("base10")},{code:53,name:"dns",size:ue},{code:54,name:"dns4",size:ue},{code:55,name:"dns6",size:ue},{code:56,name:"dnsaddr",size:ue},{code:132,name:"sctp",size:16,valueToBytes:Ft,bytesToValue:br,validate:pn},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ue,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:ue,bytesToValue:ca("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?ua("base58btc")(t):ne.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:fa,valueToBytes:Df},{code:445,name:"onion3",size:296,bytesToValue:fa,valueToBytes:_f},{code:446,name:"garlic64",size:ue},{code:447,name:"garlic32",size:ue},{code:448,name:"tls"},{code:449,name:"sni",size:ue},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ue,bytesToValue:Pf(ls),valueToBytes:kf},{code:480,name:"http"},{code:481,name:"http-path",size:ue,stringToValue:t=>`/${decodeURIComponent(t)}`,valueToString:t=>encodeURIComponent(t.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:ue}];F0.forEach(t=>{nt.addProtocol(t)});function Uf(t){let e=[],r=0;for(;r<t.length;){let n=ia(t,r),o=nt.getProtocol(n),s=yr(n),i=N0(o,t,r+s),a=0;i>0&&o.size===ue&&(a=yr(i));let c=s+a+i,u={code:n,name:o.name,bytes:Ae(t.subarray(r,r+c))};if(i>0){let f=r+s+a,d=t.subarray(f,f+i);u.value=o.bytesToValue?.(d)??z(d)}e.push(u),r+=c}return e}function Ff(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=nt.getProtocol(n.code),s=yr(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??$(n.value),a=i.byteLength,o.size===ue&&(c=yr(a)));let u=new Uint8Array(s+c+a),f=0;sa(n.code,u,f),f+=s,i!=null&&(o.size===ue&&(sa(a,u,f),f+=c),u.set(i,f)),n.bytes=u}r.push(n.bytes),e+=n.bytes.byteLength}return kt(r,e)}function Nf(t){if(t.charAt(0)!=="/")throw new de('String multiaddr must start with "/"');let e=[],r="protocol",n="",o="";for(let s=1;s<t.length;s++){let i=t.charAt(s);i!=="/"&&(r==="protocol"?o+=t.charAt(s):n+=t.charAt(s));let a=s===t.length-1;if(i==="/"||a){let c=nt.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new de(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new de(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}e.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new de("Incomplete multiaddr");return e}function Kf(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=nt.getProtocol(e.code);if(r==null)throw new de(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function N0(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:ia(e,r)}var K0=Symbol.for("nodejs.util.inspect.custom"),pa=Symbol.for("@multiformats/multiaddr");function M0(t){if(t==null&&(t="/"),wo(t))return t.getComponents();if(t instanceof Uint8Array)return Uf(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),Nf(t);if(Array.isArray(t))return t;throw new de("Must be a string, Uint8Array, Component[], or another Multiaddr")}var xo=class t{[pa]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=M0(e),r.validate!==!1&&q0(this)}get bytes(){return this.#r==null&&(this.#r=Ff(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=Kf(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let r=new t(e);return new t([...this.#e,...r.getComponents()],{validate:!1})}decapsulate(e){let r=e.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new po(`Address ${this.toString()} does not contain subaddress: ${r}`);return new t(n.slice(0,o),{validate:!1})}decapsulateCode(e){let r;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){r=n;break}return new t(this.#e.slice(0,r),{validate:!1})}equals(e){return W(this.bytes,e.bytes)}[K0](){return`Multiaddr(${this.toString()})`}};function q0(t){t.getComponents().forEach(e=>{let r=nt.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function wo(t){return!!t?.[pa]}function Nt(t){return new xo(t)}var Mf="libp2p-peer-record",qf=Uint8Array.from([3,1]);var mn;(function(t){let e;(function(i){let a;i.codec=()=>(a==null&&(a=we((d,l,h={})=>{h.lengthDelimited!==!1&&l.fork(),d.multiaddr!=null&&d.multiaddr.byteLength>0&&(l.uint32(10),l.bytes(d.multiaddr)),h.lengthDelimited!==!1&&l.ldelim()},(d,l,h={})=>{let p={multiaddr:De(0)},b=l==null?d.len:d.pos+l;for(;d.pos<b;){let m=d.uint32();m>>>3===1?p.multiaddr=d.bytes():d.skipType(m&7)}return p},function*(d,l,h,p={}){let b=l==null?d.len:d.pos+l;for(;d.pos<b;){let m=d.uint32();m>>>3===1?yield{field:`${h}.multiaddr`,value:d.bytes()}:d.skipType(m&7)}})),a);function c(d){return ge(d,i.codec())}i.encode=c;function u(d,l){return be(d,i.codec(),l)}i.decode=u;function f(d,l){return xe(d,i.codec(),l)}i.stream=f})(e=t.AddressInfo||(t.AddressInfo={}));let r;t.codec=()=>(r==null&&(r=we((i,a,c={})=>{if(c.lengthDelimited!==!1&&a.fork(),i.peerId!=null&&i.peerId.byteLength>0&&(a.uint32(10),a.bytes(i.peerId)),i.seq!=null&&i.seq!==0n&&(a.uint32(16),a.uint64(i.seq)),i.addresses!=null&&i.addresses.length>0)for(let u of i.addresses)a.uint32(26),t.AddressInfo.codec().encode(u,a);c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let u={peerId:De(0),seq:0n,addresses:[]},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{u.peerId=i.bytes();break}case 2:{u.seq=i.uint64();break}case 3:{if(c.limits?.addresses!=null&&u.addresses.length===c.limits.addresses)throw new Le('Decode error - repeated field "addresses" had too many elements');u.addresses.push(t.AddressInfo.codec().decode(i,i.uint32(),{limits:c.limits?.addresses$}));break}default:{i.skipType(d&7);break}}}return u},function*(i,a,c,u={}){let f={addresses:0},d=a==null?i.len:i.pos+a;for(;i.pos<d;){let l=i.uint32();switch(l>>>3){case 1:{yield{field:`${c}.peerId`,value:i.bytes()};break}case 2:{yield{field:`${c}.seq`,value:i.uint64()};break}case 3:{if(u.limits?.addresses!=null&&f.addresses===u.limits.addresses)throw new Le('Streaming decode error - repeated field "addresses" had too many elements');for(let h of t.AddressInfo.codec().stream(i,i.uint32(),`${c}.addresses[]`,{limits:u.limits?.addresses$}))yield{...h,index:f.addresses};f.addresses++;break}default:{i.skipType(l&7);break}}}})),r);function n(i){return ge(i,t.codec())}t.encode=n;function o(i,a){return be(i,t.codec(),a)}t.decode=o;function s(i,a){return xe(i,t.codec(),a)}t.stream=s})(mn||(mn={}));function zf(t,e){let r=(n,o)=>n.toString().localeCompare(o.toString());return t.length!==e.length?!1:(e.sort(r),t.sort(r).every((n,o)=>e[o].equals(n)))}var Kt=class t{static createFromProtobuf=e=>{let r=mn.decode(e),n=Ji(Zt(r.peerId)),o=(r.addresses??[]).map(i=>Nt(i.multiaddr)),s=r.seq;return new t({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Mf;static CODEC=qf;peerId;multiaddrs;seqNumber;domain=t.DOMAIN;codec=t.CODEC;marshaled;constructor(e){let{peerId:r,multiaddrs:n,seqNumber:o}=e;this.peerId=r,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=mn.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(e=>({multiaddr:e.bytes}))})),this.marshaled}equals(e){return!(!(e instanceof t)||!this.peerId.equals(e.peerId)||this.seqNumber!==e.seqNumber||!zf(this.multiaddrs,e.multiaddrs))}};function z0(t){return t[Symbol.asyncIterator]!=null}function V0(t){if(z0(t))return(async()=>{let r=[];for await(let n of t)r.push(n);return r})();let e=[];for(let r of t)e.push(r);return e}var Vf=V0;function Eo(t,e){let r={[Symbol.iterator]:()=>r,next:()=>{let n=t.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:e(o)}}};return r}var yn=class{map;constructor(e){if(this.map=new Map,e!=null)for(let[r,n]of e.entries())this.map.set(r.toString(),{key:r,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(e){return this.map.delete(e.toString())}entries(){return Eo(this.map.entries(),e=>[e[1].key,e[1].value])}forEach(e){this.map.forEach((r,n)=>{e(r.value,r.key,this)})}get(e){return this.map.get(e.toString())?.value}has(e){return this.map.has(e.toString())}set(e,r){this.map.set(e.toString(),{key:e,value:r})}keys(){return Eo(this.map.values(),e=>e.key)}values(){return Eo(this.map.values(),e=>e.value)}get size(){return this.map.size}};function vo(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var So=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},gr=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new So(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let r=this.head;this.head=r.next=new So(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var ma=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Hf(t={}){return H0(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},t)}function H0(t,e){e=e??{};let r=e.onEnd,n=new gr,o,s,i,a=vo(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((m,y)=>{s=x=>{s=null,n.push(x);try{m(t(n))}catch(w){y(w)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=vo()})}},u=m=>s!=null?s(m):(n.push(m),o),f=m=>(n=new gr,s!=null?s({error:m}):(n.push({error:m}),o)),d=m=>{if(i)return o;if(e?.objectMode!==!0&&m?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:m})},l=m=>i?o:(i=!0,m!=null?f(m):u({done:!0})),h=()=>(n=new gr,l(),{done:!0}),p=m=>(l(m),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:h,throw:p,push:d,end:l,get readableLength(){return n.size},onEmpty:async m=>{let y=m?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let x,w;y!=null&&(x=new Promise((C,I)=>{w=()=>{I(new ma)},y.addEventListener("abort",w)}));try{await Promise.race([a.promise,x])}finally{w!=null&&y!=null&&y?.removeEventListener("abort",w)}}},r==null)return o;let b=o;return o={[Symbol.asyncIterator](){return this},next(){return b.next()},throw(m){return b.throw(m),r!=null&&(r(m),r=void 0),{done:!0}},return(){return b.return(),r!=null&&(r(),r=void 0),{done:!0}},push:d,end(m){return b.end(m),r!=null&&(r(m),r=void 0),o},get readableLength(){return b.readableLength},onEmpty:m=>b.onEmpty(m)},o}function $0(t){return t.reason}async function $f(t,e,r){if(e==null)return t;let n=r?.translateError??$0;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var ya=class extends yn{metric;constructor(e){super();let{name:r,metrics:n}=e;this.metric=n.registerMetric(r),this.updateComponentMetric()}set(e,r){return super.set(e,r),this.updateComponentMetric(),this}delete(e){let r=super.delete(e);return this.updateComponentMetric(),r}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function ba(t){let{name:e,metrics:r}=t,n;return r!=null?n=new ya({name:e,metrics:r}):n=new yn,n}var Te=class extends Error{static name="AbortError";name="AbortError";constructor(e="The operation was aborted",...r){super(e,...r)}};async function Ao(t,e,r,n){let o=new Te(n?.errorMessage);n?.errorCode!=null&&(o.code=n.errorCode);let s=n?.errorEvent??"error";return r?.aborted===!0?Promise.reject(o):new Promise((i,a)=>{function c(){xa(r,"abort",d),xa(t,e,u),xa(t,s,f)}let u=l=>{try{if(n?.filter?.(l)===!1)return}catch(h){c(),a(h);return}c(),i(l)},f=l=>{if(c(),l instanceof Error){a(l);return}a(l.detail??n?.error??new Error(`The "${n?.errorEvent}" event was emitted but the event had no '.detail' field. Pass an 'error' option to race-event to change this message.`))},d=()=>{c(),a(o)};ga(r,"abort",d),ga(t,e,u),ga(t,s,f)})}function ga(t,e,r){t!=null&&(jf(t)?t.addEventListener(e,r):t.addListener(e,r))}function xa(t,e,r){t!=null&&(jf(t)?t.removeEventListener(e,r):t.removeListener(e,r))}function jf(t){return typeof t.addEventListener=="function"&&typeof t.removeEventListener=="function"}var Co=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};var Io=class{deferred;signal;constructor(e){this.signal=e,this.deferred=Promise.withResolvers(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Te)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function j0(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var To=class{id;fn;options;recipients;status;timeline;controller;constructor(e,r){this.id=j0(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Te),this.cleanup())}async join(e={}){let r=new Io(e.signal);return this.recipients.push(r),e.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await $f(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(r=>{r.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};function wa(t,e){let r,n=function(){let o=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var bn=class extends Ht{concurrency;maxSize;queue;pending;sort;autoStart;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.maxSize=e.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.autoStart=e.autoStart??!0,this.sort=e.sort,this.queue=[],this.emitEmpty=wa(this.emitEmpty.bind(this),1),this.emitIdle=wa(this.emitIdle.bind(this),1)}[Symbol.asyncIterator](){return this.toGenerator()}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}tryToStartAnother(){if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let e;for(let r of this.queue)if(r.status==="queued"){e=r;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===e){this.queue.splice(r,1);break}this.pending--,this.safeDispatchEvent("next"),this.autoStart&&this.tryToStartAnother()}),!0)}return!1}enqueue(e){this.queue.push(e),this.sort!=null&&this.queue.sort(this.sort)}start(){this.autoStart===!1&&(this.autoStart=!0,this.tryToStartAnother())}pause(){this.autoStart=!1}async add(e,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new Co;let n=new To(e,r);return this.enqueue(n),this.safeDispatchEvent("add"),this.autoStart&&this.tryToStartAnother(),n.join(r).then(o=>(this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new Te)}),this.clear()}async onEmpty(e){this.size!==0&&await Ao(this,"empty",e?.signal)}async onSizeLessThan(e,r){this.size<e||await Ao(this,"next",r?.signal,{filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await Ao(this,"idle",e?.signal)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let r=Hf({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},o=c=>{c.detail!=null&&r.push(c.detail.result)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new Te("Queue aborted"))};this.addEventListener("success",o),this.addEventListener("failure",s),this.addEventListener("idle",i),e?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("success",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),e?.signal?.removeEventListener("abort",a),n()}}};var Do="lock:worker:request-read",_o="lock:worker:abort-read-request",Bo="lock:worker:release-read",Lo="lock:master:grant-read",Ro="lock:master:error-read",Oo="lock:worker:request-write",ko="lock:worker:abort-write-request",Po="lock:worker:release-write",Uo="lock:master:grant-write",Fo="lock:master:error-write",No="lock:worker:finalize",Ko="mortice",Wf={singleProcess:!1};var Ea=(t,e,r,n,o,s,i,a,c)=>u=>{if(u.data==null)return;let f={type:u.data.type,name:u.data.name,identifier:u.data.identifier};f.type===o&&t.safeDispatchEvent(r,{detail:{name:f.name,identifier:f.identifier,handler:async()=>{e.postMessage({type:c,name:f.name,identifier:f.identifier}),await new Promise(d=>{let l=h=>{if(h?.data==null)return;let p={type:h.data.type,name:h.data.name,identifier:h.data.identifier};p.type===a&&p.identifier===f.identifier&&(e.removeEventListener("message",l),d())};e.addEventListener("message",l)})},onError:d=>{e.postMessage({type:i,name:f.name,identifier:f.identifier,error:{message:d.message,name:d.name,stack:d.stack}})}}}),f.type===s&&t.safeDispatchEvent(n,{detail:{name:f.name,identifier:f.identifier}}),f.type===No&&t.safeDispatchEvent("finalizeRequest",{detail:{name:f.name}})};var Gf=(t=10)=>Math.random().toString().substring(2,t+2);var Mo=class{name;channel;constructor(e){this.name=e,this.channel=new BroadcastChannel(Ko)}readLock(e){return this.sendRequest(Do,_o,Lo,Ro,Bo,e)}writeLock(e){return this.sendRequest(Oo,ko,Uo,Fo,Po,e)}finalize(){this.channel.postMessage({type:No,name:this.name}),this.channel.close()}async sendRequest(e,r,n,o,s,i){i?.signal?.throwIfAborted();let a=Gf();return this.channel.postMessage({type:e,identifier:a,name:this.name}),new Promise((c,u)=>{let f=()=>{this.channel.postMessage({type:r,identifier:a,name:this.name})};i?.signal?.addEventListener("abort",f,{once:!0});let d=l=>{if(l.data?.identifier===a&&(l.data?.type===n&&(this.channel.removeEventListener("message",d),i?.signal?.removeEventListener("abort",f),c(()=>{this.channel.postMessage({type:s,identifier:a,name:this.name})})),l.data.type===o)){this.channel.removeEventListener("message",d),i?.signal?.removeEventListener("abort",f);let h=new Error;l.data.error!=null&&(h.message=l.data.error.message,h.name=l.data.error.name,h.stack=l.data.error.stack),u(h)}};this.channel.addEventListener("message",d)})}};var Zf=t=>{if(t=Object.assign({},Wf,t),!!globalThis.document||t.singleProcess){let r=new BroadcastChannel(Ko),n=new Ht;return r.addEventListener("message",Ea(n,r,"requestReadLock","abortReadLockRequest",Do,_o,Ro,Bo,Lo)),r.addEventListener("message",Ea(n,r,"requestWriteLock","abortWriteLockRequest",Oo,ko,Fo,Po,Uo)),n}return new Mo(t.name)};var Mt=new Map,gn;function Yf(t){return typeof t?.readLock=="function"&&typeof t?.writeLock=="function"}function W0(t){if(gn==null&&(gn=Zf(t),!Yf(gn))){let e=gn;e.addEventListener("requestReadLock",r=>{let n=r.detail.name,o=r.detail.identifier,s=Mt.get(n);if(s==null)return;let i=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==o||i.abort()};e.addEventListener("abortReadLockRequest",a),s.readLock({signal:i.signal}).then(async c=>{await r.detail.handler().finally(()=>{c()})}).catch(c=>{r.detail.onError(c)}).finally(()=>{e.removeEventListener("abortReadLockRequest",a)})}),e.addEventListener("requestWriteLock",r=>{let n=r.detail.name,o=r.detail.identifier,s=Mt.get(n);if(s==null)return;let i=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==o||i.abort()};e.addEventListener("abortWriteLockRequest",a),s.writeLock({signal:i.signal}).then(async c=>{await r.detail.handler().finally(()=>{c()})}).catch(c=>{r.detail.onError(c)}).finally(()=>{e.removeEventListener("abortWriteLockRequest",a)})}),e.addEventListener("finalizeRequest",r=>{let n=r.detail.name,o=Mt.get(n);o?.finalize()})}return gn}async function va(t,e){let r,n,o=new Promise((i,a)=>{r=i,n=a}),s=()=>{n(new Te)};return e?.signal?.addEventListener("abort",s,{once:!0}),t.add(async()=>{await new Promise(i=>{r(()=>{e?.signal?.removeEventListener("abort",s),i()})})},{signal:e?.signal}).catch(i=>{n(i)}),o}var Xf=(t,e)=>{let r=Mt.get(t);if(r!=null)return r;let n=W0(e);if(Yf(n))return r=n,Mt.set(t,r),r;let o=new bn({concurrency:1}),s;return r={async readLock(i){if(s!=null)return va(s,i);s=new bn({concurrency:e.concurrency,autoStart:!1});let a=s,c=va(s,i);return o.add(async()=>{a.start(),await a.onIdle().then(()=>{s===a&&(s=null)})}),c},async writeLock(i){return s=null,va(o,i)},finalize:()=>{Mt.delete(t)},queue:o},Mt.set(t,r),e.autoFinalize===!0&&o.addEventListener("idle",()=>{r.finalize()},{once:!0}),r};var G0={name:"lock",concurrency:1/0,singleProcess:!1,autoFinalize:!1};function Sa(t){let e=Object.assign({},G0,t);return Xf(e.name,e)}var ot;(function(t){let e;(function(a){let c;a.codec=()=>(c==null&&(c=we((l,h,p={})=>{p.lengthDelimited!==!1&&h.fork(),l.key!=null&&l.key!==""&&(h.uint32(10),h.string(l.key)),l.value!=null&&l.value.byteLength>0&&(h.uint32(18),h.bytes(l.value)),p.lengthDelimited!==!1&&h.ldelim()},(l,h,p={})=>{let b={key:"",value:De(0)},m=h==null?l.len:l.pos+h;for(;l.pos<m;){let y=l.uint32();switch(y>>>3){case 1:{b.key=l.string();break}case 2:{b.value=l.bytes();break}default:{l.skipType(y&7);break}}}return b},function*(l,h,p,b={}){let m=h==null?l.len:l.pos+h;for(;l.pos<m;){let y=l.uint32();switch(y>>>3){case 1:{yield{field:`${p}.key`,value:l.string()};break}case 2:{yield{field:`${p}.value`,value:l.bytes()};break}default:{l.skipType(y&7);break}}}})),c);function u(l){return ge(l,a.codec())}a.encode=u;function f(l,h){return be(l,a.codec(),h)}a.decode=f;function d(l,h){return xe(l,a.codec(),h)}a.stream=d})(e=t.Peer$metadataEntry||(t.Peer$metadataEntry={}));let r;(function(a){let c;a.codec=()=>(c==null&&(c=we((l,h,p={})=>{p.lengthDelimited!==!1&&h.fork(),l.key!=null&&l.key!==""&&(h.uint32(10),h.string(l.key)),l.value!=null&&(h.uint32(18),wn.codec().encode(l.value,h)),p.lengthDelimited!==!1&&h.ldelim()},(l,h,p={})=>{let b={key:""},m=h==null?l.len:l.pos+h;for(;l.pos<m;){let y=l.uint32();switch(y>>>3){case 1:{b.key=l.string();break}case 2:{b.value=wn.codec().decode(l,l.uint32(),{limits:p.limits?.value});break}default:{l.skipType(y&7);break}}}return b},function*(l,h,p,b={}){let m=h==null?l.len:l.pos+h;for(;l.pos<m;){let y=l.uint32();switch(y>>>3){case 1:{yield{field:`${p}.key`,value:l.string()};break}case 2:{yield*wn.codec().stream(l,l.uint32(),`${p}.value`,{limits:b.limits?.value});break}default:{l.skipType(y&7);break}}}})),c);function u(l){return ge(l,a.codec())}a.encode=u;function f(l,h){return be(l,a.codec(),h)}a.decode=f;function d(l,h){return xe(l,a.codec(),h)}a.stream=d})(r=t.Peer$tagsEntry||(t.Peer$tagsEntry={}));let n;t.codec=()=>(n==null&&(n=we((a,c,u={})=>{if(u.lengthDelimited!==!1&&c.fork(),a.addresses!=null&&a.addresses.length>0)for(let f of a.addresses)c.uint32(10),xn.codec().encode(f,c);if(a.protocols!=null&&a.protocols.length>0)for(let f of a.protocols)c.uint32(18),c.string(f);if(a.publicKey!=null&&(c.uint32(34),c.bytes(a.publicKey)),a.peerRecordEnvelope!=null&&(c.uint32(42),c.bytes(a.peerRecordEnvelope)),a.metadata!=null&&a.metadata.size>0)for(let[f,d]of a.metadata.entries())c.uint32(50),t.Peer$metadataEntry.codec().encode({key:f,value:d},c);if(a.tags!=null&&a.tags.size>0)for(let[f,d]of a.tags.entries())c.uint32(58),t.Peer$tagsEntry.codec().encode({key:f,value:d},c);a.updated!=null&&(c.uint32(64),c.uint64Number(a.updated)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={addresses:[],protocols:[],metadata:new Map,tags:new Map},d=c==null?a.len:a.pos+c;for(;a.pos<d;){let l=a.uint32();switch(l>>>3){case 1:{if(u.limits?.addresses!=null&&f.addresses.length===u.limits.addresses)throw new Le('Decode error - repeated field "addresses" had too many elements');f.addresses.push(xn.codec().decode(a,a.uint32(),{limits:u.limits?.addresses$}));break}case 2:{if(u.limits?.protocols!=null&&f.protocols.length===u.limits.protocols)throw new Le('Decode error - repeated field "protocols" had too many elements');f.protocols.push(a.string());break}case 4:{f.publicKey=a.bytes();break}case 5:{f.peerRecordEnvelope=a.bytes();break}case 6:{if(u.limits?.metadata!=null&&f.metadata.size===u.limits.metadata)throw new on('Decode error - map field "metadata" had too many elements');let h=t.Peer$metadataEntry.codec().decode(a,a.uint32(),{limits:{value:u.limits?.metadata$value}});f.metadata.set(h.key,h.value);break}case 7:{if(u.limits?.tags!=null&&f.tags.size===u.limits.tags)throw new on('Decode error - map field "tags" had too many elements');let h=t.Peer$tagsEntry.codec().decode(a,a.uint32(),{limits:{value:u.limits?.tags$value}});f.tags.set(h.key,h.value);break}case 8:{f.updated=a.uint64Number();break}default:{a.skipType(l&7);break}}}return f},function*(a,c,u,f={}){let d={addresses:0,protocols:0,metadata:0,tags:0},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let h=a.uint32();switch(h>>>3){case 1:{if(f.limits?.addresses!=null&&d.addresses===f.limits.addresses)throw new Le('Streaming decode error - repeated field "addresses" had too many elements');for(let p of xn.codec().stream(a,a.uint32(),`${u}.addresses[]`,{limits:f.limits?.addresses$}))yield{...p,index:d.addresses};d.addresses++;break}case 2:{if(f.limits?.protocols!=null&&d.protocols===f.limits.protocols)throw new Le('Streaming decode error - repeated field "protocols" had too many elements');yield{field:`${u}.protocols[]`,index:d.protocols,value:a.string()},d.protocols++;break}case 4:{yield{field:`${u}.publicKey`,value:a.bytes()};break}case 5:{yield{field:`${u}.peerRecordEnvelope`,value:a.bytes()};break}case 6:{if(f.limits?.metadata!=null&&d.metadata===f.limits.metadata)throw new Le('Decode error - map field "metadata" had too many elements');yield*t.Peer$metadataEntry.codec().stream(a,a.uint32(),`${u}.metadata{}`,{limits:{value:f.limits?.metadata$value}}),d.metadata++;break}case 7:{if(f.limits?.tags!=null&&d.tags===f.limits.tags)throw new Le('Decode error - map field "tags" had too many elements');yield*t.Peer$tagsEntry.codec().stream(a,a.uint32(),`${u}.tags{}`,{limits:{value:f.limits?.tags$value}}),d.tags++;break}case 8:{yield{field:`${u}.updated`,value:a.uint64Number()};break}default:{a.skipType(h&7);break}}}})),n);function o(a){return ge(a,t.codec())}t.encode=o;function s(a,c){return be(a,t.codec(),c)}t.decode=s;function i(a,c){return xe(a,t.codec(),c)}t.stream=i})(ot||(ot={}));var xn;(function(t){let e;t.codec=()=>(e==null&&(e=we((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.multiaddr!=null&&s.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(s.multiaddr)),s.isCertified!=null&&(i.uint32(16),i.bool(s.isCertified)),s.observed!=null&&(i.uint32(24),i.uint64Number(s.observed)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={multiaddr:De(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.multiaddr=s.bytes();break}case 2:{c.isCertified=s.bool();break}case 3:{c.observed=s.uint64Number();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.multiaddr`,value:s.bytes()};break}case 2:{yield{field:`${a}.isCertified`,value:s.bool()};break}case 3:{yield{field:`${a}.observed`,value:s.uint64Number()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ge(s,t.codec())}t.encode=r;function n(s,i){return be(s,t.codec(),i)}t.decode=n;function o(s,i){return xe(s,t.codec(),i)}t.stream=o})(xn||(xn={}));var wn;(function(t){let e;t.codec=()=>(e==null&&(e=we((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.value!=null&&s.value!==0&&(i.uint32(8),i.uint32(s.value)),s.expiry!=null&&(i.uint32(16),i.uint64(s.expiry)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={value:0},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.value=s.uint32();break}case 2:{c.expiry=s.uint64();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.value`,value:s.uint32()};break}case 2:{yield{field:`${a}.expiry`,value:s.uint64()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ge(s,t.codec())}t.encode=r;function n(s,i){return be(s,t.codec(),i)}t.decode=n;function o(s,i){return xe(s,t.codec(),i)}t.stream=o})(wn||(wn={}));function Z0(t,e){if(t.publicKey!=null||e.publicKey==null)return t;let r;t.type==="RSA"&&(r=t.toMultihash());let n=uo(e.publicKey,r);return vf(n)}function Qf(t,e,r){let n=ot.decode(e);return xr(t,n,r)}function xr(t,e,r){let n=new Map,o=BigInt(Date.now());for(let[s,i]of e.tags.entries())i.expiry!=null&&i.expiry<o||n.set(s,i);return{...e,id:Z0(t,e),addresses:e.addresses.filter(({observed:s})=>s!=null&&s>Date.now()-r).map(({multiaddr:s,isCertified:i})=>({multiaddr:Nt(s),isCertified:i??!1})),metadata:e.metadata,peerRecordEnvelope:e.peerRecordEnvelope??void 0,tags:n}}function Jf(t,e){return Y0(t.addresses,e.addresses)&&X0(t.protocols,e.protocols)&&Q0(t.publicKey,e.publicKey)&&J0(t.peerRecordEnvelope,e.peerRecordEnvelope)&&ey(t.metadata,e.metadata)&&ty(t.tags,e.tags)}function Y0(t,e){return tl(t,e,(r,n)=>!(r.isCertified!==n.isCertified||!W(r.multiaddr,n.multiaddr)))}function X0(t,e){return tl(t,e,(r,n)=>r===n)}function Q0(t,e){return el(t,e)}function J0(t,e){return el(t,e)}function ey(t,e){return rl(t,e,(r,n)=>W(r,n))}function ty(t,e){return rl(t,e,(r,n)=>r.value===n.value&&r.expiry===n.expiry)}function el(t,e){return t==null&&e==null?!0:t!=null&&e!=null?W(t,e):!1}function tl(t,e,r){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(!r(t[n],e[n]))return!1;return!0}function rl(t,e,r){if(t.size!==e.size)return!1;for(let[n,o]of t.entries()){let s=e.get(n);if(s==null||!r(o,s))return!1}return!0}var Da={};F(Da,{base10:()=>cy});var tv=new Uint8Array(0);function nl(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function st(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function ol(t){return new TextEncoder().encode(t)}function sl(t){return new TextDecoder().decode(t)}function ry(t,e){if(t.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<t.length;o++){var s=t.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function d(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var b=0,m=0,y=0,x=p.length;y!==x&&p[y]===0;)y++,b++;for(var w=(x-y)*f+1>>>0,C=new Uint8Array(w);y!==x;){for(var I=p[y],R=0,_=w-1;(I!==0||R<m)&&_!==-1;_--,R++)I+=256*C[_]>>>0,C[_]=I%a>>>0,I=I/a>>>0;if(I!==0)throw new Error("Non-zero carry");m=R,y++}for(var A=w-m;A!==w&&C[A]===0;)A++;for(var P=c.repeat(b);A<w;++A)P+=t.charAt(C[A]);return P}function l(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var b=0;if(p[b]!==" "){for(var m=0,y=0;p[b]===c;)m++,b++;for(var x=(p.length-b)*u+1>>>0,w=new Uint8Array(x);p[b];){var C=r[p.charCodeAt(b)];if(C===255)return;for(var I=0,R=x-1;(C!==0||I<y)&&R!==-1;R--,I++)C+=a*w[R]>>>0,w[R]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");y=I,b++}if(p[b]!==" "){for(var _=x-y;_!==x&&w[_]===0;)_++;for(var A=new Uint8Array(m+(x-_)),P=m;_!==x;)A[P++]=w[_++];return A}}}function h(p){var b=l(p);if(b)return b;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:l,decode:h}}var ny=ry,oy=ny,al=oy;var Aa=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Ca=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,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(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return cl(this,e)}},Ia=class{decoders;constructor(e){this.decoders=e}or(e){return cl(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function cl(t,e){return new Ia({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Ta=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Aa(e,r,n),this.decoder=new Ca(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function wr({name:t,prefix:e,encode:r,decode:n}){return new Ta(t,e,r,n)}function St({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=al(r,t);return wr({prefix:e,name:t,encode:n,decode:s=>st(o(s))})}function sy(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function iy(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function ay(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function ee({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=ay(n);return wr({prefix:e,name:t,encode(s){return iy(s,n,r)},decode(s){return sy(s,o,r,t)}})}var cy=St({prefix:"9",name:"base10",alphabet:"0123456789"});var _a={};F(_a,{base16:()=>uy,base16upper:()=>fy});var uy=ee({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),fy=ee({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Ba={};F(Ba,{base2:()=>ly});var ly=ee({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var La={};F(La,{base256emoji:()=>yy});var ul=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}"),dy=ul.reduce((t,e,r)=>(t[r]=e,t),[]),hy=ul.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function py(t){return t.reduce((e,r)=>(e+=dy[r],e),"")}function my(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=hy[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var yy=wr({prefix:"\u{1F680}",name:"base256emoji",encode:py,decode:my});var Ra={};F(Ra,{base32:()=>Er,base32hex:()=>wy,base32hexpad:()=>vy,base32hexpadupper:()=>Sy,base32hexupper:()=>Ey,base32pad:()=>gy,base32padupper:()=>xy,base32upper:()=>by,base32z:()=>Ay});var Er=ee({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),by=ee({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),gy=ee({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),xy=ee({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),wy=ee({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ey=ee({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),vy=ee({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Sy=ee({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ay=ee({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Oa={};F(Oa,{base36:()=>En,base36upper:()=>Cy});var En=St({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Cy=St({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ka={};F(ka,{base58btc:()=>je,base58flickr:()=>Iy});var je=St({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Iy=St({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Pa={};F(Pa,{base64:()=>Ty,base64pad:()=>Dy,base64url:()=>_y,base64urlpad:()=>By});var Ty=ee({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Dy=ee({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),_y=ee({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),By=ee({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ua={};F(Ua,{base8:()=>Ly});var Ly=ee({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Fa={};F(Fa,{identity:()=>Ry});var Ry=wr({prefix:"\0",name:"identity",encode:t=>sl(t),decode:t=>ol(t)});var bv=new TextEncoder,gv=new TextDecoder;var Ka={};F(Ka,{identity:()=>tb});var Py=dl,fl=128,Uy=127,Fy=~Uy,Ny=Math.pow(2,31);function dl(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Ny;)e[r++]=t&255|fl,t/=128;for(;t&Fy;)e[r++]=t&255|fl,t>>>=7;return e[r]=t|0,dl.bytes=r-n+1,e}var Ky=Na,My=128,ll=127;function Na(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw Na.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&ll)<<o:(i&ll)*Math.pow(2,o),o+=7}while(i>=My);return Na.bytes=s-n,r}var qy=Math.pow(2,7),zy=Math.pow(2,14),Vy=Math.pow(2,21),Hy=Math.pow(2,28),$y=Math.pow(2,35),jy=Math.pow(2,42),Wy=Math.pow(2,49),Gy=Math.pow(2,56),Zy=Math.pow(2,63),Yy=function(t){return t<qy?1:t<zy?2:t<Vy?3:t<Hy?4:t<$y?5:t<jy?6:t<Wy?7:t<Gy?8:t<Zy?9:10},Xy={encode:Py,decode:Ky,encodingLength:Yy},Qy=Xy,vn=Qy;function Sn(t,e=0){return[vn.decode(t,e),vn.decode.bytes]}function vr(t,e,r=0){return vn.encode(t,e,r),e}function Sr(t){return vn.encodingLength(t)}function Cr(t,e){let r=e.byteLength,n=Sr(t),o=n+Sr(r),s=new Uint8Array(o+r);return vr(t,s,0),vr(r,s,n),s.set(e,o),new Ar(t,r,e,s)}function hl(t){let e=st(t),[r,n]=Sn(e),[o,s]=Sn(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ar(r,o,i,e)}function pl(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&nl(t.bytes,r.bytes)}}var Ar=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};var ml=0,Jy="identity",yl=st;function eb(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return Cr(ml,yl(t))}var tb={code:ml,name:Jy,encode:yl,digest:eb};var za={};F(za,{sha256:()=>nb,sha512:()=>ob});var rb=20;function qa({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new Ma(t,e,r,n,o)}var Ma=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??rb,this.maxDigestLength=s}digest(e,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(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?bl(n,this.code,r?.truncate):n.then(o=>bl(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function bl(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return Cr(e,t)}function xl(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var nb=qa({name:"sha2-256",code:18,encode:xl("SHA-256")}),ob=qa({name:"sha2-512",code:19,encode:xl("SHA-512")});function wl(t,e){let{bytes:r,version:n}=t;return n===0?ib(r,Va(t),e??je.encoder):ab(r,Va(t),e??Er.encoder)}var El=new WeakMap;function Va(t){let e=El.get(t);if(e==null){let r=new Map;return El.set(t,r),r}return e}var zo=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,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:e,multihash:r}=this;if(e!==Cn)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==cb)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.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:e,digest:r}=this.multihash,n=Cr(e,r);return t.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(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&pl(e.multihash,n.multihash)}toString(e){return wl(this,e)}toJSON(){return{"/":wl(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new t(n,o,s,i??vl(n,o,s.bytes))}else if(r[ub]===!0){let{version:n,multihash:o,code:s}=r,i=hl(o);return t.create(n,s,i)}else return null}static create(e,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(e){case 0:{if(r!==Cn)throw new Error(`Version 0 CID must use dag-pb (code: ${Cn}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=vl(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Cn,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=st(e.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 Ar(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[d,l]=Sn(e.subarray(r));return r+=l,d},o=n(),s=Cn;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,o]=sb(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Va(s).set(n,e),s}};function sb(t,e){switch(t[0]){case"Q":{let r=e??je;return[je.prefix,r.decode(`${je.prefix}${t}`)]}case je.prefix:{let r=e??je;return[je.prefix,r.decode(t)]}case Er.prefix:{let r=e??Er;return[Er.prefix,r.decode(t)]}case En.prefix:{let r=e??En;return[En.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function ib(t,e,r){let{prefix:n}=r;if(n!==je.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function ab(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var Cn=112,cb=18;function vl(t,e,r){let n=Sr(t),o=n+Sr(e),s=new Uint8Array(o+r.byteLength);return vr(t,s,0),vr(e,s,n),s.set(r,o),s}var ub=Symbol.for("@ipld/js-cid/CID");var Ha={...Fa,...Ba,...Ua,...Da,..._a,...Ra,...Oa,...ka,...Pa,...La},Mv={...za,...Ka};function Sl(t=0){return new Uint8Array(t)}function Cl(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Al=Cl("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),$a=Cl("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Sl(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),fb={utf8:Al,"utf-8":Al,hex:Ha.base16,latin1:$a,ascii:$a,binary:$a,...Ha},Vo=fb;function Il(t,e="utf8"){let r=Vo[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Tl(t,e="utf8"){let r=Vo[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var it="/",Dl=new TextEncoder().encode(it),Ho=Dl[0],$o=class t{_buf;constructor(e,r){if(typeof e=="string")this._buf=Il(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(r==null&&(r=!0),r&&this.clean(),this._buf.byteLength===0||this._buf[0]!==Ho)throw new Error("Invalid key")}toString(e="utf8"){return Tl(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new t(e.join(it))}static random(){return new t(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new t(e):typeof e.uint8Array=="function"?new t(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=Dl),this._buf[0]!==Ho){let e=new Uint8Array(this._buf.byteLength+1);e.fill(Ho,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Ho;)this._buf=this._buf.subarray(0,-1)}less(e){let r=this.list(),n=e.list();for(let o=0;o<r.length;o++){if(n.length<o+1)return!1;let s=r[o],i=n[o];if(s<i)return!0;if(s>i)return!1}return r.length<n.length}reverse(){return t.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(it).slice(1)}type(){return lb(this.baseNamespace())}name(){return db(this.baseNamespace())}instance(e){return new t(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(it)||(e+=it),e+=this.type(),new t(e)}parent(){let e=this.list();return e.length===1?new t(it):new t(e.slice(0,-1).join(it))}child(e){return this.toString()===it?e:e.toString()===it?this:new t(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return t.withNamespaces([...this.namespaces(),...hb(e.map(r=>r.namespaces()))])}};function lb(t){let e=t.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function db(t){let e=t.split(":");return e[e.length-1]}function hb(t){return[].concat(...t)}var ja="/peers/";function In(t){if(!Vt(t)||t.type==null)throw new M("Invalid PeerId");let e=t.toCID().toString();return new $o(`${ja}${e}`)}async function _l(t,e,r,n,o){let s=new Map;for(let i of r){if(i==null)continue;if(i.multiaddr instanceof Uint8Array&&(i.multiaddr=Nt(i.multiaddr)),!wo(i.multiaddr))throw new M("Multiaddr was invalid");if(!await e(t,i.multiaddr,o))continue;let a=i.isCertified??!1,c=i.multiaddr.toString(),u=s.get(c);u!=null?i.isCertified=u.isCertified||a:s.set(c,{multiaddr:i.multiaddr,isCertified:a})}return[...s.values()].sort((i,a)=>i.multiaddr.toString().localeCompare(a.multiaddr.toString())).map(({isCertified:i,multiaddr:a})=>{let c=a.getComponents().find(u=>u.code===421)?.value;return t.equals(c)&&(a=a.decapsulate(Nt(`/p2p/${t}`))),{isCertified:i,multiaddr:a.bytes}})}async function Wo(t,e,r,n){if(e==null)throw new M("Invalid PeerData");if(e.publicKey!=null&&t.publicKey!=null&&!e.publicKey.equals(t.publicKey))throw new M("publicKey bytes do not match peer id publicKey bytes");let o=n.existingPeer?.peer;if(o!=null&&!t.equals(o.id))throw new M("peer id did not match existing peer id");let s=o?.addresses??[],i=new Set(o?.protocols??[]),a=o?.metadata??new Map,c=o?.tags??new Map,u=o?.peerRecordEnvelope;if(r==="patch"){if((e.multiaddrs!=null||e.addresses!=null)&&(s=[],e.multiaddrs!=null&&s.push(...e.multiaddrs.map(l=>({isCertified:!1,multiaddr:l}))),e.addresses!=null&&s.push(...e.addresses)),e.protocols!=null&&(i=new Set(e.protocols)),e.metadata!=null){let l=e.metadata instanceof Map?[...e.metadata.entries()]:Object.entries(e.metadata);a=jo(l,{validate:Bl})}if(e.tags!=null){let l=e.tags instanceof Map?[...e.tags.entries()]:Object.entries(e.tags);c=jo(l,{validate:Ll,map:Rl})}e.peerRecordEnvelope!=null&&(u=e.peerRecordEnvelope)}if(r==="merge"){if(e.multiaddrs!=null&&s.push(...e.multiaddrs.map(l=>({isCertified:!1,multiaddr:l}))),e.addresses!=null&&s.push(...e.addresses),e.protocols!=null&&(i=new Set([...i,...e.protocols])),e.metadata!=null){let l=e.metadata instanceof Map?[...e.metadata.entries()]:Object.entries(e.metadata);for(let[h,p]of l)p==null?a.delete(h):a.set(h,p);a=jo([...a.entries()],{validate:Bl})}if(e.tags!=null){let l=e.tags instanceof Map?[...e.tags.entries()]:Object.entries(e.tags),h=new Map(c);for(let[p,b]of l)b==null?h.delete(p):h.set(p,b);c=jo([...h.entries()],{validate:Ll,map:Rl})}e.peerRecordEnvelope!=null&&(u=e.peerRecordEnvelope)}let f;o?.id.publicKey!=null?f=_e(o.id.publicKey):e.publicKey!=null?f=_e(e.publicKey):t.publicKey!=null&&(f=_e(t.publicKey));let d={addresses:await _l(t,n.addressFilter??(async()=>!0),s,n.existingPeer?.peerPB.addresses,n),protocols:[...i.values()].sort((l,h)=>l.localeCompare(h)),metadata:a,tags:c,publicKey:f,peerRecordEnvelope:u};return d.addresses.forEach(l=>{l.observed=n.existingPeer?.peerPB.addresses?.find(h=>W(h.multiaddr,h.multiaddr))?.observed??Date.now()}),t.type!=="RSA"&&delete d.publicKey,d}function jo(t,e){let r=new Map;for(let[n,o]of t)o!=null&&e.validate(n,o);for(let[n,o]of t.sort(([s],[i])=>s.localeCompare(i)))o!=null&&r.set(n,e.map?.(n,o)??o);return r}function Bl(t,e){if(typeof t!="string")throw new M("Metadata key must be a string");if(!(e instanceof Uint8Array))throw new M("Metadata value must be a Uint8Array")}function Ll(t,e){if(typeof t!="string")throw new M("Tag name must be a string");if(e.value!=null){if(parseInt(`${e.value}`,10)!==e.value)throw new M("Tag value must be an integer");if(e.value<0||e.value>100)throw new M("Tag value must be between 0-100")}if(e.ttl!=null){if(parseInt(`${e.ttl}`,10)!==e.ttl)throw new M("Tag ttl must be an integer");if(e.ttl<0)throw new M("Tag ttl must be between greater than 0")}}function Rl(t,e){let r;e.expiry!=null&&(r=e.expiry),e.ttl!=null&&(r=BigInt(Date.now()+Number(e.ttl)));let n={value:e.value??0};return r!=null&&(n.expiry=r),n}function Ol(t){let e=t.toString().split("/")[2],r=ne.parse(e,Ke);return fo(r)}function Wa(t,e,r){let n=Ol(t);return Qf(n,e,r)}function pb(t,e){return{prefix:ja,filters:(t.filters??[]).map(r=>({key:n,value:o})=>r(Wa(n,o,e))),orders:(t.orders??[]).map(r=>(n,o)=>r(Wa(n.key,n.value,e),Wa(o.key,o.value,e)))}}var Go=class{peerId;datastore;locks;addressFilter;log;maxAddressAge;maxPeerAge;constructor(e,r={}){this.log=e.logger.forComponent("libp2p:peer-store"),this.peerId=e.peerId,this.datastore=e.datastore,this.addressFilter=r.addressFilter,this.locks=ba({name:"libp2p_peer_store_locks",metrics:e.metrics}),this.maxAddressAge=r.maxAddressAge??36e5,this.maxPeerAge=r.maxPeerAge??216e5}getLock(e){let r=this.locks.get(e);return r==null&&(r={refs:0,lock:Sa({name:e.toString(),singleProcess:!0})},this.locks.set(e,r)),r.refs++,r}maybeRemoveLock(e,r){r.refs--,r.refs===0&&(r.lock.finalize(),this.locks.delete(e))}async getReadLock(e,r){let n=this.getLock(e);try{let o=await n.lock.readLock(r);return()=>{o(),this.maybeRemoveLock(e,n)}}catch(o){throw this.maybeRemoveLock(e,n),o}}async getWriteLock(e,r){let n=this.getLock(e);try{let o=await n.lock.writeLock(r);return()=>{o(),this.maybeRemoveLock(e,n)}}catch(o){throw this.maybeRemoveLock(e,n),o}}async has(e,r){try{return await this.load(e,r),!0}catch(n){if(n.name!=="NotFoundError")throw n}return!1}async delete(e,r){this.peerId.equals(e)||await this.datastore.delete(In(e),r)}async load(e,r){let n=In(e),o=await this.datastore.get(n,r),s=ot.decode(o);if(this.#r(e,s))throw await this.datastore.delete(n,r),new Tr;return xr(e,s,this.peerId.equals(e)?1/0:this.maxAddressAge)}async save(e,r,n){let o=await this.#e(e,n),s=await Wo(e,r,"patch",{...n,addressFilter:this.addressFilter});return this.#t(e,s,o)}async patch(e,r,n){let o=await this.#e(e,n),s=await Wo(e,r,"patch",{...n,addressFilter:this.addressFilter,existingPeer:o});return this.#t(e,s,o)}async merge(e,r,n){let o=await this.#e(e,n),s=await Wo(e,r,"merge",{addressFilter:this.addressFilter,existingPeer:o});return this.#t(e,s,o)}async*all(e){for await(let{key:r,value:n}of this.datastore.query(pb(e??{},this.maxAddressAge),e)){let o=Ol(r);if(o.equals(this.peerId))continue;let s=ot.decode(n);if(this.#r(o,s)){await this.datastore.delete(r,e);continue}yield xr(o,s,this.peerId.equals(o)?1/0:this.maxAddressAge)}}async#e(e,r){try{let n=In(e),o=await this.datastore.get(n,r),s=ot.decode(o);if(this.#r(e,s))throw await this.datastore.delete(n,r),new Tr;return{peerPB:s,peer:xr(e,s,this.maxAddressAge)}}catch(n){n.name!=="NotFoundError"&&this.log.error("invalid peer data found in peer store - %e",n)}}async#t(e,r,n,o){r.updated=Date.now();let s=ot.encode(r);return await this.datastore.put(In(e),s,o),{peer:xr(e,r,this.maxAddressAge),previous:n?.peer,updated:n==null||!Jf(r,n.peerPB)}}#r(e,r){if(r.updated==null)return!0;if(this.peerId.equals(e))return!1;let n=r.updated<Date.now()-this.maxPeerAge,o=Date.now()-this.maxAddressAge,s=r.addresses.filter(i=>i.observed!=null&&i.observed>o);return n&&s.length===0}};var Ga=class{store;events;peerId;log;constructor(e,r={}){this.log=e.logger.forComponent("libp2p:peer-store"),this.events=e.events,this.peerId=e.peerId,this.store=new Go(e,r)}[Symbol.toStringTag]="@libp2p/peer-store";async forEach(e,r){for await(let n of this.store.all(r))e(n)}async all(e){return Vf(this.store.all(e))}async delete(e,r){let n=await this.store.getReadLock(e,r);try{await this.store.delete(e,r)}finally{n()}}async has(e,r){let n=await this.store.getReadLock(e,r);try{return await this.store.has(e,r)}finally{this.log.trace("has release read lock"),n?.()}}async get(e,r){let n=await this.store.getReadLock(e,r);try{return await this.store.load(e,r)}finally{n?.()}}async getInfo(e,r){let n=await this.get(e,r);return{id:n.id,multiaddrs:n.addresses.map(({multiaddr:o})=>o)}}async save(e,r,n){let o=await this.store.getWriteLock(e,n);try{let s=await this.store.save(e,r,n);return this.#e(e,s),s.peer}finally{o?.()}}async patch(e,r,n){let o=await this.store.getWriteLock(e,n);try{let s=await this.store.patch(e,r,n);return this.#e(e,s),s.peer}finally{o?.()}}async merge(e,r,n){let o=await this.store.getWriteLock(e,n);try{let s=await this.store.merge(e,r,n);return this.#e(e,s),s.peer}finally{o?.()}}async consumePeerRecord(e,r,n){let o=Vt(r)?r:Vt(r?.expectedPeer)?r.expectedPeer:void 0,s=Vt(r)||r===void 0?n:r,i=await mr.openAndCertify(e,Kt.DOMAIN,s),a=fo(i.publicKey.toCID());if(o?.equals(a)===!1)return this.log("envelope peer id was not the expected peer id - expected: %p received: %p",o,a),!1;let c=Kt.createFromProtobuf(i.payload),u;try{u=await this.get(a,s)}catch(f){if(f.name!=="NotFoundError")throw f}if(u?.peerRecordEnvelope!=null){let f=mr.createFromProtobuf(u.peerRecordEnvelope),d=Kt.createFromProtobuf(f.payload);if(d.seqNumber>=c.seqNumber)return this.log("sequence number was lower or equal to existing sequence number - stored: %d received: %d",d.seqNumber,c.seqNumber),!1}return await this.patch(c.peerId,{peerRecordEnvelope:e,addresses:c.multiaddrs.map(f=>({isCertified:!0,multiaddr:f}))},s),!0}#e(e,r){r.updated&&(this.peerId.equals(e)?this.events.safeDispatchEvent("self:peer:update",{detail:r}):this.events.safeDispatchEvent("peer:update",{detail:r}))}};function mb(t,e={}){return new Ga(t,e)}return Nl(yb);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/curves/utils.js:
|