@libp2p/peer-store 12.0.21-a34745c01 → 12.0.22

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 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 Zo=Object.defineProperty;var Rl=Object.getOwnPropertyDescriptor;var Ol=Object.getOwnPropertyNames;var kl=Object.prototype.hasOwnProperty;var K=(t,e)=>{for(var r in e)Zo(t,r,{get:e[r],enumerable:!0})},Pl=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Ol(e))!kl.call(t,o)&&o!==r&&Zo(t,o,{get:()=>e[o],enumerable:!(n=Rl(e,o))||n.enumerable});return t};var Ul=t=>Pl(Zo({},"__esModule",{value:!0}),t);var ib={};K(ib,{persistentPeerStore:()=>sb});var M=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},zt=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var Tr=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var Tn=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},Dn=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var vt=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var _n=Symbol.for("@libp2p/peer-id");function Vt(t){return!!t?.[_n]}function Kl(t){return typeof t?.handleEvent=="function"}function Nl(t){return(t!==!0&&t!==!1&&t?.once)??!1}var Ht=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){let o=Nl(n);super.addEventListener(e,i=>{if(o){let a=this.#e.get(i.type);a!=null&&(a=a.filter(({callback:c})=>c!==r),this.#e.set(i.type,a))}Kl(r)?r.handleEvent(i):r(i)},n);let s=this.#e.get(e);s==null&&(s=[],this.#e.set(e,s)),s.push({callback:r,once:o})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==r),this.#e.set(e,o))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var Jo={};K(Jo,{base58btc:()=>X,base58flickr:()=>jl});var lb=new Uint8Array(0);function Ya(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function je(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return St(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return St(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function Xa(t){return new TextEncoder().encode(t)}function Qa(t){return new TextDecoder().decode(t)}function Fl(t){return t?.buffer instanceof ArrayBuffer}function St(t){return Fl(t)?t:t.slice()}function Ml(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var s=t.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function d(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var b=0,m=0,y=0,x=p.length;y!==x&&p[y]===0;)y++,b++;for(var w=(x-y)*f+1>>>0,C=new Uint8Array(w);y!==x;){for(var I=p[y],R=0,_=w-1;(I!==0||R<m)&&_!==-1;_--,R++)I+=256*C[_]>>>0,C[_]=I%a>>>0,I=I/a>>>0;if(I!==0)throw new Error("Non-zero carry");m=R,y++}for(var A=w-m;A!==w&&C[A]===0;)A++;for(var P=c.repeat(b);A<w;++A)P+=t.charAt(C[A]);return P}function l(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var b=0;if(p[b]!==" "){for(var m=0,y=0;p[b]===c;)m++,b++;for(var x=(p.length-b)*u+1>>>0,w=new Uint8Array(x);p[b];){var C=r[p.charCodeAt(b)];if(C===255)return;for(var I=0,R=x-1;(C!==0||I<y)&&R!==-1;R--,I++)C+=a*w[R]>>>0,w[R]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");y=I,b++}if(p[b]!==" "){for(var _=x-y;_!==x&&w[_]===0;)_++;for(var A=new Uint8Array(m+(x-_)),P=m;_!==x;)A[P++]=w[_++];return A}}}function h(p){var b=l(p);if(b)return b;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:l,decode:h}}var ql=Ml,zl=ql,ec=zl;var Go=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Yo=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return tc(this,e)}},Xo=class{decoders;constructor(e){this.decoders=e}or(e){return tc(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function tc(t,e){return new Xo({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Qo=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Go(e,r,n),this.decoder=new Yo(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function $t({name:t,prefix:e,encode:r,decode:n}){return new Qo(t,e,r,n)}function it({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=ec(r,t);return $t({prefix:e,name:t,encode:n,decode:s=>je(o(s))})}function Vl(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Hl(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function $l(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function Y({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=$l(n);return $t({prefix:e,name:t,encode(s){return Hl(s,n,r)},decode(s){return Vl(s,o,r,t)}})}var X=it({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),jl=it({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var es={};K(es,{base32:()=>Ne,base32hex:()=>Yl,base32hexpad:()=>Ql,base32hexpadupper:()=>Jl,base32hexupper:()=>Xl,base32pad:()=>Zl,base32padupper:()=>Gl,base32upper:()=>Wl,base32z:()=>ed});var Ne=Y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Wl=Y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Zl=Y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Gl=Y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Yl=Y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Xl=Y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ql=Y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Jl=Y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ed=Y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ts={};K(ts,{base36:()=>Dr,base36upper:()=>td});var Dr=it({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),td=it({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var rd=oc,rc=128,nd=127,od=~nd,sd=Math.pow(2,31);function oc(t,e,r){e=e||[],r=r||0;for(var n=r;t>=sd;)e[r++]=t&255|rc,t/=128;for(;t&od;)e[r++]=t&255|rc,t>>>=7;return e[r]=t|0,oc.bytes=r-n+1,e}var id=rs,ad=128,nc=127;function rs(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw rs.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&nc)<<o:(i&nc)*Math.pow(2,o),o+=7}while(i>=ad);return rs.bytes=s-n,r}var cd=Math.pow(2,7),ud=Math.pow(2,14),fd=Math.pow(2,21),ld=Math.pow(2,28),dd=Math.pow(2,35),hd=Math.pow(2,42),pd=Math.pow(2,49),md=Math.pow(2,56),yd=Math.pow(2,63),bd=function(t){return t<cd?1:t<ud?2:t<fd?3:t<ld?4:t<dd?5:t<hd?6:t<pd?7:t<md?8:t<yd?9:10},gd={encode:rd,decode:id,encodingLength:bd},xd=gd,_r=xd;function Br(t,e=0){return[_r.decode(t,e),_r.decode.bytes]}function jt(t,e,r=0){return _r.encode(t,e,r),e}function Wt(t){return _r.encodingLength(t)}function Fe(t,e){let r=e.byteLength,n=Wt(t),o=n+Wt(r),s=new Uint8Array(o+r);return jt(t,s,0),jt(r,s,n),s.set(e,o),new Zt(t,r,e,s)}function Gt(t){let e=je(t),[r,n]=Br(e),[o,s]=Br(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Zt(r,o,i,e)}function sc(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Ya(t.bytes,r.bytes)}}var Zt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=St(n),this.bytes=St(o)}};function ic(t,e){let{bytes:r,version:n}=t;return n===0?Ed(r,ns(t),e??X.encoder):vd(r,ns(t),e??Ne.encoder)}var ac=new WeakMap;function ns(t){let e=ac.get(t);if(e==null){let r=new Map;return ac.set(t,r),r}return e}var oe=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=St(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==Lr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Sd)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=Fe(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&sc(e.multihash,n.multihash)}toString(e){return ic(this,e)}toJSON(){return{"/":ic(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new t(n,o,s,i??cc(n,o,s.bytes))}else if(r[Ad]===!0){let{version:n,multihash:o,code:s}=r,i=Gt(o);return t.create(n,s,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==Lr)throw new Error(`Version 0 CID must use dag-pb (code: ${Lr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=cc(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Lr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=je(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Zt(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[d,l]=Br(e.subarray(r));return r+=l,d},o=n(),s=Lr;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,o]=wd(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ns(s).set(n,e),s}};function wd(t,e){switch(t[0]){case"Q":{let r=e??X;return[X.prefix,r.decode(`${X.prefix}${t}`)]}case X.prefix:{let r=e??X;return[X.prefix,r.decode(t)]}case Ne.prefix:{let r=e??Ne;return[Ne.prefix,r.decode(t)]}case Dr.prefix:{let r=e??Dr;return[Dr.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function Ed(t,e,r){let{prefix:n}=r;if(n!==X.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function vd(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var Lr=112,Sd=18;function cc(t,e,r){let n=Wt(t),o=n+Wt(e),s=new Uint8Array(o+r.byteLength);return jt(t,s,0),jt(e,s,n),s.set(r,o),s}var Ad=Symbol.for("@ipld/js-cid/CID");var os={};K(os,{identity:()=>Le});var uc=0,Cd="identity",fc=je;function Id(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return Fe(uc,fc(t))}var Le={code:uc,name:Cd,encode:fc,digest:Id};function W(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Td(t){return t.buffer instanceof ArrayBuffer}function Se(t){return Td(t)?t:t.slice()}async function lc(t,e,r,n){let o=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,Se(e),Se(r.subarray()));return n?.signal?.throwIfAborted(),s}function We(t=0){return new Uint8Array(t)}function Rr(t=0){return new Uint8Array(t)}function ss(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=Rr(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}function dc(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}var pc=Symbol.for("@achingbrain/uint8arraylist");function hc(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let o=r+n.byteLength;if(e<o)return{buf:n,index:e-r};r=o}throw new RangeError("index is out of bounds")}function Ln(t){return!!t?.[pc]}var ye=class t{bufs;length;[pc]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Ln(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Ln(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(e){let r=hc(this.bufs,e);return r.buf[r.index]}set(e,r){let n=hc(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(Ln(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:o}=this._subList(e,r);return ss(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:ss(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),s=new t;return s.length=o,s.bufs=n,s}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,e>=c)continue;let u=e>=a&&e<c,f=r>a&&r<=c;if(u&&f){if(e===a&&r===c){n.push(i);break}let d=e-a;n.push(i.subarray(d,d+(r-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!Ln(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let d=0;d<s;d++)i[d]=-1;for(let d=0;d<o;d++)i[n[d]]=d;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let d=r;d<=c;d+=f){f=0;for(let l=u;l>=0;l--){let h=this.get(d+l);if(n[l]!==h){f=Math.max(1,l-a[h]);break}}if(f===0)return d}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=Rr(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let o=We(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let o=We(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let o=We(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=Rr(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let o=We(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let o=We(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let o=We(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let o=We(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let o=We(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!dc(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var is={};K(is,{base10:()=>Dd});var Dd=it({prefix:"9",name:"base10",alphabet:"0123456789"});var as={};K(as,{base16:()=>_d,base16upper:()=>Bd});var _d=Y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Bd=Y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var cs={};K(cs,{base2:()=>Ld});var Ld=Y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var us={};K(us,{base256emoji:()=>Ud});var mc=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Rd=mc.reduce((t,e,r)=>(t[r]=e,t),[]),Od=mc.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function kd(t){return t.reduce((e,r)=>(e+=Rd[r],e),"")}function Pd(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Od[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Ud=$t({prefix:"\u{1F680}",name:"base256emoji",encode:kd,decode:Pd});var ls={};K(ls,{base64:()=>Kd,base64pad:()=>Nd,base64url:()=>fs,base64urlpad:()=>Fd});var Kd=Y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Nd=Y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),fs=Y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Fd=Y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ds={};K(ds,{base8:()=>Md});var Md=Y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var hs={};K(hs,{identity:()=>qd});var qd=$t({prefix:"\0",name:"identity",encode:t=>Qa(t),decode:t=>Xa(t)});var Qb=new TextEncoder,Jb=new TextDecoder;var ys={};K(ys,{sha256:()=>Or,sha512:()=>$d});var Hd=20;function ms({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new ps(t,e,r,n,o)}var ps=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Hd,this.maxDigestLength=s}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?yc(n,this.code,r?.truncate):n.then(o=>yc(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function yc(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return Fe(e,t)}function gc(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Or=ms({name:"sha2-256",code:18,encode:gc("SHA-256")}),$d=ms({name:"sha2-512",code:19,encode:gc("SHA-512")});var kr={...hs,...cs,...ds,...is,...as,...es,...ts,...Jo,...ls,...us},lg={...ys,...os};function Te(t=0){return new Uint8Array(t)}function At(t=0){return new Uint8Array(t)}function wc(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var xc=wc("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),bs=wc("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=At(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),jd={utf8:xc,"utf-8":xc,hex:kr.base16,latin1:bs,ascii:bs,binary:bs,...kr},Rn=jd;function $(t,e="utf8"){let r=Rn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function z(t,e="utf8"){let r=Rn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var Wd=parseInt("11111",2),gs=parseInt("10000000",2),Zd=parseInt("01111111",2),Ec={0:Pr,1:Pr,2:Gd,3:Qd,4:Jd,5:Xd,6:Yd,16:Pr,22:Pr,48:Pr};function Ze(t,e={offset:0}){let r=t[e.offset]&Wd;if(e.offset++,Ec[r]!=null)return Ec[r](t,e);throw new Error("No decoder for tag "+r)}function Ur(t,e){let r=0;if((t[e.offset]&gs)===gs){let n=t[e.offset]&Zd,o="0x";e.offset++;for(let s=0;s<n;s++,e.offset++)o+=t[e.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=t[e.offset],e.offset++;return r}function Pr(t,e){Ur(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=Ze(t,e);if(n===null)break;r.push(n)}return r}function Gd(t,e){let r=Ur(t,e),n=e.offset,o=e.offset+r,s=[];for(let i=n;i<o;i++)i===n&&t[i]===0||s.push(t[i]);return e.offset+=r,Uint8Array.from(s)}function Yd(t,e){let r=Ur(t,e),n=e.offset+r,o=t[e.offset];e.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;e.offset<n;){let u=t[e.offset];if(e.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let d=0;d<c.length;d++)f+=c[d]<<d*7;a+=`.${f}`,c=[]}}return a}function Xd(t,e){return e.offset++,null}function Qd(t,e){let r=Ur(t,e),n=t[e.offset];e.offset++;let o=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Jd(t,e){let r=Ur(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function eh(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new ye;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function xs(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=eh(t.byteLength);return new ye(Uint8Array.from([e.byteLength|gs]),e)}function ve(t){let e=new ye,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new ye(Uint8Array.from([2]),xs(e),e)}function On(t){let e=Uint8Array.from([0]),r=new ye(e,t);return new ye(Uint8Array.from([3]),xs(r),r)}function ct(t,e=48){let r=new ye;for(let n of t)r.append(n);return new ye(Uint8Array.from([e]),xs(r),r)}var th=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),rh=Uint8Array.from([6,5,43,129,4,0,34]),nh=Uint8Array.from([6,5,43,129,4,0,35]),oh={ext:!0,kty:"EC",crv:"P-256"},sh={ext:!0,kty:"EC",crv:"P-384"},ih={ext:!0,kty:"EC",crv:"P-521"},ws=32,Es=48,vs=66;function Ss(t){let e=Ze(t);return vc(e)}function vc(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===ws*2+1)return n=z(e.subarray(r,r+ws),"base64url"),o=z(e.subarray(r+ws),"base64url"),new Yt({...oh,key_ops:["verify"],x:n,y:o});if(e.byteLength===Es*2+1)return n=z(e.subarray(r,r+Es),"base64url"),o=z(e.subarray(r+Es),"base64url"),new Yt({...sh,key_ops:["verify"],x:n,y:o});if(e.byteLength===vs*2+1)return n=z(e.subarray(r,r+vs),"base64url"),o=z(e.subarray(r+vs),"base64url"),new Yt({...ih,key_ops:["verify"],x:n,y:o});throw new M(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Sc(t){return ct([ve(Uint8Array.from([1])),ct([ah(t.crv)],160),ct([On(new ye(Uint8Array.from([4]),$(t.x??"","base64url"),$(t.y??"","base64url")))],161)]).subarray()}function ah(t){if(t==="P-256")return th;if(t==="P-384")return rh;if(t==="P-521")return nh;throw new M(`Invalid curve ${t}`)}var Yt=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Sc(this.jwk)),this._raw}toMultihash(){return Le.digest(De(this))}toCID(){return oe.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:W(this.raw,e.raw)}async verify(e,r,n){return lc(this.jwk,r,e,n)}};function As(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function ut(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(`${r}expected number, got ${typeof t}`)}if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new RangeError(`${r}expected integer >= 0, got ${t}`)}}function Ae(t,e,r=""){let n=As(t),o=t?.length,s=e!==void 0;if(!n||s&&o!==e){let i=r&&`"${r}" `,a=s?` of length ${e}`:"",c=n?`length=${o}`:`type=${typeof t}`,u=i+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(u):new TypeError(u)}return t}function kn(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(ut(t.outputLen),ut(t.blockLen),t.outputLen<1)throw new Error('"outputLen" must be >= 1');if(t.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Xt(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function Pn(t,e){Ae(t,void 0,"digestInto() output");let r=e.outputLen;if(t.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function Ye(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Un(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Re(t,e){return t<<32-e|t>>>e}var Cc=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",ch=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Kn(t){if(Ae(t),Cc)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=ch[t[r]];return e}var Ge={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ac(t){if(t>=Ge._0&&t<=Ge._9)return t-Ge._0;if(t>=Ge.A&&t<=Ge.F)return t-(Ge.A-10);if(t>=Ge.a&&t<=Ge.f)return t-(Ge.a-10)}function Kr(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Cc)try{return Uint8Array.fromHex(t)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=Ac(t.charCodeAt(s)),a=Ac(t.charCodeAt(s+1));if(i===void 0||a===void 0){let c=t[s]+t[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Cs(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];Ae(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let s=t[n];r.set(s,o),o+=s.length}return r}function Is(t,e={}){let r=(o,s)=>t(s).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function Ic(t=32){ut(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var Ts=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Tc(t,e,r){return t&e^~t&r}function Dc(t,e,r){return t&e^t&r^e&r}var Nr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,o){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=Un(this.buffer)}update(e){Xt(this),Ae(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Un(e);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Xt(this),Pn(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Ye(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let d=i;d<o;d++)r[d]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=Un(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<u;d++)a.setUint32(4*d,f[d],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=s,e.length=o,e.pos=a,o%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},Xe=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var le=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Nn=BigInt(4294967295),_c=BigInt(32);function uh(t,e=!1){return e?{h:Number(t&Nn),l:Number(t>>_c&Nn)}:{h:Number(t>>_c&Nn)|0,l:Number(t&Nn)|0}}function Bc(t,e=!1){let r=t.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=uh(t[s],e);[n[s],o[s]]=[i,a]}return[n,o]}var Ds=(t,e,r)=>t>>>r,_s=(t,e,r)=>t<<32-r|e>>>r,Ct=(t,e,r)=>t>>>r|e<<32-r,It=(t,e,r)=>t<<32-r|e>>>r,Fr=(t,e,r)=>t<<64-r|e>>>r-32,Mr=(t,e,r)=>t>>>r-32|e<<64-r;function Me(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var Lc=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Rc=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Oc=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),kc=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,Pc=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Uc=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;var lh=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),ft=new Uint32Array(64),Bs=class extends Nr{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[e,r,n,o,s,i,a,c]}set(e,r,n,o,s,i,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(e,r){for(let d=0;d<16;d++,r+=4)ft[d]=e.getUint32(r,!1);for(let d=16;d<64;d++){let l=ft[d-15],h=ft[d-2],p=Re(l,7)^Re(l,18)^l>>>3,b=Re(h,17)^Re(h,19)^h>>>10;ft[d]=b+ft[d-7]+p+ft[d-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let d=0;d<64;d++){let l=Re(a,6)^Re(a,11)^Re(a,25),h=f+l+Tc(a,c,u)+lh[d]+ft[d]|0,b=(Re(n,2)^Re(n,13)^Re(n,22))+Dc(n,o,s)|0;f=u,u=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+b|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,u,f)}roundClean(){Ye(ft)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Ye(this.buffer)}},Ls=class extends Bs{A=Xe[0]|0;B=Xe[1]|0;C=Xe[2]|0;D=Xe[3]|0;E=Xe[4]|0;F=Xe[5]|0;G=Xe[6]|0;H=Xe[7]|0;constructor(){super(32)}};var Kc=Bc(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),dh=Kc[0],hh=Kc[1],lt=new Uint32Array(80),dt=new Uint32Array(80),Rs=class extends Nr{constructor(e){super(128,e,16,!1)}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:d,Fl:l,Gh:h,Gl:p,Hh:b,Hl:m}=this;return[e,r,n,o,s,i,a,c,u,f,d,l,h,p,b,m]}set(e,r,n,o,s,i,a,c,u,f,d,l,h,p,b,m){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=d|0,this.Fl=l|0,this.Gh=h|0,this.Gl=p|0,this.Hh=b|0,this.Hl=m|0}process(e,r){for(let w=0;w<16;w++,r+=4)lt[w]=e.getUint32(r),dt[w]=e.getUint32(r+=4);for(let w=16;w<80;w++){let C=lt[w-15]|0,I=dt[w-15]|0,R=Ct(C,I,1)^Ct(C,I,8)^Ds(C,I,7),_=It(C,I,1)^It(C,I,8)^_s(C,I,7),A=lt[w-2]|0,P=dt[w-2]|0,H=Ct(A,P,19)^Fr(A,P,61)^Ds(A,P,6),U=It(A,P,19)^Mr(A,P,61)^_s(A,P,6),g=Oc(_,U,dt[w-7],dt[w-16]),E=kc(g,R,H,lt[w-7],lt[w-16]);lt[w]=E|0,dt[w]=g|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:d,El:l,Fh:h,Fl:p,Gh:b,Gl:m,Hh:y,Hl:x}=this;for(let w=0;w<80;w++){let C=Ct(d,l,14)^Ct(d,l,18)^Fr(d,l,41),I=It(d,l,14)^It(d,l,18)^Mr(d,l,41),R=d&h^~d&b,_=l&p^~l&m,A=Pc(x,I,_,hh[w],dt[w]),P=Uc(A,y,C,R,dh[w],lt[w]),H=A|0,U=Ct(n,o,28)^Fr(n,o,34)^Fr(n,o,39),g=It(n,o,28)^Mr(n,o,34)^Mr(n,o,39),E=n&s^n&a^s&a,T=o&i^o&c^i&c;y=b|0,x=m|0,b=h|0,m=p|0,h=d|0,p=l|0,{h:d,l}=Me(u|0,f|0,P|0,H|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let S=Lc(H,g,T);n=Rc(S,P,U,E),o=S|0}({h:n,l:o}=Me(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Me(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Me(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Me(this.Dh|0,this.Dl|0,u|0,f|0),{h:d,l}=Me(this.Eh|0,this.El|0,d|0,l|0),{h,l:p}=Me(this.Fh|0,this.Fl|0,h|0,p|0),{h:b,l:m}=Me(this.Gh|0,this.Gl|0,b|0,m|0),{h:y,l:x}=Me(this.Hh|0,this.Hl|0,y|0,x|0),this.set(n,o,s,i,a,c,u,f,d,l,h,p,b,m,y,x)}roundClean(){Ye(lt,dt)}destroy(){this.destroyed=!0,Ye(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Os=class extends Rs{Ah=le[0]|0;Al=le[1]|0;Bh=le[2]|0;Bl=le[3]|0;Ch=le[4]|0;Cl=le[5]|0;Dh=le[6]|0;Dl=le[7]|0;Eh=le[8]|0;El=le[9]|0;Fh=le[10]|0;Fl=le[11]|0;Gh=le[12]|0;Gl=le[13]|0;Hh=le[14]|0;Hl=le[15]|0;constructor(){super(64)}};var Qt=Is(()=>new Ls,Ts(1));var Fn=Is(()=>new Os,Ts(3));var q=(t,e,r)=>Ae(t,e,r),Ps=ut,Jt=Kn,ie=(...t)=>Cs(...t),er=t=>Kr(t),Tt=As,qr=t=>Ic(t),qn=BigInt(0),ks=BigInt(1);function Oe(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new TypeError(r+"expected boolean, got type="+typeof t)}return t}function zn(t){if(typeof t=="bigint"){if(!Mn(t))throw new RangeError("positive bigint expected, got "+t)}else Ps(t);return t}function ke(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function zr(t){let e=zn(t).toString(16);return e.length&1?"0"+e:e}function Nc(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?qn:BigInt("0x"+t)}function Dt(t){return Nc(Kn(t))}function qe(t){return Nc(Kn(Vr(Ae(t)).reverse()))}function Vn(t,e){if(ut(e),e===0)throw new RangeError("zero length");t=zn(t);let r=t.toString(16);if(r.length>e*2)throw new RangeError("number too large");return Kr(r.padStart(e*2,"0"))}function Us(t,e){return Vn(t,e).reverse()}function Fc(t,e){if(t=q(t),e=q(e),t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function Vr(t){return Uint8Array.from(q(t))}function Hn(t){if(typeof t!="string")throw new TypeError("ascii string expected, got "+typeof t);return Uint8Array.from(t,(e,r)=>{let n=e.charCodeAt(0);if(e.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${t[r]}" with code ${n} at position ${r}`);return n})}var Mn=t=>typeof t=="bigint"&&qn<=t;function ph(t,e,r){return Mn(t)&&Mn(e)&&Mn(r)&&e<=t&&t<r}function tr(t,e,r,n){if(!ph(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function rr(t){if(t<qn)throw new Error("expected non-negative bigint, got "+t);let e;for(e=0;t>qn;t>>=ks,e+=1);return e}var Hr=t=>(ks<<BigInt(t))-ks;function Mc(t,e,r){if(ut(t,"hashLen"),ut(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=m=>new Uint8Array(m),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(t),u=n(t),f=0,d=()=>{c.fill(1),u.fill(0),f=0},l=(...m)=>r(u,ie(c,...m)),h=(m=o)=>{u=l(s,m),c=l(),m.length!==0&&(u=l(i,m),c=l())},p=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let m=0,y=[];for(;m<e;){c=l();let x=c.slice();y.push(x),m+=c.length}return ie(...y)};return(m,y)=>{d(),h(m);let x;for(;(x=y(p()))===void 0;)h();return d(),x}}function Pe(t,e={},r={}){if(Object.prototype.toString.call(t)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,i,a){if(!a&&i!=="function"&&!Object.hasOwn(t,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let c=t[s];if(a&&c===void 0)return;let u=typeof c;if(u!==i||c===null)throw new TypeError(`param "${s}" is invalid: expected ${i}, got ${u}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(e,!1),o(r,!0)}var Ks=()=>{throw new Error("not implemented")};var de=BigInt(0),Q=BigInt(1),_t=BigInt(2),Hc=BigInt(3),$c=BigInt(4),jc=BigInt(5),mh=BigInt(7),Wc=BigInt(8),yh=BigInt(9),Zc=BigInt(16);function ne(t,e){if(e<=de)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=de?r:e+r}function j(t,e,r){if(e<de)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >de;)n*=n,n%=r;return n}function qc(t,e){if(t===de)throw new Error("invert: expected non-zero number");if(e<=de)throw new Error("invert: expected positive modulus, got "+e);let r=ne(t,e),n=e,o=de,s=Q,i=Q,a=de;for(;r!==de;){let u=n/r,f=n-r*u,d=o-i*u,l=s-a*u;n=r,r=f,o=i,s=a,i=d,a=l}if(n!==Q)throw new Error("invert: does not exist");return ne(o,e)}function Ns(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function Gc(t,e){let r=t,n=(r.ORDER+Q)/$c,o=r.pow(e,n);return Ns(r,o,e),o}function bh(t,e){let r=t,n=(r.ORDER-jc)/Wc,o=r.mul(e,_t),s=r.pow(o,n),i=r.mul(e,s),a=r.mul(r.mul(i,_t),s),c=r.mul(i,r.sub(a,r.ONE));return Ns(r,c,e),c}function gh(t){let e=nr(t),r=Yc(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+mh)/Zc;return((a,c)=>{let u=a,f=u.pow(c,i),d=u.mul(f,n),l=u.mul(f,o),h=u.mul(f,s),p=u.eql(u.sqr(d),c),b=u.eql(u.sqr(l),c);f=u.cmov(f,d,p),d=u.cmov(h,l,b);let m=u.eql(u.sqr(d),c),y=u.cmov(f,d,m);return Ns(u,y,c),y})}function Yc(t){if(t<Hc)throw new Error("sqrt is not defined for small field");let e=t-Q,r=0;for(;e%_t===de;)e/=_t,r++;let n=_t,o=nr(t);for(;zc(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Gc;let s=o.pow(n,e),i=(e+Q)/_t;return function(c,u){let f=c;if(f.is0(u))return u;if(zc(f,u)!==1)throw new Error("Cannot find square root");let d=r,l=f.mul(f.ONE,s),h=f.pow(u,e),p=f.pow(u,i);for(;!f.eql(h,f.ONE);){if(f.is0(h))return f.ZERO;let b=1,m=f.sqr(h);for(;!f.eql(m,f.ONE);)if(b++,m=f.sqr(m),b===d)throw new Error("Cannot find square root");let y=Q<<BigInt(d-b-1),x=f.pow(l,y);d=b,l=f.sqr(x),h=f.mul(h,l),p=f.mul(p,x)}return p}}function xh(t){return t%$c===Hc?Gc:t%Wc===jc?bh:t%Zc===yh?gh(t):Yc(t)}var Qe=(t,e)=>(ne(t,e)&Q)===Q,wh=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Fs(t){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=wh.reduce((n,o)=>(n[o]="function",n),e);if(Pe(t,r),ke(t.BYTES,"BYTES"),ke(t.BITS,"BITS"),t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=Q)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function Eh(t,e,r){let n=t;if(r<de)throw new Error("invalid exponent, negatives unsupported");if(r===de)return n.ONE;if(r===Q)return e;let o=n.ONE,s=e;for(;r>de;)r&Q&&(o=n.mul(o,s)),s=n.sqr(s),r>>=Q;return o}function $r(t,e,r=!1){let n=t,o=new Array(e.length).fill(r?n.ZERO:void 0),s=e.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return e.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),i),o}function zc(t,e){let r=t,n=(r.ORDER-Q)/_t,o=r.pow(e,n),s=r.eql(o,r.ONE),i=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function vh(t,e){if(e!==void 0&&Ps(e),t<=de)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=rr(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${e})`);let n=e!==void 0?e:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var Vc=new WeakMap,$n=class{ORDER;BITS;BYTES;isLE;ZERO=de;ONE=Q;_lengths;_mod;constructor(e,r={}){if(e<=Q)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=vh(e,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(e){return ne(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return de<=e&&e<this.ORDER}is0(e){return e===de}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&Q)===Q}neg(e){return ne(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return ne(e*e,this.ORDER)}add(e,r){return ne(e+r,this.ORDER)}sub(e,r){return ne(e-r,this.ORDER)}mul(e,r){return ne(e*r,this.ORDER)}pow(e,r){return Eh(this,e,r)}div(e,r){return ne(e*qc(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return qc(e,this.ORDER)}sqrt(e){let r=Vc.get(this);return r||Vc.set(this,r=xh(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?Us(e,this.BYTES):Vn(e,this.BYTES)}fromBytes(e,r=!1){q(e);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(o);u.set(e,s?0:u.length-e.length),e=u}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=s?qe(e):Dt(e);if(a&&(c=ne(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return $r(this,e)}cmov(e,r,n){return Oe(n,"condition"),n?r:e}};Object.freeze($n.prototype);function nr(t,e={}){return new $n(t,e)}function Xc(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=Q)throw new Error("field order must be greater than 1");let e=rr(t-Q);return Math.ceil(e/8)}function Ms(t){let e=Xc(t);return e+Math.ceil(e/2)}function qs(t,e,r=!1){q(t);let n=t.length,o=Xc(e),s=Math.max(Ms(e),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?qe(t):Dt(t),a=ne(i,e-Q)+Q;return r?Us(a,o):Vn(a,o)}var or=BigInt(0),Bt=BigInt(1);function jr(t,e){let r=e.negate();return t?r:e}function Lt(t,e){let r=$r(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function tu(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function zs(t,e){tu(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),o=2**t,s=Hr(t),i=BigInt(t);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Qc(t,e,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(t&o),c=t>>i;a>n&&(a-=s,c+=Bt);let u=e*n,f=u+Math.abs(a)-1,d=a===0,l=a<0,h=e%2!==0;return{nextN:c,offset:f,isZero:d,isNeg:l,isNegF:h,offsetF:u}}var Vs=new WeakMap,ru=new WeakMap;function Hs(t){return ru.get(t)||1}function Jc(t){if(t!==or)throw new Error("invalid wNAF")}var sr=class{BASE;ZERO;Fn;bits;constructor(e,r){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let o=e;for(;r>or;)r&Bt&&(n=n.add(o)),o=o.double(),r>>=Bt;return n}precomputeWindow(e,r){let{windows:n,windowSize:o}=zs(r,this.bits),s=[],i=e,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let u=1;u<o;u++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=zs(e,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:d,isNegF:l,offsetF:h}=Qc(n,a,i);n=c,f?s=s.add(jr(l,r[h])):o=o.add(jr(d,r[u]))}return Jc(n),{p:o,f:s}}wNAFUnsafe(e,r,n,o=this.ZERO){let s=zs(e,this.bits);for(let i=0;i<s.windows&&n!==or;i++){let{nextN:a,offset:c,isZero:u,isNeg:f}=Qc(n,i,s);if(n=a,!u){let d=r[c];o=o.add(f?d.negate():d)}}return Jc(n),o}getPrecomputes(e,r,n){let o=Vs.get(r);return o||(o=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(o=n(o)),Vs.set(r,o))),o}cached(e,r,n){let o=Hs(e);return this.wNAF(o,this.getPrecomputes(o,e,n),r)}unsafe(e,r,n,o){let s=Hs(e);return s===1?this._unsafeLadder(e,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,e,n),r,o)}createCache(e,r){tu(r,this.bits),ru.set(e,r),Vs.delete(e)}hasCache(e){return Hs(e)!==1}};function nu(t,e,r,n){let o=e,s=t.ZERO,i=t.ZERO;for(;r>or||n>or;)r&Bt&&(s=s.add(o)),n&Bt&&(i=i.add(o)),o=o.double(),r>>=Bt,n>>=Bt;return{p1:s,p2:i}}function eu(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Fs(e),e}else return nr(t,{isLE:r})}function jn(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let c of["p","n","h"]){let u=e[c];if(!(typeof u=="bigint"&&u>or))throw new Error(`CURVE.${c} must be positive bigint`)}let o=eu(e.p,r.Fp,n),s=eu(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:s}}function Wn(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var ht=BigInt(0),ue=BigInt(1),$s=BigInt(2),Sh=BigInt(8);function Ah(t,e,r,n){let o=t.sqr(r),s=t.sqr(n),i=t.add(t.mul(e.a,o),s),a=t.add(t.ONE,t.mul(e.d,t.mul(o,s)));return t.eql(i,a)}function ou(t,e={}){let r=e,n=jn("edwards",t,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;Pe(r,{},{uvRatio:"function"});let c=$s<<BigInt(s.BYTES*8)-ue,u=b=>o.create(b),f=r.uvRatio===void 0?(b,m)=>{try{return{isValid:!0,value:o.sqrt(o.div(b,m))}}catch{return{isValid:!1,value:ht}}}:r.uvRatio;if(!Ah(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function d(b,m,y=!1){let x=y?ue:ht;return tr("coordinate "+b,m,x,c),m}function l(b){if(!(b instanceof h))throw new Error("EdwardsPoint expected")}class h{static BASE=new h(i.Gx,i.Gy,ue,u(i.Gx*i.Gy));static ZERO=new h(ht,ue,ue,ht);static Fp=o;static Fn=s;X;Y;Z;T;constructor(m,y,x,w){this.X=d("x",m),this.Y=d("y",y),this.Z=d("z",x,!0),this.T=d("t",w),Object.freeze(this)}static CURVE(){return i}static fromAffine(m){if(m instanceof h)throw new Error("extended point not allowed");let{x:y,y:x}=m||{};return d("x",y),d("y",x),new h(y,x,ue,u(y*x))}static fromBytes(m,y=!1){let x=o.BYTES,{a:w,d:C}=i;m=Vr(q(m,x,"point")),Oe(y,"zip215");let I=Vr(m),R=m[x-1];I[x-1]=R&-129;let _=qe(I),A=y?c:o.ORDER;tr("point.y",_,ht,A);let P=u(_*_),H=u(P-ue),U=u(C*P-w),{isValid:g,value:E}=f(H,U);if(!g)throw new Error("bad point: invalid y coordinate");let T=(E&ue)===ue,S=(R&128)!==0;if(!y&&E===ht&&S)throw new Error("bad point: x=0 and x_0=1");return S!==T&&(E=u(-E)),h.fromAffine({x:E,y:_})}static fromHex(m,y=!1){return h.fromBytes(er(m),y)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,y=!0){return p.createCache(this,m),y||this.multiply($s),this}assertValidity(){let m=this,{a:y,d:x}=i;if(m.is0())throw new Error("bad point: ZERO");let{X:w,Y:C,Z:I,T:R}=m,_=u(w*w),A=u(C*C),P=u(I*I),H=u(P*P),U=u(_*y),g=u(P*u(U+A)),E=u(H+u(x*u(_*A)));if(g!==E)throw new Error("bad point: equation left != right (1)");let T=u(w*C),S=u(I*R);if(T!==S)throw new Error("bad point: equation left != right (2)")}equals(m){l(m);let{X:y,Y:x,Z:w}=this,{X:C,Y:I,Z:R}=m,_=u(y*R),A=u(C*w),P=u(x*R),H=u(I*w);return _===A&&P===H}is0(){return this.equals(h.ZERO)}negate(){return new h(u(-this.X),this.Y,this.Z,u(-this.T))}double(){let{a:m}=i,{X:y,Y:x,Z:w}=this,C=u(y*y),I=u(x*x),R=u($s*u(w*w)),_=u(m*C),A=y+x,P=u(u(A*A)-C-I),H=_+I,U=H-R,g=_-I,E=u(P*U),T=u(H*g),S=u(P*g),v=u(U*H);return new h(E,T,v,S)}add(m){l(m);let{a:y,d:x}=i,{X:w,Y:C,Z:I,T:R}=this,{X:_,Y:A,Z:P,T:H}=m,U=u(w*_),g=u(C*A),E=u(R*x*H),T=u(I*P),S=u((w+C)*(_+A)-U-g),v=T-E,D=T+E,L=u(g-y*U),B=u(S*v),O=u(D*L),k=u(S*L),F=u(v*D);return new h(B,O,F,k)}subtract(m){return l(m),this.add(m.negate())}multiply(m){if(!s.isValidNot0(m))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:y,f:x}=p.cached(this,m,w=>Lt(h,w));return Lt(h,[y,x])[0]}multiplyUnsafe(m){if(!s.isValid(m))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return m===ht?h.ZERO:this.is0()||m===ue?this:p.unsafe(this,m,y=>Lt(h,y))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return p.unsafe(this,i.n).is0()}toAffine(m){let y=this,x=m,{X:w,Y:C,Z:I}=y,R=y.is0();x==null&&(x=R?Sh:o.inv(I));let _=u(w*x),A=u(C*x),P=o.mul(I,x);if(R)return{x:ht,y:ue};if(P!==ue)throw new Error("invZ was invalid");return{x:_,y:A}}clearCofactor(){return a===ue?this:this.multiplyUnsafe(a)}toBytes(){let{x:m,y}=this.toAffine(),x=o.toBytes(y);return x[x.length-1]|=m&ue?128:0,x}toHex(){return Jt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let p=new sr(h,s.BITS);return s.BITS>=8&&h.BASE.precompute(8),Object.freeze(h.prototype),Object.freeze(h),h}var Zn=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(e){this.ep=e}static fromBytes(e){Ks()}static fromHex(e){Ks()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(e){return this.ep.toAffine(e)}toHex(){return Jt(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(e){return this.assertSame(e),this.init(this.ep.add(e.ep))}subtract(e){return this.assertSame(e),this.init(this.ep.subtract(e.ep))}multiply(e){return this.init(this.ep.multiply(e))}multiplyUnsafe(e){return this.init(this.ep.multiplyUnsafe(e))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(e,r){return this.ep.precompute(e,r),this}};function su(t,e,r={}){if(typeof e!="function")throw new Error('"hash" function param is required');let n=e,o=r;Pe(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=t,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(ke(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let d=o.randomBytes===void 0?qr:o.randomBytes,l=o.adjustScalarBytes===void 0?g=>g:o.adjustScalarBytes,h=o.domain===void 0?(g,E,T)=>{if(Oe(T,"phflag"),E.length||T)throw new Error("Contexts/pre-hash are not supported");return g}:o.domain;function p(g){return c.create(qe(g))}function b(g){let E=_.secretKey;q(g,_.secretKey,"secretKey");let T=q(n(g),2*E,"hashedSecretKey"),S=l(T.slice(0,E)),v=T.slice(E,2*E),D=p(S);return{head:S,prefix:v,scalar:D}}function m(g){let{head:E,prefix:T,scalar:S}=b(g),v=i.multiply(S),D=v.toBytes();return{head:E,prefix:T,scalar:S,point:v,pointBytes:D}}function y(g){return m(g).pointBytes}function x(g=Uint8Array.of(),...E){let T=ie(...E);return p(n(h(T,q(g,void 0,"context"),!!s)))}function w(g,E,T={}){g=q(g,void 0,"message"),s&&(g=s(g));let{prefix:S,scalar:v,pointBytes:D}=m(E),L=x(T.context,S,g),B=i.multiply(L).toBytes(),O=x(T.context,B,D,g),k=c.create(L+O*v);if(!c.isValid(k))throw new Error("sign failed: invalid s");let F=ie(B,c.toBytes(k));return q(F,_.signature,"result")}let C={zip215:o.zip215};function I(g,E,T,S=C){let{context:v}=S,D=S.zip215===void 0?!!C.zip215:S.zip215,L=_.signature;g=q(g,L,"signature"),E=q(E,void 0,"message"),T=q(T,_.publicKey,"publicKey"),D!==void 0&&Oe(D,"zip215"),s&&(E=s(E));let B=L/2,O=g.subarray(0,B),k=qe(g.subarray(B,L)),F,V,N;try{F=t.fromBytes(T,D),V=t.fromBytes(O,D),N=i.multiplyUnsafe(k)}catch{return!1}if(!D&&F.isSmallOrder())return!1;let se=x(v,O,T,E);return V.add(F.multiplyUnsafe(se)).subtract(N).clearCofactor().is0()}let R=a.BYTES,_={secretKey:R,publicKey:R,signature:2*R,seed:R};function A(g){return g=g===void 0?d(_.seed):g,q(g,_.seed,"seed")}function P(g){return Tt(g)&&g.length===_.secretKey}function H(g,E){try{return!!t.fromBytes(g,E===void 0?C.zip215:E)}catch{return!1}}let U={getExtendedPublicKey:m,randomSecretKey:A,isValidSecretKey:P,isValidPublicKey:H,toMontgomery(g){let{y:E}=t.fromBytes(g),T=_.publicKey,S=T===32;if(!S&&T!==57)throw new Error("only defined for 25519 and 448");let v=S?a.div(ue+E,ue-E):a.div(E-ue,E+ue);return a.toBytes(v)},toMontgomerySecret(g){let E=_.secretKey;q(g,E);let T=n(g.subarray(0,E));return l(T).subarray(0,E)}};return Object.freeze(_),Object.freeze(U),Object.freeze({keygen:Wn(A,y),getPublicKey:y,sign:w,verify:I,utils:U,Point:t,lengths:_})}function Wr(t,e){if(ke(t),ke(e),e<0||e>4)throw new Error("invalid I2OSP length: "+e);if(t<0||t>2**(8*e)-1)throw new Error("invalid I2OSP input: "+t);let r=Array.from({length:e}).fill(0);for(let n=e-1;n>=0;n--)r[n]=t&255,t>>>=8;return new Uint8Array(r)}function Ch(t,e){let r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t[n]^e[n];return r}function Ih(t){if(!Tt(t)&&typeof t!="string")throw new Error("DST must be Uint8Array or ascii string");let e=typeof t=="string"?Hn(t):t;if(e.length===0)throw new Error("DST must be non-empty");return e}function js(t,e,r,n){q(t),ke(r),e=Ih(e),e.length>255&&(e=n(ie(Hn("H2C-OVERSIZE-DST-"),e)));let{outputLen:o,blockLen:s}=n,i=Math.ceil(r/o);if(r>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=ie(e,Wr(e.length,1)),c=new Uint8Array(s),u=Wr(r,2),f=new Array(i),d=n(ie(c,t,u,Wr(0,1),a));f[0]=n(ie(d,Wr(1,1),a));for(let h=1;h<i;h++){let p=[Ch(d,f[h-1]),Wr(h+1,1),a];f[h]=n(ie(...p))}return ie(...f).slice(0,r)}var iu="HashToScalar-";var Th=BigInt(0),Je=BigInt(1),au=BigInt(2);var Dh=BigInt(5),_h=BigInt(8),ir=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Ys={p:ir,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:_h,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Bh(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=ir,a=t*t%s*t%s,c=j(a,au,s)*a%s,u=j(c,Je,s)*t%s,f=j(u,Dh,s)*u%s,d=j(f,e,s)*f%s,l=j(d,r,s)*d%s,h=j(l,n,s)*l%s,p=j(h,o,s)*h%s,b=j(p,o,s)*h%s,m=j(b,e,s)*f%s;return{pow_p_5_8:j(m,au,s)*t%s,b2:a}}function Lh(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var Ws=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Xs(t,e){let r=ir,n=ne(e*e*e,r),o=ne(n*n*e,r),s=Bh(t*o).pow_p_5_8,i=ne(t*n*s,r),a=ne(e*i*i,r),c=i,u=ne(i*Ws,r),f=a===t,d=a===ne(-t,r),l=a===ne(-t*Ws,r);return f&&(i=c),(d||l)&&(i=u),Qe(i,r)&&(i=ne(-i,r)),{isValid:f||d,value:i}}var mt=ou(Ys,{uvRatio:Xs}),pt=mt.Fp,fu=mt.Fn;function Rh(t){return su(mt,Fn,Object.assign({adjustScalarBytes:Lh,zip215:!0},t))}var lu=Rh({});var Zs=Ws,Oh=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),kh=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Ph=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Uh=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),cu=t=>Xs(Je,t),Kh=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Gs=t=>pt.create(qe(t)&Kh);function uu(t){let{d:e}=Ys,r=ir,n=y=>pt.create(y),o=n(Zs*t*t),s=n((o+Je)*Ph),i=BigInt(-1),a=n((i-e*o)*n(o+e)),{isValid:c,value:u}=Xs(s,a),f=n(u*t);Qe(f,r)||(f=n(-f)),c||(u=f),c||(i=o);let d=n(i*(o-Je)*Uh-a),l=u*u,h=n((u+u)*a),p=n(d*Oh),b=n(Je-l),m=n(Je+l);return new mt(n(h*m),n(b*p),n(p*m),n(h*b))}var yt=class t extends Zn{static BASE=new t(mt.BASE);static ZERO=new t(mt.ZERO);static Fp=pt;static Fn=fu;constructor(e){super(e)}static fromAffine(e){return new t(mt.fromAffine(e))}assertSame(e){if(!(e instanceof t))throw new Error("RistrettoPoint expected")}init(e){return new t(e)}static fromBytes(e){Ae(e,32);let{a:r,d:n}=Ys,o=ir,s=C=>pt.create(C),i=Gs(e);if(!Fc(pt.toBytes(i),e)||Qe(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(Je+r*a),u=s(Je-r*a),f=s(c*c),d=s(u*u),l=s(r*n*f-d),{isValid:h,value:p}=cu(s(l*d)),b=s(p*u),m=s(p*b*l),y=s((i+i)*b);Qe(y,o)&&(y=s(-y));let x=s(c*m),w=s(y*x);if(!h||Qe(w,o)||x===Th)throw new Error("invalid ristretto255 encoding 2");return new t(new mt(y,x,Je,w))}static fromHex(e){return t.fromBytes(Kr(e))}toBytes(){let{X:e,Y:r,Z:n,T:o}=this.ep,s=ir,i=m=>pt.create(m),a=i(i(n+r)*i(n-r)),c=i(e*r),u=i(c*c),{value:f}=cu(i(a*u)),d=i(f*a),l=i(f*c),h=i(d*l*o),p;if(Qe(o*h,s)){let m=i(r*Zs),y=i(e*Zs);e=m,r=y,p=i(d*kh)}else p=l;Qe(e*h,s)&&(r=i(-r));let b=i((n-r)*p);return Qe(b,s)&&(b=i(-b)),pt.toBytes(b)}equals(e){this.assertSame(e);let{X:r,Y:n}=this.ep,{X:o,Y:s}=e.ep,i=u=>pt.create(u),a=i(r*s)===i(n*o),c=i(n*s)===i(r*o);return a||c}is0(){return this.equals(t.ZERO)}};Object.freeze(yt.BASE);Object.freeze(yt.ZERO);Object.freeze(yt.prototype);Object.freeze(yt);var Nh=Object.freeze({Point:yt,hashToCurve(t,e){let r=e?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":e.DST,n=js(t,r,64,Fn);return Nh.deriveToCurve(n)},hashToScalar(t,e={DST:iu}){let r=js(t,e.DST,64,Fn);return fu.create(qe(r))},deriveToCurve(t){Ae(t,64);let e=Gs(t.subarray(0,32)),r=uu(e),n=Gs(t.subarray(32,64)),o=uu(n);return new yt(r.add(o))}});var Zr=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},Gn=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var _e={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new Gn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var Yn=32;var Qs,Fh=(async()=>{try{return await _e.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Mh(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await _e.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await _e.get().subtle.verify({name:"Ed25519"},n,Se(e),Se(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function qh(t,e,r){return lu.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function du(t,e,r){return Qs==null&&(Qs=await Fh),Qs?Mh(t,e,r):qh(t,e,r)}function zh(t){return t?.buffer instanceof ArrayBuffer}function Js(t){if(zh(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Rt(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=At(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return Js(r)}function Xn(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Qn=class{type="Ed25519";raw;constructor(e){this.raw=ei(e,Yn)}toMultihash(){return Le.digest(De(this))}toCID(){return oe.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:W(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let o=du(this.raw,r,e);return Xn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function ti(t){return t=ei(t,Yn),new Qn(t)}function ei(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new M(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}function pu(t=0){return new Uint8Array(t)}var Hh=Math.pow(2,7),$h=Math.pow(2,14),jh=Math.pow(2,21),mu=Math.pow(2,28),yu=Math.pow(2,35),bu=Math.pow(2,42),gu=Math.pow(2,49),J=128,bt=127;function Ot(t){if(t<Hh)return 1;if(t<$h)return 2;if(t<jh)return 3;if(t<mu)return 4;if(t<yu)return 5;if(t<bu)return 6;if(t<gu)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ri(t,e,r=0){switch(Ot(t)){case 8:e[r++]=t&255|J,t/=128;case 7:e[r++]=t&255|J,t/=128;case 6:e[r++]=t&255|J,t/=128;case 5:e[r++]=t&255|J,t/=128;case 4:e[r++]=t&255|J,t>>>=7;case 3:e[r++]=t&255|J,t>>>=7;case 2:e[r++]=t&255|J,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Wh(t,e,r=0){switch(Ot(t)){case 8:e.set(r++,t&255|J),t/=128;case 7:e.set(r++,t&255|J),t/=128;case 6:e.set(r++,t&255|J),t/=128;case 5:e.set(r++,t&255|J),t/=128;case 4:e.set(r++,t&255|J),t>>>=7;case 3:e.set(r++,t&255|J),t>>>=7;case 2:e.set(r++,t&255|J),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function xu(t,e){let r=t[e],n=0;if(n+=r&bt,r<J||(r=t[e+1],n+=(r&bt)<<7,r<J)||(r=t[e+2],n+=(r&bt)<<14,r<J)||(r=t[e+3],n+=(r&bt)<<21,r<J)||(r=t[e+4],n+=(r&bt)*mu,r<J)||(r=t[e+5],n+=(r&bt)*yu,r<J)||(r=t[e+6],n+=(r&bt)*bu,r<J)||(r=t[e+7],n+=(r&bt)*gu,r<J))return n;throw new RangeError("Could not decode varint")}function Jn(t,e,r=0){return e==null&&(e=pu(Ot(t))),e instanceof Uint8Array?ri(t,e,r):Wh(t,e,r)}var ni=new Float32Array([-0]),gt=new Uint8Array(ni.buffer);function wu(t,e,r){ni[0]=t,e[r]=gt[0],e[r+1]=gt[1],e[r+2]=gt[2],e[r+3]=gt[3]}function Eu(t,e){return gt[0]=t[e],gt[1]=t[e+1],gt[2]=t[e+2],gt[3]=t[e+3],ni[0]}var oi=new Float64Array([-0]),pe=new Uint8Array(oi.buffer);function vu(t,e,r){oi[0]=t,e[r]=pe[0],e[r+1]=pe[1],e[r+2]=pe[2],e[r+3]=pe[3],e[r+4]=pe[4],e[r+5]=pe[5],e[r+6]=pe[6],e[r+7]=pe[7]}function Su(t,e){return pe[0]=t[e],pe[1]=t[e+1],pe[2]=t[e+2],pe[3]=t[e+3],pe[4]=t[e+4],pe[5]=t[e+5],pe[6]=t[e+6],pe[7]=t[e+7],oi[0]}var Gh=BigInt(Number.MAX_SAFE_INTEGER),Yh=BigInt(Number.MIN_SAFE_INTEGER),Ce=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return kt;if(e<Gh&&e>Yh)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,o=e-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Au&&(o=0n,++n>Au&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return kt;let r=e<0;r&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new t(n,o)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):kt}},kt=new Ce(0,0);kt.toBigInt=function(){return 0n};kt.zzEncode=kt.zzDecode=function(){return this};kt.length=function(){return 1};var Au=4294967296n;function Cu(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function Iu(t,e,r){if(r-e<1)return"";let o,s=[],i=0,a;for(;e<r;)a=t[e++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function si(t,e,r){let n=r,o,s;for(let i=0;i<t.length;++i)o=t.charCodeAt(i),o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&((s=t.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128);return r-n}function Ue(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function eo(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var ii=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Ue(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ue(this,4);return eo(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ue(this,4);return eo(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ue(this,4);let e=Eu(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ue(this,4);let e=Su(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw Ue(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Iu(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ue(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ue(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Ce(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Ue(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw Ue(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ue(this,8);let e=eo(this.buf,this.pos+=4),r=eo(this.buf,this.pos+=4);return new Ce(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=xu(this.buf,this.pos);return this.pos+=Ot(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Gr(t){return new ii(t instanceof Uint8Array?t:t.subarray())}function be(t,e,r){let n=Gr(t);return e.decode(n,void 0,r)}function Pt(t=0){return new Uint8Array(t)}var li={};K(li,{base10:()=>np});var nw=new Uint8Array(0);function Du(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function et(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function _u(t){return new TextEncoder().encode(t)}function Bu(t){return new TextDecoder().decode(t)}function Xh(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var s=t.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function d(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var b=0,m=0,y=0,x=p.length;y!==x&&p[y]===0;)y++,b++;for(var w=(x-y)*f+1>>>0,C=new Uint8Array(w);y!==x;){for(var I=p[y],R=0,_=w-1;(I!==0||R<m)&&_!==-1;_--,R++)I+=256*C[_]>>>0,C[_]=I%a>>>0,I=I/a>>>0;if(I!==0)throw new Error("Non-zero carry");m=R,y++}for(var A=w-m;A!==w&&C[A]===0;)A++;for(var P=c.repeat(b);A<w;++A)P+=t.charAt(C[A]);return P}function l(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var b=0;if(p[b]!==" "){for(var m=0,y=0;p[b]===c;)m++,b++;for(var x=(p.length-b)*u+1>>>0,w=new Uint8Array(x);p[b];){var C=r[p.charCodeAt(b)];if(C===255)return;for(var I=0,R=x-1;(C!==0||I<y)&&R!==-1;R--,I++)C+=a*w[R]>>>0,w[R]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");y=I,b++}if(p[b]!==" "){for(var _=x-y;_!==x&&w[_]===0;)_++;for(var A=new Uint8Array(m+(x-_)),P=m;_!==x;)A[P++]=w[_++];return A}}}function h(p){var b=l(p);if(b)return b;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:l,decode:h}}var Qh=Xh,Jh=Qh,Ru=Jh;var ai=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},ci=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Ou(this,e)}},ui=class{decoders;constructor(e){this.decoders=e}or(e){return Ou(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ou(t,e){return new ui({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var fi=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new ai(e,r,n),this.decoder=new ci(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ar({name:t,prefix:e,encode:r,decode:n}){return new fi(t,e,r,n)}function xt({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=Ru(r,t);return ar({prefix:e,name:t,encode:n,decode:s=>et(o(s))})}function ep(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function tp(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function rp(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function ee({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=rp(n);return ar({prefix:e,name:t,encode(s){return tp(s,n,r)},decode(s){return ep(s,o,r,t)}})}var np=xt({prefix:"9",name:"base10",alphabet:"0123456789"});var di={};K(di,{base16:()=>op,base16upper:()=>sp});var op=ee({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),sp=ee({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var hi={};K(hi,{base2:()=>ip});var ip=ee({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var pi={};K(pi,{base256emoji:()=>lp});var ku=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),ap=ku.reduce((t,e,r)=>(t[r]=e,t),[]),cp=ku.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function up(t){return t.reduce((e,r)=>(e+=ap[r],e),"")}function fp(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=cp[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var lp=ar({prefix:"\u{1F680}",name:"base256emoji",encode:up,decode:fp});var mi={};K(mi,{base32:()=>cr,base32hex:()=>mp,base32hexpad:()=>bp,base32hexpadupper:()=>gp,base32hexupper:()=>yp,base32pad:()=>hp,base32padupper:()=>pp,base32upper:()=>dp,base32z:()=>xp});var cr=ee({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),dp=ee({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),hp=ee({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),pp=ee({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),mp=ee({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),yp=ee({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),bp=ee({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),gp=ee({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),xp=ee({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var yi={};K(yi,{base36:()=>Yr,base36upper:()=>wp});var Yr=xt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),wp=xt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var bi={};K(bi,{base58btc:()=>ze,base58flickr:()=>Ep});var ze=xt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ep=xt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var gi={};K(gi,{base64:()=>vp,base64pad:()=>Sp,base64url:()=>Ap,base64urlpad:()=>Cp});var vp=ee({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Sp=ee({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ap=ee({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Cp=ee({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var xi={};K(xi,{base8:()=>Ip});var Ip=ee({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var wi={};K(wi,{identity:()=>Tp});var Tp=ar({prefix:"\0",name:"identity",encode:t=>Bu(t),decode:t=>_u(t)});var xw=new TextEncoder,ww=new TextDecoder;var vi={};K(vi,{identity:()=>Yp});var Bp=Ku,Pu=128,Lp=127,Rp=~Lp,Op=Math.pow(2,31);function Ku(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Op;)e[r++]=t&255|Pu,t/=128;for(;t&Rp;)e[r++]=t&255|Pu,t>>>=7;return e[r]=t|0,Ku.bytes=r-n+1,e}var kp=Ei,Pp=128,Uu=127;function Ei(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw Ei.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&Uu)<<o:(i&Uu)*Math.pow(2,o),o+=7}while(i>=Pp);return Ei.bytes=s-n,r}var Up=Math.pow(2,7),Kp=Math.pow(2,14),Np=Math.pow(2,21),Fp=Math.pow(2,28),Mp=Math.pow(2,35),qp=Math.pow(2,42),zp=Math.pow(2,49),Vp=Math.pow(2,56),Hp=Math.pow(2,63),$p=function(t){return t<Up?1:t<Kp?2:t<Np?3:t<Fp?4:t<Mp?5:t<qp?6:t<zp?7:t<Vp?8:t<Hp?9:10},jp={encode:Bp,decode:kp,encodingLength:$p},Wp=jp,Xr=Wp;function Qr(t,e=0){return[Xr.decode(t,e),Xr.decode.bytes]}function ur(t,e,r=0){return Xr.encode(t,e,r),e}function fr(t){return Xr.encodingLength(t)}function dr(t,e){let r=e.byteLength,n=fr(t),o=n+fr(r),s=new Uint8Array(o+r);return ur(t,s,0),ur(r,s,n),s.set(e,o),new lr(t,r,e,s)}function Nu(t){let e=et(t),[r,n]=Qr(e),[o,s]=Qr(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new lr(r,o,i,e)}function Fu(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Du(t.bytes,r.bytes)}}var lr=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};var Mu=0,Zp="identity",qu=et;function Gp(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return dr(Mu,qu(t))}var Yp={code:Mu,name:Zp,encode:qu,digest:Gp};var Ci={};K(Ci,{sha256:()=>Qp,sha512:()=>Jp});var Xp=20;function Ai({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new Si(t,e,r,n,o)}var Si=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Xp,this.maxDigestLength=s}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?zu(n,this.code,r?.truncate):n.then(o=>zu(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function zu(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return dr(e,t)}function Hu(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Qp=Ai({name:"sha2-256",code:18,encode:Hu("SHA-256")}),Jp=Ai({name:"sha2-512",code:19,encode:Hu("SHA-512")});function $u(t,e){let{bytes:r,version:n}=t;return n===0?tm(r,Ii(t),e??ze.encoder):rm(r,Ii(t),e??cr.encoder)}var ju=new WeakMap;function Ii(t){let e=ju.get(t);if(e==null){let r=new Map;return ju.set(t,r),r}return e}var ro=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==en)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==nm)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=dr(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&Fu(e.multihash,n.multihash)}toString(e){return $u(this,e)}toJSON(){return{"/":$u(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new t(n,o,s,i??Wu(n,o,s.bytes))}else if(r[om]===!0){let{version:n,multihash:o,code:s}=r,i=Nu(o);return t.create(n,s,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==en)throw new Error(`Version 0 CID must use dag-pb (code: ${en}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=Wu(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,en,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=et(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new lr(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[d,l]=Qr(e.subarray(r));return r+=l,d},o=n(),s=en;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,o]=em(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ii(s).set(n,e),s}};function em(t,e){switch(t[0]){case"Q":{let r=e??ze;return[ze.prefix,r.decode(`${ze.prefix}${t}`)]}case ze.prefix:{let r=e??ze;return[ze.prefix,r.decode(t)]}case cr.prefix:{let r=e??cr;return[cr.prefix,r.decode(t)]}case Yr.prefix:{let r=e??Yr;return[Yr.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function tm(t,e,r){let{prefix:n}=r;if(n!==ze.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function rm(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var en=112,nm=18;function Wu(t,e,r){let n=fr(t),o=n+fr(e),s=new Uint8Array(o+r.byteLength);return ur(t,s,0),ur(e,s,n),s.set(r,o),s}var om=Symbol.for("@ipld/js-cid/CID");var Ti={...wi,...hi,...xi,...li,...di,...mi,...yi,...bi,...gi,...pi},zw={...Ci,...vi};function Gu(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Zu=Gu("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Di=Gu("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Pt(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),sm={utf8:Zu,"utf-8":Zu,hex:Ti.base16,latin1:Di,ascii:Di,binary:Di,...Ti},Yu=sm;function Xu(t,e="utf8"){let r=Yu[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function _i(t){let e=t??8192,r=e>>>1,n,o=e;return function(i){if(i<1||i>r)return Pt(i);o+i>e&&(n=Pt(e),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Ut=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Bi(){}var Ri=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},im=_i();function am(t){return globalThis.Buffer!=null?Pt(t):im(t)}var rn=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ut(Bi,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Ut(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Oi((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(no,10,Ce.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Ce.fromBigInt(e);return this._push(no,r.length(),r)}uint64Number(e){return this._push(ri,Ot(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=Ce.fromBigInt(e).zzEncode();return this._push(no,r.length(),r)}sint64Number(e){let r=Ce.fromNumber(e).zzEncode();return this._push(no,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Li,1,e?1:0)}fixed32(e){return this._push(tn,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Ce.fromBigInt(e);return this._push(tn,4,r.lo)._push(tn,4,r.hi)}fixed64Number(e){let r=Ce.fromNumber(e);return this._push(tn,4,r.lo)._push(tn,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(wu,4,e)}double(e){return this._push(vu,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Li,1,0):this.uint32(r)._push(um,r,e)}string(e){let r=Cu(e);return r!==0?this.uint32(r)._push(si,r,e):this._push(Li,1,0)}fork(){return this.states=new Ri(this),this.head=this.tail=new Ut(Bi,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Ut(Bi,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=am(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Li(t,e,r){e[r]=t&255}function cm(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var Oi=class extends Ut{next;constructor(e,r){super(cm,e,r),this.next=void 0}};function no(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function tn(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function um(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(rn.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(fm,e,t),this},rn.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(lm,e,t),this});function fm(t,e,r){e.set(t,r)}function lm(t,e,r){t.length<40?si(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(Xu(t),r)}function ki(){return new rn}function ge(t,e){let r=ki();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*xe(t,e,r){let n=Gr(t);yield*e.stream(n,void 0,"$",r)}var oo={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function so(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function Pi(t){function e(s){if(t[s.toString()]==null)throw new Error("Invalid enum value");return t[s]}let r=function(i,a){let c=e(i);a.int32(c)},n=function(i){let a=i.int32();return e(a)},o=function*(i){let a=i.int32();yield e(a)};return so("enum",oo.VARINT,r,n,o)}function we(t,e,r){return so("message",oo.LENGTH_DELIMITED,t,e,r)}var Be=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},nn=class extends Error{code="ERR_MAX_SIZE";name="MaxSizeError"};var Z;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(Z||(Z={}));var Ui;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(Ui||(Ui={}));(function(t){t.codec=()=>Pi(Ui)})(Z||(Z={}));var Ve;(function(t){let e;t.codec=()=>(e==null&&(e=we((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),Z.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=Z.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:Z.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ge(s,t.codec())}t.encode=r;function n(s,i){return be(s,t.codec(),i)}t.decode=n;function o(s,i){return xe(s,t.codec(),i)}t.stream=o})(Ve||(Ve={}));var Ki;(function(t){let e;t.codec=()=>(e==null&&(e=we((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),Z.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=Z.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:Z.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ge(s,t.codec())}t.encode=r;function n(s,i){return be(s,t.codec(),i)}t.decode=n;function o(s,i){return xe(s,t.codec(),i)}t.stream=o})(Ki||(Ki={}));var sn={};K(sn,{MAX_RSA_KEY_SIZE:()=>Ni,generateRSAKeyPair:()=>rf,jwkToJWKKeyPair:()=>nf,jwkToPkcs1:()=>mm,jwkToPkix:()=>zi,jwkToRSAPrivateKey:()=>ji,pkcs1MessageToJwk:()=>Mi,pkcs1MessageToRSAPrivateKey:()=>Vi,pkcs1ToJwk:()=>pm,pkcs1ToRSAPrivateKey:()=>tf,pkixMessageToJwk:()=>qi,pkixMessageToRSAPublicKey:()=>$i,pkixToJwk:()=>ym,pkixToRSAPublicKey:()=>Hi});var hr=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=sn.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return oe.createV1(114,this._multihash)}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:W(this.raw,e.raw)}verify(e,r,n){return ef(this.jwk,r,e,n)}},on=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=sn.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:W(this.raw,e.raw)}sign(e,r){return Ju(this.jwk,e,r)}};var Ni=8192,Fi=18,dm=1062,hm=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function pm(t){let e=Ze(t);return Mi(e)}function Mi(t){return{n:z(t[1],"base64url"),e:z(t[2],"base64url"),d:z(t[3],"base64url"),p:z(t[4],"base64url"),q:z(t[5],"base64url"),dp:z(t[6],"base64url"),dq:z(t[7],"base64url"),qi:z(t[8],"base64url"),kty:"RSA"}}function mm(t){if(t.n==null||t.e==null||t.d==null||t.p==null||t.q==null||t.dp==null||t.dq==null||t.qi==null)throw new M("JWK was missing components");return ct([ve(Uint8Array.from([0])),ve($(t.n,"base64url")),ve($(t.e,"base64url")),ve($(t.d,"base64url")),ve($(t.p,"base64url")),ve($(t.q,"base64url")),ve($(t.dp,"base64url")),ve($(t.dq,"base64url")),ve($(t.qi,"base64url"))]).subarray()}function ym(t){let e=Ze(t,{offset:0});return qi(e)}function qi(t){let e=Ze(t[1],{offset:0});return{kty:"RSA",n:z(e[0],"base64url"),e:z(e[1],"base64url")}}function zi(t){if(t.n==null||t.e==null)throw new M("JWK was missing components");return ct([hm,On(ct([ve($(t.n,"base64url")),ve($(t.e,"base64url"))]))]).subarray()}function tf(t){let e=Ze(t);return Vi(e)}function Vi(t){let e=Mi(t);return ji(e)}function Hi(t,e){if(t.byteLength>=dm)throw new zt("Key size is too large");let r=Ze(t,{offset:0});return $i(r,t,e)}function $i(t,e,r){let n=qi(t);if(r==null){let o=Qt(Ve.encode({Type:Z.RSA,Data:e}));r=Fe(Fi,o)}return new hr(n,r)}function ji(t){if(sf(t)>Ni)throw new M("Key size is too large");let e=nf(t),r=Qt(Ve.encode({Type:Z.RSA,Data:zi(e.publicKey)})),n=Fe(Fi,r);return new on(e.privateKey,new hr(e.publicKey,n))}async function rf(t){if(t>Ni)throw new M("Key size is too large");let e=await of(t),r=Qt(Ve.encode({Type:Z.RSA,Data:zi(e.publicKey)})),n=Fe(Fi,r);return new on(e.privateKey,new hr(e.publicKey,n))}function nf(t){if(t==null)throw new M("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function of(t,e){let r=await _e.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:t,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await bm(r,e);return{privateKey:n[0],publicKey:n[1]}}async function Ju(t,e,r){let n=await _e.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await _e.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,Se(e instanceof Uint8Array?e:e.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function ef(t,e,r,n){let o=await _e.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await _e.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,Se(e),Se(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),s}async function bm(t,e){if(t.privateKey==null||t.publicKey==null)throw new M("Private and public key are required");let r=await Promise.all([_e.get().subtle.exportKey("jwk",t.privateKey),_e.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function sf(t){if(t.kty!=="RSA")throw new M("invalid key type");if(t.n==null)throw new M("invalid key modulus");return $(t.n,"base64url").length*8}var io=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(kn(e),Ae(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Ye(o)}update(e){return Xt(this),this.iHash.update(e),this}digestInto(e){Xt(this),Pn(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},af=(()=>{let t=((e,r,n)=>new io(e,r).update(n).digest());return t.create=(e,r)=>new io(e,r),t})();var cf=(t,e)=>(t+(t>=0?e:-e)/uf)/e;function gm(t,e,r){tr("scalar",t,He,r);let[[n,o],[s,i]]=e,a=cf(i*t,r),c=cf(-o*t,r),u=t-a*n-c*s,f=-a*o-c*i,d=u<He,l=f<He;d&&(u=-u),l&&(f=-f);let h=Hr(Math.ceil(rr(r)/2))+wt;if(u<He||u>=h||f<He||f>=h)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:d,k1:u,k2neg:l,k2:f}}function Zi(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Wi(t,e){Pe(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Oe(r.lowS,"lowS"),Oe(r.prehash,"prehash"),r.format!==void 0&&Zi(r.format),r}var Gi=class extends Error{constructor(e=""){super(e)}},Ke={Err:Gi,_tlv:{encode:(t,e)=>{let{Err:r}=Ke;if(ke(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(typeof e!="string")throw new TypeError('"data" expected string, got type='+typeof e);if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=zr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?zr(o.length/2|128):"";return zr(t)+s+o+e},decode(t,e){let{Err:r}=Ke;e=q(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=Ke;if(zn(t),t<He)throw new e("integer: negative integers are not allowed");let r=zr(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=Ke;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return Dt(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=Ke,o=q(t,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:u,l:f}=n.decode(2,c);if(f.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(t){let{_tlv:e,_int:r}=Ke,n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),s=n+o;return e.encode(48,s)}};Object.freeze(Ke._tlv);Object.freeze(Ke._int);Object.freeze(Ke);var He=BigInt(0),wt=BigInt(1),uf=BigInt(2),ao=BigInt(3),xm=BigInt(4);function ff(t,e={}){let r=jn("weierstrass",t,e),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;Pe(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c,allowInfinityPoint:u}=e;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=df(n,o);function d(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(U,g,E){if(u&&g.is0())return Uint8Array.of(0);let{x:T,y:S}=g.toAffine(),v=n.toBytes(T);if(Oe(E,"isCompressed"),E){d();let D=!n.isOdd(S);return ie(lf(D),v)}else return ie(Uint8Array.of(4),v,n.toBytes(S))}function h(U){q(U,void 0,"Point");let{publicKey:g,publicKeyUncompressed:E}=f,T=U.length,S=U[0],v=U.subarray(1);if(u&&T===1&&S===0)return{x:n.ZERO,y:n.ZERO};if(T===g&&(S===2||S===3)){let D=n.fromBytes(v);if(!n.isValid(D))throw new Error("bad point: is not on curve, wrong x");let L=m(D),B;try{B=n.sqrt(L)}catch(F){let V=F instanceof Error?": "+F.message:"";throw new Error("bad point: is not on curve, sqrt error"+V)}d();let O=n.isOdd(B);return(S&1)===1!==O&&(B=n.neg(B)),{x:D,y:B}}else if(T===E&&S===4){let D=n.BYTES,L=n.fromBytes(v.subarray(0,D)),B=n.fromBytes(v.subarray(D,D*2));if(!y(L,B))throw new Error("bad point: is not on curve");return{x:L,y:B}}else throw new Error(`bad point: got length ${T}, expected compressed=${g} or uncompressed=${E}`)}let p=e.toBytes===void 0?l:e.toBytes,b=e.fromBytes===void 0?h:e.fromBytes;function m(U){let g=n.sqr(U),E=n.mul(g,U);return n.add(n.add(E,n.mul(U,s.a)),s.b)}function y(U,g){let E=n.sqr(g),T=m(U);return n.eql(E,T)}if(!y(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let x=n.mul(n.pow(s.a,ao),xm),w=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(x,w)))throw new Error("bad curve params: a or b");function C(U,g,E=!1){if(!n.isValid(g)||E&&n.is0(g))throw new Error(`bad point coordinate ${U}`);return g}function I(U){if(!(U instanceof A))throw new Error("Weierstrass Point expected")}function R(U){if(!c||!c.basises)throw new Error("no endo");return gm(U,c.basises,o.ORDER)}function _(U,g,E,T,S){return E=new A(n.mul(E.X,U),E.Y,E.Z),g=jr(T,g),E=jr(S,E),g.add(E)}class A{static BASE=new A(s.Gx,s.Gy,n.ONE);static ZERO=new A(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(g,E,T){this.X=C("x",g),this.Y=C("y",E,!0),this.Z=C("z",T),Object.freeze(this)}static CURVE(){return s}static fromAffine(g){let{x:E,y:T}=g||{};if(!g||!n.isValid(E)||!n.isValid(T))throw new Error("invalid affine point");if(g instanceof A)throw new Error("projective point not allowed");return n.is0(E)&&n.is0(T)?A.ZERO:new A(E,T,n.ONE)}static fromBytes(g){let E=A.fromAffine(b(q(g,void 0,"point")));return E.assertValidity(),E}static fromHex(g){return A.fromBytes(er(g))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,E=!0){return H.createCache(this,g),E||this.multiply(ao),this}assertValidity(){let g=this;if(g.is0()){if(e.allowInfinityPoint&&n.is0(g.X)&&n.eql(g.Y,n.ONE)&&n.is0(g.Z))return;throw new Error("bad point: ZERO")}let{x:E,y:T}=g.toAffine();if(!n.isValid(E)||!n.isValid(T))throw new Error("bad point: x or y not field elements");if(!y(E,T))throw new Error("bad point: equation left != right");if(!g.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:g}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(g)}equals(g){I(g);let{X:E,Y:T,Z:S}=this,{X:v,Y:D,Z:L}=g,B=n.eql(n.mul(E,L),n.mul(v,S)),O=n.eql(n.mul(T,L),n.mul(D,S));return B&&O}negate(){return new A(this.X,n.neg(this.Y),this.Z)}double(){let{a:g,b:E}=s,T=n.mul(E,ao),{X:S,Y:v,Z:D}=this,L=n.ZERO,B=n.ZERO,O=n.ZERO,k=n.mul(S,S),F=n.mul(v,v),V=n.mul(D,D),N=n.mul(S,v);return N=n.add(N,N),O=n.mul(S,D),O=n.add(O,O),L=n.mul(g,O),B=n.mul(T,V),B=n.add(L,B),L=n.sub(F,B),B=n.add(F,B),B=n.mul(L,B),L=n.mul(N,L),O=n.mul(T,O),V=n.mul(g,V),N=n.sub(k,V),N=n.mul(g,N),N=n.add(N,O),O=n.add(k,k),k=n.add(O,k),k=n.add(k,V),k=n.mul(k,N),B=n.add(B,k),V=n.mul(v,D),V=n.add(V,V),k=n.mul(V,N),L=n.sub(L,k),O=n.mul(V,F),O=n.add(O,O),O=n.add(O,O),new A(L,B,O)}add(g){I(g);let{X:E,Y:T,Z:S}=this,{X:v,Y:D,Z:L}=g,B=n.ZERO,O=n.ZERO,k=n.ZERO,F=s.a,V=n.mul(s.b,ao),N=n.mul(E,v),se=n.mul(T,D),ae=n.mul(S,L),ce=n.add(E,T),re=n.add(v,D);ce=n.mul(ce,re),re=n.add(N,se),ce=n.sub(ce,re),re=n.add(E,S);let Ee=n.add(v,L);return re=n.mul(re,Ee),Ee=n.add(N,ae),re=n.sub(re,Ee),Ee=n.add(T,S),B=n.add(D,L),Ee=n.mul(Ee,B),B=n.add(se,ae),Ee=n.sub(Ee,B),k=n.mul(F,re),B=n.mul(V,ae),k=n.add(B,k),B=n.sub(se,k),k=n.add(se,k),O=n.mul(B,k),se=n.add(N,N),se=n.add(se,N),ae=n.mul(F,ae),re=n.mul(V,re),se=n.add(se,ae),ae=n.sub(N,ae),ae=n.mul(F,ae),re=n.add(re,ae),N=n.mul(se,re),O=n.add(O,N),N=n.mul(Ee,re),B=n.mul(ce,B),B=n.sub(B,N),N=n.mul(ce,se),k=n.mul(Ee,k),k=n.add(k,N),new A(B,O,k)}subtract(g){return I(g),this.add(g.negate())}is0(){return this.equals(A.ZERO)}multiply(g){let{endo:E}=e;if(!o.isValidNot0(g))throw new RangeError("invalid scalar: out of range");let T,S,v=D=>H.cached(this,D,L=>Lt(A,L));if(E){let{k1neg:D,k1:L,k2neg:B,k2:O}=R(g),{p:k,f:F}=v(L),{p:V,f:N}=v(O);S=F.add(N),T=_(E.beta,k,V,D,B)}else{let{p:D,f:L}=v(g);T=D,S=L}return Lt(A,[T,S])[0]}multiplyUnsafe(g){let{endo:E}=e,T=this,S=g;if(!o.isValid(S))throw new RangeError("invalid scalar: out of range");if(S===He||T.is0())return A.ZERO;if(S===wt)return T;if(H.hasCache(this))return this.multiply(S);if(E){let{k1neg:v,k1:D,k2neg:L,k2:B}=R(S),{p1:O,p2:k}=nu(A,T,D,B);return _(E.beta,O,k,v,L)}else return H.unsafe(T,S)}toAffine(g){let E=this,T=g,{X:S,Y:v,Z:D}=E;if(n.eql(D,n.ONE))return{x:S,y:v};let L=E.is0();T==null&&(T=L?n.ONE:n.inv(D));let B=n.mul(S,T),O=n.mul(v,T),k=n.mul(D,T);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(k,n.ONE))throw new Error("invZ was invalid");return{x:B,y:O}}isTorsionFree(){let{isTorsionFree:g}=e;return i===wt?!0:g?g(A,this):H.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:g}=e;return i===wt?this:g?g(A,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===wt?this.is0():this.clearCofactor().is0()}toBytes(g=!0){return Oe(g,"isCompressed"),this.assertValidity(),p(A,this,g)}toHex(g=!0){return Jt(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let P=o.BITS,H=new sr(A,e.endo?Math.ceil(P/2):P);return P>=8&&A.BASE.precompute(8),Object.freeze(A.prototype),Object.freeze(A),A}function lf(t){return Uint8Array.of(t?2:3)}function df(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function wm(t,e={}){let{Fn:r}=t,n=e.randomBytes===void 0?qr:e.randomBytes,o=Object.assign(df(t.Fp,r),{seed:Math.max(Ms(r.ORDER),16)});function s(h){try{let p=r.fromBytes(h);return r.isValidNot0(p)}catch{return!1}}function i(h,p){let{publicKey:b,publicKeyUncompressed:m}=o;try{let y=h.length;return p===!0&&y!==b||p===!1&&y!==m?!1:!!t.fromBytes(h)}catch{return!1}}function a(h){return h=h===void 0?n(o.seed):h,qs(q(h,o.seed,"seed"),r.ORDER)}function c(h,p=!0){return t.BASE.multiply(r.fromBytes(h)).toBytes(p)}function u(h){let{secretKey:p,publicKey:b,publicKeyUncompressed:m}=o,y=r._lengths;if(!Tt(h))return;let x=q(h,void 0,"key").length,w=x===b||x===m,C=x===p||!!y?.includes(x);if(!(w&&C))return w}function f(h,p,b=!0){if(u(h)===!0)throw new Error("first arg must be private key");if(u(p)===!1)throw new Error("second arg must be public key");let m=r.fromBytes(h);return t.fromBytes(p).multiply(m).toBytes(b)}let d={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},l=Wn(a,c);return Object.freeze(d),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:l,Point:t,utils:d,lengths:o})}function hf(t,e,r={}){let n=e;kn(n),Pe(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?qr:r.randomBytes,s=r.hmac===void 0?(S,v)=>af(n,S,v):r.hmac,{Fp:i,Fn:a}=t,{ORDER:c,BITS:u}=a,{keygen:f,getPublicKey:d,getSharedSecret:l,utils:h,lengths:p}=wm(t,r),b={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},m=c*uf+wt<i.ORDER;function y(S){let v=c>>wt;return S>v}function x(S,v){if(!a.isValidNot0(v))throw new Error(`invalid signature ${S}: out of range 1..Point.Fn.ORDER`);return v}function w(){if(m)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function C(S,v){Zi(v);let D=p.signature,L=v==="compact"?D:v==="recovered"?D+1:void 0;return q(S,L)}class I{r;s;recovery;constructor(v,D,L){if(this.r=x("r",v),this.s=x("s",D),L!=null){if(w(),![0,1,2,3].includes(L))throw new Error("invalid recovery id");this.recovery=L}Object.freeze(this)}static fromBytes(v,D=b.format){C(v,D);let L;if(D==="der"){let{r:F,s:V}=Ke.toSig(q(v));return new I(F,V)}D==="recovered"&&(L=v[0],D="compact",v=v.subarray(1));let B=p.signature/2,O=v.subarray(0,B),k=v.subarray(B,B*2);return new I(a.fromBytes(O),a.fromBytes(k),L)}static fromHex(v,D){return this.fromBytes(er(v),D)}assertRecovery(){let{recovery:v}=this;if(v==null)throw new Error("invalid recovery id: must be present");return v}addRecoveryBit(v){return new I(this.r,this.s,v)}recoverPublicKey(v){let{r:D,s:L}=this,B=this.assertRecovery(),O=B===2||B===3?D+c:D;if(!i.isValid(O))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let k=i.toBytes(O),F=t.fromBytes(ie(lf((B&1)===0),k)),V=a.inv(O),N=_(q(v,void 0,"msgHash")),se=a.create(-N*V),ae=a.create(L*V),ce=t.BASE.multiplyUnsafe(se).add(F.multiplyUnsafe(ae));if(ce.is0())throw new Error("invalid recovery: point at infinify");return ce.assertValidity(),ce}hasHighS(){return y(this.s)}toBytes(v=b.format){if(Zi(v),v==="der")return er(Ke.hexFromSig(this));let{r:D,s:L}=this,B=a.toBytes(D),O=a.toBytes(L);return v==="recovered"?(w(),ie(Uint8Array.of(this.assertRecovery()),B,O)):ie(B,O)}toHex(v){return Jt(this.toBytes(v))}}Object.freeze(I.prototype),Object.freeze(I);let R=r.bits2int===void 0?function(v){if(v.length>8192)throw new Error("input is too large");let D=Dt(v),L=v.length*8-u;return L>0?D>>BigInt(L):D}:r.bits2int,_=r.bits2int_modN===void 0?function(v){return a.create(R(v))}:r.bits2int_modN,A=Hr(u);function P(S){return tr("num < 2^"+u,S,He,A),a.toBytes(S)}function H(S,v){return q(S,void 0,"message"),v?q(n(S),void 0,"prehashed message"):S}function U(S,v,D){let{lowS:L,prehash:B,extraEntropy:O}=Wi(D,b);S=H(S,B);let k=_(S),F=a.fromBytes(v);if(!a.isValidNot0(F))throw new Error("invalid private key");let V=[P(F),P(k)];if(O!=null&&O!==!1){let ce=O===!0?o(p.secretKey):O;V.push(q(ce,void 0,"extraEntropy"))}let N=ie(...V),se=k;function ae(ce){let re=R(ce);if(!a.isValidNot0(re))return;let Ee=a.inv(re),qt=t.BASE.multiply(re).toAffine(),Ir=a.create(qt.x);if(Ir===He)return;let In=a.create(Ee*a.create(se+Ir*F));if(In===He)return;let Za=(qt.x===Ir?0:2)|Number(qt.y&wt),Ga=In;return L&&y(In)&&(Ga=a.neg(In),Za^=1),new I(Ir,Ga,m?void 0:Za)}return{seed:N,k2sig:ae}}function g(S,v,D={}){let{seed:L,k2sig:B}=U(S,v,D);return Mc(n.outputLen,a.BYTES,s)(L,B).toBytes(D.format)}function E(S,v,D,L={}){let{lowS:B,prehash:O,format:k}=Wi(L,b);if(D=q(D,void 0,"publicKey"),v=H(v,O),!Tt(S)){let F=S instanceof I?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+F)}C(S,k);try{let F=I.fromBytes(S,k),V=t.fromBytes(D);if(B&&F.hasHighS())return!1;let{r:N,s:se}=F,ae=_(v),ce=a.inv(se),re=a.create(ae*ce),Ee=a.create(N*ce),qt=t.BASE.multiplyUnsafe(re).add(V.multiplyUnsafe(Ee));return qt.is0()?!1:a.create(qt.x)===N}catch{return!1}}function T(S,v,D={}){let{prehash:L}=Wi(D,b);return v=H(v,L),I.fromBytes(S,"recovered").recoverPublicKey(v).toBytes()}return Object.freeze({keygen:f,getPublicKey:d,getSharedSecret:l,utils:h,lengths:p,Point:t,sign:g,verify:E,recoverPublicKey:T,Signature:I,hash:n})}var Xi={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Em={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var pf=BigInt(2);function vm(t){let e=Xi.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=t*t*t%e,f=u*u*t%e,d=j(f,r,e)*f%e,l=j(d,r,e)*f%e,h=j(l,pf,e)*u%e,p=j(h,o,e)*h%e,b=j(p,s,e)*p%e,m=j(b,a,e)*b%e,y=j(m,c,e)*m%e,x=j(y,a,e)*b%e,w=j(x,r,e)*f%e,C=j(w,i,e)*p%e,I=j(C,n,e)*u%e,R=j(I,pf,e);if(!Yi.eql(Yi.sqr(R),t))throw new Error("Cannot find square root");return R}var Yi=nr(Xi.p,{sqrt:vm}),Sm=ff(Xi,{Fp:Yi,endo:Em}),pr=hf(Sm,Qt);function mf(t,e,r,n){let o=Or.digest(r instanceof Uint8Array?r:r.subarray());if(Xn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),pr.verify(e,s,t,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Zr(String(s))});try{return n?.signal?.throwIfAborted(),pr.verify(e,o.digest,t,{prehash:!1,format:"der"})}catch(s){throw new Zr(String(s))}}var co=class{type="secp256k1";raw;_key;constructor(e){this._key=bf(e),this.raw=yf(this._key)}toMultihash(){return Le.digest(De(this))}toCID(){return oe.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:W(this.raw,e.raw)}verify(e,r,n){return mf(this._key,r,e,n)}};function Qi(t){return new co(t)}function yf(t){return pr.Point.fromBytes(t).toBytes()}function bf(t){try{return pr.Point.fromBytes(t),t}catch(e){throw new zt(String(e))}}function uo(t,e){let{Type:r,Data:n}=Ve.decode(t),o=n??new Uint8Array;switch(r){case Z.RSA:return Hi(o,e);case Z.Ed25519:return ti(o);case Z.secp256k1:return Qi(o);case Z.ECDSA:return Ss(o);default:throw new vt}}function gf(t){let{Type:e,Data:r}=Ve.decode(t.digest),n=r??new Uint8Array;switch(e){case Z.Ed25519:return ti(n);case Z.secp256k1:return Qi(n);case Z.ECDSA:return Ss(n);default:throw new vt}}function De(t){return Ve.encode({Type:Z[t.type],Data:t.raw})}var xf=Symbol.for("nodejs.util.inspect.custom"),Am=114,an=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[_n]=!0;toString(){return this.string==null&&(this.string=X.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return oe.createV1(Am,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return W(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return W(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[xf](){return`PeerId(${this.toString()})`}},cn=class extends an{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},un=class extends an{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},fn=class extends an{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Cm=2336,ln=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Le.digest($(this.url))}[xf](){return`PeerId(${this.url})`}[_n]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return oe.createV1(Cm,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=z(e)),e.toString()===this.toString())}};var Im=114,wf=2336;function Ef(t){if(t.type==="Ed25519")return new un({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new fn({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new cn({multihash:t.toCID().multihash,publicKey:t});throw new vt}function Ji(t){if(Dm(t))return new cn({multihash:t});if(Tm(t))try{let e=gf(t);if(e.type==="Ed25519")return new un({multihash:t,publicKey:e});if(e.type==="secp256k1")return new fn({multihash:t,publicKey:e})}catch{let r=z(t.digest);return new ln(new URL(r))}throw new Dn("Supplied PeerID Multihash is invalid")}function fo(t){if(t?.multihash==null||t.version==null||t.version===1&&t.code!==Im&&t.code!==wf)throw new Tn("Supplied PeerID CID is invalid");if(t.code===wf){let e=z(t.multihash.digest);return new ln(new URL(e))}return Ji(t.multihash)}function Tm(t){return t.code===Le.code}function Dm(t){return t.code===Or.code}var dn;(function(t){let e;t.codec=()=>(e==null&&(e=we((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.publicKey!=null&&s.publicKey.byteLength>0&&(i.uint32(10),i.bytes(s.publicKey)),s.payloadType!=null&&s.payloadType.byteLength>0&&(i.uint32(18),i.bytes(s.payloadType)),s.payload!=null&&s.payload.byteLength>0&&(i.uint32(26),i.bytes(s.payload)),s.signature!=null&&s.signature.byteLength>0&&(i.uint32(42),i.bytes(s.signature)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={publicKey:Te(0),payloadType:Te(0),payload:Te(0),signature:Te(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.publicKey=s.bytes();break}case 2:{c.payloadType=s.bytes();break}case 3:{c.payload=s.bytes();break}case 5:{c.signature=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.publicKey`,value:s.bytes()};break}case 2:{yield{field:`${a}.payloadType`,value:s.bytes()};break}case 3:{yield{field:`${a}.payload`,value:s.bytes()};break}case 5:{yield{field:`${a}.signature`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ge(s,t.codec())}t.encode=r;function n(s,i){return be(s,t.codec(),i)}t.decode=n;function o(s,i){return xe(s,t.codec(),i)}t.stream=o})(dn||(dn={}));var lo=class extends Error{constructor(e="Invalid signature"){super(e),this.name="InvalidSignatureError"}};var mr=class t{static createFromProtobuf=e=>{let r=dn.decode(e),n=uo(r.publicKey);return new t({publicKey:n,payloadType:r.payloadType,payload:r.payload,signature:r.signature})};static seal=async(e,r,n)=>{if(r==null)throw new Error("Missing private key");let o=e.domain,s=e.codec,i=e.marshal(),a=vf(o,s,i),c=await r.sign(a.subarray(),n);return new t({publicKey:r.publicKey,payloadType:s,payload:i,signature:c})};static openAndCertify=async(e,r,n)=>{let o=t.createFromProtobuf(e);if(!await o.validate(r,n))throw new lo("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(e){let{publicKey:r,payloadType:n,payload:o,signature:s}=e;this.publicKey=r,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=dn.encode({publicKey:De(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(e){return e==null?!1:W(this.marshal(),e.marshal())}async validate(e,r){let n=vf(e,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},vf=(t,e,r)=>{let n=$(t),o=Jn(n.byteLength),s=Jn(e.length),i=Jn(r.length);return new ye(o,n,s,e,i,r)};var _m=Math.pow(2,7),Bm=Math.pow(2,14),Lm=Math.pow(2,21),ea=Math.pow(2,28),ta=Math.pow(2,35),ra=Math.pow(2,42),na=Math.pow(2,49),G=128,me=127;function yr(t){if(t<_m)return 1;if(t<Bm)return 2;if(t<Lm)return 3;if(t<ea)return 4;if(t<ta)return 5;if(t<ra)return 6;if(t<na)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function oa(t,e,r=0){switch(yr(t)){case 8:e[r++]=t&255|G,t/=128;case 7:e[r++]=t&255|G,t/=128;case 6:e[r++]=t&255|G,t/=128;case 5:e[r++]=t&255|G,t/=128;case 4:e[r++]=t&255|G,t>>>=7;case 3:e[r++]=t&255|G,t>>>=7;case 2:e[r++]=t&255|G,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Rm(t,e){let r=t[e],n=0;if(n+=r&me,r<G||(r=t[e+1],n+=(r&me)<<7,r<G)||(r=t[e+2],n+=(r&me)<<14,r<G)||(r=t[e+3],n+=(r&me)<<21,r<G)||(r=t[e+4],n+=(r&me)*ea,r<G)||(r=t[e+5],n+=(r&me)*ta,r<G)||(r=t[e+6],n+=(r&me)*ra,r<G)||(r=t[e+7],n+=(r&me)*na,r<G))return n;throw new RangeError("Could not decode varint")}function Om(t,e){let r=t.get(e),n=0;if(n+=r&me,r<G||(r=t.get(e+1),n+=(r&me)<<7,r<G)||(r=t.get(e+2),n+=(r&me)<<14,r<G)||(r=t.get(e+3),n+=(r&me)<<21,r<G)||(r=t.get(e+4),n+=(r&me)*ea,r<G)||(r=t.get(e+5),n+=(r&me)*ta,r<G)||(r=t.get(e+6),n+=(r&me)*ra,r<G)||(r=t.get(e+7),n+=(r&me)*na,r<G))return n;throw new RangeError("Could not decode varint")}function sa(t,e=0){return t instanceof Uint8Array?Rm(t,e):Om(t,e)}var he=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},tt=class extends Error{static name="ValidationError";name="ValidationError"},ho=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},po=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var mo=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let r=this.index,n=e();return n===void 0&&(this.index=r),n}parseWith(e){let r=e();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let r=this.readChar();if(r===e)return r})}readSeparator(e,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let d=this.readChar();if(d===void 0)return;let l=Number.parseInt(d,e);if(!Number.isNaN(l))return l});if(f===void 0)break;if(s*=e,s+=f,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let r=0;r<e.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[r]=n}return e})}readIPv6Addr(){let e=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=e(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Pm=45,Um=15,yo=new mo;function Sf(t){if(!(t.length>Um))return yo.new(t).parseWith(()=>yo.readIPv4Addr())}function Af(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>Pm))return yo.new(t).parseWith(()=>yo.readIPv6Addr())}function bo(t){return!!Sf(t)}function Cf(t){return!!Af(t)}function aa(t){return e=>z(e,t)}function ca(t){return e=>$(e,t)}function br(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Kt(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function If(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let r=$(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Kt(n);return Rt([r,o],r.length+o.length)}function Tf(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=Ne.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Kt(n);return Rt([r,o],r.length+o.length)}function ua(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=z(e,"base32"),o=br(r);return`${n}:${o}`}var fa=function(t){t=t.toString().trim();let e=new Uint8Array(4);return t.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new he("Invalid byte value in IP address");e[n]=o}),e},Df=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let s=bo(r[n]),i;s&&(i=fa(r[n]),r[n]=z(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,z(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(e+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new he("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},_f=function(t){if(t.byteLength!==4)throw new he("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},Bf=function(t){if(t.byteLength!==16)throw new he("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let o=t[n],s=t[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let r=e.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new he(`Invalid IPv6 address "${r}"`)}};function Lf(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new he(`Invalid IPv6 address "${t}"`)}}var ia=Object.values(kr).map(t=>t.decoder),Km=(function(){let t=ia[0].or(ia[1]);return ia.slice(2).forEach(e=>t=t.or(e)),t})();function Rf(t){return Km.decode(t)}function Of(t){return e=>t.encoder.encode(e)}function Nm(t){if(parseInt(t).toString()!==t)throw new tt("Value must be an integer")}function Fm(t){if(t<0)throw new tt("Value must be a positive integer, or zero")}function Mm(t){return e=>{if(e>t)throw new tt(`Value must be smaller than or equal to ${t}`)}}function qm(...t){return e=>{for(let r of t)r(e)}}var hn=qm(Nm,Fm,Mm(65535));var fe=-1,la=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let r;if(typeof e=="string"?r=this.protocolsByName.get(e):r=this.protocolsByCode.get(e),r==null)throw new po(`Protocol ${e} was unknown`);return r}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(r=>{this.protocolsByName.set(r,e)})}removeProtocol(e){let r=this.protocolsByCode.get(e);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},rt=new la,T0=[{code:4,name:"ip4",size:32,valueToBytes:fa,bytesToValue:_f,validate:t=>{if(!bo(t))throw new tt(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Kt,bytesToValue:br,validate:hn},{code:273,name:"udp",size:16,valueToBytes:Kt,bytesToValue:br,validate:hn},{code:33,name:"dccp",size:16,valueToBytes:Kt,bytesToValue:br,validate:hn},{code:41,name:"ip6",size:128,valueToBytes:Df,bytesToValue:Bf,stringToValue:Lf,validate:t=>{if(!Cf(t))throw new tt(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:fe},{code:43,name:"ipcidr",size:8,bytesToValue:aa("base10"),valueToBytes:ca("base10")},{code:53,name:"dns",size:fe},{code:54,name:"dns4",size:fe},{code:55,name:"dns6",size:fe},{code:56,name:"dnsaddr",size:fe},{code:132,name:"sctp",size:16,valueToBytes:Kt,bytesToValue:br,validate:hn},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:fe,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:fe,bytesToValue:aa("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?ca("base58btc")(t):oe.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:ua,valueToBytes:If},{code:445,name:"onion3",size:296,bytesToValue:ua,valueToBytes:Tf},{code:446,name:"garlic64",size:fe},{code:447,name:"garlic32",size:fe},{code:448,name:"tls"},{code:449,name:"sni",size:fe},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:fe,bytesToValue:Of(fs),valueToBytes:Rf},{code:480,name:"http"},{code:481,name:"http-path",size:fe,stringToValue:t=>`/${decodeURIComponent(t)}`,valueToString:t=>encodeURIComponent(t.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:fe}];T0.forEach(t=>{rt.addProtocol(t)});function kf(t){let e=[],r=0;for(;r<t.length;){let n=sa(t,r),o=rt.getProtocol(n),s=yr(n),i=D0(o,t,r+s),a=0;i>0&&o.size===fe&&(a=yr(i));let c=s+a+i,u={code:n,name:o.name,bytes:Se(t.subarray(r,r+c))};if(i>0){let f=r+s+a,d=t.subarray(f,f+i);u.value=o.bytesToValue?.(d)??z(d)}e.push(u),r+=c}return e}function Pf(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=rt.getProtocol(n.code),s=yr(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??$(n.value),a=i.byteLength,o.size===fe&&(c=yr(a)));let u=new Uint8Array(s+c+a),f=0;oa(n.code,u,f),f+=s,i!=null&&(o.size===fe&&(oa(a,u,f),f+=c),u.set(i,f)),n.bytes=u}r.push(n.bytes),e+=n.bytes.byteLength}return Rt(r,e)}function Uf(t){if(t.charAt(0)!=="/")throw new he('String multiaddr must start with "/"');let e=[],r="protocol",n="",o="";for(let s=1;s<t.length;s++){let i=t.charAt(s);i!=="/"&&(r==="protocol"?o+=t.charAt(s):n+=t.charAt(s));let a=s===t.length-1;if(i==="/"||a){let c=rt.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new he(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new he(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}e.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new he("Incomplete multiaddr");return e}function Kf(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=rt.getProtocol(e.code);if(r==null)throw new he(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function D0(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:sa(e,r)}var _0=Symbol.for("nodejs.util.inspect.custom"),ha=Symbol.for("@multiformats/multiaddr");function B0(t){if(t==null&&(t="/"),xo(t))return t.getComponents();if(t instanceof Uint8Array)return kf(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),Uf(t);if(Array.isArray(t))return t;throw new he("Must be a string, Uint8Array, Component[], or another Multiaddr")}var go=class t{[ha]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=B0(e),r.validate!==!1&&L0(this)}get bytes(){return this.#r==null&&(this.#r=Pf(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=Kf(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let r=new t(e);return new t([...this.#e,...r.getComponents()],{validate:!1})}decapsulate(e){let r=e.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new ho(`Address ${this.toString()} does not contain subaddress: ${r}`);return new t(n.slice(0,o),{validate:!1})}decapsulateCode(e){let r;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){r=n;break}return new t(this.#e.slice(0,r),{validate:!1})}equals(e){return W(this.bytes,e.bytes)}[_0](){return`Multiaddr(${this.toString()})`}};function L0(t){t.getComponents().forEach(e=>{let r=rt.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function xo(t){return!!t?.[ha]}function Nt(t){return new go(t)}var Nf="libp2p-peer-record",Ff=Uint8Array.from([3,1]);var pn;(function(t){let e;(function(i){let a;i.codec=()=>(a==null&&(a=we((d,l,h={})=>{h.lengthDelimited!==!1&&l.fork(),d.multiaddr!=null&&d.multiaddr.byteLength>0&&(l.uint32(10),l.bytes(d.multiaddr)),h.lengthDelimited!==!1&&l.ldelim()},(d,l,h={})=>{let p={multiaddr:Te(0)},b=l==null?d.len:d.pos+l;for(;d.pos<b;){let m=d.uint32();m>>>3===1?p.multiaddr=d.bytes():d.skipType(m&7)}return p},function*(d,l,h,p={}){let b=l==null?d.len:d.pos+l;for(;d.pos<b;){let m=d.uint32();m>>>3===1?yield{field:`${h}.multiaddr`,value:d.bytes()}:d.skipType(m&7)}})),a);function c(d){return ge(d,i.codec())}i.encode=c;function u(d,l){return be(d,i.codec(),l)}i.decode=u;function f(d,l){return xe(d,i.codec(),l)}i.stream=f})(e=t.AddressInfo||(t.AddressInfo={}));let r;t.codec=()=>(r==null&&(r=we((i,a,c={})=>{if(c.lengthDelimited!==!1&&a.fork(),i.peerId!=null&&i.peerId.byteLength>0&&(a.uint32(10),a.bytes(i.peerId)),i.seq!=null&&i.seq!==0n&&(a.uint32(16),a.uint64(i.seq)),i.addresses!=null&&i.addresses.length>0)for(let u of i.addresses)a.uint32(26),t.AddressInfo.codec().encode(u,a);c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let u={peerId:Te(0),seq:0n,addresses:[]},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let d=i.uint32();switch(d>>>3){case 1:{u.peerId=i.bytes();break}case 2:{u.seq=i.uint64();break}case 3:{if(c.limits?.addresses!=null&&u.addresses.length===c.limits.addresses)throw new Be('Decode error - repeated field "addresses" had too many elements');u.addresses.push(t.AddressInfo.codec().decode(i,i.uint32(),{limits:c.limits?.addresses$}));break}default:{i.skipType(d&7);break}}}return u},function*(i,a,c,u={}){let f={addresses:0},d=a==null?i.len:i.pos+a;for(;i.pos<d;){let l=i.uint32();switch(l>>>3){case 1:{yield{field:`${c}.peerId`,value:i.bytes()};break}case 2:{yield{field:`${c}.seq`,value:i.uint64()};break}case 3:{if(u.limits?.addresses!=null&&f.addresses===u.limits.addresses)throw new Be('Streaming decode error - repeated field "addresses" had too many elements');for(let h of t.AddressInfo.codec().stream(i,i.uint32(),`${c}.addresses[]`,{limits:u.limits?.addresses$}))yield{...h,index:f.addresses};f.addresses++;break}default:{i.skipType(l&7);break}}}})),r);function n(i){return ge(i,t.codec())}t.encode=n;function o(i,a){return be(i,t.codec(),a)}t.decode=o;function s(i,a){return xe(i,t.codec(),a)}t.stream=s})(pn||(pn={}));function Mf(t,e){let r=(n,o)=>n.toString().localeCompare(o.toString());return t.length!==e.length?!1:(e.sort(r),t.sort(r).every((n,o)=>e[o].equals(n)))}var Ft=class t{static createFromProtobuf=e=>{let r=pn.decode(e),n=Ji(Gt(r.peerId)),o=(r.addresses??[]).map(i=>Nt(i.multiaddr)),s=r.seq;return new t({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Nf;static CODEC=Ff;peerId;multiaddrs;seqNumber;domain=t.DOMAIN;codec=t.CODEC;marshaled;constructor(e){let{peerId:r,multiaddrs:n,seqNumber:o}=e;this.peerId=r,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=pn.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(e=>({multiaddr:e.bytes}))})),this.marshaled}equals(e){return!(!(e instanceof t)||!this.peerId.equals(e.peerId)||this.seqNumber!==e.seqNumber||!Mf(this.multiaddrs,e.multiaddrs))}};function R0(t){return t[Symbol.asyncIterator]!=null}function O0(t){if(R0(t))return(async()=>{let r=[];for await(let n of t)r.push(n);return r})();let e=[];for(let r of t)e.push(r);return e}var qf=O0;function wo(t,e){let r={[Symbol.iterator]:()=>r,next:()=>{let n=t.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:e(o)}}};return r}var mn=class{map;constructor(e){if(this.map=new Map,e!=null)for(let[r,n]of e.entries())this.map.set(r.toString(),{key:r,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(e){return this.map.delete(e.toString())}entries(){return wo(this.map.entries(),e=>[e[1].key,e[1].value])}forEach(e){this.map.forEach((r,n)=>{e(r.value,r.key,this)})}get(e){return this.map.get(e.toString())?.value}has(e){return this.map.has(e.toString())}set(e,r){this.map.set(e.toString(),{key:e,value:r})}keys(){return wo(this.map.values(),e=>e.key)}values(){return wo(this.map.values(),e=>e.value)}get size(){return this.map.size}};function Eo(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var vo=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},gr=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new vo(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let r=this.head;this.head=r.next=new vo(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var pa=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function zf(t={}){return k0(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},t)}function k0(t,e){e=e??{};let r=e.onEnd,n=new gr,o,s,i,a=Eo(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((m,y)=>{s=x=>{s=null,n.push(x);try{m(t(n))}catch(w){y(w)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Eo()})}},u=m=>s!=null?s(m):(n.push(m),o),f=m=>(n=new gr,s!=null?s({error:m}):(n.push({error:m}),o)),d=m=>{if(i)return o;if(e?.objectMode!==!0&&m?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:m})},l=m=>i?o:(i=!0,m!=null?f(m):u({done:!0})),h=()=>(n=new gr,l(),{done:!0}),p=m=>(l(m),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:h,throw:p,push:d,end:l,get readableLength(){return n.size},onEmpty:async m=>{let y=m?.signal;if(y?.throwIfAborted(),n.isEmpty())return;let x,w;y!=null&&(x=new Promise((C,I)=>{w=()=>{I(new pa)},y.addEventListener("abort",w)}));try{await Promise.race([a.promise,x])}finally{w!=null&&y!=null&&y?.removeEventListener("abort",w)}}},r==null)return o;let b=o;return o={[Symbol.asyncIterator](){return this},next(){return b.next()},throw(m){return b.throw(m),r!=null&&(r(m),r=void 0),{done:!0}},return(){return b.return(),r!=null&&(r(),r=void 0),{done:!0}},push:d,end(m){return b.end(m),r!=null&&(r(m),r=void 0),o},get readableLength(){return b.readableLength},onEmpty:m=>b.onEmpty(m)},o}function P0(t){return t.reason}async function Vf(t,e,r){if(e==null)return t;let n=r?.translateError??P0;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var ma=class extends mn{metric;constructor(e){super();let{name:r,metrics:n}=e;this.metric=n.registerMetric(r),this.updateComponentMetric()}set(e,r){return super.set(e,r),this.updateComponentMetric(),this}delete(e){let r=super.delete(e);return this.updateComponentMetric(),r}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function ya(t){let{name:e,metrics:r}=t,n;return r!=null?n=new ma({name:e,metrics:r}):n=new mn,n}var Ie=class extends Error{static name="AbortError";name="AbortError";constructor(e="The operation was aborted",...r){super(e,...r)}};async function So(t,e,r,n){let o=new Ie(n?.errorMessage);n?.errorCode!=null&&(o.code=n.errorCode);let s=n?.errorEvent??"error";return r?.aborted===!0?Promise.reject(o):new Promise((i,a)=>{function c(){ga(r,"abort",d),ga(t,e,u),ga(t,s,f)}let u=l=>{try{if(n?.filter?.(l)===!1)return}catch(h){c(),a(h);return}c(),i(l)},f=l=>{if(c(),l instanceof Error){a(l);return}a(l.detail??n?.error??new Error(`The "${n?.errorEvent}" event was emitted but the event had no '.detail' field. Pass an 'error' option to race-event to change this message.`))},d=()=>{c(),a(o)};ba(r,"abort",d),ba(t,e,u),ba(t,s,f)})}function ba(t,e,r){t!=null&&(Hf(t)?t.addEventListener(e,r):t.addListener(e,r))}function ga(t,e,r){t!=null&&(Hf(t)?t.removeEventListener(e,r):t.removeListener(e,r))}function Hf(t){return typeof t.addEventListener=="function"&&typeof t.removeEventListener=="function"}var Ao=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};var Co=class{deferred;signal;constructor(e){this.signal=e,this.deferred=Promise.withResolvers(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new Ie)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function U0(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Io=class{id;fn;options;recipients;status;timeline;controller;constructor(e,r){this.id=U0(),this.status="queued",this.fn=e,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new Ie),this.cleanup())}async join(e={}){let r=new Co(e.signal);return this.recipients.push(r),e.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await Vf(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(r=>{r.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};function xa(t,e){let r,n=function(){let o=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var yn=class extends Ht{concurrency;maxSize;queue;pending;sort;autoStart;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.maxSize=e.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.autoStart=e.autoStart??!0,this.sort=e.sort,this.queue=[],this.emitEmpty=xa(this.emitEmpty.bind(this),1),this.emitIdle=xa(this.emitIdle.bind(this),1)}[Symbol.asyncIterator](){return this.toGenerator()}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}tryToStartAnother(){if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let e;for(let r of this.queue)if(r.status==="queued"){e=r;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===e){this.queue.splice(r,1);break}this.pending--,this.safeDispatchEvent("next"),this.autoStart&&this.tryToStartAnother()}),!0)}return!1}enqueue(e){this.queue.push(e),this.sort!=null&&this.queue.sort(this.sort)}start(){this.autoStart===!1&&(this.autoStart=!0,this.tryToStartAnother())}pause(){this.autoStart=!1}async add(e,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new Ao;let n=new Io(e,r);return this.enqueue(n),this.safeDispatchEvent("add"),this.autoStart&&this.tryToStartAnother(),n.join(r).then(o=>(this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new Ie)}),this.clear()}async onEmpty(e){this.size!==0&&await So(this,"empty",e?.signal)}async onSizeLessThan(e,r){this.size<e||await So(this,"next",r?.signal,{filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await So(this,"idle",e?.signal)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let r=zf({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},o=c=>{c.detail!=null&&r.push(c.detail.result)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new Ie("Queue aborted"))};this.addEventListener("success",o),this.addEventListener("failure",s),this.addEventListener("idle",i),e?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("success",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),e?.signal?.removeEventListener("abort",a),n()}}};var To="lock:worker:request-read",Do="lock:worker:abort-read-request",_o="lock:worker:release-read",Bo="lock:master:grant-read",Lo="lock:master:error-read",Ro="lock:worker:request-write",Oo="lock:worker:abort-write-request",ko="lock:worker:release-write",Po="lock:master:grant-write",Uo="lock:master:error-write",Ko="lock:worker:finalize",No="mortice",$f={singleProcess:!1};var wa=(t,e,r,n,o,s,i,a,c)=>u=>{if(u.data==null)return;let f={type:u.data.type,name:u.data.name,identifier:u.data.identifier};f.type===o&&t.safeDispatchEvent(r,{detail:{name:f.name,identifier:f.identifier,handler:async()=>{e.postMessage({type:c,name:f.name,identifier:f.identifier}),await new Promise(d=>{let l=h=>{if(h?.data==null)return;let p={type:h.data.type,name:h.data.name,identifier:h.data.identifier};p.type===a&&p.identifier===f.identifier&&(e.removeEventListener("message",l),d())};e.addEventListener("message",l)})},onError:d=>{e.postMessage({type:i,name:f.name,identifier:f.identifier,error:{message:d.message,name:d.name,stack:d.stack}})}}}),f.type===s&&t.safeDispatchEvent(n,{detail:{name:f.name,identifier:f.identifier}}),f.type===Ko&&t.safeDispatchEvent("finalizeRequest",{detail:{name:f.name}})};var jf=(t=10)=>Math.random().toString().substring(2,t+2);var Fo=class{name;channel;constructor(e){this.name=e,this.channel=new BroadcastChannel(No)}readLock(e){return this.sendRequest(To,Do,Bo,Lo,_o,e)}writeLock(e){return this.sendRequest(Ro,Oo,Po,Uo,ko,e)}finalize(){this.channel.postMessage({type:Ko,name:this.name}),this.channel.close()}async sendRequest(e,r,n,o,s,i){i?.signal?.throwIfAborted();let a=jf();return this.channel.postMessage({type:e,identifier:a,name:this.name}),new Promise((c,u)=>{let f=()=>{this.channel.postMessage({type:r,identifier:a,name:this.name})};i?.signal?.addEventListener("abort",f,{once:!0});let d=l=>{if(l.data?.identifier===a&&(l.data?.type===n&&(this.channel.removeEventListener("message",d),i?.signal?.removeEventListener("abort",f),c(()=>{this.channel.postMessage({type:s,identifier:a,name:this.name})})),l.data.type===o)){this.channel.removeEventListener("message",d),i?.signal?.removeEventListener("abort",f);let h=new Error;l.data.error!=null&&(h.message=l.data.error.message,h.name=l.data.error.name,h.stack=l.data.error.stack),u(h)}};this.channel.addEventListener("message",d)})}};var Wf=t=>{if(t=Object.assign({},$f,t),!!globalThis.document||t.singleProcess){let r=new BroadcastChannel(No),n=new Ht;return r.addEventListener("message",wa(n,r,"requestReadLock","abortReadLockRequest",To,Do,Lo,_o,Bo)),r.addEventListener("message",wa(n,r,"requestWriteLock","abortWriteLockRequest",Ro,Oo,Uo,ko,Po)),n}return new Fo(t.name)};var Mt=new Map,bn;function Zf(t){return typeof t?.readLock=="function"&&typeof t?.writeLock=="function"}function K0(t){if(bn==null&&(bn=Wf(t),!Zf(bn))){let e=bn;e.addEventListener("requestReadLock",r=>{let n=r.detail.name,o=r.detail.identifier,s=Mt.get(n);if(s==null)return;let i=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==o||i.abort()};e.addEventListener("abortReadLockRequest",a),s.readLock({signal:i.signal}).then(async c=>{await r.detail.handler().finally(()=>{c()})}).catch(c=>{r.detail.onError(c)}).finally(()=>{e.removeEventListener("abortReadLockRequest",a)})}),e.addEventListener("requestWriteLock",r=>{let n=r.detail.name,o=r.detail.identifier,s=Mt.get(n);if(s==null)return;let i=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==o||i.abort()};e.addEventListener("abortWriteLockRequest",a),s.writeLock({signal:i.signal}).then(async c=>{await r.detail.handler().finally(()=>{c()})}).catch(c=>{r.detail.onError(c)}).finally(()=>{e.removeEventListener("abortWriteLockRequest",a)})}),e.addEventListener("finalizeRequest",r=>{let n=r.detail.name,o=Mt.get(n);o?.finalize()})}return bn}async function Ea(t,e){let r,n,o=new Promise((i,a)=>{r=i,n=a}),s=()=>{n(new Ie)};return e?.signal?.addEventListener("abort",s,{once:!0}),t.add(async()=>{await new Promise(i=>{r(()=>{e?.signal?.removeEventListener("abort",s),i()})})},{signal:e?.signal}).catch(i=>{n(i)}),o}var Gf=(t,e)=>{let r=Mt.get(t);if(r!=null)return r;let n=K0(e);if(Zf(n))return r=n,Mt.set(t,r),r;let o=new yn({concurrency:1}),s;return r={async readLock(i){if(s!=null)return Ea(s,i);s=new yn({concurrency:e.concurrency,autoStart:!1});let a=s,c=Ea(s,i);return o.add(async()=>{a.start(),await a.onIdle().then(()=>{s===a&&(s=null)})}),c},async writeLock(i){return s=null,Ea(o,i)},finalize:()=>{Mt.delete(t)},queue:o},Mt.set(t,r),e.autoFinalize===!0&&o.addEventListener("idle",()=>{r.finalize()},{once:!0}),r};var N0={name:"lock",concurrency:1/0,singleProcess:!1,autoFinalize:!1};function va(t){let e=Object.assign({},N0,t);return Gf(e.name,e)}var nt;(function(t){let e;(function(a){let c;a.codec=()=>(c==null&&(c=we((l,h,p={})=>{p.lengthDelimited!==!1&&h.fork(),l.key!=null&&l.key!==""&&(h.uint32(10),h.string(l.key)),l.value!=null&&l.value.byteLength>0&&(h.uint32(18),h.bytes(l.value)),p.lengthDelimited!==!1&&h.ldelim()},(l,h,p={})=>{let b={key:"",value:Te(0)},m=h==null?l.len:l.pos+h;for(;l.pos<m;){let y=l.uint32();switch(y>>>3){case 1:{b.key=l.string();break}case 2:{b.value=l.bytes();break}default:{l.skipType(y&7);break}}}return b},function*(l,h,p,b={}){let m=h==null?l.len:l.pos+h;for(;l.pos<m;){let y=l.uint32();switch(y>>>3){case 1:{yield{field:`${p}.key`,value:l.string()};break}case 2:{yield{field:`${p}.value`,value:l.bytes()};break}default:{l.skipType(y&7);break}}}})),c);function u(l){return ge(l,a.codec())}a.encode=u;function f(l,h){return be(l,a.codec(),h)}a.decode=f;function d(l,h){return xe(l,a.codec(),h)}a.stream=d})(e=t.Peer$metadataEntry||(t.Peer$metadataEntry={}));let r;(function(a){let c;a.codec=()=>(c==null&&(c=we((l,h,p={})=>{p.lengthDelimited!==!1&&h.fork(),l.key!=null&&l.key!==""&&(h.uint32(10),h.string(l.key)),l.value!=null&&(h.uint32(18),xn.codec().encode(l.value,h)),p.lengthDelimited!==!1&&h.ldelim()},(l,h,p={})=>{let b={key:""},m=h==null?l.len:l.pos+h;for(;l.pos<m;){let y=l.uint32();switch(y>>>3){case 1:{b.key=l.string();break}case 2:{b.value=xn.codec().decode(l,l.uint32(),{limits:p.limits?.value});break}default:{l.skipType(y&7);break}}}return b},function*(l,h,p,b={}){let m=h==null?l.len:l.pos+h;for(;l.pos<m;){let y=l.uint32();switch(y>>>3){case 1:{yield{field:`${p}.key`,value:l.string()};break}case 2:{yield*xn.codec().stream(l,l.uint32(),`${p}.value`,{limits:b.limits?.value});break}default:{l.skipType(y&7);break}}}})),c);function u(l){return ge(l,a.codec())}a.encode=u;function f(l,h){return be(l,a.codec(),h)}a.decode=f;function d(l,h){return xe(l,a.codec(),h)}a.stream=d})(r=t.Peer$tagsEntry||(t.Peer$tagsEntry={}));let n;t.codec=()=>(n==null&&(n=we((a,c,u={})=>{if(u.lengthDelimited!==!1&&c.fork(),a.addresses!=null&&a.addresses.length>0)for(let f of a.addresses)c.uint32(10),gn.codec().encode(f,c);if(a.protocols!=null&&a.protocols.length>0)for(let f of a.protocols)c.uint32(18),c.string(f);if(a.publicKey!=null&&(c.uint32(34),c.bytes(a.publicKey)),a.peerRecordEnvelope!=null&&(c.uint32(42),c.bytes(a.peerRecordEnvelope)),a.metadata!=null&&a.metadata.size>0)for(let[f,d]of a.metadata.entries())c.uint32(50),t.Peer$metadataEntry.codec().encode({key:f,value:d},c);if(a.tags!=null&&a.tags.size>0)for(let[f,d]of a.tags.entries())c.uint32(58),t.Peer$tagsEntry.codec().encode({key:f,value:d},c);a.updated!=null&&(c.uint32(64),c.uint64Number(a.updated)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={addresses:[],protocols:[],metadata:new Map,tags:new Map},d=c==null?a.len:a.pos+c;for(;a.pos<d;){let l=a.uint32();switch(l>>>3){case 1:{if(u.limits?.addresses!=null&&f.addresses.length===u.limits.addresses)throw new Be('Decode error - repeated field "addresses" had too many elements');f.addresses.push(gn.codec().decode(a,a.uint32(),{limits:u.limits?.addresses$}));break}case 2:{if(u.limits?.protocols!=null&&f.protocols.length===u.limits.protocols)throw new Be('Decode error - repeated field "protocols" had too many elements');f.protocols.push(a.string());break}case 4:{f.publicKey=a.bytes();break}case 5:{f.peerRecordEnvelope=a.bytes();break}case 6:{if(u.limits?.metadata!=null&&f.metadata.size===u.limits.metadata)throw new nn('Decode error - map field "metadata" had too many elements');let h=t.Peer$metadataEntry.codec().decode(a,a.uint32(),{limits:{value:u.limits?.metadata$value}});f.metadata.set(h.key,h.value);break}case 7:{if(u.limits?.tags!=null&&f.tags.size===u.limits.tags)throw new nn('Decode error - map field "tags" had too many elements');let h=t.Peer$tagsEntry.codec().decode(a,a.uint32(),{limits:{value:u.limits?.tags$value}});f.tags.set(h.key,h.value);break}case 8:{f.updated=a.uint64Number();break}default:{a.skipType(l&7);break}}}return f},function*(a,c,u,f={}){let d={addresses:0,protocols:0,metadata:0,tags:0},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let h=a.uint32();switch(h>>>3){case 1:{if(f.limits?.addresses!=null&&d.addresses===f.limits.addresses)throw new Be('Streaming decode error - repeated field "addresses" had too many elements');for(let p of gn.codec().stream(a,a.uint32(),`${u}.addresses[]`,{limits:f.limits?.addresses$}))yield{...p,index:d.addresses};d.addresses++;break}case 2:{if(f.limits?.protocols!=null&&d.protocols===f.limits.protocols)throw new Be('Streaming decode error - repeated field "protocols" had too many elements');yield{field:`${u}.protocols[]`,index:d.protocols,value:a.string()},d.protocols++;break}case 4:{yield{field:`${u}.publicKey`,value:a.bytes()};break}case 5:{yield{field:`${u}.peerRecordEnvelope`,value:a.bytes()};break}case 6:{if(f.limits?.metadata!=null&&d.metadata===f.limits.metadata)throw new Be('Decode error - map field "metadata" had too many elements');yield*t.Peer$metadataEntry.codec().stream(a,a.uint32(),`${u}.metadata{}`,{limits:{value:f.limits?.metadata$value}}),d.metadata++;break}case 7:{if(f.limits?.tags!=null&&d.tags===f.limits.tags)throw new Be('Decode error - map field "tags" had too many elements');yield*t.Peer$tagsEntry.codec().stream(a,a.uint32(),`${u}.tags{}`,{limits:{value:f.limits?.tags$value}}),d.tags++;break}case 8:{yield{field:`${u}.updated`,value:a.uint64Number()};break}default:{a.skipType(h&7);break}}}})),n);function o(a){return ge(a,t.codec())}t.encode=o;function s(a,c){return be(a,t.codec(),c)}t.decode=s;function i(a,c){return xe(a,t.codec(),c)}t.stream=i})(nt||(nt={}));var gn;(function(t){let e;t.codec=()=>(e==null&&(e=we((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.multiaddr!=null&&s.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(s.multiaddr)),s.isCertified!=null&&(i.uint32(16),i.bool(s.isCertified)),s.observed!=null&&(i.uint32(24),i.uint64Number(s.observed)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={multiaddr:Te(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.multiaddr=s.bytes();break}case 2:{c.isCertified=s.bool();break}case 3:{c.observed=s.uint64Number();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.multiaddr`,value:s.bytes()};break}case 2:{yield{field:`${a}.isCertified`,value:s.bool()};break}case 3:{yield{field:`${a}.observed`,value:s.uint64Number()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ge(s,t.codec())}t.encode=r;function n(s,i){return be(s,t.codec(),i)}t.decode=n;function o(s,i){return xe(s,t.codec(),i)}t.stream=o})(gn||(gn={}));var xn;(function(t){let e;t.codec=()=>(e==null&&(e=we((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.value!=null&&s.value!==0&&(i.uint32(8),i.uint32(s.value)),s.expiry!=null&&(i.uint32(16),i.uint64(s.expiry)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={value:0},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.value=s.uint32();break}case 2:{c.expiry=s.uint64();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.value`,value:s.uint32()};break}case 2:{yield{field:`${a}.expiry`,value:s.uint64()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ge(s,t.codec())}t.encode=r;function n(s,i){return be(s,t.codec(),i)}t.decode=n;function o(s,i){return xe(s,t.codec(),i)}t.stream=o})(xn||(xn={}));function F0(t,e){if(t.publicKey!=null||e.publicKey==null)return t;let r;t.type==="RSA"&&(r=t.toMultihash());let n=uo(e.publicKey,r);return Ef(n)}function Yf(t,e,r){let n=nt.decode(e);return xr(t,n,r)}function xr(t,e,r){let n=new Map,o=BigInt(Date.now());for(let[s,i]of e.tags.entries())i.expiry!=null&&i.expiry<o||n.set(s,i);return{...e,id:F0(t,e),addresses:e.addresses.filter(({observed:s})=>s!=null&&s>Date.now()-r).map(({multiaddr:s,isCertified:i})=>({multiaddr:Nt(s),isCertified:i??!1})),metadata:e.metadata,peerRecordEnvelope:e.peerRecordEnvelope??void 0,tags:n}}function Xf(t,e){return M0(t.addresses,e.addresses)&&q0(t.protocols,e.protocols)&&z0(t.publicKey,e.publicKey)&&V0(t.peerRecordEnvelope,e.peerRecordEnvelope)&&H0(t.metadata,e.metadata)&&$0(t.tags,e.tags)}function M0(t,e){return Jf(t,e,(r,n)=>!(r.isCertified!==n.isCertified||!W(r.multiaddr,n.multiaddr)))}function q0(t,e){return Jf(t,e,(r,n)=>r===n)}function z0(t,e){return Qf(t,e)}function V0(t,e){return Qf(t,e)}function H0(t,e){return el(t,e,(r,n)=>W(r,n))}function $0(t,e){return el(t,e,(r,n)=>r.value===n.value&&r.expiry===n.expiry)}function Qf(t,e){return t==null&&e==null?!0:t!=null&&e!=null?W(t,e):!1}function Jf(t,e,r){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(!r(t[n],e[n]))return!1;return!0}function el(t,e,r){if(t.size!==e.size)return!1;for(let[n,o]of t.entries()){let s=e.get(n);if(s==null||!r(o,s))return!1}return!0}var Ta={};K(Ta,{base10:()=>Q0});var V6=new Uint8Array(0);function tl(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function ot(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function rl(t){return new TextEncoder().encode(t)}function nl(t){return new TextDecoder().decode(t)}function j0(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var s=t.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function d(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var b=0,m=0,y=0,x=p.length;y!==x&&p[y]===0;)y++,b++;for(var w=(x-y)*f+1>>>0,C=new Uint8Array(w);y!==x;){for(var I=p[y],R=0,_=w-1;(I!==0||R<m)&&_!==-1;_--,R++)I+=256*C[_]>>>0,C[_]=I%a>>>0,I=I/a>>>0;if(I!==0)throw new Error("Non-zero carry");m=R,y++}for(var A=w-m;A!==w&&C[A]===0;)A++;for(var P=c.repeat(b);A<w;++A)P+=t.charAt(C[A]);return P}function l(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var b=0;if(p[b]!==" "){for(var m=0,y=0;p[b]===c;)m++,b++;for(var x=(p.length-b)*u+1>>>0,w=new Uint8Array(x);p[b];){var C=r[p.charCodeAt(b)];if(C===255)return;for(var I=0,R=x-1;(C!==0||I<y)&&R!==-1;R--,I++)C+=a*w[R]>>>0,w[R]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");y=I,b++}if(p[b]!==" "){for(var _=x-y;_!==x&&w[_]===0;)_++;for(var A=new Uint8Array(m+(x-_)),P=m;_!==x;)A[P++]=w[_++];return A}}}function h(p){var b=l(p);if(b)return b;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:l,decode:h}}var W0=j0,Z0=W0,sl=Z0;var Sa=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Aa=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return il(this,e)}},Ca=class{decoders;constructor(e){this.decoders=e}or(e){return il(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function il(t,e){return new Ca({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Ia=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Sa(e,r,n),this.decoder=new Aa(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function wr({name:t,prefix:e,encode:r,decode:n}){return new Ia(t,e,r,n)}function Et({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=sl(r,t);return wr({prefix:e,name:t,encode:n,decode:s=>ot(o(s))})}function G0(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Y0(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function X0(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function te({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=X0(n);return wr({prefix:e,name:t,encode(s){return Y0(s,n,r)},decode(s){return G0(s,o,r,t)}})}var Q0=Et({prefix:"9",name:"base10",alphabet:"0123456789"});var Da={};K(Da,{base16:()=>J0,base16upper:()=>ey});var J0=te({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),ey=te({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var _a={};K(_a,{base2:()=>ty});var ty=te({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ba={};K(Ba,{base256emoji:()=>iy});var al=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),ry=al.reduce((t,e,r)=>(t[r]=e,t),[]),ny=al.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function oy(t){return t.reduce((e,r)=>(e+=ry[r],e),"")}function sy(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=ny[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var iy=wr({prefix:"\u{1F680}",name:"base256emoji",encode:oy,decode:sy});var La={};K(La,{base32:()=>Er,base32hex:()=>fy,base32hexpad:()=>dy,base32hexpadupper:()=>hy,base32hexupper:()=>ly,base32pad:()=>cy,base32padupper:()=>uy,base32upper:()=>ay,base32z:()=>py});var Er=te({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ay=te({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),cy=te({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),uy=te({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),fy=te({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ly=te({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),dy=te({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),hy=te({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),py=te({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ra={};K(Ra,{base36:()=>wn,base36upper:()=>my});var wn=Et({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),my=Et({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Oa={};K(Oa,{base58btc:()=>$e,base58flickr:()=>yy});var $e=Et({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),yy=Et({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ka={};K(ka,{base64:()=>by,base64pad:()=>gy,base64url:()=>xy,base64urlpad:()=>wy});var by=te({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),gy=te({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),xy=te({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),wy=te({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Pa={};K(Pa,{base8:()=>Ey});var Ey=te({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ua={};K(Ua,{identity:()=>vy});var vy=wr({prefix:"\0",name:"identity",encode:t=>nl(t),decode:t=>rl(t)});var s8=new TextEncoder,i8=new TextDecoder;var Na={};K(Na,{identity:()=>$y});var Cy=fl,cl=128,Iy=127,Ty=~Iy,Dy=Math.pow(2,31);function fl(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Dy;)e[r++]=t&255|cl,t/=128;for(;t&Ty;)e[r++]=t&255|cl,t>>>=7;return e[r]=t|0,fl.bytes=r-n+1,e}var _y=Ka,By=128,ul=127;function Ka(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw Ka.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&ul)<<o:(i&ul)*Math.pow(2,o),o+=7}while(i>=By);return Ka.bytes=s-n,r}var Ly=Math.pow(2,7),Ry=Math.pow(2,14),Oy=Math.pow(2,21),ky=Math.pow(2,28),Py=Math.pow(2,35),Uy=Math.pow(2,42),Ky=Math.pow(2,49),Ny=Math.pow(2,56),Fy=Math.pow(2,63),My=function(t){return t<Ly?1:t<Ry?2:t<Oy?3:t<ky?4:t<Py?5:t<Uy?6:t<Ky?7:t<Ny?8:t<Fy?9:10},qy={encode:Cy,decode:_y,encodingLength:My},zy=qy,En=zy;function vn(t,e=0){return[En.decode(t,e),En.decode.bytes]}function vr(t,e,r=0){return En.encode(t,e,r),e}function Sr(t){return En.encodingLength(t)}function Cr(t,e){let r=e.byteLength,n=Sr(t),o=n+Sr(r),s=new Uint8Array(o+r);return vr(t,s,0),vr(r,s,n),s.set(e,o),new Ar(t,r,e,s)}function ll(t){let e=ot(t),[r,n]=vn(e),[o,s]=vn(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ar(r,o,i,e)}function dl(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&tl(t.bytes,r.bytes)}}var Ar=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};var hl=0,Vy="identity",pl=ot;function Hy(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return Cr(hl,pl(t))}var $y={code:hl,name:Vy,encode:pl,digest:Hy};var qa={};K(qa,{sha256:()=>Wy,sha512:()=>Zy});var jy=20;function Ma({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new Fa(t,e,r,n,o)}var Fa=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??jy,this.maxDigestLength=s}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?ml(n,this.code,r?.truncate):n.then(o=>ml(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function ml(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return Cr(e,t)}function bl(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Wy=Ma({name:"sha2-256",code:18,encode:bl("SHA-256")}),Zy=Ma({name:"sha2-512",code:19,encode:bl("SHA-512")});function gl(t,e){let{bytes:r,version:n}=t;return n===0?Yy(r,za(t),e??$e.encoder):Xy(r,za(t),e??Er.encoder)}var xl=new WeakMap;function za(t){let e=xl.get(t);if(e==null){let r=new Map;return xl.set(t,r),r}return e}var qo=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==An)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Qy)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=Cr(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&dl(e.multihash,n.multihash)}toString(e){return gl(this,e)}toJSON(){return{"/":gl(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new t(n,o,s,i??wl(n,o,s.bytes))}else if(r[Jy]===!0){let{version:n,multihash:o,code:s}=r,i=ll(o);return t.create(n,s,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==An)throw new Error(`Version 0 CID must use dag-pb (code: ${An}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=wl(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,An,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=ot(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Ar(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[d,l]=vn(e.subarray(r));return r+=l,d},o=n(),s=An;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,o]=Gy(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return za(s).set(n,e),s}};function Gy(t,e){switch(t[0]){case"Q":{let r=e??$e;return[$e.prefix,r.decode(`${$e.prefix}${t}`)]}case $e.prefix:{let r=e??$e;return[$e.prefix,r.decode(t)]}case Er.prefix:{let r=e??Er;return[Er.prefix,r.decode(t)]}case wn.prefix:{let r=e??wn;return[wn.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function Yy(t,e,r){let{prefix:n}=r;if(n!==$e.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function Xy(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var An=112,Qy=18;function wl(t,e,r){let n=Sr(t),o=n+Sr(e),s=new Uint8Array(o+r.byteLength);return vr(t,s,0),vr(e,s,n),s.set(r,o),s}var Jy=Symbol.for("@ipld/js-cid/CID");var Va={...Ua,..._a,...Pa,...Ta,...Da,...La,...Ra,...Oa,...ka,...Ba},D8={...qa,...Na};function El(t=0){return new Uint8Array(t)}function Sl(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var vl=Sl("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Ha=Sl("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=El(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),eb={utf8:vl,"utf-8":vl,hex:Va.base16,latin1:Ha,ascii:Ha,binary:Ha,...Va},zo=eb;function Al(t,e="utf8"){let r=zo[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Cl(t,e="utf8"){let r=zo[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var st="/",Il=new TextEncoder().encode(st),Vo=Il[0],Ho=class t{_buf;constructor(e,r){if(typeof e=="string")this._buf=Al(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(r==null&&(r=!0),r&&this.clean(),this._buf.byteLength===0||this._buf[0]!==Vo)throw new Error("Invalid key")}toString(e="utf8"){return Cl(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new t(e.join(st))}static random(){return new t(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new t(e):typeof e.uint8Array=="function"?new t(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=Il),this._buf[0]!==Vo){let e=new Uint8Array(this._buf.byteLength+1);e.fill(Vo,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Vo;)this._buf=this._buf.subarray(0,-1)}less(e){let r=this.list(),n=e.list();for(let o=0;o<r.length;o++){if(n.length<o+1)return!1;let s=r[o],i=n[o];if(s<i)return!0;if(s>i)return!1}return r.length<n.length}reverse(){return t.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(st).slice(1)}type(){return tb(this.baseNamespace())}name(){return rb(this.baseNamespace())}instance(e){return new t(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(st)||(e+=st),e+=this.type(),new t(e)}parent(){let e=this.list();return e.length===1?new t(st):new t(e.slice(0,-1).join(st))}child(e){return this.toString()===st?e:e.toString()===st?this:new t(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return t.withNamespaces([...this.namespaces(),...nb(e.map(r=>r.namespaces()))])}};function tb(t){let e=t.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function rb(t){let e=t.split(":");return e[e.length-1]}function nb(t){return[].concat(...t)}var $a="/peers/";function Cn(t){if(!Vt(t)||t.type==null)throw new M("Invalid PeerId");let e=t.toCID().toString();return new Ho(`${$a}${e}`)}async function Tl(t,e,r,n,o){let s=new Map;for(let i of r){if(i==null)continue;if(i.multiaddr instanceof Uint8Array&&(i.multiaddr=Nt(i.multiaddr)),!xo(i.multiaddr))throw new M("Multiaddr was invalid");if(!await e(t,i.multiaddr,o))continue;let a=i.isCertified??!1,c=i.multiaddr.toString(),u=s.get(c);u!=null?i.isCertified=u.isCertified||a:s.set(c,{multiaddr:i.multiaddr,isCertified:a})}return[...s.values()].sort((i,a)=>i.multiaddr.toString().localeCompare(a.multiaddr.toString())).map(({isCertified:i,multiaddr:a})=>{let c=a.getComponents().find(u=>u.code===421)?.value;return t.equals(c)&&(a=a.decapsulate(Nt(`/p2p/${t}`))),{isCertified:i,multiaddr:a.bytes}})}async function jo(t,e,r,n){if(e==null)throw new M("Invalid PeerData");if(e.publicKey!=null&&t.publicKey!=null&&!e.publicKey.equals(t.publicKey))throw new M("publicKey bytes do not match peer id publicKey bytes");let o=n.existingPeer?.peer;if(o!=null&&!t.equals(o.id))throw new M("peer id did not match existing peer id");let s=o?.addresses??[],i=new Set(o?.protocols??[]),a=o?.metadata??new Map,c=o?.tags??new Map,u=o?.peerRecordEnvelope;if(r==="patch"){if((e.multiaddrs!=null||e.addresses!=null)&&(s=[],e.multiaddrs!=null&&s.push(...e.multiaddrs.map(l=>({isCertified:!1,multiaddr:l}))),e.addresses!=null&&s.push(...e.addresses)),e.protocols!=null&&(i=new Set(e.protocols)),e.metadata!=null){let l=e.metadata instanceof Map?[...e.metadata.entries()]:Object.entries(e.metadata);a=$o(l,{validate:Dl})}if(e.tags!=null){let l=e.tags instanceof Map?[...e.tags.entries()]:Object.entries(e.tags);c=$o(l,{validate:_l,map:Bl})}e.peerRecordEnvelope!=null&&(u=e.peerRecordEnvelope)}if(r==="merge"){if(e.multiaddrs!=null&&s.push(...e.multiaddrs.map(l=>({isCertified:!1,multiaddr:l}))),e.addresses!=null&&s.push(...e.addresses),e.protocols!=null&&(i=new Set([...i,...e.protocols])),e.metadata!=null){let l=e.metadata instanceof Map?[...e.metadata.entries()]:Object.entries(e.metadata);for(let[h,p]of l)p==null?a.delete(h):a.set(h,p);a=$o([...a.entries()],{validate:Dl})}if(e.tags!=null){let l=e.tags instanceof Map?[...e.tags.entries()]:Object.entries(e.tags),h=new Map(c);for(let[p,b]of l)b==null?h.delete(p):h.set(p,b);c=$o([...h.entries()],{validate:_l,map:Bl})}e.peerRecordEnvelope!=null&&(u=e.peerRecordEnvelope)}let f;o?.id.publicKey!=null?f=De(o.id.publicKey):e.publicKey!=null?f=De(e.publicKey):t.publicKey!=null&&(f=De(t.publicKey));let d={addresses:await Tl(t,n.addressFilter??(async()=>!0),s,n.existingPeer?.peerPB.addresses,n),protocols:[...i.values()].sort((l,h)=>l.localeCompare(h)),metadata:a,tags:c,publicKey:f,peerRecordEnvelope:u};return d.addresses.forEach(l=>{l.observed=n.existingPeer?.peerPB.addresses?.find(h=>W(h.multiaddr,h.multiaddr))?.observed??Date.now()}),t.type!=="RSA"&&delete d.publicKey,d}function $o(t,e){let r=new Map;for(let[n,o]of t)o!=null&&e.validate(n,o);for(let[n,o]of t.sort(([s],[i])=>s.localeCompare(i)))o!=null&&r.set(n,e.map?.(n,o)??o);return r}function Dl(t,e){if(typeof t!="string")throw new M("Metadata key must be a string");if(!(e instanceof Uint8Array))throw new M("Metadata value must be a Uint8Array")}function _l(t,e){if(typeof t!="string")throw new M("Tag name must be a string");if(e.value!=null){if(parseInt(`${e.value}`,10)!==e.value)throw new M("Tag value must be an integer");if(e.value<0||e.value>100)throw new M("Tag value must be between 0-100")}if(e.ttl!=null){if(parseInt(`${e.ttl}`,10)!==e.ttl)throw new M("Tag ttl must be an integer");if(e.ttl<0)throw new M("Tag ttl must be between greater than 0")}}function Bl(t,e){let r;e.expiry!=null&&(r=e.expiry),e.ttl!=null&&(r=BigInt(Date.now()+Number(e.ttl)));let n={value:e.value??0};return r!=null&&(n.expiry=r),n}function Ll(t){let e=t.toString().split("/")[2],r=oe.parse(e,Ne);return fo(r)}function ja(t,e,r){let n=Ll(t);return Yf(n,e,r)}function ob(t,e){return{prefix:$a,filters:(t.filters??[]).map(r=>({key:n,value:o})=>r(ja(n,o,e))),orders:(t.orders??[]).map(r=>(n,o)=>r(ja(n.key,n.value,e),ja(o.key,o.value,e)))}}var Wo=class{peerId;datastore;locks;addressFilter;log;maxAddressAge;maxPeerAge;constructor(e,r={}){this.log=e.logger.forComponent("libp2p:peer-store"),this.peerId=e.peerId,this.datastore=e.datastore,this.addressFilter=r.addressFilter,this.locks=ya({name:"libp2p_peer_store_locks",metrics:e.metrics}),this.maxAddressAge=r.maxAddressAge??36e5,this.maxPeerAge=r.maxPeerAge??216e5}getLock(e){let r=this.locks.get(e);return r==null&&(r={refs:0,lock:va({name:e.toString(),singleProcess:!0})},this.locks.set(e,r)),r.refs++,r}maybeRemoveLock(e,r){r.refs--,r.refs===0&&(r.lock.finalize(),this.locks.delete(e))}async getReadLock(e,r){let n=this.getLock(e);try{let o=await n.lock.readLock(r);return()=>{o(),this.maybeRemoveLock(e,n)}}catch(o){throw this.maybeRemoveLock(e,n),o}}async getWriteLock(e,r){let n=this.getLock(e);try{let o=await n.lock.writeLock(r);return()=>{o(),this.maybeRemoveLock(e,n)}}catch(o){throw this.maybeRemoveLock(e,n),o}}async has(e,r){try{return await this.load(e,r),!0}catch(n){if(n.name!=="NotFoundError")throw n}return!1}async delete(e,r){this.peerId.equals(e)||await this.datastore.delete(Cn(e),r)}async load(e,r){let n=Cn(e),o=await this.datastore.get(n,r),s=nt.decode(o);if(this.#r(e,s))throw await this.datastore.delete(n,r),new Tr;return xr(e,s,this.peerId.equals(e)?1/0:this.maxAddressAge)}async save(e,r,n){let o=await this.#e(e,n),s=await jo(e,r,"patch",{...n,addressFilter:this.addressFilter});return this.#t(e,s,o)}async patch(e,r,n){let o=await this.#e(e,n),s=await jo(e,r,"patch",{...n,addressFilter:this.addressFilter,existingPeer:o});return this.#t(e,s,o)}async merge(e,r,n){let o=await this.#e(e,n),s=await jo(e,r,"merge",{addressFilter:this.addressFilter,existingPeer:o});return this.#t(e,s,o)}async*all(e){for await(let{key:r,value:n}of this.datastore.query(ob(e??{},this.maxAddressAge),e)){let o=Ll(r);if(o.equals(this.peerId))continue;let s=nt.decode(n);if(this.#r(o,s)){await this.datastore.delete(r,e);continue}yield xr(o,s,this.peerId.equals(o)?1/0:this.maxAddressAge)}}async#e(e,r){try{let n=Cn(e),o=await this.datastore.get(n,r),s=nt.decode(o);if(this.#r(e,s))throw await this.datastore.delete(n,r),new Tr;return{peerPB:s,peer:xr(e,s,this.maxAddressAge)}}catch(n){n.name!=="NotFoundError"&&this.log.error("invalid peer data found in peer store - %e",n)}}async#t(e,r,n,o){r.updated=Date.now();let s=nt.encode(r);return await this.datastore.put(Cn(e),s,o),{peer:xr(e,r,this.maxAddressAge),previous:n?.peer,updated:n==null||!Xf(r,n.peerPB)}}#r(e,r){if(r.updated==null)return!0;if(this.peerId.equals(e))return!1;let n=r.updated<Date.now()-this.maxPeerAge,o=Date.now()-this.maxAddressAge,s=r.addresses.filter(i=>i.observed!=null&&i.observed>o);return n&&s.length===0}};var Wa=class{store;events;peerId;log;constructor(e,r={}){this.log=e.logger.forComponent("libp2p:peer-store"),this.events=e.events,this.peerId=e.peerId,this.store=new Wo(e,r)}[Symbol.toStringTag]="@libp2p/peer-store";async forEach(e,r){for await(let n of this.store.all(r))e(n)}async all(e){return qf(this.store.all(e))}async delete(e,r){let n=await this.store.getReadLock(e,r);try{await this.store.delete(e,r)}finally{n()}}async has(e,r){let n=await this.store.getReadLock(e,r);try{return await this.store.has(e,r)}finally{this.log.trace("has release read lock"),n?.()}}async get(e,r){let n=await this.store.getReadLock(e,r);try{return await this.store.load(e,r)}finally{n?.()}}async getInfo(e,r){let n=await this.get(e,r);return{id:n.id,multiaddrs:n.addresses.map(({multiaddr:o})=>o)}}async save(e,r,n){let o=await this.store.getWriteLock(e,n);try{let s=await this.store.save(e,r,n);return this.#e(e,s),s.peer}finally{o?.()}}async patch(e,r,n){let o=await this.store.getWriteLock(e,n);try{let s=await this.store.patch(e,r,n);return this.#e(e,s),s.peer}finally{o?.()}}async merge(e,r,n){let o=await this.store.getWriteLock(e,n);try{let s=await this.store.merge(e,r,n);return this.#e(e,s),s.peer}finally{o?.()}}async consumePeerRecord(e,r,n){let o=Vt(r)?r:Vt(r?.expectedPeer)?r.expectedPeer:void 0,s=Vt(r)||r===void 0?n:r,i=await mr.openAndCertify(e,Ft.DOMAIN,s),a=fo(i.publicKey.toCID());if(o?.equals(a)===!1)return this.log("envelope peer id was not the expected peer id - expected: %p received: %p",o,a),!1;let c=Ft.createFromProtobuf(i.payload),u;try{u=await this.get(a,s)}catch(f){if(f.name!=="NotFoundError")throw f}if(u?.peerRecordEnvelope!=null){let f=mr.createFromProtobuf(u.peerRecordEnvelope),d=Ft.createFromProtobuf(f.payload);if(d.seqNumber>=c.seqNumber)return this.log("sequence number was lower or equal to existing sequence number - stored: %d received: %d",d.seqNumber,c.seqNumber),!1}return await this.patch(c.peerId,{peerRecordEnvelope:e,addresses:c.multiaddrs.map(f=>({isCertified:!0,multiaddr:f}))},s),!0}#e(e,r){r.updated&&(this.peerId.equals(e)?this.events.safeDispatchEvent("self:peer:update",{detail:r}):this.events.safeDispatchEvent("peer:update",{detail:r}))}};function sb(t,e={}){return new Wa(t,e)}return Ul(ib);})();
2
+ "use strict";var Libp2PPeerStore=(()=>{var ao=Object.defineProperty;var Qc=Object.getOwnPropertyDescriptor;var Jc=Object.getOwnPropertyNames;var tu=Object.prototype.hasOwnProperty;var Et=(e,t)=>{for(var r in t)ao(e,r,{get:t[r],enumerable:!0})},eu=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Jc(t))!tu.call(e,o)&&o!==r&&ao(e,o,{get:()=>t[o],enumerable:!(n=Qc(t,o))||n.enumerable});return e};var ru=e=>eu(ao({},"__esModule",{value:!0}),e);var nh={};Et(nh,{persistentPeerStore:()=>rh});var F=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 nu(e){return typeof e?.handleEvent=="function"}function ou(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=ou(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))}nu(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:()=>du});var ch=new Uint8Array(0);function gi(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 Ht(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 wi(e){return new TextEncoder().encode(e)}function xi(e){return new TextDecoder().decode(e)}function su(e){return e?.buffer instanceof ArrayBuffer}function me(e){return su(e)?e:e.slice()}function iu(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=e.length,c=e.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(y){if(y instanceof Uint8Array||(ArrayBuffer.isView(y)?y=new Uint8Array(y.buffer,y.byteOffset,y.byteLength):Array.isArray(y)&&(y=Uint8Array.from(y))),!(y instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(y.length===0)return"";for(var g=0,p=0,b=0,v=y.length;b!==v&&y[b]===0;)b++,g++;for(var A=(v-b)*f+1>>>0,L=new Uint8Array(A);b!==v;){for(var R=y[b],k=0,D=A-1;(R!==0||k<p)&&D!==-1;D--,k++)R+=256*L[D]>>>0,L[D]=R%a>>>0,R=R/a>>>0;if(R!==0)throw new Error("Non-zero carry");p=k,b++}for(var B=A-p;B!==A&&L[B]===0;)B++;for(var P=c.repeat(g);B<A;++B)P+=e.charAt(L[B]);return P}function d(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return new Uint8Array;var g=0;if(y[g]!==" "){for(var p=0,b=0;y[g]===c;)p++,g++;for(var v=(y.length-g)*u+1>>>0,A=new Uint8Array(v);y[g];){var L=r[y.charCodeAt(g)];if(L===255)return;for(var R=0,k=v-1;(L!==0||R<b)&&k!==-1;k--,R++)L+=a*A[k]>>>0,A[k]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");b=R,g++}if(y[g]!==" "){for(var D=v-b;D!==v&&A[D]===0;)D++;for(var B=new Uint8Array(p+(v-D)),P=p;D!==v;)B[P++]=A[D++];return B}}}function h(y){var g=d(y);if(g)return g;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:d,decode:h}}var au=iu,cu=au,vi=cu;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 Si(this,t)}},fo=class{decoders;constructor(t){this.decoders=t}or(t){return Si(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 Si(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}){let{encode:n,decode:o}=vi(r,e);return Oe({prefix:t,name:e,encode:n,decode:s=>Ht(o(s))})}function uu(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 fu(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 lu(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function Y({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=lu(n);return Oe({prefix:t,name:e,encode(s){return fu(s,n,r)},decode(s){return uu(s,o,r,e)}})}var G=ee({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),du=ee({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var po={};Et(po,{base32:()=>Nt,base32hex:()=>yu,base32hexpad:()=>gu,base32hexpadupper:()=>wu,base32hexupper:()=>bu,base32pad:()=>pu,base32padupper:()=>mu,base32upper:()=>hu,base32z:()=>xu});var Nt=Y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),hu=Y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),pu=Y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),mu=Y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),yu=Y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),bu=Y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),gu=Y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),wu=Y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),xu=Y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var mo={};Et(mo,{base36:()=>or,base36upper:()=>Eu});var or=ee({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Eu=ee({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var vu=Ti,Ai=128,Su=127,Au=~Su,_u=Math.pow(2,31);function Ti(e,t,r){t=t||[],r=r||0;for(var n=r;e>=_u;)t[r++]=e&255|Ai,e/=128;for(;e&Au;)t[r++]=e&255|Ai,e>>>=7;return t[r]=e|0,Ti.bytes=r-n+1,t}var Tu=yo,Bu=128,_i=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&_i)<<o:(i&_i)*Math.pow(2,o),o+=7}while(i>=Bu);return yo.bytes=s-n,r}var Iu=Math.pow(2,7),Ru=Math.pow(2,14),Cu=Math.pow(2,21),Lu=Math.pow(2,28),Du=Math.pow(2,35),Ou=Math.pow(2,42),ku=Math.pow(2,49),Pu=Math.pow(2,56),Ku=Math.pow(2,63),Nu=function(e){return e<Iu?1:e<Ru?2:e<Cu?3:e<Lu?4:e<Du?5:e<Ou?6:e<ku?7:e<Pu?8:e<Ku?9:10},Uu={encode:vu,decode:Tu,encodingLength:Nu},Fu=Uu,sr=Fu;function ir(e,t=0){return[sr.decode(e,t),sr.decode.bytes]}function ke(e,t,r=0){return sr.encode(e,t,r),t}function Pe(e){return sr.encodingLength(e)}function Ut(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=Ht(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&&gi(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 Ii(e,t){let{bytes:r,version:n}=e;return n===0?qu(r,bo(e),t??G.encoder):zu(r,bo(e),t??Nt.encoder)}var Ri=new WeakMap;function bo(e){let t=Ri.get(e);if(t==null){let r=new Map;return Ri.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!==Vu)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=Ut(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 Ii(this,t)}toJSON(){return{"/":Ii(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??Ci(n,o,s.bytes))}else if(r[Hu]===!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=Ci(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=Ht(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]=Mu(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 Mu(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 Nt.prefix:{let r=t??Nt;return[Nt.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 qu(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 zu(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var ar=112,Vu=18;function Ci(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 Hu=Symbol.for("@ipld/js-cid/CID");var go={};Et(go,{identity:()=>Ct});var Li=0,$u="identity",Di=Ht;function Wu(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 Ut(Li,Di(e))}var Ct={code:Li,name:$u,encode:Di,digest:Wu};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 ju(e){return e.buffer instanceof ArrayBuffer}function pt(e){return ju(e)?e:e.slice()}async function Oi(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 Zu(e){return e?.buffer instanceof ArrayBuffer}function wo(e){if(Zu(e))return e;let t=e.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function Ft(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=lt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return wo(r)}var Pi=Symbol.for("@achingbrain/uint8arraylist");function ki(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?.[Pi]}var mt=class e{bufs;length;[Pi]=!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=ki(this.bufs,t);return r.buf[r.index]}set(t,r){let n=ki(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 Ft(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Ft(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=n,s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,f=r>a&&r<=c;if(u&&f){if(t===a&&r===c){n.push(i);break}let 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:()=>Yu});var Yu=ee({prefix:"9",name:"base10",alphabet:"0123456789"});var Eo={};Et(Eo,{base16:()=>Gu,base16upper:()=>Xu});var Gu=Y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Xu=Y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var vo={};Et(vo,{base2:()=>Qu});var Qu=Y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var So={};Et(So,{base256emoji:()=>nf});var Ki=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}"),Ju=Ki.reduce((e,t,r)=>(e[r]=t,e),[]),tf=Ki.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function ef(e){return e.reduce((t,r)=>(t+=Ju[r],t),"")}function rf(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=tf[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var nf=Oe({prefix:"\u{1F680}",name:"base256emoji",encode:ef,decode:rf});var _o={};Et(_o,{base64:()=>of,base64pad:()=>sf,base64url:()=>Ao,base64urlpad:()=>af});var of=Y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),sf=Y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ao=Y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),af=Y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var To={};Et(To,{base8:()=>cf});var cf=Y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Bo={};Et(Bo,{identity:()=>uf});var uf=Oe({prefix:"\0",name:"identity",encode:e=>xi(e),decode:e=>wi(e)});var jh=new TextEncoder,Zh=new TextDecoder;var Co={};Et(Co,{sha256:()=>cr,sha512:()=>hf});var df=20;function Ro({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Io(e,t,r,n,o)}var Io=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??df,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?Ni(n,this.code,r?.truncate):n.then(o=>Ni(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ni(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 Ut(t,e)}function Fi(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var cr=Ro({name:"sha2-256",code:18,encode:Fi("SHA-256")}),hf=Ro({name:"sha2-512",code:19,encode:Fi("SHA-512")});var ur={...Bo,...vo,...To,...xo,...Eo,...po,...mo,...ho,..._o,...So},ip={...Co,...go};function qi(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Mi=qi("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Lo=qi("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}),pf={utf8:Mi,"utf-8":Mi,hex:ur.base16,latin1:Lo,ascii:Lo,binary:Lo,...ur},Gr=pf;function V(e,t="utf8"){let r=Gr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function M(e,t="utf8"){let r=Gr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var mf=parseInt("11111",2),Do=parseInt("10000000",2),yf=parseInt("01111111",2),zi={0:fr,1:fr,2:bf,3:xf,4:Ef,5:wf,6:gf,16:fr,22:fr,48:fr};function $t(e,t={offset:0}){let r=e[t.offset]&mf;if(t.offset++,zi[r]!=null)return zi[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]&yf,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function fr(e,t){lr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=$t(e,t);if(n===null)break;r.push(n)}return r}function bf(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 gf(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 wf(e,t){return t.offset++,null}function xf(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 Ef(e,t){let r=lr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function vf(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=vf(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 Sf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Af=Uint8Array.from([6,5,43,129,4,0,34]),_f=Uint8Array.from([6,5,43,129,4,0,35]),Tf={ext:!0,kty:"EC",crv:"P-256"},Bf={ext:!0,kty:"EC",crv:"P-384"},If={ext:!0,kty:"EC",crv:"P-521"},ko=32,Po=48,Ko=66;function No(e){let t=$t(e);return Vi(t)}function Vi(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===ko*2+1)return n=M(t.subarray(r,r+ko),"base64url"),o=M(t.subarray(r+ko),"base64url"),new Ue({...Tf,key_ops:["verify"],x:n,y:o});if(t.byteLength===Po*2+1)return n=M(t.subarray(r,r+Po),"base64url"),o=M(t.subarray(r+Po),"base64url"),new Ue({...Bf,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ko*2+1)return n=M(t.subarray(r,r+Ko),"base64url"),o=M(t.subarray(r+Ko),"base64url"),new Ue({...If,key_ops:["verify"],x:n,y:o});throw new F(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Hi(e){return ne([vt(Uint8Array.from([1])),ne([Rf(e.crv)],160),ne([Xr(new mt(Uint8Array.from([4]),V(e.x??"","base64url"),V(e.y??"","base64url")))],161)]).subarray()}function Rf(e){if(e==="P-256")return Sf;if(e==="P-384")return Af;if(e==="P-521")return _f;throw new F(`Invalid curve ${e}`)}var Ue=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Hi(this.jwk)),this._raw}toMultihash(){return Ct.digest(Tt(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 Oi(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 Lt(e,t){return e<<32-t|e>>>t}var Wi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Cf=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function en(e){if(St(e),Wi)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Cf[e[r]];return t}var Wt={_0:48,_9:57,A:65,F:70,a:97,f:102};function $i(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(Wi)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=$i(e.charCodeAt(s)),a=$i(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 ji(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 Zi(e,t,r){return e&t^~e&r}function Yi(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),Gi=BigInt(32);function Lf(e,t=!1){return t?{h:Number(e&rn),l:Number(e>>Gi&rn)}:{h:Number(e>>Gi&rn)|0,l:Number(e&rn)|0}}function Xi(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}=Lf(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 Mt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Qi=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Ji=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ta=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),ea=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,ra=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),na=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var Of=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],y=Lt(d,7)^Lt(d,18)^d>>>3,g=Lt(h,17)^Lt(h,19)^h>>>10;se[l]=g+se[l-7]+y+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=Lt(a,6)^Lt(a,11)^Lt(a,25),h=f+d+Zi(a,c,u)+Of[l]+se[l]|0,g=(Lt(n,2)^Lt(n,13)^Lt(n,22))+Yi(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(){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 oa=Xi(["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))),kf=oa[0],Pf=oa[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:y,Hh:g,Hl:p}=this;return[t,r,n,o,s,i,a,c,u,f,l,d,h,y,g,p]}set(t,r,n,o,s,i,a,c,u,f,l,d,h,y,g,p){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=d|0,this.Gh=h|0,this.Gl=y|0,this.Hh=g|0,this.Hl=p|0}process(t,r){for(let A=0;A<16;A++,r+=4)ie[A]=t.getUint32(r),ae[A]=t.getUint32(r+=4);for(let A=16;A<80;A++){let L=ie[A-15]|0,R=ae[A-15]|0,k=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),B=ie[A-2]|0,P=ae[A-2]|0,$=ye(B,P,19)^pr(B,P,61)^zo(B,P,6),K=be(B,P,19)^mr(B,P,61)^Vo(B,P,6),m=ta(D,K,ae[A-7],ae[A-16]),w=ea(m,k,$,ie[A-7],ie[A-16]);ie[A]=w|0,ae[A]=m|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:d,Fh:h,Fl:y,Gh:g,Gl:p,Hh:b,Hl:v}=this;for(let A=0;A<80;A++){let 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),k=l&h^~l&g,D=d&y^~d&p,B=ra(v,R,D,Pf[A],ae[A]),P=na(B,b,L,k,kf[A],ie[A]),$=B|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),w=n&s^n&a^s&a,S=o&i^o&c^i&c;b=g|0,v=p|0,g=h|0,p=y|0,h=l|0,y=d|0,{h:l,l:d}=Mt(u|0,f|0,P|0,$|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let E=Qi($,m,S);n=Ji(E,P,K,w),o=E|0}({h:n,l:o}=Mt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Mt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Mt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Mt(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:d}=Mt(this.Eh|0,this.El|0,l|0,d|0),{h,l:y}=Mt(this.Fh|0,this.Fl|0,h|0,y|0),{h:g,l:p}=Mt(this.Gh|0,this.Gl|0,g|0,p|0),{h:b,l:v}=Mt(this.Hh|0,this.Hl|0,b|0,v|0),this.set(n,o,s,i,a,c,u,f,l,d,h,y,g,p,b,v)}roundClean(){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 q=(e,t,r)=>St(e,t,r),Yo=oe,qe=en,nt=(...e)=>Fo(...e),ze=e=>dr(e),ge=Uo,yr=e=>ji(e),sn=BigInt(0),Zo=BigInt(1);function Dt(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new TypeError(r+"expected boolean, got type="+typeof e)}return e}function an(e){if(typeof e=="bigint"){if(!on(e))throw new RangeError("positive bigint expected, got "+e)}else Yo(e);return e}function Ot(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 sa(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?sn:BigInt("0x"+e)}function we(e){return sa(en(e))}function qt(e){return sa(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 ia(e,t){if(e=q(e),t=q(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(q(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 Kf(e,t,r){return on(e)&&on(t)&&on(r)&&t<=e&&e<r}function Ve(e,t,r,n){if(!Kf(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 aa(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())},y=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let p=0,b=[];for(;p<t;){c=d();let v=c.slice();b.push(v),p+=c.length}return nt(...b)};return(p,b)=>{l(),h(p);let v;for(;(v=b(y()))===void 0;)h();return l(),v}}function kt(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),la=BigInt(3),da=BigInt(4),ha=BigInt(5),Nf=BigInt(7),pa=BigInt(8),Uf=BigInt(9),ma=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 ca(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 ya(e,t){let r=e,n=(r.ORDER+X)/da,o=r.pow(t,n);return Qo(r,o,t),o}function Ff(e,t){let r=e,n=(r.ORDER-ha)/pa,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 Mf(e){let t=$e(e),r=ba(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+Nf)/ma;return((a,c)=>{let u=a,f=u.pow(c,i),l=u.mul(f,n),d=u.mul(f,o),h=u.mul(f,s),y=u.eql(u.sqr(l),c),g=u.eql(u.sqr(d),c);f=u.cmov(f,l,y),l=u.cmov(h,d,g);let p=u.eql(u.sqr(l),c),b=u.cmov(f,l,p);return Qo(u,b,c),b})}function ba(e){if(e<la)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(;ua(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return ya;let s=o.pow(n,t),i=(t+X)/xe;return function(c,u){let f=c;if(f.is0(u))return u;if(ua(f,u)!==1)throw new Error("Cannot find square root");let l=r,d=f.mul(f.ONE,s),h=f.pow(u,t),y=f.pow(u,i);for(;!f.eql(h,f.ONE);){if(f.is0(h))return f.ZERO;let g=1,p=f.sqr(h);for(;!f.eql(p,f.ONE);)if(g++,p=f.sqr(p),g===l)throw new Error("Cannot find square root");let b=X<<BigInt(l-g-1),v=f.pow(d,b);l=g,d=f.sqr(v),h=f.mul(h,d),y=f.mul(y,v)}return y}}function qf(e){return e%da===la?ya:e%pa===ha?Ff:e%ma===Uf?Mf(e):ba(e)}var Yt=(e,t)=>(tt(e,t)&X)===X,zf=["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=zf.reduce((n,o)=>(n[o]="function",n),t);if(kt(e,r),Ot(e.BYTES,"BYTES"),Ot(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 Vf(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 ua(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 Hf(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 fa=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}=Hf(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 Vf(this,t,r)}div(t,r){return tt(t*ca(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 ca(t,this.ORDER)}sqrt(t){let r=fa.get(this);return r||fa.set(this,r=qf(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?Go(t,this.BYTES):cn(t,this.BYTES)}fromBytes(t,r=!1){q(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?qt(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 Dt(n,"condition"),n?r:t}};Object.freeze(fn.prototype);function $e(e,t={}){return new fn(e,t)}function ga(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=ga(e);return t+Math.ceil(t/2)}function es(e,t,r=!1){q(e);let n=e.length,o=ga(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?qt(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 va(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){va(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 wa(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,Sa=new WeakMap;function os(e){return Sa.get(e)||1}function xa(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}=wa(n,a,i);n=c,f?s=s.add(Er(d,r[h])):o=o.add(Er(l,r[u]))}return xa(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}=wa(n,i,s);if(n=a,!u){let l=r[c];o=o.add(f?l.negate():l)}}return xa(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){va(r,this.bits),Sa.set(t,r),ns.delete(t)}hasCache(t){return os(t)!==1}};function Aa(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 Ea(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=Ea(t.p,r.Fp,n),s=Ea(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),$f=BigInt(8);function Wf(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 _a(e,t={}){let r=t,n=ln("edwards",e,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;kt(r,{},{uvRatio:"function"});let c=ss<<BigInt(s.BYTES*8)-it,u=g=>o.create(g),f=r.uvRatio===void 0?(g,p)=>{try{return{isValid:!0,value:o.sqrt(o.div(g,p))}}catch{return{isValid:!1,value:ce}}}:r.uvRatio;if(!Wf(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function l(g,p,b=!1){let v=b?it:ce;return Ve("coordinate "+g,p,v,c),p}function d(g){if(!(g instanceof h))throw new Error("EdwardsPoint expected")}class h{static BASE=new h(i.Gx,i.Gy,it,u(i.Gx*i.Gy));static ZERO=new h(ce,it,it,ce);static Fp=o;static Fn=s;X;Y;Z;T;constructor(p,b,v,A){this.X=l("x",p),this.Y=l("y",b),this.Z=l("z",v,!0),this.T=l("t",A),Object.freeze(this)}static CURVE(){return i}static fromAffine(p){if(p instanceof h)throw new Error("extended point not allowed");let{x:b,y:v}=p||{};return l("x",b),l("y",v),new h(b,v,it,u(b*v))}static fromBytes(p,b=!1){let v=o.BYTES,{a:A,d:L}=i;p=gr(q(p,v,"point")),Dt(b,"zip215");let R=gr(p),k=p[v-1];R[v-1]=k&-129;let D=qt(R),B=b?c:o.ORDER;Ve("point.y",D,ce,B);let P=u(D*D),$=u(P-it),K=u(L*P-A),{isValid:m,value:w}=f($,K);if(!m)throw new Error("bad point: invalid y coordinate");let S=(w&it)===it,E=(k&128)!==0;if(!b&&w===ce&&E)throw new Error("bad point: x=0 and x_0=1");return E!==S&&(w=u(-w)),h.fromAffine({x:w,y:D})}static fromHex(p,b=!1){return h.fromBytes(ze(p),b)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=8,b=!0){return y.createCache(this,p),b||this.multiply(ss),this}assertValidity(){let p=this,{a:b,d:v}=i;if(p.is0())throw new Error("bad point: ZERO");let{X:A,Y:L,Z:R,T:k}=p,D=u(A*A),B=u(L*L),P=u(R*R),$=u(P*P),K=u(D*b),m=u(P*u(K+B)),w=u($+u(v*u(D*B)));if(m!==w)throw new Error("bad point: equation left != right (1)");let S=u(A*L),E=u(R*k);if(S!==E)throw new Error("bad point: equation left != right (2)")}equals(p){d(p);let{X:b,Y:v,Z:A}=this,{X:L,Y:R,Z:k}=p,D=u(b*k),B=u(L*A),P=u(v*k),$=u(R*A);return D===B&&P===$}is0(){return this.equals(h.ZERO)}negate(){return new h(u(-this.X),this.Y,this.Z,u(-this.T))}double(){let{a:p}=i,{X:b,Y:v,Z:A}=this,L=u(b*b),R=u(v*v),k=u(ss*u(A*A)),D=u(p*L),B=b+v,P=u(u(B*B)-L-R),$=D+R,K=$-k,m=D-R,w=u(P*K),S=u($*m),E=u(P*m),x=u(K*$);return new h(w,S,x,E)}add(p){d(p);let{a:b,d:v}=i,{X:A,Y:L,Z:R,T:k}=this,{X:D,Y:B,Z:P,T:$}=p,K=u(A*D),m=u(L*B),w=u(k*v*$),S=u(R*P),E=u((A+L)*(D+B)-K-m),x=S-w,_=S+w,I=u(m-b*K),T=u(E*x),C=u(_*I),O=u(E*I),U=u(x*_);return new h(T,C,U,O)}subtract(p){return d(p),this.add(p.negate())}multiply(p){if(!s.isValidNot0(p))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:b,f:v}=y.cached(this,p,A=>ve(h,A));return ve(h,[b,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:y.unsafe(this,p,b=>ve(h,b))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return y.unsafe(this,i.n).is0()}toAffine(p){let b=this,v=p,{X:A,Y:L,Z:R}=b,k=b.is0();v==null&&(v=k?$f:o.inv(R));let D=u(A*v),B=u(L*v),P=o.mul(R,v);if(k)return{x:ce,y:it};if(P!==it)throw new Error("invZ was invalid");return{x:D,y:B}}clearCofactor(){return a===it?this:this.multiplyUnsafe(a)}toBytes(){let{x:p,y:b}=this.toAffine(),v=o.toBytes(b);return v[v.length-1]|=p&it?128:0,v}toHex(){return qe(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let y=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 Ta(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=r;kt(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&&(Ot(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,w,S)=>{if(Dt(S,"phflag"),w.length||S)throw new Error("Contexts/pre-hash are not supported");return m}:o.domain;function y(m){return c.create(qt(m))}function g(m){let w=D.secretKey;q(m,D.secretKey,"secretKey");let S=q(n(m),2*w,"hashedSecretKey"),E=d(S.slice(0,w)),x=S.slice(w,2*w),_=y(E);return{head:E,prefix:x,scalar:_}}function p(m){let{head:w,prefix:S,scalar:E}=g(m),x=i.multiply(E),_=x.toBytes();return{head:w,prefix:S,scalar:E,point:x,pointBytes:_}}function b(m){return p(m).pointBytes}function v(m=Uint8Array.of(),...w){let S=nt(...w);return y(n(h(S,q(m,void 0,"context"),!!s)))}function A(m,w,S={}){m=q(m,void 0,"message"),s&&(m=s(m));let{prefix:E,scalar:x,pointBytes:_}=p(w),I=v(S.context,E,m),T=i.multiply(I).toBytes(),C=v(S.context,T,_,m),O=c.create(I+C*x);if(!c.isValid(O))throw new Error("sign failed: invalid s");let U=nt(T,c.toBytes(O));return q(U,D.signature,"result")}let L={zip215:o.zip215};function R(m,w,S,E=L){let{context:x}=E,_=E.zip215===void 0?!!L.zip215:E.zip215,I=D.signature;m=q(m,I,"signature"),w=q(w,void 0,"message"),S=q(S,D.publicKey,"publicKey"),_!==void 0&&Dt(_,"zip215"),s&&(w=s(w));let T=I/2,C=m.subarray(0,T),O=qt(m.subarray(T,I)),U,z,N;try{U=e.fromBytes(S,_),z=e.fromBytes(C,_),N=i.multiplyUnsafe(O)}catch{return!1}if(!_&&U.isSmallOrder())return!1;let rt=v(x,C,S,w);return z.add(U.multiplyUnsafe(rt)).subtract(N).clearCofactor().is0()}let k=a.BYTES,D={secretKey:k,publicKey:k,signature:2*k,seed:k};function B(m){return m=m===void 0?l(D.seed):m,q(m,D.seed,"seed")}function P(m){return ge(m)&&m.length===D.secretKey}function $(m,w){try{return!!e.fromBytes(m,w===void 0?L.zip215:w)}catch{return!1}}let K={getExtendedPublicKey:p,randomSecretKey:B,isValidSecretKey:P,isValidPublicKey:$,toMontgomery(m){let{y:w}=e.fromBytes(m),S=D.publicKey,E=S===32;if(!E&&S!==57)throw new Error("only defined for 25519 and 448");let x=E?a.div(it+w,it-w):a.div(w-it,w+it);return a.toBytes(x)},toMontgomerySecret(m){let w=D.secretKey;q(m,w);let S=n(m.subarray(0,w));return d(S).subarray(0,w)}};return Object.freeze(D),Object.freeze(K),Object.freeze({keygen:dn(B,b),getPublicKey:b,sign:A,verify:R,utils:K,Point:e,lengths:D})}function vr(e,t){if(Ot(e),Ot(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 jf(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 Zf(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){q(e),Ot(r),t=Zf(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 y=[jf(l,f[h-1]),vr(h+1,1),a];f[h]=n(nt(...y))}return nt(...f).slice(0,r)}var Ba="HashToScalar-";var Yf=BigInt(0),Gt=BigInt(1),Ia=BigInt(2);var Gf=BigInt(5),Xf=BigInt(8),Ze=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),fs={p:Ze,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Xf,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Qf(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,Ia,s)*a%s,u=j(c,Gt,s)*e%s,f=j(u,Gf,s)*u%s,l=j(f,t,s)*f%s,d=j(l,r,s)*l%s,h=j(d,n,s)*d%s,y=j(h,o,s)*h%s,g=j(y,o,s)*h%s,p=j(g,t,s)*f%s;return{pow_p_5_8:j(p,Ia,s)*e%s,b2:a}}function Jf(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=Qf(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=_a(fs,{uvRatio:ls}),ue=fe.Fp,La=fe.Fn;function tl(e){return Ta(fe,nn,Object.assign({adjustScalarBytes:Jf,zip215:!0},e))}var Da=tl({});var cs=as,el=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),rl=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),nl=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),ol=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Ra=e=>ls(Gt,e),sl=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),us=e=>ue.create(qt(e)&sl);function Ca(e){let{d:t}=fs,r=Ze,n=b=>ue.create(b),o=n(cs*e*e),s=n((o+Gt)*nl),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)*ol-a),d=u*u,h=n((u+u)*a),y=n(l*el),g=n(Gt-d),p=n(Gt+d);return new fe(n(h*p),n(g*y),n(y*p),n(h*g))}var le=class e extends hn{static BASE=new e(fe.BASE);static ZERO=new e(fe.ZERO);static Fp=ue;static Fn=La;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(!ia(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:y}=Ra(s(d*l)),g=s(y*u),p=s(y*g*d),b=s((i+i)*g);Yt(b,o)&&(b=s(-b));let v=s(c*p),A=s(b*v);if(!h||Yt(A,o)||v===Yf)throw new Error("invalid ristretto255 encoding 2");return new e(new fe(b,v,Gt,A))}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}=Ra(i(a*u)),l=i(f*a),d=i(f*c),h=i(l*d*o),y;if(Yt(o*h,s)){let p=i(r*cs),b=i(t*cs);t=p,r=b,y=i(l*rl)}else y=d;Yt(t*h,s)&&(r=i(-r));let g=i((n-r)*y);return Yt(g,s)&&(g=i(-g)),ue.toBytes(g)}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 il=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 il.deriveToCurve(n)},hashToScalar(e,t={DST:Ba}){let r=is(e,t.DST,64,nn);return La.create(qt(r))},deriveToCurve(e){St(e,64);let t=us(e.subarray(0,32)),r=Ca(t),n=us(e.subarray(32,64)),o=Ca(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,al=(async()=>{try{return await Bt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function cl(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 ul(e,t,r){return Da.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Oa(e,t,r){return ds==null&&(ds=await al),ds?cl(e,t,r):ul(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 Ct.digest(Tt(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=Oa(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 F(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var ll=Math.pow(2,7),dl=Math.pow(2,14),hl=Math.pow(2,21),ms=Math.pow(2,28),ys=Math.pow(2,35),bs=Math.pow(2,42),gs=Math.pow(2,49),H=128,dt=127;function It(e){if(e<ll)return 1;if(e<dl)return 2;if(e<hl)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(It(e)){case 8:t[r++]=e&255|H,e/=128;case 7:t[r++]=e&255|H,e/=128;case 6:t[r++]=e&255|H,e/=128;case 5:t[r++]=e&255|H,e/=128;case 4:t[r++]=e&255|H,e>>>=7;case 3:t[r++]=e&255|H,e>>>=7;case 2:t[r++]=e&255|H,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function pl(e,t,r=0){switch(It(e)){case 8:t.set(r++,e&255|H),e/=128;case 7:t.set(r++,e&255|H),e/=128;case 6:t.set(r++,e&255|H),e/=128;case 5:t.set(r++,e&255|H),e/=128;case 4:t.set(r++,e&255|H),e>>>=7;case 3:t.set(r++,e&255|H),e>>>=7;case 2:t.set(r++,e&255|H),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function ws(e,t){let r=e[t],n=0;if(n+=r&dt,r<H||(r=e[t+1],n+=(r&dt)<<7,r<H)||(r=e[t+2],n+=(r&dt)<<14,r<H)||(r=e[t+3],n+=(r&dt)<<21,r<H)||(r=e[t+4],n+=(r&dt)*ms,r<H)||(r=e[t+5],n+=(r&dt)*ys,r<H)||(r=e[t+6],n+=(r&dt)*bs,r<H)||(r=e[t+7],n+=(r&dt)*gs,r<H))return n;throw new RangeError("Could not decode varint")}function ml(e,t){let r=e.get(t),n=0;if(n+=r&dt,r<H||(r=e.get(t+1),n+=(r&dt)<<7,r<H)||(r=e.get(t+2),n+=(r&dt)<<14,r<H)||(r=e.get(t+3),n+=(r&dt)<<21,r<H)||(r=e.get(t+4),n+=(r&dt)*ms,r<H)||(r=e.get(t+5),n+=(r&dt)*ys,r<H)||(r=e.get(t+6),n+=(r&dt)*bs,r<H)||(r=e.get(t+7),n+=(r&dt)*gs,r<H))return n;throw new RangeError("Could not decode varint")}function gn(e,t,r=0){return t==null&&(t=lt(It(e))),t instanceof Uint8Array?Ye(e,t,r):pl(e,t,r)}function xs(e,t=0){return e instanceof Uint8Array?ws(e,t):ml(e,t)}var Es=new Float32Array([-0]),de=new Uint8Array(Es.buffer);function Ka(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 Na(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 Ua(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 Fa(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 yl=BigInt(Number.MAX_SAFE_INTEGER),bl=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<yl&&t>bl)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>Ma&&(o=0n,++n>Ma&&(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 Ma=4294967296n;function qa(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 za(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 Pt(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,Pt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Pt(this,4);return wn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Pt(this,4);return wn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Pt(this,4);let t=Na(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Pt(this,4);let t=Fa(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Pt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return za(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Pt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Pt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new At(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Pt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Pt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Pt(this,8);let t=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+=It(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function 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 Is=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},gl=_s();function wl(e){return globalThis.Buffer!=null?lt(e):gl(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,It(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=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(Bs,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(Ka,4,t)}double(t){return this._push(Ua,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Bs,1,0):this.uint32(r)._push(El,r,t)}string(t){let r=qa(t);return r!==0?this.uint32(r)._push(Ss,r,t):this._push(Bs,1,0)}fork(){return this.states=new Is(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=wl(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Bs(e,t,r){t[r]=e&255}function xl(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(xl,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 El(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(vl,t,e),this},Tr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Sl,t,e),this});function vl(e,t,r){t.set(e,r)}function Sl(e,t,r){e.length<40?Ss(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(V(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 Rt=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},Br=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 zt;(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})(zt||(zt={}));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:()=>Za,jwkToJWKKeyPair:()=>Ya,jwkToPkcs1:()=>Bl,jwkToPkix:()=>Us,jwkToRSAPrivateKey:()=>zs,pkcs1MessageToJwk:()=>Ks,pkcs1MessageToRSAPrivateKey:()=>Fs,pkcs1ToJwk:()=>Tl,pkcs1ToRSAPrivateKey:()=>ja,pkixMessageToJwk:()=>Ns,pkixMessageToRSAPublicKey:()=>qs,pkixToJwk:()=>Il,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 Wa(this.jwk,r,t,n)}},Ir=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 $a(this.jwk,t,r)}};var ks=8192,Ps=18,Al=1062,_l=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Tl(e){let t=$t(e);return Ks(t)}function Ks(e){return{n:M(e[1],"base64url"),e:M(e[2],"base64url"),d:M(e[3],"base64url"),p:M(e[4],"base64url"),q:M(e[5],"base64url"),dp:M(e[6],"base64url"),dq:M(e[7],"base64url"),qi:M(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 F("JWK was missing components");return ne([vt(Uint8Array.from([0])),vt(V(e.n,"base64url")),vt(V(e.e,"base64url")),vt(V(e.d,"base64url")),vt(V(e.p,"base64url")),vt(V(e.q,"base64url")),vt(V(e.dp,"base64url")),vt(V(e.dq,"base64url")),vt(V(e.qi,"base64url"))]).subarray()}function Il(e){let t=$t(e,{offset:0});return Ns(t)}function Ns(e){let t=$t(e[1],{offset:0});return{kty:"RSA",n:M(t[0],"base64url"),e:M(t[1],"base64url")}}function Us(e){if(e.n==null||e.e==null)throw new F("JWK was missing components");return ne([_l,Xr(ne([vt(V(e.n,"base64url")),vt(V(e.e,"base64url"))]))]).subarray()}function ja(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>=Al)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(zt.encode({Type:Z.RSA,Data:t}));r=Ut(Ps,o)}return new Ge(n,r)}function zs(e){if(Xa(e)>ks)throw new F("Key size is too large");let t=Ya(e),r=Me(zt.encode({Type:Z.RSA,Data:Us(t.publicKey)})),n=Ut(Ps,r);return new Ir(t.privateKey,new Ge(t.publicKey,n))}async function Za(e){if(e>ks)throw new F("Key size is too large");let t=await Ga(e),r=Me(zt.encode({Type:Z.RSA,Data:Us(t.publicKey)})),n=Ut(Ps,r);return new Ir(t.privateKey,new Ge(t.publicKey,n))}function Ya(e){if(e==null)throw new F("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function Ga(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 Rl(r,t);return{privateKey:n[0],publicKey:n[1]}}async function $a(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 Wa(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 Rl(e,t){if(e.privateKey==null||e.publicKey==null)throw new F("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 Xa(e){if(e.kty!=="RSA")throw new F("invalid key type");if(e.n==null)throw new F("invalid key modulus");return V(e.n,"base64url").length*8}var 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()}},Qa=(()=>{let e=((t,r,n)=>new Sn(t,r).update(n).digest());return e.create=(t,r)=>new Sn(t,r),e})();var Ja=(e,t)=>(e+(e>=0?t:-t)/tc)/t;function Cl(e,t,r){Ve("scalar",e,Vt,r);let[[n,o],[s,i]]=t,a=Ja(i*e,r),c=Ja(-o*e,r),u=e-a*n-c*s,f=-a*o-c*i,l=u<Vt,d=f<Vt;l&&(u=-u),d&&(f=-f);let h=wr(Math.ceil(He(r)/2))+he;if(u<Vt||u>=h||f<Vt||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){kt(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return Dt(r.lowS,"lowS"),Dt(r.prehash,"prehash"),r.format!==void 0&&Hs(r.format),r}var $s=class extends Error{constructor(t=""){super(t)}},Kt={Err:$s,_tlv:{encode:(e,t)=>{let{Err:r}=Kt;if(Ot(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}=Kt;t=q(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}=Kt;if(an(e),e<Vt)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}=Kt;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}=Kt,o=q(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}=Kt,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(Kt._tlv);Object.freeze(Kt._int);Object.freeze(Kt);var Vt=BigInt(0),he=BigInt(1),tc=BigInt(2),An=BigInt(3),Ll=BigInt(4);function ec(e,t={}){let r=ln("weierstrass",e,t),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;kt(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=nc(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function d(K,m,w){if(u&&m.is0())return Uint8Array.of(0);let{x:S,y:E}=m.toAffine(),x=n.toBytes(S);if(Dt(w,"isCompressed"),w){l();let _=!n.isOdd(E);return nt(rc(_),x)}else return nt(Uint8Array.of(4),x,n.toBytes(E))}function h(K){q(K,void 0,"Point");let{publicKey:m,publicKeyUncompressed:w}=f,S=K.length,E=K[0],x=K.subarray(1);if(u&&S===1&&E===0)return{x:n.ZERO,y:n.ZERO};if(S===m&&(E===2||E===3)){let _=n.fromBytes(x);if(!n.isValid(_))throw new Error("bad point: is not on curve, wrong x");let I=p(_),T;try{T=n.sqrt(I)}catch(U){let z=U instanceof Error?": "+U.message:"";throw new Error("bad point: is not on curve, sqrt error"+z)}l();let C=n.isOdd(T);return(E&1)===1!==C&&(T=n.neg(T)),{x:_,y:T}}else if(S===w&&E===4){let _=n.BYTES,I=n.fromBytes(x.subarray(0,_)),T=n.fromBytes(x.subarray(_,_*2));if(!b(I,T))throw new Error("bad point: is not on curve");return{x:I,y:T}}else throw new Error(`bad point: got length ${S}, expected compressed=${m} or uncompressed=${w}`)}let y=t.toBytes===void 0?d:t.toBytes,g=t.fromBytes===void 0?h:t.fromBytes;function p(K){let m=n.sqr(K),w=n.mul(m,K);return n.add(n.add(w,n.mul(K,s.a)),s.b)}function b(K,m){let w=n.sqr(m),S=p(K);return n.eql(w,S)}if(!b(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let v=n.mul(n.pow(s.a,An),Ll),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(v,A)))throw new Error("bad curve params: a or b");function L(K,m,w=!1){if(!n.isValid(m)||w&&n.is0(m))throw new Error(`bad point coordinate ${K}`);return m}function R(K){if(!(K instanceof B))throw new Error("Weierstrass Point expected")}function k(K){if(!c||!c.basises)throw new Error("no endo");return Cl(K,c.basises,o.ORDER)}function D(K,m,w,S,E){return w=new B(n.mul(w.X,K),w.Y,w.Z),m=Er(S,m),w=Er(E,w),m.add(w)}class B{static BASE=new B(s.Gx,s.Gy,n.ONE);static ZERO=new B(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(m,w,S){this.X=L("x",m),this.Y=L("y",w,!0),this.Z=L("z",S),Object.freeze(this)}static CURVE(){return s}static fromAffine(m){let{x:w,y:S}=m||{};if(!m||!n.isValid(w)||!n.isValid(S))throw new Error("invalid affine point");if(m instanceof B)throw new Error("projective point not allowed");return n.is0(w)&&n.is0(S)?B.ZERO:new B(w,S,n.ONE)}static fromBytes(m){let w=B.fromAffine(g(q(m,void 0,"point")));return w.assertValidity(),w}static fromHex(m){return B.fromBytes(ze(m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,w=!0){return $.createCache(this,m),w||this.multiply(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:w,y:S}=m.toAffine();if(!n.isValid(w)||!n.isValid(S))throw new Error("bad point: x or y not field elements");if(!b(w,S))throw new Error("bad point: equation left != right");if(!m.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:m}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(m)}equals(m){R(m);let{X:w,Y:S,Z:E}=this,{X:x,Y:_,Z:I}=m,T=n.eql(n.mul(w,I),n.mul(x,E)),C=n.eql(n.mul(S,I),n.mul(_,E));return T&&C}negate(){return new B(this.X,n.neg(this.Y),this.Z)}double(){let{a:m,b:w}=s,S=n.mul(w,An),{X:E,Y:x,Z:_}=this,I=n.ZERO,T=n.ZERO,C=n.ZERO,O=n.mul(E,E),U=n.mul(x,x),z=n.mul(_,_),N=n.mul(E,x);return N=n.add(N,N),C=n.mul(E,_),C=n.add(C,C),I=n.mul(m,C),T=n.mul(S,z),T=n.add(I,T),I=n.sub(U,T),T=n.add(U,T),T=n.mul(I,T),I=n.mul(N,I),C=n.mul(S,C),z=n.mul(m,z),N=n.sub(O,z),N=n.mul(m,N),N=n.add(N,C),C=n.add(O,O),O=n.add(C,O),O=n.add(O,z),O=n.mul(O,N),T=n.add(T,O),z=n.mul(x,_),z=n.add(z,z),O=n.mul(z,N),I=n.sub(I,O),C=n.mul(z,U),C=n.add(C,C),C=n.add(C,C),new B(I,T,C)}add(m){R(m);let{X:w,Y:S,Z:E}=this,{X:x,Y:_,Z:I}=m,T=n.ZERO,C=n.ZERO,O=n.ZERO,U=s.a,z=n.mul(s.b,An),N=n.mul(w,x),rt=n.mul(S,_),ot=n.mul(E,I),st=n.add(w,S),Q=n.add(x,_);st=n.mul(st,Q),Q=n.add(N,rt),st=n.sub(st,Q),Q=n.add(w,E);let xt=n.add(x,I);return Q=n.mul(Q,xt),xt=n.add(N,ot),Q=n.sub(Q,xt),xt=n.add(S,E),T=n.add(_,I),xt=n.mul(xt,T),T=n.add(rt,ot),xt=n.sub(xt,T),O=n.mul(U,Q),T=n.mul(z,ot),O=n.add(T,O),T=n.sub(rt,O),O=n.add(rt,O),C=n.mul(T,O),rt=n.add(N,N),rt=n.add(rt,N),ot=n.mul(U,ot),Q=n.mul(z,Q),rt=n.add(rt,ot),ot=n.sub(N,ot),ot=n.mul(U,ot),Q=n.add(Q,ot),N=n.mul(rt,Q),C=n.add(C,N),N=n.mul(xt,Q),T=n.mul(st,T),T=n.sub(T,N),N=n.mul(st,rt),O=n.mul(xt,O),O=n.add(O,N),new B(T,C,O)}subtract(m){return R(m),this.add(m.negate())}is0(){return this.equals(B.ZERO)}multiply(m){let{endo:w}=t;if(!o.isValidNot0(m))throw new RangeError("invalid scalar: out of range");let S,E,x=_=>$.cached(this,_,I=>ve(B,I));if(w){let{k1neg:_,k1:I,k2neg:T,k2:C}=k(m),{p:O,f:U}=x(I),{p:z,f:N}=x(C);E=U.add(N),S=D(w.beta,O,z,_,T)}else{let{p:_,f:I}=x(m);S=_,E=I}return ve(B,[S,E])[0]}multiplyUnsafe(m){let{endo:w}=t,S=this,E=m;if(!o.isValid(E))throw new RangeError("invalid scalar: out of range");if(E===Vt||S.is0())return B.ZERO;if(E===he)return S;if($.hasCache(this))return this.multiply(E);if(w){let{k1neg:x,k1:_,k2neg:I,k2:T}=k(E),{p1:C,p2:O}=Aa(B,S,_,T);return D(w.beta,C,O,x,I)}else return $.unsafe(S,E)}toAffine(m){let w=this,S=m,{X:E,Y:x,Z:_}=w;if(n.eql(_,n.ONE))return{x:E,y:x};let I=w.is0();S==null&&(S=I?n.ONE:n.inv(_));let T=n.mul(E,S),C=n.mul(x,S),O=n.mul(_,S);if(I)return{x:n.ZERO,y:n.ZERO};if(!n.eql(O,n.ONE))throw new Error("invZ was invalid");return{x:T,y:C}}isTorsionFree(){let{isTorsionFree:m}=t;return i===he?!0:m?m(B,this):$.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:m}=t;return i===he?this:m?m(B,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===he?this.is0():this.clearCofactor().is0()}toBytes(m=!0){return Dt(m,"isCompressed"),this.assertValidity(),y(B,this,m)}toHex(m=!0){return qe(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let P=o.BITS,$=new je(B,t.endo?Math.ceil(P/2):P);return P>=8&&B.BASE.precompute(8),Object.freeze(B.prototype),Object.freeze(B),B}function rc(e){return Uint8Array.of(e?2:3)}function nc(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Dl(e,t={}){let{Fn:r}=e,n=t.randomBytes===void 0?yr:t.randomBytes,o=Object.assign(nc(e.Fp,r),{seed:Math.max(ts(r.ORDER),16)});function s(h){try{let y=r.fromBytes(h);return r.isValidNot0(y)}catch{return!1}}function i(h,y){let{publicKey:g,publicKeyUncompressed:p}=o;try{let b=h.length;return y===!0&&b!==g||y===!1&&b!==p?!1:!!e.fromBytes(h)}catch{return!1}}function a(h){return h=h===void 0?n(o.seed):h,es(q(h,o.seed,"seed"),r.ORDER)}function c(h,y=!0){return e.BASE.multiply(r.fromBytes(h)).toBytes(y)}function u(h){let{secretKey:y,publicKey:g,publicKeyUncompressed:p}=o,b=r._lengths;if(!ge(h))return;let v=q(h,void 0,"key").length,A=v===g||v===p,L=v===y||!!b?.includes(v);if(!(A&&L))return A}function f(h,y,g=!0){if(u(h)===!0)throw new Error("first arg must be private key");if(u(y)===!1)throw new Error("second arg must be public key");let p=r.fromBytes(h);return e.fromBytes(y).multiply(p).toBytes(g)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},d=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 oc(e,t,r={}){let n=t;Qr(n),kt(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?(E,x)=>Qa(n,E,x):r.hmac,{Fp:i,Fn:a}=e,{ORDER:c,BITS:u}=a,{keygen:f,getPublicKey:l,getSharedSecret:d,utils:h,lengths:y}=Dl(e,r),g={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},p=c*tc+he<i.ORDER;function b(E){let x=c>>he;return E>x}function v(E,x){if(!a.isValidNot0(x))throw new Error(`invalid signature ${E}: out of range 1..Point.Fn.ORDER`);return x}function A(){if(p)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function L(E,x){Hs(x);let _=y.signature,I=x==="compact"?_:x==="recovered"?_+1:void 0;return q(E,I)}class R{r;s;recovery;constructor(x,_,I){if(this.r=v("r",x),this.s=v("s",_),I!=null){if(A(),![0,1,2,3].includes(I))throw new Error("invalid recovery id");this.recovery=I}Object.freeze(this)}static fromBytes(x,_=g.format){L(x,_);let I;if(_==="der"){let{r:U,s:z}=Kt.toSig(q(x));return new R(U,z)}_==="recovered"&&(I=x[0],_="compact",x=x.subarray(1));let T=y.signature/2,C=x.subarray(0,T),O=x.subarray(T,T*2);return new R(a.fromBytes(C),a.fromBytes(O),I)}static fromHex(x,_){return this.fromBytes(ze(x),_)}assertRecovery(){let{recovery:x}=this;if(x==null)throw new Error("invalid recovery id: must be present");return x}addRecoveryBit(x){return new R(this.r,this.s,x)}recoverPublicKey(x){let{r:_,s:I}=this,T=this.assertRecovery(),C=T===2||T===3?_+c:_;if(!i.isValid(C))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let O=i.toBytes(C),U=e.fromBytes(nt(rc((T&1)===0),O)),z=a.inv(C),N=D(q(x,void 0,"msgHash")),rt=a.create(-N*z),ot=a.create(I*z),st=e.BASE.multiplyUnsafe(rt).add(U.multiplyUnsafe(ot));if(st.is0())throw new Error("invalid recovery: point at infinify");return st.assertValidity(),st}hasHighS(){return b(this.s)}toBytes(x=g.format){if(Hs(x),x==="der")return ze(Kt.hexFromSig(this));let{r:_,s:I}=this,T=a.toBytes(_),C=a.toBytes(I);return x==="recovered"?(A(),nt(Uint8Array.of(this.assertRecovery()),T,C)):nt(T,C)}toHex(x){return qe(this.toBytes(x))}}Object.freeze(R.prototype),Object.freeze(R);let k=r.bits2int===void 0?function(x){if(x.length>8192)throw new Error("input is too large");let _=we(x),I=x.length*8-u;return I>0?_>>BigInt(I):_}:r.bits2int,D=r.bits2int_modN===void 0?function(x){return a.create(k(x))}:r.bits2int_modN,B=wr(u);function P(E){return Ve("num < 2^"+u,E,Vt,B),a.toBytes(E)}function $(E,x){return q(E,void 0,"message"),x?q(n(E),void 0,"prehashed message"):E}function K(E,x,_){let{lowS:I,prehash:T,extraEntropy:C}=Vs(_,g);E=$(E,T);let O=D(E),U=a.fromBytes(x);if(!a.isValidNot0(U))throw new Error("invalid private key");let z=[P(U),P(O)];if(C!=null&&C!==!1){let st=C===!0?o(y.secretKey):C;z.push(q(st,void 0,"extraEntropy"))}let N=nt(...z),rt=O;function ot(st){let Q=k(st);if(!a.isValidNot0(Q))return;let xt=a.inv(Q),Re=e.BASE.multiply(Q).toAffine(),rr=a.create(Re.x);if(rr===Vt)return;let Hr=a.create(xt*a.create(rt+rr*U));if(Hr===Vt)return;let yi=(Re.x===rr?0:2)|Number(Re.y&he),bi=Hr;return I&&b(Hr)&&(bi=a.neg(Hr),yi^=1),new R(rr,bi,p?void 0:yi)}return{seed:N,k2sig:ot}}function m(E,x,_={}){let{seed:I,k2sig:T}=K(E,x,_);return aa(n.outputLen,a.BYTES,s)(I,T).toBytes(_.format)}function w(E,x,_,I={}){let{lowS:T,prehash:C,format:O}=Vs(I,g);if(_=q(_,void 0,"publicKey"),x=$(x,C),!ge(E)){let U=E instanceof R?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+U)}L(E,O);try{let U=R.fromBytes(E,O),z=e.fromBytes(_);if(T&&U.hasHighS())return!1;let{r:N,s:rt}=U,ot=D(x),st=a.inv(rt),Q=a.create(ot*st),xt=a.create(N*st),Re=e.BASE.multiplyUnsafe(Q).add(z.multiplyUnsafe(xt));return Re.is0()?!1:a.create(Re.x)===N}catch{return!1}}function S(E,x,_={}){let{prehash:I}=Vs(_,g);return x=$(x,I),R.fromBytes(E,"recovered").recoverPublicKey(x).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:d,utils:h,lengths:y,Point:e,sign:m,verify:w,recoverPublicKey:S,Signature: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")},Ol={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var sc=BigInt(2);function kl(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,sc,t)*u%t,y=j(h,o,t)*h%t,g=j(y,s,t)*y%t,p=j(g,a,t)*g%t,b=j(p,c,t)*p%t,v=j(b,a,t)*g%t,A=j(v,r,t)*f%t,L=j(A,i,t)*y%t,R=j(L,n,t)*u%t,k=j(R,sc,t);if(!Ws.eql(Ws.sqr(k),e))throw new Error("Cannot find square root");return k}var Ws=$e(js.p,{sqrt:kl}),Pl=ec(js,{Fp:Ws,endo:Ol}),Xe=oc(Pl,Me);function ic(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=cc(t),this.raw=ac(this._key)}toMultihash(){return Ct.digest(Tt(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 ic(this._key,r,t,n)}};function Zs(e){return new _n(e)}function ac(e){return Xe.Point.fromBytes(e).toBytes()}function cc(e){try{return Xe.Point.fromBytes(e),e}catch(t){throw new Ce(String(t))}}function Tn(e,t){let{Type:r,Data:n}=zt.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 uc(e){let{Type:t,Data:r}=zt.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 Tt(e){return zt.encode({Type:Z[e.type],Data:e.raw})}var fc=Symbol.for("nodejs.util.inspect.custom"),Kl=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(Kl,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")}[fc](){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}},Nl=2336,kr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Ct.digest(V(this.url))}[fc](){return`PeerId(${this.url})`}[jr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return et.createV1(Nl,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=M(t)),t.toString()===this.toString())}};var Ul=114,lc=2336;function dc(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(Ml(e))return new Lr({multihash:e});if(Fl(e))try{let t=uc(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=M(e.digest);return new kr(new URL(r))}throw new Wr("Supplied PeerID Multihash is invalid")}function Bn(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==Ul&&e.code!==lc)throw new $r("Supplied PeerID CID is invalid");if(e.code===lc){let t=M(e.multihash.digest);return new kr(new URL(t))}return Ys(e.multihash)}function Fl(e){return e.code===Ct.code}function Ml(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 In=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=hc(o,s,i),c=await r.sign(a.subarray(),n);return new e({publicKey:r.publicKey,payloadType:s,payload:i,signature:c})};static openAndCertify=async(t,r,n)=>{let o=e.createFromProtobuf(t);if(!await o.validate(r,n))throw new In("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:r,payloadType:n,payload:o,signature:s}=t;this.publicKey=r,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=Pr.encode({publicKey:Tt(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=hc(t,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},hc=(e,t,r)=>{let n=V(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 ql=45,zl=15,Dn=new Ln;function pc(e){if(!(e.length>zl))return Dn.new(e).parseWith(()=>Dn.readIPv4Addr())}function mc(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>ql))return Dn.new(e).parseWith(()=>Dn.readIPv6Addr())}function On(e){return!!pc(e)}function yc(e){return!!mc(e)}function Xs(e){return t=>M(t,e)}function Qs(e){return t=>V(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 bc(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let r=V(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=_e(n);return Ft([r,o],r.length+o.length)}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!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let r=Nt.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 Ft([r,o],r.length+o.length)}function Js(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=M(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},wc=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]=M(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,M(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},xc=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(".")},Ec=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 vc(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),Vl=(function(){let e=Gs[0].or(Gs[1]);return Gs.slice(2).forEach(t=>e=e.or(t)),e})();function Sc(e){return Vl.decode(e)}function Ac(e){return t=>e.encoder.encode(t)}function Hl(e){if(parseInt(e).toString()!==e)throw new Xt("Value must be an integer")}function $l(e){if(e<0)throw new Xt("Value must be a positive integer, or zero")}function Wl(e){return t=>{if(t>e)throw new Xt(`Value must be smaller than or equal to ${e}`)}}function jl(...e){return t=>{for(let r of e)r(t)}}var Kr=jl(Hl,$l,Wl(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,Od=[{code:4,name:"ip4",size:32,valueToBytes:ti,bytesToValue:xc,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:wc,bytesToValue:Ec,stringToValue:vc,validate:e=>{if(!yc(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:bc},{code:445,name:"onion3",size:296,bytesToValue:Js,valueToBytes:gc},{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:Ac(Ao),valueToBytes:Sc},{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}];Od.forEach(e=>{Qt.addProtocol(e)});function _c(e){let t=[],r=0;for(;r<e.length;){let n=xs(e,r),o=Qt.getProtocol(n),s=It(n),i=kd(o,e,r+s),a=0;i>0&&o.size===at&&(a=It(i));let c=s+a+i,u={code:n,name:o.name,bytes: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)??M(l)}t.push(u),r+=c}return t}function Tc(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=Qt.getProtocol(n.code),s=It(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??V(n.value),a=i.byteLength,o.size===at&&(c=It(a)));let u=new Uint8Array(s+c+a),f=0;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 Ft(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 Ic(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 kd(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:xs(t,r)}var Pd=Symbol.for("nodejs.util.inspect.custom"),ni=Symbol.for("@multiformats/multiaddr");function Kd(e){if(e==null&&(e="/"),Pn(e))return e.getComponents();if(e instanceof Uint8Array)return _c(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=Kd(t),r.validate!==!1&&Nd(this)}get bytes(){return this.#r==null&&(this.#r=Tc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Ic(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)}[Pd](){return`Multiaddr(${this.toString()})`}};function Nd(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 Rc="libp2p-peer-record",Cc=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 y={multiaddr:J(0)},g=d==null?l.len:l.pos+d;for(;l.pos<g;){let p=l.uint32();p>>>3===1?y.multiaddr=l.bytes():l.skipType(p&7)}return y},function*(l,d,h,y={}){let g=d==null?l.len:l.pos+d;for(;l.pos<g;){let p=l.uint32();p>>>3===1?yield{field:`${h}.multiaddr`,value:l.bytes()}:l.skipType(p&7)}})),a);function c(l){return 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 Rt('Decode error - repeated field "addresses" had too many elements');u.addresses.push(e.AddressInfo.codec().decode(i,i.uint32(),{limits:c.limits?.addresses$}));break}default:{i.skipType(l&7);break}}}return u},function*(i,a,c,u={}){let f={addresses:0},l=a==null?i.len:i.pos+a;for(;i.pos<l;){let d=i.uint32();switch(d>>>3){case 1:{yield{field:`${c}.peerId`,value:i.bytes()};break}case 2:{yield{field:`${c}.seq`,value:i.uint64()};break}case 3:{if(u.limits?.addresses!=null&&f.addresses===u.limits.addresses)throw new Rt('Streaming decode error - repeated field "addresses" had too many elements');for(let h of e.AddressInfo.codec().stream(i,i.uint32(),`${c}.addresses[]`,{limits:u.limits?.addresses$}))yield{...h,index:f.addresses};f.addresses++;break}default:{i.skipType(d&7);break}}}})),r);function n(i){return 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 Lc(e,t){let r=(n,o)=>n.toString().localeCompare(o.toString());return e.length!==t.length?!1:(t.sort(r),e.sort(r).every((n,o)=>t[o].equals(n)))}var Be=class e{static createFromProtobuf=t=>{let r=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=Rc;static CODEC=Cc;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||!Lc(this.multiaddrs,t.multiaddrs))}};function Ud(e){return e[Symbol.asyncIterator]!=null}function Fd(e){if(Ud(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 Dc=Fd;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 Oc(e={}){return Md(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 Md(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,b)=>{s=v=>{s=null,n.push(v);try{p(e(n))}catch(A){b(A)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=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}),y=p=>(d(p),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:h,throw:y,push:l,end:d,get readableLength(){return n.size},onEmpty:async p=>{let b=p?.signal;if(b?.throwIfAborted(),n.isEmpty())return;let v,A;b!=null&&(v=new Promise((L,R)=>{A=()=>{R(new oi)},b.addEventListener("abort",A)}));try{await Promise.race([a.promise,v])}finally{A!=null&&b!=null&&b?.removeEventListener("abort",A)}}},r==null)return o;let g=o;return o={[Symbol.asyncIterator](){return this},next(){return g.next()},throw(p){return g.throw(p),r!=null&&(r(p),r=void 0),{done:!0}},return(){return g.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(p){return g.end(p),r!=null&&(r(p),r=void 0),o},get readableLength(){return g.readableLength},onEmpty:p=>g.onEmpty(p)},o}function qd(e){return e.reason}async function kc(e,t,r){if(t==null)return e;let n=r?.translateError??qd;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&&(Pc(e)?e.addEventListener(t,r):e.addListener(t,r))}function ci(e,t,r){e!=null&&(Pc(e)?e.removeEventListener(t,r):e.removeListener(t,r))}function Pc(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 zd(){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=zd(),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 kc(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=Oc({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",Kc={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 y={type:h.data.type,name:h.data.name,identifier:h.data.identifier};y.type===a&&y.identifier===f.identifier&&(t.removeEventListener("message",d),l())};t.addEventListener("message",d)})},onError:l=>{t.postMessage({type:i,name:f.name,identifier:f.identifier,error:{message:l.message,name:l.name,stack:l.stack}})}}}),f.type===s&&e.safeDispatchEvent(n,{detail:{name:f.name,identifier:f.identifier}}),f.type===Jn&&e.safeDispatchEvent("finalizeRequest",{detail:{name:f.name}})};var Nc=(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=Nc();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 Uc=e=>{if(e=Object.assign({},Kc,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 Ie=new Map,Mr;function Fc(e){return typeof e?.readLock=="function"&&typeof e?.writeLock=="function"}function Vd(e){if(Mr==null&&(Mr=Uc(e),!Fc(Mr))){let t=Mr;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 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 Mc=(e,t)=>{let r=Ie.get(e);if(r!=null)return r;let n=Vd(t);if(Fc(n))return r=n,Ie.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:()=>{Ie.delete(e)},queue:o},Ie.set(e,r),t.autoFinalize===!0&&o.addEventListener("idle",()=>{r.finalize()},{once:!0}),r};var Hd={name:"lock",concurrency:1/0,singleProcess:!1,autoFinalize:!1};function di(e){let t=Object.assign({},Hd,e);return Mc(t.name,t)}var Jt;(function(e){let t;(function(a){let c;a.codec=()=>(c==null&&(c=wt((d,h,y={})=>{y.lengthDelimited!==!1&&h.fork(),d.key!=null&&d.key!==""&&(h.uint32(10),h.string(d.key)),d.value!=null&&d.value.byteLength>0&&(h.uint32(18),h.bytes(d.value)),y.lengthDelimited!==!1&&h.ldelim()},(d,h,y={})=>{let g={key:"",value:J(0)},p=h==null?d.len:d.pos+h;for(;d.pos<p;){let b=d.uint32();switch(b>>>3){case 1:{g.key=d.string();break}case 2:{g.value=d.bytes();break}default:{d.skipType(b&7);break}}}return g},function*(d,h,y,g={}){let p=h==null?d.len:d.pos+h;for(;d.pos<p;){let b=d.uint32();switch(b>>>3){case 1:{yield{field:`${y}.key`,value:d.string()};break}case 2:{yield{field:`${y}.value`,value:d.bytes()};break}default:{d.skipType(b&7);break}}}})),c);function u(d){return 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,y={})=>{y.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)),y.lengthDelimited!==!1&&h.ldelim()},(d,h,y={})=>{let g={key:""},p=h==null?d.len:d.pos+h;for(;d.pos<p;){let b=d.uint32();switch(b>>>3){case 1:{g.key=d.string();break}case 2:{g.value=zr.codec().decode(d,d.uint32(),{limits:y.limits?.value});break}default:{d.skipType(b&7);break}}}return g},function*(d,h,y,g={}){let p=h==null?d.len:d.pos+h;for(;d.pos<p;){let b=d.uint32();switch(b>>>3){case 1:{yield{field:`${y}.key`,value:d.string()};break}case 2:{yield*zr.codec().stream(d,d.uint32(),`${y}.value`,{limits:g.limits?.value});break}default:{d.skipType(b&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 Rt('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 Rt('Decode error - repeated field "protocols" had too many elements');f.protocols.push(a.string());break}case 4:{f.publicKey=a.bytes();break}case 5:{f.peerRecordEnvelope=a.bytes();break}case 6:{if(u.limits?.metadata!=null&&f.metadata.size===u.limits.metadata)throw new Br('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 Br('Decode error - map field "tags" had too many elements');let h=e.Peer$tagsEntry.codec().decode(a,a.uint32(),{limits:{value:u.limits?.tags$value}});f.tags.set(h.key,h.value);break}case 8:{f.updated=a.uint64Number();break}default:{a.skipType(d&7);break}}}return f},function*(a,c,u,f={}){let l={addresses:0,protocols:0,metadata:0,tags:0},d=c==null?a.len:a.pos+c;for(;a.pos<d;){let h=a.uint32();switch(h>>>3){case 1:{if(f.limits?.addresses!=null&&l.addresses===f.limits.addresses)throw new Rt('Streaming decode error - repeated field "addresses" had too many elements');for(let y of qr.codec().stream(a,a.uint32(),`${u}.addresses[]`,{limits:f.limits?.addresses$}))yield{...y,index:l.addresses};l.addresses++;break}case 2:{if(f.limits?.protocols!=null&&l.protocols===f.limits.protocols)throw new Rt('Streaming decode error - repeated field "protocols" had too many elements');yield{field:`${u}.protocols[]`,index:l.protocols,value:a.string()},l.protocols++;break}case 4:{yield{field:`${u}.publicKey`,value:a.bytes()};break}case 5:{yield{field:`${u}.peerRecordEnvelope`,value:a.bytes()};break}case 6:{if(f.limits?.metadata!=null&&l.metadata===f.limits.metadata)throw new Rt('Decode error - map field "metadata" had too many elements');yield*e.Peer$metadataEntry.codec().stream(a,a.uint32(),`${u}.metadata{}`,{limits:{value:f.limits?.metadata$value}}),l.metadata++;break}case 7:{if(f.limits?.tags!=null&&l.tags===f.limits.tags)throw new Rt('Decode error - map field "tags" had too many elements');yield*e.Peer$tagsEntry.codec().stream(a,a.uint32(),`${u}.tags{}`,{limits:{value:f.limits?.tags$value}}),l.tags++;break}case 8:{yield{field:`${u}.updated`,value:a.uint64Number()};break}default:{a.skipType(h&7);break}}}})),n);function o(a){return 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 $d(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 dc(n)}function qc(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:$d(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 zc(e,t){return Wd(e.addresses,t.addresses)&&jd(e.protocols,t.protocols)&&Zd(e.publicKey,t.publicKey)&&Yd(e.peerRecordEnvelope,t.peerRecordEnvelope)&&Gd(e.metadata,t.metadata)&&Xd(e.tags,t.tags)}function Wd(e,t){return Hc(e,t,(r,n)=>!(r.isCertified!==n.isCertified||!W(r.multiaddr,n.multiaddr)))}function jd(e,t){return Hc(e,t,(r,n)=>r===n)}function Zd(e,t){return Vc(e,t)}function Yd(e,t){return Vc(e,t)}function Gd(e,t){return $c(e,t,(r,n)=>W(r,n))}function Xd(e,t){return $c(e,t,(r,n)=>r.value===n.value&&r.expiry===n.expiry)}function Vc(e,t){return e==null&&t==null?!0:e!=null&&t!=null?W(e,t):!1}function Hc(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 $c(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="/",Wc=new TextEncoder().encode(te),ro=Wc[0],no=class e{_buf;constructor(t,r){if(typeof t=="string")this._buf=V(t);else if(t instanceof Uint8Array)this._buf=t;else throw new Error("Invalid key, should be String of Uint8Array");if(r==null&&(r=!0),r&&this.clean(),this._buf.byteLength===0||this._buf[0]!==ro)throw new Error("Invalid key")}toString(t="utf8"){return M(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=Wc),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 Qd(this.baseNamespace())}name(){return Jd(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(),...th(t.map(r=>r.namespaces()))])}};function Qd(e){let t=e.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function Jd(e){let t=e.split(":");return t[t.length-1]}function th(e){return[].concat(...e)}var hi="/peers/";function Vr(e){if(!Le(e)||e.type==null)throw new F("Invalid PeerId");let t=e.toCID().toString();return new no(`${hi}${t}`)}async function jc(e,t,r,n,o){let s=new Map;for(let i of r){if(i==null)continue;if(i.multiaddr instanceof Uint8Array&&(i.multiaddr=Te(i.multiaddr)),!Pn(i.multiaddr))throw new F("Multiaddr was invalid");if(!await t(e,i.multiaddr,o))continue;let a=i.isCertified??!1,c=i.multiaddr.toString(),u=s.get(c);u!=null?i.isCertified=u.isCertified||a:s.set(c,{multiaddr:i.multiaddr,isCertified:a})}return[...s.values()].sort((i,a)=>i.multiaddr.toString().localeCompare(a.multiaddr.toString())).map(({isCertified:i,multiaddr:a})=>{let c=a.getComponents().find(u=>u.code===421)?.value;return e.equals(c)&&(a=a.decapsulate(Te(`/p2p/${e}`))),{isCertified:i,multiaddr:a.bytes}})}async function so(e,t,r,n){if(t==null)throw new F("Invalid PeerData");if(t.publicKey!=null&&e.publicKey!=null&&!t.publicKey.equals(e.publicKey))throw new F("publicKey bytes do not match peer id publicKey bytes");let o=n.existingPeer?.peer;if(o!=null&&!e.equals(o.id))throw new F("peer id did not match existing peer id");let s=o?.addresses??[],i=new Set(o?.protocols??[]),a=o?.metadata??new Map,c=o?.tags??new Map,u=o?.peerRecordEnvelope;if(r==="patch"){if((t.multiaddrs!=null||t.addresses!=null)&&(s=[],t.multiaddrs!=null&&s.push(...t.multiaddrs.map(d=>({isCertified:!1,multiaddr:d}))),t.addresses!=null&&s.push(...t.addresses)),t.protocols!=null&&(i=new Set(t.protocols)),t.metadata!=null){let d=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);a=oo(d,{validate:Zc})}if(t.tags!=null){let d=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags);c=oo(d,{validate:Yc,map:Gc})}t.peerRecordEnvelope!=null&&(u=t.peerRecordEnvelope)}if(r==="merge"){if(t.multiaddrs!=null&&s.push(...t.multiaddrs.map(d=>({isCertified:!1,multiaddr:d}))),t.addresses!=null&&s.push(...t.addresses),t.protocols!=null&&(i=new Set([...i,...t.protocols])),t.metadata!=null){let d=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);for(let[h,y]of d)y==null?a.delete(h):a.set(h,y);a=oo([...a.entries()],{validate:Zc})}if(t.tags!=null){let d=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags),h=new Map(c);for(let[y,g]of d)g==null?h.delete(y):h.set(y,g);c=oo([...h.entries()],{validate:Yc,map:Gc})}t.peerRecordEnvelope!=null&&(u=t.peerRecordEnvelope)}let f;o?.id.publicKey!=null?f=Tt(o.id.publicKey):t.publicKey!=null?f=Tt(t.publicKey):e.publicKey!=null&&(f=Tt(e.publicKey));let l={addresses:await jc(e,n.addressFilter??(async()=>!0),s,n.existingPeer?.peerPB.addresses,n),protocols:[...i.values()].sort((d,h)=>d.localeCompare(h)),metadata:a,tags:c,publicKey:f,peerRecordEnvelope:u};return l.addresses.forEach(d=>{d.observed=n.existingPeer?.peerPB.addresses?.find(h=>W(h.multiaddr,h.multiaddr))?.observed??Date.now()}),e.type!=="RSA"&&delete l.publicKey,l}function 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 Zc(e,t){if(typeof e!="string")throw new F("Metadata key must be a string");if(!(t instanceof Uint8Array))throw new F("Metadata value must be a Uint8Array")}function Yc(e,t){if(typeof e!="string")throw new F("Tag name must be a string");if(t.value!=null){if(parseInt(`${t.value}`,10)!==t.value)throw new F("Tag value must be an integer");if(t.value<0||t.value>100)throw new F("Tag value must be between 0-100")}if(t.ttl!=null){if(parseInt(`${t.ttl}`,10)!==t.ttl)throw new F("Tag ttl must be an integer");if(t.ttl<0)throw new F("Tag ttl must be between greater than 0")}}function Gc(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 Xc(e){let t=e.toString().split("/")[2],r=et.parse(t,Nt);return Bn(r)}function pi(e,t,r){let n=Xc(e);return qc(n,t,r)}function eh(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(eh(t??{},this.maxAddressAge),t)){let o=Xc(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||!zc(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 Dc(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,Be.DOMAIN,s),a=Bn(i.publicKey.toCID());if(o?.equals(a)===!1)return this.log("envelope peer id was not the expected peer id - expected: %p received: %p",o,a),!1;let c=Be.createFromProtobuf(i.payload),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=Be.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 rh(e,t={}){return new mi(e,t)}return ru(nh);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/curves/utils.js: