@libp2p/peer-store 12.0.14 → 12.0.15-b30baa93a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +2 -2
- package/package.json +8 -8
- package/dist/typedoc-urls.json +0 -10
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 qn=Object.defineProperty;var Sc=Object.getOwnPropertyDescriptor;var Ac=Object.getOwnPropertyNames;var _c=Object.prototype.hasOwnProperty;var gt=(e,t)=>{for(var r in t)qn(e,r,{get:t[r],enumerable:!0})},Ic=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ac(t))!_c.call(e,o)&&o!==r&&qn(e,o,{get:()=>t[o],enumerable:!(n=Sc(t,o))||n.enumerable});return e};var Cc=e=>Ic(qn({},"__esModule",{value:!0}),e);var gd={};gt(gd,{persistentPeerStore:()=>bd});var q=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Ee=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var We=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var Dr=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 ae=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Or=Symbol.for("@libp2p/peer-id");function ve(e){return!!e?.[Or]}var Se=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){super.addEventListener(t,r,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,r,n){super.removeEventListener(t.toString(),r??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==r),this.#t.set(t,o))}dispatchEvent(t){let r=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),r}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var $n={};gt($n,{base58btc:()=>J,base58flickr:()=>kc});var Sd=new Uint8Array(0);function $s(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Nt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Ws(e){return new TextEncoder().encode(e)}function Zs(e){return new TextDecoder().decode(e)}function Tc(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=e.length,c=e.charAt(0),l=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function d(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var E=0,y=0,m=0,_=p.length;m!==_&&p[m]===0;)m++,E++;for(var w=(_-m)*u+1>>>0,I=new Uint8Array(w);m!==_;){for(var O=p[m],N=0,U=w-1;(O!==0||N<y)&&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");y=N,m++}for(var S=w-y;S!==w&&I[S]===0;)S++;for(var v=c.repeat(E);S<w;++S)v+=e.charAt(I[S]);return v}function f(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var E=0;if(p[E]!==" "){for(var y=0,m=0;p[E]===c;)y++,E++;for(var _=(p.length-E)*l+1>>>0,w=new Uint8Array(_);p[E];){var I=r[p.charCodeAt(E)];if(I===255)return;for(var O=0,N=_-1;(I!==0||O<m)&&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");m=O,E++}if(p[E]!==" "){for(var U=_-m;U!==_&&w[U]===0;)U++;for(var S=new Uint8Array(y+(_-U)),v=y;U!==_;)S[v++]=w[U++];return S}}}function h(p){var E=f(p);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:d,decodeUnsafe:f,decode:h}}var Bc=Tc,Rc=Bc,Ys=Rc;var Vn=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Hn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Xs(this,t)}},zn=class{decoders;constructor(t){this.decoders=t}or(t){return Xs(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Xs(e,t){return new zn({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Fn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Vn(t,r,n),this.decoder=new Hn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ae({name:e,prefix:t,encode:r,decode:n}){return new Fn(e,t,r,n)}function jt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Ys(r,e);return Ae({prefix:t,name:e,encode:n,decode:s=>Nt(o(s))})}function Dc(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let l=0;l<o;++l){let u=t[e[l]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Lc(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],i+=8;i>r;)i-=r,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Oc(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function Q({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Oc(n);return Ae({prefix:t,name:e,encode(s){return Lc(s,n,r)},decode(s){return Dc(s,o,r,e)}})}var J=jt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),kc=jt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Wn={};gt(Wn,{base32:()=>Lt,base32hex:()=>Uc,base32hexpad:()=>qc,base32hexpadupper:()=>Vc,base32hexupper:()=>Mc,base32pad:()=>Pc,base32padupper:()=>Nc,base32upper:()=>Kc,base32z:()=>Hc});var Lt=Q({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Kc=Q({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Pc=Q({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Nc=Q({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Uc=Q({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Mc=Q({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),qc=Q({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Vc=Q({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Hc=Q({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Zn={};gt(Zn,{base36:()=>Ze,base36upper:()=>zc});var Ze=jt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),zc=jt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Fc=Js,js=128,$c=127,Wc=~$c,Zc=Math.pow(2,31);function Js(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Zc;)t[r++]=e&255|js,e/=128;for(;e&Wc;)t[r++]=e&255|js,e>>>=7;return t[r]=e|0,Js.bytes=r-n+1,t}var Gc=Gn,Yc=128,Qs=127;function Gn(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw Gn.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Qs)<<o:(i&Qs)*Math.pow(2,o),o+=7}while(i>=Yc);return Gn.bytes=s-n,r}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(e){return e<Xc?1:e<jc?2:e<Qc?3:e<Jc?4:e<tu?5:e<eu?6:e<ru?7:e<nu?8:e<ou?9:10},iu={encode:Fc,decode:Gc,encodingLength:su},au=iu,Ge=au;function Ye(e,t=0){return[Ge.decode(e,t),Ge.decode.bytes]}function _e(e,t,r=0){return Ge.encode(e,t,r),t}function Ie(e){return Ge.encodingLength(e)}function Ot(e,t){let r=t.byteLength,n=Ie(e),o=n+Ie(r),s=new Uint8Array(o+r);return _e(e,s,0),_e(r,s,n),s.set(t,o),new Ce(e,r,t,s)}function Te(e){let t=Nt(e),[r,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 Ce(r,o,i,t)}function ti(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&$s(e.bytes,r.bytes)}}var Ce=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function ei(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return uu(r,Yn(e),t??J.encoder);default:return lu(r,Yn(e),t??Lt.encoder)}}var ri=new WeakMap;function Yn(e){let t=ri.get(e);if(t==null){let r=new Map;return ri.set(e,r),r}return t}var et=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==Xe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==fu)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=Ot(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&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 r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??ni(n,o,s.bytes))}else if(r[du]===!0){let{version:n,multihash:o,code:s}=r,i=Te(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==Xe)throw new Error(`Version 0 CID must use dag-pb (code: ${Xe}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=ni(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Xe,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Nt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Ce(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[d,f]=Ye(t.subarray(r));return r+=f,d},o=n(),s=Xe;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),l=r+c,u=l-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:l}}static parse(t,r){let[n,o]=cu(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Yn(s).set(n,t),s}};function cu(e,t){switch(e[0]){case"Q":{let r=t??J;return[J.prefix,r.decode(`${J.prefix}${e}`)]}case J.prefix:{let r=t??J;return[J.prefix,r.decode(e)]}case Lt.prefix:{let r=t??Lt;return[Lt.prefix,r.decode(e)]}case Ze.prefix:{let r=t??Ze;return[Ze.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function uu(e,t,r){let{prefix:n}=r;if(n!==J.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function lu(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var Xe=112,fu=18;function ni(e,t,r){let n=Ie(e),o=n+Ie(t),s=new Uint8Array(o+r.byteLength);return _e(e,s,0),_e(t,s,n),s.set(r,o),s}var du=Symbol.for("@ipld/js-cid/CID");var Xn={};gt(Xn,{identity:()=>Tt});var oi=0,hu="identity",si=Nt;function pu(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Ot(oi,si(e))}var Tt={code:oi,name:hu,encode:si,digest:pu};function W(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function rt(e=0){return new Uint8Array(e)}function xt(e=0){return new Uint8Array(e)}function Ut(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=xt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var ai=Symbol.for("@achingbrain/uint8arraylist");function ii(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function Kr(e){return!!e?.[ai]}var dt=class e{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 r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Kr(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Kr(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=ii(this.bufs,t);return r.buf[r.index]}set(t,r){let n=ii(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(Kr(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return Ut(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Ut(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let l=t>=a&&t<c,u=r>a&&r<=c;if(l&&u){if(t===a&&r===c){n.push(i);break}let d=t-a;n.push(i.subarray(d,d+(r-t)));break}if(l){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Kr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let d=0;d<s;d++)i[d]=-1;for(let d=0;d<o;d++)i[n[d]]=d;let a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let d=r;d<=c;d+=u){u=0;for(let f=l;f>=0;f--){let h=this.get(d+f);if(n[f]!==h){u=Math.max(1,f-a[h]);break}}if(u===0)return d}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=xt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=rt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=xt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=rt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!W(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var jn={};gt(jn,{base10:()=>mu});var mu=jt({prefix:"9",name:"base10",alphabet:"0123456789"});var Qn={};gt(Qn,{base16:()=>yu,base16upper:()=>bu});var yu=Q({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),bu=Q({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Jn={};gt(Jn,{base2:()=>gu});var gu=Q({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var to={};gt(to,{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((e,t,r)=>(e[r]=t,e),[]),wu=ci.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Eu(e){return e.reduce((t,r)=>(t+=xu[r],t),"")}function vu(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=wu[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Su=Ae({prefix:"\u{1F680}",name:"base256emoji",encode:Eu,decode:vu});var ro={};gt(ro,{base64:()=>Au,base64pad:()=>_u,base64url:()=>eo,base64urlpad:()=>Iu});var Au=Q({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),_u=Q({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),eo=Q({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Iu=Q({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var no={};gt(no,{base8:()=>Cu});var Cu=Q({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var oo={};gt(oo,{identity:()=>Tu});var Tu=Ae({prefix:"\0",name:"identity",encode:e=>Zs(e),decode:e=>Ws(e)});var ih=new TextEncoder,ah=new TextDecoder;var ao={};gt(ao,{sha256:()=>je,sha512:()=>Lu});var Du=20;function io({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new so(e,t,r,n,o)}var so=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Du,this.maxDigestLength=s}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?ui(n,this.code,r?.truncate):n.then(o=>ui(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function ui(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Ot(t,e)}function fi(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var je=io({name:"sha2-256",code:18,encode:fi("SHA-256")}),Lu=io({name:"sha2-512",code:19,encode:fi("SHA-512")});var Qe={...oo,...Jn,...no,...jn,...Qn,...Wn,...Zn,...$n,...ro,...to},xh={...ao,...Xn};function hi(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var di=hi("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),co=hi("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=xt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Ou={utf8:di,"utf-8":di,hex:Qe.base16,latin1:co,ascii:co,binary:co,...Qe},Pr=Ou;function z(e,t="utf8"){let r=Pr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function V(e,t="utf8"){let r=Pr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var ku=parseInt("11111",2),uo=parseInt("10000000",2),Ku=parseInt("01111111",2),pi={0:Je,1:Je,2:Pu,3:Mu,4:qu,5:Uu,6:Nu,16:Je,22:Je,48:Je};function Mt(e,t={offset:0}){let r=e[t.offset]&ku;if(t.offset++,pi[r]!=null)return pi[r](e,t);throw new Error("No decoder for tag "+r)}function tr(e,t){let r=0;if((e[t.offset]&uo)===uo){let n=e[t.offset]&Ku,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function Je(e,t){tr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Mt(e,t);if(n===null)break;r.push(n)}return r}function Pu(e,t){let r=tr(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function Nu(e,t){let r=tr(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let l=e[t.offset];if(t.offset++,c.push(l&127),l<128){c.reverse();let u=0;for(let d=0;d<c.length;d++)u+=c[d]<<d*7;a+=`.${u}`,c=[]}}return a}function Uu(e,t){return t.offset++,null}function Mu(e,t){let r=tr(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function qu(e,t){let r=tr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Vu(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new dt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function lo(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Vu(e.byteLength);return new dt(Uint8Array.from([t.byteLength|uo]),t)}function wt(e){let t=new dt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new dt(Uint8Array.from([2]),lo(t),t)}function Nr(e){let t=Uint8Array.from([0]),r=new dt(t,e);return new dt(Uint8Array.from([3]),lo(r),r)}function Jt(e,t=48){let r=new dt;for(let n of e)r.append(n);return new dt(Uint8Array.from([t]),lo(r),r)}async function mi(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),s}var 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]),$u={ext:!0,kty:"EC",crv:"P-256"},Wu={ext:!0,kty:"EC",crv:"P-384"},Zu={ext:!0,kty:"EC",crv:"P-521"},fo=32,ho=48,po=66;function mo(e){let t=Mt(e);return yi(t)}function yi(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===fo*2+1)return n=V(t.subarray(r,r+fo),"base64url"),o=V(t.subarray(r+fo),"base64url"),new Be({...$u,key_ops:["verify"],x:n,y:o});if(t.byteLength===ho*2+1)return n=V(t.subarray(r,r+ho),"base64url"),o=V(t.subarray(r+ho),"base64url"),new Be({...Wu,key_ops:["verify"],x:n,y:o});if(t.byteLength===po*2+1)return n=V(t.subarray(r,r+po),"base64url"),o=V(t.subarray(r+po),"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(e){return Jt([wt(Uint8Array.from([1])),Jt([Gu(e.crv)],160),Jt([Nr(new dt(Uint8Array.from([4]),z(e.x??"","base64url"),z(e.y??"","base64url")))],161)]).subarray()}function Gu(e){if(e==="P-256")return Hu;if(e==="P-384")return zu;if(e==="P-521")return Fu;throw new q(`Invalid curve ${e}`)}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 Tt.digest(At(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}async verify(t,r,n){return mi(this.jwk,r,t,n)}};function ce(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function kt(e,t=""){if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new Error(`${r}expected integer >= 0, got ${e}`)}}function P(e,t,r=""){let n=ce(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return e}function Ur(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash must wrapped by utils.createHasher");kt(e.outputLen),kt(e.blockLen)}function Re(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function xi(e,t){P(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function Vt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Mr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Bt(e,t){return e<<32-t|e>>>t}var wi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Yu=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Ht(e){if(P(e),wi)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Yu[e[r]];return t}var qt={_0:48,_9:57,A:65,F:70,a:97,f:102};function gi(e){if(e>=qt._0&&e<=qt._9)return e-qt._0;if(e>=qt.A&&e<=qt.F)return e-(qt.A-10);if(e>=qt.a&&e<=qt.f)return e-(qt.a-10)}function zt(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(wi)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=gi(e.charCodeAt(s)),a=gi(e.charCodeAt(s+1));if(i===void 0||a===void 0){let c=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Et(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];P(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}function yo(e,t={}){let r=(o,s)=>e(s).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function De(e=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(e))}var bo=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function Ei(e,t,r){return e&t^~e&r}function vi(e,t,r){return e&t^e&r^t&r}var er=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,o){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Mr(this.buffer)}update(t){Re(this),P(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Mr(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(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Re(this),xi(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Vt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let d=i;d<o;d++)r[d]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=Mr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let l=c/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<l;d++)a.setUint32(4*d,u[d],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Ft=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 qr=BigInt(4294967295),Si=BigInt(32);function Xu(e,t=!1){return t?{h:Number(e&qr),l:Number(e>>Si&qr)}:{h:Number(e>>Si&qr)|0,l:Number(e&qr)|0}}function Ai(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=Xu(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var go=(e,t,r)=>e>>>r,xo=(e,t,r)=>e<<32-r|t>>>r,ue=(e,t,r)=>e>>>r|t<<32-r,le=(e,t,r)=>e<<32-r|t>>>r,rr=(e,t,r)=>e<<64-r|t>>>r-32,nr=(e,t,r)=>e>>>r-32|t<<64-r;function Kt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var _i=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Ii=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Ci=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Ti=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Bi=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Ri=(e,t,r,n,o,s)=>t+r+n+o+s+(e/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]),te=new Uint32Array(64),wo=class extends er{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,r,n,o,s,i,a,c]}set(t,r,n,o,s,i,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,r){for(let d=0;d<16;d++,r+=4)te[d]=t.getUint32(r,!1);for(let d=16;d<64;d++){let f=te[d-15],h=te[d-2],p=Bt(f,7)^Bt(f,18)^f>>>3,E=Bt(h,17)^Bt(h,19)^h>>>10;te[d]=E+te[d-7]+p+te[d-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:l,H:u}=this;for(let d=0;d<64;d++){let f=Bt(a,6)^Bt(a,11)^Bt(a,25),h=u+f+Ei(a,c,l)+Qu[d]+te[d]|0,E=(Bt(n,2)^Bt(n,13)^Bt(n,22))+vi(n,o,s)|0;u=l,l=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+E|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,c,l,u)}roundClean(){Vt(te)}destroy(){this.set(0,0,0,0,0,0,0,0),Vt(this.buffer)}},Eo=class extends wo{A=Ft[0]|0;B=Ft[1]|0;C=Ft[2]|0;D=Ft[3]|0;E=Ft[4]|0;F=Ft[5]|0;G=Ft[6]|0;H=Ft[7]|0;constructor(){super(32)}};var Di=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(e=>BigInt(e))),Ju=Di[0],tl=Di[1],ee=new Uint32Array(80),re=new Uint32Array(80),vo=class extends er{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:l,El:u,Fh:d,Fl:f,Gh:h,Gl:p,Hh:E,Hl:y}=this;return[t,r,n,o,s,i,a,c,l,u,d,f,h,p,E,y]}set(t,r,n,o,s,i,a,c,l,u,d,f,h,p,E,y){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=l|0,this.El=u|0,this.Fh=d|0,this.Fl=f|0,this.Gh=h|0,this.Gl=p|0,this.Hh=E|0,this.Hl=y|0}process(t,r){for(let w=0;w<16;w++,r+=4)ee[w]=t.getUint32(r),re[w]=t.getUint32(r+=4);for(let w=16;w<80;w++){let I=ee[w-15]|0,O=re[w-15]|0,N=ue(I,O,1)^ue(I,O,8)^go(I,O,7),U=le(I,O,1)^le(I,O,8)^xo(I,O,7),S=ee[w-2]|0,v=re[w-2]|0,k=ue(S,v,19)^rr(S,v,61)^go(S,v,6),M=le(S,v,19)^nr(S,v,61)^xo(S,v,6),R=Ci(U,M,re[w-7],re[w-16]),g=Ti(R,N,k,ee[w-7],ee[w-16]);ee[w]=g|0,re[w]=R|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:l,Dl:u,Eh:d,El:f,Fh:h,Fl:p,Gh:E,Gl:y,Hh:m,Hl:_}=this;for(let w=0;w<80;w++){let I=ue(d,f,14)^ue(d,f,18)^rr(d,f,41),O=le(d,f,14)^le(d,f,18)^nr(d,f,41),N=d&h^~d&E,U=f&p^~f&y,S=Bi(_,O,U,tl[w],re[w]),v=Ri(S,m,I,N,Ju[w],ee[w]),k=S|0,M=ue(n,o,28)^rr(n,o,34)^rr(n,o,39),R=le(n,o,28)^nr(n,o,34)^nr(n,o,39),g=n&s^n&a^s&a,x=o&i^o&c^i&c;m=E|0,_=y|0,E=h|0,y=p|0,h=d|0,p=f|0,{h:d,l:f}=Kt(l|0,u|0,v|0,k|0),l=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let b=_i(k,R,x);n=Ii(b,v,M,g),o=b|0}({h:n,l:o}=Kt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Kt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Kt(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:u}=Kt(this.Dh|0,this.Dl|0,l|0,u|0),{h:d,l:f}=Kt(this.Eh|0,this.El|0,d|0,f|0),{h,l:p}=Kt(this.Fh|0,this.Fl|0,h|0,p|0),{h:E,l:y}=Kt(this.Gh|0,this.Gl|0,E|0,y|0),{h:m,l:_}=Kt(this.Hh|0,this.Hl|0,m|0,_|0),this.set(n,o,s,i,a,c,l,u,d,f,h,p,E,y,m,_)}roundClean(){Vt(ee,re)}destroy(){Vt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},So=class extends vo{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 Le=yo(()=>new Eo,bo(1));var Li=yo(()=>new So,bo(3));var _o=BigInt(0),Ao=BigInt(1);function $t(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function Oi(e){if(typeof e=="bigint"){if(!Vr(e))throw new Error("positive bigint expected, got "+e)}else kt(e);return e}function or(e){let t=Oi(e).toString(16);return t.length&1?"0"+t:t}function ki(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?_o:BigInt("0x"+e)}function Oe(e){return ki(Ht(e))}function fe(e){return ki(Ht(zr(P(e)).reverse()))}function Hr(e,t){kt(t),e=Oi(e);let r=zt(e.toString(16).padStart(t*2,"0"));if(r.length!==t)throw new Error("number too large");return r}function Io(e,t){return Hr(e,t).reverse()}function zr(e){return Uint8Array.from(e)}var Vr=e=>typeof e=="bigint"&&_o<=e;function el(e,t,r){return Vr(e)&&Vr(t)&&Vr(r)&&t<=e&&e<r}function sr(e,t,r,n){if(!el(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Co(e){let t;for(t=0;e>_o;e>>=Ao,t+=1);return t}var ir=e=>(Ao<<BigInt(e))-Ao;function Ki(e,t,r){if(kt(e,"hashLen"),kt(t,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");let n=y=>new Uint8Array(y),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(e),l=n(e),u=0,d=()=>{c.fill(1),l.fill(0),u=0},f=(...y)=>r(l,Et(c,...y)),h=(y=o)=>{l=f(s,y),c=f(),y.length!==0&&(l=f(i,y),c=f())},p=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let y=0,m=[];for(;y<t;){c=f();let _=c.slice();m.push(_),y+=c.length}return Et(...m)};return(y,m)=>{d(),h(y);let _;for(;!(_=m(p()));)h();return d(),_}}function ne(e,t={},r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(s,i,a){let c=e[s];if(a&&c===void 0)return;let l=typeof c;if(l!==i||c===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${l}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(t,!1),o(r,!0)}function ke(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var ht=BigInt(0),nt=BigInt(1),de=BigInt(2),Ui=BigInt(3),Mi=BigInt(4),qi=BigInt(5),rl=BigInt(7),Vi=BigInt(8),nl=BigInt(9),Hi=BigInt(16);function tt(e,t){let r=e%t;return r>=ht?r:t+r}function Z(e,t,r){let n=e;for(;t-- >ht;)n*=n,n%=r;return n}function Pi(e,t){if(e===ht)throw new Error("invert: expected non-zero number");if(t<=ht)throw new Error("invert: expected positive modulus, got "+t);let r=tt(e,t),n=t,o=ht,s=nt,i=nt,a=ht;for(;r!==ht;){let l=n/r,u=n%r,d=o-i*l,f=s-a*l;n=r,r=u,o=i,s=a,i=d,a=f}if(n!==nt)throw new Error("invert: does not exist");return tt(o,t)}function Bo(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function zi(e,t){let r=(e.ORDER+nt)/Mi,n=e.pow(t,r);return Bo(e,n,t),n}function ol(e,t){let r=(e.ORDER-qi)/Vi,n=e.mul(t,de),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,de),o),a=e.mul(s,e.sub(i,e.ONE));return Bo(e,a,t),a}function sl(e){let t=Ke(e),r=Fi(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+rl)/Hi;return(a,c)=>{let l=a.pow(c,i),u=a.mul(l,n),d=a.mul(l,o),f=a.mul(l,s),h=a.eql(a.sqr(u),c),p=a.eql(a.sqr(d),c);l=a.cmov(l,u,h),u=a.cmov(f,d,p);let E=a.eql(a.sqr(u),c),y=a.cmov(l,u,E);return Bo(a,y,c),y}}function Fi(e){if(e<Ui)throw new Error("sqrt is not defined for small field");let t=e-nt,r=0;for(;t%de===ht;)t/=de,r++;let n=de,o=Ke(e);for(;Ni(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return zi;let s=o.pow(n,t),i=(t+nt)/de;return function(c,l){if(c.is0(l))return l;if(Ni(c,l)!==1)throw new Error("Cannot find square root");let u=r,d=c.mul(c.ONE,s),f=c.pow(l,t),h=c.pow(l,i);for(;!c.eql(f,c.ONE);){if(c.is0(f))return c.ZERO;let p=1,E=c.sqr(f);for(;!c.eql(E,c.ONE);)if(p++,E=c.sqr(E),p===u)throw new Error("Cannot find square root");let y=nt<<BigInt(u-p-1),m=c.pow(d,y);u=p,d=c.sqr(m),f=c.mul(f,d),h=c.mul(h,m)}return h}}function il(e){return e%Mi===Ui?zi:e%Vi===qi?ol:e%Hi===nl?sl(e):Fi(e)}var $i=(e,t)=>(tt(e,t)&nt)===nt,al=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ro(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=al.reduce((n,o)=>(n[o]="function",n),t);return ne(e,r),e}function cl(e,t,r){if(r<ht)throw new Error("invalid exponent, negatives unsupported");if(r===ht)return e.ONE;if(r===nt)return t;let n=e.ONE,o=t;for(;r>ht;)r&nt&&(n=e.mul(n,o)),o=e.sqr(o),r>>=nt;return n}function ar(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,a,c)=>e.is0(a)?i:(n[c]=i,e.mul(i,a)),e.ONE),s=e.inv(o);return t.reduceRight((i,a,c)=>e.is0(a)?i:(n[c]=e.mul(i,n[c]),e.mul(i,a)),s),n}function Ni(e,t){let r=(e.ORDER-nt)/de,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function ul(e,t){t!==void 0&&kt(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}var To=class{ORDER;BITS;BYTES;isLE;ZERO=ht;ONE=nt;_lengths;_sqrt;_mod;constructor(t,r={}){if(t<=ht)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&(this.sqrt=r.sqrt),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=r.allowedLengths?.slice()),typeof r.modFromBytes=="boolean"&&(this._mod=r.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 tt(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 tt(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return tt(t*t,this.ORDER)}add(t,r){return tt(t+r,this.ORDER)}sub(t,r){return tt(t-r,this.ORDER)}mul(t,r){return tt(t*r,this.ORDER)}pow(t,r){return cl(this,t,r)}div(t,r){return tt(t*Pi(r,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,r){return t+r}subN(t,r){return t-r}mulN(t,r){return t*r}inv(t){return Pi(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=il(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?Io(t,this.BYTES):Hr(t,this.BYTES)}fromBytes(t,r=!1){P(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 l=new Uint8Array(o);l.set(t,s?0:l.length-t.length),t=l}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=s?fe(t):Oe(t);if(a&&(c=tt(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return ar(this,t)}cmov(t,r,n){return n?r:t}};function Ke(e,t={}){return new To(e,t)}function Wi(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function Do(e){let t=Wi(e);return t+Math.ceil(t/2)}function Lo(e,t,r=!1){P(e);let n=e.length,o=Wi(t),s=Do(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?fe(e):Oe(e),a=tt(i,t-nt)+nt;return r?Io(a,o):Hr(a,o)}var Pe=BigInt(0),he=BigInt(1);function cr(e,t){let r=t.negate();return e?r:t}function pe(e,t){let r=ar(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Xi(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Oo(e,t){Xi(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=ir(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Zi(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(e&o),c=e>>i;a>n&&(a-=s,c+=he);let l=t*n,u=l+Math.abs(a)-1,d=a===0,f=a<0,h=t%2!==0;return{nextN:c,offset:u,isZero:d,isNeg:f,isNegF:h,offsetF:l}}var ko=new WeakMap,ji=new WeakMap;function Ko(e){return ji.get(e)||1}function Gi(e){if(e!==Pe)throw new Error("invalid wNAF")}var Ne=class{BASE;ZERO;Fn;bits;constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>Pe;)r&he&&(n=n.add(o)),o=o.double(),r>>=he;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=Oo(r,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let l=1;l<o;l++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Oo(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:l,isZero:u,isNeg:d,isNegF:f,offsetF:h}=Zi(n,a,i);n=c,u?s=s.add(cr(f,r[h])):o=o.add(cr(d,r[l]))}return Gi(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=Oo(t,this.bits);for(let i=0;i<s.windows&&n!==Pe;i++){let{nextN:a,offset:c,isZero:l,isNeg:u}=Zi(n,i,s);if(n=a,!l){let d=r[c];o=o.add(u?d.negate():d)}}return Gi(n),o}getPrecomputes(t,r,n){let o=ko.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),ko.set(r,o))),o}cached(t,r,n){let o=Ko(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=Ko(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){Xi(r,this.bits),ji.set(t,r),ko.delete(t)}hasCache(t){return Ko(t)!==1}};function Qi(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Pe||n>Pe;)r&he&&(s=s.add(o)),n&he&&(i=i.add(o)),o=o.double(),r>>=he,n>>=he;return{p1:s,p2:i}}function Yi(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Ro(t),t}else return Ke(e,{isLE:r})}function Fr(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let c of["p","n","h"]){let l=t[c];if(!(typeof l=="bigint"&&l>Pe))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Yi(t.p,r.Fp,n),s=Yi(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let 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 $r(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var oe=BigInt(0),ot=BigInt(1),Po=BigInt(2),ll=BigInt(8);function fl(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),a=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,a)}function Ji(e,t={}){let r=Fr("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;ne(t,{},{uvRatio:"function"});let a=Po<<BigInt(o.BYTES*8)-ot,c=y=>n.create(y),l=t.uvRatio||((y,m)=>{try{return{isValid:!0,value:n.sqrt(n.div(y,m))}}catch{return{isValid:!1,value:oe}}});if(!fl(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function u(y,m,_=!1){let w=_?ot:oe;return sr("coordinate "+y,m,w,a),m}function d(y){if(!(y instanceof p))throw new Error("EdwardsPoint expected")}let f=ke((y,m)=>{let{X:_,Y:w,Z:I}=y,O=y.is0();m==null&&(m=O?ll:n.inv(I));let N=c(_*m),U=c(w*m),S=n.mul(I,m);if(O)return{x:oe,y:ot};if(S!==ot)throw new Error("invZ was invalid");return{x:N,y:U}}),h=ke(y=>{let{a:m,d:_}=s;if(y.is0())throw new Error("bad point: ZERO");let{X:w,Y:I,Z:O,T:N}=y,U=c(w*w),S=c(I*I),v=c(O*O),k=c(v*v),M=c(U*m),R=c(v*c(M+S)),g=c(k+c(_*c(U*S)));if(R!==g)throw new Error("bad point: equation left != right (1)");let x=c(w*I),b=c(O*N);if(x!==b)throw new Error("bad point: equation left != right (2)");return!0});class p{static BASE=new p(s.Gx,s.Gy,ot,c(s.Gx*s.Gy));static ZERO=new p(oe,ot,ot,oe);static Fp=n;static Fn=o;X;Y;Z;T;constructor(m,_,w,I){this.X=u("x",m),this.Y=u("y",_),this.Z=u("z",w,!0),this.T=u("t",I),Object.freeze(this)}static CURVE(){return s}static fromAffine(m){if(m instanceof p)throw new Error("extended point not allowed");let{x:_,y:w}=m||{};return u("x",_),u("y",w),new p(_,w,ot,c(_*w))}static fromBytes(m,_=!1){let w=n.BYTES,{a:I,d:O}=s;m=zr(P(m,w,"point")),$t(_,"zip215");let N=zr(m),U=m[w-1];N[w-1]=U&-129;let S=fe(N),v=_?a:n.ORDER;sr("point.y",S,oe,v);let k=c(S*S),M=c(k-ot),R=c(O*k-I),{isValid:g,value:x}=l(M,R);if(!g)throw new Error("bad point: invalid y coordinate");let b=(x&ot)===ot,A=(U&128)!==0;if(!_&&x===oe&&A)throw new Error("bad point: x=0 and x_0=1");return A!==b&&(x=c(-x)),p.fromAffine({x,y:S})}static fromHex(m,_=!1){return p.fromBytes(zt(m),_)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,_=!0){return E.createCache(this,m),_||this.multiply(Po),this}assertValidity(){h(this)}equals(m){d(m);let{X:_,Y:w,Z:I}=this,{X:O,Y:N,Z:U}=m,S=c(_*U),v=c(O*I),k=c(w*U),M=c(N*I);return S===v&&k===M}is0(){return this.equals(p.ZERO)}negate(){return new p(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:m}=s,{X:_,Y:w,Z:I}=this,O=c(_*_),N=c(w*w),U=c(Po*c(I*I)),S=c(m*O),v=_+w,k=c(c(v*v)-O-N),M=S+N,R=M-U,g=S-N,x=c(k*R),b=c(M*g),A=c(k*g),C=c(R*M);return new p(x,b,C,A)}add(m){d(m);let{a:_,d:w}=s,{X:I,Y:O,Z:N,T:U}=this,{X:S,Y:v,Z:k,T:M}=m,R=c(I*S),g=c(O*v),x=c(U*w*M),b=c(N*k),A=c((I+O)*(S+v)-R-g),C=b-x,B=b+x,D=c(g-_*R),T=c(A*C),L=c(B*D),K=c(A*D),Y=c(C*B);return new p(T,L,Y,K)}subtract(m){return this.add(m.negate())}multiply(m){if(!o.isValidNot0(m))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:_,f:w}=E.cached(this,m,I=>pe(p,I));return pe(p,[_,w])[0]}multiplyUnsafe(m,_=p.ZERO){if(!o.isValid(m))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return m===oe?p.ZERO:this.is0()||m===ot?this:E.unsafe(this,m,w=>pe(p,w),_)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return E.unsafe(this,s.n).is0()}toAffine(m){return f(this,m)}clearCofactor(){return i===ot?this:this.multiplyUnsafe(i)}toBytes(){let{x:m,y:_}=this.toAffine(),w=n.toBytes(_);return w[w.length-1]|=m&ot?128:0,w}toHex(){return Ht(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let E=new Ne(p,o.BITS);return p.BASE.precompute(8),p}function ta(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');ne(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=e,a=r.randomBytes||De,c=r.adjustScalarBytes||(S=>S),l=r.domain||((S,v,k)=>{if($t(k,"phflag"),v.length||k)throw new Error("Contexts/pre-hash are not supported");return S});function u(S){return i.create(fe(S))}function d(S){let v=w.secretKey;P(S,w.secretKey,"secretKey");let k=P(t(S),2*v,"hashedSecretKey"),M=c(k.slice(0,v)),R=k.slice(v,2*v),g=u(M);return{head:M,prefix:R,scalar:g}}function f(S){let{head:v,prefix:k,scalar:M}=d(S),R=o.multiply(M),g=R.toBytes();return{head:v,prefix:k,scalar:M,point:R,pointBytes:g}}function h(S){return f(S).pointBytes}function p(S=Uint8Array.of(),...v){let k=Et(...v);return u(t(l(k,P(S,void 0,"context"),!!n)))}function E(S,v,k={}){S=P(S,void 0,"message"),n&&(S=n(S));let{prefix:M,scalar:R,pointBytes:g}=f(v),x=p(k.context,M,S),b=o.multiply(x).toBytes(),A=p(k.context,b,g,S),C=i.create(x+A*R);if(!i.isValid(C))throw new Error("sign failed: invalid s");let B=Et(b,i.toBytes(C));return P(B,w.signature,"result")}let y={zip215:!0};function m(S,v,k,M=y){let{context:R,zip215:g}=M,x=w.signature;S=P(S,x,"signature"),v=P(v,void 0,"message"),k=P(k,w.publicKey,"publicKey"),g!==void 0&&$t(g,"zip215"),n&&(v=n(v));let b=x/2,A=S.subarray(0,b),C=fe(S.subarray(b,x)),B,D,T;try{B=e.fromBytes(k,g),D=e.fromBytes(A,g),T=o.multiplyUnsafe(C)}catch{return!1}if(!g&&B.isSmallOrder())return!1;let L=p(R,D.toBytes(),B.toBytes(),v);return D.add(B.multiplyUnsafe(L)).subtract(T).clearCofactor().is0()}let _=s.BYTES,w={secretKey:_,publicKey:_,signature:2*_,seed:_};function I(S=a(w.seed)){return P(S,w.seed,"seed")}function O(S){return ce(S)&&S.length===i.BYTES}function N(S,v){try{return!!e.fromBytes(S,v)}catch{return!1}}let U={getExtendedPublicKey:f,randomSecretKey:I,isValidSecretKey:O,isValidPublicKey:N,toMontgomery(S){let{y:v}=e.fromBytes(S),k=w.publicKey,M=k===32;if(!M&&k!==57)throw new Error("only defined for 25519 and 448");let R=M?s.div(ot+v,ot-v):s.div(v-ot,v+ot);return s.toBytes(R)},toMontgomerySecret(S){let v=w.secretKey;P(S,v);let k=t(S.subarray(0,v));return c(k).subarray(0,v)}};return Object.freeze({keygen:$r(I,h),getPublicKey:h,sign:E,verify:m,utils:U,Point:e,lengths:w})}var dl=BigInt(1),ea=BigInt(2);var hl=BigInt(5),pl=BigInt(8),No=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),ml={p:No,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:pl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function yl(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=No,a=e*e%s*e%s,c=Z(a,ea,s)*a%s,l=Z(c,dl,s)*e%s,u=Z(l,hl,s)*l%s,d=Z(u,t,s)*u%s,f=Z(d,r,s)*d%s,h=Z(f,n,s)*f%s,p=Z(h,o,s)*h%s,E=Z(p,o,s)*h%s,y=Z(E,t,s)*u%s;return{pow_p_5_8:Z(y,ea,s)*e%s,b2:a}}function bl(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var ra=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function gl(e,t){let r=No,n=tt(t*t*t,r),o=tt(n*n*t,r),s=yl(e*o).pow_p_5_8,i=tt(e*n*s,r),a=tt(t*i*i,r),c=i,l=tt(i*ra,r),u=a===e,d=a===tt(-e,r),f=a===tt(-e*ra,r);return u&&(i=c),(d||f)&&(i=l),$i(i,r)&&(i=tt(-i,r)),{isValid:u||d,value:i}}var xl=Ji(ml,{uvRatio:gl});function wl(e){return ta(xl,Li,Object.assign({adjustScalarBytes:bl},e))}var na=wl({});var ur=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Wr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var oa={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Wr("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 _t=oa;var Zr=32;var Uo,El=(async()=>{try{return await _t.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function vl(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await _t.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await _t.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Sl(e,t,r){return na.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function sa(e,t,r){return Uo==null&&(Uo=await El),Uo?vl(e,t,r):Sl(e,t,r)}function Gr(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Yr=class{type="Ed25519";raw;constructor(t){this.raw=Mo(t,Zr)}toMultihash(){return Tt.digest(At(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=sa(this.raw,r,t);return Gr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function qo(e){return e=Mo(e,Zr),new Yr(e)}function Mo(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new q(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var _l=Math.pow(2,7),Il=Math.pow(2,14),Cl=Math.pow(2,21),Vo=Math.pow(2,28),Ho=Math.pow(2,35),zo=Math.pow(2,42),Fo=Math.pow(2,49),F=128,lt=127;function It(e){if(e<_l)return 1;if(e<Il)return 2;if(e<Cl)return 3;if(e<Vo)return 4;if(e<Ho)return 5;if(e<zo)return 6;if(e<Fo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ue(e,t,r=0){switch(It(e)){case 8:t[r++]=e&255|F,e/=128;case 7:t[r++]=e&255|F,e/=128;case 6:t[r++]=e&255|F,e/=128;case 5:t[r++]=e&255|F,e/=128;case 4:t[r++]=e&255|F,e>>>=7;case 3:t[r++]=e&255|F,e>>>=7;case 2:t[r++]=e&255|F,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Tl(e,t,r=0){switch(It(e)){case 8:t.set(r++,e&255|F),e/=128;case 7:t.set(r++,e&255|F),e/=128;case 6:t.set(r++,e&255|F),e/=128;case 5:t.set(r++,e&255|F),e/=128;case 4:t.set(r++,e&255|F),e>>>=7;case 3:t.set(r++,e&255|F),e>>>=7;case 2:t.set(r++,e&255|F),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function $o(e,t){let r=e[t],n=0;if(n+=r<,r<F||(r=e[t+1],n+=(r<)<<7,r<F)||(r=e[t+2],n+=(r<)<<14,r<F)||(r=e[t+3],n+=(r<)<<21,r<F)||(r=e[t+4],n+=(r<)*Vo,r<F)||(r=e[t+5],n+=(r<)*Ho,r<F)||(r=e[t+6],n+=(r<)*zo,r<F)||(r=e[t+7],n+=(r<)*Fo,r<F))return n;throw new RangeError("Could not decode varint")}function Bl(e,t){let r=e.get(t),n=0;if(n+=r<,r<F||(r=e.get(t+1),n+=(r<)<<7,r<F)||(r=e.get(t+2),n+=(r<)<<14,r<F)||(r=e.get(t+3),n+=(r<)<<21,r<F)||(r=e.get(t+4),n+=(r<)*Vo,r<F)||(r=e.get(t+5),n+=(r<)*Ho,r<F)||(r=e.get(t+6),n+=(r<)*zo,r<F)||(r=e.get(t+7),n+=(r<)*Fo,r<F))return n;throw new RangeError("Could not decode varint")}function Xr(e,t,r=0){return t==null&&(t=xt(It(e))),t instanceof Uint8Array?Ue(e,t,r):Tl(e,t,r)}function Wo(e,t=0){return e instanceof Uint8Array?$o(e,t):Bl(e,t)}var Zo=new Float32Array([-0]),se=new Uint8Array(Zo.buffer);function ca(e,t,r){Zo[0]=e,t[r]=se[0],t[r+1]=se[1],t[r+2]=se[2],t[r+3]=se[3]}function ua(e,t){return se[0]=e[t],se[1]=e[t+1],se[2]=e[t+2],se[3]=e[t+3],Zo[0]}var Go=new Float64Array([-0]),ft=new Uint8Array(Go.buffer);function la(e,t,r){Go[0]=e,t[r]=ft[0],t[r+1]=ft[1],t[r+2]=ft[2],t[r+3]=ft[3],t[r+4]=ft[4],t[r+5]=ft[5],t[r+6]=ft[6],t[r+7]=ft[7]}function fa(e,t){return ft[0]=e[t],ft[1]=e[t+1],ft[2]=e[t+2],ft[3]=e[t+3],ft[4]=e[t+4],ft[5]=e[t+5],ft[6]=e[t+6],ft[7]=e[t+7],Go[0]}var Rl=BigInt(Number.MAX_SAFE_INTEGER),Dl=BigInt(Number.MIN_SAFE_INTEGER),vt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return me;if(t<Rl&&t>Dl)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>da&&(o=0n,++n>da&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return me;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):me}},me=new vt(0,0);me.toBigInt=function(){return 0n};me.zzEncode=me.zzDecode=function(){return this};me.length=function(){return 1};var da=4294967296n;function ha(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function pa(e,t,r){if(r-t<1)return"";let o,s=[],i=0,a;for(;t<r;)a=e[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Yo(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Rt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function jr(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Xo=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,Rt(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 Rt(this,4);return jr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Rt(this,4);return jr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Rt(this,4);let t=ua(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Rt(this,4);let t=fa(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Rt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,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 Rt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Rt(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 vt(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Rt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Rt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Rt(this,8);let t=jr(this.buf,this.pos+=4),r=jr(this.buf,this.pos+=4);return new vt(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=$o(this.buf,this.pos);return this.pos+=It(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 lr(e){return new Xo(e instanceof Uint8Array?e:e.subarray())}function pt(e,t,r){let n=lr(e);return t.decode(n,void 0,r)}function jo(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return xt(i);o+i>t&&(n=xt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var ye=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function 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}},Ll=jo();function Ol(e){return globalThis.Buffer!=null?xt(e):Ll(e)}var dr=class{len;head;tail;states;constructor(){this.len=0,this.head=new ye(Qo,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ye(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new 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(Qr,10,vt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=vt.fromBigInt(t);return this._push(Qr,r.length(),r)}uint64Number(t){return this._push(Ue,It(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=vt.fromBigInt(t).zzEncode();return this._push(Qr,r.length(),r)}sint64Number(t){let r=vt.fromNumber(t).zzEncode();return this._push(Qr,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Jo,1,t?1:0)}fixed32(t){return this._push(fr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=vt.fromBigInt(t);return this._push(fr,4,r.lo)._push(fr,4,r.hi)}fixed64Number(t){let r=vt.fromNumber(t);return this._push(fr,4,r.lo)._push(fr,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(ca,4,t)}double(t){return this._push(la,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Jo,1,0):this.uint32(r)._push(Kl,r,t)}string(t){let r=ha(t);return r!==0?this.uint32(r)._push(Yo,r,t):this._push(Jo,1,0)}fork(){return this.states=new ts(this),this.head=this.tail=new ye(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 ye(Qo,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=Ol(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Jo(e,t,r){t[r]=e&255}function kl(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var es=class extends ye{next;constructor(t,r){super(kl,t,r),this.next=void 0}};function Qr(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function fr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function Kl(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(dr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Pl,t,e),this},dr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Nl,t,e),this});function Pl(e,t,r){t.set(e,r)}function Nl(e,t,r){e.length<40?Yo(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(z(e),r)}function rs(){return new dr}function mt(e,t){let r=rs();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*yt(e,t,r){let n=lr(e);yield*t.stream(n,void 0,"$",r)}var Jr={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function tn(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function ns(e){function t(s){if(e[s.toString()]==null)throw new Error("Invalid enum value");return e[s]}let r=function(i,a){let c=t(i);a.int32(c)},n=function(i){let a=i.int32();return t(a)},o=function*(i){let a=i.int32();yield t(a)};return tn("enum",Jr.VARINT,r,n,o)}function bt(e,t,r){return tn("message",Jr.LENGTH_DELIMITED,e,t,r)}var Ct=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},hr=class extends Error{code="ERR_MAX_SIZE";name="MaxSizeError"};var G;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(G||(G={}));var os;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(os||(os={}));(function(e){e.codec=()=>ns(os)})(G||(G={}));var Pt;(function(e){let t;e.codec=()=>(t==null&&(t=bt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),G.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},l=i==null?s.len:s.pos+i;for(;s.pos<l;){let u=s.uint32();switch(u>>>3){case 1:{c.Type=G.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return c},function*(s,i,a,c={}){let l=i==null?s.len:s.pos+i;for(;s.pos<l;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:G.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return mt(s,e.codec())}e.encode=r;function n(s,i){return pt(s,e.codec(),i)}e.decode=n;function o(s,i){return yt(s,e.codec(),i)}e.stream=o})(Pt||(Pt={}));var ss;(function(e){let t;e.codec=()=>(t==null&&(t=bt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),G.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},l=i==null?s.len:s.pos+i;for(;s.pos<l;){let u=s.uint32();switch(u>>>3){case 1:{c.Type=G.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return c},function*(s,i,a,c={}){let l=i==null?s.len:s.pos+i;for(;s.pos<l;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:G.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return mt(s,e.codec())}e.encode=r;function n(s,i){return pt(s,e.codec(),i)}e.decode=n;function o(s,i){return yt(s,e.codec(),i)}e.stream=o})(ss||(ss={}));var mr={};gt(mr,{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,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=mr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return et.createV1(114,this._multihash)}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}verify(t,r,n){return ga(this.jwk,r,t,n)}},pr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=mr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}sign(t,r){return ba(this.jwk,t,r)}};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(e){let t=Mt(e);return cs(t)}function cs(e){return{n:V(e[1],"base64url"),e:V(e[2],"base64url"),d:V(e[3],"base64url"),p:V(e[4],"base64url"),q:V(e[5],"base64url"),dp:V(e[6],"base64url"),dq:V(e[7],"base64url"),qi:V(e[8],"base64url"),kty:"RSA"}}function Vl(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new q("JWK was missing components");return Jt([wt(Uint8Array.from([0])),wt(z(e.n,"base64url")),wt(z(e.e,"base64url")),wt(z(e.d,"base64url")),wt(z(e.p,"base64url")),wt(z(e.q,"base64url")),wt(z(e.dp,"base64url")),wt(z(e.dq,"base64url")),wt(z(e.qi,"base64url"))]).subarray()}function Hl(e){let t=Mt(e,{offset:0});return us(t)}function us(e){let t=Mt(e[1],{offset:0});return{kty:"RSA",n:V(t[0],"base64url"),e:V(t[1],"base64url")}}function ls(e){if(e.n==null||e.e==null)throw new q("JWK was missing components");return Jt([Ml,Nr(Jt([wt(z(e.n,"base64url")),wt(z(e.e,"base64url"))]))]).subarray()}function xa(e){let t=Mt(e);return fs(t)}function fs(e){let t=cs(e);return ps(t)}function ds(e,t){if(e.byteLength>=Ul)throw new Ee("Key size is too large");let r=Mt(e,{offset:0});return hs(r,e,t)}function hs(e,t,r){let n=us(e);if(r==null){let o=Le(Pt.encode({Type:G.RSA,Data:t}));r=Ot(as,o)}return new Me(n,r)}function ps(e){if(Sa(e)>is)throw new q("Key size is too large");let t=Ea(e),r=Le(Pt.encode({Type:G.RSA,Data:ls(t.publicKey)})),n=Ot(as,r);return new pr(t.privateKey,new Me(t.publicKey,n))}async function wa(e){if(e>is)throw new q("Key size is too large");let t=await va(e),r=Le(Pt.encode({Type:G.RSA,Data:ls(t.publicKey)})),n=Ot(as,r);return new pr(t.privateKey,new Me(t.publicKey,n))}function Ea(e){if(e==null)throw new q("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function va(e,t){let r=await _t.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await zl(r,t);return{privateKey:n[0],publicKey:n[1]}}async function ba(e,t,r){let n=await _t.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await _t.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function ga(e,t,r,n){let o=await _t.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await _t.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function zl(e,t){if(e.privateKey==null||e.publicKey==null)throw new q("Private and public key are required");let r=await Promise.all([_t.get().subtle.exportKey("jwk",e.privateKey),_t.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function Sa(e){if(e.kty!=="RSA")throw new q("invalid key type");if(e.n==null)throw new q("invalid key modulus");return z(e.n,"base64url").length*8}var en=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,r){if(Ur(t),P(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Vt(o)}update(t){return Re(this),this.iHash.update(t),this}digestInto(t){Re(this),P(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:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ms=(e,t,r)=>new en(e,t).update(r).digest();ms.create=(e,t)=>new en(e,t);var Aa=(e,t)=>(e+(e>=0?t:-t)/_a)/t;function Fl(e,t,r){let[[n,o],[s,i]]=t,a=Aa(i*e,r),c=Aa(-o*e,r),l=e-a*n-c*s,u=-a*o-c*i,d=l<Wt,f=u<Wt;d&&(l=-l),f&&(u=-u);let h=ir(Math.ceil(Co(r)/2))+qe;if(l<Wt||l>=h||u<Wt||u>=h)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:d,k1:l,k2neg:f,k2:u}}function bs(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function ys(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return $t(r.lowS,"lowS"),$t(r.prehash,"prehash"),r.format!==void 0&&bs(r.format),r}var gs=class extends Error{constructor(t=""){super(t)}},ie={Err:gs,_tlv:{encode:(e,t)=>{let{Err:r}=ie;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=or(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?or(o.length/2|128):"";return or(e)+s+o+t},decode(e,t){let{Err:r}=ie,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let l=t.subarray(n,n+c);if(l.length!==c)throw new r("tlv.decode: length bytes not complete");if(l[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of l)i=i<<8|u;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=ie;if(e<Wt)throw new t("integer: negative integers are not allowed");let r=or(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=ie;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Oe(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=ie,o=P(e,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:l,l:u}=n.decode(2,c);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(l)}},hexFromSig(e){let{_tlv:t,_int:r}=ie,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},Wt=BigInt(0),qe=BigInt(1),_a=BigInt(2),rn=BigInt(3),$l=BigInt(4);function Ia(e,t={}){let r=Fr("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:a}=s;ne(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 l=Ta(n,o);function u(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function d(R,g,x){let{x:b,y:A}=g.toAffine(),C=n.toBytes(b);if($t(x,"isCompressed"),x){u();let B=!n.isOdd(A);return Et(Ca(B),C)}else return Et(Uint8Array.of(4),C,n.toBytes(A))}function f(R){P(R,void 0,"Point");let{publicKey:g,publicKeyUncompressed:x}=l,b=R.length,A=R[0],C=R.subarray(1);if(b===g&&(A===2||A===3)){let B=n.fromBytes(C);if(!n.isValid(B))throw new Error("bad point: is not on curve, wrong x");let D=E(B),T;try{T=n.sqrt(D)}catch(Y){let $=Y instanceof Error?": "+Y.message:"";throw new Error("bad point: is not on curve, sqrt error"+$)}u();let L=n.isOdd(T);return(A&1)===1!==L&&(T=n.neg(T)),{x:B,y:T}}else if(b===x&&A===4){let B=n.BYTES,D=n.fromBytes(C.subarray(0,B)),T=n.fromBytes(C.subarray(B,B*2));if(!y(D,T))throw new Error("bad point: is not on curve");return{x:D,y:T}}else throw new Error(`bad point: got length ${b}, expected compressed=${g} or uncompressed=${x}`)}let h=t.toBytes||d,p=t.fromBytes||f;function E(R){let g=n.sqr(R),x=n.mul(g,R);return n.add(n.add(x,n.mul(R,s.a)),s.b)}function y(R,g){let x=n.sqr(g),b=E(R);return n.eql(x,b)}if(!y(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let m=n.mul(n.pow(s.a,rn),$l),_=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(m,_)))throw new Error("bad curve params: a or b");function w(R,g,x=!1){if(!n.isValid(g)||x&&n.is0(g))throw new Error(`bad point coordinate ${R}`);return g}function I(R){if(!(R instanceof v))throw new Error("Weierstrass Point expected")}function O(R){if(!c||!c.basises)throw new Error("no endo");return Fl(R,c.basises,o.ORDER)}let N=ke((R,g)=>{let{X:x,Y:b,Z:A}=R;if(n.eql(A,n.ONE))return{x,y:b};let C=R.is0();g==null&&(g=C?n.ONE:n.inv(A));let B=n.mul(x,g),D=n.mul(b,g),T=n.mul(A,g);if(C)return{x:n.ZERO,y:n.ZERO};if(!n.eql(T,n.ONE))throw new Error("invZ was invalid");return{x:B,y:D}}),U=ke(R=>{if(R.is0()){if(t.allowInfinityPoint&&!n.is0(R.Y))return;throw new Error("bad point: ZERO")}let{x:g,y:x}=R.toAffine();if(!n.isValid(g)||!n.isValid(x))throw new Error("bad point: x or y not field elements");if(!y(g,x))throw new Error("bad point: equation left != right");if(!R.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function S(R,g,x,b,A){return x=new v(n.mul(x.X,R),x.Y,x.Z),g=cr(b,g),x=cr(A,x),g.add(x)}class v{static BASE=new v(s.Gx,s.Gy,n.ONE);static ZERO=new v(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(g,x,b){this.X=w("x",g),this.Y=w("y",x,!0),this.Z=w("z",b),Object.freeze(this)}static CURVE(){return s}static fromAffine(g){let{x,y:b}=g||{};if(!g||!n.isValid(x)||!n.isValid(b))throw new Error("invalid affine point");if(g instanceof v)throw new Error("projective point not allowed");return n.is0(x)&&n.is0(b)?v.ZERO:new v(x,b,n.ONE)}static fromBytes(g){let x=v.fromAffine(p(P(g,void 0,"point")));return x.assertValidity(),x}static fromHex(g){return v.fromBytes(zt(g))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,x=!0){return M.createCache(this,g),x||this.multiply(rn),this}assertValidity(){U(this)}hasEvenY(){let{y:g}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(g)}equals(g){I(g);let{X:x,Y:b,Z:A}=this,{X:C,Y:B,Z:D}=g,T=n.eql(n.mul(x,D),n.mul(C,A)),L=n.eql(n.mul(b,D),n.mul(B,A));return T&&L}negate(){return new v(this.X,n.neg(this.Y),this.Z)}double(){let{a:g,b:x}=s,b=n.mul(x,rn),{X:A,Y:C,Z:B}=this,D=n.ZERO,T=n.ZERO,L=n.ZERO,K=n.mul(A,A),Y=n.mul(C,C),$=n.mul(B,B),H=n.mul(A,C);return H=n.add(H,H),L=n.mul(A,B),L=n.add(L,L),D=n.mul(g,L),T=n.mul(b,$),T=n.add(D,T),D=n.sub(Y,T),T=n.add(Y,T),T=n.mul(D,T),D=n.mul(H,D),L=n.mul(b,L),$=n.mul(g,$),H=n.sub(K,$),H=n.mul(g,H),H=n.add(H,L),L=n.add(K,K),K=n.add(L,K),K=n.add(K,$),K=n.mul(K,H),T=n.add(T,K),$=n.mul(C,B),$=n.add($,$),K=n.mul($,H),D=n.sub(D,K),L=n.mul($,Y),L=n.add(L,L),L=n.add(L,L),new v(D,T,L)}add(g){I(g);let{X:x,Y:b,Z:A}=this,{X:C,Y:B,Z:D}=g,T=n.ZERO,L=n.ZERO,K=n.ZERO,Y=s.a,$=n.mul(s.b,rn),H=n.mul(x,C),X=n.mul(b,B),it=n.mul(A,D),Dt=n.add(x,b),j=n.add(C,B);Dt=n.mul(Dt,j),j=n.add(H,X),Dt=n.sub(Dt,j),j=n.add(x,A);let ut=n.add(C,D);return j=n.mul(j,ut),ut=n.add(H,it),j=n.sub(j,ut),ut=n.add(b,A),T=n.add(B,D),ut=n.mul(ut,T),T=n.add(X,it),ut=n.sub(ut,T),K=n.mul(Y,j),T=n.mul($,it),K=n.add(T,K),T=n.sub(X,K),K=n.add(X,K),L=n.mul(T,K),X=n.add(H,H),X=n.add(X,H),it=n.mul(Y,it),j=n.mul($,j),X=n.add(X,it),it=n.sub(H,it),it=n.mul(Y,it),j=n.add(j,it),H=n.mul(X,j),L=n.add(L,H),H=n.mul(ut,j),T=n.mul(Dt,T),T=n.sub(T,H),H=n.mul(Dt,X),K=n.mul(ut,K),K=n.add(K,H),new v(T,L,K)}subtract(g){return this.add(g.negate())}is0(){return this.equals(v.ZERO)}multiply(g){let{endo:x}=t;if(!o.isValidNot0(g))throw new Error("invalid scalar: out of range");let b,A,C=B=>M.cached(this,B,D=>pe(v,D));if(x){let{k1neg:B,k1:D,k2neg:T,k2:L}=O(g),{p:K,f:Y}=C(D),{p:$,f:H}=C(L);A=Y.add(H),b=S(x.beta,K,$,B,T)}else{let{p:B,f:D}=C(g);b=B,A=D}return pe(v,[b,A])[0]}multiplyUnsafe(g){let{endo:x}=t,b=this;if(!o.isValid(g))throw new Error("invalid scalar: out of range");if(g===Wt||b.is0())return v.ZERO;if(g===qe)return b;if(M.hasCache(this))return this.multiply(g);if(x){let{k1neg:A,k1:C,k2neg:B,k2:D}=O(g),{p1:T,p2:L}=Qi(v,b,C,D);return S(x.beta,T,L,A,B)}else return M.unsafe(b,g)}toAffine(g){return N(this,g)}isTorsionFree(){let{isTorsionFree:g}=t;return i===qe?!0:g?g(v,this):M.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:g}=t;return i===qe?this:g?g(v,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(g=!0){return $t(g,"isCompressed"),this.assertValidity(),h(v,this,g)}toHex(g=!0){return Ht(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let k=o.BITS,M=new Ne(v,t.endo?Math.ceil(k/2):k);return v.BASE.precompute(8),v}function Ca(e){return Uint8Array.of(e?2:3)}function Ta(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Wl(e,t={}){let{Fn:r}=e,n=t.randomBytes||De,o=Object.assign(Ta(e.Fp,r),{seed:Do(r.ORDER)});function s(h){try{let p=r.fromBytes(h);return r.isValidNot0(p)}catch{return!1}}function i(h,p){let{publicKey:E,publicKeyUncompressed:y}=o;try{let m=h.length;return p===!0&&m!==E||p===!1&&m!==y?!1:!!e.fromBytes(h)}catch{return!1}}function a(h=n(o.seed)){return Lo(P(h,o.seed,"seed"),r.ORDER)}function c(h,p=!0){return e.BASE.multiply(r.fromBytes(h)).toBytes(p)}function l(h){let{secretKey:p,publicKey:E,publicKeyUncompressed:y}=o;if(!ce(h)||"_lengths"in r&&r._lengths||p===E)return;let m=P(h,void 0,"key").length;return m===E||m===y}function u(h,p,E=!0){if(l(h)===!0)throw new Error("first arg must be private key");if(l(p)===!1)throw new Error("second arg must be public key");let y=r.fromBytes(h);return e.fromBytes(p).multiply(y).toBytes(E)}let d={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},f=$r(a,c);return Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:f,Point:e,utils:d,lengths:o})}function Ba(e,t,r={}){Ur(t),ne(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let n=r.randomBytes||De,o=r.hmac||((x,b)=>ms(t,x,b)),{Fp:s,Fn:i}=e,{ORDER:a,BITS:c}=i,{keygen:l,getPublicKey:u,getSharedSecret:d,utils:f,lengths:h}=Wl(e,r),p={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},E=a*_a<s.ORDER;function y(x){let b=a>>qe;return x>b}function m(x,b){if(!i.isValidNot0(b))throw new Error(`invalid signature ${x}: out of range 1..Point.Fn.ORDER`);return b}function _(){if(E)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function w(x,b){bs(b);let A=h.signature,C=b==="compact"?A:b==="recovered"?A+1:void 0;return P(x,C)}class I{r;s;recovery;constructor(b,A,C){if(this.r=m("r",b),this.s=m("s",A),C!=null){if(_(),![0,1,2,3].includes(C))throw new Error("invalid recovery id");this.recovery=C}Object.freeze(this)}static fromBytes(b,A=p.format){w(b,A);let C;if(A==="der"){let{r:L,s:K}=ie.toSig(P(b));return new I(L,K)}A==="recovered"&&(C=b[0],A="compact",b=b.subarray(1));let B=h.signature/2,D=b.subarray(0,B),T=b.subarray(B,B*2);return new I(i.fromBytes(D),i.fromBytes(T),C)}static fromHex(b,A){return this.fromBytes(zt(b),A)}assertRecovery(){let{recovery:b}=this;if(b==null)throw new Error("invalid recovery id: must be present");return b}addRecoveryBit(b){return new I(this.r,this.s,b)}recoverPublicKey(b){let{r:A,s:C}=this,B=this.assertRecovery(),D=B===2||B===3?A+a:A;if(!s.isValid(D))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let T=s.toBytes(D),L=e.fromBytes(Et(Ca((B&1)===0),T)),K=i.inv(D),Y=N(P(b,void 0,"msgHash")),$=i.create(-Y*K),H=i.create(C*K),X=e.BASE.multiplyUnsafe($).add(L.multiplyUnsafe(H));if(X.is0())throw new Error("invalid recovery: point at infinify");return X.assertValidity(),X}hasHighS(){return y(this.s)}toBytes(b=p.format){if(bs(b),b==="der")return zt(ie.hexFromSig(this));let{r:A,s:C}=this,B=i.toBytes(A),D=i.toBytes(C);return b==="recovered"?(_(),Et(Uint8Array.of(this.assertRecovery()),B,D)):Et(B,D)}toHex(b){return Ht(this.toBytes(b))}}let O=r.bits2int||function(b){if(b.length>8192)throw new Error("input is too large");let A=Oe(b),C=b.length*8-c;return C>0?A>>BigInt(C):A},N=r.bits2int_modN||function(b){return i.create(O(b))},U=ir(c);function S(x){return sr("num < 2^"+c,x,Wt,U),i.toBytes(x)}function v(x,b){return P(x,void 0,"message"),b?P(t(x),void 0,"prehashed message"):x}function k(x,b,A){let{lowS:C,prehash:B,extraEntropy:D}=ys(A,p);x=v(x,B);let T=N(x),L=i.fromBytes(b);if(!i.isValidNot0(L))throw new Error("invalid private key");let K=[S(L),S(T)];if(D!=null&&D!==!1){let X=D===!0?n(h.secretKey):D;K.push(P(X,void 0,"extraEntropy"))}let Y=Et(...K),$=T;function H(X){let it=O(X);if(!i.isValidNot0(it))return;let Dt=i.inv(it),j=e.BASE.multiply(it).toAffine(),ut=i.create(j.x);if(ut===Wt)return;let Rr=i.create(Dt*i.create($+ut*L));if(Rr===Wt)return;let zs=(j.x===ut?0:2)|Number(j.y&qe),Fs=Rr;return C&&y(Rr)&&(Fs=i.neg(Rr),zs^=1),new I(ut,Fs,E?void 0:zs)}return{seed:Y,k2sig:H}}function M(x,b,A={}){let{seed:C,k2sig:B}=k(x,b,A);return Ki(t.outputLen,i.BYTES,o)(C,B).toBytes(A.format)}function R(x,b,A,C={}){let{lowS:B,prehash:D,format:T}=ys(C,p);if(A=P(A,void 0,"publicKey"),b=v(b,D),!ce(x)){let L=x instanceof I?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+L)}w(x,T);try{let L=I.fromBytes(x,T),K=e.fromBytes(A);if(B&&L.hasHighS())return!1;let{r:Y,s:$}=L,H=N(b),X=i.inv($),it=i.create(H*X),Dt=i.create(Y*X),j=e.BASE.multiplyUnsafe(it).add(K.multiplyUnsafe(Dt));return j.is0()?!1:i.create(j.x)===Y}catch{return!1}}function g(x,b,A={}){let{prehash:C}=ys(A,p);return b=v(b,C),I.fromBytes(x,"recovered").recoverPublicKey(b).toBytes()}return Object.freeze({keygen:l,getPublicKey:u,getSharedSecret:d,utils:f,lengths:h,Point:e,sign:M,verify:R,recoverPublicKey:g,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 Ra=BigInt(2);function Gl(e){let t=ws.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),l=e*e*e%t,u=l*l*e%t,d=Z(u,r,t)*u%t,f=Z(d,r,t)*u%t,h=Z(f,Ra,t)*l%t,p=Z(h,o,t)*h%t,E=Z(p,s,t)*p%t,y=Z(E,a,t)*E%t,m=Z(y,c,t)*y%t,_=Z(m,a,t)*E%t,w=Z(_,r,t)*u%t,I=Z(w,i,t)*p%t,O=Z(I,n,t)*l%t,N=Z(O,Ra,t);if(!xs.eql(xs.sqr(N),e))throw new Error("Cannot find square root");return N}var xs=Ke(ws.p,{sqrt:Gl}),Yl=Ia(ws,{Fp:xs,endo:Zl}),Ve=Ba(Yl,Le);function Da(e,t,r,n){let o=je.digest(r instanceof Uint8Array?r:r.subarray());if(Gr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ve.verify(t,s,e,{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,e,{prehash:!1,format:"der"})}catch(s){throw new ur(String(s))}}var nn=class{type="secp256k1";raw;_key;constructor(t){this._key=Oa(t),this.raw=La(this._key)}toMultihash(){return Tt.digest(At(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}verify(t,r,n){return Da(this._key,r,t,n)}};function Es(e){return new nn(e)}function La(e){return Ve.Point.fromBytes(e).toBytes()}function Oa(e){try{return Ve.Point.fromBytes(e),e}catch(t){throw new Ee(String(t))}}function on(e,t){let{Type:r,Data:n}=Pt.decode(e),o=n??new Uint8Array;switch(r){case G.RSA:return ds(o,t);case G.Ed25519:return qo(o);case G.secp256k1:return Es(o);case G.ECDSA:return mo(o);default:throw new ae}}function ka(e){let{Type:t,Data:r}=Pt.decode(e.digest),n=r??new Uint8Array;switch(t){case G.Ed25519:return qo(n);case G.secp256k1:return Es(n);case G.ECDSA:return mo(n);default:throw new ae}}function At(e){return Pt.encode({Type:G[e.type],Data:e.raw})}var Ka=Symbol.for("nodejs.util.inspect.custom"),Xl=114,yr=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()})`}[Or]=!0;toString(){return this.string==null&&(this.string=J.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 W(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return W(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ka](){return`PeerId(${this.toString()})`}},br=class extends yr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},gr=class extends yr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},xr=class extends yr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},jl=2336,wr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Tt.digest(z(this.url))}[Ka](){return`PeerId(${this.url})`}[Or]=!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,Pa=2336;function Na(e){if(e.type==="Ed25519")return new gr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new xr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new br({multihash:e.toCID().multihash,publicKey:e});throw new ae}function vs(e){if(tf(e))return new br({multihash:e});if(Jl(e))try{let t=ka(e);if(t.type==="Ed25519")return new gr({multihash:e,publicKey:t});if(t.type==="secp256k1")return new xr({multihash:e,publicKey:t})}catch{let r=V(e.digest);return new wr(new URL(r))}throw new Lr("Supplied PeerID Multihash is invalid")}function sn(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==Ql&&e.code!==Pa)throw new Dr("Supplied PeerID CID is invalid");if(e.code===Pa){let t=V(e.multihash.digest);return new wr(new URL(t))}return vs(e.multihash)}function Jl(e){return e.code===Tt.code}function tf(e){return e.code===je.code}var Er;(function(e){let t;e.codec=()=>(t==null&&(t=bt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.publicKey!=null&&s.publicKey.byteLength>0&&(i.uint32(10),i.bytes(s.publicKey)),s.payloadType!=null&&s.payloadType.byteLength>0&&(i.uint32(18),i.bytes(s.payloadType)),s.payload!=null&&s.payload.byteLength>0&&(i.uint32(26),i.bytes(s.payload)),s.signature!=null&&s.signature.byteLength>0&&(i.uint32(42),i.bytes(s.signature)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={publicKey:rt(0),payloadType:rt(0),payload:rt(0),signature:rt(0)},l=i==null?s.len:s.pos+i;for(;s.pos<l;){let u=s.uint32();switch(u>>>3){case 1:{c.publicKey=s.bytes();break}case 2:{c.payloadType=s.bytes();break}case 3:{c.payload=s.bytes();break}case 5:{c.signature=s.bytes();break}default:{s.skipType(u&7);break}}}return c},function*(s,i,a,c={}){let l=i==null?s.len:s.pos+i;for(;s.pos<l;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.publicKey`,value:s.bytes()};break}case 2:{yield{field:`${a}.payloadType`,value:s.bytes()};break}case 3:{yield{field:`${a}.payload`,value:s.bytes()};break}case 5:{yield{field:`${a}.signature`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return mt(s,e.codec())}e.encode=r;function n(s,i){return pt(s,e.codec(),i)}e.decode=n;function o(s,i){return yt(s,e.codec(),i)}e.stream=o})(Er||(Er={}));var an=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var He=class e{static createFromProtobuf=t=>{let r=Er.decode(t),n=on(r.publicKey);return new e({publicKey:n,payloadType:r.payloadType,payload:r.payload,signature:r.signature})};static seal=async(t,r,n)=>{if(r==null)throw new Error("Missing private key");let o=t.domain,s=t.codec,i=t.marshal(),a=Ua(o,s,i),c=await r.sign(a.subarray(),n);return new e({publicKey:r.publicKey,payloadType:s,payload:i,signature:c})};static openAndCertify=async(t,r,n)=>{let o=e.createFromProtobuf(t);if(!await o.validate(r,n))throw new an("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:r,payloadType:n,payload:o,signature:s}=t;this.publicKey=r,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=Er.encode({publicKey:At(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return t==null?!1:W(this.marshal(),t.marshal())}async validate(t,r){let n=Ua(t,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},Ua=(e,t,r)=>{let n=z(e),o=Xr(n.byteLength),s=Xr(t.length),i=Xr(r.length);return new dt(o,n,s,t,i,r)};var ct=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Zt=class extends Error{static name="ValidationError";name="ValidationError"},cn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},un=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var ln=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",l=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let d=this.readChar();if(d===void 0)return;let f=Number.parseInt(d,t);if(!Number.isNaN(f))return f});if(u===void 0)break;if(s*=t,s+=u,s>l||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=t(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var ef=45,rf=15,fn=new ln;function Ma(e){if(!(e.length>rf))return fn.new(e).parseWith(()=>fn.readIPv4Addr())}function qa(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>ef))return fn.new(e).parseWith(()=>fn.readIPv6Addr())}function dn(e){return!!Ma(e)}function Va(e){return!!qa(e)}function As(e){return t=>V(t,e)}function _s(e){return t=>z(t,e)}function ze(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function be(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function Ha(e){let t=e.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 r=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=be(n);return Ut([r,o],r.length+o.length)}function za(e){let t=e.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 r=Lt.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=be(n);return Ut([r,o],r.length+o.length)}function Is(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=V(t,"base32"),o=ze(r);return`${n}:${o}`}var Cs=function(e){e=e.toString().trim();let t=new Uint8Array(4);return e.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new ct("Invalid byte value in IP address");t[n]=o}),t},Fa=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let s=dn(r[n]),i;s&&(i=Cs(r[n]),r[n]=V(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,V(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(t+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new ct("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},$a=function(e){if(e.byteLength!==4)throw new ct("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},Wa=function(e){if(e.byteLength!==16)throw new ct("IPv6 address was incorrect length");let t=[];for(let n=0;n<e.byteLength;n+=2){let o=e[n],s=e[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let r=t.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new ct(`Invalid IPv6 address "${r}"`)}};function Za(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new ct(`Invalid IPv6 address "${e}"`)}}var Ss=Object.values(Qe).map(e=>e.decoder),nf=(function(){let e=Ss[0].or(Ss[1]);return Ss.slice(2).forEach(t=>e=e.or(t)),e})();function Ga(e){return nf.decode(e)}function Ya(e){return t=>e.encoder.encode(t)}function of(e){if(parseInt(e).toString()!==e)throw new Zt("Value must be an integer")}function sf(e){if(e<0)throw new Zt("Value must be a positive integer, or zero")}function af(e){return t=>{if(t>e)throw new Zt(`Value must be smaller than or equal to ${e}`)}}function cf(...e){return t=>{for(let r of e)r(t)}}var vr=cf(of,sf,af(65535));var st=-1,Ts=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let r;if(typeof t=="string"?r=this.protocolsByName.get(t):r=this.protocolsByCode.get(t),r==null)throw new un(`Protocol ${t} was unknown`);return r}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(r=>{this.protocolsByName.set(r,t)})}removeProtocol(t){let r=this.protocolsByCode.get(t);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},Gt=new Ts,Gf=[{code:4,name:"ip4",size:32,valueToBytes:Cs,bytesToValue:$a,validate:e=>{if(!dn(e))throw new Zt(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:be,bytesToValue:ze,validate:vr},{code:273,name:"udp",size:16,valueToBytes:be,bytesToValue:ze,validate:vr},{code:33,name:"dccp",size:16,valueToBytes:be,bytesToValue:ze,validate:vr},{code:41,name:"ip6",size:128,valueToBytes:Fa,bytesToValue:Wa,stringToValue:Za,validate:e=>{if(!Va(e))throw new Zt(`Invalid IPv6 address "${e}"`)}},{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:be,bytesToValue:ze,validate:vr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:st,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:st,bytesToValue:As("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?_s("base58btc")(e):et.parse(e).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(eo),valueToBytes:Ga},{code:480,name:"http"},{code:481,name:"http-path",size:st,stringToValue:e=>`/${decodeURIComponent(e)}`,valueToString:e=>encodeURIComponent(e.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(e=>{Gt.addProtocol(e)});function Xa(e){let t=[],r=0;for(;r<e.length;){let n=Wo(e,r),o=Gt.getProtocol(n),s=It(n),i=Yf(o,e,r+s),a=0;i>0&&o.size===st&&(a=It(i));let c=s+a+i,l={code:n,name:o.name,bytes:e.subarray(r,r+c)};if(i>0){let u=r+s+a,d=e.subarray(u,u+i);l.value=o.bytesToValue?.(d)??V(d)}t.push(l),r+=c}return t}function ja(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=Gt.getProtocol(n.code),s=It(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=It(a)));let l=new Uint8Array(s+c+a),u=0;Ue(n.code,l,u),u+=s,i!=null&&(o.size===st&&(Ue(a,l,u),u+=c),l.set(i,u)),n.bytes=l}r.push(n.bytes),t+=n.bytes.byteLength}return Ut(r,t)}function Qa(e){if(e.charAt(0)!=="/")throw new ct('String multiaddr must start with "/"');let t=[],r="protocol",n="",o="";for(let s=1;s<e.length;s++){let i=e.charAt(s);i!=="/"&&(r==="protocol"?o+=e.charAt(s):n+=e.charAt(s));let a=s===e.length-1;if(i==="/"||a){let c=Gt.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new ct(`Component ${o} was missing value`);r="value"}else if(r==="value"){let l={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new ct(`Component ${o} was missing value`);l.value=c.stringToValue?.(n)??n}t.push(l),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new ct("Incomplete multiaddr");return t}function Ja(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=Gt.getProtocol(t.code);if(r==null)throw new ct(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function Yf(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:Wo(t,r)}var Xf=Symbol.for("nodejs.util.inspect.custom"),Rs=Symbol.for("@multiformats/multiaddr");function jf(e){if(e==null&&(e="/"),pn(e))return e.getComponents();if(e instanceof Uint8Array)return Xa(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),Qa(e);if(Array.isArray(e))return e;throw new ct("Must be a string, Uint8Array, Component[], or another Multiaddr")}var hn=class e{[Rs]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=jf(t),r.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 r=new e(t);return new e([...this.#t,...r.getComponents()],{validate:!1})}decapsulate(t){let r=t.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new cn(`Address ${this.toString()} does not contain subaddress: ${r}`);return new e(n.slice(0,o),{validate:!1})}decapsulateCode(t){let r;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){r=n;break}return new e(this.#t.slice(0,r),{validate:!1})}equals(t){return W(this.bytes,t.bytes)}[Xf](){return`Multiaddr(${this.toString()})`}};function Qf(e){e.getComponents().forEach(t=>{let r=Gt.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function pn(e){return!!e?.[Rs]}function ge(e){return new hn(e)}var tc="libp2p-peer-record",ec=Uint8Array.from([3,1]);var Sr;(function(e){let t;(function(i){let a;i.codec=()=>(a==null&&(a=bt((d,f,h={})=>{h.lengthDelimited!==!1&&f.fork(),d.multiaddr!=null&&d.multiaddr.byteLength>0&&(f.uint32(10),f.bytes(d.multiaddr)),h.lengthDelimited!==!1&&f.ldelim()},(d,f,h={})=>{let p={multiaddr:rt(0)},E=f==null?d.len:d.pos+f;for(;d.pos<E;){let y=d.uint32();switch(y>>>3){case 1:{p.multiaddr=d.bytes();break}default:{d.skipType(y&7);break}}}return p},function*(d,f,h,p={}){let E=f==null?d.len:d.pos+f;for(;d.pos<E;){let y=d.uint32();switch(y>>>3){case 1:{yield{field:`${h}.multiaddr`,value:d.bytes()};break}default:{d.skipType(y&7);break}}}})),a);function c(d){return mt(d,i.codec())}i.encode=c;function l(d,f){return pt(d,i.codec(),f)}i.decode=l;function u(d,f){return yt(d,i.codec(),f)}i.stream=u})(t=e.AddressInfo||(e.AddressInfo={}));let r;e.codec=()=>(r==null&&(r=bt((i,a,c={})=>{if(c.lengthDelimited!==!1&&a.fork(),i.peerId!=null&&i.peerId.byteLength>0&&(a.uint32(10),a.bytes(i.peerId)),i.seq!=null&&i.seq!==0n&&(a.uint32(16),a.uint64(i.seq)),i.addresses!=null&&i.addresses.length>0)for(let l of i.addresses)a.uint32(26),e.AddressInfo.codec().encode(l,a);c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let l={peerId:rt(0),seq:0n,addresses:[]},u=a==null?i.len:i.pos+a;for(;i.pos<u;){let d=i.uint32();switch(d>>>3){case 1:{l.peerId=i.bytes();break}case 2:{l.seq=i.uint64();break}case 3:{if(c.limits?.addresses!=null&&l.addresses.length===c.limits.addresses)throw new Ct('Decode error - repeated field "addresses" had too many elements');l.addresses.push(e.AddressInfo.codec().decode(i,i.uint32(),{limits:c.limits?.addresses$}));break}default:{i.skipType(d&7);break}}}return l},function*(i,a,c,l={}){let u={addresses:0},d=a==null?i.len:i.pos+a;for(;i.pos<d;){let f=i.uint32();switch(f>>>3){case 1:{yield{field:`${c}.peerId`,value:i.bytes()};break}case 2:{yield{field:`${c}.seq`,value:i.uint64()};break}case 3:{if(l.limits?.addresses!=null&&u.addresses===l.limits.addresses)throw new Ct('Streaming decode error - repeated field "addresses" had too many elements');for(let h of e.AddressInfo.codec().stream(i,i.uint32(),`${c}.addresses[]`,{limits:l.limits?.addresses$}))yield{...h,index:u.addresses};u.addresses++;break}default:{i.skipType(f&7);break}}}})),r);function n(i){return mt(i,e.codec())}e.encode=n;function o(i,a){return pt(i,e.codec(),a)}e.decode=o;function s(i,a){return yt(i,e.codec(),a)}e.stream=s})(Sr||(Sr={}));function rc(e,t){let r=(n,o)=>n.toString().localeCompare(o.toString());return e.length!==t.length?!1:(t.sort(r),e.sort(r).every((n,o)=>t[o].equals(n)))}var xe=class e{static createFromProtobuf=t=>{let r=Sr.decode(t),n=vs(Te(r.peerId)),o=(r.addresses??[]).map(i=>ge(i.multiaddr)),s=r.seq;return new e({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=tc;static CODEC=ec;peerId;multiaddrs;seqNumber;domain=e.DOMAIN;codec=e.CODEC;marshaled;constructor(t){let{peerId:r,multiaddrs:n,seqNumber:o}=t;this.peerId=r,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=Sr.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 e)||!this.peerId.equals(t.peerId)||this.seqNumber!==t.seqNumber||!rc(this.multiaddrs,t.multiaddrs))}};function Jf(e){return e[Symbol.asyncIterator]!=null}function td(e){if(Jf(e))return(async()=>{let r=[];for await(let n of e)r.push(n);return r})();let t=[];for(let r of e)t.push(r);return t}var nc=td;function mn(e,t){let r={[Symbol.iterator]:()=>r,next:()=>{let n=e.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return r}var Ar=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[r,n]of t.entries())this.map.set(r.toString(),{key:r,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return mn(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((r,n)=>{t(r.value,r.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,r){this.map.set(t.toString(),{key:t,value:r})}keys(){return mn(this.map.values(),t=>t.key)}values(){return mn(this.map.values(),t=>t.value)}get size(){return this.map.size}};function yn(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var bn=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 bn(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 r=this.head;this.head=r.next=new bn(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Ds=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function oc(e={}){return ed(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},e)}function ed(e,t){t=t??{};let r=t.onEnd,n=new Fe,o,s,i,a=yn(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((y,m)=>{s=_=>{s=null,n.push(_);try{y(e(n))}catch(w){m(w)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=yn()})}},l=y=>s!=null?s(y):(n.push(y),o),u=y=>(n=new Fe,s!=null?s({error:y}):(n.push({error:y}),o)),d=y=>{if(i)return o;if(t?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:y})},f=y=>i?o:(i=!0,y!=null?u(y):l({done:!0})),h=()=>(n=new Fe,f(),{done:!0}),p=y=>(f(y),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:h,throw:p,push:d,end:f,get readableLength(){return n.size},onEmpty:async y=>{let m=y?.signal;if(m?.throwIfAborted(),n.isEmpty())return;let _,w;m!=null&&(_=new Promise((I,O)=>{w=()=>{O(new Ds)},m.addEventListener("abort",w)}));try{await Promise.race([a.promise,_])}finally{w!=null&&m!=null&&m?.removeEventListener("abort",w)}}},r==null)return o;let E=o;return o={[Symbol.asyncIterator](){return this},next(){return E.next()},throw(y){return E.throw(y),r!=null&&(r(y),r=void 0),{done:!0}},return(){return E.return(),r!=null&&(r(),r=void 0),{done:!0}},push:d,end(y){return E.end(y),r!=null&&(r(y),r=void 0),o},get readableLength(){return E.readableLength},onEmpty:y=>E.onEmpty(y)},o}function rd(e){return e.reason}async function sc(e,t,r){if(t==null)return e;let n=r?.translateError??rd;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([e,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}var Ls=class extends Ar{metric;constructor(t){super();let{name:r,metrics:n}=t;this.metric=n.registerMetric(r),this.updateComponentMetric()}set(t,r){return super.set(t,r),this.updateComponentMetric(),this}delete(t){let r=super.delete(t);return this.updateComponentMetric(),r}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function Os(e){let{name:t,metrics:r}=e,n;return r!=null?n=new Ls({name:t,metrics:r}):n=new Ar,n}var St=class extends Error{static name="AbortError";name="AbortError";constructor(t="The operation was aborted",...r){super(t,...r)}};async function gn(e,t,r,n){let o=new St(n?.errorMessage);n?.errorCode!=null&&(o.code=n.errorCode);let s=n?.errorEvent??"error";return r?.aborted===!0?Promise.reject(o):new Promise((i,a)=>{function c(){Ks(r,"abort",d),Ks(e,t,l),Ks(e,s,u)}let l=f=>{try{if(n?.filter?.(f)===!1)return}catch(h){c(),a(h);return}c(),i(f)},u=f=>{if(c(),f instanceof Error){a(f);return}a(f.detail??n?.error??new Error(`The "${n?.errorEvent}" event was emitted but the event had no '.detail' field. Pass an 'error' option to race-event to change this message.`))},d=()=>{c(),a(o)};ks(r,"abort",d),ks(e,t,l),ks(e,s,u)})}function ks(e,t,r){e!=null&&(ic(e)?e.addEventListener(t,r):e.addListener(t,r))}function Ks(e,t,r){e!=null&&(ic(e)?e.removeEventListener(t,r):e.removeListener(t,r))}function ic(e){return typeof e.addEventListener=="function"&&typeof e.removeEventListener=="function"}var xn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};var wn=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 St)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function nd(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var En=class{id;fn;options;recipients;status;timeline;controller;constructor(t,r){this.id=nd(),this.status="queued",this.fn=t,this.options=r,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((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new St),this.cleanup())}async join(t={}){let r=new wn(t.signal);return this.recipients.push(r),t.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await sc(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(t)}),this.status="complete"}catch(t){this.recipients.forEach(r=>{r.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(e,t){let r,n=function(){let o=function(){r=void 0,e()};clearTimeout(r),r=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var _r=class extends Se{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 r of this.queue)if(r.status==="queued"){t=r;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===t){this.queue.splice(r,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,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new xn;let n=new En(t,r);return this.enqueue(n),this.safeDispatchEvent("add"),this.autoStart&&this.tryToStartAnother(),n.join(r).then(o=>(this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(t=>{t.abort(new St)}),this.clear()}async onEmpty(t){this.size!==0&&await gn(this,"empty",t?.signal)}async onSizeLessThan(t,r){this.size<t||await gn(this,"next",r?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await gn(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 r=oc({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},o=c=>{c.detail!=null&&r.push(c.detail.result)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new St("Queue aborted"))};this.addEventListener("success",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("success",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};var vn="lock:worker:request-read",Sn="lock:worker:abort-read-request",An="lock:worker:release-read",_n="lock:master:grant-read",In="lock:master:error-read",Cn="lock:worker:request-write",Tn="lock:worker:abort-write-request",Bn="lock:worker:release-write",Rn="lock:master:grant-write",Dn="lock:master:error-write",Ln="lock:worker:finalize",On="mortice",ac={singleProcess:!1};var Ns=(e,t,r,n,o,s,i,a,c)=>l=>{if(l.data==null)return;let u={type:l.data.type,name:l.data.name,identifier:l.data.identifier};u.type===o&&e.safeDispatchEvent(r,{detail:{name:u.name,identifier:u.identifier,handler:async()=>{t.postMessage({type:c,name:u.name,identifier:u.identifier}),await new Promise(d=>{let f=h=>{if(h?.data==null)return;let p={type:h.data.type,name:h.data.name,identifier:h.data.identifier};p.type===a&&p.identifier===u.identifier&&(t.removeEventListener("message",f),d())};t.addEventListener("message",f)})},onError:d=>{t.postMessage({type:i,name:u.name,identifier:u.identifier,error:{message:d.message,name:d.name,stack:d.stack}})}}}),u.type===s&&e.safeDispatchEvent(n,{detail:{name:u.name,identifier:u.identifier}}),u.type===Ln&&e.safeDispatchEvent("finalizeRequest",{detail:{name:u.name}})};var cc=(e=10)=>Math.random().toString().substring(2,e+2);var kn=class{name;channel;constructor(t){this.name=t,this.channel=new BroadcastChannel(On)}readLock(t){return this.sendRequest(vn,Sn,_n,In,An,t)}writeLock(t){return this.sendRequest(Cn,Tn,Rn,Dn,Bn,t)}finalize(){this.channel.postMessage({type:Ln,name:this.name}),this.channel.close()}async sendRequest(t,r,n,o,s,i){i?.signal?.throwIfAborted();let a=cc();return this.channel.postMessage({type:t,identifier:a,name:this.name}),new Promise((c,l)=>{let u=()=>{this.channel.postMessage({type:r,identifier:a,name:this.name})};i?.signal?.addEventListener("abort",u,{once:!0});let d=f=>{if(f.data?.identifier===a&&(f.data?.type===n&&(this.channel.removeEventListener("message",d),i?.signal?.removeEventListener("abort",u),c(()=>{this.channel.postMessage({type:s,identifier:a,name:this.name})})),f.data.type===o)){this.channel.removeEventListener("message",d),i?.signal?.removeEventListener("abort",u);let h=new Error;f.data.error!=null&&(h.message=f.data.error.message,h.name=f.data.error.name,h.stack=f.data.error.stack),l(h)}};this.channel.addEventListener("message",d)})}};var uc=e=>{if(e=Object.assign({},ac,e),!!globalThis.document||e.singleProcess){let r=new BroadcastChannel(On),n=new Se;return r.addEventListener("message",Ns(n,r,"requestReadLock","abortReadLockRequest",vn,Sn,In,An,_n)),r.addEventListener("message",Ns(n,r,"requestWriteLock","abortWriteLockRequest",Cn,Tn,Dn,Bn,Rn)),n}return new kn(e.name)};var we=new Map,Ir;function lc(e){return typeof e?.readLock=="function"&&typeof e?.writeLock=="function"}function od(e){if(Ir==null&&(Ir=uc(e),!lc(Ir))){let t=Ir;t.addEventListener("requestReadLock",r=>{let n=r.detail.name,o=r.detail.identifier,s=we.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 r.detail.handler().finally(()=>{c()})}).catch(c=>{r.detail.onError(c)}).finally(()=>{t.removeEventListener("abortReadLockRequest",a)})}),t.addEventListener("requestWriteLock",r=>{let n=r.detail.name,o=r.detail.identifier,s=we.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 r.detail.handler().finally(()=>{c()})}).catch(c=>{r.detail.onError(c)}).finally(()=>{t.removeEventListener("abortWriteLockRequest",a)})}),t.addEventListener("finalizeRequest",r=>{let n=r.detail.name,o=we.get(n);o?.finalize()})}return Ir}async function Us(e,t){let r,n,o=new Promise((i,a)=>{r=i,n=a}),s=()=>{n(new St)};return t?.signal?.addEventListener("abort",s,{once:!0}),e.add(async()=>{await new Promise(i=>{r(()=>{t?.signal?.removeEventListener("abort",s),i()})})},{signal:t?.signal}).catch(i=>{n(i)}),o}var fc=(e,t)=>{let r=we.get(e);if(r!=null)return r;let n=od(t);if(lc(n))return r=n,we.set(e,r),r;let o=new _r({concurrency:1}),s;return r={async readLock(i){if(s!=null)return Us(s,i);s=new _r({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:()=>{we.delete(e)},queue:o},we.set(e,r),t.autoFinalize===!0&&o.addEventListener("idle",()=>{r.finalize()},{once:!0}),r};var sd={name:"lock",concurrency:1/0,singleProcess:!1,autoFinalize:!1};function Ms(e){let t=Object.assign({},sd,e);return fc(t.name,t)}var Yt;(function(e){let t;(function(a){let c;a.codec=()=>(c==null&&(c=bt((f,h,p={})=>{p.lengthDelimited!==!1&&h.fork(),f.key!=null&&f.key!==""&&(h.uint32(10),h.string(f.key)),f.value!=null&&f.value.byteLength>0&&(h.uint32(18),h.bytes(f.value)),p.lengthDelimited!==!1&&h.ldelim()},(f,h,p={})=>{let E={key:"",value:rt(0)},y=h==null?f.len:f.pos+h;for(;f.pos<y;){let m=f.uint32();switch(m>>>3){case 1:{E.key=f.string();break}case 2:{E.value=f.bytes();break}default:{f.skipType(m&7);break}}}return E},function*(f,h,p,E={}){let y=h==null?f.len:f.pos+h;for(;f.pos<y;){let m=f.uint32();switch(m>>>3){case 1:{yield{field:`${p}.key`,value:f.string()};break}case 2:{yield{field:`${p}.value`,value:f.bytes()};break}default:{f.skipType(m&7);break}}}})),c);function l(f){return mt(f,a.codec())}a.encode=l;function u(f,h){return pt(f,a.codec(),h)}a.decode=u;function d(f,h){return yt(f,a.codec(),h)}a.stream=d})(t=e.Peer$metadataEntry||(e.Peer$metadataEntry={}));let r;(function(a){let c;a.codec=()=>(c==null&&(c=bt((f,h,p={})=>{p.lengthDelimited!==!1&&h.fork(),f.key!=null&&f.key!==""&&(h.uint32(10),h.string(f.key)),f.value!=null&&(h.uint32(18),Tr.codec().encode(f.value,h)),p.lengthDelimited!==!1&&h.ldelim()},(f,h,p={})=>{let E={key:""},y=h==null?f.len:f.pos+h;for(;f.pos<y;){let m=f.uint32();switch(m>>>3){case 1:{E.key=f.string();break}case 2:{E.value=Tr.codec().decode(f,f.uint32(),{limits:p.limits?.value});break}default:{f.skipType(m&7);break}}}return E},function*(f,h,p,E={}){let y=h==null?f.len:f.pos+h;for(;f.pos<y;){let m=f.uint32();switch(m>>>3){case 1:{yield{field:`${p}.key`,value:f.string()};break}case 2:{yield*Tr.codec().stream(f,f.uint32(),`${p}.value`,{limits:E.limits?.value});break}default:{f.skipType(m&7);break}}}})),c);function l(f){return mt(f,a.codec())}a.encode=l;function u(f,h){return pt(f,a.codec(),h)}a.decode=u;function d(f,h){return yt(f,a.codec(),h)}a.stream=d})(r=e.Peer$tagsEntry||(e.Peer$tagsEntry={}));let n;e.codec=()=>(n==null&&(n=bt((a,c,l={})=>{if(l.lengthDelimited!==!1&&c.fork(),a.addresses!=null&&a.addresses.length>0)for(let u of a.addresses)c.uint32(10),Cr.codec().encode(u,c);if(a.protocols!=null&&a.protocols.length>0)for(let u of a.protocols)c.uint32(18),c.string(u);if(a.publicKey!=null&&(c.uint32(34),c.bytes(a.publicKey)),a.peerRecordEnvelope!=null&&(c.uint32(42),c.bytes(a.peerRecordEnvelope)),a.metadata!=null&&a.metadata.size>0)for(let[u,d]of a.metadata.entries())c.uint32(50),e.Peer$metadataEntry.codec().encode({key:u,value:d},c);if(a.tags!=null&&a.tags.size>0)for(let[u,d]of a.tags.entries())c.uint32(58),e.Peer$tagsEntry.codec().encode({key:u,value:d},c);a.updated!=null&&(c.uint32(64),c.uint64Number(a.updated)),l.lengthDelimited!==!1&&c.ldelim()},(a,c,l={})=>{let u={addresses:[],protocols:[],metadata:new Map,tags:new Map},d=c==null?a.len:a.pos+c;for(;a.pos<d;){let f=a.uint32();switch(f>>>3){case 1:{if(l.limits?.addresses!=null&&u.addresses.length===l.limits.addresses)throw new Ct('Decode error - repeated field "addresses" had too many elements');u.addresses.push(Cr.codec().decode(a,a.uint32(),{limits:l.limits?.addresses$}));break}case 2:{if(l.limits?.protocols!=null&&u.protocols.length===l.limits.protocols)throw new Ct('Decode error - repeated field "protocols" had too many elements');u.protocols.push(a.string());break}case 4:{u.publicKey=a.bytes();break}case 5:{u.peerRecordEnvelope=a.bytes();break}case 6:{if(l.limits?.metadata!=null&&u.metadata.size===l.limits.metadata)throw new hr('Decode error - map field "metadata" had too many elements');let h=e.Peer$metadataEntry.codec().decode(a,a.uint32(),{limits:{value:l.limits?.metadata$value}});u.metadata.set(h.key,h.value);break}case 7:{if(l.limits?.tags!=null&&u.tags.size===l.limits.tags)throw new hr('Decode error - map field "tags" had too many elements');let h=e.Peer$tagsEntry.codec().decode(a,a.uint32(),{limits:{value:l.limits?.tags$value}});u.tags.set(h.key,h.value);break}case 8:{u.updated=a.uint64Number();break}default:{a.skipType(f&7);break}}}return u},function*(a,c,l,u={}){let d={addresses:0,protocols:0,metadata:0,tags:0},f=c==null?a.len:a.pos+c;for(;a.pos<f;){let h=a.uint32();switch(h>>>3){case 1:{if(u.limits?.addresses!=null&&d.addresses===u.limits.addresses)throw new Ct('Streaming decode error - repeated field "addresses" had too many elements');for(let p of Cr.codec().stream(a,a.uint32(),`${l}.addresses[]`,{limits:u.limits?.addresses$}))yield{...p,index:d.addresses};d.addresses++;break}case 2:{if(u.limits?.protocols!=null&&d.protocols===u.limits.protocols)throw new Ct('Streaming decode error - repeated field "protocols" had too many elements');yield{field:`${l}.protocols[]`,index:d.protocols,value:a.string()},d.protocols++;break}case 4:{yield{field:`${l}.publicKey`,value:a.bytes()};break}case 5:{yield{field:`${l}.peerRecordEnvelope`,value:a.bytes()};break}case 6:{if(u.limits?.metadata!=null&&d.metadata===u.limits.metadata)throw new Ct('Decode error - map field "metadata" had too many elements');yield*e.Peer$metadataEntry.codec().stream(a,a.uint32(),`${l}.metadata{}`,{limits:{value:u.limits?.metadata$value}}),d.metadata++;break}case 7:{if(u.limits?.tags!=null&&d.tags===u.limits.tags)throw new Ct('Decode error - map field "tags" had too many elements');yield*e.Peer$tagsEntry.codec().stream(a,a.uint32(),`${l}.tags{}`,{limits:{value:u.limits?.tags$value}}),d.tags++;break}case 8:{yield{field:`${l}.updated`,value:a.uint64Number()};break}default:{a.skipType(h&7);break}}}})),n);function o(a){return mt(a,e.codec())}e.encode=o;function s(a,c){return pt(a,e.codec(),c)}e.decode=s;function i(a,c){return yt(a,e.codec(),c)}e.stream=i})(Yt||(Yt={}));var Cr;(function(e){let t;e.codec=()=>(t==null&&(t=bt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.multiaddr!=null&&s.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(s.multiaddr)),s.isCertified!=null&&(i.uint32(16),i.bool(s.isCertified)),s.observed!=null&&(i.uint32(24),i.uint64Number(s.observed)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={multiaddr:rt(0)},l=i==null?s.len:s.pos+i;for(;s.pos<l;){let u=s.uint32();switch(u>>>3){case 1:{c.multiaddr=s.bytes();break}case 2:{c.isCertified=s.bool();break}case 3:{c.observed=s.uint64Number();break}default:{s.skipType(u&7);break}}}return c},function*(s,i,a,c={}){let l=i==null?s.len:s.pos+i;for(;s.pos<l;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.multiaddr`,value:s.bytes()};break}case 2:{yield{field:`${a}.isCertified`,value:s.bool()};break}case 3:{yield{field:`${a}.observed`,value:s.uint64Number()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return mt(s,e.codec())}e.encode=r;function n(s,i){return pt(s,e.codec(),i)}e.decode=n;function o(s,i){return yt(s,e.codec(),i)}e.stream=o})(Cr||(Cr={}));var Tr;(function(e){let t;e.codec=()=>(t==null&&(t=bt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.value!=null&&s.value!==0&&(i.uint32(8),i.uint32(s.value)),s.expiry!=null&&(i.uint32(16),i.uint64(s.expiry)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={value:0},l=i==null?s.len:s.pos+i;for(;s.pos<l;){let u=s.uint32();switch(u>>>3){case 1:{c.value=s.uint32();break}case 2:{c.expiry=s.uint64();break}default:{s.skipType(u&7);break}}}return c},function*(s,i,a,c={}){let l=i==null?s.len:s.pos+i;for(;s.pos<l;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.value`,value:s.uint32()};break}case 2:{yield{field:`${a}.expiry`,value:s.uint64()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return mt(s,e.codec())}e.encode=r;function n(s,i){return pt(s,e.codec(),i)}e.decode=n;function o(s,i){return yt(s,e.codec(),i)}e.stream=o})(Tr||(Tr={}));function id(e,t){if(e.publicKey!=null||t.publicKey==null)return e;let r;e.type==="RSA"&&(r=e.toMultihash());let n=on(t.publicKey,r);return Na(n)}function dc(e,t,r){let n=Yt.decode(t);return $e(e,n,r)}function $e(e,t,r){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:id(e,t),addresses:t.addresses.filter(({observed:s})=>s!=null&&s>Date.now()-r).map(({multiaddr:s,isCertified:i})=>({multiaddr:ge(s),isCertified:i??!1})),metadata:t.metadata,peerRecordEnvelope:t.peerRecordEnvelope??void 0,tags:n}}function hc(e,t){return ad(e.addresses,t.addresses)&&cd(e.protocols,t.protocols)&&ud(e.publicKey,t.publicKey)&&ld(e.peerRecordEnvelope,t.peerRecordEnvelope)&&fd(e.metadata,t.metadata)&&dd(e.tags,t.tags)}function ad(e,t){return mc(e,t,(r,n)=>!(r.isCertified!==n.isCertified||!W(r.multiaddr,n.multiaddr)))}function cd(e,t){return mc(e,t,(r,n)=>r===n)}function ud(e,t){return pc(e,t)}function ld(e,t){return pc(e,t)}function fd(e,t){return yc(e,t,(r,n)=>W(r,n))}function dd(e,t){return yc(e,t,(r,n)=>r.value===n.value&&r.expiry===n.expiry)}function pc(e,t){return e==null&&t==null?!0:e!=null&&t!=null?W(e,t):!1}function mc(e,t,r){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!r(e[n],t[n]))return!1;return!0}function yc(e,t,r){if(e.size!==t.size)return!1;for(let[n,o]of e.entries()){let s=t.get(n);if(s==null||!r(o,s))return!1}return!0}var Xt="/",bc=new TextEncoder().encode(Xt),Kn=bc[0],Pn=class e{_buf;constructor(t,r){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(r==null&&(r=!0),r&&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 e(t.join(Xt))}static random(){return new e(Math.random().toString().substring(2))}static asKey(t){return t instanceof Uint8Array||typeof t=="string"?new e(t):typeof t.uint8Array=="function"?new e(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 r=this.list(),n=t.list();for(let o=0;o<r.length;o++){if(n.length<o+1)return!1;let s=r[o],i=n[o];if(s<i)return!0;if(s>i)return!1}return r.length<n.length}reverse(){return e.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let t=this.namespaces();return t[t.length-1]}list(){return this.toString().split(Xt).slice(1)}type(){return hd(this.baseNamespace())}name(){return pd(this.baseNamespace())}instance(t){return new e(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(Xt)||(t+=Xt),t+=this.type(),new e(t)}parent(){let t=this.list();return t.length===1?new e(Xt):new e(t.slice(0,-1).join(Xt))}child(t){return this.toString()===Xt?t:t.toString()===Xt?this:new e(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 e.withNamespaces([...this.namespaces(),...md(t.map(r=>r.namespaces()))])}};function hd(e){let t=e.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function pd(e){let t=e.split(":");return t[t.length-1]}function md(e){return[].concat(...e)}var qs="/peers/";function Br(e){if(!ve(e)||e.type==null)throw new q("Invalid PeerId");let t=e.toCID().toString();return new Pn(`${qs}${t}`)}async function gc(e,t,r,n,o){let s=new Map;for(let i of r){if(i==null)continue;if(i.multiaddr instanceof Uint8Array&&(i.multiaddr=ge(i.multiaddr)),!pn(i.multiaddr))throw new q("Multiaddr was invalid");if(!await t(e,i.multiaddr,o))continue;let a=i.isCertified??!1,c=i.multiaddr.toString(),l=s.get(c);l!=null?i.isCertified=l.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(l=>l.code===421)?.value;return e.equals(c)&&(a=a.decapsulate(ge(`/p2p/${e}`))),{isCertified:i,multiaddr:a.bytes}})}async function Un(e,t,r,n){if(t==null)throw new q("Invalid PeerData");if(t.publicKey!=null&&e.publicKey!=null&&!t.publicKey.equals(e.publicKey))throw new q("publicKey bytes do not match peer id publicKey bytes");let o=n.existingPeer?.peer;if(o!=null&&!e.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,l=o?.peerRecordEnvelope;if(r==="patch"){if((t.multiaddrs!=null||t.addresses!=null)&&(s=[],t.multiaddrs!=null&&s.push(...t.multiaddrs.map(f=>({isCertified:!1,multiaddr:f}))),t.addresses!=null&&s.push(...t.addresses)),t.protocols!=null&&(i=new Set(t.protocols)),t.metadata!=null){let f=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);a=Nn(f,{validate:xc})}if(t.tags!=null){let f=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags);c=Nn(f,{validate:wc,map:Ec})}t.peerRecordEnvelope!=null&&(l=t.peerRecordEnvelope)}if(r==="merge"){if(t.multiaddrs!=null&&s.push(...t.multiaddrs.map(f=>({isCertified:!1,multiaddr:f}))),t.addresses!=null&&s.push(...t.addresses),t.protocols!=null&&(i=new Set([...i,...t.protocols])),t.metadata!=null){let f=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);for(let[h,p]of f)p==null?a.delete(h):a.set(h,p);a=Nn([...a.entries()],{validate:xc})}if(t.tags!=null){let f=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags),h=new Map(c);for(let[p,E]of f)E==null?h.delete(p):h.set(p,E);c=Nn([...h.entries()],{validate:wc,map:Ec})}t.peerRecordEnvelope!=null&&(l=t.peerRecordEnvelope)}let u;o?.id.publicKey!=null?u=At(o.id.publicKey):t.publicKey!=null?u=At(t.publicKey):e.publicKey!=null&&(u=At(e.publicKey));let d={addresses:await gc(e,n.addressFilter??(async()=>!0),s,n.existingPeer?.peerPB.addresses,n),protocols:[...i.values()].sort((f,h)=>f.localeCompare(h)),metadata:a,tags:c,publicKey:u,peerRecordEnvelope:l};return d.addresses.forEach(f=>{f.observed=n.existingPeer?.peerPB.addresses?.find(h=>W(h.multiaddr,h.multiaddr))?.observed??Date.now()}),e.type!=="RSA"&&delete d.publicKey,d}function Nn(e,t){let r=new Map;for(let[n,o]of e)o!=null&&t.validate(n,o);for(let[n,o]of e.sort(([s],[i])=>s.localeCompare(i)))o!=null&&r.set(n,t.map?.(n,o)??o);return r}function xc(e,t){if(typeof e!="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(e,t){if(typeof e!="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(e,t){let r;t.expiry!=null&&(r=t.expiry),t.ttl!=null&&(r=BigInt(Date.now()+Number(t.ttl)));let n={value:t.value??0};return r!=null&&(n.expiry=r),n}function vc(e){let t=e.toString().split("/")[2],r=et.parse(t,Lt);return sn(r)}function Vs(e,t,r){let n=vc(e);return dc(n,t,r)}function yd(e,t){return{prefix:qs,filters:(e.filters??[]).map(r=>({key:n,value:o})=>r(Vs(n,o,t))),orders:(e.orders??[]).map(r=>(n,o)=>r(Vs(n.key,n.value,t),Vs(o.key,o.value,t)))}}var Mn=class{peerId;datastore;locks;addressFilter;log;maxAddressAge;maxPeerAge;constructor(t,r={}){this.log=t.logger.forComponent("libp2p:peer-store"),this.peerId=t.peerId,this.datastore=t.datastore,this.addressFilter=r.addressFilter,this.locks=Os({name:"libp2p_peer_store_locks",metrics:t.metrics}),this.maxAddressAge=r.maxAddressAge??36e5,this.maxPeerAge=r.maxPeerAge??216e5}getLock(t){let r=this.locks.get(t);return r==null&&(r={refs:0,lock:Ms({name:t.toString(),singleProcess:!0})},this.locks.set(t,r)),r.refs++,r}maybeRemoveLock(t,r){r.refs--,r.refs===0&&(r.lock.finalize(),this.locks.delete(t))}async getReadLock(t,r){let n=this.getLock(t);try{let o=await n.lock.readLock(r);return()=>{o(),this.maybeRemoveLock(t,n)}}catch(o){throw this.maybeRemoveLock(t,n),o}}async getWriteLock(t,r){let n=this.getLock(t);try{let o=await n.lock.writeLock(r);return()=>{o(),this.maybeRemoveLock(t,n)}}catch(o){throw this.maybeRemoveLock(t,n),o}}async has(t,r){try{return await this.load(t,r),!0}catch(n){if(n.name!=="NotFoundError")throw n}return!1}async delete(t,r){this.peerId.equals(t)||await this.datastore.delete(Br(t),r)}async load(t,r){let n=Br(t),o=await this.datastore.get(n,r),s=Yt.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,r),new We;return $e(t,s,this.peerId.equals(t)?1/0:this.maxAddressAge)}async save(t,r,n){let o=await this.#t(t,n),s=await Un(t,r,"patch",{...n,addressFilter:this.addressFilter});return this.#e(t,s,o)}async patch(t,r,n){let o=await this.#t(t,n),s=await Un(t,r,"patch",{...n,addressFilter:this.addressFilter,existingPeer:o});return this.#e(t,s,o)}async merge(t,r,n){let o=await this.#t(t,n),s=await Un(t,r,"merge",{addressFilter:this.addressFilter,existingPeer:o});return this.#e(t,s,o)}async*all(t){for await(let{key:r,value:n}of this.datastore.query(yd(t??{},this.maxAddressAge),t)){let o=vc(r);if(o.equals(this.peerId))continue;let s=Yt.decode(n);if(this.#r(o,s)){await this.datastore.delete(r,t);continue}yield $e(o,s,this.peerId.equals(o)?1/0:this.maxAddressAge)}}async#t(t,r){try{let n=Br(t),o=await this.datastore.get(n,r),s=Yt.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,r),new We;return{peerPB:s,peer:$e(t,s,this.maxAddressAge)}}catch(n){n.name!=="NotFoundError"&&this.log.error("invalid peer data found in peer store - %e",n)}}async#e(t,r,n,o){r.updated=Date.now();let s=Yt.encode(r);return await this.datastore.put(Br(t),s,o),{peer:$e(t,r,this.maxAddressAge),previous:n?.peer,updated:n==null||!hc(r,n.peerPB)}}#r(t,r){if(r.updated==null)return!0;if(this.peerId.equals(t))return!1;let n=r.updated<Date.now()-this.maxPeerAge,o=Date.now()-this.maxAddressAge,s=r.addresses.filter(i=>i.observed!=null&&i.observed>o);return n&&s.length===0}};var Hs=class{store;events;peerId;log;constructor(t,r={}){this.log=t.logger.forComponent("libp2p:peer-store"),this.events=t.events,this.peerId=t.peerId,this.store=new Mn(t,r)}[Symbol.toStringTag]="@libp2p/peer-store";async forEach(t,r){for await(let n of this.store.all(r))t(n)}async all(t){return nc(this.store.all(t))}async delete(t,r){let n=await this.store.getReadLock(t,r);try{await this.store.delete(t,r)}finally{n()}}async has(t,r){let n=await this.store.getReadLock(t,r);try{return await this.store.has(t,r)}finally{this.log.trace("has release read lock"),n?.()}}async get(t,r){let n=await this.store.getReadLock(t,r);try{return await this.store.load(t,r)}finally{n?.()}}async getInfo(t,r){let n=await this.get(t,r);return{id:n.id,multiaddrs:n.addresses.map(({multiaddr:o})=>o)}}async save(t,r,n){let o=await this.store.getWriteLock(t,n);try{let s=await this.store.save(t,r,n);return this.#t(t,s),s.peer}finally{o?.()}}async patch(t,r,n){let o=await this.store.getWriteLock(t,n);try{let s=await this.store.patch(t,r,n);return this.#t(t,s),s.peer}finally{o?.()}}async merge(t,r,n){let o=await this.store.getWriteLock(t,n);try{let s=await this.store.merge(t,r,n);return this.#t(t,s),s.peer}finally{o?.()}}async consumePeerRecord(t,r,n){let o=ve(r)?r:ve(r?.expectedPeer)?r.expectedPeer:void 0,s=ve(r)||r===void 0?n:r,i=await He.openAndCertify(t,xe.DOMAIN,s),a=sn(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=xe.createFromProtobuf(i.payload),l;try{l=await this.get(a,s)}catch(u){if(u.name!=="NotFoundError")throw u}if(l?.peerRecordEnvelope!=null){let u=He.createFromProtobuf(l.peerRecordEnvelope),d=xe.createFromProtobuf(u.payload);if(d.seqNumber>=c.seqNumber)return this.log("sequence number was lower or equal to existing sequence number - stored: %d received: %d",d.seqNumber,c.seqNumber),!1}return await this.patch(c.peerId,{peerRecordEnvelope:t,addresses:c.multiaddrs.map(u=>({isCertified:!0,multiaddr:u}))},s),!0}#t(t,r){r.updated&&(this.peerId.equals(t)?this.events.safeDispatchEvent("self:peer:update",{detail:r}):this.events.safeDispatchEvent("peer:update",{detail:r}))}};function bd(e,t={}){return new Hs(e,t)}return Cc(gd);})();
|
|
2
|
+
"use strict";var Libp2PPeerStore=(()=>{var qn=Object.defineProperty;var Sc=Object.getOwnPropertyDescriptor;var Ac=Object.getOwnPropertyNames;var _c=Object.prototype.hasOwnProperty;var gt=(e,t)=>{for(var r in t)qn(e,r,{get:t[r],enumerable:!0})},Ic=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ac(t))!_c.call(e,o)&&o!==r&&qn(e,o,{get:()=>t[o],enumerable:!(n=Sc(t,o))||n.enumerable});return e};var Cc=e=>Ic(qn({},"__esModule",{value:!0}),e);var gd={};gt(gd,{persistentPeerStore:()=>bd});var q=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Ee=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var We=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var Dr=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 ae=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Or=Symbol.for("@libp2p/peer-id");function ve(e){return!!e?.[Or]}var Se=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){super.addEventListener(t,r,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,r,n){super.removeEventListener(t.toString(),r??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==r),this.#t.set(t,o))}dispatchEvent(t){let r=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),r}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var $n={};gt($n,{base58btc:()=>J,base58flickr:()=>kc});var Sd=new Uint8Array(0);function $s(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Nt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Ws(e){return new TextEncoder().encode(e)}function Zs(e){return new TextDecoder().decode(e)}function Tc(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=e.length,c=e.charAt(0),l=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function d(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var E=0,y=0,m=0,_=p.length;m!==_&&p[m]===0;)m++,E++;for(var w=(_-m)*u+1>>>0,I=new Uint8Array(w);m!==_;){for(var O=p[m],N=0,U=w-1;(O!==0||N<y)&&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");y=N,m++}for(var S=w-y;S!==w&&I[S]===0;)S++;for(var v=c.repeat(E);S<w;++S)v+=e.charAt(I[S]);return v}function f(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var E=0;if(p[E]!==" "){for(var y=0,m=0;p[E]===c;)y++,E++;for(var _=(p.length-E)*l+1>>>0,w=new Uint8Array(_);p[E];){var I=r[p.charCodeAt(E)];if(I===255)return;for(var O=0,N=_-1;(I!==0||O<m)&&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");m=O,E++}if(p[E]!==" "){for(var U=_-m;U!==_&&w[U]===0;)U++;for(var S=new Uint8Array(y+(_-U)),v=y;U!==_;)S[v++]=w[U++];return S}}}function h(p){var E=f(p);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:d,decodeUnsafe:f,decode:h}}var Bc=Tc,Rc=Bc,Ys=Rc;var Vn=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Hn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Xs(this,t)}},zn=class{decoders;constructor(t){this.decoders=t}or(t){return Xs(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Xs(e,t){return new zn({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Fn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Vn(t,r,n),this.decoder=new Hn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ae({name:e,prefix:t,encode:r,decode:n}){return new Fn(e,t,r,n)}function jt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Ys(r,e);return Ae({prefix:t,name:e,encode:n,decode:s=>Nt(o(s))})}function Dc(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let l=0;l<o;++l){let u=t[e[l]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Lc(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],i+=8;i>r;)i-=r,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Oc(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function Q({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Oc(n);return Ae({prefix:t,name:e,encode(s){return Lc(s,n,r)},decode(s){return Dc(s,o,r,e)}})}var J=jt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),kc=jt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Wn={};gt(Wn,{base32:()=>Lt,base32hex:()=>Uc,base32hexpad:()=>qc,base32hexpadupper:()=>Vc,base32hexupper:()=>Mc,base32pad:()=>Pc,base32padupper:()=>Nc,base32upper:()=>Kc,base32z:()=>Hc});var Lt=Q({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Kc=Q({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Pc=Q({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Nc=Q({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Uc=Q({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Mc=Q({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),qc=Q({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Vc=Q({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Hc=Q({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Zn={};gt(Zn,{base36:()=>Ze,base36upper:()=>zc});var Ze=jt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),zc=jt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Fc=Js,js=128,$c=127,Wc=~$c,Zc=Math.pow(2,31);function Js(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Zc;)t[r++]=e&255|js,e/=128;for(;e&Wc;)t[r++]=e&255|js,e>>>=7;return t[r]=e|0,Js.bytes=r-n+1,t}var Gc=Gn,Yc=128,Qs=127;function Gn(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw Gn.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Qs)<<o:(i&Qs)*Math.pow(2,o),o+=7}while(i>=Yc);return Gn.bytes=s-n,r}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(e){return e<Xc?1:e<jc?2:e<Qc?3:e<Jc?4:e<tu?5:e<eu?6:e<ru?7:e<nu?8:e<ou?9:10},iu={encode:Fc,decode:Gc,encodingLength:su},au=iu,Ge=au;function Ye(e,t=0){return[Ge.decode(e,t),Ge.decode.bytes]}function _e(e,t,r=0){return Ge.encode(e,t,r),t}function Ie(e){return Ge.encodingLength(e)}function Ot(e,t){let r=t.byteLength,n=Ie(e),o=n+Ie(r),s=new Uint8Array(o+r);return _e(e,s,0),_e(r,s,n),s.set(t,o),new Ce(e,r,t,s)}function Te(e){let t=Nt(e),[r,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 Ce(r,o,i,t)}function ti(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&$s(e.bytes,r.bytes)}}var Ce=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function ei(e,t){let{bytes:r,version:n}=e;return n===0?uu(r,Yn(e),t??J.encoder):lu(r,Yn(e),t??Lt.encoder)}var ri=new WeakMap;function Yn(e){let t=ri.get(e);if(t==null){let r=new Map;return ri.set(e,r),r}return t}var et=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==Xe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==fu)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=Ot(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&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 r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??ni(n,o,s.bytes))}else if(r[du]===!0){let{version:n,multihash:o,code:s}=r,i=Te(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==Xe)throw new Error(`Version 0 CID must use dag-pb (code: ${Xe}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=ni(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Xe,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Nt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Ce(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[d,f]=Ye(t.subarray(r));return r+=f,d},o=n(),s=Xe;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),l=r+c,u=l-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:l}}static parse(t,r){let[n,o]=cu(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Yn(s).set(n,t),s}};function cu(e,t){switch(e[0]){case"Q":{let r=t??J;return[J.prefix,r.decode(`${J.prefix}${e}`)]}case J.prefix:{let r=t??J;return[J.prefix,r.decode(e)]}case Lt.prefix:{let r=t??Lt;return[Lt.prefix,r.decode(e)]}case Ze.prefix:{let r=t??Ze;return[Ze.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function uu(e,t,r){let{prefix:n}=r;if(n!==J.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function lu(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var Xe=112,fu=18;function ni(e,t,r){let n=Ie(e),o=n+Ie(t),s=new Uint8Array(o+r.byteLength);return _e(e,s,0),_e(t,s,n),s.set(r,o),s}var du=Symbol.for("@ipld/js-cid/CID");var Xn={};gt(Xn,{identity:()=>Tt});var oi=0,hu="identity",si=Nt;function pu(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Ot(oi,si(e))}var Tt={code:oi,name:hu,encode:si,digest:pu};function W(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function rt(e=0){return new Uint8Array(e)}function xt(e=0){return new Uint8Array(e)}function Ut(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=xt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var ai=Symbol.for("@achingbrain/uint8arraylist");function ii(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function Kr(e){return!!e?.[ai]}var dt=class e{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 r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Kr(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Kr(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=ii(this.bufs,t);return r.buf[r.index]}set(t,r){let n=ii(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(Kr(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return Ut(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Ut(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let l=t>=a&&t<c,u=r>a&&r<=c;if(l&&u){if(t===a&&r===c){n.push(i);break}let d=t-a;n.push(i.subarray(d,d+(r-t)));break}if(l){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Kr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let d=0;d<s;d++)i[d]=-1;for(let d=0;d<o;d++)i[n[d]]=d;let a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let d=r;d<=c;d+=u){u=0;for(let f=l;f>=0;f--){let h=this.get(d+f);if(n[f]!==h){u=Math.max(1,f-a[h]);break}}if(u===0)return d}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=xt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=rt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=xt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=rt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!W(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var jn={};gt(jn,{base10:()=>mu});var mu=jt({prefix:"9",name:"base10",alphabet:"0123456789"});var Qn={};gt(Qn,{base16:()=>yu,base16upper:()=>bu});var yu=Q({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),bu=Q({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Jn={};gt(Jn,{base2:()=>gu});var gu=Q({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var to={};gt(to,{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((e,t,r)=>(e[r]=t,e),[]),wu=ci.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Eu(e){return e.reduce((t,r)=>(t+=xu[r],t),"")}function vu(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=wu[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Su=Ae({prefix:"\u{1F680}",name:"base256emoji",encode:Eu,decode:vu});var ro={};gt(ro,{base64:()=>Au,base64pad:()=>_u,base64url:()=>eo,base64urlpad:()=>Iu});var Au=Q({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),_u=Q({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),eo=Q({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Iu=Q({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var no={};gt(no,{base8:()=>Cu});var Cu=Q({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var oo={};gt(oo,{identity:()=>Tu});var Tu=Ae({prefix:"\0",name:"identity",encode:e=>Zs(e),decode:e=>Ws(e)});var ih=new TextEncoder,ah=new TextDecoder;var ao={};gt(ao,{sha256:()=>je,sha512:()=>Lu});var Du=20;function io({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new so(e,t,r,n,o)}var so=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Du,this.maxDigestLength=s}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?ui(n,this.code,r?.truncate):n.then(o=>ui(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function ui(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Ot(t,e)}function fi(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var je=io({name:"sha2-256",code:18,encode:fi("SHA-256")}),Lu=io({name:"sha2-512",code:19,encode:fi("SHA-512")});var Qe={...oo,...Jn,...no,...jn,...Qn,...Wn,...Zn,...$n,...ro,...to},xh={...ao,...Xn};function hi(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var di=hi("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),co=hi("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=xt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Ou={utf8:di,"utf-8":di,hex:Qe.base16,latin1:co,ascii:co,binary:co,...Qe},Pr=Ou;function z(e,t="utf8"){let r=Pr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function V(e,t="utf8"){let r=Pr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var ku=parseInt("11111",2),uo=parseInt("10000000",2),Ku=parseInt("01111111",2),pi={0:Je,1:Je,2:Pu,3:Mu,4:qu,5:Uu,6:Nu,16:Je,22:Je,48:Je};function Mt(e,t={offset:0}){let r=e[t.offset]&ku;if(t.offset++,pi[r]!=null)return pi[r](e,t);throw new Error("No decoder for tag "+r)}function tr(e,t){let r=0;if((e[t.offset]&uo)===uo){let n=e[t.offset]&Ku,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function Je(e,t){tr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Mt(e,t);if(n===null)break;r.push(n)}return r}function Pu(e,t){let r=tr(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function Nu(e,t){let r=tr(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let l=e[t.offset];if(t.offset++,c.push(l&127),l<128){c.reverse();let u=0;for(let d=0;d<c.length;d++)u+=c[d]<<d*7;a+=`.${u}`,c=[]}}return a}function Uu(e,t){return t.offset++,null}function Mu(e,t){let r=tr(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function qu(e,t){let r=tr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Vu(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new dt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function lo(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Vu(e.byteLength);return new dt(Uint8Array.from([t.byteLength|uo]),t)}function wt(e){let t=new dt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new dt(Uint8Array.from([2]),lo(t),t)}function Nr(e){let t=Uint8Array.from([0]),r=new dt(t,e);return new dt(Uint8Array.from([3]),lo(r),r)}function Jt(e,t=48){let r=new dt;for(let n of e)r.append(n);return new dt(Uint8Array.from([t]),lo(r),r)}async function mi(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),s}var 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]),$u={ext:!0,kty:"EC",crv:"P-256"},Wu={ext:!0,kty:"EC",crv:"P-384"},Zu={ext:!0,kty:"EC",crv:"P-521"},fo=32,ho=48,po=66;function mo(e){let t=Mt(e);return yi(t)}function yi(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===fo*2+1)return n=V(t.subarray(r,r+fo),"base64url"),o=V(t.subarray(r+fo),"base64url"),new Be({...$u,key_ops:["verify"],x:n,y:o});if(t.byteLength===ho*2+1)return n=V(t.subarray(r,r+ho),"base64url"),o=V(t.subarray(r+ho),"base64url"),new Be({...Wu,key_ops:["verify"],x:n,y:o});if(t.byteLength===po*2+1)return n=V(t.subarray(r,r+po),"base64url"),o=V(t.subarray(r+po),"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(e){return Jt([wt(Uint8Array.from([1])),Jt([Gu(e.crv)],160),Jt([Nr(new dt(Uint8Array.from([4]),z(e.x??"","base64url"),z(e.y??"","base64url")))],161)]).subarray()}function Gu(e){if(e==="P-256")return Hu;if(e==="P-384")return zu;if(e==="P-521")return Fu;throw new q(`Invalid curve ${e}`)}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 Tt.digest(At(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}async verify(t,r,n){return mi(this.jwk,r,t,n)}};function ce(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function kt(e,t=""){if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new Error(`${r}expected integer >= 0, got ${e}`)}}function P(e,t,r=""){let n=ce(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return e}function Ur(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash must wrapped by utils.createHasher");kt(e.outputLen),kt(e.blockLen)}function Re(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function xi(e,t){P(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function Vt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Mr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Bt(e,t){return e<<32-t|e>>>t}var wi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Yu=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Ht(e){if(P(e),wi)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Yu[e[r]];return t}var qt={_0:48,_9:57,A:65,F:70,a:97,f:102};function gi(e){if(e>=qt._0&&e<=qt._9)return e-qt._0;if(e>=qt.A&&e<=qt.F)return e-(qt.A-10);if(e>=qt.a&&e<=qt.f)return e-(qt.a-10)}function zt(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(wi)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=gi(e.charCodeAt(s)),a=gi(e.charCodeAt(s+1));if(i===void 0||a===void 0){let c=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Et(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];P(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}function yo(e,t={}){let r=(o,s)=>e(s).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function De(e=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(e))}var bo=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function Ei(e,t,r){return e&t^~e&r}function vi(e,t,r){return e&t^e&r^t&r}var er=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,o){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Mr(this.buffer)}update(t){Re(this),P(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Mr(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(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Re(this),xi(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Vt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let d=i;d<o;d++)r[d]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=Mr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let l=c/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<l;d++)a.setUint32(4*d,u[d],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Ft=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 qr=BigInt(4294967295),Si=BigInt(32);function Xu(e,t=!1){return t?{h:Number(e&qr),l:Number(e>>Si&qr)}:{h:Number(e>>Si&qr)|0,l:Number(e&qr)|0}}function Ai(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=Xu(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var go=(e,t,r)=>e>>>r,xo=(e,t,r)=>e<<32-r|t>>>r,ue=(e,t,r)=>e>>>r|t<<32-r,le=(e,t,r)=>e<<32-r|t>>>r,rr=(e,t,r)=>e<<64-r|t>>>r-32,nr=(e,t,r)=>e>>>r-32|t<<64-r;function Kt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var _i=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Ii=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Ci=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Ti=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Bi=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Ri=(e,t,r,n,o,s)=>t+r+n+o+s+(e/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]),te=new Uint32Array(64),wo=class extends er{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,r,n,o,s,i,a,c]}set(t,r,n,o,s,i,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,r){for(let d=0;d<16;d++,r+=4)te[d]=t.getUint32(r,!1);for(let d=16;d<64;d++){let f=te[d-15],h=te[d-2],p=Bt(f,7)^Bt(f,18)^f>>>3,E=Bt(h,17)^Bt(h,19)^h>>>10;te[d]=E+te[d-7]+p+te[d-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:l,H:u}=this;for(let d=0;d<64;d++){let f=Bt(a,6)^Bt(a,11)^Bt(a,25),h=u+f+Ei(a,c,l)+Qu[d]+te[d]|0,E=(Bt(n,2)^Bt(n,13)^Bt(n,22))+vi(n,o,s)|0;u=l,l=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+E|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,c,l,u)}roundClean(){Vt(te)}destroy(){this.set(0,0,0,0,0,0,0,0),Vt(this.buffer)}},Eo=class extends wo{A=Ft[0]|0;B=Ft[1]|0;C=Ft[2]|0;D=Ft[3]|0;E=Ft[4]|0;F=Ft[5]|0;G=Ft[6]|0;H=Ft[7]|0;constructor(){super(32)}};var Di=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(e=>BigInt(e))),Ju=Di[0],tl=Di[1],ee=new Uint32Array(80),re=new Uint32Array(80),vo=class extends er{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:l,El:u,Fh:d,Fl:f,Gh:h,Gl:p,Hh:E,Hl:y}=this;return[t,r,n,o,s,i,a,c,l,u,d,f,h,p,E,y]}set(t,r,n,o,s,i,a,c,l,u,d,f,h,p,E,y){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=l|0,this.El=u|0,this.Fh=d|0,this.Fl=f|0,this.Gh=h|0,this.Gl=p|0,this.Hh=E|0,this.Hl=y|0}process(t,r){for(let w=0;w<16;w++,r+=4)ee[w]=t.getUint32(r),re[w]=t.getUint32(r+=4);for(let w=16;w<80;w++){let I=ee[w-15]|0,O=re[w-15]|0,N=ue(I,O,1)^ue(I,O,8)^go(I,O,7),U=le(I,O,1)^le(I,O,8)^xo(I,O,7),S=ee[w-2]|0,v=re[w-2]|0,k=ue(S,v,19)^rr(S,v,61)^go(S,v,6),M=le(S,v,19)^nr(S,v,61)^xo(S,v,6),R=Ci(U,M,re[w-7],re[w-16]),g=Ti(R,N,k,ee[w-7],ee[w-16]);ee[w]=g|0,re[w]=R|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:l,Dl:u,Eh:d,El:f,Fh:h,Fl:p,Gh:E,Gl:y,Hh:m,Hl:_}=this;for(let w=0;w<80;w++){let I=ue(d,f,14)^ue(d,f,18)^rr(d,f,41),O=le(d,f,14)^le(d,f,18)^nr(d,f,41),N=d&h^~d&E,U=f&p^~f&y,S=Bi(_,O,U,tl[w],re[w]),v=Ri(S,m,I,N,Ju[w],ee[w]),k=S|0,M=ue(n,o,28)^rr(n,o,34)^rr(n,o,39),R=le(n,o,28)^nr(n,o,34)^nr(n,o,39),g=n&s^n&a^s&a,x=o&i^o&c^i&c;m=E|0,_=y|0,E=h|0,y=p|0,h=d|0,p=f|0,{h:d,l:f}=Kt(l|0,u|0,v|0,k|0),l=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let b=_i(k,R,x);n=Ii(b,v,M,g),o=b|0}({h:n,l:o}=Kt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Kt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Kt(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:u}=Kt(this.Dh|0,this.Dl|0,l|0,u|0),{h:d,l:f}=Kt(this.Eh|0,this.El|0,d|0,f|0),{h,l:p}=Kt(this.Fh|0,this.Fl|0,h|0,p|0),{h:E,l:y}=Kt(this.Gh|0,this.Gl|0,E|0,y|0),{h:m,l:_}=Kt(this.Hh|0,this.Hl|0,m|0,_|0),this.set(n,o,s,i,a,c,l,u,d,f,h,p,E,y,m,_)}roundClean(){Vt(ee,re)}destroy(){Vt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},So=class extends vo{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 Le=yo(()=>new Eo,bo(1));var Li=yo(()=>new So,bo(3));var _o=BigInt(0),Ao=BigInt(1);function $t(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function Oi(e){if(typeof e=="bigint"){if(!Vr(e))throw new Error("positive bigint expected, got "+e)}else kt(e);return e}function or(e){let t=Oi(e).toString(16);return t.length&1?"0"+t:t}function ki(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?_o:BigInt("0x"+e)}function Oe(e){return ki(Ht(e))}function fe(e){return ki(Ht(zr(P(e)).reverse()))}function Hr(e,t){kt(t),e=Oi(e);let r=zt(e.toString(16).padStart(t*2,"0"));if(r.length!==t)throw new Error("number too large");return r}function Io(e,t){return Hr(e,t).reverse()}function zr(e){return Uint8Array.from(e)}var Vr=e=>typeof e=="bigint"&&_o<=e;function el(e,t,r){return Vr(e)&&Vr(t)&&Vr(r)&&t<=e&&e<r}function sr(e,t,r,n){if(!el(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Co(e){let t;for(t=0;e>_o;e>>=Ao,t+=1);return t}var ir=e=>(Ao<<BigInt(e))-Ao;function Ki(e,t,r){if(kt(e,"hashLen"),kt(t,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");let n=y=>new Uint8Array(y),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(e),l=n(e),u=0,d=()=>{c.fill(1),l.fill(0),u=0},f=(...y)=>r(l,Et(c,...y)),h=(y=o)=>{l=f(s,y),c=f(),y.length!==0&&(l=f(i,y),c=f())},p=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let y=0,m=[];for(;y<t;){c=f();let _=c.slice();m.push(_),y+=c.length}return Et(...m)};return(y,m)=>{d(),h(y);let _;for(;!(_=m(p()));)h();return d(),_}}function ne(e,t={},r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(s,i,a){let c=e[s];if(a&&c===void 0)return;let l=typeof c;if(l!==i||c===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${l}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(t,!1),o(r,!0)}function ke(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var ht=BigInt(0),nt=BigInt(1),de=BigInt(2),Ui=BigInt(3),Mi=BigInt(4),qi=BigInt(5),rl=BigInt(7),Vi=BigInt(8),nl=BigInt(9),Hi=BigInt(16);function tt(e,t){let r=e%t;return r>=ht?r:t+r}function Z(e,t,r){let n=e;for(;t-- >ht;)n*=n,n%=r;return n}function Pi(e,t){if(e===ht)throw new Error("invert: expected non-zero number");if(t<=ht)throw new Error("invert: expected positive modulus, got "+t);let r=tt(e,t),n=t,o=ht,s=nt,i=nt,a=ht;for(;r!==ht;){let l=n/r,u=n%r,d=o-i*l,f=s-a*l;n=r,r=u,o=i,s=a,i=d,a=f}if(n!==nt)throw new Error("invert: does not exist");return tt(o,t)}function Bo(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function zi(e,t){let r=(e.ORDER+nt)/Mi,n=e.pow(t,r);return Bo(e,n,t),n}function ol(e,t){let r=(e.ORDER-qi)/Vi,n=e.mul(t,de),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,de),o),a=e.mul(s,e.sub(i,e.ONE));return Bo(e,a,t),a}function sl(e){let t=Ke(e),r=Fi(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+rl)/Hi;return(a,c)=>{let l=a.pow(c,i),u=a.mul(l,n),d=a.mul(l,o),f=a.mul(l,s),h=a.eql(a.sqr(u),c),p=a.eql(a.sqr(d),c);l=a.cmov(l,u,h),u=a.cmov(f,d,p);let E=a.eql(a.sqr(u),c),y=a.cmov(l,u,E);return Bo(a,y,c),y}}function Fi(e){if(e<Ui)throw new Error("sqrt is not defined for small field");let t=e-nt,r=0;for(;t%de===ht;)t/=de,r++;let n=de,o=Ke(e);for(;Ni(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return zi;let s=o.pow(n,t),i=(t+nt)/de;return function(c,l){if(c.is0(l))return l;if(Ni(c,l)!==1)throw new Error("Cannot find square root");let u=r,d=c.mul(c.ONE,s),f=c.pow(l,t),h=c.pow(l,i);for(;!c.eql(f,c.ONE);){if(c.is0(f))return c.ZERO;let p=1,E=c.sqr(f);for(;!c.eql(E,c.ONE);)if(p++,E=c.sqr(E),p===u)throw new Error("Cannot find square root");let y=nt<<BigInt(u-p-1),m=c.pow(d,y);u=p,d=c.sqr(m),f=c.mul(f,d),h=c.mul(h,m)}return h}}function il(e){return e%Mi===Ui?zi:e%Vi===qi?ol:e%Hi===nl?sl(e):Fi(e)}var $i=(e,t)=>(tt(e,t)&nt)===nt,al=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ro(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=al.reduce((n,o)=>(n[o]="function",n),t);return ne(e,r),e}function cl(e,t,r){if(r<ht)throw new Error("invalid exponent, negatives unsupported");if(r===ht)return e.ONE;if(r===nt)return t;let n=e.ONE,o=t;for(;r>ht;)r&nt&&(n=e.mul(n,o)),o=e.sqr(o),r>>=nt;return n}function ar(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,a,c)=>e.is0(a)?i:(n[c]=i,e.mul(i,a)),e.ONE),s=e.inv(o);return t.reduceRight((i,a,c)=>e.is0(a)?i:(n[c]=e.mul(i,n[c]),e.mul(i,a)),s),n}function Ni(e,t){let r=(e.ORDER-nt)/de,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function ul(e,t){t!==void 0&&kt(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}var To=class{ORDER;BITS;BYTES;isLE;ZERO=ht;ONE=nt;_lengths;_sqrt;_mod;constructor(t,r={}){if(t<=ht)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&(this.sqrt=r.sqrt),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=r.allowedLengths?.slice()),typeof r.modFromBytes=="boolean"&&(this._mod=r.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 tt(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 tt(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return tt(t*t,this.ORDER)}add(t,r){return tt(t+r,this.ORDER)}sub(t,r){return tt(t-r,this.ORDER)}mul(t,r){return tt(t*r,this.ORDER)}pow(t,r){return cl(this,t,r)}div(t,r){return tt(t*Pi(r,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,r){return t+r}subN(t,r){return t-r}mulN(t,r){return t*r}inv(t){return Pi(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=il(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?Io(t,this.BYTES):Hr(t,this.BYTES)}fromBytes(t,r=!1){P(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 l=new Uint8Array(o);l.set(t,s?0:l.length-t.length),t=l}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=s?fe(t):Oe(t);if(a&&(c=tt(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return ar(this,t)}cmov(t,r,n){return n?r:t}};function Ke(e,t={}){return new To(e,t)}function Wi(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function Do(e){let t=Wi(e);return t+Math.ceil(t/2)}function Lo(e,t,r=!1){P(e);let n=e.length,o=Wi(t),s=Do(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?fe(e):Oe(e),a=tt(i,t-nt)+nt;return r?Io(a,o):Hr(a,o)}var Pe=BigInt(0),he=BigInt(1);function cr(e,t){let r=t.negate();return e?r:t}function pe(e,t){let r=ar(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Xi(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Oo(e,t){Xi(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=ir(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Zi(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(e&o),c=e>>i;a>n&&(a-=s,c+=he);let l=t*n,u=l+Math.abs(a)-1,d=a===0,f=a<0,h=t%2!==0;return{nextN:c,offset:u,isZero:d,isNeg:f,isNegF:h,offsetF:l}}var ko=new WeakMap,ji=new WeakMap;function Ko(e){return ji.get(e)||1}function Gi(e){if(e!==Pe)throw new Error("invalid wNAF")}var Ne=class{BASE;ZERO;Fn;bits;constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>Pe;)r&he&&(n=n.add(o)),o=o.double(),r>>=he;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=Oo(r,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let l=1;l<o;l++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Oo(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:l,isZero:u,isNeg:d,isNegF:f,offsetF:h}=Zi(n,a,i);n=c,u?s=s.add(cr(f,r[h])):o=o.add(cr(d,r[l]))}return Gi(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=Oo(t,this.bits);for(let i=0;i<s.windows&&n!==Pe;i++){let{nextN:a,offset:c,isZero:l,isNeg:u}=Zi(n,i,s);if(n=a,!l){let d=r[c];o=o.add(u?d.negate():d)}}return Gi(n),o}getPrecomputes(t,r,n){let o=ko.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),ko.set(r,o))),o}cached(t,r,n){let o=Ko(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=Ko(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){Xi(r,this.bits),ji.set(t,r),ko.delete(t)}hasCache(t){return Ko(t)!==1}};function Qi(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Pe||n>Pe;)r&he&&(s=s.add(o)),n&he&&(i=i.add(o)),o=o.double(),r>>=he,n>>=he;return{p1:s,p2:i}}function Yi(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Ro(t),t}else return Ke(e,{isLE:r})}function Fr(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let c of["p","n","h"]){let l=t[c];if(!(typeof l=="bigint"&&l>Pe))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Yi(t.p,r.Fp,n),s=Yi(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let 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 $r(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var oe=BigInt(0),ot=BigInt(1),Po=BigInt(2),ll=BigInt(8);function fl(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),a=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,a)}function Ji(e,t={}){let r=Fr("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;ne(t,{},{uvRatio:"function"});let a=Po<<BigInt(o.BYTES*8)-ot,c=y=>n.create(y),l=t.uvRatio||((y,m)=>{try{return{isValid:!0,value:n.sqrt(n.div(y,m))}}catch{return{isValid:!1,value:oe}}});if(!fl(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function u(y,m,_=!1){let w=_?ot:oe;return sr("coordinate "+y,m,w,a),m}function d(y){if(!(y instanceof p))throw new Error("EdwardsPoint expected")}let f=ke((y,m)=>{let{X:_,Y:w,Z:I}=y,O=y.is0();m==null&&(m=O?ll:n.inv(I));let N=c(_*m),U=c(w*m),S=n.mul(I,m);if(O)return{x:oe,y:ot};if(S!==ot)throw new Error("invZ was invalid");return{x:N,y:U}}),h=ke(y=>{let{a:m,d:_}=s;if(y.is0())throw new Error("bad point: ZERO");let{X:w,Y:I,Z:O,T:N}=y,U=c(w*w),S=c(I*I),v=c(O*O),k=c(v*v),M=c(U*m),R=c(v*c(M+S)),g=c(k+c(_*c(U*S)));if(R!==g)throw new Error("bad point: equation left != right (1)");let x=c(w*I),b=c(O*N);if(x!==b)throw new Error("bad point: equation left != right (2)");return!0});class p{static BASE=new p(s.Gx,s.Gy,ot,c(s.Gx*s.Gy));static ZERO=new p(oe,ot,ot,oe);static Fp=n;static Fn=o;X;Y;Z;T;constructor(m,_,w,I){this.X=u("x",m),this.Y=u("y",_),this.Z=u("z",w,!0),this.T=u("t",I),Object.freeze(this)}static CURVE(){return s}static fromAffine(m){if(m instanceof p)throw new Error("extended point not allowed");let{x:_,y:w}=m||{};return u("x",_),u("y",w),new p(_,w,ot,c(_*w))}static fromBytes(m,_=!1){let w=n.BYTES,{a:I,d:O}=s;m=zr(P(m,w,"point")),$t(_,"zip215");let N=zr(m),U=m[w-1];N[w-1]=U&-129;let S=fe(N),v=_?a:n.ORDER;sr("point.y",S,oe,v);let k=c(S*S),M=c(k-ot),R=c(O*k-I),{isValid:g,value:x}=l(M,R);if(!g)throw new Error("bad point: invalid y coordinate");let b=(x&ot)===ot,A=(U&128)!==0;if(!_&&x===oe&&A)throw new Error("bad point: x=0 and x_0=1");return A!==b&&(x=c(-x)),p.fromAffine({x,y:S})}static fromHex(m,_=!1){return p.fromBytes(zt(m),_)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,_=!0){return E.createCache(this,m),_||this.multiply(Po),this}assertValidity(){h(this)}equals(m){d(m);let{X:_,Y:w,Z:I}=this,{X:O,Y:N,Z:U}=m,S=c(_*U),v=c(O*I),k=c(w*U),M=c(N*I);return S===v&&k===M}is0(){return this.equals(p.ZERO)}negate(){return new p(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:m}=s,{X:_,Y:w,Z:I}=this,O=c(_*_),N=c(w*w),U=c(Po*c(I*I)),S=c(m*O),v=_+w,k=c(c(v*v)-O-N),M=S+N,R=M-U,g=S-N,x=c(k*R),b=c(M*g),A=c(k*g),C=c(R*M);return new p(x,b,C,A)}add(m){d(m);let{a:_,d:w}=s,{X:I,Y:O,Z:N,T:U}=this,{X:S,Y:v,Z:k,T:M}=m,R=c(I*S),g=c(O*v),x=c(U*w*M),b=c(N*k),A=c((I+O)*(S+v)-R-g),C=b-x,B=b+x,D=c(g-_*R),T=c(A*C),L=c(B*D),K=c(A*D),Y=c(C*B);return new p(T,L,Y,K)}subtract(m){return this.add(m.negate())}multiply(m){if(!o.isValidNot0(m))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:_,f:w}=E.cached(this,m,I=>pe(p,I));return pe(p,[_,w])[0]}multiplyUnsafe(m,_=p.ZERO){if(!o.isValid(m))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return m===oe?p.ZERO:this.is0()||m===ot?this:E.unsafe(this,m,w=>pe(p,w),_)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return E.unsafe(this,s.n).is0()}toAffine(m){return f(this,m)}clearCofactor(){return i===ot?this:this.multiplyUnsafe(i)}toBytes(){let{x:m,y:_}=this.toAffine(),w=n.toBytes(_);return w[w.length-1]|=m&ot?128:0,w}toHex(){return Ht(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let E=new Ne(p,o.BITS);return p.BASE.precompute(8),p}function ta(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');ne(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=e,a=r.randomBytes||De,c=r.adjustScalarBytes||(S=>S),l=r.domain||((S,v,k)=>{if($t(k,"phflag"),v.length||k)throw new Error("Contexts/pre-hash are not supported");return S});function u(S){return i.create(fe(S))}function d(S){let v=w.secretKey;P(S,w.secretKey,"secretKey");let k=P(t(S),2*v,"hashedSecretKey"),M=c(k.slice(0,v)),R=k.slice(v,2*v),g=u(M);return{head:M,prefix:R,scalar:g}}function f(S){let{head:v,prefix:k,scalar:M}=d(S),R=o.multiply(M),g=R.toBytes();return{head:v,prefix:k,scalar:M,point:R,pointBytes:g}}function h(S){return f(S).pointBytes}function p(S=Uint8Array.of(),...v){let k=Et(...v);return u(t(l(k,P(S,void 0,"context"),!!n)))}function E(S,v,k={}){S=P(S,void 0,"message"),n&&(S=n(S));let{prefix:M,scalar:R,pointBytes:g}=f(v),x=p(k.context,M,S),b=o.multiply(x).toBytes(),A=p(k.context,b,g,S),C=i.create(x+A*R);if(!i.isValid(C))throw new Error("sign failed: invalid s");let B=Et(b,i.toBytes(C));return P(B,w.signature,"result")}let y={zip215:!0};function m(S,v,k,M=y){let{context:R,zip215:g}=M,x=w.signature;S=P(S,x,"signature"),v=P(v,void 0,"message"),k=P(k,w.publicKey,"publicKey"),g!==void 0&&$t(g,"zip215"),n&&(v=n(v));let b=x/2,A=S.subarray(0,b),C=fe(S.subarray(b,x)),B,D,T;try{B=e.fromBytes(k,g),D=e.fromBytes(A,g),T=o.multiplyUnsafe(C)}catch{return!1}if(!g&&B.isSmallOrder())return!1;let L=p(R,D.toBytes(),B.toBytes(),v);return D.add(B.multiplyUnsafe(L)).subtract(T).clearCofactor().is0()}let _=s.BYTES,w={secretKey:_,publicKey:_,signature:2*_,seed:_};function I(S=a(w.seed)){return P(S,w.seed,"seed")}function O(S){return ce(S)&&S.length===i.BYTES}function N(S,v){try{return!!e.fromBytes(S,v)}catch{return!1}}let U={getExtendedPublicKey:f,randomSecretKey:I,isValidSecretKey:O,isValidPublicKey:N,toMontgomery(S){let{y:v}=e.fromBytes(S),k=w.publicKey,M=k===32;if(!M&&k!==57)throw new Error("only defined for 25519 and 448");let R=M?s.div(ot+v,ot-v):s.div(v-ot,v+ot);return s.toBytes(R)},toMontgomerySecret(S){let v=w.secretKey;P(S,v);let k=t(S.subarray(0,v));return c(k).subarray(0,v)}};return Object.freeze({keygen:$r(I,h),getPublicKey:h,sign:E,verify:m,utils:U,Point:e,lengths:w})}var dl=BigInt(1),ea=BigInt(2);var hl=BigInt(5),pl=BigInt(8),No=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),ml={p:No,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:pl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function yl(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=No,a=e*e%s*e%s,c=Z(a,ea,s)*a%s,l=Z(c,dl,s)*e%s,u=Z(l,hl,s)*l%s,d=Z(u,t,s)*u%s,f=Z(d,r,s)*d%s,h=Z(f,n,s)*f%s,p=Z(h,o,s)*h%s,E=Z(p,o,s)*h%s,y=Z(E,t,s)*u%s;return{pow_p_5_8:Z(y,ea,s)*e%s,b2:a}}function bl(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var ra=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function gl(e,t){let r=No,n=tt(t*t*t,r),o=tt(n*n*t,r),s=yl(e*o).pow_p_5_8,i=tt(e*n*s,r),a=tt(t*i*i,r),c=i,l=tt(i*ra,r),u=a===e,d=a===tt(-e,r),f=a===tt(-e*ra,r);return u&&(i=c),(d||f)&&(i=l),$i(i,r)&&(i=tt(-i,r)),{isValid:u||d,value:i}}var xl=Ji(ml,{uvRatio:gl});function wl(e){return ta(xl,Li,Object.assign({adjustScalarBytes:bl},e))}var na=wl({});var ur=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Wr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var oa={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Wr("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 _t=oa;var Zr=32;var Uo,El=(async()=>{try{return await _t.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function vl(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await _t.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await _t.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Sl(e,t,r){return na.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function sa(e,t,r){return Uo==null&&(Uo=await El),Uo?vl(e,t,r):Sl(e,t,r)}function Gr(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Yr=class{type="Ed25519";raw;constructor(t){this.raw=Mo(t,Zr)}toMultihash(){return Tt.digest(At(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=sa(this.raw,r,t);return Gr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function qo(e){return e=Mo(e,Zr),new Yr(e)}function Mo(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new q(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var _l=Math.pow(2,7),Il=Math.pow(2,14),Cl=Math.pow(2,21),Vo=Math.pow(2,28),Ho=Math.pow(2,35),zo=Math.pow(2,42),Fo=Math.pow(2,49),F=128,lt=127;function It(e){if(e<_l)return 1;if(e<Il)return 2;if(e<Cl)return 3;if(e<Vo)return 4;if(e<Ho)return 5;if(e<zo)return 6;if(e<Fo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ue(e,t,r=0){switch(It(e)){case 8:t[r++]=e&255|F,e/=128;case 7:t[r++]=e&255|F,e/=128;case 6:t[r++]=e&255|F,e/=128;case 5:t[r++]=e&255|F,e/=128;case 4:t[r++]=e&255|F,e>>>=7;case 3:t[r++]=e&255|F,e>>>=7;case 2:t[r++]=e&255|F,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Tl(e,t,r=0){switch(It(e)){case 8:t.set(r++,e&255|F),e/=128;case 7:t.set(r++,e&255|F),e/=128;case 6:t.set(r++,e&255|F),e/=128;case 5:t.set(r++,e&255|F),e/=128;case 4:t.set(r++,e&255|F),e>>>=7;case 3:t.set(r++,e&255|F),e>>>=7;case 2:t.set(r++,e&255|F),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function $o(e,t){let r=e[t],n=0;if(n+=r<,r<F||(r=e[t+1],n+=(r<)<<7,r<F)||(r=e[t+2],n+=(r<)<<14,r<F)||(r=e[t+3],n+=(r<)<<21,r<F)||(r=e[t+4],n+=(r<)*Vo,r<F)||(r=e[t+5],n+=(r<)*Ho,r<F)||(r=e[t+6],n+=(r<)*zo,r<F)||(r=e[t+7],n+=(r<)*Fo,r<F))return n;throw new RangeError("Could not decode varint")}function Bl(e,t){let r=e.get(t),n=0;if(n+=r<,r<F||(r=e.get(t+1),n+=(r<)<<7,r<F)||(r=e.get(t+2),n+=(r<)<<14,r<F)||(r=e.get(t+3),n+=(r<)<<21,r<F)||(r=e.get(t+4),n+=(r<)*Vo,r<F)||(r=e.get(t+5),n+=(r<)*Ho,r<F)||(r=e.get(t+6),n+=(r<)*zo,r<F)||(r=e.get(t+7),n+=(r<)*Fo,r<F))return n;throw new RangeError("Could not decode varint")}function Xr(e,t,r=0){return t==null&&(t=xt(It(e))),t instanceof Uint8Array?Ue(e,t,r):Tl(e,t,r)}function Wo(e,t=0){return e instanceof Uint8Array?$o(e,t):Bl(e,t)}var Zo=new Float32Array([-0]),se=new Uint8Array(Zo.buffer);function ca(e,t,r){Zo[0]=e,t[r]=se[0],t[r+1]=se[1],t[r+2]=se[2],t[r+3]=se[3]}function ua(e,t){return se[0]=e[t],se[1]=e[t+1],se[2]=e[t+2],se[3]=e[t+3],Zo[0]}var Go=new Float64Array([-0]),ft=new Uint8Array(Go.buffer);function la(e,t,r){Go[0]=e,t[r]=ft[0],t[r+1]=ft[1],t[r+2]=ft[2],t[r+3]=ft[3],t[r+4]=ft[4],t[r+5]=ft[5],t[r+6]=ft[6],t[r+7]=ft[7]}function fa(e,t){return ft[0]=e[t],ft[1]=e[t+1],ft[2]=e[t+2],ft[3]=e[t+3],ft[4]=e[t+4],ft[5]=e[t+5],ft[6]=e[t+6],ft[7]=e[t+7],Go[0]}var Rl=BigInt(Number.MAX_SAFE_INTEGER),Dl=BigInt(Number.MIN_SAFE_INTEGER),vt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return me;if(t<Rl&&t>Dl)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>da&&(o=0n,++n>da&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return me;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):me}},me=new vt(0,0);me.toBigInt=function(){return 0n};me.zzEncode=me.zzDecode=function(){return this};me.length=function(){return 1};var da=4294967296n;function ha(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function pa(e,t,r){if(r-t<1)return"";let o,s=[],i=0,a;for(;t<r;)a=e[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Yo(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Rt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function jr(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Xo=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,Rt(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 Rt(this,4);return jr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Rt(this,4);return jr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Rt(this,4);let t=ua(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Rt(this,4);let t=fa(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Rt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,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 Rt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Rt(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 vt(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Rt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Rt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Rt(this,8);let t=jr(this.buf,this.pos+=4),r=jr(this.buf,this.pos+=4);return new vt(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=$o(this.buf,this.pos);return this.pos+=It(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 lr(e){return new Xo(e instanceof Uint8Array?e:e.subarray())}function pt(e,t,r){let n=lr(e);return t.decode(n,void 0,r)}function jo(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return xt(i);o+i>t&&(n=xt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var ye=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function 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}},Ll=jo();function Ol(e){return globalThis.Buffer!=null?xt(e):Ll(e)}var dr=class{len;head;tail;states;constructor(){this.len=0,this.head=new ye(Qo,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ye(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new 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(Qr,10,vt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=vt.fromBigInt(t);return this._push(Qr,r.length(),r)}uint64Number(t){return this._push(Ue,It(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=vt.fromBigInt(t).zzEncode();return this._push(Qr,r.length(),r)}sint64Number(t){let r=vt.fromNumber(t).zzEncode();return this._push(Qr,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Jo,1,t?1:0)}fixed32(t){return this._push(fr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=vt.fromBigInt(t);return this._push(fr,4,r.lo)._push(fr,4,r.hi)}fixed64Number(t){let r=vt.fromNumber(t);return this._push(fr,4,r.lo)._push(fr,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(ca,4,t)}double(t){return this._push(la,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Jo,1,0):this.uint32(r)._push(Kl,r,t)}string(t){let r=ha(t);return r!==0?this.uint32(r)._push(Yo,r,t):this._push(Jo,1,0)}fork(){return this.states=new ts(this),this.head=this.tail=new ye(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 ye(Qo,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=Ol(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Jo(e,t,r){t[r]=e&255}function kl(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var es=class extends ye{next;constructor(t,r){super(kl,t,r),this.next=void 0}};function Qr(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function fr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function Kl(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(dr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Pl,t,e),this},dr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Nl,t,e),this});function Pl(e,t,r){t.set(e,r)}function Nl(e,t,r){e.length<40?Yo(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(z(e),r)}function rs(){return new dr}function mt(e,t){let r=rs();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*yt(e,t,r){let n=lr(e);yield*t.stream(n,void 0,"$",r)}var Jr={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function tn(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function ns(e){function t(s){if(e[s.toString()]==null)throw new Error("Invalid enum value");return e[s]}let r=function(i,a){let c=t(i);a.int32(c)},n=function(i){let a=i.int32();return t(a)},o=function*(i){let a=i.int32();yield t(a)};return tn("enum",Jr.VARINT,r,n,o)}function bt(e,t,r){return tn("message",Jr.LENGTH_DELIMITED,e,t,r)}var Ct=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},hr=class extends Error{code="ERR_MAX_SIZE";name="MaxSizeError"};var G;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(G||(G={}));var os;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(os||(os={}));(function(e){e.codec=()=>ns(os)})(G||(G={}));var Pt;(function(e){let t;e.codec=()=>(t==null&&(t=bt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),G.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},l=i==null?s.len:s.pos+i;for(;s.pos<l;){let u=s.uint32();switch(u>>>3){case 1:{c.Type=G.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return c},function*(s,i,a,c={}){let l=i==null?s.len:s.pos+i;for(;s.pos<l;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:G.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return mt(s,e.codec())}e.encode=r;function n(s,i){return pt(s,e.codec(),i)}e.decode=n;function o(s,i){return yt(s,e.codec(),i)}e.stream=o})(Pt||(Pt={}));var ss;(function(e){let t;e.codec=()=>(t==null&&(t=bt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),G.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},l=i==null?s.len:s.pos+i;for(;s.pos<l;){let u=s.uint32();switch(u>>>3){case 1:{c.Type=G.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return c},function*(s,i,a,c={}){let l=i==null?s.len:s.pos+i;for(;s.pos<l;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:G.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return mt(s,e.codec())}e.encode=r;function n(s,i){return pt(s,e.codec(),i)}e.decode=n;function o(s,i){return yt(s,e.codec(),i)}e.stream=o})(ss||(ss={}));var mr={};gt(mr,{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,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=mr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return et.createV1(114,this._multihash)}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}verify(t,r,n){return ga(this.jwk,r,t,n)}},pr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=mr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}sign(t,r){return ba(this.jwk,t,r)}};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(e){let t=Mt(e);return cs(t)}function cs(e){return{n:V(e[1],"base64url"),e:V(e[2],"base64url"),d:V(e[3],"base64url"),p:V(e[4],"base64url"),q:V(e[5],"base64url"),dp:V(e[6],"base64url"),dq:V(e[7],"base64url"),qi:V(e[8],"base64url"),kty:"RSA"}}function Vl(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new q("JWK was missing components");return Jt([wt(Uint8Array.from([0])),wt(z(e.n,"base64url")),wt(z(e.e,"base64url")),wt(z(e.d,"base64url")),wt(z(e.p,"base64url")),wt(z(e.q,"base64url")),wt(z(e.dp,"base64url")),wt(z(e.dq,"base64url")),wt(z(e.qi,"base64url"))]).subarray()}function Hl(e){let t=Mt(e,{offset:0});return us(t)}function us(e){let t=Mt(e[1],{offset:0});return{kty:"RSA",n:V(t[0],"base64url"),e:V(t[1],"base64url")}}function ls(e){if(e.n==null||e.e==null)throw new q("JWK was missing components");return Jt([Ml,Nr(Jt([wt(z(e.n,"base64url")),wt(z(e.e,"base64url"))]))]).subarray()}function xa(e){let t=Mt(e);return fs(t)}function fs(e){let t=cs(e);return ps(t)}function ds(e,t){if(e.byteLength>=Ul)throw new Ee("Key size is too large");let r=Mt(e,{offset:0});return hs(r,e,t)}function hs(e,t,r){let n=us(e);if(r==null){let o=Le(Pt.encode({Type:G.RSA,Data:t}));r=Ot(as,o)}return new Me(n,r)}function ps(e){if(Sa(e)>is)throw new q("Key size is too large");let t=Ea(e),r=Le(Pt.encode({Type:G.RSA,Data:ls(t.publicKey)})),n=Ot(as,r);return new pr(t.privateKey,new Me(t.publicKey,n))}async function wa(e){if(e>is)throw new q("Key size is too large");let t=await va(e),r=Le(Pt.encode({Type:G.RSA,Data:ls(t.publicKey)})),n=Ot(as,r);return new pr(t.privateKey,new Me(t.publicKey,n))}function Ea(e){if(e==null)throw new q("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function va(e,t){let r=await _t.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await zl(r,t);return{privateKey:n[0],publicKey:n[1]}}async function ba(e,t,r){let n=await _t.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await _t.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function ga(e,t,r,n){let o=await _t.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await _t.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function zl(e,t){if(e.privateKey==null||e.publicKey==null)throw new q("Private and public key are required");let r=await Promise.all([_t.get().subtle.exportKey("jwk",e.privateKey),_t.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function Sa(e){if(e.kty!=="RSA")throw new q("invalid key type");if(e.n==null)throw new q("invalid key modulus");return z(e.n,"base64url").length*8}var en=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,r){if(Ur(t),P(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Vt(o)}update(t){return Re(this),this.iHash.update(t),this}digestInto(t){Re(this),P(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:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ms=(e,t,r)=>new en(e,t).update(r).digest();ms.create=(e,t)=>new en(e,t);var Aa=(e,t)=>(e+(e>=0?t:-t)/_a)/t;function Fl(e,t,r){let[[n,o],[s,i]]=t,a=Aa(i*e,r),c=Aa(-o*e,r),l=e-a*n-c*s,u=-a*o-c*i,d=l<Wt,f=u<Wt;d&&(l=-l),f&&(u=-u);let h=ir(Math.ceil(Co(r)/2))+qe;if(l<Wt||l>=h||u<Wt||u>=h)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:d,k1:l,k2neg:f,k2:u}}function bs(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function ys(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return $t(r.lowS,"lowS"),$t(r.prehash,"prehash"),r.format!==void 0&&bs(r.format),r}var gs=class extends Error{constructor(t=""){super(t)}},ie={Err:gs,_tlv:{encode:(e,t)=>{let{Err:r}=ie;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=or(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?or(o.length/2|128):"";return or(e)+s+o+t},decode(e,t){let{Err:r}=ie,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let l=t.subarray(n,n+c);if(l.length!==c)throw new r("tlv.decode: length bytes not complete");if(l[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of l)i=i<<8|u;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=ie;if(e<Wt)throw new t("integer: negative integers are not allowed");let r=or(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=ie;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Oe(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=ie,o=P(e,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:l,l:u}=n.decode(2,c);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(l)}},hexFromSig(e){let{_tlv:t,_int:r}=ie,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},Wt=BigInt(0),qe=BigInt(1),_a=BigInt(2),rn=BigInt(3),$l=BigInt(4);function Ia(e,t={}){let r=Fr("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:a}=s;ne(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 l=Ta(n,o);function u(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function d(R,g,x){let{x:b,y:A}=g.toAffine(),C=n.toBytes(b);if($t(x,"isCompressed"),x){u();let B=!n.isOdd(A);return Et(Ca(B),C)}else return Et(Uint8Array.of(4),C,n.toBytes(A))}function f(R){P(R,void 0,"Point");let{publicKey:g,publicKeyUncompressed:x}=l,b=R.length,A=R[0],C=R.subarray(1);if(b===g&&(A===2||A===3)){let B=n.fromBytes(C);if(!n.isValid(B))throw new Error("bad point: is not on curve, wrong x");let D=E(B),T;try{T=n.sqrt(D)}catch(Y){let $=Y instanceof Error?": "+Y.message:"";throw new Error("bad point: is not on curve, sqrt error"+$)}u();let L=n.isOdd(T);return(A&1)===1!==L&&(T=n.neg(T)),{x:B,y:T}}else if(b===x&&A===4){let B=n.BYTES,D=n.fromBytes(C.subarray(0,B)),T=n.fromBytes(C.subarray(B,B*2));if(!y(D,T))throw new Error("bad point: is not on curve");return{x:D,y:T}}else throw new Error(`bad point: got length ${b}, expected compressed=${g} or uncompressed=${x}`)}let h=t.toBytes||d,p=t.fromBytes||f;function E(R){let g=n.sqr(R),x=n.mul(g,R);return n.add(n.add(x,n.mul(R,s.a)),s.b)}function y(R,g){let x=n.sqr(g),b=E(R);return n.eql(x,b)}if(!y(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let m=n.mul(n.pow(s.a,rn),$l),_=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(m,_)))throw new Error("bad curve params: a or b");function w(R,g,x=!1){if(!n.isValid(g)||x&&n.is0(g))throw new Error(`bad point coordinate ${R}`);return g}function I(R){if(!(R instanceof v))throw new Error("Weierstrass Point expected")}function O(R){if(!c||!c.basises)throw new Error("no endo");return Fl(R,c.basises,o.ORDER)}let N=ke((R,g)=>{let{X:x,Y:b,Z:A}=R;if(n.eql(A,n.ONE))return{x,y:b};let C=R.is0();g==null&&(g=C?n.ONE:n.inv(A));let B=n.mul(x,g),D=n.mul(b,g),T=n.mul(A,g);if(C)return{x:n.ZERO,y:n.ZERO};if(!n.eql(T,n.ONE))throw new Error("invZ was invalid");return{x:B,y:D}}),U=ke(R=>{if(R.is0()){if(t.allowInfinityPoint&&!n.is0(R.Y))return;throw new Error("bad point: ZERO")}let{x:g,y:x}=R.toAffine();if(!n.isValid(g)||!n.isValid(x))throw new Error("bad point: x or y not field elements");if(!y(g,x))throw new Error("bad point: equation left != right");if(!R.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function S(R,g,x,b,A){return x=new v(n.mul(x.X,R),x.Y,x.Z),g=cr(b,g),x=cr(A,x),g.add(x)}class v{static BASE=new v(s.Gx,s.Gy,n.ONE);static ZERO=new v(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(g,x,b){this.X=w("x",g),this.Y=w("y",x,!0),this.Z=w("z",b),Object.freeze(this)}static CURVE(){return s}static fromAffine(g){let{x,y:b}=g||{};if(!g||!n.isValid(x)||!n.isValid(b))throw new Error("invalid affine point");if(g instanceof v)throw new Error("projective point not allowed");return n.is0(x)&&n.is0(b)?v.ZERO:new v(x,b,n.ONE)}static fromBytes(g){let x=v.fromAffine(p(P(g,void 0,"point")));return x.assertValidity(),x}static fromHex(g){return v.fromBytes(zt(g))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,x=!0){return M.createCache(this,g),x||this.multiply(rn),this}assertValidity(){U(this)}hasEvenY(){let{y:g}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(g)}equals(g){I(g);let{X:x,Y:b,Z:A}=this,{X:C,Y:B,Z:D}=g,T=n.eql(n.mul(x,D),n.mul(C,A)),L=n.eql(n.mul(b,D),n.mul(B,A));return T&&L}negate(){return new v(this.X,n.neg(this.Y),this.Z)}double(){let{a:g,b:x}=s,b=n.mul(x,rn),{X:A,Y:C,Z:B}=this,D=n.ZERO,T=n.ZERO,L=n.ZERO,K=n.mul(A,A),Y=n.mul(C,C),$=n.mul(B,B),H=n.mul(A,C);return H=n.add(H,H),L=n.mul(A,B),L=n.add(L,L),D=n.mul(g,L),T=n.mul(b,$),T=n.add(D,T),D=n.sub(Y,T),T=n.add(Y,T),T=n.mul(D,T),D=n.mul(H,D),L=n.mul(b,L),$=n.mul(g,$),H=n.sub(K,$),H=n.mul(g,H),H=n.add(H,L),L=n.add(K,K),K=n.add(L,K),K=n.add(K,$),K=n.mul(K,H),T=n.add(T,K),$=n.mul(C,B),$=n.add($,$),K=n.mul($,H),D=n.sub(D,K),L=n.mul($,Y),L=n.add(L,L),L=n.add(L,L),new v(D,T,L)}add(g){I(g);let{X:x,Y:b,Z:A}=this,{X:C,Y:B,Z:D}=g,T=n.ZERO,L=n.ZERO,K=n.ZERO,Y=s.a,$=n.mul(s.b,rn),H=n.mul(x,C),X=n.mul(b,B),it=n.mul(A,D),Dt=n.add(x,b),j=n.add(C,B);Dt=n.mul(Dt,j),j=n.add(H,X),Dt=n.sub(Dt,j),j=n.add(x,A);let ut=n.add(C,D);return j=n.mul(j,ut),ut=n.add(H,it),j=n.sub(j,ut),ut=n.add(b,A),T=n.add(B,D),ut=n.mul(ut,T),T=n.add(X,it),ut=n.sub(ut,T),K=n.mul(Y,j),T=n.mul($,it),K=n.add(T,K),T=n.sub(X,K),K=n.add(X,K),L=n.mul(T,K),X=n.add(H,H),X=n.add(X,H),it=n.mul(Y,it),j=n.mul($,j),X=n.add(X,it),it=n.sub(H,it),it=n.mul(Y,it),j=n.add(j,it),H=n.mul(X,j),L=n.add(L,H),H=n.mul(ut,j),T=n.mul(Dt,T),T=n.sub(T,H),H=n.mul(Dt,X),K=n.mul(ut,K),K=n.add(K,H),new v(T,L,K)}subtract(g){return this.add(g.negate())}is0(){return this.equals(v.ZERO)}multiply(g){let{endo:x}=t;if(!o.isValidNot0(g))throw new Error("invalid scalar: out of range");let b,A,C=B=>M.cached(this,B,D=>pe(v,D));if(x){let{k1neg:B,k1:D,k2neg:T,k2:L}=O(g),{p:K,f:Y}=C(D),{p:$,f:H}=C(L);A=Y.add(H),b=S(x.beta,K,$,B,T)}else{let{p:B,f:D}=C(g);b=B,A=D}return pe(v,[b,A])[0]}multiplyUnsafe(g){let{endo:x}=t,b=this;if(!o.isValid(g))throw new Error("invalid scalar: out of range");if(g===Wt||b.is0())return v.ZERO;if(g===qe)return b;if(M.hasCache(this))return this.multiply(g);if(x){let{k1neg:A,k1:C,k2neg:B,k2:D}=O(g),{p1:T,p2:L}=Qi(v,b,C,D);return S(x.beta,T,L,A,B)}else return M.unsafe(b,g)}toAffine(g){return N(this,g)}isTorsionFree(){let{isTorsionFree:g}=t;return i===qe?!0:g?g(v,this):M.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:g}=t;return i===qe?this:g?g(v,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(g=!0){return $t(g,"isCompressed"),this.assertValidity(),h(v,this,g)}toHex(g=!0){return Ht(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let k=o.BITS,M=new Ne(v,t.endo?Math.ceil(k/2):k);return v.BASE.precompute(8),v}function Ca(e){return Uint8Array.of(e?2:3)}function Ta(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Wl(e,t={}){let{Fn:r}=e,n=t.randomBytes||De,o=Object.assign(Ta(e.Fp,r),{seed:Do(r.ORDER)});function s(h){try{let p=r.fromBytes(h);return r.isValidNot0(p)}catch{return!1}}function i(h,p){let{publicKey:E,publicKeyUncompressed:y}=o;try{let m=h.length;return p===!0&&m!==E||p===!1&&m!==y?!1:!!e.fromBytes(h)}catch{return!1}}function a(h=n(o.seed)){return Lo(P(h,o.seed,"seed"),r.ORDER)}function c(h,p=!0){return e.BASE.multiply(r.fromBytes(h)).toBytes(p)}function l(h){let{secretKey:p,publicKey:E,publicKeyUncompressed:y}=o;if(!ce(h)||"_lengths"in r&&r._lengths||p===E)return;let m=P(h,void 0,"key").length;return m===E||m===y}function u(h,p,E=!0){if(l(h)===!0)throw new Error("first arg must be private key");if(l(p)===!1)throw new Error("second arg must be public key");let y=r.fromBytes(h);return e.fromBytes(p).multiply(y).toBytes(E)}let d={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},f=$r(a,c);return Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:f,Point:e,utils:d,lengths:o})}function Ba(e,t,r={}){Ur(t),ne(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let n=r.randomBytes||De,o=r.hmac||((x,b)=>ms(t,x,b)),{Fp:s,Fn:i}=e,{ORDER:a,BITS:c}=i,{keygen:l,getPublicKey:u,getSharedSecret:d,utils:f,lengths:h}=Wl(e,r),p={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},E=a*_a<s.ORDER;function y(x){let b=a>>qe;return x>b}function m(x,b){if(!i.isValidNot0(b))throw new Error(`invalid signature ${x}: out of range 1..Point.Fn.ORDER`);return b}function _(){if(E)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function w(x,b){bs(b);let A=h.signature,C=b==="compact"?A:b==="recovered"?A+1:void 0;return P(x,C)}class I{r;s;recovery;constructor(b,A,C){if(this.r=m("r",b),this.s=m("s",A),C!=null){if(_(),![0,1,2,3].includes(C))throw new Error("invalid recovery id");this.recovery=C}Object.freeze(this)}static fromBytes(b,A=p.format){w(b,A);let C;if(A==="der"){let{r:L,s:K}=ie.toSig(P(b));return new I(L,K)}A==="recovered"&&(C=b[0],A="compact",b=b.subarray(1));let B=h.signature/2,D=b.subarray(0,B),T=b.subarray(B,B*2);return new I(i.fromBytes(D),i.fromBytes(T),C)}static fromHex(b,A){return this.fromBytes(zt(b),A)}assertRecovery(){let{recovery:b}=this;if(b==null)throw new Error("invalid recovery id: must be present");return b}addRecoveryBit(b){return new I(this.r,this.s,b)}recoverPublicKey(b){let{r:A,s:C}=this,B=this.assertRecovery(),D=B===2||B===3?A+a:A;if(!s.isValid(D))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let T=s.toBytes(D),L=e.fromBytes(Et(Ca((B&1)===0),T)),K=i.inv(D),Y=N(P(b,void 0,"msgHash")),$=i.create(-Y*K),H=i.create(C*K),X=e.BASE.multiplyUnsafe($).add(L.multiplyUnsafe(H));if(X.is0())throw new Error("invalid recovery: point at infinify");return X.assertValidity(),X}hasHighS(){return y(this.s)}toBytes(b=p.format){if(bs(b),b==="der")return zt(ie.hexFromSig(this));let{r:A,s:C}=this,B=i.toBytes(A),D=i.toBytes(C);return b==="recovered"?(_(),Et(Uint8Array.of(this.assertRecovery()),B,D)):Et(B,D)}toHex(b){return Ht(this.toBytes(b))}}let O=r.bits2int||function(b){if(b.length>8192)throw new Error("input is too large");let A=Oe(b),C=b.length*8-c;return C>0?A>>BigInt(C):A},N=r.bits2int_modN||function(b){return i.create(O(b))},U=ir(c);function S(x){return sr("num < 2^"+c,x,Wt,U),i.toBytes(x)}function v(x,b){return P(x,void 0,"message"),b?P(t(x),void 0,"prehashed message"):x}function k(x,b,A){let{lowS:C,prehash:B,extraEntropy:D}=ys(A,p);x=v(x,B);let T=N(x),L=i.fromBytes(b);if(!i.isValidNot0(L))throw new Error("invalid private key");let K=[S(L),S(T)];if(D!=null&&D!==!1){let X=D===!0?n(h.secretKey):D;K.push(P(X,void 0,"extraEntropy"))}let Y=Et(...K),$=T;function H(X){let it=O(X);if(!i.isValidNot0(it))return;let Dt=i.inv(it),j=e.BASE.multiply(it).toAffine(),ut=i.create(j.x);if(ut===Wt)return;let Rr=i.create(Dt*i.create($+ut*L));if(Rr===Wt)return;let zs=(j.x===ut?0:2)|Number(j.y&qe),Fs=Rr;return C&&y(Rr)&&(Fs=i.neg(Rr),zs^=1),new I(ut,Fs,E?void 0:zs)}return{seed:Y,k2sig:H}}function M(x,b,A={}){let{seed:C,k2sig:B}=k(x,b,A);return Ki(t.outputLen,i.BYTES,o)(C,B).toBytes(A.format)}function R(x,b,A,C={}){let{lowS:B,prehash:D,format:T}=ys(C,p);if(A=P(A,void 0,"publicKey"),b=v(b,D),!ce(x)){let L=x instanceof I?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+L)}w(x,T);try{let L=I.fromBytes(x,T),K=e.fromBytes(A);if(B&&L.hasHighS())return!1;let{r:Y,s:$}=L,H=N(b),X=i.inv($),it=i.create(H*X),Dt=i.create(Y*X),j=e.BASE.multiplyUnsafe(it).add(K.multiplyUnsafe(Dt));return j.is0()?!1:i.create(j.x)===Y}catch{return!1}}function g(x,b,A={}){let{prehash:C}=ys(A,p);return b=v(b,C),I.fromBytes(x,"recovered").recoverPublicKey(b).toBytes()}return Object.freeze({keygen:l,getPublicKey:u,getSharedSecret:d,utils:f,lengths:h,Point:e,sign:M,verify:R,recoverPublicKey:g,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 Ra=BigInt(2);function Gl(e){let t=ws.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),l=e*e*e%t,u=l*l*e%t,d=Z(u,r,t)*u%t,f=Z(d,r,t)*u%t,h=Z(f,Ra,t)*l%t,p=Z(h,o,t)*h%t,E=Z(p,s,t)*p%t,y=Z(E,a,t)*E%t,m=Z(y,c,t)*y%t,_=Z(m,a,t)*E%t,w=Z(_,r,t)*u%t,I=Z(w,i,t)*p%t,O=Z(I,n,t)*l%t,N=Z(O,Ra,t);if(!xs.eql(xs.sqr(N),e))throw new Error("Cannot find square root");return N}var xs=Ke(ws.p,{sqrt:Gl}),Yl=Ia(ws,{Fp:xs,endo:Zl}),Ve=Ba(Yl,Le);function Da(e,t,r,n){let o=je.digest(r instanceof Uint8Array?r:r.subarray());if(Gr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ve.verify(t,s,e,{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,e,{prehash:!1,format:"der"})}catch(s){throw new ur(String(s))}}var nn=class{type="secp256k1";raw;_key;constructor(t){this._key=Oa(t),this.raw=La(this._key)}toMultihash(){return Tt.digest(At(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}verify(t,r,n){return Da(this._key,r,t,n)}};function Es(e){return new nn(e)}function La(e){return Ve.Point.fromBytes(e).toBytes()}function Oa(e){try{return Ve.Point.fromBytes(e),e}catch(t){throw new Ee(String(t))}}function on(e,t){let{Type:r,Data:n}=Pt.decode(e),o=n??new Uint8Array;switch(r){case G.RSA:return ds(o,t);case G.Ed25519:return qo(o);case G.secp256k1:return Es(o);case G.ECDSA:return mo(o);default:throw new ae}}function ka(e){let{Type:t,Data:r}=Pt.decode(e.digest),n=r??new Uint8Array;switch(t){case G.Ed25519:return qo(n);case G.secp256k1:return Es(n);case G.ECDSA:return mo(n);default:throw new ae}}function At(e){return Pt.encode({Type:G[e.type],Data:e.raw})}var Ka=Symbol.for("nodejs.util.inspect.custom"),Xl=114,yr=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()})`}[Or]=!0;toString(){return this.string==null&&(this.string=J.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 W(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return W(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ka](){return`PeerId(${this.toString()})`}},br=class extends yr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},gr=class extends yr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},xr=class extends yr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},jl=2336,wr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Tt.digest(z(this.url))}[Ka](){return`PeerId(${this.url})`}[Or]=!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,Pa=2336;function Na(e){if(e.type==="Ed25519")return new gr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new xr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new br({multihash:e.toCID().multihash,publicKey:e});throw new ae}function vs(e){if(tf(e))return new br({multihash:e});if(Jl(e))try{let t=ka(e);if(t.type==="Ed25519")return new gr({multihash:e,publicKey:t});if(t.type==="secp256k1")return new xr({multihash:e,publicKey:t})}catch{let r=V(e.digest);return new wr(new URL(r))}throw new Lr("Supplied PeerID Multihash is invalid")}function sn(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==Ql&&e.code!==Pa)throw new Dr("Supplied PeerID CID is invalid");if(e.code===Pa){let t=V(e.multihash.digest);return new wr(new URL(t))}return vs(e.multihash)}function Jl(e){return e.code===Tt.code}function tf(e){return e.code===je.code}var Er;(function(e){let t;e.codec=()=>(t==null&&(t=bt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.publicKey!=null&&s.publicKey.byteLength>0&&(i.uint32(10),i.bytes(s.publicKey)),s.payloadType!=null&&s.payloadType.byteLength>0&&(i.uint32(18),i.bytes(s.payloadType)),s.payload!=null&&s.payload.byteLength>0&&(i.uint32(26),i.bytes(s.payload)),s.signature!=null&&s.signature.byteLength>0&&(i.uint32(42),i.bytes(s.signature)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={publicKey:rt(0),payloadType:rt(0),payload:rt(0),signature:rt(0)},l=i==null?s.len:s.pos+i;for(;s.pos<l;){let u=s.uint32();switch(u>>>3){case 1:{c.publicKey=s.bytes();break}case 2:{c.payloadType=s.bytes();break}case 3:{c.payload=s.bytes();break}case 5:{c.signature=s.bytes();break}default:{s.skipType(u&7);break}}}return c},function*(s,i,a,c={}){let l=i==null?s.len:s.pos+i;for(;s.pos<l;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.publicKey`,value:s.bytes()};break}case 2:{yield{field:`${a}.payloadType`,value:s.bytes()};break}case 3:{yield{field:`${a}.payload`,value:s.bytes()};break}case 5:{yield{field:`${a}.signature`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return mt(s,e.codec())}e.encode=r;function n(s,i){return pt(s,e.codec(),i)}e.decode=n;function o(s,i){return yt(s,e.codec(),i)}e.stream=o})(Er||(Er={}));var an=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var He=class e{static createFromProtobuf=t=>{let r=Er.decode(t),n=on(r.publicKey);return new e({publicKey:n,payloadType:r.payloadType,payload:r.payload,signature:r.signature})};static seal=async(t,r,n)=>{if(r==null)throw new Error("Missing private key");let o=t.domain,s=t.codec,i=t.marshal(),a=Ua(o,s,i),c=await r.sign(a.subarray(),n);return new e({publicKey:r.publicKey,payloadType:s,payload:i,signature:c})};static openAndCertify=async(t,r,n)=>{let o=e.createFromProtobuf(t);if(!await o.validate(r,n))throw new an("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:r,payloadType:n,payload:o,signature:s}=t;this.publicKey=r,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=Er.encode({publicKey:At(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return t==null?!1:W(this.marshal(),t.marshal())}async validate(t,r){let n=Ua(t,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},Ua=(e,t,r)=>{let n=z(e),o=Xr(n.byteLength),s=Xr(t.length),i=Xr(r.length);return new dt(o,n,s,t,i,r)};var ct=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Zt=class extends Error{static name="ValidationError";name="ValidationError"},cn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},un=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var ln=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",l=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let d=this.readChar();if(d===void 0)return;let f=Number.parseInt(d,t);if(!Number.isNaN(f))return f});if(u===void 0)break;if(s*=t,s+=u,s>l||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=t(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var ef=45,rf=15,fn=new ln;function Ma(e){if(!(e.length>rf))return fn.new(e).parseWith(()=>fn.readIPv4Addr())}function qa(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>ef))return fn.new(e).parseWith(()=>fn.readIPv6Addr())}function dn(e){return!!Ma(e)}function Va(e){return!!qa(e)}function As(e){return t=>V(t,e)}function _s(e){return t=>z(t,e)}function ze(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function be(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function Ha(e){let t=e.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 r=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=be(n);return Ut([r,o],r.length+o.length)}function za(e){let t=e.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 r=Lt.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=be(n);return Ut([r,o],r.length+o.length)}function Is(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=V(t,"base32"),o=ze(r);return`${n}:${o}`}var Cs=function(e){e=e.toString().trim();let t=new Uint8Array(4);return e.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new ct("Invalid byte value in IP address");t[n]=o}),t},Fa=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let s=dn(r[n]),i;s&&(i=Cs(r[n]),r[n]=V(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,V(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(t+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new ct("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},$a=function(e){if(e.byteLength!==4)throw new ct("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},Wa=function(e){if(e.byteLength!==16)throw new ct("IPv6 address was incorrect length");let t=[];for(let n=0;n<e.byteLength;n+=2){let o=e[n],s=e[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let r=t.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new ct(`Invalid IPv6 address "${r}"`)}};function Za(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new ct(`Invalid IPv6 address "${e}"`)}}var Ss=Object.values(Qe).map(e=>e.decoder),nf=(function(){let e=Ss[0].or(Ss[1]);return Ss.slice(2).forEach(t=>e=e.or(t)),e})();function Ga(e){return nf.decode(e)}function Ya(e){return t=>e.encoder.encode(t)}function of(e){if(parseInt(e).toString()!==e)throw new Zt("Value must be an integer")}function sf(e){if(e<0)throw new Zt("Value must be a positive integer, or zero")}function af(e){return t=>{if(t>e)throw new Zt(`Value must be smaller than or equal to ${e}`)}}function cf(...e){return t=>{for(let r of e)r(t)}}var vr=cf(of,sf,af(65535));var st=-1,Ts=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let r;if(typeof t=="string"?r=this.protocolsByName.get(t):r=this.protocolsByCode.get(t),r==null)throw new un(`Protocol ${t} was unknown`);return r}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(r=>{this.protocolsByName.set(r,t)})}removeProtocol(t){let r=this.protocolsByCode.get(t);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},Gt=new Ts,Gf=[{code:4,name:"ip4",size:32,valueToBytes:Cs,bytesToValue:$a,validate:e=>{if(!dn(e))throw new Zt(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:be,bytesToValue:ze,validate:vr},{code:273,name:"udp",size:16,valueToBytes:be,bytesToValue:ze,validate:vr},{code:33,name:"dccp",size:16,valueToBytes:be,bytesToValue:ze,validate:vr},{code:41,name:"ip6",size:128,valueToBytes:Fa,bytesToValue:Wa,stringToValue:Za,validate:e=>{if(!Va(e))throw new Zt(`Invalid IPv6 address "${e}"`)}},{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:be,bytesToValue:ze,validate:vr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:st,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:st,bytesToValue:As("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?_s("base58btc")(e):et.parse(e).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(eo),valueToBytes:Ga},{code:480,name:"http"},{code:481,name:"http-path",size:st,stringToValue:e=>`/${decodeURIComponent(e)}`,valueToString:e=>encodeURIComponent(e.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(e=>{Gt.addProtocol(e)});function Xa(e){let t=[],r=0;for(;r<e.length;){let n=Wo(e,r),o=Gt.getProtocol(n),s=It(n),i=Yf(o,e,r+s),a=0;i>0&&o.size===st&&(a=It(i));let c=s+a+i,l={code:n,name:o.name,bytes:e.subarray(r,r+c)};if(i>0){let u=r+s+a,d=e.subarray(u,u+i);l.value=o.bytesToValue?.(d)??V(d)}t.push(l),r+=c}return t}function ja(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=Gt.getProtocol(n.code),s=It(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=It(a)));let l=new Uint8Array(s+c+a),u=0;Ue(n.code,l,u),u+=s,i!=null&&(o.size===st&&(Ue(a,l,u),u+=c),l.set(i,u)),n.bytes=l}r.push(n.bytes),t+=n.bytes.byteLength}return Ut(r,t)}function Qa(e){if(e.charAt(0)!=="/")throw new ct('String multiaddr must start with "/"');let t=[],r="protocol",n="",o="";for(let s=1;s<e.length;s++){let i=e.charAt(s);i!=="/"&&(r==="protocol"?o+=e.charAt(s):n+=e.charAt(s));let a=s===e.length-1;if(i==="/"||a){let c=Gt.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new ct(`Component ${o} was missing value`);r="value"}else if(r==="value"){let l={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new ct(`Component ${o} was missing value`);l.value=c.stringToValue?.(n)??n}t.push(l),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new ct("Incomplete multiaddr");return t}function Ja(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=Gt.getProtocol(t.code);if(r==null)throw new ct(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function Yf(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:Wo(t,r)}var Xf=Symbol.for("nodejs.util.inspect.custom"),Rs=Symbol.for("@multiformats/multiaddr");function jf(e){if(e==null&&(e="/"),pn(e))return e.getComponents();if(e instanceof Uint8Array)return Xa(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),Qa(e);if(Array.isArray(e))return e;throw new ct("Must be a string, Uint8Array, Component[], or another Multiaddr")}var hn=class e{[Rs]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=jf(t),r.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 r=new e(t);return new e([...this.#t,...r.getComponents()],{validate:!1})}decapsulate(t){let r=t.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new cn(`Address ${this.toString()} does not contain subaddress: ${r}`);return new e(n.slice(0,o),{validate:!1})}decapsulateCode(t){let r;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){r=n;break}return new e(this.#t.slice(0,r),{validate:!1})}equals(t){return W(this.bytes,t.bytes)}[Xf](){return`Multiaddr(${this.toString()})`}};function Qf(e){e.getComponents().forEach(t=>{let r=Gt.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function pn(e){return!!e?.[Rs]}function ge(e){return new hn(e)}var tc="libp2p-peer-record",ec=Uint8Array.from([3,1]);var Sr;(function(e){let t;(function(i){let a;i.codec=()=>(a==null&&(a=bt((d,f,h={})=>{h.lengthDelimited!==!1&&f.fork(),d.multiaddr!=null&&d.multiaddr.byteLength>0&&(f.uint32(10),f.bytes(d.multiaddr)),h.lengthDelimited!==!1&&f.ldelim()},(d,f,h={})=>{let p={multiaddr:rt(0)},E=f==null?d.len:d.pos+f;for(;d.pos<E;){let y=d.uint32();y>>>3===1?p.multiaddr=d.bytes():d.skipType(y&7)}return p},function*(d,f,h,p={}){let E=f==null?d.len:d.pos+f;for(;d.pos<E;){let y=d.uint32();y>>>3===1?yield{field:`${h}.multiaddr`,value:d.bytes()}:d.skipType(y&7)}})),a);function c(d){return mt(d,i.codec())}i.encode=c;function l(d,f){return pt(d,i.codec(),f)}i.decode=l;function u(d,f){return yt(d,i.codec(),f)}i.stream=u})(t=e.AddressInfo||(e.AddressInfo={}));let r;e.codec=()=>(r==null&&(r=bt((i,a,c={})=>{if(c.lengthDelimited!==!1&&a.fork(),i.peerId!=null&&i.peerId.byteLength>0&&(a.uint32(10),a.bytes(i.peerId)),i.seq!=null&&i.seq!==0n&&(a.uint32(16),a.uint64(i.seq)),i.addresses!=null&&i.addresses.length>0)for(let l of i.addresses)a.uint32(26),e.AddressInfo.codec().encode(l,a);c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let l={peerId:rt(0),seq:0n,addresses:[]},u=a==null?i.len:i.pos+a;for(;i.pos<u;){let d=i.uint32();switch(d>>>3){case 1:{l.peerId=i.bytes();break}case 2:{l.seq=i.uint64();break}case 3:{if(c.limits?.addresses!=null&&l.addresses.length===c.limits.addresses)throw new Ct('Decode error - repeated field "addresses" had too many elements');l.addresses.push(e.AddressInfo.codec().decode(i,i.uint32(),{limits:c.limits?.addresses$}));break}default:{i.skipType(d&7);break}}}return l},function*(i,a,c,l={}){let u={addresses:0},d=a==null?i.len:i.pos+a;for(;i.pos<d;){let f=i.uint32();switch(f>>>3){case 1:{yield{field:`${c}.peerId`,value:i.bytes()};break}case 2:{yield{field:`${c}.seq`,value:i.uint64()};break}case 3:{if(l.limits?.addresses!=null&&u.addresses===l.limits.addresses)throw new Ct('Streaming decode error - repeated field "addresses" had too many elements');for(let h of e.AddressInfo.codec().stream(i,i.uint32(),`${c}.addresses[]`,{limits:l.limits?.addresses$}))yield{...h,index:u.addresses};u.addresses++;break}default:{i.skipType(f&7);break}}}})),r);function n(i){return mt(i,e.codec())}e.encode=n;function o(i,a){return pt(i,e.codec(),a)}e.decode=o;function s(i,a){return yt(i,e.codec(),a)}e.stream=s})(Sr||(Sr={}));function rc(e,t){let r=(n,o)=>n.toString().localeCompare(o.toString());return e.length!==t.length?!1:(t.sort(r),e.sort(r).every((n,o)=>t[o].equals(n)))}var xe=class e{static createFromProtobuf=t=>{let r=Sr.decode(t),n=vs(Te(r.peerId)),o=(r.addresses??[]).map(i=>ge(i.multiaddr)),s=r.seq;return new e({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=tc;static CODEC=ec;peerId;multiaddrs;seqNumber;domain=e.DOMAIN;codec=e.CODEC;marshaled;constructor(t){let{peerId:r,multiaddrs:n,seqNumber:o}=t;this.peerId=r,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=Sr.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 e)||!this.peerId.equals(t.peerId)||this.seqNumber!==t.seqNumber||!rc(this.multiaddrs,t.multiaddrs))}};function Jf(e){return e[Symbol.asyncIterator]!=null}function td(e){if(Jf(e))return(async()=>{let r=[];for await(let n of e)r.push(n);return r})();let t=[];for(let r of e)t.push(r);return t}var nc=td;function mn(e,t){let r={[Symbol.iterator]:()=>r,next:()=>{let n=e.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return r}var Ar=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[r,n]of t.entries())this.map.set(r.toString(),{key:r,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return mn(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((r,n)=>{t(r.value,r.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,r){this.map.set(t.toString(),{key:t,value:r})}keys(){return mn(this.map.values(),t=>t.key)}values(){return mn(this.map.values(),t=>t.value)}get size(){return this.map.size}};function yn(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var bn=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 bn(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 r=this.head;this.head=r.next=new bn(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Ds=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function oc(e={}){return ed(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},e)}function ed(e,t){t=t??{};let r=t.onEnd,n=new Fe,o,s,i,a=yn(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((y,m)=>{s=_=>{s=null,n.push(_);try{y(e(n))}catch(w){m(w)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=yn()})}},l=y=>s!=null?s(y):(n.push(y),o),u=y=>(n=new Fe,s!=null?s({error:y}):(n.push({error:y}),o)),d=y=>{if(i)return o;if(t?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:y})},f=y=>i?o:(i=!0,y!=null?u(y):l({done:!0})),h=()=>(n=new Fe,f(),{done:!0}),p=y=>(f(y),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:h,throw:p,push:d,end:f,get readableLength(){return n.size},onEmpty:async y=>{let m=y?.signal;if(m?.throwIfAborted(),n.isEmpty())return;let _,w;m!=null&&(_=new Promise((I,O)=>{w=()=>{O(new Ds)},m.addEventListener("abort",w)}));try{await Promise.race([a.promise,_])}finally{w!=null&&m!=null&&m?.removeEventListener("abort",w)}}},r==null)return o;let E=o;return o={[Symbol.asyncIterator](){return this},next(){return E.next()},throw(y){return E.throw(y),r!=null&&(r(y),r=void 0),{done:!0}},return(){return E.return(),r!=null&&(r(),r=void 0),{done:!0}},push:d,end(y){return E.end(y),r!=null&&(r(y),r=void 0),o},get readableLength(){return E.readableLength},onEmpty:y=>E.onEmpty(y)},o}function rd(e){return e.reason}async function sc(e,t,r){if(t==null)return e;let n=r?.translateError??rd;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([e,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}var Ls=class extends Ar{metric;constructor(t){super();let{name:r,metrics:n}=t;this.metric=n.registerMetric(r),this.updateComponentMetric()}set(t,r){return super.set(t,r),this.updateComponentMetric(),this}delete(t){let r=super.delete(t);return this.updateComponentMetric(),r}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function Os(e){let{name:t,metrics:r}=e,n;return r!=null?n=new Ls({name:t,metrics:r}):n=new Ar,n}var St=class extends Error{static name="AbortError";name="AbortError";constructor(t="The operation was aborted",...r){super(t,...r)}};async function gn(e,t,r,n){let o=new St(n?.errorMessage);n?.errorCode!=null&&(o.code=n.errorCode);let s=n?.errorEvent??"error";return r?.aborted===!0?Promise.reject(o):new Promise((i,a)=>{function c(){Ks(r,"abort",d),Ks(e,t,l),Ks(e,s,u)}let l=f=>{try{if(n?.filter?.(f)===!1)return}catch(h){c(),a(h);return}c(),i(f)},u=f=>{if(c(),f instanceof Error){a(f);return}a(f.detail??n?.error??new Error(`The "${n?.errorEvent}" event was emitted but the event had no '.detail' field. Pass an 'error' option to race-event to change this message.`))},d=()=>{c(),a(o)};ks(r,"abort",d),ks(e,t,l),ks(e,s,u)})}function ks(e,t,r){e!=null&&(ic(e)?e.addEventListener(t,r):e.addListener(t,r))}function Ks(e,t,r){e!=null&&(ic(e)?e.removeEventListener(t,r):e.removeListener(t,r))}function ic(e){return typeof e.addEventListener=="function"&&typeof e.removeEventListener=="function"}var xn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};var wn=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 St)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function nd(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var En=class{id;fn;options;recipients;status;timeline;controller;constructor(t,r){this.id=nd(),this.status="queued",this.fn=t,this.options=r,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((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new St),this.cleanup())}async join(t={}){let r=new wn(t.signal);return this.recipients.push(r),t.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await sc(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(t)}),this.status="complete"}catch(t){this.recipients.forEach(r=>{r.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(e,t){let r,n=function(){let o=function(){r=void 0,e()};clearTimeout(r),r=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var _r=class extends Se{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 r of this.queue)if(r.status==="queued"){t=r;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===t){this.queue.splice(r,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,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new xn;let n=new En(t,r);return this.enqueue(n),this.safeDispatchEvent("add"),this.autoStart&&this.tryToStartAnother(),n.join(r).then(o=>(this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(t=>{t.abort(new St)}),this.clear()}async onEmpty(t){this.size!==0&&await gn(this,"empty",t?.signal)}async onSizeLessThan(t,r){this.size<t||await gn(this,"next",r?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await gn(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 r=oc({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},o=c=>{c.detail!=null&&r.push(c.detail.result)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new St("Queue aborted"))};this.addEventListener("success",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("success",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};var vn="lock:worker:request-read",Sn="lock:worker:abort-read-request",An="lock:worker:release-read",_n="lock:master:grant-read",In="lock:master:error-read",Cn="lock:worker:request-write",Tn="lock:worker:abort-write-request",Bn="lock:worker:release-write",Rn="lock:master:grant-write",Dn="lock:master:error-write",Ln="lock:worker:finalize",On="mortice",ac={singleProcess:!1};var Ns=(e,t,r,n,o,s,i,a,c)=>l=>{if(l.data==null)return;let u={type:l.data.type,name:l.data.name,identifier:l.data.identifier};u.type===o&&e.safeDispatchEvent(r,{detail:{name:u.name,identifier:u.identifier,handler:async()=>{t.postMessage({type:c,name:u.name,identifier:u.identifier}),await new Promise(d=>{let f=h=>{if(h?.data==null)return;let p={type:h.data.type,name:h.data.name,identifier:h.data.identifier};p.type===a&&p.identifier===u.identifier&&(t.removeEventListener("message",f),d())};t.addEventListener("message",f)})},onError:d=>{t.postMessage({type:i,name:u.name,identifier:u.identifier,error:{message:d.message,name:d.name,stack:d.stack}})}}}),u.type===s&&e.safeDispatchEvent(n,{detail:{name:u.name,identifier:u.identifier}}),u.type===Ln&&e.safeDispatchEvent("finalizeRequest",{detail:{name:u.name}})};var cc=(e=10)=>Math.random().toString().substring(2,e+2);var kn=class{name;channel;constructor(t){this.name=t,this.channel=new BroadcastChannel(On)}readLock(t){return this.sendRequest(vn,Sn,_n,In,An,t)}writeLock(t){return this.sendRequest(Cn,Tn,Rn,Dn,Bn,t)}finalize(){this.channel.postMessage({type:Ln,name:this.name}),this.channel.close()}async sendRequest(t,r,n,o,s,i){i?.signal?.throwIfAborted();let a=cc();return this.channel.postMessage({type:t,identifier:a,name:this.name}),new Promise((c,l)=>{let u=()=>{this.channel.postMessage({type:r,identifier:a,name:this.name})};i?.signal?.addEventListener("abort",u,{once:!0});let d=f=>{if(f.data?.identifier===a&&(f.data?.type===n&&(this.channel.removeEventListener("message",d),i?.signal?.removeEventListener("abort",u),c(()=>{this.channel.postMessage({type:s,identifier:a,name:this.name})})),f.data.type===o)){this.channel.removeEventListener("message",d),i?.signal?.removeEventListener("abort",u);let h=new Error;f.data.error!=null&&(h.message=f.data.error.message,h.name=f.data.error.name,h.stack=f.data.error.stack),l(h)}};this.channel.addEventListener("message",d)})}};var uc=e=>{if(e=Object.assign({},ac,e),!!globalThis.document||e.singleProcess){let r=new BroadcastChannel(On),n=new Se;return r.addEventListener("message",Ns(n,r,"requestReadLock","abortReadLockRequest",vn,Sn,In,An,_n)),r.addEventListener("message",Ns(n,r,"requestWriteLock","abortWriteLockRequest",Cn,Tn,Dn,Bn,Rn)),n}return new kn(e.name)};var we=new Map,Ir;function lc(e){return typeof e?.readLock=="function"&&typeof e?.writeLock=="function"}function od(e){if(Ir==null&&(Ir=uc(e),!lc(Ir))){let t=Ir;t.addEventListener("requestReadLock",r=>{let n=r.detail.name,o=r.detail.identifier,s=we.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 r.detail.handler().finally(()=>{c()})}).catch(c=>{r.detail.onError(c)}).finally(()=>{t.removeEventListener("abortReadLockRequest",a)})}),t.addEventListener("requestWriteLock",r=>{let n=r.detail.name,o=r.detail.identifier,s=we.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 r.detail.handler().finally(()=>{c()})}).catch(c=>{r.detail.onError(c)}).finally(()=>{t.removeEventListener("abortWriteLockRequest",a)})}),t.addEventListener("finalizeRequest",r=>{let n=r.detail.name,o=we.get(n);o?.finalize()})}return Ir}async function Us(e,t){let r,n,o=new Promise((i,a)=>{r=i,n=a}),s=()=>{n(new St)};return t?.signal?.addEventListener("abort",s,{once:!0}),e.add(async()=>{await new Promise(i=>{r(()=>{t?.signal?.removeEventListener("abort",s),i()})})},{signal:t?.signal}).catch(i=>{n(i)}),o}var fc=(e,t)=>{let r=we.get(e);if(r!=null)return r;let n=od(t);if(lc(n))return r=n,we.set(e,r),r;let o=new _r({concurrency:1}),s;return r={async readLock(i){if(s!=null)return Us(s,i);s=new _r({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:()=>{we.delete(e)},queue:o},we.set(e,r),t.autoFinalize===!0&&o.addEventListener("idle",()=>{r.finalize()},{once:!0}),r};var sd={name:"lock",concurrency:1/0,singleProcess:!1,autoFinalize:!1};function Ms(e){let t=Object.assign({},sd,e);return fc(t.name,t)}var Yt;(function(e){let t;(function(a){let c;a.codec=()=>(c==null&&(c=bt((f,h,p={})=>{p.lengthDelimited!==!1&&h.fork(),f.key!=null&&f.key!==""&&(h.uint32(10),h.string(f.key)),f.value!=null&&f.value.byteLength>0&&(h.uint32(18),h.bytes(f.value)),p.lengthDelimited!==!1&&h.ldelim()},(f,h,p={})=>{let E={key:"",value:rt(0)},y=h==null?f.len:f.pos+h;for(;f.pos<y;){let m=f.uint32();switch(m>>>3){case 1:{E.key=f.string();break}case 2:{E.value=f.bytes();break}default:{f.skipType(m&7);break}}}return E},function*(f,h,p,E={}){let y=h==null?f.len:f.pos+h;for(;f.pos<y;){let m=f.uint32();switch(m>>>3){case 1:{yield{field:`${p}.key`,value:f.string()};break}case 2:{yield{field:`${p}.value`,value:f.bytes()};break}default:{f.skipType(m&7);break}}}})),c);function l(f){return mt(f,a.codec())}a.encode=l;function u(f,h){return pt(f,a.codec(),h)}a.decode=u;function d(f,h){return yt(f,a.codec(),h)}a.stream=d})(t=e.Peer$metadataEntry||(e.Peer$metadataEntry={}));let r;(function(a){let c;a.codec=()=>(c==null&&(c=bt((f,h,p={})=>{p.lengthDelimited!==!1&&h.fork(),f.key!=null&&f.key!==""&&(h.uint32(10),h.string(f.key)),f.value!=null&&(h.uint32(18),Tr.codec().encode(f.value,h)),p.lengthDelimited!==!1&&h.ldelim()},(f,h,p={})=>{let E={key:""},y=h==null?f.len:f.pos+h;for(;f.pos<y;){let m=f.uint32();switch(m>>>3){case 1:{E.key=f.string();break}case 2:{E.value=Tr.codec().decode(f,f.uint32(),{limits:p.limits?.value});break}default:{f.skipType(m&7);break}}}return E},function*(f,h,p,E={}){let y=h==null?f.len:f.pos+h;for(;f.pos<y;){let m=f.uint32();switch(m>>>3){case 1:{yield{field:`${p}.key`,value:f.string()};break}case 2:{yield*Tr.codec().stream(f,f.uint32(),`${p}.value`,{limits:E.limits?.value});break}default:{f.skipType(m&7);break}}}})),c);function l(f){return mt(f,a.codec())}a.encode=l;function u(f,h){return pt(f,a.codec(),h)}a.decode=u;function d(f,h){return yt(f,a.codec(),h)}a.stream=d})(r=e.Peer$tagsEntry||(e.Peer$tagsEntry={}));let n;e.codec=()=>(n==null&&(n=bt((a,c,l={})=>{if(l.lengthDelimited!==!1&&c.fork(),a.addresses!=null&&a.addresses.length>0)for(let u of a.addresses)c.uint32(10),Cr.codec().encode(u,c);if(a.protocols!=null&&a.protocols.length>0)for(let u of a.protocols)c.uint32(18),c.string(u);if(a.publicKey!=null&&(c.uint32(34),c.bytes(a.publicKey)),a.peerRecordEnvelope!=null&&(c.uint32(42),c.bytes(a.peerRecordEnvelope)),a.metadata!=null&&a.metadata.size>0)for(let[u,d]of a.metadata.entries())c.uint32(50),e.Peer$metadataEntry.codec().encode({key:u,value:d},c);if(a.tags!=null&&a.tags.size>0)for(let[u,d]of a.tags.entries())c.uint32(58),e.Peer$tagsEntry.codec().encode({key:u,value:d},c);a.updated!=null&&(c.uint32(64),c.uint64Number(a.updated)),l.lengthDelimited!==!1&&c.ldelim()},(a,c,l={})=>{let u={addresses:[],protocols:[],metadata:new Map,tags:new Map},d=c==null?a.len:a.pos+c;for(;a.pos<d;){let f=a.uint32();switch(f>>>3){case 1:{if(l.limits?.addresses!=null&&u.addresses.length===l.limits.addresses)throw new Ct('Decode error - repeated field "addresses" had too many elements');u.addresses.push(Cr.codec().decode(a,a.uint32(),{limits:l.limits?.addresses$}));break}case 2:{if(l.limits?.protocols!=null&&u.protocols.length===l.limits.protocols)throw new Ct('Decode error - repeated field "protocols" had too many elements');u.protocols.push(a.string());break}case 4:{u.publicKey=a.bytes();break}case 5:{u.peerRecordEnvelope=a.bytes();break}case 6:{if(l.limits?.metadata!=null&&u.metadata.size===l.limits.metadata)throw new hr('Decode error - map field "metadata" had too many elements');let h=e.Peer$metadataEntry.codec().decode(a,a.uint32(),{limits:{value:l.limits?.metadata$value}});u.metadata.set(h.key,h.value);break}case 7:{if(l.limits?.tags!=null&&u.tags.size===l.limits.tags)throw new hr('Decode error - map field "tags" had too many elements');let h=e.Peer$tagsEntry.codec().decode(a,a.uint32(),{limits:{value:l.limits?.tags$value}});u.tags.set(h.key,h.value);break}case 8:{u.updated=a.uint64Number();break}default:{a.skipType(f&7);break}}}return u},function*(a,c,l,u={}){let d={addresses:0,protocols:0,metadata:0,tags:0},f=c==null?a.len:a.pos+c;for(;a.pos<f;){let h=a.uint32();switch(h>>>3){case 1:{if(u.limits?.addresses!=null&&d.addresses===u.limits.addresses)throw new Ct('Streaming decode error - repeated field "addresses" had too many elements');for(let p of Cr.codec().stream(a,a.uint32(),`${l}.addresses[]`,{limits:u.limits?.addresses$}))yield{...p,index:d.addresses};d.addresses++;break}case 2:{if(u.limits?.protocols!=null&&d.protocols===u.limits.protocols)throw new Ct('Streaming decode error - repeated field "protocols" had too many elements');yield{field:`${l}.protocols[]`,index:d.protocols,value:a.string()},d.protocols++;break}case 4:{yield{field:`${l}.publicKey`,value:a.bytes()};break}case 5:{yield{field:`${l}.peerRecordEnvelope`,value:a.bytes()};break}case 6:{if(u.limits?.metadata!=null&&d.metadata===u.limits.metadata)throw new Ct('Decode error - map field "metadata" had too many elements');yield*e.Peer$metadataEntry.codec().stream(a,a.uint32(),`${l}.metadata{}`,{limits:{value:u.limits?.metadata$value}}),d.metadata++;break}case 7:{if(u.limits?.tags!=null&&d.tags===u.limits.tags)throw new Ct('Decode error - map field "tags" had too many elements');yield*e.Peer$tagsEntry.codec().stream(a,a.uint32(),`${l}.tags{}`,{limits:{value:u.limits?.tags$value}}),d.tags++;break}case 8:{yield{field:`${l}.updated`,value:a.uint64Number()};break}default:{a.skipType(h&7);break}}}})),n);function o(a){return mt(a,e.codec())}e.encode=o;function s(a,c){return pt(a,e.codec(),c)}e.decode=s;function i(a,c){return yt(a,e.codec(),c)}e.stream=i})(Yt||(Yt={}));var Cr;(function(e){let t;e.codec=()=>(t==null&&(t=bt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.multiaddr!=null&&s.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(s.multiaddr)),s.isCertified!=null&&(i.uint32(16),i.bool(s.isCertified)),s.observed!=null&&(i.uint32(24),i.uint64Number(s.observed)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={multiaddr:rt(0)},l=i==null?s.len:s.pos+i;for(;s.pos<l;){let u=s.uint32();switch(u>>>3){case 1:{c.multiaddr=s.bytes();break}case 2:{c.isCertified=s.bool();break}case 3:{c.observed=s.uint64Number();break}default:{s.skipType(u&7);break}}}return c},function*(s,i,a,c={}){let l=i==null?s.len:s.pos+i;for(;s.pos<l;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.multiaddr`,value:s.bytes()};break}case 2:{yield{field:`${a}.isCertified`,value:s.bool()};break}case 3:{yield{field:`${a}.observed`,value:s.uint64Number()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return mt(s,e.codec())}e.encode=r;function n(s,i){return pt(s,e.codec(),i)}e.decode=n;function o(s,i){return yt(s,e.codec(),i)}e.stream=o})(Cr||(Cr={}));var Tr;(function(e){let t;e.codec=()=>(t==null&&(t=bt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.value!=null&&s.value!==0&&(i.uint32(8),i.uint32(s.value)),s.expiry!=null&&(i.uint32(16),i.uint64(s.expiry)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={value:0},l=i==null?s.len:s.pos+i;for(;s.pos<l;){let u=s.uint32();switch(u>>>3){case 1:{c.value=s.uint32();break}case 2:{c.expiry=s.uint64();break}default:{s.skipType(u&7);break}}}return c},function*(s,i,a,c={}){let l=i==null?s.len:s.pos+i;for(;s.pos<l;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.value`,value:s.uint32()};break}case 2:{yield{field:`${a}.expiry`,value:s.uint64()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return mt(s,e.codec())}e.encode=r;function n(s,i){return pt(s,e.codec(),i)}e.decode=n;function o(s,i){return yt(s,e.codec(),i)}e.stream=o})(Tr||(Tr={}));function id(e,t){if(e.publicKey!=null||t.publicKey==null)return e;let r;e.type==="RSA"&&(r=e.toMultihash());let n=on(t.publicKey,r);return Na(n)}function dc(e,t,r){let n=Yt.decode(t);return $e(e,n,r)}function $e(e,t,r){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:id(e,t),addresses:t.addresses.filter(({observed:s})=>s!=null&&s>Date.now()-r).map(({multiaddr:s,isCertified:i})=>({multiaddr:ge(s),isCertified:i??!1})),metadata:t.metadata,peerRecordEnvelope:t.peerRecordEnvelope??void 0,tags:n}}function hc(e,t){return ad(e.addresses,t.addresses)&&cd(e.protocols,t.protocols)&&ud(e.publicKey,t.publicKey)&&ld(e.peerRecordEnvelope,t.peerRecordEnvelope)&&fd(e.metadata,t.metadata)&&dd(e.tags,t.tags)}function ad(e,t){return mc(e,t,(r,n)=>!(r.isCertified!==n.isCertified||!W(r.multiaddr,n.multiaddr)))}function cd(e,t){return mc(e,t,(r,n)=>r===n)}function ud(e,t){return pc(e,t)}function ld(e,t){return pc(e,t)}function fd(e,t){return yc(e,t,(r,n)=>W(r,n))}function dd(e,t){return yc(e,t,(r,n)=>r.value===n.value&&r.expiry===n.expiry)}function pc(e,t){return e==null&&t==null?!0:e!=null&&t!=null?W(e,t):!1}function mc(e,t,r){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!r(e[n],t[n]))return!1;return!0}function yc(e,t,r){if(e.size!==t.size)return!1;for(let[n,o]of e.entries()){let s=t.get(n);if(s==null||!r(o,s))return!1}return!0}var Xt="/",bc=new TextEncoder().encode(Xt),Kn=bc[0],Pn=class e{_buf;constructor(t,r){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(r==null&&(r=!0),r&&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 e(t.join(Xt))}static random(){return new e(Math.random().toString().substring(2))}static asKey(t){return t instanceof Uint8Array||typeof t=="string"?new e(t):typeof t.uint8Array=="function"?new e(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 r=this.list(),n=t.list();for(let o=0;o<r.length;o++){if(n.length<o+1)return!1;let s=r[o],i=n[o];if(s<i)return!0;if(s>i)return!1}return r.length<n.length}reverse(){return e.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let t=this.namespaces();return t[t.length-1]}list(){return this.toString().split(Xt).slice(1)}type(){return hd(this.baseNamespace())}name(){return pd(this.baseNamespace())}instance(t){return new e(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(Xt)||(t+=Xt),t+=this.type(),new e(t)}parent(){let t=this.list();return t.length===1?new e(Xt):new e(t.slice(0,-1).join(Xt))}child(t){return this.toString()===Xt?t:t.toString()===Xt?this:new e(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 e.withNamespaces([...this.namespaces(),...md(t.map(r=>r.namespaces()))])}};function hd(e){let t=e.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function pd(e){let t=e.split(":");return t[t.length-1]}function md(e){return[].concat(...e)}var qs="/peers/";function Br(e){if(!ve(e)||e.type==null)throw new q("Invalid PeerId");let t=e.toCID().toString();return new Pn(`${qs}${t}`)}async function gc(e,t,r,n,o){let s=new Map;for(let i of r){if(i==null)continue;if(i.multiaddr instanceof Uint8Array&&(i.multiaddr=ge(i.multiaddr)),!pn(i.multiaddr))throw new q("Multiaddr was invalid");if(!await t(e,i.multiaddr,o))continue;let a=i.isCertified??!1,c=i.multiaddr.toString(),l=s.get(c);l!=null?i.isCertified=l.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(l=>l.code===421)?.value;return e.equals(c)&&(a=a.decapsulate(ge(`/p2p/${e}`))),{isCertified:i,multiaddr:a.bytes}})}async function Un(e,t,r,n){if(t==null)throw new q("Invalid PeerData");if(t.publicKey!=null&&e.publicKey!=null&&!t.publicKey.equals(e.publicKey))throw new q("publicKey bytes do not match peer id publicKey bytes");let o=n.existingPeer?.peer;if(o!=null&&!e.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,l=o?.peerRecordEnvelope;if(r==="patch"){if((t.multiaddrs!=null||t.addresses!=null)&&(s=[],t.multiaddrs!=null&&s.push(...t.multiaddrs.map(f=>({isCertified:!1,multiaddr:f}))),t.addresses!=null&&s.push(...t.addresses)),t.protocols!=null&&(i=new Set(t.protocols)),t.metadata!=null){let f=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);a=Nn(f,{validate:xc})}if(t.tags!=null){let f=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags);c=Nn(f,{validate:wc,map:Ec})}t.peerRecordEnvelope!=null&&(l=t.peerRecordEnvelope)}if(r==="merge"){if(t.multiaddrs!=null&&s.push(...t.multiaddrs.map(f=>({isCertified:!1,multiaddr:f}))),t.addresses!=null&&s.push(...t.addresses),t.protocols!=null&&(i=new Set([...i,...t.protocols])),t.metadata!=null){let f=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);for(let[h,p]of f)p==null?a.delete(h):a.set(h,p);a=Nn([...a.entries()],{validate:xc})}if(t.tags!=null){let f=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags),h=new Map(c);for(let[p,E]of f)E==null?h.delete(p):h.set(p,E);c=Nn([...h.entries()],{validate:wc,map:Ec})}t.peerRecordEnvelope!=null&&(l=t.peerRecordEnvelope)}let u;o?.id.publicKey!=null?u=At(o.id.publicKey):t.publicKey!=null?u=At(t.publicKey):e.publicKey!=null&&(u=At(e.publicKey));let d={addresses:await gc(e,n.addressFilter??(async()=>!0),s,n.existingPeer?.peerPB.addresses,n),protocols:[...i.values()].sort((f,h)=>f.localeCompare(h)),metadata:a,tags:c,publicKey:u,peerRecordEnvelope:l};return d.addresses.forEach(f=>{f.observed=n.existingPeer?.peerPB.addresses?.find(h=>W(h.multiaddr,h.multiaddr))?.observed??Date.now()}),e.type!=="RSA"&&delete d.publicKey,d}function Nn(e,t){let r=new Map;for(let[n,o]of e)o!=null&&t.validate(n,o);for(let[n,o]of e.sort(([s],[i])=>s.localeCompare(i)))o!=null&&r.set(n,t.map?.(n,o)??o);return r}function xc(e,t){if(typeof e!="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(e,t){if(typeof e!="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(e,t){let r;t.expiry!=null&&(r=t.expiry),t.ttl!=null&&(r=BigInt(Date.now()+Number(t.ttl)));let n={value:t.value??0};return r!=null&&(n.expiry=r),n}function vc(e){let t=e.toString().split("/")[2],r=et.parse(t,Lt);return sn(r)}function Vs(e,t,r){let n=vc(e);return dc(n,t,r)}function yd(e,t){return{prefix:qs,filters:(e.filters??[]).map(r=>({key:n,value:o})=>r(Vs(n,o,t))),orders:(e.orders??[]).map(r=>(n,o)=>r(Vs(n.key,n.value,t),Vs(o.key,o.value,t)))}}var Mn=class{peerId;datastore;locks;addressFilter;log;maxAddressAge;maxPeerAge;constructor(t,r={}){this.log=t.logger.forComponent("libp2p:peer-store"),this.peerId=t.peerId,this.datastore=t.datastore,this.addressFilter=r.addressFilter,this.locks=Os({name:"libp2p_peer_store_locks",metrics:t.metrics}),this.maxAddressAge=r.maxAddressAge??36e5,this.maxPeerAge=r.maxPeerAge??216e5}getLock(t){let r=this.locks.get(t);return r==null&&(r={refs:0,lock:Ms({name:t.toString(),singleProcess:!0})},this.locks.set(t,r)),r.refs++,r}maybeRemoveLock(t,r){r.refs--,r.refs===0&&(r.lock.finalize(),this.locks.delete(t))}async getReadLock(t,r){let n=this.getLock(t);try{let o=await n.lock.readLock(r);return()=>{o(),this.maybeRemoveLock(t,n)}}catch(o){throw this.maybeRemoveLock(t,n),o}}async getWriteLock(t,r){let n=this.getLock(t);try{let o=await n.lock.writeLock(r);return()=>{o(),this.maybeRemoveLock(t,n)}}catch(o){throw this.maybeRemoveLock(t,n),o}}async has(t,r){try{return await this.load(t,r),!0}catch(n){if(n.name!=="NotFoundError")throw n}return!1}async delete(t,r){this.peerId.equals(t)||await this.datastore.delete(Br(t),r)}async load(t,r){let n=Br(t),o=await this.datastore.get(n,r),s=Yt.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,r),new We;return $e(t,s,this.peerId.equals(t)?1/0:this.maxAddressAge)}async save(t,r,n){let o=await this.#t(t,n),s=await Un(t,r,"patch",{...n,addressFilter:this.addressFilter});return this.#e(t,s,o)}async patch(t,r,n){let o=await this.#t(t,n),s=await Un(t,r,"patch",{...n,addressFilter:this.addressFilter,existingPeer:o});return this.#e(t,s,o)}async merge(t,r,n){let o=await this.#t(t,n),s=await Un(t,r,"merge",{addressFilter:this.addressFilter,existingPeer:o});return this.#e(t,s,o)}async*all(t){for await(let{key:r,value:n}of this.datastore.query(yd(t??{},this.maxAddressAge),t)){let o=vc(r);if(o.equals(this.peerId))continue;let s=Yt.decode(n);if(this.#r(o,s)){await this.datastore.delete(r,t);continue}yield $e(o,s,this.peerId.equals(o)?1/0:this.maxAddressAge)}}async#t(t,r){try{let n=Br(t),o=await this.datastore.get(n,r),s=Yt.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,r),new We;return{peerPB:s,peer:$e(t,s,this.maxAddressAge)}}catch(n){n.name!=="NotFoundError"&&this.log.error("invalid peer data found in peer store - %e",n)}}async#e(t,r,n,o){r.updated=Date.now();let s=Yt.encode(r);return await this.datastore.put(Br(t),s,o),{peer:$e(t,r,this.maxAddressAge),previous:n?.peer,updated:n==null||!hc(r,n.peerPB)}}#r(t,r){if(r.updated==null)return!0;if(this.peerId.equals(t))return!1;let n=r.updated<Date.now()-this.maxPeerAge,o=Date.now()-this.maxAddressAge,s=r.addresses.filter(i=>i.observed!=null&&i.observed>o);return n&&s.length===0}};var Hs=class{store;events;peerId;log;constructor(t,r={}){this.log=t.logger.forComponent("libp2p:peer-store"),this.events=t.events,this.peerId=t.peerId,this.store=new Mn(t,r)}[Symbol.toStringTag]="@libp2p/peer-store";async forEach(t,r){for await(let n of this.store.all(r))t(n)}async all(t){return nc(this.store.all(t))}async delete(t,r){let n=await this.store.getReadLock(t,r);try{await this.store.delete(t,r)}finally{n()}}async has(t,r){let n=await this.store.getReadLock(t,r);try{return await this.store.has(t,r)}finally{this.log.trace("has release read lock"),n?.()}}async get(t,r){let n=await this.store.getReadLock(t,r);try{return await this.store.load(t,r)}finally{n?.()}}async getInfo(t,r){let n=await this.get(t,r);return{id:n.id,multiaddrs:n.addresses.map(({multiaddr:o})=>o)}}async save(t,r,n){let o=await this.store.getWriteLock(t,n);try{let s=await this.store.save(t,r,n);return this.#t(t,s),s.peer}finally{o?.()}}async patch(t,r,n){let o=await this.store.getWriteLock(t,n);try{let s=await this.store.patch(t,r,n);return this.#t(t,s),s.peer}finally{o?.()}}async merge(t,r,n){let o=await this.store.getWriteLock(t,n);try{let s=await this.store.merge(t,r,n);return this.#t(t,s),s.peer}finally{o?.()}}async consumePeerRecord(t,r,n){let o=ve(r)?r:ve(r?.expectedPeer)?r.expectedPeer:void 0,s=ve(r)||r===void 0?n:r,i=await He.openAndCertify(t,xe.DOMAIN,s),a=sn(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=xe.createFromProtobuf(i.payload),l;try{l=await this.get(a,s)}catch(u){if(u.name!=="NotFoundError")throw u}if(l?.peerRecordEnvelope!=null){let u=He.createFromProtobuf(l.peerRecordEnvelope),d=xe.createFromProtobuf(u.payload);if(d.seqNumber>=c.seqNumber)return this.log("sequence number was lower or equal to existing sequence number - stored: %d received: %d",d.seqNumber,c.seqNumber),!1}return await this.patch(c.peerId,{peerRecordEnvelope:t,addresses:c.multiaddrs.map(u=>({isCertified:!0,multiaddr:u}))},s),!0}#t(t,r){r.updated&&(this.peerId.equals(t)?this.events.safeDispatchEvent("self:peer:update",{detail:r}):this.events.safeDispatchEvent("peer:update",{detail:r}))}};function bd(e,t={}){return new Hs(e,t)}return Cc(gd);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/hashes/utils.js:
|