@libp2p/peer-store 12.0.20 → 12.0.21-7ae12f9b0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/utils/bytes-to-peer.d.ts +1 -1
- package/dist/src/utils/bytes-to-peer.js +1 -1
- package/dist/src/utils/dedupe-addresses.d.ts +2 -2
- package/dist/src/utils/peer-equals.d.ts +1 -1
- package/dist/src/utils/to-peer-pb.d.ts +3 -3
- package/package.json +11 -11
- package/src/utils/bytes-to-peer.ts +1 -1
- package/src/utils/dedupe-addresses.ts +2 -2
- package/src/utils/peer-equals.ts +1 -1
- package/src/utils/to-peer-pb.ts +3 -3
- 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 so=Object.defineProperty;var Gc=Object.getOwnPropertyDescriptor;var Xc=Object.getOwnPropertyNames;var Qc=Object.prototype.hasOwnProperty;var wt=(e,t)=>{for(var r in t)so(e,r,{get:t[r],enumerable:!0})},Jc=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Xc(t))!Qc.call(e,o)&&o!==r&&so(e,o,{get:()=>t[o],enumerable:!(n=Gc(t,o))||n.enumerable});return e};var tu=e=>Jc(so({},"__esModule",{value:!0}),e);var Qd={};wt(Qd,{persistentPeerStore:()=>Xd});var F=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Re=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var er=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var Vr=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Hr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var he=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var $r=Symbol.for("@libp2p/peer-id");function Be(e){return!!e?.[$r]}function eu(e){return typeof e?.handleEvent=="function"}function ru(e){return(e!==!0&&e!==!1&&e?.once)??!1}var Ce=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){let o=ru(n);super.addEventListener(t,i=>{if(o){let a=this.#t.get(i.type);a!=null&&(a=a.filter(({callback:c})=>c!==r),this.#t.set(i.type,a))}eu(r)?r.handleEvent(i):r(i)},n);let s=this.#t.get(t);s==null&&(s=[],this.#t.set(t,s)),s.push({callback:r,once:o})}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))}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var fo={};wt(fo,{base58btc:()=>G,base58flickr:()=>uu});var nh=new Uint8Array(0);function mi(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 zt(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 yi(e){return new TextEncoder().encode(e)}function bi(e){return new TextDecoder().decode(e)}function nu(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),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(y){if(y instanceof Uint8Array||(ArrayBuffer.isView(y)?y=new Uint8Array(y.buffer,y.byteOffset,y.byteLength):Array.isArray(y)&&(y=Uint8Array.from(y))),!(y instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(y.length===0)return"";for(var g=0,p=0,b=0,v=y.length;b!==v&&y[b]===0;)b++,g++;for(var A=(v-b)*f+1>>>0,D=new Uint8Array(A);b!==v;){for(var B=y[b],k=0,L=A-1;(B!==0||k<p)&&L!==-1;L--,k++)B+=256*D[L]>>>0,D[L]=B%a>>>0,B=B/a>>>0;if(B!==0)throw new Error("Non-zero carry");p=k,b++}for(var I=A-p;I!==A&&D[I]===0;)I++;for(var P=c.repeat(g);I<A;++I)P+=e.charAt(D[I]);return P}function d(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return new Uint8Array;var g=0;if(y[g]!==" "){for(var p=0,b=0;y[g]===c;)p++,g++;for(var v=(y.length-g)*u+1>>>0,A=new Uint8Array(v);y[g];){var D=r[y.charCodeAt(g)];if(D===255)return;for(var B=0,k=v-1;(D!==0||B<b)&&k!==-1;k--,B++)D+=a*A[k]>>>0,A[k]=D%256>>>0,D=D/256>>>0;if(D!==0)throw new Error("Non-zero carry");b=B,g++}if(y[g]!==" "){for(var L=v-b;L!==v&&A[L]===0;)L++;for(var I=new Uint8Array(p+(v-L)),P=p;L!==v;)I[P++]=A[L++];return I}}}function h(y){var g=d(y);if(g)return g;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:d,decode:h}}var ou=nu,su=ou,wi=su;var io=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")}},ao=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 xi(this,t)}},co=class{decoders;constructor(t){this.decoders=t}or(t){return xi(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 xi(e,t){return new co({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var uo=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 io(t,r,n),this.decoder=new ao(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function De({name:e,prefix:t,encode:r,decode:n}){return new uo(e,t,r,n)}function te({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=wi(r,e);return De({prefix:t,name:e,encode:n,decode:s=>zt(o(s))})}function iu(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 u=0;u<o;++u){let f=t[e[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function au(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 cu(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function Y({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=cu(n);return De({prefix:t,name:e,encode(s){return au(s,n,r)},decode(s){return iu(s,o,r,e)}})}var G=te({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),uu=te({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var lo={};wt(lo,{base32:()=>Kt,base32hex:()=>hu,base32hexpad:()=>mu,base32hexpadupper:()=>yu,base32hexupper:()=>pu,base32pad:()=>lu,base32padupper:()=>du,base32upper:()=>fu,base32z:()=>bu});var Kt=Y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),fu=Y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),lu=Y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),du=Y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),hu=Y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),pu=Y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),mu=Y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),yu=Y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),bu=Y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ho={};wt(ho,{base36:()=>rr,base36upper:()=>gu});var rr=te({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),gu=te({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var wu=Si,Ei=128,xu=127,Eu=~xu,vu=Math.pow(2,31);function Si(e,t,r){t=t||[],r=r||0;for(var n=r;e>=vu;)t[r++]=e&255|Ei,e/=128;for(;e&Eu;)t[r++]=e&255|Ei,e>>>=7;return t[r]=e|0,Si.bytes=r-n+1,t}var Su=po,Au=128,vi=127;function po(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw po.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&vi)<<o:(i&vi)*Math.pow(2,o),o+=7}while(i>=Au);return po.bytes=s-n,r}var _u=Math.pow(2,7),Tu=Math.pow(2,14),Iu=Math.pow(2,21),Ru=Math.pow(2,28),Bu=Math.pow(2,35),Cu=Math.pow(2,42),Du=Math.pow(2,49),Lu=Math.pow(2,56),Ou=Math.pow(2,63),ku=function(e){return e<_u?1:e<Tu?2:e<Iu?3:e<Ru?4:e<Bu?5:e<Cu?6:e<Du?7:e<Lu?8:e<Ou?9:10},Pu={encode:wu,decode:Su,encodingLength:ku},Ku=Pu,nr=Ku;function or(e,t=0){return[nr.decode(e,t),nr.decode.bytes]}function Le(e,t,r=0){return nr.encode(e,t,r),t}function Oe(e){return nr.encodingLength(e)}function Nt(e,t){let r=t.byteLength,n=Oe(e),o=n+Oe(r),s=new Uint8Array(o+r);return Le(e,s,0),Le(r,s,n),s.set(t,o),new ke(e,r,t,s)}function Pe(e){let t=zt(e),[r,n]=or(t),[o,s]=or(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ke(r,o,i,t)}function Ai(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&mi(e.bytes,r.bytes)}}var ke=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function _i(e,t){let{bytes:r,version:n}=e;return n===0?Uu(r,mo(e),t??G.encoder):Fu(r,mo(e),t??Kt.encoder)}var Ti=new WeakMap;function mo(e){let t=Ti.get(e);if(t==null){let r=new Map;return Ti.set(e,r),r}return t}var tt=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!==sr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Mu)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=Nt(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&&Ai(t.multihash,n.multihash)}toString(t){return _i(this,t)}toJSON(){return{"/":_i(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??Ii(n,o,s.bytes))}else if(r[qu]===!0){let{version:n,multihash:o,code:s}=r,i=Pe(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!==sr)throw new Error(`Version 0 CID must use dag-pb (code: ${sr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Ii(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,sr,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=zt(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 ke(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,d]=or(t.subarray(r));return r+=d,l},o=n(),s=sr;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,r){let[n,o]=Nu(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 mo(s).set(n,t),s}};function Nu(e,t){switch(e[0]){case"Q":{let r=t??G;return[G.prefix,r.decode(`${G.prefix}${e}`)]}case G.prefix:{let r=t??G;return[G.prefix,r.decode(e)]}case Kt.prefix:{let r=t??Kt;return[Kt.prefix,r.decode(e)]}case rr.prefix:{let r=t??rr;return[rr.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!==G.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 Fu(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 sr=112,Mu=18;function Ii(e,t,r){let n=Oe(e),o=n+Oe(t),s=new Uint8Array(o+r.byteLength);return Le(e,s,0),Le(t,s,n),s.set(r,o),s}var qu=Symbol.for("@ipld/js-cid/CID");var yo={};wt(yo,{identity:()=>Bt});var Ri=0,zu="identity",Bi=zt;function Vu(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 Nt(Ri,Bi(e))}var Bt={code:Ri,name:zu,encode:Bi,digest:Vu};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}async function Ci(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),s}function et(e=0){return new Uint8Array(e)}function xt(e=0){return new Uint8Array(e)}function Vt(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 Li=Symbol.for("@achingbrain/uint8arraylist");function Di(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 jr(e){return!!e?.[Li]}var ht=class e{bufs;length;[Li]=!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(jr(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(jr(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=Di(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Di(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(jr(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 Vt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Vt(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 u=t>=a&&t<c,f=r>a&&r<=c;if(u&&f){if(t===a&&r===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!jr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let d=u;d>=0;d--){let h=this.get(l+d);if(n[d]!==h){f=Math.max(1,d-a[h]);break}}if(f===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=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=et(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=et(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=et(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=et(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=et(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=et(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=et(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=et(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 bo={};wt(bo,{base10:()=>Hu});var Hu=te({prefix:"9",name:"base10",alphabet:"0123456789"});var go={};wt(go,{base16:()=>$u,base16upper:()=>Wu});var $u=Y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Wu=Y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var wo={};wt(wo,{base2:()=>ju});var ju=Y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var xo={};wt(xo,{base256emoji:()=>Qu});var Oi=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}"),Zu=Oi.reduce((e,t,r)=>(e[r]=t,e),[]),Yu=Oi.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Gu(e){return e.reduce((t,r)=>(t+=Zu[r],t),"")}function Xu(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Yu[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Qu=De({prefix:"\u{1F680}",name:"base256emoji",encode:Gu,decode:Xu});var vo={};wt(vo,{base64:()=>Ju,base64pad:()=>tf,base64url:()=>Eo,base64urlpad:()=>ef});var Ju=Y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),tf=Y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Eo=Y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ef=Y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var So={};wt(So,{base8:()=>rf});var rf=Y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ao={};wt(Ao,{identity:()=>nf});var nf=De({prefix:"\0",name:"identity",encode:e=>bi(e),decode:e=>yi(e)});var qh=new TextEncoder,zh=new TextDecoder;var Io={};wt(Io,{sha256:()=>ir,sha512:()=>cf});var af=20;function To({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new _o(e,t,r,n,o)}var _o=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??af,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?ki(n,this.code,r?.truncate):n.then(o=>ki(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function ki(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 Nt(t,e)}function Ki(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var ir=To({name:"sha2-256",code:18,encode:Ki("SHA-256")}),cf=To({name:"sha2-512",code:19,encode:Ki("SHA-512")});var ar={...Ao,...wo,...So,...bo,...go,...lo,...ho,...fo,...vo,...xo},tp={...Io,...yo};function Ui(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Ni=Ui("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Ro=Ui("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}),uf={utf8:Ni,"utf-8":Ni,hex:ar.base16,latin1:Ro,ascii:Ro,binary:Ro,...ar},Zr=uf;function V(e,t="utf8"){let r=Zr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function q(e,t="utf8"){let r=Zr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var ff=parseInt("11111",2),Bo=parseInt("10000000",2),lf=parseInt("01111111",2),Fi={0:cr,1:cr,2:df,3:mf,4:yf,5:pf,6:hf,16:cr,22:cr,48:cr};function Ht(e,t={offset:0}){let r=e[t.offset]&ff;if(t.offset++,Fi[r]!=null)return Fi[r](e,t);throw new Error("No decoder for tag "+r)}function ur(e,t){let r=0;if((e[t.offset]&Bo)===Bo){let n=e[t.offset]&lf,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 cr(e,t){ur(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Ht(e,t);if(n===null)break;r.push(n)}return r}function df(e,t){let r=ur(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 hf(e,t){let r=ur(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 u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function pf(e,t){return t.offset++,null}function mf(e,t){let r=ur(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 yf(e,t){let r=ur(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function bf(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new ht;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Co(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=bf(e.byteLength);return new ht(Uint8Array.from([t.byteLength|Bo]),t)}function Et(e){let t=new ht,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new ht(Uint8Array.from([2]),Co(t),t)}function Yr(e){let t=Uint8Array.from([0]),r=new ht(t,e);return new ht(Uint8Array.from([3]),Co(r),r)}function re(e,t=48){let r=new ht;for(let n of e)r.append(n);return new ht(Uint8Array.from([t]),Co(r),r)}var gf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),wf=Uint8Array.from([6,5,43,129,4,0,34]),xf=Uint8Array.from([6,5,43,129,4,0,35]),Ef={ext:!0,kty:"EC",crv:"P-256"},vf={ext:!0,kty:"EC",crv:"P-384"},Sf={ext:!0,kty:"EC",crv:"P-521"},Do=32,Lo=48,Oo=66;function ko(e){let t=Ht(e);return Mi(t)}function Mi(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Do*2+1)return n=q(t.subarray(r,r+Do),"base64url"),o=q(t.subarray(r+Do),"base64url"),new Ke({...Ef,key_ops:["verify"],x:n,y:o});if(t.byteLength===Lo*2+1)return n=q(t.subarray(r,r+Lo),"base64url"),o=q(t.subarray(r+Lo),"base64url"),new Ke({...vf,key_ops:["verify"],x:n,y:o});if(t.byteLength===Oo*2+1)return n=q(t.subarray(r,r+Oo),"base64url"),o=q(t.subarray(r+Oo),"base64url"),new Ke({...Sf,key_ops:["verify"],x:n,y:o});throw new F(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function qi(e){return re([Et(Uint8Array.from([1])),re([Af(e.crv)],160),re([Yr(new ht(Uint8Array.from([4]),V(e.x??"","base64url"),V(e.y??"","base64url")))],161)]).subarray()}function Af(e){if(e==="P-256")return gf;if(e==="P-384")return wf;if(e==="P-521")return xf;throw new F(`Invalid curve ${e}`)}var Ke=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=qi(this.jwk)),this._raw}toMultihash(){return Bt.digest(_t(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return G.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 Ci(this.jwk,r,t,n)}};function Po(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}function ne(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(`${r}expected number, got ${typeof e}`)}if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new RangeError(`${r}expected integer >= 0, got ${e}`)}}function vt(e,t,r=""){let n=Po(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}`,u=i+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(u):new TypeError(u)}return e}function Gr(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(ne(e.outputLen),ne(e.blockLen),e.outputLen<1)throw new Error('"outputLen" must be >= 1');if(e.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Ne(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 Xr(e,t){vt(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function Wt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Qr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Ct(e,t){return e<<32-t|e>>>t}var Vi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",_f=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Jr(e){if(vt(e),Vi)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=_f[e[r]];return t}var $t={_0:48,_9:57,A:65,F:70,a:97,f:102};function zi(e){if(e>=$t._0&&e<=$t._9)return e-$t._0;if(e>=$t.A&&e<=$t.F)return e-($t.A-10);if(e>=$t.a&&e<=$t.f)return e-($t.a-10)}function fr(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(Vi)try{return Uint8Array.fromHex(e)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let t=e.length,r=t/2;if(t%2)throw new RangeError("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=zi(e.charCodeAt(s)),a=zi(e.charCodeAt(s+1));if(i===void 0||a===void 0){let c=e[s]+e[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Ko(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];vt(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 No(e,t={}){let r=(o,s)=>e(s).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function Hi(e=32){ne(e,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(e>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}var Uo=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function $i(e,t,r){return e&t^~e&r}function Wi(e,t,r){return e&t^e&r^t&r}var lr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,o){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Qr(this.buffer)}update(t){Ne(this),vt(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=Qr(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){Ne(this),Xr(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Wt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=Qr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},jt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ct=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var tn=BigInt(4294967295),ji=BigInt(32);function Tf(e,t=!1){return t?{h:Number(e&tn),l:Number(e>>ji&tn)}:{h:Number(e>>ji&tn)|0,l:Number(e&tn)|0}}function Zi(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=Tf(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Fo=(e,t,r)=>e>>>r,Mo=(e,t,r)=>e<<32-r|t>>>r,pe=(e,t,r)=>e>>>r|t<<32-r,me=(e,t,r)=>e<<32-r|t>>>r,dr=(e,t,r)=>e<<64-r|t>>>r-32,hr=(e,t,r)=>e>>>r-32|t<<64-r;function Ut(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Yi=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Gi=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Xi=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Qi=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Ji=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),ta=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var Rf=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),oe=new Uint32Array(64),qo=class extends lr{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 l=0;l<16;l++,r+=4)oe[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let d=oe[l-15],h=oe[l-2],y=Ct(d,7)^Ct(d,18)^d>>>3,g=Ct(h,17)^Ct(h,19)^h>>>10;oe[l]=g+oe[l-7]+y+oe[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let d=Ct(a,6)^Ct(a,11)^Ct(a,25),h=f+d+$i(a,c,u)+Rf[l]+oe[l]|0,g=(Ct(n,2)^Ct(n,13)^Ct(n,22))+Wi(n,o,s)|0;f=u,u=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+g|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,u,f)}roundClean(){Wt(oe)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Wt(this.buffer)}},zo=class extends qo{A=jt[0]|0;B=jt[1]|0;C=jt[2]|0;D=jt[3]|0;E=jt[4]|0;F=jt[5]|0;G=jt[6]|0;H=jt[7]|0;constructor(){super(32)}};var ea=Zi(["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))),Bf=ea[0],Cf=ea[1],se=new Uint32Array(80),ie=new Uint32Array(80),Vo=class extends lr{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:u,El:f,Fh:l,Fl:d,Gh:h,Gl:y,Hh:g,Hl:p}=this;return[t,r,n,o,s,i,a,c,u,f,l,d,h,y,g,p]}set(t,r,n,o,s,i,a,c,u,f,l,d,h,y,g,p){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=u|0,this.El=f|0,this.Fh=l|0,this.Fl=d|0,this.Gh=h|0,this.Gl=y|0,this.Hh=g|0,this.Hl=p|0}process(t,r){for(let A=0;A<16;A++,r+=4)se[A]=t.getUint32(r),ie[A]=t.getUint32(r+=4);for(let A=16;A<80;A++){let D=se[A-15]|0,B=ie[A-15]|0,k=pe(D,B,1)^pe(D,B,8)^Fo(D,B,7),L=me(D,B,1)^me(D,B,8)^Mo(D,B,7),I=se[A-2]|0,P=ie[A-2]|0,$=pe(I,P,19)^dr(I,P,61)^Fo(I,P,6),K=me(I,P,19)^hr(I,P,61)^Mo(I,P,6),m=Xi(L,K,ie[A-7],ie[A-16]),w=Qi(m,k,$,se[A-7],se[A-16]);se[A]=w|0,ie[A]=m|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:d,Fh:h,Fl:y,Gh:g,Gl:p,Hh:b,Hl:v}=this;for(let A=0;A<80;A++){let D=pe(l,d,14)^pe(l,d,18)^dr(l,d,41),B=me(l,d,14)^me(l,d,18)^hr(l,d,41),k=l&h^~l&g,L=d&y^~d&p,I=Ji(v,B,L,Cf[A],ie[A]),P=ta(I,b,D,k,Bf[A],se[A]),$=I|0,K=pe(n,o,28)^dr(n,o,34)^dr(n,o,39),m=me(n,o,28)^hr(n,o,34)^hr(n,o,39),w=n&s^n&a^s&a,S=o&i^o&c^i&c;b=g|0,v=p|0,g=h|0,p=y|0,h=l|0,y=d|0,{h:l,l:d}=Ut(u|0,f|0,P|0,$|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let E=Yi($,m,S);n=Gi(E,P,K,w),o=E|0}({h:n,l:o}=Ut(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ut(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Ut(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Ut(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:d}=Ut(this.Eh|0,this.El|0,l|0,d|0),{h,l:y}=Ut(this.Fh|0,this.Fl|0,h|0,y|0),{h:g,l:p}=Ut(this.Gh|0,this.Gl|0,g|0,p|0),{h:b,l:v}=Ut(this.Hh|0,this.Hl|0,b|0,v|0),this.set(n,o,s,i,a,c,u,f,l,d,h,y,g,p,b,v)}roundClean(){Wt(se,ie)}destroy(){this.destroyed=!0,Wt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Ho=class extends Vo{Ah=ct[0]|0;Al=ct[1]|0;Bh=ct[2]|0;Bl=ct[3]|0;Ch=ct[4]|0;Cl=ct[5]|0;Dh=ct[6]|0;Dl=ct[7]|0;Eh=ct[8]|0;El=ct[9]|0;Fh=ct[10]|0;Fl=ct[11]|0;Gh=ct[12]|0;Gl=ct[13]|0;Hh=ct[14]|0;Hl=ct[15]|0;constructor(){super(64)}};var Ue=No(()=>new zo,Uo(1));var en=No(()=>new Ho,Uo(3));var M=(e,t,r)=>vt(e,t,r),Wo=ne,Fe=Jr,nt=(...e)=>Ko(...e),Me=e=>fr(e),ye=Po,pr=e=>Hi(e),nn=BigInt(0),$o=BigInt(1);function Dt(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new TypeError(r+"expected boolean, got type="+typeof e)}return e}function on(e){if(typeof e=="bigint"){if(!rn(e))throw new RangeError("positive bigint expected, got "+e)}else Wo(e);return e}function Lt(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(r+"expected number, got type="+typeof e)}if(!Number.isSafeInteger(e)){let r=t&&`"${t}" `;throw new RangeError(r+"expected safe integer, got "+e)}}function mr(e){let t=on(e).toString(16);return t.length&1?"0"+t:t}function ra(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?nn:BigInt("0x"+e)}function be(e){return ra(Jr(e))}function Ft(e){return ra(Jr(yr(vt(e)).reverse()))}function sn(e,t){if(ne(t),t===0)throw new RangeError("zero length");e=on(e);let r=e.toString(16);if(r.length>t*2)throw new RangeError("number too large");return fr(r.padStart(t*2,"0"))}function jo(e,t){return sn(e,t).reverse()}function na(e,t){if(e=M(e),t=M(t),e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function yr(e){return Uint8Array.from(M(e))}function an(e){if(typeof e!="string")throw new TypeError("ascii string expected, got "+typeof e);return Uint8Array.from(e,(t,r)=>{let n=t.charCodeAt(0);if(t.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${e[r]}" with code ${n} at position ${r}`);return n})}var rn=e=>typeof e=="bigint"&&nn<=e;function Df(e,t,r){return rn(e)&&rn(t)&&rn(r)&&t<=e&&e<r}function qe(e,t,r,n){if(!Df(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function ze(e){if(e<nn)throw new Error("expected non-negative bigint, got "+e);let t;for(t=0;e>nn;e>>=$o,t+=1);return t}var br=e=>($o<<BigInt(e))-$o;function oa(e,t,r){if(ne(e,"hashLen"),ne(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=p=>new Uint8Array(p),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(e),u=n(e),f=0,l=()=>{c.fill(1),u.fill(0),f=0},d=(...p)=>r(u,nt(c,...p)),h=(p=o)=>{u=d(s,p),c=d(),p.length!==0&&(u=d(i,p),c=d())},y=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let p=0,b=[];for(;p<t;){c=d();let v=c.slice();b.push(v),p+=c.length}return nt(...b)};return(p,b)=>{l(),h(p);let v;for(;(v=b(y()))===void 0;)h();return l(),v}}function Ot(e,t={},r={}){if(Object.prototype.toString.call(e)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,i,a){if(!a&&i!=="function"&&!Object.hasOwn(e,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let c=e[s];if(a&&c===void 0)return;let u=typeof c;if(u!==i||c===null)throw new TypeError(`param "${s}" is invalid: expected ${i}, got ${u}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(t,!1),o(r,!0)}var Zo=()=>{throw new Error("not implemented")};var ut=BigInt(0),X=BigInt(1),ge=BigInt(2),ca=BigInt(3),ua=BigInt(4),fa=BigInt(5),Lf=BigInt(7),la=BigInt(8),Of=BigInt(9),da=BigInt(16);function J(e,t){if(t<=ut)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=ut?r:t+r}function j(e,t,r){if(t<ut)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >ut;)n*=n,n%=r;return n}function sa(e,t){if(e===ut)throw new Error("invert: expected non-zero number");if(t<=ut)throw new Error("invert: expected positive modulus, got "+t);let r=J(e,t),n=t,o=ut,s=X,i=X,a=ut;for(;r!==ut;){let u=n/r,f=n-r*u,l=o-i*u,d=s-a*u;n=r,r=f,o=i,s=a,i=l,a=d}if(n!==X)throw new Error("invert: does not exist");return J(o,t)}function Yo(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function ha(e,t){let r=e,n=(r.ORDER+X)/ua,o=r.pow(t,n);return Yo(r,o,t),o}function kf(e,t){let r=e,n=(r.ORDER-fa)/la,o=r.mul(t,ge),s=r.pow(o,n),i=r.mul(t,s),a=r.mul(r.mul(i,ge),s),c=r.mul(i,r.sub(a,r.ONE));return Yo(r,c,t),c}function Pf(e){let t=Ve(e),r=pa(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+Lf)/da;return((a,c)=>{let u=a,f=u.pow(c,i),l=u.mul(f,n),d=u.mul(f,o),h=u.mul(f,s),y=u.eql(u.sqr(l),c),g=u.eql(u.sqr(d),c);f=u.cmov(f,l,y),l=u.cmov(h,d,g);let p=u.eql(u.sqr(l),c),b=u.cmov(f,l,p);return Yo(u,b,c),b})}function pa(e){if(e<ca)throw new Error("sqrt is not defined for small field");let t=e-X,r=0;for(;t%ge===ut;)t/=ge,r++;let n=ge,o=Ve(e);for(;ia(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return ha;let s=o.pow(n,t),i=(t+X)/ge;return function(c,u){let f=c;if(f.is0(u))return u;if(ia(f,u)!==1)throw new Error("Cannot find square root");let l=r,d=f.mul(f.ONE,s),h=f.pow(u,t),y=f.pow(u,i);for(;!f.eql(h,f.ONE);){if(f.is0(h))return f.ZERO;let g=1,p=f.sqr(h);for(;!f.eql(p,f.ONE);)if(g++,p=f.sqr(p),g===l)throw new Error("Cannot find square root");let b=X<<BigInt(l-g-1),v=f.pow(d,b);l=g,d=f.sqr(v),h=f.mul(h,d),y=f.mul(y,v)}return y}}function Kf(e){return e%ua===ca?ha:e%la===fa?kf:e%da===Of?Pf(e):pa(e)}var Zt=(e,t)=>(J(e,t)&X)===X,Nf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Go(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=Nf.reduce((n,o)=>(n[o]="function",n),t);if(Ot(e,r),Lt(e.BYTES,"BYTES"),Lt(e.BITS,"BITS"),e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=X)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function Uf(e,t,r){let n=e;if(r<ut)throw new Error("invalid exponent, negatives unsupported");if(r===ut)return n.ONE;if(r===X)return t;let o=n.ONE,s=t;for(;r>ut;)r&X&&(o=n.mul(o,s)),s=n.sqr(s),r>>=X;return o}function gr(e,t,r=!1){let n=e,o=new Array(t.length).fill(r?n.ZERO:void 0),s=t.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return t.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),i),o}function ia(e,t){let r=e,n=(r.ORDER-X)/ge,o=r.pow(t,n),s=r.eql(o,r.ONE),i=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function Ff(e,t){if(t!==void 0&&Wo(t),e<=ut)throw new Error("invalid n length: expected positive n, got "+e);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let r=ze(e);if(t!==void 0&&t<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${t})`);let n=t!==void 0?t:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var aa=new WeakMap,cn=class{ORDER;BITS;BYTES;isLE;ZERO=ut;ONE=X;_lengths;_mod;constructor(t,r={}){if(t<=X)throw new Error("invalid field: expected ORDER > 1, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=Ff(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(t){return J(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return ut<=t&&t<this.ORDER}is0(t){return t===ut}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&X)===X}neg(t){return J(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return J(t*t,this.ORDER)}add(t,r){return J(t+r,this.ORDER)}sub(t,r){return J(t-r,this.ORDER)}mul(t,r){return J(t*r,this.ORDER)}pow(t,r){return Uf(this,t,r)}div(t,r){return J(t*sa(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 sa(t,this.ORDER)}sqrt(t){let r=aa.get(this);return r||aa.set(this,r=Kf(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?jo(t,this.BYTES):sn(t,this.BYTES)}fromBytes(t,r=!1){M(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(t.length<1||!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let u=new Uint8Array(o);u.set(t,s?0:u.length-t.length),t=u}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=s?Ft(t):be(t);if(a&&(c=J(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return gr(this,t)}cmov(t,r,n){return Dt(n,"condition"),n?r:t}};Object.freeze(cn.prototype);function Ve(e,t={}){return new cn(e,t)}function ma(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=X)throw new Error("field order must be greater than 1");let t=ze(e-X);return Math.ceil(t/8)}function Xo(e){let t=ma(e);return t+Math.ceil(t/2)}function Qo(e,t,r=!1){M(e);let n=e.length,o=ma(t),s=Math.max(Xo(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Ft(e):be(e),a=J(i,t-X)+X;return r?jo(a,o):sn(a,o)}var He=BigInt(0),we=BigInt(1);function wr(e,t){let r=t.negate();return e?r:t}function xe(e,t){let r=gr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function wa(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Jo(e,t){wa(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=br(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function ya(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+=we);let u=t*n,f=u+Math.abs(a)-1,l=a===0,d=a<0,h=t%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:d,isNegF:h,offsetF:u}}var ts=new WeakMap,xa=new WeakMap;function es(e){return xa.get(e)||1}function ba(e){if(e!==He)throw new Error("invalid wNAF")}var $e=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>He;)r&we&&(n=n.add(o)),o=o.double(),r>>=we;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=Jo(r,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let u=1;u<o;u++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Jo(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:l,isNegF:d,offsetF:h}=ya(n,a,i);n=c,f?s=s.add(wr(d,r[h])):o=o.add(wr(l,r[u]))}return ba(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=Jo(t,this.bits);for(let i=0;i<s.windows&&n!==He;i++){let{nextN:a,offset:c,isZero:u,isNeg:f}=ya(n,i,s);if(n=a,!u){let l=r[c];o=o.add(f?l.negate():l)}}return ba(n),o}getPrecomputes(t,r,n){let o=ts.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),ts.set(r,o))),o}cached(t,r,n){let o=es(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=es(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){wa(r,this.bits),xa.set(t,r),ts.delete(t)}hasCache(t){return es(t)!==1}};function Ea(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>He||n>He;)r&we&&(s=s.add(o)),n&we&&(i=i.add(o)),o=o.double(),r>>=we,n>>=we;return{p1:s,p2:i}}function ga(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Go(t),t}else return Ve(e,{isLE:r})}function un(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 u=t[c];if(!(typeof u=="bigint"&&u>He))throw new Error(`CURVE.${c} must be positive bigint`)}let o=ga(t.p,r.Fp,n),s=ga(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 fn(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var ae=BigInt(0),it=BigInt(1),rs=BigInt(2),Mf=BigInt(8);function qf(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 va(e,t={}){let r=t,n=un("edwards",e,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;Ot(r,{},{uvRatio:"function"});let c=rs<<BigInt(s.BYTES*8)-it,u=g=>o.create(g),f=r.uvRatio===void 0?(g,p)=>{try{return{isValid:!0,value:o.sqrt(o.div(g,p))}}catch{return{isValid:!1,value:ae}}}:r.uvRatio;if(!qf(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function l(g,p,b=!1){let v=b?it:ae;return qe("coordinate "+g,p,v,c),p}function d(g){if(!(g instanceof h))throw new Error("EdwardsPoint expected")}class h{static BASE=new h(i.Gx,i.Gy,it,u(i.Gx*i.Gy));static ZERO=new h(ae,it,it,ae);static Fp=o;static Fn=s;X;Y;Z;T;constructor(p,b,v,A){this.X=l("x",p),this.Y=l("y",b),this.Z=l("z",v,!0),this.T=l("t",A),Object.freeze(this)}static CURVE(){return i}static fromAffine(p){if(p instanceof h)throw new Error("extended point not allowed");let{x:b,y:v}=p||{};return l("x",b),l("y",v),new h(b,v,it,u(b*v))}static fromBytes(p,b=!1){let v=o.BYTES,{a:A,d:D}=i;p=yr(M(p,v,"point")),Dt(b,"zip215");let B=yr(p),k=p[v-1];B[v-1]=k&-129;let L=Ft(B),I=b?c:o.ORDER;qe("point.y",L,ae,I);let P=u(L*L),$=u(P-it),K=u(D*P-A),{isValid:m,value:w}=f($,K);if(!m)throw new Error("bad point: invalid y coordinate");let S=(w&it)===it,E=(k&128)!==0;if(!b&&w===ae&&E)throw new Error("bad point: x=0 and x_0=1");return E!==S&&(w=u(-w)),h.fromAffine({x:w,y:L})}static fromHex(p,b=!1){return h.fromBytes(Me(p),b)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=8,b=!0){return y.createCache(this,p),b||this.multiply(rs),this}assertValidity(){let p=this,{a:b,d:v}=i;if(p.is0())throw new Error("bad point: ZERO");let{X:A,Y:D,Z:B,T:k}=p,L=u(A*A),I=u(D*D),P=u(B*B),$=u(P*P),K=u(L*b),m=u(P*u(K+I)),w=u($+u(v*u(L*I)));if(m!==w)throw new Error("bad point: equation left != right (1)");let S=u(A*D),E=u(B*k);if(S!==E)throw new Error("bad point: equation left != right (2)")}equals(p){d(p);let{X:b,Y:v,Z:A}=this,{X:D,Y:B,Z:k}=p,L=u(b*k),I=u(D*A),P=u(v*k),$=u(B*A);return L===I&&P===$}is0(){return this.equals(h.ZERO)}negate(){return new h(u(-this.X),this.Y,this.Z,u(-this.T))}double(){let{a:p}=i,{X:b,Y:v,Z:A}=this,D=u(b*b),B=u(v*v),k=u(rs*u(A*A)),L=u(p*D),I=b+v,P=u(u(I*I)-D-B),$=L+B,K=$-k,m=L-B,w=u(P*K),S=u($*m),E=u(P*m),x=u(K*$);return new h(w,S,x,E)}add(p){d(p);let{a:b,d:v}=i,{X:A,Y:D,Z:B,T:k}=this,{X:L,Y:I,Z:P,T:$}=p,K=u(A*L),m=u(D*I),w=u(k*v*$),S=u(B*P),E=u((A+D)*(L+I)-K-m),x=S-w,_=S+w,R=u(m-b*K),T=u(E*x),C=u(_*R),O=u(E*R),U=u(x*_);return new h(T,C,U,O)}subtract(p){return d(p),this.add(p.negate())}multiply(p){if(!s.isValidNot0(p))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:b,f:v}=y.cached(this,p,A=>xe(h,A));return xe(h,[b,v])[0]}multiplyUnsafe(p){if(!s.isValid(p))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return p===ae?h.ZERO:this.is0()||p===it?this:y.unsafe(this,p,b=>xe(h,b))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return y.unsafe(this,i.n).is0()}toAffine(p){let b=this,v=p,{X:A,Y:D,Z:B}=b,k=b.is0();v==null&&(v=k?Mf:o.inv(B));let L=u(A*v),I=u(D*v),P=o.mul(B,v);if(k)return{x:ae,y:it};if(P!==it)throw new Error("invZ was invalid");return{x:L,y:I}}clearCofactor(){return a===it?this:this.multiplyUnsafe(a)}toBytes(){let{x:p,y:b}=this.toAffine(),v=o.toBytes(b);return v[v.length-1]|=p&it?128:0,v}toHex(){return Fe(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let y=new $e(h,s.BITS);return s.BITS>=8&&h.BASE.precompute(8),Object.freeze(h.prototype),Object.freeze(h),h}var ln=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(t){this.ep=t}static fromBytes(t){Zo()}static fromHex(t){Zo()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return Fe(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.ep.precompute(t,r),this}};function Sa(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=r;Ot(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=e,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(Lt(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=o.randomBytes===void 0?pr:o.randomBytes,d=o.adjustScalarBytes===void 0?m=>m:o.adjustScalarBytes,h=o.domain===void 0?(m,w,S)=>{if(Dt(S,"phflag"),w.length||S)throw new Error("Contexts/pre-hash are not supported");return m}:o.domain;function y(m){return c.create(Ft(m))}function g(m){let w=L.secretKey;M(m,L.secretKey,"secretKey");let S=M(n(m),2*w,"hashedSecretKey"),E=d(S.slice(0,w)),x=S.slice(w,2*w),_=y(E);return{head:E,prefix:x,scalar:_}}function p(m){let{head:w,prefix:S,scalar:E}=g(m),x=i.multiply(E),_=x.toBytes();return{head:w,prefix:S,scalar:E,point:x,pointBytes:_}}function b(m){return p(m).pointBytes}function v(m=Uint8Array.of(),...w){let S=nt(...w);return y(n(h(S,M(m,void 0,"context"),!!s)))}function A(m,w,S={}){m=M(m,void 0,"message"),s&&(m=s(m));let{prefix:E,scalar:x,pointBytes:_}=p(w),R=v(S.context,E,m),T=i.multiply(R).toBytes(),C=v(S.context,T,_,m),O=c.create(R+C*x);if(!c.isValid(O))throw new Error("sign failed: invalid s");let U=nt(T,c.toBytes(O));return M(U,L.signature,"result")}let D={zip215:o.zip215};function B(m,w,S,E=D){let{context:x}=E,_=E.zip215===void 0?!!D.zip215:E.zip215,R=L.signature;m=M(m,R,"signature"),w=M(w,void 0,"message"),S=M(S,L.publicKey,"publicKey"),_!==void 0&&Dt(_,"zip215"),s&&(w=s(w));let T=R/2,C=m.subarray(0,T),O=Ft(m.subarray(T,R)),U,z,N;try{U=e.fromBytes(S,_),z=e.fromBytes(C,_),N=i.multiplyUnsafe(O)}catch{return!1}if(!_&&U.isSmallOrder())return!1;let rt=v(x,C,S,w);return z.add(U.multiplyUnsafe(rt)).subtract(N).clearCofactor().is0()}let k=a.BYTES,L={secretKey:k,publicKey:k,signature:2*k,seed:k};function I(m){return m=m===void 0?l(L.seed):m,M(m,L.seed,"seed")}function P(m){return ye(m)&&m.length===L.secretKey}function $(m,w){try{return!!e.fromBytes(m,w===void 0?D.zip215:w)}catch{return!1}}let K={getExtendedPublicKey:p,randomSecretKey:I,isValidSecretKey:P,isValidPublicKey:$,toMontgomery(m){let{y:w}=e.fromBytes(m),S=L.publicKey,E=S===32;if(!E&&S!==57)throw new Error("only defined for 25519 and 448");let x=E?a.div(it+w,it-w):a.div(w-it,w+it);return a.toBytes(x)},toMontgomerySecret(m){let w=L.secretKey;M(m,w);let S=n(m.subarray(0,w));return d(S).subarray(0,w)}};return Object.freeze(L),Object.freeze(K),Object.freeze({keygen:fn(I,b),getPublicKey:b,sign:A,verify:B,utils:K,Point:e,lengths:L})}function xr(e,t){if(Lt(e),Lt(t),t<0||t>4)throw new Error("invalid I2OSP length: "+t);if(e<0||e>2**(8*t)-1)throw new Error("invalid I2OSP input: "+e);let r=Array.from({length:t}).fill(0);for(let n=t-1;n>=0;n--)r[n]=e&255,e>>>=8;return new Uint8Array(r)}function zf(e,t){let r=new Uint8Array(e.length);for(let n=0;n<e.length;n++)r[n]=e[n]^t[n];return r}function Vf(e){if(!ye(e)&&typeof e!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof e=="string"?an(e):e;if(t.length===0)throw new Error("DST must be non-empty");return t}function ns(e,t,r,n){M(e),Lt(r),t=Vf(t),t.length>255&&(t=n(nt(an("H2C-OVERSIZE-DST-"),t)));let{outputLen:o,blockLen:s}=n,i=Math.ceil(r/o);if(r>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=nt(t,xr(t.length,1)),c=new Uint8Array(s),u=xr(r,2),f=new Array(i),l=n(nt(c,e,u,xr(0,1),a));f[0]=n(nt(l,xr(1,1),a));for(let h=1;h<i;h++){let y=[zf(l,f[h-1]),xr(h+1,1),a];f[h]=n(nt(...y))}return nt(...f).slice(0,r)}var Aa="HashToScalar-";var Hf=BigInt(0),Yt=BigInt(1),_a=BigInt(2);var $f=BigInt(5),Wf=BigInt(8),We=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),as={p:We,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Wf,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function jf(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=We,a=e*e%s*e%s,c=j(a,_a,s)*a%s,u=j(c,Yt,s)*e%s,f=j(u,$f,s)*u%s,l=j(f,t,s)*f%s,d=j(l,r,s)*l%s,h=j(d,n,s)*d%s,y=j(h,o,s)*h%s,g=j(y,o,s)*h%s,p=j(g,t,s)*f%s;return{pow_p_5_8:j(p,_a,s)*e%s,b2:a}}function Zf(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var os=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function cs(e,t){let r=We,n=J(t*t*t,r),o=J(n*n*t,r),s=jf(e*o).pow_p_5_8,i=J(e*n*s,r),a=J(t*i*i,r),c=i,u=J(i*os,r),f=a===e,l=a===J(-e,r),d=a===J(-e*os,r);return f&&(i=c),(l||d)&&(i=u),Zt(i,r)&&(i=J(-i,r)),{isValid:f||l,value:i}}var ue=va(as,{uvRatio:cs}),ce=ue.Fp,Ra=ue.Fn;function Yf(e){return Sa(ue,en,Object.assign({adjustScalarBytes:Zf,zip215:!0},e))}var Ba=Yf({});var ss=os,Gf=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Xf=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Qf=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Jf=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Ta=e=>cs(Yt,e),tl=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),is=e=>ce.create(Ft(e)&tl);function Ia(e){let{d:t}=as,r=We,n=b=>ce.create(b),o=n(ss*e*e),s=n((o+Yt)*Qf),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:c,value:u}=cs(s,a),f=n(u*e);Zt(f,r)||(f=n(-f)),c||(u=f),c||(i=o);let l=n(i*(o-Yt)*Jf-a),d=u*u,h=n((u+u)*a),y=n(l*Gf),g=n(Yt-d),p=n(Yt+d);return new ue(n(h*p),n(g*y),n(y*p),n(h*g))}var fe=class e extends ln{static BASE=new e(ue.BASE);static ZERO=new e(ue.ZERO);static Fp=ce;static Fn=Ra;constructor(t){super(t)}static fromAffine(t){return new e(ue.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static fromBytes(t){vt(t,32);let{a:r,d:n}=as,o=We,s=D=>ce.create(D),i=is(t);if(!na(ce.toBytes(i),t)||Zt(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(Yt+r*a),u=s(Yt-r*a),f=s(c*c),l=s(u*u),d=s(r*n*f-l),{isValid:h,value:y}=Ta(s(d*l)),g=s(y*u),p=s(y*g*d),b=s((i+i)*g);Zt(b,o)&&(b=s(-b));let v=s(c*p),A=s(b*v);if(!h||Zt(A,o)||v===Hf)throw new Error("invalid ristretto255 encoding 2");return new e(new ue(b,v,Yt,A))}static fromHex(t){return e.fromBytes(fr(t))}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=We,i=p=>ce.create(p),a=i(i(n+r)*i(n-r)),c=i(t*r),u=i(c*c),{value:f}=Ta(i(a*u)),l=i(f*a),d=i(f*c),h=i(l*d*o),y;if(Zt(o*h,s)){let p=i(r*ss),b=i(t*ss);t=p,r=b,y=i(l*Xf)}else y=d;Zt(t*h,s)&&(r=i(-r));let g=i((n-r)*y);return Zt(g,s)&&(g=i(-g)),ce.toBytes(g)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=u=>ce.create(u),a=i(r*s)===i(n*o),c=i(n*s)===i(r*o);return a||c}is0(){return this.equals(e.ZERO)}};Object.freeze(fe.BASE);Object.freeze(fe.ZERO);Object.freeze(fe.prototype);Object.freeze(fe);var el=Object.freeze({Point:fe,hashToCurve(e,t){let r=t?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":t.DST,n=ns(e,r,64,en);return el.deriveToCurve(n)},hashToScalar(e,t={DST:Aa}){let r=ns(e,t.DST,64,en);return Ra.create(Ft(r))},deriveToCurve(e){vt(e,64);let t=is(e.subarray(0,32)),r=Ia(t),n=is(e.subarray(32,64)),o=Ia(n);return new fe(r.add(o))}});var Er=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},dn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Ca={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new dn("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 Tt=Ca;var hn=32;var us,rl=(async()=>{try{return await Tt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function nl(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Tt.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Tt.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 ol(e,t,r){return Ba.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Da(e,t,r){return us==null&&(us=await rl),us?nl(e,t,r):ol(e,t,r)}function pn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var mn=class{type="Ed25519";raw;constructor(t){this.raw=fs(t,hn)}toMultihash(){return Bt.digest(_t(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return G.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=Da(this.raw,r,t);return pn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function ls(e){return e=fs(e,hn),new mn(e)}function fs(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new F(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var il=Math.pow(2,7),al=Math.pow(2,14),cl=Math.pow(2,21),ds=Math.pow(2,28),hs=Math.pow(2,35),ps=Math.pow(2,42),ms=Math.pow(2,49),H=128,lt=127;function It(e){if(e<il)return 1;if(e<al)return 2;if(e<cl)return 3;if(e<ds)return 4;if(e<hs)return 5;if(e<ps)return 6;if(e<ms)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function je(e,t,r=0){switch(It(e)){case 8:t[r++]=e&255|H,e/=128;case 7:t[r++]=e&255|H,e/=128;case 6:t[r++]=e&255|H,e/=128;case 5:t[r++]=e&255|H,e/=128;case 4:t[r++]=e&255|H,e>>>=7;case 3:t[r++]=e&255|H,e>>>=7;case 2:t[r++]=e&255|H,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function ul(e,t,r=0){switch(It(e)){case 8:t.set(r++,e&255|H),e/=128;case 7:t.set(r++,e&255|H),e/=128;case 6:t.set(r++,e&255|H),e/=128;case 5:t.set(r++,e&255|H),e/=128;case 4:t.set(r++,e&255|H),e>>>=7;case 3:t.set(r++,e&255|H),e>>>=7;case 2:t.set(r++,e&255|H),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function ys(e,t){let r=e[t],n=0;if(n+=r<,r<H||(r=e[t+1],n+=(r<)<<7,r<H)||(r=e[t+2],n+=(r<)<<14,r<H)||(r=e[t+3],n+=(r<)<<21,r<H)||(r=e[t+4],n+=(r<)*ds,r<H)||(r=e[t+5],n+=(r<)*hs,r<H)||(r=e[t+6],n+=(r<)*ps,r<H)||(r=e[t+7],n+=(r<)*ms,r<H))return n;throw new RangeError("Could not decode varint")}function fl(e,t){let r=e.get(t),n=0;if(n+=r<,r<H||(r=e.get(t+1),n+=(r<)<<7,r<H)||(r=e.get(t+2),n+=(r<)<<14,r<H)||(r=e.get(t+3),n+=(r<)<<21,r<H)||(r=e.get(t+4),n+=(r<)*ds,r<H)||(r=e.get(t+5),n+=(r<)*hs,r<H)||(r=e.get(t+6),n+=(r<)*ps,r<H)||(r=e.get(t+7),n+=(r<)*ms,r<H))return n;throw new RangeError("Could not decode varint")}function yn(e,t,r=0){return t==null&&(t=xt(It(e))),t instanceof Uint8Array?je(e,t,r):ul(e,t,r)}function bs(e,t=0){return e instanceof Uint8Array?ys(e,t):fl(e,t)}var gs=new Float32Array([-0]),le=new Uint8Array(gs.buffer);function ka(e,t,r){gs[0]=e,t[r]=le[0],t[r+1]=le[1],t[r+2]=le[2],t[r+3]=le[3]}function Pa(e,t){return le[0]=e[t],le[1]=e[t+1],le[2]=e[t+2],le[3]=e[t+3],gs[0]}var ws=new Float64Array([-0]),dt=new Uint8Array(ws.buffer);function Ka(e,t,r){ws[0]=e,t[r]=dt[0],t[r+1]=dt[1],t[r+2]=dt[2],t[r+3]=dt[3],t[r+4]=dt[4],t[r+5]=dt[5],t[r+6]=dt[6],t[r+7]=dt[7]}function Na(e,t){return dt[0]=e[t],dt[1]=e[t+1],dt[2]=e[t+2],dt[3]=e[t+3],dt[4]=e[t+4],dt[5]=e[t+5],dt[6]=e[t+6],dt[7]=e[t+7],ws[0]}var ll=BigInt(Number.MAX_SAFE_INTEGER),dl=BigInt(Number.MIN_SAFE_INTEGER),St=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return Ee;if(t<ll&&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>Ua&&(o=0n,++n>Ua&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return Ee;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):Ee}},Ee=new St(0,0);Ee.toBigInt=function(){return 0n};Ee.zzEncode=Ee.zzDecode=function(){return this};Ee.length=function(){return 1};var Ua=4294967296n;function Fa(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 Ma(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 xs(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 kt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function bn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Es=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,kt(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 kt(this,4);return bn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw kt(this,4);return bn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw kt(this,4);let t=Pa(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw kt(this,4);let t=Na(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 kt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Ma(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw kt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw kt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new St(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw kt(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 kt(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 kt(this,8);let t=bn(this.buf,this.pos+=4),r=bn(this.buf,this.pos+=4);return new St(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=ys(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 vr(e){return new Es(e instanceof Uint8Array?e:e.subarray())}function pt(e,t,r){let n=vr(e);return t.decode(n,void 0,r)}function vs(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 ve=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Ss(){}var _s=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},hl=vs();function pl(e){return globalThis.Buffer!=null?xt(e):hl(e)}var Ar=class{len;head;tail;states;constructor(){this.len=0,this.head=new ve(Ss,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ve(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Ts((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(gn,10,St.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=St.fromBigInt(t);return this._push(gn,r.length(),r)}uint64Number(t){return this._push(je,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=St.fromBigInt(t).zzEncode();return this._push(gn,r.length(),r)}sint64Number(t){let r=St.fromNumber(t).zzEncode();return this._push(gn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(As,1,t?1:0)}fixed32(t){return this._push(Sr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=St.fromBigInt(t);return this._push(Sr,4,r.lo)._push(Sr,4,r.hi)}fixed64Number(t){let r=St.fromNumber(t);return this._push(Sr,4,r.lo)._push(Sr,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(ka,4,t)}double(t){return this._push(Ka,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(As,1,0):this.uint32(r)._push(yl,r,t)}string(t){let r=Fa(t);return r!==0?this.uint32(r)._push(xs,r,t):this._push(As,1,0)}fork(){return this.states=new _s(this),this.head=this.tail=new ve(Ss,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 ve(Ss,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=pl(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function As(e,t,r){t[r]=e&255}function ml(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Ts=class extends ve{next;constructor(t,r){super(ml,t,r),this.next=void 0}};function gn(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 Sr(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 yl(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Ar.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(bl,t,e),this},Ar.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(gl,t,e),this});function bl(e,t,r){t.set(e,r)}function gl(e,t,r){e.length<40?xs(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(V(e),r)}function Is(){return new Ar}function mt(e,t){let r=Is();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*yt(e,t,r){let n=vr(e);yield*t.stream(n,void 0,"$",r)}var wn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function xn(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function Rs(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 xn("enum",wn.VARINT,r,n,o)}function bt(e,t,r){return xn("message",wn.LENGTH_DELIMITED,e,t,r)}var Rt=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},_r=class extends Error{code="ERR_MAX_SIZE";name="MaxSizeError"};var Z;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(Z||(Z={}));var Bs;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Bs||(Bs={}));(function(e){e.codec=()=>Rs(Bs)})(Z||(Z={}));var Mt;(function(e){let t;e.codec=()=>(t==null&&(t=bt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),Z.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=Z.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:Z.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&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})(Mt||(Mt={}));var Cs;(function(e){let t;e.codec=()=>(t==null&&(t=bt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),Z.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=Z.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:Z.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&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})(Cs||(Cs={}));var Ir={};wt(Ir,{MAX_RSA_KEY_SIZE:()=>Ds,generateRSAKeyPair:()=>Wa,jwkToJWKKeyPair:()=>ja,jwkToPkcs1:()=>vl,jwkToPkix:()=>Ps,jwkToRSAPrivateKey:()=>Fs,pkcs1MessageToJwk:()=>Os,pkcs1MessageToRSAPrivateKey:()=>Ks,pkcs1ToJwk:()=>El,pkcs1ToRSAPrivateKey:()=>$a,pkixMessageToJwk:()=>ks,pkixMessageToRSAPublicKey:()=>Us,pkixToJwk:()=>Sl,pkixToRSAPublicKey:()=>Ns});var Ze=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Ir.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return tt.createV1(114,this._multihash)}toString(){return G.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 Ha(this.jwk,r,t,n)}},Tr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Ir.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}sign(t,r){return Va(this.jwk,t,r)}};var Ds=8192,Ls=18,wl=1062,xl=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function El(e){let t=Ht(e);return Os(t)}function Os(e){return{n:q(e[1],"base64url"),e:q(e[2],"base64url"),d:q(e[3],"base64url"),p:q(e[4],"base64url"),q:q(e[5],"base64url"),dp:q(e[6],"base64url"),dq:q(e[7],"base64url"),qi:q(e[8],"base64url"),kty:"RSA"}}function 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 F("JWK was missing components");return re([Et(Uint8Array.from([0])),Et(V(e.n,"base64url")),Et(V(e.e,"base64url")),Et(V(e.d,"base64url")),Et(V(e.p,"base64url")),Et(V(e.q,"base64url")),Et(V(e.dp,"base64url")),Et(V(e.dq,"base64url")),Et(V(e.qi,"base64url"))]).subarray()}function Sl(e){let t=Ht(e,{offset:0});return ks(t)}function ks(e){let t=Ht(e[1],{offset:0});return{kty:"RSA",n:q(t[0],"base64url"),e:q(t[1],"base64url")}}function Ps(e){if(e.n==null||e.e==null)throw new F("JWK was missing components");return re([xl,Yr(re([Et(V(e.n,"base64url")),Et(V(e.e,"base64url"))]))]).subarray()}function $a(e){let t=Ht(e);return Ks(t)}function Ks(e){let t=Os(e);return Fs(t)}function Ns(e,t){if(e.byteLength>=wl)throw new Re("Key size is too large");let r=Ht(e,{offset:0});return Us(r,e,t)}function Us(e,t,r){let n=ks(e);if(r==null){let o=Ue(Mt.encode({Type:Z.RSA,Data:t}));r=Nt(Ls,o)}return new Ze(n,r)}function Fs(e){if(Ya(e)>Ds)throw new F("Key size is too large");let t=ja(e),r=Ue(Mt.encode({Type:Z.RSA,Data:Ps(t.publicKey)})),n=Nt(Ls,r);return new Tr(t.privateKey,new Ze(t.publicKey,n))}async function Wa(e){if(e>Ds)throw new F("Key size is too large");let t=await Za(e),r=Ue(Mt.encode({Type:Z.RSA,Data:Ps(t.publicKey)})),n=Nt(Ls,r);return new Tr(t.privateKey,new Ze(t.publicKey,n))}function ja(e){if(e==null)throw new F("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function Za(e,t){let r=await Tt.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 Al(r,t);return{privateKey:n[0],publicKey:n[1]}}async function Va(e,t,r){let n=await Tt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Tt.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 Ha(e,t,r,n){let o=await Tt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Tt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function Al(e,t){if(e.privateKey==null||e.publicKey==null)throw new F("Private and public key are required");let r=await Promise.all([Tt.get().subtle.exportKey("jwk",e.privateKey),Tt.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function Ya(e){if(e.kty!=="RSA")throw new F("invalid key type");if(e.n==null)throw new F("invalid key modulus");return V(e.n,"base64url").length*8}var En=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(Gr(t),vt(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),Wt(o)}update(t){return Ne(this),this.iHash.update(t),this}digestInto(t){Ne(this),Xr(t,this),this.finished=!0;let r=t.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ga=(()=>{let e=((t,r,n)=>new En(t,r).update(n).digest());return e.create=(t,r)=>new En(t,r),e})();var Xa=(e,t)=>(e+(e>=0?t:-t)/Qa)/t;function _l(e,t,r){qe("scalar",e,qt,r);let[[n,o],[s,i]]=t,a=Xa(i*e,r),c=Xa(-o*e,r),u=e-a*n-c*s,f=-a*o-c*i,l=u<qt,d=f<qt;l&&(u=-u),d&&(f=-f);let h=br(Math.ceil(ze(r)/2))+de;if(u<qt||u>=h||f<qt||f>=h)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:d,k2:f}}function qs(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Ms(e,t){Ot(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return Dt(r.lowS,"lowS"),Dt(r.prehash,"prehash"),r.format!==void 0&&qs(r.format),r}var zs=class extends Error{constructor(t=""){super(t)}},Pt={Err:zs,_tlv:{encode:(e,t)=>{let{Err:r}=Pt;if(Lt(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(typeof t!="string")throw new TypeError('"data" expected string, got type='+typeof t);if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=mr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?mr(o.length/2|128):"";return mr(e)+s+o+t},decode(e,t){let{Err:r}=Pt;t=M(t,void 0,"DER data");let n=0;if(e<0||e>255)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=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}=Pt;if(on(e),e<qt)throw new t("integer: negative integers are not allowed");let r=mr(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}=Pt;if(e.length<1)throw new t("invalid signature integer: empty");if(e[0]&128)throw new t("invalid signature integer: negative");if(e.length>1&&e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return be(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Pt,o=M(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:u,l:f}=n.decode(2,c);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=Pt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}};Object.freeze(Pt._tlv);Object.freeze(Pt._int);Object.freeze(Pt);var qt=BigInt(0),de=BigInt(1),Qa=BigInt(2),vn=BigInt(3),Tl=BigInt(4);function Ja(e,t={}){let r=un("weierstrass",e,t),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;Ot(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c,allowInfinityPoint:u}=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 f=ec(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function d(K,m,w){if(u&&m.is0())return Uint8Array.of(0);let{x:S,y:E}=m.toAffine(),x=n.toBytes(S);if(Dt(w,"isCompressed"),w){l();let _=!n.isOdd(E);return nt(tc(_),x)}else return nt(Uint8Array.of(4),x,n.toBytes(E))}function h(K){M(K,void 0,"Point");let{publicKey:m,publicKeyUncompressed:w}=f,S=K.length,E=K[0],x=K.subarray(1);if(u&&S===1&&E===0)return{x:n.ZERO,y:n.ZERO};if(S===m&&(E===2||E===3)){let _=n.fromBytes(x);if(!n.isValid(_))throw new Error("bad point: is not on curve, wrong x");let R=p(_),T;try{T=n.sqrt(R)}catch(U){let z=U instanceof Error?": "+U.message:"";throw new Error("bad point: is not on curve, sqrt error"+z)}l();let C=n.isOdd(T);return(E&1)===1!==C&&(T=n.neg(T)),{x:_,y:T}}else if(S===w&&E===4){let _=n.BYTES,R=n.fromBytes(x.subarray(0,_)),T=n.fromBytes(x.subarray(_,_*2));if(!b(R,T))throw new Error("bad point: is not on curve");return{x:R,y:T}}else throw new Error(`bad point: got length ${S}, expected compressed=${m} or uncompressed=${w}`)}let y=t.toBytes===void 0?d:t.toBytes,g=t.fromBytes===void 0?h:t.fromBytes;function p(K){let m=n.sqr(K),w=n.mul(m,K);return n.add(n.add(w,n.mul(K,s.a)),s.b)}function b(K,m){let w=n.sqr(m),S=p(K);return n.eql(w,S)}if(!b(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let v=n.mul(n.pow(s.a,vn),Tl),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(v,A)))throw new Error("bad curve params: a or b");function D(K,m,w=!1){if(!n.isValid(m)||w&&n.is0(m))throw new Error(`bad point coordinate ${K}`);return m}function B(K){if(!(K instanceof I))throw new Error("Weierstrass Point expected")}function k(K){if(!c||!c.basises)throw new Error("no endo");return _l(K,c.basises,o.ORDER)}function L(K,m,w,S,E){return w=new I(n.mul(w.X,K),w.Y,w.Z),m=wr(S,m),w=wr(E,w),m.add(w)}class I{static BASE=new I(s.Gx,s.Gy,n.ONE);static ZERO=new I(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(m,w,S){this.X=D("x",m),this.Y=D("y",w,!0),this.Z=D("z",S),Object.freeze(this)}static CURVE(){return s}static fromAffine(m){let{x:w,y:S}=m||{};if(!m||!n.isValid(w)||!n.isValid(S))throw new Error("invalid affine point");if(m instanceof I)throw new Error("projective point not allowed");return n.is0(w)&&n.is0(S)?I.ZERO:new I(w,S,n.ONE)}static fromBytes(m){let w=I.fromAffine(g(M(m,void 0,"point")));return w.assertValidity(),w}static fromHex(m){return I.fromBytes(Me(m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,w=!0){return $.createCache(this,m),w||this.multiply(vn),this}assertValidity(){let m=this;if(m.is0()){if(t.allowInfinityPoint&&n.is0(m.X)&&n.eql(m.Y,n.ONE)&&n.is0(m.Z))return;throw new Error("bad point: ZERO")}let{x:w,y:S}=m.toAffine();if(!n.isValid(w)||!n.isValid(S))throw new Error("bad point: x or y not field elements");if(!b(w,S))throw new Error("bad point: equation left != right");if(!m.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:m}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(m)}equals(m){B(m);let{X:w,Y:S,Z:E}=this,{X:x,Y:_,Z:R}=m,T=n.eql(n.mul(w,R),n.mul(x,E)),C=n.eql(n.mul(S,R),n.mul(_,E));return T&&C}negate(){return new I(this.X,n.neg(this.Y),this.Z)}double(){let{a:m,b:w}=s,S=n.mul(w,vn),{X:E,Y:x,Z:_}=this,R=n.ZERO,T=n.ZERO,C=n.ZERO,O=n.mul(E,E),U=n.mul(x,x),z=n.mul(_,_),N=n.mul(E,x);return N=n.add(N,N),C=n.mul(E,_),C=n.add(C,C),R=n.mul(m,C),T=n.mul(S,z),T=n.add(R,T),R=n.sub(U,T),T=n.add(U,T),T=n.mul(R,T),R=n.mul(N,R),C=n.mul(S,C),z=n.mul(m,z),N=n.sub(O,z),N=n.mul(m,N),N=n.add(N,C),C=n.add(O,O),O=n.add(C,O),O=n.add(O,z),O=n.mul(O,N),T=n.add(T,O),z=n.mul(x,_),z=n.add(z,z),O=n.mul(z,N),R=n.sub(R,O),C=n.mul(z,U),C=n.add(C,C),C=n.add(C,C),new I(R,T,C)}add(m){B(m);let{X:w,Y:S,Z:E}=this,{X:x,Y:_,Z:R}=m,T=n.ZERO,C=n.ZERO,O=n.ZERO,U=s.a,z=n.mul(s.b,vn),N=n.mul(w,x),rt=n.mul(S,_),ot=n.mul(E,R),st=n.add(w,S),Q=n.add(x,_);st=n.mul(st,Q),Q=n.add(N,rt),st=n.sub(st,Q),Q=n.add(w,E);let gt=n.add(x,R);return Q=n.mul(Q,gt),gt=n.add(N,ot),Q=n.sub(Q,gt),gt=n.add(S,E),T=n.add(_,R),gt=n.mul(gt,T),T=n.add(rt,ot),gt=n.sub(gt,T),O=n.mul(U,Q),T=n.mul(z,ot),O=n.add(T,O),T=n.sub(rt,O),O=n.add(rt,O),C=n.mul(T,O),rt=n.add(N,N),rt=n.add(rt,N),ot=n.mul(U,ot),Q=n.mul(z,Q),rt=n.add(rt,ot),ot=n.sub(N,ot),ot=n.mul(U,ot),Q=n.add(Q,ot),N=n.mul(rt,Q),C=n.add(C,N),N=n.mul(gt,Q),T=n.mul(st,T),T=n.sub(T,N),N=n.mul(st,rt),O=n.mul(gt,O),O=n.add(O,N),new I(T,C,O)}subtract(m){return B(m),this.add(m.negate())}is0(){return this.equals(I.ZERO)}multiply(m){let{endo:w}=t;if(!o.isValidNot0(m))throw new RangeError("invalid scalar: out of range");let S,E,x=_=>$.cached(this,_,R=>xe(I,R));if(w){let{k1neg:_,k1:R,k2neg:T,k2:C}=k(m),{p:O,f:U}=x(R),{p:z,f:N}=x(C);E=U.add(N),S=L(w.beta,O,z,_,T)}else{let{p:_,f:R}=x(m);S=_,E=R}return xe(I,[S,E])[0]}multiplyUnsafe(m){let{endo:w}=t,S=this,E=m;if(!o.isValid(E))throw new RangeError("invalid scalar: out of range");if(E===qt||S.is0())return I.ZERO;if(E===de)return S;if($.hasCache(this))return this.multiply(E);if(w){let{k1neg:x,k1:_,k2neg:R,k2:T}=k(E),{p1:C,p2:O}=Ea(I,S,_,T);return L(w.beta,C,O,x,R)}else return $.unsafe(S,E)}toAffine(m){let w=this,S=m,{X:E,Y:x,Z:_}=w;if(n.eql(_,n.ONE))return{x:E,y:x};let R=w.is0();S==null&&(S=R?n.ONE:n.inv(_));let T=n.mul(E,S),C=n.mul(x,S),O=n.mul(_,S);if(R)return{x:n.ZERO,y:n.ZERO};if(!n.eql(O,n.ONE))throw new Error("invZ was invalid");return{x:T,y:C}}isTorsionFree(){let{isTorsionFree:m}=t;return i===de?!0:m?m(I,this):$.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:m}=t;return i===de?this:m?m(I,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===de?this.is0():this.clearCofactor().is0()}toBytes(m=!0){return Dt(m,"isCompressed"),this.assertValidity(),y(I,this,m)}toHex(m=!0){return Fe(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let P=o.BITS,$=new $e(I,t.endo?Math.ceil(P/2):P);return P>=8&&I.BASE.precompute(8),Object.freeze(I.prototype),Object.freeze(I),I}function tc(e){return Uint8Array.of(e?2:3)}function ec(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Il(e,t={}){let{Fn:r}=e,n=t.randomBytes===void 0?pr:t.randomBytes,o=Object.assign(ec(e.Fp,r),{seed:Math.max(Xo(r.ORDER),16)});function s(h){try{let y=r.fromBytes(h);return r.isValidNot0(y)}catch{return!1}}function i(h,y){let{publicKey:g,publicKeyUncompressed:p}=o;try{let b=h.length;return y===!0&&b!==g||y===!1&&b!==p?!1:!!e.fromBytes(h)}catch{return!1}}function a(h){return h=h===void 0?n(o.seed):h,Qo(M(h,o.seed,"seed"),r.ORDER)}function c(h,y=!0){return e.BASE.multiply(r.fromBytes(h)).toBytes(y)}function u(h){let{secretKey:y,publicKey:g,publicKeyUncompressed:p}=o,b=r._lengths;if(!ye(h))return;let v=M(h,void 0,"key").length,A=v===g||v===p,D=v===y||!!b?.includes(v);if(!(A&&D))return A}function f(h,y,g=!0){if(u(h)===!0)throw new Error("first arg must be private key");if(u(y)===!1)throw new Error("second arg must be public key");let p=r.fromBytes(h);return e.fromBytes(y).multiply(p).toBytes(g)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},d=fn(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:d,Point:e,utils:l,lengths:o})}function rc(e,t,r={}){let n=t;Gr(n),Ot(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?pr:r.randomBytes,s=r.hmac===void 0?(E,x)=>Ga(n,E,x):r.hmac,{Fp:i,Fn:a}=e,{ORDER:c,BITS:u}=a,{keygen:f,getPublicKey:l,getSharedSecret:d,utils:h,lengths:y}=Il(e,r),g={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},p=c*Qa+de<i.ORDER;function b(E){let x=c>>de;return E>x}function v(E,x){if(!a.isValidNot0(x))throw new Error(`invalid signature ${E}: out of range 1..Point.Fn.ORDER`);return x}function A(){if(p)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function D(E,x){qs(x);let _=y.signature,R=x==="compact"?_:x==="recovered"?_+1:void 0;return M(E,R)}class B{r;s;recovery;constructor(x,_,R){if(this.r=v("r",x),this.s=v("s",_),R!=null){if(A(),![0,1,2,3].includes(R))throw new Error("invalid recovery id");this.recovery=R}Object.freeze(this)}static fromBytes(x,_=g.format){D(x,_);let R;if(_==="der"){let{r:U,s:z}=Pt.toSig(M(x));return new B(U,z)}_==="recovered"&&(R=x[0],_="compact",x=x.subarray(1));let T=y.signature/2,C=x.subarray(0,T),O=x.subarray(T,T*2);return new B(a.fromBytes(C),a.fromBytes(O),R)}static fromHex(x,_){return this.fromBytes(Me(x),_)}assertRecovery(){let{recovery:x}=this;if(x==null)throw new Error("invalid recovery id: must be present");return x}addRecoveryBit(x){return new B(this.r,this.s,x)}recoverPublicKey(x){let{r:_,s:R}=this,T=this.assertRecovery(),C=T===2||T===3?_+c:_;if(!i.isValid(C))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let O=i.toBytes(C),U=e.fromBytes(nt(tc((T&1)===0),O)),z=a.inv(C),N=L(M(x,void 0,"msgHash")),rt=a.create(-N*z),ot=a.create(R*z),st=e.BASE.multiplyUnsafe(rt).add(U.multiplyUnsafe(ot));if(st.is0())throw new Error("invalid recovery: point at infinify");return st.assertValidity(),st}hasHighS(){return b(this.s)}toBytes(x=g.format){if(qs(x),x==="der")return Me(Pt.hexFromSig(this));let{r:_,s:R}=this,T=a.toBytes(_),C=a.toBytes(R);return x==="recovered"?(A(),nt(Uint8Array.of(this.assertRecovery()),T,C)):nt(T,C)}toHex(x){return Fe(this.toBytes(x))}}Object.freeze(B.prototype),Object.freeze(B);let k=r.bits2int===void 0?function(x){if(x.length>8192)throw new Error("input is too large");let _=be(x),R=x.length*8-u;return R>0?_>>BigInt(R):_}:r.bits2int,L=r.bits2int_modN===void 0?function(x){return a.create(k(x))}:r.bits2int_modN,I=br(u);function P(E){return qe("num < 2^"+u,E,qt,I),a.toBytes(E)}function $(E,x){return M(E,void 0,"message"),x?M(n(E),void 0,"prehashed message"):E}function K(E,x,_){let{lowS:R,prehash:T,extraEntropy:C}=Ms(_,g);E=$(E,T);let O=L(E),U=a.fromBytes(x);if(!a.isValidNot0(U))throw new Error("invalid private key");let z=[P(U),P(O)];if(C!=null&&C!==!1){let st=C===!0?o(y.secretKey):C;z.push(M(st,void 0,"extraEntropy"))}let N=nt(...z),rt=O;function ot(st){let Q=k(st);if(!a.isValidNot0(Q))return;let gt=a.inv(Q),Ie=e.BASE.multiply(Q).toAffine(),tr=a.create(Ie.x);if(tr===qt)return;let zr=a.create(gt*a.create(rt+tr*U));if(zr===qt)return;let hi=(Ie.x===tr?0:2)|Number(Ie.y&de),pi=zr;return R&&b(zr)&&(pi=a.neg(zr),hi^=1),new B(tr,pi,p?void 0:hi)}return{seed:N,k2sig:ot}}function m(E,x,_={}){let{seed:R,k2sig:T}=K(E,x,_);return oa(n.outputLen,a.BYTES,s)(R,T).toBytes(_.format)}function w(E,x,_,R={}){let{lowS:T,prehash:C,format:O}=Ms(R,g);if(_=M(_,void 0,"publicKey"),x=$(x,C),!ye(E)){let U=E instanceof B?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+U)}D(E,O);try{let U=B.fromBytes(E,O),z=e.fromBytes(_);if(T&&U.hasHighS())return!1;let{r:N,s:rt}=U,ot=L(x),st=a.inv(rt),Q=a.create(ot*st),gt=a.create(N*st),Ie=e.BASE.multiplyUnsafe(Q).add(z.multiplyUnsafe(gt));return Ie.is0()?!1:a.create(Ie.x)===N}catch{return!1}}function S(E,x,_={}){let{prehash:R}=Ms(_,g);return x=$(x,R),B.fromBytes(E,"recovered").recoverPublicKey(x).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:d,utils:h,lengths:y,Point:e,sign:m,verify:w,recoverPublicKey:S,Signature:B,hash:n})}var Hs={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Rl={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var nc=BigInt(2);function Bl(e){let t=Hs.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,f=u*u*e%t,l=j(f,r,t)*f%t,d=j(l,r,t)*f%t,h=j(d,nc,t)*u%t,y=j(h,o,t)*h%t,g=j(y,s,t)*y%t,p=j(g,a,t)*g%t,b=j(p,c,t)*p%t,v=j(b,a,t)*g%t,A=j(v,r,t)*f%t,D=j(A,i,t)*y%t,B=j(D,n,t)*u%t,k=j(B,nc,t);if(!Vs.eql(Vs.sqr(k),e))throw new Error("Cannot find square root");return k}var Vs=Ve(Hs.p,{sqrt:Bl}),Cl=Ja(Hs,{Fp:Vs,endo:Rl}),Ye=rc(Cl,Ue);function oc(e,t,r,n){let o=ir.digest(r instanceof Uint8Array?r:r.subarray());if(pn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ye.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Er(String(s))});try{return n?.signal?.throwIfAborted(),Ye.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new Er(String(s))}}var Sn=class{type="secp256k1";raw;_key;constructor(t){this._key=ic(t),this.raw=sc(this._key)}toMultihash(){return Bt.digest(_t(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return G.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 oc(this._key,r,t,n)}};function $s(e){return new Sn(e)}function sc(e){return Ye.Point.fromBytes(e).toBytes()}function ic(e){try{return Ye.Point.fromBytes(e),e}catch(t){throw new Re(String(t))}}function An(e,t){let{Type:r,Data:n}=Mt.decode(e),o=n??new Uint8Array;switch(r){case Z.RSA:return Ns(o,t);case Z.Ed25519:return ls(o);case Z.secp256k1:return $s(o);case Z.ECDSA:return ko(o);default:throw new he}}function ac(e){let{Type:t,Data:r}=Mt.decode(e.digest),n=r??new Uint8Array;switch(t){case Z.Ed25519:return ls(n);case Z.secp256k1:return $s(n);case Z.ECDSA:return ko(n);default:throw new he}}function _t(e){return Mt.encode({Type:Z[e.type],Data:e.raw})}var cc=Symbol.for("nodejs.util.inspect.custom"),Dl=114,Rr=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()})`}[$r]=!0;toString(){return this.string==null&&(this.string=G.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return tt.createV1(Dl,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")}[cc](){return`PeerId(${this.toString()})`}},Br=class extends Rr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Cr=class extends Rr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Dr=class extends Rr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Ll=2336,Lr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Bt.digest(V(this.url))}[cc](){return`PeerId(${this.url})`}[$r]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return tt.createV1(Ll,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=q(t)),t.toString()===this.toString())}};var Ol=114,uc=2336;function fc(e){if(e.type==="Ed25519")return new Cr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new Dr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new Br({multihash:e.toCID().multihash,publicKey:e});throw new he}function Ws(e){if(Pl(e))return new Br({multihash:e});if(kl(e))try{let t=ac(e);if(t.type==="Ed25519")return new Cr({multihash:e,publicKey:t});if(t.type==="secp256k1")return new Dr({multihash:e,publicKey:t})}catch{let r=q(e.digest);return new Lr(new URL(r))}throw new Hr("Supplied PeerID Multihash is invalid")}function _n(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==Ol&&e.code!==uc)throw new Vr("Supplied PeerID CID is invalid");if(e.code===uc){let t=q(e.multihash.digest);return new Lr(new URL(t))}return Ws(e.multihash)}function kl(e){return e.code===Bt.code}function Pl(e){return e.code===ir.code}var Or;(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:et(0),payloadType:et(0),payload:et(0),signature:et(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.publicKey=s.bytes();break}case 2:{c.payloadType=s.bytes();break}case 3:{c.payload=s.bytes();break}case 5:{c.signature=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.publicKey`,value:s.bytes()};break}case 2:{yield{field:`${a}.payloadType`,value:s.bytes()};break}case 3:{yield{field:`${a}.payload`,value:s.bytes()};break}case 5:{yield{field:`${a}.signature`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),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})(Or||(Or={}));var Tn=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var Ge=class e{static createFromProtobuf=t=>{let r=Or.decode(t),n=An(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=lc(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 Tn("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=Or.encode({publicKey:_t(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=lc(t,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},lc=(e,t,r)=>{let n=V(e),o=yn(n.byteLength),s=yn(t.length),i=yn(r.length);return new ht(o,n,s,t,i,r)};var ft=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Gt=class extends Error{static name="ValidationError";name="ValidationError"},In=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Rn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Bn=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",u=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let d=Number.parseInt(l,t);if(!Number.isNaN(d))return d});if(f===void 0)break;if(s*=t,s+=f,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let 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 Kl=45,Nl=15,Cn=new Bn;function dc(e){if(!(e.length>Nl))return Cn.new(e).parseWith(()=>Cn.readIPv4Addr())}function hc(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>Kl))return Cn.new(e).parseWith(()=>Cn.readIPv6Addr())}function Dn(e){return!!dc(e)}function pc(e){return!!hc(e)}function Zs(e){return t=>q(t,e)}function Ys(e){return t=>V(t,e)}function Xe(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function Se(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function mc(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=V(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=Se(n);return Vt([r,o],r.length+o.length)}function yc(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=Kt.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=Se(n);return Vt([r,o],r.length+o.length)}function Gs(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=q(t,"base32"),o=Xe(r);return`${n}:${o}`}var Xs=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 ft("Invalid byte value in IP address");t[n]=o}),t},bc=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=Xs(r[n]),r[n]=q(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,q(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 ft("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},gc=function(e){if(e.byteLength!==4)throw new ft("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},wc=function(e){if(e.byteLength!==16)throw new ft("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 ft(`Invalid IPv6 address "${r}"`)}};function xc(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new ft(`Invalid IPv6 address "${e}"`)}}var js=Object.values(ar).map(e=>e.decoder),Ul=(function(){let e=js[0].or(js[1]);return js.slice(2).forEach(t=>e=e.or(t)),e})();function Ec(e){return Ul.decode(e)}function vc(e){return t=>e.encoder.encode(t)}function Fl(e){if(parseInt(e).toString()!==e)throw new Gt("Value must be an integer")}function Ml(e){if(e<0)throw new Gt("Value must be a positive integer, or zero")}function ql(e){return t=>{if(t>e)throw new Gt(`Value must be smaller than or equal to ${e}`)}}function zl(...e){return t=>{for(let r of e)r(t)}}var kr=zl(Fl,Ml,ql(65535));var at=-1,Qs=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 Rn(`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)}))}},Xt=new Qs,Rd=[{code:4,name:"ip4",size:32,valueToBytes:Xs,bytesToValue:gc,validate:e=>{if(!Dn(e))throw new Gt(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Se,bytesToValue:Xe,validate:kr},{code:273,name:"udp",size:16,valueToBytes:Se,bytesToValue:Xe,validate:kr},{code:33,name:"dccp",size:16,valueToBytes:Se,bytesToValue:Xe,validate:kr},{code:41,name:"ip6",size:128,valueToBytes:bc,bytesToValue:wc,stringToValue:xc,validate:e=>{if(!pc(e))throw new Gt(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:at},{code:43,name:"ipcidr",size:8,bytesToValue:Zs("base10"),valueToBytes:Ys("base10")},{code:53,name:"dns",size:at},{code:54,name:"dns4",size:at},{code:55,name:"dns6",size:at},{code:56,name:"dnsaddr",size:at},{code:132,name:"sctp",size:16,valueToBytes:Se,bytesToValue:Xe,validate:kr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:at,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:at,bytesToValue:Zs("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?Ys("base58btc")(e):tt.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Gs,valueToBytes:mc},{code:445,name:"onion3",size:296,bytesToValue:Gs,valueToBytes:yc},{code:446,name:"garlic64",size:at},{code:447,name:"garlic32",size:at},{code:448,name:"tls"},{code:449,name:"sni",size:at},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:at,bytesToValue:vc(Eo),valueToBytes:Ec},{code:480,name:"http"},{code:481,name:"http-path",size:at,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:at}];Rd.forEach(e=>{Xt.addProtocol(e)});function Sc(e){let t=[],r=0;for(;r<e.length;){let n=bs(e,r),o=Xt.getProtocol(n),s=It(n),i=Bd(o,e,r+s),a=0;i>0&&o.size===at&&(a=It(i));let c=s+a+i,u={code:n,name:o.name,bytes:e.subarray(r,r+c)};if(i>0){let f=r+s+a,l=e.subarray(f,f+i);u.value=o.bytesToValue?.(l)??q(l)}t.push(u),r+=c}return t}function Ac(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=Xt.getProtocol(n.code),s=It(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??V(n.value),a=i.byteLength,o.size===at&&(c=It(a)));let u=new Uint8Array(s+c+a),f=0;je(n.code,u,f),f+=s,i!=null&&(o.size===at&&(je(a,u,f),f+=c),u.set(i,f)),n.bytes=u}r.push(n.bytes),t+=n.bytes.byteLength}return Vt(r,t)}function _c(e){if(e.charAt(0)!=="/")throw new ft('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=Xt.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 ft(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new ft(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}t.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new ft("Incomplete multiaddr");return t}function Tc(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=Xt.getProtocol(t.code);if(r==null)throw new ft(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function Bd(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:bs(t,r)}var Cd=Symbol.for("nodejs.util.inspect.custom"),ti=Symbol.for("@multiformats/multiaddr");function Dd(e){if(e==null&&(e="/"),On(e))return e.getComponents();if(e instanceof Uint8Array)return Sc(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),_c(e);if(Array.isArray(e))return e;throw new ft("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Ln=class e{[ti]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=Dd(t),r.validate!==!1&&Ld(this)}get bytes(){return this.#r==null&&(this.#r=Ac(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Tc(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 In(`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)}[Cd](){return`Multiaddr(${this.toString()})`}};function Ld(e){e.getComponents().forEach(t=>{let r=Xt.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function On(e){return!!e?.[ti]}function Ae(e){return new Ln(e)}var Ic="libp2p-peer-record",Rc=Uint8Array.from([3,1]);var Pr;(function(e){let t;(function(i){let a;i.codec=()=>(a==null&&(a=bt((l,d,h={})=>{h.lengthDelimited!==!1&&d.fork(),l.multiaddr!=null&&l.multiaddr.byteLength>0&&(d.uint32(10),d.bytes(l.multiaddr)),h.lengthDelimited!==!1&&d.ldelim()},(l,d,h={})=>{let y={multiaddr:et(0)},g=d==null?l.len:l.pos+d;for(;l.pos<g;){let p=l.uint32();p>>>3===1?y.multiaddr=l.bytes():l.skipType(p&7)}return y},function*(l,d,h,y={}){let g=d==null?l.len:l.pos+d;for(;l.pos<g;){let p=l.uint32();p>>>3===1?yield{field:`${h}.multiaddr`,value:l.bytes()}:l.skipType(p&7)}})),a);function c(l){return mt(l,i.codec())}i.encode=c;function u(l,d){return pt(l,i.codec(),d)}i.decode=u;function f(l,d){return yt(l,i.codec(),d)}i.stream=f})(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 u of i.addresses)a.uint32(26),e.AddressInfo.codec().encode(u,a);c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let u={peerId:et(0),seq:0n,addresses:[]},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let l=i.uint32();switch(l>>>3){case 1:{u.peerId=i.bytes();break}case 2:{u.seq=i.uint64();break}case 3:{if(c.limits?.addresses!=null&&u.addresses.length===c.limits.addresses)throw new Rt('Decode error - repeated field "addresses" had too many elements');u.addresses.push(e.AddressInfo.codec().decode(i,i.uint32(),{limits:c.limits?.addresses$}));break}default:{i.skipType(l&7);break}}}return u},function*(i,a,c,u={}){let f={addresses:0},l=a==null?i.len:i.pos+a;for(;i.pos<l;){let d=i.uint32();switch(d>>>3){case 1:{yield{field:`${c}.peerId`,value:i.bytes()};break}case 2:{yield{field:`${c}.seq`,value:i.uint64()};break}case 3:{if(u.limits?.addresses!=null&&f.addresses===u.limits.addresses)throw new Rt('Streaming decode error - repeated field "addresses" had too many elements');for(let h of e.AddressInfo.codec().stream(i,i.uint32(),`${c}.addresses[]`,{limits:u.limits?.addresses$}))yield{...h,index:f.addresses};f.addresses++;break}default:{i.skipType(d&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})(Pr||(Pr={}));function Bc(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 _e=class e{static createFromProtobuf=t=>{let r=Pr.decode(t),n=Ws(Pe(r.peerId)),o=(r.addresses??[]).map(i=>Ae(i.multiaddr)),s=r.seq;return new e({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Ic;static CODEC=Rc;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=Pr.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||!Bc(this.multiaddrs,t.multiaddrs))}};function Od(e){return e[Symbol.asyncIterator]!=null}function kd(e){if(Od(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 Cc=kd;function kn(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 Kr=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 kn(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 kn(this.map.values(),t=>t.key)}values(){return kn(this.map.values(),t=>t.value)}get size(){return this.map.size}};function Pn(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var Kn=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}},Qe=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Kn(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 Kn(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 ei=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Dc(e={}){return Pd(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 Pd(e,t){t=t??{};let r=t.onEnd,n=new Qe,o,s,i,a=Pn(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,b)=>{s=v=>{s=null,n.push(v);try{p(e(n))}catch(A){b(A)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Pn()})}},u=p=>s!=null?s(p):(n.push(p),o),f=p=>(n=new Qe,s!=null?s({error:p}):(n.push({error:p}),o)),l=p=>{if(i)return o;if(t?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:p})},d=p=>i?o:(i=!0,p!=null?f(p):u({done:!0})),h=()=>(n=new Qe,d(),{done:!0}),y=p=>(d(p),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:h,throw:y,push:l,end:d,get readableLength(){return n.size},onEmpty:async p=>{let b=p?.signal;if(b?.throwIfAborted(),n.isEmpty())return;let v,A;b!=null&&(v=new Promise((D,B)=>{A=()=>{B(new ei)},b.addEventListener("abort",A)}));try{await Promise.race([a.promise,v])}finally{A!=null&&b!=null&&b?.removeEventListener("abort",A)}}},r==null)return o;let g=o;return o={[Symbol.asyncIterator](){return this},next(){return g.next()},throw(p){return g.throw(p),r!=null&&(r(p),r=void 0),{done:!0}},return(){return g.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(p){return g.end(p),r!=null&&(r(p),r=void 0),o},get readableLength(){return g.readableLength},onEmpty:p=>g.onEmpty(p)},o}function Kd(e){return e.reason}async function Lc(e,t,r){if(t==null)return e;let n=r?.translateError??Kd;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 ri=class extends Kr{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 ni(e){let{name:t,metrics:r}=e,n;return r!=null?n=new ri({name:t,metrics:r}):n=new Kr,n}var At=class extends Error{static name="AbortError";name="AbortError";constructor(t="The operation was aborted",...r){super(t,...r)}};async function Nn(e,t,r,n){let o=new At(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(){si(r,"abort",l),si(e,t,u),si(e,s,f)}let u=d=>{try{if(n?.filter?.(d)===!1)return}catch(h){c(),a(h);return}c(),i(d)},f=d=>{if(c(),d instanceof Error){a(d);return}a(d.detail??n?.error??new Error(`The "${n?.errorEvent}" event was emitted but the event had no '.detail' field. Pass an 'error' option to race-event to change this message.`))},l=()=>{c(),a(o)};oi(r,"abort",l),oi(e,t,u),oi(e,s,f)})}function oi(e,t,r){e!=null&&(Oc(e)?e.addEventListener(t,r):e.addListener(t,r))}function si(e,t,r){e!=null&&(Oc(e)?e.removeEventListener(t,r):e.removeListener(t,r))}function Oc(e){return typeof e.addEventListener=="function"&&typeof e.removeEventListener=="function"}var Un=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};var Fn=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 At)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Nd(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Mn=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 At),this.cleanup())}async join(t={}){let r=new Fn(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 Lc(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 ii(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 Nr=class extends Ce{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=ii(this.emitEmpty.bind(this),1),this.emitIdle=ii(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 Un;let n=new Mn(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 At)}),this.clear()}async onEmpty(t){this.size!==0&&await Nn(this,"empty",t?.signal)}async onSizeLessThan(t,r){this.size<t||await Nn(this,"next",r?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await Nn(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=Dc({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 At("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 qn="lock:worker:request-read",zn="lock:worker:abort-read-request",Vn="lock:worker:release-read",Hn="lock:master:grant-read",$n="lock:master:error-read",Wn="lock:worker:request-write",jn="lock:worker:abort-write-request",Zn="lock:worker:release-write",Yn="lock:master:grant-write",Gn="lock:master:error-write",Xn="lock:worker:finalize",Qn="mortice",kc={singleProcess:!1};var ai=(e,t,r,n,o,s,i,a,c)=>u=>{if(u.data==null)return;let f={type:u.data.type,name:u.data.name,identifier:u.data.identifier};f.type===o&&e.safeDispatchEvent(r,{detail:{name:f.name,identifier:f.identifier,handler:async()=>{t.postMessage({type:c,name:f.name,identifier:f.identifier}),await new Promise(l=>{let d=h=>{if(h?.data==null)return;let y={type:h.data.type,name:h.data.name,identifier:h.data.identifier};y.type===a&&y.identifier===f.identifier&&(t.removeEventListener("message",d),l())};t.addEventListener("message",d)})},onError:l=>{t.postMessage({type:i,name:f.name,identifier:f.identifier,error:{message:l.message,name:l.name,stack:l.stack}})}}}),f.type===s&&e.safeDispatchEvent(n,{detail:{name:f.name,identifier:f.identifier}}),f.type===Xn&&e.safeDispatchEvent("finalizeRequest",{detail:{name:f.name}})};var Pc=(e=10)=>Math.random().toString().substring(2,e+2);var Jn=class{name;channel;constructor(t){this.name=t,this.channel=new BroadcastChannel(Qn)}readLock(t){return this.sendRequest(qn,zn,Hn,$n,Vn,t)}writeLock(t){return this.sendRequest(Wn,jn,Yn,Gn,Zn,t)}finalize(){this.channel.postMessage({type:Xn,name:this.name}),this.channel.close()}async sendRequest(t,r,n,o,s,i){i?.signal?.throwIfAborted();let a=Pc();return this.channel.postMessage({type:t,identifier:a,name:this.name}),new Promise((c,u)=>{let f=()=>{this.channel.postMessage({type:r,identifier:a,name:this.name})};i?.signal?.addEventListener("abort",f,{once:!0});let l=d=>{if(d.data?.identifier===a&&(d.data?.type===n&&(this.channel.removeEventListener("message",l),i?.signal?.removeEventListener("abort",f),c(()=>{this.channel.postMessage({type:s,identifier:a,name:this.name})})),d.data.type===o)){this.channel.removeEventListener("message",l),i?.signal?.removeEventListener("abort",f);let h=new Error;d.data.error!=null&&(h.message=d.data.error.message,h.name=d.data.error.name,h.stack=d.data.error.stack),u(h)}};this.channel.addEventListener("message",l)})}};var Kc=e=>{if(e=Object.assign({},kc,e),!!globalThis.document||e.singleProcess){let r=new BroadcastChannel(Qn),n=new Ce;return r.addEventListener("message",ai(n,r,"requestReadLock","abortReadLockRequest",qn,zn,$n,Vn,Hn)),r.addEventListener("message",ai(n,r,"requestWriteLock","abortWriteLockRequest",Wn,jn,Gn,Zn,Yn)),n}return new Jn(e.name)};var Te=new Map,Ur;function Nc(e){return typeof e?.readLock=="function"&&typeof e?.writeLock=="function"}function Ud(e){if(Ur==null&&(Ur=Kc(e),!Nc(Ur))){let t=Ur;t.addEventListener("requestReadLock",r=>{let n=r.detail.name,o=r.detail.identifier,s=Te.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=Te.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=Te.get(n);o?.finalize()})}return Ur}async function ci(e,t){let r,n,o=new Promise((i,a)=>{r=i,n=a}),s=()=>{n(new At)};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 Uc=(e,t)=>{let r=Te.get(e);if(r!=null)return r;let n=Ud(t);if(Nc(n))return r=n,Te.set(e,r),r;let o=new Nr({concurrency:1}),s;return r={async readLock(i){if(s!=null)return ci(s,i);s=new Nr({concurrency:t.concurrency,autoStart:!1});let a=s,c=ci(s,i);return o.add(async()=>{a.start(),await a.onIdle().then(()=>{s===a&&(s=null)})}),c},async writeLock(i){return s=null,ci(o,i)},finalize:()=>{Te.delete(e)},queue:o},Te.set(e,r),t.autoFinalize===!0&&o.addEventListener("idle",()=>{r.finalize()},{once:!0}),r};var Fd={name:"lock",concurrency:1/0,singleProcess:!1,autoFinalize:!1};function ui(e){let t=Object.assign({},Fd,e);return Uc(t.name,t)}var Qt;(function(e){let t;(function(a){let c;a.codec=()=>(c==null&&(c=bt((d,h,y={})=>{y.lengthDelimited!==!1&&h.fork(),d.key!=null&&d.key!==""&&(h.uint32(10),h.string(d.key)),d.value!=null&&d.value.byteLength>0&&(h.uint32(18),h.bytes(d.value)),y.lengthDelimited!==!1&&h.ldelim()},(d,h,y={})=>{let g={key:"",value:et(0)},p=h==null?d.len:d.pos+h;for(;d.pos<p;){let b=d.uint32();switch(b>>>3){case 1:{g.key=d.string();break}case 2:{g.value=d.bytes();break}default:{d.skipType(b&7);break}}}return g},function*(d,h,y,g={}){let p=h==null?d.len:d.pos+h;for(;d.pos<p;){let b=d.uint32();switch(b>>>3){case 1:{yield{field:`${y}.key`,value:d.string()};break}case 2:{yield{field:`${y}.value`,value:d.bytes()};break}default:{d.skipType(b&7);break}}}})),c);function u(d){return mt(d,a.codec())}a.encode=u;function f(d,h){return pt(d,a.codec(),h)}a.decode=f;function l(d,h){return yt(d,a.codec(),h)}a.stream=l})(t=e.Peer$metadataEntry||(e.Peer$metadataEntry={}));let r;(function(a){let c;a.codec=()=>(c==null&&(c=bt((d,h,y={})=>{y.lengthDelimited!==!1&&h.fork(),d.key!=null&&d.key!==""&&(h.uint32(10),h.string(d.key)),d.value!=null&&(h.uint32(18),Mr.codec().encode(d.value,h)),y.lengthDelimited!==!1&&h.ldelim()},(d,h,y={})=>{let g={key:""},p=h==null?d.len:d.pos+h;for(;d.pos<p;){let b=d.uint32();switch(b>>>3){case 1:{g.key=d.string();break}case 2:{g.value=Mr.codec().decode(d,d.uint32(),{limits:y.limits?.value});break}default:{d.skipType(b&7);break}}}return g},function*(d,h,y,g={}){let p=h==null?d.len:d.pos+h;for(;d.pos<p;){let b=d.uint32();switch(b>>>3){case 1:{yield{field:`${y}.key`,value:d.string()};break}case 2:{yield*Mr.codec().stream(d,d.uint32(),`${y}.value`,{limits:g.limits?.value});break}default:{d.skipType(b&7);break}}}})),c);function u(d){return mt(d,a.codec())}a.encode=u;function f(d,h){return pt(d,a.codec(),h)}a.decode=f;function l(d,h){return yt(d,a.codec(),h)}a.stream=l})(r=e.Peer$tagsEntry||(e.Peer$tagsEntry={}));let n;e.codec=()=>(n==null&&(n=bt((a,c,u={})=>{if(u.lengthDelimited!==!1&&c.fork(),a.addresses!=null&&a.addresses.length>0)for(let f of a.addresses)c.uint32(10),Fr.codec().encode(f,c);if(a.protocols!=null&&a.protocols.length>0)for(let f of a.protocols)c.uint32(18),c.string(f);if(a.publicKey!=null&&(c.uint32(34),c.bytes(a.publicKey)),a.peerRecordEnvelope!=null&&(c.uint32(42),c.bytes(a.peerRecordEnvelope)),a.metadata!=null&&a.metadata.size>0)for(let[f,l]of a.metadata.entries())c.uint32(50),e.Peer$metadataEntry.codec().encode({key:f,value:l},c);if(a.tags!=null&&a.tags.size>0)for(let[f,l]of a.tags.entries())c.uint32(58),e.Peer$tagsEntry.codec().encode({key:f,value:l},c);a.updated!=null&&(c.uint32(64),c.uint64Number(a.updated)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={addresses:[],protocols:[],metadata:new Map,tags:new Map},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();switch(d>>>3){case 1:{if(u.limits?.addresses!=null&&f.addresses.length===u.limits.addresses)throw new Rt('Decode error - repeated field "addresses" had too many elements');f.addresses.push(Fr.codec().decode(a,a.uint32(),{limits:u.limits?.addresses$}));break}case 2:{if(u.limits?.protocols!=null&&f.protocols.length===u.limits.protocols)throw new Rt('Decode error - repeated field "protocols" had too many elements');f.protocols.push(a.string());break}case 4:{f.publicKey=a.bytes();break}case 5:{f.peerRecordEnvelope=a.bytes();break}case 6:{if(u.limits?.metadata!=null&&f.metadata.size===u.limits.metadata)throw new _r('Decode error - map field "metadata" had too many elements');let h=e.Peer$metadataEntry.codec().decode(a,a.uint32(),{limits:{value:u.limits?.metadata$value}});f.metadata.set(h.key,h.value);break}case 7:{if(u.limits?.tags!=null&&f.tags.size===u.limits.tags)throw new _r('Decode error - map field "tags" had too many elements');let h=e.Peer$tagsEntry.codec().decode(a,a.uint32(),{limits:{value:u.limits?.tags$value}});f.tags.set(h.key,h.value);break}case 8:{f.updated=a.uint64Number();break}default:{a.skipType(d&7);break}}}return f},function*(a,c,u,f={}){let l={addresses:0,protocols:0,metadata:0,tags:0},d=c==null?a.len:a.pos+c;for(;a.pos<d;){let h=a.uint32();switch(h>>>3){case 1:{if(f.limits?.addresses!=null&&l.addresses===f.limits.addresses)throw new Rt('Streaming decode error - repeated field "addresses" had too many elements');for(let y of Fr.codec().stream(a,a.uint32(),`${u}.addresses[]`,{limits:f.limits?.addresses$}))yield{...y,index:l.addresses};l.addresses++;break}case 2:{if(f.limits?.protocols!=null&&l.protocols===f.limits.protocols)throw new Rt('Streaming decode error - repeated field "protocols" had too many elements');yield{field:`${u}.protocols[]`,index:l.protocols,value:a.string()},l.protocols++;break}case 4:{yield{field:`${u}.publicKey`,value:a.bytes()};break}case 5:{yield{field:`${u}.peerRecordEnvelope`,value:a.bytes()};break}case 6:{if(f.limits?.metadata!=null&&l.metadata===f.limits.metadata)throw new Rt('Decode error - map field "metadata" had too many elements');yield*e.Peer$metadataEntry.codec().stream(a,a.uint32(),`${u}.metadata{}`,{limits:{value:f.limits?.metadata$value}}),l.metadata++;break}case 7:{if(f.limits?.tags!=null&&l.tags===f.limits.tags)throw new Rt('Decode error - map field "tags" had too many elements');yield*e.Peer$tagsEntry.codec().stream(a,a.uint32(),`${u}.tags{}`,{limits:{value:f.limits?.tags$value}}),l.tags++;break}case 8:{yield{field:`${u}.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})(Qt||(Qt={}));var Fr;(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:et(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.multiaddr=s.bytes();break}case 2:{c.isCertified=s.bool();break}case 3:{c.observed=s.uint64Number();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.multiaddr`,value:s.bytes()};break}case 2:{yield{field:`${a}.isCertified`,value:s.bool()};break}case 3:{yield{field:`${a}.observed`,value:s.uint64Number()};break}default:{s.skipType(f&7);break}}}})),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})(Fr||(Fr={}));var Mr;(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},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.value=s.uint32();break}case 2:{c.expiry=s.uint64();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.value`,value:s.uint32()};break}case 2:{yield{field:`${a}.expiry`,value:s.uint64()};break}default:{s.skipType(f&7);break}}}})),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})(Mr||(Mr={}));function Md(e,t){if(e.publicKey!=null||t.publicKey==null)return e;let r;e.type==="RSA"&&(r=e.toMultihash());let n=An(t.publicKey,r);return fc(n)}function Fc(e,t,r){let n=Qt.decode(t);return Je(e,n,r)}function Je(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:Md(e,t),addresses:t.addresses.filter(({observed:s})=>s!=null&&s>Date.now()-r).map(({multiaddr:s,isCertified:i})=>({multiaddr:Ae(s),isCertified:i??!1})),metadata:t.metadata,peerRecordEnvelope:t.peerRecordEnvelope??void 0,tags:n}}function Mc(e,t){return qd(e.addresses,t.addresses)&&zd(e.protocols,t.protocols)&&Vd(e.publicKey,t.publicKey)&&Hd(e.peerRecordEnvelope,t.peerRecordEnvelope)&&$d(e.metadata,t.metadata)&&Wd(e.tags,t.tags)}function qd(e,t){return zc(e,t,(r,n)=>!(r.isCertified!==n.isCertified||!W(r.multiaddr,n.multiaddr)))}function zd(e,t){return zc(e,t,(r,n)=>r===n)}function Vd(e,t){return qc(e,t)}function Hd(e,t){return qc(e,t)}function $d(e,t){return Vc(e,t,(r,n)=>W(r,n))}function Wd(e,t){return Vc(e,t,(r,n)=>r.value===n.value&&r.expiry===n.expiry)}function qc(e,t){return e==null&&t==null?!0:e!=null&&t!=null?W(e,t):!1}function zc(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 Vc(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 Jt="/",Hc=new TextEncoder().encode(Jt),to=Hc[0],eo=class e{_buf;constructor(t,r){if(typeof t=="string")this._buf=V(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]!==to)throw new Error("Invalid key")}toString(t="utf8"){return q(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new e(t.join(Jt))}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=Hc),this._buf[0]!==to){let t=new Uint8Array(this._buf.byteLength+1);t.fill(to,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===to;)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(Jt).slice(1)}type(){return jd(this.baseNamespace())}name(){return Zd(this.baseNamespace())}instance(t){return new e(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(Jt)||(t+=Jt),t+=this.type(),new e(t)}parent(){let t=this.list();return t.length===1?new e(Jt):new e(t.slice(0,-1).join(Jt))}child(t){return this.toString()===Jt?t:t.toString()===Jt?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(),...Yd(t.map(r=>r.namespaces()))])}};function jd(e){let t=e.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function Zd(e){let t=e.split(":");return t[t.length-1]}function Yd(e){return[].concat(...e)}var fi="/peers/";function qr(e){if(!Be(e)||e.type==null)throw new F("Invalid PeerId");let t=e.toCID().toString();return new eo(`${fi}${t}`)}async function $c(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=Ae(i.multiaddr)),!On(i.multiaddr))throw new F("Multiaddr was invalid");if(!await t(e,i.multiaddr,o))continue;let a=i.isCertified??!1,c=i.multiaddr.toString(),u=s.get(c);u!=null?i.isCertified=u.isCertified||a:s.set(c,{multiaddr:i.multiaddr,isCertified:a})}return[...s.values()].sort((i,a)=>i.multiaddr.toString().localeCompare(a.multiaddr.toString())).map(({isCertified:i,multiaddr:a})=>{let c=a.getComponents().find(u=>u.code===421)?.value;return e.equals(c)&&(a=a.decapsulate(Ae(`/p2p/${e}`))),{isCertified:i,multiaddr:a.bytes}})}async function no(e,t,r,n){if(t==null)throw new F("Invalid PeerData");if(t.publicKey!=null&&e.publicKey!=null&&!t.publicKey.equals(e.publicKey))throw new F("publicKey bytes do not match peer id publicKey bytes");let o=n.existingPeer?.peer;if(o!=null&&!e.equals(o.id))throw new F("peer id did not match existing peer id");let s=o?.addresses??[],i=new Set(o?.protocols??[]),a=o?.metadata??new Map,c=o?.tags??new Map,u=o?.peerRecordEnvelope;if(r==="patch"){if((t.multiaddrs!=null||t.addresses!=null)&&(s=[],t.multiaddrs!=null&&s.push(...t.multiaddrs.map(d=>({isCertified:!1,multiaddr:d}))),t.addresses!=null&&s.push(...t.addresses)),t.protocols!=null&&(i=new Set(t.protocols)),t.metadata!=null){let d=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);a=ro(d,{validate:Wc})}if(t.tags!=null){let d=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags);c=ro(d,{validate:jc,map:Zc})}t.peerRecordEnvelope!=null&&(u=t.peerRecordEnvelope)}if(r==="merge"){if(t.multiaddrs!=null&&s.push(...t.multiaddrs.map(d=>({isCertified:!1,multiaddr:d}))),t.addresses!=null&&s.push(...t.addresses),t.protocols!=null&&(i=new Set([...i,...t.protocols])),t.metadata!=null){let d=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);for(let[h,y]of d)y==null?a.delete(h):a.set(h,y);a=ro([...a.entries()],{validate:Wc})}if(t.tags!=null){let d=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags),h=new Map(c);for(let[y,g]of d)g==null?h.delete(y):h.set(y,g);c=ro([...h.entries()],{validate:jc,map:Zc})}t.peerRecordEnvelope!=null&&(u=t.peerRecordEnvelope)}let f;o?.id.publicKey!=null?f=_t(o.id.publicKey):t.publicKey!=null?f=_t(t.publicKey):e.publicKey!=null&&(f=_t(e.publicKey));let l={addresses:await $c(e,n.addressFilter??(async()=>!0),s,n.existingPeer?.peerPB.addresses,n),protocols:[...i.values()].sort((d,h)=>d.localeCompare(h)),metadata:a,tags:c,publicKey:f,peerRecordEnvelope:u};return l.addresses.forEach(d=>{d.observed=n.existingPeer?.peerPB.addresses?.find(h=>W(h.multiaddr,h.multiaddr))?.observed??Date.now()}),e.type!=="RSA"&&delete l.publicKey,l}function ro(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 Wc(e,t){if(typeof e!="string")throw new F("Metadata key must be a string");if(!(t instanceof Uint8Array))throw new F("Metadata value must be a Uint8Array")}function jc(e,t){if(typeof e!="string")throw new F("Tag name must be a string");if(t.value!=null){if(parseInt(`${t.value}`,10)!==t.value)throw new F("Tag value must be an integer");if(t.value<0||t.value>100)throw new F("Tag value must be between 0-100")}if(t.ttl!=null){if(parseInt(`${t.ttl}`,10)!==t.ttl)throw new F("Tag ttl must be an integer");if(t.ttl<0)throw new F("Tag ttl must be between greater than 0")}}function Zc(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 Yc(e){let t=e.toString().split("/")[2],r=tt.parse(t,Kt);return _n(r)}function li(e,t,r){let n=Yc(e);return Fc(n,t,r)}function Gd(e,t){return{prefix:fi,filters:(e.filters??[]).map(r=>({key:n,value:o})=>r(li(n,o,t))),orders:(e.orders??[]).map(r=>(n,o)=>r(li(n.key,n.value,t),li(o.key,o.value,t)))}}var oo=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=ni({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:ui({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(qr(t),r)}async load(t,r){let n=qr(t),o=await this.datastore.get(n,r),s=Qt.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,r),new er;return Je(t,s,this.peerId.equals(t)?1/0:this.maxAddressAge)}async save(t,r,n){let o=await this.#t(t,n),s=await no(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 no(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 no(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(Gd(t??{},this.maxAddressAge),t)){let o=Yc(r);if(o.equals(this.peerId))continue;let s=Qt.decode(n);if(this.#r(o,s)){await this.datastore.delete(r,t);continue}yield Je(o,s,this.peerId.equals(o)?1/0:this.maxAddressAge)}}async#t(t,r){try{let n=qr(t),o=await this.datastore.get(n,r),s=Qt.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,r),new er;return{peerPB:s,peer:Je(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=Qt.encode(r);return await this.datastore.put(qr(t),s,o),{peer:Je(t,r,this.maxAddressAge),previous:n?.peer,updated:n==null||!Mc(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 di=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 oo(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 Cc(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=Be(r)?r:Be(r?.expectedPeer)?r.expectedPeer:void 0,s=Be(r)||r===void 0?n:r,i=await Ge.openAndCertify(t,_e.DOMAIN,s),a=_n(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=_e.createFromProtobuf(i.payload),u;try{u=await this.get(a,s)}catch(f){if(f.name!=="NotFoundError")throw f}if(u?.peerRecordEnvelope!=null){let f=Ge.createFromProtobuf(u.peerRecordEnvelope),l=_e.createFromProtobuf(f.payload);if(l.seqNumber>=c.seqNumber)return this.log("sequence number was lower or equal to existing sequence number - stored: %d received: %d",l.seqNumber,c.seqNumber),!1}return await this.patch(c.peerId,{peerRecordEnvelope:t,addresses:c.multiaddrs.map(f=>({isCertified:!0,multiaddr:f}))},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 Xd(e,t={}){return new di(e,t)}return tu(Qd);})();
|
|
2
|
+
"use strict";var Libp2PPeerStore=(()=>{var Zo=Object.defineProperty;var Rl=Object.getOwnPropertyDescriptor;var Ol=Object.getOwnPropertyNames;var kl=Object.prototype.hasOwnProperty;var K=(t,e)=>{for(var r in e)Zo(t,r,{get:e[r],enumerable:!0})},Pl=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Ol(e))!kl.call(t,o)&&o!==r&&Zo(t,o,{get:()=>e[o],enumerable:!(n=Rl(e,o))||n.enumerable});return t};var Ul=t=>Pl(Zo({},"__esModule",{value:!0}),t);var ib={};K(ib,{persistentPeerStore:()=>sb});var M=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},zt=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var Tr=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var Tn=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},Dn=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var vt=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var _n=Symbol.for("@libp2p/peer-id");function Vt(t){return!!t?.[_n]}function Kl(t){return typeof t?.handleEvent=="function"}function Nl(t){return(t!==!0&&t!==!1&&t?.once)??!1}var Ht=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){let o=Nl(n);super.addEventListener(e,i=>{if(o){let a=this.#e.get(i.type);a!=null&&(a=a.filter(({callback:c})=>c!==r),this.#e.set(i.type,a))}Kl(r)?r.handleEvent(i):r(i)},n);let s=this.#e.get(e);s==null&&(s=[],this.#e.set(e,s)),s.push({callback:r,once:o})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==r),this.#e.set(e,o))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var Jo={};K(Jo,{base58btc:()=>X,base58flickr:()=>jl});var lb=new Uint8Array(0);function Ya(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function je(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return St(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return St(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function Xa(t){return new TextEncoder().encode(t)}function Qa(t){return new TextDecoder().decode(t)}function Fl(t){return t?.buffer instanceof ArrayBuffer}function St(t){return Fl(t)?t:t.slice()}function Ml(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var s=t.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function d(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var b=0,m=0,y=0,x=p.length;y!==x&&p[y]===0;)y++,b++;for(var w=(x-y)*f+1>>>0,C=new Uint8Array(w);y!==x;){for(var I=p[y],R=0,_=w-1;(I!==0||R<m)&&_!==-1;_--,R++)I+=256*C[_]>>>0,C[_]=I%a>>>0,I=I/a>>>0;if(I!==0)throw new Error("Non-zero carry");m=R,y++}for(var A=w-m;A!==w&&C[A]===0;)A++;for(var P=c.repeat(b);A<w;++A)P+=t.charAt(C[A]);return P}function l(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var b=0;if(p[b]!==" "){for(var m=0,y=0;p[b]===c;)m++,b++;for(var x=(p.length-b)*u+1>>>0,w=new Uint8Array(x);p[b];){var C=r[p.charCodeAt(b)];if(C===255)return;for(var I=0,R=x-1;(C!==0||I<y)&&R!==-1;R--,I++)C+=a*w[R]>>>0,w[R]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");y=I,b++}if(p[b]!==" "){for(var _=x-y;_!==x&&w[_]===0;)_++;for(var A=new Uint8Array(m+(x-_)),P=m;_!==x;)A[P++]=w[_++];return A}}}function h(p){var b=l(p);if(b)return b;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:l,decode:h}}var ql=Ml,zl=ql,ec=zl;var Go=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Yo=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return tc(this,e)}},Xo=class{decoders;constructor(e){this.decoders=e}or(e){return tc(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function tc(t,e){return new Xo({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Qo=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Go(e,r,n),this.decoder=new Yo(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function $t({name:t,prefix:e,encode:r,decode:n}){return new Qo(t,e,r,n)}function it({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=ec(r,t);return $t({prefix:e,name:t,encode:n,decode:s=>je(o(s))})}function Vl(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Hl(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function $l(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function Y({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=$l(n);return $t({prefix:e,name:t,encode(s){return Hl(s,n,r)},decode(s){return Vl(s,o,r,t)}})}var X=it({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),jl=it({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var es={};K(es,{base32:()=>Ne,base32hex:()=>Yl,base32hexpad:()=>Ql,base32hexpadupper:()=>Jl,base32hexupper:()=>Xl,base32pad:()=>Zl,base32padupper:()=>Gl,base32upper:()=>Wl,base32z:()=>ed});var Ne=Y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Wl=Y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Zl=Y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Gl=Y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Yl=Y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Xl=Y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ql=Y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Jl=Y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ed=Y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ts={};K(ts,{base36:()=>Dr,base36upper:()=>td});var Dr=it({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),td=it({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var rd=oc,rc=128,nd=127,od=~nd,sd=Math.pow(2,31);function oc(t,e,r){e=e||[],r=r||0;for(var n=r;t>=sd;)e[r++]=t&255|rc,t/=128;for(;t&od;)e[r++]=t&255|rc,t>>>=7;return e[r]=t|0,oc.bytes=r-n+1,e}var id=rs,ad=128,nc=127;function rs(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw rs.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&nc)<<o:(i&nc)*Math.pow(2,o),o+=7}while(i>=ad);return rs.bytes=s-n,r}var cd=Math.pow(2,7),ud=Math.pow(2,14),fd=Math.pow(2,21),ld=Math.pow(2,28),dd=Math.pow(2,35),hd=Math.pow(2,42),pd=Math.pow(2,49),md=Math.pow(2,56),yd=Math.pow(2,63),bd=function(t){return t<cd?1:t<ud?2:t<fd?3:t<ld?4:t<dd?5:t<hd?6:t<pd?7:t<md?8:t<yd?9:10},gd={encode:rd,decode:id,encodingLength:bd},xd=gd,_r=xd;function Br(t,e=0){return[_r.decode(t,e),_r.decode.bytes]}function jt(t,e,r=0){return _r.encode(t,e,r),e}function Wt(t){return _r.encodingLength(t)}function Fe(t,e){let r=e.byteLength,n=Wt(t),o=n+Wt(r),s=new Uint8Array(o+r);return jt(t,s,0),jt(r,s,n),s.set(e,o),new Zt(t,r,e,s)}function Gt(t){let e=je(t),[r,n]=Br(e),[o,s]=Br(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Zt(r,o,i,e)}function sc(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Ya(t.bytes,r.bytes)}}var Zt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=St(n),this.bytes=St(o)}};function ic(t,e){let{bytes:r,version:n}=t;return n===0?Ed(r,ns(t),e??X.encoder):vd(r,ns(t),e??Ne.encoder)}var ac=new WeakMap;function ns(t){let e=ac.get(t);if(e==null){let r=new Map;return ac.set(t,r),r}return e}var oe=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=St(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==Lr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Sd)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=Fe(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&sc(e.multihash,n.multihash)}toString(e){return ic(this,e)}toJSON(){return{"/":ic(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new t(n,o,s,i??cc(n,o,s.bytes))}else if(r[Ad]===!0){let{version:n,multihash:o,code:s}=r,i=Gt(o);return t.create(n,s,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==Lr)throw new Error(`Version 0 CID must use dag-pb (code: ${Lr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=cc(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Lr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=je(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Zt(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[d,l]=Br(e.subarray(r));return r+=l,d},o=n(),s=Lr;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,o]=wd(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ns(s).set(n,e),s}};function wd(t,e){switch(t[0]){case"Q":{let r=e??X;return[X.prefix,r.decode(`${X.prefix}${t}`)]}case X.prefix:{let r=e??X;return[X.prefix,r.decode(t)]}case Ne.prefix:{let r=e??Ne;return[Ne.prefix,r.decode(t)]}case Dr.prefix:{let r=e??Dr;return[Dr.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function Ed(t,e,r){let{prefix:n}=r;if(n!==X.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function vd(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var Lr=112,Sd=18;function cc(t,e,r){let n=Wt(t),o=n+Wt(e),s=new Uint8Array(o+r.byteLength);return jt(t,s,0),jt(e,s,n),s.set(r,o),s}var Ad=Symbol.for("@ipld/js-cid/CID");var os={};K(os,{identity:()=>Le});var uc=0,Cd="identity",fc=je;function Id(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return Fe(uc,fc(t))}var Le={code:uc,name:Cd,encode:fc,digest:Id};function W(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Td(t){return t.buffer instanceof ArrayBuffer}function Se(t){return Td(t)?t:t.slice()}async function lc(t,e,r,n){let o=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,Se(e),Se(r.subarray()));return n?.signal?.throwIfAborted(),s}function We(t=0){return new Uint8Array(t)}function Rr(t=0){return new Uint8Array(t)}function ss(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=Rr(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}function dc(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}var pc=Symbol.for("@achingbrain/uint8arraylist");function hc(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let o=r+n.byteLength;if(e<o)return{buf:n,index:e-r};r=o}throw new RangeError("index is out of bounds")}function Ln(t){return!!t?.[pc]}var ye=class t{bufs;length;[pc]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Ln(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Ln(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(e){let r=hc(this.bufs,e);return r.buf[r.index]}set(e,r){let n=hc(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(Ln(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:o}=this._subList(e,r);return ss(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:ss(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),s=new t;return s.length=o,s.bufs=n,s}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,e>=c)continue;let u=e>=a&&e<c,f=r>a&&r<=c;if(u&&f){if(e===a&&r===c){n.push(i);break}let d=e-a;n.push(i.subarray(d,d+(r-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!Ln(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let d=0;d<s;d++)i[d]=-1;for(let d=0;d<o;d++)i[n[d]]=d;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let d=r;d<=c;d+=f){f=0;for(let l=u;l>=0;l--){let h=this.get(d+l);if(n[l]!==h){f=Math.max(1,l-a[h]);break}}if(f===0)return d}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=Rr(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let o=We(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let o=We(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let o=We(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=Rr(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let o=We(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let o=We(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let o=We(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let o=We(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let o=We(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!dc(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var is={};K(is,{base10:()=>Dd});var Dd=it({prefix:"9",name:"base10",alphabet:"0123456789"});var as={};K(as,{base16:()=>_d,base16upper:()=>Bd});var _d=Y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Bd=Y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var cs={};K(cs,{base2:()=>Ld});var Ld=Y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var us={};K(us,{base256emoji:()=>Ud});var mc=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}"),Rd=mc.reduce((t,e,r)=>(t[r]=e,t),[]),Od=mc.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function kd(t){return t.reduce((e,r)=>(e+=Rd[r],e),"")}function Pd(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Od[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Ud=$t({prefix:"\u{1F680}",name:"base256emoji",encode:kd,decode:Pd});var ls={};K(ls,{base64:()=>Kd,base64pad:()=>Nd,base64url:()=>fs,base64urlpad:()=>Fd});var Kd=Y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Nd=Y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),fs=Y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Fd=Y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ds={};K(ds,{base8:()=>Md});var Md=Y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var hs={};K(hs,{identity:()=>qd});var qd=$t({prefix:"\0",name:"identity",encode:t=>Qa(t),decode:t=>Xa(t)});var Qb=new TextEncoder,Jb=new TextDecoder;var ys={};K(ys,{sha256:()=>Or,sha512:()=>$d});var Hd=20;function ms({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new ps(t,e,r,n,o)}var ps=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Hd,this.maxDigestLength=s}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?yc(n,this.code,r?.truncate):n.then(o=>yc(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function yc(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return Fe(e,t)}function gc(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Or=ms({name:"sha2-256",code:18,encode:gc("SHA-256")}),$d=ms({name:"sha2-512",code:19,encode:gc("SHA-512")});var kr={...hs,...cs,...ds,...is,...as,...es,...ts,...Jo,...ls,...us},lg={...ys,...os};function Te(t=0){return new Uint8Array(t)}function At(t=0){return new Uint8Array(t)}function wc(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var xc=wc("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),bs=wc("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=At(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),jd={utf8:xc,"utf-8":xc,hex:kr.base16,latin1:bs,ascii:bs,binary:bs,...kr},Rn=jd;function $(t,e="utf8"){let r=Rn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function z(t,e="utf8"){let r=Rn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var Wd=parseInt("11111",2),gs=parseInt("10000000",2),Zd=parseInt("01111111",2),Ec={0:Pr,1:Pr,2:Gd,3:Qd,4:Jd,5:Xd,6:Yd,16:Pr,22:Pr,48:Pr};function Ze(t,e={offset:0}){let r=t[e.offset]&Wd;if(e.offset++,Ec[r]!=null)return Ec[r](t,e);throw new Error("No decoder for tag "+r)}function Ur(t,e){let r=0;if((t[e.offset]&gs)===gs){let n=t[e.offset]&Zd,o="0x";e.offset++;for(let s=0;s<n;s++,e.offset++)o+=t[e.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=t[e.offset],e.offset++;return r}function Pr(t,e){Ur(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=Ze(t,e);if(n===null)break;r.push(n)}return r}function Gd(t,e){let r=Ur(t,e),n=e.offset,o=e.offset+r,s=[];for(let i=n;i<o;i++)i===n&&t[i]===0||s.push(t[i]);return e.offset+=r,Uint8Array.from(s)}function Yd(t,e){let r=Ur(t,e),n=e.offset+r,o=t[e.offset];e.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;e.offset<n;){let u=t[e.offset];if(e.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let d=0;d<c.length;d++)f+=c[d]<<d*7;a+=`.${f}`,c=[]}}return a}function Xd(t,e){return e.offset++,null}function Qd(t,e){let r=Ur(t,e),n=t[e.offset];e.offset++;let o=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Jd(t,e){let r=Ur(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function eh(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new ye;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function xs(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=eh(t.byteLength);return new ye(Uint8Array.from([e.byteLength|gs]),e)}function ve(t){let e=new ye,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new ye(Uint8Array.from([2]),xs(e),e)}function On(t){let e=Uint8Array.from([0]),r=new ye(e,t);return new ye(Uint8Array.from([3]),xs(r),r)}function ct(t,e=48){let r=new ye;for(let n of t)r.append(n);return new ye(Uint8Array.from([e]),xs(r),r)}var th=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),rh=Uint8Array.from([6,5,43,129,4,0,34]),nh=Uint8Array.from([6,5,43,129,4,0,35]),oh={ext:!0,kty:"EC",crv:"P-256"},sh={ext:!0,kty:"EC",crv:"P-384"},ih={ext:!0,kty:"EC",crv:"P-521"},ws=32,Es=48,vs=66;function Ss(t){let e=Ze(t);return vc(e)}function vc(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===ws*2+1)return n=z(e.subarray(r,r+ws),"base64url"),o=z(e.subarray(r+ws),"base64url"),new Yt({...oh,key_ops:["verify"],x:n,y:o});if(e.byteLength===Es*2+1)return n=z(e.subarray(r,r+Es),"base64url"),o=z(e.subarray(r+Es),"base64url"),new Yt({...sh,key_ops:["verify"],x:n,y:o});if(e.byteLength===vs*2+1)return n=z(e.subarray(r,r+vs),"base64url"),o=z(e.subarray(r+vs),"base64url"),new Yt({...ih,key_ops:["verify"],x:n,y:o});throw new M(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Sc(t){return ct([ve(Uint8Array.from([1])),ct([ah(t.crv)],160),ct([On(new ye(Uint8Array.from([4]),$(t.x??"","base64url"),$(t.y??"","base64url")))],161)]).subarray()}function ah(t){if(t==="P-256")return th;if(t==="P-384")return rh;if(t==="P-521")return nh;throw new M(`Invalid curve ${t}`)}var Yt=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Sc(this.jwk)),this._raw}toMultihash(){return Le.digest(De(this))}toCID(){return oe.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:W(this.raw,e.raw)}async verify(e,r,n){return lc(this.jwk,r,e,n)}};function As(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function ut(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(`${r}expected number, got ${typeof t}`)}if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new RangeError(`${r}expected integer >= 0, got ${t}`)}}function Ae(t,e,r=""){let n=As(t),o=t?.length,s=e!==void 0;if(!n||s&&o!==e){let i=r&&`"${r}" `,a=s?` of length ${e}`:"",c=n?`length=${o}`:`type=${typeof t}`,u=i+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(u):new TypeError(u)}return t}function kn(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(ut(t.outputLen),ut(t.blockLen),t.outputLen<1)throw new Error('"outputLen" must be >= 1');if(t.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Xt(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function Pn(t,e){Ae(t,void 0,"digestInto() output");let r=e.outputLen;if(t.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function Ye(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Un(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Re(t,e){return t<<32-e|t>>>e}var Cc=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",ch=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Kn(t){if(Ae(t),Cc)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=ch[t[r]];return e}var Ge={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ac(t){if(t>=Ge._0&&t<=Ge._9)return t-Ge._0;if(t>=Ge.A&&t<=Ge.F)return t-(Ge.A-10);if(t>=Ge.a&&t<=Ge.f)return t-(Ge.a-10)}function Kr(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Cc)try{return Uint8Array.fromHex(t)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=Ac(t.charCodeAt(s)),a=Ac(t.charCodeAt(s+1));if(i===void 0||a===void 0){let c=t[s]+t[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Cs(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];Ae(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let s=t[n];r.set(s,o),o+=s.length}return r}function Is(t,e={}){let r=(o,s)=>t(s).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function Ic(t=32){ut(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var Ts=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Tc(t,e,r){return t&e^~t&r}function Dc(t,e,r){return t&e^t&r^e&r}var Nr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,o){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=Un(this.buffer)}update(e){Xt(this),Ae(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Un(e);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Xt(this),Pn(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Ye(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=Un(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<u;d++)a.setUint32(4*d,f[d],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=s,e.length=o,e.pos=a,o%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},Xe=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var le=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Nn=BigInt(4294967295),_c=BigInt(32);function uh(t,e=!1){return e?{h:Number(t&Nn),l:Number(t>>_c&Nn)}:{h:Number(t>>_c&Nn)|0,l:Number(t&Nn)|0}}function Bc(t,e=!1){let r=t.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=uh(t[s],e);[n[s],o[s]]=[i,a]}return[n,o]}var Ds=(t,e,r)=>t>>>r,_s=(t,e,r)=>t<<32-r|e>>>r,Ct=(t,e,r)=>t>>>r|e<<32-r,It=(t,e,r)=>t<<32-r|e>>>r,Fr=(t,e,r)=>t<<64-r|e>>>r-32,Mr=(t,e,r)=>t>>>r-32|e<<64-r;function Me(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var Lc=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Rc=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Oc=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),kc=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,Pc=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Uc=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;var lh=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]),ft=new Uint32Array(64),Bs=class extends Nr{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[e,r,n,o,s,i,a,c]}set(e,r,n,o,s,i,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(e,r){for(let d=0;d<16;d++,r+=4)ft[d]=e.getUint32(r,!1);for(let d=16;d<64;d++){let l=ft[d-15],h=ft[d-2],p=Re(l,7)^Re(l,18)^l>>>3,b=Re(h,17)^Re(h,19)^h>>>10;ft[d]=b+ft[d-7]+p+ft[d-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let d=0;d<64;d++){let l=Re(a,6)^Re(a,11)^Re(a,25),h=f+l+Tc(a,c,u)+lh[d]+ft[d]|0,b=(Re(n,2)^Re(n,13)^Re(n,22))+Dc(n,o,s)|0;f=u,u=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+b|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,u,f)}roundClean(){Ye(ft)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Ye(this.buffer)}},Ls=class extends Bs{A=Xe[0]|0;B=Xe[1]|0;C=Xe[2]|0;D=Xe[3]|0;E=Xe[4]|0;F=Xe[5]|0;G=Xe[6]|0;H=Xe[7]|0;constructor(){super(32)}};var Kc=Bc(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),dh=Kc[0],hh=Kc[1],lt=new Uint32Array(80),dt=new Uint32Array(80),Rs=class extends Nr{constructor(e){super(128,e,16,!1)}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:d,Fl:l,Gh:h,Gl:p,Hh:b,Hl:m}=this;return[e,r,n,o,s,i,a,c,u,f,d,l,h,p,b,m]}set(e,r,n,o,s,i,a,c,u,f,d,l,h,p,b,m){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=d|0,this.Fl=l|0,this.Gh=h|0,this.Gl=p|0,this.Hh=b|0,this.Hl=m|0}process(e,r){for(let w=0;w<16;w++,r+=4)lt[w]=e.getUint32(r),dt[w]=e.getUint32(r+=4);for(let w=16;w<80;w++){let C=lt[w-15]|0,I=dt[w-15]|0,R=Ct(C,I,1)^Ct(C,I,8)^Ds(C,I,7),_=It(C,I,1)^It(C,I,8)^_s(C,I,7),A=lt[w-2]|0,P=dt[w-2]|0,H=Ct(A,P,19)^Fr(A,P,61)^Ds(A,P,6),U=It(A,P,19)^Mr(A,P,61)^_s(A,P,6),g=Oc(_,U,dt[w-7],dt[w-16]),E=kc(g,R,H,lt[w-7],lt[w-16]);lt[w]=E|0,dt[w]=g|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:d,El:l,Fh:h,Fl:p,Gh:b,Gl:m,Hh:y,Hl:x}=this;for(let w=0;w<80;w++){let C=Ct(d,l,14)^Ct(d,l,18)^Fr(d,l,41),I=It(d,l,14)^It(d,l,18)^Mr(d,l,41),R=d&h^~d&b,_=l&p^~l&m,A=Pc(x,I,_,hh[w],dt[w]),P=Uc(A,y,C,R,dh[w],lt[w]),H=A|0,U=Ct(n,o,28)^Fr(n,o,34)^Fr(n,o,39),g=It(n,o,28)^Mr(n,o,34)^Mr(n,o,39),E=n&s^n&a^s&a,T=o&i^o&c^i&c;y=b|0,x=m|0,b=h|0,m=p|0,h=d|0,p=l|0,{h:d,l}=Me(u|0,f|0,P|0,H|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let S=Lc(H,g,T);n=Rc(S,P,U,E),o=S|0}({h:n,l:o}=Me(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Me(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Me(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Me(this.Dh|0,this.Dl|0,u|0,f|0),{h:d,l}=Me(this.Eh|0,this.El|0,d|0,l|0),{h,l:p}=Me(this.Fh|0,this.Fl|0,h|0,p|0),{h:b,l:m}=Me(this.Gh|0,this.Gl|0,b|0,m|0),{h:y,l:x}=Me(this.Hh|0,this.Hl|0,y|0,x|0),this.set(n,o,s,i,a,c,u,f,d,l,h,p,b,m,y,x)}roundClean(){Ye(lt,dt)}destroy(){this.destroyed=!0,Ye(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Os=class extends Rs{Ah=le[0]|0;Al=le[1]|0;Bh=le[2]|0;Bl=le[3]|0;Ch=le[4]|0;Cl=le[5]|0;Dh=le[6]|0;Dl=le[7]|0;Eh=le[8]|0;El=le[9]|0;Fh=le[10]|0;Fl=le[11]|0;Gh=le[12]|0;Gl=le[13]|0;Hh=le[14]|0;Hl=le[15]|0;constructor(){super(64)}};var Qt=Is(()=>new Ls,Ts(1));var Fn=Is(()=>new Os,Ts(3));var q=(t,e,r)=>Ae(t,e,r),Ps=ut,Jt=Kn,ie=(...t)=>Cs(...t),er=t=>Kr(t),Tt=As,qr=t=>Ic(t),qn=BigInt(0),ks=BigInt(1);function Oe(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new TypeError(r+"expected boolean, got type="+typeof t)}return t}function zn(t){if(typeof t=="bigint"){if(!Mn(t))throw new RangeError("positive bigint expected, got "+t)}else Ps(t);return t}function ke(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function zr(t){let e=zn(t).toString(16);return e.length&1?"0"+e:e}function Nc(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?qn:BigInt("0x"+t)}function Dt(t){return Nc(Kn(t))}function qe(t){return Nc(Kn(Vr(Ae(t)).reverse()))}function Vn(t,e){if(ut(e),e===0)throw new RangeError("zero length");t=zn(t);let r=t.toString(16);if(r.length>e*2)throw new RangeError("number too large");return Kr(r.padStart(e*2,"0"))}function Us(t,e){return Vn(t,e).reverse()}function Fc(t,e){if(t=q(t),e=q(e),t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function Vr(t){return Uint8Array.from(q(t))}function Hn(t){if(typeof t!="string")throw new TypeError("ascii string expected, got "+typeof t);return Uint8Array.from(t,(e,r)=>{let n=e.charCodeAt(0);if(e.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${t[r]}" with code ${n} at position ${r}`);return n})}var Mn=t=>typeof t=="bigint"&&qn<=t;function ph(t,e,r){return Mn(t)&&Mn(e)&&Mn(r)&&e<=t&&t<r}function tr(t,e,r,n){if(!ph(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function rr(t){if(t<qn)throw new Error("expected non-negative bigint, got "+t);let e;for(e=0;t>qn;t>>=ks,e+=1);return e}var Hr=t=>(ks<<BigInt(t))-ks;function Mc(t,e,r){if(ut(t,"hashLen"),ut(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=m=>new Uint8Array(m),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(t),u=n(t),f=0,d=()=>{c.fill(1),u.fill(0),f=0},l=(...m)=>r(u,ie(c,...m)),h=(m=o)=>{u=l(s,m),c=l(),m.length!==0&&(u=l(i,m),c=l())},p=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let m=0,y=[];for(;m<e;){c=l();let x=c.slice();y.push(x),m+=c.length}return ie(...y)};return(m,y)=>{d(),h(m);let x;for(;(x=y(p()))===void 0;)h();return d(),x}}function Pe(t,e={},r={}){if(Object.prototype.toString.call(t)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,i,a){if(!a&&i!=="function"&&!Object.hasOwn(t,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let c=t[s];if(a&&c===void 0)return;let u=typeof c;if(u!==i||c===null)throw new TypeError(`param "${s}" is invalid: expected ${i}, got ${u}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(e,!1),o(r,!0)}var Ks=()=>{throw new Error("not implemented")};var de=BigInt(0),Q=BigInt(1),_t=BigInt(2),Hc=BigInt(3),$c=BigInt(4),jc=BigInt(5),mh=BigInt(7),Wc=BigInt(8),yh=BigInt(9),Zc=BigInt(16);function ne(t,e){if(e<=de)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=de?r:e+r}function j(t,e,r){if(e<de)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >de;)n*=n,n%=r;return n}function qc(t,e){if(t===de)throw new Error("invert: expected non-zero number");if(e<=de)throw new Error("invert: expected positive modulus, got "+e);let r=ne(t,e),n=e,o=de,s=Q,i=Q,a=de;for(;r!==de;){let u=n/r,f=n-r*u,d=o-i*u,l=s-a*u;n=r,r=f,o=i,s=a,i=d,a=l}if(n!==Q)throw new Error("invert: does not exist");return ne(o,e)}function Ns(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function Gc(t,e){let r=t,n=(r.ORDER+Q)/$c,o=r.pow(e,n);return Ns(r,o,e),o}function bh(t,e){let r=t,n=(r.ORDER-jc)/Wc,o=r.mul(e,_t),s=r.pow(o,n),i=r.mul(e,s),a=r.mul(r.mul(i,_t),s),c=r.mul(i,r.sub(a,r.ONE));return Ns(r,c,e),c}function gh(t){let e=nr(t),r=Yc(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+mh)/Zc;return((a,c)=>{let u=a,f=u.pow(c,i),d=u.mul(f,n),l=u.mul(f,o),h=u.mul(f,s),p=u.eql(u.sqr(d),c),b=u.eql(u.sqr(l),c);f=u.cmov(f,d,p),d=u.cmov(h,l,b);let m=u.eql(u.sqr(d),c),y=u.cmov(f,d,m);return Ns(u,y,c),y})}function Yc(t){if(t<Hc)throw new Error("sqrt is not defined for small field");let e=t-Q,r=0;for(;e%_t===de;)e/=_t,r++;let n=_t,o=nr(t);for(;zc(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Gc;let s=o.pow(n,e),i=(e+Q)/_t;return function(c,u){let f=c;if(f.is0(u))return u;if(zc(f,u)!==1)throw new Error("Cannot find square root");let d=r,l=f.mul(f.ONE,s),h=f.pow(u,e),p=f.pow(u,i);for(;!f.eql(h,f.ONE);){if(f.is0(h))return f.ZERO;let b=1,m=f.sqr(h);for(;!f.eql(m,f.ONE);)if(b++,m=f.sqr(m),b===d)throw new Error("Cannot find square root");let y=Q<<BigInt(d-b-1),x=f.pow(l,y);d=b,l=f.sqr(x),h=f.mul(h,l),p=f.mul(p,x)}return p}}function xh(t){return t%$c===Hc?Gc:t%Wc===jc?bh:t%Zc===yh?gh(t):Yc(t)}var Qe=(t,e)=>(ne(t,e)&Q)===Q,wh=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Fs(t){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=wh.reduce((n,o)=>(n[o]="function",n),e);if(Pe(t,r),ke(t.BYTES,"BYTES"),ke(t.BITS,"BITS"),t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=Q)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function Eh(t,e,r){let n=t;if(r<de)throw new Error("invalid exponent, negatives unsupported");if(r===de)return n.ONE;if(r===Q)return e;let o=n.ONE,s=e;for(;r>de;)r&Q&&(o=n.mul(o,s)),s=n.sqr(s),r>>=Q;return o}function $r(t,e,r=!1){let n=t,o=new Array(e.length).fill(r?n.ZERO:void 0),s=e.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return e.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),i),o}function zc(t,e){let r=t,n=(r.ORDER-Q)/_t,o=r.pow(e,n),s=r.eql(o,r.ONE),i=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function vh(t,e){if(e!==void 0&&Ps(e),t<=de)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=rr(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${e})`);let n=e!==void 0?e:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var Vc=new WeakMap,$n=class{ORDER;BITS;BYTES;isLE;ZERO=de;ONE=Q;_lengths;_mod;constructor(e,r={}){if(e<=Q)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=vh(e,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(e){return ne(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return de<=e&&e<this.ORDER}is0(e){return e===de}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&Q)===Q}neg(e){return ne(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return ne(e*e,this.ORDER)}add(e,r){return ne(e+r,this.ORDER)}sub(e,r){return ne(e-r,this.ORDER)}mul(e,r){return ne(e*r,this.ORDER)}pow(e,r){return Eh(this,e,r)}div(e,r){return ne(e*qc(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return qc(e,this.ORDER)}sqrt(e){let r=Vc.get(this);return r||Vc.set(this,r=xh(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?Us(e,this.BYTES):Vn(e,this.BYTES)}fromBytes(e,r=!1){q(e);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(o);u.set(e,s?0:u.length-e.length),e=u}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=s?qe(e):Dt(e);if(a&&(c=ne(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return $r(this,e)}cmov(e,r,n){return Oe(n,"condition"),n?r:e}};Object.freeze($n.prototype);function nr(t,e={}){return new $n(t,e)}function Xc(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=Q)throw new Error("field order must be greater than 1");let e=rr(t-Q);return Math.ceil(e/8)}function Ms(t){let e=Xc(t);return e+Math.ceil(e/2)}function qs(t,e,r=!1){q(t);let n=t.length,o=Xc(e),s=Math.max(Ms(e),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?qe(t):Dt(t),a=ne(i,e-Q)+Q;return r?Us(a,o):Vn(a,o)}var or=BigInt(0),Bt=BigInt(1);function jr(t,e){let r=e.negate();return t?r:e}function Lt(t,e){let r=$r(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function tu(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function zs(t,e){tu(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),o=2**t,s=Hr(t),i=BigInt(t);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Qc(t,e,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(t&o),c=t>>i;a>n&&(a-=s,c+=Bt);let u=e*n,f=u+Math.abs(a)-1,d=a===0,l=a<0,h=e%2!==0;return{nextN:c,offset:f,isZero:d,isNeg:l,isNegF:h,offsetF:u}}var Vs=new WeakMap,ru=new WeakMap;function Hs(t){return ru.get(t)||1}function Jc(t){if(t!==or)throw new Error("invalid wNAF")}var sr=class{BASE;ZERO;Fn;bits;constructor(e,r){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let o=e;for(;r>or;)r&Bt&&(n=n.add(o)),o=o.double(),r>>=Bt;return n}precomputeWindow(e,r){let{windows:n,windowSize:o}=zs(r,this.bits),s=[],i=e,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let u=1;u<o;u++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=zs(e,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:d,isNegF:l,offsetF:h}=Qc(n,a,i);n=c,f?s=s.add(jr(l,r[h])):o=o.add(jr(d,r[u]))}return Jc(n),{p:o,f:s}}wNAFUnsafe(e,r,n,o=this.ZERO){let s=zs(e,this.bits);for(let i=0;i<s.windows&&n!==or;i++){let{nextN:a,offset:c,isZero:u,isNeg:f}=Qc(n,i,s);if(n=a,!u){let d=r[c];o=o.add(f?d.negate():d)}}return Jc(n),o}getPrecomputes(e,r,n){let o=Vs.get(r);return o||(o=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(o=n(o)),Vs.set(r,o))),o}cached(e,r,n){let o=Hs(e);return this.wNAF(o,this.getPrecomputes(o,e,n),r)}unsafe(e,r,n,o){let s=Hs(e);return s===1?this._unsafeLadder(e,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,e,n),r,o)}createCache(e,r){tu(r,this.bits),ru.set(e,r),Vs.delete(e)}hasCache(e){return Hs(e)!==1}};function nu(t,e,r,n){let o=e,s=t.ZERO,i=t.ZERO;for(;r>or||n>or;)r&Bt&&(s=s.add(o)),n&Bt&&(i=i.add(o)),o=o.double(),r>>=Bt,n>>=Bt;return{p1:s,p2:i}}function eu(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Fs(e),e}else return nr(t,{isLE:r})}function jn(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let c of["p","n","h"]){let u=e[c];if(!(typeof u=="bigint"&&u>or))throw new Error(`CURVE.${c} must be positive bigint`)}let o=eu(e.p,r.Fp,n),s=eu(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:s}}function Wn(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var ht=BigInt(0),ue=BigInt(1),$s=BigInt(2),Sh=BigInt(8);function Ah(t,e,r,n){let o=t.sqr(r),s=t.sqr(n),i=t.add(t.mul(e.a,o),s),a=t.add(t.ONE,t.mul(e.d,t.mul(o,s)));return t.eql(i,a)}function ou(t,e={}){let r=e,n=jn("edwards",t,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;Pe(r,{},{uvRatio:"function"});let c=$s<<BigInt(s.BYTES*8)-ue,u=b=>o.create(b),f=r.uvRatio===void 0?(b,m)=>{try{return{isValid:!0,value:o.sqrt(o.div(b,m))}}catch{return{isValid:!1,value:ht}}}:r.uvRatio;if(!Ah(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function d(b,m,y=!1){let x=y?ue:ht;return tr("coordinate "+b,m,x,c),m}function l(b){if(!(b instanceof h))throw new Error("EdwardsPoint expected")}class h{static BASE=new h(i.Gx,i.Gy,ue,u(i.Gx*i.Gy));static ZERO=new h(ht,ue,ue,ht);static Fp=o;static Fn=s;X;Y;Z;T;constructor(m,y,x,w){this.X=d("x",m),this.Y=d("y",y),this.Z=d("z",x,!0),this.T=d("t",w),Object.freeze(this)}static CURVE(){return i}static fromAffine(m){if(m instanceof h)throw new Error("extended point not allowed");let{x:y,y:x}=m||{};return d("x",y),d("y",x),new h(y,x,ue,u(y*x))}static fromBytes(m,y=!1){let x=o.BYTES,{a:w,d:C}=i;m=Vr(q(m,x,"point")),Oe(y,"zip215");let I=Vr(m),R=m[x-1];I[x-1]=R&-129;let _=qe(I),A=y?c:o.ORDER;tr("point.y",_,ht,A);let P=u(_*_),H=u(P-ue),U=u(C*P-w),{isValid:g,value:E}=f(H,U);if(!g)throw new Error("bad point: invalid y coordinate");let T=(E&ue)===ue,S=(R&128)!==0;if(!y&&E===ht&&S)throw new Error("bad point: x=0 and x_0=1");return S!==T&&(E=u(-E)),h.fromAffine({x:E,y:_})}static fromHex(m,y=!1){return h.fromBytes(er(m),y)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,y=!0){return p.createCache(this,m),y||this.multiply($s),this}assertValidity(){let m=this,{a:y,d:x}=i;if(m.is0())throw new Error("bad point: ZERO");let{X:w,Y:C,Z:I,T:R}=m,_=u(w*w),A=u(C*C),P=u(I*I),H=u(P*P),U=u(_*y),g=u(P*u(U+A)),E=u(H+u(x*u(_*A)));if(g!==E)throw new Error("bad point: equation left != right (1)");let T=u(w*C),S=u(I*R);if(T!==S)throw new Error("bad point: equation left != right (2)")}equals(m){l(m);let{X:y,Y:x,Z:w}=this,{X:C,Y:I,Z:R}=m,_=u(y*R),A=u(C*w),P=u(x*R),H=u(I*w);return _===A&&P===H}is0(){return this.equals(h.ZERO)}negate(){return new h(u(-this.X),this.Y,this.Z,u(-this.T))}double(){let{a:m}=i,{X:y,Y:x,Z:w}=this,C=u(y*y),I=u(x*x),R=u($s*u(w*w)),_=u(m*C),A=y+x,P=u(u(A*A)-C-I),H=_+I,U=H-R,g=_-I,E=u(P*U),T=u(H*g),S=u(P*g),v=u(U*H);return new h(E,T,v,S)}add(m){l(m);let{a:y,d:x}=i,{X:w,Y:C,Z:I,T:R}=this,{X:_,Y:A,Z:P,T:H}=m,U=u(w*_),g=u(C*A),E=u(R*x*H),T=u(I*P),S=u((w+C)*(_+A)-U-g),v=T-E,D=T+E,L=u(g-y*U),B=u(S*v),O=u(D*L),k=u(S*L),F=u(v*D);return new h(B,O,F,k)}subtract(m){return l(m),this.add(m.negate())}multiply(m){if(!s.isValidNot0(m))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:y,f:x}=p.cached(this,m,w=>Lt(h,w));return Lt(h,[y,x])[0]}multiplyUnsafe(m){if(!s.isValid(m))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return m===ht?h.ZERO:this.is0()||m===ue?this:p.unsafe(this,m,y=>Lt(h,y))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return p.unsafe(this,i.n).is0()}toAffine(m){let y=this,x=m,{X:w,Y:C,Z:I}=y,R=y.is0();x==null&&(x=R?Sh:o.inv(I));let _=u(w*x),A=u(C*x),P=o.mul(I,x);if(R)return{x:ht,y:ue};if(P!==ue)throw new Error("invZ was invalid");return{x:_,y:A}}clearCofactor(){return a===ue?this:this.multiplyUnsafe(a)}toBytes(){let{x:m,y}=this.toAffine(),x=o.toBytes(y);return x[x.length-1]|=m&ue?128:0,x}toHex(){return Jt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let p=new sr(h,s.BITS);return s.BITS>=8&&h.BASE.precompute(8),Object.freeze(h.prototype),Object.freeze(h),h}var Zn=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(e){this.ep=e}static fromBytes(e){Ks()}static fromHex(e){Ks()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(e){return this.ep.toAffine(e)}toHex(){return Jt(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(e){return this.assertSame(e),this.init(this.ep.add(e.ep))}subtract(e){return this.assertSame(e),this.init(this.ep.subtract(e.ep))}multiply(e){return this.init(this.ep.multiply(e))}multiplyUnsafe(e){return this.init(this.ep.multiplyUnsafe(e))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(e,r){return this.ep.precompute(e,r),this}};function su(t,e,r={}){if(typeof e!="function")throw new Error('"hash" function param is required');let n=e,o=r;Pe(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=t,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(ke(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let d=o.randomBytes===void 0?qr:o.randomBytes,l=o.adjustScalarBytes===void 0?g=>g:o.adjustScalarBytes,h=o.domain===void 0?(g,E,T)=>{if(Oe(T,"phflag"),E.length||T)throw new Error("Contexts/pre-hash are not supported");return g}:o.domain;function p(g){return c.create(qe(g))}function b(g){let E=_.secretKey;q(g,_.secretKey,"secretKey");let T=q(n(g),2*E,"hashedSecretKey"),S=l(T.slice(0,E)),v=T.slice(E,2*E),D=p(S);return{head:S,prefix:v,scalar:D}}function m(g){let{head:E,prefix:T,scalar:S}=b(g),v=i.multiply(S),D=v.toBytes();return{head:E,prefix:T,scalar:S,point:v,pointBytes:D}}function y(g){return m(g).pointBytes}function x(g=Uint8Array.of(),...E){let T=ie(...E);return p(n(h(T,q(g,void 0,"context"),!!s)))}function w(g,E,T={}){g=q(g,void 0,"message"),s&&(g=s(g));let{prefix:S,scalar:v,pointBytes:D}=m(E),L=x(T.context,S,g),B=i.multiply(L).toBytes(),O=x(T.context,B,D,g),k=c.create(L+O*v);if(!c.isValid(k))throw new Error("sign failed: invalid s");let F=ie(B,c.toBytes(k));return q(F,_.signature,"result")}let C={zip215:o.zip215};function I(g,E,T,S=C){let{context:v}=S,D=S.zip215===void 0?!!C.zip215:S.zip215,L=_.signature;g=q(g,L,"signature"),E=q(E,void 0,"message"),T=q(T,_.publicKey,"publicKey"),D!==void 0&&Oe(D,"zip215"),s&&(E=s(E));let B=L/2,O=g.subarray(0,B),k=qe(g.subarray(B,L)),F,V,N;try{F=t.fromBytes(T,D),V=t.fromBytes(O,D),N=i.multiplyUnsafe(k)}catch{return!1}if(!D&&F.isSmallOrder())return!1;let se=x(v,O,T,E);return V.add(F.multiplyUnsafe(se)).subtract(N).clearCofactor().is0()}let R=a.BYTES,_={secretKey:R,publicKey:R,signature:2*R,seed:R};function A(g){return g=g===void 0?d(_.seed):g,q(g,_.seed,"seed")}function P(g){return Tt(g)&&g.length===_.secretKey}function H(g,E){try{return!!t.fromBytes(g,E===void 0?C.zip215:E)}catch{return!1}}let U={getExtendedPublicKey:m,randomSecretKey:A,isValidSecretKey:P,isValidPublicKey:H,toMontgomery(g){let{y:E}=t.fromBytes(g),T=_.publicKey,S=T===32;if(!S&&T!==57)throw new Error("only defined for 25519 and 448");let v=S?a.div(ue+E,ue-E):a.div(E-ue,E+ue);return a.toBytes(v)},toMontgomerySecret(g){let E=_.secretKey;q(g,E);let T=n(g.subarray(0,E));return l(T).subarray(0,E)}};return Object.freeze(_),Object.freeze(U),Object.freeze({keygen:Wn(A,y),getPublicKey:y,sign:w,verify:I,utils:U,Point:t,lengths:_})}function Wr(t,e){if(ke(t),ke(e),e<0||e>4)throw new Error("invalid I2OSP length: "+e);if(t<0||t>2**(8*e)-1)throw new Error("invalid I2OSP input: "+t);let r=Array.from({length:e}).fill(0);for(let n=e-1;n>=0;n--)r[n]=t&255,t>>>=8;return new Uint8Array(r)}function Ch(t,e){let r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t[n]^e[n];return r}function Ih(t){if(!Tt(t)&&typeof t!="string")throw new Error("DST must be Uint8Array or ascii string");let e=typeof t=="string"?Hn(t):t;if(e.length===0)throw new Error("DST must be non-empty");return e}function js(t,e,r,n){q(t),ke(r),e=Ih(e),e.length>255&&(e=n(ie(Hn("H2C-OVERSIZE-DST-"),e)));let{outputLen:o,blockLen:s}=n,i=Math.ceil(r/o);if(r>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=ie(e,Wr(e.length,1)),c=new Uint8Array(s),u=Wr(r,2),f=new Array(i),d=n(ie(c,t,u,Wr(0,1),a));f[0]=n(ie(d,Wr(1,1),a));for(let h=1;h<i;h++){let p=[Ch(d,f[h-1]),Wr(h+1,1),a];f[h]=n(ie(...p))}return ie(...f).slice(0,r)}var iu="HashToScalar-";var Th=BigInt(0),Je=BigInt(1),au=BigInt(2);var Dh=BigInt(5),_h=BigInt(8),ir=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Ys={p:ir,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:_h,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Bh(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=ir,a=t*t%s*t%s,c=j(a,au,s)*a%s,u=j(c,Je,s)*t%s,f=j(u,Dh,s)*u%s,d=j(f,e,s)*f%s,l=j(d,r,s)*d%s,h=j(l,n,s)*l%s,p=j(h,o,s)*h%s,b=j(p,o,s)*h%s,m=j(b,e,s)*f%s;return{pow_p_5_8:j(m,au,s)*t%s,b2:a}}function Lh(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var Ws=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Xs(t,e){let r=ir,n=ne(e*e*e,r),o=ne(n*n*e,r),s=Bh(t*o).pow_p_5_8,i=ne(t*n*s,r),a=ne(e*i*i,r),c=i,u=ne(i*Ws,r),f=a===t,d=a===ne(-t,r),l=a===ne(-t*Ws,r);return f&&(i=c),(d||l)&&(i=u),Qe(i,r)&&(i=ne(-i,r)),{isValid:f||d,value:i}}var mt=ou(Ys,{uvRatio:Xs}),pt=mt.Fp,fu=mt.Fn;function Rh(t){return su(mt,Fn,Object.assign({adjustScalarBytes:Lh,zip215:!0},t))}var lu=Rh({});var Zs=Ws,Oh=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),kh=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Ph=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Uh=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),cu=t=>Xs(Je,t),Kh=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Gs=t=>pt.create(qe(t)&Kh);function uu(t){let{d:e}=Ys,r=ir,n=y=>pt.create(y),o=n(Zs*t*t),s=n((o+Je)*Ph),i=BigInt(-1),a=n((i-e*o)*n(o+e)),{isValid:c,value:u}=Xs(s,a),f=n(u*t);Qe(f,r)||(f=n(-f)),c||(u=f),c||(i=o);let d=n(i*(o-Je)*Uh-a),l=u*u,h=n((u+u)*a),p=n(d*Oh),b=n(Je-l),m=n(Je+l);return new mt(n(h*m),n(b*p),n(p*m),n(h*b))}var yt=class t extends Zn{static BASE=new t(mt.BASE);static ZERO=new t(mt.ZERO);static Fp=pt;static Fn=fu;constructor(e){super(e)}static fromAffine(e){return new t(mt.fromAffine(e))}assertSame(e){if(!(e instanceof t))throw new Error("RistrettoPoint expected")}init(e){return new t(e)}static fromBytes(e){Ae(e,32);let{a:r,d:n}=Ys,o=ir,s=C=>pt.create(C),i=Gs(e);if(!Fc(pt.toBytes(i),e)||Qe(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(Je+r*a),u=s(Je-r*a),f=s(c*c),d=s(u*u),l=s(r*n*f-d),{isValid:h,value:p}=cu(s(l*d)),b=s(p*u),m=s(p*b*l),y=s((i+i)*b);Qe(y,o)&&(y=s(-y));let x=s(c*m),w=s(y*x);if(!h||Qe(w,o)||x===Th)throw new Error("invalid ristretto255 encoding 2");return new t(new mt(y,x,Je,w))}static fromHex(e){return t.fromBytes(Kr(e))}toBytes(){let{X:e,Y:r,Z:n,T:o}=this.ep,s=ir,i=m=>pt.create(m),a=i(i(n+r)*i(n-r)),c=i(e*r),u=i(c*c),{value:f}=cu(i(a*u)),d=i(f*a),l=i(f*c),h=i(d*l*o),p;if(Qe(o*h,s)){let m=i(r*Zs),y=i(e*Zs);e=m,r=y,p=i(d*kh)}else p=l;Qe(e*h,s)&&(r=i(-r));let b=i((n-r)*p);return Qe(b,s)&&(b=i(-b)),pt.toBytes(b)}equals(e){this.assertSame(e);let{X:r,Y:n}=this.ep,{X:o,Y:s}=e.ep,i=u=>pt.create(u),a=i(r*s)===i(n*o),c=i(n*s)===i(r*o);return a||c}is0(){return this.equals(t.ZERO)}};Object.freeze(yt.BASE);Object.freeze(yt.ZERO);Object.freeze(yt.prototype);Object.freeze(yt);var Nh=Object.freeze({Point:yt,hashToCurve(t,e){let r=e?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":e.DST,n=js(t,r,64,Fn);return Nh.deriveToCurve(n)},hashToScalar(t,e={DST:iu}){let r=js(t,e.DST,64,Fn);return fu.create(qe(r))},deriveToCurve(t){Ae(t,64);let e=Gs(t.subarray(0,32)),r=uu(e),n=Gs(t.subarray(32,64)),o=uu(n);return new yt(r.add(o))}});var Zr=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},Gn=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var _e={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new Gn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var Yn=32;var Qs,Fh=(async()=>{try{return await _e.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Mh(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await _e.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await _e.get().subtle.verify({name:"Ed25519"},n,Se(e),Se(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function qh(t,e,r){return lu.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function du(t,e,r){return Qs==null&&(Qs=await Fh),Qs?Mh(t,e,r):qh(t,e,r)}function zh(t){return t?.buffer instanceof ArrayBuffer}function Js(t){if(zh(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Rt(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=At(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return Js(r)}function Xn(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Qn=class{type="Ed25519";raw;constructor(e){this.raw=ei(e,Yn)}toMultihash(){return Le.digest(De(this))}toCID(){return oe.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:W(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let o=du(this.raw,r,e);return Xn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function ti(t){return t=ei(t,Yn),new Qn(t)}function ei(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new M(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}function pu(t=0){return new Uint8Array(t)}var Hh=Math.pow(2,7),$h=Math.pow(2,14),jh=Math.pow(2,21),mu=Math.pow(2,28),yu=Math.pow(2,35),bu=Math.pow(2,42),gu=Math.pow(2,49),J=128,bt=127;function Ot(t){if(t<Hh)return 1;if(t<$h)return 2;if(t<jh)return 3;if(t<mu)return 4;if(t<yu)return 5;if(t<bu)return 6;if(t<gu)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ri(t,e,r=0){switch(Ot(t)){case 8:e[r++]=t&255|J,t/=128;case 7:e[r++]=t&255|J,t/=128;case 6:e[r++]=t&255|J,t/=128;case 5:e[r++]=t&255|J,t/=128;case 4:e[r++]=t&255|J,t>>>=7;case 3:e[r++]=t&255|J,t>>>=7;case 2:e[r++]=t&255|J,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Wh(t,e,r=0){switch(Ot(t)){case 8:e.set(r++,t&255|J),t/=128;case 7:e.set(r++,t&255|J),t/=128;case 6:e.set(r++,t&255|J),t/=128;case 5:e.set(r++,t&255|J),t/=128;case 4:e.set(r++,t&255|J),t>>>=7;case 3:e.set(r++,t&255|J),t>>>=7;case 2:e.set(r++,t&255|J),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function xu(t,e){let r=t[e],n=0;if(n+=r&bt,r<J||(r=t[e+1],n+=(r&bt)<<7,r<J)||(r=t[e+2],n+=(r&bt)<<14,r<J)||(r=t[e+3],n+=(r&bt)<<21,r<J)||(r=t[e+4],n+=(r&bt)*mu,r<J)||(r=t[e+5],n+=(r&bt)*yu,r<J)||(r=t[e+6],n+=(r&bt)*bu,r<J)||(r=t[e+7],n+=(r&bt)*gu,r<J))return n;throw new RangeError("Could not decode varint")}function Jn(t,e,r=0){return e==null&&(e=pu(Ot(t))),e instanceof Uint8Array?ri(t,e,r):Wh(t,e,r)}var ni=new Float32Array([-0]),gt=new Uint8Array(ni.buffer);function wu(t,e,r){ni[0]=t,e[r]=gt[0],e[r+1]=gt[1],e[r+2]=gt[2],e[r+3]=gt[3]}function Eu(t,e){return gt[0]=t[e],gt[1]=t[e+1],gt[2]=t[e+2],gt[3]=t[e+3],ni[0]}var oi=new Float64Array([-0]),pe=new Uint8Array(oi.buffer);function vu(t,e,r){oi[0]=t,e[r]=pe[0],e[r+1]=pe[1],e[r+2]=pe[2],e[r+3]=pe[3],e[r+4]=pe[4],e[r+5]=pe[5],e[r+6]=pe[6],e[r+7]=pe[7]}function Su(t,e){return pe[0]=t[e],pe[1]=t[e+1],pe[2]=t[e+2],pe[3]=t[e+3],pe[4]=t[e+4],pe[5]=t[e+5],pe[6]=t[e+6],pe[7]=t[e+7],oi[0]}var Gh=BigInt(Number.MAX_SAFE_INTEGER),Yh=BigInt(Number.MIN_SAFE_INTEGER),Ce=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return kt;if(e<Gh&&e>Yh)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,o=e-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Au&&(o=0n,++n>Au&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return kt;let r=e<0;r&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new t(n,o)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):kt}},kt=new Ce(0,0);kt.toBigInt=function(){return 0n};kt.zzEncode=kt.zzDecode=function(){return this};kt.length=function(){return 1};var Au=4294967296n;function Cu(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function Iu(t,e,r){if(r-e<1)return"";let o,s=[],i=0,a;for(;e<r;)a=t[e++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function si(t,e,r){let n=r,o,s;for(let i=0;i<t.length;++i)o=t.charCodeAt(i),o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&((s=t.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128);return r-n}function Ue(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function eo(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var ii=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Ue(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ue(this,4);return eo(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ue(this,4);return eo(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ue(this,4);let e=Eu(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ue(this,4);let e=Su(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw Ue(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Iu(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ue(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ue(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Ce(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Ue(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw Ue(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ue(this,8);let e=eo(this.buf,this.pos+=4),r=eo(this.buf,this.pos+=4);return new Ce(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=xu(this.buf,this.pos);return this.pos+=Ot(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Gr(t){return new ii(t instanceof Uint8Array?t:t.subarray())}function be(t,e,r){let n=Gr(t);return e.decode(n,void 0,r)}function Pt(t=0){return new Uint8Array(t)}var li={};K(li,{base10:()=>np});var nw=new Uint8Array(0);function Du(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function et(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function _u(t){return new TextEncoder().encode(t)}function Bu(t){return new TextDecoder().decode(t)}function Xh(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var s=t.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function d(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var b=0,m=0,y=0,x=p.length;y!==x&&p[y]===0;)y++,b++;for(var w=(x-y)*f+1>>>0,C=new Uint8Array(w);y!==x;){for(var I=p[y],R=0,_=w-1;(I!==0||R<m)&&_!==-1;_--,R++)I+=256*C[_]>>>0,C[_]=I%a>>>0,I=I/a>>>0;if(I!==0)throw new Error("Non-zero carry");m=R,y++}for(var A=w-m;A!==w&&C[A]===0;)A++;for(var P=c.repeat(b);A<w;++A)P+=t.charAt(C[A]);return P}function l(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var b=0;if(p[b]!==" "){for(var m=0,y=0;p[b]===c;)m++,b++;for(var x=(p.length-b)*u+1>>>0,w=new Uint8Array(x);p[b];){var C=r[p.charCodeAt(b)];if(C===255)return;for(var I=0,R=x-1;(C!==0||I<y)&&R!==-1;R--,I++)C+=a*w[R]>>>0,w[R]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");y=I,b++}if(p[b]!==" "){for(var _=x-y;_!==x&&w[_]===0;)_++;for(var A=new Uint8Array(m+(x-_)),P=m;_!==x;)A[P++]=w[_++];return A}}}function h(p){var b=l(p);if(b)return b;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:l,decode:h}}var Qh=Xh,Jh=Qh,Ru=Jh;var ai=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},ci=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Ou(this,e)}},ui=class{decoders;constructor(e){this.decoders=e}or(e){return Ou(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ou(t,e){return new ui({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var fi=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new ai(e,r,n),this.decoder=new ci(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ar({name:t,prefix:e,encode:r,decode:n}){return new fi(t,e,r,n)}function xt({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=Ru(r,t);return ar({prefix:e,name:t,encode:n,decode:s=>et(o(s))})}function ep(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function tp(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function rp(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function ee({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=rp(n);return ar({prefix:e,name:t,encode(s){return tp(s,n,r)},decode(s){return ep(s,o,r,t)}})}var np=xt({prefix:"9",name:"base10",alphabet:"0123456789"});var di={};K(di,{base16:()=>op,base16upper:()=>sp});var op=ee({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),sp=ee({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var hi={};K(hi,{base2:()=>ip});var ip=ee({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var pi={};K(pi,{base256emoji:()=>lp});var ku=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),ap=ku.reduce((t,e,r)=>(t[r]=e,t),[]),cp=ku.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function up(t){return t.reduce((e,r)=>(e+=ap[r],e),"")}function fp(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=cp[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var lp=ar({prefix:"\u{1F680}",name:"base256emoji",encode:up,decode:fp});var mi={};K(mi,{base32:()=>cr,base32hex:()=>mp,base32hexpad:()=>bp,base32hexpadupper:()=>gp,base32hexupper:()=>yp,base32pad:()=>hp,base32padupper:()=>pp,base32upper:()=>dp,base32z:()=>xp});var cr=ee({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),dp=ee({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),hp=ee({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),pp=ee({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),mp=ee({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),yp=ee({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),bp=ee({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),gp=ee({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),xp=ee({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var yi={};K(yi,{base36:()=>Yr,base36upper:()=>wp});var Yr=xt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),wp=xt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var bi={};K(bi,{base58btc:()=>ze,base58flickr:()=>Ep});var ze=xt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ep=xt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var gi={};K(gi,{base64:()=>vp,base64pad:()=>Sp,base64url:()=>Ap,base64urlpad:()=>Cp});var vp=ee({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Sp=ee({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ap=ee({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Cp=ee({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var xi={};K(xi,{base8:()=>Ip});var Ip=ee({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var wi={};K(wi,{identity:()=>Tp});var Tp=ar({prefix:"\0",name:"identity",encode:t=>Bu(t),decode:t=>_u(t)});var xw=new TextEncoder,ww=new TextDecoder;var vi={};K(vi,{identity:()=>Yp});var Bp=Ku,Pu=128,Lp=127,Rp=~Lp,Op=Math.pow(2,31);function Ku(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Op;)e[r++]=t&255|Pu,t/=128;for(;t&Rp;)e[r++]=t&255|Pu,t>>>=7;return e[r]=t|0,Ku.bytes=r-n+1,e}var kp=Ei,Pp=128,Uu=127;function Ei(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw Ei.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&Uu)<<o:(i&Uu)*Math.pow(2,o),o+=7}while(i>=Pp);return Ei.bytes=s-n,r}var Up=Math.pow(2,7),Kp=Math.pow(2,14),Np=Math.pow(2,21),Fp=Math.pow(2,28),Mp=Math.pow(2,35),qp=Math.pow(2,42),zp=Math.pow(2,49),Vp=Math.pow(2,56),Hp=Math.pow(2,63),$p=function(t){return t<Up?1:t<Kp?2:t<Np?3:t<Fp?4:t<Mp?5:t<qp?6:t<zp?7:t<Vp?8:t<Hp?9:10},jp={encode:Bp,decode:kp,encodingLength:$p},Wp=jp,Xr=Wp;function Qr(t,e=0){return[Xr.decode(t,e),Xr.decode.bytes]}function ur(t,e,r=0){return Xr.encode(t,e,r),e}function fr(t){return Xr.encodingLength(t)}function dr(t,e){let r=e.byteLength,n=fr(t),o=n+fr(r),s=new Uint8Array(o+r);return ur(t,s,0),ur(r,s,n),s.set(e,o),new lr(t,r,e,s)}function Nu(t){let e=et(t),[r,n]=Qr(e),[o,s]=Qr(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new lr(r,o,i,e)}function Fu(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Du(t.bytes,r.bytes)}}var lr=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};var Mu=0,Zp="identity",qu=et;function Gp(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return dr(Mu,qu(t))}var Yp={code:Mu,name:Zp,encode:qu,digest:Gp};var Ci={};K(Ci,{sha256:()=>Qp,sha512:()=>Jp});var Xp=20;function Ai({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new Si(t,e,r,n,o)}var Si=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Xp,this.maxDigestLength=s}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?zu(n,this.code,r?.truncate):n.then(o=>zu(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function zu(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return dr(e,t)}function Hu(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Qp=Ai({name:"sha2-256",code:18,encode:Hu("SHA-256")}),Jp=Ai({name:"sha2-512",code:19,encode:Hu("SHA-512")});function $u(t,e){let{bytes:r,version:n}=t;return n===0?tm(r,Ii(t),e??ze.encoder):rm(r,Ii(t),e??cr.encoder)}var ju=new WeakMap;function Ii(t){let e=ju.get(t);if(e==null){let r=new Map;return ju.set(t,r),r}return e}var ro=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==en)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==nm)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=dr(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&Fu(e.multihash,n.multihash)}toString(e){return $u(this,e)}toJSON(){return{"/":$u(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new t(n,o,s,i??Wu(n,o,s.bytes))}else if(r[om]===!0){let{version:n,multihash:o,code:s}=r,i=Nu(o);return t.create(n,s,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==en)throw new Error(`Version 0 CID must use dag-pb (code: ${en}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=Wu(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,en,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=et(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new lr(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[d,l]=Qr(e.subarray(r));return r+=l,d},o=n(),s=en;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,o]=em(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ii(s).set(n,e),s}};function em(t,e){switch(t[0]){case"Q":{let r=e??ze;return[ze.prefix,r.decode(`${ze.prefix}${t}`)]}case ze.prefix:{let r=e??ze;return[ze.prefix,r.decode(t)]}case cr.prefix:{let r=e??cr;return[cr.prefix,r.decode(t)]}case Yr.prefix:{let r=e??Yr;return[Yr.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function tm(t,e,r){let{prefix:n}=r;if(n!==ze.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function rm(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var en=112,nm=18;function Wu(t,e,r){let n=fr(t),o=n+fr(e),s=new Uint8Array(o+r.byteLength);return ur(t,s,0),ur(e,s,n),s.set(r,o),s}var om=Symbol.for("@ipld/js-cid/CID");var Ti={...wi,...hi,...xi,...li,...di,...mi,...yi,...bi,...gi,...pi},zw={...Ci,...vi};function Gu(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Zu=Gu("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Di=Gu("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Pt(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),sm={utf8:Zu,"utf-8":Zu,hex:Ti.base16,latin1:Di,ascii:Di,binary:Di,...Ti},Yu=sm;function Xu(t,e="utf8"){let r=Yu[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function _i(t){let e=t??8192,r=e>>>1,n,o=e;return function(i){if(i<1||i>r)return Pt(i);o+i>e&&(n=Pt(e),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Ut=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Bi(){}var Ri=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},im=_i();function am(t){return globalThis.Buffer!=null?Pt(t):im(t)}var rn=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ut(Bi,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Ut(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Oi((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(no,10,Ce.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Ce.fromBigInt(e);return this._push(no,r.length(),r)}uint64Number(e){return this._push(ri,Ot(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=Ce.fromBigInt(e).zzEncode();return this._push(no,r.length(),r)}sint64Number(e){let r=Ce.fromNumber(e).zzEncode();return this._push(no,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Li,1,e?1:0)}fixed32(e){return this._push(tn,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Ce.fromBigInt(e);return this._push(tn,4,r.lo)._push(tn,4,r.hi)}fixed64Number(e){let r=Ce.fromNumber(e);return this._push(tn,4,r.lo)._push(tn,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(wu,4,e)}double(e){return this._push(vu,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Li,1,0):this.uint32(r)._push(um,r,e)}string(e){let r=Cu(e);return r!==0?this.uint32(r)._push(si,r,e):this._push(Li,1,0)}fork(){return this.states=new Ri(this),this.head=this.tail=new Ut(Bi,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Ut(Bi,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=am(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Li(t,e,r){e[r]=t&255}function cm(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var Oi=class extends Ut{next;constructor(e,r){super(cm,e,r),this.next=void 0}};function no(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function tn(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function um(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(rn.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(fm,e,t),this},rn.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(lm,e,t),this});function fm(t,e,r){e.set(t,r)}function lm(t,e,r){t.length<40?si(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(Xu(t),r)}function ki(){return new rn}function ge(t,e){let r=ki();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*xe(t,e,r){let n=Gr(t);yield*e.stream(n,void 0,"$",r)}var oo={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function so(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function Pi(t){function e(s){if(t[s.toString()]==null)throw new Error("Invalid enum value");return t[s]}let r=function(i,a){let c=e(i);a.int32(c)},n=function(i){let a=i.int32();return e(a)},o=function*(i){let a=i.int32();yield e(a)};return so("enum",oo.VARINT,r,n,o)}function we(t,e,r){return so("message",oo.LENGTH_DELIMITED,t,e,r)}var Be=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},nn=class extends Error{code="ERR_MAX_SIZE";name="MaxSizeError"};var Z;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(Z||(Z={}));var Ui;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(Ui||(Ui={}));(function(t){t.codec=()=>Pi(Ui)})(Z||(Z={}));var Ve;(function(t){let e;t.codec=()=>(e==null&&(e=we((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),Z.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=Z.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:Z.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ge(s,t.codec())}t.encode=r;function n(s,i){return be(s,t.codec(),i)}t.decode=n;function o(s,i){return xe(s,t.codec(),i)}t.stream=o})(Ve||(Ve={}));var Ki;(function(t){let e;t.codec=()=>(e==null&&(e=we((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),Z.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=Z.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:Z.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ge(s,t.codec())}t.encode=r;function n(s,i){return be(s,t.codec(),i)}t.decode=n;function o(s,i){return xe(s,t.codec(),i)}t.stream=o})(Ki||(Ki={}));var sn={};K(sn,{MAX_RSA_KEY_SIZE:()=>Ni,generateRSAKeyPair:()=>rf,jwkToJWKKeyPair:()=>nf,jwkToPkcs1:()=>mm,jwkToPkix:()=>zi,jwkToRSAPrivateKey:()=>ji,pkcs1MessageToJwk:()=>Mi,pkcs1MessageToRSAPrivateKey:()=>Vi,pkcs1ToJwk:()=>pm,pkcs1ToRSAPrivateKey:()=>tf,pkixMessageToJwk:()=>qi,pkixMessageToRSAPublicKey:()=>$i,pkixToJwk:()=>ym,pkixToRSAPublicKey:()=>Hi});var hr=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=sn.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return oe.createV1(114,this._multihash)}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:W(this.raw,e.raw)}verify(e,r,n){return ef(this.jwk,r,e,n)}},on=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=sn.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:W(this.raw,e.raw)}sign(e,r){return Ju(this.jwk,e,r)}};var Ni=8192,Fi=18,dm=1062,hm=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function pm(t){let e=Ze(t);return Mi(e)}function Mi(t){return{n:z(t[1],"base64url"),e:z(t[2],"base64url"),d:z(t[3],"base64url"),p:z(t[4],"base64url"),q:z(t[5],"base64url"),dp:z(t[6],"base64url"),dq:z(t[7],"base64url"),qi:z(t[8],"base64url"),kty:"RSA"}}function mm(t){if(t.n==null||t.e==null||t.d==null||t.p==null||t.q==null||t.dp==null||t.dq==null||t.qi==null)throw new M("JWK was missing components");return ct([ve(Uint8Array.from([0])),ve($(t.n,"base64url")),ve($(t.e,"base64url")),ve($(t.d,"base64url")),ve($(t.p,"base64url")),ve($(t.q,"base64url")),ve($(t.dp,"base64url")),ve($(t.dq,"base64url")),ve($(t.qi,"base64url"))]).subarray()}function ym(t){let e=Ze(t,{offset:0});return qi(e)}function qi(t){let e=Ze(t[1],{offset:0});return{kty:"RSA",n:z(e[0],"base64url"),e:z(e[1],"base64url")}}function zi(t){if(t.n==null||t.e==null)throw new M("JWK was missing components");return ct([hm,On(ct([ve($(t.n,"base64url")),ve($(t.e,"base64url"))]))]).subarray()}function tf(t){let e=Ze(t);return Vi(e)}function Vi(t){let e=Mi(t);return ji(e)}function Hi(t,e){if(t.byteLength>=dm)throw new zt("Key size is too large");let r=Ze(t,{offset:0});return $i(r,t,e)}function $i(t,e,r){let n=qi(t);if(r==null){let o=Qt(Ve.encode({Type:Z.RSA,Data:e}));r=Fe(Fi,o)}return new hr(n,r)}function ji(t){if(sf(t)>Ni)throw new M("Key size is too large");let e=nf(t),r=Qt(Ve.encode({Type:Z.RSA,Data:zi(e.publicKey)})),n=Fe(Fi,r);return new on(e.privateKey,new hr(e.publicKey,n))}async function rf(t){if(t>Ni)throw new M("Key size is too large");let e=await of(t),r=Qt(Ve.encode({Type:Z.RSA,Data:zi(e.publicKey)})),n=Fe(Fi,r);return new on(e.privateKey,new hr(e.publicKey,n))}function nf(t){if(t==null)throw new M("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function of(t,e){let r=await _e.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:t,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await bm(r,e);return{privateKey:n[0],publicKey:n[1]}}async function Ju(t,e,r){let n=await _e.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await _e.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,Se(e instanceof Uint8Array?e:e.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function ef(t,e,r,n){let o=await _e.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await _e.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,Se(e),Se(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),s}async function bm(t,e){if(t.privateKey==null||t.publicKey==null)throw new M("Private and public key are required");let r=await Promise.all([_e.get().subtle.exportKey("jwk",t.privateKey),_e.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function sf(t){if(t.kty!=="RSA")throw new M("invalid key type");if(t.n==null)throw new M("invalid key modulus");return $(t.n,"base64url").length*8}var io=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(kn(e),Ae(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Ye(o)}update(e){return Xt(this),this.iHash.update(e),this}digestInto(e){Xt(this),Pn(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},af=(()=>{let t=((e,r,n)=>new io(e,r).update(n).digest());return t.create=(e,r)=>new io(e,r),t})();var cf=(t,e)=>(t+(t>=0?e:-e)/uf)/e;function gm(t,e,r){tr("scalar",t,He,r);let[[n,o],[s,i]]=e,a=cf(i*t,r),c=cf(-o*t,r),u=t-a*n-c*s,f=-a*o-c*i,d=u<He,l=f<He;d&&(u=-u),l&&(f=-f);let h=Hr(Math.ceil(rr(r)/2))+wt;if(u<He||u>=h||f<He||f>=h)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:d,k1:u,k2neg:l,k2:f}}function Zi(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Wi(t,e){Pe(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Oe(r.lowS,"lowS"),Oe(r.prehash,"prehash"),r.format!==void 0&&Zi(r.format),r}var Gi=class extends Error{constructor(e=""){super(e)}},Ke={Err:Gi,_tlv:{encode:(t,e)=>{let{Err:r}=Ke;if(ke(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(typeof e!="string")throw new TypeError('"data" expected string, got type='+typeof e);if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=zr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?zr(o.length/2|128):"";return zr(t)+s+o+e},decode(t,e){let{Err:r}=Ke;e=q(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=Ke;if(zn(t),t<He)throw new e("integer: negative integers are not allowed");let r=zr(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=Ke;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return Dt(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=Ke,o=q(t,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:u,l:f}=n.decode(2,c);if(f.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(t){let{_tlv:e,_int:r}=Ke,n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),s=n+o;return e.encode(48,s)}};Object.freeze(Ke._tlv);Object.freeze(Ke._int);Object.freeze(Ke);var He=BigInt(0),wt=BigInt(1),uf=BigInt(2),ao=BigInt(3),xm=BigInt(4);function ff(t,e={}){let r=jn("weierstrass",t,e),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;Pe(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c,allowInfinityPoint:u}=e;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=df(n,o);function d(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(U,g,E){if(u&&g.is0())return Uint8Array.of(0);let{x:T,y:S}=g.toAffine(),v=n.toBytes(T);if(Oe(E,"isCompressed"),E){d();let D=!n.isOdd(S);return ie(lf(D),v)}else return ie(Uint8Array.of(4),v,n.toBytes(S))}function h(U){q(U,void 0,"Point");let{publicKey:g,publicKeyUncompressed:E}=f,T=U.length,S=U[0],v=U.subarray(1);if(u&&T===1&&S===0)return{x:n.ZERO,y:n.ZERO};if(T===g&&(S===2||S===3)){let D=n.fromBytes(v);if(!n.isValid(D))throw new Error("bad point: is not on curve, wrong x");let L=m(D),B;try{B=n.sqrt(L)}catch(F){let V=F instanceof Error?": "+F.message:"";throw new Error("bad point: is not on curve, sqrt error"+V)}d();let O=n.isOdd(B);return(S&1)===1!==O&&(B=n.neg(B)),{x:D,y:B}}else if(T===E&&S===4){let D=n.BYTES,L=n.fromBytes(v.subarray(0,D)),B=n.fromBytes(v.subarray(D,D*2));if(!y(L,B))throw new Error("bad point: is not on curve");return{x:L,y:B}}else throw new Error(`bad point: got length ${T}, expected compressed=${g} or uncompressed=${E}`)}let p=e.toBytes===void 0?l:e.toBytes,b=e.fromBytes===void 0?h:e.fromBytes;function m(U){let g=n.sqr(U),E=n.mul(g,U);return n.add(n.add(E,n.mul(U,s.a)),s.b)}function y(U,g){let E=n.sqr(g),T=m(U);return n.eql(E,T)}if(!y(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let x=n.mul(n.pow(s.a,ao),xm),w=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(x,w)))throw new Error("bad curve params: a or b");function C(U,g,E=!1){if(!n.isValid(g)||E&&n.is0(g))throw new Error(`bad point coordinate ${U}`);return g}function I(U){if(!(U instanceof A))throw new Error("Weierstrass Point expected")}function R(U){if(!c||!c.basises)throw new Error("no endo");return gm(U,c.basises,o.ORDER)}function _(U,g,E,T,S){return E=new A(n.mul(E.X,U),E.Y,E.Z),g=jr(T,g),E=jr(S,E),g.add(E)}class A{static BASE=new A(s.Gx,s.Gy,n.ONE);static ZERO=new A(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(g,E,T){this.X=C("x",g),this.Y=C("y",E,!0),this.Z=C("z",T),Object.freeze(this)}static CURVE(){return s}static fromAffine(g){let{x:E,y:T}=g||{};if(!g||!n.isValid(E)||!n.isValid(T))throw new Error("invalid affine point");if(g instanceof A)throw new Error("projective point not allowed");return n.is0(E)&&n.is0(T)?A.ZERO:new A(E,T,n.ONE)}static fromBytes(g){let E=A.fromAffine(b(q(g,void 0,"point")));return E.assertValidity(),E}static fromHex(g){return A.fromBytes(er(g))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,E=!0){return H.createCache(this,g),E||this.multiply(ao),this}assertValidity(){let g=this;if(g.is0()){if(e.allowInfinityPoint&&n.is0(g.X)&&n.eql(g.Y,n.ONE)&&n.is0(g.Z))return;throw new Error("bad point: ZERO")}let{x:E,y:T}=g.toAffine();if(!n.isValid(E)||!n.isValid(T))throw new Error("bad point: x or y not field elements");if(!y(E,T))throw new Error("bad point: equation left != right");if(!g.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:g}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(g)}equals(g){I(g);let{X:E,Y:T,Z:S}=this,{X:v,Y:D,Z:L}=g,B=n.eql(n.mul(E,L),n.mul(v,S)),O=n.eql(n.mul(T,L),n.mul(D,S));return B&&O}negate(){return new A(this.X,n.neg(this.Y),this.Z)}double(){let{a:g,b:E}=s,T=n.mul(E,ao),{X:S,Y:v,Z:D}=this,L=n.ZERO,B=n.ZERO,O=n.ZERO,k=n.mul(S,S),F=n.mul(v,v),V=n.mul(D,D),N=n.mul(S,v);return N=n.add(N,N),O=n.mul(S,D),O=n.add(O,O),L=n.mul(g,O),B=n.mul(T,V),B=n.add(L,B),L=n.sub(F,B),B=n.add(F,B),B=n.mul(L,B),L=n.mul(N,L),O=n.mul(T,O),V=n.mul(g,V),N=n.sub(k,V),N=n.mul(g,N),N=n.add(N,O),O=n.add(k,k),k=n.add(O,k),k=n.add(k,V),k=n.mul(k,N),B=n.add(B,k),V=n.mul(v,D),V=n.add(V,V),k=n.mul(V,N),L=n.sub(L,k),O=n.mul(V,F),O=n.add(O,O),O=n.add(O,O),new A(L,B,O)}add(g){I(g);let{X:E,Y:T,Z:S}=this,{X:v,Y:D,Z:L}=g,B=n.ZERO,O=n.ZERO,k=n.ZERO,F=s.a,V=n.mul(s.b,ao),N=n.mul(E,v),se=n.mul(T,D),ae=n.mul(S,L),ce=n.add(E,T),re=n.add(v,D);ce=n.mul(ce,re),re=n.add(N,se),ce=n.sub(ce,re),re=n.add(E,S);let Ee=n.add(v,L);return re=n.mul(re,Ee),Ee=n.add(N,ae),re=n.sub(re,Ee),Ee=n.add(T,S),B=n.add(D,L),Ee=n.mul(Ee,B),B=n.add(se,ae),Ee=n.sub(Ee,B),k=n.mul(F,re),B=n.mul(V,ae),k=n.add(B,k),B=n.sub(se,k),k=n.add(se,k),O=n.mul(B,k),se=n.add(N,N),se=n.add(se,N),ae=n.mul(F,ae),re=n.mul(V,re),se=n.add(se,ae),ae=n.sub(N,ae),ae=n.mul(F,ae),re=n.add(re,ae),N=n.mul(se,re),O=n.add(O,N),N=n.mul(Ee,re),B=n.mul(ce,B),B=n.sub(B,N),N=n.mul(ce,se),k=n.mul(Ee,k),k=n.add(k,N),new A(B,O,k)}subtract(g){return I(g),this.add(g.negate())}is0(){return this.equals(A.ZERO)}multiply(g){let{endo:E}=e;if(!o.isValidNot0(g))throw new RangeError("invalid scalar: out of range");let T,S,v=D=>H.cached(this,D,L=>Lt(A,L));if(E){let{k1neg:D,k1:L,k2neg:B,k2:O}=R(g),{p:k,f:F}=v(L),{p:V,f:N}=v(O);S=F.add(N),T=_(E.beta,k,V,D,B)}else{let{p:D,f:L}=v(g);T=D,S=L}return Lt(A,[T,S])[0]}multiplyUnsafe(g){let{endo:E}=e,T=this,S=g;if(!o.isValid(S))throw new RangeError("invalid scalar: out of range");if(S===He||T.is0())return A.ZERO;if(S===wt)return T;if(H.hasCache(this))return this.multiply(S);if(E){let{k1neg:v,k1:D,k2neg:L,k2:B}=R(S),{p1:O,p2:k}=nu(A,T,D,B);return _(E.beta,O,k,v,L)}else return H.unsafe(T,S)}toAffine(g){let E=this,T=g,{X:S,Y:v,Z:D}=E;if(n.eql(D,n.ONE))return{x:S,y:v};let L=E.is0();T==null&&(T=L?n.ONE:n.inv(D));let B=n.mul(S,T),O=n.mul(v,T),k=n.mul(D,T);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(k,n.ONE))throw new Error("invZ was invalid");return{x:B,y:O}}isTorsionFree(){let{isTorsionFree:g}=e;return i===wt?!0:g?g(A,this):H.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:g}=e;return i===wt?this:g?g(A,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===wt?this.is0():this.clearCofactor().is0()}toBytes(g=!0){return Oe(g,"isCompressed"),this.assertValidity(),p(A,this,g)}toHex(g=!0){return Jt(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let P=o.BITS,H=new sr(A,e.endo?Math.ceil(P/2):P);return P>=8&&A.BASE.precompute(8),Object.freeze(A.prototype),Object.freeze(A),A}function lf(t){return Uint8Array.of(t?2:3)}function df(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function wm(t,e={}){let{Fn:r}=t,n=e.randomBytes===void 0?qr:e.randomBytes,o=Object.assign(df(t.Fp,r),{seed:Math.max(Ms(r.ORDER),16)});function s(h){try{let p=r.fromBytes(h);return r.isValidNot0(p)}catch{return!1}}function i(h,p){let{publicKey:b,publicKeyUncompressed:m}=o;try{let y=h.length;return p===!0&&y!==b||p===!1&&y!==m?!1:!!t.fromBytes(h)}catch{return!1}}function a(h){return h=h===void 0?n(o.seed):h,qs(q(h,o.seed,"seed"),r.ORDER)}function c(h,p=!0){return t.BASE.multiply(r.fromBytes(h)).toBytes(p)}function u(h){let{secretKey:p,publicKey:b,publicKeyUncompressed:m}=o,y=r._lengths;if(!Tt(h))return;let x=q(h,void 0,"key").length,w=x===b||x===m,C=x===p||!!y?.includes(x);if(!(w&&C))return w}function f(h,p,b=!0){if(u(h)===!0)throw new Error("first arg must be private key");if(u(p)===!1)throw new Error("second arg must be public key");let m=r.fromBytes(h);return t.fromBytes(p).multiply(m).toBytes(b)}let d={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},l=Wn(a,c);return Object.freeze(d),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:l,Point:t,utils:d,lengths:o})}function hf(t,e,r={}){let n=e;kn(n),Pe(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?qr:r.randomBytes,s=r.hmac===void 0?(S,v)=>af(n,S,v):r.hmac,{Fp:i,Fn:a}=t,{ORDER:c,BITS:u}=a,{keygen:f,getPublicKey:d,getSharedSecret:l,utils:h,lengths:p}=wm(t,r),b={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},m=c*uf+wt<i.ORDER;function y(S){let v=c>>wt;return S>v}function x(S,v){if(!a.isValidNot0(v))throw new Error(`invalid signature ${S}: out of range 1..Point.Fn.ORDER`);return v}function w(){if(m)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function C(S,v){Zi(v);let D=p.signature,L=v==="compact"?D:v==="recovered"?D+1:void 0;return q(S,L)}class I{r;s;recovery;constructor(v,D,L){if(this.r=x("r",v),this.s=x("s",D),L!=null){if(w(),![0,1,2,3].includes(L))throw new Error("invalid recovery id");this.recovery=L}Object.freeze(this)}static fromBytes(v,D=b.format){C(v,D);let L;if(D==="der"){let{r:F,s:V}=Ke.toSig(q(v));return new I(F,V)}D==="recovered"&&(L=v[0],D="compact",v=v.subarray(1));let B=p.signature/2,O=v.subarray(0,B),k=v.subarray(B,B*2);return new I(a.fromBytes(O),a.fromBytes(k),L)}static fromHex(v,D){return this.fromBytes(er(v),D)}assertRecovery(){let{recovery:v}=this;if(v==null)throw new Error("invalid recovery id: must be present");return v}addRecoveryBit(v){return new I(this.r,this.s,v)}recoverPublicKey(v){let{r:D,s:L}=this,B=this.assertRecovery(),O=B===2||B===3?D+c:D;if(!i.isValid(O))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let k=i.toBytes(O),F=t.fromBytes(ie(lf((B&1)===0),k)),V=a.inv(O),N=_(q(v,void 0,"msgHash")),se=a.create(-N*V),ae=a.create(L*V),ce=t.BASE.multiplyUnsafe(se).add(F.multiplyUnsafe(ae));if(ce.is0())throw new Error("invalid recovery: point at infinify");return ce.assertValidity(),ce}hasHighS(){return y(this.s)}toBytes(v=b.format){if(Zi(v),v==="der")return er(Ke.hexFromSig(this));let{r:D,s:L}=this,B=a.toBytes(D),O=a.toBytes(L);return v==="recovered"?(w(),ie(Uint8Array.of(this.assertRecovery()),B,O)):ie(B,O)}toHex(v){return Jt(this.toBytes(v))}}Object.freeze(I.prototype),Object.freeze(I);let R=r.bits2int===void 0?function(v){if(v.length>8192)throw new Error("input is too large");let D=Dt(v),L=v.length*8-u;return L>0?D>>BigInt(L):D}:r.bits2int,_=r.bits2int_modN===void 0?function(v){return a.create(R(v))}:r.bits2int_modN,A=Hr(u);function P(S){return tr("num < 2^"+u,S,He,A),a.toBytes(S)}function H(S,v){return q(S,void 0,"message"),v?q(n(S),void 0,"prehashed message"):S}function U(S,v,D){let{lowS:L,prehash:B,extraEntropy:O}=Wi(D,b);S=H(S,B);let k=_(S),F=a.fromBytes(v);if(!a.isValidNot0(F))throw new Error("invalid private key");let V=[P(F),P(k)];if(O!=null&&O!==!1){let ce=O===!0?o(p.secretKey):O;V.push(q(ce,void 0,"extraEntropy"))}let N=ie(...V),se=k;function ae(ce){let re=R(ce);if(!a.isValidNot0(re))return;let Ee=a.inv(re),qt=t.BASE.multiply(re).toAffine(),Ir=a.create(qt.x);if(Ir===He)return;let In=a.create(Ee*a.create(se+Ir*F));if(In===He)return;let Za=(qt.x===Ir?0:2)|Number(qt.y&wt),Ga=In;return L&&y(In)&&(Ga=a.neg(In),Za^=1),new I(Ir,Ga,m?void 0:Za)}return{seed:N,k2sig:ae}}function g(S,v,D={}){let{seed:L,k2sig:B}=U(S,v,D);return Mc(n.outputLen,a.BYTES,s)(L,B).toBytes(D.format)}function E(S,v,D,L={}){let{lowS:B,prehash:O,format:k}=Wi(L,b);if(D=q(D,void 0,"publicKey"),v=H(v,O),!Tt(S)){let F=S instanceof I?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+F)}C(S,k);try{let F=I.fromBytes(S,k),V=t.fromBytes(D);if(B&&F.hasHighS())return!1;let{r:N,s:se}=F,ae=_(v),ce=a.inv(se),re=a.create(ae*ce),Ee=a.create(N*ce),qt=t.BASE.multiplyUnsafe(re).add(V.multiplyUnsafe(Ee));return qt.is0()?!1:a.create(qt.x)===N}catch{return!1}}function T(S,v,D={}){let{prehash:L}=Wi(D,b);return v=H(v,L),I.fromBytes(S,"recovered").recoverPublicKey(v).toBytes()}return Object.freeze({keygen:f,getPublicKey:d,getSharedSecret:l,utils:h,lengths:p,Point:t,sign:g,verify:E,recoverPublicKey:T,Signature:I,hash:n})}var Xi={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Em={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var pf=BigInt(2);function vm(t){let e=Xi.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=t*t*t%e,f=u*u*t%e,d=j(f,r,e)*f%e,l=j(d,r,e)*f%e,h=j(l,pf,e)*u%e,p=j(h,o,e)*h%e,b=j(p,s,e)*p%e,m=j(b,a,e)*b%e,y=j(m,c,e)*m%e,x=j(y,a,e)*b%e,w=j(x,r,e)*f%e,C=j(w,i,e)*p%e,I=j(C,n,e)*u%e,R=j(I,pf,e);if(!Yi.eql(Yi.sqr(R),t))throw new Error("Cannot find square root");return R}var Yi=nr(Xi.p,{sqrt:vm}),Sm=ff(Xi,{Fp:Yi,endo:Em}),pr=hf(Sm,Qt);function mf(t,e,r,n){let o=Or.digest(r instanceof Uint8Array?r:r.subarray());if(Xn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),pr.verify(e,s,t,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Zr(String(s))});try{return n?.signal?.throwIfAborted(),pr.verify(e,o.digest,t,{prehash:!1,format:"der"})}catch(s){throw new Zr(String(s))}}var co=class{type="secp256k1";raw;_key;constructor(e){this._key=bf(e),this.raw=yf(this._key)}toMultihash(){return Le.digest(De(this))}toCID(){return oe.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:W(this.raw,e.raw)}verify(e,r,n){return mf(this._key,r,e,n)}};function Qi(t){return new co(t)}function yf(t){return pr.Point.fromBytes(t).toBytes()}function bf(t){try{return pr.Point.fromBytes(t),t}catch(e){throw new zt(String(e))}}function uo(t,e){let{Type:r,Data:n}=Ve.decode(t),o=n??new Uint8Array;switch(r){case Z.RSA:return Hi(o,e);case Z.Ed25519:return ti(o);case Z.secp256k1:return Qi(o);case Z.ECDSA:return Ss(o);default:throw new vt}}function gf(t){let{Type:e,Data:r}=Ve.decode(t.digest),n=r??new Uint8Array;switch(e){case Z.Ed25519:return ti(n);case Z.secp256k1:return Qi(n);case Z.ECDSA:return Ss(n);default:throw new vt}}function De(t){return Ve.encode({Type:Z[t.type],Data:t.raw})}var xf=Symbol.for("nodejs.util.inspect.custom"),Am=114,an=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[_n]=!0;toString(){return this.string==null&&(this.string=X.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return oe.createV1(Am,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return W(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return W(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[xf](){return`PeerId(${this.toString()})`}},cn=class extends an{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},un=class extends an{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},fn=class extends an{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Cm=2336,ln=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Le.digest($(this.url))}[xf](){return`PeerId(${this.url})`}[_n]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return oe.createV1(Cm,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=z(e)),e.toString()===this.toString())}};var Im=114,wf=2336;function Ef(t){if(t.type==="Ed25519")return new un({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new fn({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new cn({multihash:t.toCID().multihash,publicKey:t});throw new vt}function Ji(t){if(Dm(t))return new cn({multihash:t});if(Tm(t))try{let e=gf(t);if(e.type==="Ed25519")return new un({multihash:t,publicKey:e});if(e.type==="secp256k1")return new fn({multihash:t,publicKey:e})}catch{let r=z(t.digest);return new ln(new URL(r))}throw new Dn("Supplied PeerID Multihash is invalid")}function fo(t){if(t?.multihash==null||t.version==null||t.version===1&&t.code!==Im&&t.code!==wf)throw new Tn("Supplied PeerID CID is invalid");if(t.code===wf){let e=z(t.multihash.digest);return new ln(new URL(e))}return Ji(t.multihash)}function Tm(t){return t.code===Le.code}function Dm(t){return t.code===Or.code}var dn;(function(t){let e;t.codec=()=>(e==null&&(e=we((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.publicKey!=null&&s.publicKey.byteLength>0&&(i.uint32(10),i.bytes(s.publicKey)),s.payloadType!=null&&s.payloadType.byteLength>0&&(i.uint32(18),i.bytes(s.payloadType)),s.payload!=null&&s.payload.byteLength>0&&(i.uint32(26),i.bytes(s.payload)),s.signature!=null&&s.signature.byteLength>0&&(i.uint32(42),i.bytes(s.signature)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={publicKey:Te(0),payloadType:Te(0),payload:Te(0),signature:Te(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.publicKey=s.bytes();break}case 2:{c.payloadType=s.bytes();break}case 3:{c.payload=s.bytes();break}case 5:{c.signature=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.publicKey`,value:s.bytes()};break}case 2:{yield{field:`${a}.payloadType`,value:s.bytes()};break}case 3:{yield{field:`${a}.payload`,value:s.bytes()};break}case 5:{yield{field:`${a}.signature`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ge(s,t.codec())}t.encode=r;function n(s,i){return be(s,t.codec(),i)}t.decode=n;function o(s,i){return xe(s,t.codec(),i)}t.stream=o})(dn||(dn={}));var lo=class extends Error{constructor(e="Invalid signature"){super(e),this.name="InvalidSignatureError"}};var mr=class t{static createFromProtobuf=e=>{let r=dn.decode(e),n=uo(r.publicKey);return new t({publicKey:n,payloadType:r.payloadType,payload:r.payload,signature:r.signature})};static seal=async(e,r,n)=>{if(r==null)throw new Error("Missing private key");let o=e.domain,s=e.codec,i=e.marshal(),a=vf(o,s,i),c=await r.sign(a.subarray(),n);return new t({publicKey:r.publicKey,payloadType:s,payload:i,signature:c})};static openAndCertify=async(e,r,n)=>{let o=t.createFromProtobuf(e);if(!await o.validate(r,n))throw new lo("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(e){let{publicKey:r,payloadType:n,payload:o,signature:s}=e;this.publicKey=r,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=dn.encode({publicKey:De(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(e){return e==null?!1:W(this.marshal(),e.marshal())}async validate(e,r){let n=vf(e,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},vf=(t,e,r)=>{let n=$(t),o=Jn(n.byteLength),s=Jn(e.length),i=Jn(r.length);return new ye(o,n,s,e,i,r)};var _m=Math.pow(2,7),Bm=Math.pow(2,14),Lm=Math.pow(2,21),ea=Math.pow(2,28),ta=Math.pow(2,35),ra=Math.pow(2,42),na=Math.pow(2,49),G=128,me=127;function yr(t){if(t<_m)return 1;if(t<Bm)return 2;if(t<Lm)return 3;if(t<ea)return 4;if(t<ta)return 5;if(t<ra)return 6;if(t<na)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function oa(t,e,r=0){switch(yr(t)){case 8:e[r++]=t&255|G,t/=128;case 7:e[r++]=t&255|G,t/=128;case 6:e[r++]=t&255|G,t/=128;case 5:e[r++]=t&255|G,t/=128;case 4:e[r++]=t&255|G,t>>>=7;case 3:e[r++]=t&255|G,t>>>=7;case 2:e[r++]=t&255|G,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Rm(t,e){let r=t[e],n=0;if(n+=r&me,r<G||(r=t[e+1],n+=(r&me)<<7,r<G)||(r=t[e+2],n+=(r&me)<<14,r<G)||(r=t[e+3],n+=(r&me)<<21,r<G)||(r=t[e+4],n+=(r&me)*ea,r<G)||(r=t[e+5],n+=(r&me)*ta,r<G)||(r=t[e+6],n+=(r&me)*ra,r<G)||(r=t[e+7],n+=(r&me)*na,r<G))return n;throw new RangeError("Could not decode varint")}function Om(t,e){let r=t.get(e),n=0;if(n+=r&me,r<G||(r=t.get(e+1),n+=(r&me)<<7,r<G)||(r=t.get(e+2),n+=(r&me)<<14,r<G)||(r=t.get(e+3),n+=(r&me)<<21,r<G)||(r=t.get(e+4),n+=(r&me)*ea,r<G)||(r=t.get(e+5),n+=(r&me)*ta,r<G)||(r=t.get(e+6),n+=(r&me)*ra,r<G)||(r=t.get(e+7),n+=(r&me)*na,r<G))return n;throw new RangeError("Could not decode varint")}function sa(t,e=0){return t instanceof Uint8Array?Rm(t,e):Om(t,e)}var he=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},tt=class extends Error{static name="ValidationError";name="ValidationError"},ho=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},po=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var mo=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let r=this.index,n=e();return n===void 0&&(this.index=r),n}parseWith(e){let r=e();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let r=this.readChar();if(r===e)return r})}readSeparator(e,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let d=this.readChar();if(d===void 0)return;let l=Number.parseInt(d,e);if(!Number.isNaN(l))return l});if(f===void 0)break;if(s*=e,s+=f,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let r=0;r<e.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[r]=n}return e})}readIPv6Addr(){let e=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=e(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Pm=45,Um=15,yo=new mo;function Sf(t){if(!(t.length>Um))return yo.new(t).parseWith(()=>yo.readIPv4Addr())}function Af(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>Pm))return yo.new(t).parseWith(()=>yo.readIPv6Addr())}function bo(t){return!!Sf(t)}function Cf(t){return!!Af(t)}function aa(t){return e=>z(e,t)}function ca(t){return e=>$(e,t)}function br(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Kt(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function If(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let r=$(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Kt(n);return Rt([r,o],r.length+o.length)}function Tf(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=Ne.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Kt(n);return Rt([r,o],r.length+o.length)}function ua(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=z(e,"base32"),o=br(r);return`${n}:${o}`}var fa=function(t){t=t.toString().trim();let e=new Uint8Array(4);return t.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new he("Invalid byte value in IP address");e[n]=o}),e},Df=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let s=bo(r[n]),i;s&&(i=fa(r[n]),r[n]=z(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,z(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(e+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new he("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},_f=function(t){if(t.byteLength!==4)throw new he("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},Bf=function(t){if(t.byteLength!==16)throw new he("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let o=t[n],s=t[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let r=e.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new he(`Invalid IPv6 address "${r}"`)}};function Lf(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new he(`Invalid IPv6 address "${t}"`)}}var ia=Object.values(kr).map(t=>t.decoder),Km=(function(){let t=ia[0].or(ia[1]);return ia.slice(2).forEach(e=>t=t.or(e)),t})();function Rf(t){return Km.decode(t)}function Of(t){return e=>t.encoder.encode(e)}function Nm(t){if(parseInt(t).toString()!==t)throw new tt("Value must be an integer")}function Fm(t){if(t<0)throw new tt("Value must be a positive integer, or zero")}function Mm(t){return e=>{if(e>t)throw new tt(`Value must be smaller than or equal to ${t}`)}}function qm(...t){return e=>{for(let r of t)r(e)}}var hn=qm(Nm,Fm,Mm(65535));var fe=-1,la=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let r;if(typeof e=="string"?r=this.protocolsByName.get(e):r=this.protocolsByCode.get(e),r==null)throw new po(`Protocol ${e} was unknown`);return r}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(r=>{this.protocolsByName.set(r,e)})}removeProtocol(e){let r=this.protocolsByCode.get(e);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},rt=new la,T0=[{code:4,name:"ip4",size:32,valueToBytes:fa,bytesToValue:_f,validate:t=>{if(!bo(t))throw new tt(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Kt,bytesToValue:br,validate:hn},{code:273,name:"udp",size:16,valueToBytes:Kt,bytesToValue:br,validate:hn},{code:33,name:"dccp",size:16,valueToBytes:Kt,bytesToValue:br,validate:hn},{code:41,name:"ip6",size:128,valueToBytes:Df,bytesToValue:Bf,stringToValue:Lf,validate:t=>{if(!Cf(t))throw new tt(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:fe},{code:43,name:"ipcidr",size:8,bytesToValue:aa("base10"),valueToBytes:ca("base10")},{code:53,name:"dns",size:fe},{code:54,name:"dns4",size:fe},{code:55,name:"dns6",size:fe},{code:56,name:"dnsaddr",size:fe},{code:132,name:"sctp",size:16,valueToBytes:Kt,bytesToValue:br,validate:hn},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:fe,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:fe,bytesToValue:aa("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?ca("base58btc")(t):oe.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:ua,valueToBytes:If},{code:445,name:"onion3",size:296,bytesToValue:ua,valueToBytes:Tf},{code:446,name:"garlic64",size:fe},{code:447,name:"garlic32",size:fe},{code:448,name:"tls"},{code:449,name:"sni",size:fe},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:fe,bytesToValue:Of(fs),valueToBytes:Rf},{code:480,name:"http"},{code:481,name:"http-path",size:fe,stringToValue:t=>`/${decodeURIComponent(t)}`,valueToString:t=>encodeURIComponent(t.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:fe}];T0.forEach(t=>{rt.addProtocol(t)});function kf(t){let e=[],r=0;for(;r<t.length;){let n=sa(t,r),o=rt.getProtocol(n),s=yr(n),i=D0(o,t,r+s),a=0;i>0&&o.size===fe&&(a=yr(i));let c=s+a+i,u={code:n,name:o.name,bytes:Se(t.subarray(r,r+c))};if(i>0){let f=r+s+a,d=t.subarray(f,f+i);u.value=o.bytesToValue?.(d)??z(d)}e.push(u),r+=c}return e}function Pf(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=rt.getProtocol(n.code),s=yr(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??$(n.value),a=i.byteLength,o.size===fe&&(c=yr(a)));let u=new Uint8Array(s+c+a),f=0;oa(n.code,u,f),f+=s,i!=null&&(o.size===fe&&(oa(a,u,f),f+=c),u.set(i,f)),n.bytes=u}r.push(n.bytes),e+=n.bytes.byteLength}return Rt(r,e)}function Uf(t){if(t.charAt(0)!=="/")throw new he('String multiaddr must start with "/"');let e=[],r="protocol",n="",o="";for(let s=1;s<t.length;s++){let i=t.charAt(s);i!=="/"&&(r==="protocol"?o+=t.charAt(s):n+=t.charAt(s));let a=s===t.length-1;if(i==="/"||a){let c=rt.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new he(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new he(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}e.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new he("Incomplete multiaddr");return e}function Kf(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=rt.getProtocol(e.code);if(r==null)throw new he(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function D0(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:sa(e,r)}var _0=Symbol.for("nodejs.util.inspect.custom"),ha=Symbol.for("@multiformats/multiaddr");function B0(t){if(t==null&&(t="/"),xo(t))return t.getComponents();if(t instanceof Uint8Array)return kf(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),Uf(t);if(Array.isArray(t))return t;throw new he("Must be a string, Uint8Array, Component[], or another Multiaddr")}var go=class t{[ha]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=B0(e),r.validate!==!1&&L0(this)}get bytes(){return this.#r==null&&(this.#r=Pf(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=Kf(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let r=new t(e);return new t([...this.#e,...r.getComponents()],{validate:!1})}decapsulate(e){let r=e.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new ho(`Address ${this.toString()} does not contain subaddress: ${r}`);return new t(n.slice(0,o),{validate:!1})}decapsulateCode(e){let r;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){r=n;break}return new t(this.#e.slice(0,r),{validate:!1})}equals(e){return W(this.bytes,e.bytes)}[_0](){return`Multiaddr(${this.toString()})`}};function L0(t){t.getComponents().forEach(e=>{let r=rt.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function xo(t){return!!t?.[ha]}function Nt(t){return new go(t)}var Nf="libp2p-peer-record",Ff=Uint8Array.from([3,1]);var pn;(function(t){let e;(function(i){let a;i.codec=()=>(a==null&&(a=we((d,l,h={})=>{h.lengthDelimited!==!1&&l.fork(),d.multiaddr!=null&&d.multiaddr.byteLength>0&&(l.uint32(10),l.bytes(d.multiaddr)),h.lengthDelimited!==!1&&l.ldelim()},(d,l,h={})=>{let p={multiaddr:Te(0)},b=l==null?d.len:d.pos+l;for(;d.pos<b;){let m=d.uint32();m>>>3===1?p.multiaddr=d.bytes():d.skipType(m&7)}return p},function*(d,l,h,p={}){let b=l==null?d.len:d.pos+l;for(;d.pos<b;){let m=d.uint32();m>>>3===1?yield{field:`${h}.multiaddr`,value:d.bytes()}:d.skipType(m&7)}})),a);function c(d){return ge(d,i.codec())}i.encode=c;function u(d,l){return be(d,i.codec(),l)}i.decode=u;function f(d,l){return xe(d,i.codec(),l)}i.stream=f})(e=t.AddressInfo||(t.AddressInfo={}));let r;t.codec=()=>(r==null&&(r=we((i,a,c={})=>{if(c.lengthDelimited!==!1&&a.fork(),i.peerId!=null&&i.peerId.byteLength>0&&(a.uint32(10),a.bytes(i.peerId)),i.seq!=null&&i.seq!==0n&&(a.uint32(16),a.uint64(i.seq)),i.addresses!=null&&i.addresses.length>0)for(let u of i.addresses)a.uint32(26),t.AddressInfo.codec().encode(u,a);c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let u={peerId:Te(0),seq:0n,addresses:[]},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{u.peerId=i.bytes();break}case 2:{u.seq=i.uint64();break}case 3:{if(c.limits?.addresses!=null&&u.addresses.length===c.limits.addresses)throw new Be('Decode error - repeated field "addresses" had too many elements');u.addresses.push(t.AddressInfo.codec().decode(i,i.uint32(),{limits:c.limits?.addresses$}));break}default:{i.skipType(d&7);break}}}return u},function*(i,a,c,u={}){let f={addresses:0},d=a==null?i.len:i.pos+a;for(;i.pos<d;){let l=i.uint32();switch(l>>>3){case 1:{yield{field:`${c}.peerId`,value:i.bytes()};break}case 2:{yield{field:`${c}.seq`,value:i.uint64()};break}case 3:{if(u.limits?.addresses!=null&&f.addresses===u.limits.addresses)throw new Be('Streaming decode error - repeated field "addresses" had too many elements');for(let h of t.AddressInfo.codec().stream(i,i.uint32(),`${c}.addresses[]`,{limits:u.limits?.addresses$}))yield{...h,index:f.addresses};f.addresses++;break}default:{i.skipType(l&7);break}}}})),r);function n(i){return ge(i,t.codec())}t.encode=n;function o(i,a){return be(i,t.codec(),a)}t.decode=o;function s(i,a){return xe(i,t.codec(),a)}t.stream=s})(pn||(pn={}));function Mf(t,e){let r=(n,o)=>n.toString().localeCompare(o.toString());return t.length!==e.length?!1:(e.sort(r),t.sort(r).every((n,o)=>e[o].equals(n)))}var Ft=class t{static createFromProtobuf=e=>{let r=pn.decode(e),n=Ji(Gt(r.peerId)),o=(r.addresses??[]).map(i=>Nt(i.multiaddr)),s=r.seq;return new t({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Nf;static CODEC=Ff;peerId;multiaddrs;seqNumber;domain=t.DOMAIN;codec=t.CODEC;marshaled;constructor(e){let{peerId:r,multiaddrs:n,seqNumber:o}=e;this.peerId=r,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=pn.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(e=>({multiaddr:e.bytes}))})),this.marshaled}equals(e){return!(!(e instanceof t)||!this.peerId.equals(e.peerId)||this.seqNumber!==e.seqNumber||!Mf(this.multiaddrs,e.multiaddrs))}};function R0(t){return t[Symbol.asyncIterator]!=null}function O0(t){if(R0(t))return(async()=>{let r=[];for await(let n of t)r.push(n);return r})();let e=[];for(let r of t)e.push(r);return e}var qf=O0;function wo(t,e){let r={[Symbol.iterator]:()=>r,next:()=>{let n=t.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:e(o)}}};return r}var mn=class{map;constructor(e){if(this.map=new Map,e!=null)for(let[r,n]of e.entries())this.map.set(r.toString(),{key:r,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(e){return this.map.delete(e.toString())}entries(){return wo(this.map.entries(),e=>[e[1].key,e[1].value])}forEach(e){this.map.forEach((r,n)=>{e(r.value,r.key,this)})}get(e){return this.map.get(e.toString())?.value}has(e){return this.map.has(e.toString())}set(e,r){this.map.set(e.toString(),{key:e,value:r})}keys(){return wo(this.map.values(),e=>e.key)}values(){return wo(this.map.values(),e=>e.value)}get size(){return this.map.size}};function Eo(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var vo=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},gr=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new vo(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let r=this.head;this.head=r.next=new vo(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var pa=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function zf(t={}){return k0(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},t)}function k0(t,e){e=e??{};let r=e.onEnd,n=new gr,o,s,i,a=Eo(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((m,y)=>{s=x=>{s=null,n.push(x);try{m(t(n))}catch(w){y(w)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Eo()})}},u=m=>s!=null?s(m):(n.push(m),o),f=m=>(n=new gr,s!=null?s({error:m}):(n.push({error:m}),o)),d=m=>{if(i)return o;if(e?.objectMode!==!0&&m?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:m})},l=m=>i?o:(i=!0,m!=null?f(m):u({done:!0})),h=()=>(n=new gr,l(),{done:!0}),p=m=>(l(m),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:h,throw:p,push:d,end:l,get readableLength(){return n.size},onEmpty:async m=>{let y=m?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let x,w;y!=null&&(x=new Promise((C,I)=>{w=()=>{I(new pa)},y.addEventListener("abort",w)}));try{await Promise.race([a.promise,x])}finally{w!=null&&y!=null&&y?.removeEventListener("abort",w)}}},r==null)return o;let b=o;return o={[Symbol.asyncIterator](){return this},next(){return b.next()},throw(m){return b.throw(m),r!=null&&(r(m),r=void 0),{done:!0}},return(){return b.return(),r!=null&&(r(),r=void 0),{done:!0}},push:d,end(m){return b.end(m),r!=null&&(r(m),r=void 0),o},get readableLength(){return b.readableLength},onEmpty:m=>b.onEmpty(m)},o}function P0(t){return t.reason}async function Vf(t,e,r){if(e==null)return t;let n=r?.translateError??P0;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var ma=class extends mn{metric;constructor(e){super();let{name:r,metrics:n}=e;this.metric=n.registerMetric(r),this.updateComponentMetric()}set(e,r){return super.set(e,r),this.updateComponentMetric(),this}delete(e){let r=super.delete(e);return this.updateComponentMetric(),r}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function ya(t){let{name:e,metrics:r}=t,n;return r!=null?n=new ma({name:e,metrics:r}):n=new mn,n}var Ie=class extends Error{static name="AbortError";name="AbortError";constructor(e="The operation was aborted",...r){super(e,...r)}};async function So(t,e,r,n){let o=new Ie(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(){ga(r,"abort",d),ga(t,e,u),ga(t,s,f)}let u=l=>{try{if(n?.filter?.(l)===!1)return}catch(h){c(),a(h);return}c(),i(l)},f=l=>{if(c(),l instanceof Error){a(l);return}a(l.detail??n?.error??new Error(`The "${n?.errorEvent}" event was emitted but the event had no '.detail' field. Pass an 'error' option to race-event to change this message.`))},d=()=>{c(),a(o)};ba(r,"abort",d),ba(t,e,u),ba(t,s,f)})}function ba(t,e,r){t!=null&&(Hf(t)?t.addEventListener(e,r):t.addListener(e,r))}function ga(t,e,r){t!=null&&(Hf(t)?t.removeEventListener(e,r):t.removeListener(e,r))}function Hf(t){return typeof t.addEventListener=="function"&&typeof t.removeEventListener=="function"}var Ao=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};var Co=class{deferred;signal;constructor(e){this.signal=e,this.deferred=Promise.withResolvers(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Ie)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function U0(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Io=class{id;fn;options;recipients;status;timeline;controller;constructor(e,r){this.id=U0(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Ie),this.cleanup())}async join(e={}){let r=new Co(e.signal);return this.recipients.push(r),e.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await Vf(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(r=>{r.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};function xa(t,e){let r,n=function(){let o=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var yn=class extends Ht{concurrency;maxSize;queue;pending;sort;autoStart;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.maxSize=e.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.autoStart=e.autoStart??!0,this.sort=e.sort,this.queue=[],this.emitEmpty=xa(this.emitEmpty.bind(this),1),this.emitIdle=xa(this.emitIdle.bind(this),1)}[Symbol.asyncIterator](){return this.toGenerator()}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}tryToStartAnother(){if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let e;for(let r of this.queue)if(r.status==="queued"){e=r;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===e){this.queue.splice(r,1);break}this.pending--,this.safeDispatchEvent("next"),this.autoStart&&this.tryToStartAnother()}),!0)}return!1}enqueue(e){this.queue.push(e),this.sort!=null&&this.queue.sort(this.sort)}start(){this.autoStart===!1&&(this.autoStart=!0,this.tryToStartAnother())}pause(){this.autoStart=!1}async add(e,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new Ao;let n=new Io(e,r);return this.enqueue(n),this.safeDispatchEvent("add"),this.autoStart&&this.tryToStartAnother(),n.join(r).then(o=>(this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new Ie)}),this.clear()}async onEmpty(e){this.size!==0&&await So(this,"empty",e?.signal)}async onSizeLessThan(e,r){this.size<e||await So(this,"next",r?.signal,{filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await So(this,"idle",e?.signal)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let r=zf({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 Ie("Queue aborted"))};this.addEventListener("success",o),this.addEventListener("failure",s),this.addEventListener("idle",i),e?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("success",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),e?.signal?.removeEventListener("abort",a),n()}}};var To="lock:worker:request-read",Do="lock:worker:abort-read-request",_o="lock:worker:release-read",Bo="lock:master:grant-read",Lo="lock:master:error-read",Ro="lock:worker:request-write",Oo="lock:worker:abort-write-request",ko="lock:worker:release-write",Po="lock:master:grant-write",Uo="lock:master:error-write",Ko="lock:worker:finalize",No="mortice",$f={singleProcess:!1};var wa=(t,e,r,n,o,s,i,a,c)=>u=>{if(u.data==null)return;let f={type:u.data.type,name:u.data.name,identifier:u.data.identifier};f.type===o&&t.safeDispatchEvent(r,{detail:{name:f.name,identifier:f.identifier,handler:async()=>{e.postMessage({type:c,name:f.name,identifier:f.identifier}),await new Promise(d=>{let l=h=>{if(h?.data==null)return;let p={type:h.data.type,name:h.data.name,identifier:h.data.identifier};p.type===a&&p.identifier===f.identifier&&(e.removeEventListener("message",l),d())};e.addEventListener("message",l)})},onError:d=>{e.postMessage({type:i,name:f.name,identifier:f.identifier,error:{message:d.message,name:d.name,stack:d.stack}})}}}),f.type===s&&t.safeDispatchEvent(n,{detail:{name:f.name,identifier:f.identifier}}),f.type===Ko&&t.safeDispatchEvent("finalizeRequest",{detail:{name:f.name}})};var jf=(t=10)=>Math.random().toString().substring(2,t+2);var Fo=class{name;channel;constructor(e){this.name=e,this.channel=new BroadcastChannel(No)}readLock(e){return this.sendRequest(To,Do,Bo,Lo,_o,e)}writeLock(e){return this.sendRequest(Ro,Oo,Po,Uo,ko,e)}finalize(){this.channel.postMessage({type:Ko,name:this.name}),this.channel.close()}async sendRequest(e,r,n,o,s,i){i?.signal?.throwIfAborted();let a=jf();return this.channel.postMessage({type:e,identifier:a,name:this.name}),new Promise((c,u)=>{let f=()=>{this.channel.postMessage({type:r,identifier:a,name:this.name})};i?.signal?.addEventListener("abort",f,{once:!0});let d=l=>{if(l.data?.identifier===a&&(l.data?.type===n&&(this.channel.removeEventListener("message",d),i?.signal?.removeEventListener("abort",f),c(()=>{this.channel.postMessage({type:s,identifier:a,name:this.name})})),l.data.type===o)){this.channel.removeEventListener("message",d),i?.signal?.removeEventListener("abort",f);let h=new Error;l.data.error!=null&&(h.message=l.data.error.message,h.name=l.data.error.name,h.stack=l.data.error.stack),u(h)}};this.channel.addEventListener("message",d)})}};var Wf=t=>{if(t=Object.assign({},$f,t),!!globalThis.document||t.singleProcess){let r=new BroadcastChannel(No),n=new Ht;return r.addEventListener("message",wa(n,r,"requestReadLock","abortReadLockRequest",To,Do,Lo,_o,Bo)),r.addEventListener("message",wa(n,r,"requestWriteLock","abortWriteLockRequest",Ro,Oo,Uo,ko,Po)),n}return new Fo(t.name)};var Mt=new Map,bn;function Zf(t){return typeof t?.readLock=="function"&&typeof t?.writeLock=="function"}function K0(t){if(bn==null&&(bn=Wf(t),!Zf(bn))){let e=bn;e.addEventListener("requestReadLock",r=>{let n=r.detail.name,o=r.detail.identifier,s=Mt.get(n);if(s==null)return;let i=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==o||i.abort()};e.addEventListener("abortReadLockRequest",a),s.readLock({signal:i.signal}).then(async c=>{await r.detail.handler().finally(()=>{c()})}).catch(c=>{r.detail.onError(c)}).finally(()=>{e.removeEventListener("abortReadLockRequest",a)})}),e.addEventListener("requestWriteLock",r=>{let n=r.detail.name,o=r.detail.identifier,s=Mt.get(n);if(s==null)return;let i=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==o||i.abort()};e.addEventListener("abortWriteLockRequest",a),s.writeLock({signal:i.signal}).then(async c=>{await r.detail.handler().finally(()=>{c()})}).catch(c=>{r.detail.onError(c)}).finally(()=>{e.removeEventListener("abortWriteLockRequest",a)})}),e.addEventListener("finalizeRequest",r=>{let n=r.detail.name,o=Mt.get(n);o?.finalize()})}return bn}async function Ea(t,e){let r,n,o=new Promise((i,a)=>{r=i,n=a}),s=()=>{n(new Ie)};return e?.signal?.addEventListener("abort",s,{once:!0}),t.add(async()=>{await new Promise(i=>{r(()=>{e?.signal?.removeEventListener("abort",s),i()})})},{signal:e?.signal}).catch(i=>{n(i)}),o}var Gf=(t,e)=>{let r=Mt.get(t);if(r!=null)return r;let n=K0(e);if(Zf(n))return r=n,Mt.set(t,r),r;let o=new yn({concurrency:1}),s;return r={async readLock(i){if(s!=null)return Ea(s,i);s=new yn({concurrency:e.concurrency,autoStart:!1});let a=s,c=Ea(s,i);return o.add(async()=>{a.start(),await a.onIdle().then(()=>{s===a&&(s=null)})}),c},async writeLock(i){return s=null,Ea(o,i)},finalize:()=>{Mt.delete(t)},queue:o},Mt.set(t,r),e.autoFinalize===!0&&o.addEventListener("idle",()=>{r.finalize()},{once:!0}),r};var N0={name:"lock",concurrency:1/0,singleProcess:!1,autoFinalize:!1};function va(t){let e=Object.assign({},N0,t);return Gf(e.name,e)}var nt;(function(t){let e;(function(a){let c;a.codec=()=>(c==null&&(c=we((l,h,p={})=>{p.lengthDelimited!==!1&&h.fork(),l.key!=null&&l.key!==""&&(h.uint32(10),h.string(l.key)),l.value!=null&&l.value.byteLength>0&&(h.uint32(18),h.bytes(l.value)),p.lengthDelimited!==!1&&h.ldelim()},(l,h,p={})=>{let b={key:"",value:Te(0)},m=h==null?l.len:l.pos+h;for(;l.pos<m;){let y=l.uint32();switch(y>>>3){case 1:{b.key=l.string();break}case 2:{b.value=l.bytes();break}default:{l.skipType(y&7);break}}}return b},function*(l,h,p,b={}){let m=h==null?l.len:l.pos+h;for(;l.pos<m;){let y=l.uint32();switch(y>>>3){case 1:{yield{field:`${p}.key`,value:l.string()};break}case 2:{yield{field:`${p}.value`,value:l.bytes()};break}default:{l.skipType(y&7);break}}}})),c);function u(l){return ge(l,a.codec())}a.encode=u;function f(l,h){return be(l,a.codec(),h)}a.decode=f;function d(l,h){return xe(l,a.codec(),h)}a.stream=d})(e=t.Peer$metadataEntry||(t.Peer$metadataEntry={}));let r;(function(a){let c;a.codec=()=>(c==null&&(c=we((l,h,p={})=>{p.lengthDelimited!==!1&&h.fork(),l.key!=null&&l.key!==""&&(h.uint32(10),h.string(l.key)),l.value!=null&&(h.uint32(18),xn.codec().encode(l.value,h)),p.lengthDelimited!==!1&&h.ldelim()},(l,h,p={})=>{let b={key:""},m=h==null?l.len:l.pos+h;for(;l.pos<m;){let y=l.uint32();switch(y>>>3){case 1:{b.key=l.string();break}case 2:{b.value=xn.codec().decode(l,l.uint32(),{limits:p.limits?.value});break}default:{l.skipType(y&7);break}}}return b},function*(l,h,p,b={}){let m=h==null?l.len:l.pos+h;for(;l.pos<m;){let y=l.uint32();switch(y>>>3){case 1:{yield{field:`${p}.key`,value:l.string()};break}case 2:{yield*xn.codec().stream(l,l.uint32(),`${p}.value`,{limits:b.limits?.value});break}default:{l.skipType(y&7);break}}}})),c);function u(l){return ge(l,a.codec())}a.encode=u;function f(l,h){return be(l,a.codec(),h)}a.decode=f;function d(l,h){return xe(l,a.codec(),h)}a.stream=d})(r=t.Peer$tagsEntry||(t.Peer$tagsEntry={}));let n;t.codec=()=>(n==null&&(n=we((a,c,u={})=>{if(u.lengthDelimited!==!1&&c.fork(),a.addresses!=null&&a.addresses.length>0)for(let f of a.addresses)c.uint32(10),gn.codec().encode(f,c);if(a.protocols!=null&&a.protocols.length>0)for(let f of a.protocols)c.uint32(18),c.string(f);if(a.publicKey!=null&&(c.uint32(34),c.bytes(a.publicKey)),a.peerRecordEnvelope!=null&&(c.uint32(42),c.bytes(a.peerRecordEnvelope)),a.metadata!=null&&a.metadata.size>0)for(let[f,d]of a.metadata.entries())c.uint32(50),t.Peer$metadataEntry.codec().encode({key:f,value:d},c);if(a.tags!=null&&a.tags.size>0)for(let[f,d]of a.tags.entries())c.uint32(58),t.Peer$tagsEntry.codec().encode({key:f,value:d},c);a.updated!=null&&(c.uint32(64),c.uint64Number(a.updated)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={addresses:[],protocols:[],metadata:new Map,tags:new Map},d=c==null?a.len:a.pos+c;for(;a.pos<d;){let l=a.uint32();switch(l>>>3){case 1:{if(u.limits?.addresses!=null&&f.addresses.length===u.limits.addresses)throw new Be('Decode error - repeated field "addresses" had too many elements');f.addresses.push(gn.codec().decode(a,a.uint32(),{limits:u.limits?.addresses$}));break}case 2:{if(u.limits?.protocols!=null&&f.protocols.length===u.limits.protocols)throw new Be('Decode error - repeated field "protocols" had too many elements');f.protocols.push(a.string());break}case 4:{f.publicKey=a.bytes();break}case 5:{f.peerRecordEnvelope=a.bytes();break}case 6:{if(u.limits?.metadata!=null&&f.metadata.size===u.limits.metadata)throw new nn('Decode error - map field "metadata" had too many elements');let h=t.Peer$metadataEntry.codec().decode(a,a.uint32(),{limits:{value:u.limits?.metadata$value}});f.metadata.set(h.key,h.value);break}case 7:{if(u.limits?.tags!=null&&f.tags.size===u.limits.tags)throw new nn('Decode error - map field "tags" had too many elements');let h=t.Peer$tagsEntry.codec().decode(a,a.uint32(),{limits:{value:u.limits?.tags$value}});f.tags.set(h.key,h.value);break}case 8:{f.updated=a.uint64Number();break}default:{a.skipType(l&7);break}}}return f},function*(a,c,u,f={}){let d={addresses:0,protocols:0,metadata:0,tags:0},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let h=a.uint32();switch(h>>>3){case 1:{if(f.limits?.addresses!=null&&d.addresses===f.limits.addresses)throw new Be('Streaming decode error - repeated field "addresses" had too many elements');for(let p of gn.codec().stream(a,a.uint32(),`${u}.addresses[]`,{limits:f.limits?.addresses$}))yield{...p,index:d.addresses};d.addresses++;break}case 2:{if(f.limits?.protocols!=null&&d.protocols===f.limits.protocols)throw new Be('Streaming decode error - repeated field "protocols" had too many elements');yield{field:`${u}.protocols[]`,index:d.protocols,value:a.string()},d.protocols++;break}case 4:{yield{field:`${u}.publicKey`,value:a.bytes()};break}case 5:{yield{field:`${u}.peerRecordEnvelope`,value:a.bytes()};break}case 6:{if(f.limits?.metadata!=null&&d.metadata===f.limits.metadata)throw new Be('Decode error - map field "metadata" had too many elements');yield*t.Peer$metadataEntry.codec().stream(a,a.uint32(),`${u}.metadata{}`,{limits:{value:f.limits?.metadata$value}}),d.metadata++;break}case 7:{if(f.limits?.tags!=null&&d.tags===f.limits.tags)throw new Be('Decode error - map field "tags" had too many elements');yield*t.Peer$tagsEntry.codec().stream(a,a.uint32(),`${u}.tags{}`,{limits:{value:f.limits?.tags$value}}),d.tags++;break}case 8:{yield{field:`${u}.updated`,value:a.uint64Number()};break}default:{a.skipType(h&7);break}}}})),n);function o(a){return ge(a,t.codec())}t.encode=o;function s(a,c){return be(a,t.codec(),c)}t.decode=s;function i(a,c){return xe(a,t.codec(),c)}t.stream=i})(nt||(nt={}));var gn;(function(t){let e;t.codec=()=>(e==null&&(e=we((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.multiaddr!=null&&s.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(s.multiaddr)),s.isCertified!=null&&(i.uint32(16),i.bool(s.isCertified)),s.observed!=null&&(i.uint32(24),i.uint64Number(s.observed)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={multiaddr:Te(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.multiaddr=s.bytes();break}case 2:{c.isCertified=s.bool();break}case 3:{c.observed=s.uint64Number();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.multiaddr`,value:s.bytes()};break}case 2:{yield{field:`${a}.isCertified`,value:s.bool()};break}case 3:{yield{field:`${a}.observed`,value:s.uint64Number()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ge(s,t.codec())}t.encode=r;function n(s,i){return be(s,t.codec(),i)}t.decode=n;function o(s,i){return xe(s,t.codec(),i)}t.stream=o})(gn||(gn={}));var xn;(function(t){let e;t.codec=()=>(e==null&&(e=we((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.value!=null&&s.value!==0&&(i.uint32(8),i.uint32(s.value)),s.expiry!=null&&(i.uint32(16),i.uint64(s.expiry)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={value:0},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.value=s.uint32();break}case 2:{c.expiry=s.uint64();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.value`,value:s.uint32()};break}case 2:{yield{field:`${a}.expiry`,value:s.uint64()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ge(s,t.codec())}t.encode=r;function n(s,i){return be(s,t.codec(),i)}t.decode=n;function o(s,i){return xe(s,t.codec(),i)}t.stream=o})(xn||(xn={}));function F0(t,e){if(t.publicKey!=null||e.publicKey==null)return t;let r;t.type==="RSA"&&(r=t.toMultihash());let n=uo(e.publicKey,r);return Ef(n)}function Yf(t,e,r){let n=nt.decode(e);return xr(t,n,r)}function xr(t,e,r){let n=new Map,o=BigInt(Date.now());for(let[s,i]of e.tags.entries())i.expiry!=null&&i.expiry<o||n.set(s,i);return{...e,id:F0(t,e),addresses:e.addresses.filter(({observed:s})=>s!=null&&s>Date.now()-r).map(({multiaddr:s,isCertified:i})=>({multiaddr:Nt(s),isCertified:i??!1})),metadata:e.metadata,peerRecordEnvelope:e.peerRecordEnvelope??void 0,tags:n}}function Xf(t,e){return M0(t.addresses,e.addresses)&&q0(t.protocols,e.protocols)&&z0(t.publicKey,e.publicKey)&&V0(t.peerRecordEnvelope,e.peerRecordEnvelope)&&H0(t.metadata,e.metadata)&&$0(t.tags,e.tags)}function M0(t,e){return Jf(t,e,(r,n)=>!(r.isCertified!==n.isCertified||!W(r.multiaddr,n.multiaddr)))}function q0(t,e){return Jf(t,e,(r,n)=>r===n)}function z0(t,e){return Qf(t,e)}function V0(t,e){return Qf(t,e)}function H0(t,e){return el(t,e,(r,n)=>W(r,n))}function $0(t,e){return el(t,e,(r,n)=>r.value===n.value&&r.expiry===n.expiry)}function Qf(t,e){return t==null&&e==null?!0:t!=null&&e!=null?W(t,e):!1}function Jf(t,e,r){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(!r(t[n],e[n]))return!1;return!0}function el(t,e,r){if(t.size!==e.size)return!1;for(let[n,o]of t.entries()){let s=e.get(n);if(s==null||!r(o,s))return!1}return!0}var Ta={};K(Ta,{base10:()=>Q0});var V6=new Uint8Array(0);function tl(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function ot(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function rl(t){return new TextEncoder().encode(t)}function nl(t){return new TextDecoder().decode(t)}function j0(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var s=t.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function d(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var b=0,m=0,y=0,x=p.length;y!==x&&p[y]===0;)y++,b++;for(var w=(x-y)*f+1>>>0,C=new Uint8Array(w);y!==x;){for(var I=p[y],R=0,_=w-1;(I!==0||R<m)&&_!==-1;_--,R++)I+=256*C[_]>>>0,C[_]=I%a>>>0,I=I/a>>>0;if(I!==0)throw new Error("Non-zero carry");m=R,y++}for(var A=w-m;A!==w&&C[A]===0;)A++;for(var P=c.repeat(b);A<w;++A)P+=t.charAt(C[A]);return P}function l(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var b=0;if(p[b]!==" "){for(var m=0,y=0;p[b]===c;)m++,b++;for(var x=(p.length-b)*u+1>>>0,w=new Uint8Array(x);p[b];){var C=r[p.charCodeAt(b)];if(C===255)return;for(var I=0,R=x-1;(C!==0||I<y)&&R!==-1;R--,I++)C+=a*w[R]>>>0,w[R]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");y=I,b++}if(p[b]!==" "){for(var _=x-y;_!==x&&w[_]===0;)_++;for(var A=new Uint8Array(m+(x-_)),P=m;_!==x;)A[P++]=w[_++];return A}}}function h(p){var b=l(p);if(b)return b;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:l,decode:h}}var W0=j0,Z0=W0,sl=Z0;var Sa=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Aa=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return il(this,e)}},Ca=class{decoders;constructor(e){this.decoders=e}or(e){return il(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function il(t,e){return new Ca({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Ia=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Sa(e,r,n),this.decoder=new Aa(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function wr({name:t,prefix:e,encode:r,decode:n}){return new Ia(t,e,r,n)}function Et({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=sl(r,t);return wr({prefix:e,name:t,encode:n,decode:s=>ot(o(s))})}function G0(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Y0(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function X0(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function te({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=X0(n);return wr({prefix:e,name:t,encode(s){return Y0(s,n,r)},decode(s){return G0(s,o,r,t)}})}var Q0=Et({prefix:"9",name:"base10",alphabet:"0123456789"});var Da={};K(Da,{base16:()=>J0,base16upper:()=>ey});var J0=te({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),ey=te({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var _a={};K(_a,{base2:()=>ty});var ty=te({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ba={};K(Ba,{base256emoji:()=>iy});var al=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}"),ry=al.reduce((t,e,r)=>(t[r]=e,t),[]),ny=al.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function oy(t){return t.reduce((e,r)=>(e+=ry[r],e),"")}function sy(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=ny[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var iy=wr({prefix:"\u{1F680}",name:"base256emoji",encode:oy,decode:sy});var La={};K(La,{base32:()=>Er,base32hex:()=>fy,base32hexpad:()=>dy,base32hexpadupper:()=>hy,base32hexupper:()=>ly,base32pad:()=>cy,base32padupper:()=>uy,base32upper:()=>ay,base32z:()=>py});var Er=te({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ay=te({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),cy=te({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),uy=te({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),fy=te({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ly=te({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),dy=te({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),hy=te({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),py=te({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ra={};K(Ra,{base36:()=>wn,base36upper:()=>my});var wn=Et({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),my=Et({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Oa={};K(Oa,{base58btc:()=>$e,base58flickr:()=>yy});var $e=Et({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),yy=Et({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ka={};K(ka,{base64:()=>by,base64pad:()=>gy,base64url:()=>xy,base64urlpad:()=>wy});var by=te({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),gy=te({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),xy=te({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),wy=te({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Pa={};K(Pa,{base8:()=>Ey});var Ey=te({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ua={};K(Ua,{identity:()=>vy});var vy=wr({prefix:"\0",name:"identity",encode:t=>nl(t),decode:t=>rl(t)});var s8=new TextEncoder,i8=new TextDecoder;var Na={};K(Na,{identity:()=>$y});var Cy=fl,cl=128,Iy=127,Ty=~Iy,Dy=Math.pow(2,31);function fl(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Dy;)e[r++]=t&255|cl,t/=128;for(;t&Ty;)e[r++]=t&255|cl,t>>>=7;return e[r]=t|0,fl.bytes=r-n+1,e}var _y=Ka,By=128,ul=127;function Ka(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw Ka.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&ul)<<o:(i&ul)*Math.pow(2,o),o+=7}while(i>=By);return Ka.bytes=s-n,r}var Ly=Math.pow(2,7),Ry=Math.pow(2,14),Oy=Math.pow(2,21),ky=Math.pow(2,28),Py=Math.pow(2,35),Uy=Math.pow(2,42),Ky=Math.pow(2,49),Ny=Math.pow(2,56),Fy=Math.pow(2,63),My=function(t){return t<Ly?1:t<Ry?2:t<Oy?3:t<ky?4:t<Py?5:t<Uy?6:t<Ky?7:t<Ny?8:t<Fy?9:10},qy={encode:Cy,decode:_y,encodingLength:My},zy=qy,En=zy;function vn(t,e=0){return[En.decode(t,e),En.decode.bytes]}function vr(t,e,r=0){return En.encode(t,e,r),e}function Sr(t){return En.encodingLength(t)}function Cr(t,e){let r=e.byteLength,n=Sr(t),o=n+Sr(r),s=new Uint8Array(o+r);return vr(t,s,0),vr(r,s,n),s.set(e,o),new Ar(t,r,e,s)}function ll(t){let e=ot(t),[r,n]=vn(e),[o,s]=vn(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ar(r,o,i,e)}function dl(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&tl(t.bytes,r.bytes)}}var Ar=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};var hl=0,Vy="identity",pl=ot;function Hy(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return Cr(hl,pl(t))}var $y={code:hl,name:Vy,encode:pl,digest:Hy};var qa={};K(qa,{sha256:()=>Wy,sha512:()=>Zy});var jy=20;function Ma({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new Fa(t,e,r,n,o)}var Fa=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??jy,this.maxDigestLength=s}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?ml(n,this.code,r?.truncate):n.then(o=>ml(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function ml(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return Cr(e,t)}function bl(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Wy=Ma({name:"sha2-256",code:18,encode:bl("SHA-256")}),Zy=Ma({name:"sha2-512",code:19,encode:bl("SHA-512")});function gl(t,e){let{bytes:r,version:n}=t;return n===0?Yy(r,za(t),e??$e.encoder):Xy(r,za(t),e??Er.encoder)}var xl=new WeakMap;function za(t){let e=xl.get(t);if(e==null){let r=new Map;return xl.set(t,r),r}return e}var qo=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==An)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Qy)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=Cr(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&dl(e.multihash,n.multihash)}toString(e){return gl(this,e)}toJSON(){return{"/":gl(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new t(n,o,s,i??wl(n,o,s.bytes))}else if(r[Jy]===!0){let{version:n,multihash:o,code:s}=r,i=ll(o);return t.create(n,s,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==An)throw new Error(`Version 0 CID must use dag-pb (code: ${An}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=wl(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,An,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=ot(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Ar(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[d,l]=vn(e.subarray(r));return r+=l,d},o=n(),s=An;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,o]=Gy(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return za(s).set(n,e),s}};function Gy(t,e){switch(t[0]){case"Q":{let r=e??$e;return[$e.prefix,r.decode(`${$e.prefix}${t}`)]}case $e.prefix:{let r=e??$e;return[$e.prefix,r.decode(t)]}case Er.prefix:{let r=e??Er;return[Er.prefix,r.decode(t)]}case wn.prefix:{let r=e??wn;return[wn.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function Yy(t,e,r){let{prefix:n}=r;if(n!==$e.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function Xy(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var An=112,Qy=18;function wl(t,e,r){let n=Sr(t),o=n+Sr(e),s=new Uint8Array(o+r.byteLength);return vr(t,s,0),vr(e,s,n),s.set(r,o),s}var Jy=Symbol.for("@ipld/js-cid/CID");var Va={...Ua,..._a,...Pa,...Ta,...Da,...La,...Ra,...Oa,...ka,...Ba},D8={...qa,...Na};function El(t=0){return new Uint8Array(t)}function Sl(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var vl=Sl("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Ha=Sl("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=El(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),eb={utf8:vl,"utf-8":vl,hex:Va.base16,latin1:Ha,ascii:Ha,binary:Ha,...Va},zo=eb;function Al(t,e="utf8"){let r=zo[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Cl(t,e="utf8"){let r=zo[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var st="/",Il=new TextEncoder().encode(st),Vo=Il[0],Ho=class t{_buf;constructor(e,r){if(typeof e=="string")this._buf=Al(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(r==null&&(r=!0),r&&this.clean(),this._buf.byteLength===0||this._buf[0]!==Vo)throw new Error("Invalid key")}toString(e="utf8"){return Cl(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new t(e.join(st))}static random(){return new t(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new t(e):typeof e.uint8Array=="function"?new t(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=Il),this._buf[0]!==Vo){let e=new Uint8Array(this._buf.byteLength+1);e.fill(Vo,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Vo;)this._buf=this._buf.subarray(0,-1)}less(e){let r=this.list(),n=e.list();for(let o=0;o<r.length;o++){if(n.length<o+1)return!1;let s=r[o],i=n[o];if(s<i)return!0;if(s>i)return!1}return r.length<n.length}reverse(){return t.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(st).slice(1)}type(){return tb(this.baseNamespace())}name(){return rb(this.baseNamespace())}instance(e){return new t(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(st)||(e+=st),e+=this.type(),new t(e)}parent(){let e=this.list();return e.length===1?new t(st):new t(e.slice(0,-1).join(st))}child(e){return this.toString()===st?e:e.toString()===st?this:new t(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return t.withNamespaces([...this.namespaces(),...nb(e.map(r=>r.namespaces()))])}};function tb(t){let e=t.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function rb(t){let e=t.split(":");return e[e.length-1]}function nb(t){return[].concat(...t)}var $a="/peers/";function Cn(t){if(!Vt(t)||t.type==null)throw new M("Invalid PeerId");let e=t.toCID().toString();return new Ho(`${$a}${e}`)}async function Tl(t,e,r,n,o){let s=new Map;for(let i of r){if(i==null)continue;if(i.multiaddr instanceof Uint8Array&&(i.multiaddr=Nt(i.multiaddr)),!xo(i.multiaddr))throw new M("Multiaddr was invalid");if(!await e(t,i.multiaddr,o))continue;let a=i.isCertified??!1,c=i.multiaddr.toString(),u=s.get(c);u!=null?i.isCertified=u.isCertified||a:s.set(c,{multiaddr:i.multiaddr,isCertified:a})}return[...s.values()].sort((i,a)=>i.multiaddr.toString().localeCompare(a.multiaddr.toString())).map(({isCertified:i,multiaddr:a})=>{let c=a.getComponents().find(u=>u.code===421)?.value;return t.equals(c)&&(a=a.decapsulate(Nt(`/p2p/${t}`))),{isCertified:i,multiaddr:a.bytes}})}async function jo(t,e,r,n){if(e==null)throw new M("Invalid PeerData");if(e.publicKey!=null&&t.publicKey!=null&&!e.publicKey.equals(t.publicKey))throw new M("publicKey bytes do not match peer id publicKey bytes");let o=n.existingPeer?.peer;if(o!=null&&!t.equals(o.id))throw new M("peer id did not match existing peer id");let s=o?.addresses??[],i=new Set(o?.protocols??[]),a=o?.metadata??new Map,c=o?.tags??new Map,u=o?.peerRecordEnvelope;if(r==="patch"){if((e.multiaddrs!=null||e.addresses!=null)&&(s=[],e.multiaddrs!=null&&s.push(...e.multiaddrs.map(l=>({isCertified:!1,multiaddr:l}))),e.addresses!=null&&s.push(...e.addresses)),e.protocols!=null&&(i=new Set(e.protocols)),e.metadata!=null){let l=e.metadata instanceof Map?[...e.metadata.entries()]:Object.entries(e.metadata);a=$o(l,{validate:Dl})}if(e.tags!=null){let l=e.tags instanceof Map?[...e.tags.entries()]:Object.entries(e.tags);c=$o(l,{validate:_l,map:Bl})}e.peerRecordEnvelope!=null&&(u=e.peerRecordEnvelope)}if(r==="merge"){if(e.multiaddrs!=null&&s.push(...e.multiaddrs.map(l=>({isCertified:!1,multiaddr:l}))),e.addresses!=null&&s.push(...e.addresses),e.protocols!=null&&(i=new Set([...i,...e.protocols])),e.metadata!=null){let l=e.metadata instanceof Map?[...e.metadata.entries()]:Object.entries(e.metadata);for(let[h,p]of l)p==null?a.delete(h):a.set(h,p);a=$o([...a.entries()],{validate:Dl})}if(e.tags!=null){let l=e.tags instanceof Map?[...e.tags.entries()]:Object.entries(e.tags),h=new Map(c);for(let[p,b]of l)b==null?h.delete(p):h.set(p,b);c=$o([...h.entries()],{validate:_l,map:Bl})}e.peerRecordEnvelope!=null&&(u=e.peerRecordEnvelope)}let f;o?.id.publicKey!=null?f=De(o.id.publicKey):e.publicKey!=null?f=De(e.publicKey):t.publicKey!=null&&(f=De(t.publicKey));let d={addresses:await Tl(t,n.addressFilter??(async()=>!0),s,n.existingPeer?.peerPB.addresses,n),protocols:[...i.values()].sort((l,h)=>l.localeCompare(h)),metadata:a,tags:c,publicKey:f,peerRecordEnvelope:u};return d.addresses.forEach(l=>{l.observed=n.existingPeer?.peerPB.addresses?.find(h=>W(h.multiaddr,h.multiaddr))?.observed??Date.now()}),t.type!=="RSA"&&delete d.publicKey,d}function $o(t,e){let r=new Map;for(let[n,o]of t)o!=null&&e.validate(n,o);for(let[n,o]of t.sort(([s],[i])=>s.localeCompare(i)))o!=null&&r.set(n,e.map?.(n,o)??o);return r}function Dl(t,e){if(typeof t!="string")throw new M("Metadata key must be a string");if(!(e instanceof Uint8Array))throw new M("Metadata value must be a Uint8Array")}function _l(t,e){if(typeof t!="string")throw new M("Tag name must be a string");if(e.value!=null){if(parseInt(`${e.value}`,10)!==e.value)throw new M("Tag value must be an integer");if(e.value<0||e.value>100)throw new M("Tag value must be between 0-100")}if(e.ttl!=null){if(parseInt(`${e.ttl}`,10)!==e.ttl)throw new M("Tag ttl must be an integer");if(e.ttl<0)throw new M("Tag ttl must be between greater than 0")}}function Bl(t,e){let r;e.expiry!=null&&(r=e.expiry),e.ttl!=null&&(r=BigInt(Date.now()+Number(e.ttl)));let n={value:e.value??0};return r!=null&&(n.expiry=r),n}function Ll(t){let e=t.toString().split("/")[2],r=oe.parse(e,Ne);return fo(r)}function ja(t,e,r){let n=Ll(t);return Yf(n,e,r)}function ob(t,e){return{prefix:$a,filters:(t.filters??[]).map(r=>({key:n,value:o})=>r(ja(n,o,e))),orders:(t.orders??[]).map(r=>(n,o)=>r(ja(n.key,n.value,e),ja(o.key,o.value,e)))}}var Wo=class{peerId;datastore;locks;addressFilter;log;maxAddressAge;maxPeerAge;constructor(e,r={}){this.log=e.logger.forComponent("libp2p:peer-store"),this.peerId=e.peerId,this.datastore=e.datastore,this.addressFilter=r.addressFilter,this.locks=ya({name:"libp2p_peer_store_locks",metrics:e.metrics}),this.maxAddressAge=r.maxAddressAge??36e5,this.maxPeerAge=r.maxPeerAge??216e5}getLock(e){let r=this.locks.get(e);return r==null&&(r={refs:0,lock:va({name:e.toString(),singleProcess:!0})},this.locks.set(e,r)),r.refs++,r}maybeRemoveLock(e,r){r.refs--,r.refs===0&&(r.lock.finalize(),this.locks.delete(e))}async getReadLock(e,r){let n=this.getLock(e);try{let o=await n.lock.readLock(r);return()=>{o(),this.maybeRemoveLock(e,n)}}catch(o){throw this.maybeRemoveLock(e,n),o}}async getWriteLock(e,r){let n=this.getLock(e);try{let o=await n.lock.writeLock(r);return()=>{o(),this.maybeRemoveLock(e,n)}}catch(o){throw this.maybeRemoveLock(e,n),o}}async has(e,r){try{return await this.load(e,r),!0}catch(n){if(n.name!=="NotFoundError")throw n}return!1}async delete(e,r){this.peerId.equals(e)||await this.datastore.delete(Cn(e),r)}async load(e,r){let n=Cn(e),o=await this.datastore.get(n,r),s=nt.decode(o);if(this.#r(e,s))throw await this.datastore.delete(n,r),new Tr;return xr(e,s,this.peerId.equals(e)?1/0:this.maxAddressAge)}async save(e,r,n){let o=await this.#e(e,n),s=await jo(e,r,"patch",{...n,addressFilter:this.addressFilter});return this.#t(e,s,o)}async patch(e,r,n){let o=await this.#e(e,n),s=await jo(e,r,"patch",{...n,addressFilter:this.addressFilter,existingPeer:o});return this.#t(e,s,o)}async merge(e,r,n){let o=await this.#e(e,n),s=await jo(e,r,"merge",{addressFilter:this.addressFilter,existingPeer:o});return this.#t(e,s,o)}async*all(e){for await(let{key:r,value:n}of this.datastore.query(ob(e??{},this.maxAddressAge),e)){let o=Ll(r);if(o.equals(this.peerId))continue;let s=nt.decode(n);if(this.#r(o,s)){await this.datastore.delete(r,e);continue}yield xr(o,s,this.peerId.equals(o)?1/0:this.maxAddressAge)}}async#e(e,r){try{let n=Cn(e),o=await this.datastore.get(n,r),s=nt.decode(o);if(this.#r(e,s))throw await this.datastore.delete(n,r),new Tr;return{peerPB:s,peer:xr(e,s,this.maxAddressAge)}}catch(n){n.name!=="NotFoundError"&&this.log.error("invalid peer data found in peer store - %e",n)}}async#t(e,r,n,o){r.updated=Date.now();let s=nt.encode(r);return await this.datastore.put(Cn(e),s,o),{peer:xr(e,r,this.maxAddressAge),previous:n?.peer,updated:n==null||!Xf(r,n.peerPB)}}#r(e,r){if(r.updated==null)return!0;if(this.peerId.equals(e))return!1;let n=r.updated<Date.now()-this.maxPeerAge,o=Date.now()-this.maxAddressAge,s=r.addresses.filter(i=>i.observed!=null&&i.observed>o);return n&&s.length===0}};var Wa=class{store;events;peerId;log;constructor(e,r={}){this.log=e.logger.forComponent("libp2p:peer-store"),this.events=e.events,this.peerId=e.peerId,this.store=new Wo(e,r)}[Symbol.toStringTag]="@libp2p/peer-store";async forEach(e,r){for await(let n of this.store.all(r))e(n)}async all(e){return qf(this.store.all(e))}async delete(e,r){let n=await this.store.getReadLock(e,r);try{await this.store.delete(e,r)}finally{n()}}async has(e,r){let n=await this.store.getReadLock(e,r);try{return await this.store.has(e,r)}finally{this.log.trace("has release read lock"),n?.()}}async get(e,r){let n=await this.store.getReadLock(e,r);try{return await this.store.load(e,r)}finally{n?.()}}async getInfo(e,r){let n=await this.get(e,r);return{id:n.id,multiaddrs:n.addresses.map(({multiaddr:o})=>o)}}async save(e,r,n){let o=await this.store.getWriteLock(e,n);try{let s=await this.store.save(e,r,n);return this.#e(e,s),s.peer}finally{o?.()}}async patch(e,r,n){let o=await this.store.getWriteLock(e,n);try{let s=await this.store.patch(e,r,n);return this.#e(e,s),s.peer}finally{o?.()}}async merge(e,r,n){let o=await this.store.getWriteLock(e,n);try{let s=await this.store.merge(e,r,n);return this.#e(e,s),s.peer}finally{o?.()}}async consumePeerRecord(e,r,n){let o=Vt(r)?r:Vt(r?.expectedPeer)?r.expectedPeer:void 0,s=Vt(r)||r===void 0?n:r,i=await mr.openAndCertify(e,Ft.DOMAIN,s),a=fo(i.publicKey.toCID());if(o?.equals(a)===!1)return this.log("envelope peer id was not the expected peer id - expected: %p received: %p",o,a),!1;let c=Ft.createFromProtobuf(i.payload),u;try{u=await this.get(a,s)}catch(f){if(f.name!=="NotFoundError")throw f}if(u?.peerRecordEnvelope!=null){let f=mr.createFromProtobuf(u.peerRecordEnvelope),d=Ft.createFromProtobuf(f.payload);if(d.seqNumber>=c.seqNumber)return this.log("sequence number was lower or equal to existing sequence number - stored: %d received: %d",d.seqNumber,c.seqNumber),!1}return await this.patch(c.peerId,{peerRecordEnvelope:e,addresses:c.multiaddrs.map(f=>({isCertified:!0,multiaddr:f}))},s),!0}#e(e,r){r.updated&&(this.peerId.equals(e)?this.events.safeDispatchEvent("self:peer:update",{detail:r}):this.events.safeDispatchEvent("peer:update",{detail:r}))}};function sb(t,e={}){return new Wa(t,e)}return Ul(ib);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/curves/utils.js:
|