@libp2p/peer-store 12.0.19 → 12.0.20-29797a5bb
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 +9 -9
- 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 Lo=Object.defineProperty;var Cf=Object.getOwnPropertyDescriptor;var Bf=Object.getOwnPropertyNames;var Df=Object.prototype.hasOwnProperty;var H=(t,e)=>{for(var r in e)Lo(t,r,{get:e[r],enumerable:!0})},Rf=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Bf(e))!Df.call(t,o)&&o!==r&&Lo(t,o,{get:()=>e[o],enumerable:!(n=Cf(e,o))||n.enumerable});return t};var Lf=t=>Rf(Lo({},"__esModule",{value:!0}),t);var zm={};H(zm,{persistentPeerStore:()=>qm});var F=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Kt=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var mr=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var ln=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},dn=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var gt=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var hn=Symbol.for("@libp2p/peer-id");function Ut(t){return!!t?.[hn]}function Of(t){return typeof t?.handleEvent=="function"}function kf(t){return(t!==!0&&t!==!1&&t?.once)??!1}var Nt=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){let o=kf(n);super.addEventListener(e,i=>{if(o){let a=this.#e.get(i.type);a!=null&&(a=a.filter(({callback:c})=>c!==r),this.#e.set(i.type,a))}Of(r)?r.handleEvent(i):r(i)},n);let s=this.#e.get(e);s==null&&(s=[],this.#e.set(e,s)),s.push({callback:r,once:o})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==r),this.#e.set(e,o))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var Uo={};H(Uo,{base58btc:()=>Y,base58flickr:()=>qf});var Wm=new Uint8Array(0);function ha(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function $e(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function pa(t){return new TextEncoder().encode(t)}function ma(t){return new TextDecoder().decode(t)}function Pf(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var s=t.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function d(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var g=0,p=0,b=0,E=m.length;b!==E&&m[b]===0;)b++,g++;for(var S=(E-b)*f+1>>>0,C=new Uint8Array(S);b!==E;){for(var I=m[b],O=0,R=S-1;(I!==0||O<p)&&R!==-1;R--,O++)I+=256*C[R]>>>0,C[R]=I%a>>>0,I=I/a>>>0;if(I!==0)throw new Error("Non-zero carry");p=O,b++}for(var _=S-p;_!==S&&C[_]===0;)_++;for(var P=c.repeat(g);_<S;++_)P+=t.charAt(C[_]);return P}function l(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var g=0;if(m[g]!==" "){for(var p=0,b=0;m[g]===c;)p++,g++;for(var E=(m.length-g)*u+1>>>0,S=new Uint8Array(E);m[g];){var C=r[m.charCodeAt(g)];if(C===255)return;for(var I=0,O=E-1;(C!==0||I<b)&&O!==-1;O--,I++)C+=a*S[O]>>>0,S[O]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");b=I,g++}if(m[g]!==" "){for(var R=E-b;R!==E&&S[R]===0;)R++;for(var _=new Uint8Array(p+(E-R)),P=p;R!==E;)_[P++]=S[R++];return _}}}function h(m){var g=l(m);if(g)return g;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:l,decode:h}}var Kf=Pf,Uf=Kf,ba=Uf;var Oo=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},ko=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return ga(this,e)}},Po=class{decoders;constructor(e){this.decoders=e}or(e){return ga(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ga(t,e){return new Po({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Ko=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Oo(e,r,n),this.decoder=new ko(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Ft({name:t,prefix:e,encode:r,decode:n}){return new Ko(t,e,r,n)}function ot({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=ba(r,t);return Ft({prefix:e,name:t,encode:n,decode:s=>$e(o(s))})}function Nf(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Ff(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Mf(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function Z({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=Mf(n);return Ft({prefix:e,name:t,encode(s){return Ff(s,n,r)},decode(s){return Nf(s,o,r,t)}})}var Y=ot({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),qf=ot({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var No={};H(No,{base32:()=>Ue,base32hex:()=>$f,base32hexpad:()=>Wf,base32hexpadupper:()=>Zf,base32hexupper:()=>jf,base32pad:()=>Vf,base32padupper:()=>Hf,base32upper:()=>zf,base32z:()=>Yf});var Ue=Z({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),zf=Z({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Vf=Z({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Hf=Z({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),$f=Z({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),jf=Z({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Wf=Z({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Zf=Z({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Yf=Z({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Fo={};H(Fo,{base36:()=>yr,base36upper:()=>Gf});var yr=ot({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Gf=ot({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Xf=Ea,xa=128,Qf=127,Jf=~Qf,el=Math.pow(2,31);function Ea(t,e,r){e=e||[],r=r||0;for(var n=r;t>=el;)e[r++]=t&255|xa,t/=128;for(;t&Jf;)e[r++]=t&255|xa,t>>>=7;return e[r]=t|0,Ea.bytes=r-n+1,e}var tl=Mo,rl=128,wa=127;function Mo(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw Mo.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&wa)<<o:(i&wa)*Math.pow(2,o),o+=7}while(i>=rl);return Mo.bytes=s-n,r}var nl=Math.pow(2,7),ol=Math.pow(2,14),sl=Math.pow(2,21),il=Math.pow(2,28),al=Math.pow(2,35),cl=Math.pow(2,42),ul=Math.pow(2,49),fl=Math.pow(2,56),ll=Math.pow(2,63),dl=function(t){return t<nl?1:t<ol?2:t<sl?3:t<il?4:t<al?5:t<cl?6:t<ul?7:t<fl?8:t<ll?9:10},hl={encode:Xf,decode:tl,encodingLength:dl},pl=hl,br=pl;function gr(t,e=0){return[br.decode(t,e),br.decode.bytes]}function Mt(t,e,r=0){return br.encode(t,e,r),e}function qt(t){return br.encodingLength(t)}function Ne(t,e){let r=e.byteLength,n=qt(t),o=n+qt(r),s=new Uint8Array(o+r);return Mt(t,s,0),Mt(r,s,n),s.set(e,o),new zt(t,r,e,s)}function Vt(t){let e=$e(t),[r,n]=gr(e),[o,s]=gr(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new zt(r,o,i,e)}function va(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&ha(t.bytes,r.bytes)}}var zt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};function Sa(t,e){let{bytes:r,version:n}=t;return n===0?yl(r,qo(t),e??Y.encoder):bl(r,qo(t),e??Ue.encoder)}var Aa=new WeakMap;function qo(t){let e=Aa.get(t);if(e==null){let r=new Map;return Aa.set(t,r),r}return e}var te=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==xr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==gl)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=Ne(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&va(e.multihash,n.multihash)}toString(e){return Sa(this,e)}toJSON(){return{"/":Sa(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new t(n,o,s,i??Ta(n,o,s.bytes))}else if(r[xl]===!0){let{version:n,multihash:o,code:s}=r,i=Vt(o);return t.create(n,s,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==xr)throw new Error(`Version 0 CID must use dag-pb (code: ${xr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=Ta(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,xr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=$e(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new zt(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[d,l]=gr(e.subarray(r));return r+=l,d},o=n(),s=xr;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,o]=ml(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return qo(s).set(n,e),s}};function ml(t,e){switch(t[0]){case"Q":{let r=e??Y;return[Y.prefix,r.decode(`${Y.prefix}${t}`)]}case Y.prefix:{let r=e??Y;return[Y.prefix,r.decode(t)]}case Ue.prefix:{let r=e??Ue;return[Ue.prefix,r.decode(t)]}case yr.prefix:{let r=e??yr;return[yr.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function yl(t,e,r){let{prefix:n}=r;if(n!==Y.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function bl(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var xr=112,gl=18;function Ta(t,e,r){let n=qt(t),o=n+qt(e),s=new Uint8Array(o+r.byteLength);return Mt(t,s,0),Mt(e,s,n),s.set(r,o),s}var xl=Symbol.for("@ipld/js-cid/CID");var zo={};H(zo,{identity:()=>Ce});var _a=0,wl="identity",Ia=$e;function El(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return Ne(_a,Ia(t))}var Ce={code:_a,name:wl,encode:Ia,digest:El};function re(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function vl(t){return t.buffer instanceof ArrayBuffer}function Fe(t){return vl(t)?t:t.slice()}async function Ca(t,e,r,n){let o=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,Fe(e),Fe(r.subarray()));return n?.signal?.throwIfAborted(),s}function je(t=0){return new Uint8Array(t)}function wr(t=0){return new Uint8Array(t)}function Vo(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=wr(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}function Ba(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}var Ra=Symbol.for("@achingbrain/uint8arraylist");function Da(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let o=r+n.byteLength;if(e<o)return{buf:n,index:e-r};r=o}throw new RangeError("index is out of bounds")}function mn(t){return!!t?.[Ra]}var pe=class t{bufs;length;[Ra]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(mn(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(mn(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(e){let r=Da(this.bufs,e);return r.buf[r.index]}set(e,r){let n=Da(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(mn(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:o}=this._subList(e,r);return Vo(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:Vo(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),s=new t;return s.length=o,s.bufs=n,s}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,e>=c)continue;let u=e>=a&&e<c,f=r>a&&r<=c;if(u&&f){if(e===a&&r===c){n.push(i);break}let d=e-a;n.push(i.subarray(d,d+(r-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!mn(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let d=0;d<s;d++)i[d]=-1;for(let d=0;d<o;d++)i[n[d]]=d;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let d=r;d<=c;d+=f){f=0;for(let l=u;l>=0;l--){let h=this.get(d+l);if(n[l]!==h){f=Math.max(1,l-a[h]);break}}if(f===0)return d}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=wr(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let o=je(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let o=je(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let o=je(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=wr(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let o=je(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let o=je(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let o=je(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let o=je(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let o=je(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!Ba(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var Zo={};H(Zo,{base10:()=>Dl});var _0=new Uint8Array(0);function La(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function We(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return xt(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return xt(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function Oa(t){return new TextEncoder().encode(t)}function ka(t){return new TextDecoder().decode(t)}function Sl(t){return t?.buffer instanceof ArrayBuffer}function xt(t){return Sl(t)?t:t.slice()}function Al(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var s=t.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function d(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var g=0,p=0,b=0,E=m.length;b!==E&&m[b]===0;)b++,g++;for(var S=(E-b)*f+1>>>0,C=new Uint8Array(S);b!==E;){for(var I=m[b],O=0,R=S-1;(I!==0||O<p)&&R!==-1;R--,O++)I+=256*C[R]>>>0,C[R]=I%a>>>0,I=I/a>>>0;if(I!==0)throw new Error("Non-zero carry");p=O,b++}for(var _=S-p;_!==S&&C[_]===0;)_++;for(var P=c.repeat(g);_<S;++_)P+=t.charAt(C[_]);return P}function l(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var g=0;if(m[g]!==" "){for(var p=0,b=0;m[g]===c;)p++,g++;for(var E=(m.length-g)*u+1>>>0,S=new Uint8Array(E);m[g];){var C=r[m.charCodeAt(g)];if(C===255)return;for(var I=0,O=E-1;(C!==0||I<b)&&O!==-1;O--,I++)C+=a*S[O]>>>0,S[O]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");b=I,g++}if(m[g]!==" "){for(var R=E-b;R!==E&&S[R]===0;)R++;for(var _=new Uint8Array(p+(E-R)),P=p;R!==E;)_[P++]=S[R++];return _}}}function h(m){var g=l(m);if(g)return g;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:l,decode:h}}var Tl=Al,_l=Tl,Ka=_l;var Ho=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},$o=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Ua(this,e)}},jo=class{decoders;constructor(e){this.decoders=e}or(e){return Ua(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ua(t,e){return new jo({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Wo=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Ho(e,r,n),this.decoder=new $o(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Ht({name:t,prefix:e,encode:r,decode:n}){return new Wo(t,e,r,n)}function it({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=Ka(r,t);return Ht({prefix:e,name:t,encode:n,decode:s=>We(o(s))})}function Il(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Cl(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Bl(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function G({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=Bl(n);return Ht({prefix:e,name:t,encode(s){return Cl(s,n,r)},decode(s){return Il(s,o,r,t)}})}var Dl=it({prefix:"9",name:"base10",alphabet:"0123456789"});var Yo={};H(Yo,{base16:()=>Rl,base16upper:()=>Ll});var Rl=G({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ll=G({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Go={};H(Go,{base2:()=>Ol});var Ol=G({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Xo={};H(Xo,{base256emoji:()=>Nl});var Na=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),kl=Na.reduce((t,e,r)=>(t[r]=e,t),[]),Pl=Na.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Kl(t){return t.reduce((e,r)=>(e+=kl[r],e),"")}function Ul(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Pl[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Nl=Ht({prefix:"\u{1F680}",name:"base256emoji",encode:Kl,decode:Ul});var Qo={};H(Qo,{base32:()=>$t,base32hex:()=>zl,base32hexpad:()=>Hl,base32hexpadupper:()=>$l,base32hexupper:()=>Vl,base32pad:()=>Ml,base32padupper:()=>ql,base32upper:()=>Fl,base32z:()=>jl});var $t=G({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Fl=G({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ml=G({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ql=G({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),zl=G({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Vl=G({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Hl=G({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),$l=G({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),jl=G({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Jo={};H(Jo,{base36:()=>Er,base36upper:()=>Wl});var Er=it({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Wl=it({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var es={};H(es,{base58btc:()=>Me,base58flickr:()=>Zl});var Me=it({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Zl=it({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ts={};H(ts,{base64:()=>Yl,base64pad:()=>Gl,base64url:()=>Xl,base64urlpad:()=>Ql});var Yl=G({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Gl=G({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Xl=G({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ql=G({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var rs={};H(rs,{base8:()=>Jl});var Jl=G({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ns={};H(ns,{identity:()=>ed});var ed=Ht({prefix:"\0",name:"identity",encode:t=>ka(t),decode:t=>Oa(t)});var z0=new TextEncoder,V0=new TextDecoder;var ss={};H(ss,{identity:()=>Sd});var nd=qa,Fa=128,od=127,sd=~od,id=Math.pow(2,31);function qa(t,e,r){e=e||[],r=r||0;for(var n=r;t>=id;)e[r++]=t&255|Fa,t/=128;for(;t&sd;)e[r++]=t&255|Fa,t>>>=7;return e[r]=t|0,qa.bytes=r-n+1,e}var ad=os,cd=128,Ma=127;function os(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw os.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&Ma)<<o:(i&Ma)*Math.pow(2,o),o+=7}while(i>=cd);return os.bytes=s-n,r}var ud=Math.pow(2,7),fd=Math.pow(2,14),ld=Math.pow(2,21),dd=Math.pow(2,28),hd=Math.pow(2,35),pd=Math.pow(2,42),md=Math.pow(2,49),yd=Math.pow(2,56),bd=Math.pow(2,63),gd=function(t){return t<ud?1:t<fd?2:t<ld?3:t<dd?4:t<hd?5:t<pd?6:t<md?7:t<yd?8:t<bd?9:10},xd={encode:nd,decode:ad,encodingLength:gd},wd=xd,vr=wd;function Sr(t,e=0){return[vr.decode(t,e),vr.decode.bytes]}function jt(t,e,r=0){return vr.encode(t,e,r),e}function Wt(t){return vr.encodingLength(t)}function Yt(t,e){let r=e.byteLength,n=Wt(t),o=n+Wt(r),s=new Uint8Array(o+r);return jt(t,s,0),jt(r,s,n),s.set(e,o),new Zt(t,r,e,s)}function za(t){let e=We(t),[r,n]=Sr(e),[o,s]=Sr(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Zt(r,o,i,e)}function Va(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&La(t.bytes,r.bytes)}}var Zt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=xt(n),this.bytes=xt(o)}};var Ha=0,Ed="identity",$a=We;function vd(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return Yt(Ha,$a(t))}var Sd={code:Ha,name:Ed,encode:$a,digest:vd};var cs={};H(cs,{sha256:()=>Td,sha512:()=>_d});var Ad=20;function as({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new is(t,e,r,n,o)}var is=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Ad,this.maxDigestLength=s}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?ja(n,this.code,r?.truncate):n.then(o=>ja(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function ja(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return Yt(e,t)}function Za(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Td=as({name:"sha2-256",code:18,encode:Za("SHA-256")}),_d=as({name:"sha2-512",code:19,encode:Za("SHA-512")});function Ya(t,e){let{bytes:r,version:n}=t;return n===0?Cd(r,us(t),e??Me.encoder):Bd(r,us(t),e??$t.encoder)}var Ga=new WeakMap;function us(t){let e=Ga.get(t);if(e==null){let r=new Map;return Ga.set(t,r),r}return e}var bn=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=xt(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==Tr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Dd)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=Yt(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&Va(e.multihash,n.multihash)}toString(e){return Ya(this,e)}toJSON(){return{"/":Ya(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new t(n,o,s,i??Xa(n,o,s.bytes))}else if(r[Rd]===!0){let{version:n,multihash:o,code:s}=r,i=za(o);return t.create(n,s,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==Tr)throw new Error(`Version 0 CID must use dag-pb (code: ${Tr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=Xa(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Tr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=We(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Zt(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[d,l]=Sr(e.subarray(r));return r+=l,d},o=n(),s=Tr;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,o]=Id(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return us(s).set(n,e),s}};function Id(t,e){switch(t[0]){case"Q":{let r=e??Me;return[Me.prefix,r.decode(`${Me.prefix}${t}`)]}case Me.prefix:{let r=e??Me;return[Me.prefix,r.decode(t)]}case $t.prefix:{let r=e??$t;return[$t.prefix,r.decode(t)]}case Er.prefix:{let r=e??Er;return[Er.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function Cd(t,e,r){let{prefix:n}=r;if(n!==Me.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function Bd(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var Tr=112,Dd=18;function Xa(t,e,r){let n=Wt(t),o=n+Wt(e),s=new Uint8Array(o+r.byteLength);return jt(t,s,0),jt(e,s,n),s.set(r,o),s}var Rd=Symbol.for("@ipld/js-cid/CID");var fs={...ns,...Go,...rs,...Zo,...Yo,...Qo,...Jo,...es,...ts,...Xo},ly={...cs,...ss};function Be(t=0){return new Uint8Array(t)}function ls(t=0){return new Uint8Array(t)}function Ja(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Qa=Ja("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),ds=Ja("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=ls(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Ld={utf8:Qa,"utf-8":Qa,hex:fs.base16,latin1:ds,ascii:ds,binary:ds,...fs},gn=Ld;function J(t,e="utf8"){let r=gn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function $(t,e="utf8"){let r=gn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var Od=parseInt("11111",2),hs=parseInt("10000000",2),kd=parseInt("01111111",2),ec={0:_r,1:_r,2:Pd,3:Nd,4:Fd,5:Ud,6:Kd,16:_r,22:_r,48:_r};function Ze(t,e={offset:0}){let r=t[e.offset]&Od;if(e.offset++,ec[r]!=null)return ec[r](t,e);throw new Error("No decoder for tag "+r)}function Ir(t,e){let r=0;if((t[e.offset]&hs)===hs){let n=t[e.offset]&kd,o="0x";e.offset++;for(let s=0;s<n;s++,e.offset++)o+=t[e.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=t[e.offset],e.offset++;return r}function _r(t,e){Ir(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=Ze(t,e);if(n===null)break;r.push(n)}return r}function Pd(t,e){let r=Ir(t,e),n=e.offset,o=e.offset+r,s=[];for(let i=n;i<o;i++)i===n&&t[i]===0||s.push(t[i]);return e.offset+=r,Uint8Array.from(s)}function Kd(t,e){let r=Ir(t,e),n=e.offset+r,o=t[e.offset];e.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;e.offset<n;){let u=t[e.offset];if(e.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let d=0;d<c.length;d++)f+=c[d]<<d*7;a+=`.${f}`,c=[]}}return a}function Ud(t,e){return e.offset++,null}function Nd(t,e){let r=Ir(t,e),n=t[e.offset];e.offset++;let o=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Fd(t,e){let r=Ir(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function Md(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new pe;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function ps(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=Md(t.byteLength);return new pe(Uint8Array.from([e.byteLength|hs]),e)}function we(t){let e=new pe,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new pe(Uint8Array.from([2]),ps(e),e)}function xn(t){let e=Uint8Array.from([0]),r=new pe(e,t);return new pe(Uint8Array.from([3]),ps(r),r)}function at(t,e=48){let r=new pe;for(let n of t)r.append(n);return new pe(Uint8Array.from([e]),ps(r),r)}var qd=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),zd=Uint8Array.from([6,5,43,129,4,0,34]),Vd=Uint8Array.from([6,5,43,129,4,0,35]),Hd={ext:!0,kty:"EC",crv:"P-256"},$d={ext:!0,kty:"EC",crv:"P-384"},jd={ext:!0,kty:"EC",crv:"P-521"},ms=32,ys=48,bs=66;function gs(t){let e=Ze(t);return tc(e)}function tc(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===ms*2+1)return n=$(e.subarray(r,r+ms),"base64url"),o=$(e.subarray(r+ms),"base64url"),new Gt({...Hd,key_ops:["verify"],x:n,y:o});if(e.byteLength===ys*2+1)return n=$(e.subarray(r,r+ys),"base64url"),o=$(e.subarray(r+ys),"base64url"),new Gt({...$d,key_ops:["verify"],x:n,y:o});if(e.byteLength===bs*2+1)return n=$(e.subarray(r,r+bs),"base64url"),o=$(e.subarray(r+bs),"base64url"),new Gt({...jd,key_ops:["verify"],x:n,y:o});throw new F(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function rc(t){return at([we(Uint8Array.from([1])),at([Wd(t.crv)],160),at([xn(new pe(Uint8Array.from([4]),J(t.x??"","base64url"),J(t.y??"","base64url")))],161)]).subarray()}function Wd(t){if(t==="P-256")return qd;if(t==="P-384")return zd;if(t==="P-521")return Vd;throw new F(`Invalid curve ${t}`)}var Gt=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=rc(this.jwk)),this._raw}toMultihash(){return Ce.digest(Ae(this))}toCID(){return te.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:re(this.raw,e.raw)}async verify(e,r,n){return Ca(this.jwk,r,e,n)}};function xs(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function ct(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(`${r}expected number, got ${typeof t}`)}if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new RangeError(`${r}expected integer >= 0, got ${t}`)}}function Ee(t,e,r=""){let n=xs(t),o=t?.length,s=e!==void 0;if(!n||s&&o!==e){let i=r&&`"${r}" `,a=s?` of length ${e}`:"",c=n?`length=${o}`:`type=${typeof t}`,u=i+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(u):new TypeError(u)}return t}function wn(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(ct(t.outputLen),ct(t.blockLen),t.outputLen<1)throw new Error('"outputLen" must be >= 1');if(t.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Xt(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function En(t,e){Ee(t,void 0,"digestInto() output");let r=e.outputLen;if(t.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function Ge(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function vn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function De(t,e){return t<<32-e|t>>>e}var oc=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Zd=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Sn(t){if(Ee(t),oc)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=Zd[t[r]];return e}var Ye={_0:48,_9:57,A:65,F:70,a:97,f:102};function nc(t){if(t>=Ye._0&&t<=Ye._9)return t-Ye._0;if(t>=Ye.A&&t<=Ye.F)return t-(Ye.A-10);if(t>=Ye.a&&t<=Ye.f)return t-(Ye.a-10)}function Cr(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(oc)try{return Uint8Array.fromHex(t)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=nc(t.charCodeAt(s)),a=nc(t.charCodeAt(s+1));if(i===void 0||a===void 0){let c=t[s]+t[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function ws(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];Ee(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let s=t[n];r.set(s,o),o+=s.length}return r}function Es(t,e={}){let r=(o,s)=>t(s).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function sc(t=32){ct(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var vs=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function ic(t,e,r){return t&e^~t&r}function ac(t,e,r){return t&e^t&r^e&r}var Br=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,o){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=vn(this.buffer)}update(e){Xt(this),Ee(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=vn(e);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Xt(this),En(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Ge(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let d=i;d<o;d++)r[d]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=vn(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<u;d++)a.setUint32(4*d,f[d],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=s,e.length=o,e.pos=a,o%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},Xe=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ue=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var An=BigInt(4294967295),cc=BigInt(32);function Yd(t,e=!1){return e?{h:Number(t&An),l:Number(t>>cc&An)}:{h:Number(t>>cc&An)|0,l:Number(t&An)|0}}function uc(t,e=!1){let r=t.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=Yd(t[s],e);[n[s],o[s]]=[i,a]}return[n,o]}var Ss=(t,e,r)=>t>>>r,As=(t,e,r)=>t<<32-r|e>>>r,wt=(t,e,r)=>t>>>r|e<<32-r,Et=(t,e,r)=>t<<32-r|e>>>r,Dr=(t,e,r)=>t<<64-r|e>>>r-32,Rr=(t,e,r)=>t>>>r-32|e<<64-r;function qe(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var fc=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),lc=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,dc=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),hc=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,pc=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),mc=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;var Xd=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),ut=new Uint32Array(64),Ts=class extends Br{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[e,r,n,o,s,i,a,c]}set(e,r,n,o,s,i,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(e,r){for(let d=0;d<16;d++,r+=4)ut[d]=e.getUint32(r,!1);for(let d=16;d<64;d++){let l=ut[d-15],h=ut[d-2],m=De(l,7)^De(l,18)^l>>>3,g=De(h,17)^De(h,19)^h>>>10;ut[d]=g+ut[d-7]+m+ut[d-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let d=0;d<64;d++){let l=De(a,6)^De(a,11)^De(a,25),h=f+l+ic(a,c,u)+Xd[d]+ut[d]|0,g=(De(n,2)^De(n,13)^De(n,22))+ac(n,o,s)|0;f=u,u=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+g|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,u,f)}roundClean(){Ge(ut)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Ge(this.buffer)}},_s=class extends Ts{A=Xe[0]|0;B=Xe[1]|0;C=Xe[2]|0;D=Xe[3]|0;E=Xe[4]|0;F=Xe[5]|0;G=Xe[6]|0;H=Xe[7]|0;constructor(){super(32)}};var yc=uc(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),Qd=yc[0],Jd=yc[1],ft=new Uint32Array(80),lt=new Uint32Array(80),Is=class extends Br{constructor(e){super(128,e,16,!1)}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:d,Fl:l,Gh:h,Gl:m,Hh:g,Hl:p}=this;return[e,r,n,o,s,i,a,c,u,f,d,l,h,m,g,p]}set(e,r,n,o,s,i,a,c,u,f,d,l,h,m,g,p){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=d|0,this.Fl=l|0,this.Gh=h|0,this.Gl=m|0,this.Hh=g|0,this.Hl=p|0}process(e,r){for(let S=0;S<16;S++,r+=4)ft[S]=e.getUint32(r),lt[S]=e.getUint32(r+=4);for(let S=16;S<80;S++){let C=ft[S-15]|0,I=lt[S-15]|0,O=wt(C,I,1)^wt(C,I,8)^Ss(C,I,7),R=Et(C,I,1)^Et(C,I,8)^As(C,I,7),_=ft[S-2]|0,P=lt[S-2]|0,V=wt(_,P,19)^Dr(_,P,61)^Ss(_,P,6),K=Et(_,P,19)^Rr(_,P,61)^As(_,P,6),y=dc(R,K,lt[S-7],lt[S-16]),x=hc(y,O,V,ft[S-7],ft[S-16]);ft[S]=x|0,lt[S]=y|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:d,El:l,Fh:h,Fl:m,Gh:g,Gl:p,Hh:b,Hl:E}=this;for(let S=0;S<80;S++){let C=wt(d,l,14)^wt(d,l,18)^Dr(d,l,41),I=Et(d,l,14)^Et(d,l,18)^Rr(d,l,41),O=d&h^~d&g,R=l&m^~l&p,_=pc(E,I,R,Jd[S],lt[S]),P=mc(_,b,C,O,Qd[S],ft[S]),V=_|0,K=wt(n,o,28)^Dr(n,o,34)^Dr(n,o,39),y=Et(n,o,28)^Rr(n,o,34)^Rr(n,o,39),x=n&s^n&a^s&a,A=o&i^o&c^i&c;b=g|0,E=p|0,g=h|0,p=m|0,h=d|0,m=l|0,{h:d,l}=qe(u|0,f|0,P|0,V|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let v=fc(V,y,A);n=lc(v,P,K,x),o=v|0}({h:n,l:o}=qe(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=qe(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=qe(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=qe(this.Dh|0,this.Dl|0,u|0,f|0),{h:d,l}=qe(this.Eh|0,this.El|0,d|0,l|0),{h,l:m}=qe(this.Fh|0,this.Fl|0,h|0,m|0),{h:g,l:p}=qe(this.Gh|0,this.Gl|0,g|0,p|0),{h:b,l:E}=qe(this.Hh|0,this.Hl|0,b|0,E|0),this.set(n,o,s,i,a,c,u,f,d,l,h,m,g,p,b,E)}roundClean(){Ge(ft,lt)}destroy(){this.destroyed=!0,Ge(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Cs=class extends Is{Ah=ue[0]|0;Al=ue[1]|0;Bh=ue[2]|0;Bl=ue[3]|0;Ch=ue[4]|0;Cl=ue[5]|0;Dh=ue[6]|0;Dl=ue[7]|0;Eh=ue[8]|0;El=ue[9]|0;Fh=ue[10]|0;Fl=ue[11]|0;Gh=ue[12]|0;Gl=ue[13]|0;Hh=ue[14]|0;Hl=ue[15]|0;constructor(){super(64)}};var Qt=Es(()=>new _s,vs(1));var Tn=Es(()=>new Cs,vs(3));var M=(t,e,r)=>Ee(t,e,r),Ds=ct,Jt=Sn,oe=(...t)=>ws(...t),er=t=>Cr(t),vt=xs,Lr=t=>sc(t),In=BigInt(0),Bs=BigInt(1);function Re(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new TypeError(r+"expected boolean, got type="+typeof t)}return t}function Cn(t){if(typeof t=="bigint"){if(!_n(t))throw new RangeError("positive bigint expected, got "+t)}else Ds(t);return t}function Le(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function Or(t){let e=Cn(t).toString(16);return e.length&1?"0"+e:e}function bc(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?In:BigInt("0x"+t)}function St(t){return bc(Sn(t))}function ze(t){return bc(Sn(kr(Ee(t)).reverse()))}function Bn(t,e){if(ct(e),e===0)throw new RangeError("zero length");t=Cn(t);let r=t.toString(16);if(r.length>e*2)throw new RangeError("number too large");return Cr(r.padStart(e*2,"0"))}function Rs(t,e){return Bn(t,e).reverse()}function gc(t,e){if(t=M(t),e=M(e),t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function kr(t){return Uint8Array.from(M(t))}function Dn(t){if(typeof t!="string")throw new TypeError("ascii string expected, got "+typeof t);return Uint8Array.from(t,(e,r)=>{let n=e.charCodeAt(0);if(e.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${t[r]}" with code ${n} at position ${r}`);return n})}var _n=t=>typeof t=="bigint"&&In<=t;function eh(t,e,r){return _n(t)&&_n(e)&&_n(r)&&e<=t&&t<r}function tr(t,e,r,n){if(!eh(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function rr(t){if(t<In)throw new Error("expected non-negative bigint, got "+t);let e;for(e=0;t>In;t>>=Bs,e+=1);return e}var Pr=t=>(Bs<<BigInt(t))-Bs;function xc(t,e,r){if(ct(t,"hashLen"),ct(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=p=>new Uint8Array(p),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(t),u=n(t),f=0,d=()=>{c.fill(1),u.fill(0),f=0},l=(...p)=>r(u,oe(c,...p)),h=(p=o)=>{u=l(s,p),c=l(),p.length!==0&&(u=l(i,p),c=l())},m=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let p=0,b=[];for(;p<e;){c=l();let E=c.slice();b.push(E),p+=c.length}return oe(...b)};return(p,b)=>{d(),h(p);let E;for(;(E=b(m()))===void 0;)h();return d(),E}}function Oe(t,e={},r={}){if(Object.prototype.toString.call(t)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,i,a){if(!a&&i!=="function"&&!Object.hasOwn(t,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let c=t[s];if(a&&c===void 0)return;let u=typeof c;if(u!==i||c===null)throw new TypeError(`param "${s}" is invalid: expected ${i}, got ${u}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(e,!1),o(r,!0)}var Ls=()=>{throw new Error("not implemented")};var fe=BigInt(0),X=BigInt(1),At=BigInt(2),Sc=BigInt(3),Ac=BigInt(4),Tc=BigInt(5),th=BigInt(7),_c=BigInt(8),rh=BigInt(9),Ic=BigInt(16);function ee(t,e){if(e<=fe)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=fe?r:e+r}function j(t,e,r){if(e<fe)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >fe;)n*=n,n%=r;return n}function wc(t,e){if(t===fe)throw new Error("invert: expected non-zero number");if(e<=fe)throw new Error("invert: expected positive modulus, got "+e);let r=ee(t,e),n=e,o=fe,s=X,i=X,a=fe;for(;r!==fe;){let u=n/r,f=n-r*u,d=o-i*u,l=s-a*u;n=r,r=f,o=i,s=a,i=d,a=l}if(n!==X)throw new Error("invert: does not exist");return ee(o,e)}function Os(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function Cc(t,e){let r=t,n=(r.ORDER+X)/Ac,o=r.pow(e,n);return Os(r,o,e),o}function nh(t,e){let r=t,n=(r.ORDER-Tc)/_c,o=r.mul(e,At),s=r.pow(o,n),i=r.mul(e,s),a=r.mul(r.mul(i,At),s),c=r.mul(i,r.sub(a,r.ONE));return Os(r,c,e),c}function oh(t){let e=nr(t),r=Bc(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+th)/Ic;return((a,c)=>{let u=a,f=u.pow(c,i),d=u.mul(f,n),l=u.mul(f,o),h=u.mul(f,s),m=u.eql(u.sqr(d),c),g=u.eql(u.sqr(l),c);f=u.cmov(f,d,m),d=u.cmov(h,l,g);let p=u.eql(u.sqr(d),c),b=u.cmov(f,d,p);return Os(u,b,c),b})}function Bc(t){if(t<Sc)throw new Error("sqrt is not defined for small field");let e=t-X,r=0;for(;e%At===fe;)e/=At,r++;let n=At,o=nr(t);for(;Ec(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Cc;let s=o.pow(n,e),i=(e+X)/At;return function(c,u){let f=c;if(f.is0(u))return u;if(Ec(f,u)!==1)throw new Error("Cannot find square root");let d=r,l=f.mul(f.ONE,s),h=f.pow(u,e),m=f.pow(u,i);for(;!f.eql(h,f.ONE);){if(f.is0(h))return f.ZERO;let g=1,p=f.sqr(h);for(;!f.eql(p,f.ONE);)if(g++,p=f.sqr(p),g===d)throw new Error("Cannot find square root");let b=X<<BigInt(d-g-1),E=f.pow(l,b);d=g,l=f.sqr(E),h=f.mul(h,l),m=f.mul(m,E)}return m}}function sh(t){return t%Ac===Sc?Cc:t%_c===Tc?nh:t%Ic===rh?oh(t):Bc(t)}var Qe=(t,e)=>(ee(t,e)&X)===X,ih=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ks(t){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=ih.reduce((n,o)=>(n[o]="function",n),e);if(Oe(t,r),Le(t.BYTES,"BYTES"),Le(t.BITS,"BITS"),t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=X)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function ah(t,e,r){let n=t;if(r<fe)throw new Error("invalid exponent, negatives unsupported");if(r===fe)return n.ONE;if(r===X)return e;let o=n.ONE,s=e;for(;r>fe;)r&X&&(o=n.mul(o,s)),s=n.sqr(s),r>>=X;return o}function Kr(t,e,r=!1){let n=t,o=new Array(e.length).fill(r?n.ZERO:void 0),s=e.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return e.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),i),o}function Ec(t,e){let r=t,n=(r.ORDER-X)/At,o=r.pow(e,n),s=r.eql(o,r.ONE),i=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function ch(t,e){if(e!==void 0&&Ds(e),t<=fe)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=rr(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${e})`);let n=e!==void 0?e:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var vc=new WeakMap,Rn=class{ORDER;BITS;BYTES;isLE;ZERO=fe;ONE=X;_lengths;_mod;constructor(e,r={}){if(e<=X)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=ch(e,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(e){return ee(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return fe<=e&&e<this.ORDER}is0(e){return e===fe}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&X)===X}neg(e){return ee(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return ee(e*e,this.ORDER)}add(e,r){return ee(e+r,this.ORDER)}sub(e,r){return ee(e-r,this.ORDER)}mul(e,r){return ee(e*r,this.ORDER)}pow(e,r){return ah(this,e,r)}div(e,r){return ee(e*wc(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return wc(e,this.ORDER)}sqrt(e){let r=vc.get(this);return r||vc.set(this,r=sh(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?Rs(e,this.BYTES):Bn(e,this.BYTES)}fromBytes(e,r=!1){M(e);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(o);u.set(e,s?0:u.length-e.length),e=u}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=s?ze(e):St(e);if(a&&(c=ee(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return Kr(this,e)}cmov(e,r,n){return Re(n,"condition"),n?r:e}};Object.freeze(Rn.prototype);function nr(t,e={}){return new Rn(t,e)}function Dc(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=X)throw new Error("field order must be greater than 1");let e=rr(t-X);return Math.ceil(e/8)}function Ps(t){let e=Dc(t);return e+Math.ceil(e/2)}function Ks(t,e,r=!1){M(t);let n=t.length,o=Dc(e),s=Math.max(Ps(e),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?ze(t):St(t),a=ee(i,e-X)+X;return r?Rs(a,o):Bn(a,o)}var or=BigInt(0),Tt=BigInt(1);function Ur(t,e){let r=e.negate();return t?r:e}function _t(t,e){let r=Kr(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function kc(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Us(t,e){kc(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),o=2**t,s=Pr(t),i=BigInt(t);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Rc(t,e,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(t&o),c=t>>i;a>n&&(a-=s,c+=Tt);let u=e*n,f=u+Math.abs(a)-1,d=a===0,l=a<0,h=e%2!==0;return{nextN:c,offset:f,isZero:d,isNeg:l,isNegF:h,offsetF:u}}var Ns=new WeakMap,Pc=new WeakMap;function Fs(t){return Pc.get(t)||1}function Lc(t){if(t!==or)throw new Error("invalid wNAF")}var sr=class{BASE;ZERO;Fn;bits;constructor(e,r){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let o=e;for(;r>or;)r&Tt&&(n=n.add(o)),o=o.double(),r>>=Tt;return n}precomputeWindow(e,r){let{windows:n,windowSize:o}=Us(r,this.bits),s=[],i=e,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let u=1;u<o;u++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Us(e,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:d,isNegF:l,offsetF:h}=Rc(n,a,i);n=c,f?s=s.add(Ur(l,r[h])):o=o.add(Ur(d,r[u]))}return Lc(n),{p:o,f:s}}wNAFUnsafe(e,r,n,o=this.ZERO){let s=Us(e,this.bits);for(let i=0;i<s.windows&&n!==or;i++){let{nextN:a,offset:c,isZero:u,isNeg:f}=Rc(n,i,s);if(n=a,!u){let d=r[c];o=o.add(f?d.negate():d)}}return Lc(n),o}getPrecomputes(e,r,n){let o=Ns.get(r);return o||(o=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(o=n(o)),Ns.set(r,o))),o}cached(e,r,n){let o=Fs(e);return this.wNAF(o,this.getPrecomputes(o,e,n),r)}unsafe(e,r,n,o){let s=Fs(e);return s===1?this._unsafeLadder(e,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,e,n),r,o)}createCache(e,r){kc(r,this.bits),Pc.set(e,r),Ns.delete(e)}hasCache(e){return Fs(e)!==1}};function Kc(t,e,r,n){let o=e,s=t.ZERO,i=t.ZERO;for(;r>or||n>or;)r&Tt&&(s=s.add(o)),n&Tt&&(i=i.add(o)),o=o.double(),r>>=Tt,n>>=Tt;return{p1:s,p2:i}}function Oc(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ks(e),e}else return nr(t,{isLE:r})}function Ln(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let c of["p","n","h"]){let u=e[c];if(!(typeof u=="bigint"&&u>or))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Oc(e.p,r.Fp,n),s=Oc(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:s}}function On(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var dt=BigInt(0),ae=BigInt(1),Ms=BigInt(2),uh=BigInt(8);function fh(t,e,r,n){let o=t.sqr(r),s=t.sqr(n),i=t.add(t.mul(e.a,o),s),a=t.add(t.ONE,t.mul(e.d,t.mul(o,s)));return t.eql(i,a)}function Uc(t,e={}){let r=e,n=Ln("edwards",t,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;Oe(r,{},{uvRatio:"function"});let c=Ms<<BigInt(s.BYTES*8)-ae,u=g=>o.create(g),f=r.uvRatio===void 0?(g,p)=>{try{return{isValid:!0,value:o.sqrt(o.div(g,p))}}catch{return{isValid:!1,value:dt}}}:r.uvRatio;if(!fh(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function d(g,p,b=!1){let E=b?ae:dt;return tr("coordinate "+g,p,E,c),p}function l(g){if(!(g instanceof h))throw new Error("EdwardsPoint expected")}class h{static BASE=new h(i.Gx,i.Gy,ae,u(i.Gx*i.Gy));static ZERO=new h(dt,ae,ae,dt);static Fp=o;static Fn=s;X;Y;Z;T;constructor(p,b,E,S){this.X=d("x",p),this.Y=d("y",b),this.Z=d("z",E,!0),this.T=d("t",S),Object.freeze(this)}static CURVE(){return i}static fromAffine(p){if(p instanceof h)throw new Error("extended point not allowed");let{x:b,y:E}=p||{};return d("x",b),d("y",E),new h(b,E,ae,u(b*E))}static fromBytes(p,b=!1){let E=o.BYTES,{a:S,d:C}=i;p=kr(M(p,E,"point")),Re(b,"zip215");let I=kr(p),O=p[E-1];I[E-1]=O&-129;let R=ze(I),_=b?c:o.ORDER;tr("point.y",R,dt,_);let P=u(R*R),V=u(P-ae),K=u(C*P-S),{isValid:y,value:x}=f(V,K);if(!y)throw new Error("bad point: invalid y coordinate");let A=(x&ae)===ae,v=(O&128)!==0;if(!b&&x===dt&&v)throw new Error("bad point: x=0 and x_0=1");return v!==A&&(x=u(-x)),h.fromAffine({x,y:R})}static fromHex(p,b=!1){return h.fromBytes(er(p),b)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=8,b=!0){return m.createCache(this,p),b||this.multiply(Ms),this}assertValidity(){let p=this,{a:b,d:E}=i;if(p.is0())throw new Error("bad point: ZERO");let{X:S,Y:C,Z:I,T:O}=p,R=u(S*S),_=u(C*C),P=u(I*I),V=u(P*P),K=u(R*b),y=u(P*u(K+_)),x=u(V+u(E*u(R*_)));if(y!==x)throw new Error("bad point: equation left != right (1)");let A=u(S*C),v=u(I*O);if(A!==v)throw new Error("bad point: equation left != right (2)")}equals(p){l(p);let{X:b,Y:E,Z:S}=this,{X:C,Y:I,Z:O}=p,R=u(b*O),_=u(C*S),P=u(E*O),V=u(I*S);return R===_&&P===V}is0(){return this.equals(h.ZERO)}negate(){return new h(u(-this.X),this.Y,this.Z,u(-this.T))}double(){let{a:p}=i,{X:b,Y:E,Z:S}=this,C=u(b*b),I=u(E*E),O=u(Ms*u(S*S)),R=u(p*C),_=b+E,P=u(u(_*_)-C-I),V=R+I,K=V-O,y=R-I,x=u(P*K),A=u(V*y),v=u(P*y),w=u(K*V);return new h(x,A,w,v)}add(p){l(p);let{a:b,d:E}=i,{X:S,Y:C,Z:I,T:O}=this,{X:R,Y:_,Z:P,T:V}=p,K=u(S*R),y=u(C*_),x=u(O*E*V),A=u(I*P),v=u((S+C)*(R+_)-K-y),w=A-x,T=A+x,D=u(y-b*K),B=u(v*w),L=u(T*D),k=u(v*D),N=u(w*T);return new h(B,L,N,k)}subtract(p){return l(p),this.add(p.negate())}multiply(p){if(!s.isValidNot0(p))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:b,f:E}=m.cached(this,p,S=>_t(h,S));return _t(h,[b,E])[0]}multiplyUnsafe(p){if(!s.isValid(p))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return p===dt?h.ZERO:this.is0()||p===ae?this:m.unsafe(this,p,b=>_t(h,b))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return m.unsafe(this,i.n).is0()}toAffine(p){let b=this,E=p,{X:S,Y:C,Z:I}=b,O=b.is0();E==null&&(E=O?uh:o.inv(I));let R=u(S*E),_=u(C*E),P=o.mul(I,E);if(O)return{x:dt,y:ae};if(P!==ae)throw new Error("invZ was invalid");return{x:R,y:_}}clearCofactor(){return a===ae?this:this.multiplyUnsafe(a)}toBytes(){let{x:p,y:b}=this.toAffine(),E=o.toBytes(b);return E[E.length-1]|=p&ae?128:0,E}toHex(){return Jt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let m=new sr(h,s.BITS);return s.BITS>=8&&h.BASE.precompute(8),Object.freeze(h.prototype),Object.freeze(h),h}var kn=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(e){this.ep=e}static fromBytes(e){Ls()}static fromHex(e){Ls()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(e){return this.ep.toAffine(e)}toHex(){return Jt(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(e){return this.assertSame(e),this.init(this.ep.add(e.ep))}subtract(e){return this.assertSame(e),this.init(this.ep.subtract(e.ep))}multiply(e){return this.init(this.ep.multiply(e))}multiplyUnsafe(e){return this.init(this.ep.multiplyUnsafe(e))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(e,r){return this.ep.precompute(e,r),this}};function Nc(t,e,r={}){if(typeof e!="function")throw new Error('"hash" function param is required');let n=e,o=r;Oe(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=t,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(Le(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let d=o.randomBytes===void 0?Lr:o.randomBytes,l=o.adjustScalarBytes===void 0?y=>y:o.adjustScalarBytes,h=o.domain===void 0?(y,x,A)=>{if(Re(A,"phflag"),x.length||A)throw new Error("Contexts/pre-hash are not supported");return y}:o.domain;function m(y){return c.create(ze(y))}function g(y){let x=R.secretKey;M(y,R.secretKey,"secretKey");let A=M(n(y),2*x,"hashedSecretKey"),v=l(A.slice(0,x)),w=A.slice(x,2*x),T=m(v);return{head:v,prefix:w,scalar:T}}function p(y){let{head:x,prefix:A,scalar:v}=g(y),w=i.multiply(v),T=w.toBytes();return{head:x,prefix:A,scalar:v,point:w,pointBytes:T}}function b(y){return p(y).pointBytes}function E(y=Uint8Array.of(),...x){let A=oe(...x);return m(n(h(A,M(y,void 0,"context"),!!s)))}function S(y,x,A={}){y=M(y,void 0,"message"),s&&(y=s(y));let{prefix:v,scalar:w,pointBytes:T}=p(x),D=E(A.context,v,y),B=i.multiply(D).toBytes(),L=E(A.context,B,T,y),k=c.create(D+L*w);if(!c.isValid(k))throw new Error("sign failed: invalid s");let N=oe(B,c.toBytes(k));return M(N,R.signature,"result")}let C={zip215:o.zip215};function I(y,x,A,v=C){let{context:w}=v,T=v.zip215===void 0?!!C.zip215:v.zip215,D=R.signature;y=M(y,D,"signature"),x=M(x,void 0,"message"),A=M(A,R.publicKey,"publicKey"),T!==void 0&&Re(T,"zip215"),s&&(x=s(x));let B=D/2,L=y.subarray(0,B),k=ze(y.subarray(B,D)),N,q,U;try{N=t.fromBytes(A,T),q=t.fromBytes(L,T),U=i.multiplyUnsafe(k)}catch{return!1}if(!T&&N.isSmallOrder())return!1;let ne=E(w,L,A,x);return q.add(N.multiplyUnsafe(ne)).subtract(U).clearCofactor().is0()}let O=a.BYTES,R={secretKey:O,publicKey:O,signature:2*O,seed:O};function _(y){return y=y===void 0?d(R.seed):y,M(y,R.seed,"seed")}function P(y){return vt(y)&&y.length===R.secretKey}function V(y,x){try{return!!t.fromBytes(y,x===void 0?C.zip215:x)}catch{return!1}}let K={getExtendedPublicKey:p,randomSecretKey:_,isValidSecretKey:P,isValidPublicKey:V,toMontgomery(y){let{y:x}=t.fromBytes(y),A=R.publicKey,v=A===32;if(!v&&A!==57)throw new Error("only defined for 25519 and 448");let w=v?a.div(ae+x,ae-x):a.div(x-ae,x+ae);return a.toBytes(w)},toMontgomerySecret(y){let x=R.secretKey;M(y,x);let A=n(y.subarray(0,x));return l(A).subarray(0,x)}};return Object.freeze(R),Object.freeze(K),Object.freeze({keygen:On(_,b),getPublicKey:b,sign:S,verify:I,utils:K,Point:t,lengths:R})}function Nr(t,e){if(Le(t),Le(e),e<0||e>4)throw new Error("invalid I2OSP length: "+e);if(t<0||t>2**(8*e)-1)throw new Error("invalid I2OSP input: "+t);let r=Array.from({length:e}).fill(0);for(let n=e-1;n>=0;n--)r[n]=t&255,t>>>=8;return new Uint8Array(r)}function lh(t,e){let r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t[n]^e[n];return r}function dh(t){if(!vt(t)&&typeof t!="string")throw new Error("DST must be Uint8Array or ascii string");let e=typeof t=="string"?Dn(t):t;if(e.length===0)throw new Error("DST must be non-empty");return e}function qs(t,e,r,n){M(t),Le(r),e=dh(e),e.length>255&&(e=n(oe(Dn("H2C-OVERSIZE-DST-"),e)));let{outputLen:o,blockLen:s}=n,i=Math.ceil(r/o);if(r>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=oe(e,Nr(e.length,1)),c=new Uint8Array(s),u=Nr(r,2),f=new Array(i),d=n(oe(c,t,u,Nr(0,1),a));f[0]=n(oe(d,Nr(1,1),a));for(let h=1;h<i;h++){let m=[lh(d,f[h-1]),Nr(h+1,1),a];f[h]=n(oe(...m))}return oe(...f).slice(0,r)}var Fc="HashToScalar-";var hh=BigInt(0),Je=BigInt(1),Mc=BigInt(2);var ph=BigInt(5),mh=BigInt(8),ir=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),$s={p:ir,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:mh,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function yh(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=ir,a=t*t%s*t%s,c=j(a,Mc,s)*a%s,u=j(c,Je,s)*t%s,f=j(u,ph,s)*u%s,d=j(f,e,s)*f%s,l=j(d,r,s)*d%s,h=j(l,n,s)*l%s,m=j(h,o,s)*h%s,g=j(m,o,s)*h%s,p=j(g,e,s)*f%s;return{pow_p_5_8:j(p,Mc,s)*t%s,b2:a}}function bh(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var zs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function js(t,e){let r=ir,n=ee(e*e*e,r),o=ee(n*n*e,r),s=yh(t*o).pow_p_5_8,i=ee(t*n*s,r),a=ee(e*i*i,r),c=i,u=ee(i*zs,r),f=a===t,d=a===ee(-t,r),l=a===ee(-t*zs,r);return f&&(i=c),(d||l)&&(i=u),Qe(i,r)&&(i=ee(-i,r)),{isValid:f||d,value:i}}var pt=Uc($s,{uvRatio:js}),ht=pt.Fp,Vc=pt.Fn;function gh(t){return Nc(pt,Tn,Object.assign({adjustScalarBytes:bh,zip215:!0},t))}var Hc=gh({});var Vs=zs,xh=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),wh=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Eh=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),vh=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),qc=t=>js(Je,t),Sh=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Hs=t=>ht.create(ze(t)&Sh);function zc(t){let{d:e}=$s,r=ir,n=b=>ht.create(b),o=n(Vs*t*t),s=n((o+Je)*Eh),i=BigInt(-1),a=n((i-e*o)*n(o+e)),{isValid:c,value:u}=js(s,a),f=n(u*t);Qe(f,r)||(f=n(-f)),c||(u=f),c||(i=o);let d=n(i*(o-Je)*vh-a),l=u*u,h=n((u+u)*a),m=n(d*xh),g=n(Je-l),p=n(Je+l);return new pt(n(h*p),n(g*m),n(m*p),n(h*g))}var mt=class t extends kn{static BASE=new t(pt.BASE);static ZERO=new t(pt.ZERO);static Fp=ht;static Fn=Vc;constructor(e){super(e)}static fromAffine(e){return new t(pt.fromAffine(e))}assertSame(e){if(!(e instanceof t))throw new Error("RistrettoPoint expected")}init(e){return new t(e)}static fromBytes(e){Ee(e,32);let{a:r,d:n}=$s,o=ir,s=C=>ht.create(C),i=Hs(e);if(!gc(ht.toBytes(i),e)||Qe(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(Je+r*a),u=s(Je-r*a),f=s(c*c),d=s(u*u),l=s(r*n*f-d),{isValid:h,value:m}=qc(s(l*d)),g=s(m*u),p=s(m*g*l),b=s((i+i)*g);Qe(b,o)&&(b=s(-b));let E=s(c*p),S=s(b*E);if(!h||Qe(S,o)||E===hh)throw new Error("invalid ristretto255 encoding 2");return new t(new pt(b,E,Je,S))}static fromHex(e){return t.fromBytes(Cr(e))}toBytes(){let{X:e,Y:r,Z:n,T:o}=this.ep,s=ir,i=p=>ht.create(p),a=i(i(n+r)*i(n-r)),c=i(e*r),u=i(c*c),{value:f}=qc(i(a*u)),d=i(f*a),l=i(f*c),h=i(d*l*o),m;if(Qe(o*h,s)){let p=i(r*Vs),b=i(e*Vs);e=p,r=b,m=i(d*wh)}else m=l;Qe(e*h,s)&&(r=i(-r));let g=i((n-r)*m);return Qe(g,s)&&(g=i(-g)),ht.toBytes(g)}equals(e){this.assertSame(e);let{X:r,Y:n}=this.ep,{X:o,Y:s}=e.ep,i=u=>ht.create(u),a=i(r*s)===i(n*o),c=i(n*s)===i(r*o);return a||c}is0(){return this.equals(t.ZERO)}};Object.freeze(mt.BASE);Object.freeze(mt.ZERO);Object.freeze(mt.prototype);Object.freeze(mt);var Ah=Object.freeze({Point:mt,hashToCurve(t,e){let r=e?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":e.DST,n=qs(t,r,64,Tn);return Ah.deriveToCurve(n)},hashToScalar(t,e={DST:Fc}){let r=qs(t,e.DST,64,Tn);return Vc.create(ze(r))},deriveToCurve(t){Ee(t,64);let e=Hs(t.subarray(0,32)),r=zc(e),n=Hs(t.subarray(32,64)),o=zc(n);return new mt(r.add(o))}});var Fr=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},Pn=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var Te={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new Pn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var Kn=32;var Ws,Th=(async()=>{try{return await Te.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function _h(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await Te.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await Te.get().subtle.verify({name:"Ed25519"},n,Fe(e),Fe(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Ih(t,e,r){return Hc.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function $c(t,e,r){return Ws==null&&(Ws=await Th),Ws?_h(t,e,r):Ih(t,e,r)}function Un(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Nn=class{type="Ed25519";raw;constructor(e){this.raw=Zs(e,Kn)}toMultihash(){return Ce.digest(Ae(this))}toCID(){return te.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:re(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let o=$c(this.raw,r,e);return Un(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Ys(t){return t=Zs(t,Kn),new Nn(t)}function Zs(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new F(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}function Wc(t=0){return new Uint8Array(t)}var Bh=Math.pow(2,7),Dh=Math.pow(2,14),Rh=Math.pow(2,21),Gs=Math.pow(2,28),Xs=Math.pow(2,35),Qs=Math.pow(2,42),Js=Math.pow(2,49),z=128,de=127;function _e(t){if(t<Bh)return 1;if(t<Dh)return 2;if(t<Rh)return 3;if(t<Gs)return 4;if(t<Xs)return 5;if(t<Qs)return 6;if(t<Js)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ar(t,e,r=0){switch(_e(t)){case 8:e[r++]=t&255|z,t/=128;case 7:e[r++]=t&255|z,t/=128;case 6:e[r++]=t&255|z,t/=128;case 5:e[r++]=t&255|z,t/=128;case 4:e[r++]=t&255|z,t>>>=7;case 3:e[r++]=t&255|z,t>>>=7;case 2:e[r++]=t&255|z,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Lh(t,e,r=0){switch(_e(t)){case 8:e.set(r++,t&255|z),t/=128;case 7:e.set(r++,t&255|z),t/=128;case 6:e.set(r++,t&255|z),t/=128;case 5:e.set(r++,t&255|z),t/=128;case 4:e.set(r++,t&255|z),t>>>=7;case 3:e.set(r++,t&255|z),t>>>=7;case 2:e.set(r++,t&255|z),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function ei(t,e){let r=t[e],n=0;if(n+=r&de,r<z||(r=t[e+1],n+=(r&de)<<7,r<z)||(r=t[e+2],n+=(r&de)<<14,r<z)||(r=t[e+3],n+=(r&de)<<21,r<z)||(r=t[e+4],n+=(r&de)*Gs,r<z)||(r=t[e+5],n+=(r&de)*Xs,r<z)||(r=t[e+6],n+=(r&de)*Qs,r<z)||(r=t[e+7],n+=(r&de)*Js,r<z))return n;throw new RangeError("Could not decode varint")}function Oh(t,e){let r=t.get(e),n=0;if(n+=r&de,r<z||(r=t.get(e+1),n+=(r&de)<<7,r<z)||(r=t.get(e+2),n+=(r&de)<<14,r<z)||(r=t.get(e+3),n+=(r&de)<<21,r<z)||(r=t.get(e+4),n+=(r&de)*Gs,r<z)||(r=t.get(e+5),n+=(r&de)*Xs,r<z)||(r=t.get(e+6),n+=(r&de)*Qs,r<z)||(r=t.get(e+7),n+=(r&de)*Js,r<z))return n;throw new RangeError("Could not decode varint")}function Fn(t,e,r=0){return e==null&&(e=Wc(_e(t))),e instanceof Uint8Array?ar(t,e,r):Lh(t,e,r)}function ti(t,e=0){return t instanceof Uint8Array?ei(t,e):Oh(t,e)}var ri=new Float32Array([-0]),yt=new Uint8Array(ri.buffer);function Yc(t,e,r){ri[0]=t,e[r]=yt[0],e[r+1]=yt[1],e[r+2]=yt[2],e[r+3]=yt[3]}function Gc(t,e){return yt[0]=t[e],yt[1]=t[e+1],yt[2]=t[e+2],yt[3]=t[e+3],ri[0]}var ni=new Float64Array([-0]),he=new Uint8Array(ni.buffer);function Xc(t,e,r){ni[0]=t,e[r]=he[0],e[r+1]=he[1],e[r+2]=he[2],e[r+3]=he[3],e[r+4]=he[4],e[r+5]=he[5],e[r+6]=he[6],e[r+7]=he[7]}function Qc(t,e){return he[0]=t[e],he[1]=t[e+1],he[2]=t[e+2],he[3]=t[e+3],he[4]=t[e+4],he[5]=t[e+5],he[6]=t[e+6],he[7]=t[e+7],ni[0]}var kh=BigInt(Number.MAX_SAFE_INTEGER),Ph=BigInt(Number.MIN_SAFE_INTEGER),ve=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return It;if(e<kh&&e>Ph)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,o=e-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Jc&&(o=0n,++n>Jc&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return It;let r=e<0;r&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new t(n,o)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):It}},It=new ve(0,0);It.toBigInt=function(){return 0n};It.zzEncode=It.zzDecode=function(){return this};It.length=function(){return 1};var Jc=4294967296n;function eu(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function tu(t,e,r){if(r-e<1)return"";let o,s=[],i=0,a;for(;e<r;)a=t[e++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function oi(t,e,r){let n=r,o,s;for(let i=0;i<t.length;++i)o=t.charCodeAt(i),o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&((s=t.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128);return r-n}function ke(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function Mn(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var si=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,ke(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw ke(this,4);return Mn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw ke(this,4);return Mn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw ke(this,4);let e=Gc(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw ke(this,4);let e=Qc(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw ke(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return tu(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw ke(this,e);this.pos+=e}else do if(this.pos>=this.len)throw ke(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new ve(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw ke(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw ke(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw ke(this,8);let e=Mn(this.buf,this.pos+=4),r=Mn(this.buf,this.pos+=4);return new ve(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=ei(this.buf,this.pos);return this.pos+=_e(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Mr(t){return new si(t instanceof Uint8Array?t:t.subarray())}function me(t,e,r){let n=Mr(t);return e.decode(n,void 0,r)}function Ct(t=0){return new Uint8Array(t)}var ii={};H(ii,{base10:()=>Kh});var Kh=ot({prefix:"9",name:"base10",alphabet:"0123456789"});var ai={};H(ai,{base16:()=>Uh,base16upper:()=>Nh});var Uh=Z({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Nh=Z({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ci={};H(ci,{base2:()=>Fh});var Fh=Z({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ui={};H(ui,{base256emoji:()=>Hh});var nu=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Mh=nu.reduce((t,e,r)=>(t[r]=e,t),[]),qh=nu.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function zh(t){return t.reduce((e,r)=>(e+=Mh[r],e),"")}function Vh(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=qh[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Hh=Ft({prefix:"\u{1F680}",name:"base256emoji",encode:zh,decode:Vh});var li={};H(li,{base64:()=>$h,base64pad:()=>jh,base64url:()=>fi,base64urlpad:()=>Wh});var $h=Z({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),jh=Z({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),fi=Z({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Wh=Z({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var di={};H(di,{base8:()=>Zh});var Zh=Z({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var hi={};H(hi,{identity:()=>Yh});var Yh=Ft({prefix:"\0",name:"identity",encode:t=>ma(t),decode:t=>pa(t)});var hg=new TextEncoder,pg=new TextDecoder;var yi={};H(yi,{sha256:()=>qr,sha512:()=>Jh});var Qh=20;function mi({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new pi(t,e,r,n,o)}var pi=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Qh,this.maxDigestLength=s}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?ou(n,this.code,r?.truncate):n.then(o=>ou(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function ou(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return Ne(e,t)}function iu(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var qr=mi({name:"sha2-256",code:18,encode:iu("SHA-256")}),Jh=mi({name:"sha2-512",code:19,encode:iu("SHA-512")});var Pe={...hi,...ci,...di,...ii,...ai,...No,...Fo,...Uo,...li,...ui},_g={...yi,...zo};function cu(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var au=cu("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),bi=cu("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Ct(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),ep={utf8:au,"utf-8":au,hex:Pe.base16,latin1:bi,ascii:bi,binary:bi,...Pe},uu=ep;function fu(t,e="utf8"){let r=uu[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function gi(t){let e=t??8192,r=e>>>1,n,o=e;return function(i){if(i<1||i>r)return Ct(i);o+i>e&&(n=Ct(e),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Bt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function xi(){}var Ei=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},tp=gi();function rp(t){return globalThis.Buffer!=null?Ct(t):tp(t)}var Vr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Bt(xi,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Bt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new vi((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(qn,10,ve.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=ve.fromBigInt(e);return this._push(qn,r.length(),r)}uint64Number(e){return this._push(ar,_e(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=ve.fromBigInt(e).zzEncode();return this._push(qn,r.length(),r)}sint64Number(e){let r=ve.fromNumber(e).zzEncode();return this._push(qn,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(wi,1,e?1:0)}fixed32(e){return this._push(zr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=ve.fromBigInt(e);return this._push(zr,4,r.lo)._push(zr,4,r.hi)}fixed64Number(e){let r=ve.fromNumber(e);return this._push(zr,4,r.lo)._push(zr,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(Yc,4,e)}double(e){return this._push(Xc,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(wi,1,0):this.uint32(r)._push(op,r,e)}string(e){let r=eu(e);return r!==0?this.uint32(r)._push(oi,r,e):this._push(wi,1,0)}fork(){return this.states=new Ei(this),this.head=this.tail=new Bt(xi,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Bt(xi,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=rp(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function wi(t,e,r){e[r]=t&255}function np(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var vi=class extends Bt{next;constructor(e,r){super(np,e,r),this.next=void 0}};function qn(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function zr(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function op(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(Vr.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(sp,e,t),this},Vr.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(ip,e,t),this});function sp(t,e,r){e.set(t,r)}function ip(t,e,r){t.length<40?oi(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(fu(t),r)}function Si(){return new Vr}function ye(t,e){let r=Si();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*be(t,e,r){let n=Mr(t);yield*e.stream(n,void 0,"$",r)}var zn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Vn(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function Ai(t){function e(s){if(t[s.toString()]==null)throw new Error("Invalid enum value");return t[s]}let r=function(i,a){let c=e(i);a.int32(c)},n=function(i){let a=i.int32();return e(a)},o=function*(i){let a=i.int32();yield e(a)};return Vn("enum",zn.VARINT,r,n,o)}function ge(t,e,r){return Vn("message",zn.LENGTH_DELIMITED,t,e,r)}var Ie=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},Hr=class extends Error{code="ERR_MAX_SIZE";name="MaxSizeError"};var W;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(W||(W={}));var Ti;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(Ti||(Ti={}));(function(t){t.codec=()=>Ai(Ti)})(W||(W={}));var Ve;(function(t){let e;t.codec=()=>(e==null&&(e=ge((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),W.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=W.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:W.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ye(s,t.codec())}t.encode=r;function n(s,i){return me(s,t.codec(),i)}t.decode=n;function o(s,i){return be(s,t.codec(),i)}t.stream=o})(Ve||(Ve={}));var _i;(function(t){let e;t.codec=()=>(e==null&&(e=ge((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),W.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=W.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:W.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ye(s,t.codec())}t.encode=r;function n(s,i){return me(s,t.codec(),i)}t.decode=n;function o(s,i){return be(s,t.codec(),i)}t.stream=o})(_i||(_i={}));var jr={};H(jr,{MAX_RSA_KEY_SIZE:()=>Ii,generateRSAKeyPair:()=>mu,jwkToJWKKeyPair:()=>yu,jwkToPkcs1:()=>fp,jwkToPkix:()=>Ri,jwkToRSAPrivateKey:()=>Pi,pkcs1MessageToJwk:()=>Bi,pkcs1MessageToRSAPrivateKey:()=>Li,pkcs1ToJwk:()=>up,pkcs1ToRSAPrivateKey:()=>pu,pkixMessageToJwk:()=>Di,pkixMessageToRSAPublicKey:()=>ki,pkixToJwk:()=>lp,pkixToRSAPublicKey:()=>Oi});var cr=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=jr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return te.createV1(114,this._multihash)}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:re(this.raw,e.raw)}verify(e,r,n){return hu(this.jwk,r,e,n)}},$r=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=jr.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:re(this.raw,e.raw)}sign(e,r){return du(this.jwk,e,r)}};var Ii=8192,Ci=18,ap=1062,cp=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function up(t){let e=Ze(t);return Bi(e)}function Bi(t){return{n:$(t[1],"base64url"),e:$(t[2],"base64url"),d:$(t[3],"base64url"),p:$(t[4],"base64url"),q:$(t[5],"base64url"),dp:$(t[6],"base64url"),dq:$(t[7],"base64url"),qi:$(t[8],"base64url"),kty:"RSA"}}function fp(t){if(t.n==null||t.e==null||t.d==null||t.p==null||t.q==null||t.dp==null||t.dq==null||t.qi==null)throw new F("JWK was missing components");return at([we(Uint8Array.from([0])),we(J(t.n,"base64url")),we(J(t.e,"base64url")),we(J(t.d,"base64url")),we(J(t.p,"base64url")),we(J(t.q,"base64url")),we(J(t.dp,"base64url")),we(J(t.dq,"base64url")),we(J(t.qi,"base64url"))]).subarray()}function lp(t){let e=Ze(t,{offset:0});return Di(e)}function Di(t){let e=Ze(t[1],{offset:0});return{kty:"RSA",n:$(e[0],"base64url"),e:$(e[1],"base64url")}}function Ri(t){if(t.n==null||t.e==null)throw new F("JWK was missing components");return at([cp,xn(at([we(J(t.n,"base64url")),we(J(t.e,"base64url"))]))]).subarray()}function pu(t){let e=Ze(t);return Li(e)}function Li(t){let e=Bi(t);return Pi(e)}function Oi(t,e){if(t.byteLength>=ap)throw new Kt("Key size is too large");let r=Ze(t,{offset:0});return ki(r,t,e)}function ki(t,e,r){let n=Di(t);if(r==null){let o=Qt(Ve.encode({Type:W.RSA,Data:e}));r=Ne(Ci,o)}return new cr(n,r)}function Pi(t){if(gu(t)>Ii)throw new F("Key size is too large");let e=yu(t),r=Qt(Ve.encode({Type:W.RSA,Data:Ri(e.publicKey)})),n=Ne(Ci,r);return new $r(e.privateKey,new cr(e.publicKey,n))}async function mu(t){if(t>Ii)throw new F("Key size is too large");let e=await bu(t),r=Qt(Ve.encode({Type:W.RSA,Data:Ri(e.publicKey)})),n=Ne(Ci,r);return new $r(e.privateKey,new cr(e.publicKey,n))}function yu(t){if(t==null)throw new F("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function bu(t,e){let r=await Te.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:t,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await dp(r,e);return{privateKey:n[0],publicKey:n[1]}}async function du(t,e,r){let n=await Te.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Te.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,Fe(e instanceof Uint8Array?e:e.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function hu(t,e,r,n){let o=await Te.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Te.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,Fe(e),Fe(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),s}async function dp(t,e){if(t.privateKey==null||t.publicKey==null)throw new F("Private and public key are required");let r=await Promise.all([Te.get().subtle.exportKey("jwk",t.privateKey),Te.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function gu(t){if(t.kty!=="RSA")throw new F("invalid key type");if(t.n==null)throw new F("invalid key modulus");return J(t.n,"base64url").length*8}var Hn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(wn(e),Ee(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Ge(o)}update(e){return Xt(this),this.iHash.update(e),this}digestInto(e){Xt(this),En(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},xu=(()=>{let t=((e,r,n)=>new Hn(e,r).update(n).digest());return t.create=(e,r)=>new Hn(e,r),t})();var wu=(t,e)=>(t+(t>=0?e:-e)/Eu)/e;function hp(t,e,r){tr("scalar",t,He,r);let[[n,o],[s,i]]=e,a=wu(i*t,r),c=wu(-o*t,r),u=t-a*n-c*s,f=-a*o-c*i,d=u<He,l=f<He;d&&(u=-u),l&&(f=-f);let h=Pr(Math.ceil(rr(r)/2))+bt;if(u<He||u>=h||f<He||f>=h)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:d,k1:u,k2neg:l,k2:f}}function Ui(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Ki(t,e){Oe(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Re(r.lowS,"lowS"),Re(r.prehash,"prehash"),r.format!==void 0&&Ui(r.format),r}var Ni=class extends Error{constructor(e=""){super(e)}},Ke={Err:Ni,_tlv:{encode:(t,e)=>{let{Err:r}=Ke;if(Le(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(typeof e!="string")throw new TypeError('"data" expected string, got type='+typeof e);if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=Or(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Or(o.length/2|128):"";return Or(t)+s+o+e},decode(t,e){let{Err:r}=Ke;e=M(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=Ke;if(Cn(t),t<He)throw new e("integer: negative integers are not allowed");let r=Or(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=Ke;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return St(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=Ke,o=M(t,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:u,l:f}=n.decode(2,c);if(f.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(t){let{_tlv:e,_int:r}=Ke,n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),s=n+o;return e.encode(48,s)}};Object.freeze(Ke._tlv);Object.freeze(Ke._int);Object.freeze(Ke);var He=BigInt(0),bt=BigInt(1),Eu=BigInt(2),$n=BigInt(3),pp=BigInt(4);function vu(t,e={}){let r=Ln("weierstrass",t,e),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;Oe(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c,allowInfinityPoint:u}=e;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=Au(n,o);function d(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(K,y,x){if(u&&y.is0())return Uint8Array.of(0);let{x:A,y:v}=y.toAffine(),w=n.toBytes(A);if(Re(x,"isCompressed"),x){d();let T=!n.isOdd(v);return oe(Su(T),w)}else return oe(Uint8Array.of(4),w,n.toBytes(v))}function h(K){M(K,void 0,"Point");let{publicKey:y,publicKeyUncompressed:x}=f,A=K.length,v=K[0],w=K.subarray(1);if(u&&A===1&&v===0)return{x:n.ZERO,y:n.ZERO};if(A===y&&(v===2||v===3)){let T=n.fromBytes(w);if(!n.isValid(T))throw new Error("bad point: is not on curve, wrong x");let D=p(T),B;try{B=n.sqrt(D)}catch(N){let q=N instanceof Error?": "+N.message:"";throw new Error("bad point: is not on curve, sqrt error"+q)}d();let L=n.isOdd(B);return(v&1)===1!==L&&(B=n.neg(B)),{x:T,y:B}}else if(A===x&&v===4){let T=n.BYTES,D=n.fromBytes(w.subarray(0,T)),B=n.fromBytes(w.subarray(T,T*2));if(!b(D,B))throw new Error("bad point: is not on curve");return{x:D,y:B}}else throw new Error(`bad point: got length ${A}, expected compressed=${y} or uncompressed=${x}`)}let m=e.toBytes===void 0?l:e.toBytes,g=e.fromBytes===void 0?h:e.fromBytes;function p(K){let y=n.sqr(K),x=n.mul(y,K);return n.add(n.add(x,n.mul(K,s.a)),s.b)}function b(K,y){let x=n.sqr(y),A=p(K);return n.eql(x,A)}if(!b(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let E=n.mul(n.pow(s.a,$n),pp),S=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(E,S)))throw new Error("bad curve params: a or b");function C(K,y,x=!1){if(!n.isValid(y)||x&&n.is0(y))throw new Error(`bad point coordinate ${K}`);return y}function I(K){if(!(K instanceof _))throw new Error("Weierstrass Point expected")}function O(K){if(!c||!c.basises)throw new Error("no endo");return hp(K,c.basises,o.ORDER)}function R(K,y,x,A,v){return x=new _(n.mul(x.X,K),x.Y,x.Z),y=Ur(A,y),x=Ur(v,x),y.add(x)}class _{static BASE=new _(s.Gx,s.Gy,n.ONE);static ZERO=new _(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(y,x,A){this.X=C("x",y),this.Y=C("y",x,!0),this.Z=C("z",A),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){let{x,y:A}=y||{};if(!y||!n.isValid(x)||!n.isValid(A))throw new Error("invalid affine point");if(y instanceof _)throw new Error("projective point not allowed");return n.is0(x)&&n.is0(A)?_.ZERO:new _(x,A,n.ONE)}static fromBytes(y){let x=_.fromAffine(g(M(y,void 0,"point")));return x.assertValidity(),x}static fromHex(y){return _.fromBytes(er(y))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,x=!0){return V.createCache(this,y),x||this.multiply($n),this}assertValidity(){let y=this;if(y.is0()){if(e.allowInfinityPoint&&n.is0(y.X)&&n.eql(y.Y,n.ONE)&&n.is0(y.Z))return;throw new Error("bad point: ZERO")}let{x,y:A}=y.toAffine();if(!n.isValid(x)||!n.isValid(A))throw new Error("bad point: x or y not field elements");if(!b(x,A))throw new Error("bad point: equation left != right");if(!y.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(y)}equals(y){I(y);let{X:x,Y:A,Z:v}=this,{X:w,Y:T,Z:D}=y,B=n.eql(n.mul(x,D),n.mul(w,v)),L=n.eql(n.mul(A,D),n.mul(T,v));return B&&L}negate(){return new _(this.X,n.neg(this.Y),this.Z)}double(){let{a:y,b:x}=s,A=n.mul(x,$n),{X:v,Y:w,Z:T}=this,D=n.ZERO,B=n.ZERO,L=n.ZERO,k=n.mul(v,v),N=n.mul(w,w),q=n.mul(T,T),U=n.mul(v,w);return U=n.add(U,U),L=n.mul(v,T),L=n.add(L,L),D=n.mul(y,L),B=n.mul(A,q),B=n.add(D,B),D=n.sub(N,B),B=n.add(N,B),B=n.mul(D,B),D=n.mul(U,D),L=n.mul(A,L),q=n.mul(y,q),U=n.sub(k,q),U=n.mul(y,U),U=n.add(U,L),L=n.add(k,k),k=n.add(L,k),k=n.add(k,q),k=n.mul(k,U),B=n.add(B,k),q=n.mul(w,T),q=n.add(q,q),k=n.mul(q,U),D=n.sub(D,k),L=n.mul(q,N),L=n.add(L,L),L=n.add(L,L),new _(D,B,L)}add(y){I(y);let{X:x,Y:A,Z:v}=this,{X:w,Y:T,Z:D}=y,B=n.ZERO,L=n.ZERO,k=n.ZERO,N=s.a,q=n.mul(s.b,$n),U=n.mul(x,w),ne=n.mul(A,T),se=n.mul(v,D),ie=n.add(x,A),Q=n.add(w,T);ie=n.mul(ie,Q),Q=n.add(U,ne),ie=n.sub(ie,Q),Q=n.add(x,v);let xe=n.add(w,D);return Q=n.mul(Q,xe),xe=n.add(U,se),Q=n.sub(Q,xe),xe=n.add(A,v),B=n.add(T,D),xe=n.mul(xe,B),B=n.add(ne,se),xe=n.sub(xe,B),k=n.mul(N,Q),B=n.mul(q,se),k=n.add(B,k),B=n.sub(ne,k),k=n.add(ne,k),L=n.mul(B,k),ne=n.add(U,U),ne=n.add(ne,U),se=n.mul(N,se),Q=n.mul(q,Q),ne=n.add(ne,se),se=n.sub(U,se),se=n.mul(N,se),Q=n.add(Q,se),U=n.mul(ne,Q),L=n.add(L,U),U=n.mul(xe,Q),B=n.mul(ie,B),B=n.sub(B,U),U=n.mul(ie,ne),k=n.mul(xe,k),k=n.add(k,U),new _(B,L,k)}subtract(y){return I(y),this.add(y.negate())}is0(){return this.equals(_.ZERO)}multiply(y){let{endo:x}=e;if(!o.isValidNot0(y))throw new RangeError("invalid scalar: out of range");let A,v,w=T=>V.cached(this,T,D=>_t(_,D));if(x){let{k1neg:T,k1:D,k2neg:B,k2:L}=O(y),{p:k,f:N}=w(D),{p:q,f:U}=w(L);v=N.add(U),A=R(x.beta,k,q,T,B)}else{let{p:T,f:D}=w(y);A=T,v=D}return _t(_,[A,v])[0]}multiplyUnsafe(y){let{endo:x}=e,A=this,v=y;if(!o.isValid(v))throw new RangeError("invalid scalar: out of range");if(v===He||A.is0())return _.ZERO;if(v===bt)return A;if(V.hasCache(this))return this.multiply(v);if(x){let{k1neg:w,k1:T,k2neg:D,k2:B}=O(v),{p1:L,p2:k}=Kc(_,A,T,B);return R(x.beta,L,k,w,D)}else return V.unsafe(A,v)}toAffine(y){let x=this,A=y,{X:v,Y:w,Z:T}=x;if(n.eql(T,n.ONE))return{x:v,y:w};let D=x.is0();A==null&&(A=D?n.ONE:n.inv(T));let B=n.mul(v,A),L=n.mul(w,A),k=n.mul(T,A);if(D)return{x:n.ZERO,y:n.ZERO};if(!n.eql(k,n.ONE))throw new Error("invZ was invalid");return{x:B,y:L}}isTorsionFree(){let{isTorsionFree:y}=e;return i===bt?!0:y?y(_,this):V.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:y}=e;return i===bt?this:y?y(_,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===bt?this.is0():this.clearCofactor().is0()}toBytes(y=!0){return Re(y,"isCompressed"),this.assertValidity(),m(_,this,y)}toHex(y=!0){return Jt(this.toBytes(y))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let P=o.BITS,V=new sr(_,e.endo?Math.ceil(P/2):P);return P>=8&&_.BASE.precompute(8),Object.freeze(_.prototype),Object.freeze(_),_}function Su(t){return Uint8Array.of(t?2:3)}function Au(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function mp(t,e={}){let{Fn:r}=t,n=e.randomBytes===void 0?Lr:e.randomBytes,o=Object.assign(Au(t.Fp,r),{seed:Math.max(Ps(r.ORDER),16)});function s(h){try{let m=r.fromBytes(h);return r.isValidNot0(m)}catch{return!1}}function i(h,m){let{publicKey:g,publicKeyUncompressed:p}=o;try{let b=h.length;return m===!0&&b!==g||m===!1&&b!==p?!1:!!t.fromBytes(h)}catch{return!1}}function a(h){return h=h===void 0?n(o.seed):h,Ks(M(h,o.seed,"seed"),r.ORDER)}function c(h,m=!0){return t.BASE.multiply(r.fromBytes(h)).toBytes(m)}function u(h){let{secretKey:m,publicKey:g,publicKeyUncompressed:p}=o,b=r._lengths;if(!vt(h))return;let E=M(h,void 0,"key").length,S=E===g||E===p,C=E===m||!!b?.includes(E);if(!(S&&C))return S}function f(h,m,g=!0){if(u(h)===!0)throw new Error("first arg must be private key");if(u(m)===!1)throw new Error("second arg must be public key");let p=r.fromBytes(h);return t.fromBytes(m).multiply(p).toBytes(g)}let d={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},l=On(a,c);return Object.freeze(d),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:l,Point:t,utils:d,lengths:o})}function Tu(t,e,r={}){let n=e;wn(n),Oe(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?Lr:r.randomBytes,s=r.hmac===void 0?(v,w)=>xu(n,v,w):r.hmac,{Fp:i,Fn:a}=t,{ORDER:c,BITS:u}=a,{keygen:f,getPublicKey:d,getSharedSecret:l,utils:h,lengths:m}=mp(t,r),g={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},p=c*Eu+bt<i.ORDER;function b(v){let w=c>>bt;return v>w}function E(v,w){if(!a.isValidNot0(w))throw new Error(`invalid signature ${v}: out of range 1..Point.Fn.ORDER`);return w}function S(){if(p)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function C(v,w){Ui(w);let T=m.signature,D=w==="compact"?T:w==="recovered"?T+1:void 0;return M(v,D)}class I{r;s;recovery;constructor(w,T,D){if(this.r=E("r",w),this.s=E("s",T),D!=null){if(S(),![0,1,2,3].includes(D))throw new Error("invalid recovery id");this.recovery=D}Object.freeze(this)}static fromBytes(w,T=g.format){C(w,T);let D;if(T==="der"){let{r:N,s:q}=Ke.toSig(M(w));return new I(N,q)}T==="recovered"&&(D=w[0],T="compact",w=w.subarray(1));let B=m.signature/2,L=w.subarray(0,B),k=w.subarray(B,B*2);return new I(a.fromBytes(L),a.fromBytes(k),D)}static fromHex(w,T){return this.fromBytes(er(w),T)}assertRecovery(){let{recovery:w}=this;if(w==null)throw new Error("invalid recovery id: must be present");return w}addRecoveryBit(w){return new I(this.r,this.s,w)}recoverPublicKey(w){let{r:T,s:D}=this,B=this.assertRecovery(),L=B===2||B===3?T+c:T;if(!i.isValid(L))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let k=i.toBytes(L),N=t.fromBytes(oe(Su((B&1)===0),k)),q=a.inv(L),U=R(M(w,void 0,"msgHash")),ne=a.create(-U*q),se=a.create(D*q),ie=t.BASE.multiplyUnsafe(ne).add(N.multiplyUnsafe(se));if(ie.is0())throw new Error("invalid recovery: point at infinify");return ie.assertValidity(),ie}hasHighS(){return b(this.s)}toBytes(w=g.format){if(Ui(w),w==="der")return er(Ke.hexFromSig(this));let{r:T,s:D}=this,B=a.toBytes(T),L=a.toBytes(D);return w==="recovered"?(S(),oe(Uint8Array.of(this.assertRecovery()),B,L)):oe(B,L)}toHex(w){return Jt(this.toBytes(w))}}Object.freeze(I.prototype),Object.freeze(I);let O=r.bits2int===void 0?function(w){if(w.length>8192)throw new Error("input is too large");let T=St(w),D=w.length*8-u;return D>0?T>>BigInt(D):T}:r.bits2int,R=r.bits2int_modN===void 0?function(w){return a.create(O(w))}:r.bits2int_modN,_=Pr(u);function P(v){return tr("num < 2^"+u,v,He,_),a.toBytes(v)}function V(v,w){return M(v,void 0,"message"),w?M(n(v),void 0,"prehashed message"):v}function K(v,w,T){let{lowS:D,prehash:B,extraEntropy:L}=Ki(T,g);v=V(v,B);let k=R(v),N=a.fromBytes(w);if(!a.isValidNot0(N))throw new Error("invalid private key");let q=[P(N),P(k)];if(L!=null&&L!==!1){let ie=L===!0?o(m.secretKey):L;q.push(M(ie,void 0,"extraEntropy"))}let U=oe(...q),ne=k;function se(ie){let Q=O(ie);if(!a.isValidNot0(Q))return;let xe=a.inv(Q),Pt=t.BASE.multiply(Q).toAffine(),pr=a.create(Pt.x);if(pr===He)return;let fn=a.create(xe*a.create(ne+pr*N));if(fn===He)return;let la=(Pt.x===pr?0:2)|Number(Pt.y&bt),da=fn;return D&&b(fn)&&(da=a.neg(fn),la^=1),new I(pr,da,p?void 0:la)}return{seed:U,k2sig:se}}function y(v,w,T={}){let{seed:D,k2sig:B}=K(v,w,T);return xc(n.outputLen,a.BYTES,s)(D,B).toBytes(T.format)}function x(v,w,T,D={}){let{lowS:B,prehash:L,format:k}=Ki(D,g);if(T=M(T,void 0,"publicKey"),w=V(w,L),!vt(v)){let N=v instanceof I?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+N)}C(v,k);try{let N=I.fromBytes(v,k),q=t.fromBytes(T);if(B&&N.hasHighS())return!1;let{r:U,s:ne}=N,se=R(w),ie=a.inv(ne),Q=a.create(se*ie),xe=a.create(U*ie),Pt=t.BASE.multiplyUnsafe(Q).add(q.multiplyUnsafe(xe));return Pt.is0()?!1:a.create(Pt.x)===U}catch{return!1}}function A(v,w,T={}){let{prehash:D}=Ki(T,g);return w=V(w,D),I.fromBytes(v,"recovered").recoverPublicKey(w).toBytes()}return Object.freeze({keygen:f,getPublicKey:d,getSharedSecret:l,utils:h,lengths:m,Point:t,sign:y,verify:x,recoverPublicKey:A,Signature:I,hash:n})}var Mi={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},yp={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var _u=BigInt(2);function bp(t){let e=Mi.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=t*t*t%e,f=u*u*t%e,d=j(f,r,e)*f%e,l=j(d,r,e)*f%e,h=j(l,_u,e)*u%e,m=j(h,o,e)*h%e,g=j(m,s,e)*m%e,p=j(g,a,e)*g%e,b=j(p,c,e)*p%e,E=j(b,a,e)*g%e,S=j(E,r,e)*f%e,C=j(S,i,e)*m%e,I=j(C,n,e)*u%e,O=j(I,_u,e);if(!Fi.eql(Fi.sqr(O),t))throw new Error("Cannot find square root");return O}var Fi=nr(Mi.p,{sqrt:bp}),gp=vu(Mi,{Fp:Fi,endo:yp}),ur=Tu(gp,Qt);function Iu(t,e,r,n){let o=qr.digest(r instanceof Uint8Array?r:r.subarray());if(Un(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),ur.verify(e,s,t,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Fr(String(s))});try{return n?.signal?.throwIfAborted(),ur.verify(e,o.digest,t,{prehash:!1,format:"der"})}catch(s){throw new Fr(String(s))}}var jn=class{type="secp256k1";raw;_key;constructor(e){this._key=Bu(e),this.raw=Cu(this._key)}toMultihash(){return Ce.digest(Ae(this))}toCID(){return te.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:re(this.raw,e.raw)}verify(e,r,n){return Iu(this._key,r,e,n)}};function qi(t){return new jn(t)}function Cu(t){return ur.Point.fromBytes(t).toBytes()}function Bu(t){try{return ur.Point.fromBytes(t),t}catch(e){throw new Kt(String(e))}}function Wn(t,e){let{Type:r,Data:n}=Ve.decode(t),o=n??new Uint8Array;switch(r){case W.RSA:return Oi(o,e);case W.Ed25519:return Ys(o);case W.secp256k1:return qi(o);case W.ECDSA:return gs(o);default:throw new gt}}function Du(t){let{Type:e,Data:r}=Ve.decode(t.digest),n=r??new Uint8Array;switch(e){case W.Ed25519:return Ys(n);case W.secp256k1:return qi(n);case W.ECDSA:return gs(n);default:throw new gt}}function Ae(t){return Ve.encode({Type:W[t.type],Data:t.raw})}var Ru=Symbol.for("nodejs.util.inspect.custom"),xp=114,Wr=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[hn]=!0;toString(){return this.string==null&&(this.string=Y.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return te.createV1(xp,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return re(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return re(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[Ru](){return`PeerId(${this.toString()})`}},Zr=class extends Wr{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Yr=class extends Wr{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Gr=class extends Wr{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},wp=2336,Xr=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Ce.digest(J(this.url))}[Ru](){return`PeerId(${this.url})`}[hn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return te.createV1(wp,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=$(e)),e.toString()===this.toString())}};var Ep=114,Lu=2336;function Ou(t){if(t.type==="Ed25519")return new Yr({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new Gr({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new Zr({multihash:t.toCID().multihash,publicKey:t});throw new gt}function zi(t){if(Sp(t))return new Zr({multihash:t});if(vp(t))try{let e=Du(t);if(e.type==="Ed25519")return new Yr({multihash:t,publicKey:e});if(e.type==="secp256k1")return new Gr({multihash:t,publicKey:e})}catch{let r=$(t.digest);return new Xr(new URL(r))}throw new dn("Supplied PeerID Multihash is invalid")}function Zn(t){if(t?.multihash==null||t.version==null||t.version===1&&t.code!==Ep&&t.code!==Lu)throw new ln("Supplied PeerID CID is invalid");if(t.code===Lu){let e=$(t.multihash.digest);return new Xr(new URL(e))}return zi(t.multihash)}function vp(t){return t.code===Ce.code}function Sp(t){return t.code===qr.code}var Qr;(function(t){let e;t.codec=()=>(e==null&&(e=ge((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.publicKey!=null&&s.publicKey.byteLength>0&&(i.uint32(10),i.bytes(s.publicKey)),s.payloadType!=null&&s.payloadType.byteLength>0&&(i.uint32(18),i.bytes(s.payloadType)),s.payload!=null&&s.payload.byteLength>0&&(i.uint32(26),i.bytes(s.payload)),s.signature!=null&&s.signature.byteLength>0&&(i.uint32(42),i.bytes(s.signature)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={publicKey:Be(0),payloadType:Be(0),payload:Be(0),signature:Be(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.publicKey=s.bytes();break}case 2:{c.payloadType=s.bytes();break}case 3:{c.payload=s.bytes();break}case 5:{c.signature=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.publicKey`,value:s.bytes()};break}case 2:{yield{field:`${a}.payloadType`,value:s.bytes()};break}case 3:{yield{field:`${a}.payload`,value:s.bytes()};break}case 5:{yield{field:`${a}.signature`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ye(s,t.codec())}t.encode=r;function n(s,i){return me(s,t.codec(),i)}t.decode=n;function o(s,i){return be(s,t.codec(),i)}t.stream=o})(Qr||(Qr={}));var Yn=class extends Error{constructor(e="Invalid signature"){super(e),this.name="InvalidSignatureError"}};var fr=class t{static createFromProtobuf=e=>{let r=Qr.decode(e),n=Wn(r.publicKey);return new t({publicKey:n,payloadType:r.payloadType,payload:r.payload,signature:r.signature})};static seal=async(e,r,n)=>{if(r==null)throw new Error("Missing private key");let o=e.domain,s=e.codec,i=e.marshal(),a=ku(o,s,i),c=await r.sign(a.subarray(),n);return new t({publicKey:r.publicKey,payloadType:s,payload:i,signature:c})};static openAndCertify=async(e,r,n)=>{let o=t.createFromProtobuf(e);if(!await o.validate(r,n))throw new Yn("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(e){let{publicKey:r,payloadType:n,payload:o,signature:s}=e;this.publicKey=r,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=Qr.encode({publicKey:Ae(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(e){return e==null?!1:re(this.marshal(),e.marshal())}async validate(e,r){let n=ku(e,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},ku=(t,e,r)=>{let n=J(t),o=Fn(n.byteLength),s=Fn(e.length),i=Fn(r.length);return new pe(o,n,s,e,i,r)};function Pu(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Gn(t=0){return new Uint8Array(t)}function Jr(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=Gn(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}function Uu(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Ku=Uu("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Vi=Uu("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Gn(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Ap={utf8:Ku,"utf-8":Ku,hex:Pe.base16,latin1:Vi,ascii:Vi,binary:Vi,...Pe},Xn=Ap;function en(t,e="utf8"){let r=Xn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Dt(t,e="utf8"){let r=Xn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var le=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},et=class extends Error{static name="ValidationError";name="ValidationError"},Qn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Jn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var eo=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let r=this.index,n=e();return n===void 0&&(this.index=r),n}parseWith(e){let r=e();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let r=this.readChar();if(r===e)return r})}readSeparator(e,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let d=this.readChar();if(d===void 0)return;let l=Number.parseInt(d,e);if(!Number.isNaN(l))return l});if(f===void 0)break;if(s*=e,s+=f,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let r=0;r<e.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[r]=n}return e})}readIPv6Addr(){let e=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=e(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Tp=45,_p=15,to=new eo;function Nu(t){if(!(t.length>_p))return to.new(t).parseWith(()=>to.readIPv4Addr())}function Fu(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>Tp))return to.new(t).parseWith(()=>to.readIPv6Addr())}function ro(t){return!!Nu(t)}function Mu(t){return!!Fu(t)}function $i(t){return e=>Dt(e,t)}function ji(t){return e=>en(e,t)}function lr(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Rt(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function qu(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let r=en(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Rt(n);return Jr([r,o],r.length+o.length)}function zu(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=Ue.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Rt(n);return Jr([r,o],r.length+o.length)}function Wi(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=Dt(e,"base32"),o=lr(r);return`${n}:${o}`}var Zi=function(t){t=t.toString().trim();let e=new Uint8Array(4);return t.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new le("Invalid byte value in IP address");e[n]=o}),e},Vu=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let s=ro(r[n]),i;s&&(i=Zi(r[n]),r[n]=Dt(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,Dt(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(e+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new le("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},Hu=function(t){if(t.byteLength!==4)throw new le("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},$u=function(t){if(t.byteLength!==16)throw new le("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let o=t[n],s=t[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let r=e.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new le(`Invalid IPv6 address "${r}"`)}};function ju(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new le(`Invalid IPv6 address "${t}"`)}}var Hi=Object.values(Pe).map(t=>t.decoder),Ip=(function(){let t=Hi[0].or(Hi[1]);return Hi.slice(2).forEach(e=>t=t.or(e)),t})();function Wu(t){return Ip.decode(t)}function Zu(t){return e=>t.encoder.encode(e)}function Cp(t){if(parseInt(t).toString()!==t)throw new et("Value must be an integer")}function Bp(t){if(t<0)throw new et("Value must be a positive integer, or zero")}function Dp(t){return e=>{if(e>t)throw new et(`Value must be smaller than or equal to ${t}`)}}function Rp(...t){return e=>{for(let r of t)r(e)}}var tn=Rp(Cp,Bp,Dp(65535));var ce=-1,Yi=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let r;if(typeof e=="string"?r=this.protocolsByName.get(e):r=this.protocolsByCode.get(e),r==null)throw new Jn(`Protocol ${e} was unknown`);return r}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(r=>{this.protocolsByName.set(r,e)})}removeProtocol(e){let r=this.protocolsByCode.get(e);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},tt=new Yi,bm=[{code:4,name:"ip4",size:32,valueToBytes:Zi,bytesToValue:Hu,validate:t=>{if(!ro(t))throw new et(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Rt,bytesToValue:lr,validate:tn},{code:273,name:"udp",size:16,valueToBytes:Rt,bytesToValue:lr,validate:tn},{code:33,name:"dccp",size:16,valueToBytes:Rt,bytesToValue:lr,validate:tn},{code:41,name:"ip6",size:128,valueToBytes:Vu,bytesToValue:$u,stringToValue:ju,validate:t=>{if(!Mu(t))throw new et(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:ce},{code:43,name:"ipcidr",size:8,bytesToValue:$i("base10"),valueToBytes:ji("base10")},{code:53,name:"dns",size:ce},{code:54,name:"dns4",size:ce},{code:55,name:"dns6",size:ce},{code:56,name:"dnsaddr",size:ce},{code:132,name:"sctp",size:16,valueToBytes:Rt,bytesToValue:lr,validate:tn},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ce,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:ce,bytesToValue:$i("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?ji("base58btc")(t):te.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Wi,valueToBytes:qu},{code:445,name:"onion3",size:296,bytesToValue:Wi,valueToBytes:zu},{code:446,name:"garlic64",size:ce},{code:447,name:"garlic32",size:ce},{code:448,name:"tls"},{code:449,name:"sni",size:ce},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ce,bytesToValue:Zu(fi),valueToBytes:Wu},{code:480,name:"http"},{code:481,name:"http-path",size:ce,stringToValue:t=>`/${decodeURIComponent(t)}`,valueToString:t=>encodeURIComponent(t.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:ce}];bm.forEach(t=>{tt.addProtocol(t)});function Yu(t){let e=[],r=0;for(;r<t.length;){let n=ti(t,r),o=tt.getProtocol(n),s=_e(n),i=gm(o,t,r+s),a=0;i>0&&o.size===ce&&(a=_e(i));let c=s+a+i,u={code:n,name:o.name,bytes:t.subarray(r,r+c)};if(i>0){let f=r+s+a,d=t.subarray(f,f+i);u.value=o.bytesToValue?.(d)??Dt(d)}e.push(u),r+=c}return e}function Gu(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=tt.getProtocol(n.code),s=_e(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??en(n.value),a=i.byteLength,o.size===ce&&(c=_e(a)));let u=new Uint8Array(s+c+a),f=0;ar(n.code,u,f),f+=s,i!=null&&(o.size===ce&&(ar(a,u,f),f+=c),u.set(i,f)),n.bytes=u}r.push(n.bytes),e+=n.bytes.byteLength}return Jr(r,e)}function Xu(t){if(t.charAt(0)!=="/")throw new le('String multiaddr must start with "/"');let e=[],r="protocol",n="",o="";for(let s=1;s<t.length;s++){let i=t.charAt(s);i!=="/"&&(r==="protocol"?o+=t.charAt(s):n+=t.charAt(s));let a=s===t.length-1;if(i==="/"||a){let c=tt.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new le(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new le(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}e.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new le("Incomplete multiaddr");return e}function Qu(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=tt.getProtocol(e.code);if(r==null)throw new le(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function gm(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:ti(e,r)}var xm=Symbol.for("nodejs.util.inspect.custom"),Xi=Symbol.for("@multiformats/multiaddr");function wm(t){if(t==null&&(t="/"),oo(t))return t.getComponents();if(t instanceof Uint8Array)return Yu(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),Xu(t);if(Array.isArray(t))return t;throw new le("Must be a string, Uint8Array, Component[], or another Multiaddr")}var no=class t{[Xi]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=wm(e),r.validate!==!1&&Em(this)}get bytes(){return this.#r==null&&(this.#r=Gu(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=Qu(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let r=new t(e);return new t([...this.#e,...r.getComponents()],{validate:!1})}decapsulate(e){let r=e.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new Qn(`Address ${this.toString()} does not contain subaddress: ${r}`);return new t(n.slice(0,o),{validate:!1})}decapsulateCode(e){let r;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){r=n;break}return new t(this.#e.slice(0,r),{validate:!1})}equals(e){return Pu(this.bytes,e.bytes)}[xm](){return`Multiaddr(${this.toString()})`}};function Em(t){t.getComponents().forEach(e=>{let r=tt.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function oo(t){return!!t?.[Xi]}function Lt(t){return new no(t)}var Ju="libp2p-peer-record",ef=Uint8Array.from([3,1]);var rn;(function(t){let e;(function(i){let a;i.codec=()=>(a==null&&(a=ge((d,l,h={})=>{h.lengthDelimited!==!1&&l.fork(),d.multiaddr!=null&&d.multiaddr.byteLength>0&&(l.uint32(10),l.bytes(d.multiaddr)),h.lengthDelimited!==!1&&l.ldelim()},(d,l,h={})=>{let m={multiaddr:Be(0)},g=l==null?d.len:d.pos+l;for(;d.pos<g;){let p=d.uint32();p>>>3===1?m.multiaddr=d.bytes():d.skipType(p&7)}return m},function*(d,l,h,m={}){let g=l==null?d.len:d.pos+l;for(;d.pos<g;){let p=d.uint32();p>>>3===1?yield{field:`${h}.multiaddr`,value:d.bytes()}:d.skipType(p&7)}})),a);function c(d){return ye(d,i.codec())}i.encode=c;function u(d,l){return me(d,i.codec(),l)}i.decode=u;function f(d,l){return be(d,i.codec(),l)}i.stream=f})(e=t.AddressInfo||(t.AddressInfo={}));let r;t.codec=()=>(r==null&&(r=ge((i,a,c={})=>{if(c.lengthDelimited!==!1&&a.fork(),i.peerId!=null&&i.peerId.byteLength>0&&(a.uint32(10),a.bytes(i.peerId)),i.seq!=null&&i.seq!==0n&&(a.uint32(16),a.uint64(i.seq)),i.addresses!=null&&i.addresses.length>0)for(let u of i.addresses)a.uint32(26),t.AddressInfo.codec().encode(u,a);c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let u={peerId:Be(0),seq:0n,addresses:[]},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{u.peerId=i.bytes();break}case 2:{u.seq=i.uint64();break}case 3:{if(c.limits?.addresses!=null&&u.addresses.length===c.limits.addresses)throw new Ie('Decode error - repeated field "addresses" had too many elements');u.addresses.push(t.AddressInfo.codec().decode(i,i.uint32(),{limits:c.limits?.addresses$}));break}default:{i.skipType(d&7);break}}}return u},function*(i,a,c,u={}){let f={addresses:0},d=a==null?i.len:i.pos+a;for(;i.pos<d;){let l=i.uint32();switch(l>>>3){case 1:{yield{field:`${c}.peerId`,value:i.bytes()};break}case 2:{yield{field:`${c}.seq`,value:i.uint64()};break}case 3:{if(u.limits?.addresses!=null&&f.addresses===u.limits.addresses)throw new Ie('Streaming decode error - repeated field "addresses" had too many elements');for(let h of t.AddressInfo.codec().stream(i,i.uint32(),`${c}.addresses[]`,{limits:u.limits?.addresses$}))yield{...h,index:f.addresses};f.addresses++;break}default:{i.skipType(l&7);break}}}})),r);function n(i){return ye(i,t.codec())}t.encode=n;function o(i,a){return me(i,t.codec(),a)}t.decode=o;function s(i,a){return be(i,t.codec(),a)}t.stream=s})(rn||(rn={}));function tf(t,e){let r=(n,o)=>n.toString().localeCompare(o.toString());return t.length!==e.length?!1:(e.sort(r),t.sort(r).every((n,o)=>e[o].equals(n)))}var Ot=class t{static createFromProtobuf=e=>{let r=rn.decode(e),n=zi(Vt(r.peerId)),o=(r.addresses??[]).map(i=>Lt(i.multiaddr)),s=r.seq;return new t({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Ju;static CODEC=ef;peerId;multiaddrs;seqNumber;domain=t.DOMAIN;codec=t.CODEC;marshaled;constructor(e){let{peerId:r,multiaddrs:n,seqNumber:o}=e;this.peerId=r,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=rn.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(e=>({multiaddr:e.bytes}))})),this.marshaled}equals(e){return!(!(e instanceof t)||!this.peerId.equals(e.peerId)||this.seqNumber!==e.seqNumber||!tf(this.multiaddrs,e.multiaddrs))}};function vm(t){return t[Symbol.asyncIterator]!=null}function Sm(t){if(vm(t))return(async()=>{let r=[];for await(let n of t)r.push(n);return r})();let e=[];for(let r of t)e.push(r);return e}var rf=Sm;function so(t,e){let r={[Symbol.iterator]:()=>r,next:()=>{let n=t.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:e(o)}}};return r}var nn=class{map;constructor(e){if(this.map=new Map,e!=null)for(let[r,n]of e.entries())this.map.set(r.toString(),{key:r,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(e){return this.map.delete(e.toString())}entries(){return so(this.map.entries(),e=>[e[1].key,e[1].value])}forEach(e){this.map.forEach((r,n)=>{e(r.value,r.key,this)})}get(e){return this.map.get(e.toString())?.value}has(e){return this.map.has(e.toString())}set(e,r){this.map.set(e.toString(),{key:e,value:r})}keys(){return so(this.map.values(),e=>e.key)}values(){return so(this.map.values(),e=>e.value)}get size(){return this.map.size}};function io(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var ao=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},dr=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new ao(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let r=this.head;this.head=r.next=new ao(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Qi=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function nf(t={}){return Am(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},t)}function Am(t,e){e=e??{};let r=e.onEnd,n=new dr,o,s,i,a=io(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,b)=>{s=E=>{s=null,n.push(E);try{p(t(n))}catch(S){b(S)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=io()})}},u=p=>s!=null?s(p):(n.push(p),o),f=p=>(n=new dr,s!=null?s({error:p}):(n.push({error:p}),o)),d=p=>{if(i)return o;if(e?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:p})},l=p=>i?o:(i=!0,p!=null?f(p):u({done:!0})),h=()=>(n=new dr,l(),{done:!0}),m=p=>(l(p),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:h,throw:m,push:d,end:l,get readableLength(){return n.size},onEmpty:async p=>{let b=p?.signal;if(b?.throwIfAborted(),n.isEmpty())return;let E,S;b!=null&&(E=new Promise((C,I)=>{S=()=>{I(new Qi)},b.addEventListener("abort",S)}));try{await Promise.race([a.promise,E])}finally{S!=null&&b!=null&&b?.removeEventListener("abort",S)}}},r==null)return o;let g=o;return o={[Symbol.asyncIterator](){return this},next(){return g.next()},throw(p){return g.throw(p),r!=null&&(r(p),r=void 0),{done:!0}},return(){return g.return(),r!=null&&(r(),r=void 0),{done:!0}},push:d,end(p){return g.end(p),r!=null&&(r(p),r=void 0),o},get readableLength(){return g.readableLength},onEmpty:p=>g.onEmpty(p)},o}function Tm(t){return t.reason}async function of(t,e,r){if(e==null)return t;let n=r?.translateError??Tm;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var Ji=class extends nn{metric;constructor(e){super();let{name:r,metrics:n}=e;this.metric=n.registerMetric(r),this.updateComponentMetric()}set(e,r){return super.set(e,r),this.updateComponentMetric(),this}delete(e){let r=super.delete(e);return this.updateComponentMetric(),r}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function ea(t){let{name:e,metrics:r}=t,n;return r!=null?n=new Ji({name:e,metrics:r}):n=new nn,n}var Se=class extends Error{static name="AbortError";name="AbortError";constructor(e="The operation was aborted",...r){super(e,...r)}};async function co(t,e,r,n){let o=new Se(n?.errorMessage);n?.errorCode!=null&&(o.code=n.errorCode);let s=n?.errorEvent??"error";return r?.aborted===!0?Promise.reject(o):new Promise((i,a)=>{function c(){ra(r,"abort",d),ra(t,e,u),ra(t,s,f)}let u=l=>{try{if(n?.filter?.(l)===!1)return}catch(h){c(),a(h);return}c(),i(l)},f=l=>{if(c(),l instanceof Error){a(l);return}a(l.detail??n?.error??new Error(`The "${n?.errorEvent}" event was emitted but the event had no '.detail' field. Pass an 'error' option to race-event to change this message.`))},d=()=>{c(),a(o)};ta(r,"abort",d),ta(t,e,u),ta(t,s,f)})}function ta(t,e,r){t!=null&&(sf(t)?t.addEventListener(e,r):t.addListener(e,r))}function ra(t,e,r){t!=null&&(sf(t)?t.removeEventListener(e,r):t.removeListener(e,r))}function sf(t){return typeof t.addEventListener=="function"&&typeof t.removeEventListener=="function"}var uo=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};var fo=class{deferred;signal;constructor(e){this.signal=e,this.deferred=Promise.withResolvers(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Se)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function _m(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var lo=class{id;fn;options;recipients;status;timeline;controller;constructor(e,r){this.id=_m(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Se),this.cleanup())}async join(e={}){let r=new fo(e.signal);return this.recipients.push(r),e.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await of(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(r=>{r.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};function na(t,e){let r,n=function(){let o=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var on=class extends Nt{concurrency;maxSize;queue;pending;sort;autoStart;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.maxSize=e.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.autoStart=e.autoStart??!0,this.sort=e.sort,this.queue=[],this.emitEmpty=na(this.emitEmpty.bind(this),1),this.emitIdle=na(this.emitIdle.bind(this),1)}[Symbol.asyncIterator](){return this.toGenerator()}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}tryToStartAnother(){if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let e;for(let r of this.queue)if(r.status==="queued"){e=r;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===e){this.queue.splice(r,1);break}this.pending--,this.safeDispatchEvent("next"),this.autoStart&&this.tryToStartAnother()}),!0)}return!1}enqueue(e){this.queue.push(e),this.sort!=null&&this.queue.sort(this.sort)}start(){this.autoStart===!1&&(this.autoStart=!0,this.tryToStartAnother())}pause(){this.autoStart=!1}async add(e,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new uo;let n=new lo(e,r);return this.enqueue(n),this.safeDispatchEvent("add"),this.autoStart&&this.tryToStartAnother(),n.join(r).then(o=>(this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new Se)}),this.clear()}async onEmpty(e){this.size!==0&&await co(this,"empty",e?.signal)}async onSizeLessThan(e,r){this.size<e||await co(this,"next",r?.signal,{filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await co(this,"idle",e?.signal)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let r=nf({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},o=c=>{c.detail!=null&&r.push(c.detail.result)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new Se("Queue aborted"))};this.addEventListener("success",o),this.addEventListener("failure",s),this.addEventListener("idle",i),e?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("success",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),e?.signal?.removeEventListener("abort",a),n()}}};var ho="lock:worker:request-read",po="lock:worker:abort-read-request",mo="lock:worker:release-read",yo="lock:master:grant-read",bo="lock:master:error-read",go="lock:worker:request-write",xo="lock:worker:abort-write-request",wo="lock:worker:release-write",Eo="lock:master:grant-write",vo="lock:master:error-write",So="lock:worker:finalize",Ao="mortice",af={singleProcess:!1};var oa=(t,e,r,n,o,s,i,a,c)=>u=>{if(u.data==null)return;let f={type:u.data.type,name:u.data.name,identifier:u.data.identifier};f.type===o&&t.safeDispatchEvent(r,{detail:{name:f.name,identifier:f.identifier,handler:async()=>{e.postMessage({type:c,name:f.name,identifier:f.identifier}),await new Promise(d=>{let l=h=>{if(h?.data==null)return;let m={type:h.data.type,name:h.data.name,identifier:h.data.identifier};m.type===a&&m.identifier===f.identifier&&(e.removeEventListener("message",l),d())};e.addEventListener("message",l)})},onError:d=>{e.postMessage({type:i,name:f.name,identifier:f.identifier,error:{message:d.message,name:d.name,stack:d.stack}})}}}),f.type===s&&t.safeDispatchEvent(n,{detail:{name:f.name,identifier:f.identifier}}),f.type===So&&t.safeDispatchEvent("finalizeRequest",{detail:{name:f.name}})};var cf=(t=10)=>Math.random().toString().substring(2,t+2);var To=class{name;channel;constructor(e){this.name=e,this.channel=new BroadcastChannel(Ao)}readLock(e){return this.sendRequest(ho,po,yo,bo,mo,e)}writeLock(e){return this.sendRequest(go,xo,Eo,vo,wo,e)}finalize(){this.channel.postMessage({type:So,name:this.name}),this.channel.close()}async sendRequest(e,r,n,o,s,i){i?.signal?.throwIfAborted();let a=cf();return this.channel.postMessage({type:e,identifier:a,name:this.name}),new Promise((c,u)=>{let f=()=>{this.channel.postMessage({type:r,identifier:a,name:this.name})};i?.signal?.addEventListener("abort",f,{once:!0});let d=l=>{if(l.data?.identifier===a&&(l.data?.type===n&&(this.channel.removeEventListener("message",d),i?.signal?.removeEventListener("abort",f),c(()=>{this.channel.postMessage({type:s,identifier:a,name:this.name})})),l.data.type===o)){this.channel.removeEventListener("message",d),i?.signal?.removeEventListener("abort",f);let h=new Error;l.data.error!=null&&(h.message=l.data.error.message,h.name=l.data.error.name,h.stack=l.data.error.stack),u(h)}};this.channel.addEventListener("message",d)})}};var uf=t=>{if(t=Object.assign({},af,t),!!globalThis.document||t.singleProcess){let r=new BroadcastChannel(Ao),n=new Nt;return r.addEventListener("message",oa(n,r,"requestReadLock","abortReadLockRequest",ho,po,bo,mo,yo)),r.addEventListener("message",oa(n,r,"requestWriteLock","abortWriteLockRequest",go,xo,vo,wo,Eo)),n}return new To(t.name)};var kt=new Map,sn;function ff(t){return typeof t?.readLock=="function"&&typeof t?.writeLock=="function"}function Im(t){if(sn==null&&(sn=uf(t),!ff(sn))){let e=sn;e.addEventListener("requestReadLock",r=>{let n=r.detail.name,o=r.detail.identifier,s=kt.get(n);if(s==null)return;let i=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==o||i.abort()};e.addEventListener("abortReadLockRequest",a),s.readLock({signal:i.signal}).then(async c=>{await r.detail.handler().finally(()=>{c()})}).catch(c=>{r.detail.onError(c)}).finally(()=>{e.removeEventListener("abortReadLockRequest",a)})}),e.addEventListener("requestWriteLock",r=>{let n=r.detail.name,o=r.detail.identifier,s=kt.get(n);if(s==null)return;let i=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==o||i.abort()};e.addEventListener("abortWriteLockRequest",a),s.writeLock({signal:i.signal}).then(async c=>{await r.detail.handler().finally(()=>{c()})}).catch(c=>{r.detail.onError(c)}).finally(()=>{e.removeEventListener("abortWriteLockRequest",a)})}),e.addEventListener("finalizeRequest",r=>{let n=r.detail.name,o=kt.get(n);o?.finalize()})}return sn}async function sa(t,e){let r,n,o=new Promise((i,a)=>{r=i,n=a}),s=()=>{n(new Se)};return e?.signal?.addEventListener("abort",s,{once:!0}),t.add(async()=>{await new Promise(i=>{r(()=>{e?.signal?.removeEventListener("abort",s),i()})})},{signal:e?.signal}).catch(i=>{n(i)}),o}var lf=(t,e)=>{let r=kt.get(t);if(r!=null)return r;let n=Im(e);if(ff(n))return r=n,kt.set(t,r),r;let o=new on({concurrency:1}),s;return r={async readLock(i){if(s!=null)return sa(s,i);s=new on({concurrency:e.concurrency,autoStart:!1});let a=s,c=sa(s,i);return o.add(async()=>{a.start(),await a.onIdle().then(()=>{s===a&&(s=null)})}),c},async writeLock(i){return s=null,sa(o,i)},finalize:()=>{kt.delete(t)},queue:o},kt.set(t,r),e.autoFinalize===!0&&o.addEventListener("idle",()=>{r.finalize()},{once:!0}),r};var Cm={name:"lock",concurrency:1/0,singleProcess:!1,autoFinalize:!1};function ia(t){let e=Object.assign({},Cm,t);return lf(e.name,e)}var rt;(function(t){let e;(function(a){let c;a.codec=()=>(c==null&&(c=ge((l,h,m={})=>{m.lengthDelimited!==!1&&h.fork(),l.key!=null&&l.key!==""&&(h.uint32(10),h.string(l.key)),l.value!=null&&l.value.byteLength>0&&(h.uint32(18),h.bytes(l.value)),m.lengthDelimited!==!1&&h.ldelim()},(l,h,m={})=>{let g={key:"",value:Be(0)},p=h==null?l.len:l.pos+h;for(;l.pos<p;){let b=l.uint32();switch(b>>>3){case 1:{g.key=l.string();break}case 2:{g.value=l.bytes();break}default:{l.skipType(b&7);break}}}return g},function*(l,h,m,g={}){let p=h==null?l.len:l.pos+h;for(;l.pos<p;){let b=l.uint32();switch(b>>>3){case 1:{yield{field:`${m}.key`,value:l.string()};break}case 2:{yield{field:`${m}.value`,value:l.bytes()};break}default:{l.skipType(b&7);break}}}})),c);function u(l){return ye(l,a.codec())}a.encode=u;function f(l,h){return me(l,a.codec(),h)}a.decode=f;function d(l,h){return be(l,a.codec(),h)}a.stream=d})(e=t.Peer$metadataEntry||(t.Peer$metadataEntry={}));let r;(function(a){let c;a.codec=()=>(c==null&&(c=ge((l,h,m={})=>{m.lengthDelimited!==!1&&h.fork(),l.key!=null&&l.key!==""&&(h.uint32(10),h.string(l.key)),l.value!=null&&(h.uint32(18),cn.codec().encode(l.value,h)),m.lengthDelimited!==!1&&h.ldelim()},(l,h,m={})=>{let g={key:""},p=h==null?l.len:l.pos+h;for(;l.pos<p;){let b=l.uint32();switch(b>>>3){case 1:{g.key=l.string();break}case 2:{g.value=cn.codec().decode(l,l.uint32(),{limits:m.limits?.value});break}default:{l.skipType(b&7);break}}}return g},function*(l,h,m,g={}){let p=h==null?l.len:l.pos+h;for(;l.pos<p;){let b=l.uint32();switch(b>>>3){case 1:{yield{field:`${m}.key`,value:l.string()};break}case 2:{yield*cn.codec().stream(l,l.uint32(),`${m}.value`,{limits:g.limits?.value});break}default:{l.skipType(b&7);break}}}})),c);function u(l){return ye(l,a.codec())}a.encode=u;function f(l,h){return me(l,a.codec(),h)}a.decode=f;function d(l,h){return be(l,a.codec(),h)}a.stream=d})(r=t.Peer$tagsEntry||(t.Peer$tagsEntry={}));let n;t.codec=()=>(n==null&&(n=ge((a,c,u={})=>{if(u.lengthDelimited!==!1&&c.fork(),a.addresses!=null&&a.addresses.length>0)for(let f of a.addresses)c.uint32(10),an.codec().encode(f,c);if(a.protocols!=null&&a.protocols.length>0)for(let f of a.protocols)c.uint32(18),c.string(f);if(a.publicKey!=null&&(c.uint32(34),c.bytes(a.publicKey)),a.peerRecordEnvelope!=null&&(c.uint32(42),c.bytes(a.peerRecordEnvelope)),a.metadata!=null&&a.metadata.size>0)for(let[f,d]of a.metadata.entries())c.uint32(50),t.Peer$metadataEntry.codec().encode({key:f,value:d},c);if(a.tags!=null&&a.tags.size>0)for(let[f,d]of a.tags.entries())c.uint32(58),t.Peer$tagsEntry.codec().encode({key:f,value:d},c);a.updated!=null&&(c.uint32(64),c.uint64Number(a.updated)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={addresses:[],protocols:[],metadata:new Map,tags:new Map},d=c==null?a.len:a.pos+c;for(;a.pos<d;){let l=a.uint32();switch(l>>>3){case 1:{if(u.limits?.addresses!=null&&f.addresses.length===u.limits.addresses)throw new Ie('Decode error - repeated field "addresses" had too many elements');f.addresses.push(an.codec().decode(a,a.uint32(),{limits:u.limits?.addresses$}));break}case 2:{if(u.limits?.protocols!=null&&f.protocols.length===u.limits.protocols)throw new Ie('Decode error - repeated field "protocols" had too many elements');f.protocols.push(a.string());break}case 4:{f.publicKey=a.bytes();break}case 5:{f.peerRecordEnvelope=a.bytes();break}case 6:{if(u.limits?.metadata!=null&&f.metadata.size===u.limits.metadata)throw new Hr('Decode error - map field "metadata" had too many elements');let h=t.Peer$metadataEntry.codec().decode(a,a.uint32(),{limits:{value:u.limits?.metadata$value}});f.metadata.set(h.key,h.value);break}case 7:{if(u.limits?.tags!=null&&f.tags.size===u.limits.tags)throw new Hr('Decode error - map field "tags" had too many elements');let h=t.Peer$tagsEntry.codec().decode(a,a.uint32(),{limits:{value:u.limits?.tags$value}});f.tags.set(h.key,h.value);break}case 8:{f.updated=a.uint64Number();break}default:{a.skipType(l&7);break}}}return f},function*(a,c,u,f={}){let d={addresses:0,protocols:0,metadata:0,tags:0},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let h=a.uint32();switch(h>>>3){case 1:{if(f.limits?.addresses!=null&&d.addresses===f.limits.addresses)throw new Ie('Streaming decode error - repeated field "addresses" had too many elements');for(let m of an.codec().stream(a,a.uint32(),`${u}.addresses[]`,{limits:f.limits?.addresses$}))yield{...m,index:d.addresses};d.addresses++;break}case 2:{if(f.limits?.protocols!=null&&d.protocols===f.limits.protocols)throw new Ie('Streaming decode error - repeated field "protocols" had too many elements');yield{field:`${u}.protocols[]`,index:d.protocols,value:a.string()},d.protocols++;break}case 4:{yield{field:`${u}.publicKey`,value:a.bytes()};break}case 5:{yield{field:`${u}.peerRecordEnvelope`,value:a.bytes()};break}case 6:{if(f.limits?.metadata!=null&&d.metadata===f.limits.metadata)throw new Ie('Decode error - map field "metadata" had too many elements');yield*t.Peer$metadataEntry.codec().stream(a,a.uint32(),`${u}.metadata{}`,{limits:{value:f.limits?.metadata$value}}),d.metadata++;break}case 7:{if(f.limits?.tags!=null&&d.tags===f.limits.tags)throw new Ie('Decode error - map field "tags" had too many elements');yield*t.Peer$tagsEntry.codec().stream(a,a.uint32(),`${u}.tags{}`,{limits:{value:f.limits?.tags$value}}),d.tags++;break}case 8:{yield{field:`${u}.updated`,value:a.uint64Number()};break}default:{a.skipType(h&7);break}}}})),n);function o(a){return ye(a,t.codec())}t.encode=o;function s(a,c){return me(a,t.codec(),c)}t.decode=s;function i(a,c){return be(a,t.codec(),c)}t.stream=i})(rt||(rt={}));var an;(function(t){let e;t.codec=()=>(e==null&&(e=ge((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.multiaddr!=null&&s.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(s.multiaddr)),s.isCertified!=null&&(i.uint32(16),i.bool(s.isCertified)),s.observed!=null&&(i.uint32(24),i.uint64Number(s.observed)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={multiaddr:Be(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.multiaddr=s.bytes();break}case 2:{c.isCertified=s.bool();break}case 3:{c.observed=s.uint64Number();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.multiaddr`,value:s.bytes()};break}case 2:{yield{field:`${a}.isCertified`,value:s.bool()};break}case 3:{yield{field:`${a}.observed`,value:s.uint64Number()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ye(s,t.codec())}t.encode=r;function n(s,i){return me(s,t.codec(),i)}t.decode=n;function o(s,i){return be(s,t.codec(),i)}t.stream=o})(an||(an={}));var cn;(function(t){let e;t.codec=()=>(e==null&&(e=ge((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.value!=null&&s.value!==0&&(i.uint32(8),i.uint32(s.value)),s.expiry!=null&&(i.uint32(16),i.uint64(s.expiry)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={value:0},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.value=s.uint32();break}case 2:{c.expiry=s.uint64();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.value`,value:s.uint32()};break}case 2:{yield{field:`${a}.expiry`,value:s.uint64()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ye(s,t.codec())}t.encode=r;function n(s,i){return me(s,t.codec(),i)}t.decode=n;function o(s,i){return be(s,t.codec(),i)}t.stream=o})(cn||(cn={}));function Bm(t,e){if(t.publicKey!=null||e.publicKey==null)return t;let r;t.type==="RSA"&&(r=t.toMultihash());let n=Wn(e.publicKey,r);return Ou(n)}function df(t,e,r){let n=rt.decode(e);return hr(t,n,r)}function hr(t,e,r){let n=new Map,o=BigInt(Date.now());for(let[s,i]of e.tags.entries())i.expiry!=null&&i.expiry<o||n.set(s,i);return{...e,id:Bm(t,e),addresses:e.addresses.filter(({observed:s})=>s!=null&&s>Date.now()-r).map(({multiaddr:s,isCertified:i})=>({multiaddr:Lt(s),isCertified:i??!1})),metadata:e.metadata,peerRecordEnvelope:e.peerRecordEnvelope??void 0,tags:n}}function hf(t,e){return Dm(t.addresses,e.addresses)&&Rm(t.protocols,e.protocols)&&Lm(t.publicKey,e.publicKey)&&Om(t.peerRecordEnvelope,e.peerRecordEnvelope)&&km(t.metadata,e.metadata)&&Pm(t.tags,e.tags)}function Dm(t,e){return mf(t,e,(r,n)=>!(r.isCertified!==n.isCertified||!re(r.multiaddr,n.multiaddr)))}function Rm(t,e){return mf(t,e,(r,n)=>r===n)}function Lm(t,e){return pf(t,e)}function Om(t,e){return pf(t,e)}function km(t,e){return yf(t,e,(r,n)=>re(r,n))}function Pm(t,e){return yf(t,e,(r,n)=>r.value===n.value&&r.expiry===n.expiry)}function pf(t,e){return t==null&&e==null?!0:t!=null&&e!=null?re(t,e):!1}function mf(t,e,r){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(!r(t[n],e[n]))return!1;return!0}function yf(t,e,r){if(t.size!==e.size)return!1;for(let[n,o]of t.entries()){let s=e.get(n);if(s==null||!r(o,s))return!1}return!0}function bf(t=0){return new Uint8Array(t)}function xf(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var gf=xf("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),aa=xf("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=bf(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Km={utf8:gf,"utf-8":gf,hex:Pe.base16,latin1:aa,ascii:aa,binary:aa,...Pe},_o=Km;function wf(t,e="utf8"){let r=_o[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Ef(t,e="utf8"){let r=_o[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var nt="/",vf=new TextEncoder().encode(nt),Io=vf[0],Co=class t{_buf;constructor(e,r){if(typeof e=="string")this._buf=wf(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(r==null&&(r=!0),r&&this.clean(),this._buf.byteLength===0||this._buf[0]!==Io)throw new Error("Invalid key")}toString(e="utf8"){return Ef(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new t(e.join(nt))}static random(){return new t(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new t(e):typeof e.uint8Array=="function"?new t(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=vf),this._buf[0]!==Io){let e=new Uint8Array(this._buf.byteLength+1);e.fill(Io,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Io;)this._buf=this._buf.subarray(0,-1)}less(e){let r=this.list(),n=e.list();for(let o=0;o<r.length;o++){if(n.length<o+1)return!1;let s=r[o],i=n[o];if(s<i)return!0;if(s>i)return!1}return r.length<n.length}reverse(){return t.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(nt).slice(1)}type(){return Um(this.baseNamespace())}name(){return Nm(this.baseNamespace())}instance(e){return new t(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(nt)||(e+=nt),e+=this.type(),new t(e)}parent(){let e=this.list();return e.length===1?new t(nt):new t(e.slice(0,-1).join(nt))}child(e){return this.toString()===nt?e:e.toString()===nt?this:new t(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return t.withNamespaces([...this.namespaces(),...Fm(e.map(r=>r.namespaces()))])}};function Um(t){let e=t.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function Nm(t){let e=t.split(":");return e[e.length-1]}function Fm(t){return[].concat(...t)}var ca="/peers/";function un(t){if(!Ut(t)||t.type==null)throw new F("Invalid PeerId");let e=t.toCID().toString();return new Co(`${ca}${e}`)}async function Sf(t,e,r,n,o){let s=new Map;for(let i of r){if(i==null)continue;if(i.multiaddr instanceof Uint8Array&&(i.multiaddr=Lt(i.multiaddr)),!oo(i.multiaddr))throw new F("Multiaddr was invalid");if(!await e(t,i.multiaddr,o))continue;let a=i.isCertified??!1,c=i.multiaddr.toString(),u=s.get(c);u!=null?i.isCertified=u.isCertified||a:s.set(c,{multiaddr:i.multiaddr,isCertified:a})}return[...s.values()].sort((i,a)=>i.multiaddr.toString().localeCompare(a.multiaddr.toString())).map(({isCertified:i,multiaddr:a})=>{let c=a.getComponents().find(u=>u.code===421)?.value;return t.equals(c)&&(a=a.decapsulate(Lt(`/p2p/${t}`))),{isCertified:i,multiaddr:a.bytes}})}async function Do(t,e,r,n){if(e==null)throw new F("Invalid PeerData");if(e.publicKey!=null&&t.publicKey!=null&&!e.publicKey.equals(t.publicKey))throw new F("publicKey bytes do not match peer id publicKey bytes");let o=n.existingPeer?.peer;if(o!=null&&!t.equals(o.id))throw new F("peer id did not match existing peer id");let s=o?.addresses??[],i=new Set(o?.protocols??[]),a=o?.metadata??new Map,c=o?.tags??new Map,u=o?.peerRecordEnvelope;if(r==="patch"){if((e.multiaddrs!=null||e.addresses!=null)&&(s=[],e.multiaddrs!=null&&s.push(...e.multiaddrs.map(l=>({isCertified:!1,multiaddr:l}))),e.addresses!=null&&s.push(...e.addresses)),e.protocols!=null&&(i=new Set(e.protocols)),e.metadata!=null){let l=e.metadata instanceof Map?[...e.metadata.entries()]:Object.entries(e.metadata);a=Bo(l,{validate:Af})}if(e.tags!=null){let l=e.tags instanceof Map?[...e.tags.entries()]:Object.entries(e.tags);c=Bo(l,{validate:Tf,map:_f})}e.peerRecordEnvelope!=null&&(u=e.peerRecordEnvelope)}if(r==="merge"){if(e.multiaddrs!=null&&s.push(...e.multiaddrs.map(l=>({isCertified:!1,multiaddr:l}))),e.addresses!=null&&s.push(...e.addresses),e.protocols!=null&&(i=new Set([...i,...e.protocols])),e.metadata!=null){let l=e.metadata instanceof Map?[...e.metadata.entries()]:Object.entries(e.metadata);for(let[h,m]of l)m==null?a.delete(h):a.set(h,m);a=Bo([...a.entries()],{validate:Af})}if(e.tags!=null){let l=e.tags instanceof Map?[...e.tags.entries()]:Object.entries(e.tags),h=new Map(c);for(let[m,g]of l)g==null?h.delete(m):h.set(m,g);c=Bo([...h.entries()],{validate:Tf,map:_f})}e.peerRecordEnvelope!=null&&(u=e.peerRecordEnvelope)}let f;o?.id.publicKey!=null?f=Ae(o.id.publicKey):e.publicKey!=null?f=Ae(e.publicKey):t.publicKey!=null&&(f=Ae(t.publicKey));let d={addresses:await Sf(t,n.addressFilter??(async()=>!0),s,n.existingPeer?.peerPB.addresses,n),protocols:[...i.values()].sort((l,h)=>l.localeCompare(h)),metadata:a,tags:c,publicKey:f,peerRecordEnvelope:u};return d.addresses.forEach(l=>{l.observed=n.existingPeer?.peerPB.addresses?.find(h=>re(h.multiaddr,h.multiaddr))?.observed??Date.now()}),t.type!=="RSA"&&delete d.publicKey,d}function Bo(t,e){let r=new Map;for(let[n,o]of t)o!=null&&e.validate(n,o);for(let[n,o]of t.sort(([s],[i])=>s.localeCompare(i)))o!=null&&r.set(n,e.map?.(n,o)??o);return r}function Af(t,e){if(typeof t!="string")throw new F("Metadata key must be a string");if(!(e instanceof Uint8Array))throw new F("Metadata value must be a Uint8Array")}function Tf(t,e){if(typeof t!="string")throw new F("Tag name must be a string");if(e.value!=null){if(parseInt(`${e.value}`,10)!==e.value)throw new F("Tag value must be an integer");if(e.value<0||e.value>100)throw new F("Tag value must be between 0-100")}if(e.ttl!=null){if(parseInt(`${e.ttl}`,10)!==e.ttl)throw new F("Tag ttl must be an integer");if(e.ttl<0)throw new F("Tag ttl must be between greater than 0")}}function _f(t,e){let r;e.expiry!=null&&(r=e.expiry),e.ttl!=null&&(r=BigInt(Date.now()+Number(e.ttl)));let n={value:e.value??0};return r!=null&&(n.expiry=r),n}function If(t){let e=t.toString().split("/")[2],r=te.parse(e,Ue);return Zn(r)}function ua(t,e,r){let n=If(t);return df(n,e,r)}function Mm(t,e){return{prefix:ca,filters:(t.filters??[]).map(r=>({key:n,value:o})=>r(ua(n,o,e))),orders:(t.orders??[]).map(r=>(n,o)=>r(ua(n.key,n.value,e),ua(o.key,o.value,e)))}}var Ro=class{peerId;datastore;locks;addressFilter;log;maxAddressAge;maxPeerAge;constructor(e,r={}){this.log=e.logger.forComponent("libp2p:peer-store"),this.peerId=e.peerId,this.datastore=e.datastore,this.addressFilter=r.addressFilter,this.locks=ea({name:"libp2p_peer_store_locks",metrics:e.metrics}),this.maxAddressAge=r.maxAddressAge??36e5,this.maxPeerAge=r.maxPeerAge??216e5}getLock(e){let r=this.locks.get(e);return r==null&&(r={refs:0,lock:ia({name:e.toString(),singleProcess:!0})},this.locks.set(e,r)),r.refs++,r}maybeRemoveLock(e,r){r.refs--,r.refs===0&&(r.lock.finalize(),this.locks.delete(e))}async getReadLock(e,r){let n=this.getLock(e);try{let o=await n.lock.readLock(r);return()=>{o(),this.maybeRemoveLock(e,n)}}catch(o){throw this.maybeRemoveLock(e,n),o}}async getWriteLock(e,r){let n=this.getLock(e);try{let o=await n.lock.writeLock(r);return()=>{o(),this.maybeRemoveLock(e,n)}}catch(o){throw this.maybeRemoveLock(e,n),o}}async has(e,r){try{return await this.load(e,r),!0}catch(n){if(n.name!=="NotFoundError")throw n}return!1}async delete(e,r){this.peerId.equals(e)||await this.datastore.delete(un(e),r)}async load(e,r){let n=un(e),o=await this.datastore.get(n,r),s=rt.decode(o);if(this.#r(e,s))throw await this.datastore.delete(n,r),new mr;return hr(e,s,this.peerId.equals(e)?1/0:this.maxAddressAge)}async save(e,r,n){let o=await this.#e(e,n),s=await Do(e,r,"patch",{...n,addressFilter:this.addressFilter});return this.#t(e,s,o)}async patch(e,r,n){let o=await this.#e(e,n),s=await Do(e,r,"patch",{...n,addressFilter:this.addressFilter,existingPeer:o});return this.#t(e,s,o)}async merge(e,r,n){let o=await this.#e(e,n),s=await Do(e,r,"merge",{addressFilter:this.addressFilter,existingPeer:o});return this.#t(e,s,o)}async*all(e){for await(let{key:r,value:n}of this.datastore.query(Mm(e??{},this.maxAddressAge),e)){let o=If(r);if(o.equals(this.peerId))continue;let s=rt.decode(n);if(this.#r(o,s)){await this.datastore.delete(r,e);continue}yield hr(o,s,this.peerId.equals(o)?1/0:this.maxAddressAge)}}async#e(e,r){try{let n=un(e),o=await this.datastore.get(n,r),s=rt.decode(o);if(this.#r(e,s))throw await this.datastore.delete(n,r),new mr;return{peerPB:s,peer:hr(e,s,this.maxAddressAge)}}catch(n){n.name!=="NotFoundError"&&this.log.error("invalid peer data found in peer store - %e",n)}}async#t(e,r,n,o){r.updated=Date.now();let s=rt.encode(r);return await this.datastore.put(un(e),s,o),{peer:hr(e,r,this.maxAddressAge),previous:n?.peer,updated:n==null||!hf(r,n.peerPB)}}#r(e,r){if(r.updated==null)return!0;if(this.peerId.equals(e))return!1;let n=r.updated<Date.now()-this.maxPeerAge,o=Date.now()-this.maxAddressAge,s=r.addresses.filter(i=>i.observed!=null&&i.observed>o);return n&&s.length===0}};var fa=class{store;events;peerId;log;constructor(e,r={}){this.log=e.logger.forComponent("libp2p:peer-store"),this.events=e.events,this.peerId=e.peerId,this.store=new Ro(e,r)}[Symbol.toStringTag]="@libp2p/peer-store";async forEach(e,r){for await(let n of this.store.all(r))e(n)}async all(e){return rf(this.store.all(e))}async delete(e,r){let n=await this.store.getReadLock(e,r);try{await this.store.delete(e,r)}finally{n()}}async has(e,r){let n=await this.store.getReadLock(e,r);try{return await this.store.has(e,r)}finally{this.log.trace("has release read lock"),n?.()}}async get(e,r){let n=await this.store.getReadLock(e,r);try{return await this.store.load(e,r)}finally{n?.()}}async getInfo(e,r){let n=await this.get(e,r);return{id:n.id,multiaddrs:n.addresses.map(({multiaddr:o})=>o)}}async save(e,r,n){let o=await this.store.getWriteLock(e,n);try{let s=await this.store.save(e,r,n);return this.#e(e,s),s.peer}finally{o?.()}}async patch(e,r,n){let o=await this.store.getWriteLock(e,n);try{let s=await this.store.patch(e,r,n);return this.#e(e,s),s.peer}finally{o?.()}}async merge(e,r,n){let o=await this.store.getWriteLock(e,n);try{let s=await this.store.merge(e,r,n);return this.#e(e,s),s.peer}finally{o?.()}}async consumePeerRecord(e,r,n){let o=Ut(r)?r:Ut(r?.expectedPeer)?r.expectedPeer:void 0,s=Ut(r)||r===void 0?n:r,i=await fr.openAndCertify(e,Ot.DOMAIN,s),a=Zn(i.publicKey.toCID());if(o?.equals(a)===!1)return this.log("envelope peer id was not the expected peer id - expected: %p received: %p",o,a),!1;let c=Ot.createFromProtobuf(i.payload),u;try{u=await this.get(a,s)}catch(f){if(f.name!=="NotFoundError")throw f}if(u?.peerRecordEnvelope!=null){let f=fr.createFromProtobuf(u.peerRecordEnvelope),d=Ot.createFromProtobuf(f.payload);if(d.seqNumber>=c.seqNumber)return this.log("sequence number was lower or equal to existing sequence number - stored: %d received: %d",d.seqNumber,c.seqNumber),!1}return await this.patch(c.peerId,{peerRecordEnvelope:e,addresses:c.multiaddrs.map(f=>({isCertified:!0,multiaddr:f}))},s),!0}#e(e,r){r.updated&&(this.peerId.equals(e)?this.events.safeDispatchEvent("self:peer:update",{detail:r}):this.events.safeDispatchEvent("peer:update",{detail:r}))}};function qm(t,e={}){return new fa(t,e)}return Lf(zm);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/curves/utils.js:
|