@libp2p/peer-store 12.0.24 → 12.0.25
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 ao=Object.defineProperty;var Jc=Object.getOwnPropertyDescriptor;var tu=Object.getOwnPropertyNames;var eu=Object.prototype.hasOwnProperty;var Et=(e,t)=>{for(var r in t)ao(e,r,{get:t[r],enumerable:!0})},ru=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of tu(t))!eu.call(e,o)&&o!==r&&ao(e,o,{get:()=>t[o],enumerable:!(n=Jc(t,o))||n.enumerable});return e};var nu=e=>ru(ao({},"__esModule",{value:!0}),e);var oh={};Et(oh,{persistentPeerStore:()=>nh});var M=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Ce=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var nr=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var $r=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Wr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var pe=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var jr=Symbol.for("@libp2p/peer-id");function Le(e){return!!e?.[jr]}function ou(e){return typeof e?.handleEvent=="function"}function su(e){return(e!==!0&&e!==!1&&e?.once)??!1}var De=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=su(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))}ou(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 ho={};Et(ho,{base58btc:()=>G,base58flickr:()=>hu});var uh=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 me(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return me(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 iu(e){return e?.buffer instanceof ArrayBuffer}function me(e){return iu(e)?e:e.slice()}function au(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,l=e.charAt(0),d=Math.log(f)/Math.log(256),h=Math.log(256)/Math.log(f);function b(y){if(y instanceof Uint8Array||(ArrayBuffer.isView(y)?y=new Uint8Array(y.buffer,y.byteOffset,y.byteLength):Array.isArray(y)&&(y=Uint8Array.from(y))),!(y instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(y.length===0)return"";for(var v=0,_=0,L=0,R=y.length;L!==R&&y[L]===0;)L++,v++;for(var P=(R-L)*h+1>>>0,D=new Uint8Array(P);L!==R;){for(var T=y[L],K=0,N=P-1;(T!==0||K<_)&&N!==-1;N--,K++)T+=256*D[N]>>>0,D[N]=T%f>>>0,T=T/f>>>0;if(T!==0)throw new Error("Non-zero carry");_=K,L++}for(var k=P-_;k!==P&&D[k]===0;)k++;for(var m=l.repeat(v);k<P;++k)m+=e.charAt(D[k]);return m}function E(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return new Uint8Array;var v=0;if(y[v]!==" "){for(var _=0,L=0;y[v]===l;)_++,v++;for(var R=(y.length-v)*d+1>>>0,P=new Uint8Array(R);y[v];){var D=n[y.charCodeAt(v)];if(D===255)return;for(var T=0,K=R-1;(D!==0||T<L)&&K!==-1;K--,T++)D+=f*P[K]>>>0,P[K]=D%256>>>0,D=D/256>>>0;if(D!==0)throw new Error("Non-zero carry");L=T,v++}if(y[v]!==" "){for(var N=R-L;N!==R&&P[N]===0;)N++;for(var k=new Uint8Array(_+(R-N)),m=_;N!==R;)k[m++]=P[N++];return k}}}function p(y){var v=E(y);if(v)return v;throw new Error(`Non-${t} character`)}return{encode:b,decodeUnsafe:E,decode:p}}var cu=au,uu=cu,Si=uu;var co=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")}},uo=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)}},fo=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 fo({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var lo=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 co(t,r,n),this.decoder=new uo(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Oe({name:e,prefix:t,encode:r,decode:n}){return new lo(e,t,r,n)}function ee({name:e,prefix:t,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:s}=Si(r,e,n);return Oe({prefix:t,name:e,encode:o,decode:i=>Tt(s(i))})}function fu(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 lu(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 du(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 Y({name:e,prefix:t,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let s=du(n,o);return Oe({prefix:t,name:e,encode(i){return lu(i,n,r)},decode(i){return fu(i,s,r,e)}})}var G=ee({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),hu=ee({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var po={};Et(po,{base32:()=>Ut,base32hex:()=>bu,base32hexpad:()=>wu,base32hexpadupper:()=>xu,base32hexupper:()=>gu,base32pad:()=>mu,base32padupper:()=>yu,base32upper:()=>pu,base32z:()=>Eu});var Ut=Y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),pu=Y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),mu=Y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),yu=Y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),bu=Y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),gu=Y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),wu=Y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),xu=Y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),Eu=Y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var mo={};Et(mo,{base36:()=>or,base36upper:()=>vu});var or=ee({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),vu=ee({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Su=Ii,_i=128,Au=127,_u=~Au,Tu=Math.pow(2,31);function Ii(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Tu;)t[r++]=e&255|_i,e/=128;for(;e&_u;)t[r++]=e&255|_i,e>>>=7;return t[r]=e|0,Ii.bytes=r-n+1,t}var Iu=yo,Bu=128,Ti=127;function yo(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw yo.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>=Bu);return yo.bytes=s-n,r}var Ru=Math.pow(2,7),Cu=Math.pow(2,14),Lu=Math.pow(2,21),Du=Math.pow(2,28),Ou=Math.pow(2,35),ku=Math.pow(2,42),Pu=Math.pow(2,49),Ku=Math.pow(2,56),Nu=Math.pow(2,63),Uu=function(e){return e<Ru?1:e<Cu?2:e<Lu?3:e<Du?4:e<Ou?5:e<ku?6:e<Pu?7:e<Ku?8:e<Nu?9:10},Fu={encode:Su,decode:Iu,encodingLength:Uu},Mu=Fu,sr=Mu;function ir(e,t=0){return[sr.decode(e,t),sr.decode.bytes]}function ke(e,t,r=0){return sr.encode(e,t,r),t}function Pe(e){return sr.encodingLength(e)}function Ft(e,t){let r=t.byteLength,n=Pe(e),o=n+Pe(r),s=new Uint8Array(o+r);return ke(e,s,0),ke(r,s,n),s.set(t,o),new Ke(e,r,t,s)}function Ne(e){let t=Tt(e),[r,n]=ir(t),[o,s]=ir(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 Bi(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=me(n),this.bytes=me(o)}};function Ri(e,t){let{bytes:r,version:n}=e;return n===0?zu(r,bo(e),t??G.encoder):Vu(r,bo(e),t??Ut.encoder)}var Ci=new WeakMap;function bo(e){let t=Ci.get(e);if(t==null){let r=new Map;return Ci.set(e,r),r}return t}var et=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=me(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!==ar)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Hu)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=Ft(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&&Bi(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[$u]===!0){let{version:n,multihash:o,code:s}=r,i=Ne(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!==ar)throw new Error(`Version 0 CID must use dag-pb (code: ${ar}) 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,ar,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[l,d]=ir(t.subarray(r));return r+=d,l},o=n(),s=ar;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]=qu(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 bo(s).set(n,t),s}};function qu(e,t){switch(e[0]){case"Q":{let r=t??G;return[G.prefix,r.decode(`${G.prefix}${e}`)]}case G.prefix:{let r=t??G;return[G.prefix,r.decode(e)]}case Ut.prefix:{let r=t??Ut;return[Ut.prefix,r.decode(e)]}case or.prefix:{let r=t??or;return[or.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 zu(e,t,r){let{prefix:n}=r;if(n!==G.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function Vu(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 ar=112,Hu=18;function Li(e,t,r){let n=Pe(e),o=n+Pe(t),s=new Uint8Array(o+r.byteLength);return ke(e,s,0),ke(t,s,n),s.set(r,o),s}var $u=Symbol.for("@ipld/js-cid/CID");var go={};Et(go,{identity:()=>Lt});var Di=0,Wu="identity",Oi=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 Ft(Di,Oi(e))}var Lt={code:Di,name:Wu,encode:Oi,digest:ju};function W(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Zu(e){return e.buffer instanceof ArrayBuffer}function pt(e){return Zu(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 J(e=0){return new Uint8Array(e)}function lt(e=0){return new Uint8Array(e)}function Yu(e){return e?.buffer instanceof ArrayBuffer}function wo(e){if(Yu(e))return e;let t=e.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function Mt(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=lt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return wo(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 Yr(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(Yr(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(Yr(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(Yr(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 Mt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Mt(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=n,s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,f=r>a&&r<=c;if(u&&f){if(t===a&&r===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Yr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let d=u;d>=0;d--){let h=this.get(l+d);if(n[d]!==h){f=Math.max(1,d-a[h]);break}}if(f===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=lt(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=J(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=J(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=J(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=lt(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=J(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=J(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=J(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=J(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=J(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!W(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var xo={};Et(xo,{base10:()=>Gu});var Gu=ee({prefix:"9",name:"base10",alphabet:"0123456789"});var Eo={};Et(Eo,{base16:()=>Xu,base16upper:()=>Qu});var Xu=Y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Qu=Y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var vo={};Et(vo,{base2:()=>Ju});var Ju=Y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var So={};Et(So,{base256emoji:()=>of});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}"),tf=Ni.reduce((e,t,r)=>(e[r]=t,e),[]),ef=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 rf(e){return e.reduce((t,r)=>(t+=tf[r],t),"")}function nf(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=ef[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var of=Oe({prefix:"\u{1F680}",name:"base256emoji",encode:rf,decode:nf});var _o={};Et(_o,{base64:()=>sf,base64pad:()=>af,base64url:()=>Ao,base64urlpad:()=>cf});var sf=Y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),af=Y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ao=Y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),cf=Y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var To={};Et(To,{base8:()=>uf});var uf=Y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Io={};Et(Io,{identity:()=>ff});var ff=Oe({prefix:"\0",name:"identity",encode:e=>Ei(Tt(e)),decode:e=>Tt(xi(e))});var Zh=new TextEncoder,Yh=new TextDecoder;var Co={};Et(Co,{sha256:()=>cr,sha512:()=>pf});var hf=20;function Ro({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Bo(e,t,r,n,o)}var Bo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??hf,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 Ft(t,e)}function Mi(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var cr=Ro({name:"sha2-256",code:18,encode:Mi("SHA-256")}),pf=Ro({name:"sha2-512",code:19,encode:Mi("SHA-512")});var ur={...Io,...vo,...To,...xo,...Eo,...po,...mo,...ho,..._o,...So},ap={...Co,...go};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))),Lo=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=lt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),mf={utf8:qi,"utf-8":qi,hex:ur.base16,latin1:Lo,ascii:Lo,binary:Lo,...ur},Gr=mf;function H(e,t="utf8"){let r=Gr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function q(e,t="utf8"){let r=Gr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var yf=parseInt("11111",2),Do=parseInt("10000000",2),bf=parseInt("01111111",2),Vi={0:fr,1:fr,2:gf,3:Ef,4:vf,5:xf,6:wf,16:fr,22:fr,48:fr};function $t(e,t={offset:0}){let r=e[t.offset]&yf;if(t.offset++,Vi[r]!=null)return Vi[r](e,t);throw new Error("No decoder for tag "+r)}function lr(e,t){let r=0;if((e[t.offset]&Do)===Do){let n=e[t.offset]&bf,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function fr(e,t){lr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=$t(e,t);if(n===null)break;r.push(n)}return r}function gf(e,t){let r=lr(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 wf(e,t){let r=lr(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function xf(e,t){return t.offset++,null}function Ef(e,t){let r=lr(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 vf(e,t){let r=lr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Sf(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 Oo(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Sf(e.byteLength);return new mt(Uint8Array.from([t.byteLength|Do]),t)}function vt(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]),Oo(t),t)}function Xr(e){let t=Uint8Array.from([0]),r=new mt(t,e);return new mt(Uint8Array.from([3]),Oo(r),r)}function ne(e,t=48){let r=new mt;for(let n of e)r.append(n);return new mt(Uint8Array.from([t]),Oo(r),r)}var Af=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),_f=Uint8Array.from([6,5,43,129,4,0,34]),Tf=Uint8Array.from([6,5,43,129,4,0,35]),If={ext:!0,kty:"EC",crv:"P-256"},Bf={ext:!0,kty:"EC",crv:"P-384"},Rf={ext:!0,kty:"EC",crv:"P-521"},ko=32,Po=48,Ko=66;function No(e){let t=$t(e);return Hi(t)}function Hi(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===ko*2+1)return n=q(t.subarray(r,r+ko),"base64url"),o=q(t.subarray(r+ko),"base64url"),new Ue({...If,key_ops:["verify"],x:n,y:o});if(t.byteLength===Po*2+1)return n=q(t.subarray(r,r+Po),"base64url"),o=q(t.subarray(r+Po),"base64url"),new Ue({...Bf,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ko*2+1)return n=q(t.subarray(r,r+Ko),"base64url"),o=q(t.subarray(r+Ko),"base64url"),new Ue({...Rf,key_ops:["verify"],x:n,y:o});throw new M(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function $i(e){return ne([vt(Uint8Array.from([1])),ne([Cf(e.crv)],160),ne([Xr(new mt(Uint8Array.from([4]),H(e.x??"","base64url"),H(e.y??"","base64url")))],161)]).subarray()}function Cf(e){if(e==="P-256")return Af;if(e==="P-384")return _f;if(e==="P-521")return Tf;throw new M(`Invalid curve ${e}`)}var Ue=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 Lt.digest(It(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}async verify(t,r,n){return ki(this.jwk,r,t,n)}};function Uo(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}function oe(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(`${r}expected number, got ${typeof e}`)}if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new RangeError(`${r}expected integer >= 0, got ${e}`)}}function St(e,t,r=""){let n=Uo(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof e}`,u=i+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(u):new TypeError(u)}return e}function Qr(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(oe(e.outputLen),oe(e.blockLen),e.outputLen<1)throw new Error('"outputLen" must be >= 1');if(e.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Fe(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Jr(e,t){St(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function jt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function tn(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Dt(e,t){return e<<32-t|e>>>t}var ji=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Lf=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function en(e){if(St(e),ji)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Lf[e[r]];return t}var Wt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Wi(e){if(e>=Wt._0&&e<=Wt._9)return e-Wt._0;if(e>=Wt.A&&e<=Wt.F)return e-(Wt.A-10);if(e>=Wt.a&&e<=Wt.f)return e-(Wt.a-10)}function dr(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(ji)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=Wi(e.charCodeAt(s)),a=Wi(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 Fo(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];St(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 Mo(e,t={}){let r=(o,s)=>e(s).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function Zi(e=32){oe(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 qo=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function Yi(e,t,r){return e&t^~e&r}function Gi(e,t,r){return e&t^e&r^t&r}var hr=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=tn(this.buffer)}update(t){Fe(this),St(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=tn(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Fe(this),Jr(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,jt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=tn(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Zt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ct=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var rn=BigInt(4294967295),Xi=BigInt(32);function Df(e,t=!1){return t?{h:Number(e&rn),l:Number(e>>Xi&rn)}:{h:Number(e>>Xi&rn)|0,l:Number(e&rn)|0}}function Qi(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}=Df(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var zo=(e,t,r)=>e>>>r,Vo=(e,t,r)=>e<<32-r|t>>>r,ye=(e,t,r)=>e>>>r|t<<32-r,be=(e,t,r)=>e<<32-r|t>>>r,pr=(e,t,r)=>e<<64-r|t>>>r-32,mr=(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),ta=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ea=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),ra=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,na=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),oa=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var kf=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]),se=new Uint32Array(64),Ho=class extends hr{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,r,n,o,s,i,a,c]}set(t,r,n,o,s,i,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,r){for(let l=0;l<16;l++,r+=4)se[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let d=se[l-15],h=se[l-2],b=Dt(d,7)^Dt(d,18)^d>>>3,E=Dt(h,17)^Dt(h,19)^h>>>10;se[l]=E+se[l-7]+b+se[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let d=Dt(a,6)^Dt(a,11)^Dt(a,25),h=f+d+Yi(a,c,u)+kf[l]+se[l]|0,E=(Dt(n,2)^Dt(n,13)^Dt(n,22))+Gi(n,o,s)|0;f=u,u=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+E|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,u,f)}roundClean(){jt(se)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),jt(this.buffer)}},$o=class extends Ho{A=Zt[0]|0;B=Zt[1]|0;C=Zt[2]|0;D=Zt[3]|0;E=Zt[4]|0;F=Zt[5]|0;G=Zt[6]|0;H=Zt[7]|0;constructor(){super(32)}};var sa=Qi(["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))),Pf=sa[0],Kf=sa[1],ie=new Uint32Array(80),ae=new Uint32Array(80),Wo=class extends hr{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:d,Gh:h,Gl:b,Hh:E,Hl:p}=this;return[t,r,n,o,s,i,a,c,u,f,l,d,h,b,E,p]}set(t,r,n,o,s,i,a,c,u,f,l,d,h,b,E,p){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=d|0,this.Gh=h|0,this.Gl=b|0,this.Hh=E|0,this.Hl=p|0}process(t,r){for(let _=0;_<16;_++,r+=4)ie[_]=t.getUint32(r),ae[_]=t.getUint32(r+=4);for(let _=16;_<80;_++){let L=ie[_-15]|0,R=ae[_-15]|0,P=ye(L,R,1)^ye(L,R,8)^zo(L,R,7),D=be(L,R,1)^be(L,R,8)^Vo(L,R,7),T=ie[_-2]|0,K=ae[_-2]|0,N=ye(T,K,19)^pr(T,K,61)^zo(T,K,6),k=be(T,K,19)^mr(T,K,61)^Vo(T,K,6),m=ea(D,k,ae[_-7],ae[_-16]),g=ra(m,P,N,ie[_-7],ie[_-16]);ie[_]=g|0,ae[_]=m|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:d,Fh:h,Fl:b,Gh:E,Gl:p,Hh:y,Hl:v}=this;for(let _=0;_<80;_++){let L=ye(l,d,14)^ye(l,d,18)^pr(l,d,41),R=be(l,d,14)^be(l,d,18)^mr(l,d,41),P=l&h^~l&E,D=d&b^~d&p,T=na(v,R,D,Kf[_],ae[_]),K=oa(T,y,L,P,Pf[_],ie[_]),N=T|0,k=ye(n,o,28)^pr(n,o,34)^pr(n,o,39),m=be(n,o,28)^mr(n,o,34)^mr(n,o,39),g=n&s^n&a^s&a,S=o&i^o&c^i&c;y=E|0,v=p|0,E=h|0,p=b|0,h=l|0,b=d|0,{h:l,l:d}=qt(u|0,f|0,K|0,N|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let x=Ji(N,m,S);n=ta(x,K,k,g),o=x|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:l,l:d}=qt(this.Eh|0,this.El|0,l|0,d|0),{h,l:b}=qt(this.Fh|0,this.Fl|0,h|0,b|0),{h:E,l:p}=qt(this.Gh|0,this.Gl|0,E|0,p|0),{h:y,l:v}=qt(this.Hh|0,this.Hl|0,y|0,v|0),this.set(n,o,s,i,a,c,u,f,l,d,h,b,E,p,y,v)}roundClean(){jt(ie,ae)}destroy(){this.destroyed=!0,jt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},jo=class extends Wo{Ah=ct[0]|0;Al=ct[1]|0;Bh=ct[2]|0;Bl=ct[3]|0;Ch=ct[4]|0;Cl=ct[5]|0;Dh=ct[6]|0;Dl=ct[7]|0;Eh=ct[8]|0;El=ct[9]|0;Fh=ct[10]|0;Fl=ct[11]|0;Gh=ct[12]|0;Gl=ct[13]|0;Hh=ct[14]|0;Hl=ct[15]|0;constructor(){super(64)}};var Me=Mo(()=>new $o,qo(1));var nn=Mo(()=>new jo,qo(3));var z=(e,t,r)=>St(e,t,r),Yo=oe,qe=en,nt=(...e)=>Fo(...e),ze=e=>dr(e),ge=Uo,yr=e=>Zi(e),sn=BigInt(0),Zo=BigInt(1);function Ot(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new TypeError(r+"expected boolean, got type="+typeof e)}return e}function an(e){if(typeof e=="bigint"){if(!on(e))throw new RangeError("positive bigint expected, got "+e)}else Yo(e);return e}function kt(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 br(e){let t=an(e).toString(16);return t.length&1?"0"+t:t}function ia(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?sn:BigInt("0x"+e)}function we(e){return ia(en(e))}function zt(e){return ia(en(gr(St(e)).reverse()))}function cn(e,t){if(oe(t),t===0)throw new RangeError("zero length");e=an(e);let r=e.toString(16);if(r.length>t*2)throw new RangeError("number too large");return dr(r.padStart(t*2,"0"))}function Go(e,t){return cn(e,t).reverse()}function aa(e,t){if(e=z(e),t=z(t),e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function gr(e){return Uint8Array.from(z(e))}function un(e){if(typeof e!="string")throw new TypeError("ascii string expected, got "+typeof e);return Uint8Array.from(e,(t,r)=>{let n=t.charCodeAt(0);if(t.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${e[r]}" with code ${n} at position ${r}`);return n})}var on=e=>typeof e=="bigint"&&sn<=e;function Nf(e,t,r){return on(e)&&on(t)&&on(r)&&t<=e&&e<r}function Ve(e,t,r,n){if(!Nf(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function He(e){if(e<sn)throw new Error("expected non-negative bigint, got "+e);let t;for(t=0;e>sn;e>>=Zo,t+=1);return t}var wr=e=>(Zo<<BigInt(e))-Zo;function ca(e,t,r){if(oe(e,"hashLen"),oe(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=p=>new Uint8Array(p),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(e),u=n(e),f=0,l=()=>{c.fill(1),u.fill(0),f=0},d=(...p)=>r(u,nt(c,...p)),h=(p=o)=>{u=d(s,p),c=d(),p.length!==0&&(u=d(i,p),c=d())},b=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let p=0,y=[];for(;p<t;){c=d();let v=c.slice();y.push(v),p+=c.length}return nt(...y)};return(p,y)=>{l(),h(p);let v;for(;(v=y(b()))===void 0;)h();return l(),v}}function Pt(e,t={},r={}){if(Object.prototype.toString.call(e)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,i,a){if(!a&&i!=="function"&&!Object.hasOwn(e,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let c=e[s];if(a&&c===void 0)return;let u=typeof c;if(u!==i||c===null)throw new TypeError(`param "${s}" is invalid: expected ${i}, got ${u}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(t,!1),o(r,!0)}var Xo=()=>{throw new Error("not implemented")};var ut=BigInt(0),X=BigInt(1),xe=BigInt(2),da=BigInt(3),ha=BigInt(4),pa=BigInt(5),Uf=BigInt(7),ma=BigInt(8),Ff=BigInt(9),ya=BigInt(16);function tt(e,t){if(t<=ut)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=ut?r:t+r}function j(e,t,r){if(t<ut)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >ut;)n*=n,n%=r;return n}function ua(e,t){if(e===ut)throw new Error("invert: expected non-zero number");if(t<=ut)throw new Error("invert: expected positive modulus, got "+t);let r=tt(e,t),n=t,o=ut,s=X,i=X,a=ut;for(;r!==ut;){let u=n/r,f=n-r*u,l=o-i*u,d=s-a*u;n=r,r=f,o=i,s=a,i=l,a=d}if(n!==X)throw new Error("invert: does not exist");return tt(o,t)}function Qo(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function ba(e,t){let r=e,n=(r.ORDER+X)/ha,o=r.pow(t,n);return Qo(r,o,t),o}function Mf(e,t){let r=e,n=(r.ORDER-pa)/ma,o=r.mul(t,xe),s=r.pow(o,n),i=r.mul(t,s),a=r.mul(r.mul(i,xe),s),c=r.mul(i,r.sub(a,r.ONE));return Qo(r,c,t),c}function qf(e){let t=$e(e),r=ga(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+Uf)/ya;return((a,c)=>{let u=a,f=u.pow(c,i),l=u.mul(f,n),d=u.mul(f,o),h=u.mul(f,s),b=u.eql(u.sqr(l),c),E=u.eql(u.sqr(d),c);f=u.cmov(f,l,b),l=u.cmov(h,d,E);let p=u.eql(u.sqr(l),c),y=u.cmov(f,l,p);return Qo(u,y,c),y})}function ga(e){if(e<da)throw new Error("sqrt is not defined for small field");let t=e-X,r=0;for(;t%xe===ut;)t/=xe,r++;let n=xe,o=$e(e);for(;fa(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return ba;let s=o.pow(n,t),i=(t+X)/xe;return function(c,u){let f=c;if(f.is0(u))return u;if(fa(f,u)!==1)throw new Error("Cannot find square root");let l=r,d=f.mul(f.ONE,s),h=f.pow(u,t),b=f.pow(u,i);for(;!f.eql(h,f.ONE);){if(f.is0(h))return f.ZERO;let E=1,p=f.sqr(h);for(;!f.eql(p,f.ONE);)if(E++,p=f.sqr(p),E===l)throw new Error("Cannot find square root");let y=X<<BigInt(l-E-1),v=f.pow(d,y);l=E,d=f.sqr(v),h=f.mul(h,d),b=f.mul(b,v)}return b}}function zf(e){return e%ha===da?ba:e%ma===pa?Mf:e%ya===Ff?qf(e):ga(e)}var Yt=(e,t)=>(tt(e,t)&X)===X,Vf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Jo(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=Vf.reduce((n,o)=>(n[o]="function",n),t);if(Pt(e,r),kt(e.BYTES,"BYTES"),kt(e.BITS,"BITS"),e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=X)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function Hf(e,t,r){let n=e;if(r<ut)throw new Error("invalid exponent, negatives unsupported");if(r===ut)return n.ONE;if(r===X)return t;let o=n.ONE,s=t;for(;r>ut;)r&X&&(o=n.mul(o,s)),s=n.sqr(s),r>>=X;return o}function xr(e,t,r=!1){let n=e,o=new Array(t.length).fill(r?n.ZERO:void 0),s=t.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return t.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),i),o}function fa(e,t){let r=e,n=(r.ORDER-X)/xe,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 $f(e,t){if(t!==void 0&&Yo(t),e<=ut)throw new Error("invalid n length: expected positive n, got "+e);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let r=He(e);if(t!==void 0&&t<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${t})`);let n=t!==void 0?t:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var la=new WeakMap,fn=class{ORDER;BITS;BYTES;isLE;ZERO=ut;ONE=X;_lengths;_mod;constructor(t,r={}){if(t<=X)throw new Error("invalid field: expected ORDER > 1, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=$f(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 tt(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return ut<=t&&t<this.ORDER}is0(t){return t===ut}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&X)===X}neg(t){return tt(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return tt(t*t,this.ORDER)}add(t,r){return tt(t+r,this.ORDER)}sub(t,r){return tt(t-r,this.ORDER)}mul(t,r){return tt(t*r,this.ORDER)}pow(t,r){return Hf(this,t,r)}div(t,r){return tt(t*ua(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 ua(t,this.ORDER)}sqrt(t){let r=la.get(this);return r||la.set(this,r=zf(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?Go(t,this.BYTES):cn(t,this.BYTES)}fromBytes(t,r=!1){z(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?zt(t):we(t);if(a&&(c=tt(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return xr(this,t)}cmov(t,r,n){return Ot(n,"condition"),n?r:t}};Object.freeze(fn.prototype);function $e(e,t={}){return new fn(e,t)}function wa(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=X)throw new Error("field order must be greater than 1");let t=He(e-X);return Math.ceil(t/8)}function ts(e){let t=wa(e);return t+Math.ceil(t/2)}function es(e,t,r=!1){z(e);let n=e.length,o=wa(t),s=Math.max(ts(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?zt(e):we(e),a=tt(i,t-X)+X;return r?Go(a,o):cn(a,o)}var We=BigInt(0),Ee=BigInt(1);function Er(e,t){let r=t.negate();return e?r:t}function ve(e,t){let r=xr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Sa(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function rs(e,t){Sa(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=wr(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function xa(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(e&o),c=e>>i;a>n&&(a-=s,c+=Ee);let u=t*n,f=u+Math.abs(a)-1,l=a===0,d=a<0,h=t%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:d,isNegF:h,offsetF:u}}var ns=new WeakMap,Aa=new WeakMap;function os(e){return Aa.get(e)||1}function Ea(e){if(e!==We)throw new Error("invalid wNAF")}var je=class{BASE;ZERO;Fn;bits;constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>We;)r&Ee&&(n=n.add(o)),o=o.double(),r>>=Ee;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=rs(r,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let u=1;u<o;u++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=rs(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:l,isNegF:d,offsetF:h}=xa(n,a,i);n=c,f?s=s.add(Er(d,r[h])):o=o.add(Er(l,r[u]))}return Ea(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=rs(t,this.bits);for(let i=0;i<s.windows&&n!==We;i++){let{nextN:a,offset:c,isZero:u,isNeg:f}=xa(n,i,s);if(n=a,!u){let l=r[c];o=o.add(f?l.negate():l)}}return Ea(n),o}getPrecomputes(t,r,n){let o=ns.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),ns.set(r,o))),o}cached(t,r,n){let o=os(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=os(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){Sa(r,this.bits),Aa.set(t,r),ns.delete(t)}hasCache(t){return os(t)!==1}};function _a(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>We||n>We;)r&Ee&&(s=s.add(o)),n&Ee&&(i=i.add(o)),o=o.double(),r>>=Ee,n>>=Ee;return{p1:s,p2:i}}function va(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Jo(t),t}else return $e(e,{isLE:r})}function ln(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let c of["p","n","h"]){let u=t[c];if(!(typeof u=="bigint"&&u>We))throw new Error(`CURVE.${c} must be positive bigint`)}let o=va(t.p,r.Fp,n),s=va(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 dn(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var ce=BigInt(0),it=BigInt(1),ss=BigInt(2),Wf=BigInt(8);function jf(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 Ta(e,t={}){let r=t,n=ln("edwards",e,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;Pt(r,{},{uvRatio:"function"});let c=ss<<BigInt(s.BYTES*8)-it,u=E=>o.create(E),f=r.uvRatio===void 0?(E,p)=>{try{return{isValid:!0,value:o.sqrt(o.div(E,p))}}catch{return{isValid:!1,value:ce}}}:r.uvRatio;if(!jf(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function l(E,p,y=!1){let v=y?it:ce;return Ve("coordinate "+E,p,v,c),p}function d(E){if(!(E instanceof h))throw new Error("EdwardsPoint expected")}class h{static BASE=new h(i.Gx,i.Gy,it,u(i.Gx*i.Gy));static ZERO=new h(ce,it,it,ce);static Fp=o;static Fn=s;X;Y;Z;T;constructor(p,y,v,_){this.X=l("x",p),this.Y=l("y",y),this.Z=l("z",v,!0),this.T=l("t",_),Object.freeze(this)}static CURVE(){return i}static fromAffine(p){if(p instanceof h)throw new Error("extended point not allowed");let{x:y,y:v}=p||{};return l("x",y),l("y",v),new h(y,v,it,u(y*v))}static fromBytes(p,y=!1){let v=o.BYTES,{a:_,d:L}=i;p=gr(z(p,v,"point")),Ot(y,"zip215");let R=gr(p),P=p[v-1];R[v-1]=P&-129;let D=zt(R),T=y?c:o.ORDER;Ve("point.y",D,ce,T);let K=u(D*D),N=u(K-it),k=u(L*K-_),{isValid:m,value:g}=f(N,k);if(!m)throw new Error("bad point: invalid y coordinate");let S=(g&it)===it,x=(P&128)!==0;if(!y&&g===ce&&x)throw new Error("bad point: x=0 and x_0=1");return x!==S&&(g=u(-g)),h.fromAffine({x:g,y:D})}static fromHex(p,y=!1){return h.fromBytes(ze(p),y)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=8,y=!0){return b.createCache(this,p),y||this.multiply(ss),this}assertValidity(){let p=this,{a:y,d:v}=i;if(p.is0())throw new Error("bad point: ZERO");let{X:_,Y:L,Z:R,T:P}=p,D=u(_*_),T=u(L*L),K=u(R*R),N=u(K*K),k=u(D*y),m=u(K*u(k+T)),g=u(N+u(v*u(D*T)));if(m!==g)throw new Error("bad point: equation left != right (1)");let S=u(_*L),x=u(R*P);if(S!==x)throw new Error("bad point: equation left != right (2)")}equals(p){d(p);let{X:y,Y:v,Z:_}=this,{X:L,Y:R,Z:P}=p,D=u(y*P),T=u(L*_),K=u(v*P),N=u(R*_);return D===T&&K===N}is0(){return this.equals(h.ZERO)}negate(){return new h(u(-this.X),this.Y,this.Z,u(-this.T))}double(){let{a:p}=i,{X:y,Y:v,Z:_}=this,L=u(y*y),R=u(v*v),P=u(ss*u(_*_)),D=u(p*L),T=y+v,K=u(u(T*T)-L-R),N=D+R,k=N-P,m=D-R,g=u(K*k),S=u(N*m),x=u(K*m),w=u(k*N);return new h(g,S,w,x)}add(p){d(p);let{a:y,d:v}=i,{X:_,Y:L,Z:R,T:P}=this,{X:D,Y:T,Z:K,T:N}=p,k=u(_*D),m=u(L*T),g=u(P*v*N),S=u(R*K),x=u((_+L)*(D+T)-k-m),w=S-g,A=S+g,B=u(m-y*k),I=u(x*w),C=u(A*B),O=u(x*B),F=u(w*A);return new h(I,C,F,O)}subtract(p){return d(p),this.add(p.negate())}multiply(p){if(!s.isValidNot0(p))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:y,f:v}=b.cached(this,p,_=>ve(h,_));return ve(h,[y,v])[0]}multiplyUnsafe(p){if(!s.isValid(p))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return p===ce?h.ZERO:this.is0()||p===it?this:b.unsafe(this,p,y=>ve(h,y))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return b.unsafe(this,i.n).is0()}toAffine(p){let y=this,v=p,{X:_,Y:L,Z:R}=y,P=y.is0();v==null&&(v=P?Wf:o.inv(R));let D=u(_*v),T=u(L*v),K=o.mul(R,v);if(P)return{x:ce,y:it};if(K!==it)throw new Error("invZ was invalid");return{x:D,y:T}}clearCofactor(){return a===it?this:this.multiplyUnsafe(a)}toBytes(){let{x:p,y}=this.toAffine(),v=o.toBytes(y);return v[v.length-1]|=p&it?128:0,v}toHex(){return qe(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let b=new je(h,s.BITS);return s.BITS>=8&&h.BASE.precompute(8),Object.freeze(h.prototype),Object.freeze(h),h}var hn=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(t){this.ep=t}static fromBytes(t){Xo()}static fromHex(t){Xo()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return qe(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.ep.precompute(t,r),this}};function Ia(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=r;Pt(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=e,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(kt(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=o.randomBytes===void 0?yr:o.randomBytes,d=o.adjustScalarBytes===void 0?m=>m:o.adjustScalarBytes,h=o.domain===void 0?(m,g,S)=>{if(Ot(S,"phflag"),g.length||S)throw new Error("Contexts/pre-hash are not supported");return m}:o.domain;function b(m){return c.create(zt(m))}function E(m){let g=D.secretKey;z(m,D.secretKey,"secretKey");let S=z(n(m),2*g,"hashedSecretKey"),x=d(S.slice(0,g)),w=S.slice(g,2*g),A=b(x);return{head:x,prefix:w,scalar:A}}function p(m){let{head:g,prefix:S,scalar:x}=E(m),w=i.multiply(x),A=w.toBytes();return{head:g,prefix:S,scalar:x,point:w,pointBytes:A}}function y(m){return p(m).pointBytes}function v(m=Uint8Array.of(),...g){let S=nt(...g);return b(n(h(S,z(m,void 0,"context"),!!s)))}function _(m,g,S={}){m=z(m,void 0,"message"),s&&(m=s(m));let{prefix:x,scalar:w,pointBytes:A}=p(g),B=v(S.context,x,m),I=i.multiply(B).toBytes(),C=v(S.context,I,A,m),O=c.create(B+C*w);if(!c.isValid(O))throw new Error("sign failed: invalid s");let F=nt(I,c.toBytes(O));return z(F,D.signature,"result")}let L={zip215:o.zip215};function R(m,g,S,x=L){let{context:w}=x,A=x.zip215===void 0?!!L.zip215:x.zip215,B=D.signature;m=z(m,B,"signature"),g=z(g,void 0,"message"),S=z(S,D.publicKey,"publicKey"),A!==void 0&&Ot(A,"zip215"),s&&(g=s(g));let I=B/2,C=m.subarray(0,I),O=zt(m.subarray(I,B)),F,V,U;try{F=e.fromBytes(S,A),V=e.fromBytes(C,A),U=i.multiplyUnsafe(O)}catch{return!1}if(!A&&F.isSmallOrder())return!1;let rt=v(w,C,S,g);return V.add(F.multiplyUnsafe(rt)).subtract(U).clearCofactor().is0()}let P=a.BYTES,D={secretKey:P,publicKey:P,signature:2*P,seed:P};function T(m){return m=m===void 0?l(D.seed):m,z(m,D.seed,"seed")}function K(m){return ge(m)&&m.length===D.secretKey}function N(m,g){try{return!!e.fromBytes(m,g===void 0?L.zip215:g)}catch{return!1}}let k={getExtendedPublicKey:p,randomSecretKey:T,isValidSecretKey:K,isValidPublicKey:N,toMontgomery(m){let{y:g}=e.fromBytes(m),S=D.publicKey,x=S===32;if(!x&&S!==57)throw new Error("only defined for 25519 and 448");let w=x?a.div(it+g,it-g):a.div(g-it,g+it);return a.toBytes(w)},toMontgomerySecret(m){let g=D.secretKey;z(m,g);let S=n(m.subarray(0,g));return d(S).subarray(0,g)}};return Object.freeze(D),Object.freeze(k),Object.freeze({keygen:dn(T,y),getPublicKey:y,sign:_,verify:R,utils:k,Point:e,lengths:D})}function vr(e,t){if(kt(e),kt(t),t<0||t>4)throw new Error("invalid I2OSP length: "+t);if(e<0||e>2**(8*t)-1)throw new Error("invalid I2OSP input: "+e);let r=Array.from({length:t}).fill(0);for(let n=t-1;n>=0;n--)r[n]=e&255,e>>>=8;return new Uint8Array(r)}function Zf(e,t){let r=new Uint8Array(e.length);for(let n=0;n<e.length;n++)r[n]=e[n]^t[n];return r}function Yf(e){if(!ge(e)&&typeof e!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof e=="string"?un(e):e;if(t.length===0)throw new Error("DST must be non-empty");return t}function is(e,t,r,n){z(e),kt(r),t=Yf(t),t.length>255&&(t=n(nt(un("H2C-OVERSIZE-DST-"),t)));let{outputLen:o,blockLen:s}=n,i=Math.ceil(r/o);if(r>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=nt(t,vr(t.length,1)),c=new Uint8Array(s),u=vr(r,2),f=new Array(i),l=n(nt(c,e,u,vr(0,1),a));f[0]=n(nt(l,vr(1,1),a));for(let h=1;h<i;h++){let b=[Zf(l,f[h-1]),vr(h+1,1),a];f[h]=n(nt(...b))}return nt(...f).slice(0,r)}var Ba="HashToScalar-";var Gf=BigInt(0),Gt=BigInt(1),Ra=BigInt(2);var Xf=BigInt(5),Qf=BigInt(8),Ze=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),fs={p:Ze,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Qf,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Jf(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Ze,a=e*e%s*e%s,c=j(a,Ra,s)*a%s,u=j(c,Gt,s)*e%s,f=j(u,Xf,s)*u%s,l=j(f,t,s)*f%s,d=j(l,r,s)*l%s,h=j(d,n,s)*d%s,b=j(h,o,s)*h%s,E=j(b,o,s)*h%s,p=j(E,t,s)*f%s;return{pow_p_5_8:j(p,Ra,s)*e%s,b2:a}}function tl(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var as=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function ls(e,t){let r=Ze,n=tt(t*t*t,r),o=tt(n*n*t,r),s=Jf(e*o).pow_p_5_8,i=tt(e*n*s,r),a=tt(t*i*i,r),c=i,u=tt(i*as,r),f=a===e,l=a===tt(-e,r),d=a===tt(-e*as,r);return f&&(i=c),(l||d)&&(i=u),Yt(i,r)&&(i=tt(-i,r)),{isValid:f||l,value:i}}var fe=Ta(fs,{uvRatio:ls}),ue=fe.Fp,Da=fe.Fn;function el(e){return Ia(fe,nn,Object.assign({adjustScalarBytes:tl,zip215:!0},e))}var Oa=el({});var cs=as,rl=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),nl=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),ol=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),sl=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Ca=e=>ls(Gt,e),il=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),us=e=>ue.create(zt(e)&il);function La(e){let{d:t}=fs,r=Ze,n=y=>ue.create(y),o=n(cs*e*e),s=n((o+Gt)*ol),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:c,value:u}=ls(s,a),f=n(u*e);Yt(f,r)||(f=n(-f)),c||(u=f),c||(i=o);let l=n(i*(o-Gt)*sl-a),d=u*u,h=n((u+u)*a),b=n(l*rl),E=n(Gt-d),p=n(Gt+d);return new fe(n(h*p),n(E*b),n(b*p),n(h*E))}var le=class e extends hn{static BASE=new e(fe.BASE);static ZERO=new e(fe.ZERO);static Fp=ue;static Fn=Da;constructor(t){super(t)}static fromAffine(t){return new e(fe.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static fromBytes(t){St(t,32);let{a:r,d:n}=fs,o=Ze,s=L=>ue.create(L),i=us(t);if(!aa(ue.toBytes(i),t)||Yt(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(Gt+r*a),u=s(Gt-r*a),f=s(c*c),l=s(u*u),d=s(r*n*f-l),{isValid:h,value:b}=Ca(s(d*l)),E=s(b*u),p=s(b*E*d),y=s((i+i)*E);Yt(y,o)&&(y=s(-y));let v=s(c*p),_=s(y*v);if(!h||Yt(_,o)||v===Gf)throw new Error("invalid ristretto255 encoding 2");return new e(new fe(y,v,Gt,_))}static fromHex(t){return e.fromBytes(dr(t))}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=Ze,i=p=>ue.create(p),a=i(i(n+r)*i(n-r)),c=i(t*r),u=i(c*c),{value:f}=Ca(i(a*u)),l=i(f*a),d=i(f*c),h=i(l*d*o),b;if(Yt(o*h,s)){let p=i(r*cs),y=i(t*cs);t=p,r=y,b=i(l*nl)}else b=d;Yt(t*h,s)&&(r=i(-r));let E=i((n-r)*b);return Yt(E,s)&&(E=i(-E)),ue.toBytes(E)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=u=>ue.create(u),a=i(r*s)===i(n*o),c=i(n*s)===i(r*o);return a||c}is0(){return this.equals(e.ZERO)}};Object.freeze(le.BASE);Object.freeze(le.ZERO);Object.freeze(le.prototype);Object.freeze(le);var al=Object.freeze({Point:le,hashToCurve(e,t){let r=t?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":t.DST,n=is(e,r,64,nn);return al.deriveToCurve(n)},hashToScalar(e,t={DST:Ba}){let r=is(e,t.DST,64,nn);return Da.create(zt(r))},deriveToCurve(e){St(e,64);let t=us(e.subarray(0,32)),r=La(t),n=us(e.subarray(32,64)),o=La(n);return new le(r.add(o))}});var Sr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},pn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Bt={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new pn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var mn=32;var ds,cl=(async()=>{try{return await Bt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function ul(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Bt.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Bt.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 fl(e,t,r){return Oa.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function ka(e,t,r){return ds==null&&(ds=await cl),ds?ul(e,t,r):fl(e,t,r)}function yn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var bn=class{type="Ed25519";raw;constructor(t){this.raw=hs(t,mn)}toMultihash(){return Lt.digest(It(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=ka(this.raw,r,t);return yn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function ps(e){return e=hs(e,mn),new bn(e)}function hs(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new M(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var dl=Math.pow(2,7),hl=Math.pow(2,14),pl=Math.pow(2,21),ms=Math.pow(2,28),ys=Math.pow(2,35),bs=Math.pow(2,42),gs=Math.pow(2,49),$=128,dt=127;function Rt(e){if(e<dl)return 1;if(e<hl)return 2;if(e<pl)return 3;if(e<ms)return 4;if(e<ys)return 5;if(e<bs)return 6;if(e<gs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ye(e,t,r=0){switch(Rt(e)){case 8:t[r++]=e&255|$,e/=128;case 7:t[r++]=e&255|$,e/=128;case 6:t[r++]=e&255|$,e/=128;case 5:t[r++]=e&255|$,e/=128;case 4:t[r++]=e&255|$,e>>>=7;case 3:t[r++]=e&255|$,e>>>=7;case 2:t[r++]=e&255|$,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function ml(e,t,r=0){switch(Rt(e)){case 8:t.set(r++,e&255|$),e/=128;case 7:t.set(r++,e&255|$),e/=128;case 6:t.set(r++,e&255|$),e/=128;case 5:t.set(r++,e&255|$),e/=128;case 4:t.set(r++,e&255|$),e>>>=7;case 3:t.set(r++,e&255|$),e>>>=7;case 2:t.set(r++,e&255|$),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function ws(e,t){let r=e[t],n=0;if(n+=r&dt,r<$||(r=e[t+1],n+=(r&dt)<<7,r<$)||(r=e[t+2],n+=(r&dt)<<14,r<$)||(r=e[t+3],n+=(r&dt)<<21,r<$)||(r=e[t+4],n+=(r&dt)*ms,r<$)||(r=e[t+5],n+=(r&dt)*ys,r<$)||(r=e[t+6],n+=(r&dt)*bs,r<$)||(r=e[t+7],n+=(r&dt)*gs,r<$))return n;throw new RangeError("Could not decode varint")}function yl(e,t){let r=e.get(t),n=0;if(n+=r&dt,r<$||(r=e.get(t+1),n+=(r&dt)<<7,r<$)||(r=e.get(t+2),n+=(r&dt)<<14,r<$)||(r=e.get(t+3),n+=(r&dt)<<21,r<$)||(r=e.get(t+4),n+=(r&dt)*ms,r<$)||(r=e.get(t+5),n+=(r&dt)*ys,r<$)||(r=e.get(t+6),n+=(r&dt)*bs,r<$)||(r=e.get(t+7),n+=(r&dt)*gs,r<$))return n;throw new RangeError("Could not decode varint")}function gn(e,t,r=0){return t==null&&(t=lt(Rt(e))),t instanceof Uint8Array?Ye(e,t,r):ml(e,t,r)}function xs(e,t=0){return e instanceof Uint8Array?ws(e,t):yl(e,t)}var Es=new Float32Array([-0]),de=new Uint8Array(Es.buffer);function Na(e,t,r){Es[0]=e,t[r]=de[0],t[r+1]=de[1],t[r+2]=de[2],t[r+3]=de[3]}function Ua(e,t){return de[0]=e[t],de[1]=e[t+1],de[2]=e[t+2],de[3]=e[t+3],Es[0]}var vs=new Float64Array([-0]),ht=new Uint8Array(vs.buffer);function Fa(e,t,r){vs[0]=e,t[r]=ht[0],t[r+1]=ht[1],t[r+2]=ht[2],t[r+3]=ht[3],t[r+4]=ht[4],t[r+5]=ht[5],t[r+6]=ht[6],t[r+7]=ht[7]}function Ma(e,t){return ht[0]=e[t],ht[1]=e[t+1],ht[2]=e[t+2],ht[3]=e[t+3],ht[4]=e[t+4],ht[5]=e[t+5],ht[6]=e[t+6],ht[7]=e[t+7],vs[0]}var bl=BigInt(Number.MAX_SAFE_INTEGER),gl=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 Se;if(t<bl&&t>gl)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>qa&&(o=0n,++n>qa&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return Se;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):Se}},Se=new At(0,0);Se.toBigInt=function(){return 0n};Se.zzEncode=Se.zzDecode=function(){return this};Se.length=function(){return 1};var qa=4294967296n;function za(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 Va(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 Ss(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Kt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function wn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var As=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,Kt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Kt(this,4);return wn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Kt(this,4);return wn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Kt(this,4);let t=Ua(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Kt(this,4);let t=Ma(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Kt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Va(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Kt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Kt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new 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 Kt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Kt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Kt(this,8);let t=wn(this.buf,this.pos+=4),r=wn(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=ws(this.buf,this.pos);return this.pos+=Rt(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 Ar(e){return new As(e instanceof Uint8Array?e:e.subarray())}function yt(e,t,r){let n=Ar(e);return t.decode(n,void 0,r)}function _s(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return lt(i);o+i>t&&(n=lt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Ae=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Ts(){}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}},wl=_s();function xl(e){return globalThis.Buffer!=null?lt(e):wl(e)}var Tr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ae(Ts,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new Ae(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Rs((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(xn,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(xn,r.length(),r)}uint64Number(t){return this._push(Ye,Rt(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(xn,r.length(),r)}sint64Number(t){let r=At.fromNumber(t).zzEncode();return this._push(xn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Is,1,t?1:0)}fixed32(t){return this._push(_r,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=At.fromBigInt(t);return this._push(_r,4,r.lo)._push(_r,4,r.hi)}fixed64Number(t){let r=At.fromNumber(t);return this._push(_r,4,r.lo)._push(_r,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(Na,4,t)}double(t){return this._push(Fa,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Is,1,0):this.uint32(r)._push(vl,r,t)}string(t){let r=za(t);return r!==0?this.uint32(r)._push(Ss,r,t):this._push(Is,1,0)}fork(){return this.states=new Bs(this),this.head=this.tail=new Ae(Ts,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 Ae(Ts,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=xl(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Is(e,t,r){t[r]=e&255}function El(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Rs=class extends Ae{next;constructor(t,r){super(El,t,r),this.next=void 0}};function xn(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 _r(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 vl(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Tr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Sl,t,e),this},Tr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Al,t,e),this});function Sl(e,t,r){t.set(e,r)}function Al(e,t,r){e.length<40?Ss(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(H(e),r)}function Cs(){return new Tr}function bt(e,t){let r=Cs();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*gt(e,t,r){let n=Ar(e);yield*t.stream(n,void 0,"$",r)}var En={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function vn(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function Ls(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 vn("enum",En.VARINT,r,n,o)}function wt(e,t,r){return vn("message",En.LENGTH_DELIMITED,e,t,r)}var Ct=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},Ir=class extends Error{code="ERR_MAX_SIZE";name="MaxSizeError"};var Z;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(Z||(Z={}));var Ds;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Ds||(Ds={}));(function(e){e.codec=()=>Ls(Ds)})(Z||(Z={}));var Vt;(function(e){let t;e.codec=()=>(t==null&&(t=wt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),Z.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=Z.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:Z.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return 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})(Vt||(Vt={}));var Os;(function(e){let t;e.codec=()=>(t==null&&(t=wt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),Z.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=Z.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:Z.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return 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})(Os||(Os={}));var Rr={};Et(Rr,{MAX_RSA_KEY_SIZE:()=>ks,generateRSAKeyPair:()=>Ya,jwkToJWKKeyPair:()=>Ga,jwkToPkcs1:()=>Bl,jwkToPkix:()=>Us,jwkToRSAPrivateKey:()=>zs,pkcs1MessageToJwk:()=>Ks,pkcs1MessageToRSAPrivateKey:()=>Fs,pkcs1ToJwk:()=>Il,pkcs1ToRSAPrivateKey:()=>Za,pkixMessageToJwk:()=>Ns,pkixMessageToRSAPublicKey:()=>qs,pkixToJwk:()=>Rl,pkixToRSAPublicKey:()=>Ms});var Ge=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Rr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return et.createV1(114,this._multihash)}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}verify(t,r,n){return ja(this.jwk,r,t,n)}},Br=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Rr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}sign(t,r){return Wa(this.jwk,t,r)}};var ks=8192,Ps=18,_l=1062,Tl=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Il(e){let t=$t(e);return Ks(t)}function Ks(e){return{n:q(e[1],"base64url"),e:q(e[2],"base64url"),d:q(e[3],"base64url"),p:q(e[4],"base64url"),q:q(e[5],"base64url"),dp:q(e[6],"base64url"),dq:q(e[7],"base64url"),qi:q(e[8],"base64url"),kty:"RSA"}}function Bl(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 M("JWK was missing components");return ne([vt(Uint8Array.from([0])),vt(H(e.n,"base64url")),vt(H(e.e,"base64url")),vt(H(e.d,"base64url")),vt(H(e.p,"base64url")),vt(H(e.q,"base64url")),vt(H(e.dp,"base64url")),vt(H(e.dq,"base64url")),vt(H(e.qi,"base64url"))]).subarray()}function Rl(e){let t=$t(e,{offset:0});return Ns(t)}function Ns(e){let t=$t(e[1],{offset:0});return{kty:"RSA",n:q(t[0],"base64url"),e:q(t[1],"base64url")}}function Us(e){if(e.n==null||e.e==null)throw new M("JWK was missing components");return ne([Tl,Xr(ne([vt(H(e.n,"base64url")),vt(H(e.e,"base64url"))]))]).subarray()}function Za(e){let t=$t(e);return Fs(t)}function Fs(e){let t=Ks(e);return zs(t)}function Ms(e,t){if(e.byteLength>=_l)throw new Ce("Key size is too large");let r=$t(e,{offset:0});return qs(r,e,t)}function qs(e,t,r){let n=Ns(e);if(r==null){let o=Me(Vt.encode({Type:Z.RSA,Data:t}));r=Ft(Ps,o)}return new Ge(n,r)}function zs(e){if(Qa(e)>ks)throw new M("Key size is too large");let t=Ga(e),r=Me(Vt.encode({Type:Z.RSA,Data:Us(t.publicKey)})),n=Ft(Ps,r);return new Br(t.privateKey,new Ge(t.publicKey,n))}async function Ya(e){if(e>ks)throw new M("Key size is too large");let t=await Xa(e),r=Me(Vt.encode({Type:Z.RSA,Data:Us(t.publicKey)})),n=Ft(Ps,r);return new Br(t.privateKey,new Ge(t.publicKey,n))}function Ga(e){if(e==null)throw new M("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function Xa(e,t){let r=await Bt.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 Cl(r,t);return{privateKey:n[0],publicKey:n[1]}}async function Wa(e,t,r){let n=await Bt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Bt.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 ja(e,t,r,n){let o=await Bt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Bt.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 Cl(e,t){if(e.privateKey==null||e.publicKey==null)throw new M("Private and public key are required");let r=await Promise.all([Bt.get().subtle.exportKey("jwk",e.privateKey),Bt.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function Qa(e){if(e.kty!=="RSA")throw new M("invalid key type");if(e.n==null)throw new M("invalid key modulus");return H(e.n,"base64url").length*8}var Sn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(Qr(t),St(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),jt(o)}update(t){return Fe(this),this.iHash.update(t),this}digestInto(t){Fe(this),Jr(t,this),this.finished=!0;let r=t.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ja=(()=>{let e=((t,r,n)=>new Sn(t,r).update(n).digest());return e.create=(t,r)=>new Sn(t,r),e})();var tc=(e,t)=>(e+(e>=0?t:-t)/ec)/t;function Ll(e,t,r){Ve("scalar",e,Ht,r);let[[n,o],[s,i]]=t,a=tc(i*e,r),c=tc(-o*e,r),u=e-a*n-c*s,f=-a*o-c*i,l=u<Ht,d=f<Ht;l&&(u=-u),d&&(f=-f);let h=wr(Math.ceil(He(r)/2))+he;if(u<Ht||u>=h||f<Ht||f>=h)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:d,k2:f}}function Hs(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Vs(e,t){Pt(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return Ot(r.lowS,"lowS"),Ot(r.prehash,"prehash"),r.format!==void 0&&Hs(r.format),r}var $s=class extends Error{constructor(t=""){super(t)}},Nt={Err:$s,_tlv:{encode:(e,t)=>{let{Err:r}=Nt;if(kt(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(typeof t!="string")throw new TypeError('"data" expected string, got type='+typeof t);if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=br(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?br(o.length/2|128):"";return br(e)+s+o+t},decode(e,t){let{Err:r}=Nt;t=z(t,void 0,"DER data");let n=0;if(e<0||e>255)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Nt;if(an(e),e<Ht)throw new t("integer: negative integers are not allowed");let r=br(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}=Nt;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 we(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Nt,o=z(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}=Nt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}};Object.freeze(Nt._tlv);Object.freeze(Nt._int);Object.freeze(Nt);var Ht=BigInt(0),he=BigInt(1),ec=BigInt(2),An=BigInt(3),Dl=BigInt(4);function rc(e,t={}){let r=ln("weierstrass",e,t),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;Pt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c,allowInfinityPoint:u}=t;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=oc(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function d(k,m,g){if(u&&m.is0())return Uint8Array.of(0);let{x:S,y:x}=m.toAffine(),w=n.toBytes(S);if(Ot(g,"isCompressed"),g){l();let A=!n.isOdd(x);return nt(nc(A),w)}else return nt(Uint8Array.of(4),w,n.toBytes(x))}function h(k){z(k,void 0,"Point");let{publicKey:m,publicKeyUncompressed:g}=f,S=k.length,x=k[0],w=k.subarray(1);if(u&&S===1&&x===0)return{x:n.ZERO,y:n.ZERO};if(S===m&&(x===2||x===3)){let A=n.fromBytes(w);if(!n.isValid(A))throw new Error("bad point: is not on curve, wrong x");let B=p(A),I;try{I=n.sqrt(B)}catch(F){let V=F instanceof Error?": "+F.message:"";throw new Error("bad point: is not on curve, sqrt error"+V)}l();let C=n.isOdd(I);return(x&1)===1!==C&&(I=n.neg(I)),{x:A,y:I}}else if(S===g&&x===4){let A=n.BYTES,B=n.fromBytes(w.subarray(0,A)),I=n.fromBytes(w.subarray(A,A*2));if(!y(B,I))throw new Error("bad point: is not on curve");return{x:B,y:I}}else throw new Error(`bad point: got length ${S}, expected compressed=${m} or uncompressed=${g}`)}let b=t.toBytes===void 0?d:t.toBytes,E=t.fromBytes===void 0?h:t.fromBytes;function p(k){let m=n.sqr(k),g=n.mul(m,k);return n.add(n.add(g,n.mul(k,s.a)),s.b)}function y(k,m){let g=n.sqr(m),S=p(k);return n.eql(g,S)}if(!y(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let v=n.mul(n.pow(s.a,An),Dl),_=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(v,_)))throw new Error("bad curve params: a or b");function L(k,m,g=!1){if(!n.isValid(m)||g&&n.is0(m))throw new Error(`bad point coordinate ${k}`);return m}function R(k){if(!(k instanceof T))throw new Error("Weierstrass Point expected")}function P(k){if(!c||!c.basises)throw new Error("no endo");return Ll(k,c.basises,o.ORDER)}function D(k,m,g,S,x){return g=new T(n.mul(g.X,k),g.Y,g.Z),m=Er(S,m),g=Er(x,g),m.add(g)}class T{static BASE=new T(s.Gx,s.Gy,n.ONE);static ZERO=new T(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(m,g,S){this.X=L("x",m),this.Y=L("y",g,!0),this.Z=L("z",S),Object.freeze(this)}static CURVE(){return s}static fromAffine(m){let{x:g,y:S}=m||{};if(!m||!n.isValid(g)||!n.isValid(S))throw new Error("invalid affine point");if(m instanceof T)throw new Error("projective point not allowed");return n.is0(g)&&n.is0(S)?T.ZERO:new T(g,S,n.ONE)}static fromBytes(m){let g=T.fromAffine(E(z(m,void 0,"point")));return g.assertValidity(),g}static fromHex(m){return T.fromBytes(ze(m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,g=!0){return N.createCache(this,m),g||this.multiply(An),this}assertValidity(){let m=this;if(m.is0()){if(t.allowInfinityPoint&&n.is0(m.X)&&n.eql(m.Y,n.ONE)&&n.is0(m.Z))return;throw new Error("bad point: ZERO")}let{x:g,y:S}=m.toAffine();if(!n.isValid(g)||!n.isValid(S))throw new Error("bad point: x or y not field elements");if(!y(g,S))throw new Error("bad point: equation left != right");if(!m.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:m}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(m)}equals(m){R(m);let{X:g,Y:S,Z:x}=this,{X:w,Y:A,Z:B}=m,I=n.eql(n.mul(g,B),n.mul(w,x)),C=n.eql(n.mul(S,B),n.mul(A,x));return I&&C}negate(){return new T(this.X,n.neg(this.Y),this.Z)}double(){let{a:m,b:g}=s,S=n.mul(g,An),{X:x,Y:w,Z:A}=this,B=n.ZERO,I=n.ZERO,C=n.ZERO,O=n.mul(x,x),F=n.mul(w,w),V=n.mul(A,A),U=n.mul(x,w);return U=n.add(U,U),C=n.mul(x,A),C=n.add(C,C),B=n.mul(m,C),I=n.mul(S,V),I=n.add(B,I),B=n.sub(F,I),I=n.add(F,I),I=n.mul(B,I),B=n.mul(U,B),C=n.mul(S,C),V=n.mul(m,V),U=n.sub(O,V),U=n.mul(m,U),U=n.add(U,C),C=n.add(O,O),O=n.add(C,O),O=n.add(O,V),O=n.mul(O,U),I=n.add(I,O),V=n.mul(w,A),V=n.add(V,V),O=n.mul(V,U),B=n.sub(B,O),C=n.mul(V,F),C=n.add(C,C),C=n.add(C,C),new T(B,I,C)}add(m){R(m);let{X:g,Y:S,Z:x}=this,{X:w,Y:A,Z:B}=m,I=n.ZERO,C=n.ZERO,O=n.ZERO,F=s.a,V=n.mul(s.b,An),U=n.mul(g,w),rt=n.mul(S,A),ot=n.mul(x,B),st=n.add(g,S),Q=n.add(w,A);st=n.mul(st,Q),Q=n.add(U,rt),st=n.sub(st,Q),Q=n.add(g,x);let xt=n.add(w,B);return Q=n.mul(Q,xt),xt=n.add(U,ot),Q=n.sub(Q,xt),xt=n.add(S,x),I=n.add(A,B),xt=n.mul(xt,I),I=n.add(rt,ot),xt=n.sub(xt,I),O=n.mul(F,Q),I=n.mul(V,ot),O=n.add(I,O),I=n.sub(rt,O),O=n.add(rt,O),C=n.mul(I,O),rt=n.add(U,U),rt=n.add(rt,U),ot=n.mul(F,ot),Q=n.mul(V,Q),rt=n.add(rt,ot),ot=n.sub(U,ot),ot=n.mul(F,ot),Q=n.add(Q,ot),U=n.mul(rt,Q),C=n.add(C,U),U=n.mul(xt,Q),I=n.mul(st,I),I=n.sub(I,U),U=n.mul(st,rt),O=n.mul(xt,O),O=n.add(O,U),new T(I,C,O)}subtract(m){return R(m),this.add(m.negate())}is0(){return this.equals(T.ZERO)}multiply(m){let{endo:g}=t;if(!o.isValidNot0(m))throw new RangeError("invalid scalar: out of range");let S,x,w=A=>N.cached(this,A,B=>ve(T,B));if(g){let{k1neg:A,k1:B,k2neg:I,k2:C}=P(m),{p:O,f:F}=w(B),{p:V,f:U}=w(C);x=F.add(U),S=D(g.beta,O,V,A,I)}else{let{p:A,f:B}=w(m);S=A,x=B}return ve(T,[S,x])[0]}multiplyUnsafe(m){let{endo:g}=t,S=this,x=m;if(!o.isValid(x))throw new RangeError("invalid scalar: out of range");if(x===Ht||S.is0())return T.ZERO;if(x===he)return S;if(N.hasCache(this))return this.multiply(x);if(g){let{k1neg:w,k1:A,k2neg:B,k2:I}=P(x),{p1:C,p2:O}=_a(T,S,A,I);return D(g.beta,C,O,w,B)}else return N.unsafe(S,x)}toAffine(m){let g=this,S=m,{X:x,Y:w,Z:A}=g;if(n.eql(A,n.ONE))return{x,y:w};let B=g.is0();S==null&&(S=B?n.ONE:n.inv(A));let I=n.mul(x,S),C=n.mul(w,S),O=n.mul(A,S);if(B)return{x:n.ZERO,y:n.ZERO};if(!n.eql(O,n.ONE))throw new Error("invZ was invalid");return{x:I,y:C}}isTorsionFree(){let{isTorsionFree:m}=t;return i===he?!0:m?m(T,this):N.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:m}=t;return i===he?this:m?m(T,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===he?this.is0():this.clearCofactor().is0()}toBytes(m=!0){return Ot(m,"isCompressed"),this.assertValidity(),b(T,this,m)}toHex(m=!0){return qe(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let K=o.BITS,N=new je(T,t.endo?Math.ceil(K/2):K);return K>=8&&T.BASE.precompute(8),Object.freeze(T.prototype),Object.freeze(T),T}function nc(e){return Uint8Array.of(e?2:3)}function oc(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Ol(e,t={}){let{Fn:r}=e,n=t.randomBytes===void 0?yr:t.randomBytes,o=Object.assign(oc(e.Fp,r),{seed:Math.max(ts(r.ORDER),16)});function s(h){try{let b=r.fromBytes(h);return r.isValidNot0(b)}catch{return!1}}function i(h,b){let{publicKey:E,publicKeyUncompressed:p}=o;try{let y=h.length;return b===!0&&y!==E||b===!1&&y!==p?!1:!!e.fromBytes(h)}catch{return!1}}function a(h){return h=h===void 0?n(o.seed):h,es(z(h,o.seed,"seed"),r.ORDER)}function c(h,b=!0){return e.BASE.multiply(r.fromBytes(h)).toBytes(b)}function u(h){let{secretKey:b,publicKey:E,publicKeyUncompressed:p}=o,y=r._lengths;if(!ge(h))return;let v=z(h,void 0,"key").length,_=v===E||v===p,L=v===b||!!y?.includes(v);if(!(_&&L))return _}function f(h,b,E=!0){if(u(h)===!0)throw new Error("first arg must be private key");if(u(b)===!1)throw new Error("second arg must be public key");let p=r.fromBytes(h);return e.fromBytes(b).multiply(p).toBytes(E)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},d=dn(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:d,Point:e,utils:l,lengths:o})}function sc(e,t,r={}){let n=t;Qr(n),Pt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?yr:r.randomBytes,s=r.hmac===void 0?(x,w)=>Ja(n,x,w):r.hmac,{Fp:i,Fn:a}=e,{ORDER:c,BITS:u}=a,{keygen:f,getPublicKey:l,getSharedSecret:d,utils:h,lengths:b}=Ol(e,r),E={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},p=c*ec+he<i.ORDER;function y(x){let w=c>>he;return x>w}function v(x,w){if(!a.isValidNot0(w))throw new Error(`invalid signature ${x}: out of range 1..Point.Fn.ORDER`);return w}function _(){if(p)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function L(x,w){Hs(w);let A=b.signature,B=w==="compact"?A:w==="recovered"?A+1:void 0;return z(x,B)}class R{r;s;recovery;constructor(w,A,B){if(this.r=v("r",w),this.s=v("s",A),B!=null){if(_(),![0,1,2,3].includes(B))throw new Error("invalid recovery id");this.recovery=B}Object.freeze(this)}static fromBytes(w,A=E.format){L(w,A);let B;if(A==="der"){let{r:F,s:V}=Nt.toSig(z(w));return new R(F,V)}A==="recovered"&&(B=w[0],A="compact",w=w.subarray(1));let I=b.signature/2,C=w.subarray(0,I),O=w.subarray(I,I*2);return new R(a.fromBytes(C),a.fromBytes(O),B)}static fromHex(w,A){return this.fromBytes(ze(w),A)}assertRecovery(){let{recovery:w}=this;if(w==null)throw new Error("invalid recovery id: must be present");return w}addRecoveryBit(w){return new R(this.r,this.s,w)}recoverPublicKey(w){let{r:A,s:B}=this,I=this.assertRecovery(),C=I===2||I===3?A+c:A;if(!i.isValid(C))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let O=i.toBytes(C),F=e.fromBytes(nt(nc((I&1)===0),O)),V=a.inv(C),U=D(z(w,void 0,"msgHash")),rt=a.create(-U*V),ot=a.create(B*V),st=e.BASE.multiplyUnsafe(rt).add(F.multiplyUnsafe(ot));if(st.is0())throw new Error("invalid recovery: point at infinify");return st.assertValidity(),st}hasHighS(){return y(this.s)}toBytes(w=E.format){if(Hs(w),w==="der")return ze(Nt.hexFromSig(this));let{r:A,s:B}=this,I=a.toBytes(A),C=a.toBytes(B);return w==="recovered"?(_(),nt(Uint8Array.of(this.assertRecovery()),I,C)):nt(I,C)}toHex(w){return qe(this.toBytes(w))}}Object.freeze(R.prototype),Object.freeze(R);let P=r.bits2int===void 0?function(w){if(w.length>8192)throw new Error("input is too large");let A=we(w),B=w.length*8-u;return B>0?A>>BigInt(B):A}:r.bits2int,D=r.bits2int_modN===void 0?function(w){return a.create(P(w))}:r.bits2int_modN,T=wr(u);function K(x){return Ve("num < 2^"+u,x,Ht,T),a.toBytes(x)}function N(x,w){return z(x,void 0,"message"),w?z(n(x),void 0,"prehashed message"):x}function k(x,w,A){let{lowS:B,prehash:I,extraEntropy:C}=Vs(A,E);x=N(x,I);let O=D(x),F=a.fromBytes(w);if(!a.isValidNot0(F))throw new Error("invalid private key");let V=[K(F),K(O)];if(C!=null&&C!==!1){let st=C===!0?o(b.secretKey):C;V.push(z(st,void 0,"extraEntropy"))}let U=nt(...V),rt=O;function ot(st){let Q=P(st);if(!a.isValidNot0(Q))return;let xt=a.inv(Q),Re=e.BASE.multiply(Q).toAffine(),rr=a.create(Re.x);if(rr===Ht)return;let Hr=a.create(xt*a.create(rt+rr*F));if(Hr===Ht)return;let yi=(Re.x===rr?0:2)|Number(Re.y&he),bi=Hr;return B&&y(Hr)&&(bi=a.neg(Hr),yi^=1),new R(rr,bi,p?void 0:yi)}return{seed:U,k2sig:ot}}function m(x,w,A={}){let{seed:B,k2sig:I}=k(x,w,A);return ca(n.outputLen,a.BYTES,s)(B,I).toBytes(A.format)}function g(x,w,A,B={}){let{lowS:I,prehash:C,format:O}=Vs(B,E);if(A=z(A,void 0,"publicKey"),w=N(w,C),!ge(x)){let F=x instanceof R?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+F)}L(x,O);try{let F=R.fromBytes(x,O),V=e.fromBytes(A);if(I&&F.hasHighS())return!1;let{r:U,s:rt}=F,ot=D(w),st=a.inv(rt),Q=a.create(ot*st),xt=a.create(U*st),Re=e.BASE.multiplyUnsafe(Q).add(V.multiplyUnsafe(xt));return Re.is0()?!1:a.create(Re.x)===U}catch{return!1}}function S(x,w,A={}){let{prehash:B}=Vs(A,E);return w=N(w,B),R.fromBytes(x,"recovered").recoverPublicKey(w).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:d,utils:h,lengths:b,Point:e,sign:m,verify:g,recoverPublicKey:S,Signature:R,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")},kl={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var ic=BigInt(2);function Pl(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,l=j(f,r,t)*f%t,d=j(l,r,t)*f%t,h=j(d,ic,t)*u%t,b=j(h,o,t)*h%t,E=j(b,s,t)*b%t,p=j(E,a,t)*E%t,y=j(p,c,t)*p%t,v=j(y,a,t)*E%t,_=j(v,r,t)*f%t,L=j(_,i,t)*b%t,R=j(L,n,t)*u%t,P=j(R,ic,t);if(!Ws.eql(Ws.sqr(P),e))throw new Error("Cannot find square root");return P}var Ws=$e(js.p,{sqrt:Pl}),Kl=rc(js,{Fp:Ws,endo:kl}),Xe=sc(Kl,Me);function ac(e,t,r,n){let o=cr.digest(r instanceof Uint8Array?r:r.subarray());if(yn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Xe.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Sr(String(s))});try{return n?.signal?.throwIfAborted(),Xe.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new Sr(String(s))}}var _n=class{type="secp256k1";raw;_key;constructor(t){this._key=uc(t),this.raw=cc(this._key)}toMultihash(){return Lt.digest(It(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}verify(t,r,n){return ac(this._key,r,t,n)}};function Zs(e){return new _n(e)}function cc(e){return Xe.Point.fromBytes(e).toBytes()}function uc(e){try{return Xe.Point.fromBytes(e),e}catch(t){throw new Ce(String(t))}}function Tn(e,t){let{Type:r,Data:n}=Vt.decode(e),o=n??new Uint8Array;switch(r){case Z.RSA:return Ms(o,t);case Z.Ed25519:return ps(o);case Z.secp256k1:return Zs(o);case Z.ECDSA:return No(o);default:throw new pe}}function fc(e){let{Type:t,Data:r}=Vt.decode(e.digest),n=r??new Uint8Array;switch(t){case Z.Ed25519:return ps(n);case Z.secp256k1:return Zs(n);case Z.ECDSA:return No(n);default:throw new pe}}function It(e){return Vt.encode({Type:Z[e.type],Data:e.raw})}var lc=Symbol.for("nodejs.util.inspect.custom"),Nl=114,Cr=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()})`}[jr]=!0;toString(){return this.string==null&&(this.string=G.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return et.createV1(Nl,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return W(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return W(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[lc](){return`PeerId(${this.toString()})`}},Lr=class extends Cr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Dr=class extends Cr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Or=class extends Cr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Ul=2336,kr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Lt.digest(H(this.url))}[lc](){return`PeerId(${this.url})`}[jr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return et.createV1(Ul,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=q(t)),t.toString()===this.toString())}};var Fl=114,dc=2336;function hc(e){if(e.type==="Ed25519")return new Dr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new Or({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new Lr({multihash:e.toCID().multihash,publicKey:e});throw new pe}function Ys(e){if(ql(e))return new Lr({multihash:e});if(Ml(e))try{let t=fc(e);if(t.type==="Ed25519")return new Dr({multihash:e,publicKey:t});if(t.type==="secp256k1")return new Or({multihash:e,publicKey:t})}catch{let r=q(e.digest);return new kr(new URL(r))}throw new Wr("Supplied PeerID Multihash is invalid")}function In(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==Fl&&e.code!==dc)throw new $r("Supplied PeerID CID is invalid");if(e.code===dc){let t=q(e.multihash.digest);return new kr(new URL(t))}return Ys(e.multihash)}function Ml(e){return e.code===Lt.code}function ql(e){return e.code===cr.code}var Pr;(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:J(0),payloadType:J(0),payload:J(0),signature:J(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})(Pr||(Pr={}));var Bn=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var Qe=class e{static createFromProtobuf=t=>{let r=Pr.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=pc(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 Bn("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=Pr.encode({publicKey:It(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return t==null?!1:W(this.marshal(),t.marshal())}async validate(t,r){let n=pc(t,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},pc=(e,t,r)=>{let n=H(e),o=gn(n.byteLength),s=gn(t.length),i=gn(r.length);return new mt(o,n,s,t,i,r)};var ft=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Xt=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 l=this.readChar();if(l===void 0)return;let d=Number.parseInt(l,t);if(!Number.isNaN(d))return d});if(f===void 0)break;if(s*=t,s+=f,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=t(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var zl=45,Vl=15,Dn=new Ln;function mc(e){if(!(e.length>Vl))return Dn.new(e).parseWith(()=>Dn.readIPv4Addr())}function yc(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>zl))return Dn.new(e).parseWith(()=>Dn.readIPv6Addr())}function On(e){return!!mc(e)}function bc(e){return!!yc(e)}function Xs(e){return t=>q(t,e)}function Qs(e){return t=>H(t,e)}function Je(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function _e(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function gc(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=H(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=_e(n);return Mt([r,o],r.length+o.length)}function wc(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=_e(n);return Mt([r,o],r.length+o.length)}function Js(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=q(t,"base32"),o=Je(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 ft("Invalid byte value in IP address");t[n]=o}),t},xc=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]=q(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,q(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(t+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new ft("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Ec=function(e){if(e.byteLength!==4)throw new ft("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},vc=function(e){if(e.byteLength!==16)throw new ft("IPv6 address was incorrect length");let t=[];for(let n=0;n<e.byteLength;n+=2){let o=e[n],s=e[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let r=t.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new ft(`Invalid IPv6 address "${r}"`)}};function Sc(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new ft(`Invalid IPv6 address "${e}"`)}}var Gs=Object.values(ur).map(e=>e.decoder),Hl=(function(){let e=Gs[0].or(Gs[1]);return Gs.slice(2).forEach(t=>e=e.or(t)),e})();function Ac(e){return Hl.decode(e)}function _c(e){return t=>e.encoder.encode(t)}function $l(e){if(parseInt(e).toString()!==e)throw new Xt("Value must be an integer")}function Wl(e){if(e<0)throw new Xt("Value must be a positive integer, or zero")}function jl(e){return t=>{if(t>e)throw new Xt(`Value must be smaller than or equal to ${e}`)}}function Zl(...e){return t=>{for(let r of e)r(t)}}var Kr=Zl($l,Wl,jl(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)}))}},Qt=new ei,kd=[{code:4,name:"ip4",size:32,valueToBytes:ti,bytesToValue:Ec,validate:e=>{if(!On(e))throw new Xt(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:_e,bytesToValue:Je,validate:Kr},{code:273,name:"udp",size:16,valueToBytes:_e,bytesToValue:Je,validate:Kr},{code:33,name:"dccp",size:16,valueToBytes:_e,bytesToValue:Je,validate:Kr},{code:41,name:"ip6",size:128,valueToBytes:xc,bytesToValue:vc,stringToValue:Sc,validate:e=>{if(!bc(e))throw new Xt(`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:_e,bytesToValue:Je,validate:Kr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:at,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:at,bytesToValue:Xs("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?Qs("base58btc")(e):et.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Js,valueToBytes:gc},{code:445,name:"onion3",size:296,bytesToValue:Js,valueToBytes:wc},{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:_c(Ao),valueToBytes:Ac},{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}];kd.forEach(e=>{Qt.addProtocol(e)});function Tc(e){let t=[],r=0;for(;r<e.length;){let n=xs(e,r),o=Qt.getProtocol(n),s=Rt(n),i=Pd(o,e,r+s),a=0;i>0&&o.size===at&&(a=Rt(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,l=e.subarray(f,f+i);u.value=o.bytesToValue?.(l)??q(l)}t.push(u),r+=c}return t}function Ic(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=Qt.getProtocol(n.code),s=Rt(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??H(n.value),a=i.byteLength,o.size===at&&(c=Rt(a)));let u=new Uint8Array(s+c+a),f=0;Ye(n.code,u,f),f+=s,i!=null&&(o.size===at&&(Ye(a,u,f),f+=c),u.set(i,f)),n.bytes=u}r.push(n.bytes),t+=n.bytes.byteLength}return Mt(r,t)}function Bc(e){if(e.charAt(0)!=="/")throw new ft('String multiaddr must start with "/"');let t=[],r="protocol",n="",o="";for(let s=1;s<e.length;s++){let i=e.charAt(s);i!=="/"&&(r==="protocol"?o+=e.charAt(s):n+=e.charAt(s));let a=s===e.length-1;if(i==="/"||a){let c=Qt.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new ft(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new ft(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}t.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new ft("Incomplete multiaddr");return t}function Rc(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=Qt.getProtocol(t.code);if(r==null)throw new ft(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function Pd(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:xs(t,r)}var Kd=Symbol.for("nodejs.util.inspect.custom"),ni=Symbol.for("@multiformats/multiaddr");function Nd(e){if(e==null&&(e="/"),Pn(e))return e.getComponents();if(e instanceof Uint8Array)return Tc(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),Bc(e);if(Array.isArray(e))return e;throw new ft("Must be a string, Uint8Array, Component[], or another Multiaddr")}var kn=class e{[ni]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=Nd(t),r.validate!==!1&&Ud(this)}get bytes(){return this.#r==null&&(this.#r=Ic(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Rc(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 W(this.bytes,t.bytes)}[Kd](){return`Multiaddr(${this.toString()})`}};function Ud(e){e.getComponents().forEach(t=>{let r=Qt.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function Pn(e){return!!e?.[ni]}function Te(e){return new kn(e)}var Cc="libp2p-peer-record",Lc=Uint8Array.from([3,1]);var Nr;(function(e){let t;(function(i){let a;i.codec=()=>(a==null&&(a=wt((l,d,h={})=>{h.lengthDelimited!==!1&&d.fork(),l.multiaddr!=null&&l.multiaddr.byteLength>0&&(d.uint32(10),d.bytes(l.multiaddr)),h.lengthDelimited!==!1&&d.ldelim()},(l,d,h={})=>{let b={multiaddr:J(0)},E=d==null?l.len:l.pos+d;for(;l.pos<E;){let p=l.uint32();p>>>3===1?b.multiaddr=l.bytes():l.skipType(p&7)}return b},function*(l,d,h,b={}){let E=d==null?l.len:l.pos+d;for(;l.pos<E;){let p=l.uint32();p>>>3===1?yield{field:`${h}.multiaddr`,value:l.bytes()}:l.skipType(p&7)}})),a);function c(l){return bt(l,i.codec())}i.encode=c;function u(l,d){return yt(l,i.codec(),d)}i.decode=u;function f(l,d){return gt(l,i.codec(),d)}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:J(0),seq:0n,addresses:[]},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let l=i.uint32();switch(l>>>3){case 1:{u.peerId=i.bytes();break}case 2:{u.seq=i.uint64();break}case 3:{if(c.limits?.addresses!=null&&u.addresses.length===c.limits.addresses)throw new Ct('Decode error - repeated field "addresses" had too many elements');u.addresses.push(e.AddressInfo.codec().decode(i,i.uint32(),{limits:c.limits?.addresses$}));break}default:{i.skipType(l&7);break}}}return u},function*(i,a,c,u={}){let f={addresses:0},l=a==null?i.len:i.pos+a;for(;i.pos<l;){let d=i.uint32();switch(d>>>3){case 1:{yield{field:`${c}.peerId`,value:i.bytes()};break}case 2:{yield{field:`${c}.seq`,value:i.uint64()};break}case 3:{if(u.limits?.addresses!=null&&f.addresses===u.limits.addresses)throw new Ct('Streaming decode error - repeated field "addresses" had too many elements');for(let h of e.AddressInfo.codec().stream(i,i.uint32(),`${c}.addresses[]`,{limits:u.limits?.addresses$}))yield{...h,index:f.addresses};f.addresses++;break}default:{i.skipType(d&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})(Nr||(Nr={}));function Dc(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 Ie=class e{static createFromProtobuf=t=>{let r=Nr.decode(t),n=Ys(Ne(r.peerId)),o=(r.addresses??[]).map(i=>Te(i.multiaddr)),s=r.seq;return new e({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Cc;static CODEC=Lc;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=Nr.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||!Dc(this.multiaddrs,t.multiaddrs))}};function Fd(e){return e[Symbol.asyncIterator]!=null}function Md(e){if(Fd(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 Oc=Md;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 Ur=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}},tr=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 kc(e={}){return qd(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 qd(e,t){t=t??{};let r=t.onEnd,n=new tr,o,s,i,a=Nn(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,y)=>{s=v=>{s=null,n.push(v);try{p(e(n))}catch(_){y(_)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Nn()})}},u=p=>s!=null?s(p):(n.push(p),o),f=p=>(n=new tr,s!=null?s({error:p}):(n.push({error:p}),o)),l=p=>{if(i)return o;if(t?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:p})},d=p=>i?o:(i=!0,p!=null?f(p):u({done:!0})),h=()=>(n=new tr,d(),{done:!0}),b=p=>(d(p),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:h,throw:b,push:l,end:d,get readableLength(){return n.size},onEmpty:async p=>{let y=p?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let v,_;y!=null&&(v=new Promise((L,R)=>{_=()=>{R(new oi)},y.addEventListener("abort",_)}));try{await Promise.race([a.promise,v])}finally{_!=null&&y!=null&&y?.removeEventListener("abort",_)}}},r==null)return o;let E=o;return o={[Symbol.asyncIterator](){return this},next(){return E.next()},throw(p){return E.throw(p),r!=null&&(r(p),r=void 0),{done:!0}},return(){return E.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(p){return E.end(p),r!=null&&(r(p),r=void 0),o},get readableLength(){return E.readableLength},onEmpty:p=>E.onEmpty(p)},o}function zd(e){return e.reason}async function Pc(e,t,r){if(t==null)return e;let n=r?.translateError??zd;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 Ur{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 Ur,n}var _t=class extends Error{static name="AbortError";name="AbortError";constructor(t="The operation was aborted",...r){super(t,...r)}};async function Fn(e,t,r,n){let o=new _t(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",l),ci(e,t,u),ci(e,s,f)}let u=d=>{try{if(n?.filter?.(d)===!1)return}catch(h){c(),a(h);return}c(),i(d)},f=d=>{if(c(),d instanceof Error){a(d);return}a(d.detail??n?.error??new Error(`The "${n?.errorEvent}" event was emitted but the event had no '.detail' field. Pass an 'error' option to race-event to change this message.`))},l=()=>{c(),a(o)};ai(r,"abort",l),ai(e,t,u),ai(e,s,f)})}function ai(e,t,r){e!=null&&(Kc(e)?e.addEventListener(t,r):e.addListener(t,r))}function ci(e,t,r){e!=null&&(Kc(e)?e.removeEventListener(t,r):e.removeListener(t,r))}function Kc(e){return typeof e.addEventListener=="function"&&typeof e.removeEventListener=="function"}var Mn=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 _t)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Vd(){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=Vd(),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 _t),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 Pc(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 Fr=class extends De{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 Mn;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 _t)}),this.clear()}async onEmpty(t){this.size!==0&&await Fn(this,"empty",t?.signal)}async onSizeLessThan(t,r){this.size<t||await Fn(this,"next",r?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await Fn(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=kc({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 _t("Queue aborted"))};this.addEventListener("success",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("success",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};var Vn="lock:worker:request-read",Hn="lock:worker:abort-read-request",$n="lock:worker:release-read",Wn="lock:master:grant-read",jn="lock:master:error-read",Zn="lock:worker:request-write",Yn="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",Nc={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(l=>{let d=h=>{if(h?.data==null)return;let b={type:h.data.type,name:h.data.name,identifier:h.data.identifier};b.type===a&&b.identifier===f.identifier&&(t.removeEventListener("message",d),l())};t.addEventListener("message",d)})},onError:l=>{t.postMessage({type:i,name:f.name,identifier:f.identifier,error:{message:l.message,name:l.name,stack:l.stack}})}}}),f.type===s&&e.safeDispatchEvent(n,{detail:{name:f.name,identifier:f.identifier}}),f.type===Jn&&e.safeDispatchEvent("finalizeRequest",{detail:{name:f.name}})};var Uc=(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(Vn,Hn,Wn,jn,$n,t)}writeLock(t){return this.sendRequest(Zn,Yn,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=Uc();return this.channel.postMessage({type:t,identifier:a,name:this.name}),new Promise((c,u)=>{let f=()=>{this.channel.postMessage({type:r,identifier:a,name:this.name})};i?.signal?.addEventListener("abort",f,{once:!0});let l=d=>{if(d.data?.identifier===a&&(d.data?.type===n&&(this.channel.removeEventListener("message",l),i?.signal?.removeEventListener("abort",f),c(()=>{this.channel.postMessage({type:s,identifier:a,name:this.name})})),d.data.type===o)){this.channel.removeEventListener("message",l),i?.signal?.removeEventListener("abort",f);let h=new Error;d.data.error!=null&&(h.message=d.data.error.message,h.name=d.data.error.name,h.stack=d.data.error.stack),u(h)}};this.channel.addEventListener("message",l)})}};var Fc=e=>{if(e=Object.assign({},Nc,e),!!globalThis.document||e.singleProcess){let r=new BroadcastChannel(to),n=new De;return r.addEventListener("message",fi(n,r,"requestReadLock","abortReadLockRequest",Vn,Hn,jn,$n,Wn)),r.addEventListener("message",fi(n,r,"requestWriteLock","abortWriteLockRequest",Zn,Yn,Qn,Gn,Xn)),n}return new eo(e.name)};var Be=new Map,Mr;function Mc(e){return typeof e?.readLock=="function"&&typeof e?.writeLock=="function"}function Hd(e){if(Mr==null&&(Mr=Fc(e),!Mc(Mr))){let t=Mr;t.addEventListener("requestReadLock",r=>{let n=r.detail.name,o=r.detail.identifier,s=Be.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=Be.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=Be.get(n);o?.finalize()})}return Mr}async function li(e,t){let r,n,o=new Promise((i,a)=>{r=i,n=a}),s=()=>{n(new _t)};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 qc=(e,t)=>{let r=Be.get(e);if(r!=null)return r;let n=Hd(t);if(Mc(n))return r=n,Be.set(e,r),r;let o=new Fr({concurrency:1}),s;return r={async readLock(i){if(s!=null)return li(s,i);s=new Fr({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:()=>{Be.delete(e)},queue:o},Be.set(e,r),t.autoFinalize===!0&&o.addEventListener("idle",()=>{r.finalize()},{once:!0}),r};var $d={name:"lock",concurrency:1/0,singleProcess:!1,autoFinalize:!1};function di(e){let t=Object.assign({},$d,e);return qc(t.name,t)}var Jt;(function(e){let t;(function(a){let c;a.codec=()=>(c==null&&(c=wt((d,h,b={})=>{b.lengthDelimited!==!1&&h.fork(),d.key!=null&&d.key!==""&&(h.uint32(10),h.string(d.key)),d.value!=null&&d.value.byteLength>0&&(h.uint32(18),h.bytes(d.value)),b.lengthDelimited!==!1&&h.ldelim()},(d,h,b={})=>{let E={key:"",value:J(0)},p=h==null?d.len:d.pos+h;for(;d.pos<p;){let y=d.uint32();switch(y>>>3){case 1:{E.key=d.string();break}case 2:{E.value=d.bytes();break}default:{d.skipType(y&7);break}}}return E},function*(d,h,b,E={}){let p=h==null?d.len:d.pos+h;for(;d.pos<p;){let y=d.uint32();switch(y>>>3){case 1:{yield{field:`${b}.key`,value:d.string()};break}case 2:{yield{field:`${b}.value`,value:d.bytes()};break}default:{d.skipType(y&7);break}}}})),c);function u(d){return bt(d,a.codec())}a.encode=u;function f(d,h){return yt(d,a.codec(),h)}a.decode=f;function l(d,h){return gt(d,a.codec(),h)}a.stream=l})(t=e.Peer$metadataEntry||(e.Peer$metadataEntry={}));let r;(function(a){let c;a.codec=()=>(c==null&&(c=wt((d,h,b={})=>{b.lengthDelimited!==!1&&h.fork(),d.key!=null&&d.key!==""&&(h.uint32(10),h.string(d.key)),d.value!=null&&(h.uint32(18),zr.codec().encode(d.value,h)),b.lengthDelimited!==!1&&h.ldelim()},(d,h,b={})=>{let E={key:""},p=h==null?d.len:d.pos+h;for(;d.pos<p;){let y=d.uint32();switch(y>>>3){case 1:{E.key=d.string();break}case 2:{E.value=zr.codec().decode(d,d.uint32(),{limits:b.limits?.value});break}default:{d.skipType(y&7);break}}}return E},function*(d,h,b,E={}){let p=h==null?d.len:d.pos+h;for(;d.pos<p;){let y=d.uint32();switch(y>>>3){case 1:{yield{field:`${b}.key`,value:d.string()};break}case 2:{yield*zr.codec().stream(d,d.uint32(),`${b}.value`,{limits:E.limits?.value});break}default:{d.skipType(y&7);break}}}})),c);function u(d){return bt(d,a.codec())}a.encode=u;function f(d,h){return yt(d,a.codec(),h)}a.decode=f;function l(d,h){return gt(d,a.codec(),h)}a.stream=l})(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),qr.codec().encode(f,c);if(a.protocols!=null&&a.protocols.length>0)for(let f of a.protocols)c.uint32(18),c.string(f);if(a.publicKey!=null&&(c.uint32(34),c.bytes(a.publicKey)),a.peerRecordEnvelope!=null&&(c.uint32(42),c.bytes(a.peerRecordEnvelope)),a.metadata!=null&&a.metadata.size>0)for(let[f,l]of a.metadata.entries())c.uint32(50),e.Peer$metadataEntry.codec().encode({key:f,value:l},c);if(a.tags!=null&&a.tags.size>0)for(let[f,l]of a.tags.entries())c.uint32(58),e.Peer$tagsEntry.codec().encode({key:f,value:l},c);a.updated!=null&&(c.uint32(64),c.uint64Number(a.updated)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={addresses:[],protocols:[],metadata:new Map,tags:new Map},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();switch(d>>>3){case 1:{if(u.limits?.addresses!=null&&f.addresses.length===u.limits.addresses)throw new Ct('Decode error - repeated field "addresses" had too many elements');f.addresses.push(qr.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 Ct('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 Ir('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 Ir('Decode error - map field "tags" had too many elements');let h=e.Peer$tagsEntry.codec().decode(a,a.uint32(),{limits:{value:u.limits?.tags$value}});f.tags.set(h.key,h.value);break}case 8:{f.updated=a.uint64Number();break}default:{a.skipType(d&7);break}}}return f},function*(a,c,u,f={}){let l={addresses:0,protocols:0,metadata:0,tags:0},d=c==null?a.len:a.pos+c;for(;a.pos<d;){let h=a.uint32();switch(h>>>3){case 1:{if(f.limits?.addresses!=null&&l.addresses===f.limits.addresses)throw new Ct('Streaming decode error - repeated field "addresses" had too many elements');for(let b of qr.codec().stream(a,a.uint32(),`${u}.addresses[]`,{limits:f.limits?.addresses$}))yield{...b,index:l.addresses};l.addresses++;break}case 2:{if(f.limits?.protocols!=null&&l.protocols===f.limits.protocols)throw new Ct('Streaming decode error - repeated field "protocols" had too many elements');yield{field:`${u}.protocols[]`,index:l.protocols,value:a.string()},l.protocols++;break}case 4:{yield{field:`${u}.publicKey`,value:a.bytes()};break}case 5:{yield{field:`${u}.peerRecordEnvelope`,value:a.bytes()};break}case 6:{if(f.limits?.metadata!=null&&l.metadata===f.limits.metadata)throw new Ct('Decode error - map field "metadata" had too many elements');yield*e.Peer$metadataEntry.codec().stream(a,a.uint32(),`${u}.metadata{}`,{limits:{value:f.limits?.metadata$value}}),l.metadata++;break}case 7:{if(f.limits?.tags!=null&&l.tags===f.limits.tags)throw new Ct('Decode error - map field "tags" had too many elements');yield*e.Peer$tagsEntry.codec().stream(a,a.uint32(),`${u}.tags{}`,{limits:{value:f.limits?.tags$value}}),l.tags++;break}case 8:{yield{field:`${u}.updated`,value:a.uint64Number()};break}default:{a.skipType(h&7);break}}}})),n);function o(a){return 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})(Jt||(Jt={}));var qr;(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:J(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})(qr||(qr={}));var zr;(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})(zr||(zr={}));function Wd(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 hc(n)}function zc(e,t,r){let n=Jt.decode(t);return er(e,n,r)}function er(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:Wd(e,t),addresses:t.addresses.filter(({observed:s})=>s!=null&&s>Date.now()-r).map(({multiaddr:s,isCertified:i})=>({multiaddr:Te(s),isCertified:i??!1})),metadata:t.metadata,peerRecordEnvelope:t.peerRecordEnvelope??void 0,tags:n}}function Vc(e,t){return jd(e.addresses,t.addresses)&&Zd(e.protocols,t.protocols)&&Yd(e.publicKey,t.publicKey)&&Gd(e.peerRecordEnvelope,t.peerRecordEnvelope)&&Xd(e.metadata,t.metadata)&&Qd(e.tags,t.tags)}function jd(e,t){return $c(e,t,(r,n)=>!(r.isCertified!==n.isCertified||!W(r.multiaddr,n.multiaddr)))}function Zd(e,t){return $c(e,t,(r,n)=>r===n)}function Yd(e,t){return Hc(e,t)}function Gd(e,t){return Hc(e,t)}function Xd(e,t){return Wc(e,t,(r,n)=>W(r,n))}function Qd(e,t){return Wc(e,t,(r,n)=>r.value===n.value&&r.expiry===n.expiry)}function Hc(e,t){return e==null&&t==null?!0:e!=null&&t!=null?W(e,t):!1}function $c(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 Wc(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 te="/",jc=new TextEncoder().encode(te),ro=jc[0],no=class e{_buf;constructor(t,r){if(typeof t=="string")this._buf=H(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 q(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new e(t.join(te))}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=jc),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(te).slice(1)}type(){return Jd(this.baseNamespace())}name(){return th(this.baseNamespace())}instance(t){return new e(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(te)||(t+=te),t+=this.type(),new e(t)}parent(){let t=this.list();return t.length===1?new e(te):new e(t.slice(0,-1).join(te))}child(t){return this.toString()===te?t:t.toString()===te?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(),...eh(t.map(r=>r.namespaces()))])}};function Jd(e){let t=e.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function th(e){let t=e.split(":");return t[t.length-1]}function eh(e){return[].concat(...e)}var hi="/peers/";function Vr(e){if(!Le(e)||e.type==null)throw new M("Invalid PeerId");let t=e.toCID().toString();return new no(`${hi}${t}`)}async function Zc(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=Te(i.multiaddr)),!Pn(i.multiaddr))throw new M("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(Te(`/p2p/${e}`))),{isCertified:i,multiaddr:a.bytes}})}async function so(e,t,r,n){if(t==null)throw new M("Invalid PeerData");if(t.publicKey!=null&&!e.equals(t.publicKey.toMultihash().bytes))throw new M("publicKey does not match peer id");let o=n.existingPeer?.peer;if(o!=null&&!e.equals(o.id))throw new M("peer id did not match existing peer id");let s=o?.addresses??[],i=new Set(o?.protocols??[]),a=o?.metadata??new Map,c=o?.tags??new Map,u=o?.peerRecordEnvelope;if(r==="patch"){if((t.multiaddrs!=null||t.addresses!=null)&&(s=[],t.multiaddrs!=null&&s.push(...t.multiaddrs.map(d=>({isCertified:!1,multiaddr:d}))),t.addresses!=null&&s.push(...t.addresses)),t.protocols!=null&&(i=new Set(t.protocols)),t.metadata!=null){let d=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);a=oo(d,{validate:Yc})}if(t.tags!=null){let d=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags);c=oo(d,{validate:Gc,map:Xc})}t.peerRecordEnvelope!=null&&(u=t.peerRecordEnvelope)}if(r==="merge"){if(t.multiaddrs!=null&&s.push(...t.multiaddrs.map(d=>({isCertified:!1,multiaddr:d}))),t.addresses!=null&&s.push(...t.addresses),t.protocols!=null&&(i=new Set([...i,...t.protocols])),t.metadata!=null){let d=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);for(let[h,b]of d)b==null?a.delete(h):a.set(h,b);a=oo([...a.entries()],{validate:Yc})}if(t.tags!=null){let d=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags),h=new Map(c);for(let[b,E]of d)E==null?h.delete(b):h.set(b,E);c=oo([...h.entries()],{validate:Gc,map:Xc})}t.peerRecordEnvelope!=null&&(u=t.peerRecordEnvelope)}let f;o?.id.publicKey!=null?f=It(o.id.publicKey):t.publicKey!=null?f=It(t.publicKey):e.publicKey!=null&&(f=It(e.publicKey));let l={addresses:await Zc(e,n.addressFilter??(async()=>!0),s,n.existingPeer?.peerPB.addresses,n),protocols:[...i.values()].sort((d,h)=>d.localeCompare(h)),metadata:a,tags:c,publicKey:f,peerRecordEnvelope:u};return l.addresses.forEach(d=>{d.observed=n.existingPeer?.peerPB.addresses?.find(h=>W(h.multiaddr,d.multiaddr))?.observed??Date.now()}),e.type!=="RSA"&&delete l.publicKey,l}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 Yc(e,t){if(typeof e!="string")throw new M("Metadata key must be a string");if(!(t instanceof Uint8Array))throw new M("Metadata value must be a Uint8Array")}function Gc(e,t){if(typeof e!="string")throw new M("Tag name must be a string");if(t.value!=null){if(parseInt(`${t.value}`,10)!==t.value)throw new M("Tag value must be an integer");if(t.value<0||t.value>100)throw new M("Tag value must be between 0-100")}if(t.ttl!=null){if(parseInt(`${t.ttl}`,10)!==t.ttl)throw new M("Tag ttl must be an integer");if(t.ttl<0)throw new M("Tag ttl must be between greater than 0")}}function Xc(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 Qc(e){let t=e.toString().split("/")[2],r=et.parse(t,Ut);return In(r)}function pi(e,t,r){let n=Qc(e);return zc(n,t,r)}function rh(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(Vr(t),r)}async load(t,r){let n=Vr(t),o=await this.datastore.get(n,r),s=Jt.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,r),new nr;return er(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(rh(t??{},this.maxAddressAge),t)){let o=Qc(r);if(o.equals(this.peerId))continue;let s=Jt.decode(n);if(this.#r(o,s)){await this.datastore.delete(r,t);continue}yield er(o,s,this.peerId.equals(o)?1/0:this.maxAddressAge)}}async#t(t,r){try{let n=Vr(t),o=await this.datastore.get(n,r),s=Jt.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,r),new nr;return{peerPB:s,peer:er(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=Jt.encode(r);return await this.datastore.put(Vr(t),s,o),{peer:er(t,r,this.maxAddressAge),previous:n?.peer,updated:n==null||!Vc(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 Oc(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=Le(r)?r:Le(r?.expectedPeer)?r.expectedPeer:void 0,s=Le(r)||r===void 0?n:r,i=await Qe.openAndCertify(t,Ie.DOMAIN,s),a=In(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=Ie.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=Qe.createFromProtobuf(u.peerRecordEnvelope),l=Ie.createFromProtobuf(f.payload);if(l.seqNumber>=c.seqNumber)return this.log("sequence number was lower or equal to existing sequence number - stored: %d received: %d",l.seqNumber,c.seqNumber),!1}return await this.patch(c.peerId,{peerRecordEnvelope:t,addresses:c.multiaddrs.map(f=>({isCertified:!0,multiaddr:f}))},s),!0}#t(t,r){r.updated&&(this.peerId.equals(t)?this.events.safeDispatchEvent("self:peer:update",{detail:r}):this.events.safeDispatchEvent("peer:update",{detail:r}))}};function nh(e,t={}){return new mi(e,t)}return nu(oh);})();
|
|
2
|
+
"use strict";var Libp2PPeerStore=(()=>{var ao=Object.defineProperty;var Jc=Object.getOwnPropertyDescriptor;var tu=Object.getOwnPropertyNames;var eu=Object.prototype.hasOwnProperty;var Et=(e,t)=>{for(var r in t)ao(e,r,{get:t[r],enumerable:!0})},ru=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of tu(t))!eu.call(e,o)&&o!==r&&ao(e,o,{get:()=>t[o],enumerable:!(n=Jc(t,o))||n.enumerable});return e};var nu=e=>ru(ao({},"__esModule",{value:!0}),e);var oh={};Et(oh,{persistentPeerStore:()=>nh});var M=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Ce=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var nr=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var $r=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Wr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var pe=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var jr=Symbol.for("@libp2p/peer-id");function Le(e){return!!e?.[jr]}function ou(e){return typeof e?.handleEvent=="function"}function su(e){return(e!==!0&&e!==!1&&e?.once)??!1}var De=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=su(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))}ou(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 ho={};Et(ho,{base58btc:()=>G,base58flickr:()=>hu});var uh=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 me(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return me(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 iu(e){return e?.buffer instanceof ArrayBuffer}function me(e){return iu(e)?e:e.slice()}function au(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,l=e.charAt(0),d=Math.log(f)/Math.log(256),h=Math.log(256)/Math.log(f);function b(y){if(y instanceof Uint8Array||(ArrayBuffer.isView(y)?y=new Uint8Array(y.buffer,y.byteOffset,y.byteLength):Array.isArray(y)&&(y=Uint8Array.from(y))),!(y instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(y.length===0)return"";for(var v=0,_=0,L=0,R=y.length;L!==R&&y[L]===0;)L++,v++;for(var P=(R-L)*h+1>>>0,D=new Uint8Array(P);L!==R;){for(var T=y[L],K=0,N=P-1;(T!==0||K<_)&&N!==-1;N--,K++)T+=256*D[N]>>>0,D[N]=T%f>>>0,T=T/f>>>0;if(T!==0)throw new Error("Non-zero carry");_=K,L++}for(var k=P-_;k!==P&&D[k]===0;)k++;for(var m=l.repeat(v);k<P;++k)m+=e.charAt(D[k]);return m}function E(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return new Uint8Array;var v=0;if(y[v]!==" "){for(var _=0,L=0;y[v]===l;)_++,v++;for(var R=(y.length-v)*d+1>>>0,P=new Uint8Array(R);y[v];){var D=n[y.charCodeAt(v)];if(D===255)return;for(var T=0,K=R-1;(D!==0||T<L)&&K!==-1;K--,T++)D+=f*P[K]>>>0,P[K]=D%256>>>0,D=D/256>>>0;if(D!==0)throw new Error("Non-zero carry");L=T,v++}if(y[v]!==" "){for(var N=R-L;N!==R&&P[N]===0;)N++;for(var k=new Uint8Array(_+(R-N)),m=_;N!==R;)k[m++]=P[N++];return k}}}function p(y){var v=E(y);if(v)return v;throw new Error(`Non-${t} character`)}return{encode:b,decodeUnsafe:E,decode:p}}var cu=au,uu=cu,Si=uu;var co=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")}},uo=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)}},fo=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 fo({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var lo=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 co(t,r,n),this.decoder=new uo(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Oe({name:e,prefix:t,encode:r,decode:n}){return new lo(e,t,r,n)}function ee({name:e,prefix:t,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:s}=Si(r,e,n);return Oe({prefix:t,name:e,encode:o,decode:i=>Tt(s(i))})}function fu(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 lu(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 du(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 Y({name:e,prefix:t,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let s=du(n,o);return Oe({prefix:t,name:e,encode(i){return lu(i,n,r)},decode(i){return fu(i,s,r,e)}})}var G=ee({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),hu=ee({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var po={};Et(po,{base32:()=>Ut,base32hex:()=>bu,base32hexpad:()=>wu,base32hexpadupper:()=>xu,base32hexupper:()=>gu,base32pad:()=>mu,base32padupper:()=>yu,base32upper:()=>pu,base32z:()=>Eu});var Ut=Y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),pu=Y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),mu=Y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),yu=Y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),bu=Y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),gu=Y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),wu=Y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),xu=Y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),Eu=Y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var mo={};Et(mo,{base36:()=>or,base36upper:()=>vu});var or=ee({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),vu=ee({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Su=Ii,_i=128,Au=127,_u=~Au,Tu=Math.pow(2,31);function Ii(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Tu;)t[r++]=e&255|_i,e/=128;for(;e&_u;)t[r++]=e&255|_i,e>>>=7;return t[r]=e|0,Ii.bytes=r-n+1,t}var Iu=yo,Bu=128,Ti=127;function yo(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw yo.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>=Bu);return yo.bytes=s-n,r}var Ru=Math.pow(2,7),Cu=Math.pow(2,14),Lu=Math.pow(2,21),Du=Math.pow(2,28),Ou=Math.pow(2,35),ku=Math.pow(2,42),Pu=Math.pow(2,49),Ku=Math.pow(2,56),Nu=Math.pow(2,63),Uu=function(e){return e<Ru?1:e<Cu?2:e<Lu?3:e<Du?4:e<Ou?5:e<ku?6:e<Pu?7:e<Ku?8:e<Nu?9:10},Fu={encode:Su,decode:Iu,encodingLength:Uu},Mu=Fu,sr=Mu;function ir(e,t=0){let r=sr.decode(e,t),n=sr.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 ke(e,t,r=0){return sr.encode(e,t,r),t}function Pe(e){return sr.encodingLength(e)}function Ft(e,t){let r=t.byteLength,n=Pe(e),o=n+Pe(r),s=new Uint8Array(o+r);return ke(e,s,0),ke(r,s,n),s.set(t,o),new Ke(e,r,t,s)}function Ne(e){let t=Tt(e),[r,n]=ir(t),[o,s]=ir(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 Bi(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=me(n),this.bytes=me(o)}};function Ri(e,t){let{bytes:r,version:n}=e;return n===0?zu(r,bo(e),t??G.encoder):Vu(r,bo(e),t??Ut.encoder)}var Ci=new WeakMap;function bo(e){let t=Ci.get(e);if(t==null){let r=new Map;return Ci.set(e,r),r}return t}var et=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=me(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!==ar)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Hu)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=Ft(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&&Bi(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[$u]===!0){let{version:n,multihash:o,code:s}=r,i=Ne(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!==ar)throw new Error(`Version 0 CID must use dag-pb (code: ${ar}) 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,ar,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[l,d]=ir(t.subarray(r));return r+=d,l},o=n(),s=ar;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]=qu(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 bo(s).set(n,t),s}};function qu(e,t){switch(e[0]){case"Q":{let r=t??G;return[G.prefix,r.decode(`${G.prefix}${e}`)]}case G.prefix:{let r=t??G;return[G.prefix,r.decode(e)]}case Ut.prefix:{let r=t??Ut;return[Ut.prefix,r.decode(e)]}case or.prefix:{let r=t??or;return[or.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 zu(e,t,r){let{prefix:n}=r;if(n!==G.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function Vu(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 ar=112,Hu=18;function Li(e,t,r){let n=Pe(e),o=n+Pe(t),s=new Uint8Array(o+r.byteLength);return ke(e,s,0),ke(t,s,n),s.set(r,o),s}var $u=Symbol.for("@ipld/js-cid/CID");var go={};Et(go,{identity:()=>Lt});var Di=0,Wu="identity",Oi=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 Ft(Di,Oi(e))}var Lt={code:Di,name:Wu,encode:Oi,digest:ju};function W(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Zu(e){return e.buffer instanceof ArrayBuffer}function pt(e){return Zu(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 J(e=0){return new Uint8Array(e)}function lt(e=0){return new Uint8Array(e)}function Yu(e){return e?.buffer instanceof ArrayBuffer}function wo(e){if(Yu(e))return e;let t=e.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function Mt(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=lt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return wo(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 Yr(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(Yr(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(Yr(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(Yr(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 Mt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Mt(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=n,s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,f=r>a&&r<=c;if(u&&f){if(t===a&&r===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Yr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let d=u;d>=0;d--){let h=this.get(l+d);if(n[d]!==h){f=Math.max(1,d-a[h]);break}}if(f===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=lt(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=J(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=J(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=J(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=lt(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=J(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=J(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=J(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=J(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=J(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!W(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var xo={};Et(xo,{base10:()=>Gu});var Gu=ee({prefix:"9",name:"base10",alphabet:"0123456789"});var Eo={};Et(Eo,{base16:()=>Xu,base16upper:()=>Qu});var Xu=Y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Qu=Y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var vo={};Et(vo,{base2:()=>Ju});var Ju=Y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var So={};Et(So,{base256emoji:()=>of});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}"),tf=Ni.reduce((e,t,r)=>(e[r]=t,e),[]),ef=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 rf(e){return e.reduce((t,r)=>(t+=tf[r],t),"")}function nf(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=ef[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var of=Oe({prefix:"\u{1F680}",name:"base256emoji",encode:rf,decode:nf});var _o={};Et(_o,{base64:()=>sf,base64pad:()=>af,base64url:()=>Ao,base64urlpad:()=>cf});var sf=Y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),af=Y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ao=Y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),cf=Y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var To={};Et(To,{base8:()=>uf});var uf=Y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Io={};Et(Io,{identity:()=>ff});var ff=Oe({prefix:"\0",name:"identity",encode:e=>Ei(Tt(e)),decode:e=>Tt(xi(e))});var Zh=new TextEncoder,Yh=new TextDecoder;var Co={};Et(Co,{sha256:()=>cr,sha512:()=>pf});var hf=20;function Ro({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Bo(e,t,r,n,o)}var Bo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??hf,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 Ft(t,e)}function Mi(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var cr=Ro({name:"sha2-256",code:18,encode:Mi("SHA-256")}),pf=Ro({name:"sha2-512",code:19,encode:Mi("SHA-512")});var ur={...Io,...vo,...To,...xo,...Eo,...po,...mo,...ho,..._o,...So},ap={...Co,...go};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))),Lo=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=lt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),mf={utf8:qi,"utf-8":qi,hex:ur.base16,latin1:Lo,ascii:Lo,binary:Lo,...ur},Gr=mf;function H(e,t="utf8"){let r=Gr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function q(e,t="utf8"){let r=Gr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var yf=parseInt("11111",2),Do=parseInt("10000000",2),bf=parseInt("01111111",2),Vi={0:fr,1:fr,2:gf,3:Ef,4:vf,5:xf,6:wf,16:fr,22:fr,48:fr};function $t(e,t={offset:0}){let r=e[t.offset]&yf;if(t.offset++,Vi[r]!=null)return Vi[r](e,t);throw new Error("No decoder for tag "+r)}function lr(e,t){let r=0;if((e[t.offset]&Do)===Do){let n=e[t.offset]&bf,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function fr(e,t){lr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=$t(e,t);if(n===null)break;r.push(n)}return r}function gf(e,t){let r=lr(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 wf(e,t){let r=lr(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function xf(e,t){return t.offset++,null}function Ef(e,t){let r=lr(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 vf(e,t){let r=lr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Sf(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 Oo(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Sf(e.byteLength);return new mt(Uint8Array.from([t.byteLength|Do]),t)}function vt(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]),Oo(t),t)}function Xr(e){let t=Uint8Array.from([0]),r=new mt(t,e);return new mt(Uint8Array.from([3]),Oo(r),r)}function ne(e,t=48){let r=new mt;for(let n of e)r.append(n);return new mt(Uint8Array.from([t]),Oo(r),r)}var Af=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),_f=Uint8Array.from([6,5,43,129,4,0,34]),Tf=Uint8Array.from([6,5,43,129,4,0,35]),If={ext:!0,kty:"EC",crv:"P-256"},Bf={ext:!0,kty:"EC",crv:"P-384"},Rf={ext:!0,kty:"EC",crv:"P-521"},ko=32,Po=48,Ko=66;function No(e){let t=$t(e);return Hi(t)}function Hi(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===ko*2+1)return n=q(t.subarray(r,r+ko),"base64url"),o=q(t.subarray(r+ko),"base64url"),new Ue({...If,key_ops:["verify"],x:n,y:o});if(t.byteLength===Po*2+1)return n=q(t.subarray(r,r+Po),"base64url"),o=q(t.subarray(r+Po),"base64url"),new Ue({...Bf,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ko*2+1)return n=q(t.subarray(r,r+Ko),"base64url"),o=q(t.subarray(r+Ko),"base64url"),new Ue({...Rf,key_ops:["verify"],x:n,y:o});throw new M(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function $i(e){return ne([vt(Uint8Array.from([1])),ne([Cf(e.crv)],160),ne([Xr(new mt(Uint8Array.from([4]),H(e.x??"","base64url"),H(e.y??"","base64url")))],161)]).subarray()}function Cf(e){if(e==="P-256")return Af;if(e==="P-384")return _f;if(e==="P-521")return Tf;throw new M(`Invalid curve ${e}`)}var Ue=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 Lt.digest(It(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}async verify(t,r,n){return ki(this.jwk,r,t,n)}};function Uo(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}function oe(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(`${r}expected number, got ${typeof e}`)}if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new RangeError(`${r}expected integer >= 0, got ${e}`)}}function St(e,t,r=""){let n=Uo(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof e}`,u=i+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(u):new TypeError(u)}return e}function Qr(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(oe(e.outputLen),oe(e.blockLen),e.outputLen<1)throw new Error('"outputLen" must be >= 1');if(e.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Fe(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Jr(e,t){St(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function jt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function tn(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Dt(e,t){return e<<32-t|e>>>t}var ji=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Lf=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function en(e){if(St(e),ji)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Lf[e[r]];return t}var Wt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Wi(e){if(e>=Wt._0&&e<=Wt._9)return e-Wt._0;if(e>=Wt.A&&e<=Wt.F)return e-(Wt.A-10);if(e>=Wt.a&&e<=Wt.f)return e-(Wt.a-10)}function dr(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(ji)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=Wi(e.charCodeAt(s)),a=Wi(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 Fo(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];St(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 Mo(e,t={}){let r=(o,s)=>e(s).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function Zi(e=32){oe(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 qo=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function Yi(e,t,r){return e&t^~e&r}function Gi(e,t,r){return e&t^e&r^t&r}var hr=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=tn(this.buffer)}update(t){Fe(this),St(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=tn(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Fe(this),Jr(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,jt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=tn(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Zt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ct=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var rn=BigInt(4294967295),Xi=BigInt(32);function Df(e,t=!1){return t?{h:Number(e&rn),l:Number(e>>Xi&rn)}:{h:Number(e>>Xi&rn)|0,l:Number(e&rn)|0}}function Qi(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}=Df(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var zo=(e,t,r)=>e>>>r,Vo=(e,t,r)=>e<<32-r|t>>>r,ye=(e,t,r)=>e>>>r|t<<32-r,be=(e,t,r)=>e<<32-r|t>>>r,pr=(e,t,r)=>e<<64-r|t>>>r-32,mr=(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),ta=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ea=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),ra=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,na=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),oa=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var kf=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]),se=new Uint32Array(64),Ho=class extends hr{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,r,n,o,s,i,a,c]}set(t,r,n,o,s,i,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,r){for(let l=0;l<16;l++,r+=4)se[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let d=se[l-15],h=se[l-2],b=Dt(d,7)^Dt(d,18)^d>>>3,E=Dt(h,17)^Dt(h,19)^h>>>10;se[l]=E+se[l-7]+b+se[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let d=Dt(a,6)^Dt(a,11)^Dt(a,25),h=f+d+Yi(a,c,u)+kf[l]+se[l]|0,E=(Dt(n,2)^Dt(n,13)^Dt(n,22))+Gi(n,o,s)|0;f=u,u=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+E|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,u,f)}roundClean(){jt(se)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),jt(this.buffer)}},$o=class extends Ho{A=Zt[0]|0;B=Zt[1]|0;C=Zt[2]|0;D=Zt[3]|0;E=Zt[4]|0;F=Zt[5]|0;G=Zt[6]|0;H=Zt[7]|0;constructor(){super(32)}};var sa=Qi(["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))),Pf=sa[0],Kf=sa[1],ie=new Uint32Array(80),ae=new Uint32Array(80),Wo=class extends hr{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:d,Gh:h,Gl:b,Hh:E,Hl:p}=this;return[t,r,n,o,s,i,a,c,u,f,l,d,h,b,E,p]}set(t,r,n,o,s,i,a,c,u,f,l,d,h,b,E,p){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=d|0,this.Gh=h|0,this.Gl=b|0,this.Hh=E|0,this.Hl=p|0}process(t,r){for(let _=0;_<16;_++,r+=4)ie[_]=t.getUint32(r),ae[_]=t.getUint32(r+=4);for(let _=16;_<80;_++){let L=ie[_-15]|0,R=ae[_-15]|0,P=ye(L,R,1)^ye(L,R,8)^zo(L,R,7),D=be(L,R,1)^be(L,R,8)^Vo(L,R,7),T=ie[_-2]|0,K=ae[_-2]|0,N=ye(T,K,19)^pr(T,K,61)^zo(T,K,6),k=be(T,K,19)^mr(T,K,61)^Vo(T,K,6),m=ea(D,k,ae[_-7],ae[_-16]),g=ra(m,P,N,ie[_-7],ie[_-16]);ie[_]=g|0,ae[_]=m|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:d,Fh:h,Fl:b,Gh:E,Gl:p,Hh:y,Hl:v}=this;for(let _=0;_<80;_++){let L=ye(l,d,14)^ye(l,d,18)^pr(l,d,41),R=be(l,d,14)^be(l,d,18)^mr(l,d,41),P=l&h^~l&E,D=d&b^~d&p,T=na(v,R,D,Kf[_],ae[_]),K=oa(T,y,L,P,Pf[_],ie[_]),N=T|0,k=ye(n,o,28)^pr(n,o,34)^pr(n,o,39),m=be(n,o,28)^mr(n,o,34)^mr(n,o,39),g=n&s^n&a^s&a,S=o&i^o&c^i&c;y=E|0,v=p|0,E=h|0,p=b|0,h=l|0,b=d|0,{h:l,l:d}=qt(u|0,f|0,K|0,N|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let x=Ji(N,m,S);n=ta(x,K,k,g),o=x|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:l,l:d}=qt(this.Eh|0,this.El|0,l|0,d|0),{h,l:b}=qt(this.Fh|0,this.Fl|0,h|0,b|0),{h:E,l:p}=qt(this.Gh|0,this.Gl|0,E|0,p|0),{h:y,l:v}=qt(this.Hh|0,this.Hl|0,y|0,v|0),this.set(n,o,s,i,a,c,u,f,l,d,h,b,E,p,y,v)}roundClean(){jt(ie,ae)}destroy(){this.destroyed=!0,jt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},jo=class extends Wo{Ah=ct[0]|0;Al=ct[1]|0;Bh=ct[2]|0;Bl=ct[3]|0;Ch=ct[4]|0;Cl=ct[5]|0;Dh=ct[6]|0;Dl=ct[7]|0;Eh=ct[8]|0;El=ct[9]|0;Fh=ct[10]|0;Fl=ct[11]|0;Gh=ct[12]|0;Gl=ct[13]|0;Hh=ct[14]|0;Hl=ct[15]|0;constructor(){super(64)}};var Me=Mo(()=>new $o,qo(1));var nn=Mo(()=>new jo,qo(3));var z=(e,t,r)=>St(e,t,r),Yo=oe,qe=en,nt=(...e)=>Fo(...e),ze=e=>dr(e),ge=Uo,yr=e=>Zi(e),sn=BigInt(0),Zo=BigInt(1);function Ot(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new TypeError(r+"expected boolean, got type="+typeof e)}return e}function an(e){if(typeof e=="bigint"){if(!on(e))throw new RangeError("positive bigint expected, got "+e)}else Yo(e);return e}function kt(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 br(e){let t=an(e).toString(16);return t.length&1?"0"+t:t}function ia(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?sn:BigInt("0x"+e)}function we(e){return ia(en(e))}function zt(e){return ia(en(gr(St(e)).reverse()))}function cn(e,t){if(oe(t),t===0)throw new RangeError("zero length");e=an(e);let r=e.toString(16);if(r.length>t*2)throw new RangeError("number too large");return dr(r.padStart(t*2,"0"))}function Go(e,t){return cn(e,t).reverse()}function aa(e,t){if(e=z(e),t=z(t),e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function gr(e){return Uint8Array.from(z(e))}function un(e){if(typeof e!="string")throw new TypeError("ascii string expected, got "+typeof e);return Uint8Array.from(e,(t,r)=>{let n=t.charCodeAt(0);if(t.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${e[r]}" with code ${n} at position ${r}`);return n})}var on=e=>typeof e=="bigint"&&sn<=e;function Nf(e,t,r){return on(e)&&on(t)&&on(r)&&t<=e&&e<r}function Ve(e,t,r,n){if(!Nf(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function He(e){if(e<sn)throw new Error("expected non-negative bigint, got "+e);let t;for(t=0;e>sn;e>>=Zo,t+=1);return t}var wr=e=>(Zo<<BigInt(e))-Zo;function ca(e,t,r){if(oe(e,"hashLen"),oe(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=p=>new Uint8Array(p),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(e),u=n(e),f=0,l=()=>{c.fill(1),u.fill(0),f=0},d=(...p)=>r(u,nt(c,...p)),h=(p=o)=>{u=d(s,p),c=d(),p.length!==0&&(u=d(i,p),c=d())},b=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let p=0,y=[];for(;p<t;){c=d();let v=c.slice();y.push(v),p+=c.length}return nt(...y)};return(p,y)=>{l(),h(p);let v;for(;(v=y(b()))===void 0;)h();return l(),v}}function Pt(e,t={},r={}){if(Object.prototype.toString.call(e)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,i,a){if(!a&&i!=="function"&&!Object.hasOwn(e,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let c=e[s];if(a&&c===void 0)return;let u=typeof c;if(u!==i||c===null)throw new TypeError(`param "${s}" is invalid: expected ${i}, got ${u}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(t,!1),o(r,!0)}var Xo=()=>{throw new Error("not implemented")};var ut=BigInt(0),X=BigInt(1),xe=BigInt(2),da=BigInt(3),ha=BigInt(4),pa=BigInt(5),Uf=BigInt(7),ma=BigInt(8),Ff=BigInt(9),ya=BigInt(16);function tt(e,t){if(t<=ut)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=ut?r:t+r}function j(e,t,r){if(t<ut)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >ut;)n*=n,n%=r;return n}function ua(e,t){if(e===ut)throw new Error("invert: expected non-zero number");if(t<=ut)throw new Error("invert: expected positive modulus, got "+t);let r=tt(e,t),n=t,o=ut,s=X,i=X,a=ut;for(;r!==ut;){let u=n/r,f=n-r*u,l=o-i*u,d=s-a*u;n=r,r=f,o=i,s=a,i=l,a=d}if(n!==X)throw new Error("invert: does not exist");return tt(o,t)}function Qo(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function ba(e,t){let r=e,n=(r.ORDER+X)/ha,o=r.pow(t,n);return Qo(r,o,t),o}function Mf(e,t){let r=e,n=(r.ORDER-pa)/ma,o=r.mul(t,xe),s=r.pow(o,n),i=r.mul(t,s),a=r.mul(r.mul(i,xe),s),c=r.mul(i,r.sub(a,r.ONE));return Qo(r,c,t),c}function qf(e){let t=$e(e),r=ga(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+Uf)/ya;return((a,c)=>{let u=a,f=u.pow(c,i),l=u.mul(f,n),d=u.mul(f,o),h=u.mul(f,s),b=u.eql(u.sqr(l),c),E=u.eql(u.sqr(d),c);f=u.cmov(f,l,b),l=u.cmov(h,d,E);let p=u.eql(u.sqr(l),c),y=u.cmov(f,l,p);return Qo(u,y,c),y})}function ga(e){if(e<da)throw new Error("sqrt is not defined for small field");let t=e-X,r=0;for(;t%xe===ut;)t/=xe,r++;let n=xe,o=$e(e);for(;fa(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return ba;let s=o.pow(n,t),i=(t+X)/xe;return function(c,u){let f=c;if(f.is0(u))return u;if(fa(f,u)!==1)throw new Error("Cannot find square root");let l=r,d=f.mul(f.ONE,s),h=f.pow(u,t),b=f.pow(u,i);for(;!f.eql(h,f.ONE);){if(f.is0(h))return f.ZERO;let E=1,p=f.sqr(h);for(;!f.eql(p,f.ONE);)if(E++,p=f.sqr(p),E===l)throw new Error("Cannot find square root");let y=X<<BigInt(l-E-1),v=f.pow(d,y);l=E,d=f.sqr(v),h=f.mul(h,d),b=f.mul(b,v)}return b}}function zf(e){return e%ha===da?ba:e%ma===pa?Mf:e%ya===Ff?qf(e):ga(e)}var Yt=(e,t)=>(tt(e,t)&X)===X,Vf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Jo(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=Vf.reduce((n,o)=>(n[o]="function",n),t);if(Pt(e,r),kt(e.BYTES,"BYTES"),kt(e.BITS,"BITS"),e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=X)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function Hf(e,t,r){let n=e;if(r<ut)throw new Error("invalid exponent, negatives unsupported");if(r===ut)return n.ONE;if(r===X)return t;let o=n.ONE,s=t;for(;r>ut;)r&X&&(o=n.mul(o,s)),s=n.sqr(s),r>>=X;return o}function xr(e,t,r=!1){let n=e,o=new Array(t.length).fill(r?n.ZERO:void 0),s=t.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return t.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),i),o}function fa(e,t){let r=e,n=(r.ORDER-X)/xe,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 $f(e,t){if(t!==void 0&&Yo(t),e<=ut)throw new Error("invalid n length: expected positive n, got "+e);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let r=He(e);if(t!==void 0&&t<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${t})`);let n=t!==void 0?t:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var la=new WeakMap,fn=class{ORDER;BITS;BYTES;isLE;ZERO=ut;ONE=X;_lengths;_mod;constructor(t,r={}){if(t<=X)throw new Error("invalid field: expected ORDER > 1, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=$f(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 tt(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return ut<=t&&t<this.ORDER}is0(t){return t===ut}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&X)===X}neg(t){return tt(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return tt(t*t,this.ORDER)}add(t,r){return tt(t+r,this.ORDER)}sub(t,r){return tt(t-r,this.ORDER)}mul(t,r){return tt(t*r,this.ORDER)}pow(t,r){return Hf(this,t,r)}div(t,r){return tt(t*ua(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 ua(t,this.ORDER)}sqrt(t){let r=la.get(this);return r||la.set(this,r=zf(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?Go(t,this.BYTES):cn(t,this.BYTES)}fromBytes(t,r=!1){z(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?zt(t):we(t);if(a&&(c=tt(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return xr(this,t)}cmov(t,r,n){return Ot(n,"condition"),n?r:t}};Object.freeze(fn.prototype);function $e(e,t={}){return new fn(e,t)}function wa(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=X)throw new Error("field order must be greater than 1");let t=He(e-X);return Math.ceil(t/8)}function ts(e){let t=wa(e);return t+Math.ceil(t/2)}function es(e,t,r=!1){z(e);let n=e.length,o=wa(t),s=Math.max(ts(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?zt(e):we(e),a=tt(i,t-X)+X;return r?Go(a,o):cn(a,o)}var We=BigInt(0),Ee=BigInt(1);function Er(e,t){let r=t.negate();return e?r:t}function ve(e,t){let r=xr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Sa(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function rs(e,t){Sa(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=wr(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function xa(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(e&o),c=e>>i;a>n&&(a-=s,c+=Ee);let u=t*n,f=u+Math.abs(a)-1,l=a===0,d=a<0,h=t%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:d,isNegF:h,offsetF:u}}var ns=new WeakMap,Aa=new WeakMap;function os(e){return Aa.get(e)||1}function Ea(e){if(e!==We)throw new Error("invalid wNAF")}var je=class{BASE;ZERO;Fn;bits;constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>We;)r&Ee&&(n=n.add(o)),o=o.double(),r>>=Ee;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=rs(r,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let u=1;u<o;u++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=rs(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:l,isNegF:d,offsetF:h}=xa(n,a,i);n=c,f?s=s.add(Er(d,r[h])):o=o.add(Er(l,r[u]))}return Ea(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=rs(t,this.bits);for(let i=0;i<s.windows&&n!==We;i++){let{nextN:a,offset:c,isZero:u,isNeg:f}=xa(n,i,s);if(n=a,!u){let l=r[c];o=o.add(f?l.negate():l)}}return Ea(n),o}getPrecomputes(t,r,n){let o=ns.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),ns.set(r,o))),o}cached(t,r,n){let o=os(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=os(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){Sa(r,this.bits),Aa.set(t,r),ns.delete(t)}hasCache(t){return os(t)!==1}};function _a(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>We||n>We;)r&Ee&&(s=s.add(o)),n&Ee&&(i=i.add(o)),o=o.double(),r>>=Ee,n>>=Ee;return{p1:s,p2:i}}function va(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Jo(t),t}else return $e(e,{isLE:r})}function ln(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let c of["p","n","h"]){let u=t[c];if(!(typeof u=="bigint"&&u>We))throw new Error(`CURVE.${c} must be positive bigint`)}let o=va(t.p,r.Fp,n),s=va(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 dn(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var ce=BigInt(0),it=BigInt(1),ss=BigInt(2),Wf=BigInt(8);function jf(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 Ta(e,t={}){let r=t,n=ln("edwards",e,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;Pt(r,{},{uvRatio:"function"});let c=ss<<BigInt(s.BYTES*8)-it,u=E=>o.create(E),f=r.uvRatio===void 0?(E,p)=>{try{return{isValid:!0,value:o.sqrt(o.div(E,p))}}catch{return{isValid:!1,value:ce}}}:r.uvRatio;if(!jf(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function l(E,p,y=!1){let v=y?it:ce;return Ve("coordinate "+E,p,v,c),p}function d(E){if(!(E instanceof h))throw new Error("EdwardsPoint expected")}class h{static BASE=new h(i.Gx,i.Gy,it,u(i.Gx*i.Gy));static ZERO=new h(ce,it,it,ce);static Fp=o;static Fn=s;X;Y;Z;T;constructor(p,y,v,_){this.X=l("x",p),this.Y=l("y",y),this.Z=l("z",v,!0),this.T=l("t",_),Object.freeze(this)}static CURVE(){return i}static fromAffine(p){if(p instanceof h)throw new Error("extended point not allowed");let{x:y,y:v}=p||{};return l("x",y),l("y",v),new h(y,v,it,u(y*v))}static fromBytes(p,y=!1){let v=o.BYTES,{a:_,d:L}=i;p=gr(z(p,v,"point")),Ot(y,"zip215");let R=gr(p),P=p[v-1];R[v-1]=P&-129;let D=zt(R),T=y?c:o.ORDER;Ve("point.y",D,ce,T);let K=u(D*D),N=u(K-it),k=u(L*K-_),{isValid:m,value:g}=f(N,k);if(!m)throw new Error("bad point: invalid y coordinate");let S=(g&it)===it,x=(P&128)!==0;if(!y&&g===ce&&x)throw new Error("bad point: x=0 and x_0=1");return x!==S&&(g=u(-g)),h.fromAffine({x:g,y:D})}static fromHex(p,y=!1){return h.fromBytes(ze(p),y)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=8,y=!0){return b.createCache(this,p),y||this.multiply(ss),this}assertValidity(){let p=this,{a:y,d:v}=i;if(p.is0())throw new Error("bad point: ZERO");let{X:_,Y:L,Z:R,T:P}=p,D=u(_*_),T=u(L*L),K=u(R*R),N=u(K*K),k=u(D*y),m=u(K*u(k+T)),g=u(N+u(v*u(D*T)));if(m!==g)throw new Error("bad point: equation left != right (1)");let S=u(_*L),x=u(R*P);if(S!==x)throw new Error("bad point: equation left != right (2)")}equals(p){d(p);let{X:y,Y:v,Z:_}=this,{X:L,Y:R,Z:P}=p,D=u(y*P),T=u(L*_),K=u(v*P),N=u(R*_);return D===T&&K===N}is0(){return this.equals(h.ZERO)}negate(){return new h(u(-this.X),this.Y,this.Z,u(-this.T))}double(){let{a:p}=i,{X:y,Y:v,Z:_}=this,L=u(y*y),R=u(v*v),P=u(ss*u(_*_)),D=u(p*L),T=y+v,K=u(u(T*T)-L-R),N=D+R,k=N-P,m=D-R,g=u(K*k),S=u(N*m),x=u(K*m),w=u(k*N);return new h(g,S,w,x)}add(p){d(p);let{a:y,d:v}=i,{X:_,Y:L,Z:R,T:P}=this,{X:D,Y:T,Z:K,T:N}=p,k=u(_*D),m=u(L*T),g=u(P*v*N),S=u(R*K),x=u((_+L)*(D+T)-k-m),w=S-g,A=S+g,B=u(m-y*k),I=u(x*w),C=u(A*B),O=u(x*B),F=u(w*A);return new h(I,C,F,O)}subtract(p){return d(p),this.add(p.negate())}multiply(p){if(!s.isValidNot0(p))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:y,f:v}=b.cached(this,p,_=>ve(h,_));return ve(h,[y,v])[0]}multiplyUnsafe(p){if(!s.isValid(p))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return p===ce?h.ZERO:this.is0()||p===it?this:b.unsafe(this,p,y=>ve(h,y))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return b.unsafe(this,i.n).is0()}toAffine(p){let y=this,v=p,{X:_,Y:L,Z:R}=y,P=y.is0();v==null&&(v=P?Wf:o.inv(R));let D=u(_*v),T=u(L*v),K=o.mul(R,v);if(P)return{x:ce,y:it};if(K!==it)throw new Error("invZ was invalid");return{x:D,y:T}}clearCofactor(){return a===it?this:this.multiplyUnsafe(a)}toBytes(){let{x:p,y}=this.toAffine(),v=o.toBytes(y);return v[v.length-1]|=p&it?128:0,v}toHex(){return qe(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let b=new je(h,s.BITS);return s.BITS>=8&&h.BASE.precompute(8),Object.freeze(h.prototype),Object.freeze(h),h}var hn=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(t){this.ep=t}static fromBytes(t){Xo()}static fromHex(t){Xo()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return qe(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.ep.precompute(t,r),this}};function Ia(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=r;Pt(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=e,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(kt(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=o.randomBytes===void 0?yr:o.randomBytes,d=o.adjustScalarBytes===void 0?m=>m:o.adjustScalarBytes,h=o.domain===void 0?(m,g,S)=>{if(Ot(S,"phflag"),g.length||S)throw new Error("Contexts/pre-hash are not supported");return m}:o.domain;function b(m){return c.create(zt(m))}function E(m){let g=D.secretKey;z(m,D.secretKey,"secretKey");let S=z(n(m),2*g,"hashedSecretKey"),x=d(S.slice(0,g)),w=S.slice(g,2*g),A=b(x);return{head:x,prefix:w,scalar:A}}function p(m){let{head:g,prefix:S,scalar:x}=E(m),w=i.multiply(x),A=w.toBytes();return{head:g,prefix:S,scalar:x,point:w,pointBytes:A}}function y(m){return p(m).pointBytes}function v(m=Uint8Array.of(),...g){let S=nt(...g);return b(n(h(S,z(m,void 0,"context"),!!s)))}function _(m,g,S={}){m=z(m,void 0,"message"),s&&(m=s(m));let{prefix:x,scalar:w,pointBytes:A}=p(g),B=v(S.context,x,m),I=i.multiply(B).toBytes(),C=v(S.context,I,A,m),O=c.create(B+C*w);if(!c.isValid(O))throw new Error("sign failed: invalid s");let F=nt(I,c.toBytes(O));return z(F,D.signature,"result")}let L={zip215:o.zip215};function R(m,g,S,x=L){let{context:w}=x,A=x.zip215===void 0?!!L.zip215:x.zip215,B=D.signature;m=z(m,B,"signature"),g=z(g,void 0,"message"),S=z(S,D.publicKey,"publicKey"),A!==void 0&&Ot(A,"zip215"),s&&(g=s(g));let I=B/2,C=m.subarray(0,I),O=zt(m.subarray(I,B)),F,V,U;try{F=e.fromBytes(S,A),V=e.fromBytes(C,A),U=i.multiplyUnsafe(O)}catch{return!1}if(!A&&F.isSmallOrder())return!1;let rt=v(w,C,S,g);return V.add(F.multiplyUnsafe(rt)).subtract(U).clearCofactor().is0()}let P=a.BYTES,D={secretKey:P,publicKey:P,signature:2*P,seed:P};function T(m){return m=m===void 0?l(D.seed):m,z(m,D.seed,"seed")}function K(m){return ge(m)&&m.length===D.secretKey}function N(m,g){try{return!!e.fromBytes(m,g===void 0?L.zip215:g)}catch{return!1}}let k={getExtendedPublicKey:p,randomSecretKey:T,isValidSecretKey:K,isValidPublicKey:N,toMontgomery(m){let{y:g}=e.fromBytes(m),S=D.publicKey,x=S===32;if(!x&&S!==57)throw new Error("only defined for 25519 and 448");let w=x?a.div(it+g,it-g):a.div(g-it,g+it);return a.toBytes(w)},toMontgomerySecret(m){let g=D.secretKey;z(m,g);let S=n(m.subarray(0,g));return d(S).subarray(0,g)}};return Object.freeze(D),Object.freeze(k),Object.freeze({keygen:dn(T,y),getPublicKey:y,sign:_,verify:R,utils:k,Point:e,lengths:D})}function vr(e,t){if(kt(e),kt(t),t<0||t>4)throw new Error("invalid I2OSP length: "+t);if(e<0||e>2**(8*t)-1)throw new Error("invalid I2OSP input: "+e);let r=Array.from({length:t}).fill(0);for(let n=t-1;n>=0;n--)r[n]=e&255,e>>>=8;return new Uint8Array(r)}function Zf(e,t){let r=new Uint8Array(e.length);for(let n=0;n<e.length;n++)r[n]=e[n]^t[n];return r}function Yf(e){if(!ge(e)&&typeof e!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof e=="string"?un(e):e;if(t.length===0)throw new Error("DST must be non-empty");return t}function is(e,t,r,n){z(e),kt(r),t=Yf(t),t.length>255&&(t=n(nt(un("H2C-OVERSIZE-DST-"),t)));let{outputLen:o,blockLen:s}=n,i=Math.ceil(r/o);if(r>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=nt(t,vr(t.length,1)),c=new Uint8Array(s),u=vr(r,2),f=new Array(i),l=n(nt(c,e,u,vr(0,1),a));f[0]=n(nt(l,vr(1,1),a));for(let h=1;h<i;h++){let b=[Zf(l,f[h-1]),vr(h+1,1),a];f[h]=n(nt(...b))}return nt(...f).slice(0,r)}var Ba="HashToScalar-";var Gf=BigInt(0),Gt=BigInt(1),Ra=BigInt(2);var Xf=BigInt(5),Qf=BigInt(8),Ze=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),fs={p:Ze,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Qf,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Jf(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Ze,a=e*e%s*e%s,c=j(a,Ra,s)*a%s,u=j(c,Gt,s)*e%s,f=j(u,Xf,s)*u%s,l=j(f,t,s)*f%s,d=j(l,r,s)*l%s,h=j(d,n,s)*d%s,b=j(h,o,s)*h%s,E=j(b,o,s)*h%s,p=j(E,t,s)*f%s;return{pow_p_5_8:j(p,Ra,s)*e%s,b2:a}}function tl(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var as=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function ls(e,t){let r=Ze,n=tt(t*t*t,r),o=tt(n*n*t,r),s=Jf(e*o).pow_p_5_8,i=tt(e*n*s,r),a=tt(t*i*i,r),c=i,u=tt(i*as,r),f=a===e,l=a===tt(-e,r),d=a===tt(-e*as,r);return f&&(i=c),(l||d)&&(i=u),Yt(i,r)&&(i=tt(-i,r)),{isValid:f||l,value:i}}var fe=Ta(fs,{uvRatio:ls}),ue=fe.Fp,Da=fe.Fn;function el(e){return Ia(fe,nn,Object.assign({adjustScalarBytes:tl,zip215:!0},e))}var Oa=el({});var cs=as,rl=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),nl=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),ol=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),sl=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Ca=e=>ls(Gt,e),il=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),us=e=>ue.create(zt(e)&il);function La(e){let{d:t}=fs,r=Ze,n=y=>ue.create(y),o=n(cs*e*e),s=n((o+Gt)*ol),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:c,value:u}=ls(s,a),f=n(u*e);Yt(f,r)||(f=n(-f)),c||(u=f),c||(i=o);let l=n(i*(o-Gt)*sl-a),d=u*u,h=n((u+u)*a),b=n(l*rl),E=n(Gt-d),p=n(Gt+d);return new fe(n(h*p),n(E*b),n(b*p),n(h*E))}var le=class e extends hn{static BASE=new e(fe.BASE);static ZERO=new e(fe.ZERO);static Fp=ue;static Fn=Da;constructor(t){super(t)}static fromAffine(t){return new e(fe.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static fromBytes(t){St(t,32);let{a:r,d:n}=fs,o=Ze,s=L=>ue.create(L),i=us(t);if(!aa(ue.toBytes(i),t)||Yt(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(Gt+r*a),u=s(Gt-r*a),f=s(c*c),l=s(u*u),d=s(r*n*f-l),{isValid:h,value:b}=Ca(s(d*l)),E=s(b*u),p=s(b*E*d),y=s((i+i)*E);Yt(y,o)&&(y=s(-y));let v=s(c*p),_=s(y*v);if(!h||Yt(_,o)||v===Gf)throw new Error("invalid ristretto255 encoding 2");return new e(new fe(y,v,Gt,_))}static fromHex(t){return e.fromBytes(dr(t))}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=Ze,i=p=>ue.create(p),a=i(i(n+r)*i(n-r)),c=i(t*r),u=i(c*c),{value:f}=Ca(i(a*u)),l=i(f*a),d=i(f*c),h=i(l*d*o),b;if(Yt(o*h,s)){let p=i(r*cs),y=i(t*cs);t=p,r=y,b=i(l*nl)}else b=d;Yt(t*h,s)&&(r=i(-r));let E=i((n-r)*b);return Yt(E,s)&&(E=i(-E)),ue.toBytes(E)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=u=>ue.create(u),a=i(r*s)===i(n*o),c=i(n*s)===i(r*o);return a||c}is0(){return this.equals(e.ZERO)}};Object.freeze(le.BASE);Object.freeze(le.ZERO);Object.freeze(le.prototype);Object.freeze(le);var al=Object.freeze({Point:le,hashToCurve(e,t){let r=t?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":t.DST,n=is(e,r,64,nn);return al.deriveToCurve(n)},hashToScalar(e,t={DST:Ba}){let r=is(e,t.DST,64,nn);return Da.create(zt(r))},deriveToCurve(e){St(e,64);let t=us(e.subarray(0,32)),r=La(t),n=us(e.subarray(32,64)),o=La(n);return new le(r.add(o))}});var Sr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},pn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Bt={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new pn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var mn=32;var ds,cl=(async()=>{try{return await Bt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function ul(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Bt.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Bt.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 fl(e,t,r){return Oa.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function ka(e,t,r){return ds==null&&(ds=await cl),ds?ul(e,t,r):fl(e,t,r)}function yn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var bn=class{type="Ed25519";raw;constructor(t){this.raw=hs(t,mn)}toMultihash(){return Lt.digest(It(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=ka(this.raw,r,t);return yn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function ps(e){return e=hs(e,mn),new bn(e)}function hs(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new M(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var dl=Math.pow(2,7),hl=Math.pow(2,14),pl=Math.pow(2,21),ms=Math.pow(2,28),ys=Math.pow(2,35),bs=Math.pow(2,42),gs=Math.pow(2,49),$=128,dt=127;function Rt(e){if(e<dl)return 1;if(e<hl)return 2;if(e<pl)return 3;if(e<ms)return 4;if(e<ys)return 5;if(e<bs)return 6;if(e<gs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ye(e,t,r=0){switch(Rt(e)){case 8:t[r++]=e&255|$,e/=128;case 7:t[r++]=e&255|$,e/=128;case 6:t[r++]=e&255|$,e/=128;case 5:t[r++]=e&255|$,e/=128;case 4:t[r++]=e&255|$,e>>>=7;case 3:t[r++]=e&255|$,e>>>=7;case 2:t[r++]=e&255|$,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function ml(e,t,r=0){switch(Rt(e)){case 8:t.set(r++,e&255|$),e/=128;case 7:t.set(r++,e&255|$),e/=128;case 6:t.set(r++,e&255|$),e/=128;case 5:t.set(r++,e&255|$),e/=128;case 4:t.set(r++,e&255|$),e>>>=7;case 3:t.set(r++,e&255|$),e>>>=7;case 2:t.set(r++,e&255|$),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function ws(e,t){let r=e[t],n=0;if(n+=r&dt,r<$||(r=e[t+1],n+=(r&dt)<<7,r<$)||(r=e[t+2],n+=(r&dt)<<14,r<$)||(r=e[t+3],n+=(r&dt)<<21,r<$)||(r=e[t+4],n+=(r&dt)*ms,r<$)||(r=e[t+5],n+=(r&dt)*ys,r<$)||(r=e[t+6],n+=(r&dt)*bs,r<$)||(r=e[t+7],n+=(r&dt)*gs,r<$))return n;throw new RangeError("Could not decode varint")}function yl(e,t){let r=e.get(t),n=0;if(n+=r&dt,r<$||(r=e.get(t+1),n+=(r&dt)<<7,r<$)||(r=e.get(t+2),n+=(r&dt)<<14,r<$)||(r=e.get(t+3),n+=(r&dt)<<21,r<$)||(r=e.get(t+4),n+=(r&dt)*ms,r<$)||(r=e.get(t+5),n+=(r&dt)*ys,r<$)||(r=e.get(t+6),n+=(r&dt)*bs,r<$)||(r=e.get(t+7),n+=(r&dt)*gs,r<$))return n;throw new RangeError("Could not decode varint")}function gn(e,t,r=0){return t==null&&(t=lt(Rt(e))),t instanceof Uint8Array?Ye(e,t,r):ml(e,t,r)}function xs(e,t=0){return e instanceof Uint8Array?ws(e,t):yl(e,t)}var Es=new Float32Array([-0]),de=new Uint8Array(Es.buffer);function Na(e,t,r){Es[0]=e,t[r]=de[0],t[r+1]=de[1],t[r+2]=de[2],t[r+3]=de[3]}function Ua(e,t){return de[0]=e[t],de[1]=e[t+1],de[2]=e[t+2],de[3]=e[t+3],Es[0]}var vs=new Float64Array([-0]),ht=new Uint8Array(vs.buffer);function Fa(e,t,r){vs[0]=e,t[r]=ht[0],t[r+1]=ht[1],t[r+2]=ht[2],t[r+3]=ht[3],t[r+4]=ht[4],t[r+5]=ht[5],t[r+6]=ht[6],t[r+7]=ht[7]}function Ma(e,t){return ht[0]=e[t],ht[1]=e[t+1],ht[2]=e[t+2],ht[3]=e[t+3],ht[4]=e[t+4],ht[5]=e[t+5],ht[6]=e[t+6],ht[7]=e[t+7],vs[0]}var bl=BigInt(Number.MAX_SAFE_INTEGER),gl=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 Se;if(t<bl&&t>gl)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>qa&&(o=0n,++n>qa&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return Se;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):Se}},Se=new At(0,0);Se.toBigInt=function(){return 0n};Se.zzEncode=Se.zzDecode=function(){return this};Se.length=function(){return 1};var qa=4294967296n;function za(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 Va(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 Ss(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Kt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function wn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var As=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,Kt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Kt(this,4);return wn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Kt(this,4);return wn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Kt(this,4);let t=Ua(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Kt(this,4);let t=Ma(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Kt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Va(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Kt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Kt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new 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 Kt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Kt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Kt(this,8);let t=wn(this.buf,this.pos+=4),r=wn(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=ws(this.buf,this.pos);return this.pos+=Rt(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 Ar(e){return new As(e instanceof Uint8Array?e:e.subarray())}function yt(e,t,r){let n=Ar(e);return t.decode(n,void 0,r)}function _s(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return lt(i);o+i>t&&(n=lt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Ae=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Ts(){}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}},wl=_s();function xl(e){return globalThis.Buffer!=null?lt(e):wl(e)}var Tr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ae(Ts,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new Ae(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Rs((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(xn,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(xn,r.length(),r)}uint64Number(t){return this._push(Ye,Rt(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(xn,r.length(),r)}sint64Number(t){let r=At.fromNumber(t).zzEncode();return this._push(xn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Is,1,t?1:0)}fixed32(t){return this._push(_r,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=At.fromBigInt(t);return this._push(_r,4,r.lo)._push(_r,4,r.hi)}fixed64Number(t){let r=At.fromNumber(t);return this._push(_r,4,r.lo)._push(_r,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(Na,4,t)}double(t){return this._push(Fa,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Is,1,0):this.uint32(r)._push(vl,r,t)}string(t){let r=za(t);return r!==0?this.uint32(r)._push(Ss,r,t):this._push(Is,1,0)}fork(){return this.states=new Bs(this),this.head=this.tail=new Ae(Ts,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 Ae(Ts,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=xl(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Is(e,t,r){t[r]=e&255}function El(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Rs=class extends Ae{next;constructor(t,r){super(El,t,r),this.next=void 0}};function xn(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 _r(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 vl(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Tr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Sl,t,e),this},Tr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Al,t,e),this});function Sl(e,t,r){t.set(e,r)}function Al(e,t,r){e.length<40?Ss(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(H(e),r)}function Cs(){return new Tr}function bt(e,t){let r=Cs();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*gt(e,t,r){let n=Ar(e);yield*t.stream(n,void 0,"$",r)}var En={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function vn(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function Ls(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 vn("enum",En.VARINT,r,n,o)}function wt(e,t,r){return vn("message",En.LENGTH_DELIMITED,e,t,r)}var Ct=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},Ir=class extends Error{code="ERR_MAX_SIZE";name="MaxSizeError"};var Z;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(Z||(Z={}));var Ds;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Ds||(Ds={}));(function(e){e.codec=()=>Ls(Ds)})(Z||(Z={}));var Vt;(function(e){let t;e.codec=()=>(t==null&&(t=wt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),Z.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=Z.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:Z.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return 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})(Vt||(Vt={}));var Os;(function(e){let t;e.codec=()=>(t==null&&(t=wt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),Z.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=Z.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:Z.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return 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})(Os||(Os={}));var Rr={};Et(Rr,{MAX_RSA_KEY_SIZE:()=>ks,generateRSAKeyPair:()=>Ya,jwkToJWKKeyPair:()=>Ga,jwkToPkcs1:()=>Bl,jwkToPkix:()=>Us,jwkToRSAPrivateKey:()=>zs,pkcs1MessageToJwk:()=>Ks,pkcs1MessageToRSAPrivateKey:()=>Fs,pkcs1ToJwk:()=>Il,pkcs1ToRSAPrivateKey:()=>Za,pkixMessageToJwk:()=>Ns,pkixMessageToRSAPublicKey:()=>qs,pkixToJwk:()=>Rl,pkixToRSAPublicKey:()=>Ms});var Ge=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Rr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return et.createV1(114,this._multihash)}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}verify(t,r,n){return ja(this.jwk,r,t,n)}},Br=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Rr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}sign(t,r){return Wa(this.jwk,t,r)}};var ks=8192,Ps=18,_l=1062,Tl=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Il(e){let t=$t(e);return Ks(t)}function Ks(e){return{n:q(e[1],"base64url"),e:q(e[2],"base64url"),d:q(e[3],"base64url"),p:q(e[4],"base64url"),q:q(e[5],"base64url"),dp:q(e[6],"base64url"),dq:q(e[7],"base64url"),qi:q(e[8],"base64url"),kty:"RSA"}}function Bl(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 M("JWK was missing components");return ne([vt(Uint8Array.from([0])),vt(H(e.n,"base64url")),vt(H(e.e,"base64url")),vt(H(e.d,"base64url")),vt(H(e.p,"base64url")),vt(H(e.q,"base64url")),vt(H(e.dp,"base64url")),vt(H(e.dq,"base64url")),vt(H(e.qi,"base64url"))]).subarray()}function Rl(e){let t=$t(e,{offset:0});return Ns(t)}function Ns(e){let t=$t(e[1],{offset:0});return{kty:"RSA",n:q(t[0],"base64url"),e:q(t[1],"base64url")}}function Us(e){if(e.n==null||e.e==null)throw new M("JWK was missing components");return ne([Tl,Xr(ne([vt(H(e.n,"base64url")),vt(H(e.e,"base64url"))]))]).subarray()}function Za(e){let t=$t(e);return Fs(t)}function Fs(e){let t=Ks(e);return zs(t)}function Ms(e,t){if(e.byteLength>=_l)throw new Ce("Key size is too large");let r=$t(e,{offset:0});return qs(r,e,t)}function qs(e,t,r){let n=Ns(e);if(r==null){let o=Me(Vt.encode({Type:Z.RSA,Data:t}));r=Ft(Ps,o)}return new Ge(n,r)}function zs(e){if(Qa(e)>ks)throw new M("Key size is too large");let t=Ga(e),r=Me(Vt.encode({Type:Z.RSA,Data:Us(t.publicKey)})),n=Ft(Ps,r);return new Br(t.privateKey,new Ge(t.publicKey,n))}async function Ya(e){if(e>ks)throw new M("Key size is too large");let t=await Xa(e),r=Me(Vt.encode({Type:Z.RSA,Data:Us(t.publicKey)})),n=Ft(Ps,r);return new Br(t.privateKey,new Ge(t.publicKey,n))}function Ga(e){if(e==null)throw new M("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function Xa(e,t){let r=await Bt.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 Cl(r,t);return{privateKey:n[0],publicKey:n[1]}}async function Wa(e,t,r){let n=await Bt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Bt.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 ja(e,t,r,n){let o=await Bt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Bt.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 Cl(e,t){if(e.privateKey==null||e.publicKey==null)throw new M("Private and public key are required");let r=await Promise.all([Bt.get().subtle.exportKey("jwk",e.privateKey),Bt.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function Qa(e){if(e.kty!=="RSA")throw new M("invalid key type");if(e.n==null)throw new M("invalid key modulus");return H(e.n,"base64url").length*8}var Sn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(Qr(t),St(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),jt(o)}update(t){return Fe(this),this.iHash.update(t),this}digestInto(t){Fe(this),Jr(t,this),this.finished=!0;let r=t.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ja=(()=>{let e=((t,r,n)=>new Sn(t,r).update(n).digest());return e.create=(t,r)=>new Sn(t,r),e})();var tc=(e,t)=>(e+(e>=0?t:-t)/ec)/t;function Ll(e,t,r){Ve("scalar",e,Ht,r);let[[n,o],[s,i]]=t,a=tc(i*e,r),c=tc(-o*e,r),u=e-a*n-c*s,f=-a*o-c*i,l=u<Ht,d=f<Ht;l&&(u=-u),d&&(f=-f);let h=wr(Math.ceil(He(r)/2))+he;if(u<Ht||u>=h||f<Ht||f>=h)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:d,k2:f}}function Hs(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Vs(e,t){Pt(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return Ot(r.lowS,"lowS"),Ot(r.prehash,"prehash"),r.format!==void 0&&Hs(r.format),r}var $s=class extends Error{constructor(t=""){super(t)}},Nt={Err:$s,_tlv:{encode:(e,t)=>{let{Err:r}=Nt;if(kt(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(typeof t!="string")throw new TypeError('"data" expected string, got type='+typeof t);if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=br(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?br(o.length/2|128):"";return br(e)+s+o+t},decode(e,t){let{Err:r}=Nt;t=z(t,void 0,"DER data");let n=0;if(e<0||e>255)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Nt;if(an(e),e<Ht)throw new t("integer: negative integers are not allowed");let r=br(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}=Nt;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 we(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Nt,o=z(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}=Nt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}};Object.freeze(Nt._tlv);Object.freeze(Nt._int);Object.freeze(Nt);var Ht=BigInt(0),he=BigInt(1),ec=BigInt(2),An=BigInt(3),Dl=BigInt(4);function rc(e,t={}){let r=ln("weierstrass",e,t),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;Pt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c,allowInfinityPoint:u}=t;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=oc(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function d(k,m,g){if(u&&m.is0())return Uint8Array.of(0);let{x:S,y:x}=m.toAffine(),w=n.toBytes(S);if(Ot(g,"isCompressed"),g){l();let A=!n.isOdd(x);return nt(nc(A),w)}else return nt(Uint8Array.of(4),w,n.toBytes(x))}function h(k){z(k,void 0,"Point");let{publicKey:m,publicKeyUncompressed:g}=f,S=k.length,x=k[0],w=k.subarray(1);if(u&&S===1&&x===0)return{x:n.ZERO,y:n.ZERO};if(S===m&&(x===2||x===3)){let A=n.fromBytes(w);if(!n.isValid(A))throw new Error("bad point: is not on curve, wrong x");let B=p(A),I;try{I=n.sqrt(B)}catch(F){let V=F instanceof Error?": "+F.message:"";throw new Error("bad point: is not on curve, sqrt error"+V)}l();let C=n.isOdd(I);return(x&1)===1!==C&&(I=n.neg(I)),{x:A,y:I}}else if(S===g&&x===4){let A=n.BYTES,B=n.fromBytes(w.subarray(0,A)),I=n.fromBytes(w.subarray(A,A*2));if(!y(B,I))throw new Error("bad point: is not on curve");return{x:B,y:I}}else throw new Error(`bad point: got length ${S}, expected compressed=${m} or uncompressed=${g}`)}let b=t.toBytes===void 0?d:t.toBytes,E=t.fromBytes===void 0?h:t.fromBytes;function p(k){let m=n.sqr(k),g=n.mul(m,k);return n.add(n.add(g,n.mul(k,s.a)),s.b)}function y(k,m){let g=n.sqr(m),S=p(k);return n.eql(g,S)}if(!y(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let v=n.mul(n.pow(s.a,An),Dl),_=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(v,_)))throw new Error("bad curve params: a or b");function L(k,m,g=!1){if(!n.isValid(m)||g&&n.is0(m))throw new Error(`bad point coordinate ${k}`);return m}function R(k){if(!(k instanceof T))throw new Error("Weierstrass Point expected")}function P(k){if(!c||!c.basises)throw new Error("no endo");return Ll(k,c.basises,o.ORDER)}function D(k,m,g,S,x){return g=new T(n.mul(g.X,k),g.Y,g.Z),m=Er(S,m),g=Er(x,g),m.add(g)}class T{static BASE=new T(s.Gx,s.Gy,n.ONE);static ZERO=new T(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(m,g,S){this.X=L("x",m),this.Y=L("y",g,!0),this.Z=L("z",S),Object.freeze(this)}static CURVE(){return s}static fromAffine(m){let{x:g,y:S}=m||{};if(!m||!n.isValid(g)||!n.isValid(S))throw new Error("invalid affine point");if(m instanceof T)throw new Error("projective point not allowed");return n.is0(g)&&n.is0(S)?T.ZERO:new T(g,S,n.ONE)}static fromBytes(m){let g=T.fromAffine(E(z(m,void 0,"point")));return g.assertValidity(),g}static fromHex(m){return T.fromBytes(ze(m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,g=!0){return N.createCache(this,m),g||this.multiply(An),this}assertValidity(){let m=this;if(m.is0()){if(t.allowInfinityPoint&&n.is0(m.X)&&n.eql(m.Y,n.ONE)&&n.is0(m.Z))return;throw new Error("bad point: ZERO")}let{x:g,y:S}=m.toAffine();if(!n.isValid(g)||!n.isValid(S))throw new Error("bad point: x or y not field elements");if(!y(g,S))throw new Error("bad point: equation left != right");if(!m.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:m}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(m)}equals(m){R(m);let{X:g,Y:S,Z:x}=this,{X:w,Y:A,Z:B}=m,I=n.eql(n.mul(g,B),n.mul(w,x)),C=n.eql(n.mul(S,B),n.mul(A,x));return I&&C}negate(){return new T(this.X,n.neg(this.Y),this.Z)}double(){let{a:m,b:g}=s,S=n.mul(g,An),{X:x,Y:w,Z:A}=this,B=n.ZERO,I=n.ZERO,C=n.ZERO,O=n.mul(x,x),F=n.mul(w,w),V=n.mul(A,A),U=n.mul(x,w);return U=n.add(U,U),C=n.mul(x,A),C=n.add(C,C),B=n.mul(m,C),I=n.mul(S,V),I=n.add(B,I),B=n.sub(F,I),I=n.add(F,I),I=n.mul(B,I),B=n.mul(U,B),C=n.mul(S,C),V=n.mul(m,V),U=n.sub(O,V),U=n.mul(m,U),U=n.add(U,C),C=n.add(O,O),O=n.add(C,O),O=n.add(O,V),O=n.mul(O,U),I=n.add(I,O),V=n.mul(w,A),V=n.add(V,V),O=n.mul(V,U),B=n.sub(B,O),C=n.mul(V,F),C=n.add(C,C),C=n.add(C,C),new T(B,I,C)}add(m){R(m);let{X:g,Y:S,Z:x}=this,{X:w,Y:A,Z:B}=m,I=n.ZERO,C=n.ZERO,O=n.ZERO,F=s.a,V=n.mul(s.b,An),U=n.mul(g,w),rt=n.mul(S,A),ot=n.mul(x,B),st=n.add(g,S),Q=n.add(w,A);st=n.mul(st,Q),Q=n.add(U,rt),st=n.sub(st,Q),Q=n.add(g,x);let xt=n.add(w,B);return Q=n.mul(Q,xt),xt=n.add(U,ot),Q=n.sub(Q,xt),xt=n.add(S,x),I=n.add(A,B),xt=n.mul(xt,I),I=n.add(rt,ot),xt=n.sub(xt,I),O=n.mul(F,Q),I=n.mul(V,ot),O=n.add(I,O),I=n.sub(rt,O),O=n.add(rt,O),C=n.mul(I,O),rt=n.add(U,U),rt=n.add(rt,U),ot=n.mul(F,ot),Q=n.mul(V,Q),rt=n.add(rt,ot),ot=n.sub(U,ot),ot=n.mul(F,ot),Q=n.add(Q,ot),U=n.mul(rt,Q),C=n.add(C,U),U=n.mul(xt,Q),I=n.mul(st,I),I=n.sub(I,U),U=n.mul(st,rt),O=n.mul(xt,O),O=n.add(O,U),new T(I,C,O)}subtract(m){return R(m),this.add(m.negate())}is0(){return this.equals(T.ZERO)}multiply(m){let{endo:g}=t;if(!o.isValidNot0(m))throw new RangeError("invalid scalar: out of range");let S,x,w=A=>N.cached(this,A,B=>ve(T,B));if(g){let{k1neg:A,k1:B,k2neg:I,k2:C}=P(m),{p:O,f:F}=w(B),{p:V,f:U}=w(C);x=F.add(U),S=D(g.beta,O,V,A,I)}else{let{p:A,f:B}=w(m);S=A,x=B}return ve(T,[S,x])[0]}multiplyUnsafe(m){let{endo:g}=t,S=this,x=m;if(!o.isValid(x))throw new RangeError("invalid scalar: out of range");if(x===Ht||S.is0())return T.ZERO;if(x===he)return S;if(N.hasCache(this))return this.multiply(x);if(g){let{k1neg:w,k1:A,k2neg:B,k2:I}=P(x),{p1:C,p2:O}=_a(T,S,A,I);return D(g.beta,C,O,w,B)}else return N.unsafe(S,x)}toAffine(m){let g=this,S=m,{X:x,Y:w,Z:A}=g;if(n.eql(A,n.ONE))return{x,y:w};let B=g.is0();S==null&&(S=B?n.ONE:n.inv(A));let I=n.mul(x,S),C=n.mul(w,S),O=n.mul(A,S);if(B)return{x:n.ZERO,y:n.ZERO};if(!n.eql(O,n.ONE))throw new Error("invZ was invalid");return{x:I,y:C}}isTorsionFree(){let{isTorsionFree:m}=t;return i===he?!0:m?m(T,this):N.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:m}=t;return i===he?this:m?m(T,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===he?this.is0():this.clearCofactor().is0()}toBytes(m=!0){return Ot(m,"isCompressed"),this.assertValidity(),b(T,this,m)}toHex(m=!0){return qe(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let K=o.BITS,N=new je(T,t.endo?Math.ceil(K/2):K);return K>=8&&T.BASE.precompute(8),Object.freeze(T.prototype),Object.freeze(T),T}function nc(e){return Uint8Array.of(e?2:3)}function oc(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Ol(e,t={}){let{Fn:r}=e,n=t.randomBytes===void 0?yr:t.randomBytes,o=Object.assign(oc(e.Fp,r),{seed:Math.max(ts(r.ORDER),16)});function s(h){try{let b=r.fromBytes(h);return r.isValidNot0(b)}catch{return!1}}function i(h,b){let{publicKey:E,publicKeyUncompressed:p}=o;try{let y=h.length;return b===!0&&y!==E||b===!1&&y!==p?!1:!!e.fromBytes(h)}catch{return!1}}function a(h){return h=h===void 0?n(o.seed):h,es(z(h,o.seed,"seed"),r.ORDER)}function c(h,b=!0){return e.BASE.multiply(r.fromBytes(h)).toBytes(b)}function u(h){let{secretKey:b,publicKey:E,publicKeyUncompressed:p}=o,y=r._lengths;if(!ge(h))return;let v=z(h,void 0,"key").length,_=v===E||v===p,L=v===b||!!y?.includes(v);if(!(_&&L))return _}function f(h,b,E=!0){if(u(h)===!0)throw new Error("first arg must be private key");if(u(b)===!1)throw new Error("second arg must be public key");let p=r.fromBytes(h);return e.fromBytes(b).multiply(p).toBytes(E)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},d=dn(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:d,Point:e,utils:l,lengths:o})}function sc(e,t,r={}){let n=t;Qr(n),Pt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?yr:r.randomBytes,s=r.hmac===void 0?(x,w)=>Ja(n,x,w):r.hmac,{Fp:i,Fn:a}=e,{ORDER:c,BITS:u}=a,{keygen:f,getPublicKey:l,getSharedSecret:d,utils:h,lengths:b}=Ol(e,r),E={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},p=c*ec+he<i.ORDER;function y(x){let w=c>>he;return x>w}function v(x,w){if(!a.isValidNot0(w))throw new Error(`invalid signature ${x}: out of range 1..Point.Fn.ORDER`);return w}function _(){if(p)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function L(x,w){Hs(w);let A=b.signature,B=w==="compact"?A:w==="recovered"?A+1:void 0;return z(x,B)}class R{r;s;recovery;constructor(w,A,B){if(this.r=v("r",w),this.s=v("s",A),B!=null){if(_(),![0,1,2,3].includes(B))throw new Error("invalid recovery id");this.recovery=B}Object.freeze(this)}static fromBytes(w,A=E.format){L(w,A);let B;if(A==="der"){let{r:F,s:V}=Nt.toSig(z(w));return new R(F,V)}A==="recovered"&&(B=w[0],A="compact",w=w.subarray(1));let I=b.signature/2,C=w.subarray(0,I),O=w.subarray(I,I*2);return new R(a.fromBytes(C),a.fromBytes(O),B)}static fromHex(w,A){return this.fromBytes(ze(w),A)}assertRecovery(){let{recovery:w}=this;if(w==null)throw new Error("invalid recovery id: must be present");return w}addRecoveryBit(w){return new R(this.r,this.s,w)}recoverPublicKey(w){let{r:A,s:B}=this,I=this.assertRecovery(),C=I===2||I===3?A+c:A;if(!i.isValid(C))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let O=i.toBytes(C),F=e.fromBytes(nt(nc((I&1)===0),O)),V=a.inv(C),U=D(z(w,void 0,"msgHash")),rt=a.create(-U*V),ot=a.create(B*V),st=e.BASE.multiplyUnsafe(rt).add(F.multiplyUnsafe(ot));if(st.is0())throw new Error("invalid recovery: point at infinify");return st.assertValidity(),st}hasHighS(){return y(this.s)}toBytes(w=E.format){if(Hs(w),w==="der")return ze(Nt.hexFromSig(this));let{r:A,s:B}=this,I=a.toBytes(A),C=a.toBytes(B);return w==="recovered"?(_(),nt(Uint8Array.of(this.assertRecovery()),I,C)):nt(I,C)}toHex(w){return qe(this.toBytes(w))}}Object.freeze(R.prototype),Object.freeze(R);let P=r.bits2int===void 0?function(w){if(w.length>8192)throw new Error("input is too large");let A=we(w),B=w.length*8-u;return B>0?A>>BigInt(B):A}:r.bits2int,D=r.bits2int_modN===void 0?function(w){return a.create(P(w))}:r.bits2int_modN,T=wr(u);function K(x){return Ve("num < 2^"+u,x,Ht,T),a.toBytes(x)}function N(x,w){return z(x,void 0,"message"),w?z(n(x),void 0,"prehashed message"):x}function k(x,w,A){let{lowS:B,prehash:I,extraEntropy:C}=Vs(A,E);x=N(x,I);let O=D(x),F=a.fromBytes(w);if(!a.isValidNot0(F))throw new Error("invalid private key");let V=[K(F),K(O)];if(C!=null&&C!==!1){let st=C===!0?o(b.secretKey):C;V.push(z(st,void 0,"extraEntropy"))}let U=nt(...V),rt=O;function ot(st){let Q=P(st);if(!a.isValidNot0(Q))return;let xt=a.inv(Q),Re=e.BASE.multiply(Q).toAffine(),rr=a.create(Re.x);if(rr===Ht)return;let Hr=a.create(xt*a.create(rt+rr*F));if(Hr===Ht)return;let yi=(Re.x===rr?0:2)|Number(Re.y&he),bi=Hr;return B&&y(Hr)&&(bi=a.neg(Hr),yi^=1),new R(rr,bi,p?void 0:yi)}return{seed:U,k2sig:ot}}function m(x,w,A={}){let{seed:B,k2sig:I}=k(x,w,A);return ca(n.outputLen,a.BYTES,s)(B,I).toBytes(A.format)}function g(x,w,A,B={}){let{lowS:I,prehash:C,format:O}=Vs(B,E);if(A=z(A,void 0,"publicKey"),w=N(w,C),!ge(x)){let F=x instanceof R?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+F)}L(x,O);try{let F=R.fromBytes(x,O),V=e.fromBytes(A);if(I&&F.hasHighS())return!1;let{r:U,s:rt}=F,ot=D(w),st=a.inv(rt),Q=a.create(ot*st),xt=a.create(U*st),Re=e.BASE.multiplyUnsafe(Q).add(V.multiplyUnsafe(xt));return Re.is0()?!1:a.create(Re.x)===U}catch{return!1}}function S(x,w,A={}){let{prehash:B}=Vs(A,E);return w=N(w,B),R.fromBytes(x,"recovered").recoverPublicKey(w).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:d,utils:h,lengths:b,Point:e,sign:m,verify:g,recoverPublicKey:S,Signature:R,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")},kl={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var ic=BigInt(2);function Pl(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,l=j(f,r,t)*f%t,d=j(l,r,t)*f%t,h=j(d,ic,t)*u%t,b=j(h,o,t)*h%t,E=j(b,s,t)*b%t,p=j(E,a,t)*E%t,y=j(p,c,t)*p%t,v=j(y,a,t)*E%t,_=j(v,r,t)*f%t,L=j(_,i,t)*b%t,R=j(L,n,t)*u%t,P=j(R,ic,t);if(!Ws.eql(Ws.sqr(P),e))throw new Error("Cannot find square root");return P}var Ws=$e(js.p,{sqrt:Pl}),Kl=rc(js,{Fp:Ws,endo:kl}),Xe=sc(Kl,Me);function ac(e,t,r,n){let o=cr.digest(r instanceof Uint8Array?r:r.subarray());if(yn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Xe.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Sr(String(s))});try{return n?.signal?.throwIfAborted(),Xe.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new Sr(String(s))}}var _n=class{type="secp256k1";raw;_key;constructor(t){this._key=uc(t),this.raw=cc(this._key)}toMultihash(){return Lt.digest(It(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}verify(t,r,n){return ac(this._key,r,t,n)}};function Zs(e){return new _n(e)}function cc(e){return Xe.Point.fromBytes(e).toBytes()}function uc(e){try{return Xe.Point.fromBytes(e),e}catch(t){throw new Ce(String(t))}}function Tn(e,t){let{Type:r,Data:n}=Vt.decode(e),o=n??new Uint8Array;switch(r){case Z.RSA:return Ms(o,t);case Z.Ed25519:return ps(o);case Z.secp256k1:return Zs(o);case Z.ECDSA:return No(o);default:throw new pe}}function fc(e){let{Type:t,Data:r}=Vt.decode(e.digest),n=r??new Uint8Array;switch(t){case Z.Ed25519:return ps(n);case Z.secp256k1:return Zs(n);case Z.ECDSA:return No(n);default:throw new pe}}function It(e){return Vt.encode({Type:Z[e.type],Data:e.raw})}var lc=Symbol.for("nodejs.util.inspect.custom"),Nl=114,Cr=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()})`}[jr]=!0;toString(){return this.string==null&&(this.string=G.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return et.createV1(Nl,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return W(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return W(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[lc](){return`PeerId(${this.toString()})`}},Lr=class extends Cr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Dr=class extends Cr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Or=class extends Cr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Ul=2336,kr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Lt.digest(H(this.url))}[lc](){return`PeerId(${this.url})`}[jr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return et.createV1(Ul,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=q(t)),t.toString()===this.toString())}};var Fl=114,dc=2336;function hc(e){if(e.type==="Ed25519")return new Dr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new Or({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new Lr({multihash:e.toCID().multihash,publicKey:e});throw new pe}function Ys(e){if(ql(e))return new Lr({multihash:e});if(Ml(e))try{let t=fc(e);if(t.type==="Ed25519")return new Dr({multihash:e,publicKey:t});if(t.type==="secp256k1")return new Or({multihash:e,publicKey:t})}catch{let r=q(e.digest);return new kr(new URL(r))}throw new Wr("Supplied PeerID Multihash is invalid")}function In(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==Fl&&e.code!==dc)throw new $r("Supplied PeerID CID is invalid");if(e.code===dc){let t=q(e.multihash.digest);return new kr(new URL(t))}return Ys(e.multihash)}function Ml(e){return e.code===Lt.code}function ql(e){return e.code===cr.code}var Pr;(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:J(0),payloadType:J(0),payload:J(0),signature:J(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})(Pr||(Pr={}));var Bn=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var Qe=class e{static createFromProtobuf=t=>{let r=Pr.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=pc(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 Bn("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=Pr.encode({publicKey:It(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return t==null?!1:W(this.marshal(),t.marshal())}async validate(t,r){let n=pc(t,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},pc=(e,t,r)=>{let n=H(e),o=gn(n.byteLength),s=gn(t.length),i=gn(r.length);return new mt(o,n,s,t,i,r)};var ft=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Xt=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 l=this.readChar();if(l===void 0)return;let d=Number.parseInt(l,t);if(!Number.isNaN(d))return d});if(f===void 0)break;if(s*=t,s+=f,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=t(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var zl=45,Vl=15,Dn=new Ln;function mc(e){if(!(e.length>Vl))return Dn.new(e).parseWith(()=>Dn.readIPv4Addr())}function yc(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>zl))return Dn.new(e).parseWith(()=>Dn.readIPv6Addr())}function On(e){return!!mc(e)}function bc(e){return!!yc(e)}function Xs(e){return t=>q(t,e)}function Qs(e){return t=>H(t,e)}function Je(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function _e(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function gc(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=H(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=_e(n);return Mt([r,o],r.length+o.length)}function wc(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=_e(n);return Mt([r,o],r.length+o.length)}function Js(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=q(t,"base32"),o=Je(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 ft("Invalid byte value in IP address");t[n]=o}),t},xc=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]=q(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,q(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(t+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new ft("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Ec=function(e){if(e.byteLength!==4)throw new ft("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},vc=function(e){if(e.byteLength!==16)throw new ft("IPv6 address was incorrect length");let t=[];for(let n=0;n<e.byteLength;n+=2){let o=e[n],s=e[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let r=t.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new ft(`Invalid IPv6 address "${r}"`)}};function Sc(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new ft(`Invalid IPv6 address "${e}"`)}}var Gs=Object.values(ur).map(e=>e.decoder),Hl=(function(){let e=Gs[0].or(Gs[1]);return Gs.slice(2).forEach(t=>e=e.or(t)),e})();function Ac(e){return Hl.decode(e)}function _c(e){return t=>e.encoder.encode(t)}function $l(e){if(parseInt(e).toString()!==e)throw new Xt("Value must be an integer")}function Wl(e){if(e<0)throw new Xt("Value must be a positive integer, or zero")}function jl(e){return t=>{if(t>e)throw new Xt(`Value must be smaller than or equal to ${e}`)}}function Zl(...e){return t=>{for(let r of e)r(t)}}var Kr=Zl($l,Wl,jl(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)}))}},Qt=new ei,kd=[{code:4,name:"ip4",size:32,valueToBytes:ti,bytesToValue:Ec,validate:e=>{if(!On(e))throw new Xt(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:_e,bytesToValue:Je,validate:Kr},{code:273,name:"udp",size:16,valueToBytes:_e,bytesToValue:Je,validate:Kr},{code:33,name:"dccp",size:16,valueToBytes:_e,bytesToValue:Je,validate:Kr},{code:41,name:"ip6",size:128,valueToBytes:xc,bytesToValue:vc,stringToValue:Sc,validate:e=>{if(!bc(e))throw new Xt(`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:_e,bytesToValue:Je,validate:Kr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:at,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:at,bytesToValue:Xs("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?Qs("base58btc")(e):et.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Js,valueToBytes:gc},{code:445,name:"onion3",size:296,bytesToValue:Js,valueToBytes:wc},{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:_c(Ao),valueToBytes:Ac},{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}];kd.forEach(e=>{Qt.addProtocol(e)});function Tc(e){let t=[],r=0;for(;r<e.length;){let n=xs(e,r),o=Qt.getProtocol(n),s=Rt(n),i=Pd(o,e,r+s),a=0;i>0&&o.size===at&&(a=Rt(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,l=e.subarray(f,f+i);u.value=o.bytesToValue?.(l)??q(l)}t.push(u),r+=c}return t}function Ic(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=Qt.getProtocol(n.code),s=Rt(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??H(n.value),a=i.byteLength,o.size===at&&(c=Rt(a)));let u=new Uint8Array(s+c+a),f=0;Ye(n.code,u,f),f+=s,i!=null&&(o.size===at&&(Ye(a,u,f),f+=c),u.set(i,f)),n.bytes=u}r.push(n.bytes),t+=n.bytes.byteLength}return Mt(r,t)}function Bc(e){if(e.charAt(0)!=="/")throw new ft('String multiaddr must start with "/"');let t=[],r="protocol",n="",o="";for(let s=1;s<e.length;s++){let i=e.charAt(s);i!=="/"&&(r==="protocol"?o+=e.charAt(s):n+=e.charAt(s));let a=s===e.length-1;if(i==="/"||a){let c=Qt.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new ft(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new ft(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}t.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new ft("Incomplete multiaddr");return t}function Rc(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=Qt.getProtocol(t.code);if(r==null)throw new ft(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function Pd(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:xs(t,r)}var Kd=Symbol.for("nodejs.util.inspect.custom"),ni=Symbol.for("@multiformats/multiaddr");function Nd(e){if(e==null&&(e="/"),Pn(e))return e.getComponents();if(e instanceof Uint8Array)return Tc(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),Bc(e);if(Array.isArray(e))return e;throw new ft("Must be a string, Uint8Array, Component[], or another Multiaddr")}var kn=class e{[ni]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=Nd(t),r.validate!==!1&&Ud(this)}get bytes(){return this.#r==null&&(this.#r=Ic(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Rc(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 W(this.bytes,t.bytes)}[Kd](){return`Multiaddr(${this.toString()})`}};function Ud(e){e.getComponents().forEach(t=>{let r=Qt.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function Pn(e){return!!e?.[ni]}function Te(e){return new kn(e)}var Cc="libp2p-peer-record",Lc=Uint8Array.from([3,1]);var Nr;(function(e){let t;(function(i){let a;i.codec=()=>(a==null&&(a=wt((l,d,h={})=>{h.lengthDelimited!==!1&&d.fork(),l.multiaddr!=null&&l.multiaddr.byteLength>0&&(d.uint32(10),d.bytes(l.multiaddr)),h.lengthDelimited!==!1&&d.ldelim()},(l,d,h={})=>{let b={multiaddr:J(0)},E=d==null?l.len:l.pos+d;for(;l.pos<E;){let p=l.uint32();p>>>3===1?b.multiaddr=l.bytes():l.skipType(p&7)}return b},function*(l,d,h,b={}){let E=d==null?l.len:l.pos+d;for(;l.pos<E;){let p=l.uint32();p>>>3===1?yield{field:`${h}.multiaddr`,value:l.bytes()}:l.skipType(p&7)}})),a);function c(l){return bt(l,i.codec())}i.encode=c;function u(l,d){return yt(l,i.codec(),d)}i.decode=u;function f(l,d){return gt(l,i.codec(),d)}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:J(0),seq:0n,addresses:[]},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let l=i.uint32();switch(l>>>3){case 1:{u.peerId=i.bytes();break}case 2:{u.seq=i.uint64();break}case 3:{if(c.limits?.addresses!=null&&u.addresses.length===c.limits.addresses)throw new Ct('Decode error - repeated field "addresses" had too many elements');u.addresses.push(e.AddressInfo.codec().decode(i,i.uint32(),{limits:c.limits?.addresses$}));break}default:{i.skipType(l&7);break}}}return u},function*(i,a,c,u={}){let f={addresses:0},l=a==null?i.len:i.pos+a;for(;i.pos<l;){let d=i.uint32();switch(d>>>3){case 1:{yield{field:`${c}.peerId`,value:i.bytes()};break}case 2:{yield{field:`${c}.seq`,value:i.uint64()};break}case 3:{if(u.limits?.addresses!=null&&f.addresses===u.limits.addresses)throw new Ct('Streaming decode error - repeated field "addresses" had too many elements');for(let h of e.AddressInfo.codec().stream(i,i.uint32(),`${c}.addresses[]`,{limits:u.limits?.addresses$}))yield{...h,index:f.addresses};f.addresses++;break}default:{i.skipType(d&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})(Nr||(Nr={}));function Dc(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 Ie=class e{static createFromProtobuf=t=>{let r=Nr.decode(t),n=Ys(Ne(r.peerId)),o=(r.addresses??[]).map(i=>Te(i.multiaddr)),s=r.seq;return new e({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Cc;static CODEC=Lc;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=Nr.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||!Dc(this.multiaddrs,t.multiaddrs))}};function Fd(e){return e[Symbol.asyncIterator]!=null}function Md(e){if(Fd(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 Oc=Md;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 Ur=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}},tr=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 kc(e={}){return qd(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 qd(e,t){t=t??{};let r=t.onEnd,n=new tr,o,s,i,a=Nn(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,y)=>{s=v=>{s=null,n.push(v);try{p(e(n))}catch(_){y(_)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Nn()})}},u=p=>s!=null?s(p):(n.push(p),o),f=p=>(n=new tr,s!=null?s({error:p}):(n.push({error:p}),o)),l=p=>{if(i)return o;if(t?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:p})},d=p=>i?o:(i=!0,p!=null?f(p):u({done:!0})),h=()=>(n=new tr,d(),{done:!0}),b=p=>(d(p),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:h,throw:b,push:l,end:d,get readableLength(){return n.size},onEmpty:async p=>{let y=p?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let v,_;y!=null&&(v=new Promise((L,R)=>{_=()=>{R(new oi)},y.addEventListener("abort",_)}));try{await Promise.race([a.promise,v])}finally{_!=null&&y!=null&&y?.removeEventListener("abort",_)}}},r==null)return o;let E=o;return o={[Symbol.asyncIterator](){return this},next(){return E.next()},throw(p){return E.throw(p),r!=null&&(r(p),r=void 0),{done:!0}},return(){return E.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(p){return E.end(p),r!=null&&(r(p),r=void 0),o},get readableLength(){return E.readableLength},onEmpty:p=>E.onEmpty(p)},o}function zd(e){return e.reason}async function Pc(e,t,r){if(t==null)return e;let n=r?.translateError??zd;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 Ur{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 Ur,n}var _t=class extends Error{static name="AbortError";name="AbortError";constructor(t="The operation was aborted",...r){super(t,...r)}};async function Fn(e,t,r,n){let o=new _t(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",l),ci(e,t,u),ci(e,s,f)}let u=d=>{try{if(n?.filter?.(d)===!1)return}catch(h){c(),a(h);return}c(),i(d)},f=d=>{if(c(),d instanceof Error){a(d);return}a(d.detail??n?.error??new Error(`The "${n?.errorEvent}" event was emitted but the event had no '.detail' field. Pass an 'error' option to race-event to change this message.`))},l=()=>{c(),a(o)};ai(r,"abort",l),ai(e,t,u),ai(e,s,f)})}function ai(e,t,r){e!=null&&(Kc(e)?e.addEventListener(t,r):e.addListener(t,r))}function ci(e,t,r){e!=null&&(Kc(e)?e.removeEventListener(t,r):e.removeListener(t,r))}function Kc(e){return typeof e.addEventListener=="function"&&typeof e.removeEventListener=="function"}var Mn=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 _t)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Vd(){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=Vd(),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 _t),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 Pc(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 Fr=class extends De{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 Mn;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 _t)}),this.clear()}async onEmpty(t){this.size!==0&&await Fn(this,"empty",t?.signal)}async onSizeLessThan(t,r){this.size<t||await Fn(this,"next",r?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await Fn(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=kc({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 _t("Queue aborted"))};this.addEventListener("success",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("success",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};var Vn="lock:worker:request-read",Hn="lock:worker:abort-read-request",$n="lock:worker:release-read",Wn="lock:master:grant-read",jn="lock:master:error-read",Zn="lock:worker:request-write",Yn="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",Nc={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(l=>{let d=h=>{if(h?.data==null)return;let b={type:h.data.type,name:h.data.name,identifier:h.data.identifier};b.type===a&&b.identifier===f.identifier&&(t.removeEventListener("message",d),l())};t.addEventListener("message",d)})},onError:l=>{t.postMessage({type:i,name:f.name,identifier:f.identifier,error:{message:l.message,name:l.name,stack:l.stack}})}}}),f.type===s&&e.safeDispatchEvent(n,{detail:{name:f.name,identifier:f.identifier}}),f.type===Jn&&e.safeDispatchEvent("finalizeRequest",{detail:{name:f.name}})};var Uc=(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(Vn,Hn,Wn,jn,$n,t)}writeLock(t){return this.sendRequest(Zn,Yn,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=Uc();return this.channel.postMessage({type:t,identifier:a,name:this.name}),new Promise((c,u)=>{let f=()=>{this.channel.postMessage({type:r,identifier:a,name:this.name})};i?.signal?.addEventListener("abort",f,{once:!0});let l=d=>{if(d.data?.identifier===a&&(d.data?.type===n&&(this.channel.removeEventListener("message",l),i?.signal?.removeEventListener("abort",f),c(()=>{this.channel.postMessage({type:s,identifier:a,name:this.name})})),d.data.type===o)){this.channel.removeEventListener("message",l),i?.signal?.removeEventListener("abort",f);let h=new Error;d.data.error!=null&&(h.message=d.data.error.message,h.name=d.data.error.name,h.stack=d.data.error.stack),u(h)}};this.channel.addEventListener("message",l)})}};var Fc=e=>{if(e=Object.assign({},Nc,e),!!globalThis.document||e.singleProcess){let r=new BroadcastChannel(to),n=new De;return r.addEventListener("message",fi(n,r,"requestReadLock","abortReadLockRequest",Vn,Hn,jn,$n,Wn)),r.addEventListener("message",fi(n,r,"requestWriteLock","abortWriteLockRequest",Zn,Yn,Qn,Gn,Xn)),n}return new eo(e.name)};var Be=new Map,Mr;function Mc(e){return typeof e?.readLock=="function"&&typeof e?.writeLock=="function"}function Hd(e){if(Mr==null&&(Mr=Fc(e),!Mc(Mr))){let t=Mr;t.addEventListener("requestReadLock",r=>{let n=r.detail.name,o=r.detail.identifier,s=Be.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=Be.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=Be.get(n);o?.finalize()})}return Mr}async function li(e,t){let r,n,o=new Promise((i,a)=>{r=i,n=a}),s=()=>{n(new _t)};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 qc=(e,t)=>{let r=Be.get(e);if(r!=null)return r;let n=Hd(t);if(Mc(n))return r=n,Be.set(e,r),r;let o=new Fr({concurrency:1}),s;return r={async readLock(i){if(s!=null)return li(s,i);s=new Fr({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:()=>{Be.delete(e)},queue:o},Be.set(e,r),t.autoFinalize===!0&&o.addEventListener("idle",()=>{r.finalize()},{once:!0}),r};var $d={name:"lock",concurrency:1/0,singleProcess:!1,autoFinalize:!1};function di(e){let t=Object.assign({},$d,e);return qc(t.name,t)}var Jt;(function(e){let t;(function(a){let c;a.codec=()=>(c==null&&(c=wt((d,h,b={})=>{b.lengthDelimited!==!1&&h.fork(),d.key!=null&&d.key!==""&&(h.uint32(10),h.string(d.key)),d.value!=null&&d.value.byteLength>0&&(h.uint32(18),h.bytes(d.value)),b.lengthDelimited!==!1&&h.ldelim()},(d,h,b={})=>{let E={key:"",value:J(0)},p=h==null?d.len:d.pos+h;for(;d.pos<p;){let y=d.uint32();switch(y>>>3){case 1:{E.key=d.string();break}case 2:{E.value=d.bytes();break}default:{d.skipType(y&7);break}}}return E},function*(d,h,b,E={}){let p=h==null?d.len:d.pos+h;for(;d.pos<p;){let y=d.uint32();switch(y>>>3){case 1:{yield{field:`${b}.key`,value:d.string()};break}case 2:{yield{field:`${b}.value`,value:d.bytes()};break}default:{d.skipType(y&7);break}}}})),c);function u(d){return bt(d,a.codec())}a.encode=u;function f(d,h){return yt(d,a.codec(),h)}a.decode=f;function l(d,h){return gt(d,a.codec(),h)}a.stream=l})(t=e.Peer$metadataEntry||(e.Peer$metadataEntry={}));let r;(function(a){let c;a.codec=()=>(c==null&&(c=wt((d,h,b={})=>{b.lengthDelimited!==!1&&h.fork(),d.key!=null&&d.key!==""&&(h.uint32(10),h.string(d.key)),d.value!=null&&(h.uint32(18),zr.codec().encode(d.value,h)),b.lengthDelimited!==!1&&h.ldelim()},(d,h,b={})=>{let E={key:""},p=h==null?d.len:d.pos+h;for(;d.pos<p;){let y=d.uint32();switch(y>>>3){case 1:{E.key=d.string();break}case 2:{E.value=zr.codec().decode(d,d.uint32(),{limits:b.limits?.value});break}default:{d.skipType(y&7);break}}}return E},function*(d,h,b,E={}){let p=h==null?d.len:d.pos+h;for(;d.pos<p;){let y=d.uint32();switch(y>>>3){case 1:{yield{field:`${b}.key`,value:d.string()};break}case 2:{yield*zr.codec().stream(d,d.uint32(),`${b}.value`,{limits:E.limits?.value});break}default:{d.skipType(y&7);break}}}})),c);function u(d){return bt(d,a.codec())}a.encode=u;function f(d,h){return yt(d,a.codec(),h)}a.decode=f;function l(d,h){return gt(d,a.codec(),h)}a.stream=l})(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),qr.codec().encode(f,c);if(a.protocols!=null&&a.protocols.length>0)for(let f of a.protocols)c.uint32(18),c.string(f);if(a.publicKey!=null&&(c.uint32(34),c.bytes(a.publicKey)),a.peerRecordEnvelope!=null&&(c.uint32(42),c.bytes(a.peerRecordEnvelope)),a.metadata!=null&&a.metadata.size>0)for(let[f,l]of a.metadata.entries())c.uint32(50),e.Peer$metadataEntry.codec().encode({key:f,value:l},c);if(a.tags!=null&&a.tags.size>0)for(let[f,l]of a.tags.entries())c.uint32(58),e.Peer$tagsEntry.codec().encode({key:f,value:l},c);a.updated!=null&&(c.uint32(64),c.uint64Number(a.updated)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={addresses:[],protocols:[],metadata:new Map,tags:new Map},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();switch(d>>>3){case 1:{if(u.limits?.addresses!=null&&f.addresses.length===u.limits.addresses)throw new Ct('Decode error - repeated field "addresses" had too many elements');f.addresses.push(qr.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 Ct('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 Ir('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 Ir('Decode error - map field "tags" had too many elements');let h=e.Peer$tagsEntry.codec().decode(a,a.uint32(),{limits:{value:u.limits?.tags$value}});f.tags.set(h.key,h.value);break}case 8:{f.updated=a.uint64Number();break}default:{a.skipType(d&7);break}}}return f},function*(a,c,u,f={}){let l={addresses:0,protocols:0,metadata:0,tags:0},d=c==null?a.len:a.pos+c;for(;a.pos<d;){let h=a.uint32();switch(h>>>3){case 1:{if(f.limits?.addresses!=null&&l.addresses===f.limits.addresses)throw new Ct('Streaming decode error - repeated field "addresses" had too many elements');for(let b of qr.codec().stream(a,a.uint32(),`${u}.addresses[]`,{limits:f.limits?.addresses$}))yield{...b,index:l.addresses};l.addresses++;break}case 2:{if(f.limits?.protocols!=null&&l.protocols===f.limits.protocols)throw new Ct('Streaming decode error - repeated field "protocols" had too many elements');yield{field:`${u}.protocols[]`,index:l.protocols,value:a.string()},l.protocols++;break}case 4:{yield{field:`${u}.publicKey`,value:a.bytes()};break}case 5:{yield{field:`${u}.peerRecordEnvelope`,value:a.bytes()};break}case 6:{if(f.limits?.metadata!=null&&l.metadata===f.limits.metadata)throw new Ct('Decode error - map field "metadata" had too many elements');yield*e.Peer$metadataEntry.codec().stream(a,a.uint32(),`${u}.metadata{}`,{limits:{value:f.limits?.metadata$value}}),l.metadata++;break}case 7:{if(f.limits?.tags!=null&&l.tags===f.limits.tags)throw new Ct('Decode error - map field "tags" had too many elements');yield*e.Peer$tagsEntry.codec().stream(a,a.uint32(),`${u}.tags{}`,{limits:{value:f.limits?.tags$value}}),l.tags++;break}case 8:{yield{field:`${u}.updated`,value:a.uint64Number()};break}default:{a.skipType(h&7);break}}}})),n);function o(a){return 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})(Jt||(Jt={}));var qr;(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:J(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})(qr||(qr={}));var zr;(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})(zr||(zr={}));function Wd(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 hc(n)}function zc(e,t,r){let n=Jt.decode(t);return er(e,n,r)}function er(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:Wd(e,t),addresses:t.addresses.filter(({observed:s})=>s!=null&&s>Date.now()-r).map(({multiaddr:s,isCertified:i})=>({multiaddr:Te(s),isCertified:i??!1})),metadata:t.metadata,peerRecordEnvelope:t.peerRecordEnvelope??void 0,tags:n}}function Vc(e,t){return jd(e.addresses,t.addresses)&&Zd(e.protocols,t.protocols)&&Yd(e.publicKey,t.publicKey)&&Gd(e.peerRecordEnvelope,t.peerRecordEnvelope)&&Xd(e.metadata,t.metadata)&&Qd(e.tags,t.tags)}function jd(e,t){return $c(e,t,(r,n)=>!(r.isCertified!==n.isCertified||!W(r.multiaddr,n.multiaddr)))}function Zd(e,t){return $c(e,t,(r,n)=>r===n)}function Yd(e,t){return Hc(e,t)}function Gd(e,t){return Hc(e,t)}function Xd(e,t){return Wc(e,t,(r,n)=>W(r,n))}function Qd(e,t){return Wc(e,t,(r,n)=>r.value===n.value&&r.expiry===n.expiry)}function Hc(e,t){return e==null&&t==null?!0:e!=null&&t!=null?W(e,t):!1}function $c(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 Wc(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 te="/",jc=new TextEncoder().encode(te),ro=jc[0],no=class e{_buf;constructor(t,r){if(typeof t=="string")this._buf=H(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 q(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new e(t.join(te))}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=jc),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(te).slice(1)}type(){return Jd(this.baseNamespace())}name(){return th(this.baseNamespace())}instance(t){return new e(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(te)||(t+=te),t+=this.type(),new e(t)}parent(){let t=this.list();return t.length===1?new e(te):new e(t.slice(0,-1).join(te))}child(t){return this.toString()===te?t:t.toString()===te?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(),...eh(t.map(r=>r.namespaces()))])}};function Jd(e){let t=e.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function th(e){let t=e.split(":");return t[t.length-1]}function eh(e){return[].concat(...e)}var hi="/peers/";function Vr(e){if(!Le(e)||e.type==null)throw new M("Invalid PeerId");let t=e.toCID().toString();return new no(`${hi}${t}`)}async function Zc(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=Te(i.multiaddr)),!Pn(i.multiaddr))throw new M("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(Te(`/p2p/${e}`))),{isCertified:i,multiaddr:a.bytes}})}async function so(e,t,r,n){if(t==null)throw new M("Invalid PeerData");if(t.publicKey!=null&&!e.equals(t.publicKey.toMultihash().bytes))throw new M("publicKey does not match peer id");let o=n.existingPeer?.peer;if(o!=null&&!e.equals(o.id))throw new M("peer id did not match existing peer id");let s=o?.addresses??[],i=new Set(o?.protocols??[]),a=o?.metadata??new Map,c=o?.tags??new Map,u=o?.peerRecordEnvelope;if(r==="patch"){if((t.multiaddrs!=null||t.addresses!=null)&&(s=[],t.multiaddrs!=null&&s.push(...t.multiaddrs.map(d=>({isCertified:!1,multiaddr:d}))),t.addresses!=null&&s.push(...t.addresses)),t.protocols!=null&&(i=new Set(t.protocols)),t.metadata!=null){let d=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);a=oo(d,{validate:Yc})}if(t.tags!=null){let d=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags);c=oo(d,{validate:Gc,map:Xc})}t.peerRecordEnvelope!=null&&(u=t.peerRecordEnvelope)}if(r==="merge"){if(t.multiaddrs!=null&&s.push(...t.multiaddrs.map(d=>({isCertified:!1,multiaddr:d}))),t.addresses!=null&&s.push(...t.addresses),t.protocols!=null&&(i=new Set([...i,...t.protocols])),t.metadata!=null){let d=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);for(let[h,b]of d)b==null?a.delete(h):a.set(h,b);a=oo([...a.entries()],{validate:Yc})}if(t.tags!=null){let d=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags),h=new Map(c);for(let[b,E]of d)E==null?h.delete(b):h.set(b,E);c=oo([...h.entries()],{validate:Gc,map:Xc})}t.peerRecordEnvelope!=null&&(u=t.peerRecordEnvelope)}let f;o?.id.publicKey!=null?f=It(o.id.publicKey):t.publicKey!=null?f=It(t.publicKey):e.publicKey!=null&&(f=It(e.publicKey));let l={addresses:await Zc(e,n.addressFilter??(async()=>!0),s,n.existingPeer?.peerPB.addresses,n),protocols:[...i.values()].sort((d,h)=>d.localeCompare(h)),metadata:a,tags:c,publicKey:f,peerRecordEnvelope:u};return l.addresses.forEach(d=>{d.observed=n.existingPeer?.peerPB.addresses?.find(h=>W(h.multiaddr,d.multiaddr))?.observed??Date.now()}),e.type!=="RSA"&&delete l.publicKey,l}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 Yc(e,t){if(typeof e!="string")throw new M("Metadata key must be a string");if(!(t instanceof Uint8Array))throw new M("Metadata value must be a Uint8Array")}function Gc(e,t){if(typeof e!="string")throw new M("Tag name must be a string");if(t.value!=null){if(parseInt(`${t.value}`,10)!==t.value)throw new M("Tag value must be an integer");if(t.value<0||t.value>100)throw new M("Tag value must be between 0-100")}if(t.ttl!=null){if(parseInt(`${t.ttl}`,10)!==t.ttl)throw new M("Tag ttl must be an integer");if(t.ttl<0)throw new M("Tag ttl must be between greater than 0")}}function Xc(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 Qc(e){let t=e.toString().split("/")[2],r=et.parse(t,Ut);return In(r)}function pi(e,t,r){let n=Qc(e);return zc(n,t,r)}function rh(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(Vr(t),r)}async load(t,r){let n=Vr(t),o=await this.datastore.get(n,r),s=Jt.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,r),new nr;return er(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(rh(t??{},this.maxAddressAge),t)){let o=Qc(r);if(o.equals(this.peerId))continue;let s=Jt.decode(n);if(this.#r(o,s)){await this.datastore.delete(r,t);continue}yield er(o,s,this.peerId.equals(o)?1/0:this.maxAddressAge)}}async#t(t,r){try{let n=Vr(t),o=await this.datastore.get(n,r),s=Jt.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,r),new nr;return{peerPB:s,peer:er(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=Jt.encode(r);return await this.datastore.put(Vr(t),s,o),{peer:er(t,r,this.maxAddressAge),previous:n?.peer,updated:n==null||!Vc(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 Oc(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=Le(r)?r:Le(r?.expectedPeer)?r.expectedPeer:void 0,s=Le(r)||r===void 0?n:r,i=await Qe.openAndCertify(t,Ie.DOMAIN,s),a=In(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=Ie.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=Qe.createFromProtobuf(u.peerRecordEnvelope),l=Ie.createFromProtobuf(f.payload);if(l.seqNumber>=c.seqNumber)return this.log("sequence number was lower or equal to existing sequence number - stored: %d received: %d",l.seqNumber,c.seqNumber),!1}return await this.patch(c.peerId,{peerRecordEnvelope:t,addresses:c.multiaddrs.map(f=>({isCertified:!0,multiaddr:f}))},s),!0}#t(t,r){r.updated&&(this.peerId.equals(t)?this.events.safeDispatchEvent("self:peer:update",{detail:r}):this.events.safeDispatchEvent("peer:update",{detail:r}))}};function nh(e,t={}){return new mi(e,t)}return nu(oh);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/curves/utils.js:
|