@libp2p/peer-store 12.0.9 → 12.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PPeerStore = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PPeerStore=(()=>{var Mn=Object.defineProperty;var Sc=Object.getOwnPropertyDescriptor;var Ac=Object.getOwnPropertyNames;var _c=Object.prototype.hasOwnProperty;var bt=(r,t)=>{for(var e in t)Mn(r,e,{get:t[e],enumerable:!0})},Ic=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ac(t))!_c.call(r,o)&&o!==e&&Mn(r,o,{get:()=>t[o],enumerable:!(n=Sc(t,o))||n.enumerable});return r};var Rc=r=>Ic(Mn({},"__esModule",{value:!0}),r);var bd={};bt(bd,{persistentPeerStore:()=>yd});var q=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},we=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var $e=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var Br=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Lr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var se=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Tr=Symbol.for("@libp2p/peer-id");function Ee(r){return!!r?.[Tr]}var ve=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==e),this.#t.set(t,o))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var Fn={};bt(Fn,{base58btc:()=>Q,base58flickr:()=>Kc});var vd=new Uint8Array(0);function Ws(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Pt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function $s(r){return new TextEncoder().encode(r)}function Zs(r){return new TextDecoder().decode(r)}function Bc(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var _=0,x=0,b=0,A=h.length;b!==A&&h[b]===0;)b++,_++;for(var w=(A-b)*l+1>>>0,I=new Uint8Array(w);b!==A;){for(var O=h[b],N=0,U=w-1;(O!==0||N<x)&&U!==-1;U--,N++)O+=256*I[U]>>>0,I[U]=O%a>>>0,O=O/a>>>0;if(O!==0)throw new Error("Non-zero carry");x=N,b++}for(var v=w-x;v!==w&&I[v]===0;)v++;for(var E=c.repeat(_);v<w;++v)E+=r.charAt(I[v]);return E}function d(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var _=0;if(h[_]!==" "){for(var x=0,b=0;h[_]===c;)x++,_++;for(var A=(h.length-_)*u+1>>>0,w=new Uint8Array(A);h[_];){var I=e[h.charCodeAt(_)];if(I===255)return;for(var O=0,N=A-1;(I!==0||O<b)&&N!==-1;N--,O++)I+=a*w[N]>>>0,w[N]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");b=O,_++}if(h[_]!==" "){for(var U=A-b;U!==A&&w[U]===0;)U++;for(var v=new Uint8Array(x+(A-U)),E=x;U!==A;)v[E++]=w[U++];return v}}}function g(h){var _=d(h);if(_)return _;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:d,decode:g}}var Lc=Bc,Tc=Lc,Ys=Tc;var qn=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Vn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Xs(this,t)}},Hn=class{decoders;constructor(t){this.decoders=t}or(t){return Xs(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Xs(r,t){return new Hn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var zn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new qn(t,e,n),this.decoder=new Vn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Se({name:r,prefix:t,encode:e,decode:n}){return new zn(r,t,e,n)}function Yt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Ys(e,r);return Se({prefix:t,name:r,encode:n,decode:s=>Pt(o(s))})}function Cc(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let l=t[r[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|l,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Dc(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Oc(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function j({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=Oc(n);return Se({prefix:t,name:r,encode(s){return Dc(s,n,e)},decode(s){return Cc(s,o,e,r)}})}var Q=Yt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Kc=Yt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Wn={};bt(Wn,{base32:()=>Tt,base32hex:()=>Uc,base32hexpad:()=>qc,base32hexpadupper:()=>Vc,base32hexupper:()=>Mc,base32pad:()=>kc,base32padupper:()=>Nc,base32upper:()=>Pc,base32z:()=>Hc});var Tt=j({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Pc=j({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),kc=j({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Nc=j({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Uc=j({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Mc=j({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),qc=j({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Vc=j({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Hc=j({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var $n={};bt($n,{base36:()=>Ze,base36upper:()=>zc});var Ze=Yt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),zc=Yt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Fc=Js,js=128,Wc=127,$c=~Wc,Zc=Math.pow(2,31);function Js(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Zc;)t[e++]=r&255|js,r/=128;for(;r&$c;)t[e++]=r&255|js,r>>>=7;return t[e]=r|0,Js.bytes=e-n+1,t}var Gc=Zn,Yc=128,Qs=127;function Zn(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Zn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Qs)<<o:(i&Qs)*Math.pow(2,o),o+=7}while(i>=Yc);return Zn.bytes=s-n,e}var Xc=Math.pow(2,7),jc=Math.pow(2,14),Qc=Math.pow(2,21),Jc=Math.pow(2,28),tu=Math.pow(2,35),eu=Math.pow(2,42),ru=Math.pow(2,49),nu=Math.pow(2,56),ou=Math.pow(2,63),su=function(r){return r<Xc?1:r<jc?2:r<Qc?3:r<Jc?4:r<tu?5:r<eu?6:r<ru?7:r<nu?8:r<ou?9:10},iu={encode:Fc,decode:Gc,encodingLength:su},au=iu,Ge=au;function Ye(r,t=0){return[Ge.decode(r,t),Ge.decode.bytes]}function Ae(r,t,e=0){return Ge.encode(r,t,e),t}function _e(r){return Ge.encodingLength(r)}function Ct(r,t){let e=t.byteLength,n=_e(r),o=n+_e(e),s=new Uint8Array(o+e);return Ae(r,s,0),Ae(e,s,n),s.set(t,o),new Ie(r,e,t,s)}function Re(r){let t=Pt(r),[e,n]=Ye(t),[o,s]=Ye(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ie(e,o,i,t)}function ti(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Ws(r.bytes,e.bytes)}}var Ie=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function ei(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return uu(e,Gn(r),t??Q.encoder);default:return lu(e,Gn(r),t??Tt.encoder)}}var ri=new WeakMap;function Gn(r){let t=ri.get(r);if(t==null){let e=new Map;return ri.set(r,e),e}return t}var et=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==Xe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==fu)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=Ct(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&ti(t.multihash,n.multihash)}toString(t){return ei(this,t)}toJSON(){return{"/":ei(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??ni(n,o,s.bytes))}else if(e[du]===!0){let{version:n,multihash:o,code:s}=e,i=Re(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Xe)throw new Error(`Version 0 CID must use dag-pb (code: ${Xe}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=ni(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Xe,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Pt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new Ie(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[f,d]=Ye(t.subarray(e));return e+=d,f},o=n(),s=Xe;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),u=e+c,l=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(t,e){let[n,o]=cu(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Gn(s).set(n,t),s}};function cu(r,t){switch(r[0]){case"Q":{let e=t??Q;return[Q.prefix,e.decode(`${Q.prefix}${r}`)]}case Q.prefix:{let e=t??Q;return[Q.prefix,e.decode(r)]}case Tt.prefix:{let e=t??Tt;return[Tt.prefix,e.decode(r)]}case Ze.prefix:{let e=t??Ze;return[Ze.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function uu(r,t,e){let{prefix:n}=e;if(n!==Q.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function lu(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var Xe=112,fu=18;function ni(r,t,e){let n=_e(r),o=n+_e(t),s=new Uint8Array(o+e.byteLength);return Ae(r,s,0),Ae(t,s,n),s.set(e,o),s}var du=Symbol.for("@ipld/js-cid/CID");var Yn={};bt(Yn,{identity:()=>It});var oi=0,hu="identity",si=Pt;function pu(r,t){if(t?.truncate!=null&&t.truncate!==r.byteLength){if(t.truncate<0||t.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t.truncate)}return Ct(oi,si(r))}var It={code:oi,name:hu,encode:si,digest:pu};function $(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function rt(r=0){return new Uint8Array(r)}function gt(r=0){return new Uint8Array(r)}function kt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=gt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var ai=Symbol.for("@achingbrain/uint8arraylist");function ii(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function Dr(r){return!!r?.[ai]}var dt=class r{bufs;length;[ai]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Dr(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Dr(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=ii(this.bufs,t);return e.buf[e.index]}set(t,e){let n=ii(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Dr(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return kt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:kt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===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,t>=c)continue;let u=t>=a&&t<c,l=e>a&&e<=c;if(u&&l){if(t===a&&e===c){n.push(i);break}let f=t-a;n.push(i.subarray(f,f+(e-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(l){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Dr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;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 f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let f=e;f<=c;f+=l){l=0;for(let d=u;d>=0;d--){let g=this.get(f+d);if(n[d]!==g){l=Math.max(1,d-a[g]);break}}if(l===0)return f}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=gt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=rt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=gt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=rt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!$(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var Xn={};bt(Xn,{base10:()=>mu});var mu=Yt({prefix:"9",name:"base10",alphabet:"0123456789"});var jn={};bt(jn,{base16:()=>yu,base16upper:()=>bu});var yu=j({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),bu=j({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Qn={};bt(Qn,{base2:()=>gu});var gu=j({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Jn={};bt(Jn,{base256emoji:()=>Su});var ci=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}"),xu=ci.reduce((r,t,e)=>(r[e]=t,r),[]),wu=ci.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Eu(r){return r.reduce((t,e)=>(t+=xu[e],t),"")}function vu(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=wu[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Su=Se({prefix:"\u{1F680}",name:"base256emoji",encode:Eu,decode:vu});var eo={};bt(eo,{base64:()=>Au,base64pad:()=>_u,base64url:()=>to,base64urlpad:()=>Iu});var Au=j({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),_u=j({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),to=j({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Iu=j({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ro={};bt(ro,{base8:()=>Ru});var Ru=j({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var no={};bt(no,{identity:()=>Bu});var Bu=Se({prefix:"\0",name:"identity",encode:r=>Zs(r),decode:r=>$s(r)});var sh=new TextEncoder,ih=new TextDecoder;var io={};bt(io,{sha256:()=>je,sha512:()=>Du});var Cu=20;function so({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new oo(r,t,e,n,o)}var oo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??Cu,this.maxDigestLength=s}digest(t,e){if(e?.truncate!=null){if(e.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&e.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?ui(n,this.code,e?.truncate):n.then(o=>ui(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function ui(r,t,e){if(e!=null&&e!==r.byteLength){if(e>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e)}return Ct(t,r)}function fi(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var je=so({name:"sha2-256",code:18,encode:fi("SHA-256")}),Du=so({name:"sha2-512",code:19,encode:fi("SHA-512")});var Qe={...no,...Qn,...ro,...Xn,...jn,...Wn,...$n,...Fn,...eo,...Jn},gh={...io,...Yn};function hi(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var di=hi("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ao=hi("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=gt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Ou={utf8:di,"utf-8":di,hex:Qe.base16,latin1:ao,ascii:ao,binary:ao,...Qe},Or=Ou;function z(r,t="utf8"){let e=Or[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function V(r,t="utf8"){let e=Or[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Ku=parseInt("11111",2),co=parseInt("10000000",2),Pu=parseInt("01111111",2),pi={0:Je,1:Je,2:ku,3:Mu,4:qu,5:Uu,6:Nu,16:Je,22:Je,48:Je};function Nt(r,t={offset:0}){let e=r[t.offset]&Ku;if(t.offset++,pi[e]!=null)return pi[e](r,t);throw new Error("No decoder for tag "+e)}function tr(r,t){let e=0;if((r[t.offset]&co)===co){let n=r[t.offset]&Pu,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function Je(r,t){tr(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Nt(r,t);if(n===null)break;e.push(n)}return e}function ku(r,t){let e=tr(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function Nu(r,t){let e=tr(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let u=r[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let l=0;for(let f=0;f<c.length;f++)l+=c[f]<<f*7;a+=`.${l}`,c=[]}}return a}function Uu(r,t){return t.offset++,null}function Mu(r,t){let e=tr(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function qu(r,t){let e=tr(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Vu(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new dt;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function uo(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Vu(r.byteLength);return new dt(Uint8Array.from([t.byteLength|co]),t)}function xt(r){let t=new dt,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new dt(Uint8Array.from([2]),uo(t),t)}function Kr(r){let t=Uint8Array.from([0]),e=new dt(t,r);return new dt(Uint8Array.from([3]),uo(e),e)}function jt(r,t=48){let e=new dt;for(let n of r)e.append(n);return new dt(Uint8Array.from([t]),uo(e),e)}async function mi(r,t,e,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,e.subarray());return n?.signal?.throwIfAborted(),s}var Hu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),zu=Uint8Array.from([6,5,43,129,4,0,34]),Fu=Uint8Array.from([6,5,43,129,4,0,35]),Wu={ext:!0,kty:"EC",crv:"P-256"},$u={ext:!0,kty:"EC",crv:"P-384"},Zu={ext:!0,kty:"EC",crv:"P-521"},lo=32,fo=48,ho=66;function po(r){let t=Nt(r);return yi(t)}function yi(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===lo*2+1)return n=V(t.subarray(e,e+lo),"base64url"),o=V(t.subarray(e+lo),"base64url"),new Be({...Wu,key_ops:["verify"],x:n,y:o});if(t.byteLength===fo*2+1)return n=V(t.subarray(e,e+fo),"base64url"),o=V(t.subarray(e+fo),"base64url"),new Be({...$u,key_ops:["verify"],x:n,y:o});if(t.byteLength===ho*2+1)return n=V(t.subarray(e,e+ho),"base64url"),o=V(t.subarray(e+ho),"base64url"),new Be({...Zu,key_ops:["verify"],x:n,y:o});throw new q(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function bi(r){return jt([xt(Uint8Array.from([1])),jt([Gu(r.crv)],160),jt([Kr(new dt(Uint8Array.from([4]),z(r.x??"","base64url"),z(r.y??"","base64url")))],161)]).subarray()}function Gu(r){if(r==="P-256")return Hu;if(r==="P-384")return zu;if(r==="P-521")return Fu;throw new q(`Invalid curve ${r}`)}var Be=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=bi(this.jwk)),this._raw}toMultihash(){return It.digest(St(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return Q.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:$(this.raw,t.raw)}async verify(t,e,n){return mi(this.jwk,e,t,n)}};function ie(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Dt(r,t=""){if(!Number.isSafeInteger(r)||r<0){let e=t&&`"${t}" `;throw new Error(`${e}expected integer >= 0, got ${r}`)}}function k(r,t,e=""){let n=ie(r),o=r?.length,s=t!==void 0;if(!n||s&&o!==t){let i=e&&`"${e}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof r}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return r}function Pr(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash must wrapped by utils.createHasher");Dt(r.outputLen),Dt(r.blockLen)}function Le(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function xi(r,t){k(r,void 0,"digestInto() output");let e=t.outputLen;if(r.length<e)throw new Error('"digestInto() output" expected to be of length >='+e)}function Mt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function kr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Rt(r,t){return r<<32-t|r>>>t}var wi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Yu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function qt(r){if(k(r),wi)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Yu[r[e]];return t}var Ut={_0:48,_9:57,A:65,F:70,a:97,f:102};function gi(r){if(r>=Ut._0&&r<=Ut._9)return r-Ut._0;if(r>=Ut.A&&r<=Ut.F)return r-(Ut.A-10);if(r>=Ut.a&&r<=Ut.f)return r-(Ut.a-10)}function Vt(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(wi)return Uint8Array.fromHex(r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=gi(r.charCodeAt(s)),a=gi(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function wt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];k(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}function mo(r,t={}){let e=(o,s)=>r(s).update(o).digest(),n=r(void 0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=o=>r(o),Object.assign(e,t),Object.freeze(e)}function Te(r=32){let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(r))}var yo=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function Ei(r,t,e){return r&t^~r&e}function vi(r,t,e){return r&t^r&e^t&e}var er=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,e,n,o){this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=kr(this.buffer)}update(t){Le(this),k(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=kr(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Le(this),xi(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Mt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)e[f]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=kr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)a.setUint32(4*f,l[f],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Ht=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var at=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Nr=BigInt(4294967295),Si=BigInt(32);function Xu(r,t=!1){return t?{h:Number(r&Nr),l:Number(r>>Si&Nr)}:{h:Number(r>>Si&Nr)|0,l:Number(r&Nr)|0}}function Ai(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:a}=Xu(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var bo=(r,t,e)=>r>>>e,go=(r,t,e)=>r<<32-e|t>>>e,ae=(r,t,e)=>r>>>e|t<<32-e,ce=(r,t,e)=>r<<32-e|t>>>e,rr=(r,t,e)=>r<<64-e|t>>>e-32,nr=(r,t,e)=>r>>>e-32|t<<64-e;function Ot(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var _i=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Ii=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Ri=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Bi=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Li=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Ti=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Qu=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]),Qt=new Uint32Array(64),xo=class extends er{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|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(t,e){for(let f=0;f<16;f++,e+=4)Qt[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let d=Qt[f-15],g=Qt[f-2],h=Rt(d,7)^Rt(d,18)^d>>>3,_=Rt(g,17)^Rt(g,19)^g>>>10;Qt[f]=_+Qt[f-7]+h+Qt[f-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){let d=Rt(a,6)^Rt(a,11)^Rt(a,25),g=l+d+Ei(a,c,u)+Qu[f]+Qt[f]|0,_=(Rt(n,2)^Rt(n,13)^Rt(n,22))+vi(n,o,s)|0;l=u,u=c,c=a,a=i+g|0,i=s,s=o,o=n,n=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,l=l+this.H|0,this.set(n,o,s,i,a,c,u,l)}roundClean(){Mt(Qt)}destroy(){this.set(0,0,0,0,0,0,0,0),Mt(this.buffer)}},wo=class extends xo{A=Ht[0]|0;B=Ht[1]|0;C=Ht[2]|0;D=Ht[3]|0;E=Ht[4]|0;F=Ht[5]|0;G=Ht[6]|0;H=Ht[7]|0;constructor(){super(32)}};var Ci=Ai(["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(r=>BigInt(r))),Ju=Ci[0],tl=Ci[1],Jt=new Uint32Array(80),te=new Uint32Array(80),Eo=class extends er{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:l,Fh:f,Fl:d,Gh:g,Gl:h,Hh:_,Hl:x}=this;return[t,e,n,o,s,i,a,c,u,l,f,d,g,h,_,x]}set(t,e,n,o,s,i,a,c,u,l,f,d,g,h,_,x){this.Ah=t|0,this.Al=e|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=l|0,this.Fh=f|0,this.Fl=d|0,this.Gh=g|0,this.Gl=h|0,this.Hh=_|0,this.Hl=x|0}process(t,e){for(let w=0;w<16;w++,e+=4)Jt[w]=t.getUint32(e),te[w]=t.getUint32(e+=4);for(let w=16;w<80;w++){let I=Jt[w-15]|0,O=te[w-15]|0,N=ae(I,O,1)^ae(I,O,8)^bo(I,O,7),U=ce(I,O,1)^ce(I,O,8)^go(I,O,7),v=Jt[w-2]|0,E=te[w-2]|0,K=ae(v,E,19)^rr(v,E,61)^bo(v,E,6),M=ce(v,E,19)^nr(v,E,61)^go(v,E,6),T=Ri(U,M,te[w-7],te[w-16]),m=Bi(T,N,K,Jt[w-7],Jt[w-16]);Jt[w]=m|0,te[w]=T|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:d,Fh:g,Fl:h,Gh:_,Gl:x,Hh:b,Hl:A}=this;for(let w=0;w<80;w++){let I=ae(f,d,14)^ae(f,d,18)^rr(f,d,41),O=ce(f,d,14)^ce(f,d,18)^nr(f,d,41),N=f&g^~f&_,U=d&h^~d&x,v=Li(A,O,U,tl[w],te[w]),E=Ti(v,b,I,N,Ju[w],Jt[w]),K=v|0,M=ae(n,o,28)^rr(n,o,34)^rr(n,o,39),T=ce(n,o,28)^nr(n,o,34)^nr(n,o,39),m=n&s^n&a^s&a,y=o&i^o&c^i&c;b=_|0,A=x|0,_=g|0,x=h|0,g=f|0,h=d|0,{h:f,l:d}=Ot(u|0,l|0,E|0,K|0),u=a|0,l=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let p=_i(K,T,y);n=Ii(p,E,M,m),o=p|0}({h:n,l:o}=Ot(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ot(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Ot(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=Ot(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:d}=Ot(this.Eh|0,this.El|0,f|0,d|0),{h:g,l:h}=Ot(this.Fh|0,this.Fl|0,g|0,h|0),{h:_,l:x}=Ot(this.Gh|0,this.Gl|0,_|0,x|0),{h:b,l:A}=Ot(this.Hh|0,this.Hl|0,b|0,A|0),this.set(n,o,s,i,a,c,u,l,f,d,g,h,_,x,b,A)}roundClean(){Mt(Jt,te)}destroy(){Mt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},vo=class extends Eo{Ah=at[0]|0;Al=at[1]|0;Bh=at[2]|0;Bl=at[3]|0;Ch=at[4]|0;Cl=at[5]|0;Dh=at[6]|0;Dl=at[7]|0;Eh=at[8]|0;El=at[9]|0;Fh=at[10]|0;Fl=at[11]|0;Gh=at[12]|0;Gl=at[13]|0;Hh=at[14]|0;Hl=at[15]|0;constructor(){super(64)}};var Ce=mo(()=>new wo,yo(1));var Di=mo(()=>new vo,yo(3));var Ao=BigInt(0),So=BigInt(1);function zt(r,t=""){if(typeof r!="boolean"){let e=t&&`"${t}" `;throw new Error(e+"expected boolean, got type="+typeof r)}return r}function Oi(r){if(typeof r=="bigint"){if(!Ur(r))throw new Error("positive bigint expected, got "+r)}else Dt(r);return r}function or(r){let t=Oi(r).toString(16);return t.length&1?"0"+t:t}function Ki(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Ao:BigInt("0x"+r)}function De(r){return Ki(qt(r))}function ue(r){return Ki(qt(qr(k(r)).reverse()))}function Mr(r,t){Dt(t),r=Oi(r);let e=Vt(r.toString(16).padStart(t*2,"0"));if(e.length!==t)throw new Error("number too large");return e}function _o(r,t){return Mr(r,t).reverse()}function qr(r){return Uint8Array.from(r)}var Ur=r=>typeof r=="bigint"&&Ao<=r;function el(r,t,e){return Ur(r)&&Ur(t)&&Ur(e)&&t<=r&&r<e}function sr(r,t,e,n){if(!el(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Io(r){let t;for(t=0;r>Ao;r>>=So,t+=1);return t}var ir=r=>(So<<BigInt(r))-So;function Pi(r,t,e){if(Dt(r,"hashLen"),Dt(t,"qByteLen"),typeof e!="function")throw new Error("hmacFn must be a function");let n=x=>new Uint8Array(x),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(r),u=n(r),l=0,f=()=>{c.fill(1),u.fill(0),l=0},d=(...x)=>e(u,wt(c,...x)),g=(x=o)=>{u=d(s,x),c=d(),x.length!==0&&(u=d(i,x),c=d())},h=()=>{if(l++>=a)throw new Error("drbg: tried max amount of iterations");let x=0,b=[];for(;x<t;){c=d();let A=c.slice();b.push(A),x+=c.length}return wt(...b)};return(x,b)=>{f(),g(x);let A;for(;!(A=b(h()));)g();return f(),A}}function ee(r,t={},e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(s,i,a){let c=r[s];if(a&&c===void 0)return;let u=typeof c;if(u!==i||c===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${u}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(t,!1),o(e,!0)}function Oe(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var ht=BigInt(0),nt=BigInt(1),le=BigInt(2),Ui=BigInt(3),Mi=BigInt(4),qi=BigInt(5),rl=BigInt(7),Vi=BigInt(8),nl=BigInt(9),Hi=BigInt(16);function J(r,t){let e=r%t;return e>=ht?e:t+e}function Z(r,t,e){let n=r;for(;t-- >ht;)n*=n,n%=e;return n}function ki(r,t){if(r===ht)throw new Error("invert: expected non-zero number");if(t<=ht)throw new Error("invert: expected positive modulus, got "+t);let e=J(r,t),n=t,o=ht,s=nt,i=nt,a=ht;for(;e!==ht;){let u=n/e,l=n%e,f=o-i*u,d=s-a*u;n=e,e=l,o=i,s=a,i=f,a=d}if(n!==nt)throw new Error("invert: does not exist");return J(o,t)}function Bo(r,t,e){if(!r.eql(r.sqr(t),e))throw new Error("Cannot find square root")}function zi(r,t){let e=(r.ORDER+nt)/Mi,n=r.pow(t,e);return Bo(r,n,t),n}function ol(r,t){let e=(r.ORDER-qi)/Vi,n=r.mul(t,le),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,le),o),a=r.mul(s,r.sub(i,r.ONE));return Bo(r,a,t),a}function sl(r){let t=Ke(r),e=Fi(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+rl)/Hi;return(a,c)=>{let u=a.pow(c,i),l=a.mul(u,n),f=a.mul(u,o),d=a.mul(u,s),g=a.eql(a.sqr(l),c),h=a.eql(a.sqr(f),c);u=a.cmov(u,l,g),l=a.cmov(d,f,h);let _=a.eql(a.sqr(l),c),x=a.cmov(u,l,_);return Bo(a,x,c),x}}function Fi(r){if(r<Ui)throw new Error("sqrt is not defined for small field");let t=r-nt,e=0;for(;t%le===ht;)t/=le,e++;let n=le,o=Ke(r);for(;Ni(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return zi;let s=o.pow(n,t),i=(t+nt)/le;return function(c,u){if(c.is0(u))return u;if(Ni(c,u)!==1)throw new Error("Cannot find square root");let l=e,f=c.mul(c.ONE,s),d=c.pow(u,t),g=c.pow(u,i);for(;!c.eql(d,c.ONE);){if(c.is0(d))return c.ZERO;let h=1,_=c.sqr(d);for(;!c.eql(_,c.ONE);)if(h++,_=c.sqr(_),h===l)throw new Error("Cannot find square root");let x=nt<<BigInt(l-h-1),b=c.pow(f,x);l=h,f=c.sqr(b),d=c.mul(d,f),g=c.mul(g,b)}return g}}function il(r){return r%Mi===Ui?zi:r%Vi===qi?ol:r%Hi===nl?sl(r):Fi(r)}var Wi=(r,t)=>(J(r,t)&nt)===nt,al=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Lo(r){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},e=al.reduce((n,o)=>(n[o]="function",n),t);return ee(r,e),r}function cl(r,t,e){if(e<ht)throw new Error("invalid exponent, negatives unsupported");if(e===ht)return r.ONE;if(e===nt)return t;let n=r.ONE,o=t;for(;e>ht;)e&nt&&(n=r.mul(n,o)),o=r.sqr(o),e>>=nt;return n}function ar(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,a,c)=>r.is0(a)?i:(n[c]=i,r.mul(i,a)),r.ONE),s=r.inv(o);return t.reduceRight((i,a,c)=>r.is0(a)?i:(n[c]=r.mul(i,n[c]),r.mul(i,a)),s),n}function Ni(r,t){let e=(r.ORDER-nt)/le,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function ul(r,t){t!==void 0&&Dt(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}var Ro=class{ORDER;BITS;BYTES;isLE;ZERO=ht;ONE=nt;_lengths;_sqrt;_mod;constructor(t,e={}){if(t<=ht)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,e!=null&&typeof e=="object"&&(typeof e.BITS=="number"&&(n=e.BITS),typeof e.sqrt=="function"&&(this.sqrt=e.sqrt),typeof e.isLE=="boolean"&&(this.isLE=e.isLE),e.allowedLengths&&(this._lengths=e.allowedLengths?.slice()),typeof e.modFromBytes=="boolean"&&(this._mod=e.modFromBytes));let{nBitLength:o,nByteLength:s}=ul(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return J(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return ht<=t&&t<this.ORDER}is0(t){return t===ht}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&nt)===nt}neg(t){return J(-t,this.ORDER)}eql(t,e){return t===e}sqr(t){return J(t*t,this.ORDER)}add(t,e){return J(t+e,this.ORDER)}sub(t,e){return J(t-e,this.ORDER)}mul(t,e){return J(t*e,this.ORDER)}pow(t,e){return cl(this,t,e)}div(t,e){return J(t*ki(e,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,e){return t+e}subN(t,e){return t-e}mulN(t,e){return t*e}inv(t){return ki(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=il(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?_o(t,this.BYTES):Mr(t,this.BYTES)}fromBytes(t,e=!1){k(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let u=new Uint8Array(o);u.set(t,s?0:u.length-t.length),t=u}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=s?ue(t):De(t);if(a&&(c=J(c,i)),!e&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return ar(this,t)}cmov(t,e,n){return n?e:t}};function Ke(r,t={}){return new Ro(r,t)}function $i(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function To(r){let t=$i(r);return t+Math.ceil(t/2)}function Co(r,t,e=!1){k(r);let n=r.length,o=$i(t),s=To(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?ue(r):De(r),a=J(i,t-nt)+nt;return e?_o(a,o):Mr(a,o)}var Pe=BigInt(0),fe=BigInt(1);function cr(r,t){let e=t.negate();return r?e:t}function de(r,t){let e=ar(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function Xi(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Do(r,t){Xi(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=ir(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Zi(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=fe);let u=t*n,l=u+Math.abs(a)-1,f=a===0,d=a<0,g=t%2!==0;return{nextN:c,offset:l,isZero:f,isNeg:d,isNegF:g,offsetF:u}}var Oo=new WeakMap,ji=new WeakMap;function Ko(r){return ji.get(r)||1}function Gi(r){if(r!==Pe)throw new Error("invalid wNAF")}var ke=class{BASE;ZERO;Fn;bits;constructor(t,e){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=e}_unsafeLadder(t,e,n=this.ZERO){let o=t;for(;e>Pe;)e&fe&&(n=n.add(o)),o=o.double(),e>>=fe;return n}precomputeWindow(t,e){let{windows:n,windowSize:o}=Do(e,this.bits),s=[],i=t,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(t,e,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Do(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:l,isNeg:f,isNegF:d,offsetF:g}=Zi(n,a,i);n=c,l?s=s.add(cr(d,e[g])):o=o.add(cr(f,e[u]))}return Gi(n),{p:o,f:s}}wNAFUnsafe(t,e,n,o=this.ZERO){let s=Do(t,this.bits);for(let i=0;i<s.windows&&n!==Pe;i++){let{nextN:a,offset:c,isZero:u,isNeg:l}=Zi(n,i,s);if(n=a,!u){let f=e[c];o=o.add(l?f.negate():f)}}return Gi(n),o}getPrecomputes(t,e,n){let o=Oo.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),Oo.set(e,o))),o}cached(t,e,n){let o=Ko(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=Ko(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){Xi(e,this.bits),ji.set(t,e),Oo.delete(t)}hasCache(t){return Ko(t)!==1}};function Qi(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>Pe||n>Pe;)e&fe&&(s=s.add(o)),n&fe&&(i=i.add(o)),o=o.double(),e>>=fe,n>>=fe;return{p1:s,p2:i}}function Yi(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Lo(t),t}else return Ke(r,{isLE:e})}function Vr(r,t,e={},n){if(n===void 0&&(n=r==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let c of["p","n","h"]){let u=t[c];if(!(typeof u=="bigint"&&u>Pe))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Yi(t.p,e.Fp,n),s=Yi(t.n,e.Fn,n),a=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function Hr(r,t){return function(n){let o=r(n);return{secretKey:o,publicKey:t(o)}}}var re=BigInt(0),ot=BigInt(1),Po=BigInt(2),ll=BigInt(8);function fl(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),a=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,a)}function Ji(r,t={}){let e=Vr("edwards",r,t,t.FpFnLE),{Fp:n,Fn:o}=e,s=e.CURVE,{h:i}=s;ee(t,{},{uvRatio:"function"});let a=Po<<BigInt(o.BYTES*8)-ot,c=x=>n.create(x),u=t.uvRatio||((x,b)=>{try{return{isValid:!0,value:n.sqrt(n.div(x,b))}}catch{return{isValid:!1,value:re}}});if(!fl(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function l(x,b,A=!1){let w=A?ot:re;return sr("coordinate "+x,b,w,a),b}function f(x){if(!(x instanceof h))throw new Error("EdwardsPoint expected")}let d=Oe((x,b)=>{let{X:A,Y:w,Z:I}=x,O=x.is0();b==null&&(b=O?ll:n.inv(I));let N=c(A*b),U=c(w*b),v=n.mul(I,b);if(O)return{x:re,y:ot};if(v!==ot)throw new Error("invZ was invalid");return{x:N,y:U}}),g=Oe(x=>{let{a:b,d:A}=s;if(x.is0())throw new Error("bad point: ZERO");let{X:w,Y:I,Z:O,T:N}=x,U=c(w*w),v=c(I*I),E=c(O*O),K=c(E*E),M=c(U*b),T=c(E*c(M+v)),m=c(K+c(A*c(U*v)));if(T!==m)throw new Error("bad point: equation left != right (1)");let y=c(w*I),p=c(O*N);if(y!==p)throw new Error("bad point: equation left != right (2)");return!0});class h{static BASE=new h(s.Gx,s.Gy,ot,c(s.Gx*s.Gy));static ZERO=new h(re,ot,ot,re);static Fp=n;static Fn=o;X;Y;Z;T;constructor(b,A,w,I){this.X=l("x",b),this.Y=l("y",A),this.Z=l("z",w,!0),this.T=l("t",I),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){if(b instanceof h)throw new Error("extended point not allowed");let{x:A,y:w}=b||{};return l("x",A),l("y",w),new h(A,w,ot,c(A*w))}static fromBytes(b,A=!1){let w=n.BYTES,{a:I,d:O}=s;b=qr(k(b,w,"point")),zt(A,"zip215");let N=qr(b),U=b[w-1];N[w-1]=U&-129;let v=ue(N),E=A?a:n.ORDER;sr("point.y",v,re,E);let K=c(v*v),M=c(K-ot),T=c(O*K-I),{isValid:m,value:y}=u(M,T);if(!m)throw new Error("bad point: invalid y coordinate");let p=(y&ot)===ot,S=(U&128)!==0;if(!A&&y===re&&S)throw new Error("bad point: x=0 and x_0=1");return S!==p&&(y=c(-y)),h.fromAffine({x:y,y:v})}static fromHex(b,A=!1){return h.fromBytes(Vt(b),A)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,A=!0){return _.createCache(this,b),A||this.multiply(Po),this}assertValidity(){g(this)}equals(b){f(b);let{X:A,Y:w,Z:I}=this,{X:O,Y:N,Z:U}=b,v=c(A*U),E=c(O*I),K=c(w*U),M=c(N*I);return v===E&&K===M}is0(){return this.equals(h.ZERO)}negate(){return new h(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:b}=s,{X:A,Y:w,Z:I}=this,O=c(A*A),N=c(w*w),U=c(Po*c(I*I)),v=c(b*O),E=A+w,K=c(c(E*E)-O-N),M=v+N,T=M-U,m=v-N,y=c(K*T),p=c(M*m),S=c(K*m),R=c(T*M);return new h(y,p,R,S)}add(b){f(b);let{a:A,d:w}=s,{X:I,Y:O,Z:N,T:U}=this,{X:v,Y:E,Z:K,T:M}=b,T=c(I*v),m=c(O*E),y=c(U*w*M),p=c(N*K),S=c((I+O)*(v+E)-T-m),R=p-y,L=p+y,C=c(m-A*T),B=c(S*R),D=c(L*C),P=c(S*C),G=c(R*L);return new h(B,D,G,P)}subtract(b){return this.add(b.negate())}multiply(b){if(!o.isValidNot0(b))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:A,f:w}=_.cached(this,b,I=>de(h,I));return de(h,[A,w])[0]}multiplyUnsafe(b,A=h.ZERO){if(!o.isValid(b))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return b===re?h.ZERO:this.is0()||b===ot?this:_.unsafe(this,b,w=>de(h,w),A)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return _.unsafe(this,s.n).is0()}toAffine(b){return d(this,b)}clearCofactor(){return i===ot?this:this.multiplyUnsafe(i)}toBytes(){let{x:b,y:A}=this.toAffine(),w=n.toBytes(A);return w[w.length-1]|=b&ot?128:0,w}toHex(){return qt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let _=new ke(h,o.BITS);return h.BASE.precompute(8),h}function ta(r,t,e={}){if(typeof t!="function")throw new Error('"hash" function param is required');ee(e,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=e,{BASE:o,Fp:s,Fn:i}=r,a=e.randomBytes||Te,c=e.adjustScalarBytes||(v=>v),u=e.domain||((v,E,K)=>{if(zt(K,"phflag"),E.length||K)throw new Error("Contexts/pre-hash are not supported");return v});function l(v){return i.create(ue(v))}function f(v){let E=w.secretKey;k(v,w.secretKey,"secretKey");let K=k(t(v),2*E,"hashedSecretKey"),M=c(K.slice(0,E)),T=K.slice(E,2*E),m=l(M);return{head:M,prefix:T,scalar:m}}function d(v){let{head:E,prefix:K,scalar:M}=f(v),T=o.multiply(M),m=T.toBytes();return{head:E,prefix:K,scalar:M,point:T,pointBytes:m}}function g(v){return d(v).pointBytes}function h(v=Uint8Array.of(),...E){let K=wt(...E);return l(t(u(K,k(v,void 0,"context"),!!n)))}function _(v,E,K={}){v=k(v,void 0,"message"),n&&(v=n(v));let{prefix:M,scalar:T,pointBytes:m}=d(E),y=h(K.context,M,v),p=o.multiply(y).toBytes(),S=h(K.context,p,m,v),R=i.create(y+S*T);if(!i.isValid(R))throw new Error("sign failed: invalid s");let L=wt(p,i.toBytes(R));return k(L,w.signature,"result")}let x={zip215:!0};function b(v,E,K,M=x){let{context:T,zip215:m}=M,y=w.signature;v=k(v,y,"signature"),E=k(E,void 0,"message"),K=k(K,w.publicKey,"publicKey"),m!==void 0&&zt(m,"zip215"),n&&(E=n(E));let p=y/2,S=v.subarray(0,p),R=ue(v.subarray(p,y)),L,C,B;try{L=r.fromBytes(K,m),C=r.fromBytes(S,m),B=o.multiplyUnsafe(R)}catch{return!1}if(!m&&L.isSmallOrder())return!1;let D=h(T,C.toBytes(),L.toBytes(),E);return C.add(L.multiplyUnsafe(D)).subtract(B).clearCofactor().is0()}let A=s.BYTES,w={secretKey:A,publicKey:A,signature:2*A,seed:A};function I(v=a(w.seed)){return k(v,w.seed,"seed")}function O(v){return ie(v)&&v.length===i.BYTES}function N(v,E){try{return!!r.fromBytes(v,E)}catch{return!1}}let U={getExtendedPublicKey:d,randomSecretKey:I,isValidSecretKey:O,isValidPublicKey:N,toMontgomery(v){let{y:E}=r.fromBytes(v),K=w.publicKey,M=K===32;if(!M&&K!==57)throw new Error("only defined for 25519 and 448");let T=M?s.div(ot+E,ot-E):s.div(E-ot,E+ot);return s.toBytes(T)},toMontgomerySecret(v){let E=w.secretKey;k(v,E);let K=t(v.subarray(0,E));return c(K).subarray(0,E)}};return Object.freeze({keygen:Hr(I,g),getPublicKey:g,sign:_,verify:b,utils:U,Point:r,lengths:w})}var dl=BigInt(1),ea=BigInt(2);var hl=BigInt(5),pl=BigInt(8),ko=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),ml={p:ko,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:pl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function yl(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=ko,a=r*r%s*r%s,c=Z(a,ea,s)*a%s,u=Z(c,dl,s)*r%s,l=Z(u,hl,s)*u%s,f=Z(l,t,s)*l%s,d=Z(f,e,s)*f%s,g=Z(d,n,s)*d%s,h=Z(g,o,s)*g%s,_=Z(h,o,s)*g%s,x=Z(_,t,s)*l%s;return{pow_p_5_8:Z(x,ea,s)*r%s,b2:a}}function bl(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var ra=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function gl(r,t){let e=ko,n=J(t*t*t,e),o=J(n*n*t,e),s=yl(r*o).pow_p_5_8,i=J(r*n*s,e),a=J(t*i*i,e),c=i,u=J(i*ra,e),l=a===r,f=a===J(-r,e),d=a===J(-r*ra,e);return l&&(i=c),(f||d)&&(i=u),Wi(i,e)&&(i=J(-i,e)),{isValid:l||f,value:i}}var xl=Ji(ml,{uvRatio:gl});function wl(r){return ta(xl,Di,Object.assign({adjustScalarBytes:bl},r))}var na=wl({});var ur=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},zr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var oa={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new zr("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var At=oa;var Fr=32;var No,El=(async()=>{try{return await At.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function vl(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await At.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await At.get().subtle.verify({name:"Ed25519"},n,t,e instanceof Uint8Array?e:e.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Sl(r,t,e){return na.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function sa(r,t,e){return No==null&&(No=await El),No?vl(r,t,e):Sl(r,t,e)}function Wr(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var $r=class{type="Ed25519";raw;constructor(t){this.raw=Uo(t,Fr)}toMultihash(){return It.digest(St(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return Q.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:$(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=sa(this.raw,e,t);return Wr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Mo(r){return r=Uo(r,Fr),new $r(r)}function Uo(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new q(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var _l=Math.pow(2,7),Il=Math.pow(2,14),Rl=Math.pow(2,21),qo=Math.pow(2,28),Vo=Math.pow(2,35),Ho=Math.pow(2,42),zo=Math.pow(2,49),F=128,lt=127;function _t(r){if(r<_l)return 1;if(r<Il)return 2;if(r<Rl)return 3;if(r<qo)return 4;if(r<Vo)return 5;if(r<Ho)return 6;if(r<zo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ne(r,t,e=0){switch(_t(r)){case 8:t[e++]=r&255|F,r/=128;case 7:t[e++]=r&255|F,r/=128;case 6:t[e++]=r&255|F,r/=128;case 5:t[e++]=r&255|F,r/=128;case 4:t[e++]=r&255|F,r>>>=7;case 3:t[e++]=r&255|F,r>>>=7;case 2:t[e++]=r&255|F,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Bl(r,t,e=0){switch(_t(r)){case 8:t.set(e++,r&255|F),r/=128;case 7:t.set(e++,r&255|F),r/=128;case 6:t.set(e++,r&255|F),r/=128;case 5:t.set(e++,r&255|F),r/=128;case 4:t.set(e++,r&255|F),r>>>=7;case 3:t.set(e++,r&255|F),r>>>=7;case 2:t.set(e++,r&255|F),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Fo(r,t){let e=r[t],n=0;if(n+=e&lt,e<F||(e=r[t+1],n+=(e&lt)<<7,e<F)||(e=r[t+2],n+=(e&lt)<<14,e<F)||(e=r[t+3],n+=(e&lt)<<21,e<F)||(e=r[t+4],n+=(e&lt)*qo,e<F)||(e=r[t+5],n+=(e&lt)*Vo,e<F)||(e=r[t+6],n+=(e&lt)*Ho,e<F)||(e=r[t+7],n+=(e&lt)*zo,e<F))return n;throw new RangeError("Could not decode varint")}function Ll(r,t){let e=r.get(t),n=0;if(n+=e&lt,e<F||(e=r.get(t+1),n+=(e&lt)<<7,e<F)||(e=r.get(t+2),n+=(e&lt)<<14,e<F)||(e=r.get(t+3),n+=(e&lt)<<21,e<F)||(e=r.get(t+4),n+=(e&lt)*qo,e<F)||(e=r.get(t+5),n+=(e&lt)*Vo,e<F)||(e=r.get(t+6),n+=(e&lt)*Ho,e<F)||(e=r.get(t+7),n+=(e&lt)*zo,e<F))return n;throw new RangeError("Could not decode varint")}function Zr(r,t,e=0){return t==null&&(t=gt(_t(r))),t instanceof Uint8Array?Ne(r,t,e):Bl(r,t,e)}function Wo(r,t=0){return r instanceof Uint8Array?Fo(r,t):Ll(r,t)}var $o=new Float32Array([-0]),ne=new Uint8Array($o.buffer);function ca(r,t,e){$o[0]=r,t[e]=ne[0],t[e+1]=ne[1],t[e+2]=ne[2],t[e+3]=ne[3]}function ua(r,t){return ne[0]=r[t],ne[1]=r[t+1],ne[2]=r[t+2],ne[3]=r[t+3],$o[0]}var Zo=new Float64Array([-0]),ft=new Uint8Array(Zo.buffer);function la(r,t,e){Zo[0]=r,t[e]=ft[0],t[e+1]=ft[1],t[e+2]=ft[2],t[e+3]=ft[3],t[e+4]=ft[4],t[e+5]=ft[5],t[e+6]=ft[6],t[e+7]=ft[7]}function fa(r,t){return ft[0]=r[t],ft[1]=r[t+1],ft[2]=r[t+2],ft[3]=r[t+3],ft[4]=r[t+4],ft[5]=r[t+5],ft[6]=r[t+6],ft[7]=r[t+7],Zo[0]}var Tl=BigInt(Number.MAX_SAFE_INTEGER),Cl=BigInt(Number.MIN_SAFE_INTEGER),Et=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return he;if(t<Tl&&t>Cl)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>da&&(o=0n,++n>da&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return he;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):he}},he=new Et(0,0);he.toBigInt=function(){return 0n};he.zzEncode=he.zzDecode=function(){return this};he.length=function(){return 1};var da=4294967296n;function ha(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function pa(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Go(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function Bt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Gr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Yo=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Bt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Bt(this,4);return Gr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Bt(this,4);return Gr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Bt(this,4);let t=ua(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Bt(this,4);let t=fa(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw Bt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return pa(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Bt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Bt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Et(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw Bt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw Bt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Bt(this,8);let t=Gr(this.buf,this.pos+=4),e=Gr(this.buf,this.pos+=4);return new Et(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Fo(this.buf,this.pos);return this.pos+=_t(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Xo(r){return new Yo(r instanceof Uint8Array?r:r.subarray())}function pt(r,t,e){let n=Xo(r);return t.decode(n,void 0,e)}function jo(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return gt(i);o+i>t&&(n=gt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var pe=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Qo(){}var ts=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Dl=jo();function Ol(r){return globalThis.Buffer!=null?gt(r):Dl(r)}var fr=class{len;head;tail;states;constructor(){this.len=0,this.head=new pe(Qo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new pe(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new es((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Yr,10,Et.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Et.fromBigInt(t);return this._push(Yr,e.length(),e)}uint64Number(t){return this._push(Ne,_t(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=Et.fromBigInt(t).zzEncode();return this._push(Yr,e.length(),e)}sint64Number(t){let e=Et.fromNumber(t).zzEncode();return this._push(Yr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Jo,1,t?1:0)}fixed32(t){return this._push(lr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Et.fromBigInt(t);return this._push(lr,4,e.lo)._push(lr,4,e.hi)}fixed64Number(t){let e=Et.fromNumber(t);return this._push(lr,4,e.lo)._push(lr,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(ca,4,t)}double(t){return this._push(la,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Jo,1,0):this.uint32(e)._push(Pl,e,t)}string(t){let e=ha(t);return e!==0?this.uint32(e)._push(Go,e,t):this._push(Jo,1,0)}fork(){return this.states=new ts(this),this.head=this.tail=new pe(Qo,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 pe(Qo,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Ol(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Jo(r,t,e){t[e]=r&255}function Kl(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var es=class extends pe{next;constructor(t,e){super(Kl,t,e),this.next=void 0}};function Yr(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function lr(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Pl(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(fr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(kl,t,r),this},fr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Nl,t,r),this});function kl(r,t,e){t.set(r,e)}function Nl(r,t,e){r.length<40?Go(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(z(r),e)}function rs(){return new fr}function mt(r,t){let e=rs();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Ue;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(Ue||(Ue={}));function Xr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function ns(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return Xr("enum",Ue.VARINT,e,n)}function yt(r,t){return Xr("message",Ue.LENGTH_DELIMITED,r,t)}var me=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},dr=class extends Error{code="ERR_MAX_SIZE";name="MaxSizeError"};var tt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(tt||(tt={}));var os;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(os||(os={}));(function(r){r.codec=()=>ns(os)})(tt||(tt={}));var Kt;(function(r){let t;r.codec=()=>(t==null&&(t=yt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),tt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=tt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>mt(e,r.codec()),r.decode=(e,n)=>pt(e,r.codec(),n)})(Kt||(Kt={}));var ss;(function(r){let t;r.codec=()=>(t==null&&(t=yt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),tt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=tt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>mt(e,r.codec()),r.decode=(e,n)=>pt(e,r.codec(),n)})(ss||(ss={}));var pr={};bt(pr,{MAX_RSA_KEY_SIZE:()=>is,generateRSAKeyPair:()=>wa,jwkToJWKKeyPair:()=>Ea,jwkToPkcs1:()=>Vl,jwkToPkix:()=>ls,jwkToRSAPrivateKey:()=>ps,pkcs1MessageToJwk:()=>cs,pkcs1MessageToRSAPrivateKey:()=>fs,pkcs1ToJwk:()=>ql,pkcs1ToRSAPrivateKey:()=>xa,pkixMessageToJwk:()=>us,pkixMessageToRSAPublicKey:()=>hs,pkixToJwk:()=>Hl,pkixToRSAPublicKey:()=>ds});var Me=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=pr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return et.createV1(114,this._multihash)}toString(){return Q.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:$(this.raw,t.raw)}verify(t,e,n){return ga(this.jwk,e,t,n)}},hr=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=pr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:$(this.raw,t.raw)}sign(t,e){return ba(this.jwk,t,e)}};var is=8192,as=18,Ul=1062,Ml=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function ql(r){let t=Nt(r);return cs(t)}function cs(r){return{n:V(r[1],"base64url"),e:V(r[2],"base64url"),d:V(r[3],"base64url"),p:V(r[4],"base64url"),q:V(r[5],"base64url"),dp:V(r[6],"base64url"),dq:V(r[7],"base64url"),qi:V(r[8],"base64url"),kty:"RSA"}}function Vl(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new q("JWK was missing components");return jt([xt(Uint8Array.from([0])),xt(z(r.n,"base64url")),xt(z(r.e,"base64url")),xt(z(r.d,"base64url")),xt(z(r.p,"base64url")),xt(z(r.q,"base64url")),xt(z(r.dp,"base64url")),xt(z(r.dq,"base64url")),xt(z(r.qi,"base64url"))]).subarray()}function Hl(r){let t=Nt(r,{offset:0});return us(t)}function us(r){let t=Nt(r[1],{offset:0});return{kty:"RSA",n:V(t[0],"base64url"),e:V(t[1],"base64url")}}function ls(r){if(r.n==null||r.e==null)throw new q("JWK was missing components");return jt([Ml,Kr(jt([xt(z(r.n,"base64url")),xt(z(r.e,"base64url"))]))]).subarray()}function xa(r){let t=Nt(r);return fs(t)}function fs(r){let t=cs(r);return ps(t)}function ds(r,t){if(r.byteLength>=Ul)throw new we("Key size is too large");let e=Nt(r,{offset:0});return hs(e,r,t)}function hs(r,t,e){let n=us(r);if(e==null){let o=Ce(Kt.encode({Type:tt.RSA,Data:t}));e=Ct(as,o)}return new Me(n,e)}function ps(r){if(Sa(r)>is)throw new q("Key size is too large");let t=Ea(r),e=Ce(Kt.encode({Type:tt.RSA,Data:ls(t.publicKey)})),n=Ct(as,e);return new hr(t.privateKey,new Me(t.publicKey,n))}async function wa(r){if(r>is)throw new q("Key size is too large");let t=await va(r),e=Ce(Kt.encode({Type:tt.RSA,Data:ls(t.publicKey)})),n=Ct(as,e);return new hr(t.privateKey,new Me(t.publicKey,n))}function Ea(r){if(r==null)throw new q("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function va(r,t){let e=await At.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await zl(e,t);return{privateKey:n[0],publicKey:n[1]}}async function ba(r,t,e){let n=await At.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);e?.signal?.throwIfAborted();let o=await At.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return e?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function ga(r,t,e,n){let o=await At.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await At.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,e instanceof Uint8Array?e:e.subarray());return n?.signal?.throwIfAborted(),s}async function zl(r,t){if(r.privateKey==null||r.publicKey==null)throw new q("Private and public key are required");let e=await Promise.all([At.get().subtle.exportKey("jwk",r.privateKey),At.get().subtle.exportKey("jwk",r.publicKey)]);return t?.signal?.throwIfAborted(),e}function Sa(r){if(r.kty!=="RSA")throw new q("invalid key type");if(r.n==null)throw new q("invalid key modulus");return z(r.n,"base64url").length*8}var jr=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,e){if(Pr(t),k(e,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(e.length>n?t.create().update(e).digest():e);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Mt(o)}update(t){return Le(this),this.iHash.update(t),this}digestInto(t){Le(this),k(t,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ms=(r,t,e)=>new jr(r,t).update(e).digest();ms.create=(r,t)=>new jr(r,t);var Aa=(r,t)=>(r+(r>=0?t:-t)/_a)/t;function Fl(r,t,e){let[[n,o],[s,i]]=t,a=Aa(i*r,e),c=Aa(-o*r,e),u=r-a*n-c*s,l=-a*o-c*i,f=u<Ft,d=l<Ft;f&&(u=-u),d&&(l=-l);let g=ir(Math.ceil(Io(e)/2))+qe;if(u<Ft||u>=g||l<Ft||l>=g)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:f,k1:u,k2neg:d,k2:l}}function bs(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function ys(r,t){let e={};for(let n of Object.keys(t))e[n]=r[n]===void 0?t[n]:r[n];return zt(e.lowS,"lowS"),zt(e.prehash,"prehash"),e.format!==void 0&&bs(e.format),e}var gs=class extends Error{constructor(t=""){super(t)}},oe={Err:gs,_tlv:{encode:(r,t)=>{let{Err:e}=oe;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=or(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?or(o.length/2|128):"";return or(r)+s+o+t},decode(r,t){let{Err:e}=oe,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new e("tlv.decode: length bytes not complete");if(u[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let l of u)i=i<<8|l;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=oe;if(r<Ft)throw new t("integer: negative integers are not allowed");let e=or(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=oe;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return De(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=oe,o=k(r,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:u,l}=n.decode(2,c);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(u)}},hexFromSig(r){let{_tlv:t,_int:e}=oe,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},Ft=BigInt(0),qe=BigInt(1),_a=BigInt(2),Qr=BigInt(3),Wl=BigInt(4);function Ia(r,t={}){let e=Vr("weierstrass",r,t),{Fp:n,Fn:o}=e,s=e.CURVE,{h:i,n:a}=s;ee(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c}=t;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 u=Ba(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function f(T,m,y){let{x:p,y:S}=m.toAffine(),R=n.toBytes(p);if(zt(y,"isCompressed"),y){l();let L=!n.isOdd(S);return wt(Ra(L),R)}else return wt(Uint8Array.of(4),R,n.toBytes(S))}function d(T){k(T,void 0,"Point");let{publicKey:m,publicKeyUncompressed:y}=u,p=T.length,S=T[0],R=T.subarray(1);if(p===m&&(S===2||S===3)){let L=n.fromBytes(R);if(!n.isValid(L))throw new Error("bad point: is not on curve, wrong x");let C=_(L),B;try{B=n.sqrt(C)}catch(G){let W=G instanceof Error?": "+G.message:"";throw new Error("bad point: is not on curve, sqrt error"+W)}l();let D=n.isOdd(B);return(S&1)===1!==D&&(B=n.neg(B)),{x:L,y:B}}else if(p===y&&S===4){let L=n.BYTES,C=n.fromBytes(R.subarray(0,L)),B=n.fromBytes(R.subarray(L,L*2));if(!x(C,B))throw new Error("bad point: is not on curve");return{x:C,y:B}}else throw new Error(`bad point: got length ${p}, expected compressed=${m} or uncompressed=${y}`)}let g=t.toBytes||f,h=t.fromBytes||d;function _(T){let m=n.sqr(T),y=n.mul(m,T);return n.add(n.add(y,n.mul(T,s.a)),s.b)}function x(T,m){let y=n.sqr(m),p=_(T);return n.eql(y,p)}if(!x(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let b=n.mul(n.pow(s.a,Qr),Wl),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(b,A)))throw new Error("bad curve params: a or b");function w(T,m,y=!1){if(!n.isValid(m)||y&&n.is0(m))throw new Error(`bad point coordinate ${T}`);return m}function I(T){if(!(T instanceof E))throw new Error("Weierstrass Point expected")}function O(T){if(!c||!c.basises)throw new Error("no endo");return Fl(T,c.basises,o.ORDER)}let N=Oe((T,m)=>{let{X:y,Y:p,Z:S}=T;if(n.eql(S,n.ONE))return{x:y,y:p};let R=T.is0();m==null&&(m=R?n.ONE:n.inv(S));let L=n.mul(y,m),C=n.mul(p,m),B=n.mul(S,m);if(R)return{x:n.ZERO,y:n.ZERO};if(!n.eql(B,n.ONE))throw new Error("invZ was invalid");return{x:L,y:C}}),U=Oe(T=>{if(T.is0()){if(t.allowInfinityPoint&&!n.is0(T.Y))return;throw new Error("bad point: ZERO")}let{x:m,y}=T.toAffine();if(!n.isValid(m)||!n.isValid(y))throw new Error("bad point: x or y not field elements");if(!x(m,y))throw new Error("bad point: equation left != right");if(!T.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function v(T,m,y,p,S){return y=new E(n.mul(y.X,T),y.Y,y.Z),m=cr(p,m),y=cr(S,y),m.add(y)}class E{static BASE=new E(s.Gx,s.Gy,n.ONE);static ZERO=new E(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(m,y,p){this.X=w("x",m),this.Y=w("y",y,!0),this.Z=w("z",p),Object.freeze(this)}static CURVE(){return s}static fromAffine(m){let{x:y,y:p}=m||{};if(!m||!n.isValid(y)||!n.isValid(p))throw new Error("invalid affine point");if(m instanceof E)throw new Error("projective point not allowed");return n.is0(y)&&n.is0(p)?E.ZERO:new E(y,p,n.ONE)}static fromBytes(m){let y=E.fromAffine(h(k(m,void 0,"point")));return y.assertValidity(),y}static fromHex(m){return E.fromBytes(Vt(m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,y=!0){return M.createCache(this,m),y||this.multiply(Qr),this}assertValidity(){U(this)}hasEvenY(){let{y:m}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(m)}equals(m){I(m);let{X:y,Y:p,Z:S}=this,{X:R,Y:L,Z:C}=m,B=n.eql(n.mul(y,C),n.mul(R,S)),D=n.eql(n.mul(p,C),n.mul(L,S));return B&&D}negate(){return new E(this.X,n.neg(this.Y),this.Z)}double(){let{a:m,b:y}=s,p=n.mul(y,Qr),{X:S,Y:R,Z:L}=this,C=n.ZERO,B=n.ZERO,D=n.ZERO,P=n.mul(S,S),G=n.mul(R,R),W=n.mul(L,L),H=n.mul(S,R);return H=n.add(H,H),D=n.mul(S,L),D=n.add(D,D),C=n.mul(m,D),B=n.mul(p,W),B=n.add(C,B),C=n.sub(G,B),B=n.add(G,B),B=n.mul(C,B),C=n.mul(H,C),D=n.mul(p,D),W=n.mul(m,W),H=n.sub(P,W),H=n.mul(m,H),H=n.add(H,D),D=n.add(P,P),P=n.add(D,P),P=n.add(P,W),P=n.mul(P,H),B=n.add(B,P),W=n.mul(R,L),W=n.add(W,W),P=n.mul(W,H),C=n.sub(C,P),D=n.mul(W,G),D=n.add(D,D),D=n.add(D,D),new E(C,B,D)}add(m){I(m);let{X:y,Y:p,Z:S}=this,{X:R,Y:L,Z:C}=m,B=n.ZERO,D=n.ZERO,P=n.ZERO,G=s.a,W=n.mul(s.b,Qr),H=n.mul(y,R),Y=n.mul(p,L),it=n.mul(S,C),Lt=n.add(y,p),X=n.add(R,L);Lt=n.mul(Lt,X),X=n.add(H,Y),Lt=n.sub(Lt,X),X=n.add(y,S);let ut=n.add(R,C);return X=n.mul(X,ut),ut=n.add(H,it),X=n.sub(X,ut),ut=n.add(p,S),B=n.add(L,C),ut=n.mul(ut,B),B=n.add(Y,it),ut=n.sub(ut,B),P=n.mul(G,X),B=n.mul(W,it),P=n.add(B,P),B=n.sub(Y,P),P=n.add(Y,P),D=n.mul(B,P),Y=n.add(H,H),Y=n.add(Y,H),it=n.mul(G,it),X=n.mul(W,X),Y=n.add(Y,it),it=n.sub(H,it),it=n.mul(G,it),X=n.add(X,it),H=n.mul(Y,X),D=n.add(D,H),H=n.mul(ut,X),B=n.mul(Lt,B),B=n.sub(B,H),H=n.mul(Lt,Y),P=n.mul(ut,P),P=n.add(P,H),new E(B,D,P)}subtract(m){return this.add(m.negate())}is0(){return this.equals(E.ZERO)}multiply(m){let{endo:y}=t;if(!o.isValidNot0(m))throw new Error("invalid scalar: out of range");let p,S,R=L=>M.cached(this,L,C=>de(E,C));if(y){let{k1neg:L,k1:C,k2neg:B,k2:D}=O(m),{p:P,f:G}=R(C),{p:W,f:H}=R(D);S=G.add(H),p=v(y.beta,P,W,L,B)}else{let{p:L,f:C}=R(m);p=L,S=C}return de(E,[p,S])[0]}multiplyUnsafe(m){let{endo:y}=t,p=this;if(!o.isValid(m))throw new Error("invalid scalar: out of range");if(m===Ft||p.is0())return E.ZERO;if(m===qe)return p;if(M.hasCache(this))return this.multiply(m);if(y){let{k1neg:S,k1:R,k2neg:L,k2:C}=O(m),{p1:B,p2:D}=Qi(E,p,R,C);return v(y.beta,B,D,S,L)}else return M.unsafe(p,m)}toAffine(m){return N(this,m)}isTorsionFree(){let{isTorsionFree:m}=t;return i===qe?!0:m?m(E,this):M.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:m}=t;return i===qe?this:m?m(E,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(m=!0){return zt(m,"isCompressed"),this.assertValidity(),g(E,this,m)}toHex(m=!0){return qt(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let K=o.BITS,M=new ke(E,t.endo?Math.ceil(K/2):K);return E.BASE.precompute(8),E}function Ra(r){return Uint8Array.of(r?2:3)}function Ba(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function $l(r,t={}){let{Fn:e}=r,n=t.randomBytes||Te,o=Object.assign(Ba(r.Fp,e),{seed:To(e.ORDER)});function s(g){try{let h=e.fromBytes(g);return e.isValidNot0(h)}catch{return!1}}function i(g,h){let{publicKey:_,publicKeyUncompressed:x}=o;try{let b=g.length;return h===!0&&b!==_||h===!1&&b!==x?!1:!!r.fromBytes(g)}catch{return!1}}function a(g=n(o.seed)){return Co(k(g,o.seed,"seed"),e.ORDER)}function c(g,h=!0){return r.BASE.multiply(e.fromBytes(g)).toBytes(h)}function u(g){let{secretKey:h,publicKey:_,publicKeyUncompressed:x}=o;if(!ie(g)||"_lengths"in e&&e._lengths||h===_)return;let b=k(g,void 0,"key").length;return b===_||b===x}function l(g,h,_=!0){if(u(g)===!0)throw new Error("first arg must be private key");if(u(h)===!1)throw new Error("second arg must be public key");let x=e.fromBytes(g);return r.fromBytes(h).multiply(x).toBytes(_)}let f={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},d=Hr(a,c);return Object.freeze({getPublicKey:c,getSharedSecret:l,keygen:d,Point:r,utils:f,lengths:o})}function La(r,t,e={}){Pr(t),ee(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let n=e.randomBytes||Te,o=e.hmac||((y,p)=>ms(t,y,p)),{Fp:s,Fn:i}=r,{ORDER:a,BITS:c}=i,{keygen:u,getPublicKey:l,getSharedSecret:f,utils:d,lengths:g}=$l(r,e),h={prehash:!0,lowS:typeof e.lowS=="boolean"?e.lowS:!0,format:"compact",extraEntropy:!1},_=a*_a<s.ORDER;function x(y){let p=a>>qe;return y>p}function b(y,p){if(!i.isValidNot0(p))throw new Error(`invalid signature ${y}: out of range 1..Point.Fn.ORDER`);return p}function A(){if(_)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function w(y,p){bs(p);let S=g.signature,R=p==="compact"?S:p==="recovered"?S+1:void 0;return k(y,R)}class I{r;s;recovery;constructor(p,S,R){if(this.r=b("r",p),this.s=b("s",S),R!=null){if(A(),![0,1,2,3].includes(R))throw new Error("invalid recovery id");this.recovery=R}Object.freeze(this)}static fromBytes(p,S=h.format){w(p,S);let R;if(S==="der"){let{r:D,s:P}=oe.toSig(k(p));return new I(D,P)}S==="recovered"&&(R=p[0],S="compact",p=p.subarray(1));let L=g.signature/2,C=p.subarray(0,L),B=p.subarray(L,L*2);return new I(i.fromBytes(C),i.fromBytes(B),R)}static fromHex(p,S){return this.fromBytes(Vt(p),S)}assertRecovery(){let{recovery:p}=this;if(p==null)throw new Error("invalid recovery id: must be present");return p}addRecoveryBit(p){return new I(this.r,this.s,p)}recoverPublicKey(p){let{r:S,s:R}=this,L=this.assertRecovery(),C=L===2||L===3?S+a:S;if(!s.isValid(C))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let B=s.toBytes(C),D=r.fromBytes(wt(Ra((L&1)===0),B)),P=i.inv(C),G=N(k(p,void 0,"msgHash")),W=i.create(-G*P),H=i.create(R*P),Y=r.BASE.multiplyUnsafe(W).add(D.multiplyUnsafe(H));if(Y.is0())throw new Error("invalid recovery: point at infinify");return Y.assertValidity(),Y}hasHighS(){return x(this.s)}toBytes(p=h.format){if(bs(p),p==="der")return Vt(oe.hexFromSig(this));let{r:S,s:R}=this,L=i.toBytes(S),C=i.toBytes(R);return p==="recovered"?(A(),wt(Uint8Array.of(this.assertRecovery()),L,C)):wt(L,C)}toHex(p){return qt(this.toBytes(p))}}let O=e.bits2int||function(p){if(p.length>8192)throw new Error("input is too large");let S=De(p),R=p.length*8-c;return R>0?S>>BigInt(R):S},N=e.bits2int_modN||function(p){return i.create(O(p))},U=ir(c);function v(y){return sr("num < 2^"+c,y,Ft,U),i.toBytes(y)}function E(y,p){return k(y,void 0,"message"),p?k(t(y),void 0,"prehashed message"):y}function K(y,p,S){let{lowS:R,prehash:L,extraEntropy:C}=ys(S,h);y=E(y,L);let B=N(y),D=i.fromBytes(p);if(!i.isValidNot0(D))throw new Error("invalid private key");let P=[v(D),v(B)];if(C!=null&&C!==!1){let Y=C===!0?n(g.secretKey):C;P.push(k(Y,void 0,"extraEntropy"))}let G=wt(...P),W=B;function H(Y){let it=O(Y);if(!i.isValidNot0(it))return;let Lt=i.inv(it),X=r.BASE.multiply(it).toAffine(),ut=i.create(X.x);if(ut===Ft)return;let Rr=i.create(Lt*i.create(W+ut*D));if(Rr===Ft)return;let zs=(X.x===ut?0:2)|Number(X.y&qe),Fs=Rr;return R&&x(Rr)&&(Fs=i.neg(Rr),zs^=1),new I(ut,Fs,_?void 0:zs)}return{seed:G,k2sig:H}}function M(y,p,S={}){let{seed:R,k2sig:L}=K(y,p,S);return Pi(t.outputLen,i.BYTES,o)(R,L).toBytes(S.format)}function T(y,p,S,R={}){let{lowS:L,prehash:C,format:B}=ys(R,h);if(S=k(S,void 0,"publicKey"),p=E(p,C),!ie(y)){let D=y instanceof I?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+D)}w(y,B);try{let D=I.fromBytes(y,B),P=r.fromBytes(S);if(L&&D.hasHighS())return!1;let{r:G,s:W}=D,H=N(p),Y=i.inv(W),it=i.create(H*Y),Lt=i.create(G*Y),X=r.BASE.multiplyUnsafe(it).add(P.multiplyUnsafe(Lt));return X.is0()?!1:i.create(X.x)===G}catch{return!1}}function m(y,p,S={}){let{prehash:R}=ys(S,h);return p=E(p,R),I.fromBytes(y,"recovered").recoverPublicKey(p).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:f,utils:d,lengths:g,Point:r,sign:M,verify:T,recoverPublicKey:m,Signature:I,hash:t})}var ws={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Zl={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Ta=BigInt(2);function Gl(r){let t=ws.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%t,l=u*u*r%t,f=Z(l,e,t)*l%t,d=Z(f,e,t)*l%t,g=Z(d,Ta,t)*u%t,h=Z(g,o,t)*g%t,_=Z(h,s,t)*h%t,x=Z(_,a,t)*_%t,b=Z(x,c,t)*x%t,A=Z(b,a,t)*_%t,w=Z(A,e,t)*l%t,I=Z(w,i,t)*h%t,O=Z(I,n,t)*u%t,N=Z(O,Ta,t);if(!xs.eql(xs.sqr(N),r))throw new Error("Cannot find square root");return N}var xs=Ke(ws.p,{sqrt:Gl}),Yl=Ia(ws,{Fp:xs,endo:Zl}),Ve=La(Yl,Ce);function Ca(r,t,e,n){let o=je.digest(e instanceof Uint8Array?e:e.subarray());if(Wr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ve.verify(t,s,r,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new ur(String(s))});try{return n?.signal?.throwIfAborted(),Ve.verify(t,o.digest,r,{prehash:!1,format:"der"})}catch(s){throw new ur(String(s))}}var Jr=class{type="secp256k1";raw;_key;constructor(t){this._key=Oa(t),this.raw=Da(this._key)}toMultihash(){return It.digest(St(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return Q.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:$(this.raw,t.raw)}verify(t,e,n){return Ca(this._key,e,t,n)}};function Es(r){return new Jr(r)}function Da(r){return Ve.Point.fromBytes(r).toBytes()}function Oa(r){try{return Ve.Point.fromBytes(r),r}catch(t){throw new we(String(t))}}function tn(r,t){let{Type:e,Data:n}=Kt.decode(r),o=n??new Uint8Array;switch(e){case tt.RSA:return ds(o,t);case tt.Ed25519:return Mo(o);case tt.secp256k1:return Es(o);case tt.ECDSA:return po(o);default:throw new se}}function Ka(r){let{Type:t,Data:e}=Kt.decode(r.digest),n=e??new Uint8Array;switch(t){case tt.Ed25519:return Mo(n);case tt.secp256k1:return Es(n);case tt.ECDSA:return po(n);default:throw new se}}function St(r){return Kt.encode({Type:tt[r.type],Data:r.raw})}var Pa=Symbol.for("nodejs.util.inspect.custom"),Xl=114,mr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Tr]=!0;toString(){return this.string==null&&(this.string=Q.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return et.createV1(Xl,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return $(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return $(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Pa](){return`PeerId(${this.toString()})`}},yr=class extends mr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},br=class extends mr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},gr=class extends mr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},jl=2336,xr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=It.digest(z(this.url))}[Pa](){return`PeerId(${this.url})`}[Tr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return et.createV1(jl,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=V(t)),t.toString()===this.toString())}};var Ql=114,ka=2336;function Na(r){if(r.type==="Ed25519")return new br({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new gr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new yr({multihash:r.toCID().multihash,publicKey:r});throw new se}function vs(r){if(tf(r))return new yr({multihash:r});if(Jl(r))try{let t=Ka(r);if(t.type==="Ed25519")return new br({multihash:r,publicKey:t});if(t.type==="secp256k1")return new gr({multihash:r,publicKey:t})}catch{let e=V(r.digest);return new xr(new URL(e))}throw new Lr("Supplied PeerID Multihash is invalid")}function en(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==Ql&&r.code!==ka)throw new Br("Supplied PeerID CID is invalid");if(r.code===ka){let t=V(r.multihash.digest);return new xr(new URL(t))}return vs(r.multihash)}function Jl(r){return r.code===It.code}function tf(r){return r.code===je.code}var wr;(function(r){let t;r.codec=()=>(t==null&&(t=yt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.publicKey!=null&&e.publicKey.byteLength>0&&(n.uint32(10),n.bytes(e.publicKey)),e.payloadType!=null&&e.payloadType.byteLength>0&&(n.uint32(18),n.bytes(e.payloadType)),e.payload!=null&&e.payload.byteLength>0&&(n.uint32(26),n.bytes(e.payload)),e.signature!=null&&e.signature.byteLength>0&&(n.uint32(42),n.bytes(e.signature)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={publicKey:rt(0),payloadType:rt(0),payload:rt(0),signature:rt(0)},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.publicKey=e.bytes();break}case 2:{s.payloadType=e.bytes();break}case 3:{s.payload=e.bytes();break}case 5:{s.signature=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>mt(e,r.codec()),r.decode=(e,n)=>pt(e,r.codec(),n)})(wr||(wr={}));var rn=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var He=class r{static createFromProtobuf=t=>{let e=wr.decode(t),n=tn(e.publicKey);return new r({publicKey:n,payloadType:e.payloadType,payload:e.payload,signature:e.signature})};static seal=async(t,e,n)=>{if(e==null)throw new Error("Missing private key");let o=t.domain,s=t.codec,i=t.marshal(),a=Ua(o,s,i),c=await e.sign(a.subarray(),n);return new r({publicKey:e.publicKey,payloadType:s,payload:i,signature:c})};static openAndCertify=async(t,e,n)=>{let o=r.createFromProtobuf(t);if(!await o.validate(e,n))throw new rn("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:e,payloadType:n,payload:o,signature:s}=t;this.publicKey=e,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=wr.encode({publicKey:St(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return t==null?!1:$(this.marshal(),t.marshal())}async validate(t,e){let n=Ua(t,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,e)}},Ua=(r,t,e)=>{let n=z(r),o=Zr(n.byteLength),s=Zr(t.length),i=Zr(e.length);return new dt(o,n,s,t,i,e)};var ct=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Wt=class extends Error{static name="ValidationError";name="ValidationError"},nn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},on=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var sn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}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(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,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 l=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let d=Number.parseInt(f,t);if(!Number.isNaN(d))return d});if(l===void 0)break;if(s*=t,s+=l,s>u||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[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];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return e.set(s.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var ef=45,rf=15,an=new sn;function Ma(r){if(!(r.length>rf))return an.new(r).parseWith(()=>an.readIPv4Addr())}function qa(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>ef))return an.new(r).parseWith(()=>an.readIPv6Addr())}function cn(r){return!!Ma(r)}function Va(r){return!!qa(r)}function As(r){return t=>V(t,r)}function _s(r){return t=>z(t,r)}function ze(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function ye(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function Ha(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=z(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ye(n);return kt([e,o],e.length+o.length)}function za(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=Tt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ye(n);return kt([e,o],e.length+o.length)}function Is(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=V(t,"base32"),o=ze(e);return`${n}:${o}`}var Rs=function(r){r=r.toString().trim();let t=new Uint8Array(4);return r.split(/\./g).forEach((e,n)=>{let o=parseInt(e,10);if(isNaN(o)||o<0||o>255)throw new ct("Invalid byte value in IP address");t[n]=o}),t},Fa=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=cn(e[n]),i;s&&(i=Rs(e[n]),e[n]=V(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,V(i.subarray(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let s=[n,1];for(n=9-e.length;n>0;n--)s.push("0");e.splice.apply(e,s)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){e[n]===""&&(e[n]="0");let s=parseInt(e[n],16);if(isNaN(s)||s<0||s>65535)throw new ct("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Wa=function(r){if(r.byteLength!==4)throw new ct("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},$a=function(r){if(r.byteLength!==16)throw new ct("IPv6 address was incorrect length");let t=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],s=r[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let e=t.join(":");try{let n=new URL(`http://[${e}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new ct(`Invalid IPv6 address "${e}"`)}};function Za(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new ct(`Invalid IPv6 address "${r}"`)}}var Ss=Object.values(Qe).map(r=>r.decoder),nf=(function(){let r=Ss[0].or(Ss[1]);return Ss.slice(2).forEach(t=>r=r.or(t)),r})();function Ga(r){return nf.decode(r)}function Ya(r){return t=>r.encoder.encode(t)}function of(r){if(parseInt(r).toString()!==r)throw new Wt("Value must be an integer")}function sf(r){if(r<0)throw new Wt("Value must be a positive integer, or zero")}function af(r){return t=>{if(t>r)throw new Wt(`Value must be smaller than or equal to ${r}`)}}function cf(...r){return t=>{for(let e of r)e(t)}}var Er=cf(of,sf,af(65535));var st=-1,Bs=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let e;if(typeof t=="string"?e=this.protocolsByName.get(t):e=this.protocolsByCode.get(t),e==null)throw new on(`Protocol ${t} was unknown`);return e}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(e=>{this.protocolsByName.set(e,t)})}removeProtocol(t){let e=this.protocolsByCode.get(t);e!=null&&(this.protocolsByCode.delete(e.code),this.protocolsByName.delete(e.name),e.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},$t=new Bs,Gf=[{code:4,name:"ip4",size:32,valueToBytes:Rs,bytesToValue:Wa,validate:r=>{if(!cn(r))throw new Wt(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ye,bytesToValue:ze,validate:Er},{code:273,name:"udp",size:16,valueToBytes:ye,bytesToValue:ze,validate:Er},{code:33,name:"dccp",size:16,valueToBytes:ye,bytesToValue:ze,validate:Er},{code:41,name:"ip6",size:128,valueToBytes:Fa,bytesToValue:$a,stringToValue:Za,validate:r=>{if(!Va(r))throw new Wt(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:st},{code:43,name:"ipcidr",size:8,bytesToValue:As("base10"),valueToBytes:_s("base10")},{code:53,name:"dns",size:st},{code:54,name:"dns4",size:st},{code:55,name:"dns6",size:st},{code:56,name:"dnsaddr",size:st},{code:132,name:"sctp",size:16,valueToBytes:ye,bytesToValue:ze,validate:Er},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:st,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:st,bytesToValue:As("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?_s("base58btc")(r):et.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Is,valueToBytes:Ha},{code:445,name:"onion3",size:296,bytesToValue:Is,valueToBytes:za},{code:446,name:"garlic64",size:st},{code:447,name:"garlic32",size:st},{code:448,name:"tls"},{code:449,name:"sni",size:st},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:st,bytesToValue:Ya(to),valueToBytes:Ga},{code:480,name:"http"},{code:481,name:"http-path",size:st,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.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:st}];Gf.forEach(r=>{$t.addProtocol(r)});function Xa(r){let t=[],e=0;for(;e<r.length;){let n=Wo(r,e),o=$t.getProtocol(n),s=_t(n),i=Yf(o,r,e+s),a=0;i>0&&o.size===st&&(a=_t(i));let c=s+a+i,u={code:n,name:o.name,bytes:r.subarray(e,e+c)};if(i>0){let l=e+s+a,f=r.subarray(l,l+i);u.value=o.bytesToValue?.(f)??V(f)}t.push(u),e+=c}return t}function ja(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=$t.getProtocol(n.code),s=_t(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??z(n.value),a=i.byteLength,o.size===st&&(c=_t(a)));let u=new Uint8Array(s+c+a),l=0;Ne(n.code,u,l),l+=s,i!=null&&(o.size===st&&(Ne(a,u,l),l+=c),u.set(i,l)),n.bytes=u}e.push(n.bytes),t+=n.bytes.byteLength}return kt(e,t)}function Qa(r){if(r.charAt(0)!=="/")throw new ct('String multiaddr must start with "/"');let t=[],e="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(e==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let c=$t.getProtocol(o);if(e==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",e="protocol";continue}else if(a)throw new ct(`Component ${o} was missing value`);e="value"}else if(e==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new ct(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}t.push(u),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new ct("Incomplete multiaddr");return t}function Ja(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=$t.getProtocol(t.code);if(e==null)throw new ct(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function Yf(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:Wo(t,e)}var Xf=Symbol.for("nodejs.util.inspect.custom"),Ts=Symbol.for("@multiformats/multiaddr");function jf(r){if(r==null&&(r="/"),ln(r))return r.getComponents();if(r instanceof Uint8Array)return Xa(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),Qa(r);if(Array.isArray(r))return r;throw new ct("Must be a string, Uint8Array, Component[], or another Multiaddr")}var un=class r{[Ts]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=jf(t),e.validate!==!1&&Qf(this)}get bytes(){return this.#r==null&&(this.#r=ja(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Ja(this.#t)),this.#e}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let e=new r(t);return new r([...this.#t,...e.getComponents()],{validate:!1})}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new nn(`Address ${this.toString()} does not contain subaddress: ${e}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(t){let e;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){e=n;break}return new r(this.#t.slice(0,e),{validate:!1})}equals(t){return $(this.bytes,t.bytes)}[Xf](){return`Multiaddr(${this.toString()})`}};function Qf(r){r.getComponents().forEach(t=>{let e=$t.getProtocol(t.code);t.value!=null&&e.validate?.(t.value)})}function ln(r){return!!r?.[Ts]}function be(r){return new un(r)}var tc="libp2p-peer-record",ec=Uint8Array.from([3,1]);var vr;(function(r){let t;(function(n){let o;n.codec=()=>(o==null&&(o=yt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.multiaddr!=null&&s.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(s.multiaddr)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={multiaddr:rt(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let l=s.uint32();switch(l>>>3){case 1:{c.multiaddr=s.bytes();break}default:{s.skipType(l&7);break}}}return c})),o),n.encode=s=>mt(s,n.codec()),n.decode=(s,i)=>pt(s,n.codec(),i)})(t=r.AddressInfo||(r.AddressInfo={}));let e;r.codec=()=>(e==null&&(e=yt((n,o,s={})=>{if(s.lengthDelimited!==!1&&o.fork(),n.peerId!=null&&n.peerId.byteLength>0&&(o.uint32(10),o.bytes(n.peerId)),n.seq!=null&&n.seq!==0n&&(o.uint32(16),o.uint64(n.seq)),n.addresses!=null)for(let i of n.addresses)o.uint32(26),r.AddressInfo.codec().encode(i,o);s.lengthDelimited!==!1&&o.ldelim()},(n,o,s={})=>{let i={peerId:rt(0),seq:0n,addresses:[]},a=o==null?n.len:n.pos+o;for(;n.pos<a;){let c=n.uint32();switch(c>>>3){case 1:{i.peerId=n.bytes();break}case 2:{i.seq=n.uint64();break}case 3:{if(s.limits?.addresses!=null&&i.addresses.length===s.limits.addresses)throw new me('Decode error - map field "addresses" had too many elements');i.addresses.push(r.AddressInfo.codec().decode(n,n.uint32(),{limits:s.limits?.addresses$}));break}default:{n.skipType(c&7);break}}}return i})),e),r.encode=n=>mt(n,r.codec()),r.decode=(n,o)=>pt(n,r.codec(),o)})(vr||(vr={}));function rc(r,t){let e=(n,o)=>n.toString().localeCompare(o.toString());return r.length!==t.length?!1:(t.sort(e),r.sort(e).every((n,o)=>t[o].equals(n)))}var ge=class r{static createFromProtobuf=t=>{let e=vr.decode(t),n=vs(Re(e.peerId)),o=(e.addresses??[]).map(i=>be(i.multiaddr)),s=e.seq;return new r({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=tc;static CODEC=ec;peerId;multiaddrs;seqNumber;domain=r.DOMAIN;codec=r.CODEC;marshaled;constructor(t){let{peerId:e,multiaddrs:n,seqNumber:o}=t;this.peerId=e,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=vr.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(t=>({multiaddr:t.bytes}))})),this.marshaled}equals(t){return!(!(t instanceof r)||!this.peerId.equals(t.peerId)||this.seqNumber!==t.seqNumber||!rc(this.multiaddrs,t.multiaddrs))}};function Jf(r){return r[Symbol.asyncIterator]!=null}function td(r){if(Jf(r))return(async()=>{let e=[];for await(let n of r)e.push(n);return e})();let t=[];for(let e of r)t.push(e);return t}var nc=td;function fn(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return e}var Sr=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[e,n]of t.entries())this.map.set(e.toString(),{key:e,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return fn(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((e,n)=>{t(e.value,e.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,e){this.map.set(t.toString(),{key:t,value:e})}keys(){return fn(this.map.values(),t=>t.key)}values(){return fn(this.map.values(),t=>t.value)}get size(){return this.map.size}};function dn(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var hn=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},Fe=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new hn(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new hn(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Cs=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function oc(r={}){return ed(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function ed(r,t){t=t??{};let e=t.onEnd,n=new Fe,o,s,i,a=dn(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((x,b)=>{s=A=>{s=null,n.push(A);try{x(r(n))}catch(w){b(w)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=dn()})}},u=x=>s!=null?s(x):(n.push(x),o),l=x=>(n=new Fe,s!=null?s({error:x}):(n.push({error:x}),o)),f=x=>{if(i)return o;if(t?.objectMode!==!0&&x?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:x})},d=x=>i?o:(i=!0,x!=null?l(x):u({done:!0})),g=()=>(n=new Fe,d(),{done:!0}),h=x=>(d(x),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:g,throw:h,push:f,end:d,get readableLength(){return n.size},onEmpty:async x=>{let b=x?.signal;if(b?.throwIfAborted(),n.isEmpty())return;let A,w;b!=null&&(A=new Promise((I,O)=>{w=()=>{O(new Cs)},b.addEventListener("abort",w)}));try{await Promise.race([a.promise,A])}finally{w!=null&&b!=null&&b?.removeEventListener("abort",w)}}},e==null)return o;let _=o;return o={[Symbol.asyncIterator](){return this},next(){return _.next()},throw(x){return _.throw(x),e!=null&&(e(x),e=void 0),{done:!0}},return(){return _.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(x){return _.end(x),e!=null&&(e(x),e=void 0),o},get readableLength(){return _.readableLength},onEmpty:x=>_.onEmpty(x)},o}var Ds=class extends Sr{metric;constructor(t){super();let{name:e,metrics:n}=t;this.metric=n.registerMetric(e),this.updateComponentMetric()}set(t,e){return super.set(t,e),this.updateComponentMetric(),this}delete(t){let e=super.delete(t);return this.updateComponentMetric(),e}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function Os(r){let{name:t,metrics:e}=r,n;return e!=null?n=new Ds({name:t,metrics:e}):n=new Sr,n}var vt=class extends Error{static name="AbortError";name="AbortError";constructor(t="The operation was aborted",...e){super(t,...e)}};async function pn(r,t,e,n){let o=new vt(n?.errorMessage);n?.errorCode!=null&&(o.code=n.errorCode);let s=n?.errorEvent??"error";return e?.aborted===!0?Promise.reject(o):new Promise((i,a)=>{function c(){Ps(e,"abort",f),Ps(r,t,u),Ps(r,s,l)}let u=d=>{try{if(n?.filter?.(d)===!1)return}catch(g){c(),a(g);return}c(),i(d)},l=d=>{if(c(),d instanceof Error){a(d);return}a(d.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.`))},f=()=>{c(),a(o)};Ks(e,"abort",f),Ks(r,t,u),Ks(r,s,l)})}function Ks(r,t,e){r!=null&&(sc(r)?r.addEventListener(t,e):r.addListener(t,e))}function Ps(r,t,e){r!=null&&(sc(r)?r.removeEventListener(t,e):r.removeListener(t,e))}function sc(r){return typeof r.addEventListener=="function"&&typeof r.removeEventListener=="function"}var mn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};var yn=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function ic(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new yn(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new yn(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var bn=class{deferred;signal;constructor(t){this.signal=t,this.deferred=Promise.withResolvers(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new vt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function rd(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var gn=class{id;fn;options;recipients;status;timeline;controller;constructor(t,e){this.id=rd(),this.status="queued",this.fn=t,this.options=e,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(t){this.controller.abort(t)}onAbort(){this.recipients.reduce((e,n)=>e&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new vt),this.cleanup())}async join(t={}){let e=new bn(t.signal);return this.recipients.push(e),t.signal?.addEventListener("abort",this.onAbort),e.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await ic(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(e=>{e.deferred.resolve(t)}),this.status="complete"}catch(t){this.recipients.forEach(e=>{e.deferred.reject(t)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(t=>{t.cleanup(),t.signal?.removeEventListener("abort",this.onAbort)})}};function ks(r,t){let e,n=function(){let o=function(){e=void 0,r()};clearTimeout(e),e=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(e)},n}var Ar=class extends ve{concurrency;maxSize;queue;pending;sort;autoStart;constructor(t={}){super(),this.concurrency=t.concurrency??Number.POSITIVE_INFINITY,this.maxSize=t.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.autoStart=t.autoStart??!0,this.sort=t.sort,this.queue=[],this.emitEmpty=ks(this.emitEmpty.bind(this),1),this.emitIdle=ks(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 t;for(let e of this.queue)if(e.status==="queued"){t=e;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let e=0;e<this.queue.length;e++)if(this.queue[e]===t){this.queue.splice(e,1);break}this.pending--,this.safeDispatchEvent("next"),this.autoStart&&this.tryToStartAnother()}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}start(){this.autoStart===!1&&(this.autoStart=!0,this.tryToStartAnother())}pause(){this.autoStart=!1}async add(t,e){if(e?.signal?.throwIfAborted(),this.size===this.maxSize)throw new mn;let n=new gn(t,e);return this.enqueue(n),this.safeDispatchEvent("add"),this.autoStart&&this.tryToStartAnother(),n.join(e).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(t=>{t.abort(new vt)}),this.clear()}async onEmpty(t){this.size!==0&&await pn(this,"empty",t?.signal)}async onSizeLessThan(t,e){this.size<t||await pn(this,"next",e?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await pn(this,"idle",t?.signal)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(t){t?.signal?.throwIfAborted();let e=oc({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),e.end(c)},o=c=>{c.detail!=null&&e.push(c.detail.result)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new vt("Queue aborted"))};this.addEventListener("success",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*e}finally{this.removeEventListener("success",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};var xn="lock:worker:request-read",wn="lock:worker:abort-read-request",En="lock:worker:release-read",vn="lock:master:grant-read",Sn="lock:master:error-read",An="lock:worker:request-write",_n="lock:worker:abort-write-request",In="lock:worker:release-write",Rn="lock:master:grant-write",Bn="lock:master:error-write",Ln="lock:worker:finalize",Tn="mortice",ac={singleProcess:!1};var Ns=(r,t,e,n,o,s,i,a,c)=>u=>{if(u.data==null)return;let l={type:u.data.type,name:u.data.name,identifier:u.data.identifier};l.type===o&&r.safeDispatchEvent(e,{detail:{name:l.name,identifier:l.identifier,handler:async()=>{t.postMessage({type:c,name:l.name,identifier:l.identifier}),await new Promise(f=>{let d=g=>{if(g?.data==null)return;let h={type:g.data.type,name:g.data.name,identifier:g.data.identifier};h.type===a&&h.identifier===l.identifier&&(t.removeEventListener("message",d),f())};t.addEventListener("message",d)})},onError:f=>{t.postMessage({type:i,name:l.name,identifier:l.identifier,error:{message:f.message,name:f.name,stack:f.stack}})}}}),l.type===s&&r.safeDispatchEvent(n,{detail:{name:l.name,identifier:l.identifier}}),l.type===Ln&&r.safeDispatchEvent("finalizeRequest",{detail:{name:l.name}})};var cc=(r=10)=>Math.random().toString().substring(2,r+2);var Cn=class{name;channel;constructor(t){this.name=t,this.channel=new BroadcastChannel(Tn)}readLock(t){return this.sendRequest(xn,wn,vn,Sn,En,t)}writeLock(t){return this.sendRequest(An,_n,Rn,Bn,In,t)}finalize(){this.channel.postMessage({type:Ln,name:this.name}),this.channel.close()}async sendRequest(t,e,n,o,s,i){i?.signal?.throwIfAborted();let a=cc();return this.channel.postMessage({type:t,identifier:a,name:this.name}),new Promise((c,u)=>{let l=()=>{this.channel.postMessage({type:e,identifier:a,name:this.name})};i?.signal?.addEventListener("abort",l,{once:!0});let f=d=>{if(d.data?.identifier===a&&(d.data?.type===n&&(this.channel.removeEventListener("message",f),i?.signal?.removeEventListener("abort",l),c(()=>{this.channel.postMessage({type:s,identifier:a,name:this.name})})),d.data.type===o)){this.channel.removeEventListener("message",f),i?.signal?.removeEventListener("abort",l);let g=new Error;d.data.error!=null&&(g.message=d.data.error.message,g.name=d.data.error.name,g.stack=d.data.error.stack),u(g)}};this.channel.addEventListener("message",f)})}};var uc=r=>{if(r=Object.assign({},ac,r),!!globalThis.document||r.singleProcess){let e=new BroadcastChannel(Tn),n=new ve;return e.addEventListener("message",Ns(n,e,"requestReadLock","abortReadLockRequest",xn,wn,Sn,En,vn)),e.addEventListener("message",Ns(n,e,"requestWriteLock","abortWriteLockRequest",An,_n,Bn,In,Rn)),n}return new Cn(r.name)};var xe=new Map,_r;function lc(r){return typeof r?.readLock=="function"&&typeof r?.writeLock=="function"}function nd(r){if(_r==null&&(_r=uc(r),!lc(_r))){let t=_r;t.addEventListener("requestReadLock",e=>{let n=e.detail.name,o=e.detail.identifier,s=xe.get(n);if(s==null)return;let i=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==o||i.abort()};t.addEventListener("abortReadLockRequest",a),s.readLock({signal:i.signal}).then(async c=>{await e.detail.handler().finally(()=>{c()})}).catch(c=>{e.detail.onError(c)}).finally(()=>{t.removeEventListener("abortReadLockRequest",a)})}),t.addEventListener("requestWriteLock",e=>{let n=e.detail.name,o=e.detail.identifier,s=xe.get(n);if(s==null)return;let i=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==o||i.abort()};t.addEventListener("abortWriteLockRequest",a),s.writeLock({signal:i.signal}).then(async c=>{await e.detail.handler().finally(()=>{c()})}).catch(c=>{e.detail.onError(c)}).finally(()=>{t.removeEventListener("abortWriteLockRequest",a)})}),t.addEventListener("finalizeRequest",e=>{let n=e.detail.name,o=xe.get(n);o?.finalize()})}return _r}async function Us(r,t){let e,n,o=new Promise((i,a)=>{e=i,n=a}),s=()=>{n(new vt)};return t?.signal?.addEventListener("abort",s,{once:!0}),r.add(async()=>{await new Promise(i=>{e(()=>{t?.signal?.removeEventListener("abort",s),i()})})},{signal:t?.signal}).catch(i=>{n(i)}),o}var fc=(r,t)=>{let e=xe.get(r);if(e!=null)return e;let n=nd(t);if(lc(n))return e=n,xe.set(r,e),e;let o=new Ar({concurrency:1}),s;return e={async readLock(i){if(s!=null)return Us(s,i);s=new Ar({concurrency:t.concurrency,autoStart:!1});let a=s,c=Us(s,i);return o.add(async()=>{a.start(),await a.onIdle().then(()=>{s===a&&(s=null)})}),c},async writeLock(i){return s=null,Us(o,i)},finalize:()=>{xe.delete(r)},queue:o},xe.set(r,e),t.autoFinalize===!0&&o.addEventListener("idle",()=>{e.finalize()},{once:!0}),e};var od={name:"lock",concurrency:1/0,singleProcess:!1,autoFinalize:!1};function Ms(r){let t=Object.assign({},od,r);return fc(t.name,t)}var Zt;(function(r){let t;(function(o){let s;o.codec=()=>(s==null&&(s=yt((i,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),i.key!=null&&i.key!==""&&(a.uint32(10),a.string(i.key)),i.value!=null&&i.value.byteLength>0&&(a.uint32(18),a.bytes(i.value)),c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let u={key:"",value:rt(0)},l=a==null?i.len:i.pos+a;for(;i.pos<l;){let f=i.uint32();switch(f>>>3){case 1:{u.key=i.string();break}case 2:{u.value=i.bytes();break}default:{i.skipType(f&7);break}}}return u})),s),o.encode=i=>mt(i,o.codec()),o.decode=(i,a)=>pt(i,o.codec(),a)})(t=r.Peer$metadataEntry||(r.Peer$metadataEntry={}));let e;(function(o){let s;o.codec=()=>(s==null&&(s=yt((i,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),i.key!=null&&i.key!==""&&(a.uint32(10),a.string(i.key)),i.value!=null&&(a.uint32(18),On.codec().encode(i.value,a)),c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let u={key:""},l=a==null?i.len:i.pos+a;for(;i.pos<l;){let f=i.uint32();switch(f>>>3){case 1:{u.key=i.string();break}case 2:{u.value=On.codec().decode(i,i.uint32(),{limits:c.limits?.value});break}default:{i.skipType(f&7);break}}}return u})),s),o.encode=i=>mt(i,o.codec()),o.decode=(i,a)=>pt(i,o.codec(),a)})(e=r.Peer$tagsEntry||(r.Peer$tagsEntry={}));let n;r.codec=()=>(n==null&&(n=yt((o,s,i={})=>{if(i.lengthDelimited!==!1&&s.fork(),o.addresses!=null)for(let a of o.addresses)s.uint32(10),Dn.codec().encode(a,s);if(o.protocols!=null)for(let a of o.protocols)s.uint32(18),s.string(a);if(o.publicKey!=null&&(s.uint32(34),s.bytes(o.publicKey)),o.peerRecordEnvelope!=null&&(s.uint32(42),s.bytes(o.peerRecordEnvelope)),o.metadata!=null&&o.metadata.size!==0)for(let[a,c]of o.metadata.entries())s.uint32(50),r.Peer$metadataEntry.codec().encode({key:a,value:c},s);if(o.tags!=null&&o.tags.size!==0)for(let[a,c]of o.tags.entries())s.uint32(58),r.Peer$tagsEntry.codec().encode({key:a,value:c},s);o.updated!=null&&(s.uint32(64),s.uint64Number(o.updated)),i.lengthDelimited!==!1&&s.ldelim()},(o,s,i={})=>{let a={addresses:[],protocols:[],metadata:new Map,tags:new Map},c=s==null?o.len:o.pos+s;for(;o.pos<c;){let u=o.uint32();switch(u>>>3){case 1:{if(i.limits?.addresses!=null&&a.addresses.length===i.limits.addresses)throw new me('Decode error - map field "addresses" had too many elements');a.addresses.push(Dn.codec().decode(o,o.uint32(),{limits:i.limits?.addresses$}));break}case 2:{if(i.limits?.protocols!=null&&a.protocols.length===i.limits.protocols)throw new me('Decode error - map field "protocols" had too many elements');a.protocols.push(o.string());break}case 4:{a.publicKey=o.bytes();break}case 5:{a.peerRecordEnvelope=o.bytes();break}case 6:{if(i.limits?.metadata!=null&&a.metadata.size===i.limits.metadata)throw new dr('Decode error - map field "metadata" had too many elements');let l=r.Peer$metadataEntry.codec().decode(o,o.uint32());a.metadata.set(l.key,l.value);break}case 7:{if(i.limits?.tags!=null&&a.tags.size===i.limits.tags)throw new dr('Decode error - map field "tags" had too many elements');let l=r.Peer$tagsEntry.codec().decode(o,o.uint32(),{limits:{value:i.limits?.tags$value}});a.tags.set(l.key,l.value);break}case 8:{a.updated=o.uint64Number();break}default:{o.skipType(u&7);break}}}return a})),n),r.encode=o=>mt(o,r.codec()),r.decode=(o,s)=>pt(o,r.codec(),s)})(Zt||(Zt={}));var Dn;(function(r){let t;r.codec=()=>(t==null&&(t=yt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.multiaddr!=null&&e.multiaddr.byteLength>0&&(n.uint32(10),n.bytes(e.multiaddr)),e.isCertified!=null&&(n.uint32(16),n.bool(e.isCertified)),e.observed!=null&&(n.uint32(24),n.uint64Number(e.observed)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={multiaddr:rt(0)},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.multiaddr=e.bytes();break}case 2:{s.isCertified=e.bool();break}case 3:{s.observed=e.uint64Number();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>mt(e,r.codec()),r.decode=(e,n)=>pt(e,r.codec(),n)})(Dn||(Dn={}));var On;(function(r){let t;r.codec=()=>(t==null&&(t=yt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.value!=null&&e.value!==0&&(n.uint32(8),n.uint32(e.value)),e.expiry!=null&&(n.uint32(16),n.uint64(e.expiry)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={value:0},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.value=e.uint32();break}case 2:{s.expiry=e.uint64();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>mt(e,r.codec()),r.decode=(e,n)=>pt(e,r.codec(),n)})(On||(On={}));function sd(r,t){if(r.publicKey!=null||t.publicKey==null)return r;let e;r.type==="RSA"&&(e=r.toMultihash());let n=tn(t.publicKey,e);return Na(n)}function dc(r,t,e){let n=Zt.decode(t);return We(r,n,e)}function We(r,t,e){let n=new Map,o=BigInt(Date.now());for(let[s,i]of t.tags.entries())i.expiry!=null&&i.expiry<o||n.set(s,i);return{...t,id:sd(r,t),addresses:t.addresses.filter(({observed:s})=>s!=null&&s>Date.now()-e).map(({multiaddr:s,isCertified:i})=>({multiaddr:be(s),isCertified:i??!1})),metadata:t.metadata,peerRecordEnvelope:t.peerRecordEnvelope??void 0,tags:n}}function hc(r,t){return id(r.addresses,t.addresses)&&ad(r.protocols,t.protocols)&&cd(r.publicKey,t.publicKey)&&ud(r.peerRecordEnvelope,t.peerRecordEnvelope)&&ld(r.metadata,t.metadata)&&fd(r.tags,t.tags)}function id(r,t){return mc(r,t,(e,n)=>!(e.isCertified!==n.isCertified||!$(e.multiaddr,n.multiaddr)))}function ad(r,t){return mc(r,t,(e,n)=>e===n)}function cd(r,t){return pc(r,t)}function ud(r,t){return pc(r,t)}function ld(r,t){return yc(r,t,(e,n)=>$(e,n))}function fd(r,t){return yc(r,t,(e,n)=>e.value===n.value&&e.expiry===n.expiry)}function pc(r,t){return r==null&&t==null?!0:r!=null&&t!=null?$(r,t):!1}function mc(r,t,e){if(r.length!==t.length)return!1;for(let n=0;n<r.length;n++)if(!e(r[n],t[n]))return!1;return!0}function yc(r,t,e){if(r.size!==t.size)return!1;for(let[n,o]of r.entries()){let s=t.get(n);if(s==null||!e(o,s))return!1}return!0}var Gt="/",bc=new TextEncoder().encode(Gt),Kn=bc[0],Pn=class r{_buf;constructor(t,e){if(typeof t=="string")this._buf=z(t);else if(t instanceof Uint8Array)this._buf=t;else throw new Error("Invalid key, should be String of Uint8Array");if(e==null&&(e=!0),e&&this.clean(),this._buf.byteLength===0||this._buf[0]!==Kn)throw new Error("Invalid key")}toString(t="utf8"){return V(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new r(t.join(Gt))}static random(){return new r(Math.random().toString().substring(2))}static asKey(t){return t instanceof Uint8Array||typeof t=="string"?new r(t):typeof t.uint8Array=="function"?new r(t.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=bc),this._buf[0]!==Kn){let t=new Uint8Array(this._buf.byteLength+1);t.fill(Kn,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Kn;)this._buf=this._buf.subarray(0,-1)}less(t){let e=this.list(),n=t.list();for(let o=0;o<e.length;o++){if(n.length<o+1)return!1;let s=e[o],i=n[o];if(s<i)return!0;if(s>i)return!1}return e.length<n.length}reverse(){return r.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let t=this.namespaces();return t[t.length-1]}list(){return this.toString().split(Gt).slice(1)}type(){return dd(this.baseNamespace())}name(){return hd(this.baseNamespace())}instance(t){return new r(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(Gt)||(t+=Gt),t+=this.type(),new r(t)}parent(){let t=this.list();return t.length===1?new r(Gt):new r(t.slice(0,-1).join(Gt))}child(t){return this.toString()===Gt?t:t.toString()===Gt?this:new r(this.toString()+t.toString(),!1)}isAncestorOf(t){return t.toString()===this.toString()?!1:t.toString().startsWith(this.toString())}isDecendantOf(t){return t.toString()===this.toString()?!1:this.toString().startsWith(t.toString())}isTopLevel(){return this.list().length===1}concat(...t){return r.withNamespaces([...this.namespaces(),...pd(t.map(e=>e.namespaces()))])}};function dd(r){let t=r.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function hd(r){let t=r.split(":");return t[t.length-1]}function pd(r){return[].concat(...r)}var qs="/peers/";function Ir(r){if(!Ee(r)||r.type==null)throw new q("Invalid PeerId");let t=r.toCID().toString();return new Pn(`${qs}${t}`)}async function gc(r,t,e,n,o){let s=new Map;for(let i of e){if(i==null)continue;if(i.multiaddr instanceof Uint8Array&&(i.multiaddr=be(i.multiaddr)),!ln(i.multiaddr))throw new q("Multiaddr was invalid");if(!await t(r,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 r.equals(c)&&(a=a.decapsulate(be(`/p2p/${r}`))),{isCertified:i,multiaddr:a.bytes}})}async function Nn(r,t,e,n){if(t==null)throw new q("Invalid PeerData");if(t.publicKey!=null&&r.publicKey!=null&&!t.publicKey.equals(r.publicKey))throw new q("publicKey bytes do not match peer id publicKey bytes");let o=n.existingPeer?.peer;if(o!=null&&!r.equals(o.id))throw new q("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(e==="patch"){if((t.multiaddrs!=null||t.addresses!=null)&&(s=[],t.multiaddrs!=null&&s.push(...t.multiaddrs.map(d=>({isCertified:!1,multiaddr:d}))),t.addresses!=null&&s.push(...t.addresses)),t.protocols!=null&&(i=new Set(t.protocols)),t.metadata!=null){let d=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);a=kn(d,{validate:xc})}if(t.tags!=null){let d=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags);c=kn(d,{validate:wc,map:Ec})}t.peerRecordEnvelope!=null&&(u=t.peerRecordEnvelope)}if(e==="merge"){if(t.multiaddrs!=null&&s.push(...t.multiaddrs.map(d=>({isCertified:!1,multiaddr:d}))),t.addresses!=null&&s.push(...t.addresses),t.protocols!=null&&(i=new Set([...i,...t.protocols])),t.metadata!=null){let d=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);for(let[g,h]of d)h==null?a.delete(g):a.set(g,h);a=kn([...a.entries()],{validate:xc})}if(t.tags!=null){let d=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags),g=new Map(c);for(let[h,_]of d)_==null?g.delete(h):g.set(h,_);c=kn([...g.entries()],{validate:wc,map:Ec})}t.peerRecordEnvelope!=null&&(u=t.peerRecordEnvelope)}let l;o?.id.publicKey!=null?l=St(o.id.publicKey):t.publicKey!=null?l=St(t.publicKey):r.publicKey!=null&&(l=St(r.publicKey));let f={addresses:await gc(r,n.addressFilter??(async()=>!0),s,n.existingPeer?.peerPB.addresses,n),protocols:[...i.values()].sort((d,g)=>d.localeCompare(g)),metadata:a,tags:c,publicKey:l,peerRecordEnvelope:u};return f.addresses.forEach(d=>{d.observed=n.existingPeer?.peerPB.addresses?.find(g=>$(g.multiaddr,g.multiaddr))?.observed??Date.now()}),r.type!=="RSA"&&delete f.publicKey,f}function kn(r,t){let e=new Map;for(let[n,o]of r)o!=null&&t.validate(n,o);for(let[n,o]of r.sort(([s],[i])=>s.localeCompare(i)))o!=null&&e.set(n,t.map?.(n,o)??o);return e}function xc(r,t){if(typeof r!="string")throw new q("Metadata key must be a string");if(!(t instanceof Uint8Array))throw new q("Metadata value must be a Uint8Array")}function wc(r,t){if(typeof r!="string")throw new q("Tag name must be a string");if(t.value!=null){if(parseInt(`${t.value}`,10)!==t.value)throw new q("Tag value must be an integer");if(t.value<0||t.value>100)throw new q("Tag value must be between 0-100")}if(t.ttl!=null){if(parseInt(`${t.ttl}`,10)!==t.ttl)throw new q("Tag ttl must be an integer");if(t.ttl<0)throw new q("Tag ttl must be between greater than 0")}}function Ec(r,t){let e;t.expiry!=null&&(e=t.expiry),t.ttl!=null&&(e=BigInt(Date.now()+Number(t.ttl)));let n={value:t.value??0};return e!=null&&(n.expiry=e),n}function vc(r){let t=r.toString().split("/")[2],e=et.parse(t,Tt);return en(e)}function Vs(r,t,e){let n=vc(r);return dc(n,t,e)}function md(r,t){return{prefix:qs,filters:(r.filters??[]).map(e=>({key:n,value:o})=>e(Vs(n,o,t))),orders:(r.orders??[]).map(e=>(n,o)=>e(Vs(n.key,n.value,t),Vs(o.key,o.value,t)))}}var Un=class{peerId;datastore;locks;addressFilter;log;maxAddressAge;maxPeerAge;constructor(t,e={}){this.log=t.logger.forComponent("libp2p:peer-store"),this.peerId=t.peerId,this.datastore=t.datastore,this.addressFilter=e.addressFilter,this.locks=Os({name:"libp2p_peer_store_locks",metrics:t.metrics}),this.maxAddressAge=e.maxAddressAge??36e5,this.maxPeerAge=e.maxPeerAge??216e5}getLock(t){let e=this.locks.get(t);return e==null&&(e={refs:0,lock:Ms({name:t.toString(),singleProcess:!0})},this.locks.set(t,e)),e.refs++,e}maybeRemoveLock(t,e){e.refs--,e.refs===0&&(e.lock.finalize(),this.locks.delete(t))}async getReadLock(t,e){let n=this.getLock(t);try{let o=await n.lock.readLock(e);return()=>{o(),this.maybeRemoveLock(t,n)}}catch(o){throw this.maybeRemoveLock(t,n),o}}async getWriteLock(t,e){let n=this.getLock(t);try{let o=await n.lock.writeLock(e);return()=>{o(),this.maybeRemoveLock(t,n)}}catch(o){throw this.maybeRemoveLock(t,n),o}}async has(t,e){try{return await this.load(t,e),!0}catch(n){if(n.name!=="NotFoundError")throw n}return!1}async delete(t,e){this.peerId.equals(t)||await this.datastore.delete(Ir(t),e)}async load(t,e){let n=Ir(t),o=await this.datastore.get(n,e),s=Zt.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,e),new $e;return We(t,s,this.peerId.equals(t)?1/0:this.maxAddressAge)}async save(t,e,n){let o=await this.#t(t,n),s=await Nn(t,e,"patch",{...n,addressFilter:this.addressFilter});return this.#e(t,s,o)}async patch(t,e,n){let o=await this.#t(t,n),s=await Nn(t,e,"patch",{...n,addressFilter:this.addressFilter,existingPeer:o});return this.#e(t,s,o)}async merge(t,e,n){let o=await this.#t(t,n),s=await Nn(t,e,"merge",{addressFilter:this.addressFilter,existingPeer:o});return this.#e(t,s,o)}async*all(t){for await(let{key:e,value:n}of this.datastore.query(md(t??{},this.maxAddressAge),t)){let o=vc(e);if(o.equals(this.peerId))continue;let s=Zt.decode(n);if(this.#r(o,s)){await this.datastore.delete(e,t);continue}yield We(o,s,this.peerId.equals(o)?1/0:this.maxAddressAge)}}async#t(t,e){try{let n=Ir(t),o=await this.datastore.get(n,e),s=Zt.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,e),new $e;return{peerPB:s,peer:We(t,s,this.maxAddressAge)}}catch(n){n.name!=="NotFoundError"&&this.log.error("invalid peer data found in peer store - %e",n)}}async#e(t,e,n,o){e.updated=Date.now();let s=Zt.encode(e);return await this.datastore.put(Ir(t),s,o),{peer:We(t,e,this.maxAddressAge),previous:n?.peer,updated:n==null||!hc(e,n.peerPB)}}#r(t,e){if(e.updated==null)return!0;if(this.peerId.equals(t))return!1;let n=e.updated<Date.now()-this.maxPeerAge,o=Date.now()-this.maxAddressAge,s=e.addresses.filter(i=>i.observed!=null&&i.observed>o);return n&&s.length===0}};var Hs=class{store;events;peerId;log;constructor(t,e={}){this.log=t.logger.forComponent("libp2p:peer-store"),this.events=t.events,this.peerId=t.peerId,this.store=new Un(t,e)}[Symbol.toStringTag]="@libp2p/peer-store";async forEach(t,e){for await(let n of this.store.all(e))t(n)}async all(t){return nc(this.store.all(t))}async delete(t,e){let n=await this.store.getReadLock(t,e);try{await this.store.delete(t,e)}finally{n()}}async has(t,e){let n=await this.store.getReadLock(t,e);try{return await this.store.has(t,e)}finally{this.log.trace("has release read lock"),n?.()}}async get(t,e){let n=await this.store.getReadLock(t,e);try{return await this.store.load(t,e)}finally{n?.()}}async getInfo(t,e){let n=await this.get(t,e);return{id:n.id,multiaddrs:n.addresses.map(({multiaddr:o})=>o)}}async save(t,e,n){let o=await this.store.getWriteLock(t,n);try{let s=await this.store.save(t,e,n);return this.#t(t,s),s.peer}finally{o?.()}}async patch(t,e,n){let o=await this.store.getWriteLock(t,n);try{let s=await this.store.patch(t,e,n);return this.#t(t,s),s.peer}finally{o?.()}}async merge(t,e,n){let o=await this.store.getWriteLock(t,n);try{let s=await this.store.merge(t,e,n);return this.#t(t,s),s.peer}finally{o?.()}}async consumePeerRecord(t,e,n){let o=Ee(e)?e:Ee(e?.expectedPeer)?e.expectedPeer:void 0,s=Ee(e)||e===void 0?n:e,i=await He.openAndCertify(t,ge.DOMAIN,s),a=en(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=ge.createFromProtobuf(i.payload),u;try{u=await this.get(a,s)}catch(l){if(l.name!=="NotFoundError")throw l}if(u?.peerRecordEnvelope!=null){let l=He.createFromProtobuf(u.peerRecordEnvelope),f=ge.createFromProtobuf(l.payload);if(f.seqNumber>=c.seqNumber)return this.log("sequence number was lower or equal to existing sequence number - stored: %d received: %d",f.seqNumber,c.seqNumber),!1}return await this.patch(c.peerId,{peerRecordEnvelope:t,addresses:c.multiaddrs.map(l=>({isCertified:!0,multiaddr:l}))},s),!0}#t(t,e){e.updated&&(this.peerId.equals(t)?this.events.safeDispatchEvent("self:peer:update",{detail:e}):this.events.safeDispatchEvent("peer:update",{detail:e}))}};function yd(r,t={}){return new Hs(r,t)}return Rc(bd);})();
2
+ "use strict";var Libp2PPeerStore=(()=>{var Un=Object.defineProperty;var vc=Object.getOwnPropertyDescriptor;var Sc=Object.getOwnPropertyNames;var Ac=Object.prototype.hasOwnProperty;var bt=(r,t)=>{for(var e in t)Un(r,e,{get:t[e],enumerable:!0})},_c=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Sc(t))!Ac.call(r,o)&&o!==e&&Un(r,o,{get:()=>t[o],enumerable:!(n=vc(t,o))||n.enumerable});return r};var Ic=r=>_c(Un({},"__esModule",{value:!0}),r);var bd={};bt(bd,{persistentPeerStore:()=>yd});var q=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},we=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var $e=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var Br=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Lr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var se=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Tr=Symbol.for("@libp2p/peer-id");function Ee(r){return!!r?.[Tr]}var ve=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==e),this.#t.set(t,o))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var zn={};bt(zn,{base58btc:()=>Q,base58flickr:()=>Oc});var vd=new Uint8Array(0);function Fs(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Pt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Ws(r){return new TextEncoder().encode(r)}function $s(r){return new TextDecoder().decode(r)}function Rc(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var _=0,x=0,b=0,A=h.length;b!==A&&h[b]===0;)b++,_++;for(var w=(A-b)*l+1>>>0,I=new Uint8Array(w);b!==A;){for(var O=h[b],N=0,U=w-1;(O!==0||N<x)&&U!==-1;U--,N++)O+=256*I[U]>>>0,I[U]=O%a>>>0,O=O/a>>>0;if(O!==0)throw new Error("Non-zero carry");x=N,b++}for(var v=w-x;v!==w&&I[v]===0;)v++;for(var E=c.repeat(_);v<w;++v)E+=r.charAt(I[v]);return E}function d(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var _=0;if(h[_]!==" "){for(var x=0,b=0;h[_]===c;)x++,_++;for(var A=(h.length-_)*u+1>>>0,w=new Uint8Array(A);h[_];){var I=e[h.charCodeAt(_)];if(I===255)return;for(var O=0,N=A-1;(I!==0||O<b)&&N!==-1;N--,O++)I+=a*w[N]>>>0,w[N]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");b=O,_++}if(h[_]!==" "){for(var U=A-b;U!==A&&w[U]===0;)U++;for(var v=new Uint8Array(x+(A-U)),E=x;U!==A;)v[E++]=w[U++];return v}}}function g(h){var _=d(h);if(_)return _;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:d,decode:g}}var Bc=Rc,Lc=Bc,Gs=Lc;var Mn=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},qn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Ys(this,t)}},Vn=class{decoders;constructor(t){this.decoders=t}or(t){return Ys(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ys(r,t){return new Vn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Hn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new Mn(t,e,n),this.decoder=new qn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Se({name:r,prefix:t,encode:e,decode:n}){return new Hn(r,t,e,n)}function Yt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Gs(e,r);return Se({prefix:t,name:r,encode:n,decode:s=>Pt(o(s))})}function Tc(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let l=t[r[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|l,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Cc(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Dc(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function j({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=Dc(n);return Se({prefix:t,name:r,encode(s){return Cc(s,n,e)},decode(s){return Tc(s,o,e,r)}})}var Q=Yt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Oc=Yt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Fn={};bt(Fn,{base32:()=>Tt,base32hex:()=>Nc,base32hexpad:()=>Mc,base32hexpadupper:()=>qc,base32hexupper:()=>Uc,base32pad:()=>Pc,base32padupper:()=>kc,base32upper:()=>Kc,base32z:()=>Vc});var Tt=j({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Kc=j({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Pc=j({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),kc=j({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Nc=j({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Uc=j({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Mc=j({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),qc=j({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Vc=j({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Wn={};bt(Wn,{base36:()=>Ze,base36upper:()=>Hc});var Ze=Yt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Hc=Yt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var zc=Qs,Xs=128,Fc=127,Wc=~Fc,$c=Math.pow(2,31);function Qs(r,t,e){t=t||[],e=e||0;for(var n=e;r>=$c;)t[e++]=r&255|Xs,r/=128;for(;r&Wc;)t[e++]=r&255|Xs,r>>>=7;return t[e]=r|0,Qs.bytes=e-n+1,t}var Zc=$n,Gc=128,js=127;function $n(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw $n.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&js)<<o:(i&js)*Math.pow(2,o),o+=7}while(i>=Gc);return $n.bytes=s-n,e}var Yc=Math.pow(2,7),Xc=Math.pow(2,14),jc=Math.pow(2,21),Qc=Math.pow(2,28),Jc=Math.pow(2,35),tu=Math.pow(2,42),eu=Math.pow(2,49),ru=Math.pow(2,56),nu=Math.pow(2,63),ou=function(r){return r<Yc?1:r<Xc?2:r<jc?3:r<Qc?4:r<Jc?5:r<tu?6:r<eu?7:r<ru?8:r<nu?9:10},su={encode:zc,decode:Zc,encodingLength:ou},iu=su,Ge=iu;function Ye(r,t=0){return[Ge.decode(r,t),Ge.decode.bytes]}function Ae(r,t,e=0){return Ge.encode(r,t,e),t}function _e(r){return Ge.encodingLength(r)}function Ct(r,t){let e=t.byteLength,n=_e(r),o=n+_e(e),s=new Uint8Array(o+e);return Ae(r,s,0),Ae(e,s,n),s.set(t,o),new Ie(r,e,t,s)}function Re(r){let t=Pt(r),[e,n]=Ye(t),[o,s]=Ye(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ie(e,o,i,t)}function Js(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Fs(r.bytes,e.bytes)}}var Ie=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function ti(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return cu(e,Zn(r),t??Q.encoder);default:return uu(e,Zn(r),t??Tt.encoder)}}var ei=new WeakMap;function Zn(r){let t=ei.get(r);if(t==null){let e=new Map;return ei.set(r,e),e}return t}var et=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==Xe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==lu)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=Ct(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Js(t.multihash,n.multihash)}toString(t){return ti(this,t)}toJSON(){return{"/":ti(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??ri(n,o,s.bytes))}else if(e[fu]===!0){let{version:n,multihash:o,code:s}=e,i=Re(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Xe)throw new Error(`Version 0 CID must use dag-pb (code: ${Xe}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=ri(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Xe,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Pt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new Ie(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[f,d]=Ye(t.subarray(e));return e+=d,f},o=n(),s=Xe;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),u=e+c,l=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(t,e){let[n,o]=au(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Zn(s).set(n,t),s}};function au(r,t){switch(r[0]){case"Q":{let e=t??Q;return[Q.prefix,e.decode(`${Q.prefix}${r}`)]}case Q.prefix:{let e=t??Q;return[Q.prefix,e.decode(r)]}case Tt.prefix:{let e=t??Tt;return[Tt.prefix,e.decode(r)]}case Ze.prefix:{let e=t??Ze;return[Ze.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function cu(r,t,e){let{prefix:n}=e;if(n!==Q.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function uu(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var Xe=112,lu=18;function ri(r,t,e){let n=_e(r),o=n+_e(t),s=new Uint8Array(o+e.byteLength);return Ae(r,s,0),Ae(t,s,n),s.set(e,o),s}var fu=Symbol.for("@ipld/js-cid/CID");var Gn={};bt(Gn,{identity:()=>It});var ni=0,du="identity",oi=Pt;function hu(r,t){if(t?.truncate!=null&&t.truncate!==r.byteLength){if(t.truncate<0||t.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t.truncate)}return Ct(ni,oi(r))}var It={code:ni,name:du,encode:oi,digest:hu};function $(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function rt(r=0){return new Uint8Array(r)}function gt(r=0){return new Uint8Array(r)}function kt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=gt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var ii=Symbol.for("@achingbrain/uint8arraylist");function si(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function Dr(r){return!!r?.[ii]}var dt=class r{bufs;length;[ii]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Dr(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Dr(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=si(this.bufs,t);return e.buf[e.index]}set(t,e){let n=si(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Dr(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return kt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:kt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===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,t>=c)continue;let u=t>=a&&t<c,l=e>a&&e<=c;if(u&&l){if(t===a&&e===c){n.push(i);break}let f=t-a;n.push(i.subarray(f,f+(e-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(l){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Dr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;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 f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let f=e;f<=c;f+=l){l=0;for(let d=u;d>=0;d--){let g=this.get(f+d);if(n[d]!==g){l=Math.max(1,d-a[g]);break}}if(l===0)return f}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=gt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=rt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=gt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=rt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!$(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var Yn={};bt(Yn,{base10:()=>pu});var pu=Yt({prefix:"9",name:"base10",alphabet:"0123456789"});var Xn={};bt(Xn,{base16:()=>mu,base16upper:()=>yu});var mu=j({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),yu=j({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var jn={};bt(jn,{base2:()=>bu});var bu=j({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Qn={};bt(Qn,{base256emoji:()=>vu});var ai=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}"),gu=ai.reduce((r,t,e)=>(r[e]=t,r),[]),xu=ai.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function wu(r){return r.reduce((t,e)=>(t+=gu[e],t),"")}function Eu(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=xu[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var vu=Se({prefix:"\u{1F680}",name:"base256emoji",encode:wu,decode:Eu});var to={};bt(to,{base64:()=>Su,base64pad:()=>Au,base64url:()=>Jn,base64urlpad:()=>_u});var Su=j({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Au=j({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Jn=j({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),_u=j({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var eo={};bt(eo,{base8:()=>Iu});var Iu=j({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ro={};bt(ro,{identity:()=>Ru});var Ru=Se({prefix:"\0",name:"identity",encode:r=>$s(r),decode:r=>Ws(r)});var sh=new TextEncoder,ih=new TextDecoder;var so={};bt(so,{sha256:()=>je,sha512:()=>Cu});var Tu=20;function oo({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new no(r,t,e,n,o)}var no=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??Tu,this.maxDigestLength=s}digest(t,e){if(e?.truncate!=null){if(e.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&e.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?ci(n,this.code,e?.truncate):n.then(o=>ci(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function ci(r,t,e){if(e!=null&&e!==r.byteLength){if(e>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e)}return Ct(t,r)}function li(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var je=oo({name:"sha2-256",code:18,encode:li("SHA-256")}),Cu=oo({name:"sha2-512",code:19,encode:li("SHA-512")});var Qe={...ro,...jn,...eo,...Yn,...Xn,...Fn,...Wn,...zn,...to,...Qn},gh={...so,...Gn};function di(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var fi=di("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),io=di("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=gt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Du={utf8:fi,"utf-8":fi,hex:Qe.base16,latin1:io,ascii:io,binary:io,...Qe},Or=Du;function z(r,t="utf8"){let e=Or[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function V(r,t="utf8"){let e=Or[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Ou=parseInt("11111",2),ao=parseInt("10000000",2),Ku=parseInt("01111111",2),hi={0:Je,1:Je,2:Pu,3:Uu,4:Mu,5:Nu,6:ku,16:Je,22:Je,48:Je};function Nt(r,t={offset:0}){let e=r[t.offset]&Ou;if(t.offset++,hi[e]!=null)return hi[e](r,t);throw new Error("No decoder for tag "+e)}function tr(r,t){let e=0;if((r[t.offset]&ao)===ao){let n=r[t.offset]&Ku,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function Je(r,t){tr(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Nt(r,t);if(n===null)break;e.push(n)}return e}function Pu(r,t){let e=tr(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function ku(r,t){let e=tr(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let u=r[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let l=0;for(let f=0;f<c.length;f++)l+=c[f]<<f*7;a+=`.${l}`,c=[]}}return a}function Nu(r,t){return t.offset++,null}function Uu(r,t){let e=tr(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Mu(r,t){let e=tr(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function qu(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new dt;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function co(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=qu(r.byteLength);return new dt(Uint8Array.from([t.byteLength|ao]),t)}function xt(r){let t=new dt,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new dt(Uint8Array.from([2]),co(t),t)}function Kr(r){let t=Uint8Array.from([0]),e=new dt(t,r);return new dt(Uint8Array.from([3]),co(e),e)}function jt(r,t=48){let e=new dt;for(let n of r)e.append(n);return new dt(Uint8Array.from([t]),co(e),e)}async function pi(r,t,e,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,e.subarray());return n?.signal?.throwIfAborted(),s}var Vu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Hu=Uint8Array.from([6,5,43,129,4,0,34]),zu=Uint8Array.from([6,5,43,129,4,0,35]),Fu={ext:!0,kty:"EC",crv:"P-256"},Wu={ext:!0,kty:"EC",crv:"P-384"},$u={ext:!0,kty:"EC",crv:"P-521"},uo=32,lo=48,fo=66;function ho(r){let t=Nt(r);return mi(t)}function mi(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===uo*2+1)return n=V(t.subarray(e,e+uo),"base64url"),o=V(t.subarray(e+uo),"base64url"),new Be({...Fu,key_ops:["verify"],x:n,y:o});if(t.byteLength===lo*2+1)return n=V(t.subarray(e,e+lo),"base64url"),o=V(t.subarray(e+lo),"base64url"),new Be({...Wu,key_ops:["verify"],x:n,y:o});if(t.byteLength===fo*2+1)return n=V(t.subarray(e,e+fo),"base64url"),o=V(t.subarray(e+fo),"base64url"),new Be({...$u,key_ops:["verify"],x:n,y:o});throw new q(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function yi(r){return jt([xt(Uint8Array.from([1])),jt([Zu(r.crv)],160),jt([Kr(new dt(Uint8Array.from([4]),z(r.x??"","base64url"),z(r.y??"","base64url")))],161)]).subarray()}function Zu(r){if(r==="P-256")return Vu;if(r==="P-384")return Hu;if(r==="P-521")return zu;throw new q(`Invalid curve ${r}`)}var Be=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=yi(this.jwk)),this._raw}toMultihash(){return It.digest(St(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return Q.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:$(this.raw,t.raw)}async verify(t,e,n){return pi(this.jwk,e,t,n)}};function ie(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Dt(r,t=""){if(!Number.isSafeInteger(r)||r<0){let e=t&&`"${t}" `;throw new Error(`${e}expected integer >= 0, got ${r}`)}}function k(r,t,e=""){let n=ie(r),o=r?.length,s=t!==void 0;if(!n||s&&o!==t){let i=e&&`"${e}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof r}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return r}function Pr(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash must wrapped by utils.createHasher");Dt(r.outputLen),Dt(r.blockLen)}function Le(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function gi(r,t){k(r,void 0,"digestInto() output");let e=t.outputLen;if(r.length<e)throw new Error('"digestInto() output" expected to be of length >='+e)}function Mt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function kr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Rt(r,t){return r<<32-t|r>>>t}var xi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Gu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function qt(r){if(k(r),xi)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Gu[r[e]];return t}var Ut={_0:48,_9:57,A:65,F:70,a:97,f:102};function bi(r){if(r>=Ut._0&&r<=Ut._9)return r-Ut._0;if(r>=Ut.A&&r<=Ut.F)return r-(Ut.A-10);if(r>=Ut.a&&r<=Ut.f)return r-(Ut.a-10)}function Vt(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(xi)return Uint8Array.fromHex(r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=bi(r.charCodeAt(s)),a=bi(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function wt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];k(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}function po(r,t={}){let e=(o,s)=>r(s).update(o).digest(),n=r(void 0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=o=>r(o),Object.assign(e,t),Object.freeze(e)}function Te(r=32){let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(r))}var mo=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function wi(r,t,e){return r&t^~r&e}function Ei(r,t,e){return r&t^r&e^t&e}var er=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,e,n,o){this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=kr(this.buffer)}update(t){Le(this),k(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=kr(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Le(this),gi(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Mt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)e[f]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=kr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)a.setUint32(4*f,l[f],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Ht=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var at=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Nr=BigInt(4294967295),vi=BigInt(32);function Yu(r,t=!1){return t?{h:Number(r&Nr),l:Number(r>>vi&Nr)}:{h:Number(r>>vi&Nr)|0,l:Number(r&Nr)|0}}function Si(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:a}=Yu(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var yo=(r,t,e)=>r>>>e,bo=(r,t,e)=>r<<32-e|t>>>e,ae=(r,t,e)=>r>>>e|t<<32-e,ce=(r,t,e)=>r<<32-e|t>>>e,rr=(r,t,e)=>r<<64-e|t>>>e-32,nr=(r,t,e)=>r>>>e-32|t<<64-e;function Ot(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Ai=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),_i=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Ii=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Ri=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Bi=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Li=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var ju=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]),Qt=new Uint32Array(64),go=class extends er{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|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(t,e){for(let f=0;f<16;f++,e+=4)Qt[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let d=Qt[f-15],g=Qt[f-2],h=Rt(d,7)^Rt(d,18)^d>>>3,_=Rt(g,17)^Rt(g,19)^g>>>10;Qt[f]=_+Qt[f-7]+h+Qt[f-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){let d=Rt(a,6)^Rt(a,11)^Rt(a,25),g=l+d+wi(a,c,u)+ju[f]+Qt[f]|0,_=(Rt(n,2)^Rt(n,13)^Rt(n,22))+Ei(n,o,s)|0;l=u,u=c,c=a,a=i+g|0,i=s,s=o,o=n,n=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,l=l+this.H|0,this.set(n,o,s,i,a,c,u,l)}roundClean(){Mt(Qt)}destroy(){this.set(0,0,0,0,0,0,0,0),Mt(this.buffer)}},xo=class extends go{A=Ht[0]|0;B=Ht[1]|0;C=Ht[2]|0;D=Ht[3]|0;E=Ht[4]|0;F=Ht[5]|0;G=Ht[6]|0;H=Ht[7]|0;constructor(){super(32)}};var Ti=Si(["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(r=>BigInt(r))),Qu=Ti[0],Ju=Ti[1],Jt=new Uint32Array(80),te=new Uint32Array(80),wo=class extends er{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:l,Fh:f,Fl:d,Gh:g,Gl:h,Hh:_,Hl:x}=this;return[t,e,n,o,s,i,a,c,u,l,f,d,g,h,_,x]}set(t,e,n,o,s,i,a,c,u,l,f,d,g,h,_,x){this.Ah=t|0,this.Al=e|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=l|0,this.Fh=f|0,this.Fl=d|0,this.Gh=g|0,this.Gl=h|0,this.Hh=_|0,this.Hl=x|0}process(t,e){for(let w=0;w<16;w++,e+=4)Jt[w]=t.getUint32(e),te[w]=t.getUint32(e+=4);for(let w=16;w<80;w++){let I=Jt[w-15]|0,O=te[w-15]|0,N=ae(I,O,1)^ae(I,O,8)^yo(I,O,7),U=ce(I,O,1)^ce(I,O,8)^bo(I,O,7),v=Jt[w-2]|0,E=te[w-2]|0,K=ae(v,E,19)^rr(v,E,61)^yo(v,E,6),M=ce(v,E,19)^nr(v,E,61)^bo(v,E,6),T=Ii(U,M,te[w-7],te[w-16]),m=Ri(T,N,K,Jt[w-7],Jt[w-16]);Jt[w]=m|0,te[w]=T|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:d,Fh:g,Fl:h,Gh:_,Gl:x,Hh:b,Hl:A}=this;for(let w=0;w<80;w++){let I=ae(f,d,14)^ae(f,d,18)^rr(f,d,41),O=ce(f,d,14)^ce(f,d,18)^nr(f,d,41),N=f&g^~f&_,U=d&h^~d&x,v=Bi(A,O,U,Ju[w],te[w]),E=Li(v,b,I,N,Qu[w],Jt[w]),K=v|0,M=ae(n,o,28)^rr(n,o,34)^rr(n,o,39),T=ce(n,o,28)^nr(n,o,34)^nr(n,o,39),m=n&s^n&a^s&a,y=o&i^o&c^i&c;b=_|0,A=x|0,_=g|0,x=h|0,g=f|0,h=d|0,{h:f,l:d}=Ot(u|0,l|0,E|0,K|0),u=a|0,l=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let p=Ai(K,T,y);n=_i(p,E,M,m),o=p|0}({h:n,l:o}=Ot(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ot(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Ot(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=Ot(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:d}=Ot(this.Eh|0,this.El|0,f|0,d|0),{h:g,l:h}=Ot(this.Fh|0,this.Fl|0,g|0,h|0),{h:_,l:x}=Ot(this.Gh|0,this.Gl|0,_|0,x|0),{h:b,l:A}=Ot(this.Hh|0,this.Hl|0,b|0,A|0),this.set(n,o,s,i,a,c,u,l,f,d,g,h,_,x,b,A)}roundClean(){Mt(Jt,te)}destroy(){Mt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Eo=class extends wo{Ah=at[0]|0;Al=at[1]|0;Bh=at[2]|0;Bl=at[3]|0;Ch=at[4]|0;Cl=at[5]|0;Dh=at[6]|0;Dl=at[7]|0;Eh=at[8]|0;El=at[9]|0;Fh=at[10]|0;Fl=at[11]|0;Gh=at[12]|0;Gl=at[13]|0;Hh=at[14]|0;Hl=at[15]|0;constructor(){super(64)}};var Ce=po(()=>new xo,mo(1));var Ci=po(()=>new Eo,mo(3));var So=BigInt(0),vo=BigInt(1);function zt(r,t=""){if(typeof r!="boolean"){let e=t&&`"${t}" `;throw new Error(e+"expected boolean, got type="+typeof r)}return r}function Di(r){if(typeof r=="bigint"){if(!Ur(r))throw new Error("positive bigint expected, got "+r)}else Dt(r);return r}function or(r){let t=Di(r).toString(16);return t.length&1?"0"+t:t}function Oi(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?So:BigInt("0x"+r)}function De(r){return Oi(qt(r))}function ue(r){return Oi(qt(qr(k(r)).reverse()))}function Mr(r,t){Dt(t),r=Di(r);let e=Vt(r.toString(16).padStart(t*2,"0"));if(e.length!==t)throw new Error("number too large");return e}function Ao(r,t){return Mr(r,t).reverse()}function qr(r){return Uint8Array.from(r)}var Ur=r=>typeof r=="bigint"&&So<=r;function tl(r,t,e){return Ur(r)&&Ur(t)&&Ur(e)&&t<=r&&r<e}function sr(r,t,e,n){if(!tl(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function _o(r){let t;for(t=0;r>So;r>>=vo,t+=1);return t}var ir=r=>(vo<<BigInt(r))-vo;function Ki(r,t,e){if(Dt(r,"hashLen"),Dt(t,"qByteLen"),typeof e!="function")throw new Error("hmacFn must be a function");let n=x=>new Uint8Array(x),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(r),u=n(r),l=0,f=()=>{c.fill(1),u.fill(0),l=0},d=(...x)=>e(u,wt(c,...x)),g=(x=o)=>{u=d(s,x),c=d(),x.length!==0&&(u=d(i,x),c=d())},h=()=>{if(l++>=a)throw new Error("drbg: tried max amount of iterations");let x=0,b=[];for(;x<t;){c=d();let A=c.slice();b.push(A),x+=c.length}return wt(...b)};return(x,b)=>{f(),g(x);let A;for(;!(A=b(h()));)g();return f(),A}}function ee(r,t={},e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(s,i,a){let c=r[s];if(a&&c===void 0)return;let u=typeof c;if(u!==i||c===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${u}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(t,!1),o(e,!0)}function Oe(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var ht=BigInt(0),nt=BigInt(1),le=BigInt(2),Ni=BigInt(3),Ui=BigInt(4),Mi=BigInt(5),el=BigInt(7),qi=BigInt(8),rl=BigInt(9),Vi=BigInt(16);function J(r,t){let e=r%t;return e>=ht?e:t+e}function Z(r,t,e){let n=r;for(;t-- >ht;)n*=n,n%=e;return n}function Pi(r,t){if(r===ht)throw new Error("invert: expected non-zero number");if(t<=ht)throw new Error("invert: expected positive modulus, got "+t);let e=J(r,t),n=t,o=ht,s=nt,i=nt,a=ht;for(;e!==ht;){let u=n/e,l=n%e,f=o-i*u,d=s-a*u;n=e,e=l,o=i,s=a,i=f,a=d}if(n!==nt)throw new Error("invert: does not exist");return J(o,t)}function Ro(r,t,e){if(!r.eql(r.sqr(t),e))throw new Error("Cannot find square root")}function Hi(r,t){let e=(r.ORDER+nt)/Ui,n=r.pow(t,e);return Ro(r,n,t),n}function nl(r,t){let e=(r.ORDER-Mi)/qi,n=r.mul(t,le),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,le),o),a=r.mul(s,r.sub(i,r.ONE));return Ro(r,a,t),a}function ol(r){let t=Ke(r),e=zi(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+el)/Vi;return(a,c)=>{let u=a.pow(c,i),l=a.mul(u,n),f=a.mul(u,o),d=a.mul(u,s),g=a.eql(a.sqr(l),c),h=a.eql(a.sqr(f),c);u=a.cmov(u,l,g),l=a.cmov(d,f,h);let _=a.eql(a.sqr(l),c),x=a.cmov(u,l,_);return Ro(a,x,c),x}}function zi(r){if(r<Ni)throw new Error("sqrt is not defined for small field");let t=r-nt,e=0;for(;t%le===ht;)t/=le,e++;let n=le,o=Ke(r);for(;ki(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return Hi;let s=o.pow(n,t),i=(t+nt)/le;return function(c,u){if(c.is0(u))return u;if(ki(c,u)!==1)throw new Error("Cannot find square root");let l=e,f=c.mul(c.ONE,s),d=c.pow(u,t),g=c.pow(u,i);for(;!c.eql(d,c.ONE);){if(c.is0(d))return c.ZERO;let h=1,_=c.sqr(d);for(;!c.eql(_,c.ONE);)if(h++,_=c.sqr(_),h===l)throw new Error("Cannot find square root");let x=nt<<BigInt(l-h-1),b=c.pow(f,x);l=h,f=c.sqr(b),d=c.mul(d,f),g=c.mul(g,b)}return g}}function sl(r){return r%Ui===Ni?Hi:r%qi===Mi?nl:r%Vi===rl?ol(r):zi(r)}var Fi=(r,t)=>(J(r,t)&nt)===nt,il=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Bo(r){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},e=il.reduce((n,o)=>(n[o]="function",n),t);return ee(r,e),r}function al(r,t,e){if(e<ht)throw new Error("invalid exponent, negatives unsupported");if(e===ht)return r.ONE;if(e===nt)return t;let n=r.ONE,o=t;for(;e>ht;)e&nt&&(n=r.mul(n,o)),o=r.sqr(o),e>>=nt;return n}function ar(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,a,c)=>r.is0(a)?i:(n[c]=i,r.mul(i,a)),r.ONE),s=r.inv(o);return t.reduceRight((i,a,c)=>r.is0(a)?i:(n[c]=r.mul(i,n[c]),r.mul(i,a)),s),n}function ki(r,t){let e=(r.ORDER-nt)/le,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function cl(r,t){t!==void 0&&Dt(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}var Io=class{ORDER;BITS;BYTES;isLE;ZERO=ht;ONE=nt;_lengths;_sqrt;_mod;constructor(t,e={}){if(t<=ht)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,e!=null&&typeof e=="object"&&(typeof e.BITS=="number"&&(n=e.BITS),typeof e.sqrt=="function"&&(this.sqrt=e.sqrt),typeof e.isLE=="boolean"&&(this.isLE=e.isLE),e.allowedLengths&&(this._lengths=e.allowedLengths?.slice()),typeof e.modFromBytes=="boolean"&&(this._mod=e.modFromBytes));let{nBitLength:o,nByteLength:s}=cl(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return J(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return ht<=t&&t<this.ORDER}is0(t){return t===ht}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&nt)===nt}neg(t){return J(-t,this.ORDER)}eql(t,e){return t===e}sqr(t){return J(t*t,this.ORDER)}add(t,e){return J(t+e,this.ORDER)}sub(t,e){return J(t-e,this.ORDER)}mul(t,e){return J(t*e,this.ORDER)}pow(t,e){return al(this,t,e)}div(t,e){return J(t*Pi(e,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,e){return t+e}subN(t,e){return t-e}mulN(t,e){return t*e}inv(t){return Pi(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=sl(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?Ao(t,this.BYTES):Mr(t,this.BYTES)}fromBytes(t,e=!1){k(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let u=new Uint8Array(o);u.set(t,s?0:u.length-t.length),t=u}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=s?ue(t):De(t);if(a&&(c=J(c,i)),!e&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return ar(this,t)}cmov(t,e,n){return n?e:t}};function Ke(r,t={}){return new Io(r,t)}function Wi(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function Lo(r){let t=Wi(r);return t+Math.ceil(t/2)}function To(r,t,e=!1){k(r);let n=r.length,o=Wi(t),s=Lo(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?ue(r):De(r),a=J(i,t-nt)+nt;return e?Ao(a,o):Mr(a,o)}var Pe=BigInt(0),fe=BigInt(1);function cr(r,t){let e=t.negate();return r?e:t}function de(r,t){let e=ar(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function Yi(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Co(r,t){Yi(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=ir(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function $i(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=fe);let u=t*n,l=u+Math.abs(a)-1,f=a===0,d=a<0,g=t%2!==0;return{nextN:c,offset:l,isZero:f,isNeg:d,isNegF:g,offsetF:u}}var Do=new WeakMap,Xi=new WeakMap;function Oo(r){return Xi.get(r)||1}function Zi(r){if(r!==Pe)throw new Error("invalid wNAF")}var ke=class{BASE;ZERO;Fn;bits;constructor(t,e){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=e}_unsafeLadder(t,e,n=this.ZERO){let o=t;for(;e>Pe;)e&fe&&(n=n.add(o)),o=o.double(),e>>=fe;return n}precomputeWindow(t,e){let{windows:n,windowSize:o}=Co(e,this.bits),s=[],i=t,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(t,e,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Co(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:l,isNeg:f,isNegF:d,offsetF:g}=$i(n,a,i);n=c,l?s=s.add(cr(d,e[g])):o=o.add(cr(f,e[u]))}return Zi(n),{p:o,f:s}}wNAFUnsafe(t,e,n,o=this.ZERO){let s=Co(t,this.bits);for(let i=0;i<s.windows&&n!==Pe;i++){let{nextN:a,offset:c,isZero:u,isNeg:l}=$i(n,i,s);if(n=a,!u){let f=e[c];o=o.add(l?f.negate():f)}}return Zi(n),o}getPrecomputes(t,e,n){let o=Do.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),Do.set(e,o))),o}cached(t,e,n){let o=Oo(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=Oo(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){Yi(e,this.bits),Xi.set(t,e),Do.delete(t)}hasCache(t){return Oo(t)!==1}};function ji(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>Pe||n>Pe;)e&fe&&(s=s.add(o)),n&fe&&(i=i.add(o)),o=o.double(),e>>=fe,n>>=fe;return{p1:s,p2:i}}function Gi(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Bo(t),t}else return Ke(r,{isLE:e})}function Vr(r,t,e={},n){if(n===void 0&&(n=r==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let c of["p","n","h"]){let u=t[c];if(!(typeof u=="bigint"&&u>Pe))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Gi(t.p,e.Fp,n),s=Gi(t.n,e.Fn,n),a=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function Hr(r,t){return function(n){let o=r(n);return{secretKey:o,publicKey:t(o)}}}var re=BigInt(0),ot=BigInt(1),Ko=BigInt(2),ul=BigInt(8);function ll(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),a=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,a)}function Qi(r,t={}){let e=Vr("edwards",r,t,t.FpFnLE),{Fp:n,Fn:o}=e,s=e.CURVE,{h:i}=s;ee(t,{},{uvRatio:"function"});let a=Ko<<BigInt(o.BYTES*8)-ot,c=x=>n.create(x),u=t.uvRatio||((x,b)=>{try{return{isValid:!0,value:n.sqrt(n.div(x,b))}}catch{return{isValid:!1,value:re}}});if(!ll(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function l(x,b,A=!1){let w=A?ot:re;return sr("coordinate "+x,b,w,a),b}function f(x){if(!(x instanceof h))throw new Error("EdwardsPoint expected")}let d=Oe((x,b)=>{let{X:A,Y:w,Z:I}=x,O=x.is0();b==null&&(b=O?ul:n.inv(I));let N=c(A*b),U=c(w*b),v=n.mul(I,b);if(O)return{x:re,y:ot};if(v!==ot)throw new Error("invZ was invalid");return{x:N,y:U}}),g=Oe(x=>{let{a:b,d:A}=s;if(x.is0())throw new Error("bad point: ZERO");let{X:w,Y:I,Z:O,T:N}=x,U=c(w*w),v=c(I*I),E=c(O*O),K=c(E*E),M=c(U*b),T=c(E*c(M+v)),m=c(K+c(A*c(U*v)));if(T!==m)throw new Error("bad point: equation left != right (1)");let y=c(w*I),p=c(O*N);if(y!==p)throw new Error("bad point: equation left != right (2)");return!0});class h{static BASE=new h(s.Gx,s.Gy,ot,c(s.Gx*s.Gy));static ZERO=new h(re,ot,ot,re);static Fp=n;static Fn=o;X;Y;Z;T;constructor(b,A,w,I){this.X=l("x",b),this.Y=l("y",A),this.Z=l("z",w,!0),this.T=l("t",I),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){if(b instanceof h)throw new Error("extended point not allowed");let{x:A,y:w}=b||{};return l("x",A),l("y",w),new h(A,w,ot,c(A*w))}static fromBytes(b,A=!1){let w=n.BYTES,{a:I,d:O}=s;b=qr(k(b,w,"point")),zt(A,"zip215");let N=qr(b),U=b[w-1];N[w-1]=U&-129;let v=ue(N),E=A?a:n.ORDER;sr("point.y",v,re,E);let K=c(v*v),M=c(K-ot),T=c(O*K-I),{isValid:m,value:y}=u(M,T);if(!m)throw new Error("bad point: invalid y coordinate");let p=(y&ot)===ot,S=(U&128)!==0;if(!A&&y===re&&S)throw new Error("bad point: x=0 and x_0=1");return S!==p&&(y=c(-y)),h.fromAffine({x:y,y:v})}static fromHex(b,A=!1){return h.fromBytes(Vt(b),A)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,A=!0){return _.createCache(this,b),A||this.multiply(Ko),this}assertValidity(){g(this)}equals(b){f(b);let{X:A,Y:w,Z:I}=this,{X:O,Y:N,Z:U}=b,v=c(A*U),E=c(O*I),K=c(w*U),M=c(N*I);return v===E&&K===M}is0(){return this.equals(h.ZERO)}negate(){return new h(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:b}=s,{X:A,Y:w,Z:I}=this,O=c(A*A),N=c(w*w),U=c(Ko*c(I*I)),v=c(b*O),E=A+w,K=c(c(E*E)-O-N),M=v+N,T=M-U,m=v-N,y=c(K*T),p=c(M*m),S=c(K*m),R=c(T*M);return new h(y,p,R,S)}add(b){f(b);let{a:A,d:w}=s,{X:I,Y:O,Z:N,T:U}=this,{X:v,Y:E,Z:K,T:M}=b,T=c(I*v),m=c(O*E),y=c(U*w*M),p=c(N*K),S=c((I+O)*(v+E)-T-m),R=p-y,L=p+y,C=c(m-A*T),B=c(S*R),D=c(L*C),P=c(S*C),G=c(R*L);return new h(B,D,G,P)}subtract(b){return this.add(b.negate())}multiply(b){if(!o.isValidNot0(b))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:A,f:w}=_.cached(this,b,I=>de(h,I));return de(h,[A,w])[0]}multiplyUnsafe(b,A=h.ZERO){if(!o.isValid(b))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return b===re?h.ZERO:this.is0()||b===ot?this:_.unsafe(this,b,w=>de(h,w),A)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return _.unsafe(this,s.n).is0()}toAffine(b){return d(this,b)}clearCofactor(){return i===ot?this:this.multiplyUnsafe(i)}toBytes(){let{x:b,y:A}=this.toAffine(),w=n.toBytes(A);return w[w.length-1]|=b&ot?128:0,w}toHex(){return qt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let _=new ke(h,o.BITS);return h.BASE.precompute(8),h}function Ji(r,t,e={}){if(typeof t!="function")throw new Error('"hash" function param is required');ee(e,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=e,{BASE:o,Fp:s,Fn:i}=r,a=e.randomBytes||Te,c=e.adjustScalarBytes||(v=>v),u=e.domain||((v,E,K)=>{if(zt(K,"phflag"),E.length||K)throw new Error("Contexts/pre-hash are not supported");return v});function l(v){return i.create(ue(v))}function f(v){let E=w.secretKey;k(v,w.secretKey,"secretKey");let K=k(t(v),2*E,"hashedSecretKey"),M=c(K.slice(0,E)),T=K.slice(E,2*E),m=l(M);return{head:M,prefix:T,scalar:m}}function d(v){let{head:E,prefix:K,scalar:M}=f(v),T=o.multiply(M),m=T.toBytes();return{head:E,prefix:K,scalar:M,point:T,pointBytes:m}}function g(v){return d(v).pointBytes}function h(v=Uint8Array.of(),...E){let K=wt(...E);return l(t(u(K,k(v,void 0,"context"),!!n)))}function _(v,E,K={}){v=k(v,void 0,"message"),n&&(v=n(v));let{prefix:M,scalar:T,pointBytes:m}=d(E),y=h(K.context,M,v),p=o.multiply(y).toBytes(),S=h(K.context,p,m,v),R=i.create(y+S*T);if(!i.isValid(R))throw new Error("sign failed: invalid s");let L=wt(p,i.toBytes(R));return k(L,w.signature,"result")}let x={zip215:!0};function b(v,E,K,M=x){let{context:T,zip215:m}=M,y=w.signature;v=k(v,y,"signature"),E=k(E,void 0,"message"),K=k(K,w.publicKey,"publicKey"),m!==void 0&&zt(m,"zip215"),n&&(E=n(E));let p=y/2,S=v.subarray(0,p),R=ue(v.subarray(p,y)),L,C,B;try{L=r.fromBytes(K,m),C=r.fromBytes(S,m),B=o.multiplyUnsafe(R)}catch{return!1}if(!m&&L.isSmallOrder())return!1;let D=h(T,C.toBytes(),L.toBytes(),E);return C.add(L.multiplyUnsafe(D)).subtract(B).clearCofactor().is0()}let A=s.BYTES,w={secretKey:A,publicKey:A,signature:2*A,seed:A};function I(v=a(w.seed)){return k(v,w.seed,"seed")}function O(v){return ie(v)&&v.length===i.BYTES}function N(v,E){try{return!!r.fromBytes(v,E)}catch{return!1}}let U={getExtendedPublicKey:d,randomSecretKey:I,isValidSecretKey:O,isValidPublicKey:N,toMontgomery(v){let{y:E}=r.fromBytes(v),K=w.publicKey,M=K===32;if(!M&&K!==57)throw new Error("only defined for 25519 and 448");let T=M?s.div(ot+E,ot-E):s.div(E-ot,E+ot);return s.toBytes(T)},toMontgomerySecret(v){let E=w.secretKey;k(v,E);let K=t(v.subarray(0,E));return c(K).subarray(0,E)}};return Object.freeze({keygen:Hr(I,g),getPublicKey:g,sign:_,verify:b,utils:U,Point:r,lengths:w})}var fl=BigInt(1),ta=BigInt(2);var dl=BigInt(5),hl=BigInt(8),Po=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),pl={p:Po,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:hl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function ml(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=Po,a=r*r%s*r%s,c=Z(a,ta,s)*a%s,u=Z(c,fl,s)*r%s,l=Z(u,dl,s)*u%s,f=Z(l,t,s)*l%s,d=Z(f,e,s)*f%s,g=Z(d,n,s)*d%s,h=Z(g,o,s)*g%s,_=Z(h,o,s)*g%s,x=Z(_,t,s)*l%s;return{pow_p_5_8:Z(x,ta,s)*r%s,b2:a}}function yl(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var ea=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function bl(r,t){let e=Po,n=J(t*t*t,e),o=J(n*n*t,e),s=ml(r*o).pow_p_5_8,i=J(r*n*s,e),a=J(t*i*i,e),c=i,u=J(i*ea,e),l=a===r,f=a===J(-r,e),d=a===J(-r*ea,e);return l&&(i=c),(f||d)&&(i=u),Fi(i,e)&&(i=J(-i,e)),{isValid:l||f,value:i}}var gl=Qi(pl,{uvRatio:bl});function xl(r){return Ji(gl,Ci,Object.assign({adjustScalarBytes:yl},r))}var ra=xl({});var ur=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},zr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var na={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new zr("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var At=na;var Fr=32;var ko,wl=(async()=>{try{return await At.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function El(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await At.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await At.get().subtle.verify({name:"Ed25519"},n,t,e instanceof Uint8Array?e:e.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function vl(r,t,e){return ra.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function oa(r,t,e){return ko==null&&(ko=await wl),ko?El(r,t,e):vl(r,t,e)}function Wr(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var $r=class{type="Ed25519";raw;constructor(t){this.raw=No(t,Fr)}toMultihash(){return It.digest(St(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return Q.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:$(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=oa(this.raw,e,t);return Wr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Uo(r){return r=No(r,Fr),new $r(r)}function No(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new q(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var Al=Math.pow(2,7),_l=Math.pow(2,14),Il=Math.pow(2,21),Mo=Math.pow(2,28),qo=Math.pow(2,35),Vo=Math.pow(2,42),Ho=Math.pow(2,49),F=128,lt=127;function _t(r){if(r<Al)return 1;if(r<_l)return 2;if(r<Il)return 3;if(r<Mo)return 4;if(r<qo)return 5;if(r<Vo)return 6;if(r<Ho)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ne(r,t,e=0){switch(_t(r)){case 8:t[e++]=r&255|F,r/=128;case 7:t[e++]=r&255|F,r/=128;case 6:t[e++]=r&255|F,r/=128;case 5:t[e++]=r&255|F,r/=128;case 4:t[e++]=r&255|F,r>>>=7;case 3:t[e++]=r&255|F,r>>>=7;case 2:t[e++]=r&255|F,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Rl(r,t,e=0){switch(_t(r)){case 8:t.set(e++,r&255|F),r/=128;case 7:t.set(e++,r&255|F),r/=128;case 6:t.set(e++,r&255|F),r/=128;case 5:t.set(e++,r&255|F),r/=128;case 4:t.set(e++,r&255|F),r>>>=7;case 3:t.set(e++,r&255|F),r>>>=7;case 2:t.set(e++,r&255|F),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function zo(r,t){let e=r[t],n=0;if(n+=e&lt,e<F||(e=r[t+1],n+=(e&lt)<<7,e<F)||(e=r[t+2],n+=(e&lt)<<14,e<F)||(e=r[t+3],n+=(e&lt)<<21,e<F)||(e=r[t+4],n+=(e&lt)*Mo,e<F)||(e=r[t+5],n+=(e&lt)*qo,e<F)||(e=r[t+6],n+=(e&lt)*Vo,e<F)||(e=r[t+7],n+=(e&lt)*Ho,e<F))return n;throw new RangeError("Could not decode varint")}function Bl(r,t){let e=r.get(t),n=0;if(n+=e&lt,e<F||(e=r.get(t+1),n+=(e&lt)<<7,e<F)||(e=r.get(t+2),n+=(e&lt)<<14,e<F)||(e=r.get(t+3),n+=(e&lt)<<21,e<F)||(e=r.get(t+4),n+=(e&lt)*Mo,e<F)||(e=r.get(t+5),n+=(e&lt)*qo,e<F)||(e=r.get(t+6),n+=(e&lt)*Vo,e<F)||(e=r.get(t+7),n+=(e&lt)*Ho,e<F))return n;throw new RangeError("Could not decode varint")}function Zr(r,t,e=0){return t==null&&(t=gt(_t(r))),t instanceof Uint8Array?Ne(r,t,e):Rl(r,t,e)}function Fo(r,t=0){return r instanceof Uint8Array?zo(r,t):Bl(r,t)}var Wo=new Float32Array([-0]),ne=new Uint8Array(Wo.buffer);function aa(r,t,e){Wo[0]=r,t[e]=ne[0],t[e+1]=ne[1],t[e+2]=ne[2],t[e+3]=ne[3]}function ca(r,t){return ne[0]=r[t],ne[1]=r[t+1],ne[2]=r[t+2],ne[3]=r[t+3],Wo[0]}var $o=new Float64Array([-0]),ft=new Uint8Array($o.buffer);function ua(r,t,e){$o[0]=r,t[e]=ft[0],t[e+1]=ft[1],t[e+2]=ft[2],t[e+3]=ft[3],t[e+4]=ft[4],t[e+5]=ft[5],t[e+6]=ft[6],t[e+7]=ft[7]}function la(r,t){return ft[0]=r[t],ft[1]=r[t+1],ft[2]=r[t+2],ft[3]=r[t+3],ft[4]=r[t+4],ft[5]=r[t+5],ft[6]=r[t+6],ft[7]=r[t+7],$o[0]}var Ll=BigInt(Number.MAX_SAFE_INTEGER),Tl=BigInt(Number.MIN_SAFE_INTEGER),Et=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return he;if(t<Ll&&t>Tl)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>fa&&(o=0n,++n>fa&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return he;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):he}},he=new Et(0,0);he.toBigInt=function(){return 0n};he.zzEncode=he.zzDecode=function(){return this};he.length=function(){return 1};var fa=4294967296n;function da(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function ha(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Zo(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function Bt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Gr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Go=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Bt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Bt(this,4);return Gr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Bt(this,4);return Gr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Bt(this,4);let t=ca(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Bt(this,4);let t=la(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw Bt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return ha(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Bt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Bt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Et(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw Bt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw Bt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Bt(this,8);let t=Gr(this.buf,this.pos+=4),e=Gr(this.buf,this.pos+=4);return new Et(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=zo(this.buf,this.pos);return this.pos+=_t(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Yo(r){return new Go(r instanceof Uint8Array?r:r.subarray())}function pt(r,t,e){let n=Yo(r);return t.decode(n,void 0,e)}function Xo(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return gt(i);o+i>t&&(n=gt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var pe=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function jo(){}var Jo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Cl=Xo();function Dl(r){return globalThis.Buffer!=null?gt(r):Cl(r)}var fr=class{len;head;tail;states;constructor(){this.len=0,this.head=new pe(jo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new pe(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new ts((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Yr,10,Et.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Et.fromBigInt(t);return this._push(Yr,e.length(),e)}uint64Number(t){return this._push(Ne,_t(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=Et.fromBigInt(t).zzEncode();return this._push(Yr,e.length(),e)}sint64Number(t){let e=Et.fromNumber(t).zzEncode();return this._push(Yr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Qo,1,t?1:0)}fixed32(t){return this._push(lr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Et.fromBigInt(t);return this._push(lr,4,e.lo)._push(lr,4,e.hi)}fixed64Number(t){let e=Et.fromNumber(t);return this._push(lr,4,e.lo)._push(lr,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(aa,4,t)}double(t){return this._push(ua,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Qo,1,0):this.uint32(e)._push(Kl,e,t)}string(t){let e=da(t);return e!==0?this.uint32(e)._push(Zo,e,t):this._push(Qo,1,0)}fork(){return this.states=new Jo(this),this.head=this.tail=new pe(jo,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 pe(jo,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Dl(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Qo(r,t,e){t[e]=r&255}function Ol(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var ts=class extends pe{next;constructor(t,e){super(Ol,t,e),this.next=void 0}};function Yr(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function lr(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Kl(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(fr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Pl,t,r),this},fr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(kl,t,r),this});function Pl(r,t,e){t.set(r,e)}function kl(r,t,e){r.length<40?Zo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(z(r),e)}function es(){return new fr}function mt(r,t){let e=es();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Ue;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(Ue||(Ue={}));function Xr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function rs(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return Xr("enum",Ue.VARINT,e,n)}function yt(r,t){return Xr("message",Ue.LENGTH_DELIMITED,r,t)}var me=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},dr=class extends Error{code="ERR_MAX_SIZE";name="MaxSizeError"};var tt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(tt||(tt={}));var ns;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(ns||(ns={}));(function(r){r.codec=()=>rs(ns)})(tt||(tt={}));var Kt;(function(r){let t;r.codec=()=>(t==null&&(t=yt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),tt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=tt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>mt(e,r.codec()),r.decode=(e,n)=>pt(e,r.codec(),n)})(Kt||(Kt={}));var os;(function(r){let t;r.codec=()=>(t==null&&(t=yt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),tt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=tt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>mt(e,r.codec()),r.decode=(e,n)=>pt(e,r.codec(),n)})(os||(os={}));var pr={};bt(pr,{MAX_RSA_KEY_SIZE:()=>ss,generateRSAKeyPair:()=>xa,jwkToJWKKeyPair:()=>wa,jwkToPkcs1:()=>ql,jwkToPkix:()=>us,jwkToRSAPrivateKey:()=>hs,pkcs1MessageToJwk:()=>as,pkcs1MessageToRSAPrivateKey:()=>ls,pkcs1ToJwk:()=>Ml,pkcs1ToRSAPrivateKey:()=>ga,pkixMessageToJwk:()=>cs,pkixMessageToRSAPublicKey:()=>ds,pkixToJwk:()=>Vl,pkixToRSAPublicKey:()=>fs});var Me=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=pr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return et.createV1(114,this._multihash)}toString(){return Q.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:$(this.raw,t.raw)}verify(t,e,n){return ba(this.jwk,e,t,n)}},hr=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=pr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:$(this.raw,t.raw)}sign(t,e){return ya(this.jwk,t,e)}};var ss=8192,is=18,Nl=1062,Ul=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Ml(r){let t=Nt(r);return as(t)}function as(r){return{n:V(r[1],"base64url"),e:V(r[2],"base64url"),d:V(r[3],"base64url"),p:V(r[4],"base64url"),q:V(r[5],"base64url"),dp:V(r[6],"base64url"),dq:V(r[7],"base64url"),qi:V(r[8],"base64url"),kty:"RSA"}}function ql(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new q("JWK was missing components");return jt([xt(Uint8Array.from([0])),xt(z(r.n,"base64url")),xt(z(r.e,"base64url")),xt(z(r.d,"base64url")),xt(z(r.p,"base64url")),xt(z(r.q,"base64url")),xt(z(r.dp,"base64url")),xt(z(r.dq,"base64url")),xt(z(r.qi,"base64url"))]).subarray()}function Vl(r){let t=Nt(r,{offset:0});return cs(t)}function cs(r){let t=Nt(r[1],{offset:0});return{kty:"RSA",n:V(t[0],"base64url"),e:V(t[1],"base64url")}}function us(r){if(r.n==null||r.e==null)throw new q("JWK was missing components");return jt([Ul,Kr(jt([xt(z(r.n,"base64url")),xt(z(r.e,"base64url"))]))]).subarray()}function ga(r){let t=Nt(r);return ls(t)}function ls(r){let t=as(r);return hs(t)}function fs(r,t){if(r.byteLength>=Nl)throw new we("Key size is too large");let e=Nt(r,{offset:0});return ds(e,r,t)}function ds(r,t,e){let n=cs(r);if(e==null){let o=Ce(Kt.encode({Type:tt.RSA,Data:t}));e=Ct(is,o)}return new Me(n,e)}function hs(r){if(va(r)>ss)throw new q("Key size is too large");let t=wa(r),e=Ce(Kt.encode({Type:tt.RSA,Data:us(t.publicKey)})),n=Ct(is,e);return new hr(t.privateKey,new Me(t.publicKey,n))}async function xa(r){if(r>ss)throw new q("Key size is too large");let t=await Ea(r),e=Ce(Kt.encode({Type:tt.RSA,Data:us(t.publicKey)})),n=Ct(is,e);return new hr(t.privateKey,new Me(t.publicKey,n))}function wa(r){if(r==null)throw new q("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function Ea(r,t){let e=await At.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Hl(e,t);return{privateKey:n[0],publicKey:n[1]}}async function ya(r,t,e){let n=await At.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);e?.signal?.throwIfAborted();let o=await At.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return e?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function ba(r,t,e,n){let o=await At.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await At.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,e instanceof Uint8Array?e:e.subarray());return n?.signal?.throwIfAborted(),s}async function Hl(r,t){if(r.privateKey==null||r.publicKey==null)throw new q("Private and public key are required");let e=await Promise.all([At.get().subtle.exportKey("jwk",r.privateKey),At.get().subtle.exportKey("jwk",r.publicKey)]);return t?.signal?.throwIfAborted(),e}function va(r){if(r.kty!=="RSA")throw new q("invalid key type");if(r.n==null)throw new q("invalid key modulus");return z(r.n,"base64url").length*8}var jr=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,e){if(Pr(t),k(e,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(e.length>n?t.create().update(e).digest():e);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Mt(o)}update(t){return Le(this),this.iHash.update(t),this}digestInto(t){Le(this),k(t,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ps=(r,t,e)=>new jr(r,t).update(e).digest();ps.create=(r,t)=>new jr(r,t);var Sa=(r,t)=>(r+(r>=0?t:-t)/Aa)/t;function zl(r,t,e){let[[n,o],[s,i]]=t,a=Sa(i*r,e),c=Sa(-o*r,e),u=r-a*n-c*s,l=-a*o-c*i,f=u<Ft,d=l<Ft;f&&(u=-u),d&&(l=-l);let g=ir(Math.ceil(_o(e)/2))+qe;if(u<Ft||u>=g||l<Ft||l>=g)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:f,k1:u,k2neg:d,k2:l}}function ys(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function ms(r,t){let e={};for(let n of Object.keys(t))e[n]=r[n]===void 0?t[n]:r[n];return zt(e.lowS,"lowS"),zt(e.prehash,"prehash"),e.format!==void 0&&ys(e.format),e}var bs=class extends Error{constructor(t=""){super(t)}},oe={Err:bs,_tlv:{encode:(r,t)=>{let{Err:e}=oe;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=or(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?or(o.length/2|128):"";return or(r)+s+o+t},decode(r,t){let{Err:e}=oe,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new e("tlv.decode: length bytes not complete");if(u[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let l of u)i=i<<8|l;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=oe;if(r<Ft)throw new t("integer: negative integers are not allowed");let e=or(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=oe;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return De(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=oe,o=k(r,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:u,l}=n.decode(2,c);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(u)}},hexFromSig(r){let{_tlv:t,_int:e}=oe,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},Ft=BigInt(0),qe=BigInt(1),Aa=BigInt(2),Qr=BigInt(3),Fl=BigInt(4);function _a(r,t={}){let e=Vr("weierstrass",r,t),{Fp:n,Fn:o}=e,s=e.CURVE,{h:i,n:a}=s;ee(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c}=t;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 u=Ra(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function f(T,m,y){let{x:p,y:S}=m.toAffine(),R=n.toBytes(p);if(zt(y,"isCompressed"),y){l();let L=!n.isOdd(S);return wt(Ia(L),R)}else return wt(Uint8Array.of(4),R,n.toBytes(S))}function d(T){k(T,void 0,"Point");let{publicKey:m,publicKeyUncompressed:y}=u,p=T.length,S=T[0],R=T.subarray(1);if(p===m&&(S===2||S===3)){let L=n.fromBytes(R);if(!n.isValid(L))throw new Error("bad point: is not on curve, wrong x");let C=_(L),B;try{B=n.sqrt(C)}catch(G){let W=G instanceof Error?": "+G.message:"";throw new Error("bad point: is not on curve, sqrt error"+W)}l();let D=n.isOdd(B);return(S&1)===1!==D&&(B=n.neg(B)),{x:L,y:B}}else if(p===y&&S===4){let L=n.BYTES,C=n.fromBytes(R.subarray(0,L)),B=n.fromBytes(R.subarray(L,L*2));if(!x(C,B))throw new Error("bad point: is not on curve");return{x:C,y:B}}else throw new Error(`bad point: got length ${p}, expected compressed=${m} or uncompressed=${y}`)}let g=t.toBytes||f,h=t.fromBytes||d;function _(T){let m=n.sqr(T),y=n.mul(m,T);return n.add(n.add(y,n.mul(T,s.a)),s.b)}function x(T,m){let y=n.sqr(m),p=_(T);return n.eql(y,p)}if(!x(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let b=n.mul(n.pow(s.a,Qr),Fl),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(b,A)))throw new Error("bad curve params: a or b");function w(T,m,y=!1){if(!n.isValid(m)||y&&n.is0(m))throw new Error(`bad point coordinate ${T}`);return m}function I(T){if(!(T instanceof E))throw new Error("Weierstrass Point expected")}function O(T){if(!c||!c.basises)throw new Error("no endo");return zl(T,c.basises,o.ORDER)}let N=Oe((T,m)=>{let{X:y,Y:p,Z:S}=T;if(n.eql(S,n.ONE))return{x:y,y:p};let R=T.is0();m==null&&(m=R?n.ONE:n.inv(S));let L=n.mul(y,m),C=n.mul(p,m),B=n.mul(S,m);if(R)return{x:n.ZERO,y:n.ZERO};if(!n.eql(B,n.ONE))throw new Error("invZ was invalid");return{x:L,y:C}}),U=Oe(T=>{if(T.is0()){if(t.allowInfinityPoint&&!n.is0(T.Y))return;throw new Error("bad point: ZERO")}let{x:m,y}=T.toAffine();if(!n.isValid(m)||!n.isValid(y))throw new Error("bad point: x or y not field elements");if(!x(m,y))throw new Error("bad point: equation left != right");if(!T.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function v(T,m,y,p,S){return y=new E(n.mul(y.X,T),y.Y,y.Z),m=cr(p,m),y=cr(S,y),m.add(y)}class E{static BASE=new E(s.Gx,s.Gy,n.ONE);static ZERO=new E(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(m,y,p){this.X=w("x",m),this.Y=w("y",y,!0),this.Z=w("z",p),Object.freeze(this)}static CURVE(){return s}static fromAffine(m){let{x:y,y:p}=m||{};if(!m||!n.isValid(y)||!n.isValid(p))throw new Error("invalid affine point");if(m instanceof E)throw new Error("projective point not allowed");return n.is0(y)&&n.is0(p)?E.ZERO:new E(y,p,n.ONE)}static fromBytes(m){let y=E.fromAffine(h(k(m,void 0,"point")));return y.assertValidity(),y}static fromHex(m){return E.fromBytes(Vt(m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,y=!0){return M.createCache(this,m),y||this.multiply(Qr),this}assertValidity(){U(this)}hasEvenY(){let{y:m}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(m)}equals(m){I(m);let{X:y,Y:p,Z:S}=this,{X:R,Y:L,Z:C}=m,B=n.eql(n.mul(y,C),n.mul(R,S)),D=n.eql(n.mul(p,C),n.mul(L,S));return B&&D}negate(){return new E(this.X,n.neg(this.Y),this.Z)}double(){let{a:m,b:y}=s,p=n.mul(y,Qr),{X:S,Y:R,Z:L}=this,C=n.ZERO,B=n.ZERO,D=n.ZERO,P=n.mul(S,S),G=n.mul(R,R),W=n.mul(L,L),H=n.mul(S,R);return H=n.add(H,H),D=n.mul(S,L),D=n.add(D,D),C=n.mul(m,D),B=n.mul(p,W),B=n.add(C,B),C=n.sub(G,B),B=n.add(G,B),B=n.mul(C,B),C=n.mul(H,C),D=n.mul(p,D),W=n.mul(m,W),H=n.sub(P,W),H=n.mul(m,H),H=n.add(H,D),D=n.add(P,P),P=n.add(D,P),P=n.add(P,W),P=n.mul(P,H),B=n.add(B,P),W=n.mul(R,L),W=n.add(W,W),P=n.mul(W,H),C=n.sub(C,P),D=n.mul(W,G),D=n.add(D,D),D=n.add(D,D),new E(C,B,D)}add(m){I(m);let{X:y,Y:p,Z:S}=this,{X:R,Y:L,Z:C}=m,B=n.ZERO,D=n.ZERO,P=n.ZERO,G=s.a,W=n.mul(s.b,Qr),H=n.mul(y,R),Y=n.mul(p,L),it=n.mul(S,C),Lt=n.add(y,p),X=n.add(R,L);Lt=n.mul(Lt,X),X=n.add(H,Y),Lt=n.sub(Lt,X),X=n.add(y,S);let ut=n.add(R,C);return X=n.mul(X,ut),ut=n.add(H,it),X=n.sub(X,ut),ut=n.add(p,S),B=n.add(L,C),ut=n.mul(ut,B),B=n.add(Y,it),ut=n.sub(ut,B),P=n.mul(G,X),B=n.mul(W,it),P=n.add(B,P),B=n.sub(Y,P),P=n.add(Y,P),D=n.mul(B,P),Y=n.add(H,H),Y=n.add(Y,H),it=n.mul(G,it),X=n.mul(W,X),Y=n.add(Y,it),it=n.sub(H,it),it=n.mul(G,it),X=n.add(X,it),H=n.mul(Y,X),D=n.add(D,H),H=n.mul(ut,X),B=n.mul(Lt,B),B=n.sub(B,H),H=n.mul(Lt,Y),P=n.mul(ut,P),P=n.add(P,H),new E(B,D,P)}subtract(m){return this.add(m.negate())}is0(){return this.equals(E.ZERO)}multiply(m){let{endo:y}=t;if(!o.isValidNot0(m))throw new Error("invalid scalar: out of range");let p,S,R=L=>M.cached(this,L,C=>de(E,C));if(y){let{k1neg:L,k1:C,k2neg:B,k2:D}=O(m),{p:P,f:G}=R(C),{p:W,f:H}=R(D);S=G.add(H),p=v(y.beta,P,W,L,B)}else{let{p:L,f:C}=R(m);p=L,S=C}return de(E,[p,S])[0]}multiplyUnsafe(m){let{endo:y}=t,p=this;if(!o.isValid(m))throw new Error("invalid scalar: out of range");if(m===Ft||p.is0())return E.ZERO;if(m===qe)return p;if(M.hasCache(this))return this.multiply(m);if(y){let{k1neg:S,k1:R,k2neg:L,k2:C}=O(m),{p1:B,p2:D}=ji(E,p,R,C);return v(y.beta,B,D,S,L)}else return M.unsafe(p,m)}toAffine(m){return N(this,m)}isTorsionFree(){let{isTorsionFree:m}=t;return i===qe?!0:m?m(E,this):M.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:m}=t;return i===qe?this:m?m(E,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(m=!0){return zt(m,"isCompressed"),this.assertValidity(),g(E,this,m)}toHex(m=!0){return qt(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let K=o.BITS,M=new ke(E,t.endo?Math.ceil(K/2):K);return E.BASE.precompute(8),E}function Ia(r){return Uint8Array.of(r?2:3)}function Ra(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Wl(r,t={}){let{Fn:e}=r,n=t.randomBytes||Te,o=Object.assign(Ra(r.Fp,e),{seed:Lo(e.ORDER)});function s(g){try{let h=e.fromBytes(g);return e.isValidNot0(h)}catch{return!1}}function i(g,h){let{publicKey:_,publicKeyUncompressed:x}=o;try{let b=g.length;return h===!0&&b!==_||h===!1&&b!==x?!1:!!r.fromBytes(g)}catch{return!1}}function a(g=n(o.seed)){return To(k(g,o.seed,"seed"),e.ORDER)}function c(g,h=!0){return r.BASE.multiply(e.fromBytes(g)).toBytes(h)}function u(g){let{secretKey:h,publicKey:_,publicKeyUncompressed:x}=o;if(!ie(g)||"_lengths"in e&&e._lengths||h===_)return;let b=k(g,void 0,"key").length;return b===_||b===x}function l(g,h,_=!0){if(u(g)===!0)throw new Error("first arg must be private key");if(u(h)===!1)throw new Error("second arg must be public key");let x=e.fromBytes(g);return r.fromBytes(h).multiply(x).toBytes(_)}let f={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},d=Hr(a,c);return Object.freeze({getPublicKey:c,getSharedSecret:l,keygen:d,Point:r,utils:f,lengths:o})}function Ba(r,t,e={}){Pr(t),ee(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let n=e.randomBytes||Te,o=e.hmac||((y,p)=>ps(t,y,p)),{Fp:s,Fn:i}=r,{ORDER:a,BITS:c}=i,{keygen:u,getPublicKey:l,getSharedSecret:f,utils:d,lengths:g}=Wl(r,e),h={prehash:!0,lowS:typeof e.lowS=="boolean"?e.lowS:!0,format:"compact",extraEntropy:!1},_=a*Aa<s.ORDER;function x(y){let p=a>>qe;return y>p}function b(y,p){if(!i.isValidNot0(p))throw new Error(`invalid signature ${y}: out of range 1..Point.Fn.ORDER`);return p}function A(){if(_)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function w(y,p){ys(p);let S=g.signature,R=p==="compact"?S:p==="recovered"?S+1:void 0;return k(y,R)}class I{r;s;recovery;constructor(p,S,R){if(this.r=b("r",p),this.s=b("s",S),R!=null){if(A(),![0,1,2,3].includes(R))throw new Error("invalid recovery id");this.recovery=R}Object.freeze(this)}static fromBytes(p,S=h.format){w(p,S);let R;if(S==="der"){let{r:D,s:P}=oe.toSig(k(p));return new I(D,P)}S==="recovered"&&(R=p[0],S="compact",p=p.subarray(1));let L=g.signature/2,C=p.subarray(0,L),B=p.subarray(L,L*2);return new I(i.fromBytes(C),i.fromBytes(B),R)}static fromHex(p,S){return this.fromBytes(Vt(p),S)}assertRecovery(){let{recovery:p}=this;if(p==null)throw new Error("invalid recovery id: must be present");return p}addRecoveryBit(p){return new I(this.r,this.s,p)}recoverPublicKey(p){let{r:S,s:R}=this,L=this.assertRecovery(),C=L===2||L===3?S+a:S;if(!s.isValid(C))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let B=s.toBytes(C),D=r.fromBytes(wt(Ia((L&1)===0),B)),P=i.inv(C),G=N(k(p,void 0,"msgHash")),W=i.create(-G*P),H=i.create(R*P),Y=r.BASE.multiplyUnsafe(W).add(D.multiplyUnsafe(H));if(Y.is0())throw new Error("invalid recovery: point at infinify");return Y.assertValidity(),Y}hasHighS(){return x(this.s)}toBytes(p=h.format){if(ys(p),p==="der")return Vt(oe.hexFromSig(this));let{r:S,s:R}=this,L=i.toBytes(S),C=i.toBytes(R);return p==="recovered"?(A(),wt(Uint8Array.of(this.assertRecovery()),L,C)):wt(L,C)}toHex(p){return qt(this.toBytes(p))}}let O=e.bits2int||function(p){if(p.length>8192)throw new Error("input is too large");let S=De(p),R=p.length*8-c;return R>0?S>>BigInt(R):S},N=e.bits2int_modN||function(p){return i.create(O(p))},U=ir(c);function v(y){return sr("num < 2^"+c,y,Ft,U),i.toBytes(y)}function E(y,p){return k(y,void 0,"message"),p?k(t(y),void 0,"prehashed message"):y}function K(y,p,S){let{lowS:R,prehash:L,extraEntropy:C}=ms(S,h);y=E(y,L);let B=N(y),D=i.fromBytes(p);if(!i.isValidNot0(D))throw new Error("invalid private key");let P=[v(D),v(B)];if(C!=null&&C!==!1){let Y=C===!0?n(g.secretKey):C;P.push(k(Y,void 0,"extraEntropy"))}let G=wt(...P),W=B;function H(Y){let it=O(Y);if(!i.isValidNot0(it))return;let Lt=i.inv(it),X=r.BASE.multiply(it).toAffine(),ut=i.create(X.x);if(ut===Ft)return;let Rr=i.create(Lt*i.create(W+ut*D));if(Rr===Ft)return;let Hs=(X.x===ut?0:2)|Number(X.y&qe),zs=Rr;return R&&x(Rr)&&(zs=i.neg(Rr),Hs^=1),new I(ut,zs,_?void 0:Hs)}return{seed:G,k2sig:H}}function M(y,p,S={}){let{seed:R,k2sig:L}=K(y,p,S);return Ki(t.outputLen,i.BYTES,o)(R,L).toBytes(S.format)}function T(y,p,S,R={}){let{lowS:L,prehash:C,format:B}=ms(R,h);if(S=k(S,void 0,"publicKey"),p=E(p,C),!ie(y)){let D=y instanceof I?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+D)}w(y,B);try{let D=I.fromBytes(y,B),P=r.fromBytes(S);if(L&&D.hasHighS())return!1;let{r:G,s:W}=D,H=N(p),Y=i.inv(W),it=i.create(H*Y),Lt=i.create(G*Y),X=r.BASE.multiplyUnsafe(it).add(P.multiplyUnsafe(Lt));return X.is0()?!1:i.create(X.x)===G}catch{return!1}}function m(y,p,S={}){let{prehash:R}=ms(S,h);return p=E(p,R),I.fromBytes(y,"recovered").recoverPublicKey(p).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:f,utils:d,lengths:g,Point:r,sign:M,verify:T,recoverPublicKey:m,Signature:I,hash:t})}var xs={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},$l={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var La=BigInt(2);function Zl(r){let t=xs.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%t,l=u*u*r%t,f=Z(l,e,t)*l%t,d=Z(f,e,t)*l%t,g=Z(d,La,t)*u%t,h=Z(g,o,t)*g%t,_=Z(h,s,t)*h%t,x=Z(_,a,t)*_%t,b=Z(x,c,t)*x%t,A=Z(b,a,t)*_%t,w=Z(A,e,t)*l%t,I=Z(w,i,t)*h%t,O=Z(I,n,t)*u%t,N=Z(O,La,t);if(!gs.eql(gs.sqr(N),r))throw new Error("Cannot find square root");return N}var gs=Ke(xs.p,{sqrt:Zl}),Gl=_a(xs,{Fp:gs,endo:$l}),Ve=Ba(Gl,Ce);function Ta(r,t,e,n){let o=je.digest(e instanceof Uint8Array?e:e.subarray());if(Wr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ve.verify(t,s,r,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new ur(String(s))});try{return n?.signal?.throwIfAborted(),Ve.verify(t,o.digest,r,{prehash:!1,format:"der"})}catch(s){throw new ur(String(s))}}var Jr=class{type="secp256k1";raw;_key;constructor(t){this._key=Da(t),this.raw=Ca(this._key)}toMultihash(){return It.digest(St(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return Q.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:$(this.raw,t.raw)}verify(t,e,n){return Ta(this._key,e,t,n)}};function ws(r){return new Jr(r)}function Ca(r){return Ve.Point.fromBytes(r).toBytes()}function Da(r){try{return Ve.Point.fromBytes(r),r}catch(t){throw new we(String(t))}}function tn(r,t){let{Type:e,Data:n}=Kt.decode(r),o=n??new Uint8Array;switch(e){case tt.RSA:return fs(o,t);case tt.Ed25519:return Uo(o);case tt.secp256k1:return ws(o);case tt.ECDSA:return ho(o);default:throw new se}}function Oa(r){let{Type:t,Data:e}=Kt.decode(r.digest),n=e??new Uint8Array;switch(t){case tt.Ed25519:return Uo(n);case tt.secp256k1:return ws(n);case tt.ECDSA:return ho(n);default:throw new se}}function St(r){return Kt.encode({Type:tt[r.type],Data:r.raw})}var Ka=Symbol.for("nodejs.util.inspect.custom"),Yl=114,mr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Tr]=!0;toString(){return this.string==null&&(this.string=Q.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return et.createV1(Yl,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return $(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return $(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ka](){return`PeerId(${this.toString()})`}},yr=class extends mr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},br=class extends mr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},gr=class extends mr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Xl=2336,xr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=It.digest(z(this.url))}[Ka](){return`PeerId(${this.url})`}[Tr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return et.createV1(Xl,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=V(t)),t.toString()===this.toString())}};var jl=114,Pa=2336;function ka(r){if(r.type==="Ed25519")return new br({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new gr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new yr({multihash:r.toCID().multihash,publicKey:r});throw new se}function Es(r){if(Jl(r))return new yr({multihash:r});if(Ql(r))try{let t=Oa(r);if(t.type==="Ed25519")return new br({multihash:r,publicKey:t});if(t.type==="secp256k1")return new gr({multihash:r,publicKey:t})}catch{let e=V(r.digest);return new xr(new URL(e))}throw new Lr("Supplied PeerID Multihash is invalid")}function en(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==jl&&r.code!==Pa)throw new Br("Supplied PeerID CID is invalid");if(r.code===Pa){let t=V(r.multihash.digest);return new xr(new URL(t))}return Es(r.multihash)}function Ql(r){return r.code===It.code}function Jl(r){return r.code===je.code}var wr;(function(r){let t;r.codec=()=>(t==null&&(t=yt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.publicKey!=null&&e.publicKey.byteLength>0&&(n.uint32(10),n.bytes(e.publicKey)),e.payloadType!=null&&e.payloadType.byteLength>0&&(n.uint32(18),n.bytes(e.payloadType)),e.payload!=null&&e.payload.byteLength>0&&(n.uint32(26),n.bytes(e.payload)),e.signature!=null&&e.signature.byteLength>0&&(n.uint32(42),n.bytes(e.signature)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={publicKey:rt(0),payloadType:rt(0),payload:rt(0),signature:rt(0)},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.publicKey=e.bytes();break}case 2:{s.payloadType=e.bytes();break}case 3:{s.payload=e.bytes();break}case 5:{s.signature=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>mt(e,r.codec()),r.decode=(e,n)=>pt(e,r.codec(),n)})(wr||(wr={}));var rn=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var He=class r{static createFromProtobuf=t=>{let e=wr.decode(t),n=tn(e.publicKey);return new r({publicKey:n,payloadType:e.payloadType,payload:e.payload,signature:e.signature})};static seal=async(t,e,n)=>{if(e==null)throw new Error("Missing private key");let o=t.domain,s=t.codec,i=t.marshal(),a=Na(o,s,i),c=await e.sign(a.subarray(),n);return new r({publicKey:e.publicKey,payloadType:s,payload:i,signature:c})};static openAndCertify=async(t,e,n)=>{let o=r.createFromProtobuf(t);if(!await o.validate(e,n))throw new rn("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:e,payloadType:n,payload:o,signature:s}=t;this.publicKey=e,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=wr.encode({publicKey:St(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return t==null?!1:$(this.marshal(),t.marshal())}async validate(t,e){let n=Na(t,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,e)}},Na=(r,t,e)=>{let n=z(r),o=Zr(n.byteLength),s=Zr(t.length),i=Zr(e.length);return new dt(o,n,s,t,i,e)};var ct=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Wt=class extends Error{static name="ValidationError";name="ValidationError"},nn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},on=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var sn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}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(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,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 l=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let d=Number.parseInt(f,t);if(!Number.isNaN(d))return d});if(l===void 0)break;if(s*=t,s+=l,s>u||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[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];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return e.set(s.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var tf=45,ef=15,an=new sn;function Ua(r){if(!(r.length>ef))return an.new(r).parseWith(()=>an.readIPv4Addr())}function Ma(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>tf))return an.new(r).parseWith(()=>an.readIPv6Addr())}function cn(r){return!!Ua(r)}function qa(r){return!!Ma(r)}function Ss(r){return t=>V(t,r)}function As(r){return t=>z(t,r)}function ze(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function ye(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function Va(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=z(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ye(n);return kt([e,o],e.length+o.length)}function Ha(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=Tt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ye(n);return kt([e,o],e.length+o.length)}function _s(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=V(t,"base32"),o=ze(e);return`${n}:${o}`}var Is=function(r){r=r.toString().trim();let t=new Uint8Array(4);return r.split(/\./g).forEach((e,n)=>{let o=parseInt(e,10);if(isNaN(o)||o<0||o>255)throw new ct("Invalid byte value in IP address");t[n]=o}),t},za=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=cn(e[n]),i;s&&(i=Is(e[n]),e[n]=V(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,V(i.subarray(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let s=[n,1];for(n=9-e.length;n>0;n--)s.push("0");e.splice.apply(e,s)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){e[n]===""&&(e[n]="0");let s=parseInt(e[n],16);if(isNaN(s)||s<0||s>65535)throw new ct("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Fa=function(r){if(r.byteLength!==4)throw new ct("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},Wa=function(r){if(r.byteLength!==16)throw new ct("IPv6 address was incorrect length");let t=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],s=r[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let e=t.join(":");try{let n=new URL(`http://[${e}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new ct(`Invalid IPv6 address "${e}"`)}};function $a(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new ct(`Invalid IPv6 address "${r}"`)}}var vs=Object.values(Qe).map(r=>r.decoder),rf=(function(){let r=vs[0].or(vs[1]);return vs.slice(2).forEach(t=>r=r.or(t)),r})();function Za(r){return rf.decode(r)}function Ga(r){return t=>r.encoder.encode(t)}function nf(r){if(parseInt(r).toString()!==r)throw new Wt("Value must be an integer")}function of(r){if(r<0)throw new Wt("Value must be a positive integer, or zero")}function sf(r){return t=>{if(t>r)throw new Wt(`Value must be smaller than or equal to ${r}`)}}function af(...r){return t=>{for(let e of r)e(t)}}var Er=af(nf,of,sf(65535));var st=-1,Rs=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let e;if(typeof t=="string"?e=this.protocolsByName.get(t):e=this.protocolsByCode.get(t),e==null)throw new on(`Protocol ${t} was unknown`);return e}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(e=>{this.protocolsByName.set(e,t)})}removeProtocol(t){let e=this.protocolsByCode.get(t);e!=null&&(this.protocolsByCode.delete(e.code),this.protocolsByName.delete(e.name),e.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},$t=new Rs,Zf=[{code:4,name:"ip4",size:32,valueToBytes:Is,bytesToValue:Fa,validate:r=>{if(!cn(r))throw new Wt(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ye,bytesToValue:ze,validate:Er},{code:273,name:"udp",size:16,valueToBytes:ye,bytesToValue:ze,validate:Er},{code:33,name:"dccp",size:16,valueToBytes:ye,bytesToValue:ze,validate:Er},{code:41,name:"ip6",size:128,valueToBytes:za,bytesToValue:Wa,stringToValue:$a,validate:r=>{if(!qa(r))throw new Wt(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:st},{code:43,name:"ipcidr",size:8,bytesToValue:Ss("base10"),valueToBytes:As("base10")},{code:53,name:"dns",size:st},{code:54,name:"dns4",size:st},{code:55,name:"dns6",size:st},{code:56,name:"dnsaddr",size:st},{code:132,name:"sctp",size:16,valueToBytes:ye,bytesToValue:ze,validate:Er},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:st,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:st,bytesToValue:Ss("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?As("base58btc")(r):et.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:_s,valueToBytes:Va},{code:445,name:"onion3",size:296,bytesToValue:_s,valueToBytes:Ha},{code:446,name:"garlic64",size:st},{code:447,name:"garlic32",size:st},{code:448,name:"tls"},{code:449,name:"sni",size:st},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:st,bytesToValue:Ga(Jn),valueToBytes:Za},{code:480,name:"http"},{code:481,name:"http-path",size:st,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.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:st}];Zf.forEach(r=>{$t.addProtocol(r)});function Ya(r){let t=[],e=0;for(;e<r.length;){let n=Fo(r,e),o=$t.getProtocol(n),s=_t(n),i=Gf(o,r,e+s),a=0;i>0&&o.size===st&&(a=_t(i));let c=s+a+i,u={code:n,name:o.name,bytes:r.subarray(e,e+c)};if(i>0){let l=e+s+a,f=r.subarray(l,l+i);u.value=o.bytesToValue?.(f)??V(f)}t.push(u),e+=c}return t}function Xa(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=$t.getProtocol(n.code),s=_t(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??z(n.value),a=i.byteLength,o.size===st&&(c=_t(a)));let u=new Uint8Array(s+c+a),l=0;Ne(n.code,u,l),l+=s,i!=null&&(o.size===st&&(Ne(a,u,l),l+=c),u.set(i,l)),n.bytes=u}e.push(n.bytes),t+=n.bytes.byteLength}return kt(e,t)}function ja(r){if(r.charAt(0)!=="/")throw new ct('String multiaddr must start with "/"');let t=[],e="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(e==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let c=$t.getProtocol(o);if(e==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",e="protocol";continue}else if(a)throw new ct(`Component ${o} was missing value`);e="value"}else if(e==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new ct(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}t.push(u),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new ct("Incomplete multiaddr");return t}function Qa(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=$t.getProtocol(t.code);if(e==null)throw new ct(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function Gf(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:Fo(t,e)}var Yf=Symbol.for("nodejs.util.inspect.custom"),Ls=Symbol.for("@multiformats/multiaddr");function Xf(r){if(r==null&&(r="/"),ln(r))return r.getComponents();if(r instanceof Uint8Array)return Ya(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),ja(r);if(Array.isArray(r))return r;throw new ct("Must be a string, Uint8Array, Component[], or another Multiaddr")}var un=class r{[Ls]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=Xf(t),e.validate!==!1&&jf(this)}get bytes(){return this.#r==null&&(this.#r=Xa(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Qa(this.#t)),this.#e}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let e=new r(t);return new r([...this.#t,...e.getComponents()],{validate:!1})}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new nn(`Address ${this.toString()} does not contain subaddress: ${e}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(t){let e;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){e=n;break}return new r(this.#t.slice(0,e),{validate:!1})}equals(t){return $(this.bytes,t.bytes)}[Yf](){return`Multiaddr(${this.toString()})`}};function jf(r){r.getComponents().forEach(t=>{let e=$t.getProtocol(t.code);t.value!=null&&e.validate?.(t.value)})}function ln(r){return!!r?.[Ls]}function be(r){return new un(r)}var Ja="libp2p-peer-record",tc=Uint8Array.from([3,1]);var vr;(function(r){let t;(function(n){let o;n.codec=()=>(o==null&&(o=yt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.multiaddr!=null&&s.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(s.multiaddr)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={multiaddr:rt(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let l=s.uint32();switch(l>>>3){case 1:{c.multiaddr=s.bytes();break}default:{s.skipType(l&7);break}}}return c})),o),n.encode=s=>mt(s,n.codec()),n.decode=(s,i)=>pt(s,n.codec(),i)})(t=r.AddressInfo||(r.AddressInfo={}));let e;r.codec=()=>(e==null&&(e=yt((n,o,s={})=>{if(s.lengthDelimited!==!1&&o.fork(),n.peerId!=null&&n.peerId.byteLength>0&&(o.uint32(10),o.bytes(n.peerId)),n.seq!=null&&n.seq!==0n&&(o.uint32(16),o.uint64(n.seq)),n.addresses!=null)for(let i of n.addresses)o.uint32(26),r.AddressInfo.codec().encode(i,o);s.lengthDelimited!==!1&&o.ldelim()},(n,o,s={})=>{let i={peerId:rt(0),seq:0n,addresses:[]},a=o==null?n.len:n.pos+o;for(;n.pos<a;){let c=n.uint32();switch(c>>>3){case 1:{i.peerId=n.bytes();break}case 2:{i.seq=n.uint64();break}case 3:{if(s.limits?.addresses!=null&&i.addresses.length===s.limits.addresses)throw new me('Decode error - map field "addresses" had too many elements');i.addresses.push(r.AddressInfo.codec().decode(n,n.uint32(),{limits:s.limits?.addresses$}));break}default:{n.skipType(c&7);break}}}return i})),e),r.encode=n=>mt(n,r.codec()),r.decode=(n,o)=>pt(n,r.codec(),o)})(vr||(vr={}));function ec(r,t){let e=(n,o)=>n.toString().localeCompare(o.toString());return r.length!==t.length?!1:(t.sort(e),r.sort(e).every((n,o)=>t[o].equals(n)))}var ge=class r{static createFromProtobuf=t=>{let e=vr.decode(t),n=Es(Re(e.peerId)),o=(e.addresses??[]).map(i=>be(i.multiaddr)),s=e.seq;return new r({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Ja;static CODEC=tc;peerId;multiaddrs;seqNumber;domain=r.DOMAIN;codec=r.CODEC;marshaled;constructor(t){let{peerId:e,multiaddrs:n,seqNumber:o}=t;this.peerId=e,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=vr.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(t=>({multiaddr:t.bytes}))})),this.marshaled}equals(t){return!(!(t instanceof r)||!this.peerId.equals(t.peerId)||this.seqNumber!==t.seqNumber||!ec(this.multiaddrs,t.multiaddrs))}};function Qf(r){return r[Symbol.asyncIterator]!=null}function Jf(r){if(Qf(r))return(async()=>{let e=[];for await(let n of r)e.push(n);return e})();let t=[];for(let e of r)t.push(e);return t}var rc=Jf;function fn(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return e}var Sr=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[e,n]of t.entries())this.map.set(e.toString(),{key:e,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return fn(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((e,n)=>{t(e.value,e.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,e){this.map.set(t.toString(),{key:t,value:e})}keys(){return fn(this.map.values(),t=>t.key)}values(){return fn(this.map.values(),t=>t.value)}get size(){return this.map.size}};function dn(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var hn=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},Fe=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new hn(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new hn(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Ts=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function nc(r={}){return td(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function td(r,t){t=t??{};let e=t.onEnd,n=new Fe,o,s,i,a=dn(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((x,b)=>{s=A=>{s=null,n.push(A);try{x(r(n))}catch(w){b(w)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=dn()})}},u=x=>s!=null?s(x):(n.push(x),o),l=x=>(n=new Fe,s!=null?s({error:x}):(n.push({error:x}),o)),f=x=>{if(i)return o;if(t?.objectMode!==!0&&x?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:x})},d=x=>i?o:(i=!0,x!=null?l(x):u({done:!0})),g=()=>(n=new Fe,d(),{done:!0}),h=x=>(d(x),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:g,throw:h,push:f,end:d,get readableLength(){return n.size},onEmpty:async x=>{let b=x?.signal;if(b?.throwIfAborted(),n.isEmpty())return;let A,w;b!=null&&(A=new Promise((I,O)=>{w=()=>{O(new Ts)},b.addEventListener("abort",w)}));try{await Promise.race([a.promise,A])}finally{w!=null&&b!=null&&b?.removeEventListener("abort",w)}}},e==null)return o;let _=o;return o={[Symbol.asyncIterator](){return this},next(){return _.next()},throw(x){return _.throw(x),e!=null&&(e(x),e=void 0),{done:!0}},return(){return _.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(x){return _.end(x),e!=null&&(e(x),e=void 0),o},get readableLength(){return _.readableLength},onEmpty:x=>_.onEmpty(x)},o}function ed(r){return r.reason}async function oc(r,t,e){if(t==null)return r;let n=e?.translateError??ed;if(t.aborted)return r.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([r,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}var Cs=class extends Sr{metric;constructor(t){super();let{name:e,metrics:n}=t;this.metric=n.registerMetric(e),this.updateComponentMetric()}set(t,e){return super.set(t,e),this.updateComponentMetric(),this}delete(t){let e=super.delete(t);return this.updateComponentMetric(),e}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function Ds(r){let{name:t,metrics:e}=r,n;return e!=null?n=new Cs({name:t,metrics:e}):n=new Sr,n}var vt=class extends Error{static name="AbortError";name="AbortError";constructor(t="The operation was aborted",...e){super(t,...e)}};async function pn(r,t,e,n){let o=new vt(n?.errorMessage);n?.errorCode!=null&&(o.code=n.errorCode);let s=n?.errorEvent??"error";return e?.aborted===!0?Promise.reject(o):new Promise((i,a)=>{function c(){Ks(e,"abort",f),Ks(r,t,u),Ks(r,s,l)}let u=d=>{try{if(n?.filter?.(d)===!1)return}catch(g){c(),a(g);return}c(),i(d)},l=d=>{if(c(),d instanceof Error){a(d);return}a(d.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.`))},f=()=>{c(),a(o)};Os(e,"abort",f),Os(r,t,u),Os(r,s,l)})}function Os(r,t,e){r!=null&&(sc(r)?r.addEventListener(t,e):r.addListener(t,e))}function Ks(r,t,e){r!=null&&(sc(r)?r.removeEventListener(t,e):r.removeListener(t,e))}function sc(r){return typeof r.addEventListener=="function"&&typeof r.removeEventListener=="function"}var mn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};var yn=class{deferred;signal;constructor(t){this.signal=t,this.deferred=Promise.withResolvers(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new vt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function rd(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var bn=class{id;fn;options;recipients;status;timeline;controller;constructor(t,e){this.id=rd(),this.status="queued",this.fn=t,this.options=e,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(t){this.controller.abort(t)}onAbort(){this.recipients.reduce((e,n)=>e&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new vt),this.cleanup())}async join(t={}){let e=new yn(t.signal);return this.recipients.push(e),t.signal?.addEventListener("abort",this.onAbort),e.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await oc(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(e=>{e.deferred.resolve(t)}),this.status="complete"}catch(t){this.recipients.forEach(e=>{e.deferred.reject(t)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(t=>{t.cleanup(),t.signal?.removeEventListener("abort",this.onAbort)})}};function Ps(r,t){let e,n=function(){let o=function(){e=void 0,r()};clearTimeout(e),e=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(e)},n}var Ar=class extends ve{concurrency;maxSize;queue;pending;sort;autoStart;constructor(t={}){super(),this.concurrency=t.concurrency??Number.POSITIVE_INFINITY,this.maxSize=t.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.autoStart=t.autoStart??!0,this.sort=t.sort,this.queue=[],this.emitEmpty=Ps(this.emitEmpty.bind(this),1),this.emitIdle=Ps(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 t;for(let e of this.queue)if(e.status==="queued"){t=e;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let e=0;e<this.queue.length;e++)if(this.queue[e]===t){this.queue.splice(e,1);break}this.pending--,this.safeDispatchEvent("next"),this.autoStart&&this.tryToStartAnother()}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}start(){this.autoStart===!1&&(this.autoStart=!0,this.tryToStartAnother())}pause(){this.autoStart=!1}async add(t,e){if(e?.signal?.throwIfAborted(),this.size===this.maxSize)throw new mn;let n=new bn(t,e);return this.enqueue(n),this.safeDispatchEvent("add"),this.autoStart&&this.tryToStartAnother(),n.join(e).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(t=>{t.abort(new vt)}),this.clear()}async onEmpty(t){this.size!==0&&await pn(this,"empty",t?.signal)}async onSizeLessThan(t,e){this.size<t||await pn(this,"next",e?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await pn(this,"idle",t?.signal)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(t){t?.signal?.throwIfAborted();let e=nc({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),e.end(c)},o=c=>{c.detail!=null&&e.push(c.detail.result)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new vt("Queue aborted"))};this.addEventListener("success",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*e}finally{this.removeEventListener("success",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};var gn="lock:worker:request-read",xn="lock:worker:abort-read-request",wn="lock:worker:release-read",En="lock:master:grant-read",vn="lock:master:error-read",Sn="lock:worker:request-write",An="lock:worker:abort-write-request",_n="lock:worker:release-write",In="lock:master:grant-write",Rn="lock:master:error-write",Bn="lock:worker:finalize",Ln="mortice",ic={singleProcess:!1};var ks=(r,t,e,n,o,s,i,a,c)=>u=>{if(u.data==null)return;let l={type:u.data.type,name:u.data.name,identifier:u.data.identifier};l.type===o&&r.safeDispatchEvent(e,{detail:{name:l.name,identifier:l.identifier,handler:async()=>{t.postMessage({type:c,name:l.name,identifier:l.identifier}),await new Promise(f=>{let d=g=>{if(g?.data==null)return;let h={type:g.data.type,name:g.data.name,identifier:g.data.identifier};h.type===a&&h.identifier===l.identifier&&(t.removeEventListener("message",d),f())};t.addEventListener("message",d)})},onError:f=>{t.postMessage({type:i,name:l.name,identifier:l.identifier,error:{message:f.message,name:f.name,stack:f.stack}})}}}),l.type===s&&r.safeDispatchEvent(n,{detail:{name:l.name,identifier:l.identifier}}),l.type===Bn&&r.safeDispatchEvent("finalizeRequest",{detail:{name:l.name}})};var ac=(r=10)=>Math.random().toString().substring(2,r+2);var Tn=class{name;channel;constructor(t){this.name=t,this.channel=new BroadcastChannel(Ln)}readLock(t){return this.sendRequest(gn,xn,En,vn,wn,t)}writeLock(t){return this.sendRequest(Sn,An,In,Rn,_n,t)}finalize(){this.channel.postMessage({type:Bn,name:this.name}),this.channel.close()}async sendRequest(t,e,n,o,s,i){i?.signal?.throwIfAborted();let a=ac();return this.channel.postMessage({type:t,identifier:a,name:this.name}),new Promise((c,u)=>{let l=()=>{this.channel.postMessage({type:e,identifier:a,name:this.name})};i?.signal?.addEventListener("abort",l,{once:!0});let f=d=>{if(d.data?.identifier===a&&(d.data?.type===n&&(this.channel.removeEventListener("message",f),i?.signal?.removeEventListener("abort",l),c(()=>{this.channel.postMessage({type:s,identifier:a,name:this.name})})),d.data.type===o)){this.channel.removeEventListener("message",f),i?.signal?.removeEventListener("abort",l);let g=new Error;d.data.error!=null&&(g.message=d.data.error.message,g.name=d.data.error.name,g.stack=d.data.error.stack),u(g)}};this.channel.addEventListener("message",f)})}};var cc=r=>{if(r=Object.assign({},ic,r),!!globalThis.document||r.singleProcess){let e=new BroadcastChannel(Ln),n=new ve;return e.addEventListener("message",ks(n,e,"requestReadLock","abortReadLockRequest",gn,xn,vn,wn,En)),e.addEventListener("message",ks(n,e,"requestWriteLock","abortWriteLockRequest",Sn,An,Rn,_n,In)),n}return new Tn(r.name)};var xe=new Map,_r;function uc(r){return typeof r?.readLock=="function"&&typeof r?.writeLock=="function"}function nd(r){if(_r==null&&(_r=cc(r),!uc(_r))){let t=_r;t.addEventListener("requestReadLock",e=>{let n=e.detail.name,o=e.detail.identifier,s=xe.get(n);if(s==null)return;let i=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==o||i.abort()};t.addEventListener("abortReadLockRequest",a),s.readLock({signal:i.signal}).then(async c=>{await e.detail.handler().finally(()=>{c()})}).catch(c=>{e.detail.onError(c)}).finally(()=>{t.removeEventListener("abortReadLockRequest",a)})}),t.addEventListener("requestWriteLock",e=>{let n=e.detail.name,o=e.detail.identifier,s=xe.get(n);if(s==null)return;let i=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==o||i.abort()};t.addEventListener("abortWriteLockRequest",a),s.writeLock({signal:i.signal}).then(async c=>{await e.detail.handler().finally(()=>{c()})}).catch(c=>{e.detail.onError(c)}).finally(()=>{t.removeEventListener("abortWriteLockRequest",a)})}),t.addEventListener("finalizeRequest",e=>{let n=e.detail.name,o=xe.get(n);o?.finalize()})}return _r}async function Ns(r,t){let e,n,o=new Promise((i,a)=>{e=i,n=a}),s=()=>{n(new vt)};return t?.signal?.addEventListener("abort",s,{once:!0}),r.add(async()=>{await new Promise(i=>{e(()=>{t?.signal?.removeEventListener("abort",s),i()})})},{signal:t?.signal}).catch(i=>{n(i)}),o}var lc=(r,t)=>{let e=xe.get(r);if(e!=null)return e;let n=nd(t);if(uc(n))return e=n,xe.set(r,e),e;let o=new Ar({concurrency:1}),s;return e={async readLock(i){if(s!=null)return Ns(s,i);s=new Ar({concurrency:t.concurrency,autoStart:!1});let a=s,c=Ns(s,i);return o.add(async()=>{a.start(),await a.onIdle().then(()=>{s===a&&(s=null)})}),c},async writeLock(i){return s=null,Ns(o,i)},finalize:()=>{xe.delete(r)},queue:o},xe.set(r,e),t.autoFinalize===!0&&o.addEventListener("idle",()=>{e.finalize()},{once:!0}),e};var od={name:"lock",concurrency:1/0,singleProcess:!1,autoFinalize:!1};function Us(r){let t=Object.assign({},od,r);return lc(t.name,t)}var Zt;(function(r){let t;(function(o){let s;o.codec=()=>(s==null&&(s=yt((i,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),i.key!=null&&i.key!==""&&(a.uint32(10),a.string(i.key)),i.value!=null&&i.value.byteLength>0&&(a.uint32(18),a.bytes(i.value)),c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let u={key:"",value:rt(0)},l=a==null?i.len:i.pos+a;for(;i.pos<l;){let f=i.uint32();switch(f>>>3){case 1:{u.key=i.string();break}case 2:{u.value=i.bytes();break}default:{i.skipType(f&7);break}}}return u})),s),o.encode=i=>mt(i,o.codec()),o.decode=(i,a)=>pt(i,o.codec(),a)})(t=r.Peer$metadataEntry||(r.Peer$metadataEntry={}));let e;(function(o){let s;o.codec=()=>(s==null&&(s=yt((i,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),i.key!=null&&i.key!==""&&(a.uint32(10),a.string(i.key)),i.value!=null&&(a.uint32(18),Dn.codec().encode(i.value,a)),c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let u={key:""},l=a==null?i.len:i.pos+a;for(;i.pos<l;){let f=i.uint32();switch(f>>>3){case 1:{u.key=i.string();break}case 2:{u.value=Dn.codec().decode(i,i.uint32(),{limits:c.limits?.value});break}default:{i.skipType(f&7);break}}}return u})),s),o.encode=i=>mt(i,o.codec()),o.decode=(i,a)=>pt(i,o.codec(),a)})(e=r.Peer$tagsEntry||(r.Peer$tagsEntry={}));let n;r.codec=()=>(n==null&&(n=yt((o,s,i={})=>{if(i.lengthDelimited!==!1&&s.fork(),o.addresses!=null)for(let a of o.addresses)s.uint32(10),Cn.codec().encode(a,s);if(o.protocols!=null)for(let a of o.protocols)s.uint32(18),s.string(a);if(o.publicKey!=null&&(s.uint32(34),s.bytes(o.publicKey)),o.peerRecordEnvelope!=null&&(s.uint32(42),s.bytes(o.peerRecordEnvelope)),o.metadata!=null&&o.metadata.size!==0)for(let[a,c]of o.metadata.entries())s.uint32(50),r.Peer$metadataEntry.codec().encode({key:a,value:c},s);if(o.tags!=null&&o.tags.size!==0)for(let[a,c]of o.tags.entries())s.uint32(58),r.Peer$tagsEntry.codec().encode({key:a,value:c},s);o.updated!=null&&(s.uint32(64),s.uint64Number(o.updated)),i.lengthDelimited!==!1&&s.ldelim()},(o,s,i={})=>{let a={addresses:[],protocols:[],metadata:new Map,tags:new Map},c=s==null?o.len:o.pos+s;for(;o.pos<c;){let u=o.uint32();switch(u>>>3){case 1:{if(i.limits?.addresses!=null&&a.addresses.length===i.limits.addresses)throw new me('Decode error - map field "addresses" had too many elements');a.addresses.push(Cn.codec().decode(o,o.uint32(),{limits:i.limits?.addresses$}));break}case 2:{if(i.limits?.protocols!=null&&a.protocols.length===i.limits.protocols)throw new me('Decode error - map field "protocols" had too many elements');a.protocols.push(o.string());break}case 4:{a.publicKey=o.bytes();break}case 5:{a.peerRecordEnvelope=o.bytes();break}case 6:{if(i.limits?.metadata!=null&&a.metadata.size===i.limits.metadata)throw new dr('Decode error - map field "metadata" had too many elements');let l=r.Peer$metadataEntry.codec().decode(o,o.uint32());a.metadata.set(l.key,l.value);break}case 7:{if(i.limits?.tags!=null&&a.tags.size===i.limits.tags)throw new dr('Decode error - map field "tags" had too many elements');let l=r.Peer$tagsEntry.codec().decode(o,o.uint32(),{limits:{value:i.limits?.tags$value}});a.tags.set(l.key,l.value);break}case 8:{a.updated=o.uint64Number();break}default:{o.skipType(u&7);break}}}return a})),n),r.encode=o=>mt(o,r.codec()),r.decode=(o,s)=>pt(o,r.codec(),s)})(Zt||(Zt={}));var Cn;(function(r){let t;r.codec=()=>(t==null&&(t=yt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.multiaddr!=null&&e.multiaddr.byteLength>0&&(n.uint32(10),n.bytes(e.multiaddr)),e.isCertified!=null&&(n.uint32(16),n.bool(e.isCertified)),e.observed!=null&&(n.uint32(24),n.uint64Number(e.observed)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={multiaddr:rt(0)},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.multiaddr=e.bytes();break}case 2:{s.isCertified=e.bool();break}case 3:{s.observed=e.uint64Number();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>mt(e,r.codec()),r.decode=(e,n)=>pt(e,r.codec(),n)})(Cn||(Cn={}));var Dn;(function(r){let t;r.codec=()=>(t==null&&(t=yt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.value!=null&&e.value!==0&&(n.uint32(8),n.uint32(e.value)),e.expiry!=null&&(n.uint32(16),n.uint64(e.expiry)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={value:0},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.value=e.uint32();break}case 2:{s.expiry=e.uint64();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>mt(e,r.codec()),r.decode=(e,n)=>pt(e,r.codec(),n)})(Dn||(Dn={}));function sd(r,t){if(r.publicKey!=null||t.publicKey==null)return r;let e;r.type==="RSA"&&(e=r.toMultihash());let n=tn(t.publicKey,e);return ka(n)}function fc(r,t,e){let n=Zt.decode(t);return We(r,n,e)}function We(r,t,e){let n=new Map,o=BigInt(Date.now());for(let[s,i]of t.tags.entries())i.expiry!=null&&i.expiry<o||n.set(s,i);return{...t,id:sd(r,t),addresses:t.addresses.filter(({observed:s})=>s!=null&&s>Date.now()-e).map(({multiaddr:s,isCertified:i})=>({multiaddr:be(s),isCertified:i??!1})),metadata:t.metadata,peerRecordEnvelope:t.peerRecordEnvelope??void 0,tags:n}}function dc(r,t){return id(r.addresses,t.addresses)&&ad(r.protocols,t.protocols)&&cd(r.publicKey,t.publicKey)&&ud(r.peerRecordEnvelope,t.peerRecordEnvelope)&&ld(r.metadata,t.metadata)&&fd(r.tags,t.tags)}function id(r,t){return pc(r,t,(e,n)=>!(e.isCertified!==n.isCertified||!$(e.multiaddr,n.multiaddr)))}function ad(r,t){return pc(r,t,(e,n)=>e===n)}function cd(r,t){return hc(r,t)}function ud(r,t){return hc(r,t)}function ld(r,t){return mc(r,t,(e,n)=>$(e,n))}function fd(r,t){return mc(r,t,(e,n)=>e.value===n.value&&e.expiry===n.expiry)}function hc(r,t){return r==null&&t==null?!0:r!=null&&t!=null?$(r,t):!1}function pc(r,t,e){if(r.length!==t.length)return!1;for(let n=0;n<r.length;n++)if(!e(r[n],t[n]))return!1;return!0}function mc(r,t,e){if(r.size!==t.size)return!1;for(let[n,o]of r.entries()){let s=t.get(n);if(s==null||!e(o,s))return!1}return!0}var Gt="/",yc=new TextEncoder().encode(Gt),On=yc[0],Kn=class r{_buf;constructor(t,e){if(typeof t=="string")this._buf=z(t);else if(t instanceof Uint8Array)this._buf=t;else throw new Error("Invalid key, should be String of Uint8Array");if(e==null&&(e=!0),e&&this.clean(),this._buf.byteLength===0||this._buf[0]!==On)throw new Error("Invalid key")}toString(t="utf8"){return V(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new r(t.join(Gt))}static random(){return new r(Math.random().toString().substring(2))}static asKey(t){return t instanceof Uint8Array||typeof t=="string"?new r(t):typeof t.uint8Array=="function"?new r(t.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=yc),this._buf[0]!==On){let t=new Uint8Array(this._buf.byteLength+1);t.fill(On,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===On;)this._buf=this._buf.subarray(0,-1)}less(t){let e=this.list(),n=t.list();for(let o=0;o<e.length;o++){if(n.length<o+1)return!1;let s=e[o],i=n[o];if(s<i)return!0;if(s>i)return!1}return e.length<n.length}reverse(){return r.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let t=this.namespaces();return t[t.length-1]}list(){return this.toString().split(Gt).slice(1)}type(){return dd(this.baseNamespace())}name(){return hd(this.baseNamespace())}instance(t){return new r(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(Gt)||(t+=Gt),t+=this.type(),new r(t)}parent(){let t=this.list();return t.length===1?new r(Gt):new r(t.slice(0,-1).join(Gt))}child(t){return this.toString()===Gt?t:t.toString()===Gt?this:new r(this.toString()+t.toString(),!1)}isAncestorOf(t){return t.toString()===this.toString()?!1:t.toString().startsWith(this.toString())}isDecendantOf(t){return t.toString()===this.toString()?!1:this.toString().startsWith(t.toString())}isTopLevel(){return this.list().length===1}concat(...t){return r.withNamespaces([...this.namespaces(),...pd(t.map(e=>e.namespaces()))])}};function dd(r){let t=r.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function hd(r){let t=r.split(":");return t[t.length-1]}function pd(r){return[].concat(...r)}var Ms="/peers/";function Ir(r){if(!Ee(r)||r.type==null)throw new q("Invalid PeerId");let t=r.toCID().toString();return new Kn(`${Ms}${t}`)}async function bc(r,t,e,n,o){let s=new Map;for(let i of e){if(i==null)continue;if(i.multiaddr instanceof Uint8Array&&(i.multiaddr=be(i.multiaddr)),!ln(i.multiaddr))throw new q("Multiaddr was invalid");if(!await t(r,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 r.equals(c)&&(a=a.decapsulate(be(`/p2p/${r}`))),{isCertified:i,multiaddr:a.bytes}})}async function kn(r,t,e,n){if(t==null)throw new q("Invalid PeerData");if(t.publicKey!=null&&r.publicKey!=null&&!t.publicKey.equals(r.publicKey))throw new q("publicKey bytes do not match peer id publicKey bytes");let o=n.existingPeer?.peer;if(o!=null&&!r.equals(o.id))throw new q("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(e==="patch"){if((t.multiaddrs!=null||t.addresses!=null)&&(s=[],t.multiaddrs!=null&&s.push(...t.multiaddrs.map(d=>({isCertified:!1,multiaddr:d}))),t.addresses!=null&&s.push(...t.addresses)),t.protocols!=null&&(i=new Set(t.protocols)),t.metadata!=null){let d=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);a=Pn(d,{validate:gc})}if(t.tags!=null){let d=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags);c=Pn(d,{validate:xc,map:wc})}t.peerRecordEnvelope!=null&&(u=t.peerRecordEnvelope)}if(e==="merge"){if(t.multiaddrs!=null&&s.push(...t.multiaddrs.map(d=>({isCertified:!1,multiaddr:d}))),t.addresses!=null&&s.push(...t.addresses),t.protocols!=null&&(i=new Set([...i,...t.protocols])),t.metadata!=null){let d=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);for(let[g,h]of d)h==null?a.delete(g):a.set(g,h);a=Pn([...a.entries()],{validate:gc})}if(t.tags!=null){let d=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags),g=new Map(c);for(let[h,_]of d)_==null?g.delete(h):g.set(h,_);c=Pn([...g.entries()],{validate:xc,map:wc})}t.peerRecordEnvelope!=null&&(u=t.peerRecordEnvelope)}let l;o?.id.publicKey!=null?l=St(o.id.publicKey):t.publicKey!=null?l=St(t.publicKey):r.publicKey!=null&&(l=St(r.publicKey));let f={addresses:await bc(r,n.addressFilter??(async()=>!0),s,n.existingPeer?.peerPB.addresses,n),protocols:[...i.values()].sort((d,g)=>d.localeCompare(g)),metadata:a,tags:c,publicKey:l,peerRecordEnvelope:u};return f.addresses.forEach(d=>{d.observed=n.existingPeer?.peerPB.addresses?.find(g=>$(g.multiaddr,g.multiaddr))?.observed??Date.now()}),r.type!=="RSA"&&delete f.publicKey,f}function Pn(r,t){let e=new Map;for(let[n,o]of r)o!=null&&t.validate(n,o);for(let[n,o]of r.sort(([s],[i])=>s.localeCompare(i)))o!=null&&e.set(n,t.map?.(n,o)??o);return e}function gc(r,t){if(typeof r!="string")throw new q("Metadata key must be a string");if(!(t instanceof Uint8Array))throw new q("Metadata value must be a Uint8Array")}function xc(r,t){if(typeof r!="string")throw new q("Tag name must be a string");if(t.value!=null){if(parseInt(`${t.value}`,10)!==t.value)throw new q("Tag value must be an integer");if(t.value<0||t.value>100)throw new q("Tag value must be between 0-100")}if(t.ttl!=null){if(parseInt(`${t.ttl}`,10)!==t.ttl)throw new q("Tag ttl must be an integer");if(t.ttl<0)throw new q("Tag ttl must be between greater than 0")}}function wc(r,t){let e;t.expiry!=null&&(e=t.expiry),t.ttl!=null&&(e=BigInt(Date.now()+Number(t.ttl)));let n={value:t.value??0};return e!=null&&(n.expiry=e),n}function Ec(r){let t=r.toString().split("/")[2],e=et.parse(t,Tt);return en(e)}function qs(r,t,e){let n=Ec(r);return fc(n,t,e)}function md(r,t){return{prefix:Ms,filters:(r.filters??[]).map(e=>({key:n,value:o})=>e(qs(n,o,t))),orders:(r.orders??[]).map(e=>(n,o)=>e(qs(n.key,n.value,t),qs(o.key,o.value,t)))}}var Nn=class{peerId;datastore;locks;addressFilter;log;maxAddressAge;maxPeerAge;constructor(t,e={}){this.log=t.logger.forComponent("libp2p:peer-store"),this.peerId=t.peerId,this.datastore=t.datastore,this.addressFilter=e.addressFilter,this.locks=Ds({name:"libp2p_peer_store_locks",metrics:t.metrics}),this.maxAddressAge=e.maxAddressAge??36e5,this.maxPeerAge=e.maxPeerAge??216e5}getLock(t){let e=this.locks.get(t);return e==null&&(e={refs:0,lock:Us({name:t.toString(),singleProcess:!0})},this.locks.set(t,e)),e.refs++,e}maybeRemoveLock(t,e){e.refs--,e.refs===0&&(e.lock.finalize(),this.locks.delete(t))}async getReadLock(t,e){let n=this.getLock(t);try{let o=await n.lock.readLock(e);return()=>{o(),this.maybeRemoveLock(t,n)}}catch(o){throw this.maybeRemoveLock(t,n),o}}async getWriteLock(t,e){let n=this.getLock(t);try{let o=await n.lock.writeLock(e);return()=>{o(),this.maybeRemoveLock(t,n)}}catch(o){throw this.maybeRemoveLock(t,n),o}}async has(t,e){try{return await this.load(t,e),!0}catch(n){if(n.name!=="NotFoundError")throw n}return!1}async delete(t,e){this.peerId.equals(t)||await this.datastore.delete(Ir(t),e)}async load(t,e){let n=Ir(t),o=await this.datastore.get(n,e),s=Zt.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,e),new $e;return We(t,s,this.peerId.equals(t)?1/0:this.maxAddressAge)}async save(t,e,n){let o=await this.#t(t,n),s=await kn(t,e,"patch",{...n,addressFilter:this.addressFilter});return this.#e(t,s,o)}async patch(t,e,n){let o=await this.#t(t,n),s=await kn(t,e,"patch",{...n,addressFilter:this.addressFilter,existingPeer:o});return this.#e(t,s,o)}async merge(t,e,n){let o=await this.#t(t,n),s=await kn(t,e,"merge",{addressFilter:this.addressFilter,existingPeer:o});return this.#e(t,s,o)}async*all(t){for await(let{key:e,value:n}of this.datastore.query(md(t??{},this.maxAddressAge),t)){let o=Ec(e);if(o.equals(this.peerId))continue;let s=Zt.decode(n);if(this.#r(o,s)){await this.datastore.delete(e,t);continue}yield We(o,s,this.peerId.equals(o)?1/0:this.maxAddressAge)}}async#t(t,e){try{let n=Ir(t),o=await this.datastore.get(n,e),s=Zt.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,e),new $e;return{peerPB:s,peer:We(t,s,this.maxAddressAge)}}catch(n){n.name!=="NotFoundError"&&this.log.error("invalid peer data found in peer store - %e",n)}}async#e(t,e,n,o){e.updated=Date.now();let s=Zt.encode(e);return await this.datastore.put(Ir(t),s,o),{peer:We(t,e,this.maxAddressAge),previous:n?.peer,updated:n==null||!dc(e,n.peerPB)}}#r(t,e){if(e.updated==null)return!0;if(this.peerId.equals(t))return!1;let n=e.updated<Date.now()-this.maxPeerAge,o=Date.now()-this.maxAddressAge,s=e.addresses.filter(i=>i.observed!=null&&i.observed>o);return n&&s.length===0}};var Vs=class{store;events;peerId;log;constructor(t,e={}){this.log=t.logger.forComponent("libp2p:peer-store"),this.events=t.events,this.peerId=t.peerId,this.store=new Nn(t,e)}[Symbol.toStringTag]="@libp2p/peer-store";async forEach(t,e){for await(let n of this.store.all(e))t(n)}async all(t){return rc(this.store.all(t))}async delete(t,e){let n=await this.store.getReadLock(t,e);try{await this.store.delete(t,e)}finally{n()}}async has(t,e){let n=await this.store.getReadLock(t,e);try{return await this.store.has(t,e)}finally{this.log.trace("has release read lock"),n?.()}}async get(t,e){let n=await this.store.getReadLock(t,e);try{return await this.store.load(t,e)}finally{n?.()}}async getInfo(t,e){let n=await this.get(t,e);return{id:n.id,multiaddrs:n.addresses.map(({multiaddr:o})=>o)}}async save(t,e,n){let o=await this.store.getWriteLock(t,n);try{let s=await this.store.save(t,e,n);return this.#t(t,s),s.peer}finally{o?.()}}async patch(t,e,n){let o=await this.store.getWriteLock(t,n);try{let s=await this.store.patch(t,e,n);return this.#t(t,s),s.peer}finally{o?.()}}async merge(t,e,n){let o=await this.store.getWriteLock(t,n);try{let s=await this.store.merge(t,e,n);return this.#t(t,s),s.peer}finally{o?.()}}async consumePeerRecord(t,e,n){let o=Ee(e)?e:Ee(e?.expectedPeer)?e.expectedPeer:void 0,s=Ee(e)||e===void 0?n:e,i=await He.openAndCertify(t,ge.DOMAIN,s),a=en(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=ge.createFromProtobuf(i.payload),u;try{u=await this.get(a,s)}catch(l){if(l.name!=="NotFoundError")throw l}if(u?.peerRecordEnvelope!=null){let l=He.createFromProtobuf(u.peerRecordEnvelope),f=ge.createFromProtobuf(l.payload);if(f.seqNumber>=c.seqNumber)return this.log("sequence number was lower or equal to existing sequence number - stored: %d received: %d",f.seqNumber,c.seqNumber),!1}return await this.patch(c.peerId,{peerRecordEnvelope:t,addresses:c.multiaddrs.map(l=>({isCertified:!0,multiaddr:l}))},s),!0}#t(t,e){e.updated&&(this.peerId.equals(t)?this.events.safeDispatchEvent("self:peer:update",{detail:e}):this.events.safeDispatchEvent("peer:update",{detail:e}))}};function yd(r,t={}){return new Vs(r,t)}return Ic(bd);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/hashes/utils.js: