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