@libp2p/bootstrap 12.0.15 → 12.0.16-f60bd85b0

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.Libp2PBootstrap = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PBootstrap=(()=>{var nn=Object.defineProperty;var Bc=Object.getOwnPropertyDescriptor;var _c=Object.getOwnPropertyNames;var Ic=Object.prototype.hasOwnProperty;var yt=(e,t)=>{for(var r in t)nn(e,r,{get:t[r],enumerable:!0})},Cc=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of _c(t))!Ic.call(e,o)&&o!==r&&nn(e,o,{get:()=>t[o],enumerable:!(n=Bc(t,o))||n.enumerable});return e};var Dc=e=>Cc(nn({},"__esModule",{value:!0}),e);var Mu={};yt(Mu,{bootstrap:()=>Ku});var It=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},cr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var ar=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},fr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Le=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var cs=Symbol.for("@libp2p/peer-discovery");var on=Symbol.for("@libp2p/peer-id");var ur=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){super.addEventListener(t,r,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}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))}dispatchEvent(t){let r=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),r}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var as=Symbol.for("@libp2p/service-capabilities"),Zu=Symbol.for("@libp2p/service-dependencies");var un={};yt(un,{base58btc:()=>et,base58flickr:()=>Nc});var bl=new Uint8Array(0);function fs(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 Ot(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function us(e){return new TextEncoder().encode(e)}function ls(e){return new TextDecoder().decode(e)}function Tc(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),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var B=0,v=0,b=0,A=m.length;b!==A&&m[b]===0;)b++,B++;for(var y=(A-b)*u+1>>>0,_=new Uint8Array(y);b!==A;){for(var R=m[b],M=0,k=y-1;(R!==0||M<v)&&k!==-1;k--,M++)R+=256*_[k]>>>0,_[k]=R%a>>>0,R=R/a>>>0;if(R!==0)throw new Error("Non-zero carry");v=M,b++}for(var g=y-v;g!==y&&_[g]===0;)g++;for(var x=c.repeat(B);g<y;++g)x+=e.charAt(_[g]);return x}function w(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var B=0;if(m[B]!==" "){for(var v=0,b=0;m[B]===c;)v++,B++;for(var A=(m.length-B)*f+1>>>0,y=new Uint8Array(A);m[B];){var _=r[m.charCodeAt(B)];if(_===255)return;for(var R=0,M=A-1;(_!==0||R<b)&&M!==-1;M--,R++)_+=a*y[M]>>>0,y[M]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");b=R,B++}if(m[B]!==" "){for(var k=A-b;k!==A&&y[k]===0;)k++;for(var g=new Uint8Array(v+(A-k)),x=v;k!==A;)g[x++]=y[k++];return g}}}function S(m){var B=w(m);if(B)return B;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:w,decode:S}}var Oc=Tc,Lc=Oc,hs=Lc;var sn=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")}},cn=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 ps(this,t)}},an=class{decoders;constructor(t){this.decoders=t}or(t){return ps(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 ps(e,t){return new an({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var fn=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 sn(t,r,n),this.decoder=new cn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function le({name:e,prefix:t,encode:r,decode:n}){return new fn(e,t,r,n)}function zt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=hs(r,e);return le({prefix:t,name:e,encode:n,decode:s=>Ot(o(s))})}function Pc(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let f=0;f<o;++f){let u=t[e[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Rc(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 Uc(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function J({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Uc(n);return le({prefix:t,name:e,encode(s){return Rc(s,n,r)},decode(s){return Pc(s,o,r,e)}})}var et=zt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Nc=zt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ln={};yt(ln,{base32:()=>Zt,base32hex:()=>Vc,base32hexpad:()=>qc,base32hexpadupper:()=>zc,base32hexupper:()=>Hc,base32pad:()=>Mc,base32padupper:()=>kc,base32upper:()=>Kc,base32z:()=>Zc});var Zt=J({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Kc=J({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Mc=J({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),kc=J({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Vc=J({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Hc=J({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),qc=J({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),zc=J({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Zc=J({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var dn={};yt(dn,{base36:()=>Pe,base36upper:()=>Fc});var Pe=zt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Fc=zt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var $c=ys,ms=128,Yc=127,jc=~Yc,Gc=Math.pow(2,31);function ys(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Gc;)t[r++]=e&255|ms,e/=128;for(;e&jc;)t[r++]=e&255|ms,e>>>=7;return t[r]=e|0,ys.bytes=r-n+1,t}var Wc=hn,Xc=128,bs=127;function hn(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw hn.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&bs)<<o:(i&bs)*Math.pow(2,o),o+=7}while(i>=Xc);return hn.bytes=s-n,r}var Qc=Math.pow(2,7),Jc=Math.pow(2,14),ta=Math.pow(2,21),ea=Math.pow(2,28),ra=Math.pow(2,35),na=Math.pow(2,42),oa=Math.pow(2,49),sa=Math.pow(2,56),ia=Math.pow(2,63),ca=function(e){return e<Qc?1:e<Jc?2:e<ta?3:e<ea?4:e<ra?5:e<na?6:e<oa?7:e<sa?8:e<ia?9:10},aa={encode:$c,decode:Wc,encodingLength:ca},fa=aa,Re=fa;function Ue(e,t=0){return[Re.decode(e,t),Re.decode.bytes]}function de(e,t,r=0){return Re.encode(e,t,r),t}function he(e){return Re.encodingLength(e)}function me(e,t){let r=t.byteLength,n=he(e),o=n+he(r),s=new Uint8Array(o+r);return de(e,s,0),de(r,s,n),s.set(t,o),new pe(e,r,t,s)}function Ne(e){let t=Ot(e),[r,n]=Ue(t),[o,s]=Ue(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new pe(r,o,i,t)}function xs(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&fs(e.bytes,r.bytes)}}var pe=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function gs(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return la(r,pn(e),t??et.encoder);default:return da(r,pn(e),t??Zt.encoder)}}var ws=new WeakMap;function pn(e){let t=ws.get(e);if(t==null){let r=new Map;return ws.set(e,r),r}return t}var ct=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==Ke)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==ha)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=me(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&&xs(t.multihash,n.multihash)}toString(t){return gs(this,t)}toJSON(){return{"/":gs(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??Es(n,o,s.bytes))}else if(r[pa]===!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!==Ke)throw new Error(`Version 0 CID must use dag-pb (code: ${Ke}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Es(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Ke,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=Ot(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new pe(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,w]=Ue(t.subarray(r));return r+=w,l},o=n(),s=Ke;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),f=r+c,u=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(t,r){let[n,o]=ua(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 pn(s).set(n,t),s}};function ua(e,t){switch(e[0]){case"Q":{let r=t??et;return[et.prefix,r.decode(`${et.prefix}${e}`)]}case et.prefix:{let r=t??et;return[et.prefix,r.decode(e)]}case Zt.prefix:{let r=t??Zt;return[Zt.prefix,r.decode(e)]}case Pe.prefix:{let r=t??Pe;return[Pe.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 la(e,t,r){let{prefix:n}=r;if(n!==et.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 da(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 Ke=112,ha=18;function Es(e,t,r){let n=he(e),o=n+he(t),s=new Uint8Array(o+r.byteLength);return de(e,s,0),de(t,s,n),s.set(r,o),s}var pa=Symbol.for("@ipld/js-cid/CID");var mn={};yt(mn,{identity:()=>vt});var Ss=0,ma="identity",vs=Ot;function ba(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 me(Ss,vs(e))}var vt={code:Ss,name:ma,encode:vs,digest:ba};function xt(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 Lt(e=0){return new Uint8Array(e)}function gt(e=0){return new Uint8Array(e)}function Pt(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=gt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Bs=Symbol.for("@achingbrain/uint8arraylist");function As(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 dr(e){return!!e?.[Bs]}var wt=class e{bufs;length;[Bs]=!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(dr(n))r+=n.byteLength,this.bufs.push(...n.bufs);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(dr(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=As(this.bufs,t);return r.buf[r.index]}set(t,r){let n=As(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(dr(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 Pt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Pt(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let f=t>=a&&t<c,u=r>a&&r<=c;if(f&&u){if(t===a&&r===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(r-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!dr(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,f=n.byteLength-1,u;for(let l=r;l<=c;l+=u){u=0;for(let w=f;w>=0;w--){let S=this.get(l+w);if(n[w]!==S){u=Math.max(1,w-a[S]);break}}if(u===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=gt(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=Lt(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=Lt(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=Lt(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=gt(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=Lt(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=Lt(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=Lt(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=Lt(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=Lt(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(!xt(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 bn={};yt(bn,{base10:()=>ya});var ya=zt({prefix:"9",name:"base10",alphabet:"0123456789"});var yn={};yt(yn,{base16:()=>xa,base16upper:()=>ga});var xa=J({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),ga=J({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var xn={};yt(xn,{base2:()=>wa});var wa=J({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var gn={};yt(gn,{base256emoji:()=>Ba});var _s=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}"),Ea=_s.reduce((e,t,r)=>(e[r]=t,e),[]),Sa=_s.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function va(e){return e.reduce((t,r)=>(t+=Ea[r],t),"")}function Aa(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Sa[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Ba=le({prefix:"\u{1F680}",name:"base256emoji",encode:va,decode:Aa});var En={};yt(En,{base64:()=>_a,base64pad:()=>Ia,base64url:()=>wn,base64urlpad:()=>Ca});var _a=J({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ia=J({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),wn=J({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ca=J({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Sn={};yt(Sn,{base8:()=>Da});var Da=J({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var vn={};yt(vn,{identity:()=>Ta});var Ta=le({prefix:"\0",name:"identity",encode:e=>ls(e),decode:e=>us(e)});var Jl=new TextEncoder,td=new TextDecoder;var _n={};yt(_n,{sha256:()=>Me,sha512:()=>Ra});var Pa=20;function Bn({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new An(e,t,r,n,o)}var An=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Pa,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?Is(n,this.code,r?.truncate):n.then(o=>Is(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Is(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 me(t,e)}function Ds(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Me=Bn({name:"sha2-256",code:18,encode:Ds("SHA-256")}),Ra=Bn({name:"sha2-512",code:19,encode:Ds("SHA-512")});var ke={...vn,...xn,...Sn,...bn,...yn,...ln,...dn,...un,...En,...gn},dd={..._n,...mn};function Os(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Ts=Os("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),In=Os("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=gt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Ua={utf8:Ts,"utf-8":Ts,hex:ke.base16,latin1:In,ascii:In,binary:In,...ke},hr=Ua;function Et(e,t="utf8"){let r=hr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function rt(e,t="utf8"){let r=hr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Na=parseInt("11111",2),Cn=parseInt("10000000",2),Ka=parseInt("01111111",2),Ls={0:Ve,1:Ve,2:Ma,3:Ha,4:qa,5:Va,6:ka,16:Ve,22:Ve,48:Ve};function Dn(e,t={offset:0}){let r=e[t.offset]&Na;if(t.offset++,Ls[r]!=null)return Ls[r](e,t);throw new Error("No decoder for tag "+r)}function He(e,t){let r=0;if((e[t.offset]&Cn)===Cn){let n=e[t.offset]&Ka,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 Ve(e,t){He(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Dn(e,t);if(n===null)break;r.push(n)}return r}function Ma(e,t){let r=He(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 ka(e,t){let r=He(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let f=e[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let u=0;for(let l=0;l<c.length;l++)u+=c[l]<<l*7;a+=`.${u}`,c=[]}}return a}function Va(e,t){return t.offset++,null}function Ha(e,t){let r=He(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 qa(e,t){let r=He(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function za(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new wt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Tn(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=za(e.byteLength);return new wt(Uint8Array.from([t.byteLength|Cn]),t)}function Ps(e){let t=new wt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new wt(Uint8Array.from([2]),Tn(t),t)}function Rs(e){let t=Uint8Array.from([0]),r=new wt(t,e);return new wt(Uint8Array.from([3]),Tn(r),r)}function pr(e,t=48){let r=new wt;for(let n of e)r.append(n);return new wt(Uint8Array.from([t]),Tn(r),r)}async function Us(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),s}var Za=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Fa=Uint8Array.from([6,5,43,129,4,0,34]),$a=Uint8Array.from([6,5,43,129,4,0,35]),Ya={ext:!0,kty:"EC",crv:"P-256"},ja={ext:!0,kty:"EC",crv:"P-384"},Ga={ext:!0,kty:"EC",crv:"P-521"},On=32,Ln=48,Pn=66;function Ns(e){let t=Dn(e);return Ks(t)}function Ks(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===On*2+1)return n=rt(t.subarray(r,r+On),"base64url"),o=rt(t.subarray(r+On),"base64url"),new ye({...Ya,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ln*2+1)return n=rt(t.subarray(r,r+Ln),"base64url"),o=rt(t.subarray(r+Ln),"base64url"),new ye({...ja,key_ops:["verify"],x:n,y:o});if(t.byteLength===Pn*2+1)return n=rt(t.subarray(r,r+Pn),"base64url"),o=rt(t.subarray(r+Pn),"base64url"),new ye({...Ga,key_ops:["verify"],x:n,y:o});throw new It(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Ms(e){return pr([Ps(Uint8Array.from([1])),pr([Wa(e.crv)],160),pr([Rs(new wt(Uint8Array.from([4]),Et(e.x??"","base64url"),Et(e.y??"","base64url")))],161)]).subarray()}function Wa(e){if(e==="P-256")return Za;if(e==="P-384")return Fa;if(e==="P-521")return $a;throw new It(`Invalid curve ${e}`)}var ye=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Ms(this.jwk)),this._raw}toMultihash(){return vt.digest(xe(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return et.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:xt(this.raw,t.raw)}async verify(t,r,n){return Us(this.jwk,r,t,n)}};function Qt(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Ct(e,t=""){if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new Error(`${r}expected integer >= 0, got ${e}`)}}function K(e,t,r=""){let n=Qt(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}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return e}function mr(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash must wrapped by utils.createHasher");Ct(e.outputLen),Ct(e.blockLen)}function ge(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 Vs(e,t){K(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function Ut(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function br(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function At(e,t){return e<<32-t|e>>>t}var Hs=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Xa=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Nt(e){if(K(e),Hs)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Xa[e[r]];return t}var Rt={_0:48,_9:57,A:65,F:70,a:97,f:102};function ks(e){if(e>=Rt._0&&e<=Rt._9)return e-Rt._0;if(e>=Rt.A&&e<=Rt.F)return e-(Rt.A-10);if(e>=Rt.a&&e<=Rt.f)return e-(Rt.a-10)}function Kt(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Hs)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("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=ks(e.charCodeAt(s)),a=ks(e.charCodeAt(s+1));if(i===void 0||a===void 0){let c=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function bt(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];K(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 Rn(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.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function we(e=32){let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(e))}var Un=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function qs(e,t,r){return e&t^~e&r}function zs(e,t,r){return e&t^e&r^t&r}var qe=class{blockLen;outputLen;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=br(this.buffer)}update(t){ge(this),K(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=br(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){ge(this),Vs(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Ut(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=br(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)a.setUint32(4*l,u[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()}},Mt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var at=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var yr=BigInt(4294967295),Zs=BigInt(32);function Qa(e,t=!1){return t?{h:Number(e&yr),l:Number(e>>Zs&yr)}:{h:Number(e>>Zs&yr)|0,l:Number(e&yr)|0}}function Fs(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}=Qa(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Nn=(e,t,r)=>e>>>r,Kn=(e,t,r)=>e<<32-r|t>>>r,Jt=(e,t,r)=>e>>>r|t<<32-r,te=(e,t,r)=>e<<32-r|t>>>r,ze=(e,t,r)=>e<<64-r|t>>>r-32,Ze=(e,t,r)=>e>>>r-32|t<<64-r;function Dt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var $s=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Ys=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,js=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Gs=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Ws=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Xs=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var tf=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),Mn=class extends qe{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)Ft[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let w=Ft[l-15],S=Ft[l-2],m=At(w,7)^At(w,18)^w>>>3,B=At(S,17)^At(S,19)^S>>>10;Ft[l]=B+Ft[l-7]+m+Ft[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:f,H:u}=this;for(let l=0;l<64;l++){let w=At(a,6)^At(a,11)^At(a,25),S=u+w+qs(a,c,f)+tf[l]+Ft[l]|0,B=(At(n,2)^At(n,13)^At(n,22))+zs(n,o,s)|0;u=f,f=c,c=a,a=i+S|0,i=s,s=o,o=n,n=S+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,f=f+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,c,f,u)}roundClean(){Ut(Ft)}destroy(){this.set(0,0,0,0,0,0,0,0),Ut(this.buffer)}},kn=class extends Mn{A=Mt[0]|0;B=Mt[1]|0;C=Mt[2]|0;D=Mt[3]|0;E=Mt[4]|0;F=Mt[5]|0;G=Mt[6]|0;H=Mt[7]|0;constructor(){super(32)}};var Qs=Fs(["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))),ef=Qs[0],rf=Qs[1],$t=new Uint32Array(80),Yt=new Uint32Array(80),Vn=class extends qe{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:f,El:u,Fh:l,Fl:w,Gh:S,Gl:m,Hh:B,Hl:v}=this;return[t,r,n,o,s,i,a,c,f,u,l,w,S,m,B,v]}set(t,r,n,o,s,i,a,c,f,u,l,w,S,m,B,v){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=w|0,this.Gh=S|0,this.Gl=m|0,this.Hh=B|0,this.Hl=v|0}process(t,r){for(let y=0;y<16;y++,r+=4)$t[y]=t.getUint32(r),Yt[y]=t.getUint32(r+=4);for(let y=16;y<80;y++){let _=$t[y-15]|0,R=Yt[y-15]|0,M=Jt(_,R,1)^Jt(_,R,8)^Nn(_,R,7),k=te(_,R,1)^te(_,R,8)^Kn(_,R,7),g=$t[y-2]|0,x=Yt[y-2]|0,U=Jt(g,x,19)^ze(g,x,61)^Nn(g,x,6),V=te(g,x,19)^Ze(g,x,61)^Kn(g,x,6),T=js(k,V,Yt[y-7],Yt[y-16]),h=Gs(T,M,U,$t[y-7],$t[y-16]);$t[y]=h|0,Yt[y]=T|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:w,Fh:S,Fl:m,Gh:B,Gl:v,Hh:b,Hl:A}=this;for(let y=0;y<80;y++){let _=Jt(l,w,14)^Jt(l,w,18)^ze(l,w,41),R=te(l,w,14)^te(l,w,18)^Ze(l,w,41),M=l&S^~l&B,k=w&m^~w&v,g=Ws(A,R,k,rf[y],Yt[y]),x=Xs(g,b,_,M,ef[y],$t[y]),U=g|0,V=Jt(n,o,28)^ze(n,o,34)^ze(n,o,39),T=te(n,o,28)^Ze(n,o,34)^Ze(n,o,39),h=n&s^n&a^s&a,p=o&i^o&c^i&c;b=B|0,A=v|0,B=S|0,v=m|0,S=l|0,m=w|0,{h:l,l:w}=Dt(f|0,u|0,x|0,U|0),f=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let d=$s(U,T,p);n=Ys(d,x,V,h),o=d|0}({h:n,l:o}=Dt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Dt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Dt(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=Dt(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:w}=Dt(this.Eh|0,this.El|0,l|0,w|0),{h:S,l:m}=Dt(this.Fh|0,this.Fl|0,S|0,m|0),{h:B,l:v}=Dt(this.Gh|0,this.Gl|0,B|0,v|0),{h:b,l:A}=Dt(this.Hh|0,this.Hl|0,b|0,A|0),this.set(n,o,s,i,a,c,f,u,l,w,S,m,B,v,b,A)}roundClean(){Ut($t,Yt)}destroy(){Ut(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Hn=class extends Vn{Ah=at[0]|0;Al=at[1]|0;Bh=at[2]|0;Bl=at[3]|0;Ch=at[4]|0;Cl=at[5]|0;Dh=at[6]|0;Dl=at[7]|0;Eh=at[8]|0;El=at[9]|0;Fh=at[10]|0;Fl=at[11]|0;Gh=at[12]|0;Gl=at[13]|0;Hh=at[14]|0;Hl=at[15]|0;constructor(){super(64)}};var Js=Rn(()=>new kn,Un(1));var ti=Rn(()=>new Hn,Un(3));var zn=BigInt(0),qn=BigInt(1);function kt(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function ei(e){if(typeof e=="bigint"){if(!xr(e))throw new Error("positive bigint expected, got "+e)}else Ct(e);return e}function Fe(e){let t=ei(e).toString(16);return t.length&1?"0"+t:t}function ri(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?zn:BigInt("0x"+e)}function Ee(e){return ri(Nt(e))}function ee(e){return ri(Nt(wr(K(e)).reverse()))}function gr(e,t){Ct(t),e=ei(e);let r=Kt(e.toString(16).padStart(t*2,"0"));if(r.length!==t)throw new Error("number too large");return r}function Zn(e,t){return gr(e,t).reverse()}function wr(e){return Uint8Array.from(e)}var xr=e=>typeof e=="bigint"&&zn<=e;function nf(e,t,r){return xr(e)&&xr(t)&&xr(r)&&t<=e&&e<r}function $e(e,t,r,n){if(!nf(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Fn(e){let t;for(t=0;e>zn;e>>=qn,t+=1);return t}var Ye=e=>(qn<<BigInt(e))-qn;function ni(e,t,r){if(Ct(e,"hashLen"),Ct(t,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");let n=v=>new Uint8Array(v),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(e),f=n(e),u=0,l=()=>{c.fill(1),f.fill(0),u=0},w=(...v)=>r(f,bt(c,...v)),S=(v=o)=>{f=w(s,v),c=w(),v.length!==0&&(f=w(i,v),c=w())},m=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let v=0,b=[];for(;v<t;){c=w();let A=c.slice();b.push(A),v+=c.length}return bt(...b)};return(v,b)=>{l(),S(v);let A;for(;!(A=b(m()));)S();return l(),A}}function jt(e,t={},r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(s,i,a){let c=e[s];if(a&&c===void 0)return;let f=typeof c;if(f!==i||c===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${f}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(t,!1),o(r,!0)}function Se(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var pt=BigInt(0),nt=BigInt(1),re=BigInt(2),ii=BigInt(3),ci=BigInt(4),ai=BigInt(5),of=BigInt(7),fi=BigInt(8),sf=BigInt(9),ui=BigInt(16);function tt(e,t){let r=e%t;return r>=pt?r:t+r}function j(e,t,r){let n=e;for(;t-- >pt;)n*=n,n%=r;return n}function oi(e,t){if(e===pt)throw new Error("invert: expected non-zero number");if(t<=pt)throw new Error("invert: expected positive modulus, got "+t);let r=tt(e,t),n=t,o=pt,s=nt,i=nt,a=pt;for(;r!==pt;){let f=n/r,u=n%r,l=o-i*f,w=s-a*f;n=r,r=u,o=i,s=a,i=l,a=w}if(n!==nt)throw new Error("invert: does not exist");return tt(o,t)}function Yn(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function li(e,t){let r=(e.ORDER+nt)/ci,n=e.pow(t,r);return Yn(e,n,t),n}function cf(e,t){let r=(e.ORDER-ai)/fi,n=e.mul(t,re),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,re),o),a=e.mul(s,e.sub(i,e.ONE));return Yn(e,a,t),a}function af(e){let t=ve(e),r=di(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+of)/ui;return(a,c)=>{let f=a.pow(c,i),u=a.mul(f,n),l=a.mul(f,o),w=a.mul(f,s),S=a.eql(a.sqr(u),c),m=a.eql(a.sqr(l),c);f=a.cmov(f,u,S),u=a.cmov(w,l,m);let B=a.eql(a.sqr(u),c),v=a.cmov(f,u,B);return Yn(a,v,c),v}}function di(e){if(e<ii)throw new Error("sqrt is not defined for small field");let t=e-nt,r=0;for(;t%re===pt;)t/=re,r++;let n=re,o=ve(e);for(;si(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return li;let s=o.pow(n,t),i=(t+nt)/re;return function(c,f){if(c.is0(f))return f;if(si(c,f)!==1)throw new Error("Cannot find square root");let u=r,l=c.mul(c.ONE,s),w=c.pow(f,t),S=c.pow(f,i);for(;!c.eql(w,c.ONE);){if(c.is0(w))return c.ZERO;let m=1,B=c.sqr(w);for(;!c.eql(B,c.ONE);)if(m++,B=c.sqr(B),m===u)throw new Error("Cannot find square root");let v=nt<<BigInt(u-m-1),b=c.pow(l,v);u=m,l=c.sqr(b),w=c.mul(w,l),S=c.mul(S,b)}return S}}function ff(e){return e%ci===ii?li:e%fi===ai?cf:e%ui===sf?af(e):di(e)}var hi=(e,t)=>(tt(e,t)&nt)===nt,uf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function jn(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=uf.reduce((n,o)=>(n[o]="function",n),t);return jt(e,r),e}function lf(e,t,r){if(r<pt)throw new Error("invalid exponent, negatives unsupported");if(r===pt)return e.ONE;if(r===nt)return t;let n=e.ONE,o=t;for(;r>pt;)r&nt&&(n=e.mul(n,o)),o=e.sqr(o),r>>=nt;return n}function je(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,a,c)=>e.is0(a)?i:(n[c]=i,e.mul(i,a)),e.ONE),s=e.inv(o);return t.reduceRight((i,a,c)=>e.is0(a)?i:(n[c]=e.mul(i,n[c]),e.mul(i,a)),s),n}function si(e,t){let r=(e.ORDER-nt)/re,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function df(e,t){t!==void 0&&Ct(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}var $n=class{ORDER;BITS;BYTES;isLE;ZERO=pt;ONE=nt;_lengths;_sqrt;_mod;constructor(t,r={}){if(t<=pt)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&(this.sqrt=r.sqrt),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=r.allowedLengths?.slice()),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=df(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return tt(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return pt<=t&&t<this.ORDER}is0(t){return t===pt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&nt)===nt}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 lf(this,t,r)}div(t,r){return tt(t*oi(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 oi(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=ff(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?Zn(t,this.BYTES):gr(t,this.BYTES)}fromBytes(t,r=!1){K(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let f=new Uint8Array(o);f.set(t,s?0:f.length-t.length),t=f}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=s?ee(t):Ee(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 je(this,t)}cmov(t,r,n){return n?r:t}};function ve(e,t={}){return new $n(e,t)}function pi(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function Gn(e){let t=pi(e);return t+Math.ceil(t/2)}function Wn(e,t,r=!1){K(e);let n=e.length,o=pi(t),s=Gn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?ee(e):Ee(e),a=tt(i,t-nt)+nt;return r?Zn(a,o):gr(a,o)}var Ae=BigInt(0),ne=BigInt(1);function Ge(e,t){let r=t.negate();return e?r:t}function oe(e,t){let r=je(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function xi(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Xn(e,t){xi(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=Ye(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function mi(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+=ne);let f=t*n,u=f+Math.abs(a)-1,l=a===0,w=a<0,S=t%2!==0;return{nextN:c,offset:u,isZero:l,isNeg:w,isNegF:S,offsetF:f}}var Qn=new WeakMap,gi=new WeakMap;function Jn(e){return gi.get(e)||1}function bi(e){if(e!==Ae)throw new Error("invalid wNAF")}var Be=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>Ae;)r&ne&&(n=n.add(o)),o=o.double(),r>>=ne;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=Xn(r,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let f=1;f<o;f++)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=Xn(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:f,isZero:u,isNeg:l,isNegF:w,offsetF:S}=mi(n,a,i);n=c,u?s=s.add(Ge(w,r[S])):o=o.add(Ge(l,r[f]))}return bi(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=Xn(t,this.bits);for(let i=0;i<s.windows&&n!==Ae;i++){let{nextN:a,offset:c,isZero:f,isNeg:u}=mi(n,i,s);if(n=a,!f){let l=r[c];o=o.add(u?l.negate():l)}}return bi(n),o}getPrecomputes(t,r,n){let o=Qn.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),Qn.set(r,o))),o}cached(t,r,n){let o=Jn(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=Jn(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){xi(r,this.bits),gi.set(t,r),Qn.delete(t)}hasCache(t){return Jn(t)!==1}};function wi(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Ae||n>Ae;)r&ne&&(s=s.add(o)),n&ne&&(i=i.add(o)),o=o.double(),r>>=ne,n>>=ne;return{p1:s,p2:i}}function yi(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return jn(t),t}else return ve(e,{isLE:r})}function Er(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 f=t[c];if(!(typeof f=="bigint"&&f>Ae))throw new Error(`CURVE.${c} must be positive bigint`)}let o=yi(t.p,r.Fp,n),s=yi(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 Sr(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var Gt=BigInt(0),ot=BigInt(1),to=BigInt(2),hf=BigInt(8);function pf(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 Ei(e,t={}){let r=Er("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;jt(t,{},{uvRatio:"function"});let a=to<<BigInt(o.BYTES*8)-ot,c=v=>n.create(v),f=t.uvRatio||((v,b)=>{try{return{isValid:!0,value:n.sqrt(n.div(v,b))}}catch{return{isValid:!1,value:Gt}}});if(!pf(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function u(v,b,A=!1){let y=A?ot:Gt;return $e("coordinate "+v,b,y,a),b}function l(v){if(!(v instanceof m))throw new Error("EdwardsPoint expected")}let w=Se((v,b)=>{let{X:A,Y:y,Z:_}=v,R=v.is0();b==null&&(b=R?hf:n.inv(_));let M=c(A*b),k=c(y*b),g=n.mul(_,b);if(R)return{x:Gt,y:ot};if(g!==ot)throw new Error("invZ was invalid");return{x:M,y:k}}),S=Se(v=>{let{a:b,d:A}=s;if(v.is0())throw new Error("bad point: ZERO");let{X:y,Y:_,Z:R,T:M}=v,k=c(y*y),g=c(_*_),x=c(R*R),U=c(x*x),V=c(k*b),T=c(x*c(V+g)),h=c(U+c(A*c(k*g)));if(T!==h)throw new Error("bad point: equation left != right (1)");let p=c(y*_),d=c(R*M);if(p!==d)throw new Error("bad point: equation left != right (2)");return!0});class m{static BASE=new m(s.Gx,s.Gy,ot,c(s.Gx*s.Gy));static ZERO=new m(Gt,ot,ot,Gt);static Fp=n;static Fn=o;X;Y;Z;T;constructor(b,A,y,_){this.X=u("x",b),this.Y=u("y",A),this.Z=u("z",y,!0),this.T=u("t",_),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){if(b instanceof m)throw new Error("extended point not allowed");let{x:A,y}=b||{};return u("x",A),u("y",y),new m(A,y,ot,c(A*y))}static fromBytes(b,A=!1){let y=n.BYTES,{a:_,d:R}=s;b=wr(K(b,y,"point")),kt(A,"zip215");let M=wr(b),k=b[y-1];M[y-1]=k&-129;let g=ee(M),x=A?a:n.ORDER;$e("point.y",g,Gt,x);let U=c(g*g),V=c(U-ot),T=c(R*U-_),{isValid:h,value:p}=f(V,T);if(!h)throw new Error("bad point: invalid y coordinate");let d=(p&ot)===ot,E=(k&128)!==0;if(!A&&p===Gt&&E)throw new Error("bad point: x=0 and x_0=1");return E!==d&&(p=c(-p)),m.fromAffine({x:p,y:g})}static fromHex(b,A=!1){return m.fromBytes(Kt(b),A)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,A=!0){return B.createCache(this,b),A||this.multiply(to),this}assertValidity(){S(this)}equals(b){l(b);let{X:A,Y:y,Z:_}=this,{X:R,Y:M,Z:k}=b,g=c(A*k),x=c(R*_),U=c(y*k),V=c(M*_);return g===x&&U===V}is0(){return this.equals(m.ZERO)}negate(){return new m(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:b}=s,{X:A,Y:y,Z:_}=this,R=c(A*A),M=c(y*y),k=c(to*c(_*_)),g=c(b*R),x=A+y,U=c(c(x*x)-R-M),V=g+M,T=V-k,h=g-M,p=c(U*T),d=c(V*h),E=c(U*h),I=c(T*V);return new m(p,d,I,E)}add(b){l(b);let{a:A,d:y}=s,{X:_,Y:R,Z:M,T:k}=this,{X:g,Y:x,Z:U,T:V}=b,T=c(_*g),h=c(R*x),p=c(k*y*V),d=c(M*U),E=c((_+R)*(g+x)-T-h),I=d-p,D=d+p,O=c(h-A*T),C=c(E*I),P=c(D*O),N=c(E*O),W=c(I*D);return new m(C,P,W,N)}subtract(b){return this.add(b.negate())}multiply(b){if(!o.isValidNot0(b))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:A,f:y}=B.cached(this,b,_=>oe(m,_));return oe(m,[A,y])[0]}multiplyUnsafe(b,A=m.ZERO){if(!o.isValid(b))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return b===Gt?m.ZERO:this.is0()||b===ot?this:B.unsafe(this,b,y=>oe(m,y),A)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return B.unsafe(this,s.n).is0()}toAffine(b){return w(this,b)}clearCofactor(){return i===ot?this:this.multiplyUnsafe(i)}toBytes(){let{x:b,y:A}=this.toAffine(),y=n.toBytes(A);return y[y.length-1]|=b&ot?128:0,y}toHex(){return Nt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let B=new Be(m,o.BITS);return m.BASE.precompute(8),m}function Si(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');jt(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=e,a=r.randomBytes||we,c=r.adjustScalarBytes||(g=>g),f=r.domain||((g,x,U)=>{if(kt(U,"phflag"),x.length||U)throw new Error("Contexts/pre-hash are not supported");return g});function u(g){return i.create(ee(g))}function l(g){let x=y.secretKey;K(g,y.secretKey,"secretKey");let U=K(t(g),2*x,"hashedSecretKey"),V=c(U.slice(0,x)),T=U.slice(x,2*x),h=u(V);return{head:V,prefix:T,scalar:h}}function w(g){let{head:x,prefix:U,scalar:V}=l(g),T=o.multiply(V),h=T.toBytes();return{head:x,prefix:U,scalar:V,point:T,pointBytes:h}}function S(g){return w(g).pointBytes}function m(g=Uint8Array.of(),...x){let U=bt(...x);return u(t(f(U,K(g,void 0,"context"),!!n)))}function B(g,x,U={}){g=K(g,void 0,"message"),n&&(g=n(g));let{prefix:V,scalar:T,pointBytes:h}=w(x),p=m(U.context,V,g),d=o.multiply(p).toBytes(),E=m(U.context,d,h,g),I=i.create(p+E*T);if(!i.isValid(I))throw new Error("sign failed: invalid s");let D=bt(d,i.toBytes(I));return K(D,y.signature,"result")}let v={zip215:!0};function b(g,x,U,V=v){let{context:T,zip215:h}=V,p=y.signature;g=K(g,p,"signature"),x=K(x,void 0,"message"),U=K(U,y.publicKey,"publicKey"),h!==void 0&&kt(h,"zip215"),n&&(x=n(x));let d=p/2,E=g.subarray(0,d),I=ee(g.subarray(d,p)),D,O,C;try{D=e.fromBytes(U,h),O=e.fromBytes(E,h),C=o.multiplyUnsafe(I)}catch{return!1}if(!h&&D.isSmallOrder())return!1;let P=m(T,O.toBytes(),D.toBytes(),x);return O.add(D.multiplyUnsafe(P)).subtract(C).clearCofactor().is0()}let A=s.BYTES,y={secretKey:A,publicKey:A,signature:2*A,seed:A};function _(g=a(y.seed)){return K(g,y.seed,"seed")}function R(g){return Qt(g)&&g.length===i.BYTES}function M(g,x){try{return!!e.fromBytes(g,x)}catch{return!1}}let k={getExtendedPublicKey:w,randomSecretKey:_,isValidSecretKey:R,isValidPublicKey:M,toMontgomery(g){let{y:x}=e.fromBytes(g),U=y.publicKey,V=U===32;if(!V&&U!==57)throw new Error("only defined for 25519 and 448");let T=V?s.div(ot+x,ot-x):s.div(x-ot,x+ot);return s.toBytes(T)},toMontgomerySecret(g){let x=y.secretKey;K(g,x);let U=t(g.subarray(0,x));return c(U).subarray(0,x)}};return Object.freeze({keygen:Sr(_,S),getPublicKey:S,sign:B,verify:b,utils:k,Point:e,lengths:y})}var mf=BigInt(1),vi=BigInt(2);var bf=BigInt(5),yf=BigInt(8),eo=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),xf={p:eo,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:yf,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function gf(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=eo,a=e*e%s*e%s,c=j(a,vi,s)*a%s,f=j(c,mf,s)*e%s,u=j(f,bf,s)*f%s,l=j(u,t,s)*u%s,w=j(l,r,s)*l%s,S=j(w,n,s)*w%s,m=j(S,o,s)*S%s,B=j(m,o,s)*S%s,v=j(B,t,s)*u%s;return{pow_p_5_8:j(v,vi,s)*e%s,b2:a}}function wf(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Ai=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Ef(e,t){let r=eo,n=tt(t*t*t,r),o=tt(n*n*t,r),s=gf(e*o).pow_p_5_8,i=tt(e*n*s,r),a=tt(t*i*i,r),c=i,f=tt(i*Ai,r),u=a===e,l=a===tt(-e,r),w=a===tt(-e*Ai,r);return u&&(i=c),(l||w)&&(i=f),hi(i,r)&&(i=tt(-i,r)),{isValid:u||l,value:i}}var Sf=Ei(xf,{uvRatio:Ef});function vf(e){return Si(Sf,ti,Object.assign({adjustScalarBytes:wf},e))}var Bi=vf({});var We=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},vr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var _i={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new vr("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 Ar=_i;var Br=32;var ro,Af=(async()=>{try{return await Ar.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Bf(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Ar.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Ar.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function _f(e,t,r){return Bi.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Ii(e,t,r){return ro==null&&(ro=await Af),ro?Bf(e,t,r):_f(e,t,r)}function _r(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Ir=class{type="Ed25519";raw;constructor(t){this.raw=no(t,Br)}toMultihash(){return vt.digest(xe(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return et.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:xt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Ii(this.raw,r,t);return _r(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Di(e){return e=no(e,Br),new Ir(e)}function no(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new It(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Cf=Math.pow(2,7),Df=Math.pow(2,14),Tf=Math.pow(2,21),oo=Math.pow(2,28),so=Math.pow(2,35),io=Math.pow(2,42),co=Math.pow(2,49),G=128,lt=127;function Tt(e){if(e<Cf)return 1;if(e<Df)return 2;if(e<Tf)return 3;if(e<oo)return 4;if(e<so)return 5;if(e<io)return 6;if(e<co)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Xe(e,t,r=0){switch(Tt(e)){case 8:t[r++]=e&255|G,e/=128;case 7:t[r++]=e&255|G,e/=128;case 6:t[r++]=e&255|G,e/=128;case 5:t[r++]=e&255|G,e/=128;case 4:t[r++]=e&255|G,e>>>=7;case 3:t[r++]=e&255|G,e>>>=7;case 2:t[r++]=e&255|G,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function ao(e,t){let r=e[t],n=0;if(n+=r&lt,r<G||(r=e[t+1],n+=(r&lt)<<7,r<G)||(r=e[t+2],n+=(r&lt)<<14,r<G)||(r=e[t+3],n+=(r&lt)<<21,r<G)||(r=e[t+4],n+=(r&lt)*oo,r<G)||(r=e[t+5],n+=(r&lt)*so,r<G)||(r=e[t+6],n+=(r&lt)*io,r<G)||(r=e[t+7],n+=(r&lt)*co,r<G))return n;throw new RangeError("Could not decode varint")}function Of(e,t){let r=e.get(t),n=0;if(n+=r&lt,r<G||(r=e.get(t+1),n+=(r&lt)<<7,r<G)||(r=e.get(t+2),n+=(r&lt)<<14,r<G)||(r=e.get(t+3),n+=(r&lt)<<21,r<G)||(r=e.get(t+4),n+=(r&lt)*oo,r<G)||(r=e.get(t+5),n+=(r&lt)*so,r<G)||(r=e.get(t+6),n+=(r&lt)*io,r<G)||(r=e.get(t+7),n+=(r&lt)*co,r<G))return n;throw new RangeError("Could not decode varint")}function fo(e,t=0){return e instanceof Uint8Array?ao(e,t):Of(e,t)}var uo=new Float32Array([-0]),Wt=new Uint8Array(uo.buffer);function Ti(e,t,r){uo[0]=e,t[r]=Wt[0],t[r+1]=Wt[1],t[r+2]=Wt[2],t[r+3]=Wt[3]}function Oi(e,t){return Wt[0]=e[t],Wt[1]=e[t+1],Wt[2]=e[t+2],Wt[3]=e[t+3],uo[0]}var lo=new Float64Array([-0]),dt=new Uint8Array(lo.buffer);function Li(e,t,r){lo[0]=e,t[r]=dt[0],t[r+1]=dt[1],t[r+2]=dt[2],t[r+3]=dt[3],t[r+4]=dt[4],t[r+5]=dt[5],t[r+6]=dt[6],t[r+7]=dt[7]}function Pi(e,t){return dt[0]=e[t],dt[1]=e[t+1],dt[2]=e[t+2],dt[3]=e[t+3],dt[4]=e[t+4],dt[5]=e[t+5],dt[6]=e[t+6],dt[7]=e[t+7],lo[0]}var Pf=BigInt(Number.MAX_SAFE_INTEGER),Rf=BigInt(Number.MIN_SAFE_INTEGER),St=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return se;if(t<Pf&&t>Rf)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>Ri&&(o=0n,++n>Ri&&(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 St(0,0);se.toBigInt=function(){return 0n};se.zzEncode=se.zzDecode=function(){return this};se.length=function(){return 1};var Ri=4294967296n;function Ui(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 Ni(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 ho(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 Bt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Cr(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var po=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Bt(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 Bt(this,4);return Cr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Bt(this,4);return Cr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Bt(this,4);let t=Oi(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Bt(this,4);let t=Pi(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 Bt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Ni(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Bt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Bt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new St(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Bt(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 Bt(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 Bt(this,8);let t=Cr(this.buf,this.pos+=4),r=Cr(this.buf,this.pos+=4);return new St(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=ao(this.buf,this.pos);return this.pos+=Tt(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 Qe(e){return new po(e instanceof Uint8Array?e:e.subarray())}function Dr(e,t,r){let n=Qe(e);return t.decode(n,void 0,r)}function mo(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return gt(i);o+i>t&&(n=gt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var ie=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function bo(){}var xo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Uf=mo();function Nf(e){return globalThis.Buffer!=null?gt(e):Uf(e)}var tr=class{len;head;tail;states;constructor(){this.len=0,this.head=new ie(bo,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ie(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new go((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(Tr,10,St.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=St.fromBigInt(t);return this._push(Tr,r.length(),r)}uint64Number(t){return this._push(Xe,Tt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=St.fromBigInt(t).zzEncode();return this._push(Tr,r.length(),r)}sint64Number(t){let r=St.fromNumber(t).zzEncode();return this._push(Tr,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(yo,1,t?1:0)}fixed32(t){return this._push(Je,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=St.fromBigInt(t);return this._push(Je,4,r.lo)._push(Je,4,r.hi)}fixed64Number(t){let r=St.fromNumber(t);return this._push(Je,4,r.lo)._push(Je,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(Ti,4,t)}double(t){return this._push(Li,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(yo,1,0):this.uint32(r)._push(Mf,r,t)}string(t){let r=Ui(t);return r!==0?this.uint32(r)._push(ho,r,t):this._push(yo,1,0)}fork(){return this.states=new xo(this),this.head=this.tail=new ie(bo,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 ie(bo,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=Nf(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function yo(e,t,r){t[r]=e&255}function Kf(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var go=class extends ie{next;constructor(t,r){super(Kf,t,r),this.next=void 0}};function Tr(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 Je(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 Mf(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(kf,t,e),this},tr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Vf,t,e),this});function kf(e,t,r){t.set(e,r)}function Vf(e,t,r){e.length<40?ho(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(Et(e),r)}function wo(){return new tr}function Or(e,t){let r=wo();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*Lr(e,t,r){let n=Qe(e);yield*t.stream(n,void 0,"$",r)}var Pr={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Rr(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function Eo(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 Rr("enum",Pr.VARINT,r,n,o)}function Ur(e,t,r){return Rr("message",Pr.LENGTH_DELIMITED,e,t,r)}var mt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(mt||(mt={}));var So;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(So||(So={}));(function(e){e.codec=()=>Eo(So)})(mt||(mt={}));var er;(function(e){let t;e.codec=()=>(t==null&&(t=Ur((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),mt.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{c.Type=mt.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:mt.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return Or(s,e.codec())}e.encode=r;function n(s,i){return Dr(s,e.codec(),i)}e.decode=n;function o(s,i){return Lr(s,e.codec(),i)}e.stream=o})(er||(er={}));var vo;(function(e){let t;e.codec=()=>(t==null&&(t=Ur((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),mt.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{c.Type=mt.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:mt.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return Or(s,e.codec())}e.encode=r;function n(s,i){return Dr(s,e.codec(),i)}e.decode=n;function o(s,i){return Lr(s,e.codec(),i)}e.stream=o})(vo||(vo={}));var Nr=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,r){if(mr(t),K(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),Ut(o)}update(t){return ge(this),this.iHash.update(t),this}digestInto(t){ge(this),K(t,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),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()}},Ao=(e,t,r)=>new Nr(e,t).update(r).digest();Ao.create=(e,t)=>new Nr(e,t);var Mi=(e,t)=>(e+(e>=0?t:-t)/ki)/t;function qf(e,t,r){let[[n,o],[s,i]]=t,a=Mi(i*e,r),c=Mi(-o*e,r),f=e-a*n-c*s,u=-a*o-c*i,l=f<Vt,w=u<Vt;l&&(f=-f),w&&(u=-u);let S=Ye(Math.ceil(Fn(r)/2))+_e;if(f<Vt||f>=S||u<Vt||u>=S)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:f,k2neg:w,k2:u}}function _o(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Bo(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return kt(r.lowS,"lowS"),kt(r.prehash,"prehash"),r.format!==void 0&&_o(r.format),r}var Io=class extends Error{constructor(t=""){super(t)}},Xt={Err:Io,_tlv:{encode:(e,t)=>{let{Err:r}=Xt;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=Fe(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Fe(o.length/2|128):"";return Fe(e)+s+o+t},decode(e,t){let{Err:r}=Xt,n=0;if(e<0||e>256)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 f=t.subarray(n,n+c);if(f.length!==c)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of f)i=i<<8|u;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Xt;if(e<Vt)throw new t("integer: negative integers are not allowed");let r=Fe(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}=Xt;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Ee(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Xt,o=K(e,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:f,l:u}=n.decode(2,c);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(f)}},hexFromSig(e){let{_tlv:t,_int:r}=Xt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},Vt=BigInt(0),_e=BigInt(1),ki=BigInt(2),Kr=BigInt(3),zf=BigInt(4);function Vi(e,t={}){let r=Er("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:a}=s;jt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c}=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=qi(n,o);function u(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(T,h,p){let{x:d,y:E}=h.toAffine(),I=n.toBytes(d);if(kt(p,"isCompressed"),p){u();let D=!n.isOdd(E);return bt(Hi(D),I)}else return bt(Uint8Array.of(4),I,n.toBytes(E))}function w(T){K(T,void 0,"Point");let{publicKey:h,publicKeyUncompressed:p}=f,d=T.length,E=T[0],I=T.subarray(1);if(d===h&&(E===2||E===3)){let D=n.fromBytes(I);if(!n.isValid(D))throw new Error("bad point: is not on curve, wrong x");let O=B(D),C;try{C=n.sqrt(O)}catch(W){let Y=W instanceof Error?": "+W.message:"";throw new Error("bad point: is not on curve, sqrt error"+Y)}u();let P=n.isOdd(C);return(E&1)===1!==P&&(C=n.neg(C)),{x:D,y:C}}else if(d===p&&E===4){let D=n.BYTES,O=n.fromBytes(I.subarray(0,D)),C=n.fromBytes(I.subarray(D,D*2));if(!v(O,C))throw new Error("bad point: is not on curve");return{x:O,y:C}}else throw new Error(`bad point: got length ${d}, expected compressed=${h} or uncompressed=${p}`)}let S=t.toBytes||l,m=t.fromBytes||w;function B(T){let h=n.sqr(T),p=n.mul(h,T);return n.add(n.add(p,n.mul(T,s.a)),s.b)}function v(T,h){let p=n.sqr(h),d=B(T);return n.eql(p,d)}if(!v(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let b=n.mul(n.pow(s.a,Kr),zf),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(b,A)))throw new Error("bad curve params: a or b");function y(T,h,p=!1){if(!n.isValid(h)||p&&n.is0(h))throw new Error(`bad point coordinate ${T}`);return h}function _(T){if(!(T instanceof x))throw new Error("Weierstrass Point expected")}function R(T){if(!c||!c.basises)throw new Error("no endo");return qf(T,c.basises,o.ORDER)}let M=Se((T,h)=>{let{X:p,Y:d,Z:E}=T;if(n.eql(E,n.ONE))return{x:p,y:d};let I=T.is0();h==null&&(h=I?n.ONE:n.inv(E));let D=n.mul(p,h),O=n.mul(d,h),C=n.mul(E,h);if(I)return{x:n.ZERO,y:n.ZERO};if(!n.eql(C,n.ONE))throw new Error("invZ was invalid");return{x:D,y:O}}),k=Se(T=>{if(T.is0()){if(t.allowInfinityPoint&&!n.is0(T.Y))return;throw new Error("bad point: ZERO")}let{x:h,y:p}=T.toAffine();if(!n.isValid(h)||!n.isValid(p))throw new Error("bad point: x or y not field elements");if(!v(h,p))throw new Error("bad point: equation left != right");if(!T.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function g(T,h,p,d,E){return p=new x(n.mul(p.X,T),p.Y,p.Z),h=Ge(d,h),p=Ge(E,p),h.add(p)}class x{static BASE=new x(s.Gx,s.Gy,n.ONE);static ZERO=new x(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(h,p,d){this.X=y("x",h),this.Y=y("y",p,!0),this.Z=y("z",d),Object.freeze(this)}static CURVE(){return s}static fromAffine(h){let{x:p,y:d}=h||{};if(!h||!n.isValid(p)||!n.isValid(d))throw new Error("invalid affine point");if(h instanceof x)throw new Error("projective point not allowed");return n.is0(p)&&n.is0(d)?x.ZERO:new x(p,d,n.ONE)}static fromBytes(h){let p=x.fromAffine(m(K(h,void 0,"point")));return p.assertValidity(),p}static fromHex(h){return x.fromBytes(Kt(h))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=8,p=!0){return V.createCache(this,h),p||this.multiply(Kr),this}assertValidity(){k(this)}hasEvenY(){let{y:h}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(h)}equals(h){_(h);let{X:p,Y:d,Z:E}=this,{X:I,Y:D,Z:O}=h,C=n.eql(n.mul(p,O),n.mul(I,E)),P=n.eql(n.mul(d,O),n.mul(D,E));return C&&P}negate(){return new x(this.X,n.neg(this.Y),this.Z)}double(){let{a:h,b:p}=s,d=n.mul(p,Kr),{X:E,Y:I,Z:D}=this,O=n.ZERO,C=n.ZERO,P=n.ZERO,N=n.mul(E,E),W=n.mul(I,I),Y=n.mul(D,D),q=n.mul(E,I);return q=n.add(q,q),P=n.mul(E,D),P=n.add(P,P),O=n.mul(h,P),C=n.mul(d,Y),C=n.add(O,C),O=n.sub(W,C),C=n.add(W,C),C=n.mul(O,C),O=n.mul(q,O),P=n.mul(d,P),Y=n.mul(h,Y),q=n.sub(N,Y),q=n.mul(h,q),q=n.add(q,P),P=n.add(N,N),N=n.add(P,N),N=n.add(N,Y),N=n.mul(N,q),C=n.add(C,N),Y=n.mul(I,D),Y=n.add(Y,Y),N=n.mul(Y,q),O=n.sub(O,N),P=n.mul(Y,W),P=n.add(P,P),P=n.add(P,P),new x(O,C,P)}add(h){_(h);let{X:p,Y:d,Z:E}=this,{X:I,Y:D,Z:O}=h,C=n.ZERO,P=n.ZERO,N=n.ZERO,W=s.a,Y=n.mul(s.b,Kr),q=n.mul(p,I),X=n.mul(d,D),it=n.mul(E,O),_t=n.add(p,d),Q=n.add(I,D);_t=n.mul(_t,Q),Q=n.add(q,X),_t=n.sub(_t,Q),Q=n.add(p,E);let ut=n.add(I,O);return Q=n.mul(Q,ut),ut=n.add(q,it),Q=n.sub(Q,ut),ut=n.add(d,E),C=n.add(D,O),ut=n.mul(ut,C),C=n.add(X,it),ut=n.sub(ut,C),N=n.mul(W,Q),C=n.mul(Y,it),N=n.add(C,N),C=n.sub(X,N),N=n.add(X,N),P=n.mul(C,N),X=n.add(q,q),X=n.add(X,q),it=n.mul(W,it),Q=n.mul(Y,Q),X=n.add(X,it),it=n.sub(q,it),it=n.mul(W,it),Q=n.add(Q,it),q=n.mul(X,Q),P=n.add(P,q),q=n.mul(ut,Q),C=n.mul(_t,C),C=n.sub(C,q),q=n.mul(_t,X),N=n.mul(ut,N),N=n.add(N,q),new x(C,P,N)}subtract(h){return this.add(h.negate())}is0(){return this.equals(x.ZERO)}multiply(h){let{endo:p}=t;if(!o.isValidNot0(h))throw new Error("invalid scalar: out of range");let d,E,I=D=>V.cached(this,D,O=>oe(x,O));if(p){let{k1neg:D,k1:O,k2neg:C,k2:P}=R(h),{p:N,f:W}=I(O),{p:Y,f:q}=I(P);E=W.add(q),d=g(p.beta,N,Y,D,C)}else{let{p:D,f:O}=I(h);d=D,E=O}return oe(x,[d,E])[0]}multiplyUnsafe(h){let{endo:p}=t,d=this;if(!o.isValid(h))throw new Error("invalid scalar: out of range");if(h===Vt||d.is0())return x.ZERO;if(h===_e)return d;if(V.hasCache(this))return this.multiply(h);if(p){let{k1neg:E,k1:I,k2neg:D,k2:O}=R(h),{p1:C,p2:P}=wi(x,d,I,O);return g(p.beta,C,P,E,D)}else return V.unsafe(d,h)}toAffine(h){return M(this,h)}isTorsionFree(){let{isTorsionFree:h}=t;return i===_e?!0:h?h(x,this):V.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:h}=t;return i===_e?this:h?h(x,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(h=!0){return kt(h,"isCompressed"),this.assertValidity(),S(x,this,h)}toHex(h=!0){return Nt(this.toBytes(h))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let U=o.BITS,V=new Be(x,t.endo?Math.ceil(U/2):U);return x.BASE.precompute(8),x}function Hi(e){return Uint8Array.of(e?2:3)}function qi(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Zf(e,t={}){let{Fn:r}=e,n=t.randomBytes||we,o=Object.assign(qi(e.Fp,r),{seed:Gn(r.ORDER)});function s(S){try{let m=r.fromBytes(S);return r.isValidNot0(m)}catch{return!1}}function i(S,m){let{publicKey:B,publicKeyUncompressed:v}=o;try{let b=S.length;return m===!0&&b!==B||m===!1&&b!==v?!1:!!e.fromBytes(S)}catch{return!1}}function a(S=n(o.seed)){return Wn(K(S,o.seed,"seed"),r.ORDER)}function c(S,m=!0){return e.BASE.multiply(r.fromBytes(S)).toBytes(m)}function f(S){let{secretKey:m,publicKey:B,publicKeyUncompressed:v}=o;if(!Qt(S)||"_lengths"in r&&r._lengths||m===B)return;let b=K(S,void 0,"key").length;return b===B||b===v}function u(S,m,B=!0){if(f(S)===!0)throw new Error("first arg must be private key");if(f(m)===!1)throw new Error("second arg must be public key");let v=r.fromBytes(S);return e.fromBytes(m).multiply(v).toBytes(B)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},w=Sr(a,c);return Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:w,Point:e,utils:l,lengths:o})}function zi(e,t,r={}){mr(t),jt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let n=r.randomBytes||we,o=r.hmac||((p,d)=>Ao(t,p,d)),{Fp:s,Fn:i}=e,{ORDER:a,BITS:c}=i,{keygen:f,getPublicKey:u,getSharedSecret:l,utils:w,lengths:S}=Zf(e,r),m={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},B=a*ki<s.ORDER;function v(p){let d=a>>_e;return p>d}function b(p,d){if(!i.isValidNot0(d))throw new Error(`invalid signature ${p}: out of range 1..Point.Fn.ORDER`);return d}function A(){if(B)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function y(p,d){_o(d);let E=S.signature,I=d==="compact"?E:d==="recovered"?E+1:void 0;return K(p,I)}class _{r;s;recovery;constructor(d,E,I){if(this.r=b("r",d),this.s=b("s",E),I!=null){if(A(),![0,1,2,3].includes(I))throw new Error("invalid recovery id");this.recovery=I}Object.freeze(this)}static fromBytes(d,E=m.format){y(d,E);let I;if(E==="der"){let{r:P,s:N}=Xt.toSig(K(d));return new _(P,N)}E==="recovered"&&(I=d[0],E="compact",d=d.subarray(1));let D=S.signature/2,O=d.subarray(0,D),C=d.subarray(D,D*2);return new _(i.fromBytes(O),i.fromBytes(C),I)}static fromHex(d,E){return this.fromBytes(Kt(d),E)}assertRecovery(){let{recovery:d}=this;if(d==null)throw new Error("invalid recovery id: must be present");return d}addRecoveryBit(d){return new _(this.r,this.s,d)}recoverPublicKey(d){let{r:E,s:I}=this,D=this.assertRecovery(),O=D===2||D===3?E+a:E;if(!s.isValid(O))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let C=s.toBytes(O),P=e.fromBytes(bt(Hi((D&1)===0),C)),N=i.inv(O),W=M(K(d,void 0,"msgHash")),Y=i.create(-W*N),q=i.create(I*N),X=e.BASE.multiplyUnsafe(Y).add(P.multiplyUnsafe(q));if(X.is0())throw new Error("invalid recovery: point at infinify");return X.assertValidity(),X}hasHighS(){return v(this.s)}toBytes(d=m.format){if(_o(d),d==="der")return Kt(Xt.hexFromSig(this));let{r:E,s:I}=this,D=i.toBytes(E),O=i.toBytes(I);return d==="recovered"?(A(),bt(Uint8Array.of(this.assertRecovery()),D,O)):bt(D,O)}toHex(d){return Nt(this.toBytes(d))}}let R=r.bits2int||function(d){if(d.length>8192)throw new Error("input is too large");let E=Ee(d),I=d.length*8-c;return I>0?E>>BigInt(I):E},M=r.bits2int_modN||function(d){return i.create(R(d))},k=Ye(c);function g(p){return $e("num < 2^"+c,p,Vt,k),i.toBytes(p)}function x(p,d){return K(p,void 0,"message"),d?K(t(p),void 0,"prehashed message"):p}function U(p,d,E){let{lowS:I,prehash:D,extraEntropy:O}=Bo(E,m);p=x(p,D);let C=M(p),P=i.fromBytes(d);if(!i.isValidNot0(P))throw new Error("invalid private key");let N=[g(P),g(C)];if(O!=null&&O!==!1){let X=O===!0?n(S.secretKey):O;N.push(K(X,void 0,"extraEntropy"))}let W=bt(...N),Y=C;function q(X){let it=R(X);if(!i.isValidNot0(it))return;let _t=i.inv(it),Q=e.BASE.multiply(it).toAffine(),ut=i.create(Q.x);if(ut===Vt)return;let ir=i.create(_t*i.create(Y+ut*P));if(ir===Vt)return;let ss=(Q.x===ut?0:2)|Number(Q.y&_e),is=ir;return I&&v(ir)&&(is=i.neg(ir),ss^=1),new _(ut,is,B?void 0:ss)}return{seed:W,k2sig:q}}function V(p,d,E={}){let{seed:I,k2sig:D}=U(p,d,E);return ni(t.outputLen,i.BYTES,o)(I,D).toBytes(E.format)}function T(p,d,E,I={}){let{lowS:D,prehash:O,format:C}=Bo(I,m);if(E=K(E,void 0,"publicKey"),d=x(d,O),!Qt(p)){let P=p instanceof _?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+P)}y(p,C);try{let P=_.fromBytes(p,C),N=e.fromBytes(E);if(D&&P.hasHighS())return!1;let{r:W,s:Y}=P,q=M(d),X=i.inv(Y),it=i.create(q*X),_t=i.create(W*X),Q=e.BASE.multiplyUnsafe(it).add(N.multiplyUnsafe(_t));return Q.is0()?!1:i.create(Q.x)===W}catch{return!1}}function h(p,d,E={}){let{prehash:I}=Bo(E,m);return d=x(d,I),_.fromBytes(p,"recovered").recoverPublicKey(d).toBytes()}return Object.freeze({keygen:f,getPublicKey:u,getSharedSecret:l,utils:w,lengths:S,Point:e,sign:V,verify:T,recoverPublicKey:h,Signature:_,hash:t})}var Do={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Ff={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Zi=BigInt(2);function $f(e){let t=Do.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=e*e*e%t,u=f*f*e%t,l=j(u,r,t)*u%t,w=j(l,r,t)*u%t,S=j(w,Zi,t)*f%t,m=j(S,o,t)*S%t,B=j(m,s,t)*m%t,v=j(B,a,t)*B%t,b=j(v,c,t)*v%t,A=j(b,a,t)*B%t,y=j(A,r,t)*u%t,_=j(y,i,t)*m%t,R=j(_,n,t)*f%t,M=j(R,Zi,t);if(!Co.eql(Co.sqr(M),e))throw new Error("Cannot find square root");return M}var Co=ve(Do.p,{sqrt:$f}),Yf=Vi(Do,{Fp:Co,endo:Ff}),Ie=zi(Yf,Js);function Fi(e,t,r,n){let o=Me.digest(r instanceof Uint8Array?r:r.subarray());if(_r(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ie.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new We(String(s))});try{return n?.signal?.throwIfAborted(),Ie.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new We(String(s))}}var Mr=class{type="secp256k1";raw;_key;constructor(t){this._key=Yi(t),this.raw=$i(this._key)}toMultihash(){return vt.digest(xe(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return et.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:xt(this.raw,t.raw)}verify(t,r,n){return Fi(this._key,r,t,n)}};function ji(e){return new Mr(e)}function $i(e){return Ie.Point.fromBytes(e).toBytes()}function Yi(e){try{return Ie.Point.fromBytes(e),e}catch(t){throw new cr(String(t))}}function Gi(e){let{Type:t,Data:r}=er.decode(e.digest),n=r??new Uint8Array;switch(t){case mt.Ed25519:return Di(n);case mt.secp256k1:return ji(n);case mt.ECDSA:return Ns(n);default:throw new Le}}function xe(e){return er.encode({Type:mt[e.type],Data:e.raw})}var Wi=Symbol.for("nodejs.util.inspect.custom"),jf=114,rr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[on]=!0;toString(){return this.string==null&&(this.string=et.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ct.createV1(jf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return xt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return xt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Wi](){return`PeerId(${this.toString()})`}},kr=class extends rr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Vr=class extends rr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Hr=class extends rr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Gf=2336,nr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=vt.digest(Et(this.url))}[Wi](){return`PeerId(${this.url})`}[on]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ct.createV1(Gf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=rt(t)),t.toString()===this.toString())}};var Wf=114,Xi=2336;function Qi(e,t){let r;if(e.charAt(0)==="1"||e.charAt(0)==="Q")r=Ne(et.decode(`z${e}`));else{if(e.startsWith("k51qzi5uqu5")||e.startsWith("kzwfwjn5ji4")||e.startsWith("k2k4r8")||e.startsWith("bafz"))return Xf(ct.parse(e));if(t==null)throw new It('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=Ne(t.decode(e))}return Ji(r)}function Ji(e){if(Jf(e))return new kr({multihash:e});if(Qf(e))try{let t=Gi(e);if(t.type==="Ed25519")return new Vr({multihash:e,publicKey:t});if(t.type==="secp256k1")return new Hr({multihash:e,publicKey:t})}catch{let r=rt(e.digest);return new nr(new URL(r))}throw new fr("Supplied PeerID Multihash is invalid")}function Xf(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==Wf&&e.code!==Xi)throw new ar("Supplied PeerID CID is invalid");if(e.code===Xi){let t=rt(e.multihash.digest);return new nr(new URL(t))}return Ji(e.multihash)}function Qf(e){return e.code===vt.code}function Jf(e){return e.code===Me.code}var ft=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Ht=class extends Error{static name="ValidationError";name="ValidationError"},qr=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},zr=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Zr=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",f=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let w=Number.parseInt(l,t);if(!Number.isNaN(w))return w});if(u===void 0)break;if(s*=t,s+=u,s>f||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=t(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var tu=45,eu=15,Fr=new Zr;function tc(e){if(!(e.length>eu))return Fr.new(e).parseWith(()=>Fr.readIPv4Addr())}function ec(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>tu))return Fr.new(e).parseWith(()=>Fr.readIPv6Addr())}function $r(e){return!!tc(e)}function rc(e){return!!ec(e)}function Oo(e){return t=>rt(t,e)}function Lo(e){return t=>Et(t,e)}function Ce(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function ce(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function nc(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=Et(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=ce(n);return Pt([r,o],r.length+o.length)}function oc(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=Zt.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=ce(n);return Pt([r,o],r.length+o.length)}function Po(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=rt(t,"base32"),o=Ce(r);return`${n}:${o}`}var Ro=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},sc=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let s=$r(r[n]),i;s&&(i=Ro(r[n]),r[n]=rt(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,rt(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},ic=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(".")},cc=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 ac(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 To=Object.values(ke).map(e=>e.decoder),ru=(function(){let e=To[0].or(To[1]);return To.slice(2).forEach(t=>e=e.or(t)),e})();function fc(e){return ru.decode(e)}function uc(e){return t=>e.encoder.encode(t)}function nu(e){if(parseInt(e).toString()!==e)throw new Ht("Value must be an integer")}function ou(e){if(e<0)throw new Ht("Value must be a positive integer, or zero")}function su(e){return t=>{if(t>e)throw new Ht(`Value must be smaller than or equal to ${e}`)}}function iu(...e){return t=>{for(let r of e)r(t)}}var or=iu(nu,ou,su(65535));var st=-1,Uo=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 zr(`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 Uo,Eu=[{code:4,name:"ip4",size:32,valueToBytes:Ro,bytesToValue:ic,validate:e=>{if(!$r(e))throw new Ht(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ce,bytesToValue:Ce,validate:or},{code:273,name:"udp",size:16,valueToBytes:ce,bytesToValue:Ce,validate:or},{code:33,name:"dccp",size:16,valueToBytes:ce,bytesToValue:Ce,validate:or},{code:41,name:"ip6",size:128,valueToBytes:sc,bytesToValue:cc,stringToValue:ac,validate:e=>{if(!rc(e))throw new Ht(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:st},{code:43,name:"ipcidr",size:8,bytesToValue:Oo("base10"),valueToBytes:Lo("base10")},{code:53,name:"dns",size:st},{code:54,name:"dns4",size:st},{code:55,name:"dns6",size:st},{code:56,name:"dnsaddr",size:st},{code:132,name:"sctp",size:16,valueToBytes:ce,bytesToValue:Ce,validate:or},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:st,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:st,bytesToValue:Oo("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?Lo("base58btc")(e):ct.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Po,valueToBytes:nc},{code:445,name:"onion3",size:296,bytesToValue:Po,valueToBytes:oc},{code:446,name:"garlic64",size:st},{code:447,name:"garlic32",size:st},{code:448,name:"tls"},{code:449,name:"sni",size:st},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:st,bytesToValue:uc(wn),valueToBytes:fc},{code:480,name:"http"},{code:481,name:"http-path",size:st,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:st}];Eu.forEach(e=>{qt.addProtocol(e)});function lc(e){let t=[],r=0;for(;r<e.length;){let n=fo(e,r),o=qt.getProtocol(n),s=Tt(n),i=Su(o,e,r+s),a=0;i>0&&o.size===st&&(a=Tt(i));let c=s+a+i,f={code:n,name:o.name,bytes:e.subarray(r,r+c)};if(i>0){let u=r+s+a,l=e.subarray(u,u+i);f.value=o.bytesToValue?.(l)??rt(l)}t.push(f),r+=c}return t}function dc(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=qt.getProtocol(n.code),s=Tt(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??Et(n.value),a=i.byteLength,o.size===st&&(c=Tt(a)));let f=new Uint8Array(s+c+a),u=0;Xe(n.code,f,u),u+=s,i!=null&&(o.size===st&&(Xe(a,f,u),u+=c),f.set(i,u)),n.bytes=f}r.push(n.bytes),t+=n.bytes.byteLength}return Pt(r,t)}function hc(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 f={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new ft(`Component ${o} was missing value`);f.value=c.stringToValue?.(n)??n}t.push(f),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new ft("Incomplete multiaddr");return t}function pc(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 Su(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:fo(t,r)}var vu=Symbol.for("nodejs.util.inspect.custom"),Qo=Symbol.for("@multiformats/multiaddr");function Au(e){if(e==null&&(e="/"),mc(e))return e.getComponents();if(e instanceof Uint8Array)return lc(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),hc(e);if(Array.isArray(e))return e;throw new ft("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Xr=class e{[Qo]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=Au(t),r.validate!==!1&&Bu(this)}get bytes(){return this.#r==null&&(this.#r=dc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=pc(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 qr(`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 xt(this.bytes,t.bytes)}[vu](){return`Multiaddr(${this.toString()})`}};function Bu(e){e.getComponents().forEach(t=>{let r=qt.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function mc(e){return!!e?.[Qo]}function bc(e){return new Xr(e)}var F=e=>({match:t=>{let r=t[0];return r==null||r.code!==e||r.value!=null?!1:t.slice(1)}}),L=(e,t)=>({match:r=>{let n=r[0];return n?.code!==e||n.value==null||t!=null&&n.value!==t?!1:r.slice(1)}}),yc=e=>({match:t=>e.match(t)===!1?t:!1}),H=e=>({match:t=>{let r=e.match(t);return r===!1?t:r}}),ht=(...e)=>({match:t=>{let r;for(let n of e){let o=n.match(t);o!==!1&&(r==null||o.length<r.length)&&(r=o)}return r??!1}}),Z=(...e)=>({match:t=>{for(let r of e){let n=r.match(t);if(n===!1)return!1;t=n}return t}});function $(...e){function t(o){if(o==null)return!1;let s=o.getComponents();for(let i of e){let a=i.match(s);if(a===!1)return!1;s=a}return s}function r(o){return t(o)!==!1}function n(o){let s=t(o);return s===!1?!1:s.length===0}return{matchers:e,matches:r,exactMatch:n}}var _u=L(421),_m=$(_u),Jr=L(54),tn=L(55),en=L(56),ts=L(53),Im=$(Jr,H(L(421))),Cm=$(tn,H(L(421))),Dm=$(en,H(L(421))),Tm=$(ht(ts,en,Jr,tn),H(L(421))),xc=Z(L(4),H(L(43))),gc=Z(H(L(42)),L(41),H(L(43))),es=ht(xc,gc),ue=ht(es,ts,Jr,tn,en),Om=$(ht(es,Z(ht(ts,en,Jr,tn),H(L(421))))),Lm=$(xc),Pm=$(gc),Rm=$(es),rs=Z(ue,L(6)),sr=Z(ue,L(273)),Um=$(Z(rs,H(L(421)))),Nm=$(sr),ns=Z(sr,F(460),H(L(421))),rn=Z(sr,F(461),H(L(421))),Iu=ht(ns,rn),Km=$(ns),Mm=$(rn),Jo=ht(ue,rs,sr,ns,rn),wc=ht(Z(Jo,F(477),H(L(421)))),km=$(wc),Ec=ht(Z(Jo,F(478),H(L(421))),Z(Jo,F(448),H(L(449)),F(477),H(L(421)))),Vm=$(Ec),Sc=Z(sr,F(280),H(L(466)),H(L(466)),H(L(421))),Hm=$(Sc),vc=Z(rn,F(465),H(L(466)),H(L(466)),H(L(421))),qm=$(vc),Qr=ht(wc,Ec,Z(rs,H(L(421))),Z(Iu,H(L(421))),Z(ue,H(L(421))),Sc,vc,L(421)),Ac=$(Qr),Cu=Z(H(Qr),F(290),yc(F(281)),H(L(421))),zm=$(Cu),Du=ht(Z(Qr,F(290),F(281),H(L(421))),Z(Qr,F(281),H(L(421))),Z(F(281),H(L(421)))),Zm=$(Du),Tu=ht(Z(ue,L(6),F(480),H(L(421))),Z(ue,F(480),H(L(421)))),Fm=$(Tu),Ou=Z(ue,ht(Z(L(6,"443"),F(480)),Z(L(6),F(443)),Z(L(6),F(448),F(480)),Z(F(448),F(480)),F(448),F(443)),H(L(421))),$m=$(Ou),Lu=ht(Z(L(777),H(L(421)))),Ym=$(Lu),Pu=ht(Z(L(400),H(L(421)))),jm=$(Pu);var Ru="bootstrap",Uu=50,Nu=1e3,os=class extends ur{static tag="bootstrap";log;timer;list;timeout;components;_init;constructor(t,r={list:[]}){if(r.list==null||r.list.length===0)throw new Error("Bootstrap requires a list of peer addresses");super(),this.components=t,this.log=t.logger.forComponent("libp2p:bootstrap"),this.timeout=r.timeout??Nu,this.list=r.list.map(n=>bc(n)).filter(n=>Ac.matches(n)?n.getComponents().findLast(s=>s.code===421)?.value==null?(this.log.error("invalid bootstrap multiaddr without peer id"),!1):!0:(this.log.error("invalid multiaddr %a",n),!1)).map(n=>({id:Qi(n.getComponents().findLast(o=>o.code===421)?.value??""),multiaddrs:[n]})),this._init=r}[cs]=this;[Symbol.toStringTag]="@libp2p/bootstrap";[as]=["@libp2p/peer-discovery"];isStarted(){return!!this.timer}start(){this.isStarted()||(this.log("Starting bootstrap node discovery, discovering peers after %s ms",this.timeout),this.timer=setTimeout(()=>{this._discoverBootstrapPeers().catch(t=>{this.log.error("failed to discover bootstrap peers - %e",t)})},this.timeout))}async _discoverBootstrapPeers(){if(this.timer!=null)for(let t of this.list){if(await this.components.peerStore.merge(t.id,{tags:{[this._init.tagName??Ru]:{value:this._init.tagValue??Uu,ttl:this._init.tagTTL}},multiaddrs:t.multiaddrs}),this.timer==null)return;this.safeDispatchEvent("peer",{detail:t}),this.components.connectionManager.openConnection(t.id).catch(r=>{this.log.error("could not dial bootstrap peer %p - %e",t.id,r)})}}stop(){this.timer!=null&&clearTimeout(this.timer),this.timer=void 0}};function Ku(e){return t=>new os(t,e)}return Dc(Mu);})();
2
+ "use strict";var Libp2PBootstrap=(()=>{var on=Object.defineProperty;var _c=Object.getOwnPropertyDescriptor;var Ic=Object.getOwnPropertyNames;var Cc=Object.prototype.hasOwnProperty;var yt=(e,t)=>{for(var r in t)on(e,r,{get:t[r],enumerable:!0})},Dc=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ic(t))!Cc.call(e,o)&&o!==r&&on(e,o,{get:()=>t[o],enumerable:!(n=_c(t,o))||n.enumerable});return e};var Tc=e=>Dc(on({},"__esModule",{value:!0}),e);var Mu={};yt(Mu,{bootstrap:()=>Ku});var It=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},cr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var ar=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},fr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Le=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var as=Symbol.for("@libp2p/peer-discovery");var sn=Symbol.for("@libp2p/peer-id");var ur=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){super.addEventListener(t,r,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}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))}dispatchEvent(t){let r=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),r}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var fs=Symbol.for("@libp2p/service-capabilities"),Zu=Symbol.for("@libp2p/service-dependencies");var ln={};yt(ln,{base58btc:()=>et,base58flickr:()=>Kc});var bl=new Uint8Array(0);function us(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 Ot(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function ls(e){return new TextEncoder().encode(e)}function ds(e){return new TextDecoder().decode(e)}function Oc(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),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var B=0,v=0,b=0,A=m.length;b!==A&&m[b]===0;)b++,B++;for(var y=(A-b)*u+1>>>0,_=new Uint8Array(y);b!==A;){for(var R=m[b],M=0,k=y-1;(R!==0||M<v)&&k!==-1;k--,M++)R+=256*_[k]>>>0,_[k]=R%a>>>0,R=R/a>>>0;if(R!==0)throw new Error("Non-zero carry");v=M,b++}for(var g=y-v;g!==y&&_[g]===0;)g++;for(var x=c.repeat(B);g<y;++g)x+=e.charAt(_[g]);return x}function w(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var B=0;if(m[B]!==" "){for(var v=0,b=0;m[B]===c;)v++,B++;for(var A=(m.length-B)*f+1>>>0,y=new Uint8Array(A);m[B];){var _=r[m.charCodeAt(B)];if(_===255)return;for(var R=0,M=A-1;(_!==0||R<b)&&M!==-1;M--,R++)_+=a*y[M]>>>0,y[M]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");b=R,B++}if(m[B]!==" "){for(var k=A-b;k!==A&&y[k]===0;)k++;for(var g=new Uint8Array(v+(A-k)),x=v;k!==A;)g[x++]=y[k++];return g}}}function S(m){var B=w(m);if(B)return B;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:w,decode:S}}var Lc=Oc,Pc=Lc,ps=Pc;var cn=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")}},an=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 ms(this,t)}},fn=class{decoders;constructor(t){this.decoders=t}or(t){return ms(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 ms(e,t){return new fn({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var un=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 cn(t,r,n),this.decoder=new an(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ue({name:e,prefix:t,encode:r,decode:n}){return new un(e,t,r,n)}function Zt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=ps(r,e);return ue({prefix:t,name:e,encode:n,decode:s=>Ot(o(s))})}function Rc(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let f=0;f<o;++f){let u=t[e[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Uc(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 Nc(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function J({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Nc(n);return ue({prefix:t,name:e,encode(s){return Uc(s,n,r)},decode(s){return Rc(s,o,r,e)}})}var et=Zt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Kc=Zt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var dn={};yt(dn,{base32:()=>Ft,base32hex:()=>Hc,base32hexpad:()=>zc,base32hexpadupper:()=>Zc,base32hexupper:()=>qc,base32pad:()=>kc,base32padupper:()=>Vc,base32upper:()=>Mc,base32z:()=>Fc});var Ft=J({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Mc=J({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),kc=J({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Vc=J({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Hc=J({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),qc=J({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),zc=J({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Zc=J({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Fc=J({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var hn={};yt(hn,{base36:()=>Pe,base36upper:()=>$c});var Pe=Zt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),$c=Zt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Yc=xs,bs=128,jc=127,Gc=~jc,Wc=Math.pow(2,31);function xs(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Wc;)t[r++]=e&255|bs,e/=128;for(;e&Gc;)t[r++]=e&255|bs,e>>>=7;return t[r]=e|0,xs.bytes=r-n+1,t}var Xc=pn,Qc=128,ys=127;function pn(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw pn.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&ys)<<o:(i&ys)*Math.pow(2,o),o+=7}while(i>=Qc);return pn.bytes=s-n,r}var Jc=Math.pow(2,7),ta=Math.pow(2,14),ea=Math.pow(2,21),ra=Math.pow(2,28),na=Math.pow(2,35),oa=Math.pow(2,42),sa=Math.pow(2,49),ia=Math.pow(2,56),ca=Math.pow(2,63),aa=function(e){return e<Jc?1:e<ta?2:e<ea?3:e<ra?4:e<na?5:e<oa?6:e<sa?7:e<ia?8:e<ca?9:10},fa={encode:Yc,decode:Xc,encodingLength:aa},ua=fa,Re=ua;function Ue(e,t=0){return[Re.decode(e,t),Re.decode.bytes]}function le(e,t,r=0){return Re.encode(e,t,r),t}function de(e){return Re.encodingLength(e)}function pe(e,t){let r=t.byteLength,n=de(e),o=n+de(r),s=new Uint8Array(o+r);return le(e,s,0),le(r,s,n),s.set(t,o),new he(e,r,t,s)}function Ne(e){let t=Ot(e),[r,n]=Ue(t),[o,s]=Ue(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new he(r,o,i,t)}function gs(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&us(e.bytes,r.bytes)}}var he=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function ws(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return da(r,mn(e),t??et.encoder);default:return ha(r,mn(e),t??Ft.encoder)}}var Es=new WeakMap;function mn(e){let t=Es.get(e);if(t==null){let r=new Map;return Es.set(e,r),r}return t}var ct=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==Ke)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==pa)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=pe(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&&gs(t.multihash,n.multihash)}toString(t){return ws(this,t)}toJSON(){return{"/":ws(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??Ss(n,o,s.bytes))}else if(r[ma]===!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!==Ke)throw new Error(`Version 0 CID must use dag-pb (code: ${Ke}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Ss(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Ke,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=Ot(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 he(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,w]=Ue(t.subarray(r));return r+=w,l},o=n(),s=Ke;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),f=r+c,u=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(t,r){let[n,o]=la(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 mn(s).set(n,t),s}};function la(e,t){switch(e[0]){case"Q":{let r=t??et;return[et.prefix,r.decode(`${et.prefix}${e}`)]}case et.prefix:{let r=t??et;return[et.prefix,r.decode(e)]}case Ft.prefix:{let r=t??Ft;return[Ft.prefix,r.decode(e)]}case Pe.prefix:{let r=t??Pe;return[Pe.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 da(e,t,r){let{prefix:n}=r;if(n!==et.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 ha(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 Ke=112,pa=18;function Ss(e,t,r){let n=de(e),o=n+de(t),s=new Uint8Array(o+r.byteLength);return le(e,s,0),le(t,s,n),s.set(r,o),s}var ma=Symbol.for("@ipld/js-cid/CID");var bn={};yt(bn,{identity:()=>vt});var vs=0,ba="identity",As=Ot;function ya(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 pe(vs,As(e))}var vt={code:vs,name:ba,encode:As,digest:ya};function xt(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 Lt(e=0){return new Uint8Array(e)}function gt(e=0){return new Uint8Array(e)}function Pt(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=gt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var _s=Symbol.for("@achingbrain/uint8arraylist");function Bs(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 dr(e){return!!e?.[_s]}var wt=class e{bufs;length;[_s]=!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(dr(n))r+=n.byteLength,this.bufs.push(...n.bufs);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(dr(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=Bs(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Bs(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(dr(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 Pt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Pt(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let f=t>=a&&t<c,u=r>a&&r<=c;if(f&&u){if(t===a&&r===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(r-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!dr(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,f=n.byteLength-1,u;for(let l=r;l<=c;l+=u){u=0;for(let w=f;w>=0;w--){let S=this.get(l+w);if(n[w]!==S){u=Math.max(1,w-a[S]);break}}if(u===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=gt(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=Lt(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=Lt(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=Lt(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=gt(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=Lt(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=Lt(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=Lt(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=Lt(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=Lt(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(!xt(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 yn={};yt(yn,{base10:()=>xa});var xa=Zt({prefix:"9",name:"base10",alphabet:"0123456789"});var xn={};yt(xn,{base16:()=>ga,base16upper:()=>wa});var ga=J({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),wa=J({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var gn={};yt(gn,{base2:()=>Ea});var Ea=J({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var wn={};yt(wn,{base256emoji:()=>_a});var Is=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}"),Sa=Is.reduce((e,t,r)=>(e[r]=t,e),[]),va=Is.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Aa(e){return e.reduce((t,r)=>(t+=Sa[r],t),"")}function Ba(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=va[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var _a=ue({prefix:"\u{1F680}",name:"base256emoji",encode:Aa,decode:Ba});var Sn={};yt(Sn,{base64:()=>Ia,base64pad:()=>Ca,base64url:()=>En,base64urlpad:()=>Da});var Ia=J({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ca=J({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),En=J({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Da=J({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var vn={};yt(vn,{base8:()=>Ta});var Ta=J({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var An={};yt(An,{identity:()=>Oa});var Oa=ue({prefix:"\0",name:"identity",encode:e=>ds(e),decode:e=>ls(e)});var Jl=new TextEncoder,td=new TextDecoder;var In={};yt(In,{sha256:()=>Me,sha512:()=>Ua});var Ra=20;function _n({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Bn(e,t,r,n,o)}var Bn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Ra,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?Cs(n,this.code,r?.truncate):n.then(o=>Cs(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Cs(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 pe(t,e)}function Ts(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Me=_n({name:"sha2-256",code:18,encode:Ts("SHA-256")}),Ua=_n({name:"sha2-512",code:19,encode:Ts("SHA-512")});var ke={...An,...gn,...vn,...yn,...xn,...dn,...hn,...ln,...Sn,...wn},dd={...In,...bn};function Ls(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Os=Ls("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Cn=Ls("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=gt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Na={utf8:Os,"utf-8":Os,hex:ke.base16,latin1:Cn,ascii:Cn,binary:Cn,...ke},hr=Na;function Et(e,t="utf8"){let r=hr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function rt(e,t="utf8"){let r=hr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Ka=parseInt("11111",2),Dn=parseInt("10000000",2),Ma=parseInt("01111111",2),Ps={0:Ve,1:Ve,2:ka,3:qa,4:za,5:Ha,6:Va,16:Ve,22:Ve,48:Ve};function Tn(e,t={offset:0}){let r=e[t.offset]&Ka;if(t.offset++,Ps[r]!=null)return Ps[r](e,t);throw new Error("No decoder for tag "+r)}function He(e,t){let r=0;if((e[t.offset]&Dn)===Dn){let n=e[t.offset]&Ma,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 Ve(e,t){He(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Tn(e,t);if(n===null)break;r.push(n)}return r}function ka(e,t){let r=He(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 Va(e,t){let r=He(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let f=e[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let u=0;for(let l=0;l<c.length;l++)u+=c[l]<<l*7;a+=`.${u}`,c=[]}}return a}function Ha(e,t){return t.offset++,null}function qa(e,t){let r=He(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 za(e,t){let r=He(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Za(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new wt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function On(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Za(e.byteLength);return new wt(Uint8Array.from([t.byteLength|Dn]),t)}function Rs(e){let t=new wt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new wt(Uint8Array.from([2]),On(t),t)}function Us(e){let t=Uint8Array.from([0]),r=new wt(t,e);return new wt(Uint8Array.from([3]),On(r),r)}function pr(e,t=48){let r=new wt;for(let n of e)r.append(n);return new wt(Uint8Array.from([t]),On(r),r)}async function Ns(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),s}var Fa=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),$a=Uint8Array.from([6,5,43,129,4,0,34]),Ya=Uint8Array.from([6,5,43,129,4,0,35]),ja={ext:!0,kty:"EC",crv:"P-256"},Ga={ext:!0,kty:"EC",crv:"P-384"},Wa={ext:!0,kty:"EC",crv:"P-521"},Ln=32,Pn=48,Rn=66;function Ks(e){let t=Tn(e);return Ms(t)}function Ms(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Ln*2+1)return n=rt(t.subarray(r,r+Ln),"base64url"),o=rt(t.subarray(r+Ln),"base64url"),new be({...ja,key_ops:["verify"],x:n,y:o});if(t.byteLength===Pn*2+1)return n=rt(t.subarray(r,r+Pn),"base64url"),o=rt(t.subarray(r+Pn),"base64url"),new be({...Ga,key_ops:["verify"],x:n,y:o});if(t.byteLength===Rn*2+1)return n=rt(t.subarray(r,r+Rn),"base64url"),o=rt(t.subarray(r+Rn),"base64url"),new be({...Wa,key_ops:["verify"],x:n,y:o});throw new It(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function ks(e){return pr([Rs(Uint8Array.from([1])),pr([Xa(e.crv)],160),pr([Us(new wt(Uint8Array.from([4]),Et(e.x??"","base64url"),Et(e.y??"","base64url")))],161)]).subarray()}function Xa(e){if(e==="P-256")return Fa;if(e==="P-384")return $a;if(e==="P-521")return Ya;throw new It(`Invalid curve ${e}`)}var be=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=ks(this.jwk)),this._raw}toMultihash(){return vt.digest(ye(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return et.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:xt(this.raw,t.raw)}async verify(t,r,n){return Ns(this.jwk,r,t,n)}};function Jt(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Ct(e,t=""){if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new Error(`${r}expected integer >= 0, got ${e}`)}}function K(e,t,r=""){let n=Jt(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}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return e}function mr(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash must wrapped by utils.createHasher");Ct(e.outputLen),Ct(e.blockLen)}function xe(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 Hs(e,t){K(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function Ut(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function br(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function At(e,t){return e<<32-t|e>>>t}var qs=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Qa=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Nt(e){if(K(e),qs)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Qa[e[r]];return t}var Rt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Vs(e){if(e>=Rt._0&&e<=Rt._9)return e-Rt._0;if(e>=Rt.A&&e<=Rt.F)return e-(Rt.A-10);if(e>=Rt.a&&e<=Rt.f)return e-(Rt.a-10)}function Kt(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(qs)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("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=Vs(e.charCodeAt(s)),a=Vs(e.charCodeAt(s+1));if(i===void 0||a===void 0){let c=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function bt(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];K(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 Un(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.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function ge(e=32){let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(e))}var Nn=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function zs(e,t,r){return e&t^~e&r}function Zs(e,t,r){return e&t^e&r^t&r}var qe=class{blockLen;outputLen;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=br(this.buffer)}update(t){xe(this),K(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=br(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){xe(this),Hs(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Ut(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=br(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)a.setUint32(4*l,u[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()}},Mt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var at=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var yr=BigInt(4294967295),Fs=BigInt(32);function Ja(e,t=!1){return t?{h:Number(e&yr),l:Number(e>>Fs&yr)}:{h:Number(e>>Fs&yr)|0,l:Number(e&yr)|0}}function $s(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}=Ja(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Kn=(e,t,r)=>e>>>r,Mn=(e,t,r)=>e<<32-r|t>>>r,te=(e,t,r)=>e>>>r|t<<32-r,ee=(e,t,r)=>e<<32-r|t>>>r,ze=(e,t,r)=>e<<64-r|t>>>r-32,Ze=(e,t,r)=>e>>>r-32|t<<64-r;function Dt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Ys=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),js=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Gs=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Ws=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Xs=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Qs=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var ef=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]),$t=new Uint32Array(64),kn=class extends qe{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)$t[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let w=$t[l-15],S=$t[l-2],m=At(w,7)^At(w,18)^w>>>3,B=At(S,17)^At(S,19)^S>>>10;$t[l]=B+$t[l-7]+m+$t[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:f,H:u}=this;for(let l=0;l<64;l++){let w=At(a,6)^At(a,11)^At(a,25),S=u+w+zs(a,c,f)+ef[l]+$t[l]|0,B=(At(n,2)^At(n,13)^At(n,22))+Zs(n,o,s)|0;u=f,f=c,c=a,a=i+S|0,i=s,s=o,o=n,n=S+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,f=f+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,c,f,u)}roundClean(){Ut($t)}destroy(){this.set(0,0,0,0,0,0,0,0),Ut(this.buffer)}},Vn=class extends kn{A=Mt[0]|0;B=Mt[1]|0;C=Mt[2]|0;D=Mt[3]|0;E=Mt[4]|0;F=Mt[5]|0;G=Mt[6]|0;H=Mt[7]|0;constructor(){super(32)}};var Js=$s(["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))),rf=Js[0],nf=Js[1],Yt=new Uint32Array(80),jt=new Uint32Array(80),Hn=class extends qe{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:f,El:u,Fh:l,Fl:w,Gh:S,Gl:m,Hh:B,Hl:v}=this;return[t,r,n,o,s,i,a,c,f,u,l,w,S,m,B,v]}set(t,r,n,o,s,i,a,c,f,u,l,w,S,m,B,v){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=w|0,this.Gh=S|0,this.Gl=m|0,this.Hh=B|0,this.Hl=v|0}process(t,r){for(let y=0;y<16;y++,r+=4)Yt[y]=t.getUint32(r),jt[y]=t.getUint32(r+=4);for(let y=16;y<80;y++){let _=Yt[y-15]|0,R=jt[y-15]|0,M=te(_,R,1)^te(_,R,8)^Kn(_,R,7),k=ee(_,R,1)^ee(_,R,8)^Mn(_,R,7),g=Yt[y-2]|0,x=jt[y-2]|0,U=te(g,x,19)^ze(g,x,61)^Kn(g,x,6),V=ee(g,x,19)^Ze(g,x,61)^Mn(g,x,6),T=Gs(k,V,jt[y-7],jt[y-16]),h=Ws(T,M,U,Yt[y-7],Yt[y-16]);Yt[y]=h|0,jt[y]=T|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:w,Fh:S,Fl:m,Gh:B,Gl:v,Hh:b,Hl:A}=this;for(let y=0;y<80;y++){let _=te(l,w,14)^te(l,w,18)^ze(l,w,41),R=ee(l,w,14)^ee(l,w,18)^Ze(l,w,41),M=l&S^~l&B,k=w&m^~w&v,g=Xs(A,R,k,nf[y],jt[y]),x=Qs(g,b,_,M,rf[y],Yt[y]),U=g|0,V=te(n,o,28)^ze(n,o,34)^ze(n,o,39),T=ee(n,o,28)^Ze(n,o,34)^Ze(n,o,39),h=n&s^n&a^s&a,p=o&i^o&c^i&c;b=B|0,A=v|0,B=S|0,v=m|0,S=l|0,m=w|0,{h:l,l:w}=Dt(f|0,u|0,x|0,U|0),f=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let d=Ys(U,T,p);n=js(d,x,V,h),o=d|0}({h:n,l:o}=Dt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Dt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Dt(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=Dt(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:w}=Dt(this.Eh|0,this.El|0,l|0,w|0),{h:S,l:m}=Dt(this.Fh|0,this.Fl|0,S|0,m|0),{h:B,l:v}=Dt(this.Gh|0,this.Gl|0,B|0,v|0),{h:b,l:A}=Dt(this.Hh|0,this.Hl|0,b|0,A|0),this.set(n,o,s,i,a,c,f,u,l,w,S,m,B,v,b,A)}roundClean(){Ut(Yt,jt)}destroy(){Ut(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},qn=class extends Hn{Ah=at[0]|0;Al=at[1]|0;Bh=at[2]|0;Bl=at[3]|0;Ch=at[4]|0;Cl=at[5]|0;Dh=at[6]|0;Dl=at[7]|0;Eh=at[8]|0;El=at[9]|0;Fh=at[10]|0;Fl=at[11]|0;Gh=at[12]|0;Gl=at[13]|0;Hh=at[14]|0;Hl=at[15]|0;constructor(){super(64)}};var ti=Un(()=>new Vn,Nn(1));var ei=Un(()=>new qn,Nn(3));var Zn=BigInt(0),zn=BigInt(1);function kt(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function ri(e){if(typeof e=="bigint"){if(!xr(e))throw new Error("positive bigint expected, got "+e)}else Ct(e);return e}function Fe(e){let t=ri(e).toString(16);return t.length&1?"0"+t:t}function ni(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Zn:BigInt("0x"+e)}function we(e){return ni(Nt(e))}function re(e){return ni(Nt(wr(K(e)).reverse()))}function gr(e,t){Ct(t),e=ri(e);let r=Kt(e.toString(16).padStart(t*2,"0"));if(r.length!==t)throw new Error("number too large");return r}function Fn(e,t){return gr(e,t).reverse()}function wr(e){return Uint8Array.from(e)}var xr=e=>typeof e=="bigint"&&Zn<=e;function of(e,t,r){return xr(e)&&xr(t)&&xr(r)&&t<=e&&e<r}function $e(e,t,r,n){if(!of(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function $n(e){let t;for(t=0;e>Zn;e>>=zn,t+=1);return t}var Ye=e=>(zn<<BigInt(e))-zn;function oi(e,t,r){if(Ct(e,"hashLen"),Ct(t,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");let n=v=>new Uint8Array(v),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(e),f=n(e),u=0,l=()=>{c.fill(1),f.fill(0),u=0},w=(...v)=>r(f,bt(c,...v)),S=(v=o)=>{f=w(s,v),c=w(),v.length!==0&&(f=w(i,v),c=w())},m=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let v=0,b=[];for(;v<t;){c=w();let A=c.slice();b.push(A),v+=c.length}return bt(...b)};return(v,b)=>{l(),S(v);let A;for(;!(A=b(m()));)S();return l(),A}}function Gt(e,t={},r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(s,i,a){let c=e[s];if(a&&c===void 0)return;let f=typeof c;if(f!==i||c===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${f}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(t,!1),o(r,!0)}function Ee(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var pt=BigInt(0),nt=BigInt(1),ne=BigInt(2),ci=BigInt(3),ai=BigInt(4),fi=BigInt(5),sf=BigInt(7),ui=BigInt(8),cf=BigInt(9),li=BigInt(16);function tt(e,t){let r=e%t;return r>=pt?r:t+r}function j(e,t,r){let n=e;for(;t-- >pt;)n*=n,n%=r;return n}function si(e,t){if(e===pt)throw new Error("invert: expected non-zero number");if(t<=pt)throw new Error("invert: expected positive modulus, got "+t);let r=tt(e,t),n=t,o=pt,s=nt,i=nt,a=pt;for(;r!==pt;){let f=n/r,u=n%r,l=o-i*f,w=s-a*f;n=r,r=u,o=i,s=a,i=l,a=w}if(n!==nt)throw new Error("invert: does not exist");return tt(o,t)}function jn(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function di(e,t){let r=(e.ORDER+nt)/ai,n=e.pow(t,r);return jn(e,n,t),n}function af(e,t){let r=(e.ORDER-fi)/ui,n=e.mul(t,ne),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,ne),o),a=e.mul(s,e.sub(i,e.ONE));return jn(e,a,t),a}function ff(e){let t=Se(e),r=hi(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+sf)/li;return(a,c)=>{let f=a.pow(c,i),u=a.mul(f,n),l=a.mul(f,o),w=a.mul(f,s),S=a.eql(a.sqr(u),c),m=a.eql(a.sqr(l),c);f=a.cmov(f,u,S),u=a.cmov(w,l,m);let B=a.eql(a.sqr(u),c),v=a.cmov(f,u,B);return jn(a,v,c),v}}function hi(e){if(e<ci)throw new Error("sqrt is not defined for small field");let t=e-nt,r=0;for(;t%ne===pt;)t/=ne,r++;let n=ne,o=Se(e);for(;ii(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return di;let s=o.pow(n,t),i=(t+nt)/ne;return function(c,f){if(c.is0(f))return f;if(ii(c,f)!==1)throw new Error("Cannot find square root");let u=r,l=c.mul(c.ONE,s),w=c.pow(f,t),S=c.pow(f,i);for(;!c.eql(w,c.ONE);){if(c.is0(w))return c.ZERO;let m=1,B=c.sqr(w);for(;!c.eql(B,c.ONE);)if(m++,B=c.sqr(B),m===u)throw new Error("Cannot find square root");let v=nt<<BigInt(u-m-1),b=c.pow(l,v);u=m,l=c.sqr(b),w=c.mul(w,l),S=c.mul(S,b)}return S}}function uf(e){return e%ai===ci?di:e%ui===fi?af:e%li===cf?ff(e):hi(e)}var pi=(e,t)=>(tt(e,t)&nt)===nt,lf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Gn(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=lf.reduce((n,o)=>(n[o]="function",n),t);return Gt(e,r),e}function df(e,t,r){if(r<pt)throw new Error("invalid exponent, negatives unsupported");if(r===pt)return e.ONE;if(r===nt)return t;let n=e.ONE,o=t;for(;r>pt;)r&nt&&(n=e.mul(n,o)),o=e.sqr(o),r>>=nt;return n}function je(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,a,c)=>e.is0(a)?i:(n[c]=i,e.mul(i,a)),e.ONE),s=e.inv(o);return t.reduceRight((i,a,c)=>e.is0(a)?i:(n[c]=e.mul(i,n[c]),e.mul(i,a)),s),n}function ii(e,t){let r=(e.ORDER-nt)/ne,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function hf(e,t){t!==void 0&&Ct(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}var Yn=class{ORDER;BITS;BYTES;isLE;ZERO=pt;ONE=nt;_lengths;_sqrt;_mod;constructor(t,r={}){if(t<=pt)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&(this.sqrt=r.sqrt),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=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,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return tt(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return pt<=t&&t<this.ORDER}is0(t){return t===pt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&nt)===nt}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 df(this,t,r)}div(t,r){return tt(t*si(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 si(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=uf(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?Fn(t,this.BYTES):gr(t,this.BYTES)}fromBytes(t,r=!1){K(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let f=new Uint8Array(o);f.set(t,s?0:f.length-t.length),t=f}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=s?re(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 je(this,t)}cmov(t,r,n){return n?r:t}};function Se(e,t={}){return new Yn(e,t)}function mi(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function Wn(e){let t=mi(e);return t+Math.ceil(t/2)}function Xn(e,t,r=!1){K(e);let n=e.length,o=mi(t),s=Wn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?re(e):we(e),a=tt(i,t-nt)+nt;return r?Fn(a,o):gr(a,o)}var ve=BigInt(0),oe=BigInt(1);function Ge(e,t){let r=t.negate();return e?r:t}function se(e,t){let r=je(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function gi(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Qn(e,t){gi(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=Ye(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function bi(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+=oe);let f=t*n,u=f+Math.abs(a)-1,l=a===0,w=a<0,S=t%2!==0;return{nextN:c,offset:u,isZero:l,isNeg:w,isNegF:S,offsetF:f}}var Jn=new WeakMap,wi=new WeakMap;function to(e){return wi.get(e)||1}function yi(e){if(e!==ve)throw new Error("invalid wNAF")}var Ae=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>ve;)r&oe&&(n=n.add(o)),o=o.double(),r>>=oe;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=Qn(r,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let f=1;f<o;f++)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=Qn(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:f,isZero:u,isNeg:l,isNegF:w,offsetF:S}=bi(n,a,i);n=c,u?s=s.add(Ge(w,r[S])):o=o.add(Ge(l,r[f]))}return yi(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=Qn(t,this.bits);for(let i=0;i<s.windows&&n!==ve;i++){let{nextN:a,offset:c,isZero:f,isNeg:u}=bi(n,i,s);if(n=a,!f){let l=r[c];o=o.add(u?l.negate():l)}}return yi(n),o}getPrecomputes(t,r,n){let o=Jn.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),Jn.set(r,o))),o}cached(t,r,n){let o=to(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=to(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){gi(r,this.bits),wi.set(t,r),Jn.delete(t)}hasCache(t){return to(t)!==1}};function Ei(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>ve||n>ve;)r&oe&&(s=s.add(o)),n&oe&&(i=i.add(o)),o=o.double(),r>>=oe,n>>=oe;return{p1:s,p2:i}}function xi(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Gn(t),t}else return Se(e,{isLE:r})}function Er(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 f=t[c];if(!(typeof f=="bigint"&&f>ve))throw new Error(`CURVE.${c} must be positive bigint`)}let o=xi(t.p,r.Fp,n),s=xi(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 Sr(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var Wt=BigInt(0),ot=BigInt(1),eo=BigInt(2),pf=BigInt(8);function mf(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 Si(e,t={}){let r=Er("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;Gt(t,{},{uvRatio:"function"});let a=eo<<BigInt(o.BYTES*8)-ot,c=v=>n.create(v),f=t.uvRatio||((v,b)=>{try{return{isValid:!0,value:n.sqrt(n.div(v,b))}}catch{return{isValid:!1,value:Wt}}});if(!mf(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function u(v,b,A=!1){let y=A?ot:Wt;return $e("coordinate "+v,b,y,a),b}function l(v){if(!(v instanceof m))throw new Error("EdwardsPoint expected")}let w=Ee((v,b)=>{let{X:A,Y:y,Z:_}=v,R=v.is0();b==null&&(b=R?pf:n.inv(_));let M=c(A*b),k=c(y*b),g=n.mul(_,b);if(R)return{x:Wt,y:ot};if(g!==ot)throw new Error("invZ was invalid");return{x:M,y:k}}),S=Ee(v=>{let{a:b,d:A}=s;if(v.is0())throw new Error("bad point: ZERO");let{X:y,Y:_,Z:R,T:M}=v,k=c(y*y),g=c(_*_),x=c(R*R),U=c(x*x),V=c(k*b),T=c(x*c(V+g)),h=c(U+c(A*c(k*g)));if(T!==h)throw new Error("bad point: equation left != right (1)");let p=c(y*_),d=c(R*M);if(p!==d)throw new Error("bad point: equation left != right (2)");return!0});class m{static BASE=new m(s.Gx,s.Gy,ot,c(s.Gx*s.Gy));static ZERO=new m(Wt,ot,ot,Wt);static Fp=n;static Fn=o;X;Y;Z;T;constructor(b,A,y,_){this.X=u("x",b),this.Y=u("y",A),this.Z=u("z",y,!0),this.T=u("t",_),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){if(b instanceof m)throw new Error("extended point not allowed");let{x:A,y}=b||{};return u("x",A),u("y",y),new m(A,y,ot,c(A*y))}static fromBytes(b,A=!1){let y=n.BYTES,{a:_,d:R}=s;b=wr(K(b,y,"point")),kt(A,"zip215");let M=wr(b),k=b[y-1];M[y-1]=k&-129;let g=re(M),x=A?a:n.ORDER;$e("point.y",g,Wt,x);let U=c(g*g),V=c(U-ot),T=c(R*U-_),{isValid:h,value:p}=f(V,T);if(!h)throw new Error("bad point: invalid y coordinate");let d=(p&ot)===ot,E=(k&128)!==0;if(!A&&p===Wt&&E)throw new Error("bad point: x=0 and x_0=1");return E!==d&&(p=c(-p)),m.fromAffine({x:p,y:g})}static fromHex(b,A=!1){return m.fromBytes(Kt(b),A)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,A=!0){return B.createCache(this,b),A||this.multiply(eo),this}assertValidity(){S(this)}equals(b){l(b);let{X:A,Y:y,Z:_}=this,{X:R,Y:M,Z:k}=b,g=c(A*k),x=c(R*_),U=c(y*k),V=c(M*_);return g===x&&U===V}is0(){return this.equals(m.ZERO)}negate(){return new m(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:b}=s,{X:A,Y:y,Z:_}=this,R=c(A*A),M=c(y*y),k=c(eo*c(_*_)),g=c(b*R),x=A+y,U=c(c(x*x)-R-M),V=g+M,T=V-k,h=g-M,p=c(U*T),d=c(V*h),E=c(U*h),I=c(T*V);return new m(p,d,I,E)}add(b){l(b);let{a:A,d:y}=s,{X:_,Y:R,Z:M,T:k}=this,{X:g,Y:x,Z:U,T:V}=b,T=c(_*g),h=c(R*x),p=c(k*y*V),d=c(M*U),E=c((_+R)*(g+x)-T-h),I=d-p,D=d+p,O=c(h-A*T),C=c(E*I),P=c(D*O),N=c(E*O),W=c(I*D);return new m(C,P,W,N)}subtract(b){return this.add(b.negate())}multiply(b){if(!o.isValidNot0(b))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:A,f:y}=B.cached(this,b,_=>se(m,_));return se(m,[A,y])[0]}multiplyUnsafe(b,A=m.ZERO){if(!o.isValid(b))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return b===Wt?m.ZERO:this.is0()||b===ot?this:B.unsafe(this,b,y=>se(m,y),A)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return B.unsafe(this,s.n).is0()}toAffine(b){return w(this,b)}clearCofactor(){return i===ot?this:this.multiplyUnsafe(i)}toBytes(){let{x:b,y:A}=this.toAffine(),y=n.toBytes(A);return y[y.length-1]|=b&ot?128:0,y}toHex(){return Nt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let B=new Ae(m,o.BITS);return m.BASE.precompute(8),m}function vi(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');Gt(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=e,a=r.randomBytes||ge,c=r.adjustScalarBytes||(g=>g),f=r.domain||((g,x,U)=>{if(kt(U,"phflag"),x.length||U)throw new Error("Contexts/pre-hash are not supported");return g});function u(g){return i.create(re(g))}function l(g){let x=y.secretKey;K(g,y.secretKey,"secretKey");let U=K(t(g),2*x,"hashedSecretKey"),V=c(U.slice(0,x)),T=U.slice(x,2*x),h=u(V);return{head:V,prefix:T,scalar:h}}function w(g){let{head:x,prefix:U,scalar:V}=l(g),T=o.multiply(V),h=T.toBytes();return{head:x,prefix:U,scalar:V,point:T,pointBytes:h}}function S(g){return w(g).pointBytes}function m(g=Uint8Array.of(),...x){let U=bt(...x);return u(t(f(U,K(g,void 0,"context"),!!n)))}function B(g,x,U={}){g=K(g,void 0,"message"),n&&(g=n(g));let{prefix:V,scalar:T,pointBytes:h}=w(x),p=m(U.context,V,g),d=o.multiply(p).toBytes(),E=m(U.context,d,h,g),I=i.create(p+E*T);if(!i.isValid(I))throw new Error("sign failed: invalid s");let D=bt(d,i.toBytes(I));return K(D,y.signature,"result")}let v={zip215:!0};function b(g,x,U,V=v){let{context:T,zip215:h}=V,p=y.signature;g=K(g,p,"signature"),x=K(x,void 0,"message"),U=K(U,y.publicKey,"publicKey"),h!==void 0&&kt(h,"zip215"),n&&(x=n(x));let d=p/2,E=g.subarray(0,d),I=re(g.subarray(d,p)),D,O,C;try{D=e.fromBytes(U,h),O=e.fromBytes(E,h),C=o.multiplyUnsafe(I)}catch{return!1}if(!h&&D.isSmallOrder())return!1;let P=m(T,O.toBytes(),D.toBytes(),x);return O.add(D.multiplyUnsafe(P)).subtract(C).clearCofactor().is0()}let A=s.BYTES,y={secretKey:A,publicKey:A,signature:2*A,seed:A};function _(g=a(y.seed)){return K(g,y.seed,"seed")}function R(g){return Jt(g)&&g.length===i.BYTES}function M(g,x){try{return!!e.fromBytes(g,x)}catch{return!1}}let k={getExtendedPublicKey:w,randomSecretKey:_,isValidSecretKey:R,isValidPublicKey:M,toMontgomery(g){let{y:x}=e.fromBytes(g),U=y.publicKey,V=U===32;if(!V&&U!==57)throw new Error("only defined for 25519 and 448");let T=V?s.div(ot+x,ot-x):s.div(x-ot,x+ot);return s.toBytes(T)},toMontgomerySecret(g){let x=y.secretKey;K(g,x);let U=t(g.subarray(0,x));return c(U).subarray(0,x)}};return Object.freeze({keygen:Sr(_,S),getPublicKey:S,sign:B,verify:b,utils:k,Point:e,lengths:y})}var bf=BigInt(1),Ai=BigInt(2);var yf=BigInt(5),xf=BigInt(8),ro=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),gf={p:ro,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:xf,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function wf(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=ro,a=e*e%s*e%s,c=j(a,Ai,s)*a%s,f=j(c,bf,s)*e%s,u=j(f,yf,s)*f%s,l=j(u,t,s)*u%s,w=j(l,r,s)*l%s,S=j(w,n,s)*w%s,m=j(S,o,s)*S%s,B=j(m,o,s)*S%s,v=j(B,t,s)*u%s;return{pow_p_5_8:j(v,Ai,s)*e%s,b2:a}}function Ef(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Bi=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Sf(e,t){let r=ro,n=tt(t*t*t,r),o=tt(n*n*t,r),s=wf(e*o).pow_p_5_8,i=tt(e*n*s,r),a=tt(t*i*i,r),c=i,f=tt(i*Bi,r),u=a===e,l=a===tt(-e,r),w=a===tt(-e*Bi,r);return u&&(i=c),(l||w)&&(i=f),pi(i,r)&&(i=tt(-i,r)),{isValid:u||l,value:i}}var vf=Si(gf,{uvRatio:Sf});function Af(e){return vi(vf,ei,Object.assign({adjustScalarBytes:Ef},e))}var _i=Af({});var We=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},vr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Ii={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new vr("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 Ar=Ii;var Br=32;var no,Bf=(async()=>{try{return await Ar.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function _f(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Ar.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Ar.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function If(e,t,r){return _i.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Ci(e,t,r){return no==null&&(no=await Bf),no?_f(e,t,r):If(e,t,r)}function _r(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Ir=class{type="Ed25519";raw;constructor(t){this.raw=oo(t,Br)}toMultihash(){return vt.digest(ye(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return et.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:xt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Ci(this.raw,r,t);return _r(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Ti(e){return e=oo(e,Br),new Ir(e)}function oo(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new It(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Df=Math.pow(2,7),Tf=Math.pow(2,14),Of=Math.pow(2,21),so=Math.pow(2,28),io=Math.pow(2,35),co=Math.pow(2,42),ao=Math.pow(2,49),G=128,lt=127;function Tt(e){if(e<Df)return 1;if(e<Tf)return 2;if(e<Of)return 3;if(e<so)return 4;if(e<io)return 5;if(e<co)return 6;if(e<ao)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Xe(e,t,r=0){switch(Tt(e)){case 8:t[r++]=e&255|G,e/=128;case 7:t[r++]=e&255|G,e/=128;case 6:t[r++]=e&255|G,e/=128;case 5:t[r++]=e&255|G,e/=128;case 4:t[r++]=e&255|G,e>>>=7;case 3:t[r++]=e&255|G,e>>>=7;case 2:t[r++]=e&255|G,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function fo(e,t){let r=e[t],n=0;if(n+=r&lt,r<G||(r=e[t+1],n+=(r&lt)<<7,r<G)||(r=e[t+2],n+=(r&lt)<<14,r<G)||(r=e[t+3],n+=(r&lt)<<21,r<G)||(r=e[t+4],n+=(r&lt)*so,r<G)||(r=e[t+5],n+=(r&lt)*io,r<G)||(r=e[t+6],n+=(r&lt)*co,r<G)||(r=e[t+7],n+=(r&lt)*ao,r<G))return n;throw new RangeError("Could not decode varint")}function Lf(e,t){let r=e.get(t),n=0;if(n+=r&lt,r<G||(r=e.get(t+1),n+=(r&lt)<<7,r<G)||(r=e.get(t+2),n+=(r&lt)<<14,r<G)||(r=e.get(t+3),n+=(r&lt)<<21,r<G)||(r=e.get(t+4),n+=(r&lt)*so,r<G)||(r=e.get(t+5),n+=(r&lt)*io,r<G)||(r=e.get(t+6),n+=(r&lt)*co,r<G)||(r=e.get(t+7),n+=(r&lt)*ao,r<G))return n;throw new RangeError("Could not decode varint")}function uo(e,t=0){return e instanceof Uint8Array?fo(e,t):Lf(e,t)}var lo=new Float32Array([-0]),Xt=new Uint8Array(lo.buffer);function Oi(e,t,r){lo[0]=e,t[r]=Xt[0],t[r+1]=Xt[1],t[r+2]=Xt[2],t[r+3]=Xt[3]}function Li(e,t){return Xt[0]=e[t],Xt[1]=e[t+1],Xt[2]=e[t+2],Xt[3]=e[t+3],lo[0]}var ho=new Float64Array([-0]),dt=new Uint8Array(ho.buffer);function Pi(e,t,r){ho[0]=e,t[r]=dt[0],t[r+1]=dt[1],t[r+2]=dt[2],t[r+3]=dt[3],t[r+4]=dt[4],t[r+5]=dt[5],t[r+6]=dt[6],t[r+7]=dt[7]}function Ri(e,t){return dt[0]=e[t],dt[1]=e[t+1],dt[2]=e[t+2],dt[3]=e[t+3],dt[4]=e[t+4],dt[5]=e[t+5],dt[6]=e[t+6],dt[7]=e[t+7],ho[0]}var Rf=BigInt(Number.MAX_SAFE_INTEGER),Uf=BigInt(Number.MIN_SAFE_INTEGER),St=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ie;if(t<Rf&&t>Uf)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>Ui&&(o=0n,++n>Ui&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return ie;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):ie}},ie=new St(0,0);ie.toBigInt=function(){return 0n};ie.zzEncode=ie.zzDecode=function(){return this};ie.length=function(){return 1};var Ui=4294967296n;function Ni(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 Ki(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 po(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 Bt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Cr(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var mo=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Bt(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 Bt(this,4);return Cr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Bt(this,4);return Cr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Bt(this,4);let t=Li(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Bt(this,4);let t=Ri(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 Bt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Ki(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Bt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Bt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new St(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Bt(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 Bt(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 Bt(this,8);let t=Cr(this.buf,this.pos+=4),r=Cr(this.buf,this.pos+=4);return new St(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=fo(this.buf,this.pos);return this.pos+=Tt(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 Qe(e){return new mo(e instanceof Uint8Array?e:e.subarray())}function Dr(e,t,r){let n=Qe(e);return t.decode(n,void 0,r)}function bo(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return gt(i);o+i>t&&(n=gt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var ce=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function yo(){}var go=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Nf=bo();function Kf(e){return globalThis.Buffer!=null?gt(e):Nf(e)}var tr=class{len;head;tail;states;constructor(){this.len=0,this.head=new ce(yo,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ce(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new wo((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(Tr,10,St.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=St.fromBigInt(t);return this._push(Tr,r.length(),r)}uint64Number(t){return this._push(Xe,Tt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=St.fromBigInt(t).zzEncode();return this._push(Tr,r.length(),r)}sint64Number(t){let r=St.fromNumber(t).zzEncode();return this._push(Tr,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(xo,1,t?1:0)}fixed32(t){return this._push(Je,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=St.fromBigInt(t);return this._push(Je,4,r.lo)._push(Je,4,r.hi)}fixed64Number(t){let r=St.fromNumber(t);return this._push(Je,4,r.lo)._push(Je,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(Oi,4,t)}double(t){return this._push(Pi,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(xo,1,0):this.uint32(r)._push(kf,r,t)}string(t){let r=Ni(t);return r!==0?this.uint32(r)._push(po,r,t):this._push(xo,1,0)}fork(){return this.states=new go(this),this.head=this.tail=new ce(yo,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 ce(yo,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=Kf(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function xo(e,t,r){t[r]=e&255}function Mf(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var wo=class extends ce{next;constructor(t,r){super(Mf,t,r),this.next=void 0}};function Tr(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 Je(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 kf(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(Vf,t,e),this},tr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Hf,t,e),this});function Vf(e,t,r){t.set(e,r)}function Hf(e,t,r){e.length<40?po(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(Et(e),r)}function Eo(){return new tr}function Or(e,t){let r=Eo();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*Lr(e,t,r){let n=Qe(e);yield*t.stream(n,void 0,"$",r)}var Pr={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Rr(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function So(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 Rr("enum",Pr.VARINT,r,n,o)}function Ur(e,t,r){return Rr("message",Pr.LENGTH_DELIMITED,e,t,r)}var mt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(mt||(mt={}));var vo;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(vo||(vo={}));(function(e){e.codec=()=>So(vo)})(mt||(mt={}));var er;(function(e){let t;e.codec=()=>(t==null&&(t=Ur((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),mt.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{c.Type=mt.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:mt.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return Or(s,e.codec())}e.encode=r;function n(s,i){return Dr(s,e.codec(),i)}e.decode=n;function o(s,i){return Lr(s,e.codec(),i)}e.stream=o})(er||(er={}));var Ao;(function(e){let t;e.codec=()=>(t==null&&(t=Ur((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),mt.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{c.Type=mt.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:mt.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return Or(s,e.codec())}e.encode=r;function n(s,i){return Dr(s,e.codec(),i)}e.decode=n;function o(s,i){return Lr(s,e.codec(),i)}e.stream=o})(Ao||(Ao={}));var Nr=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,r){if(mr(t),K(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),Ut(o)}update(t){return xe(this),this.iHash.update(t),this}digestInto(t){xe(this),K(t,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),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()}},Bo=(e,t,r)=>new Nr(e,t).update(r).digest();Bo.create=(e,t)=>new Nr(e,t);var ki=(e,t)=>(e+(e>=0?t:-t)/Vi)/t;function zf(e,t,r){let[[n,o],[s,i]]=t,a=ki(i*e,r),c=ki(-o*e,r),f=e-a*n-c*s,u=-a*o-c*i,l=f<Vt,w=u<Vt;l&&(f=-f),w&&(u=-u);let S=Ye(Math.ceil($n(r)/2))+Be;if(f<Vt||f>=S||u<Vt||u>=S)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:f,k2neg:w,k2:u}}function Io(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function _o(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return kt(r.lowS,"lowS"),kt(r.prehash,"prehash"),r.format!==void 0&&Io(r.format),r}var Co=class extends Error{constructor(t=""){super(t)}},Qt={Err:Co,_tlv:{encode:(e,t)=>{let{Err:r}=Qt;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=Fe(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Fe(o.length/2|128):"";return Fe(e)+s+o+t},decode(e,t){let{Err:r}=Qt,n=0;if(e<0||e>256)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 f=t.subarray(n,n+c);if(f.length!==c)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of f)i=i<<8|u;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Qt;if(e<Vt)throw new t("integer: negative integers are not allowed");let r=Fe(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}=Qt;if(e[0]&128)throw new t("invalid signature integer: negative");if(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}=Qt,o=K(e,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:f,l:u}=n.decode(2,c);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(f)}},hexFromSig(e){let{_tlv:t,_int:r}=Qt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},Vt=BigInt(0),Be=BigInt(1),Vi=BigInt(2),Kr=BigInt(3),Zf=BigInt(4);function Hi(e,t={}){let r=Er("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:a}=s;Gt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c}=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=zi(n,o);function u(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(T,h,p){let{x:d,y:E}=h.toAffine(),I=n.toBytes(d);if(kt(p,"isCompressed"),p){u();let D=!n.isOdd(E);return bt(qi(D),I)}else return bt(Uint8Array.of(4),I,n.toBytes(E))}function w(T){K(T,void 0,"Point");let{publicKey:h,publicKeyUncompressed:p}=f,d=T.length,E=T[0],I=T.subarray(1);if(d===h&&(E===2||E===3)){let D=n.fromBytes(I);if(!n.isValid(D))throw new Error("bad point: is not on curve, wrong x");let O=B(D),C;try{C=n.sqrt(O)}catch(W){let Y=W instanceof Error?": "+W.message:"";throw new Error("bad point: is not on curve, sqrt error"+Y)}u();let P=n.isOdd(C);return(E&1)===1!==P&&(C=n.neg(C)),{x:D,y:C}}else if(d===p&&E===4){let D=n.BYTES,O=n.fromBytes(I.subarray(0,D)),C=n.fromBytes(I.subarray(D,D*2));if(!v(O,C))throw new Error("bad point: is not on curve");return{x:O,y:C}}else throw new Error(`bad point: got length ${d}, expected compressed=${h} or uncompressed=${p}`)}let S=t.toBytes||l,m=t.fromBytes||w;function B(T){let h=n.sqr(T),p=n.mul(h,T);return n.add(n.add(p,n.mul(T,s.a)),s.b)}function v(T,h){let p=n.sqr(h),d=B(T);return n.eql(p,d)}if(!v(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let b=n.mul(n.pow(s.a,Kr),Zf),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(b,A)))throw new Error("bad curve params: a or b");function y(T,h,p=!1){if(!n.isValid(h)||p&&n.is0(h))throw new Error(`bad point coordinate ${T}`);return h}function _(T){if(!(T instanceof x))throw new Error("Weierstrass Point expected")}function R(T){if(!c||!c.basises)throw new Error("no endo");return zf(T,c.basises,o.ORDER)}let M=Ee((T,h)=>{let{X:p,Y:d,Z:E}=T;if(n.eql(E,n.ONE))return{x:p,y:d};let I=T.is0();h==null&&(h=I?n.ONE:n.inv(E));let D=n.mul(p,h),O=n.mul(d,h),C=n.mul(E,h);if(I)return{x:n.ZERO,y:n.ZERO};if(!n.eql(C,n.ONE))throw new Error("invZ was invalid");return{x:D,y:O}}),k=Ee(T=>{if(T.is0()){if(t.allowInfinityPoint&&!n.is0(T.Y))return;throw new Error("bad point: ZERO")}let{x:h,y:p}=T.toAffine();if(!n.isValid(h)||!n.isValid(p))throw new Error("bad point: x or y not field elements");if(!v(h,p))throw new Error("bad point: equation left != right");if(!T.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function g(T,h,p,d,E){return p=new x(n.mul(p.X,T),p.Y,p.Z),h=Ge(d,h),p=Ge(E,p),h.add(p)}class x{static BASE=new x(s.Gx,s.Gy,n.ONE);static ZERO=new x(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(h,p,d){this.X=y("x",h),this.Y=y("y",p,!0),this.Z=y("z",d),Object.freeze(this)}static CURVE(){return s}static fromAffine(h){let{x:p,y:d}=h||{};if(!h||!n.isValid(p)||!n.isValid(d))throw new Error("invalid affine point");if(h instanceof x)throw new Error("projective point not allowed");return n.is0(p)&&n.is0(d)?x.ZERO:new x(p,d,n.ONE)}static fromBytes(h){let p=x.fromAffine(m(K(h,void 0,"point")));return p.assertValidity(),p}static fromHex(h){return x.fromBytes(Kt(h))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=8,p=!0){return V.createCache(this,h),p||this.multiply(Kr),this}assertValidity(){k(this)}hasEvenY(){let{y:h}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(h)}equals(h){_(h);let{X:p,Y:d,Z:E}=this,{X:I,Y:D,Z:O}=h,C=n.eql(n.mul(p,O),n.mul(I,E)),P=n.eql(n.mul(d,O),n.mul(D,E));return C&&P}negate(){return new x(this.X,n.neg(this.Y),this.Z)}double(){let{a:h,b:p}=s,d=n.mul(p,Kr),{X:E,Y:I,Z:D}=this,O=n.ZERO,C=n.ZERO,P=n.ZERO,N=n.mul(E,E),W=n.mul(I,I),Y=n.mul(D,D),q=n.mul(E,I);return q=n.add(q,q),P=n.mul(E,D),P=n.add(P,P),O=n.mul(h,P),C=n.mul(d,Y),C=n.add(O,C),O=n.sub(W,C),C=n.add(W,C),C=n.mul(O,C),O=n.mul(q,O),P=n.mul(d,P),Y=n.mul(h,Y),q=n.sub(N,Y),q=n.mul(h,q),q=n.add(q,P),P=n.add(N,N),N=n.add(P,N),N=n.add(N,Y),N=n.mul(N,q),C=n.add(C,N),Y=n.mul(I,D),Y=n.add(Y,Y),N=n.mul(Y,q),O=n.sub(O,N),P=n.mul(Y,W),P=n.add(P,P),P=n.add(P,P),new x(O,C,P)}add(h){_(h);let{X:p,Y:d,Z:E}=this,{X:I,Y:D,Z:O}=h,C=n.ZERO,P=n.ZERO,N=n.ZERO,W=s.a,Y=n.mul(s.b,Kr),q=n.mul(p,I),X=n.mul(d,D),it=n.mul(E,O),_t=n.add(p,d),Q=n.add(I,D);_t=n.mul(_t,Q),Q=n.add(q,X),_t=n.sub(_t,Q),Q=n.add(p,E);let ut=n.add(I,O);return Q=n.mul(Q,ut),ut=n.add(q,it),Q=n.sub(Q,ut),ut=n.add(d,E),C=n.add(D,O),ut=n.mul(ut,C),C=n.add(X,it),ut=n.sub(ut,C),N=n.mul(W,Q),C=n.mul(Y,it),N=n.add(C,N),C=n.sub(X,N),N=n.add(X,N),P=n.mul(C,N),X=n.add(q,q),X=n.add(X,q),it=n.mul(W,it),Q=n.mul(Y,Q),X=n.add(X,it),it=n.sub(q,it),it=n.mul(W,it),Q=n.add(Q,it),q=n.mul(X,Q),P=n.add(P,q),q=n.mul(ut,Q),C=n.mul(_t,C),C=n.sub(C,q),q=n.mul(_t,X),N=n.mul(ut,N),N=n.add(N,q),new x(C,P,N)}subtract(h){return this.add(h.negate())}is0(){return this.equals(x.ZERO)}multiply(h){let{endo:p}=t;if(!o.isValidNot0(h))throw new Error("invalid scalar: out of range");let d,E,I=D=>V.cached(this,D,O=>se(x,O));if(p){let{k1neg:D,k1:O,k2neg:C,k2:P}=R(h),{p:N,f:W}=I(O),{p:Y,f:q}=I(P);E=W.add(q),d=g(p.beta,N,Y,D,C)}else{let{p:D,f:O}=I(h);d=D,E=O}return se(x,[d,E])[0]}multiplyUnsafe(h){let{endo:p}=t,d=this;if(!o.isValid(h))throw new Error("invalid scalar: out of range");if(h===Vt||d.is0())return x.ZERO;if(h===Be)return d;if(V.hasCache(this))return this.multiply(h);if(p){let{k1neg:E,k1:I,k2neg:D,k2:O}=R(h),{p1:C,p2:P}=Ei(x,d,I,O);return g(p.beta,C,P,E,D)}else return V.unsafe(d,h)}toAffine(h){return M(this,h)}isTorsionFree(){let{isTorsionFree:h}=t;return i===Be?!0:h?h(x,this):V.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:h}=t;return i===Be?this:h?h(x,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(h=!0){return kt(h,"isCompressed"),this.assertValidity(),S(x,this,h)}toHex(h=!0){return Nt(this.toBytes(h))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let U=o.BITS,V=new Ae(x,t.endo?Math.ceil(U/2):U);return x.BASE.precompute(8),x}function qi(e){return Uint8Array.of(e?2:3)}function zi(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Ff(e,t={}){let{Fn:r}=e,n=t.randomBytes||ge,o=Object.assign(zi(e.Fp,r),{seed:Wn(r.ORDER)});function s(S){try{let m=r.fromBytes(S);return r.isValidNot0(m)}catch{return!1}}function i(S,m){let{publicKey:B,publicKeyUncompressed:v}=o;try{let b=S.length;return m===!0&&b!==B||m===!1&&b!==v?!1:!!e.fromBytes(S)}catch{return!1}}function a(S=n(o.seed)){return Xn(K(S,o.seed,"seed"),r.ORDER)}function c(S,m=!0){return e.BASE.multiply(r.fromBytes(S)).toBytes(m)}function f(S){let{secretKey:m,publicKey:B,publicKeyUncompressed:v}=o;if(!Jt(S)||"_lengths"in r&&r._lengths||m===B)return;let b=K(S,void 0,"key").length;return b===B||b===v}function u(S,m,B=!0){if(f(S)===!0)throw new Error("first arg must be private key");if(f(m)===!1)throw new Error("second arg must be public key");let v=r.fromBytes(S);return e.fromBytes(m).multiply(v).toBytes(B)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},w=Sr(a,c);return Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:w,Point:e,utils:l,lengths:o})}function Zi(e,t,r={}){mr(t),Gt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let n=r.randomBytes||ge,o=r.hmac||((p,d)=>Bo(t,p,d)),{Fp:s,Fn:i}=e,{ORDER:a,BITS:c}=i,{keygen:f,getPublicKey:u,getSharedSecret:l,utils:w,lengths:S}=Ff(e,r),m={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},B=a*Vi<s.ORDER;function v(p){let d=a>>Be;return p>d}function b(p,d){if(!i.isValidNot0(d))throw new Error(`invalid signature ${p}: out of range 1..Point.Fn.ORDER`);return d}function A(){if(B)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function y(p,d){Io(d);let E=S.signature,I=d==="compact"?E:d==="recovered"?E+1:void 0;return K(p,I)}class _{r;s;recovery;constructor(d,E,I){if(this.r=b("r",d),this.s=b("s",E),I!=null){if(A(),![0,1,2,3].includes(I))throw new Error("invalid recovery id");this.recovery=I}Object.freeze(this)}static fromBytes(d,E=m.format){y(d,E);let I;if(E==="der"){let{r:P,s:N}=Qt.toSig(K(d));return new _(P,N)}E==="recovered"&&(I=d[0],E="compact",d=d.subarray(1));let D=S.signature/2,O=d.subarray(0,D),C=d.subarray(D,D*2);return new _(i.fromBytes(O),i.fromBytes(C),I)}static fromHex(d,E){return this.fromBytes(Kt(d),E)}assertRecovery(){let{recovery:d}=this;if(d==null)throw new Error("invalid recovery id: must be present");return d}addRecoveryBit(d){return new _(this.r,this.s,d)}recoverPublicKey(d){let{r:E,s:I}=this,D=this.assertRecovery(),O=D===2||D===3?E+a:E;if(!s.isValid(O))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let C=s.toBytes(O),P=e.fromBytes(bt(qi((D&1)===0),C)),N=i.inv(O),W=M(K(d,void 0,"msgHash")),Y=i.create(-W*N),q=i.create(I*N),X=e.BASE.multiplyUnsafe(Y).add(P.multiplyUnsafe(q));if(X.is0())throw new Error("invalid recovery: point at infinify");return X.assertValidity(),X}hasHighS(){return v(this.s)}toBytes(d=m.format){if(Io(d),d==="der")return Kt(Qt.hexFromSig(this));let{r:E,s:I}=this,D=i.toBytes(E),O=i.toBytes(I);return d==="recovered"?(A(),bt(Uint8Array.of(this.assertRecovery()),D,O)):bt(D,O)}toHex(d){return Nt(this.toBytes(d))}}let R=r.bits2int||function(d){if(d.length>8192)throw new Error("input is too large");let E=we(d),I=d.length*8-c;return I>0?E>>BigInt(I):E},M=r.bits2int_modN||function(d){return i.create(R(d))},k=Ye(c);function g(p){return $e("num < 2^"+c,p,Vt,k),i.toBytes(p)}function x(p,d){return K(p,void 0,"message"),d?K(t(p),void 0,"prehashed message"):p}function U(p,d,E){let{lowS:I,prehash:D,extraEntropy:O}=_o(E,m);p=x(p,D);let C=M(p),P=i.fromBytes(d);if(!i.isValidNot0(P))throw new Error("invalid private key");let N=[g(P),g(C)];if(O!=null&&O!==!1){let X=O===!0?n(S.secretKey):O;N.push(K(X,void 0,"extraEntropy"))}let W=bt(...N),Y=C;function q(X){let it=R(X);if(!i.isValidNot0(it))return;let _t=i.inv(it),Q=e.BASE.multiply(it).toAffine(),ut=i.create(Q.x);if(ut===Vt)return;let ir=i.create(_t*i.create(Y+ut*P));if(ir===Vt)return;let is=(Q.x===ut?0:2)|Number(Q.y&Be),cs=ir;return I&&v(ir)&&(cs=i.neg(ir),is^=1),new _(ut,cs,B?void 0:is)}return{seed:W,k2sig:q}}function V(p,d,E={}){let{seed:I,k2sig:D}=U(p,d,E);return oi(t.outputLen,i.BYTES,o)(I,D).toBytes(E.format)}function T(p,d,E,I={}){let{lowS:D,prehash:O,format:C}=_o(I,m);if(E=K(E,void 0,"publicKey"),d=x(d,O),!Jt(p)){let P=p instanceof _?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+P)}y(p,C);try{let P=_.fromBytes(p,C),N=e.fromBytes(E);if(D&&P.hasHighS())return!1;let{r:W,s:Y}=P,q=M(d),X=i.inv(Y),it=i.create(q*X),_t=i.create(W*X),Q=e.BASE.multiplyUnsafe(it).add(N.multiplyUnsafe(_t));return Q.is0()?!1:i.create(Q.x)===W}catch{return!1}}function h(p,d,E={}){let{prehash:I}=_o(E,m);return d=x(d,I),_.fromBytes(p,"recovered").recoverPublicKey(d).toBytes()}return Object.freeze({keygen:f,getPublicKey:u,getSharedSecret:l,utils:w,lengths:S,Point:e,sign:V,verify:T,recoverPublicKey:h,Signature:_,hash:t})}var To={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},$f={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Fi=BigInt(2);function Yf(e){let t=To.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=e*e*e%t,u=f*f*e%t,l=j(u,r,t)*u%t,w=j(l,r,t)*u%t,S=j(w,Fi,t)*f%t,m=j(S,o,t)*S%t,B=j(m,s,t)*m%t,v=j(B,a,t)*B%t,b=j(v,c,t)*v%t,A=j(b,a,t)*B%t,y=j(A,r,t)*u%t,_=j(y,i,t)*m%t,R=j(_,n,t)*f%t,M=j(R,Fi,t);if(!Do.eql(Do.sqr(M),e))throw new Error("Cannot find square root");return M}var Do=Se(To.p,{sqrt:Yf}),jf=Hi(To,{Fp:Do,endo:$f}),_e=Zi(jf,ti);function $i(e,t,r,n){let o=Me.digest(r instanceof Uint8Array?r:r.subarray());if(_r(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),_e.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new We(String(s))});try{return n?.signal?.throwIfAborted(),_e.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new We(String(s))}}var Mr=class{type="secp256k1";raw;_key;constructor(t){this._key=ji(t),this.raw=Yi(this._key)}toMultihash(){return vt.digest(ye(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return et.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:xt(this.raw,t.raw)}verify(t,r,n){return $i(this._key,r,t,n)}};function Gi(e){return new Mr(e)}function Yi(e){return _e.Point.fromBytes(e).toBytes()}function ji(e){try{return _e.Point.fromBytes(e),e}catch(t){throw new cr(String(t))}}function Wi(e){let{Type:t,Data:r}=er.decode(e.digest),n=r??new Uint8Array;switch(t){case mt.Ed25519:return Ti(n);case mt.secp256k1:return Gi(n);case mt.ECDSA:return Ks(n);default:throw new Le}}function ye(e){return er.encode({Type:mt[e.type],Data:e.raw})}var Xi=Symbol.for("nodejs.util.inspect.custom"),Gf=114,rr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[sn]=!0;toString(){return this.string==null&&(this.string=et.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ct.createV1(Gf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return xt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return xt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Xi](){return`PeerId(${this.toString()})`}},kr=class extends rr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Vr=class extends rr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Hr=class extends rr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Wf=2336,nr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=vt.digest(Et(this.url))}[Xi](){return`PeerId(${this.url})`}[sn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ct.createV1(Wf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=rt(t)),t.toString()===this.toString())}};var Xf=114,Qi=2336;function Ji(e,t){let r;if(e.charAt(0)==="1"||e.charAt(0)==="Q")r=Ne(et.decode(`z${e}`));else{if(e.startsWith("k51qzi5uqu5")||e.startsWith("kzwfwjn5ji4")||e.startsWith("k2k4r8")||e.startsWith("bafz"))return Qf(ct.parse(e));if(t==null)throw new It('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=Ne(t.decode(e))}return tc(r)}function tc(e){if(tu(e))return new kr({multihash:e});if(Jf(e))try{let t=Wi(e);if(t.type==="Ed25519")return new Vr({multihash:e,publicKey:t});if(t.type==="secp256k1")return new Hr({multihash:e,publicKey:t})}catch{let r=rt(e.digest);return new nr(new URL(r))}throw new fr("Supplied PeerID Multihash is invalid")}function Qf(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==Xf&&e.code!==Qi)throw new ar("Supplied PeerID CID is invalid");if(e.code===Qi){let t=rt(e.multihash.digest);return new nr(new URL(t))}return tc(e.multihash)}function Jf(e){return e.code===vt.code}function tu(e){return e.code===Me.code}var ft=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Ht=class extends Error{static name="ValidationError";name="ValidationError"},qr=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},zr=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Zr=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",f=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let w=Number.parseInt(l,t);if(!Number.isNaN(w))return w});if(u===void 0)break;if(s*=t,s+=u,s>f||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=t(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var eu=45,ru=15,Fr=new Zr;function ec(e){if(!(e.length>ru))return Fr.new(e).parseWith(()=>Fr.readIPv4Addr())}function rc(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>eu))return Fr.new(e).parseWith(()=>Fr.readIPv6Addr())}function $r(e){return!!ec(e)}function nc(e){return!!rc(e)}function Lo(e){return t=>rt(t,e)}function Po(e){return t=>Et(t,e)}function Ie(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function ae(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function oc(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=Et(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=ae(n);return Pt([r,o],r.length+o.length)}function sc(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let r=Ft.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=ae(n);return Pt([r,o],r.length+o.length)}function Ro(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=rt(t,"base32"),o=Ie(r);return`${n}:${o}`}var Uo=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},ic=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let s=$r(r[n]),i;s&&(i=Uo(r[n]),r[n]=rt(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,rt(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},cc=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(".")},ac=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 fc(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 Oo=Object.values(ke).map(e=>e.decoder),nu=(function(){let e=Oo[0].or(Oo[1]);return Oo.slice(2).forEach(t=>e=e.or(t)),e})();function uc(e){return nu.decode(e)}function lc(e){return t=>e.encoder.encode(t)}function ou(e){if(parseInt(e).toString()!==e)throw new Ht("Value must be an integer")}function su(e){if(e<0)throw new Ht("Value must be a positive integer, or zero")}function iu(e){return t=>{if(t>e)throw new Ht(`Value must be smaller than or equal to ${e}`)}}function cu(...e){return t=>{for(let r of e)r(t)}}var or=cu(ou,su,iu(65535));var st=-1,No=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 zr(`Protocol ${t} was unknown`);return r}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(r=>{this.protocolsByName.set(r,t)})}removeProtocol(t){let r=this.protocolsByCode.get(t);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},zt=new No,Eu=[{code:4,name:"ip4",size:32,valueToBytes:Uo,bytesToValue:cc,validate:e=>{if(!$r(e))throw new Ht(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ae,bytesToValue:Ie,validate:or},{code:273,name:"udp",size:16,valueToBytes:ae,bytesToValue:Ie,validate:or},{code:33,name:"dccp",size:16,valueToBytes:ae,bytesToValue:Ie,validate:or},{code:41,name:"ip6",size:128,valueToBytes:ic,bytesToValue:ac,stringToValue:fc,validate:e=>{if(!nc(e))throw new Ht(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:st},{code:43,name:"ipcidr",size:8,bytesToValue:Lo("base10"),valueToBytes:Po("base10")},{code:53,name:"dns",size:st},{code:54,name:"dns4",size:st},{code:55,name:"dns6",size:st},{code:56,name:"dnsaddr",size:st},{code:132,name:"sctp",size:16,valueToBytes:ae,bytesToValue:Ie,validate:or},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:st,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:st,bytesToValue:Lo("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?Po("base58btc")(e):ct.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Ro,valueToBytes:oc},{code:445,name:"onion3",size:296,bytesToValue:Ro,valueToBytes:sc},{code:446,name:"garlic64",size:st},{code:447,name:"garlic32",size:st},{code:448,name:"tls"},{code:449,name:"sni",size:st},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:st,bytesToValue:lc(En),valueToBytes:uc},{code:480,name:"http"},{code:481,name:"http-path",size:st,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:st}];Eu.forEach(e=>{zt.addProtocol(e)});function dc(e){let t=[],r=0;for(;r<e.length;){let n=uo(e,r),o=zt.getProtocol(n),s=Tt(n),i=Su(o,e,r+s),a=0;i>0&&o.size===st&&(a=Tt(i));let c=s+a+i,f={code:n,name:o.name,bytes:e.subarray(r,r+c)};if(i>0){let u=r+s+a,l=e.subarray(u,u+i);f.value=o.bytesToValue?.(l)??rt(l)}t.push(f),r+=c}return t}function hc(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=zt.getProtocol(n.code),s=Tt(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??Et(n.value),a=i.byteLength,o.size===st&&(c=Tt(a)));let f=new Uint8Array(s+c+a),u=0;Xe(n.code,f,u),u+=s,i!=null&&(o.size===st&&(Xe(a,f,u),u+=c),f.set(i,u)),n.bytes=f}r.push(n.bytes),t+=n.bytes.byteLength}return Pt(r,t)}function pc(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=zt.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new ft(`Component ${o} was missing value`);r="value"}else if(r==="value"){let f={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new ft(`Component ${o} was missing value`);f.value=c.stringToValue?.(n)??n}t.push(f),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new ft("Incomplete multiaddr");return t}function mc(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=zt.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 Su(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:uo(t,r)}var vu=Symbol.for("nodejs.util.inspect.custom"),Jo=Symbol.for("@multiformats/multiaddr");function Au(e){if(e==null&&(e="/"),bc(e))return e.getComponents();if(e instanceof Uint8Array)return dc(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),pc(e);if(Array.isArray(e))return e;throw new ft("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Qr=class e{[Jo]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=Au(t),r.validate!==!1&&Bu(this)}get bytes(){return this.#r==null&&(this.#r=hc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=mc(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 qr(`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 xt(this.bytes,t.bytes)}[vu](){return`Multiaddr(${this.toString()})`}};function Bu(e){e.getComponents().forEach(t=>{let r=zt.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function bc(e){return!!e?.[Jo]}function yc(e){return new Qr(e)}var F=e=>({match:t=>{let r=t[0];return r==null||r.code!==e||r.value!=null?!1:t.slice(1)}}),L=(e,t)=>({match:r=>{let n=r[0];return n?.code!==e||n.value==null||t!=null&&n.value!==t?!1:r.slice(1)}}),xc=e=>({match:t=>e.match(t)===!1?t:!1}),H=e=>({match:t=>{let r=e.match(t);return r===!1?t:r}}),ht=(...e)=>({match:t=>{let r;for(let n of e){let o=n.match(t);o!==!1&&(r==null||o.length<r.length)&&(r=o)}return r??!1}}),z=(...e)=>({match:t=>{for(let r of e){let n=r.match(t);if(n===!1)return!1;t=n}return t}});function $(...e){function t(o){if(o==null)return!1;let s=o.getComponents();for(let i of e){let a=i.match(s);if(a===!1)return!1;s=a}return s}function r(o){return t(o)!==!1}function n(o){let s=t(o);return s===!1?!1:s.length===0}return{matchers:e,matches:r,exactMatch:n}}var _u=L(421),_m=$(_u),tn=L(54),en=L(55),rn=L(56),es=L(53),Im=$(tn,H(L(421))),Cm=$(en,H(L(421))),Dm=$(rn,H(L(421))),Tm=$(ht(es,rn,tn,en),H(L(421))),gc=z(L(4),H(L(43))),wc=z(H(L(42)),L(41),H(L(43))),rs=ht(gc,wc),Oe=ht(rs,es,tn,en,rn),Om=$(ht(rs,z(ht(es,rn,tn,en),H(L(421))))),Lm=$(gc),Pm=$(wc),Rm=$(rs),ns=z(Oe,L(6)),sr=z(Oe,L(273)),Um=$(z(ns,H(L(421)))),Nm=$(sr),os=z(sr,F(460),H(L(421))),nn=z(sr,F(461),H(L(421))),Iu=ht(os,nn),Km=$(os),Mm=$(nn),ts=ht(Oe,ns,sr,os,nn),Ec=ht(z(ts,F(477),H(L(421)))),km=$(Ec),Sc=ht(z(ts,F(478),H(L(421))),z(ts,F(448),H(L(449)),F(477),H(L(421)))),Vm=$(Sc),vc=z(sr,F(280),H(L(466)),H(L(466)),H(L(421))),Hm=$(vc),Ac=z(nn,F(465),H(L(466)),H(L(466)),H(L(421))),qm=$(Ac),Jr=ht(Ec,Sc,z(ns,H(L(421))),z(Iu,H(L(421))),z(Oe,H(L(421))),vc,Ac,L(421)),Bc=$(Jr),Cu=z(H(Jr),F(290),xc(F(281)),H(L(421))),zm=$(Cu),Du=ht(z(Jr,F(290),F(281),H(L(421))),z(Jr,F(281),H(L(421))),z(F(281),H(L(421)))),Zm=$(Du),Tu=z(Oe,ht(z(L(6,"80")),z(L(6),F(480)),F(480)),H(L(481)),H(L(421))),Fm=$(Tu),Ou=z(Oe,ht(z(L(6,"443")),z(L(6,"443"),F(480)),z(L(6),F(443)),z(L(6),F(448),F(480)),z(F(448),F(480)),F(448),F(443)),H(L(481)),H(L(421))),$m=$(Ou),Lu=ht(z(L(777),H(L(421)))),Ym=$(Lu),Pu=ht(z(L(400),H(L(421)))),jm=$(Pu);var Ru="bootstrap",Uu=50,Nu=1e3,ss=class extends ur{static tag="bootstrap";log;timer;list;timeout;components;_init;constructor(t,r={list:[]}){if(r.list==null||r.list.length===0)throw new Error("Bootstrap requires a list of peer addresses");super(),this.components=t,this.log=t.logger.forComponent("libp2p:bootstrap"),this.timeout=r.timeout??Nu,this.list=r.list.map(n=>yc(n)).filter(n=>Bc.matches(n)?n.getComponents().findLast(s=>s.code===421)?.value==null?(this.log.error("invalid bootstrap multiaddr without peer id"),!1):!0:(this.log.error("invalid multiaddr %a",n),!1)).map(n=>({id:Ji(n.getComponents().findLast(o=>o.code===421)?.value??""),multiaddrs:[n]})),this._init=r}[as]=this;[Symbol.toStringTag]="@libp2p/bootstrap";[fs]=["@libp2p/peer-discovery"];isStarted(){return!!this.timer}start(){this.isStarted()||(this.log("Starting bootstrap node discovery, discovering peers after %s ms",this.timeout),this.timer=setTimeout(()=>{this._discoverBootstrapPeers().catch(t=>{this.log.error("failed to discover bootstrap peers - %e",t)})},this.timeout))}async _discoverBootstrapPeers(){if(this.timer!=null)for(let t of this.list){if(await this.components.peerStore.merge(t.id,{tags:{[this._init.tagName??Ru]:{value:this._init.tagValue??Uu,ttl:this._init.tagTTL}},multiaddrs:t.multiaddrs}),this.timer==null)return;this.safeDispatchEvent("peer",{detail:t}),this.components.connectionManager.openConnection(t.id).catch(r=>{this.log.error("could not dial bootstrap peer %p - %e",t.id,r)})}}stop(){this.timer!=null&&clearTimeout(this.timer),this.timer=void 0}};function Ku(e){return t=>new ss(t,e)}return Tc(Mu);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/hashes/utils.js: