@libp2p/peer-store 12.0.26-47cf9cdc1 → 12.0.26-d5534174d
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 +3 -3
- package/package.json +7 -7
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 co=Object.defineProperty;var su=Object.getOwnPropertyDescriptor;var iu=Object.getOwnPropertyNames;var au=Object.prototype.hasOwnProperty;var xt=(e,t)=>{for(var r in t)co(e,r,{get:t[r],enumerable:!0})},cu=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of iu(t))!au.call(e,o)&&o!==r&&co(e,o,{get:()=>t[o],enumerable:!(n=su(t,o))||n.enumerable});return e};var uu=e=>cu(co({},"__esModule",{value:!0}),e);var gh={};xt(gh,{persistentPeerStore:()=>bh});var q=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Ie=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var tr=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var Ur=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Mr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var de=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Fr=Symbol.for("@libp2p/peer-id");function Re(e){return!!e?.[Fr]}function fu(e){return typeof e?.handleEvent=="function"}function lu(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=lu(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))}fu(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 po={};xt(po,{base58btc:()=>nt,base58flickr:()=>wu});var Sh=new Uint8Array(0);function bi(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 Tt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return he(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return he(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));throw new Error("Unknown type, must be binary type")}function gi(e){let t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}var yi=4096;function wi(e){let t=e.length;if(t<=yi)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.subarray(n,n+=yi));return r}function du(e){return e?.buffer instanceof ArrayBuffer}function he(e){return du(e)?e:e.slice()}function hu(e,t,r){if(e.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var s=0;s<e.length;s++){var i=e.charAt(s),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=s,r){var c=i.toLowerCase().charCodeAt(0),f=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=s),f!==a&&(n[f]=s)}}var u=e.length,d=e.charAt(0),l=Math.log(u)/Math.log(256),h=Math.log(256)/Math.log(u);function w(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var S=0,y=0,B=0,_=x.length;B!==_&&x[B]===0;)B++,S++;for(var U=(_-B)*h+1>>>0,M=new Uint8Array(U);B!==_;){for(var P=x[B],O=0,k=U-1;(P!==0||O<y)&&k!==-1;k--,O++)P+=256*M[k]>>>0,M[k]=P%u>>>0,P=P/u>>>0;if(P!==0)throw new Error("Non-zero carry");y=O,B++}for(var F=U-y;F!==U&&M[F]===0;)F++;for(var D=d.repeat(S);F<U;++F)D+=e.charAt(M[F]);return D}function g(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var S=0;if(x[S]!==" "){for(var y=0,B=0;x[S]===d;)y++,S++;for(var _=(x.length-S)*l+1>>>0,U=new Uint8Array(_);x[S];){var M=n[x.charCodeAt(S)];if(M===255)return;for(var P=0,O=_-1;(M!==0||P<B)&&O!==-1;O--,P++)M+=u*U[O]>>>0,U[O]=M%256>>>0,M=M/256>>>0;if(M!==0)throw new Error("Non-zero carry");B=P,S++}if(x[S]!==" "){for(var k=_-B;k!==_&&U[k]===0;)k++;for(var F=new Uint8Array(y+(_-k)),D=y;k!==_;)F[D++]=U[k++];return F}}}function b(x){var S=g(x);if(S)return S;throw new Error(`Non-${t} character`)}return{encode:w,decodeUnsafe:g,decode:b}}var pu=hu,mu=pu,Ei=mu;var uo=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")}},fo=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 vi(this,t)}},lo=class{decoders;constructor(t){this.decoders=t}or(t){return vi(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 vi(e,t){return new lo({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var ho=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 uo(t,r,n),this.decoder=new fo(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 ho(e,t,r,n)}function Jt({name:e,prefix:t,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:s}=Ei(r,e,n);return De({prefix:t,name:e,encode:o,decode:i=>Tt(s(i))})}function yu(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 f=0;f<o;++f){let u=t[e[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function bu(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 gu(e,t){let r={};for(let n=0;n<e.length;++n)if(r[e[n]]=n,t){let o=e[n].toLowerCase(),s=e[n].toUpperCase();o!==e[n]&&(r[o]=n),s!==e[n]&&(r[s]=n)}return r}function rt({name:e,prefix:t,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let s=gu(n,o);return De({prefix:t,name:e,encode(i){return bu(i,n,r)},decode(i){return yu(i,s,r,e)}})}var nt=Jt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),wu=Jt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var mo={};xt(mo,{base32:()=>Ut,base32hex:()=>Su,base32hexpad:()=>Bu,base32hexpadupper:()=>Tu,base32hexupper:()=>Au,base32pad:()=>Eu,base32padupper:()=>vu,base32upper:()=>xu,base32z:()=>_u});var Ut=rt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),xu=rt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Eu=rt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),vu=rt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Su=rt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Au=rt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),Bu=rt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),Tu=rt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),_u=rt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var yo={};xt(yo,{base36:()=>er,base36upper:()=>Iu});var er=Jt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),Iu=Jt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Ru=Bi,Si=128,Cu=127,Du=~Cu,Lu=Math.pow(2,31);function Bi(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Lu;)t[r++]=e&255|Si,e/=128;for(;e&Du;)t[r++]=e&255|Si,e>>>=7;return t[r]=e|0,Bi.bytes=r-n+1,t}var Ou=bo,ku=128,Ai=127;function bo(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw bo.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Ai)<<o:(i&Ai)*Math.pow(2,o),o+=7}while(i>=ku);return bo.bytes=s-n,r}var Pu=Math.pow(2,7),Ku=Math.pow(2,14),Nu=Math.pow(2,21),Uu=Math.pow(2,28),Mu=Math.pow(2,35),Fu=Math.pow(2,42),qu=Math.pow(2,49),zu=Math.pow(2,56),Hu=Math.pow(2,63),Vu=function(e){return e<Pu?1:e<Ku?2:e<Nu?3:e<Uu?4:e<Mu?5:e<Fu?6:e<qu?7:e<zu?8:e<Hu?9:10},$u={encode:Ru,decode:Ou,encodingLength:Vu},Wu=$u,rr=Wu;function nr(e,t=0){let r=rr.decode(e,t),n=rr.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&e[t+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function Le(e,t,r=0){return rr.encode(e,t,r),t}function Oe(e){return rr.encodingLength(e)}function Mt(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=Tt(e),[r,n]=nr(t),[o,s]=nr(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 Ti(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&bi(e.bytes,r.bytes)}}var ke=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=he(n),this.bytes=he(o)}};function _i(e,t){let{bytes:r,version:n}=e;return n===0?Yu(r,go(e),t??nt.encoder):Zu(r,go(e),t??Ut.encoder)}var Ii=new WeakMap;function go(e){let t=Ii.get(e);if(t==null){let r=new Map;return Ii.set(e,r),r}return t}var st=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=he(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:t,multihash:r}=this;if(t!==or)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Gu)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=Mt(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&Ti(t.multihash,n.multihash)}toString(t){return _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??Ri(n,o,s.bytes))}else if(r[Xu]===!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!==or)throw new Error(`Version 0 CID must use dag-pb (code: ${or}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Ri(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,or,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=Tt(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[d,l]=nr(t.subarray(r));return r+=l,d},o=n(),s=or;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(),f=r+c,u=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(t,r){let[n,o]=ju(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 go(s).set(n,t),s}};function ju(e,t){switch(e[0]){case"Q":{let r=t??nt;return[nt.prefix,r.decode(`${nt.prefix}${e}`)]}case nt.prefix:{let r=t??nt;return[nt.prefix,r.decode(e)]}case Ut.prefix:{let r=t??Ut;return[Ut.prefix,r.decode(e)]}case er.prefix:{let r=t??er;return[er.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 Yu(e,t,r){let{prefix:n}=r;if(n!==nt.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 Zu(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 or=112,Gu=18;function Ri(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 Xu=Symbol.for("@ipld/js-cid/CID");var wo={};xt(wo,{identity:()=>Ot});var Ci=0,Qu="identity",Di=Tt;function Ju(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 Mt(Ci,Di(e))}var Ot={code:Ci,name:Qu,encode:Di,digest:Ju};function Z(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 tf(e){return e.buffer instanceof ArrayBuffer}function pt(e){return tf(e)?e:e.slice()}async function Li(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,pt(t),pt(r.subarray()));return n?.signal?.throwIfAborted(),s}function ot(e=0){return new Uint8Array(e)}function ft(e=0){return new Uint8Array(e)}function ef(e){return e?.buffer instanceof ArrayBuffer}function xo(e){if(ef(e))return e;let t=e.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function Ft(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=ft(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return xo(r)}var ki=Symbol.for("@achingbrain/uint8arraylist");function Oi(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 zr(e){return!!e?.[ki]}var mt=class e{bufs;length;[ki]=!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(zr(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(zr(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=Oi(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Oi(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(zr(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 Ft(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Ft(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 f=t>=a&&t<c,u=r>a&&r<=c;if(f&&u){if(t===a&&r===c){n.push(i);break}let d=t-a;n.push(i.subarray(d,d+(r-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!zr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let d=0;d<s;d++)i[d]=-1;for(let d=0;d<o;d++)i[n[d]]=d;let a=i,c=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let d=r;d<=c;d+=u){u=0;for(let l=f;l>=0;l--){let h=this.get(d+l);if(n[l]!==h){u=Math.max(1,l-a[h]);break}}if(u===0)return d}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=ft(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=ot(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=ot(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=ot(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=ft(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=ot(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=ot(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=ot(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=ot(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=ot(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(!Z(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 Eo={};xt(Eo,{base10:()=>rf});var rf=Jt({prefix:"9",name:"base10",alphabet:"0123456789"});var vo={};xt(vo,{base16:()=>nf,base16upper:()=>of});var nf=rt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),of=rt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var So={};xt(So,{base2:()=>sf});var sf=rt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ao={};xt(Ao,{base256emoji:()=>lf});var Pi=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}"),af=Pi.reduce((e,t,r)=>(e[r]=t,e),[]),cf=Pi.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function uf(e){return e.reduce((t,r)=>(t+=af[r],t),"")}function ff(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=cf[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var lf=De({prefix:"\u{1F680}",name:"base256emoji",encode:uf,decode:ff});var To={};xt(To,{base64:()=>df,base64pad:()=>hf,base64url:()=>Bo,base64urlpad:()=>pf});var df=rt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),hf=rt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Bo=rt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),pf=rt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var _o={};xt(_o,{base8:()=>mf});var mf=rt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Io={};xt(Io,{identity:()=>yf});var yf=De({prefix:"\0",name:"identity",encode:e=>wi(Tt(e)),decode:e=>Tt(gi(e))});var cp=new TextEncoder,up=new TextDecoder;var Do={};xt(Do,{sha256:()=>sr,sha512:()=>xf});var wf=20;function Co({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Ro(e,t,r,n,o)}var Ro=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??wf,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 Mt(t,e)}function Ui(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var sr=Co({name:"sha2-256",code:18,encode:Ui("SHA-256")}),xf=Co({name:"sha2-512",code:19,encode:Ui("SHA-512")});var ir={...Io,...So,..._o,...Eo,...vo,...mo,...yo,...po,...To,...Ao},Ep={...Do,...wo};function Fi(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Mi=Fi("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Lo=Fi("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=ft(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Ef={utf8:Mi,"utf-8":Mi,hex:ir.base16,latin1:Lo,ascii:Lo,binary:Lo,...ir},Hr=Ef;function V(e,t="utf8"){let r=Hr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function z(e,t="utf8"){let r=Hr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var vf=parseInt("11111",2),Oo=parseInt("10000000",2),Sf=parseInt("01111111",2),qi={0:ar,1:ar,2:Af,3:_f,4:If,5:Tf,6:Bf,16:ar,22:ar,48:ar};function Vt(e,t={offset:0}){let r=e[t.offset]&vf;if(t.offset++,qi[r]!=null)return qi[r](e,t);throw new Error("No decoder for tag "+r)}function cr(e,t){let r=0;if((e[t.offset]&Oo)===Oo){let n=e[t.offset]&Sf,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++){if(t.offset>=e.byteLength)throw new Error("invalid DER element length");o+=e[t.offset].toString(16).padStart(2,"0")}r=parseInt(o,16)}else r=e[t.offset],t.offset++;if(!Number.isInteger(r)||r<0||r>e.byteLength-t.offset)throw new Error("invalid DER element length");return r}function ar(e,t){cr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Vt(e,t);if(n===null)break;r.push(n)}return r}function Af(e,t){let r=cr(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 Bf(e,t){let r=cr(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 f=e[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let u=0;for(let d=0;d<c.length;d++)u+=c[d]<<d*7;a+=`.${u}`,c=[]}}return a}function Tf(e,t){return t.offset++,null}function _f(e,t){let r=cr(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 If(e,t){let r=cr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Rf(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new mt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function ko(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Rf(e.byteLength);return new mt(Uint8Array.from([t.byteLength|Oo]),t)}function Et(e){let t=new mt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new mt(Uint8Array.from([2]),ko(t),t)}function Vr(e){let t=Uint8Array.from([0]),r=new mt(t,e);return new mt(Uint8Array.from([3]),ko(r),r)}function ee(e,t=48){let r=new mt;for(let n of e)r.append(n);return new mt(Uint8Array.from([t]),ko(r),r)}var Cf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Df=Uint8Array.from([6,5,43,129,4,0,34]),Lf=Uint8Array.from([6,5,43,129,4,0,35]),Of={ext:!0,kty:"EC",crv:"P-256"},kf={ext:!0,kty:"EC",crv:"P-384"},Pf={ext:!0,kty:"EC",crv:"P-521"},Po=32,Ko=48,No=66;function Uo(e){let t=Vt(e);return zi(t)}function zi(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Po*2+1)return n=z(t.subarray(r,r+Po),"base64url"),o=z(t.subarray(r+Po),"base64url"),new Ke({...Of,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ko*2+1)return n=z(t.subarray(r,r+Ko),"base64url"),o=z(t.subarray(r+Ko),"base64url"),new Ke({...kf,key_ops:["verify"],x:n,y:o});if(t.byteLength===No*2+1)return n=z(t.subarray(r,r+No),"base64url"),o=z(t.subarray(r+No),"base64url"),new Ke({...Pf,key_ops:["verify"],x:n,y:o});throw new q(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Hi(e){return ee([Et(Uint8Array.from([1])),ee([Kf(e.crv)],160),ee([Vr(new mt(Uint8Array.from([4]),V(e.x??"","base64url"),V(e.y??"","base64url")))],161)]).subarray()}function Kf(e){if(e==="P-256")return Cf;if(e==="P-384")return Df;if(e==="P-521")return Lf;throw new q(`Invalid curve ${e}`)}var Ke=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Hi(this.jwk)),this._raw}toMultihash(){return Ot.digest(_t(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return nt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Z(this.raw,t.raw)}async verify(t,r,n){return Li(this.jwk,r,t,n)}};var $r=BigInt(4294967295),Vi=BigInt(32);function Nf(e,t=!1){return t?{h:Number(e&$r),l:Number(e>>Vi&$r)}:{h:Number(e>>Vi&$r)|0,l:Number(e&$r)|0}}function $i(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}=Nf(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Uf=e=>e/2**32|0,Mf=e=>e>>>0;function Wi(e,t,r,n){let o=Uf(r),s=Mf(r);e.setUint32(t,n?s:o,n),e.setUint32(t+4,n?o:s,n)}var Mo=(e,t,r)=>e>>>r,Fo=(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,ur=(e,t,r)=>e<<64-r|t>>>r-32,fr=(e,t,r)=>e>>>r-32|t<<64-r;function qt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var ji=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Yi=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Zi=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Gi=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Xi=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Qi=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;function Wr(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}var qo=e=>e?`"${e}" `:"";function $t(e,t=""){if(typeof e!="number")throw new TypeError(qo(t)+"expected number, got "+typeof e);if(!Number.isSafeInteger(e)||e<0)throw new RangeError(qo(t)+"expected integer >= 0, got "+e);return e}function It(e,t,r=""){if(Wr(e)&&(t===void 0||e.length===t))return e;t!==void 0&&$t(t,"length");let n=Wr(e),o=t!==void 0?` of length ${t}`:"",s=n?`length=${e.length}`:`type=${typeof e}`,i=qo(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function jr(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if($t(e.outputLen),$t(e.blockLen),e.outputLen<1||e.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var Ji=(e,t)=>{if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError((t==="object"?"":`"${t}" `)+"expected object, got type="+typeof e)};function Ne(e,t=!0){if(e.destroyed)throw new Error("hash was destroyed");if(t&&e.finished)throw new Error("digest() was already called")}function Yr(e,t){It(e,void 0,"output");let r=t.outputLen;if(!(e.length>=r))throw new RangeError('"output" expected length >= '+r)}function ye(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Zr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function kt(e,t){return e<<32-t|e>>>t}var ea=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",qf=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Gr(e){if(It(e),ea)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=qf[e[r]];return t}function ta(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function Xr(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(ea)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=ta(e.charCodeAt(s)),a=ta(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 zo(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];It(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 zf(e,t,r="opts"){return Ji(e,"defaults"),t!==void 0&&Ji(t,r),Object.assign(e,t)}function Ho(e,t={}){if(typeof e!="function")throw new TypeError('"hashCons" expected function, got type='+typeof e);t=zf({},t,"info");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 ra(e=32){$t(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 Vo=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function na(e,t,r){return e&t^~e&r}function oa(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=Zr(this.buffer)}update(t){Ne(this),It(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length,i=!1;for(let a=0;a<s;){let c=Math.min(o-this.pos,s-a);if(c===o){let f=Zr(t);for(;o<=s-a;a+=o)this.process(f,a);i=!0;continue}n.set(a===0&&c===s?t:t.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===o&&(this.process(r,0),this.pos=0,i=!0)}return this.length+=t.length,i&&this.roundClean(),this}digestInto(t){Ne(this),Yr(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,r.fill(0,i),this.padOffset>o-i&&(this.process(n,0),r.fill(0)),Wi(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let a=t===r?n:Zr(t),c=this.outputLen,f=c/4,u=this.get();if(c%4||f>u.length)throw new Error("invalid outputLen");for(let d=0;d<f;d++)a.setUint32(4*d,u[d],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneIntoMeta(t){let{buffer:r,length:n,finished:o,destroyed:s,pos:i}=this;return t.destroyed=s,t.finished=o,t.length=n,t.pos=i,i&&t.buffer.set(r),t}clone(){return this._cloneInto()}},sa=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ia=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Hf=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]),re=new Uint32Array(64),$o=class extends lr{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(t,r){super(64,t,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}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}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,r){for(let d=0;d<16;d++,r+=4)re[d]=t.getUint32(r,!1);for(let d=16;d<64;d++){let l=re[d-15],h=re[d-2],w=kt(l,7)^kt(l,18)^l>>>3,g=kt(h,17)^kt(h,19)^h>>>10;re[d]=g+re[d-7]+w+re[d-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:f,H:u}=this;for(let d=0;d<64;d++){let l=kt(a,6)^kt(a,11)^kt(a,25),h=u+l+na(a,c,f)+Hf[d]+re[d]|0,g=(kt(n,2)^kt(n,13)^kt(n,22))+oa(n,o,s)|0;u=f,f=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,f=f+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,c,f,u)}roundClean(){ye(re)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),ye(this.buffer)}},Wo=class extends $o{constructor(){super(32,sa)}};var aa=$i(["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))),Vf=aa[0],$f=aa[1],ne=new Uint32Array(80),oe=new Uint32Array(80),jo=class extends lr{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(t,r){super(128,t,16,!1),this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:f,El:u,Fh:d,Fl:l,Gh:h,Gl:w,Hh:g,Hl:b}=this;return[t,r,n,o,s,i,a,c,f,u,d,l,h,w,g,b]}set(t,r,n,o,s,i,a,c,f,u,d,l,h,w,g,b){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=f|0,this.El=u|0,this.Fh=d|0,this.Fl=l|0,this.Gh=h|0,this.Gl=w|0,this.Hh=g|0,this.Hl=b|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,r){for(let y=0;y<16;y++,r+=4)ne[y]=t.getUint32(r),oe[y]=t.getUint32(r+=4);for(let y=16;y<80;y++){let B=ne[y-15]|0,_=oe[y-15]|0,U=pe(B,_,1)^pe(B,_,8)^Mo(B,_,7),M=me(B,_,1)^me(B,_,8)^Fo(B,_,7),P=ne[y-2]|0,O=oe[y-2]|0,k=pe(P,O,19)^ur(P,O,61)^Mo(P,O,6),F=me(P,O,19)^fr(P,O,61)^Fo(P,O,6),D=Zi(M,F,oe[y-7],oe[y-16]),G=Gi(D,U,k,ne[y-7],ne[y-16]);ne[y]=G|0,oe[y]=D|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:f,Dl:u,Eh:d,El:l,Fh:h,Fl:w,Gh:g,Gl:b,Hh:x,Hl:S}=this;for(let y=0;y<80;y++){let B=pe(d,l,14)^pe(d,l,18)^ur(d,l,41),_=me(d,l,14)^me(d,l,18)^fr(d,l,41),U=d&h^~d&g,M=l&w^~l&b,P=Xi(S,_,M,$f[y],oe[y]),O=Qi(P,x,B,U,Vf[y],ne[y]),k=P|0,F=pe(n,o,28)^ur(n,o,34)^ur(n,o,39),D=me(n,o,28)^fr(n,o,34)^fr(n,o,39),G=n&s^n&a^s&a,C=o&i^o&c^i&c;x=g|0,S=b|0,g=h|0,b=w|0,h=d|0,w=l|0,{h:d,l}=qt(f|0,u|0,O|0,k|0),f=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let R=ji(k,D,C);n=Yi(R,O,F,G),o=R|0}({h:n,l:o}=qt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=qt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=qt(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=qt(this.Dh|0,this.Dl|0,f|0,u|0),{h:d,l}=qt(this.Eh|0,this.El|0,d|0,l|0),{h,l:w}=qt(this.Fh|0,this.Fl|0,h|0,w|0),{h:g,l:b}=qt(this.Gh|0,this.Gl|0,g|0,b|0),{h:x,l:S}=qt(this.Hh|0,this.Hl|0,x|0,S|0),this.set(n,o,s,i,a,c,f,u,d,l,h,w,g,b,x,S)}roundClean(){ye(ne,oe)}destroy(){this.destroyed=!0,ye(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Yo=class extends jo{constructor(){super(64,ia)}};var Ue=Ho(()=>new Wo,Vo(1));var Zo=Ho(()=>new Yo,Vo(3));function Jr(e,t,r=()=>{}){if(!Array.isArray(e))throw new TypeError(`"${t}" expected array, got type=${typeof e}`);for(let n=0;n<e.length;n++)r(e[n],`${t}[${n}]`);return e}var W=(e,t,r)=>It(e,t,r),Go=$t;function ua(e,t=""){if(typeof e!="string"){let r=t&&`"${t}" `;throw new TypeError(r+"expected string, got type="+typeof e)}return e}function se(e,t="object"){if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError(t==="object"?"expected valid options object":`"${t}" expected object, got type=${typeof e}`);return e}function be(e,t){if(typeof e!="function")throw new TypeError(`"${t}" is invalid: expected function, got ${typeof e}`);return e}var dr=Gr,Rt=(...e)=>zo(...e),Me=e=>Xr(e),ae=Wr,ge=e=>ra(e),Qr=BigInt(0),ca=BigInt(1),Wf=e=>e?`"${e}" `:"";function vt(e,t=""){if(typeof e!="boolean")throw new TypeError(Wf(t)+"expected boolean, got type="+typeof e);return e}function tn(e){if(typeof e=="bigint"){if(!ie(e))throw new RangeError("positive bigint expected, got "+e)}else Go(e);return e}function ce(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 hr(e){let t=tn(e).toString(16);return t.length&1?"0"+t:t}function fa(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?Qr:BigInt("0x"+e)}function zt(e){return fa(Gr(e))}function we(e){return fa(Gr(rn(It(e)).reverse()))}function en(e,t){if($t(t),t===0)throw new Error("zero output length is invalid");e=tn(e);let r=t*2,n=e.toString(16);if(n.length>r)throw new RangeError("number is too large");return Xr(n.padStart(r,"0"))}function Xo(e,t){return en(e,t).reverse()}function rn(e){return Uint8Array.from(W(e))}function ie(e){return typeof e=="bigint"&&Qr<=e}function Qo(e,t,r){return ie(e)&&ie(t)&&ie(r)&&t<=e&&e<r}function Fe(e,t,r,n){if(!Qo(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function qe(e){if(e<Qr)throw new Error("expected non-negative bigint, got "+e);return e===Qr?0:e.toString(2).length}var pr=e=>(ce(e,"n"),(ca<<BigInt(e))-ca);function la(e,t,r){if($t(e,"hashLen"),$t(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=b=>new Uint8Array(b),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(e),f=n(e),u=0,d=()=>{c.fill(1),f.fill(0),u=0},l=(...b)=>r(f,Rt(c,...b)),h=(b=o)=>{f=l(s,b),c=l(),b.length!==0&&(f=l(i,b),c=l())},w=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let b=0,x=[];for(;b<t;){c=l();let S=c.slice();x.push(S),b+=c.length}return Rt(...x)};return(b,x)=>{d(),h(b);let S;for(;(S=x(w()))===void 0;)h();return d(),S}}function St(e,t={},r={},n="object"){se(e,n),se(t,"fields"),se(r,"optFields");function o(i,a,c){let f=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,u=e[i];if(!Object.hasOwn(e,i)&&(c?u!==void 0:a!=="function"))throw new TypeError(`${f} is invalid: expected own property`);if(c&&u===void 0)return;let d=typeof u;if(d!==a||u===null)throw new TypeError(`${f} is invalid: expected ${a}, got ${d}`)}let s=(i,a)=>Object.entries(i).forEach(([c,f])=>o(c,f,a));s(t,!1),s(r,!0)}var it=BigInt(0),j=BigInt(1),ue=BigInt(2),pa=BigInt(3),Jo=BigInt(4),ma=BigInt(5),jf=BigInt(7),ya=BigInt(8),Yf=BigInt(9),Zf=BigInt(15),ba=BigInt(16),Gf=BigInt("0x10000000000000000");function Q(e,t){if(t<=it)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=it?r:t+r}function ga(e,t,r){if(r<=j)throw new Error("pow: expected modulus > 1, got "+r);if(typeof t!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof t);if(t<it)throw new Error("invalid exponent, negatives unsupported");if(t===it)return j;if(t===j)return e;let n=e%r;if(n<it&&(n+=r),t<Gf){let a=j;for(;t>it;)t&j&&(a=a*n%r),n=n*n%r,t>>=j;return a}let o=[];for(;t>it;)o.push(Number(t&Zf)),t>>=Jo;let s=new Array(16);s[0]=j,s[1]=n;for(let a=2;a<16;a++)s[a]=s[a-1]*n%r;let i=s[o[o.length-1]];for(let a=o.length-2;a>=0;a--){i=i*i%r,i=i*i%r,i=i*i%r,i=i*i%r;let c=o[a];c!==0&&(i=i*s[c]%r)}return i}function X(e,t,r){if(r<=j)throw new Error("pow2: expected modulus > 1, got "+r);if(t<it)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >it;)n*=n,n%=r;return n}function da(e,t){if(e===it)throw new Error("invert: expected non-zero number");if(t<=j)throw new Error("invert: expected modulus > 1, got "+t);let r=Q(e,t),n=t,o=it,s=j;for(;r!==it;){let a=n/r,c=n-r*a,f=o-s*a;n=r,r=c,o=s,s=f}if(n!==j)throw new Error("invert: does not exist");return Q(o,t)}function wa(e,t){if(t<=j)throw new Error("invertCt: expected prime modulus > 1, got "+t);let r=Q(e,t);if(r===it)throw new Error("invertCt: expected non-zero number");let n=ga(r,t-ue,t);if(Q(r*n,t)!==j)throw new Error("invertCt: does not exist");return n}function ts(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function es(e,t){if((e&j)===it)throw new Error(t+": expected odd modulus, got "+e)}function xa(e,t){let r=e,n=(r.ORDER+j)/Jo,o=r.pow(t,n);return ts(r,o,t),o}function Xf(e,t){let r=e,n=(r.ORDER-ma)/ya,o=r.mul(t,ue),s=r.pow(o,n),i=r.mul(t,s),a=r.mul(r.mul(i,ue),s),c=r.mul(i,r.sub(a,r.ONE));return ts(r,c,t),c}function Qf(e){let t=He(e),r=Ea(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+jf)/ba;return((a,c)=>{let f=a,u=f.pow(c,i),d=f.mul(u,n),l=f.mul(u,o),h=f.mul(u,s),w=f.eql(f.sqr(d),c),g=f.eql(f.sqr(l),c);u=f.cmov(u,d,w),d=f.cmov(h,l,g);let b=f.eql(f.sqr(d),c),x=f.cmov(u,d,b);return ts(f,x,c),x})}function Ea(e){if(e<pa)throw new Error("sqrt is not defined for small field");es(e,"tonelliShanks");let t=e-j,r=0;for(;t%ue===it;)t/=ue,r++;let n=ue,o=He(e);for(;mr(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return xa;let s=o.pow(n,t),i=(t+j)/ue;return function(c,f){let u=c;if(u.is0(f))return f;if(mr(u,f)!==1)throw new Error("Cannot find square root");let d=r,l=u.mul(u.ONE,s),h=u.pow(f,t),w=u.pow(f,i);for(;!u.eql(h,u.ONE);){if(u.is0(h))throw new Error("Cannot find square root: probably non-prime P");let g=1,b=u.sqr(h);for(;!u.eql(b,u.ONE);)if(g++,b=u.sqr(b),g===d)throw new Error("Cannot find square root");let x=j<<BigInt(d-g-1),S=u.pow(l,x);d=g,l=u.sqr(S),h=u.mul(h,l),w=u.mul(w,S)}return w}}function Jf(e){return es(e,"Fp.sqrt"),e%Jo===pa?xa:e%ya===ma?Xf:e%ba===Yf?Qf(e):Ea(e)}var va=(e,t)=>(Q(e,t)&j)===j,tl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ze(e){if(se(e,"field"),typeof e.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof e.ORDER);ce(e.BYTES,"BYTES"),ce(e.BITS,"BITS");for(let t of tl)be(e[t],"field."+t);if(e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=j)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function on(e,t,r=!1){ze(e),Jr(t,"nums"),vt(r,"passZero");let n=e,o=new Array(t.length).fill(r?n.ZERO:void 0),s=t.reduce((a,c,f)=>n.is0(c)?a:(o[f]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return t.reduceRight((a,c,f)=>n.is0(c)?a:(o[f]=n.mul(a,o[f]),n.mul(a,c)),i),o}function mr(e,t){ze(e);let r=e;es(r.ORDER,"FpLegendre");let n=(r.ORDER-j)/ue,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 el(e,t){if(t!==void 0&&Go(t),e<=it)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=qe(e);if(t!==void 0&&t<r)throw new Error(`invalid n length: expected nBitLength (${t}) >= bitLen(n) (${r})`);let n=t!==void 0?t:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var ha=new WeakMap,nn=class{ORDER;BITS;BYTES;isLE;ZERO=it;ONE=j;_lengths;_mod;constructor(t,r={}){if(t<=j)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}=el(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 Q(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return it<=t&&t<this.ORDER}is0(t){return t===it}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&j)===j}neg(t){return Q(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return Q(t*t,this.ORDER)}add(t,r){return Q(t+r,this.ORDER)}sub(t,r){return Q(t-r,this.ORDER)}mul(t,r){return Q(t*r,this.ORDER)}pow(t,r){return ga(t,r,this.ORDER)}div(t,r){return Q(t*da(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 da(t,this.ORDER)}sqrt(t){let r=ha.get(this);return r||ha.set(this,r=Jf(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?Xo(t,this.BYTES):en(t,this.BYTES)}fromBytes(t,r=!1){W(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 f=new Uint8Array(o);f.set(t,s?0:f.length-t.length),t=f}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=s?we(t):zt(t);if(a&&(c=Q(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return on(this,t,!0)}cmov(t,r,n){return vt(n,"condition"),n?r:t}};function He(e,t={}){return Object.freeze(nn.prototype),new nn(e,t)}function Sa(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=j)throw new Error("field order must be greater than 1");let t=qe(e-j);return Math.ceil(t/8)}function sn(e){let t=Sa(e);return t+Math.ceil(t/2)}function an(e,t,r=!1){W(e);let n=e.length,o=Sa(t),s=Math.max(sn(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?we(e):zt(e),a=Q(i,t-j)+j;return r?Xo(a,o):en(a,o)}var os=BigInt(0),yr=BigInt(1),rl=BigInt(4),rs=16,Aa=128,nl=5,Ba=2**31;function fe(e){let t=e;if(typeof t!="function")throw new TypeError('"Point" expected constructor, got type='+typeof e);be(t.fromAffine,"Point.fromAffine"),be(t.fromBytes,"Point.fromBytes"),be(t.fromHex,"Point.fromHex"),se(t.BASE,"Point.BASE"),se(t.ZERO,"Point.ZERO"),ze(t.Fp),ze(t.Fn)}function cn(e,t){fe(e),_a(t,e);let r=on(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function ol(e,t,r=1){if(!Number.isSafeInteger(e)||e<r||e>t)throw new Error("invalid window size, expected ["+r+".."+t+"], got W="+e)}function sl(e,t){let r=e*(4*t+128);if(r>Ba)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+Ba/2**20+" MiB")}function ss(e,t){if(e!==void 0){be(e,"randomBytes");try{let r=e(t);if(!ae(r)||r.length!==t)return}catch{return}return e}}function _a(e,t){Jr(e,"points"),e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function il(e,t,r){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((n,o)=>{if(!(r===void 0?t.isValid(n):ie(n)&&n<r))throw new Error("invalid scalar at index "+o)})}var Ia=new WeakMap;function ns(e){return Ia.get(e)||1}function al(e,t){let r=e.double(),n=[e];for(let o=1;o<t;o++)n.push(n[o-1].add(r));return n}function cl(e,t){let r=2**t,n=r/2,o=BigInt(r-1),s=[];for(;e>os;){let i=0;e&yr&&(i=Number(e&o),i>=n&&(i-=r),e-=BigInt(i)),s.push(i),e>>=yr}return s}function ul(e,t,r){let n=2**t,o=n/2,s=BigInt(n-1),i=BigInt(t),a=[];for(let c=0;c<r;c++){let f=Number(e&s);e>>=i,f>o&&(f-=n,e+=yr),a.push(f)}if(e!==os)throw new Error("invalid wnaf");return a}function fl(e,t,r){let n=0;for(let s of r)n=Math.max(n,s.length);let o=e;for(let s=n-1;s>=0;s--){s!==n-1&&(o=o.double());for(let i=0;i<r.length;i++){let a=r[i][s];if(a){let c=t[i][Math.abs(a)-1>>1];o=o.add(a<0?c.negate():c)}}}return o}var Ve=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(t,r){fe(t),this.randomBytes=ss(r,rs),this.Point=t,this.BASE=t.BASE,this.ZERO=t.ZERO,this.bits=t.Fn.BITS}buildWnafTable(t,r,n){let o=Math.ceil(n/r)+1,s=2**(r-1),i=[],a=t;for(let c=0;c<o;c++){let f=a;for(let u=0;u<s;u++)i.push(f),f=f.add(a);a=i[i.length-1].double()}return{W:r,bits:n,windows:o,comp:i}}wnafCachedCT(t,r){let{W:n,windows:o,comp:s}=t,i=2**(n-1),a=ul(r,n,o),c=this.ZERO,f=this.BASE;for(let u=0;u<o;u++){let d=a[u],l=u*i,h=Math.abs(d)-1,w=s[l];for(let b=1;b<i;b++)w=b===h?s[l+b]:w;let g=w.negate();d===0?f=f.add(s[l]):c=c.add(d<0?g:w)}return{p:c,f}}getWnafPrecomputes(t,r,n,o){let s=this.wnafPrecomputes.get(r),i=s?.find(a=>a.W===t&&a.bits===n);return i||(i=this.buildWnafTable(r,t,n),typeof o=="function"&&(i={...i,comp:o(i.comp)}),s||(s=[],this.wnafPrecomputes.set(r,s)),s.push(i)),i}assertPoint(t){if(!(t instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof t)}validateMulInput(t,r){if(this.assertPoint(t),!Qo(r,yr,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(t,r,n,o){let s=ns(t);return s===1?this.fixedWindowCT(t,r,n):this.wnafCachedCT(this.getWnafPrecomputes(s,t,n,o),r)}mulCT(t,r,n){return this.validateMulInput(t,r),this.runCT(t,r,this.bits,n)}mulCTBlinded(t,r,n){if(this.validateMulInput(t,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let o=this.Point.Fn.BITS+Aa,s=this.randomBytes(rs);if(!ae(s)||s.length!==rs)throw new Error("randomBytes returned invalid byte array");s[0]=s[0]&63|128;let i=r+zt(s)*this.Point.Fn.ORDER;return this.runCT(t,i,o,n)}fixedWindowCT(t,r,n){let o=nl,s=1<<o,i=pr(o),a=new Array(s);a[0]=this.ZERO;for(let u=1;u<s;u++)a[u]=a[u-1].add(t);let c=Math.ceil(n/o),f=this.ZERO;for(let u=c-1;u>=0;u--){if(u!==c-1)for(let h=0;h<o;h++)f=f.double();let d=Number(r>>BigInt(u*o)&i),l=a[0];for(let h=1;h<s;h++)l=h===d?a[h]:l;f=f.add(l)}return{p:f,f}}shouldBlind(t,r){return this.randomBytes===void 0?!1:r===yr?!0:t!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(t,r,n,o){return this.shouldBlind(t,n)?this.mulCTBlinded(t,r,o):this.mulCT(t,r,o)}mulUnsafe(t,r,n){if(this.assertPoint(t),!ie(r))throw new Error("invalid scalar");let o=ns(t);if(o===1||r>=this.Point.Fn.ORDER)return un(this.Point,[t],[r],!0);let s=this.getWnafPrecomputes(o,t,this.bits,n);return this.wnafCachedCT(s,r).p}setWindowSize(t,r){this.assertPoint(t),ol(r,this.bits);let n=Math.ceil((this.bits+Aa)/r)+1;sl(n*2**(r-1),this.Point.Fp.BYTES),Ia.set(t,r),this.wnafPrecomputes.delete(t)}hasWindowSize(t){return ns(t)!==1}};function un(e,t,r,n=!1){if(fe(e),_a(t,e),vt(n,"allowOversized"),il(r,e.Fn,n?e.Fn.ORDER**rl:void 0),t.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=t.map(i=>al(i,4)),s=r.map(i=>cl(i,4));return fl(e.ZERO,o,s)}function Ta(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ze(t),t}else return He(e,{isLE:r})}function fn(e,t,r={},n){if(e!=="weierstrass"&&e!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);St(r);for(let c of["p","n","h"]){let f=t[c];if(!(ie(f)&&f!==os))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Ta(t.p,r.Fp,n),s=Ta(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 ln(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var dn=BigInt(0),hn=BigInt(1),pn=BigInt(2),ll=BigInt(4),Ra=BigInt(8);function dl(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 Ca(e,t={}){St(t,{},{},"extraOpts");let r=t,n=fn("edwards",e,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;if(mr(o,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(mr(o,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");St(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?ge:r.randomBytes,f=pn<<BigInt(o.BYTES*8)-hn;function u(S){if(!o.isOdd)throw new Error("Field does not have .isOdd()");return o.isOdd(S)}let d=r.uvRatio===void 0?(S,y)=>{try{return{isValid:!0,value:o.sqrt(o.div(S,y))}}catch{return{isValid:!1,value:dn}}}:r.uvRatio;if(!dl(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let l=o.eql(i.a,o.neg(o.ONE))?S=>o.neg(S):o.eql(i.a,o.ONE)?S=>S:S=>o.mul(i.a,S);function h(S,y,B=!1){let _=B?hn:dn;return Fe("coordinate "+S,y,_,f),y}function w(S){if(!(S instanceof g))throw new Error("EdwardsPoint expected")}class g{static BASE=new g(i.Gx,i.Gy,o.ONE,o.mul(i.Gx,i.Gy));static ZERO=new g(o.ZERO,o.ONE,o.ONE,o.ZERO);static Fp=o;static Fn=s;X;Y;Z;T;constructor(y,B,_,U){this.X=h("x",y),this.Y=h("y",B),this.Z=h("z",_,!0),this.T=h("t",U),Object.freeze(this)}static CURVE(){return i}static fromAffine(y){if(y instanceof g)throw new Error("extended point not allowed");let{x:B,y:_}=y||{};return h("x",B),h("y",_),new g(B,_,o.ONE,o.mul(B,_))}static fromBytes(y,B=!1){let _=o.BYTES,{a:U,d:M}=i;y=rn(W(y,_,"point")),vt(B,"zip215");let P=rn(y),O=y[_-1];P[_-1]=O&-129;let k=we(P),F=B?f:o.ORDER;Fe("point.y",k,dn,F);let D=o.sqr(k),G=o.sub(D,o.ONE),C=o.sub(o.mulN(M,D),U),{isValid:R,value:p}=d(G,C);if(!R)throw new Error("bad point: invalid y coordinate");let E=u(p),A=(O&128)!==0;if(!B&&o.is0(p)&&A)throw new Error("bad point: x=0 and x_0=1");return A!==E&&(p=o.neg(p)),g.fromAffine({x:p,y:k})}static fromHex(y,B=!1){return g.fromBytes(Me(y),B)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=6,B=!0){return x.setWindowSize(this,y),B||this.multiply(pn),this}assertValidity(){let y=this,{a:B,d:_}=i;if(y.is0())throw new Error("bad point: ZERO");let{X:U,Y:M,Z:P,T:O}=y,k=o.sqr(U),F=o.sqr(M),D=o.sqr(P),G=o.sqr(D),C=o.mul(k,B),R=o.mul(o.add(C,F),D),p=o.add(G,o.mul(_,o.mul(k,F)));if(!o.eql(R,p))throw new Error("bad point: equation left != right (1)");let E=o.mul(U,M),A=o.mul(P,O);if(!o.eql(E,A))throw new Error("bad point: equation left != right (2)")}equals(y){w(y);let{X:B,Y:_,Z:U}=this,{X:M,Y:P,Z:O}=y,k=o.mul(B,O),F=o.mul(M,U),D=o.mul(_,O),G=o.mul(P,U);return o.eql(k,F)&&o.eql(D,G)}is0(){return this.equals(g.ZERO)}negate(){return new g(o.neg(this.X),this.Y,this.Z,o.neg(this.T))}double(){let{X:y,Y:B,Z:_}=this,U=o.sqr(y),M=o.sqr(B),P=o.mul(o.sqr(_),pn),O=l(U),k=o.addN(y,B),F=o.sub(o.subN(o.sqr(k),U),M),D=o.addN(O,M),G=o.subN(D,P),C=o.subN(O,M),R=o.mul(F,G),p=o.mul(D,C),E=o.mul(F,C),A=o.mul(G,D);return new g(R,p,A,E)}add(y){w(y);let{d:B}=i,{X:_,Y:U,Z:M,T:P}=this,{X:O,Y:k,Z:F,T:D}=y,G=o.mul(_,O),C=o.mul(U,k),R=o.mul(o.mulN(P,B),D),p=o.mul(M,F),E=o.sub(o.subN(o.mulN(o.addN(_,U),o.addN(O,k)),G),C),A=o.subN(p,R),L=o.addN(p,R),v=o.sub(C,l(G)),m=o.mul(E,A),T=o.mul(L,v),I=o.mul(E,v),K=o.mul(A,L);return new g(m,T,K,I)}subtract(y){return w(y),this.add(y.negate())}multiply(y){if(!s.isValidNot0(y))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:B,f:_}=x.mulSecret(this,y,a,b);return b([B,_])[0]}multiplyUnsafe(y){if(!s.isValid(y))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return y===dn?g.ZERO:this.is0()||y===hn?this:x.mulUnsafe(this,y,b)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return x.mulUnsafe(this,i.n).is0()}toAffine(y){let B=this,_=y;if(_!=null&&typeof _!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof _);let{X:U,Y:M,Z:P}=B,O=B.is0();_==null&&(_=O?o.create(Ra):o.inv(P));let k=o.mul(U,_),F=o.mul(M,_),D=o.mul(P,_);if(O)return{x:o.ZERO,y:o.ONE};if(!o.eql(D,o.ONE))throw new Error("invZ was invalid");return{x:k,y:F}}clearCofactor(){return a===hn?this:a===pn?this.double():a===ll?this.double().double():a===Ra?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:y,y:B}=this.toAffine(),_=o.toBytes(B);return _[_.length-1]|=u(y)?128:0,_}toHex(){return dr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let b=S=>cn(g,S),x=new Ve(g,c);return x.bits>=6&&g.BASE.precompute(6),Object.freeze(g.prototype),Object.freeze(g),g}function Da(e,t,r={}){if(fe(e),typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=r;St(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=e,f=n.outputLen,u=2*a.BYTES;if(f!==void 0&&(ce(f,"hash.outputLen"),f!==u))throw new Error(`hash.outputLen must be ${u}, got ${f}`);let d=o.randomBytes===void 0?ge:o.randomBytes,l=o.toMontgomery,h=o.toMontgomerySecret,w=o.adjustScalarBytes===void 0?C=>C:o.adjustScalarBytes,g=o.domain===void 0?(C,R,p)=>{if(vt(p,"phflag"),R.length||p)throw new Error("Contexts/pre-hash are not supported");return C}:o.domain;function b(C){return c.create(we(C))}function x(C){let R=O.secretKey;W(C,O.secretKey,"secretKey");let p=W(n(C),2*R,"hashedSecretKey"),E=w(p.slice(0,R)),A=p.slice(R,2*R),L=b(E);return{head:E,prefix:A,scalar:L}}function S(C){let{head:R,prefix:p,scalar:E}=x(C),A=i.multiply(E),L=A.toBytes();return{head:R,prefix:p,scalar:E,point:A,pointBytes:L}}function y(C){return S(C).pointBytes}function B(C=Uint8Array.of(),...R){let p=Rt(...R);return b(n(g(p,W(C,void 0,"context"),!!s)))}function _(C,R,p={}){St(p,{},{},"options"),C=W(C,void 0,"message"),s&&(C=s(C));let{prefix:E,scalar:A,pointBytes:L}=S(R),v=B(p.context,E,C),m=i.multiply(v).toBytes(),T=B(p.context,m,L,C),I=c.create(v+T*A);if(!c.isValid(I))throw new Error("sign failed: invalid s");let K=Rt(m,c.toBytes(I));return W(K,O.signature,"result")}let U={zip215:o.zip215};function M(C,R,p,E=U){St(E);let{context:A}=E,L=E.zip215===void 0?!!U.zip215:E.zip215,v=O.signature;C=W(C,v,"signature"),R=W(R,void 0,"message"),p=W(p,O.publicKey,"publicKey"),L!==void 0&&vt(L,"zip215"),s&&(R=s(R));let m=v/2,T=C.subarray(0,m),I=we(C.subarray(m,v)),K,N,$;try{K=e.fromBytes(p,L),N=e.fromBytes(T,L),$=i.multiplyUnsafe(I)}catch{return!1}if(!L&&K.isSmallOrder())return!1;let H=B(A,T,p,R);return N.add(K.multiplyUnsafe(H)).subtract($).clearCofactor().is0()}let P=a.BYTES,O={secretKey:P,publicKey:P,signature:2*P,seed:P};function k(C){return C=C===void 0?d(O.seed):C,W(C,O.seed,"seed")}function F(C){return ae(C)&&C.length===O.secretKey}function D(C,R){try{return!!e.fromBytes(C,R===void 0?U.zip215:R)}catch{return!1}}let G={getExtendedPublicKey:S,randomSecretKey:k,isValidSecretKey:F,isValidPublicKey:D,toMontgomery(C){if(l===void 0)throw new Error("Montgomery conversion is not supported for this curve");return l(e.fromBytes(C))},toMontgomerySecret(C){if(h===void 0)throw new Error("Montgomery conversion is not supported for this curve");return h(C)}};return Object.freeze(O),Object.freeze(G),Object.freeze({keygen:ln(k,y),getPublicKey:y,sign:_,verify:M,utils:G,Point:e,lengths:O})}var is=BigInt(1),La=BigInt(2);var hl=BigInt(5),pl=BigInt(8),as=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),ml={p:as,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:pl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function yl(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=as,a=e*e%s*e%s,c=X(a,La,s)*a%s,f=X(c,is,s)*e%s,u=X(f,hl,s)*f%s,d=X(u,t,s)*u%s,l=X(d,r,s)*d%s,h=X(l,n,s)*l%s,w=X(h,o,s)*h%s,g=X(w,o,s)*h%s,b=X(g,t,s)*u%s;return{pow_p_5_8:X(b,La,s)*e%s,b2:a}}function Pa(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Oa=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function bl(e,t){let r=as,n=Q(t*t*t,r),o=Q(n*n*t,r),s=yl(e*o).pow_p_5_8,i=Q(e*n*s,r),a=Q(t*i*i,r),c=i,f=Q(i*Oa,r),u=a===e,d=a===Q(-e,r),l=a===Q(-e*Oa,r);return u&&(i=c),(d||l)&&(i=f),va(i,r)&&(i=Q(-i,r)),{isValid:u||d,value:i}}var cs=Ca(ml,{uvRatio:bl}),ka=cs.Fp;function gl(e){let{y:t}=e;return ka.toBytes(ka.div(is+t,is-t))}function wl(e){let t=cs.Fp.BYTES;return It(e,t),Pa(Zo(e.subarray(0,t))).subarray(0,t)}function xl(e){return Da(cs,Zo,Object.assign({adjustScalarBytes:Pa,toMontgomery:gl,toMontgomerySecret:wl,zip215:!0},e))}var Ka=xl({});var br=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},mn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Ct={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new mn("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 yn=32;var us,El=(async()=>{try{return await Ct.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function vl(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Ct.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Ct.get().subtle.verify({name:"Ed25519"},n,pt(t),pt(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Sl(e,t,r){return Ka.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Na(e,t,r){return us==null&&(us=await El),us?vl(e,t,r):Sl(e,t,r)}function bn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var gn=class{type="Ed25519";raw;constructor(t){this.raw=fs(t,yn)}toMultihash(){return Ot.digest(_t(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return nt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Z(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Na(this.raw,r,t);return bn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function ls(e){return e=fs(e,yn),new gn(e)}function fs(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new q(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Bl=Math.pow(2,7),Tl=Math.pow(2,14),_l=Math.pow(2,21),ds=Math.pow(2,28),hs=Math.pow(2,35),ps=Math.pow(2,42),ms=Math.pow(2,49),Y=128,lt=127;function Dt(e){if(e<Bl)return 1;if(e<Tl)return 2;if(e<_l)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 $e(e,t,r=0){switch(Dt(e)){case 8:t[r++]=e&255|Y,e/=128;case 7:t[r++]=e&255|Y,e/=128;case 6:t[r++]=e&255|Y,e/=128;case 5:t[r++]=e&255|Y,e/=128;case 4:t[r++]=e&255|Y,e>>>=7;case 3:t[r++]=e&255|Y,e>>>=7;case 2:t[r++]=e&255|Y,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Il(e,t,r=0){switch(Dt(e)){case 8:t.set(r++,e&255|Y),e/=128;case 7:t.set(r++,e&255|Y),e/=128;case 6:t.set(r++,e&255|Y),e/=128;case 5:t.set(r++,e&255|Y),e/=128;case 4:t.set(r++,e&255|Y),e>>>=7;case 3:t.set(r++,e&255|Y),e>>>=7;case 2:t.set(r++,e&255|Y),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<Y||(r=e[t+1],n+=(r<)<<7,r<Y)||(r=e[t+2],n+=(r<)<<14,r<Y)||(r=e[t+3],n+=(r<)<<21,r<Y)||(r=e[t+4],n+=(r<)*ds,r<Y)||(r=e[t+5],n+=(r<)*hs,r<Y)||(r=e[t+6],n+=(r<)*ps,r<Y)||(r=e[t+7],n+=(r<)*ms,r<Y))return n;throw new RangeError("Could not decode varint")}function Rl(e,t){let r=e.get(t),n=0;if(n+=r<,r<Y||(r=e.get(t+1),n+=(r<)<<7,r<Y)||(r=e.get(t+2),n+=(r<)<<14,r<Y)||(r=e.get(t+3),n+=(r<)<<21,r<Y)||(r=e.get(t+4),n+=(r<)*ds,r<Y)||(r=e.get(t+5),n+=(r<)*hs,r<Y)||(r=e.get(t+6),n+=(r<)*ps,r<Y)||(r=e.get(t+7),n+=(r<)*ms,r<Y))return n;throw new RangeError("Could not decode varint")}function wn(e,t,r=0){return t==null&&(t=ft(Dt(e))),t instanceof Uint8Array?$e(e,t,r):Il(e,t,r)}function bs(e,t=0){return e instanceof Uint8Array?ys(e,t):Rl(e,t)}var gs=new Float32Array([-0]),le=new Uint8Array(gs.buffer);function Fa(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 qa(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 za(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 Ha(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 Cl=BigInt(Number.MAX_SAFE_INTEGER),Dl=BigInt(Number.MIN_SAFE_INTEGER),At=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 xe;if(t<Cl&&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>Va&&(o=0n,++n>Va&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return xe;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):xe}},xe=new At(0,0);xe.toBigInt=function(){return 0n};xe.zzEncode=xe.zzDecode=function(){return this};xe.length=function(){return 1};var Va=4294967296n;function $a(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 Wa(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 Pt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function xn(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=pt(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,Pt(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 Pt(this,4);return xn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Pt(this,4);return xn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Pt(this,4);let t=qa(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Pt(this,4);let t=Ha(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 Pt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Wa(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Pt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Pt(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 At(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 Pt(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 Pt(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 Pt(this,8);let t=xn(this.buf,this.pos+=4),r=xn(this.buf,this.pos+=4);return new At(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+=Dt(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 gr(e){return new Es(e instanceof Uint8Array?e:e.subarray())}function yt(e,t,r){let n=gr(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 ft(i);o+i>t&&(n=ft(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Ee=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 Bs=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Ll=vs();function Ol(e){return globalThis.Buffer!=null?ft(e):Ll(e)}var xr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ee(Ss,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new Ee(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(En,10,At.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=At.fromBigInt(t);return this._push(En,r.length(),r)}uint64Number(t){return this._push($e,Dt(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=At.fromBigInt(t).zzEncode();return this._push(En,r.length(),r)}sint64Number(t){let r=At.fromNumber(t).zzEncode();return this._push(En,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(wr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=At.fromBigInt(t);return this._push(wr,4,r.lo)._push(wr,4,r.hi)}fixed64Number(t){let r=At.fromNumber(t);return this._push(wr,4,r.lo)._push(wr,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(Fa,4,t)}double(t){return this._push(za,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(As,1,0):this.uint32(r)._push(Pl,r,t)}string(t){let r=$a(t);return r!==0?this.uint32(r)._push(xs,r,t):this._push(As,1,0)}fork(){return this.states=new Bs(this),this.head=this.tail=new Ee(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 Ee(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=Ol(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 kl(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Ts=class extends Ee{next;constructor(t,r){super(kl,t,r),this.next=void 0}};function En(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 wr(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 Pl(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(xr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Kl,t,e),this},xr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Nl,t,e),this});function Kl(e,t,r){t.set(e,r)}function Nl(e,t,r){e.length<40?xs(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(V(e),r)}function _s(){return new xr}function bt(e,t){let r=_s();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*gt(e,t,r){let n=gr(e);yield*t.stream(n,void 0,"$",r)}var vn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Sn(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function Is(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 Sn("enum",vn.VARINT,r,n,o)}function wt(e,t,r){return Sn("message",vn.LENGTH_DELIMITED,e,t,r)}var Lt=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},Er=class extends Error{code="ERR_MAX_SIZE";name="MaxSizeError"};var J;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(J||(J={}));var Rs;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Rs||(Rs={}));(function(e){e.codec=()=>Is(Rs)})(J||(J={}));var Ht;(function(e){let t;e.codec=()=>(t==null&&(t=wt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),J.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={},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{c.Type=J.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:J.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return bt(s,e.codec())}e.encode=r;function n(s,i){return yt(s,e.codec(),i)}e.decode=n;function o(s,i){return gt(s,e.codec(),i)}e.stream=o})(Ht||(Ht={}));var Cs;(function(e){let t;e.codec=()=>(t==null&&(t=wt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),J.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={},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{c.Type=J.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:J.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return bt(s,e.codec())}e.encode=r;function n(s,i){return yt(s,e.codec(),i)}e.decode=n;function o(s,i){return gt(s,e.codec(),i)}e.stream=o})(Cs||(Cs={}));var Sr={};xt(Sr,{MAX_RSA_KEY_SIZE:()=>Ds,generateRSAKeyPair:()=>Qa,jwkToJWKKeyPair:()=>Ja,jwkToPkcs1:()=>ql,jwkToPkix:()=>Ps,jwkToRSAPrivateKey:()=>Ms,pkcs1MessageToJwk:()=>Os,pkcs1MessageToRSAPrivateKey:()=>Ks,pkcs1ToJwk:()=>Fl,pkcs1ToRSAPrivateKey:()=>Xa,pkixMessageToJwk:()=>ks,pkixMessageToRSAPublicKey:()=>Us,pkixToJwk:()=>zl,pkixToRSAPublicKey:()=>Ns});var We=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Sr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return st.createV1(114,this._multihash)}toString(){return nt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Z(this.raw,t.raw)}verify(t,r,n){return Ga(this.jwk,r,t,n)}},vr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Sr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Z(this.raw,t.raw)}sign(t,r){return Za(this.jwk,t,r)}};var Ds=8192,Ls=18,Ul=1062,Ml=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Fl(e){let t=Vt(e);return Os(t)}function Os(e){return{n:z(e[1],"base64url"),e:z(e[2],"base64url"),d:z(e[3],"base64url"),p:z(e[4],"base64url"),q:z(e[5],"base64url"),dp:z(e[6],"base64url"),dq:z(e[7],"base64url"),qi:z(e[8],"base64url"),kty:"RSA"}}function ql(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new q("JWK was missing components");return ee([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 zl(e){let t=Vt(e,{offset:0});return ks(t)}function ks(e){let t=Vt(e[1],{offset:0});return{kty:"RSA",n:z(t[0],"base64url"),e:z(t[1],"base64url")}}function Ps(e){if(e.n==null||e.e==null)throw new q("JWK was missing components");return ee([Ml,Vr(ee([Et(V(e.n,"base64url")),Et(V(e.e,"base64url"))]))]).subarray()}function Xa(e){let t=Vt(e);return Ks(t)}function Ks(e){let t=Os(e);return Ms(t)}function Ns(e,t){if(e.byteLength>=Ul)throw new Ie("Key size is too large");let r=Vt(e,{offset:0});return Us(r,e,t)}function Us(e,t,r){let n=ks(e);if(r==null){let o=Ue(Ht.encode({Type:J.RSA,Data:t}));r=Mt(Ls,o)}return new We(n,r)}function Ms(e){if(ec(e)>Ds)throw new q("Key size is too large");let t=Ja(e),r=Ue(Ht.encode({Type:J.RSA,Data:Ps(t.publicKey)})),n=Mt(Ls,r);return new vr(t.privateKey,new We(t.publicKey,n))}async function Qa(e){if(e>Ds)throw new q("Key size is too large");let t=await tc(e),r=Ue(Ht.encode({Type:J.RSA,Data:Ps(t.publicKey)})),n=Mt(Ls,r);return new vr(t.privateKey,new We(t.publicKey,n))}function Ja(e){if(e==null)throw new q("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function tc(e,t){let r=await Ct.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 Hl(r,t);return{privateKey:n[0],publicKey:n[1]}}async function Za(e,t,r){let n=await Ct.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Ct.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,pt(t instanceof Uint8Array?t:t.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Ga(e,t,r,n){let o=await Ct.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Ct.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,pt(t),pt(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),s}async function Hl(e,t){if(e.privateKey==null||e.publicKey==null)throw new q("Private and public key are required");let r=await Promise.all([Ct.get().subtle.exportKey("jwk",e.privateKey),Ct.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function ec(e){if(e.kty!=="RSA")throw new q("invalid key type");if(e.n==null)throw new q("invalid key modulus");return V(e.n,"base64url").length*8}var An=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(jr(t),It(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");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),ye(o)}update(t){return Ne(this),this.iHash.update(t),this}digestInto(t){Ne(this),Yr(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,canXOF:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.canXOF=c,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()}},rc=(()=>{let e=((t,r,n)=>new An(t,r).update(n).digest());return e.create=(t,r)=>new An(t,r),e})();var Vl=BigInt(0),Fs=class extends Error{constructor(t=""){super(t)}},Wt={Err:Fs,_tlv:{encode:(e,t)=>{let{Err:r}=Wt;if(ce(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(ua(t,"data"),t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=hr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?hr(o.length/2|128):"";return hr(e)+s+o+t},decode(e,t){let{Err:r}=Wt;t=W(t,void 0,"DER data");let n=0;if(e<0||e>255)throw new r("tlv.decode: 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 f=t.subarray(n,n+c);if(f.length!==c)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of f)i=i<<8|u;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Wt;if(tn(e),e<Vl)throw new t("integer: negative integers are not allowed");let r=hr(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}=Wt;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 zt(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Wt,o=W(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:f,l:u}=n.decode(2,c);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(f)}},hexFromSig(e){let{_tlv:t,_int:r}=Wt;St(e,{r:"bigint",s:"bigint"},{},"sig");let n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},qs=(Object.freeze(Wt._tlv),Object.freeze(Wt._int),Object.freeze(Wt));var nc=(e,t)=>(e+(e>=0?t:-t)/oc)/t;function $l(e,t,r){Fe("scalar",e,jt,r);let[[n,o],[s,i]]=t,a=nc(i*e,r),c=nc(-o*e,r),f=e-a*n-c*s,u=-a*o-c*i,d=f<jt,l=u<jt;d&&(f=-f),l&&(u=-u);let h=pr(Math.ceil(qe(r)/2))+ve;if(f<jt||f>=h||u<jt||u>=h)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:d,k1:f,k2neg:l,k2:u}}function Vs(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function zs(e,t){St(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return vt(r.lowS,"lowS"),vt(r.prehash,"prehash"),r.format!==void 0&&Vs(r.format),r}var jt=BigInt(0),ve=BigInt(1),oc=BigInt(2),Hs=BigInt(3),Wl=BigInt(4);function sc(e,t={}){let r=fn("weierstrass",e,t),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;St(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:f}=t,u=t.randomBytes===void 0?ge:t.randomBytes;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 d=ac(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(R,p,E){if(f&&p.is0())return Uint8Array.of(0);let{x:A,y:L}=p.toAffine(),v=n.toBytes(A);if(vt(E,"isCompressed"),E){l();let m=!n.isOdd(L);return Rt(ic(m),v)}else return Rt(Uint8Array.of(4),v,n.toBytes(L))}function w(R){W(R,void 0,"Point");let{publicKey:p,publicKeyUncompressed:E}=d,A=R.length,L=R[0],v=R.subarray(1);if(f&&A===1&&L===0)return{x:n.ZERO,y:n.ZERO};if(A===p&&(L===2||L===3)){let m=n.fromBytes(v);if(!n.isValid(m))throw new Error("bad point: is not on curve, wrong x");let T=y(m),I;try{I=n.sqrt(T)}catch($){let H=$ instanceof Error?": "+$.message:"";throw new Error("bad point: is not on curve, sqrt error"+H)}l();let K=n.isOdd(I);return(L&1)===1!==K&&(I=n.neg(I)),{x:m,y:I}}else if(A===E&&L===4){let m=n.BYTES,T=n.fromBytes(v.subarray(0,m)),I=n.fromBytes(v.subarray(m,m*2));if(!B(T,I))throw new Error("bad point: is not on curve");return{x:T,y:I}}else throw new Error(`bad point: got length ${A}, expected compressed=${p} or uncompressed=${E}`)}let g=t.toBytes===void 0?h:t.toBytes,b=t.fromBytes===void 0?w:t.fromBytes,x=n.mul(s.b,Hs),S=n.is0(s.a)?R=>n.ZERO:R=>n.mul(s.a,R);function y(R){let p=n.sqr(R),E=n.mul(p,R);return n.add(n.add(E,n.mul(R,s.a)),s.b)}function B(R,p){let E=n.sqr(p),A=y(R);return n.eql(E,A)}if(!B(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let _=n.mul(n.pow(s.a,Hs),Wl),U=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(_,U)))throw new Error("bad curve params: a or b");function M(R,p,E=!1){if(!n.isValid(p)||E&&n.is0(p))throw new Error(`bad point coordinate ${R}`);return p}function P(R){if(!(R instanceof D))throw new Error("Weierstrass Point expected")}function O(R){if(!c||!c.basises)throw new Error("no endo");return $l(R,c.basises,o.ORDER)}function k(R,p,E,A){if(!o.isValid(A))throw new RangeError("invalid scalar: out of range");if(c){let{k1neg:L,k1:v,k2neg:m,k2:T}=O(A),I=new D(n.mul(E.X,c.beta),E.Y,E.Z);R.push(L?E.negate():E,m?I.negate():I),p.push(v,T)}else R.push(E),p.push(A)}let F=new WeakSet;class D{static BASE=new D(s.Gx,s.Gy,n.ONE);static ZERO=new D(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(p,E,A){this.X=M("x",p),this.Y=M("y",E,!0),this.Z=M("z",A),Object.freeze(this)}static CURVE(){return s}static fromAffine(p){let{x:E,y:A}=p||{};if(!p||!n.isValid(E)||!n.isValid(A))throw new Error("invalid affine point");if(p instanceof D)throw new Error("projective point not allowed");return n.is0(E)&&n.is0(A)?D.ZERO:new D(E,A,n.ONE)}static fromBytes(p){let E=D.fromAffine(b(W(p,void 0,"point")));return E.assertValidity(),E}static fromHex(p){return D.fromBytes(Me(p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=6,E=!0){return C.setWindowSize(this,p),E||this.multiply(Hs),this}assertValidity(){let p=this;if(p.is0()){if(t.allowInfinityPoint&&n.is0(p.X)&&n.eql(p.Y,n.ONE)&&n.is0(p.Z))return;throw new Error("bad point: ZERO")}if(F.has(p))return;let{x:E,y:A}=p.toAffine();if(!n.isValid(E)||!n.isValid(A))throw new Error("bad point: x or y not field elements");if(!B(E,A))throw new Error("bad point: equation left != right");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");F.add(p)}hasEvenY(){let{y:p}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(p)}equals(p){P(p);let{X:E,Y:A,Z:L}=this,{X:v,Y:m,Z:T}=p,I=n.eql(n.mul(E,T),n.mul(v,L)),K=n.eql(n.mul(A,T),n.mul(m,L));return I&&K}negate(){return new D(this.X,n.neg(this.Y),this.Z)}double(){let{X:p,Y:E,Z:A}=this,L=n.ZERO,v=n.ZERO,m=n.ZERO,T=n.mul(p,p),I=n.mul(E,E),K=n.mul(A,A),N=n.mul(p,E);return N=n.add(N,N),m=n.mul(p,A),m=n.add(m,m),L=S(m),v=n.mul(x,K),v=n.add(L,v),L=n.sub(I,v),v=n.add(I,v),v=n.mul(L,v),L=n.mul(N,L),m=n.mul(x,m),K=S(K),N=n.sub(T,K),N=S(N),N=n.add(N,m),m=n.add(T,T),T=n.add(m,T),T=n.add(T,K),T=n.mul(T,N),v=n.add(v,T),K=n.mul(E,A),K=n.add(K,K),T=n.mul(K,N),L=n.sub(L,T),m=n.mul(K,I),m=n.add(m,m),m=n.add(m,m),new D(L,v,m)}add(p){P(p);let{X:E,Y:A,Z:L}=this,{X:v,Y:m,Z:T}=p,I=n.ZERO,K=n.ZERO,N=n.ZERO,$=n.mul(E,v),H=n.mul(A,m),tt=n.mul(L,T),ht=n.add(E,A),et=n.add(v,m);ht=n.mul(ht,et),et=n.add($,H),ht=n.sub(ht,et),et=n.add(E,L);let ut=n.add(v,T);return et=n.mul(et,ut),ut=n.add($,tt),et=n.sub(et,ut),ut=n.add(A,L),I=n.add(m,T),ut=n.mul(ut,I),I=n.add(H,tt),ut=n.sub(ut,I),N=S(et),I=n.mul(x,tt),N=n.add(I,N),I=n.sub(H,N),N=n.add(H,N),K=n.mul(I,N),H=n.add($,$),H=n.add(H,$),tt=S(tt),et=n.mul(x,et),H=n.add(H,tt),tt=n.sub($,tt),tt=S(tt),et=n.add(et,tt),$=n.mul(H,et),K=n.add(K,$),$=n.mul(ut,et),I=n.mul(ht,I),I=n.sub(I,$),$=n.mul(ht,H),N=n.mul(ut,N),N=n.add(N,$),new D(I,K,N)}subtract(p){return P(p),this.add(p.negate())}is0(){return this.equals(D.ZERO)}multiply(p){if(!o.isValidNot0(p))throw new RangeError("invalid scalar: out of range");let{p:E,f:A}=C.mulSecret(this,p,i,G);return G([E,A])[0]}multiplyUnsafe(p){let E=this,A=p;if(!o.isValid(A))throw new RangeError("invalid scalar: out of range");if(A===jt||E.is0())return D.ZERO;if(A===ve)return E;if(C.hasWindowSize(this))return C.mulUnsafe(E,A,G);let L=[],v=[];return k(L,v,E,A),un(D,L,v)}mulAddUnsafe(p,E,A){P(E);let L=[],v=[];return k(L,v,this,p),k(L,v,E,A),un(D,L,v)}toAffine(p){let E=this,A=p;if(A!=null&&!n.isValid(A))throw new RangeError('"invertedZ" expected valid field element');let{X:L,Y:v,Z:m}=E;if(n.eql(m,n.ONE))return{x:L,y:v};let T=E.is0();A==null&&(A=T?n.ONE:n.inv(m));let I=n.mul(L,A),K=n.mul(v,A),N=n.mul(m,A);if(T)return{x:n.ZERO,y:n.ZERO};if(!n.eql(N,n.ONE))throw new Error("invZ was invalid");return{x:I,y:K}}isTorsionFree(){let{isTorsionFree:p}=t;return i===ve?!0:p?p(D,this):C.mulUnsafe(this,a).is0()}clearCofactor(){let{clearCofactor:p}=t;return i===ve?this:p?p(D,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===ve?this.is0():this.clearCofactor().is0()}toBytes(p=!0){return vt(p,"isCompressed"),this.assertValidity(),g(D,this,p)}toHex(p=!0){return dr(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let G=R=>cn(D,R),C=new Ve(D,u);return C.bits>=6&&D.BASE.precompute(6),Object.freeze(D.prototype),Object.freeze(D),D}function ic(e){return Uint8Array.of(e?2:3)}function ac(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function jl(e,t={}){fe(e);let{Fn:r}=e,n=t.randomBytes===void 0?ge:t.randomBytes,o=Object.assign(ac(e.Fp,r),{seed:Math.max(sn(r.ORDER),16)});function s(h){try{let w=r.fromBytes(h);return r.isValidNot0(w)}catch{return!1}}function i(h,w){let{publicKey:g,publicKeyUncompressed:b}=o;try{let x=h.length;return w===!0&&x!==g||w===!1&&x!==b?!1:!!e.fromBytes(h)}catch{return!1}}function a(h){return h=h===void 0?n(o.seed):h,an(W(h,o.seed,"seed"),r.ORDER)}function c(h,w=!0){return e.BASE.multiply(r.fromBytes(h)).toBytes(w)}function f(h){let{secretKey:w,publicKey:g,publicKeyUncompressed:b}=o,x=r._lengths;if(!ae(h))return;let S=W(h,void 0,"key").length,y=S===g||S===b,B=S===w||!!x?.includes(S);if(!(y&&B))return y}function u(h,w,g=!0){if(f(h)===!0)throw new Error("first arg must be private key");if(f(w)===!1)throw new Error("second arg must be public key");let b=r.fromBytes(h);return e.fromBytes(w).multiply(b).toBytes(g)}let d={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},l=ln(a,c);return Object.freeze(d),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:l,Point:e,utils:d,lengths:o})}function cc(e,t,r={}){fe(e);let n=t;jr(n),St(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},r),s=o.randomBytes===void 0?ge:o.randomBytes,i=o.hmac===void 0?(v,m)=>rc(n,v,m):o.hmac,{Fp:a,Fn:c}=e,{ORDER:f,BITS:u}=c,d=sn(f),l=ss(s,d),{keygen:h,getPublicKey:w,getSharedSecret:g,utils:b,lengths:x}=jl(e,o),S={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},y=f*oc+ve<a.ORDER;function B(v){let m=f>>ve;return v>m}function _(v,m){if(!c.isValidNot0(m))throw new Error(`invalid signature ${v}: out of range 1..Point.Fn.ORDER`);return m}function U(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function M(v,m,T){return U(),(v===T?0:2)|Number(a.isOdd(m))}function P(){if(y)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function O(v,m){Vs(m);let T=x.signature,I=m==="compact"?T:m==="recovered"?T+1:void 0;return W(v,I)}class k{r;s;recovery;constructor(m,T,I){if(this.r=_("r",m),this.s=_("s",T),I!=null){if(P(),![0,1,2,3].includes(I))throw new Error("invalid recovery id");this.recovery=I}Object.freeze(this)}static fromBytes(m,T=S.format){O(m,T);let I;if(T==="der"){let{r:H,s:tt}=qs.toSig(W(m));return new k(H,tt)}T==="recovered"&&(I=m[0],T="compact",m=m.subarray(1));let K=x.signature/2,N=m.subarray(0,K),$=m.subarray(K,K*2);return new k(c.fromBytes(N),c.fromBytes($),I)}static fromHex(m,T){return this.fromBytes(Me(m),T)}assertRecovery(){let{recovery:m}=this;if(m==null)throw new Error("invalid recovery id: must be present");return m}addRecoveryBit(m){return new k(this.r,this.s,m)}recoverPublicKey(m){let{r:T,s:I}=this,K=this.assertRecovery(),N=K===2||K===3?T+f:T;if(!a.isValid(N))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let $=a.toBytes(N),H=e.fromBytes(Rt(ic((K&1)===0),$)),tt=c.inv(N),ht=D(W(m,void 0,"msgHash")),et=c.create(-ht*tt),ut=c.create(I*tt),Kt=e.BASE.mulAddUnsafe(et,H,ut);if(Kt.is0())throw new Error("invalid recovery: point at infinify");return Kt.assertValidity(),Kt}hasHighS(){return B(this.s)}toBytes(m=S.format){if(Vs(m),m==="der")return Me(qs.hexFromSig(this));let{r:T,s:I}=this,K=c.toBytes(T),N=c.toBytes(I);return m==="recovered"?(P(),Rt(Uint8Array.of(this.assertRecovery()),K,N)):Rt(K,N)}toHex(m){return dr(this.toBytes(m))}}Object.freeze(k.prototype),Object.freeze(k);let F=o.bits2int===void 0?function(m){if(m.length>8192)throw new Error("input is too large");let T=zt(m),I=m.length*8-u;return I>0?T>>BigInt(I):T}:o.bits2int,D=o.bits2int_modN===void 0?function(m){return c.create(F(m))}:o.bits2int_modN,G=pr(u);function C(v){return Fe("num < 2^"+u,v,jt,G),c.toBytes(v)}function R(v,m){return W(v,void 0,"message"),m?W(n(v),void 0,"prehashed message"):v}function p(v,m,T){let{lowS:I,prehash:K,extraEntropy:N}=zs(T,S);v=R(v,K);let $=D(v),H=c.fromBytes(m);if(!c.isValidNot0(H))throw new Error("invalid private key");let tt=[C(H),C($)];if(N!=null&&N!==!1){let Kt=N===!0?s(x.secretKey):N;tt.push(W(Kt,void 0,"extraEntropy"))}let ht=Rt(...tt),et=$;function ut(Kt){let _e=F(Kt);if(!c.isValidNot0(_e))return;let Qe=e.BASE.multiply(_e).toAffine(),Qt=c.create(Qe.x);if(Qt===jt)return;let Nt;if(l!==void 0){let Je=zt(an(l(d),f)),ru=c.inv(c.mul(Je,_e)),nu=c.mul(Je,et),ou=c.mul(Je,H);Nt=c.create(ru*c.create(nu+ou*Qt))}else{let Je=wa(_e,f);Nt=c.create(Je*c.create(et+Qt*H))}if(Nt===jt)return;let ao=M(Qe.x,Qe.y,Qt),mi=Nt;return I&&B(Nt)&&(mi=c.neg(Nt),ao^=1),new k(Qt,mi,y?void 0:ao)}return{seed:ht,k2sig:ut}}function E(v,m,T={}){let{seed:I,k2sig:K}=p(v,m,T);return la(n.outputLen,c.BYTES,i)(I,K).toBytes(T.format)}function A(v,m,T,I={}){let{lowS:K,prehash:N,format:$}=zs(I,S);if(T=W(T,void 0,"publicKey"),m=R(m,N),!ae(v)){let H=v instanceof k?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+H)}O(v,$);try{let H=k.fromBytes(v,$),tt=e.fromBytes(T);if(K&&H.hasHighS())return!1;let{r:ht,s:et}=H,ut=D(m),Kt=c.inv(et),_e=c.create(ut*Kt),Qe=c.create(ht*Kt),Qt=e.BASE.mulAddUnsafe(_e,tt,Qe);if(Qt.is0())return!1;let Nt=Qt.toAffine();return!(c.create(Nt.x)!==ht||$==="recovered"&&H.recovery!==M(Nt.x,Nt.y,ht))}catch{return!1}}function L(v,m,T={}){let{prehash:I}=zs(T,S);return m=R(m,I),k.fromBytes(v,"recovered").recoverPublicKey(m).toBytes()}return Object.freeze({keygen:h,getPublicKey:w,getSharedSecret:g,utils:b,lengths:x,Point:e,sign:E,verify:A,recoverPublicKey:L,Signature:k,hash:n})}var Ws={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Yl={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var uc=BigInt(2);function Zl(e){let t=Ws.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=e*e*e%t,u=f*f*e%t,d=X(u,r,t)*u%t,l=X(d,r,t)*u%t,h=X(l,uc,t)*f%t,w=X(h,o,t)*h%t,g=X(w,s,t)*w%t,b=X(g,a,t)*g%t,x=X(b,c,t)*b%t,S=X(x,a,t)*g%t,y=X(S,r,t)*u%t,B=X(y,i,t)*w%t,_=X(B,n,t)*f%t,U=X(_,uc,t);if(!$s.eql($s.sqr(U),e))throw new Error("Cannot find square root");return U}var $s=He(Ws.p,{sqrt:Zl}),Gl=sc(Ws,{Fp:$s,endo:Yl}),je=cc(Gl,Ue);function fc(e,t,r,n){let o=sr.digest(r instanceof Uint8Array?r:r.subarray());if(bn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),je.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new br(String(s))});try{return n?.signal?.throwIfAborted(),je.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new br(String(s))}}var Bn=class{type="secp256k1";raw;_key;constructor(t){this._key=dc(t),this.raw=lc(this._key)}toMultihash(){return Ot.digest(_t(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return nt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Z(this.raw,t.raw)}verify(t,r,n){return fc(this._key,r,t,n)}};function js(e){return new Bn(e)}function lc(e){return je.Point.fromBytes(e).toBytes()}function dc(e){try{return je.Point.fromBytes(e),e}catch(t){throw new Ie(String(t))}}function Tn(e,t){let{Type:r,Data:n}=Ht.decode(e),o=n??new Uint8Array;switch(r){case J.RSA:return Ns(o,t);case J.Ed25519:return ls(o);case J.secp256k1:return js(o);case J.ECDSA:return Uo(o);default:throw new de}}function hc(e){let{Type:t,Data:r}=Ht.decode(e.digest),n=r??new Uint8Array;switch(t){case J.Ed25519:return ls(n);case J.secp256k1:return js(n);case J.ECDSA:return Uo(n);default:throw new de}}function _t(e){return Ht.encode({Type:J[e.type],Data:e.raw})}var pc=Symbol.for("nodejs.util.inspect.custom"),Xl=114,Ar=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()})`}[Fr]=!0;toString(){return this.string==null&&(this.string=nt.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return st.createV1(Xl,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return Z(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return Z(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[pc](){return`PeerId(${this.toString()})`}},Br=class extends Ar{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Tr=class extends Ar{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},_r=class extends Ar{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Ql=2336,Ir=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Ot.digest(V(this.url))}[pc](){return`PeerId(${this.url})`}[Fr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return st.createV1(Ql,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=z(t)),t.toString()===this.toString())}};var Jl=114,mc=2336;function yc(e){if(e.type==="Ed25519")return new Tr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new _r({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new Br({multihash:e.toCID().multihash,publicKey:e});throw new de}function Ys(e){if(ed(e))return new Br({multihash:e});if(td(e))try{let t=hc(e);if(t.type==="Ed25519")return new Tr({multihash:e,publicKey:t});if(t.type==="secp256k1")return new _r({multihash:e,publicKey:t})}catch{let r=z(e.digest);return new Ir(new URL(r))}throw new Mr("Supplied PeerID Multihash is invalid")}function _n(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==Jl&&e.code!==mc)throw new Ur("Supplied PeerID CID is invalid");if(e.code===mc){let t=z(e.multihash.digest);return new Ir(new URL(t))}return Ys(e.multihash)}function td(e){return e.code===Ot.code}function ed(e){return e.code===sr.code}var Rr;(function(e){let t;e.codec=()=>(t==null&&(t=wt((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:ot(0),payloadType:ot(0),payload:ot(0),signature:ot(0)},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{c.publicKey=s.bytes();break}case 2:{c.payloadType=s.bytes();break}case 3:{c.payload=s.bytes();break}case 5:{c.signature=s.bytes();break}default:{s.skipType(u&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.publicKey`,value:s.bytes()};break}case 2:{yield{field:`${a}.payloadType`,value:s.bytes()};break}case 3:{yield{field:`${a}.payload`,value:s.bytes()};break}case 5:{yield{field:`${a}.signature`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return bt(s,e.codec())}e.encode=r;function n(s,i){return yt(s,e.codec(),i)}e.decode=n;function o(s,i){return gt(s,e.codec(),i)}e.stream=o})(Rr||(Rr={}));var In=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var Ye=class e{static createFromProtobuf=t=>{let r=Rr.decode(t),n=Tn(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=bc(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 In("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=Rr.encode({publicKey:_t(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return t==null?!1:Z(this.marshal(),t.marshal())}async validate(t,r){let n=bc(t,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},bc=(e,t,r)=>{let n=V(e),o=wn(n.byteLength),s=wn(t.length),i=wn(r.length);return new mt(o,n,s,t,i,r)};var ct=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Yt=class extends Error{static name="ValidationError";name="ValidationError"},Rn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Cn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Dn=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",f=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let d=this.readChar();if(d===void 0)return;let l=Number.parseInt(d,t);if(!Number.isNaN(l))return l});if(u===void 0)break;if(s*=t,s+=u,s>f||(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 rd=45,nd=15,Ln=new Dn;function gc(e){if(!(e.length>nd))return Ln.new(e).parseWith(()=>Ln.readIPv4Addr())}function wc(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>rd))return Ln.new(e).parseWith(()=>Ln.readIPv6Addr())}function On(e){return!!gc(e)}function xc(e){return!!wc(e)}function Gs(e){return t=>z(t,e)}function Xs(e){return t=>V(t,e)}function Ze(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 Ec(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 Ft([r,o],r.length+o.length)}function vc(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=Ut.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 Ft([r,o],r.length+o.length)}function Qs(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=z(t,"base32"),o=Ze(r);return`${n}:${o}`}var Js=function(e){e=e.toString().trim();let t=new Uint8Array(4);return e.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new ct("Invalid byte value in IP address");t[n]=o}),t},Sc=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let s=On(r[n]),i;s&&(i=Js(r[n]),r[n]=z(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,z(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(t+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new ct("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Ac=function(e){if(e.byteLength!==4)throw new ct("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},Bc=function(e){if(e.byteLength!==16)throw new ct("IPv6 address was incorrect length");let t=[];for(let n=0;n<e.byteLength;n+=2){let o=e[n],s=e[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let r=t.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new ct(`Invalid IPv6 address "${r}"`)}};function Tc(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new ct(`Invalid IPv6 address "${e}"`)}}var Zs=Object.values(ir).map(e=>e.decoder),od=(function(){let e=Zs[0].or(Zs[1]);return Zs.slice(2).forEach(t=>e=e.or(t)),e})();function _c(e){return od.decode(e)}function Ic(e){return t=>e.encoder.encode(t)}function sd(e){if(parseInt(e).toString()!==e)throw new Yt("Value must be an integer")}function id(e){if(e<0)throw new Yt("Value must be a positive integer, or zero")}function ad(e){return t=>{if(t>e)throw new Yt(`Value must be smaller than or equal to ${e}`)}}function cd(...e){return t=>{for(let r of e)r(t)}}var Cr=cd(sd,id,ad(65535));var at=-1,ti=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 Cn(`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)}))}},Zt=new ti,Yd=[{code:4,name:"ip4",size:32,valueToBytes:Js,bytesToValue:Ac,validate:e=>{if(!On(e))throw new Yt(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Se,bytesToValue:Ze,validate:Cr},{code:273,name:"udp",size:16,valueToBytes:Se,bytesToValue:Ze,validate:Cr},{code:33,name:"dccp",size:16,valueToBytes:Se,bytesToValue:Ze,validate:Cr},{code:41,name:"ip6",size:128,valueToBytes:Sc,bytesToValue:Bc,stringToValue:Tc,validate:e=>{if(!xc(e))throw new Yt(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:at},{code:43,name:"ipcidr",size:8,bytesToValue:Gs("base10"),valueToBytes:Xs("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:Ze,validate:Cr},{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:Gs("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?Xs("base58btc")(e):st.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Qs,valueToBytes:Ec},{code:445,name:"onion3",size:296,bytesToValue:Qs,valueToBytes:vc},{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:Ic(Bo),valueToBytes:_c},{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}];Yd.forEach(e=>{Zt.addProtocol(e)});function Rc(e){let t=[],r=0;for(;r<e.length;){let n=bs(e,r),o=Zt.getProtocol(n),s=Dt(n),i=Zd(o,e,r+s),a=0;i>0&&o.size===at&&(a=Dt(i));let c=s+a+i,f={code:n,name:o.name,bytes:pt(e.subarray(r,r+c))};if(i>0){let u=r+s+a,d=e.subarray(u,u+i);f.value=o.bytesToValue?.(d)??z(d)}t.push(f),r+=c}return t}function Cc(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=Zt.getProtocol(n.code),s=Dt(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=Dt(a)));let f=new Uint8Array(s+c+a),u=0;$e(n.code,f,u),u+=s,i!=null&&(o.size===at&&($e(a,f,u),u+=c),f.set(i,u)),n.bytes=f}r.push(n.bytes),t+=n.bytes.byteLength}return Ft(r,t)}function Dc(e){if(e.charAt(0)!=="/")throw new ct('String multiaddr must start with "/"');let t=[],r="protocol",n="",o="";for(let s=1;s<e.length;s++){let i=e.charAt(s);i!=="/"&&(r==="protocol"?o+=e.charAt(s):n+=e.charAt(s));let a=s===e.length-1;if(i==="/"||a){let c=Zt.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new ct(`Component ${o} was missing value`);r="value"}else if(r==="value"){let f={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new ct(`Component ${o} was missing value`);f.value=c.stringToValue?.(n)??n}t.push(f),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new ct("Incomplete multiaddr");return t}function Lc(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=Zt.getProtocol(t.code);if(r==null)throw new ct(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function Zd(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:bs(t,r)}var Gd=Symbol.for("nodejs.util.inspect.custom"),ri=Symbol.for("@multiformats/multiaddr");function Xd(e){if(e==null&&(e="/"),Pn(e))return e.getComponents();if(e instanceof Uint8Array)return Rc(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),Dc(e);if(Array.isArray(e))return e;throw new ct("Must be a string, Uint8Array, Component[], or another Multiaddr")}var kn=class e{[ri]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=Xd(t),r.validate!==!1&&Qd(this)}get bytes(){return this.#r==null&&(this.#r=Cc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Lc(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 Rn(`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 Z(this.bytes,t.bytes)}[Gd](){return`Multiaddr(${this.toString()})`}};function Qd(e){e.getComponents().forEach(t=>{let r=Zt.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function Pn(e){return!!e?.[ri]}function Ae(e){return new kn(e)}var Oc="libp2p-peer-record",kc=Uint8Array.from([3,1]);var Dr;(function(e){let t;(function(i){let a;i.codec=()=>(a==null&&(a=wt((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 w={multiaddr:ot(0)},g=l==null?d.len:d.pos+l;for(;d.pos<g;){let b=d.uint32();b>>>3===1?w.multiaddr=d.bytes():d.skipType(b&7)}return w},function*(d,l,h,w={}){let g=l==null?d.len:d.pos+l;for(;d.pos<g;){let b=d.uint32();b>>>3===1?yield{field:`${h}.multiaddr`,value:d.bytes()}:d.skipType(b&7)}})),a);function c(d){return bt(d,i.codec())}i.encode=c;function f(d,l){return yt(d,i.codec(),l)}i.decode=f;function u(d,l){return gt(d,i.codec(),l)}i.stream=u})(t=e.AddressInfo||(e.AddressInfo={}));let r;e.codec=()=>(r==null&&(r=wt((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 f of i.addresses)a.uint32(26),e.AddressInfo.codec().encode(f,a);c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let f={peerId:ot(0),seq:0n,addresses:[]},u=a==null?i.len:i.pos+a;for(;i.pos<u;){let d=i.uint32();switch(d>>>3){case 1:{f.peerId=i.bytes();break}case 2:{f.seq=i.uint64();break}case 3:{if(c.limits?.addresses!=null&&f.addresses.length===c.limits.addresses)throw new Lt('Decode error - repeated field "addresses" had too many elements');f.addresses.push(e.AddressInfo.codec().decode(i,i.uint32(),{limits:c.limits?.addresses$}));break}default:{i.skipType(d&7);break}}}return f},function*(i,a,c,f={}){let u={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(f.limits?.addresses!=null&&u.addresses===f.limits.addresses)throw new Lt('Streaming decode error - repeated field "addresses" had too many elements');for(let h of e.AddressInfo.codec().stream(i,i.uint32(),`${c}.addresses[]`,{limits:f.limits?.addresses$}))yield{...h,index:u.addresses};u.addresses++;break}default:{i.skipType(l&7);break}}}})),r);function n(i){return bt(i,e.codec())}e.encode=n;function o(i,a){return yt(i,e.codec(),a)}e.decode=o;function s(i,a){return gt(i,e.codec(),a)}e.stream=s})(Dr||(Dr={}));function Pc(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 Be=class e{static createFromProtobuf=t=>{let r=Dr.decode(t),n=Ys(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=Oc;static CODEC=kc;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=Dr.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||!Pc(this.multiaddrs,t.multiaddrs))}};function Jd(e){return e[Symbol.asyncIterator]!=null}function th(e){if(Jd(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 Kc=th;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 Lr=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 Nn(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var Un=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}},Ge=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Un(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 Un(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 ni=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Nc(e={}){return eh(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 eh(e,t){t=t??{};let r=t.onEnd,n=new Ge,o,s,i,a=Nn(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((b,x)=>{s=S=>{s=null,n.push(S);try{b(e(n))}catch(y){x(y)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Nn()})}},f=b=>s!=null?s(b):(n.push(b),o),u=b=>(n=new Ge,s!=null?s({error:b}):(n.push({error:b}),o)),d=b=>{if(i)return o;if(t?.objectMode!==!0&&b?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:b})},l=b=>i?o:(i=!0,b!=null?u(b):f({done:!0})),h=()=>(n=new Ge,l(),{done:!0}),w=b=>(l(b),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:h,throw:w,push:d,end:l,get readableLength(){return n.size},onEmpty:async b=>{let x=b?.signal;if(x?.throwIfAborted(),n.isEmpty())return;let S,y;x!=null&&(S=new Promise((B,_)=>{y=()=>{_(new ni)},x.addEventListener("abort",y)}));try{await Promise.race([a.promise,S])}finally{y!=null&&x!=null&&x?.removeEventListener("abort",y)}}},r==null)return o;let g=o;return o={[Symbol.asyncIterator](){return this},next(){return g.next()},throw(b){return g.throw(b),r!=null&&(r(b),r=void 0),{done:!0}},return(){return g.return(),r!=null&&(r(),r=void 0),{done:!0}},push:d,end(b){return g.end(b),r!=null&&(r(b),r=void 0),o},get readableLength(){return g.readableLength},onEmpty:b=>g.onEmpty(b)},o}function rh(e){return e.reason}async function Uc(e,t,r){if(t==null)return e;let n=r?.translateError??rh;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 oi=class extends Lr{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 si(e){let{name:t,metrics:r}=e,n;return r!=null?n=new oi({name:t,metrics:r}):n=new Lr,n}var Bt=class extends Error{static name="AbortError";name="AbortError";constructor(t="The operation was aborted",...r){super(t,...r)}};async function Mn(e,t,r,n){let o=new Bt(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(){ai(r,"abort",d),ai(e,t,f),ai(e,s,u)}let f=l=>{try{if(n?.filter?.(l)===!1)return}catch(h){c(),a(h);return}c(),i(l)},u=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)};ii(r,"abort",d),ii(e,t,f),ii(e,s,u)})}function ii(e,t,r){e!=null&&(Mc(e)?e.addEventListener(t,r):e.addListener(t,r))}function ai(e,t,r){e!=null&&(Mc(e)?e.removeEventListener(t,r):e.removeListener(t,r))}function Mc(e){return typeof e.addEventListener=="function"&&typeof e.removeEventListener=="function"}var Fn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};var qn=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 Bt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function nh(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var zn=class{id;fn;options;recipients;status;timeline;controller;constructor(t,r){this.id=nh(),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 Bt),this.cleanup())}async join(t={}){let r=new qn(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 Uc(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 ci(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 Or=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=ci(this.emitEmpty.bind(this),1),this.emitIdle=ci(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 Fn;let n=new zn(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 Bt)}),this.clear()}async onEmpty(t){this.size!==0&&await Mn(this,"empty",t?.signal)}async onSizeLessThan(t,r){this.size<t||await Mn(this,"next",r?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await Mn(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=Nc({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 Bt("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 Hn="lock:worker:request-read",Vn="lock:worker:abort-read-request",$n="lock:worker:release-read",Wn="lock:master:grant-read",jn="lock:master:error-read",Yn="lock:worker:request-write",Zn="lock:worker:abort-write-request",Gn="lock:worker:release-write",Xn="lock:master:grant-write",Qn="lock:master:error-write",Jn="lock:worker:finalize",to="mortice",Fc={singleProcess:!1};var ui=(e,t,r,n,o,s,i,a,c)=>f=>{if(f.data==null)return;let u={type:f.data.type,name:f.data.name,identifier:f.data.identifier};u.type===o&&e.safeDispatchEvent(r,{detail:{name:u.name,identifier:u.identifier,handler:async()=>{t.postMessage({type:c,name:u.name,identifier:u.identifier}),await new Promise(d=>{let l=h=>{if(h?.data==null)return;let w={type:h.data.type,name:h.data.name,identifier:h.data.identifier};w.type===a&&w.identifier===u.identifier&&(t.removeEventListener("message",l),d())};t.addEventListener("message",l)})},onError:d=>{t.postMessage({type:i,name:u.name,identifier:u.identifier,error:{message:d.message,name:d.name,stack:d.stack}})}}}),u.type===s&&e.safeDispatchEvent(n,{detail:{name:u.name,identifier:u.identifier}}),u.type===Jn&&e.safeDispatchEvent("finalizeRequest",{detail:{name:u.name}})};var qc=(e=10)=>Math.random().toString().substring(2,e+2);var eo=class{name;channel;constructor(t){this.name=t,this.channel=new BroadcastChannel(to)}readLock(t){return this.sendRequest(Hn,Vn,Wn,jn,$n,t)}writeLock(t){return this.sendRequest(Yn,Zn,Xn,Qn,Gn,t)}finalize(){this.channel.postMessage({type:Jn,name:this.name}),this.channel.close()}async sendRequest(t,r,n,o,s,i){i?.signal?.throwIfAborted();let a=qc();return this.channel.postMessage({type:t,identifier:a,name:this.name}),new Promise((c,f)=>{let u=()=>{this.channel.postMessage({type:r,identifier:a,name:this.name})};i?.signal?.addEventListener("abort",u,{once:!0});let d=l=>{if(l.data?.identifier===a&&(l.data?.type===n&&(this.channel.removeEventListener("message",d),i?.signal?.removeEventListener("abort",u),c(()=>{this.channel.postMessage({type:s,identifier:a,name:this.name})})),l.data.type===o)){this.channel.removeEventListener("message",d),i?.signal?.removeEventListener("abort",u);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),f(h)}};this.channel.addEventListener("message",d)})}};var zc=e=>{if(e=Object.assign({},Fc,e),!!globalThis.document||e.singleProcess){let r=new BroadcastChannel(to),n=new Ce;return r.addEventListener("message",ui(n,r,"requestReadLock","abortReadLockRequest",Hn,Vn,jn,$n,Wn)),r.addEventListener("message",ui(n,r,"requestWriteLock","abortWriteLockRequest",Yn,Zn,Qn,Gn,Xn)),n}return new eo(e.name)};var Te=new Map,kr;function Hc(e){return typeof e?.readLock=="function"&&typeof e?.writeLock=="function"}function oh(e){if(kr==null&&(kr=zc(e),!Hc(kr))){let t=kr;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 kr}async function fi(e,t){let r,n,o=new Promise((i,a)=>{r=i,n=a}),s=()=>{n(new Bt)};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 Vc=(e,t)=>{let r=Te.get(e);if(r!=null)return r;let n=oh(t);if(Hc(n))return r=n,Te.set(e,r),r;let o=new Or({concurrency:1}),s;return r={async readLock(i){if(s!=null)return fi(s,i);s=new Or({concurrency:t.concurrency,autoStart:!1});let a=s,c=fi(s,i);return o.add(async()=>{a.start(),await a.onIdle().then(()=>{s===a&&(s=null)})}),c},async writeLock(i){return s=null,fi(o,i)},finalize:()=>{Te.delete(e)},queue:o},Te.set(e,r),t.autoFinalize===!0&&o.addEventListener("idle",()=>{r.finalize()},{once:!0}),r};var sh={name:"lock",concurrency:1/0,singleProcess:!1,autoFinalize:!1};function li(e){let t=Object.assign({},sh,e);return Vc(t.name,t)}var Gt;(function(e){let t;(function(a){let c;a.codec=()=>(c==null&&(c=wt((l,h,w={})=>{w.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)),w.lengthDelimited!==!1&&h.ldelim()},(l,h,w={})=>{let g={key:"",value:ot(0)},b=h==null?l.len:l.pos+h;for(;l.pos<b;){let x=l.uint32();switch(x>>>3){case 1:{g.key=l.string();break}case 2:{g.value=l.bytes();break}default:{l.skipType(x&7);break}}}return g},function*(l,h,w,g={}){let b=h==null?l.len:l.pos+h;for(;l.pos<b;){let x=l.uint32();switch(x>>>3){case 1:{yield{field:`${w}.key`,value:l.string()};break}case 2:{yield{field:`${w}.value`,value:l.bytes()};break}default:{l.skipType(x&7);break}}}})),c);function f(l){return bt(l,a.codec())}a.encode=f;function u(l,h){return yt(l,a.codec(),h)}a.decode=u;function d(l,h){return gt(l,a.codec(),h)}a.stream=d})(t=e.Peer$metadataEntry||(e.Peer$metadataEntry={}));let r;(function(a){let c;a.codec=()=>(c==null&&(c=wt((l,h,w={})=>{w.lengthDelimited!==!1&&h.fork(),l.key!=null&&l.key!==""&&(h.uint32(10),h.string(l.key)),l.value!=null&&(h.uint32(18),Kr.codec().encode(l.value,h)),w.lengthDelimited!==!1&&h.ldelim()},(l,h,w={})=>{let g={key:""},b=h==null?l.len:l.pos+h;for(;l.pos<b;){let x=l.uint32();switch(x>>>3){case 1:{g.key=l.string();break}case 2:{g.value=Kr.codec().decode(l,l.uint32(),{limits:w.limits?.value});break}default:{l.skipType(x&7);break}}}return g},function*(l,h,w,g={}){let b=h==null?l.len:l.pos+h;for(;l.pos<b;){let x=l.uint32();switch(x>>>3){case 1:{yield{field:`${w}.key`,value:l.string()};break}case 2:{yield*Kr.codec().stream(l,l.uint32(),`${w}.value`,{limits:g.limits?.value});break}default:{l.skipType(x&7);break}}}})),c);function f(l){return bt(l,a.codec())}a.encode=f;function u(l,h){return yt(l,a.codec(),h)}a.decode=u;function d(l,h){return gt(l,a.codec(),h)}a.stream=d})(r=e.Peer$tagsEntry||(e.Peer$tagsEntry={}));let n;e.codec=()=>(n==null&&(n=wt((a,c,f={})=>{if(f.lengthDelimited!==!1&&c.fork(),a.addresses!=null&&a.addresses.length>0)for(let u of a.addresses)c.uint32(10),Pr.codec().encode(u,c);if(a.protocols!=null&&a.protocols.length>0)for(let u of a.protocols)c.uint32(18),c.string(u);if(a.publicKey!=null&&(c.uint32(34),c.bytes(a.publicKey)),a.peerRecordEnvelope!=null&&(c.uint32(42),c.bytes(a.peerRecordEnvelope)),a.metadata!=null&&a.metadata.size>0)for(let[u,d]of a.metadata.entries())c.uint32(50),e.Peer$metadataEntry.codec().encode({key:u,value:d},c);if(a.tags!=null&&a.tags.size>0)for(let[u,d]of a.tags.entries())c.uint32(58),e.Peer$tagsEntry.codec().encode({key:u,value:d},c);a.updated!=null&&(c.uint32(64),c.uint64Number(a.updated)),f.lengthDelimited!==!1&&c.ldelim()},(a,c,f={})=>{let u={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(f.limits?.addresses!=null&&u.addresses.length===f.limits.addresses)throw new Lt('Decode error - repeated field "addresses" had too many elements');u.addresses.push(Pr.codec().decode(a,a.uint32(),{limits:f.limits?.addresses$}));break}case 2:{if(f.limits?.protocols!=null&&u.protocols.length===f.limits.protocols)throw new Lt('Decode error - repeated field "protocols" had too many elements');u.protocols.push(a.string());break}case 4:{u.publicKey=a.bytes();break}case 5:{u.peerRecordEnvelope=a.bytes();break}case 6:{if(f.limits?.metadata!=null&&u.metadata.size===f.limits.metadata)throw new Er('Decode error - map field "metadata" had too many elements');let h=e.Peer$metadataEntry.codec().decode(a,a.uint32(),{limits:{value:f.limits?.metadata$value}});u.metadata.set(h.key,h.value);break}case 7:{if(f.limits?.tags!=null&&u.tags.size===f.limits.tags)throw new Er('Decode error - map field "tags" had too many elements');let h=e.Peer$tagsEntry.codec().decode(a,a.uint32(),{limits:{value:f.limits?.tags$value}});u.tags.set(h.key,h.value);break}case 8:{u.updated=a.uint64Number();break}default:{a.skipType(l&7);break}}}return u},function*(a,c,f,u={}){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(u.limits?.addresses!=null&&d.addresses===u.limits.addresses)throw new Lt('Streaming decode error - repeated field "addresses" had too many elements');for(let w of Pr.codec().stream(a,a.uint32(),`${f}.addresses[]`,{limits:u.limits?.addresses$}))yield{...w,index:d.addresses};d.addresses++;break}case 2:{if(u.limits?.protocols!=null&&d.protocols===u.limits.protocols)throw new Lt('Streaming decode error - repeated field "protocols" had too many elements');yield{field:`${f}.protocols[]`,index:d.protocols,value:a.string()},d.protocols++;break}case 4:{yield{field:`${f}.publicKey`,value:a.bytes()};break}case 5:{yield{field:`${f}.peerRecordEnvelope`,value:a.bytes()};break}case 6:{if(u.limits?.metadata!=null&&d.metadata===u.limits.metadata)throw new Lt('Decode error - map field "metadata" had too many elements');yield*e.Peer$metadataEntry.codec().stream(a,a.uint32(),`${f}.metadata{}`,{limits:{value:u.limits?.metadata$value}}),d.metadata++;break}case 7:{if(u.limits?.tags!=null&&d.tags===u.limits.tags)throw new Lt('Decode error - map field "tags" had too many elements');yield*e.Peer$tagsEntry.codec().stream(a,a.uint32(),`${f}.tags{}`,{limits:{value:u.limits?.tags$value}}),d.tags++;break}case 8:{yield{field:`${f}.updated`,value:a.uint64Number()};break}default:{a.skipType(h&7);break}}}})),n);function o(a){return bt(a,e.codec())}e.encode=o;function s(a,c){return yt(a,e.codec(),c)}e.decode=s;function i(a,c){return gt(a,e.codec(),c)}e.stream=i})(Gt||(Gt={}));var Pr;(function(e){let t;e.codec=()=>(t==null&&(t=wt((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:ot(0)},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{c.multiaddr=s.bytes();break}case 2:{c.isCertified=s.bool();break}case 3:{c.observed=s.uint64Number();break}default:{s.skipType(u&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.multiaddr`,value:s.bytes()};break}case 2:{yield{field:`${a}.isCertified`,value:s.bool()};break}case 3:{yield{field:`${a}.observed`,value:s.uint64Number()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return bt(s,e.codec())}e.encode=r;function n(s,i){return yt(s,e.codec(),i)}e.decode=n;function o(s,i){return gt(s,e.codec(),i)}e.stream=o})(Pr||(Pr={}));var Kr;(function(e){let t;e.codec=()=>(t==null&&(t=wt((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},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{c.value=s.uint32();break}case 2:{c.expiry=s.uint64();break}default:{s.skipType(u&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.value`,value:s.uint32()};break}case 2:{yield{field:`${a}.expiry`,value:s.uint64()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return bt(s,e.codec())}e.encode=r;function n(s,i){return yt(s,e.codec(),i)}e.decode=n;function o(s,i){return gt(s,e.codec(),i)}e.stream=o})(Kr||(Kr={}));function ih(e,t){if(e.publicKey!=null||t.publicKey==null)return e;let r;e.type==="RSA"&&(r=e.toMultihash());let n=Tn(t.publicKey,r);return yc(n)}function $c(e,t,r){let n=Gt.decode(t);return Xe(e,n,r)}function Xe(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:ih(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 Wc(e,t){return ah(e.addresses,t.addresses)&&ch(e.protocols,t.protocols)&&uh(e.publicKey,t.publicKey)&&fh(e.peerRecordEnvelope,t.peerRecordEnvelope)&&lh(e.metadata,t.metadata)&&dh(e.tags,t.tags)}function ah(e,t){return Yc(e,t,(r,n)=>!(r.isCertified!==n.isCertified||!Z(r.multiaddr,n.multiaddr)))}function ch(e,t){return Yc(e,t,(r,n)=>r===n)}function uh(e,t){return jc(e,t)}function fh(e,t){return jc(e,t)}function lh(e,t){return Zc(e,t,(r,n)=>Z(r,n))}function dh(e,t){return Zc(e,t,(r,n)=>r.value===n.value&&r.expiry===n.expiry)}function jc(e,t){return e==null&&t==null?!0:e!=null&&t!=null?Z(e,t):!1}function Yc(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 Zc(e,t,r){if(e.size!==t.size)return!1;for(let[n,o]of e.entries()){let s=t.get(n);if(s==null||!r(o,s))return!1}return!0}var Xt="/",Gc=new TextEncoder().encode(Xt),ro=Gc[0],no=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]!==ro)throw new Error("Invalid key")}toString(t="utf8"){return z(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new e(t.join(Xt))}static random(){return new e(Math.random().toString().substring(2))}static asKey(t){return t instanceof Uint8Array||typeof t=="string"?new e(t):typeof t.uint8Array=="function"?new e(t.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=Gc),this._buf[0]!==ro){let t=new Uint8Array(this._buf.byteLength+1);t.fill(ro,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===ro;)this._buf=this._buf.subarray(0,-1)}less(t){let r=this.list(),n=t.list();for(let o=0;o<r.length;o++){if(n.length<o+1)return!1;let s=r[o],i=n[o];if(s<i)return!0;if(s>i)return!1}return r.length<n.length}reverse(){return e.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let t=this.namespaces();return t[t.length-1]}list(){return this.toString().split(Xt).slice(1)}type(){return hh(this.baseNamespace())}name(){return ph(this.baseNamespace())}instance(t){return new e(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(Xt)||(t+=Xt),t+=this.type(),new e(t)}parent(){let t=this.list();return t.length===1?new e(Xt):new e(t.slice(0,-1).join(Xt))}child(t){return this.toString()===Xt?t:t.toString()===Xt?this:new e(this.toString()+t.toString(),!1)}isAncestorOf(t){return t.toString()===this.toString()?!1:t.toString().startsWith(this.toString())}isDecendantOf(t){return t.toString()===this.toString()?!1:this.toString().startsWith(t.toString())}isTopLevel(){return this.list().length===1}concat(...t){return e.withNamespaces([...this.namespaces(),...mh(t.map(r=>r.namespaces()))])}};function hh(e){let t=e.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function ph(e){let t=e.split(":");return t[t.length-1]}function mh(e){return[].concat(...e)}var di="/peers/";function Nr(e){if(!Re(e)||e.type==null)throw new q("Invalid PeerId");let t=e.toCID().toString();return new no(`${di}${t}`)}async function Xc(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)),!Pn(i.multiaddr))throw new q("Multiaddr was invalid");if(!await t(e,i.multiaddr,o))continue;let a=i.isCertified??!1,c=i.multiaddr.toString(),f=s.get(c);f!=null?i.isCertified=f.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(f=>f.code===421)?.value;return e.equals(c)&&(a=a.decapsulate(Ae(`/p2p/${e}`))),{isCertified:i,multiaddr:a.bytes}})}async function so(e,t,r,n){if(t==null)throw new q("Invalid PeerData");if(t.publicKey!=null&&!e.equals(t.publicKey.toMultihash().bytes))throw new q("publicKey does not match peer id");let o=n.existingPeer?.peer;if(o!=null&&!e.equals(o.id))throw new q("peer id did not match existing peer id");let s=o?.addresses??[],i=new Set(o?.protocols??[]),a=o?.metadata??new Map,c=o?.tags??new Map,f=o?.peerRecordEnvelope;if(r==="patch"){if((t.multiaddrs!=null||t.addresses!=null)&&(s=[],t.multiaddrs!=null&&s.push(...t.multiaddrs.map(l=>({isCertified:!1,multiaddr:l}))),t.addresses!=null&&s.push(...t.addresses)),t.protocols!=null&&(i=new Set(t.protocols)),t.metadata!=null){let l=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);a=oo(l,{validate:Qc})}if(t.tags!=null){let l=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags);c=oo(l,{validate:Jc,map:tu})}t.peerRecordEnvelope!=null&&(f=t.peerRecordEnvelope)}if(r==="merge"){if(t.multiaddrs!=null&&s.push(...t.multiaddrs.map(l=>({isCertified:!1,multiaddr:l}))),t.addresses!=null&&s.push(...t.addresses),t.protocols!=null&&(i=new Set([...i,...t.protocols])),t.metadata!=null){let l=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);for(let[h,w]of l)w==null?a.delete(h):a.set(h,w);a=oo([...a.entries()],{validate:Qc})}if(t.tags!=null){let l=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags),h=new Map(c);for(let[w,g]of l)g==null?h.delete(w):h.set(w,g);c=oo([...h.entries()],{validate:Jc,map:tu})}t.peerRecordEnvelope!=null&&(f=t.peerRecordEnvelope)}let u;o?.id.publicKey!=null?u=_t(o.id.publicKey):t.publicKey!=null?u=_t(t.publicKey):e.publicKey!=null&&(u=_t(e.publicKey));let d={addresses:await Xc(e,n.addressFilter??(async()=>!0),s,n.existingPeer?.peerPB.addresses,n),protocols:[...i.values()].sort((l,h)=>l.localeCompare(h)),metadata:a,tags:c,publicKey:u,peerRecordEnvelope:f};return d.addresses.forEach(l=>{l.observed=n.existingPeer?.peerPB.addresses?.find(h=>Z(h.multiaddr,l.multiaddr))?.observed??Date.now()}),e.type!=="RSA"&&delete d.publicKey,d}function oo(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 Qc(e,t){if(typeof e!="string")throw new q("Metadata key must be a string");if(!(t instanceof Uint8Array))throw new q("Metadata value must be a Uint8Array")}function Jc(e,t){if(typeof e!="string")throw new q("Tag name must be a string");if(t.value!=null){if(parseInt(`${t.value}`,10)!==t.value)throw new q("Tag value must be an integer");if(t.value<0||t.value>100)throw new q("Tag value must be between 0-100")}if(t.ttl!=null){if(parseInt(`${t.ttl}`,10)!==t.ttl)throw new q("Tag ttl must be an integer");if(t.ttl<0)throw new q("Tag ttl must be between greater than 0")}}function tu(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 eu(e){let t=e.toString().split("/")[2],r=st.parse(t,Ut);return _n(r)}function hi(e,t,r){let n=eu(e);return $c(n,t,r)}function yh(e,t){return{prefix:di,filters:(e.filters??[]).map(r=>({key:n,value:o})=>r(hi(n,o,t))),orders:(e.orders??[]).map(r=>(n,o)=>r(hi(n.key,n.value,t),hi(o.key,o.value,t)))}}var io=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=si({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:li({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(Nr(t),r)}async load(t,r){let n=Nr(t),o=await this.datastore.get(n,r),s=Gt.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,r),new tr;return Xe(t,s,this.peerId.equals(t)?1/0:this.maxAddressAge)}async save(t,r,n){let o=await this.#t(t,n),s=await so(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 so(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 so(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(yh(t??{},this.maxAddressAge),t)){let o=eu(r);if(o.equals(this.peerId))continue;let s=Gt.decode(n);if(this.#r(o,s)){await this.datastore.delete(r,t);continue}yield Xe(o,s,this.peerId.equals(o)?1/0:this.maxAddressAge)}}async#t(t,r){try{let n=Nr(t),o=await this.datastore.get(n,r),s=Gt.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,r),new tr;return{peerPB:s,peer:Xe(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=Gt.encode(r);return await this.datastore.put(Nr(t),s,o),{peer:Xe(t,r,this.maxAddressAge),previous:n?.peer,updated:n==null||!Wc(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 pi=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 io(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 Kc(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=Re(r)?r:Re(r?.expectedPeer)?r.expectedPeer:void 0,s=Re(r)||r===void 0?n:r,i=await Ye.openAndCertify(t,Be.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=Be.createFromProtobuf(i.payload);if(!c.peerId.equals(a))return this.log("signing key did not match peer id in the peer record - signer: %p record: %p",a,c.peerId),!1;let f;try{f=await this.get(a,s)}catch(u){if(u.name!=="NotFoundError")throw u}if(f?.peerRecordEnvelope!=null){let u=Ye.createFromProtobuf(f.peerRecordEnvelope),d=Be.createFromProtobuf(u.payload);if(d.seqNumber>=c.seqNumber)return this.log("sequence number was lower or equal to existing sequence number - stored: %d received: %d",d.seqNumber,c.seqNumber),!1}return await this.patch(c.peerId,{peerRecordEnvelope:t,addresses:c.multiaddrs.map(u=>({isCertified:!0,multiaddr:u}))},s),!0}#t(t,r){r.updated&&(this.peerId.equals(t)?this.events.safeDispatchEvent("self:peer:update",{detail:r}):this.events.safeDispatchEvent("peer:update",{detail:r}))}};function bh(e,t={}){return new pi(e,t)}return uu(gh);})();
|
|
2
|
+
"use strict";var Libp2PPeerStore=(()=>{var co=Object.defineProperty;var au=Object.getOwnPropertyDescriptor;var cu=Object.getOwnPropertyNames;var uu=Object.prototype.hasOwnProperty;var xt=(e,t)=>{for(var r in t)co(e,r,{get:t[r],enumerable:!0})},fu=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of cu(t))!uu.call(e,o)&&o!==r&&co(e,o,{get:()=>t[o],enumerable:!(n=au(t,o))||n.enumerable});return e};var lu=e=>fu(co({},"__esModule",{value:!0}),e);var Eh={};xt(Eh,{persistentPeerStore:()=>xh});var q=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Ie=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var tr=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var Ur=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Mr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var de=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Fr=Symbol.for("@libp2p/peer-id");function Re(e){return!!e?.[Fr]}function du(e){return typeof e?.handleEvent=="function"}function hu(e){return e===!0||e===!1}function pu(e){return hu(e)?e:e?.capture??!1}function uo(e){let t={capture:pu(e),once:!!e?.once};return e?.passive!=null&&(t.passive=e?.passive),e?.signal!=null&&(t.signal=e?.signal),t}function bi(e,t){return uo(e).capture===uo(t).capture}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=uo(n);if(o?.signal?.aborted===!0)return;let s=u=>{o.once&&this.removeEventListener(t,r,o),du(r)?r.handleEvent(u):r(u)},i=this.#t.get(t);if(i==null&&(i=[],this.#t.set(t,i)),i.some(u=>u.callback!==r?!1:bi(u.options,o)))return;super.addEventListener(t,s,o);let c=()=>{this.removeEventListener(t,r,o)};o.signal?.addEventListener("abort",c),i.push({callback:r,wrapper:s,options:o,onAbort:c})}removeEventListener(t,r,n){let o=this.#t.get(t);if(o==null){super.removeEventListener(t,r??null,n);return}this.#t.set(t,o.filter(s=>s.callback===r&&bi(s.options,n)?(super.removeEventListener(t,s.wrapper,n),s.options?.signal?.removeEventListener("abort",s.onAbort),!1):!0))}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var mo={};xt(mo,{base58btc:()=>nt,base58flickr:()=>vu});var Th=new Uint8Array(0);function wi(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 Tt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return he(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return he(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));throw new Error("Unknown type, must be binary type")}function xi(e){let t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}var gi=4096;function Ei(e){let t=e.length;if(t<=gi)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.subarray(n,n+=gi));return r}function mu(e){return e?.buffer instanceof ArrayBuffer}function he(e){return mu(e)?e:e.slice()}function yu(e,t,r){if(e.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var s=0;s<e.length;s++){var i=e.charAt(s),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=s,r){var c=i.toLowerCase().charCodeAt(0),u=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=s),u!==a&&(n[u]=s)}}var f=e.length,d=e.charAt(0),l=Math.log(f)/Math.log(256),h=Math.log(256)/Math.log(f);function w(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var S=0,y=0,B=0,_=x.length;B!==_&&x[B]===0;)B++,S++;for(var U=(_-B)*h+1>>>0,M=new Uint8Array(U);B!==_;){for(var P=x[B],O=0,k=U-1;(P!==0||O<y)&&k!==-1;k--,O++)P+=256*M[k]>>>0,M[k]=P%f>>>0,P=P/f>>>0;if(P!==0)throw new Error("Non-zero carry");y=O,B++}for(var F=U-y;F!==U&&M[F]===0;)F++;for(var L=d.repeat(S);F<U;++F)L+=e.charAt(M[F]);return L}function g(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var S=0;if(x[S]!==" "){for(var y=0,B=0;x[S]===d;)y++,S++;for(var _=(x.length-S)*l+1>>>0,U=new Uint8Array(_);x[S];){var M=n[x.charCodeAt(S)];if(M===255)return;for(var P=0,O=_-1;(M!==0||P<B)&&O!==-1;O--,P++)M+=f*U[O]>>>0,U[O]=M%256>>>0,M=M/256>>>0;if(M!==0)throw new Error("Non-zero carry");B=P,S++}if(x[S]!==" "){for(var k=_-B;k!==_&&U[k]===0;)k++;for(var F=new Uint8Array(y+(_-k)),L=y;k!==_;)F[L++]=U[k++];return F}}}function b(x){var S=g(x);if(S)return S;throw new Error(`Non-${t} character`)}return{encode:w,decodeUnsafe:g,decode:b}}var bu=yu,gu=bu,Si=gu;var fo=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")}},lo=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 Ai(this,t)}},ho=class{decoders;constructor(t){this.decoders=t}or(t){return Ai(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 Ai(e,t){return new ho({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var po=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 fo(t,r,n),this.decoder=new lo(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Le({name:e,prefix:t,encode:r,decode:n}){return new po(e,t,r,n)}function Jt({name:e,prefix:t,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:s}=Si(r,e,n);return Le({prefix:t,name:e,encode:o,decode:i=>Tt(s(i))})}function wu(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 xu(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 Eu(e,t){let r={};for(let n=0;n<e.length;++n)if(r[e[n]]=n,t){let o=e[n].toLowerCase(),s=e[n].toUpperCase();o!==e[n]&&(r[o]=n),s!==e[n]&&(r[s]=n)}return r}function rt({name:e,prefix:t,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let s=Eu(n,o);return Le({prefix:t,name:e,encode(i){return xu(i,n,r)},decode(i){return wu(i,s,r,e)}})}var nt=Jt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),vu=Jt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var yo={};xt(yo,{base32:()=>Ut,base32hex:()=>Tu,base32hexpad:()=>Iu,base32hexpadupper:()=>Ru,base32hexupper:()=>_u,base32pad:()=>Au,base32padupper:()=>Bu,base32upper:()=>Su,base32z:()=>Cu});var Ut=rt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Su=rt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Au=rt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Bu=rt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Tu=rt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),_u=rt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),Iu=rt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),Ru=rt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),Cu=rt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var bo={};xt(bo,{base36:()=>er,base36upper:()=>Lu});var er=Jt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),Lu=Jt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Du=_i,Bi=128,Ou=127,ku=~Ou,Pu=Math.pow(2,31);function _i(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Pu;)t[r++]=e&255|Bi,e/=128;for(;e&ku;)t[r++]=e&255|Bi,e>>>=7;return t[r]=e|0,_i.bytes=r-n+1,t}var Ku=go,Nu=128,Ti=127;function go(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw go.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Ti)<<o:(i&Ti)*Math.pow(2,o),o+=7}while(i>=Nu);return go.bytes=s-n,r}var Uu=Math.pow(2,7),Mu=Math.pow(2,14),Fu=Math.pow(2,21),qu=Math.pow(2,28),zu=Math.pow(2,35),Hu=Math.pow(2,42),Vu=Math.pow(2,49),$u=Math.pow(2,56),Wu=Math.pow(2,63),ju=function(e){return e<Uu?1:e<Mu?2:e<Fu?3:e<qu?4:e<zu?5:e<Hu?6:e<Vu?7:e<$u?8:e<Wu?9:10},Yu={encode:Du,decode:Ku,encodingLength:ju},Zu=Yu,rr=Zu;function nr(e,t=0){let r=rr.decode(e,t),n=rr.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&e[t+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function De(e,t,r=0){return rr.encode(e,t,r),t}function Oe(e){return rr.encodingLength(e)}function Mt(e,t){let r=t.byteLength,n=Oe(e),o=n+Oe(r),s=new Uint8Array(o+r);return De(e,s,0),De(r,s,n),s.set(t,o),new ke(e,r,t,s)}function Pe(e){let t=Tt(e),[r,n]=nr(t),[o,s]=nr(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 Ii(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&wi(e.bytes,r.bytes)}}var ke=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=he(n),this.bytes=he(o)}};function Ri(e,t){let{bytes:r,version:n}=e;return n===0?Xu(r,wo(e),t??nt.encoder):Qu(r,wo(e),t??Ut.encoder)}var Ci=new WeakMap;function wo(e){let t=Ci.get(e);if(t==null){let r=new Map;return Ci.set(e,r),r}return t}var st=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=he(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:t,multihash:r}=this;if(t!==or)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Ju)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=Mt(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&&Ii(t.multihash,n.multihash)}toString(t){return Ri(this,t)}toJSON(){return{"/":Ri(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??Li(n,o,s.bytes))}else if(r[tf]===!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!==or)throw new Error(`Version 0 CID must use dag-pb (code: ${or}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Li(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,or,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=Tt(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[d,l]=nr(t.subarray(r));return r+=l,d},o=n(),s=or;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]=Gu(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 wo(s).set(n,t),s}};function Gu(e,t){switch(e[0]){case"Q":{let r=t??nt;return[nt.prefix,r.decode(`${nt.prefix}${e}`)]}case nt.prefix:{let r=t??nt;return[nt.prefix,r.decode(e)]}case Ut.prefix:{let r=t??Ut;return[Ut.prefix,r.decode(e)]}case er.prefix:{let r=t??er;return[er.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 Xu(e,t,r){let{prefix:n}=r;if(n!==nt.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 Qu(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 or=112,Ju=18;function Li(e,t,r){let n=Oe(e),o=n+Oe(t),s=new Uint8Array(o+r.byteLength);return De(e,s,0),De(t,s,n),s.set(r,o),s}var tf=Symbol.for("@ipld/js-cid/CID");var xo={};xt(xo,{identity:()=>Ot});var Di=0,ef="identity",Oi=Tt;function rf(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 Mt(Di,Oi(e))}var Ot={code:Di,name:ef,encode:Oi,digest:rf};function Z(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 nf(e){return e.buffer instanceof ArrayBuffer}function pt(e){return nf(e)?e:e.slice()}async function ki(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,pt(t),pt(r.subarray()));return n?.signal?.throwIfAborted(),s}function ot(e=0){return new Uint8Array(e)}function ft(e=0){return new Uint8Array(e)}function of(e){return e?.buffer instanceof ArrayBuffer}function Eo(e){if(of(e))return e;let t=e.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function Ft(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=ft(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return Eo(r)}var Ki=Symbol.for("@achingbrain/uint8arraylist");function Pi(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 zr(e){return!!e?.[Ki]}var mt=class e{bufs;length;[Ki]=!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(zr(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(zr(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=Pi(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Pi(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(zr(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 Ft(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Ft(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 d=t-a;n.push(i.subarray(d,d+(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(!zr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let d=0;d<s;d++)i[d]=-1;for(let d=0;d<o;d++)i[n[d]]=d;let a=i,c=this.byteLength-n.byteLength,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(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=ft(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=ot(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=ot(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=ot(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=ft(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=ot(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=ot(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=ot(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=ot(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=ot(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(!Z(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 vo={};xt(vo,{base10:()=>sf});var sf=Jt({prefix:"9",name:"base10",alphabet:"0123456789"});var So={};xt(So,{base16:()=>af,base16upper:()=>cf});var af=rt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),cf=rt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Ao={};xt(Ao,{base2:()=>uf});var uf=rt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Bo={};xt(Bo,{base256emoji:()=>pf});var Ni=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}"),ff=Ni.reduce((e,t,r)=>(e[r]=t,e),[]),lf=Ni.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function df(e){return e.reduce((t,r)=>(t+=ff[r],t),"")}function hf(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=lf[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var pf=Le({prefix:"\u{1F680}",name:"base256emoji",encode:df,decode:hf});var _o={};xt(_o,{base64:()=>mf,base64pad:()=>yf,base64url:()=>To,base64urlpad:()=>bf});var mf=rt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),yf=rt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),To=rt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),bf=rt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Io={};xt(Io,{base8:()=>gf});var gf=rt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ro={};xt(Ro,{identity:()=>wf});var wf=Le({prefix:"\0",name:"identity",encode:e=>Ei(Tt(e)),decode:e=>Tt(xi(e))});var lp=new TextEncoder,dp=new TextDecoder;var Do={};xt(Do,{sha256:()=>sr,sha512:()=>Sf});var vf=20;function Lo({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Co(e,t,r,n,o)}var Co=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??vf,this.maxDigestLength=s}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Ui(n,this.code,r?.truncate):n.then(o=>Ui(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ui(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Mt(t,e)}function Fi(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var sr=Lo({name:"sha2-256",code:18,encode:Fi("SHA-256")}),Sf=Lo({name:"sha2-512",code:19,encode:Fi("SHA-512")});var ir={...Ro,...Ao,...Io,...vo,...So,...yo,...bo,...mo,..._o,...Bo},Ap={...Do,...xo};function zi(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var qi=zi("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Oo=zi("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=ft(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Af={utf8:qi,"utf-8":qi,hex:ir.base16,latin1:Oo,ascii:Oo,binary:Oo,...ir},Hr=Af;function V(e,t="utf8"){let r=Hr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function z(e,t="utf8"){let r=Hr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Bf=parseInt("11111",2),ko=parseInt("10000000",2),Tf=parseInt("01111111",2),Hi={0:ar,1:ar,2:_f,3:Cf,4:Lf,5:Rf,6:If,16:ar,22:ar,48:ar};function Vt(e,t={offset:0}){let r=e[t.offset]&Bf;if(t.offset++,Hi[r]!=null)return Hi[r](e,t);throw new Error("No decoder for tag "+r)}function cr(e,t){let r=0;if((e[t.offset]&ko)===ko){let n=e[t.offset]&Tf,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++){if(t.offset>=e.byteLength)throw new Error("invalid DER element length");o+=e[t.offset].toString(16).padStart(2,"0")}r=parseInt(o,16)}else r=e[t.offset],t.offset++;if(!Number.isInteger(r)||r<0||r>e.byteLength-t.offset)throw new Error("invalid DER element length");return r}function ar(e,t){cr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Vt(e,t);if(n===null)break;r.push(n)}return r}function _f(e,t){let r=cr(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 If(e,t){let r=cr(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 d=0;d<c.length;d++)f+=c[d]<<d*7;a+=`.${f}`,c=[]}}return a}function Rf(e,t){return t.offset++,null}function Cf(e,t){let r=cr(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 Lf(e,t){let r=cr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Df(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new mt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Po(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Df(e.byteLength);return new mt(Uint8Array.from([t.byteLength|ko]),t)}function Et(e){let t=new mt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new mt(Uint8Array.from([2]),Po(t),t)}function Vr(e){let t=Uint8Array.from([0]),r=new mt(t,e);return new mt(Uint8Array.from([3]),Po(r),r)}function ee(e,t=48){let r=new mt;for(let n of e)r.append(n);return new mt(Uint8Array.from([t]),Po(r),r)}var Of=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),kf=Uint8Array.from([6,5,43,129,4,0,34]),Pf=Uint8Array.from([6,5,43,129,4,0,35]),Kf={ext:!0,kty:"EC",crv:"P-256"},Nf={ext:!0,kty:"EC",crv:"P-384"},Uf={ext:!0,kty:"EC",crv:"P-521"},Ko=32,No=48,Uo=66;function Mo(e){let t=Vt(e);return Vi(t)}function Vi(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Ko*2+1)return n=z(t.subarray(r,r+Ko),"base64url"),o=z(t.subarray(r+Ko),"base64url"),new Ke({...Kf,key_ops:["verify"],x:n,y:o});if(t.byteLength===No*2+1)return n=z(t.subarray(r,r+No),"base64url"),o=z(t.subarray(r+No),"base64url"),new Ke({...Nf,key_ops:["verify"],x:n,y:o});if(t.byteLength===Uo*2+1)return n=z(t.subarray(r,r+Uo),"base64url"),o=z(t.subarray(r+Uo),"base64url"),new Ke({...Uf,key_ops:["verify"],x:n,y:o});throw new q(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function $i(e){return ee([Et(Uint8Array.from([1])),ee([Mf(e.crv)],160),ee([Vr(new mt(Uint8Array.from([4]),V(e.x??"","base64url"),V(e.y??"","base64url")))],161)]).subarray()}function Mf(e){if(e==="P-256")return Of;if(e==="P-384")return kf;if(e==="P-521")return Pf;throw new q(`Invalid curve ${e}`)}var Ke=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=$i(this.jwk)),this._raw}toMultihash(){return Ot.digest(_t(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return nt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Z(this.raw,t.raw)}async verify(t,r,n){return ki(this.jwk,r,t,n)}};var $r=BigInt(4294967295),Wi=BigInt(32);function Ff(e,t=!1){return t?{h:Number(e&$r),l:Number(e>>Wi&$r)}:{h:Number(e>>Wi&$r)|0,l:Number(e&$r)|0}}function ji(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}=Ff(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var qf=e=>e/2**32|0,zf=e=>e>>>0;function Yi(e,t,r,n){let o=qf(r),s=zf(r);e.setUint32(t,n?s:o,n),e.setUint32(t+4,n?o:s,n)}var Fo=(e,t,r)=>e>>>r,qo=(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,ur=(e,t,r)=>e<<64-r|t>>>r-32,fr=(e,t,r)=>e>>>r-32|t<<64-r;function qt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Zi=(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;function Wr(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}var zo=e=>e?`"${e}" `:"";function $t(e,t=""){if(typeof e!="number")throw new TypeError(zo(t)+"expected number, got "+typeof e);if(!Number.isSafeInteger(e)||e<0)throw new RangeError(zo(t)+"expected integer >= 0, got "+e);return e}function It(e,t,r=""){if(Wr(e)&&(t===void 0||e.length===t))return e;t!==void 0&&$t(t,"length");let n=Wr(e),o=t!==void 0?` of length ${t}`:"",s=n?`length=${e.length}`:`type=${typeof e}`,i=zo(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function jr(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if($t(e.outputLen),$t(e.blockLen),e.outputLen<1||e.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var ea=(e,t)=>{if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError((t==="object"?"":`"${t}" `)+"expected object, got type="+typeof e)};function Ne(e,t=!0){if(e.destroyed)throw new Error("hash was destroyed");if(t&&e.finished)throw new Error("digest() was already called")}function Yr(e,t){It(e,void 0,"output");let r=t.outputLen;if(!(e.length>=r))throw new RangeError('"output" expected length >= '+r)}function ye(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Zr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function kt(e,t){return e<<32-t|e>>>t}var na=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Vf=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Gr(e){if(It(e),na)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Vf[e[r]];return t}function ra(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function Xr(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(na)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=ra(e.charCodeAt(s)),a=ra(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 Ho(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];It(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 $f(e,t,r="opts"){return ea(e,"defaults"),t!==void 0&&ea(t,r),Object.assign(e,t)}function Vo(e,t={}){if(typeof e!="function")throw new TypeError('"hashCons" expected function, got type='+typeof e);t=$f({},t,"info");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 oa(e=32){$t(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 $o=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function sa(e,t,r){return e&t^~e&r}function ia(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=Zr(this.buffer)}update(t){Ne(this),It(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length,i=!1;for(let a=0;a<s;){let c=Math.min(o-this.pos,s-a);if(c===o){let u=Zr(t);for(;o<=s-a;a+=o)this.process(u,a);i=!0;continue}n.set(a===0&&c===s?t:t.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===o&&(this.process(r,0),this.pos=0,i=!0)}return this.length+=t.length,i&&this.roundClean(),this}digestInto(t){Ne(this),Yr(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,r.fill(0,i),this.padOffset>o-i&&(this.process(n,0),r.fill(0)),Yi(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let a=t===r?n:Zr(t),c=this.outputLen,u=c/4,f=this.get();if(c%4||u>f.length)throw new Error("invalid outputLen");for(let d=0;d<u;d++)a.setUint32(4*d,f[d],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneIntoMeta(t){let{buffer:r,length:n,finished:o,destroyed:s,pos:i}=this;return t.destroyed=s,t.finished=o,t.length=n,t.pos=i,i&&t.buffer.set(r),t}clone(){return this._cloneInto()}},aa=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ca=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Wf=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]),re=new Uint32Array(64),Wo=class extends lr{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(t,r){super(64,t,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}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}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,r){for(let d=0;d<16;d++,r+=4)re[d]=t.getUint32(r,!1);for(let d=16;d<64;d++){let l=re[d-15],h=re[d-2],w=kt(l,7)^kt(l,18)^l>>>3,g=kt(h,17)^kt(h,19)^h>>>10;re[d]=g+re[d-7]+w+re[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=kt(a,6)^kt(a,11)^kt(a,25),h=f+l+sa(a,c,u)+Wf[d]+re[d]|0,g=(kt(n,2)^kt(n,13)^kt(n,22))+ia(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(){ye(re)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),ye(this.buffer)}},jo=class extends Wo{constructor(){super(32,aa)}};var ua=ji(["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))),jf=ua[0],Yf=ua[1],ne=new Uint32Array(80),oe=new Uint32Array(80),Yo=class extends lr{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(t,r){super(128,t,16,!1),this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:t,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:w,Hh:g,Hl:b}=this;return[t,r,n,o,s,i,a,c,u,f,d,l,h,w,g,b]}set(t,r,n,o,s,i,a,c,u,f,d,l,h,w,g,b){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=d|0,this.Fl=l|0,this.Gh=h|0,this.Gl=w|0,this.Hh=g|0,this.Hl=b|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,r){for(let y=0;y<16;y++,r+=4)ne[y]=t.getUint32(r),oe[y]=t.getUint32(r+=4);for(let y=16;y<80;y++){let B=ne[y-15]|0,_=oe[y-15]|0,U=pe(B,_,1)^pe(B,_,8)^Fo(B,_,7),M=me(B,_,1)^me(B,_,8)^qo(B,_,7),P=ne[y-2]|0,O=oe[y-2]|0,k=pe(P,O,19)^ur(P,O,61)^Fo(P,O,6),F=me(P,O,19)^fr(P,O,61)^qo(P,O,6),L=Xi(M,F,oe[y-7],oe[y-16]),G=Qi(L,U,k,ne[y-7],ne[y-16]);ne[y]=G|0,oe[y]=L|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:w,Gh:g,Gl:b,Hh:x,Hl:S}=this;for(let y=0;y<80;y++){let B=pe(d,l,14)^pe(d,l,18)^ur(d,l,41),_=me(d,l,14)^me(d,l,18)^fr(d,l,41),U=d&h^~d&g,M=l&w^~l&b,P=Ji(S,_,M,Yf[y],oe[y]),O=ta(P,x,B,U,jf[y],ne[y]),k=P|0,F=pe(n,o,28)^ur(n,o,34)^ur(n,o,39),L=me(n,o,28)^fr(n,o,34)^fr(n,o,39),G=n&s^n&a^s&a,C=o&i^o&c^i&c;x=g|0,S=b|0,g=h|0,b=w|0,h=d|0,w=l|0,{h:d,l}=qt(u|0,f|0,O|0,k|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let R=Zi(k,L,C);n=Gi(R,O,F,G),o=R|0}({h:n,l:o}=qt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=qt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=qt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=qt(this.Dh|0,this.Dl|0,u|0,f|0),{h:d,l}=qt(this.Eh|0,this.El|0,d|0,l|0),{h,l:w}=qt(this.Fh|0,this.Fl|0,h|0,w|0),{h:g,l:b}=qt(this.Gh|0,this.Gl|0,g|0,b|0),{h:x,l:S}=qt(this.Hh|0,this.Hl|0,x|0,S|0),this.set(n,o,s,i,a,c,u,f,d,l,h,w,g,b,x,S)}roundClean(){ye(ne,oe)}destroy(){this.destroyed=!0,ye(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Zo=class extends Yo{constructor(){super(64,ca)}};var Ue=Vo(()=>new jo,$o(1));var Go=Vo(()=>new Zo,$o(3));function Jr(e,t,r=()=>{}){if(!Array.isArray(e))throw new TypeError(`"${t}" expected array, got type=${typeof e}`);for(let n=0;n<e.length;n++)r(e[n],`${t}[${n}]`);return e}var W=(e,t,r)=>It(e,t,r),Xo=$t;function la(e,t=""){if(typeof e!="string"){let r=t&&`"${t}" `;throw new TypeError(r+"expected string, got type="+typeof e)}return e}function se(e,t="object"){if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError(t==="object"?"expected valid options object":`"${t}" expected object, got type=${typeof e}`);return e}function be(e,t){if(typeof e!="function")throw new TypeError(`"${t}" is invalid: expected function, got ${typeof e}`);return e}var dr=Gr,Rt=(...e)=>Ho(...e),Me=e=>Xr(e),ae=Wr,ge=e=>oa(e),Qr=BigInt(0),fa=BigInt(1),Zf=e=>e?`"${e}" `:"";function vt(e,t=""){if(typeof e!="boolean")throw new TypeError(Zf(t)+"expected boolean, got type="+typeof e);return e}function tn(e){if(typeof e=="bigint"){if(!ie(e))throw new RangeError("positive bigint expected, got "+e)}else Xo(e);return e}function ce(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 hr(e){let t=tn(e).toString(16);return t.length&1?"0"+t:t}function da(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?Qr:BigInt("0x"+e)}function zt(e){return da(Gr(e))}function we(e){return da(Gr(rn(It(e)).reverse()))}function en(e,t){if($t(t),t===0)throw new Error("zero output length is invalid");e=tn(e);let r=t*2,n=e.toString(16);if(n.length>r)throw new RangeError("number is too large");return Xr(n.padStart(r,"0"))}function Qo(e,t){return en(e,t).reverse()}function rn(e){return Uint8Array.from(W(e))}function ie(e){return typeof e=="bigint"&&Qr<=e}function Jo(e,t,r){return ie(e)&&ie(t)&&ie(r)&&t<=e&&e<r}function Fe(e,t,r,n){if(!Jo(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function qe(e){if(e<Qr)throw new Error("expected non-negative bigint, got "+e);return e===Qr?0:e.toString(2).length}var pr=e=>(ce(e,"n"),(fa<<BigInt(e))-fa);function ha(e,t,r){if($t(e,"hashLen"),$t(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=b=>new Uint8Array(b),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(e),u=n(e),f=0,d=()=>{c.fill(1),u.fill(0),f=0},l=(...b)=>r(u,Rt(c,...b)),h=(b=o)=>{u=l(s,b),c=l(),b.length!==0&&(u=l(i,b),c=l())},w=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let b=0,x=[];for(;b<t;){c=l();let S=c.slice();x.push(S),b+=c.length}return Rt(...x)};return(b,x)=>{d(),h(b);let S;for(;(S=x(w()))===void 0;)h();return d(),S}}function St(e,t={},r={},n="object"){se(e,n),se(t,"fields"),se(r,"optFields");function o(i,a,c){let u=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,f=e[i];if(!Object.hasOwn(e,i)&&(c?f!==void 0:a!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&f===void 0)return;let d=typeof f;if(d!==a||f===null)throw new TypeError(`${u} is invalid: expected ${a}, got ${d}`)}let s=(i,a)=>Object.entries(i).forEach(([c,u])=>o(c,u,a));s(t,!1),s(r,!0)}var it=BigInt(0),j=BigInt(1),ue=BigInt(2),ya=BigInt(3),ts=BigInt(4),ba=BigInt(5),Gf=BigInt(7),ga=BigInt(8),Xf=BigInt(9),Qf=BigInt(15),wa=BigInt(16),Jf=BigInt("0x10000000000000000");function Q(e,t){if(t<=it)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=it?r:t+r}function xa(e,t,r){if(r<=j)throw new Error("pow: expected modulus > 1, got "+r);if(typeof t!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof t);if(t<it)throw new Error("invalid exponent, negatives unsupported");if(t===it)return j;if(t===j)return e;let n=e%r;if(n<it&&(n+=r),t<Jf){let a=j;for(;t>it;)t&j&&(a=a*n%r),n=n*n%r,t>>=j;return a}let o=[];for(;t>it;)o.push(Number(t&Qf)),t>>=ts;let s=new Array(16);s[0]=j,s[1]=n;for(let a=2;a<16;a++)s[a]=s[a-1]*n%r;let i=s[o[o.length-1]];for(let a=o.length-2;a>=0;a--){i=i*i%r,i=i*i%r,i=i*i%r,i=i*i%r;let c=o[a];c!==0&&(i=i*s[c]%r)}return i}function X(e,t,r){if(r<=j)throw new Error("pow2: expected modulus > 1, got "+r);if(t<it)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >it;)n*=n,n%=r;return n}function pa(e,t){if(e===it)throw new Error("invert: expected non-zero number");if(t<=j)throw new Error("invert: expected modulus > 1, got "+t);let r=Q(e,t),n=t,o=it,s=j;for(;r!==it;){let a=n/r,c=n-r*a,u=o-s*a;n=r,r=c,o=s,s=u}if(n!==j)throw new Error("invert: does not exist");return Q(o,t)}function Ea(e,t){if(t<=j)throw new Error("invertCt: expected prime modulus > 1, got "+t);let r=Q(e,t);if(r===it)throw new Error("invertCt: expected non-zero number");let n=xa(r,t-ue,t);if(Q(r*n,t)!==j)throw new Error("invertCt: does not exist");return n}function es(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function rs(e,t){if((e&j)===it)throw new Error(t+": expected odd modulus, got "+e)}function va(e,t){let r=e,n=(r.ORDER+j)/ts,o=r.pow(t,n);return es(r,o,t),o}function tl(e,t){let r=e,n=(r.ORDER-ba)/ga,o=r.mul(t,ue),s=r.pow(o,n),i=r.mul(t,s),a=r.mul(r.mul(i,ue),s),c=r.mul(i,r.sub(a,r.ONE));return es(r,c,t),c}function el(e){let t=He(e),r=Sa(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+Gf)/wa;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),w=u.eql(u.sqr(d),c),g=u.eql(u.sqr(l),c);f=u.cmov(f,d,w),d=u.cmov(h,l,g);let b=u.eql(u.sqr(d),c),x=u.cmov(f,d,b);return es(u,x,c),x})}function Sa(e){if(e<ya)throw new Error("sqrt is not defined for small field");rs(e,"tonelliShanks");let t=e-j,r=0;for(;t%ue===it;)t/=ue,r++;let n=ue,o=He(e);for(;mr(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return va;let s=o.pow(n,t),i=(t+j)/ue;return function(c,u){let f=c;if(f.is0(u))return u;if(mr(f,u)!==1)throw new Error("Cannot find square root");let d=r,l=f.mul(f.ONE,s),h=f.pow(u,t),w=f.pow(u,i);for(;!f.eql(h,f.ONE);){if(f.is0(h))throw new Error("Cannot find square root: probably non-prime P");let g=1,b=f.sqr(h);for(;!f.eql(b,f.ONE);)if(g++,b=f.sqr(b),g===d)throw new Error("Cannot find square root");let x=j<<BigInt(d-g-1),S=f.pow(l,x);d=g,l=f.sqr(S),h=f.mul(h,l),w=f.mul(w,S)}return w}}function rl(e){return rs(e,"Fp.sqrt"),e%ts===ya?va:e%ga===ba?tl:e%wa===Xf?el(e):Sa(e)}var Aa=(e,t)=>(Q(e,t)&j)===j,nl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ze(e){if(se(e,"field"),typeof e.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof e.ORDER);ce(e.BYTES,"BYTES"),ce(e.BITS,"BITS");for(let t of nl)be(e[t],"field."+t);if(e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=j)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function on(e,t,r=!1){ze(e),Jr(t,"nums"),vt(r,"passZero");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 mr(e,t){ze(e);let r=e;rs(r.ORDER,"FpLegendre");let n=(r.ORDER-j)/ue,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 ol(e,t){if(t!==void 0&&Xo(t),e<=it)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=qe(e);if(t!==void 0&&t<r)throw new Error(`invalid n length: expected nBitLength (${t}) >= bitLen(n) (${r})`);let n=t!==void 0?t:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var ma=new WeakMap,nn=class{ORDER;BITS;BYTES;isLE;ZERO=it;ONE=j;_lengths;_mod;constructor(t,r={}){if(t<=j)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}=ol(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 Q(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return it<=t&&t<this.ORDER}is0(t){return t===it}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&j)===j}neg(t){return Q(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return Q(t*t,this.ORDER)}add(t,r){return Q(t+r,this.ORDER)}sub(t,r){return Q(t-r,this.ORDER)}mul(t,r){return Q(t*r,this.ORDER)}pow(t,r){return xa(t,r,this.ORDER)}div(t,r){return Q(t*pa(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 pa(t,this.ORDER)}sqrt(t){let r=ma.get(this);return r||ma.set(this,r=rl(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?Qo(t,this.BYTES):en(t,this.BYTES)}fromBytes(t,r=!1){W(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?we(t):zt(t);if(a&&(c=Q(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return on(this,t,!0)}cmov(t,r,n){return vt(n,"condition"),n?r:t}};function He(e,t={}){return Object.freeze(nn.prototype),new nn(e,t)}function Ba(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=j)throw new Error("field order must be greater than 1");let t=qe(e-j);return Math.ceil(t/8)}function sn(e){let t=Ba(e);return t+Math.ceil(t/2)}function an(e,t,r=!1){W(e);let n=e.length,o=Ba(t),s=Math.max(sn(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?we(e):zt(e),a=Q(i,t-j)+j;return r?Qo(a,o):en(a,o)}var ss=BigInt(0),yr=BigInt(1),sl=BigInt(4),ns=16,Ta=128,il=5,_a=2**31;function fe(e){let t=e;if(typeof t!="function")throw new TypeError('"Point" expected constructor, got type='+typeof e);be(t.fromAffine,"Point.fromAffine"),be(t.fromBytes,"Point.fromBytes"),be(t.fromHex,"Point.fromHex"),se(t.BASE,"Point.BASE"),se(t.ZERO,"Point.ZERO"),ze(t.Fp),ze(t.Fn)}function cn(e,t){fe(e),Ra(t,e);let r=on(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function al(e,t,r=1){if(!Number.isSafeInteger(e)||e<r||e>t)throw new Error("invalid window size, expected ["+r+".."+t+"], got W="+e)}function cl(e,t){let r=e*(4*t+128);if(r>_a)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+_a/2**20+" MiB")}function is(e,t){if(e!==void 0){be(e,"randomBytes");try{let r=e(t);if(!ae(r)||r.length!==t)return}catch{return}return e}}function Ra(e,t){Jr(e,"points"),e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function ul(e,t,r){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((n,o)=>{if(!(r===void 0?t.isValid(n):ie(n)&&n<r))throw new Error("invalid scalar at index "+o)})}var Ca=new WeakMap;function os(e){return Ca.get(e)||1}function fl(e,t){let r=e.double(),n=[e];for(let o=1;o<t;o++)n.push(n[o-1].add(r));return n}function ll(e,t){let r=2**t,n=r/2,o=BigInt(r-1),s=[];for(;e>ss;){let i=0;e&yr&&(i=Number(e&o),i>=n&&(i-=r),e-=BigInt(i)),s.push(i),e>>=yr}return s}function dl(e,t,r){let n=2**t,o=n/2,s=BigInt(n-1),i=BigInt(t),a=[];for(let c=0;c<r;c++){let u=Number(e&s);e>>=i,u>o&&(u-=n,e+=yr),a.push(u)}if(e!==ss)throw new Error("invalid wnaf");return a}function hl(e,t,r){let n=0;for(let s of r)n=Math.max(n,s.length);let o=e;for(let s=n-1;s>=0;s--){s!==n-1&&(o=o.double());for(let i=0;i<r.length;i++){let a=r[i][s];if(a){let c=t[i][Math.abs(a)-1>>1];o=o.add(a<0?c.negate():c)}}}return o}var Ve=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(t,r){fe(t),this.randomBytes=is(r,ns),this.Point=t,this.BASE=t.BASE,this.ZERO=t.ZERO,this.bits=t.Fn.BITS}buildWnafTable(t,r,n){let o=Math.ceil(n/r)+1,s=2**(r-1),i=[],a=t;for(let c=0;c<o;c++){let u=a;for(let f=0;f<s;f++)i.push(u),u=u.add(a);a=i[i.length-1].double()}return{W:r,bits:n,windows:o,comp:i}}wnafCachedCT(t,r){let{W:n,windows:o,comp:s}=t,i=2**(n-1),a=dl(r,n,o),c=this.ZERO,u=this.BASE;for(let f=0;f<o;f++){let d=a[f],l=f*i,h=Math.abs(d)-1,w=s[l];for(let b=1;b<i;b++)w=b===h?s[l+b]:w;let g=w.negate();d===0?u=u.add(s[l]):c=c.add(d<0?g:w)}return{p:c,f:u}}getWnafPrecomputes(t,r,n,o){let s=this.wnafPrecomputes.get(r),i=s?.find(a=>a.W===t&&a.bits===n);return i||(i=this.buildWnafTable(r,t,n),typeof o=="function"&&(i={...i,comp:o(i.comp)}),s||(s=[],this.wnafPrecomputes.set(r,s)),s.push(i)),i}assertPoint(t){if(!(t instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof t)}validateMulInput(t,r){if(this.assertPoint(t),!Jo(r,yr,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(t,r,n,o){let s=os(t);return s===1?this.fixedWindowCT(t,r,n):this.wnafCachedCT(this.getWnafPrecomputes(s,t,n,o),r)}mulCT(t,r,n){return this.validateMulInput(t,r),this.runCT(t,r,this.bits,n)}mulCTBlinded(t,r,n){if(this.validateMulInput(t,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let o=this.Point.Fn.BITS+Ta,s=this.randomBytes(ns);if(!ae(s)||s.length!==ns)throw new Error("randomBytes returned invalid byte array");s[0]=s[0]&63|128;let i=r+zt(s)*this.Point.Fn.ORDER;return this.runCT(t,i,o,n)}fixedWindowCT(t,r,n){let o=il,s=1<<o,i=pr(o),a=new Array(s);a[0]=this.ZERO;for(let f=1;f<s;f++)a[f]=a[f-1].add(t);let c=Math.ceil(n/o),u=this.ZERO;for(let f=c-1;f>=0;f--){if(f!==c-1)for(let h=0;h<o;h++)u=u.double();let d=Number(r>>BigInt(f*o)&i),l=a[0];for(let h=1;h<s;h++)l=h===d?a[h]:l;u=u.add(l)}return{p:u,f:u}}shouldBlind(t,r){return this.randomBytes===void 0?!1:r===yr?!0:t!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(t,r,n,o){return this.shouldBlind(t,n)?this.mulCTBlinded(t,r,o):this.mulCT(t,r,o)}mulUnsafe(t,r,n){if(this.assertPoint(t),!ie(r))throw new Error("invalid scalar");let o=os(t);if(o===1||r>=this.Point.Fn.ORDER)return un(this.Point,[t],[r],!0);let s=this.getWnafPrecomputes(o,t,this.bits,n);return this.wnafCachedCT(s,r).p}setWindowSize(t,r){this.assertPoint(t),al(r,this.bits);let n=Math.ceil((this.bits+Ta)/r)+1;cl(n*2**(r-1),this.Point.Fp.BYTES),Ca.set(t,r),this.wnafPrecomputes.delete(t)}hasWindowSize(t){return os(t)!==1}};function un(e,t,r,n=!1){if(fe(e),Ra(t,e),vt(n,"allowOversized"),ul(r,e.Fn,n?e.Fn.ORDER**sl:void 0),t.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=t.map(i=>fl(i,4)),s=r.map(i=>ll(i,4));return hl(e.ZERO,o,s)}function Ia(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ze(t),t}else return He(e,{isLE:r})}function fn(e,t,r={},n){if(e!=="weierstrass"&&e!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);St(r);for(let c of["p","n","h"]){let u=t[c];if(!(ie(u)&&u!==ss))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Ia(t.p,r.Fp,n),s=Ia(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 ln(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var dn=BigInt(0),hn=BigInt(1),pn=BigInt(2),pl=BigInt(4),La=BigInt(8);function ml(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 Da(e,t={}){St(t,{},{},"extraOpts");let r=t,n=fn("edwards",e,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;if(mr(o,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(mr(o,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");St(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?ge:r.randomBytes,u=pn<<BigInt(o.BYTES*8)-hn;function f(S){if(!o.isOdd)throw new Error("Field does not have .isOdd()");return o.isOdd(S)}let d=r.uvRatio===void 0?(S,y)=>{try{return{isValid:!0,value:o.sqrt(o.div(S,y))}}catch{return{isValid:!1,value:dn}}}:r.uvRatio;if(!ml(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let l=o.eql(i.a,o.neg(o.ONE))?S=>o.neg(S):o.eql(i.a,o.ONE)?S=>S:S=>o.mul(i.a,S);function h(S,y,B=!1){let _=B?hn:dn;return Fe("coordinate "+S,y,_,u),y}function w(S){if(!(S instanceof g))throw new Error("EdwardsPoint expected")}class g{static BASE=new g(i.Gx,i.Gy,o.ONE,o.mul(i.Gx,i.Gy));static ZERO=new g(o.ZERO,o.ONE,o.ONE,o.ZERO);static Fp=o;static Fn=s;X;Y;Z;T;constructor(y,B,_,U){this.X=h("x",y),this.Y=h("y",B),this.Z=h("z",_,!0),this.T=h("t",U),Object.freeze(this)}static CURVE(){return i}static fromAffine(y){if(y instanceof g)throw new Error("extended point not allowed");let{x:B,y:_}=y||{};return h("x",B),h("y",_),new g(B,_,o.ONE,o.mul(B,_))}static fromBytes(y,B=!1){let _=o.BYTES,{a:U,d:M}=i;y=rn(W(y,_,"point")),vt(B,"zip215");let P=rn(y),O=y[_-1];P[_-1]=O&-129;let k=we(P),F=B?u:o.ORDER;Fe("point.y",k,dn,F);let L=o.sqr(k),G=o.sub(L,o.ONE),C=o.sub(o.mulN(M,L),U),{isValid:R,value:p}=d(G,C);if(!R)throw new Error("bad point: invalid y coordinate");let E=f(p),A=(O&128)!==0;if(!B&&o.is0(p)&&A)throw new Error("bad point: x=0 and x_0=1");return A!==E&&(p=o.neg(p)),g.fromAffine({x:p,y:k})}static fromHex(y,B=!1){return g.fromBytes(Me(y),B)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=6,B=!0){return x.setWindowSize(this,y),B||this.multiply(pn),this}assertValidity(){let y=this,{a:B,d:_}=i;if(y.is0())throw new Error("bad point: ZERO");let{X:U,Y:M,Z:P,T:O}=y,k=o.sqr(U),F=o.sqr(M),L=o.sqr(P),G=o.sqr(L),C=o.mul(k,B),R=o.mul(o.add(C,F),L),p=o.add(G,o.mul(_,o.mul(k,F)));if(!o.eql(R,p))throw new Error("bad point: equation left != right (1)");let E=o.mul(U,M),A=o.mul(P,O);if(!o.eql(E,A))throw new Error("bad point: equation left != right (2)")}equals(y){w(y);let{X:B,Y:_,Z:U}=this,{X:M,Y:P,Z:O}=y,k=o.mul(B,O),F=o.mul(M,U),L=o.mul(_,O),G=o.mul(P,U);return o.eql(k,F)&&o.eql(L,G)}is0(){return this.equals(g.ZERO)}negate(){return new g(o.neg(this.X),this.Y,this.Z,o.neg(this.T))}double(){let{X:y,Y:B,Z:_}=this,U=o.sqr(y),M=o.sqr(B),P=o.mul(o.sqr(_),pn),O=l(U),k=o.addN(y,B),F=o.sub(o.subN(o.sqr(k),U),M),L=o.addN(O,M),G=o.subN(L,P),C=o.subN(O,M),R=o.mul(F,G),p=o.mul(L,C),E=o.mul(F,C),A=o.mul(G,L);return new g(R,p,A,E)}add(y){w(y);let{d:B}=i,{X:_,Y:U,Z:M,T:P}=this,{X:O,Y:k,Z:F,T:L}=y,G=o.mul(_,O),C=o.mul(U,k),R=o.mul(o.mulN(P,B),L),p=o.mul(M,F),E=o.sub(o.subN(o.mulN(o.addN(_,U),o.addN(O,k)),G),C),A=o.subN(p,R),D=o.addN(p,R),v=o.sub(C,l(G)),m=o.mul(E,A),T=o.mul(D,v),I=o.mul(E,v),K=o.mul(A,D);return new g(m,T,K,I)}subtract(y){return w(y),this.add(y.negate())}multiply(y){if(!s.isValidNot0(y))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:B,f:_}=x.mulSecret(this,y,a,b);return b([B,_])[0]}multiplyUnsafe(y){if(!s.isValid(y))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return y===dn?g.ZERO:this.is0()||y===hn?this:x.mulUnsafe(this,y,b)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return x.mulUnsafe(this,i.n).is0()}toAffine(y){let B=this,_=y;if(_!=null&&typeof _!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof _);let{X:U,Y:M,Z:P}=B,O=B.is0();_==null&&(_=O?o.create(La):o.inv(P));let k=o.mul(U,_),F=o.mul(M,_),L=o.mul(P,_);if(O)return{x:o.ZERO,y:o.ONE};if(!o.eql(L,o.ONE))throw new Error("invZ was invalid");return{x:k,y:F}}clearCofactor(){return a===hn?this:a===pn?this.double():a===pl?this.double().double():a===La?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:y,y:B}=this.toAffine(),_=o.toBytes(B);return _[_.length-1]|=f(y)?128:0,_}toHex(){return dr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let b=S=>cn(g,S),x=new Ve(g,c);return x.bits>=6&&g.BASE.precompute(6),Object.freeze(g.prototype),Object.freeze(g),g}function Oa(e,t,r={}){if(fe(e),typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=r;St(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=e,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(ce(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let d=o.randomBytes===void 0?ge:o.randomBytes,l=o.toMontgomery,h=o.toMontgomerySecret,w=o.adjustScalarBytes===void 0?C=>C:o.adjustScalarBytes,g=o.domain===void 0?(C,R,p)=>{if(vt(p,"phflag"),R.length||p)throw new Error("Contexts/pre-hash are not supported");return C}:o.domain;function b(C){return c.create(we(C))}function x(C){let R=O.secretKey;W(C,O.secretKey,"secretKey");let p=W(n(C),2*R,"hashedSecretKey"),E=w(p.slice(0,R)),A=p.slice(R,2*R),D=b(E);return{head:E,prefix:A,scalar:D}}function S(C){let{head:R,prefix:p,scalar:E}=x(C),A=i.multiply(E),D=A.toBytes();return{head:R,prefix:p,scalar:E,point:A,pointBytes:D}}function y(C){return S(C).pointBytes}function B(C=Uint8Array.of(),...R){let p=Rt(...R);return b(n(g(p,W(C,void 0,"context"),!!s)))}function _(C,R,p={}){St(p,{},{},"options"),C=W(C,void 0,"message"),s&&(C=s(C));let{prefix:E,scalar:A,pointBytes:D}=S(R),v=B(p.context,E,C),m=i.multiply(v).toBytes(),T=B(p.context,m,D,C),I=c.create(v+T*A);if(!c.isValid(I))throw new Error("sign failed: invalid s");let K=Rt(m,c.toBytes(I));return W(K,O.signature,"result")}let U={zip215:o.zip215};function M(C,R,p,E=U){St(E);let{context:A}=E,D=E.zip215===void 0?!!U.zip215:E.zip215,v=O.signature;C=W(C,v,"signature"),R=W(R,void 0,"message"),p=W(p,O.publicKey,"publicKey"),D!==void 0&&vt(D,"zip215"),s&&(R=s(R));let m=v/2,T=C.subarray(0,m),I=we(C.subarray(m,v)),K,N,$;try{K=e.fromBytes(p,D),N=e.fromBytes(T,D),$=i.multiplyUnsafe(I)}catch{return!1}if(!D&&K.isSmallOrder())return!1;let H=B(A,T,p,R);return N.add(K.multiplyUnsafe(H)).subtract($).clearCofactor().is0()}let P=a.BYTES,O={secretKey:P,publicKey:P,signature:2*P,seed:P};function k(C){return C=C===void 0?d(O.seed):C,W(C,O.seed,"seed")}function F(C){return ae(C)&&C.length===O.secretKey}function L(C,R){try{return!!e.fromBytes(C,R===void 0?U.zip215:R)}catch{return!1}}let G={getExtendedPublicKey:S,randomSecretKey:k,isValidSecretKey:F,isValidPublicKey:L,toMontgomery(C){if(l===void 0)throw new Error("Montgomery conversion is not supported for this curve");return l(e.fromBytes(C))},toMontgomerySecret(C){if(h===void 0)throw new Error("Montgomery conversion is not supported for this curve");return h(C)}};return Object.freeze(O),Object.freeze(G),Object.freeze({keygen:ln(k,y),getPublicKey:y,sign:_,verify:M,utils:G,Point:e,lengths:O})}var as=BigInt(1),ka=BigInt(2);var yl=BigInt(5),bl=BigInt(8),cs=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),gl={p:cs,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:bl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function wl(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=cs,a=e*e%s*e%s,c=X(a,ka,s)*a%s,u=X(c,as,s)*e%s,f=X(u,yl,s)*u%s,d=X(f,t,s)*f%s,l=X(d,r,s)*d%s,h=X(l,n,s)*l%s,w=X(h,o,s)*h%s,g=X(w,o,s)*h%s,b=X(g,t,s)*f%s;return{pow_p_5_8:X(b,ka,s)*e%s,b2:a}}function Na(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Pa=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function xl(e,t){let r=cs,n=Q(t*t*t,r),o=Q(n*n*t,r),s=wl(e*o).pow_p_5_8,i=Q(e*n*s,r),a=Q(t*i*i,r),c=i,u=Q(i*Pa,r),f=a===e,d=a===Q(-e,r),l=a===Q(-e*Pa,r);return f&&(i=c),(d||l)&&(i=u),Aa(i,r)&&(i=Q(-i,r)),{isValid:f||d,value:i}}var us=Da(gl,{uvRatio:xl}),Ka=us.Fp;function El(e){let{y:t}=e;return Ka.toBytes(Ka.div(as+t,as-t))}function vl(e){let t=us.Fp.BYTES;return It(e,t),Na(Go(e.subarray(0,t))).subarray(0,t)}function Sl(e){return Oa(us,Go,Object.assign({adjustScalarBytes:Na,toMontgomery:El,toMontgomerySecret:vl,zip215:!0},e))}var Ua=Sl({});var br=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},mn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Ct={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new mn("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 yn=32;var fs,Al=(async()=>{try{return await Ct.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Bl(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Ct.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Ct.get().subtle.verify({name:"Ed25519"},n,pt(t),pt(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Tl(e,t,r){return Ua.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Ma(e,t,r){return fs==null&&(fs=await Al),fs?Bl(e,t,r):Tl(e,t,r)}function bn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var gn=class{type="Ed25519";raw;constructor(t){this.raw=ls(t,yn)}toMultihash(){return Ot.digest(_t(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return nt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Z(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Ma(this.raw,r,t);return bn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function ds(e){return e=ls(e,yn),new gn(e)}function ls(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new q(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Il=Math.pow(2,7),Rl=Math.pow(2,14),Cl=Math.pow(2,21),hs=Math.pow(2,28),ps=Math.pow(2,35),ms=Math.pow(2,42),ys=Math.pow(2,49),Y=128,lt=127;function Lt(e){if(e<Il)return 1;if(e<Rl)return 2;if(e<Cl)return 3;if(e<hs)return 4;if(e<ps)return 5;if(e<ms)return 6;if(e<ys)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function $e(e,t,r=0){switch(Lt(e)){case 8:t[r++]=e&255|Y,e/=128;case 7:t[r++]=e&255|Y,e/=128;case 6:t[r++]=e&255|Y,e/=128;case 5:t[r++]=e&255|Y,e/=128;case 4:t[r++]=e&255|Y,e>>>=7;case 3:t[r++]=e&255|Y,e>>>=7;case 2:t[r++]=e&255|Y,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Ll(e,t,r=0){switch(Lt(e)){case 8:t.set(r++,e&255|Y),e/=128;case 7:t.set(r++,e&255|Y),e/=128;case 6:t.set(r++,e&255|Y),e/=128;case 5:t.set(r++,e&255|Y),e/=128;case 4:t.set(r++,e&255|Y),e>>>=7;case 3:t.set(r++,e&255|Y),e>>>=7;case 2:t.set(r++,e&255|Y),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function bs(e,t){let r=e[t],n=0;if(n+=r<,r<Y||(r=e[t+1],n+=(r<)<<7,r<Y)||(r=e[t+2],n+=(r<)<<14,r<Y)||(r=e[t+3],n+=(r<)<<21,r<Y)||(r=e[t+4],n+=(r<)*hs,r<Y)||(r=e[t+5],n+=(r<)*ps,r<Y)||(r=e[t+6],n+=(r<)*ms,r<Y)||(r=e[t+7],n+=(r<)*ys,r<Y))return n;throw new RangeError("Could not decode varint")}function Dl(e,t){let r=e.get(t),n=0;if(n+=r<,r<Y||(r=e.get(t+1),n+=(r<)<<7,r<Y)||(r=e.get(t+2),n+=(r<)<<14,r<Y)||(r=e.get(t+3),n+=(r<)<<21,r<Y)||(r=e.get(t+4),n+=(r<)*hs,r<Y)||(r=e.get(t+5),n+=(r<)*ps,r<Y)||(r=e.get(t+6),n+=(r<)*ms,r<Y)||(r=e.get(t+7),n+=(r<)*ys,r<Y))return n;throw new RangeError("Could not decode varint")}function wn(e,t,r=0){return t==null&&(t=ft(Lt(e))),t instanceof Uint8Array?$e(e,t,r):Ll(e,t,r)}function gs(e,t=0){return e instanceof Uint8Array?bs(e,t):Dl(e,t)}var ws=new Float32Array([-0]),le=new Uint8Array(ws.buffer);function za(e,t,r){ws[0]=e,t[r]=le[0],t[r+1]=le[1],t[r+2]=le[2],t[r+3]=le[3]}function Ha(e,t){return le[0]=e[t],le[1]=e[t+1],le[2]=e[t+2],le[3]=e[t+3],ws[0]}var xs=new Float64Array([-0]),dt=new Uint8Array(xs.buffer);function Va(e,t,r){xs[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 $a(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],xs[0]}var Ol=BigInt(Number.MAX_SAFE_INTEGER),kl=BigInt(Number.MIN_SAFE_INTEGER),At=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 xe;if(t<Ol&&t>kl)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>Wa&&(o=0n,++n>Wa&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return xe;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):xe}},xe=new At(0,0);xe.toBigInt=function(){return 0n};xe.zzEncode=xe.zzDecode=function(){return this};xe.length=function(){return 1};var Wa=4294967296n;function ja(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 Ya(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 Es(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 Pt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function xn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var vs=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=pt(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,Pt(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 Pt(this,4);return xn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Pt(this,4);return xn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Pt(this,4);let t=Ha(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Pt(this,4);let t=$a(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 Pt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Ya(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Pt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Pt(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 At(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 Pt(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 Pt(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 Pt(this,8);let t=xn(this.buf,this.pos+=4),r=xn(this.buf,this.pos+=4);return new At(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=bs(this.buf,this.pos);return this.pos+=Lt(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 gr(e){return new vs(e instanceof Uint8Array?e:e.subarray())}function yt(e,t,r){let n=gr(e);return t.decode(n,void 0,r)}function Ss(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return ft(i);o+i>t&&(n=ft(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Ee=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function As(){}var Ts=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Pl=Ss();function Kl(e){return globalThis.Buffer!=null?ft(e):Pl(e)}var xr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ee(As,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new Ee(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new _s((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(En,10,At.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=At.fromBigInt(t);return this._push(En,r.length(),r)}uint64Number(t){return this._push($e,Lt(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=At.fromBigInt(t).zzEncode();return this._push(En,r.length(),r)}sint64Number(t){let r=At.fromNumber(t).zzEncode();return this._push(En,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Bs,1,t?1:0)}fixed32(t){return this._push(wr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=At.fromBigInt(t);return this._push(wr,4,r.lo)._push(wr,4,r.hi)}fixed64Number(t){let r=At.fromNumber(t);return this._push(wr,4,r.lo)._push(wr,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(za,4,t)}double(t){return this._push(Va,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Bs,1,0):this.uint32(r)._push(Ul,r,t)}string(t){let r=ja(t);return r!==0?this.uint32(r)._push(Es,r,t):this._push(Bs,1,0)}fork(){return this.states=new Ts(this),this.head=this.tail=new Ee(As,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 Ee(As,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=Kl(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Bs(e,t,r){t[r]=e&255}function Nl(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var _s=class extends Ee{next;constructor(t,r){super(Nl,t,r),this.next=void 0}};function En(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 wr(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 Ul(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(xr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Ml,t,e),this},xr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Fl,t,e),this});function Ml(e,t,r){t.set(e,r)}function Fl(e,t,r){e.length<40?Es(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(V(e),r)}function Is(){return new xr}function bt(e,t){let r=Is();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*gt(e,t,r){let n=gr(e);yield*t.stream(n,void 0,"$",r)}var vn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Sn(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 Sn("enum",vn.VARINT,r,n,o)}function wt(e,t,r){return Sn("message",vn.LENGTH_DELIMITED,e,t,r)}var Dt=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},Er=class extends Error{code="ERR_MAX_SIZE";name="MaxSizeError"};var J;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(J||(J={}));var Cs;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Cs||(Cs={}));(function(e){e.codec=()=>Rs(Cs)})(J||(J={}));var Ht;(function(e){let t;e.codec=()=>(t==null&&(t=wt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),J.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=J.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:J.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 bt(s,e.codec())}e.encode=r;function n(s,i){return yt(s,e.codec(),i)}e.decode=n;function o(s,i){return gt(s,e.codec(),i)}e.stream=o})(Ht||(Ht={}));var Ls;(function(e){let t;e.codec=()=>(t==null&&(t=wt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),J.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=J.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:J.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 bt(s,e.codec())}e.encode=r;function n(s,i){return yt(s,e.codec(),i)}e.decode=n;function o(s,i){return gt(s,e.codec(),i)}e.stream=o})(Ls||(Ls={}));var Sr={};xt(Sr,{MAX_RSA_KEY_SIZE:()=>Ds,generateRSAKeyPair:()=>tc,jwkToJWKKeyPair:()=>ec,jwkToPkcs1:()=>Vl,jwkToPkix:()=>Ks,jwkToRSAPrivateKey:()=>Fs,pkcs1MessageToJwk:()=>ks,pkcs1MessageToRSAPrivateKey:()=>Ns,pkcs1ToJwk:()=>Hl,pkcs1ToRSAPrivateKey:()=>Ja,pkixMessageToJwk:()=>Ps,pkixMessageToRSAPublicKey:()=>Ms,pkixToJwk:()=>$l,pkixToRSAPublicKey:()=>Us});var We=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Sr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return st.createV1(114,this._multihash)}toString(){return nt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Z(this.raw,t.raw)}verify(t,r,n){return Qa(this.jwk,r,t,n)}},vr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Sr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Z(this.raw,t.raw)}sign(t,r){return Xa(this.jwk,t,r)}};var Ds=8192,Os=18,ql=1062,zl=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Hl(e){let t=Vt(e);return ks(t)}function ks(e){return{n:z(e[1],"base64url"),e:z(e[2],"base64url"),d:z(e[3],"base64url"),p:z(e[4],"base64url"),q:z(e[5],"base64url"),dp:z(e[6],"base64url"),dq:z(e[7],"base64url"),qi:z(e[8],"base64url"),kty:"RSA"}}function Vl(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new q("JWK was missing components");return ee([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 $l(e){let t=Vt(e,{offset:0});return Ps(t)}function Ps(e){let t=Vt(e[1],{offset:0});return{kty:"RSA",n:z(t[0],"base64url"),e:z(t[1],"base64url")}}function Ks(e){if(e.n==null||e.e==null)throw new q("JWK was missing components");return ee([zl,Vr(ee([Et(V(e.n,"base64url")),Et(V(e.e,"base64url"))]))]).subarray()}function Ja(e){let t=Vt(e);return Ns(t)}function Ns(e){let t=ks(e);return Fs(t)}function Us(e,t){if(e.byteLength>=ql)throw new Ie("Key size is too large");let r=Vt(e,{offset:0});return Ms(r,e,t)}function Ms(e,t,r){let n=Ps(e);if(r==null){let o=Ue(Ht.encode({Type:J.RSA,Data:t}));r=Mt(Os,o)}return new We(n,r)}function Fs(e){if(nc(e)>Ds)throw new q("Key size is too large");let t=ec(e),r=Ue(Ht.encode({Type:J.RSA,Data:Ks(t.publicKey)})),n=Mt(Os,r);return new vr(t.privateKey,new We(t.publicKey,n))}async function tc(e){if(e>Ds)throw new q("Key size is too large");let t=await rc(e),r=Ue(Ht.encode({Type:J.RSA,Data:Ks(t.publicKey)})),n=Mt(Os,r);return new vr(t.privateKey,new We(t.publicKey,n))}function ec(e){if(e==null)throw new q("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function rc(e,t){let r=await Ct.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 Wl(r,t);return{privateKey:n[0],publicKey:n[1]}}async function Xa(e,t,r){let n=await Ct.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Ct.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,pt(t instanceof Uint8Array?t:t.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Qa(e,t,r,n){let o=await Ct.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Ct.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,pt(t),pt(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),s}async function Wl(e,t){if(e.privateKey==null||e.publicKey==null)throw new q("Private and public key are required");let r=await Promise.all([Ct.get().subtle.exportKey("jwk",e.privateKey),Ct.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function nc(e){if(e.kty!=="RSA")throw new q("invalid key type");if(e.n==null)throw new q("invalid key modulus");return V(e.n,"base64url").length*8}var An=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(jr(t),It(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");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),ye(o)}update(t){return Ne(this),this.iHash.update(t),this}digestInto(t){Ne(this),Yr(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,canXOF:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.canXOF=c,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()}},oc=(()=>{let e=((t,r,n)=>new An(t,r).update(n).digest());return e.create=(t,r)=>new An(t,r),e})();var jl=BigInt(0),qs=class extends Error{constructor(t=""){super(t)}},Wt={Err:qs,_tlv:{encode:(e,t)=>{let{Err:r}=Wt;if(ce(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(la(t,"data"),t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=hr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?hr(o.length/2|128):"";return hr(e)+s+o+t},decode(e,t){let{Err:r}=Wt;t=W(t,void 0,"DER data");let n=0;if(e<0||e>255)throw new r("tlv.decode: 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}=Wt;if(tn(e),e<jl)throw new t("integer: negative integers are not allowed");let r=hr(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}=Wt;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 zt(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Wt,o=W(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}=Wt;St(e,{r:"bigint",s:"bigint"},{},"sig");let n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},zs=(Object.freeze(Wt._tlv),Object.freeze(Wt._int),Object.freeze(Wt));var sc=(e,t)=>(e+(e>=0?t:-t)/ic)/t;function Yl(e,t,r){Fe("scalar",e,jt,r);let[[n,o],[s,i]]=t,a=sc(i*e,r),c=sc(-o*e,r),u=e-a*n-c*s,f=-a*o-c*i,d=u<jt,l=f<jt;d&&(u=-u),l&&(f=-f);let h=pr(Math.ceil(qe(r)/2))+ve;if(u<jt||u>=h||f<jt||f>=h)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:d,k1:u,k2neg:l,k2:f}}function $s(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Hs(e,t){St(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return vt(r.lowS,"lowS"),vt(r.prehash,"prehash"),r.format!==void 0&&$s(r.format),r}var jt=BigInt(0),ve=BigInt(1),ic=BigInt(2),Vs=BigInt(3),Zl=BigInt(4);function ac(e,t={}){let r=fn("weierstrass",e,t),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;St(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u}=t,f=t.randomBytes===void 0?ge:t.randomBytes;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 d=uc(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(R,p,E){if(u&&p.is0())return Uint8Array.of(0);let{x:A,y:D}=p.toAffine(),v=n.toBytes(A);if(vt(E,"isCompressed"),E){l();let m=!n.isOdd(D);return Rt(cc(m),v)}else return Rt(Uint8Array.of(4),v,n.toBytes(D))}function w(R){W(R,void 0,"Point");let{publicKey:p,publicKeyUncompressed:E}=d,A=R.length,D=R[0],v=R.subarray(1);if(u&&A===1&&D===0)return{x:n.ZERO,y:n.ZERO};if(A===p&&(D===2||D===3)){let m=n.fromBytes(v);if(!n.isValid(m))throw new Error("bad point: is not on curve, wrong x");let T=y(m),I;try{I=n.sqrt(T)}catch($){let H=$ instanceof Error?": "+$.message:"";throw new Error("bad point: is not on curve, sqrt error"+H)}l();let K=n.isOdd(I);return(D&1)===1!==K&&(I=n.neg(I)),{x:m,y:I}}else if(A===E&&D===4){let m=n.BYTES,T=n.fromBytes(v.subarray(0,m)),I=n.fromBytes(v.subarray(m,m*2));if(!B(T,I))throw new Error("bad point: is not on curve");return{x:T,y:I}}else throw new Error(`bad point: got length ${A}, expected compressed=${p} or uncompressed=${E}`)}let g=t.toBytes===void 0?h:t.toBytes,b=t.fromBytes===void 0?w:t.fromBytes,x=n.mul(s.b,Vs),S=n.is0(s.a)?R=>n.ZERO:R=>n.mul(s.a,R);function y(R){let p=n.sqr(R),E=n.mul(p,R);return n.add(n.add(E,n.mul(R,s.a)),s.b)}function B(R,p){let E=n.sqr(p),A=y(R);return n.eql(E,A)}if(!B(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let _=n.mul(n.pow(s.a,Vs),Zl),U=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(_,U)))throw new Error("bad curve params: a or b");function M(R,p,E=!1){if(!n.isValid(p)||E&&n.is0(p))throw new Error(`bad point coordinate ${R}`);return p}function P(R){if(!(R instanceof L))throw new Error("Weierstrass Point expected")}function O(R){if(!c||!c.basises)throw new Error("no endo");return Yl(R,c.basises,o.ORDER)}function k(R,p,E,A){if(!o.isValid(A))throw new RangeError("invalid scalar: out of range");if(c){let{k1neg:D,k1:v,k2neg:m,k2:T}=O(A),I=new L(n.mul(E.X,c.beta),E.Y,E.Z);R.push(D?E.negate():E,m?I.negate():I),p.push(v,T)}else R.push(E),p.push(A)}let F=new WeakSet;class L{static BASE=new L(s.Gx,s.Gy,n.ONE);static ZERO=new L(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(p,E,A){this.X=M("x",p),this.Y=M("y",E,!0),this.Z=M("z",A),Object.freeze(this)}static CURVE(){return s}static fromAffine(p){let{x:E,y:A}=p||{};if(!p||!n.isValid(E)||!n.isValid(A))throw new Error("invalid affine point");if(p instanceof L)throw new Error("projective point not allowed");return n.is0(E)&&n.is0(A)?L.ZERO:new L(E,A,n.ONE)}static fromBytes(p){let E=L.fromAffine(b(W(p,void 0,"point")));return E.assertValidity(),E}static fromHex(p){return L.fromBytes(Me(p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=6,E=!0){return C.setWindowSize(this,p),E||this.multiply(Vs),this}assertValidity(){let p=this;if(p.is0()){if(t.allowInfinityPoint&&n.is0(p.X)&&n.eql(p.Y,n.ONE)&&n.is0(p.Z))return;throw new Error("bad point: ZERO")}if(F.has(p))return;let{x:E,y:A}=p.toAffine();if(!n.isValid(E)||!n.isValid(A))throw new Error("bad point: x or y not field elements");if(!B(E,A))throw new Error("bad point: equation left != right");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");F.add(p)}hasEvenY(){let{y:p}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(p)}equals(p){P(p);let{X:E,Y:A,Z:D}=this,{X:v,Y:m,Z:T}=p,I=n.eql(n.mul(E,T),n.mul(v,D)),K=n.eql(n.mul(A,T),n.mul(m,D));return I&&K}negate(){return new L(this.X,n.neg(this.Y),this.Z)}double(){let{X:p,Y:E,Z:A}=this,D=n.ZERO,v=n.ZERO,m=n.ZERO,T=n.mul(p,p),I=n.mul(E,E),K=n.mul(A,A),N=n.mul(p,E);return N=n.add(N,N),m=n.mul(p,A),m=n.add(m,m),D=S(m),v=n.mul(x,K),v=n.add(D,v),D=n.sub(I,v),v=n.add(I,v),v=n.mul(D,v),D=n.mul(N,D),m=n.mul(x,m),K=S(K),N=n.sub(T,K),N=S(N),N=n.add(N,m),m=n.add(T,T),T=n.add(m,T),T=n.add(T,K),T=n.mul(T,N),v=n.add(v,T),K=n.mul(E,A),K=n.add(K,K),T=n.mul(K,N),D=n.sub(D,T),m=n.mul(K,I),m=n.add(m,m),m=n.add(m,m),new L(D,v,m)}add(p){P(p);let{X:E,Y:A,Z:D}=this,{X:v,Y:m,Z:T}=p,I=n.ZERO,K=n.ZERO,N=n.ZERO,$=n.mul(E,v),H=n.mul(A,m),tt=n.mul(D,T),ht=n.add(E,A),et=n.add(v,m);ht=n.mul(ht,et),et=n.add($,H),ht=n.sub(ht,et),et=n.add(E,D);let ut=n.add(v,T);return et=n.mul(et,ut),ut=n.add($,tt),et=n.sub(et,ut),ut=n.add(A,D),I=n.add(m,T),ut=n.mul(ut,I),I=n.add(H,tt),ut=n.sub(ut,I),N=S(et),I=n.mul(x,tt),N=n.add(I,N),I=n.sub(H,N),N=n.add(H,N),K=n.mul(I,N),H=n.add($,$),H=n.add(H,$),tt=S(tt),et=n.mul(x,et),H=n.add(H,tt),tt=n.sub($,tt),tt=S(tt),et=n.add(et,tt),$=n.mul(H,et),K=n.add(K,$),$=n.mul(ut,et),I=n.mul(ht,I),I=n.sub(I,$),$=n.mul(ht,H),N=n.mul(ut,N),N=n.add(N,$),new L(I,K,N)}subtract(p){return P(p),this.add(p.negate())}is0(){return this.equals(L.ZERO)}multiply(p){if(!o.isValidNot0(p))throw new RangeError("invalid scalar: out of range");let{p:E,f:A}=C.mulSecret(this,p,i,G);return G([E,A])[0]}multiplyUnsafe(p){let E=this,A=p;if(!o.isValid(A))throw new RangeError("invalid scalar: out of range");if(A===jt||E.is0())return L.ZERO;if(A===ve)return E;if(C.hasWindowSize(this))return C.mulUnsafe(E,A,G);let D=[],v=[];return k(D,v,E,A),un(L,D,v)}mulAddUnsafe(p,E,A){P(E);let D=[],v=[];return k(D,v,this,p),k(D,v,E,A),un(L,D,v)}toAffine(p){let E=this,A=p;if(A!=null&&!n.isValid(A))throw new RangeError('"invertedZ" expected valid field element');let{X:D,Y:v,Z:m}=E;if(n.eql(m,n.ONE))return{x:D,y:v};let T=E.is0();A==null&&(A=T?n.ONE:n.inv(m));let I=n.mul(D,A),K=n.mul(v,A),N=n.mul(m,A);if(T)return{x:n.ZERO,y:n.ZERO};if(!n.eql(N,n.ONE))throw new Error("invZ was invalid");return{x:I,y:K}}isTorsionFree(){let{isTorsionFree:p}=t;return i===ve?!0:p?p(L,this):C.mulUnsafe(this,a).is0()}clearCofactor(){let{clearCofactor:p}=t;return i===ve?this:p?p(L,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===ve?this.is0():this.clearCofactor().is0()}toBytes(p=!0){return vt(p,"isCompressed"),this.assertValidity(),g(L,this,p)}toHex(p=!0){return dr(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let G=R=>cn(L,R),C=new Ve(L,f);return C.bits>=6&&L.BASE.precompute(6),Object.freeze(L.prototype),Object.freeze(L),L}function cc(e){return Uint8Array.of(e?2:3)}function uc(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Gl(e,t={}){fe(e);let{Fn:r}=e,n=t.randomBytes===void 0?ge:t.randomBytes,o=Object.assign(uc(e.Fp,r),{seed:Math.max(sn(r.ORDER),16)});function s(h){try{let w=r.fromBytes(h);return r.isValidNot0(w)}catch{return!1}}function i(h,w){let{publicKey:g,publicKeyUncompressed:b}=o;try{let x=h.length;return w===!0&&x!==g||w===!1&&x!==b?!1:!!e.fromBytes(h)}catch{return!1}}function a(h){return h=h===void 0?n(o.seed):h,an(W(h,o.seed,"seed"),r.ORDER)}function c(h,w=!0){return e.BASE.multiply(r.fromBytes(h)).toBytes(w)}function u(h){let{secretKey:w,publicKey:g,publicKeyUncompressed:b}=o,x=r._lengths;if(!ae(h))return;let S=W(h,void 0,"key").length,y=S===g||S===b,B=S===w||!!x?.includes(S);if(!(y&&B))return y}function f(h,w,g=!0){if(u(h)===!0)throw new Error("first arg must be private key");if(u(w)===!1)throw new Error("second arg must be public key");let b=r.fromBytes(h);return e.fromBytes(w).multiply(b).toBytes(g)}let d={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},l=ln(a,c);return Object.freeze(d),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:l,Point:e,utils:d,lengths:o})}function fc(e,t,r={}){fe(e);let n=t;jr(n),St(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},r),s=o.randomBytes===void 0?ge:o.randomBytes,i=o.hmac===void 0?(v,m)=>oc(n,v,m):o.hmac,{Fp:a,Fn:c}=e,{ORDER:u,BITS:f}=c,d=sn(u),l=is(s,d),{keygen:h,getPublicKey:w,getSharedSecret:g,utils:b,lengths:x}=Gl(e,o),S={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},y=u*ic+ve<a.ORDER;function B(v){let m=u>>ve;return v>m}function _(v,m){if(!c.isValidNot0(m))throw new Error(`invalid signature ${v}: out of range 1..Point.Fn.ORDER`);return m}function U(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function M(v,m,T){return U(),(v===T?0:2)|Number(a.isOdd(m))}function P(){if(y)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function O(v,m){$s(m);let T=x.signature,I=m==="compact"?T:m==="recovered"?T+1:void 0;return W(v,I)}class k{r;s;recovery;constructor(m,T,I){if(this.r=_("r",m),this.s=_("s",T),I!=null){if(P(),![0,1,2,3].includes(I))throw new Error("invalid recovery id");this.recovery=I}Object.freeze(this)}static fromBytes(m,T=S.format){O(m,T);let I;if(T==="der"){let{r:H,s:tt}=zs.toSig(W(m));return new k(H,tt)}T==="recovered"&&(I=m[0],T="compact",m=m.subarray(1));let K=x.signature/2,N=m.subarray(0,K),$=m.subarray(K,K*2);return new k(c.fromBytes(N),c.fromBytes($),I)}static fromHex(m,T){return this.fromBytes(Me(m),T)}assertRecovery(){let{recovery:m}=this;if(m==null)throw new Error("invalid recovery id: must be present");return m}addRecoveryBit(m){return new k(this.r,this.s,m)}recoverPublicKey(m){let{r:T,s:I}=this,K=this.assertRecovery(),N=K===2||K===3?T+u:T;if(!a.isValid(N))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let $=a.toBytes(N),H=e.fromBytes(Rt(cc((K&1)===0),$)),tt=c.inv(N),ht=L(W(m,void 0,"msgHash")),et=c.create(-ht*tt),ut=c.create(I*tt),Kt=e.BASE.mulAddUnsafe(et,H,ut);if(Kt.is0())throw new Error("invalid recovery: point at infinify");return Kt.assertValidity(),Kt}hasHighS(){return B(this.s)}toBytes(m=S.format){if($s(m),m==="der")return Me(zs.hexFromSig(this));let{r:T,s:I}=this,K=c.toBytes(T),N=c.toBytes(I);return m==="recovered"?(P(),Rt(Uint8Array.of(this.assertRecovery()),K,N)):Rt(K,N)}toHex(m){return dr(this.toBytes(m))}}Object.freeze(k.prototype),Object.freeze(k);let F=o.bits2int===void 0?function(m){if(m.length>8192)throw new Error("input is too large");let T=zt(m),I=m.length*8-f;return I>0?T>>BigInt(I):T}:o.bits2int,L=o.bits2int_modN===void 0?function(m){return c.create(F(m))}:o.bits2int_modN,G=pr(f);function C(v){return Fe("num < 2^"+f,v,jt,G),c.toBytes(v)}function R(v,m){return W(v,void 0,"message"),m?W(n(v),void 0,"prehashed message"):v}function p(v,m,T){let{lowS:I,prehash:K,extraEntropy:N}=Hs(T,S);v=R(v,K);let $=L(v),H=c.fromBytes(m);if(!c.isValidNot0(H))throw new Error("invalid private key");let tt=[C(H),C($)];if(N!=null&&N!==!1){let Kt=N===!0?s(x.secretKey):N;tt.push(W(Kt,void 0,"extraEntropy"))}let ht=Rt(...tt),et=$;function ut(Kt){let _e=F(Kt);if(!c.isValidNot0(_e))return;let Qe=e.BASE.multiply(_e).toAffine(),Qt=c.create(Qe.x);if(Qt===jt)return;let Nt;if(l!==void 0){let Je=zt(an(l(d),u)),ou=c.inv(c.mul(Je,_e)),su=c.mul(Je,et),iu=c.mul(Je,H);Nt=c.create(ou*c.create(su+iu*Qt))}else{let Je=Ea(_e,u);Nt=c.create(Je*c.create(et+Qt*H))}if(Nt===jt)return;let ao=M(Qe.x,Qe.y,Qt),yi=Nt;return I&&B(Nt)&&(yi=c.neg(Nt),ao^=1),new k(Qt,yi,y?void 0:ao)}return{seed:ht,k2sig:ut}}function E(v,m,T={}){let{seed:I,k2sig:K}=p(v,m,T);return ha(n.outputLen,c.BYTES,i)(I,K).toBytes(T.format)}function A(v,m,T,I={}){let{lowS:K,prehash:N,format:$}=Hs(I,S);if(T=W(T,void 0,"publicKey"),m=R(m,N),!ae(v)){let H=v instanceof k?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+H)}O(v,$);try{let H=k.fromBytes(v,$),tt=e.fromBytes(T);if(K&&H.hasHighS())return!1;let{r:ht,s:et}=H,ut=L(m),Kt=c.inv(et),_e=c.create(ut*Kt),Qe=c.create(ht*Kt),Qt=e.BASE.mulAddUnsafe(_e,tt,Qe);if(Qt.is0())return!1;let Nt=Qt.toAffine();return!(c.create(Nt.x)!==ht||$==="recovered"&&H.recovery!==M(Nt.x,Nt.y,ht))}catch{return!1}}function D(v,m,T={}){let{prehash:I}=Hs(T,S);return m=R(m,I),k.fromBytes(v,"recovered").recoverPublicKey(m).toBytes()}return Object.freeze({keygen:h,getPublicKey:w,getSharedSecret:g,utils:b,lengths:x,Point:e,sign:E,verify:A,recoverPublicKey:D,Signature:k,hash:n})}var js={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Xl={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var lc=BigInt(2);function Ql(e){let t=js.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,d=X(f,r,t)*f%t,l=X(d,r,t)*f%t,h=X(l,lc,t)*u%t,w=X(h,o,t)*h%t,g=X(w,s,t)*w%t,b=X(g,a,t)*g%t,x=X(b,c,t)*b%t,S=X(x,a,t)*g%t,y=X(S,r,t)*f%t,B=X(y,i,t)*w%t,_=X(B,n,t)*u%t,U=X(_,lc,t);if(!Ws.eql(Ws.sqr(U),e))throw new Error("Cannot find square root");return U}var Ws=He(js.p,{sqrt:Ql}),Jl=ac(js,{Fp:Ws,endo:Xl}),je=fc(Jl,Ue);function dc(e,t,r,n){let o=sr.digest(r instanceof Uint8Array?r:r.subarray());if(bn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),je.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new br(String(s))});try{return n?.signal?.throwIfAborted(),je.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new br(String(s))}}var Bn=class{type="secp256k1";raw;_key;constructor(t){this._key=pc(t),this.raw=hc(this._key)}toMultihash(){return Ot.digest(_t(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return nt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Z(this.raw,t.raw)}verify(t,r,n){return dc(this._key,r,t,n)}};function Ys(e){return new Bn(e)}function hc(e){return je.Point.fromBytes(e).toBytes()}function pc(e){try{return je.Point.fromBytes(e),e}catch(t){throw new Ie(String(t))}}function Tn(e,t){let{Type:r,Data:n}=Ht.decode(e),o=n??new Uint8Array;switch(r){case J.RSA:return Us(o,t);case J.Ed25519:return ds(o);case J.secp256k1:return Ys(o);case J.ECDSA:return Mo(o);default:throw new de}}function mc(e){let{Type:t,Data:r}=Ht.decode(e.digest),n=r??new Uint8Array;switch(t){case J.Ed25519:return ds(n);case J.secp256k1:return Ys(n);case J.ECDSA:return Mo(n);default:throw new de}}function _t(e){return Ht.encode({Type:J[e.type],Data:e.raw})}var yc=Symbol.for("nodejs.util.inspect.custom"),td=114,Ar=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()})`}[Fr]=!0;toString(){return this.string==null&&(this.string=nt.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return st.createV1(td,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return Z(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return Z(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[yc](){return`PeerId(${this.toString()})`}},Br=class extends Ar{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Tr=class extends Ar{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},_r=class extends Ar{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},ed=2336,Ir=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Ot.digest(V(this.url))}[yc](){return`PeerId(${this.url})`}[Fr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return st.createV1(ed,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=z(t)),t.toString()===this.toString())}};var rd=114,bc=2336;function gc(e){if(e.type==="Ed25519")return new Tr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new _r({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new Br({multihash:e.toCID().multihash,publicKey:e});throw new de}function Zs(e){if(od(e))return new Br({multihash:e});if(nd(e))try{let t=mc(e);if(t.type==="Ed25519")return new Tr({multihash:e,publicKey:t});if(t.type==="secp256k1")return new _r({multihash:e,publicKey:t})}catch{let r=z(e.digest);return new Ir(new URL(r))}throw new Mr("Supplied PeerID Multihash is invalid")}function _n(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==rd&&e.code!==bc)throw new Ur("Supplied PeerID CID is invalid");if(e.code===bc){let t=z(e.multihash.digest);return new Ir(new URL(t))}return Zs(e.multihash)}function nd(e){return e.code===Ot.code}function od(e){return e.code===sr.code}var Rr;(function(e){let t;e.codec=()=>(t==null&&(t=wt((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:ot(0),payloadType:ot(0),payload:ot(0),signature:ot(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 bt(s,e.codec())}e.encode=r;function n(s,i){return yt(s,e.codec(),i)}e.decode=n;function o(s,i){return gt(s,e.codec(),i)}e.stream=o})(Rr||(Rr={}));var In=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var Ye=class e{static createFromProtobuf=t=>{let r=Rr.decode(t),n=Tn(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=wc(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 In("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=Rr.encode({publicKey:_t(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return t==null?!1:Z(this.marshal(),t.marshal())}async validate(t,r){let n=wc(t,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},wc=(e,t,r)=>{let n=V(e),o=wn(n.byteLength),s=wn(t.length),i=wn(r.length);return new mt(o,n,s,t,i,r)};var ct=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Yt=class extends Error{static name="ValidationError";name="ValidationError"},Rn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Cn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Ln=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let d=this.readChar();if(d===void 0)return;let l=Number.parseInt(d,t);if(!Number.isNaN(l))return l});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 sd=45,id=15,Dn=new Ln;function xc(e){if(!(e.length>id))return Dn.new(e).parseWith(()=>Dn.readIPv4Addr())}function Ec(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>sd))return Dn.new(e).parseWith(()=>Dn.readIPv6Addr())}function On(e){return!!xc(e)}function vc(e){return!!Ec(e)}function Xs(e){return t=>z(t,e)}function Qs(e){return t=>V(t,e)}function Ze(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 Sc(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 Ft([r,o],r.length+o.length)}function Ac(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=Ut.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 Ft([r,o],r.length+o.length)}function Js(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=z(t,"base32"),o=Ze(r);return`${n}:${o}`}var ti=function(e){e=e.toString().trim();let t=new Uint8Array(4);return e.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new ct("Invalid byte value in IP address");t[n]=o}),t},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=On(r[n]),i;s&&(i=ti(r[n]),r[n]=z(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,z(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(t+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new ct("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Tc=function(e){if(e.byteLength!==4)throw new ct("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},_c=function(e){if(e.byteLength!==16)throw new ct("IPv6 address was incorrect length");let t=[];for(let n=0;n<e.byteLength;n+=2){let o=e[n],s=e[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let r=t.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new ct(`Invalid IPv6 address "${r}"`)}};function Ic(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new ct(`Invalid IPv6 address "${e}"`)}}var Gs=Object.values(ir).map(e=>e.decoder),ad=(function(){let e=Gs[0].or(Gs[1]);return Gs.slice(2).forEach(t=>e=e.or(t)),e})();function Rc(e){return ad.decode(e)}function Cc(e){return t=>e.encoder.encode(t)}function cd(e){if(parseInt(e).toString()!==e)throw new Yt("Value must be an integer")}function ud(e){if(e<0)throw new Yt("Value must be a positive integer, or zero")}function fd(e){return t=>{if(t>e)throw new Yt(`Value must be smaller than or equal to ${e}`)}}function ld(...e){return t=>{for(let r of e)r(t)}}var Cr=ld(cd,ud,fd(65535));var at=-1,ei=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 Cn(`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)}))}},Zt=new ei,Xd=[{code:4,name:"ip4",size:32,valueToBytes:ti,bytesToValue:Tc,validate:e=>{if(!On(e))throw new Yt(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Se,bytesToValue:Ze,validate:Cr},{code:273,name:"udp",size:16,valueToBytes:Se,bytesToValue:Ze,validate:Cr},{code:33,name:"dccp",size:16,valueToBytes:Se,bytesToValue:Ze,validate:Cr},{code:41,name:"ip6",size:128,valueToBytes:Bc,bytesToValue:_c,stringToValue:Ic,validate:e=>{if(!vc(e))throw new Yt(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:at},{code:43,name:"ipcidr",size:8,bytesToValue:Xs("base10"),valueToBytes:Qs("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:Ze,validate:Cr},{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:Xs("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?Qs("base58btc")(e):st.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Js,valueToBytes:Sc},{code:445,name:"onion3",size:296,bytesToValue:Js,valueToBytes:Ac},{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:Cc(To),valueToBytes:Rc},{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}];Xd.forEach(e=>{Zt.addProtocol(e)});function Lc(e){let t=[],r=0;for(;r<e.length;){let n=gs(e,r),o=Zt.getProtocol(n),s=Lt(n),i=Qd(o,e,r+s),a=0;i>0&&o.size===at&&(a=Lt(i));let c=s+a+i,u={code:n,name:o.name,bytes:pt(e.subarray(r,r+c))};if(i>0){let f=r+s+a,d=e.subarray(f,f+i);u.value=o.bytesToValue?.(d)??z(d)}t.push(u),r+=c}return t}function Dc(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=Zt.getProtocol(n.code),s=Lt(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=Lt(a)));let u=new Uint8Array(s+c+a),f=0;$e(n.code,u,f),f+=s,i!=null&&(o.size===at&&($e(a,u,f),f+=c),u.set(i,f)),n.bytes=u}r.push(n.bytes),t+=n.bytes.byteLength}return Ft(r,t)}function Oc(e){if(e.charAt(0)!=="/")throw new ct('String multiaddr must start with "/"');let t=[],r="protocol",n="",o="";for(let s=1;s<e.length;s++){let i=e.charAt(s);i!=="/"&&(r==="protocol"?o+=e.charAt(s):n+=e.charAt(s));let a=s===e.length-1;if(i==="/"||a){let c=Zt.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new ct(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new ct(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}t.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new ct("Incomplete multiaddr");return t}function kc(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=Zt.getProtocol(t.code);if(r==null)throw new ct(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function Qd(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:gs(t,r)}var Jd=Symbol.for("nodejs.util.inspect.custom"),ni=Symbol.for("@multiformats/multiaddr");function th(e){if(e==null&&(e="/"),Pn(e))return e.getComponents();if(e instanceof Uint8Array)return Lc(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),Oc(e);if(Array.isArray(e))return e;throw new ct("Must be a string, Uint8Array, Component[], or another Multiaddr")}var kn=class e{[ni]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=th(t),r.validate!==!1&&eh(this)}get bytes(){return this.#r==null&&(this.#r=Dc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=kc(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 Rn(`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 Z(this.bytes,t.bytes)}[Jd](){return`Multiaddr(${this.toString()})`}};function eh(e){e.getComponents().forEach(t=>{let r=Zt.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function Pn(e){return!!e?.[ni]}function Ae(e){return new kn(e)}var Pc="libp2p-peer-record",Kc=Uint8Array.from([3,1]);var Lr;(function(e){let t;(function(i){let a;i.codec=()=>(a==null&&(a=wt((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 w={multiaddr:ot(0)},g=l==null?d.len:d.pos+l;for(;d.pos<g;){let b=d.uint32();b>>>3===1?w.multiaddr=d.bytes():d.skipType(b&7)}return w},function*(d,l,h,w={}){let g=l==null?d.len:d.pos+l;for(;d.pos<g;){let b=d.uint32();b>>>3===1?yield{field:`${h}.multiaddr`,value:d.bytes()}:d.skipType(b&7)}})),a);function c(d){return bt(d,i.codec())}i.encode=c;function u(d,l){return yt(d,i.codec(),l)}i.decode=u;function f(d,l){return gt(d,i.codec(),l)}i.stream=f})(t=e.AddressInfo||(e.AddressInfo={}));let r;e.codec=()=>(r==null&&(r=wt((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:ot(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 Dt('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(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 Dt('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(l&7);break}}}})),r);function n(i){return bt(i,e.codec())}e.encode=n;function o(i,a){return yt(i,e.codec(),a)}e.decode=o;function s(i,a){return gt(i,e.codec(),a)}e.stream=s})(Lr||(Lr={}));function Nc(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 Be=class e{static createFromProtobuf=t=>{let r=Lr.decode(t),n=Zs(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=Pc;static CODEC=Kc;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=Lr.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||!Nc(this.multiaddrs,t.multiaddrs))}};function rh(e){return e[Symbol.asyncIterator]!=null}function nh(e){if(rh(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 Uc=nh;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 Dr=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 Nn(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var Un=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}},Ge=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Un(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 Un(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 oi=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Mc(e={}){return oh(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 oh(e,t){t=t??{};let r=t.onEnd,n=new Ge,o,s,i,a=Nn(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((b,x)=>{s=S=>{s=null,n.push(S);try{b(e(n))}catch(y){x(y)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Nn()})}},u=b=>s!=null?s(b):(n.push(b),o),f=b=>(n=new Ge,s!=null?s({error:b}):(n.push({error:b}),o)),d=b=>{if(i)return o;if(t?.objectMode!==!0&&b?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:b})},l=b=>i?o:(i=!0,b!=null?f(b):u({done:!0})),h=()=>(n=new Ge,l(),{done:!0}),w=b=>(l(b),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:h,throw:w,push:d,end:l,get readableLength(){return n.size},onEmpty:async b=>{let x=b?.signal;if(x?.throwIfAborted(),n.isEmpty())return;let S,y;x!=null&&(S=new Promise((B,_)=>{y=()=>{_(new oi)},x.addEventListener("abort",y)}));try{await Promise.race([a.promise,S])}finally{y!=null&&x!=null&&x?.removeEventListener("abort",y)}}},r==null)return o;let g=o;return o={[Symbol.asyncIterator](){return this},next(){return g.next()},throw(b){return g.throw(b),r!=null&&(r(b),r=void 0),{done:!0}},return(){return g.return(),r!=null&&(r(),r=void 0),{done:!0}},push:d,end(b){return g.end(b),r!=null&&(r(b),r=void 0),o},get readableLength(){return g.readableLength},onEmpty:b=>g.onEmpty(b)},o}function sh(e){return e.reason}async function Fc(e,t,r){if(t==null)return e;let n=r?.translateError??sh;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 si=class extends Dr{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 ii(e){let{name:t,metrics:r}=e,n;return r!=null?n=new si({name:t,metrics:r}):n=new Dr,n}var Bt=class extends Error{static name="AbortError";name="AbortError";constructor(t="The operation was aborted",...r){super(t,...r)}};async function Mn(e,t,r,n){let o=new Bt(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(){ci(r,"abort",d),ci(e,t,u),ci(e,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)};ai(r,"abort",d),ai(e,t,u),ai(e,s,f)})}function ai(e,t,r){e!=null&&(qc(e)?e.addEventListener(t,r):e.addListener(t,r))}function ci(e,t,r){e!=null&&(qc(e)?e.removeEventListener(t,r):e.removeListener(t,r))}function qc(e){return typeof e.addEventListener=="function"&&typeof e.removeEventListener=="function"}var Fn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};var qn=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 Bt)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function ih(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var zn=class{id;fn;options;recipients;status;timeline;controller;constructor(t,r){this.id=ih(),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 Bt),this.cleanup())}async join(t={}){let r=new qn(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 Fc(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 ui(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 Or=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=ui(this.emitEmpty.bind(this),1),this.emitIdle=ui(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 Fn;let n=new zn(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 Bt)}),this.clear()}async onEmpty(t){this.size!==0&&await Mn(this,"empty",t?.signal)}async onSizeLessThan(t,r){this.size<t||await Mn(this,"next",r?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await Mn(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=Mc({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 Bt("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 Hn="lock:worker:request-read",Vn="lock:worker:abort-read-request",$n="lock:worker:release-read",Wn="lock:master:grant-read",jn="lock:master:error-read",Yn="lock:worker:request-write",Zn="lock:worker:abort-write-request",Gn="lock:worker:release-write",Xn="lock:master:grant-write",Qn="lock:master:error-write",Jn="lock:worker:finalize",to="mortice",zc={singleProcess:!1};var fi=(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(d=>{let l=h=>{if(h?.data==null)return;let w={type:h.data.type,name:h.data.name,identifier:h.data.identifier};w.type===a&&w.identifier===f.identifier&&(t.removeEventListener("message",l),d())};t.addEventListener("message",l)})},onError:d=>{t.postMessage({type:i,name:f.name,identifier:f.identifier,error:{message:d.message,name:d.name,stack:d.stack}})}}}),f.type===s&&e.safeDispatchEvent(n,{detail:{name:f.name,identifier:f.identifier}}),f.type===Jn&&e.safeDispatchEvent("finalizeRequest",{detail:{name:f.name}})};var Hc=(e=10)=>Math.random().toString().substring(2,e+2);var eo=class{name;channel;constructor(t){this.name=t,this.channel=new BroadcastChannel(to)}readLock(t){return this.sendRequest(Hn,Vn,Wn,jn,$n,t)}writeLock(t){return this.sendRequest(Yn,Zn,Xn,Qn,Gn,t)}finalize(){this.channel.postMessage({type:Jn,name:this.name}),this.channel.close()}async sendRequest(t,r,n,o,s,i){i?.signal?.throwIfAborted();let a=Hc();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 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 Vc=e=>{if(e=Object.assign({},zc,e),!!globalThis.document||e.singleProcess){let r=new BroadcastChannel(to),n=new Ce;return r.addEventListener("message",fi(n,r,"requestReadLock","abortReadLockRequest",Hn,Vn,jn,$n,Wn)),r.addEventListener("message",fi(n,r,"requestWriteLock","abortWriteLockRequest",Yn,Zn,Qn,Gn,Xn)),n}return new eo(e.name)};var Te=new Map,kr;function $c(e){return typeof e?.readLock=="function"&&typeof e?.writeLock=="function"}function ah(e){if(kr==null&&(kr=Vc(e),!$c(kr))){let t=kr;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 kr}async function li(e,t){let r,n,o=new Promise((i,a)=>{r=i,n=a}),s=()=>{n(new Bt)};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 Wc=(e,t)=>{let r=Te.get(e);if(r!=null)return r;let n=ah(t);if($c(n))return r=n,Te.set(e,r),r;let o=new Or({concurrency:1}),s;return r={async readLock(i){if(s!=null)return li(s,i);s=new Or({concurrency:t.concurrency,autoStart:!1});let a=s,c=li(s,i);return o.add(async()=>{a.start(),await a.onIdle().then(()=>{s===a&&(s=null)})}),c},async writeLock(i){return s=null,li(o,i)},finalize:()=>{Te.delete(e)},queue:o},Te.set(e,r),t.autoFinalize===!0&&o.addEventListener("idle",()=>{r.finalize()},{once:!0}),r};var ch={name:"lock",concurrency:1/0,singleProcess:!1,autoFinalize:!1};function di(e){let t=Object.assign({},ch,e);return Wc(t.name,t)}var Gt;(function(e){let t;(function(a){let c;a.codec=()=>(c==null&&(c=wt((l,h,w={})=>{w.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)),w.lengthDelimited!==!1&&h.ldelim()},(l,h,w={})=>{let g={key:"",value:ot(0)},b=h==null?l.len:l.pos+h;for(;l.pos<b;){let x=l.uint32();switch(x>>>3){case 1:{g.key=l.string();break}case 2:{g.value=l.bytes();break}default:{l.skipType(x&7);break}}}return g},function*(l,h,w,g={}){let b=h==null?l.len:l.pos+h;for(;l.pos<b;){let x=l.uint32();switch(x>>>3){case 1:{yield{field:`${w}.key`,value:l.string()};break}case 2:{yield{field:`${w}.value`,value:l.bytes()};break}default:{l.skipType(x&7);break}}}})),c);function u(l){return bt(l,a.codec())}a.encode=u;function f(l,h){return yt(l,a.codec(),h)}a.decode=f;function d(l,h){return gt(l,a.codec(),h)}a.stream=d})(t=e.Peer$metadataEntry||(e.Peer$metadataEntry={}));let r;(function(a){let c;a.codec=()=>(c==null&&(c=wt((l,h,w={})=>{w.lengthDelimited!==!1&&h.fork(),l.key!=null&&l.key!==""&&(h.uint32(10),h.string(l.key)),l.value!=null&&(h.uint32(18),Kr.codec().encode(l.value,h)),w.lengthDelimited!==!1&&h.ldelim()},(l,h,w={})=>{let g={key:""},b=h==null?l.len:l.pos+h;for(;l.pos<b;){let x=l.uint32();switch(x>>>3){case 1:{g.key=l.string();break}case 2:{g.value=Kr.codec().decode(l,l.uint32(),{limits:w.limits?.value});break}default:{l.skipType(x&7);break}}}return g},function*(l,h,w,g={}){let b=h==null?l.len:l.pos+h;for(;l.pos<b;){let x=l.uint32();switch(x>>>3){case 1:{yield{field:`${w}.key`,value:l.string()};break}case 2:{yield*Kr.codec().stream(l,l.uint32(),`${w}.value`,{limits:g.limits?.value});break}default:{l.skipType(x&7);break}}}})),c);function u(l){return bt(l,a.codec())}a.encode=u;function f(l,h){return yt(l,a.codec(),h)}a.decode=f;function d(l,h){return gt(l,a.codec(),h)}a.stream=d})(r=e.Peer$tagsEntry||(e.Peer$tagsEntry={}));let n;e.codec=()=>(n==null&&(n=wt((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),Pr.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),e.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),e.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 Dt('Decode error - repeated field "addresses" had too many elements');f.addresses.push(Pr.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 Dt('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 Er('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 Er('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(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 Dt('Streaming decode error - repeated field "addresses" had too many elements');for(let w of Pr.codec().stream(a,a.uint32(),`${u}.addresses[]`,{limits:f.limits?.addresses$}))yield{...w,index:d.addresses};d.addresses++;break}case 2:{if(f.limits?.protocols!=null&&d.protocols===f.limits.protocols)throw new Dt('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 Dt('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}}),d.metadata++;break}case 7:{if(f.limits?.tags!=null&&d.tags===f.limits.tags)throw new Dt('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}}),d.tags++;break}case 8:{yield{field:`${u}.updated`,value:a.uint64Number()};break}default:{a.skipType(h&7);break}}}})),n);function o(a){return bt(a,e.codec())}e.encode=o;function s(a,c){return yt(a,e.codec(),c)}e.decode=s;function i(a,c){return gt(a,e.codec(),c)}e.stream=i})(Gt||(Gt={}));var Pr;(function(e){let t;e.codec=()=>(t==null&&(t=wt((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:ot(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 bt(s,e.codec())}e.encode=r;function n(s,i){return yt(s,e.codec(),i)}e.decode=n;function o(s,i){return gt(s,e.codec(),i)}e.stream=o})(Pr||(Pr={}));var Kr;(function(e){let t;e.codec=()=>(t==null&&(t=wt((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 bt(s,e.codec())}e.encode=r;function n(s,i){return yt(s,e.codec(),i)}e.decode=n;function o(s,i){return gt(s,e.codec(),i)}e.stream=o})(Kr||(Kr={}));function uh(e,t){if(e.publicKey!=null||t.publicKey==null)return e;let r;e.type==="RSA"&&(r=e.toMultihash());let n=Tn(t.publicKey,r);return gc(n)}function jc(e,t,r){let n=Gt.decode(t);return Xe(e,n,r)}function Xe(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:uh(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 Yc(e,t){return fh(e.addresses,t.addresses)&&lh(e.protocols,t.protocols)&&dh(e.publicKey,t.publicKey)&&hh(e.peerRecordEnvelope,t.peerRecordEnvelope)&&ph(e.metadata,t.metadata)&&mh(e.tags,t.tags)}function fh(e,t){return Gc(e,t,(r,n)=>!(r.isCertified!==n.isCertified||!Z(r.multiaddr,n.multiaddr)))}function lh(e,t){return Gc(e,t,(r,n)=>r===n)}function dh(e,t){return Zc(e,t)}function hh(e,t){return Zc(e,t)}function ph(e,t){return Xc(e,t,(r,n)=>Z(r,n))}function mh(e,t){return Xc(e,t,(r,n)=>r.value===n.value&&r.expiry===n.expiry)}function Zc(e,t){return e==null&&t==null?!0:e!=null&&t!=null?Z(e,t):!1}function Gc(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 Xc(e,t,r){if(e.size!==t.size)return!1;for(let[n,o]of e.entries()){let s=t.get(n);if(s==null||!r(o,s))return!1}return!0}var Xt="/",Qc=new TextEncoder().encode(Xt),ro=Qc[0],no=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]!==ro)throw new Error("Invalid key")}toString(t="utf8"){return z(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new e(t.join(Xt))}static random(){return new e(Math.random().toString().substring(2))}static asKey(t){return t instanceof Uint8Array||typeof t=="string"?new e(t):typeof t.uint8Array=="function"?new e(t.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=Qc),this._buf[0]!==ro){let t=new Uint8Array(this._buf.byteLength+1);t.fill(ro,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===ro;)this._buf=this._buf.subarray(0,-1)}less(t){let r=this.list(),n=t.list();for(let o=0;o<r.length;o++){if(n.length<o+1)return!1;let s=r[o],i=n[o];if(s<i)return!0;if(s>i)return!1}return r.length<n.length}reverse(){return e.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let t=this.namespaces();return t[t.length-1]}list(){return this.toString().split(Xt).slice(1)}type(){return yh(this.baseNamespace())}name(){return bh(this.baseNamespace())}instance(t){return new e(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(Xt)||(t+=Xt),t+=this.type(),new e(t)}parent(){let t=this.list();return t.length===1?new e(Xt):new e(t.slice(0,-1).join(Xt))}child(t){return this.toString()===Xt?t:t.toString()===Xt?this:new e(this.toString()+t.toString(),!1)}isAncestorOf(t){return t.toString()===this.toString()?!1:t.toString().startsWith(this.toString())}isDecendantOf(t){return t.toString()===this.toString()?!1:this.toString().startsWith(t.toString())}isTopLevel(){return this.list().length===1}concat(...t){return e.withNamespaces([...this.namespaces(),...gh(t.map(r=>r.namespaces()))])}};function yh(e){let t=e.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function bh(e){let t=e.split(":");return t[t.length-1]}function gh(e){return[].concat(...e)}var hi="/peers/";function Nr(e){if(!Re(e)||e.type==null)throw new q("Invalid PeerId");let t=e.toCID().toString();return new no(`${hi}${t}`)}async function Jc(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)),!Pn(i.multiaddr))throw new q("Multiaddr was invalid");if(!await t(e,i.multiaddr,o))continue;let a=i.isCertified??!1,c=i.multiaddr.toString(),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 so(e,t,r,n){if(t==null)throw new q("Invalid PeerData");if(t.publicKey!=null&&!e.equals(t.publicKey.toMultihash().bytes))throw new q("publicKey does not match peer id");let o=n.existingPeer?.peer;if(o!=null&&!e.equals(o.id))throw new q("peer id did not match existing peer id");let s=o?.addresses??[],i=new Set(o?.protocols??[]),a=o?.metadata??new Map,c=o?.tags??new Map,u=o?.peerRecordEnvelope;if(r==="patch"){if((t.multiaddrs!=null||t.addresses!=null)&&(s=[],t.multiaddrs!=null&&s.push(...t.multiaddrs.map(l=>({isCertified:!1,multiaddr:l}))),t.addresses!=null&&s.push(...t.addresses)),t.protocols!=null&&(i=new Set(t.protocols)),t.metadata!=null){let l=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);a=oo(l,{validate:tu})}if(t.tags!=null){let l=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags);c=oo(l,{validate:eu,map:ru})}t.peerRecordEnvelope!=null&&(u=t.peerRecordEnvelope)}if(r==="merge"){if(t.multiaddrs!=null&&s.push(...t.multiaddrs.map(l=>({isCertified:!1,multiaddr:l}))),t.addresses!=null&&s.push(...t.addresses),t.protocols!=null&&(i=new Set([...i,...t.protocols])),t.metadata!=null){let l=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);for(let[h,w]of l)w==null?a.delete(h):a.set(h,w);a=oo([...a.entries()],{validate:tu})}if(t.tags!=null){let l=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags),h=new Map(c);for(let[w,g]of l)g==null?h.delete(w):h.set(w,g);c=oo([...h.entries()],{validate:eu,map:ru})}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 d={addresses:await Jc(e,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=>Z(h.multiaddr,l.multiaddr))?.observed??Date.now()}),e.type!=="RSA"&&delete d.publicKey,d}function oo(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 tu(e,t){if(typeof e!="string")throw new q("Metadata key must be a string");if(!(t instanceof Uint8Array))throw new q("Metadata value must be a Uint8Array")}function eu(e,t){if(typeof e!="string")throw new q("Tag name must be a string");if(t.value!=null){if(parseInt(`${t.value}`,10)!==t.value)throw new q("Tag value must be an integer");if(t.value<0||t.value>100)throw new q("Tag value must be between 0-100")}if(t.ttl!=null){if(parseInt(`${t.ttl}`,10)!==t.ttl)throw new q("Tag ttl must be an integer");if(t.ttl<0)throw new q("Tag ttl must be between greater than 0")}}function ru(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 nu(e){let t=e.toString().split("/")[2],r=st.parse(t,Ut);return _n(r)}function pi(e,t,r){let n=nu(e);return jc(n,t,r)}function wh(e,t){return{prefix:hi,filters:(e.filters??[]).map(r=>({key:n,value:o})=>r(pi(n,o,t))),orders:(e.orders??[]).map(r=>(n,o)=>r(pi(n.key,n.value,t),pi(o.key,o.value,t)))}}var io=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=ii({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:di({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(Nr(t),r)}async load(t,r){let n=Nr(t),o=await this.datastore.get(n,r),s=Gt.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,r),new tr;return Xe(t,s,this.peerId.equals(t)?1/0:this.maxAddressAge)}async save(t,r,n){let o=await this.#t(t,n),s=await so(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 so(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 so(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(wh(t??{},this.maxAddressAge),t)){let o=nu(r);if(o.equals(this.peerId))continue;let s=Gt.decode(n);if(this.#r(o,s)){await this.datastore.delete(r,t);continue}yield Xe(o,s,this.peerId.equals(o)?1/0:this.maxAddressAge)}}async#t(t,r){try{let n=Nr(t),o=await this.datastore.get(n,r),s=Gt.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,r),new tr;return{peerPB:s,peer:Xe(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=Gt.encode(r);return await this.datastore.put(Nr(t),s,o),{peer:Xe(t,r,this.maxAddressAge),previous:n?.peer,updated:n==null||!Yc(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 mi=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 io(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 Uc(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=Re(r)?r:Re(r?.expectedPeer)?r.expectedPeer:void 0,s=Re(r)||r===void 0?n:r,i=await Ye.openAndCertify(t,Be.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=Be.createFromProtobuf(i.payload);if(!c.peerId.equals(a))return this.log("signing key did not match peer id in the peer record - signer: %p record: %p",a,c.peerId),!1;let u;try{u=await this.get(a,s)}catch(f){if(f.name!=="NotFoundError")throw f}if(u?.peerRecordEnvelope!=null){let f=Ye.createFromProtobuf(u.peerRecordEnvelope),d=Be.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: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 xh(e,t={}){return new mi(e,t)}return lu(Eh);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/curves/utils.js:
|