@libp2p/floodsub 11.0.32-6d888970e → 11.0.32-95392efdf
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/sign.d.ts +4 -8
- package/dist/src/sign.d.ts.map +1 -1
- package/dist/src/sign.js +15 -29
- package/dist/src/sign.js.map +1 -1
- package/package.json +8 -8
- package/src/sign.ts +15 -33
package/dist/index.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PFloodsub = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PFloodsub=(()=>{var bn=Object.defineProperty;var Ma=Object.getOwnPropertyDescriptor;var Fa=Object.getOwnPropertyNames;var Ua=Object.prototype.hasOwnProperty;var mt=(e,t)=>{for(var r in t)bn(e,r,{get:t[r],enumerable:!0})},qa=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Fa(t))!Ua.call(e,s)&&s!==r&&bn(e,s,{get:()=>t[s],enumerable:!(n=Ma(t,s))||n.enumerable});return e};var za=e=>qa(bn({},"__esModule",{value:!0}),e);var il={};mt(il,{StrictNoSign:()=>rl,StrictSign:()=>el,TopicValidatorResult:()=>ze,floodsub:()=>sl,isPubSub:()=>nl,protocol:()=>di,pubSubSymbol:()=>Ve});var Ve=Symbol.for("@libp2p/pubsub");var et=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},ve=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Er=class extends Error{static name="StreamBufferError";constructor(t="The stream buffer was full"){super(t),this.name="StreamBufferError"}};var Sr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var ct=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var vr=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var oe=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var yn=Symbol.for("@libp2p/peer-id");function Ha(e){return typeof e?.handleEvent=="function"}function Va(e){return e===!0||e===!1}function $a(e){return Va(e)?e:e?.capture??!1}function gn(e){let t={capture:$a(e),once:!!e?.once};return e?.passive!=null&&(t.passive=e?.passive),e?.signal!=null&&(t.signal=e?.signal),t}function mi(e,t){return gn(e).capture===gn(t).capture}var Ae=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){let s=gn(n);if(s?.signal?.aborted===!0)return;let i=u=>{s.once&&this.removeEventListener(t,r,s),Ha(r)?r.handleEvent(u):r(u)},o=this.#t.get(t);if(o==null&&(o=[],this.#t.set(t,o)),o.some(u=>u.callback!==r?!1:mi(u.options,s)))return;super.addEventListener(t,i,s);let c=()=>{this.removeEventListener(t,r,s)};s.signal?.addEventListener("abort",c),o.push({callback:r,wrapper:i,options:s,onAbort:c})}removeEventListener(t,r,n){let s=this.#t.get(t);if(s==null){super.removeEventListener(t,r??null,n);return}this.#t.set(t,s.filter(i=>i.callback===r&&mi(i.options,n)?(super.removeEventListener(t,i.wrapper,n),i.options?.signal?.removeEventListener("abort",i.onAbort),!1):!0))}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var bi=Symbol.for("@libp2p/service-capabilities"),yi=Symbol.for("@libp2p/service-dependencies");var vn={};mt(vn,{base58btc:()=>rt,base58flickr:()=>Qa});var Nl=new Uint8Array(0);function wi(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function vt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return ae(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return ae(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));throw new Error("Unknown type, must be binary type")}function xi(e){let t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}var gi=4096;function Ei(e){let t=e.length;if(t<=gi)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.subarray(n,n+=gi));return r}function ja(e){return e?.buffer instanceof ArrayBuffer}function ae(e){return ja(e)?e:e.slice()}function Za(e,t,r){if(e.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),s=0;s<n.length;s++)n[s]=255;for(var i=0;i<e.length;i++){var o=e.charAt(i),a=o.charCodeAt(0);if(n[a]!==255)throw new TypeError(o+" is ambiguous");if(n[a]=i,r){var c=o.toLowerCase().charCodeAt(0),u=o.toUpperCase().charCodeAt(0);c!==a&&(n[c]=i),u!==a&&(n[u]=i)}}var f=e.length,d=e.charAt(0),l=Math.log(f)/Math.log(256),h=Math.log(256)/Math.log(f);function b(w){if(w instanceof Uint8Array||(ArrayBuffer.isView(w)?w=new Uint8Array(w.buffer,w.byteOffset,w.byteLength):Array.isArray(w)&&(w=Uint8Array.from(w))),!(w instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(w.length===0)return"";for(var v=0,y=0,A=0,B=w.length;A!==B&&w[A]===0;)A++,v++;for(var O=(B-A)*h+1>>>0,K=new Uint8Array(O);A!==B;){for(var k=w[A],_=0,C=O-1;(k!==0||_<y)&&C!==-1;C--,_++)k+=256*K[C]>>>0,K[C]=k%f>>>0,k=k/f>>>0;if(k!==0)throw new Error("Non-zero carry");y=_,A++}for(var q=O-y;q!==O&&K[q]===0;)q++;for(var U=d.repeat(v);q<O;++q)U+=e.charAt(K[q]);return U}function g(w){if(typeof w!="string")throw new TypeError("Expected String");if(w.length===0)return new Uint8Array;var v=0;if(w[v]!==" "){for(var y=0,A=0;w[v]===d;)y++,v++;for(var B=(w.length-v)*l+1>>>0,O=new Uint8Array(B);w[v];){var K=n[w.charCodeAt(v)];if(K===255)return;for(var k=0,_=B-1;(K!==0||k<A)&&_!==-1;_--,k++)K+=f*O[_]>>>0,O[_]=K%256>>>0,K=K/256>>>0;if(K!==0)throw new Error("Non-zero carry");A=k,v++}if(w[v]!==" "){for(var C=B-A;C!==B&&O[C]===0;)C++;for(var q=new Uint8Array(y+(B-C)),U=y;C!==B;)q[U++]=O[C++];return q}}}function E(w){var v=g(w);if(v)return v;throw new Error(`Non-${t} character`)}return{encode:b,decodeUnsafe:g,decode:E}}var Ya=Za,Ga=Ya,vi=Ga;var wn=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")}},xn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let s=r.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Ai(this,t)}},En=class{decoders;constructor(t){this.decoders=t}or(t){return Ai(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ai(e,t){return new En({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Sn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,s){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=s,this.encoder=new wn(t,r,n),this.decoder=new xn(t,r,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Be({name:e,prefix:t,encode:r,decode:n}){return new Sn(e,t,r,n)}function Ht({name:e,prefix:t,alphabet:r,caseInsensitive:n=!1}){let{encode:s,decode:i}=vi(r,e,n);return Be({prefix:t,name:e,encode:s,decode:o=>vt(i(o))})}function Wa(e,t,r,n){let s=e.length;for(;e[s-1]==="=";)--s;let i=new Uint8Array(s*r/8|0),o=0,a=0,c=0;for(let u=0;u<s;++u){let f=t[e[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,o+=r,o>=8&&(o-=8,i[c++]=255&a>>o)}if(o>=r||(255&a<<8-o)!==0)throw new SyntaxError("Unexpected end of data");return i}function Xa(e,t,r){let n=t[t.length-1]==="=",s=(1<<r)-1,i="",o=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],o+=8;o>r;)o-=r,i+=t[s&a>>o];if(o!==0&&(i+=t[s&a<<r-o]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function Ja(e,t){let r={};for(let n=0;n<e.length;++n)if(r[e[n]]=n,t){let s=e[n].toLowerCase(),i=e[n].toUpperCase();s!==e[n]&&(r[s]=n),i!==e[n]&&(r[i]=n)}return r}function it({name:e,prefix:t,bitsPerChar:r,alphabet:n,caseInsensitive:s=!1}){let i=Ja(n,s);return Be({prefix:t,name:e,encode(o){return Xa(o,n,r)},decode(o){return Wa(o,i,r,e)}})}var rt=Ht({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Qa=Ht({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var An={};mt(An,{base32:()=>Ie,base32hex:()=>nc,base32hexpad:()=>ic,base32hexpadupper:()=>oc,base32hexupper:()=>sc,base32pad:()=>ec,base32padupper:()=>rc,base32upper:()=>tc,base32z:()=>ac});var Ie=it({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),tc=it({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),ec=it({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),rc=it({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),nc=it({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),sc=it({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),ic=it({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),oc=it({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),ac=it({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Bn={};mt(Bn,{base36:()=>$e,base36upper:()=>cc});var $e=Ht({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),cc=Ht({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var uc=Ti,Bi=128,fc=127,lc=~fc,hc=Math.pow(2,31);function Ti(e,t,r){t=t||[],r=r||0;for(var n=r;e>=hc;)t[r++]=e&255|Bi,e/=128;for(;e&lc;)t[r++]=e&255|Bi,e>>>=7;return t[r]=e|0,Ti.bytes=r-n+1,t}var dc=In,pc=128,Ii=127;function In(e,n){var r=0,n=n||0,s=0,i=n,o,a=e.length;do{if(i>=a)throw In.bytes=0,new RangeError("Could not decode varint");o=e[i++],r+=s<28?(o&Ii)<<s:(o&Ii)*Math.pow(2,s),s+=7}while(o>=pc);return In.bytes=i-n,r}var mc=Math.pow(2,7),bc=Math.pow(2,14),yc=Math.pow(2,21),gc=Math.pow(2,28),wc=Math.pow(2,35),xc=Math.pow(2,42),Ec=Math.pow(2,49),Sc=Math.pow(2,56),vc=Math.pow(2,63),Ac=function(e){return e<mc?1:e<bc?2:e<yc?3:e<gc?4:e<wc?5:e<xc?6:e<Ec?7:e<Sc?8:e<vc?9:10},Bc={encode:uc,decode:dc,encodingLength:Ac},Ic=Bc,je=Ic;function Ze(e,t=0){let r=je.decode(e,t),n=je.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&e[t+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function Te(e,t,r=0){return je.encode(e,t,r),t}function Le(e){return je.encodingLength(e)}function Dt(e,t){let r=t.byteLength,n=Le(e),s=n+Le(r),i=new Uint8Array(s+r);return Te(e,i,0),Te(r,i,n),i.set(t,s),new Re(e,r,t,i)}function Vt(e){let t=vt(e),[r,n]=Ze(t),[s,i]=Ze(t.subarray(n)),o=t.subarray(n+i);if(o.byteLength!==s)throw new Error("Incorrect length");return new Re(r,s,o,t)}function Li(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&wi(e.bytes,r.bytes)}}var Re=class{code;size;digest;bytes;constructor(t,r,n,s){this.code=t,this.size=r,this.digest=ae(n),this.bytes=ae(s)}};function Ri(e,t){let{bytes:r,version:n}=e;return n===0?Lc(r,Tn(e),t??rt.encoder):Rc(r,Tn(e),t??Ie.encoder)}var _i=new WeakMap;function Tn(e){let t=_i.get(e);if(t==null){let r=new Map;return _i.set(e,r),r}return t}var ht=class e{code;version;multihash;bytes;"/";constructor(t,r,n,s){this.code=r,this.version=t,this.multihash=n,this.bytes=ae(s),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==Ye)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==_c)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=Dt(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&&Li(t.multihash,n.multihash)}toString(t){return Ri(this,t)}toJSON(){return{"/":Ri(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:s,multihash:i,bytes:o}=r;return new e(n,s,i,o??Di(n,s,i.bytes))}else if(r[Dc]===!0){let{version:n,multihash:s,code:i}=r,o=Vt(s);return e.create(n,i,o)}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!==Ye)throw new Error(`Version 0 CID must use dag-pb (code: ${Ye}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let s=Di(t,r,n.bytes);return new e(t,r,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Ye,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,s=vt(t.subarray(n,n+r.multihashSize));if(s.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=s.subarray(r.multihashSize-r.digestSize),o=new Re(r.multihashCode,r.digestSize,i,s);return[r.version===0?e.createV0(o):e.createV1(r.codec,o),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[d,l]=Ze(t.subarray(r));return r+=l,d},s=n(),i=Ye;if(s===18?(s=0,r=0):i=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let o=r,a=n(),c=n(),u=r+c,f=u-o;return{version:s,codec:i,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,r){let[n,s]=Tc(t,r),i=e.decode(s);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Tn(i).set(n,t),i}};function Tc(e,t){switch(e[0]){case"Q":{let r=t??rt;return[rt.prefix,r.decode(`${rt.prefix}${e}`)]}case rt.prefix:{let r=t??rt;return[rt.prefix,r.decode(e)]}case Ie.prefix:{let r=t??Ie;return[Ie.prefix,r.decode(e)]}case $e.prefix:{let r=t??$e;return[$e.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 Lc(e,t,r){let{prefix:n}=r;if(n!==rt.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let s=t.get(n);if(s==null){let i=r.encode(e).slice(1);return t.set(n,i),i}else return s}function Rc(e,t,r){let{prefix:n}=r,s=t.get(n);if(s==null){let i=r.encode(e);return t.set(n,i),i}else return s}var Ye=112,_c=18;function Di(e,t,r){let n=Le(e),s=n+Le(t),i=new Uint8Array(s+r.byteLength);return Te(e,i,0),Te(t,i,n),i.set(r,s),i}var Dc=Symbol.for("@ipld/js-cid/CID");var Ln={};mt(Ln,{identity:()=>Lt});var Ci=0,Cc="identity",Pi=vt;function Pc(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 Dt(Ci,Pi(e))}var Lt={code:Ci,name:Cc,encode:Pi,digest:Pc};function bt(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 Oc(e){return e.buffer instanceof ArrayBuffer}function At(e){return Oc(e)?e:e.slice()}async function Oi(e,t,r,n){let s=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let i=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},s,At(t),At(r.subarray()));return n?.signal?.throwIfAborted(),i}function kt(e=0){return new Uint8Array(e)}function yt(e=0){return new Uint8Array(e)}function kc(e){return e?.buffer instanceof ArrayBuffer}function ki(e){if(kc(e))return e;let t=e.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function ce(e,t){t==null&&(t=e.reduce((s,i)=>s+i.length,0));let r=yt(t),n=0;for(let s of e)r.set(s,n),n+=s.length;return ki(r)}var Ki=Symbol.for("@achingbrain/uint8arraylist");function Ni(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let s=r+n.byteLength;if(t<s)return{buf:n,index:t-r};r=s}throw new RangeError("index is out of bounds")}function Br(e){return!!e?.[Ki]}var lt=class e{bufs;length;[Ki]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Br(n)){r+=n.byteLength;for(let s of n.bufs)this.bufs.push(s)}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(Br(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=Ni(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Ni(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(Br(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:s}=this._subList(t,r);return ce(n,s)}subarray(t,r){let{bufs:n,length:s}=this._subList(t,r);return n.length===1?n[0]:ce(n,s)}sublist(t,r){let{bufs:n,length:s}=this._subList(t,r),i=new e;return i.length=s,i.bufs=n,i}_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=[],s=0;for(let i=0;i<this.bufs.length;i++){let o=this.bufs[i],a=s,c=a+o.byteLength;if(s=c,t>=c)continue;let u=t>=a&&t<c,f=r>a&&r<=c;if(u&&f){if(t===a&&r===c){n.push(o);break}let d=t-a;n.push(o.subarray(d,d+(r-t)));break}if(u){if(t===0){n.push(o);continue}n.push(o.subarray(t-a));continue}if(f){if(r===c){n.push(o);break}n.push(o.subarray(0,r-a));break}n.push(o)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Br(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 s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let i=256,o=new Int32Array(i);for(let d=0;d<i;d++)o[d]=-1;for(let d=0;d<s;d++)o[n[d]]=d;let a=o,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let d=r;d<=c;d+=f){f=0;for(let l=u;l>=0;l--){let h=this.get(d+l);if(n[l]!==h){f=Math.max(1,l-a[h]);break}}if(f===0)return d}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=yt(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 s=kt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,r,n),this.write(s,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 s=kt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,r,n),this.write(s,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 s=kt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,r,n),this.write(s,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=yt(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 s=kt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,r,n),this.write(s,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 s=kt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,r,n),this.write(s,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 s=kt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,r,n),this.write(s,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 s=kt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,r,n),this.write(s,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 s=kt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,r,n),this.write(s,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(!bt(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((s,i)=>s+i.byteLength,0)),n.length=r,n}};var Rn={};mt(Rn,{base10:()=>Nc});var Nc=Ht({prefix:"9",name:"base10",alphabet:"0123456789"});var _n={};mt(_n,{base16:()=>Kc,base16upper:()=>Mc});var Kc=it({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Mc=it({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Dn={};mt(Dn,{base2:()=>Fc});var Fc=it({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Cn={};mt(Cn,{base256emoji:()=>Vc});var Mi=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}"),Uc=Mi.reduce((e,t,r)=>(e[r]=t,e),[]),qc=Mi.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function zc(e){return e.reduce((t,r)=>(t+=Uc[r],t),"")}function Hc(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let s=qc[n];if(s==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(s)}return new Uint8Array(t)}var Vc=Be({prefix:"\u{1F680}",name:"base256emoji",encode:zc,decode:Hc});var Pn={};mt(Pn,{base64:()=>$c,base64pad:()=>jc,base64url:()=>Zc,base64urlpad:()=>Yc});var $c=it({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),jc=it({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Zc=it({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Yc=it({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var On={};mt(On,{base8:()=>Gc});var Gc=it({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var kn={};mt(kn,{identity:()=>Wc});var Wc=Be({prefix:"\0",name:"identity",encode:e=>Ei(vt(e)),decode:e=>vt(xi(e))});var Eh=new TextEncoder,Sh=new TextDecoder;var Mn={};mt(Mn,{sha256:()=>ue,sha512:()=>tu});var Qc=20;function Kn({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:s}){return new Nn(e,t,r,n,s)}var Nn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,s,i){this.name=t,this.code=r,this.encode=n,this.minDigestLength=s??Qc,this.maxDigestLength=i}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?Fi(n,this.code,r?.truncate):n.then(s=>Fi(s,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Fi(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 Dt(t,e)}function qi(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var ue=Kn({name:"sha2-256",code:18,encode:qi("SHA-256")}),tu=Kn({name:"sha2-512",code:19,encode:qi("SHA-512")});var Fn={...kn,...Dn,...On,...Rn,..._n,...An,...Bn,...vn,...Pn,...Cn},Oh={...Mn,...Ln};function Hi(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var zi=Hi("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Un=Hi("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=yt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),eu={utf8:zi,"utf-8":zi,hex:Fn.base16,latin1:Un,ascii:Un,binary:Un,...Fn},Ir=eu;function Y(e,t="utf8"){let r=Ir[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function Z(e,t="utf8"){let r=Ir[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var ru=parseInt("11111",2),qn=parseInt("10000000",2),nu=parseInt("01111111",2),Vi={0:Ge,1:Ge,2:su,3:au,4:cu,5:ou,6:iu,16:Ge,22:Ge,48:Ge};function Nt(e,t={offset:0}){let r=e[t.offset]&ru;if(t.offset++,Vi[r]!=null)return Vi[r](e,t);throw new Error("No decoder for tag "+r)}function We(e,t){let r=0;if((e[t.offset]&qn)===qn){let n=e[t.offset]&nu,s="0x";t.offset++;for(let i=0;i<n;i++,t.offset++){if(t.offset>=e.byteLength)throw new Error("invalid DER element length");s+=e[t.offset].toString(16).padStart(2,"0")}r=parseInt(s,16)}else r=e[t.offset],t.offset++;if(!Number.isInteger(r)||r<0||r>e.byteLength-t.offset)throw new Error("invalid DER element length");return r}function Ge(e,t){We(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Nt(e,t);if(n===null)break;r.push(n)}return r}function su(e,t){let r=We(e,t),n=t.offset,s=t.offset+r,i=[];for(let o=n;o<s;o++)o===n&&e[o]===0||i.push(e[o]);return t.offset+=r,Uint8Array.from(i)}function iu(e,t){let r=We(e,t),n=t.offset+r,s=e[t.offset];t.offset++;let i=0,o=0;s<40?(i=0,o=s):s<80?(i=1,o=s-40):(i=2,o=s-80);let a=`${i}.${o}`,c=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let d=0;d<c.length;d++)f+=c[d]<<d*7;a+=`.${f}`,c=[]}}return a}function ou(e,t){return t.offset++,null}function au(e,t){let r=We(e,t),n=e[t.offset];t.offset++;let s=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 s}function cu(e,t){let r=We(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function uu(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new lt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function zn(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=uu(e.byteLength);return new lt(Uint8Array.from([t.byteLength|qn]),t)}function gt(e){let t=new lt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new lt(Uint8Array.from([2]),zn(t),t)}function Tr(e){let t=Uint8Array.from([0]),r=new lt(t,e);return new lt(Uint8Array.from([3]),zn(r),r)}function jt(e,t=48){let r=new lt;for(let n of e)r.append(n);return new lt(Uint8Array.from([t]),zn(r),r)}var fu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),lu=Uint8Array.from([6,5,43,129,4,0,34]),hu=Uint8Array.from([6,5,43,129,4,0,35]),du={ext:!0,kty:"EC",crv:"P-256"},pu={ext:!0,kty:"EC",crv:"P-384"},mu={ext:!0,kty:"EC",crv:"P-521"},Hn=32,Vn=48,$n=66;function jn(e){let t=Nt(e);return $i(t)}function $i(e){let t=e[1][1][0],r=1,n,s;if(t.byteLength===Hn*2+1)return n=Z(t.subarray(r,r+Hn),"base64url"),s=Z(t.subarray(r+Hn),"base64url"),new _e({...du,key_ops:["verify"],x:n,y:s});if(t.byteLength===Vn*2+1)return n=Z(t.subarray(r,r+Vn),"base64url"),s=Z(t.subarray(r+Vn),"base64url"),new _e({...pu,key_ops:["verify"],x:n,y:s});if(t.byteLength===$n*2+1)return n=Z(t.subarray(r,r+$n),"base64url"),s=Z(t.subarray(r+$n),"base64url"),new _e({...mu,key_ops:["verify"],x:n,y:s});throw new et(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function ji(e){return jt([gt(Uint8Array.from([1])),jt([bu(e.crv)],160),jt([Tr(new lt(Uint8Array.from([4]),Y(e.x??"","base64url"),Y(e.y??"","base64url")))],161)]).subarray()}function bu(e){if(e==="P-256")return fu;if(e==="P-384")return lu;if(e==="P-521")return hu;throw new et(`Invalid curve ${e}`)}var _e=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=ji(this.jwk)),this._raw}toMultihash(){return Lt.digest(Kt(this))}toCID(){return ht.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}async verify(t,r,n){return Oi(this.jwk,r,t,n)}};var Lr=BigInt(4294967295),Zi=BigInt(32);function yu(e,t=!1){return t?{h:Number(e&Lr),l:Number(e>>Zi&Lr)}:{h:Number(e>>Zi&Lr)|0,l:Number(e&Lr)|0}}function Yi(e,t=!1){let r=e.length,n=new Uint32Array(r),s=new Uint32Array(r);for(let i=0;i<r;i++){let{h:o,l:a}=yu(e[i],t);[n[i],s[i]]=[o,a]}return[n,s]}var gu=e=>e/2**32|0,wu=e=>e>>>0;function Gi(e,t,r,n){let s=gu(r),i=wu(r);e.setUint32(t,n?i:s,n),e.setUint32(t+4,n?s:i,n)}var Zn=(e,t,r)=>e>>>r,Yn=(e,t,r)=>e<<32-r|t>>>r,fe=(e,t,r)=>e>>>r|t<<32-r,le=(e,t,r)=>e<<32-r|t>>>r,Xe=(e,t,r)=>e<<64-r|t>>>r-32,Je=(e,t,r)=>e>>>r-32|t<<64-r;function Ct(e,t,r,n){let s=(t>>>0)+(n>>>0);return{h:e+r+(s/2**32|0)|0,l:s|0}}var Wi=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Xi=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Ji=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Qi=(e,t,r,n,s)=>t+r+n+s+(e/2**32|0)|0,to=(e,t,r,n,s)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(s>>>0),eo=(e,t,r,n,s,i)=>t+r+n+s+i+(e/2**32|0)|0;function Rr(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}var Gn=e=>e?`"${e}" `:"";function Mt(e,t=""){if(typeof e!="number")throw new TypeError(Gn(t)+"expected number, got "+typeof e);if(!Number.isSafeInteger(e)||e<0)throw new RangeError(Gn(t)+"expected integer >= 0, got "+e);return e}function Bt(e,t,r=""){if(Rr(e)&&(t===void 0||e.length===t))return e;t!==void 0&&Mt(t,"length");let n=Rr(e),s=t!==void 0?` of length ${t}`:"",i=n?`length=${e.length}`:`type=${typeof e}`,o=Gn(r)+"expected Uint8Array"+s+", got "+i;throw n?new RangeError(o):new TypeError(o)}function _r(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(Mt(e.outputLen),Mt(e.blockLen),e.outputLen<1||e.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var Eu=(e,t)=>{if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError((t==="object"?"":`"${t}" `)+"expected object, got type="+typeof e)},ro=(e,t)=>{Eu(e,t);let r=Object.getPrototypeOf(e);if(r!==Object.prototype&&r!==null)throw new TypeError(`"${t}" expected plain object`);if(Object.hasOwn(e,"__proto__"))throw new TypeError(`"${t}.__proto__" is not allowed`)};function De(e,t=!0){if(e.destroyed)throw new Error("hash was destroyed");if(t&&e.finished)throw new Error("digest() was already called")}function Dr(e,t){Bt(e,void 0,"output");let r=t.outputLen;if(!(e.length>=r))throw new RangeError('"output" expected length >= '+r)}function he(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Cr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Rt(e,t){return e<<32-t|e>>>t}var so=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Su=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Pr(e){if(Bt(e),so)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Su[e[r]];return t}function no(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function Or(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(so)try{return Uint8Array.fromHex(e)}catch(s){throw s instanceof SyntaxError?new RangeError(s.message):s}let t=e.length,r=t/2;if(t%2)throw new RangeError("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let s=0,i=0;s<r;s++,i+=2){let o=no(e.charCodeAt(i)),a=no(e.charCodeAt(i+1));if(o===void 0||a===void 0){let c=e[i]+e[i+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+i)}n[s]=o*16+a}return n}function Wn(...e){let t=0;for(let n=0;n<e.length;n++){let s=e[n];Bt(s),t+=s.length}let r=new Uint8Array(t);for(let n=0,s=0;n<e.length;n++){let i=e[n];r.set(i,s),s+=i.length}return r}function vu(e,t,r="opts"){return ro(e,"defaults"),t!==void 0&&ro(t,r),Object.assign(Object.create(null),e,t)}function Xn(e,t={}){if(typeof e!="function")throw new TypeError('"hashCons" expected function, got type='+typeof e);t=vu({},t,"info");let r=(s,i)=>e(i).update(s).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=s=>e(s),Object.assign(r,t),Object.freeze(r)}function io(e=32){Mt(e,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(e>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}var Jn=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function oo(e,t,r){return e&t^~e&r}function ao(e,t,r){return e&t^e&r^t&r}var Qe=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,s){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(t),this.view=Cr(this.buffer)}update(t){De(this),Bt(t);let{view:r,buffer:n,blockLen:s}=this,i=t.length,o=!1;for(let a=0;a<i;){let c=Math.min(s-this.pos,i-a);if(c===s){let u=Cr(t);for(;s<=i-a;a+=s)this.process(u,a);o=!0;continue}n.set(a===0&&c===i?t:t.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===s&&(this.process(r,0),this.pos=0,o=!0)}return this.length+=t.length,o&&this.roundClean(),this}digestInto(t){De(this),Dr(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:s,isLE:i}=this,{pos:o}=this;r[o++]=128,r.fill(0,o),this.padOffset>s-o&&(this.process(n,0),r.fill(0)),Gi(n,s-8,this.length*8,i),this.process(n,0),this.roundClean();let a=t===r?n:Cr(t),c=this.outputLen,u=c/4,f=this.get();if(c%4||u>f.length)throw new Error("invalid outputLen");for(let d=0;d<u;d++)a.setUint32(4*d,f[d],i)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneIntoMeta(t){let{buffer:r,length:n,finished:s,destroyed:i,pos:o}=this;return t.destroyed=i,t.finished=s,t.length=n,t.pos=o,o&&t.buffer.set(r),t}clone(){return this._cloneInto()}},co=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var uo=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Au=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]),Zt=new Uint32Array(64),Qn=class extends Qe{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(t,r){super(64,t,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:t,B:r,C:n,D:s,E:i,F:o,G:a,H:c}=this;return[t,r,n,s,i,o,a,c]}set(t,r,n,s,i,o,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=s|0,this.E=i|0,this.F=o|0,this.G=a|0,this.H=c|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,r){for(let d=0;d<16;d++,r+=4)Zt[d]=t.getUint32(r,!1);for(let d=16;d<64;d++){let l=Zt[d-15],h=Zt[d-2],b=Rt(l,7)^Rt(l,18)^l>>>3,g=Rt(h,17)^Rt(h,19)^h>>>10;Zt[d]=g+Zt[d-7]+b+Zt[d-16]|0}let{A:n,B:s,C:i,D:o,E:a,F:c,G:u,H:f}=this;for(let d=0;d<64;d++){let l=Rt(a,6)^Rt(a,11)^Rt(a,25),h=f+l+oo(a,c,u)+Au[d]+Zt[d]|0,g=(Rt(n,2)^Rt(n,13)^Rt(n,22))+ao(n,s,i)|0;f=u,u=c,c=a,a=o+h|0,o=i,i=s,s=n,n=h+g|0}n=n+this.A|0,s=s+this.B|0,i=i+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,s,i,o,a,c,u,f)}roundClean(){he(Zt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),he(this.buffer)}},ts=class extends Qn{constructor(){super(32,co)}};var fo=Yi(["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))),Bu=fo[0],Iu=fo[1],Yt=new Uint32Array(80),Gt=new Uint32Array(80),es=class extends Qe{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(t,r){super(128,t,16,!1),this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:s,Ch:i,Cl:o,Dh:a,Dl:c,Eh:u,El:f,Fh:d,Fl:l,Gh:h,Gl:b,Hh:g,Hl:E}=this;return[t,r,n,s,i,o,a,c,u,f,d,l,h,b,g,E]}set(t,r,n,s,i,o,a,c,u,f,d,l,h,b,g,E){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=s|0,this.Ch=i|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=d|0,this.Fl=l|0,this.Gh=h|0,this.Gl=b|0,this.Hh=g|0,this.Hl=E|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,r){for(let y=0;y<16;y++,r+=4)Yt[y]=t.getUint32(r),Gt[y]=t.getUint32(r+=4);for(let y=16;y<80;y++){let A=Yt[y-15]|0,B=Gt[y-15]|0,O=fe(A,B,1)^fe(A,B,8)^Zn(A,B,7),K=le(A,B,1)^le(A,B,8)^Yn(A,B,7),k=Yt[y-2]|0,_=Gt[y-2]|0,C=fe(k,_,19)^Xe(k,_,61)^Zn(k,_,6),q=le(k,_,19)^Je(k,_,61)^Yn(k,_,6),U=Ji(K,q,Gt[y-7],Gt[y-16]),G=Qi(U,O,C,Yt[y-7],Yt[y-16]);Yt[y]=G|0,Gt[y]=U|0}let{Ah:n,Al:s,Bh:i,Bl:o,Ch:a,Cl:c,Dh:u,Dl:f,Eh:d,El:l,Fh:h,Fl:b,Gh:g,Gl:E,Hh:w,Hl:v}=this;for(let y=0;y<80;y++){let A=fe(d,l,14)^fe(d,l,18)^Xe(d,l,41),B=le(d,l,14)^le(d,l,18)^Je(d,l,41),O=d&h^~d&g,K=l&b^~l&E,k=to(v,B,K,Iu[y],Gt[y]),_=eo(k,w,A,O,Bu[y],Yt[y]),C=k|0,q=fe(n,s,28)^Xe(n,s,34)^Xe(n,s,39),U=le(n,s,28)^Je(n,s,34)^Je(n,s,39),G=n&i^n&a^i&a,T=s&o^s&c^o&c;w=g|0,v=E|0,g=h|0,E=b|0,h=d|0,b=l|0,{h:d,l}=Ct(u|0,f|0,_|0,C|0),u=a|0,f=c|0,a=i|0,c=o|0,i=n|0,o=s|0;let M=Wi(C,U,T);n=Xi(M,_,q,G),s=M|0}({h:n,l:s}=Ct(this.Ah|0,this.Al|0,n|0,s|0)),{h:i,l:o}=Ct(this.Bh|0,this.Bl|0,i|0,o|0),{h:a,l:c}=Ct(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Ct(this.Dh|0,this.Dl|0,u|0,f|0),{h:d,l}=Ct(this.Eh|0,this.El|0,d|0,l|0),{h,l:b}=Ct(this.Fh|0,this.Fl|0,h|0,b|0),{h:g,l:E}=Ct(this.Gh|0,this.Gl|0,g|0,E|0),{h:w,l:v}=Ct(this.Hh|0,this.Hl|0,w|0,v|0),this.set(n,s,i,o,a,c,u,f,d,l,h,b,g,E,w,v)}roundClean(){he(Yt,Gt)}destroy(){this.destroyed=!0,he(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},rs=class extends es{constructor(){super(64,uo)}};var Ce=Xn(()=>new ts,Jn(1));var ns=Xn(()=>new rs,Jn(3));function Nr(e,t,r=()=>{}){if(!Array.isArray(e))throw new TypeError(`"${t}" expected array, got type=${typeof e}`);for(let n=0;n<e.length;n++)r(e[n],`${t}[${n}]`);return e}var V=(e,t,r)=>Bt(e,t,r),ss=Mt;function ho(e,t=""){if(typeof e!="string"){let r=t&&`"${t}" `;throw new TypeError(r+"expected string, got type="+typeof e)}return e}function Wt(e,t="object"){if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError(t==="object"?"expected valid options object":`"${t}" expected object, got type=${typeof e}`);return e}function de(e,t){if(typeof e!="function")throw new TypeError(`"${t}" is invalid: expected function, got ${typeof e}`);return e}var tr=Pr,It=(...e)=>Wn(...e),Pe=e=>Or(e),Jt=Rr,pe=e=>io(e),kr=BigInt(0),lo=BigInt(1),Tu=e=>e?`"${e}" `:"";function wt(e,t=""){if(typeof e!="boolean")throw new TypeError(Tu(t)+"expected boolean, got type="+typeof e);return e}function Kr(e){if(typeof e=="bigint"){if(!Xt(e))throw new RangeError("positive bigint expected, got "+e)}else ss(e);return e}function Ft(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(r+"expected number, got type="+typeof e)}if(!Number.isSafeInteger(e)){let r=t&&`"${t}" `;throw new RangeError(r+"expected safe integer, got "+e)}}function er(e){let t=Kr(e).toString(16);return t.length&1?"0"+t:t}function po(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?kr:BigInt("0x"+e)}function Pt(e){return po(Pr(e))}function me(e){return po(Pr(rr(Bt(e)).reverse()))}function Mr(e,t){if(Mt(t),t===0)throw new Error("zero output length is invalid");e=Kr(e);let r=t*2,n=e.toString(16);if(n.length>r)throw new RangeError("number is too large");return Or(n.padStart(r,"0"))}function is(e,t){return Mr(e,t).reverse()}function rr(e){return Uint8Array.from(V(e))}function Xt(e){return typeof e=="bigint"&&kr<=e}function os(e,t,r){return Xt(e)&&Xt(t)&&Xt(r)&&t<=e&&e<r}function Oe(e,t,r,n){if(!os(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function ke(e){if(e<kr)throw new Error("expected non-negative bigint, got "+e);return e===kr?0:e.toString(2).length}var nr=e=>(Ft(e,"n"),(lo<<BigInt(e))-lo);function mo(e,t,r){if(Mt(e,"hashLen"),Mt(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=E=>new Uint8Array(E),s=Uint8Array.of(),i=Uint8Array.of(0),o=Uint8Array.of(1),a=1e3,c=n(e),u=n(e),f=0,d=()=>{c.fill(1),u.fill(0),f=0},l=(...E)=>r(u,It(c,...E)),h=(E=s)=>{u=l(i,E),c=l(),E.length!==0&&(u=l(o,E),c=l())},b=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let E=0,w=[];for(;E<t;){c=l();let v=c.slice();w.push(v),E+=c.length}return It(...w)};return(E,w)=>{d(),h(E);let v;for(;(v=w(b()))===void 0;)h();return d(),v}}function xt(e,t={},r={},n="object"){Wt(e,n),Wt(t,"fields"),Wt(r,"optFields");function s(o,a,c){let u=n==="object"?`param "${String(o)}"`:`"${n}.${String(o)}"`,f=e[o];if(!Object.hasOwn(e,o)&&(c?f!==void 0:a!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&f===void 0)return;let d=typeof f;if(d!==a||f===null)throw new TypeError(`${u} is invalid: expected ${a}, got ${d}`)}let i=(o,a)=>Object.entries(o).forEach(([c,u])=>s(c,u,a));i(t,!1),i(r,!0)}var ut=BigInt(0),$=BigInt(1),Qt=BigInt(2),go=BigInt(3),as=BigInt(4),wo=BigInt(5),Lu=BigInt(7),xo=BigInt(8),Ru=BigInt(9),_u=BigInt(15),Eo=BigInt(16),Du=BigInt("0x10000000000000000");function nt(e,t){if(t<=ut)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=ut?r:t+r}function So(e,t,r){if(r<=$)throw new Error("pow: expected modulus > 1, got "+r);if(typeof t!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof t);if(t<ut)throw new Error("invalid exponent, negatives unsupported");if(t===ut)return $;if(t===$)return e;let n=e%r;if(n<ut&&(n+=r),t<Du){let a=$;for(;t>ut;)t&$&&(a=a*n%r),n=n*n%r,t>>=$;return a}let s=[];for(;t>ut;)s.push(Number(t&_u)),t>>=as;let i=new Array(16);i[0]=$,i[1]=n;for(let a=2;a<16;a++)i[a]=i[a-1]*n%r;let o=i[s[s.length-1]];for(let a=s.length-2;a>=0;a--){o=o*o%r,o=o*o%r,o=o*o%r,o=o*o%r;let c=s[a];c!==0&&(o=o*i[c]%r)}return o}function Q(e,t,r){if(r<=$)throw new Error("pow2: expected modulus > 1, got "+r);if(t<ut)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >ut;)n*=n,n%=r;return n}function bo(e,t){if(e===ut)throw new Error("invert: expected non-zero number");if(t<=$)throw new Error("invert: expected modulus > 1, got "+t);let r=nt(e,t),n=t,s=ut,i=$;for(;r!==ut;){let a=n/r,c=n-r*a,u=s-i*a;n=r,r=c,s=i,i=u}if(n!==$)throw new Error("invert: does not exist");return nt(s,t)}function vo(e,t){if(t<=$)throw new Error("invertCt: expected prime modulus > 1, got "+t);let r=nt(e,t);if(r===ut)throw new Error("invertCt: expected non-zero number");let n=So(r,t-Qt,t);if(nt(r*n,t)!==$)throw new Error("invertCt: does not exist");return n}function cs(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function us(e,t){if((e&$)===ut)throw new Error(t+": expected odd modulus, got "+e)}function Ao(e,t){let r=e,n=(r.ORDER+$)/as,s=r.pow(t,n);return cs(r,s,t),s}function Cu(e,t){let r=e,n=(r.ORDER-wo)/xo,s=r.mul(t,Qt),i=r.pow(s,n),o=r.mul(t,i),a=r.mul(r.mul(o,Qt),i),c=r.mul(o,r.sub(a,r.ONE));return cs(r,c,t),c}function Pu(e){let t=Ke(e),r=Bo(e),n=r(t,t.neg(t.ONE)),s=r(t,n),i=r(t,t.neg(n)),o=(e+Lu)/Eo;return((a,c)=>{let u=a,f=u.pow(c,o),d=u.mul(f,n),l=u.mul(f,s),h=u.mul(f,i),b=u.eql(u.sqr(d),c),g=u.eql(u.sqr(l),c);f=u.cmov(f,d,b),d=u.cmov(h,l,g);let E=u.eql(u.sqr(d),c),w=u.cmov(f,d,E);return cs(u,w,c),w})}function Bo(e){if(e<go)throw new Error("sqrt is not defined for small field");us(e,"tonelliShanks");let t=e-$,r=0;for(;t%Qt===ut;)t/=Qt,r++;let n=Qt,s=Ke(e);for(;sr(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Ao;let i=s.pow(n,t),o=(t+$)/Qt;return function(c,u){let f=c;if(f.is0(u))return u;if(sr(f,u)!==1)throw new Error("Cannot find square root");let d=r,l=f.mul(f.ONE,i),h=f.pow(u,t),b=f.pow(u,o);for(;!f.eql(h,f.ONE);){if(f.is0(h))throw new Error("Cannot find square root: probably non-prime P");let g=1,E=f.sqr(h);for(;!f.eql(E,f.ONE);)if(g++,E=f.sqr(E),g===d)throw new Error("Cannot find square root");let w=$<<BigInt(d-g-1),v=f.pow(l,w);d=g,l=f.sqr(v),h=f.mul(h,l),b=f.mul(b,v)}return b}}function Ou(e){return us(e,"Fp.sqrt"),e%as===go?Ao:e%xo===wo?Cu:e%Eo===Ru?Pu(e):Bo(e)}var Io=(e,t)=>(nt(e,t)&$)===$,ku=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ne(e){if(Wt(e,"field"),typeof e.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof e.ORDER);Ft(e.BYTES,"BYTES"),Ft(e.BITS,"BITS");for(let t of ku)de(e[t],"field."+t);if(e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=$)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function Ur(e,t,r=!1){Ne(e),Nr(t,"nums"),wt(r,"passZero");let n=e,s=new Array(t.length).fill(r?n.ZERO:void 0),i=t.reduce((a,c,u)=>n.is0(c)?a:(s[u]=a,n.mul(a,c)),n.ONE),o=n.inv(i);return t.reduceRight((a,c,u)=>n.is0(c)?a:(s[u]=n.mul(a,s[u]),n.mul(a,c)),o),s}function sr(e,t){Ne(e);let r=e;us(r.ORDER,"FpLegendre");let n=(r.ORDER-$)/Qt,s=r.pow(t,n),i=r.eql(s,r.ONE),o=r.eql(s,r.ZERO),a=r.eql(s,r.neg(r.ONE));if(!i&&!o&&!a)throw new Error("invalid Legendre symbol result");return i?1:o?0:-1}function Nu(e,t){if(t!==void 0&&ss(t),e<=ut)throw new Error("invalid n length: expected positive n, got "+e);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let r=ke(e);if(t!==void 0&&t<r)throw new Error(`invalid n length: expected nBitLength (${t}) >= bitLen(n) (${r})`);let n=t!==void 0?t:r,s=Math.ceil(n/8);return{nBitLength:n,nByteLength:s}}var yo=new WeakMap,Fr=class{ORDER;BITS;BYTES;isLE;ZERO=ut;ONE=$;_lengths;_mod;constructor(t,r={}){if(t<=$)throw new Error("invalid field: expected ORDER > 1, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:s,nByteLength:i}=Nu(t,n);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=s,this.BYTES=i,Object.freeze(this)}create(t){return nt(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return ut<=t&&t<this.ORDER}is0(t){return t===ut}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&$)===$}neg(t){return nt(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return nt(t*t,this.ORDER)}add(t,r){return nt(t+r,this.ORDER)}sub(t,r){return nt(t-r,this.ORDER)}mul(t,r){return nt(t*r,this.ORDER)}pow(t,r){return So(t,r,this.ORDER)}div(t,r){return nt(t*bo(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 bo(t,this.ORDER)}sqrt(t){let r=yo.get(this);return r||yo.set(this,r=Ou(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?is(t,this.BYTES):Mr(t,this.BYTES)}fromBytes(t,r=!1){V(t);let{_lengths:n,BYTES:s,isLE:i,ORDER:o,_mod:a}=this;if(n){if(t.length<1||!n.includes(t.length)||t.length>s)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let u=new Uint8Array(s);u.set(t,i?0:u.length-t.length),t=u}if(t.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+t.length);let c=i?me(t):Pt(t);if(a&&(c=nt(c,o)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return Ur(this,t,!0)}cmov(t,r,n){return wt(n,"condition"),n?r:t}};function Ke(e,t={}){return Object.freeze(Fr.prototype),new Fr(e,t)}function To(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=$)throw new Error("field order must be greater than 1");let t=ke(e-$);return Math.ceil(t/8)}function qr(e){let t=To(e);return t+Math.ceil(t/2)}function zr(e,t,r=!1){V(e);let n=e.length,s=To(t),i=Math.max(qr(t),16);if(n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let o=r?me(e):Pt(e),a=nt(o,t-$)+$;return r?is(a,s):Mr(a,s)}var hs=BigInt(0),ir=BigInt(1),Ku=BigInt(4),fs=16,Lo=128,Mu=5,Ro=2**31;function te(e){let t=e;if(typeof t!="function")throw new TypeError('"Point" expected constructor, got type='+typeof e);de(t.fromAffine,"Point.fromAffine"),de(t.fromBytes,"Point.fromBytes"),de(t.fromHex,"Point.fromHex"),Wt(t.BASE,"Point.BASE"),Wt(t.ZERO,"Point.ZERO"),Ne(t.Fp),Ne(t.Fn)}function Hr(e,t){te(e),Do(t,e);let r=Ur(e.Fp,t.map(n=>n.Z));return t.map((n,s)=>e.fromAffine(n.toAffine(r[s])))}function Fu(e,t,r=1){if(!Number.isSafeInteger(e)||e<r||e>t)throw new Error("invalid window size, expected ["+r+".."+t+"], got W="+e)}function Uu(e,t){let r=e*(4*t+128);if(r>Ro)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+Ro/2**20+" MiB")}function ds(e,t){if(e!==void 0){de(e,"randomBytes");try{let r=e(t);if(!Jt(r)||r.length!==t)return}catch{return}return e}}function Do(e,t){Nr(e,"points"),e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function qu(e,t,r){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((n,s)=>{if(!(r===void 0?t.isValid(n):Xt(n)&&n<r))throw new Error("invalid scalar at index "+s)})}var Co=new WeakMap;function ls(e){return Co.get(e)||1}function zu(e,t){let r=e.double(),n=[e];for(let s=1;s<t;s++)n.push(n[s-1].add(r));return n}function Hu(e,t){let r=2**t,n=r/2,s=BigInt(r-1),i=[];for(;e>hs;){let o=0;e&ir&&(o=Number(e&s),o>=n&&(o-=r),e-=BigInt(o)),i.push(o),e>>=ir}return i}function Vu(e,t,r){let n=2**t,s=n/2,i=BigInt(n-1),o=BigInt(t),a=[];for(let c=0;c<r;c++){let u=Number(e&i);e>>=o,u>s&&(u-=n,e+=ir),a.push(u)}if(e!==hs)throw new Error("invalid wnaf");return a}function $u(e,t,r){let n=0;for(let i of r)n=Math.max(n,i.length);let s=e;for(let i=n-1;i>=0;i--){i!==n-1&&(s=s.double());for(let o=0;o<r.length;o++){let a=r[o][i];if(a){let c=t[o][Math.abs(a)-1>>1];s=s.add(a<0?c.negate():c)}}}return s}var Me=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(t,r){te(t),this.randomBytes=ds(r,fs),this.Point=t,this.BASE=t.BASE,this.ZERO=t.ZERO,this.bits=t.Fn.BITS}buildWnafTable(t,r,n){let s=Math.ceil(n/r)+1,i=2**(r-1),o=[],a=t;for(let c=0;c<s;c++){let u=a;for(let f=0;f<i;f++)o.push(u),u=u.add(a);a=o[o.length-1].double()}return{W:r,bits:n,windows:s,comp:o}}wnafCachedCT(t,r){let{W:n,windows:s,comp:i}=t,o=2**(n-1),a=Vu(r,n,s),c=this.ZERO,u=this.BASE;for(let f=0;f<s;f++){let d=a[f],l=f*o,h=Math.abs(d)-1,b=i[l];for(let E=1;E<o;E++)b=E===h?i[l+E]:b;let g=b.negate();d===0?u=u.add(i[l]):c=c.add(d<0?g:b)}return{p:c,f:u}}getWnafPrecomputes(t,r,n,s){let i=this.wnafPrecomputes.get(r),o=i?.find(a=>a.W===t&&a.bits===n);return o||(o=this.buildWnafTable(r,t,n),typeof s=="function"&&(o={...o,comp:s(o.comp)}),i||(i=[],this.wnafPrecomputes.set(r,i)),i.push(o)),o}assertPoint(t){if(!(t instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof t)}validateMulInput(t,r){if(this.assertPoint(t),!os(r,ir,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(t,r,n,s){let i=ls(t);return i===1?this.fixedWindowCT(t,r,n):this.wnafCachedCT(this.getWnafPrecomputes(i,t,n,s),r)}mulCT(t,r,n){return this.validateMulInput(t,r),this.runCT(t,r,this.bits,n)}mulCTBlinded(t,r,n){if(this.validateMulInput(t,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let s=this.Point.Fn.BITS+Lo,i=this.randomBytes(fs);if(!Jt(i)||i.length!==fs)throw new Error("randomBytes returned invalid byte array");i[0]=i[0]&63|128;let o=r+Pt(i)*this.Point.Fn.ORDER;return this.runCT(t,o,s,n)}fixedWindowCT(t,r,n){let s=Mu,i=1<<s,o=nr(s),a=new Array(i);a[0]=this.ZERO;for(let f=1;f<i;f++)a[f]=a[f-1].add(t);let c=Math.ceil(n/s),u=this.ZERO;for(let f=c-1;f>=0;f--){if(f!==c-1)for(let h=0;h<s;h++)u=u.double();let d=Number(r>>BigInt(f*s)&o),l=a[0];for(let h=1;h<i;h++)l=h===d?a[h]:l;u=u.add(l)}return{p:u,f:u}}shouldBlind(t,r){return this.randomBytes===void 0?!1:r===ir?!0:t!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(t,r,n,s){return this.shouldBlind(t,n)?this.mulCTBlinded(t,r,s):this.mulCT(t,r,s)}mulUnsafe(t,r,n){if(this.assertPoint(t),!Xt(r))throw new Error("invalid scalar");let s=ls(t);if(s===1||r>=this.Point.Fn.ORDER)return Vr(this.Point,[t],[r],!0);let i=this.getWnafPrecomputes(s,t,this.bits,n);return this.wnafCachedCT(i,r).p}setWindowSize(t,r){this.assertPoint(t),Fu(r,this.bits);let n=Math.ceil((this.bits+Lo)/r)+1;Uu(n*2**(r-1),this.Point.Fp.BYTES),Co.set(t,r),this.wnafPrecomputes.delete(t)}hasWindowSize(t){return ls(t)!==1}};function Vr(e,t,r,n=!1){if(te(e),Do(t,e),wt(n,"allowOversized"),qu(r,e.Fn,n?e.Fn.ORDER**Ku:void 0),t.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let s=t.map(o=>zu(o,4)),i=r.map(o=>Hu(o,4));return $u(e.ZERO,s,i)}function _o(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Ne(t),t}else return Ke(e,{isLE:r})}function $r(e,t,r={},n){if(e!=="weierstrass"&&e!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);xt(r);for(let c of["p","n","h"]){let u=t[c];if(!(Xt(u)&&u!==hs))throw new Error(`CURVE.${c} must be positive bigint`)}let s=_o(t.p,r.Fp,n),i=_o(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of a)if(!s.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:s,Fn:i}}function jr(e,t){return function(n){let s=e(n);return{secretKey:s,publicKey:t(s)}}}var Zr=BigInt(0),Yr=BigInt(1),Gr=BigInt(2),ju=BigInt(4),Po=BigInt(8);function Zu(e,t,r,n){let s=e.sqr(r),i=e.sqr(n),o=e.add(e.mul(t.a,s),i),a=e.add(e.ONE,e.mul(t.d,e.mul(s,i)));return e.eql(o,a)}function Oo(e,t={}){xt(t,{},{},"extraOpts");let r=t,n=$r("edwards",e,r,r.FpFnLE),{Fp:s,Fn:i}=n,o=n.CURVE,{h:a}=o;if(sr(s,o.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(sr(s,o.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");xt(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?pe:r.randomBytes,u=Gr<<BigInt(s.BYTES*8)-Yr;function f(v){if(!s.isOdd)throw new Error("Field does not have .isOdd()");return s.isOdd(v)}let d=r.uvRatio===void 0?(v,y)=>{try{return{isValid:!0,value:s.sqrt(s.div(v,y))}}catch{return{isValid:!1,value:Zr}}}:r.uvRatio;if(!Zu(s,o,o.Gx,o.Gy))throw new Error("bad curve params: generator point");let l=s.eql(o.a,s.neg(s.ONE))?v=>s.neg(v):s.eql(o.a,s.ONE)?v=>v:v=>s.mul(o.a,v);function h(v,y,A=!1){let B=A?Yr:Zr;return Oe("coordinate "+v,y,B,u),y}function b(v){if(!(v instanceof g))throw new Error("EdwardsPoint expected")}class g{static BASE=new g(o.Gx,o.Gy,s.ONE,s.mul(o.Gx,o.Gy));static ZERO=new g(s.ZERO,s.ONE,s.ONE,s.ZERO);static Fp=s;static Fn=i;X;Y;Z;T;constructor(y,A,B,O){this.X=h("x",y),this.Y=h("y",A),this.Z=h("z",B,!0),this.T=h("t",O),Object.freeze(this)}static CURVE(){return o}static fromAffine(y){if(y instanceof g)throw new Error("extended point not allowed");let{x:A,y:B}=y||{};return h("x",A),h("y",B),new g(A,B,s.ONE,s.mul(A,B))}static fromBytes(y,A=!1){let B=s.BYTES,{a:O,d:K}=o;y=rr(V(y,B,"point")),wt(A,"zip215");let k=rr(y),_=y[B-1];k[B-1]=_&-129;let C=me(k),q=A?u:s.ORDER;Oe("point.y",C,Zr,q);let U=s.sqr(C),G=s.sub(U,s.ONE),T=s.sub(s.mulN(K,U),O),{isValid:M,value:F}=d(G,T);if(!M)throw new Error("bad point: invalid y coordinate");let D=f(F),W=(_&128)!==0;if(!A&&s.is0(F)&&W)throw new Error("bad point: x=0 and x_0=1");return W!==D&&(F=s.neg(F)),g.fromAffine({x:F,y:C})}static fromHex(y,A=!1){return g.fromBytes(Pe(y),A)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=6,A=!0){return w.setWindowSize(this,y),A||this.multiply(Gr),this}assertValidity(){let y=this,{a:A,d:B}=o;if(y.is0())throw new Error("bad point: ZERO");let{X:O,Y:K,Z:k,T:_}=y,C=s.sqr(O),q=s.sqr(K),U=s.sqr(k),G=s.sqr(U),T=s.mul(C,A),M=s.mul(s.add(T,q),U),F=s.add(G,s.mul(B,s.mul(C,q)));if(!s.eql(M,F))throw new Error("bad point: equation left != right (1)");let D=s.mul(O,K),W=s.mul(k,_);if(!s.eql(D,W))throw new Error("bad point: equation left != right (2)")}equals(y){b(y);let{X:A,Y:B,Z:O}=this,{X:K,Y:k,Z:_}=y,C=s.mul(A,_),q=s.mul(K,O),U=s.mul(B,_),G=s.mul(k,O);return s.eql(C,q)&&s.eql(U,G)}is0(){return this.equals(g.ZERO)}negate(){return new g(s.neg(this.X),this.Y,this.Z,s.neg(this.T))}double(){let{X:y,Y:A,Z:B}=this,O=s.sqr(y),K=s.sqr(A),k=s.mul(s.sqr(B),Gr),_=l(O),C=s.addN(y,A),q=s.sub(s.subN(s.sqr(C),O),K),U=s.addN(_,K),G=s.subN(U,k),T=s.subN(_,K),M=s.mul(q,G),F=s.mul(U,T),D=s.mul(q,T),W=s.mul(G,U);return new g(M,F,W,D)}add(y){b(y);let{d:A}=o,{X:B,Y:O,Z:K,T:k}=this,{X:_,Y:C,Z:q,T:U}=y,G=s.mul(B,_),T=s.mul(O,C),M=s.mul(s.mulN(k,A),U),F=s.mul(K,q),D=s.sub(s.subN(s.mulN(s.addN(B,O),s.addN(_,C)),G),T),W=s.subN(F,M),tt=s.addN(F,M),S=s.sub(T,l(G)),p=s.mul(D,W),m=s.mul(tt,S),x=s.mul(D,S),I=s.mul(W,tt);return new g(p,m,I,x)}subtract(y){return b(y),this.add(y.negate())}multiply(y){if(!i.isValidNot0(y))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:A,f:B}=w.mulSecret(this,y,a,E);return E([A,B])[0]}multiplyUnsafe(y){if(!i.isValid(y))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return y===Zr?g.ZERO:this.is0()||y===Yr?this:w.mulUnsafe(this,y,E)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return w.mulUnsafe(this,o.n).is0()}toAffine(y){let A=this,B=y;if(B!=null&&typeof B!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof B);let{X:O,Y:K,Z:k}=A,_=A.is0();B==null&&(B=_?s.create(Po):s.inv(k));let C=s.mul(O,B),q=s.mul(K,B),U=s.mul(k,B);if(_)return{x:s.ZERO,y:s.ONE};if(!s.eql(U,s.ONE))throw new Error("invZ was invalid");return{x:C,y:q}}clearCofactor(){return a===Yr?this:a===Gr?this.double():a===ju?this.double().double():a===Po?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:y,y:A}=this.toAffine(),B=s.toBytes(A);return B[B.length-1]|=f(y)?128:0,B}toHex(){return tr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let E=v=>Hr(g,v),w=new Me(g,c);return w.bits>=6&&g.BASE.precompute(6),Object.freeze(g.prototype),Object.freeze(g),g}function ko(e,t,r={}){if(te(e),typeof t!="function")throw new Error('"hash" function param is required');let n=t,s=r;xt(s,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:i}=s,{BASE:o,Fp:a,Fn:c}=e,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(Ft(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let d=s.randomBytes===void 0?pe:s.randomBytes,l=s.toMontgomery,h=s.toMontgomerySecret,b=s.adjustScalarBytes===void 0?T=>T:s.adjustScalarBytes,g=s.domain===void 0?(T,M,F)=>{if(wt(F,"phflag"),M.length||F)throw new Error("Contexts/pre-hash are not supported");return T}:s.domain;function E(T){return c.create(me(T))}function w(T){let M=_.secretKey;V(T,_.secretKey,"secretKey");let F=V(n(T),2*M,"hashedSecretKey"),D=b(F.slice(0,M)),W=F.slice(M,2*M),tt=E(D);return{head:D,prefix:W,scalar:tt}}function v(T){let{head:M,prefix:F,scalar:D}=w(T),W=o.multiply(D),tt=W.toBytes();return{head:M,prefix:F,scalar:D,point:W,pointBytes:tt}}function y(T){return v(T).pointBytes}function A(T=Uint8Array.of(),...M){let F=It(...M);return E(n(g(F,V(T,void 0,"context"),!!i)))}function B(T,M,F={}){xt(F,{},{},"options"),T=rr(V(T,void 0,"message")),i&&(T=i(T));let{prefix:D,scalar:W,pointBytes:tt}=v(M),S=A(F.context,D,T),p=o.multiply(S).toBytes(),m=A(F.context,p,tt,T),x=c.create(S+m*W);if(!c.isValid(x))throw new Error("sign failed: invalid s");let I=It(p,c.toBytes(x));return V(I,_.signature,"result")}let O={zip215:s.zip215};function K(T,M,F,D=O){xt(D);let{context:W}=D,tt=D.zip215===void 0?!!O.zip215:D.zip215,S=_.signature;T=V(T,S,"signature"),M=V(M,void 0,"message"),F=V(F,_.publicKey,"publicKey"),tt!==void 0&&wt(tt,"zip215"),i&&(M=i(M));let p=S/2,m=T.subarray(0,p),x=me(T.subarray(p,S)),I,L,R;try{I=e.fromBytes(F,tt),L=e.fromBytes(m,tt),R=o.multiplyUnsafe(x)}catch{return!1}if(!tt&&I.isSmallOrder())return!1;let P=A(W,m,F,M);return L.add(I.multiplyUnsafe(P)).subtract(R).clearCofactor().is0()}let k=a.BYTES,_={secretKey:k,publicKey:k,signature:2*k,seed:k};function C(T){return T=T===void 0?d(_.seed):T,V(T,_.seed,"seed")}function q(T){return Jt(T)&&T.length===_.secretKey}function U(T,M){try{return!!e.fromBytes(T,M===void 0?O.zip215:M)}catch{return!1}}let G={getExtendedPublicKey:v,randomSecretKey:C,isValidSecretKey:q,isValidPublicKey:U,toMontgomery(T){if(l===void 0)throw new Error("Montgomery conversion is not supported for this curve");return l(e.fromBytes(T))},toMontgomerySecret(T){if(h===void 0)throw new Error("Montgomery conversion is not supported for this curve");return h(T)}};return Object.freeze(_),Object.freeze(G),Object.freeze({keygen:jr(C,y),getPublicKey:y,sign:B,verify:K,utils:G,Point:e,lengths:_})}var ps=BigInt(1),No=BigInt(2);var Yu=BigInt(5),Gu=BigInt(8),ms=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Wu={p:ms,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Gu,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Xu(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),s=BigInt(80),i=ms,a=e*e%i*e%i,c=Q(a,No,i)*a%i,u=Q(c,ps,i)*e%i,f=Q(u,Yu,i)*u%i,d=Q(f,t,i)*f%i,l=Q(d,r,i)*d%i,h=Q(l,n,i)*l%i,b=Q(h,s,i)*h%i,g=Q(b,s,i)*h%i,E=Q(g,t,i)*f%i;return{pow_p_5_8:Q(E,No,i)*e%i,b2:a}}function Fo(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Ko=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Ju(e,t){let r=ms,n=nt(t*t*t,r),s=nt(n*n*t,r),i=Xu(e*s).pow_p_5_8,o=nt(e*n*i,r),a=nt(t*o*o,r),c=o,u=nt(o*Ko,r),f=a===e,d=a===nt(-e,r),l=a===nt(-e*Ko,r);return f&&(o=c),(d||l)&&(o=u),Io(o,r)&&(o=nt(-o,r)),{isValid:f||d,value:o}}var bs=Oo(Wu,{uvRatio:Ju}),Mo=bs.Fp;function Qu(e){let{y:t}=e;return Mo.toBytes(Mo.div(ps+t,ps-t))}function tf(e){let t=bs.Fp.BYTES;return Bt(e,t),Fo(ns(e.subarray(0,t))).subarray(0,t)}function ef(e){return ko(bs,ns,Object.assign({adjustScalarBytes:Fo,toMontgomery:Qu,toMontgomerySecret:tf,zip215:!0},e))}var Uo=ef({});var or=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Wr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Tt={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Wr("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 Xr=32;var ys,rf=(async()=>{try{return await Tt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function nf(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Tt.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Tt.get().subtle.verify({name:"Ed25519"},n,At(t),At(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function sf(e,t,r){return Uo.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function qo(e,t,r){return ys==null&&(ys=await rf),ys?nf(e,t,r):sf(e,t,r)}function Jr(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Qr=class{type="Ed25519";raw;constructor(t){this.raw=gs(t,Xr)}toMultihash(){return Lt.digest(Kt(this))}toCID(){return ht.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let s=qo(this.raw,r,t);return Jr(s)?s.then(i=>(n?.signal?.throwIfAborted(),i)):s}};function ws(e){return e=gs(e,Xr),new Qr(e)}function gs(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new et(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var af=Math.pow(2,7),cf=Math.pow(2,14),uf=Math.pow(2,21),xs=Math.pow(2,28),Es=Math.pow(2,35),Ss=Math.pow(2,42),vs=Math.pow(2,49),j=128,dt=127;function Ut(e){if(e<af)return 1;if(e<cf)return 2;if(e<uf)return 3;if(e<xs)return 4;if(e<Es)return 5;if(e<Ss)return 6;if(e<vs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function As(e,t,r=0){switch(Ut(e)){case 8:t[r++]=e&255|j,e/=128;case 7:t[r++]=e&255|j,e/=128;case 6:t[r++]=e&255|j,e/=128;case 5:t[r++]=e&255|j,e/=128;case 4:t[r++]=e&255|j,e>>>=7;case 3:t[r++]=e&255|j,e>>>=7;case 2:t[r++]=e&255|j,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function ff(e,t,r=0){switch(Ut(e)){case 8:t.set(r++,e&255|j),e/=128;case 7:t.set(r++,e&255|j),e/=128;case 6:t.set(r++,e&255|j),e/=128;case 5:t.set(r++,e&255|j),e/=128;case 4:t.set(r++,e&255|j),e>>>=7;case 3:t.set(r++,e&255|j),e>>>=7;case 2:t.set(r++,e&255|j),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function Bs(e,t){let r=e[t],n=0;if(n+=r&dt,r<j||(r=e[t+1],n+=(r&dt)<<7,r<j)||(r=e[t+2],n+=(r&dt)<<14,r<j)||(r=e[t+3],n+=(r&dt)<<21,r<j)||(r=e[t+4],n+=(r&dt)*xs,r<j)||(r=e[t+5],n+=(r&dt)*Es,r<j)||(r=e[t+6],n+=(r&dt)*Ss,r<j)||(r=e[t+7],n+=(r&dt)*vs,r<j))return n;throw new RangeError("Could not decode varint")}function lf(e,t){let r=e.get(t),n=0;if(n+=r&dt,r<j||(r=e.get(t+1),n+=(r&dt)<<7,r<j)||(r=e.get(t+2),n+=(r&dt)<<14,r<j)||(r=e.get(t+3),n+=(r&dt)<<21,r<j)||(r=e.get(t+4),n+=(r&dt)*xs,r<j)||(r=e.get(t+5),n+=(r&dt)*Es,r<j)||(r=e.get(t+6),n+=(r&dt)*Ss,r<j)||(r=e.get(t+7),n+=(r&dt)*vs,r<j))return n;throw new RangeError("Could not decode varint")}function Ho(e,t,r=0){return t==null&&(t=yt(Ut(e))),t instanceof Uint8Array?As(e,t,r):ff(e,t,r)}function Vo(e,t=0){return e instanceof Uint8Array?Bs(e,t):lf(e,t)}var Is=new Float32Array([-0]),ee=new Uint8Array(Is.buffer);function $o(e,t,r){Is[0]=e,t[r]=ee[0],t[r+1]=ee[1],t[r+2]=ee[2],t[r+3]=ee[3]}function jo(e,t){return ee[0]=e[t],ee[1]=e[t+1],ee[2]=e[t+2],ee[3]=e[t+3],Is[0]}var Ts=new Float64Array([-0]),pt=new Uint8Array(Ts.buffer);function Zo(e,t,r){Ts[0]=e,t[r]=pt[0],t[r+1]=pt[1],t[r+2]=pt[2],t[r+3]=pt[3],t[r+4]=pt[4],t[r+5]=pt[5],t[r+6]=pt[6],t[r+7]=pt[7]}function Yo(e,t){return pt[0]=e[t],pt[1]=e[t+1],pt[2]=e[t+2],pt[3]=e[t+3],pt[4]=e[t+4],pt[5]=e[t+5],pt[6]=e[t+6],pt[7]=e[t+7],Ts[0]}var df=BigInt(Number.MAX_SAFE_INTEGER),pf=BigInt(Number.MIN_SAFE_INTEGER),Et=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 be;if(t<df&&t>pf)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,s=t-(n<<32n);return r&&(n=~n|0n,s=~s|0n,++s>Go&&(s=0n,++n>Go&&(n=0n))),new e(Number(s),Number(n))}static fromNumber(t){if(t===0)return be;let r=t<0;r&&(t=-t);let n=t>>>0,s=(t-n)/4294967296>>>0;return r&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new e(n,s)}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):be}},be=new Et(0,0);be.toBigInt=function(){return 0n};be.zzEncode=be.zzDecode=function(){return this};be.length=function(){return 1};var Go=4294967296n;function Wo(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 Xo(e,t,r){if(r-t<1)return"";let s,i=[],o=0,a;for(;t<r;)a=e[t++],a<128?i[o++]=a:a>191&&a<224?i[o++]=(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,i[o++]=55296+(a>>10),i[o++]=56320+(a&1023)):i[o++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,o>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,i)),o=0);return s!=null?(o>0&&s.push(String.fromCharCode.apply(String,i.slice(0,o))),s.join("")):String.fromCharCode.apply(String,i.slice(0,o))}function Ls(e,t,r){let n=r,s,i;for(let o=0;o<e.length;++o)s=e.charCodeAt(o),s<128?t[r++]=s:s<2048?(t[r++]=s>>6|192,t[r++]=s&63|128):(s&64512)===55296&&((i=e.charCodeAt(o+1))&64512)===56320?(s=65536+((s&1023)<<10)+(i&1023),++o,t[r++]=s>>18|240,t[r++]=s>>12&63|128,t[r++]=s>>6&63|128,t[r++]=s&63|128):(t[r++]=s>>12|224,t[r++]=s>>6&63|128,t[r++]=s&63|128);return r-n}function _t(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function tn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Rs=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=At(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,_t(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 _t(this,4);return tn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw _t(this,4);return tn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw _t(this,4);let t=jo(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw _t(this,4);let t=Yo(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 _t(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Xo(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw _t(this,t);this.pos+=t}else do if(this.pos>=this.len)throw _t(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 Et(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 _t(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 _t(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 _t(this,8);let t=tn(this.buf,this.pos+=4),r=tn(this.buf,this.pos+=4);return new Et(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Bs(this.buf,this.pos);return this.pos+=Ut(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function ar(e){return new Rs(e instanceof Uint8Array?e:e.subarray())}function re(e,t,r){let n=ar(e);return t.decode(n,void 0,r)}function _s(e){let t=e??8192,r=t>>>1,n,s=t;return function(o){if(o<1||o>r)return yt(o);s+o>t&&(n=yt(t),s=0);let a=n.subarray(s,s+=o);return(s&7)!==0&&(s=(s|7)+1),a}}var ye=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Ds(){}var Ps=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},mf=_s();function bf(e){return globalThis.Buffer!=null?yt(e):mf(e)}var ur=class{len;head;tail;states;constructor(){this.len=0,this.head=new ye(Ds,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ye(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Os((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(en,10,Et.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=Et.fromBigInt(t);return this._push(en,r.length(),r)}uint64Number(t){return this._push(As,Ut(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=Et.fromBigInt(t).zzEncode();return this._push(en,r.length(),r)}sint64Number(t){let r=Et.fromNumber(t).zzEncode();return this._push(en,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Cs,1,t?1:0)}fixed32(t){return this._push(cr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=Et.fromBigInt(t);return this._push(cr,4,r.lo)._push(cr,4,r.hi)}fixed64Number(t){let r=Et.fromNumber(t);return this._push(cr,4,r.lo)._push(cr,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($o,4,t)}double(t){return this._push(Zo,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Cs,1,0):this.uint32(r)._push(gf,r,t)}string(t){let r=Wo(t);return r!==0?this.uint32(r)._push(Ls,r,t):this._push(Cs,1,0)}fork(){return this.states=new Ps(this),this.head=this.tail=new ye(Ds,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 ye(Ds,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=bf(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Cs(e,t,r){t[r]=e&255}function yf(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Os=class extends ye{next;constructor(t,r){super(yf,t,r),this.next=void 0}};function en(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function cr(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 gf(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(ur.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(wf,t,e),this},ur.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(xf,t,e),this});function wf(e,t,r){t.set(e,r)}function xf(e,t,r){e.length<40?Ls(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(Y(e),r)}function ks(){return new ur}function ne(e,t){let r=ks();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*se(e,t,r){let n=ar(e);yield*t.stream(n,void 0,".",r)}var rn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function nn(e,t,r,n,s){return{name:e,type:t,encode:r,decode:n,stream:s}}function Ns(e){function t(i){if(e[i.toString()]==null)throw new Error("Invalid enum value");return e[i]}let r=function(o,a){let c=t(o);a.int32(c)},n=function(o){let a=o.int32();return t(a)},s=function*(o,a){};return nn("enum",rn.VARINT,r,n,s)}function ie(e,t,r){return nn("message",rn.LENGTH_DELIMITED,e,t,r)}var ge=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var st;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(st||(st={}));var Ks;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Ks||(Ks={}));(function(e){e.codec=()=>Ns(Ks)})(st||(st={}));var Ot;(function(e){let t;e.codec=()=>(t==null&&(t=ie((i,o,a={})=>{a.lengthDelimited!==!1&&o.fork(),i.Type!=null&&(o.uint32(8),st.codec().encode(i.Type,o)),i.Data!=null&&(o.uint32(18),o.bytes(i.Data)),a.lengthDelimited!==!1&&o.ldelim()},(i,o,a={})=>{let c={},u=o==null?i.len:i.pos+o;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.Type=st.codec().decode(i);break}case 2:{c.Data=i.bytes();break}default:{i.skipType(f&7);break}}}return c},function*(i,o,a,c={}){let u=o==null?i.len:i.pos+o;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:st.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(f&7);break}}}})),t);function r(i){return ne(i,e.codec())}e.encode=r;function n(i,o){return re(i,e.codec(),o)}e.decode=n;function s(i,o){return se(i,e.codec(),o)}e.stream=s})(Ot||(Ot={}));var Ms;(function(e){let t;e.codec=()=>(t==null&&(t=ie((i,o,a={})=>{a.lengthDelimited!==!1&&o.fork(),i.Type!=null&&(o.uint32(8),st.codec().encode(i.Type,o)),i.Data!=null&&(o.uint32(18),o.bytes(i.Data)),a.lengthDelimited!==!1&&o.ldelim()},(i,o,a={})=>{let c={},u=o==null?i.len:i.pos+o;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.Type=st.codec().decode(i);break}case 2:{c.Data=i.bytes();break}default:{i.skipType(f&7);break}}}return c},function*(i,o,a,c={}){let u=o==null?i.len:i.pos+o;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:st.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(f&7);break}}}})),t);function r(i){return ne(i,e.codec())}e.encode=r;function n(i,o){return re(i,e.codec(),o)}e.decode=n;function s(i,o){return se(i,e.codec(),o)}e.stream=s})(Ms||(Ms={}));var lr={};mt(lr,{MAX_RSA_KEY_SIZE:()=>Fs,generateRSAKeyPair:()=>na,jwkToJWKKeyPair:()=>sa,jwkToPkcs1:()=>Af,jwkToPkix:()=>Hs,jwkToRSAPrivateKey:()=>Zs,pkcs1MessageToJwk:()=>qs,pkcs1MessageToRSAPrivateKey:()=>Vs,pkcs1ToJwk:()=>vf,pkcs1ToRSAPrivateKey:()=>ra,pkixMessageToJwk:()=>zs,pkixMessageToRSAPublicKey:()=>js,pkixToJwk:()=>Bf,pkixToRSAPublicKey:()=>$s});var Fe=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=lr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ht.createV1(114,this._multihash)}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,r,n){return ea(this.jwk,r,t,n)}},fr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=lr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}sign(t,r){return ta(this.jwk,t,r)}};var Fs=8192,Us=18,Ef=1062,Sf=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function vf(e){let t=Nt(e);return qs(t)}function qs(e){return{n:Z(e[1],"base64url"),e:Z(e[2],"base64url"),d:Z(e[3],"base64url"),p:Z(e[4],"base64url"),q:Z(e[5],"base64url"),dp:Z(e[6],"base64url"),dq:Z(e[7],"base64url"),qi:Z(e[8],"base64url"),kty:"RSA"}}function Af(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new et("JWK was missing components");return jt([gt(Uint8Array.from([0])),gt(Y(e.n,"base64url")),gt(Y(e.e,"base64url")),gt(Y(e.d,"base64url")),gt(Y(e.p,"base64url")),gt(Y(e.q,"base64url")),gt(Y(e.dp,"base64url")),gt(Y(e.dq,"base64url")),gt(Y(e.qi,"base64url"))]).subarray()}function Bf(e){let t=Nt(e,{offset:0});return zs(t)}function zs(e){let t=Nt(e[1],{offset:0});return{kty:"RSA",n:Z(t[0],"base64url"),e:Z(t[1],"base64url")}}function Hs(e){if(e.n==null||e.e==null)throw new et("JWK was missing components");return jt([Sf,Tr(jt([gt(Y(e.n,"base64url")),gt(Y(e.e,"base64url"))]))]).subarray()}function ra(e){let t=Nt(e);return Vs(t)}function Vs(e){let t=qs(e);return Zs(t)}function $s(e,t){if(e.byteLength>=Ef)throw new ve("Key size is too large");let r=Nt(e,{offset:0});return js(r,e,t)}function js(e,t,r){let n=zs(e);if(r==null){let s=Ce(Ot.encode({Type:st.RSA,Data:t}));r=Dt(Us,s)}return new Fe(n,r)}function Zs(e){if(oa(e)>Fs)throw new et("Key size is too large");let t=sa(e),r=Ce(Ot.encode({Type:st.RSA,Data:Hs(t.publicKey)})),n=Dt(Us,r);return new fr(t.privateKey,new Fe(t.publicKey,n))}async function na(e){if(e>Fs)throw new et("Key size is too large");let t=await ia(e),r=Ce(Ot.encode({Type:st.RSA,Data:Hs(t.publicKey)})),n=Dt(Us,r);return new fr(t.privateKey,new Fe(t.publicKey,n))}function sa(e){if(e==null)throw new et("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function ia(e,t){let r=await Tt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await If(r,t);return{privateKey:n[0],publicKey:n[1]}}async function ta(e,t,r){let n=await Tt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let s=await Tt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,At(t instanceof Uint8Array?t:t.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(s,0,s.byteLength)}async function ea(e,t,r,n){let s=await Tt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await Tt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},s,At(t),At(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),i}async function If(e,t){if(e.privateKey==null||e.publicKey==null)throw new et("Private and public key are required");let r=await Promise.all([Tt.get().subtle.exportKey("jwk",e.privateKey),Tt.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function oa(e){if(e.kty!=="RSA")throw new et("invalid key type");if(e.n==null)throw new et("invalid key modulus");return Y(e.n,"base64url").length*8}var sn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(_r(t),Bt(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,s=new Uint8Array(n);s.set(r.length>n?t.create().update(r).digest():r);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),he(s)}update(t){return De(this),this.iHash.update(t),this}digestInto(t){De(this),Dr(t,this),this.finished=!0;let r=t.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:s,destroyed:i,blockLen:o,outputLen:a,canXOF:c}=this;return t=t,t.finished=s,t.destroyed=i,t.blockLen=o,t.outputLen=a,t.canXOF=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},aa=(()=>{let e=((t,r,n)=>new sn(t,r).update(n).digest());return e.create=(t,r)=>new sn(t,r),e})();var Tf=BigInt(0),Ys=class extends Error{constructor(t=""){super(t)}},qt={Err:Ys,_tlv:{encode:(e,t)=>{let{Err:r}=qt;if(Ft(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(ho(t,"data"),t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,s=er(n);if(s.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?er(s.length/2|128):"";return er(e)+i+s+t},decode(e,t){let{Err:r}=qt;t=V(t,void 0,"DER data");let n=0;if(e<0||e>255)throw new r("tlv.decode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let s=t[n++],i=!!(s&128),o=0;if(!i)o=s;else{let c=s&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)o=o<<8|f;if(n+=c,o<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+o);if(a.length!==o)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+o)}}},_int:{encode(e){let{Err:t}=qt;if(Kr(e),e<Tf)throw new t("integer: negative integers are not allowed");let r=er(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.length<1)throw new t("invalid signature integer: empty");if(e[0]&128)throw new t("invalid signature integer: negative");if(e.length>1&&e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Pt(e)}},toSig(e,t){let{Err:r,_int:n,_tlv:s}=qt;if(t!==void 0&&(Ft(t,"maxScalarBytes"),t<1))throw new r("invalid signature: maxScalarBytes must be positive");let i=V(e,void 0,"signature"),{v:o,l:a}=s.decode(48,i);if(a.length)throw new r("invalid signature: left bytes after parsing");let{v:c,l:u}=s.decode(2,o),{v:f,l:d}=s.decode(2,u);if(d.length)throw new r("invalid signature: left bytes after parsing");if(t!==void 0&&(c.length>t||f.length>t))throw new r("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(f)}},hexFromSig(e){let{_tlv:t,_int:r}=qt;xt(e,{r:"bigint",s:"bigint"},{},"sig");let n=t.encode(2,r.encode(e.r)),s=t.encode(2,r.encode(e.s)),i=n+s;return t.encode(48,i)}},on=(Object.freeze(qt._tlv),Object.freeze(qt._int),Object.freeze(qt));var ca=(e,t)=>(e+(e>=0?t:-t)/ua)/t;function Lf(e,t,r){Oe("scalar",e,zt,r);let[[n,s],[i,o]]=t,a=ca(o*e,r),c=ca(-s*e,r),u=e-a*n-c*i,f=-a*s-c*o,d=u<zt,l=f<zt;d&&(u=-u),l&&(f=-f);let h=nr(Math.ceil(ke(r)/2))+we;if(u<zt||u>=h||f<zt||f>=h)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:d,k1:u,k2neg:l,k2:f}}function Xs(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Gs(e,t){xt(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return wt(r.lowS,"lowS"),wt(r.prehash,"prehash"),r.format!==void 0&&Xs(r.format),r}var zt=BigInt(0),we=BigInt(1),ua=BigInt(2),Ws=BigInt(3),Rf=BigInt(4);function fa(e,t={}){let r=$r("weierstrass",e,t),n=r.Fp,s=r.Fn,i=r.CURVE,{h:o,n:a}=i;xt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u,clearCofactor:f,isTorsionFree:d,fromBytes:l,toBytes:h}=t,b=t.randomBytes===void 0?pe:t.randomBytes;if(c&&(!n.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let g=c?{beta:c.beta,basises:c.basises.map(S=>[...S])}:void 0,E=ha(n,s);function w(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function v(S,p,m){if(p.is0()){if(!u)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x,y:I}=p.toAffine(),L=n.toBytes(x);if(wt(m,"isCompressed"),m){w();let R=!n.isOdd(I);return It(la(R),L)}else return It(Uint8Array.of(4),L,n.toBytes(I))}function y(S){V(S,void 0,"Point");let{publicKey:p,publicKeyUncompressed:m}=E,x=S.length,I=S[0],L=S.subarray(1);if(u&&x===1&&I===0)return{x:n.ZERO,y:n.ZERO};if(x===p&&(I===2||I===3)){let R=n.fromBytes(L);if(!n.isValid(R))throw new Error("bad point: is not on curve, wrong x");let P=k(R),N;try{N=n.sqrt(P)}catch(ot){let X=ot instanceof Error?": "+ot.message:"";throw new Error("bad point: is not on curve, sqrt error"+X)}w();let H=n.isOdd(N);return(I&1)===1!==H&&(N=n.neg(N)),{x:R,y:N}}else if(x===m&&I===4){let R=n.BYTES,P=n.fromBytes(L.subarray(0,R)),N=n.fromBytes(L.subarray(R,R*2));if(!_(P,N))throw new Error("bad point: is not on curve");return{x:P,y:N}}else throw new Error(`bad point: got length ${x}, expected compressed=${p} or uncompressed=${m}`)}let A=h===void 0?v:h,B=l===void 0?y:l,O=n.mul(i.b,Ws),K=n.is0(i.a)?S=>n.ZERO:S=>n.mul(i.a,S);function k(S){let p=n.sqr(S),m=n.mul(p,S);return n.add(n.add(m,n.mul(S,i.a)),i.b)}function _(S,p){let m=n.sqr(p),x=k(S);return n.eql(m,x)}if(!_(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let C=n.mul(n.pow(i.a,Ws),Rf),q=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(C,q)))throw new Error("bad curve params: a or b");function U(S,p,m=!1){if(!n.isValid(p)||m&&n.is0(p))throw new Error(`bad point coordinate ${S}`);return typeof p=="object"&&p!==null?n.create(p):p}function G(S){if(!(S instanceof D))throw new Error("Weierstrass Point expected")}function T(S){if(!g||!g.basises)throw new Error("no endo");return Lf(S,g.basises,s.ORDER)}function M(S,p,m,x){if(!s.isValid(x))throw new RangeError("invalid scalar: out of range");if(g){let{k1neg:I,k1:L,k2neg:R,k2:P}=T(x),N=new D(n.mul(m.X,g.beta),m.Y,m.Z);S.push(I?m.negate():m,R?N.negate():N),p.push(L,P)}else S.push(m),p.push(x)}let F=new WeakSet;class D{static BASE=new D(i.Gx,i.Gy,n.ONE);static ZERO=new D(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=s;X;Y;Z;constructor(p,m,x){this.X=U("x",p),this.Y=U("y",m,!0),this.Z=U("z",x),Object.freeze(this)}static CURVE(){return i}static fromAffine(p){let{x:m,y:x}=p||{};if(!p||!n.isValid(m)||!n.isValid(x))throw new Error("invalid affine point");if(p instanceof D)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(x)?D.ZERO:new D(m,x,n.ONE)}static fromBytes(p){let m=D.fromAffine(B(V(p,void 0,"point")));return m.assertValidity(),m}static fromHex(p){return D.fromBytes(Pe(p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=6,m=!0){return tt.setWindowSize(this,p),m||this.multiply(Ws),this}assertValidity(){let p=this;if(p.is0()){if(u&&n.is0(p.X)&&n.eql(p.Y,n.ONE)&&n.is0(p.Z))return;throw new Error("bad point: ZERO")}if(F.has(p))return;let{x:m,y:x}=p.toAffine();if(!n.isValid(m)||!n.isValid(x))throw new Error("bad point: x or y not field elements");if(!_(m,x))throw new Error("bad point: equation left != right");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");F.add(p)}hasEvenY(){let{y:p}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(p)}equals(p){G(p);let{X:m,Y:x,Z:I}=this,{X:L,Y:R,Z:P}=p,N=n.eql(n.mul(m,P),n.mul(L,I)),H=n.eql(n.mul(x,P),n.mul(R,I));return N&&H}negate(){return new D(this.X,n.neg(this.Y),this.Z)}double(){let{X:p,Y:m,Z:x}=this,I=n.ZERO,L=n.ZERO,R=n.ZERO,P=n.mul(p,p),N=n.mul(m,m),H=n.mul(x,x),z=n.mul(p,m);return z=n.add(z,z),R=n.mul(p,x),R=n.add(R,R),I=K(R),L=n.mul(O,H),L=n.add(I,L),I=n.sub(N,L),L=n.add(N,L),L=n.mul(I,L),I=n.mul(z,I),R=n.mul(O,R),H=K(H),z=n.sub(P,H),z=K(z),z=n.add(z,R),R=n.add(P,P),P=n.add(R,P),P=n.add(P,H),P=n.mul(P,z),L=n.add(L,P),H=n.mul(m,x),H=n.add(H,H),P=n.mul(H,z),I=n.sub(I,P),R=n.mul(H,N),R=n.add(R,R),R=n.add(R,R),new D(I,L,R)}add(p){G(p);let{X:m,Y:x,Z:I}=this,{X:L,Y:R,Z:P}=p,N=n.ZERO,H=n.ZERO,z=n.ZERO,ot=n.mul(m,L),X=n.mul(x,R),ft=n.mul(I,P),St=n.add(m,x),J=n.add(L,R);St=n.mul(St,J),J=n.add(ot,X),St=n.sub(St,J),J=n.add(m,I);let at=n.add(L,P);return J=n.mul(J,at),at=n.add(ot,ft),J=n.sub(J,at),at=n.add(x,I),N=n.add(R,P),at=n.mul(at,N),N=n.add(X,ft),at=n.sub(at,N),z=K(J),N=n.mul(O,ft),z=n.add(N,z),N=n.sub(X,z),z=n.add(X,z),H=n.mul(N,z),X=n.add(ot,ot),X=n.add(X,ot),ft=K(ft),J=n.mul(O,J),X=n.add(X,ft),ft=n.sub(ot,ft),ft=K(ft),J=n.add(J,ft),ot=n.mul(X,J),H=n.add(H,ot),ot=n.mul(at,J),N=n.mul(St,N),N=n.sub(N,ot),ot=n.mul(St,X),z=n.mul(at,z),z=n.add(z,ot),new D(N,H,z)}subtract(p){return G(p),this.add(p.negate())}is0(){return this.equals(D.ZERO)}multiply(p){if(!s.isValidNot0(p))throw new RangeError("invalid scalar: out of range");let{p:m,f:x}=tt.mulSecret(this,p,o,W);return W([m,x])[0]}multiplyUnsafe(p){let m=this,x=p;if(!s.isValid(x))throw new RangeError("invalid scalar: out of range");if(x===zt||m.is0())return D.ZERO;if(x===we)return m;if(tt.hasWindowSize(this))return tt.mulUnsafe(m,x,W);let I=[],L=[];return M(I,L,m,x),Vr(D,I,L)}mulAddUnsafe(p,m,x){G(m);let I=[],L=[];return M(I,L,this,p),M(I,L,m,x),Vr(D,I,L)}toAffine(p){let m=this,x=p;if(x!=null&&!n.isValid(x))throw new RangeError('"invertedZ" expected valid field element');let{X:I,Y:L,Z:R}=m;if(n.eql(R,n.ONE))return{x:I,y:L};let P=m.is0();x==null&&(x=P?n.ONE:n.inv(R));let N=n.mul(I,x),H=n.mul(L,x),z=n.mul(R,x);if(P)return{x:n.ZERO,y:n.ZERO};if(!n.eql(z,n.ONE))throw new Error("invZ was invalid");return{x:N,y:H}}isTorsionFree(){return o===we?!0:d?d(D,this):tt.mulUnsafe(this,a).is0()}clearCofactor(){return o===we?this:f?f(D,this):this.multiplyUnsafe(o)}isSmallOrder(){return o===we?this.is0():this.clearCofactor().is0()}toBytes(p=!0){return wt(p,"isCompressed"),this.assertValidity(),A(D,this,p)}toHex(p=!0){return tr(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let W=S=>Hr(D,S),tt=new Me(D,b);return tt.bits>=6&&D.BASE.precompute(6),Object.freeze(D.prototype),Object.freeze(D),D}function la(e){return Uint8Array.of(e?2:3)}function ha(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function _f(e,t={}){te(e);let{Fn:r}=e,n=t.randomBytes===void 0?pe:t.randomBytes,s=Object.assign(ha(e.Fp,r),{seed:Math.max(qr(r.ORDER),16)});function i(h){try{let b=r.fromBytes(h);return r.isValidNot0(b)}catch{return!1}}function o(h,b){let{publicKey:g,publicKeyUncompressed:E}=s;try{let w=h.length;return b===!0&&w!==g||b===!1&&w!==E?!1:!e.fromBytes(h).is0()}catch{return!1}}function a(h){return h=h===void 0?n(s.seed):h,zr(V(h,s.seed,"seed"),r.ORDER)}function c(h,b=!0){return e.BASE.multiply(r.fromBytes(h)).toBytes(b)}function u(h){let{secretKey:b,publicKey:g,publicKeyUncompressed:E}=s,w=r._lengths;if(!Jt(h))return;let v=V(h,void 0,"key").length,y=v===g||v===E,A=v===b||!!w?.includes(v);if(!(y&&A))return y}function f(h,b,g=!0){if(u(h)===!0)throw new Error("first arg must be private key");if(u(b)===!1)throw new Error("second arg must be public key");let E=r.fromBytes(h),w=e.fromBytes(b);if(w.is0())throw new Error("invalid public key: point at infinity");return w.multiply(E).toBytes(g)}let d={isValidSecretKey:i,isValidPublicKey:o,randomSecretKey:a},l=jr(a,c);return Object.freeze(d),Object.freeze(s),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:l,Point:e,utils:d,lengths:s})}function da(e,t,r={}){te(e);let n=t;_r(n),xt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let s=Object.assign({},r),i=s.randomBytes===void 0?pe:s.randomBytes,o=s.hmac===void 0?(S,p)=>aa(n,S,p):s.hmac,{Fp:a,Fn:c}=e,{ORDER:u,BITS:f}=c,d=qr(u),l=ds(i,d),{keygen:h,getPublicKey:b,getSharedSecret:g,utils:E,lengths:w}=_f(e,s),v={prehash:!0,lowS:typeof s.lowS=="boolean"?s.lowS:!0,format:"compact",extraEntropy:!1},y=u*ua+we<a.ORDER;function A(S){let p=u>>we;return S>p}function B(S,p){if(!c.isValidNot0(p))throw new Error(`invalid signature ${S}: out of range 1..Point.Fn.ORDER`);return p}function O(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function K(S,p,m){return O(),(S===m?0:2)|Number(a.isOdd(p))}function k(){if(y)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function _(S,p){Xs(p);let m=w.signature,x=p==="compact"?m:p==="recovered"?m+1:void 0;return V(S,x)}class C{r;s;recovery;constructor(p,m,x){if(this.r=B("r",p),this.s=B("s",m),x!=null){if(k(),![0,1,2,3].includes(x))throw new Error("invalid recovery id");this.recovery=x}Object.freeze(this)}static fromBytes(p,m=v.format){_(p,m);let x;if(m==="der"){if(p.length>2*c.BYTES+16)throw new on.Err("invalid signature: DER signature too long");let{r:P,s:N}=on.toSig(V(p),c.BYTES+1);return new C(P,N)}m==="recovered"&&(x=p[0],m="compact",p=p.subarray(1));let I=w.signature/2,L=p.subarray(0,I),R=p.subarray(I,I*2);return new C(c.fromBytes(L),c.fromBytes(R),x)}static fromHex(p,m){return this.fromBytes(Pe(p),m)}assertRecovery(){let{recovery:p}=this;if(p==null)throw new Error("invalid recovery id: must be present");return p}addRecoveryBit(p){return new C(this.r,this.s,p)}recoverPublicKey(p){let{r:m,s:x}=this,I=this.assertRecovery(),L=I===2||I===3?m+u:m;if(!a.isValid(L))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let R=a.toBytes(L),P=e.fromBytes(It(la((I&1)===0),R)),N=c.inv(L),H=U(V(p,void 0,"msgHash")),z=c.create(-H*N),ot=c.create(x*N),X=e.BASE.mulAddUnsafe(z,P,ot);if(X.is0())throw new Error("invalid recovery: point at infinify");return X.assertValidity(),X}hasHighS(){return A(this.s)}toBytes(p=v.format){if(Xs(p),p==="der")return Pe(on.hexFromSig(this));let{r:m,s:x}=this,I=c.toBytes(m),L=c.toBytes(x);return p==="recovered"?(k(),It(Uint8Array.of(this.assertRecovery()),I,L)):It(I,L)}toHex(p){return tr(this.toBytes(p))}}Object.freeze(C.prototype),Object.freeze(C);let q=s.bits2int===void 0?function(p){if(p.length>8192)throw new Error("input is too large");let m=Pt(p),x=p.length*8-f;return x>0?m>>BigInt(x):m}:s.bits2int,U=s.bits2int_modN===void 0?function(p){return c.create(q(p))}:s.bits2int_modN,G=nr(f);function T(S){return Oe("num < 2^"+f,S,zt,G),c.toBytes(S)}function M(S,p){return V(S,void 0,"message"),p?V(n(S),void 0,"prehashed message"):S}function F(S,p,m){let{lowS:x,prehash:I,extraEntropy:L}=Gs(m,v);S=M(S,I);let R=U(S),P=c.fromBytes(p);if(!c.isValidNot0(P))throw new Error("invalid private key");let N=[T(P),T(R)];if(L!=null&&L!==!1){let X=L===!0?i(w.secretKey):L;N.push(V(X,void 0,"extraEntropy"))}let H=It(...N),z=R;function ot(X){let ft=q(X);if(!c.isValidNot0(ft))return;let St=e.BASE.multiply(ft).toAffine(),J=c.create(St.x);if(J===zt)return;let at;if(l!==void 0){let He=Pt(zr(l(d),u)),ka=c.inv(c.mul(He,ft)),Na=c.mul(He,z),Ka=c.mul(He,P);at=c.create(ka*c.create(Na+Ka*J))}else{let He=vo(ft,u);at=c.create(He*c.create(z+J*P))}if(at===zt)return;let mn=K(St.x,St.y,J),pi=at;return x&&A(at)&&(pi=c.neg(at),mn^=1),new C(J,pi,y?void 0:mn)}return{seed:H,k2sig:ot}}function D(S,p,m={}){let{seed:x,k2sig:I}=F(S,p,m);return mo(n.outputLen,c.BYTES,o)(x,I).toBytes(m.format)}function W(S,p,m,x={}){let{lowS:I,prehash:L,format:R}=Gs(x,v);if(m=V(m,void 0,"publicKey"),p=M(p,L),!Jt(S)){let P=S instanceof C?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+P)}_(S,R);try{let P=C.fromBytes(S,R),N=e.fromBytes(m);if(N.is0()||I&&P.hasHighS())return!1;let{r:H,s:z}=P,ot=U(p),X=c.inv(z),ft=c.create(ot*X),St=c.create(H*X),J=e.BASE.mulAddUnsafe(ft,N,St);if(J.is0())return!1;let at=J.toAffine();return!(c.create(at.x)!==H||R==="recovered"&&P.recovery!==K(at.x,at.y,H))}catch{return!1}}function tt(S,p,m={}){let{prehash:x}=Gs(m,v);return p=M(p,x),C.fromBytes(S,"recovered").recoverPublicKey(p).toBytes()}return Object.freeze({keygen:h,getPublicKey:b,getSharedSecret:g,utils:E,lengths:w,Point:e,sign:D,verify:W,recoverPublicKey:tt,Signature:C,hash:n})}var Qs={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Df={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var pa=BigInt(2);function Cf(e){let t=Qs.p,r=BigInt(3),n=BigInt(6),s=BigInt(11),i=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,f=u*u*e%t,d=Q(f,r,t)*f%t,l=Q(d,r,t)*f%t,h=Q(l,pa,t)*u%t,b=Q(h,s,t)*h%t,g=Q(b,i,t)*b%t,E=Q(g,a,t)*g%t,w=Q(E,c,t)*E%t,v=Q(w,a,t)*g%t,y=Q(v,r,t)*f%t,A=Q(y,o,t)*b%t,B=Q(A,n,t)*u%t,O=Q(B,pa,t);if(!Js.eql(Js.sqr(O),e))throw new Error("Cannot find square root");return O}var Js=Ke(Qs.p,{sqrt:Cf}),Pf=fa(Qs,{Fp:Js,endo:Df}),Ue=da(Pf,Ce);function ma(e,t,r,n){let s=ue.digest(r instanceof Uint8Array?r:r.subarray());if(Jr(s))return s.then(({digest:i})=>(n?.signal?.throwIfAborted(),Ue.verify(t,i,e,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new or(String(i))});try{return n?.signal?.throwIfAborted(),Ue.verify(t,s.digest,e,{prehash:!1,format:"der"})}catch(i){throw new or(String(i))}}var an=class{type="secp256k1";raw;_key;constructor(t){this._key=ya(t),this.raw=ba(this._key)}toMultihash(){return Lt.digest(Kt(this))}toCID(){return ht.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,r,n){return ma(this._key,r,t,n)}};function ti(e){return new an(e)}function ba(e){return Ue.Point.fromBytes(e).toBytes()}function ya(e){try{return Ue.Point.fromBytes(e),e}catch(t){throw new ve(String(t))}}function ei(e,t){let{Type:r,Data:n}=Ot.decode(e),s=n??new Uint8Array;switch(r){case st.RSA:return $s(s,t);case st.Ed25519:return ws(s);case st.secp256k1:return ti(s);case st.ECDSA:return jn(s);default:throw new oe}}function ga(e){let{Type:t,Data:r}=Ot.decode(e.digest),n=r??new Uint8Array;switch(t){case st.Ed25519:return ws(n);case st.secp256k1:return ti(n);case st.ECDSA:return jn(n);default:throw new oe}}function Kt(e){return Ot.encode({Type:st[e.type],Data:e.raw})}var wa=Symbol.for("nodejs.util.inspect.custom"),Of=114,hr=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()})`}[yn]=!0;toString(){return this.string==null&&(this.string=rt.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ht.createV1(Of,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return bt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return bt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[wa](){return`PeerId(${this.toString()})`}},dr=class extends hr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},pr=class extends hr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},mr=class extends hr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},kf=2336,cn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Lt.digest(Y(this.url))}[wa](){return`PeerId(${this.url})`}[yn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ht.createV1(kf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=Z(t)),t.toString()===this.toString())}};function ri(e){if(e.type==="Ed25519")return new pr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new mr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new dr({multihash:e.toCID().multihash,publicKey:e});throw new oe}function xa(e){return ri(e.publicKey)}function br(e){if(Kf(e))return new dr({multihash:e});if(Nf(e))try{let t=ga(e);if(t.type==="Ed25519")return new pr({multihash:e,publicKey:t});if(t.type==="secp256k1")return new mr({multihash:e,publicKey:t})}catch{let r=Z(e.digest);return new cn(new URL(r))}throw new Sr("Supplied PeerID Multihash is invalid")}function Nf(e){return e.code===Lt.code}function Kf(e){return e.code===ue.code}function xe(e,t){let r={[Symbol.iterator]:()=>r,next:()=>{let n=e.next(),s=n.value;return n.done===!0||s==null?{done:!0,value:void 0}:{done:!1,value:t(s)}}};return r}function un(e){let t=Vt(rt.decode(`z${e}`));return br(t)}var yr=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[r,n]of t.entries())this.map.set(r.toString(),{key:r,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return xe(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((r,n)=>{t(r.value,r.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,r){this.map.set(t.toString(),{key:t,value:r})}keys(){return xe(this.map.values(),t=>t.key)}values(){return xe(this.map.values(),t=>t.value)}get size(){return this.map.size}};var gr=class e{set;constructor(t){if(this.set=new Set,t!=null)for(let r of t)this.set.add(r.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return xe(this.set.entries(),t=>{let r=un(t[0]);return[r,r]})}forEach(t){this.set.forEach(r=>{let n=un(r);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return xe(this.set.values(),t=>un(t))}intersection(t){let r=new e;for(let n of t)this.has(n)&&r.add(n);return r}difference(t){let r=new e;for(let n of this)t.has(n)||r.add(n);return r}union(t){let r=new e;for(let n of t)r.add(n);for(let n of this)r.add(n);return r}};var ni=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},Ea=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function si(e,t){let{milliseconds:r,fallback:n,message:s,customTimers:i={setTimeout,clearTimeout},signal:o}=t,a,c,f=new Promise((d,l)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(o?.aborted){l(Ea(o)),e.then(d,l);return}if(o&&(c=()=>{l(Ea(o))},o.addEventListener("abort",c,{once:!0})),e.then(d,l),r===Number.POSITIVE_INFINITY)return;let h=new ni;a=i.setTimeout.call(void 0,()=>{if(n){try{d(n())}catch(b){l(b)}return}typeof e.cancel=="function"&&e.cancel(),s===!1?d():s instanceof Error?l(s):(h.message=s??`Promise timed out after ${r} milliseconds`,l(h))},r)}).finally(()=>{f.clear(),c&&o&&o.removeEventListener("abort",c)});return f.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},f}var Mf=e=>{let t=e.addEventListener||e.on||e.addListener,r=e.removeEventListener||e.off||e.removeListener;if(!t||!r)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(e),removeListener:r.bind(e)}};function Ff(e,t,r){let n,s=new Promise((i,o)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:u,removeListener:f}=Mf(e),d=async(...h)=>{let b=r.multiArgs?h:h[0];if(r.filter)try{if(!await r.filter(b))return}catch(g){n(),o(g);return}c.push(b),r.count===c.length&&(n(),i(c))},l=(...h)=>{n(),o(r.rejectionMultiArgs?h:h[0])};n=()=>{for(let h of a)f(h,d);for(let h of r.rejectionEvents)a.includes(h)||f(h,l)};for(let h of a)u(h,d);for(let h of r.rejectionEvents)a.includes(h)||u(h,l);r.signal&&r.signal.addEventListener("abort",()=>{l(r.signal.reason)},{once:!0}),r.resolveImmediately&&i(c)});if(s.cancel=n,typeof r.timeout=="number"){let i=si(s,{milliseconds:r.timeout});return i.cancel=()=>{n(),i.clear()},i}return s}function Sa(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Ff(e,t,r),s=n.then(i=>i[0]);return s.cancel=n.cancel,s}var Ee=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Uf(e){return e.reason}function ii(e,t,r){if(t==null||e==null)return e;let n=r?.translateError??Uf;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let s;return Promise.race([e,new Promise((i,o)=>{s=()=>{o(n(t))},t.addEventListener("abort",s)})]).finally(()=>{s!=null&&t.removeEventListener("abort",s)})}var zf=4194304,fn=class extends Error{static name="UnwrappedError";name="UnwrappedError"},ai=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ci=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},ui=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Hf(e){return typeof e?.closeRead=="function"}function Vf(e){return typeof e?.close=="function"}function oi(e){return Hf(e)?e.remoteWriteStatus!=="writable"&&e.readBufferLength===0:Vf(e)?e.status!=="open":!1}function $f(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function jf(e,t){let r=t?.maxBufferSize??zf,n=new lt,s,i=!1,o;if(!$f(e))throw new et("Argument should be a Stream or a Multiaddr");let a=d=>{if(!i&&o==null){if(n.append(d.data),n.byteLength>r){let l=n.byteLength;n.consume(l);let h=new Er(`Read buffer overflow - ${l} > ${r}`);o=h,s?.reject(h),queueMicrotask(()=>{e.abort(h)});return}s?.resolve()}};e.addEventListener("message",a);let c=d=>{d.error!=null?s?.reject(d.error):s?.resolve()};e.addEventListener("close",c);let u=()=>{s?.resolve()};e.addEventListener("remoteCloseWrite",u);let f={readBuffer:n,async read(d){if(i===!0)throw new fn("Stream was unwrapped");if(o!=null)throw o;if(oi(e)){if(n.byteLength===0&&d?.bytes==null)return null;if(d?.bytes!=null&&n.byteLength<d.bytes)throw e.log.error("closed after reading %d/%d bytes",n.byteLength,d.bytes),new Ee(`Unexpected EOF - stream closed after reading ${n.byteLength}/${d.bytes} bytes`)}let l=d?.bytes??1;for(s=Promise.withResolvers();;){if(n.byteLength>=l){s.resolve();break}if(await ii(s.promise,d?.signal),oi(e)){if(n.byteLength===0&&d?.bytes==null)return null;break}s=Promise.withResolvers()}let h=d?.bytes??n.byteLength;if(n.byteLength<h){if(oi(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,h),new Ee(`Unexpected EOF - stream closed while reading ${n.byteLength}/${h} bytes`);return f.read(d)}let b=n.sublist(0,h);return n.consume(h),b},async write(d,l){if(i===!0)throw new fn("Stream was unwrapped");e.send(d)||await Sa(e,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return i||(i=!0,e.removeEventListener("message",a),e.removeEventListener("close",c),e.removeEventListener("remoteCloseWrite",u),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.unshift(n),n.consume(n.byteLength))),e}};return f}function Zf(e,t={}){let r=jf(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=Ut(t.maxDataLength));let n=t?.lengthDecoder??Vo,s=t?.lengthEncoder??Ho;return{async read(o){let a=-1,c=new lt;for(;;){let f=await r.read({...o,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(d){if(d instanceof RangeError)continue;throw d}if(a<0)throw new ai("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new ui(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new ci(`Message length too long - ${a} > ${t.maxDataLength}`);let u=await r.read({...o,bytes:a});if(u==null)throw e.log.error("tried to read %d bytes but the stream closed",a),new Ee(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw e.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new Ee(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(o,a){await r.write(new lt(s(o.byteLength),o),a)},async writeV(o,a){let c=new lt(...o.flatMap(u=>[s(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function fi(e,t){let r=Zf(e,t),n={read:async(s,i)=>{let o=await r.read(i);return s.decode(o,i)},write:async(s,i,o)=>{await r.write(i.encode(s),o)},writeV:async(s,i,o)=>{await r.writeV(s.map(a=>i.encode(a)),o)},pb:s=>({read:async i=>n.read(s,i),write:async(i,o)=>n.write(i,s,o),writeV:async(i,o)=>n.writeV(i,s,o),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}function li(e,t,r){let n=0,s=e.length;for(;s>0;){let i=Math.trunc(s/2),o=n+i;r(e[o],t)<=0?(n=++o,s-=i+1):s=i}return n}var Yf=100,qe=class{#t=[];#e=0;#i(){this.#e!==0&&(this.#t.splice(0,this.#e),this.#e=0)}#u(t){for(let r=this.#e;r<this.#t.length;r++)if(t(this.#t[r]))return r;return-1}#b(){let t=this.#t[this.#e];return this.#t[this.#e]=void 0,this.#e++,this.#e===this.#t.length?(this.#t.length=0,this.#e=0):this.#e>Yf&&this.#e>this.#t.length/2&&this.#i(),t.run}enqueue(t,r){let{priority:n=0,id:s}=r??{},{size:i}=this,o={priority:n,id:s,run:t};if(i===0){this.#t.length=0,this.#e=0,this.#t.push(o);return}if(this.#t.at(-1).priority>=n){this.#t.push(o);return}this.#i();let a=li(this.#t,o,(c,u)=>c.priority===u.priority?0:u.priority-c.priority);this.#t.splice(a,0,o)}setPriority(t,r){let n=this.#u(i=>i.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);if(this.#t[n].priority===r)return;let[s]=this.#t.splice(n,1);this.enqueue(s.run,{priority:r,id:t})}remove(t){let r=this.#u(n=>(typeof t=="string"?n.id:n.run)===t);r===this.#e?this.#b():r!==-1&&this.#t.splice(r,1)}dequeue(){return this.#e===this.#t.length?void 0:this.#b()}filter(t){let r=[];for(let n=this.#e;n<this.#t.length;n++){let s=this.#t[n];s.priority===t.priority&&r.push(s.run)}return r}get size(){return this.#t.length-this.#e}};var ln=2147483647,va=globalThis.process?.getBuiltinModule?.("node:async_hooks"),Gf=e=>{if(va===void 0)return e;let t=new va.AsyncResource("PQueueTask");return()=>t.runInAsyncScope(e)},Aa=e=>{if(e!==void 0&&!(Number.isFinite(e)&&e>0&&e<=ln))throw new TypeError(`Expected \`timeout\` to be a positive finite number up to ${ln}, got \`${e}\` (${typeof e})`)},Ba=(e,t)=>{if(!(typeof t=="number"&&t>=1&&(t===1/0||Number.isInteger(t))))throw new TypeError(`Expected \`${e}\` to be an integer from 1 and up or \`Infinity\`, got \`${String(t)}\` (${typeof t})`)},Wf=(e,t,r)=>{if(Ba("intervalCap",t),!(Number.isFinite(e)&&e>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${String(e)}\` (${typeof e})`);if(t!==1/0&&e>ln)throw new TypeError(`Expected \`interval\` to be at most ${ln} with an \`intervalCap\`, got \`${e}\``);if(r&&e===0)throw new TypeError("The `strict` option requires a non-zero `interval`");if(r&&t===1/0)throw new TypeError("The `strict` option requires a finite `intervalCap`")},wr=class extends EventTarget{#t;#e;#i=0;#u;#b=!1;#v=!1;#h;#x=0;#f;#d;#c;#o=[];#a=0;#r;#A;#n=0;#E;#l;#z=1n;#B=new Set;#y=new Map;#p=new Set;#I;constructor(t){super(),globalThis.process?.getBuiltinModule?.("node:events")?.setMaxListeners(1/0,this);let{carryoverIntervalCount:r=!1,intervalCap:n=1/0,interval:s=0,concurrency:i=1/0,autoStart:o=!0,queueClass:a=qe,strict:c=!1,timeout:u}=t??{};Wf(s,n,c),this.#t=r,this.#e=n===1/0||s===0,this.#u=n,this.#h=s,this.#c=c,this.#A=a,this.#r=new this.#A,this.concurrency=i,this.timeout=u,this.#l=!o,this.#V()}#T(t,r){let n=this.#y.get(t);if(!n){let i=new Set,o=()=>{this.#y.delete(t);for(let a of i)a()};n={callbacks:i,dispatch:o},this.#y.set(t,n),t.addEventListener("abort",o,{once:!0})}let s=n;return s.callbacks.add(r),()=>{s.callbacks.delete(r),!(s.callbacks.size>0||this.#y.get(t)!==s)&&(this.#y.delete(t),t.removeEventListener("abort",s.dispatch))}}#s(t,r){this.dispatchEvent(new CustomEvent(t,{detail:r}))}async#m(t,r){let n=Array.isArray(t)?t:[t];return new Promise(s=>{let i=new AbortController,o=()=>{r&&!r()||(i.abort(),s())};for(let a of n)this.addEventListener(a,o,{signal:i.signal})})}get#D(){if(this.#e||this.#r.size===0)return!1;let t=Date.now();return this.#c?(this.#R(t),this.#_()>=this.#u):(this.#f===void 0&&this.#x<=t?this.#L:this.#i)>=this.#u}get#L(){return this.#t?this.#n:0}#S(){let t=this.#D;t!==this.#b&&(this.#b=t,this.#s(t?"rateLimit":"rateLimitCleared"))}#H(){this.#e||(this.#j(),this.#g())}#g(){this.#e||this.#v||(this.#v=!0,queueMicrotask(()=>{this.#v=!1,this.#S()}))}#V(){this.#e||(this.addEventListener("add",()=>{this.#r.size>0&&this.#g()}),this.addEventListener("next",()=>{this.#g()}))}#R(t){for(;this.#a<this.#o.length;){let n=this.#o[this.#a];if(n!==void 0&&t-n>=this.#h)this.#a++;else break}(this.#a>100&&this.#a>this.#o.length/2||this.#a===this.#o.length)&&(this.#o=this.#o.slice(this.#a),this.#a=0)}#$(t){this.#c?this.#o.push(t):this.#i++}#j(){if(this.#c){this.#o.length>this.#a&&this.#o.pop();return}this.#i>0&&this.#i--}#_(){return this.#o.length-this.#a}get#C(){return this.#e?!0:(this.#c?this.#_():this.#i)<this.#u}get#Z(){return this.#n<this.#E}#Y(){this.#n--,this.#n===0&&this.#s("pendingZero"),this.#w(),this.#s("next")}#G(){this.#d=void 0,this.#U(),this.#l||this.#F()}#P(t){if(this.#c){if(this.#R(t),this.#_()>=this.#u){let n=this.#o[this.#a],s=this.#h-(t-n);return this.#O(s),!0}return!1}if(this.#f===void 0){let r=this.#x-t;if(r<=0)this.#i=this.#L;else return this.#O(r),!0}return!1}#O(t){this.#d===void 0&&(this.#d=setTimeout(()=>{this.#G()},t))}#k(){this.#f!==void 0&&(clearInterval(this.#f),this.#f=void 0)}#N(){this.#d!==void 0&&(clearTimeout(this.#d),this.#d=void 0)}#K(){this.#k(),this.#s("empty"),!(this.#n>0||this.#r.size>0)&&(this.#N(),this.#c&&this.#R(Date.now()),this.#s("idle"))}#M(){let t;do t=this.#W();while(t===void 0);return t}#W(){if(this.#r.size===0)return this.#K(),!1;if(this.#l)return this.#C||this.#P(Date.now()),!1;let t=Date.now(),r=!this.#P(t);if(this.#C&&this.#Z){let n=this.#r.dequeue();this.#e||(this.#$(t),this.#g()),r&&this.#F();let s=this.#n;if(n(),this.#n===s){this.#s("next");return}return this.#s("active"),!0}return!1}#F(){this.#e||this.#f!==void 0||this.#c||(this.#N(),this.#f=setInterval(()=>{this.#U()},this.#h),this.#x=Date.now()+this.#h)}#U(){this.#c||(this.#f!==void 0&&(this.#i===0&&this.#n===0?this.#k():this.#x=Date.now()+this.#h),this.#i=this.#L),this.#w(),this.#g()}#w(){for(;this.#M(););}#q(){this.#r.size>0&&this.#w()}async#X(t,r,n){let s=r.id??(this.#z++).toString();if(r={timeout:this.#I,...r,id:s},Aa(r.timeout),r.priority!==void 0&&(typeof r.priority!="number"||Number.isNaN(r.priority)))throw new TypeError(`Expected \`priority\` to be a number, got \`${String(r.priority)}\` (${typeof r.priority})`);return n.id=s,n.priority=r.priority??0,new Promise((i,o)=>{if(r.signal?.aborted){o(r.signal.reason);return}let a=Gf(async()=>{if(n.stopListeningForAbort?.(),this.#p.delete(n),r.signal?.aborted){this.#H(),o(r.signal.reason);return}this.#n++;let u={id:s,priority:n.priority,startTime:Date.now(),timeout:r.timeout};this.#B.add(u);let{signal:f}=r,d,l,h;try{if(r.timeout!==void 0){let{signal:E,timeout:w}=r,v=new AbortController;h=setTimeout(()=>{v.abort(new hi(`Task timed out after ${w}ms (queue has ${this.#n} running, ${this.#r.size} waiting)`))},w),E&&(l=this.#T(E,()=>{v.abort(E.reason)})),f=v.signal}let b;if(f){let E=f,w=new Promise((v,y)=>{d=this.#T(E,()=>{y(E.reason)})});b=Promise.race([w,(async()=>t({signal:f}))()])}else try{b=t({signal:f})}catch(E){b=Promise.reject(E)}let g=await b;i(g),this.#s("completed",g)}catch(b){o(b),this.#s("error",b)}finally{clearTimeout(h),d?.(),l?.(),this.#B.delete(u),queueMicrotask(()=>{this.#Y()})}}),c=this.#r.size>0;if(this.#r.enqueue(a,r),n.reject=o,this.#p.add(n),r.signal){let{signal:u}=r;n.stopListeningForAbort=this.#T(u,()=>{this.#p.delete(n),this.#r instanceof qe?this.#r.remove(a):this.#r.remove(s),o(u.reason),this.#w(),this.#s("next")})}this.#s("add"),c?this.#w():this.#M()})}get timeout(){return this.#I}set timeout(t){Aa(t),this.#I=t}get concurrency(){return this.#E}set concurrency(t){Ba("concurrency",t),this.#E=t,this.#q()}setPriority(t,r){if(typeof r!="number"||!Number.isFinite(r))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${r}\` (${typeof r})`);for(let n of this.#p)if(n.id===t){this.#r.setPriority(t,r),n.priority=r;return}throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`)}add(t,r={}){let n={},s=this.#X(t,r,n);return n.promise=s,n.isCleared&&s.catch(()=>{}),s}async addAll(t,r){return Promise.all(t.map(async n=>this.add(n,r)))}start(){return this.#l?(this.#l=!1,this.#q(),this):this}pause(){this.#l=!0}clear(){if(this.#r.size===0)return;this.#r=new this.#A;let t=new DOMException("The queue was cleared","AbortError");for(let r of this.#p)r.stopListeningForAbort?.(),r.isCleared=!0,r.promise?.catch(()=>{}),r.reject(t);this.#p.clear(),this.#K(),this.#S(),this.#s("next")}async onEmpty(){this.#r.size!==0&&await this.#m(["empty","active"],()=>this.#r.size===0)}async onSizeLessThan(t){this.#r.size<t||await this.#m(["next","active"],()=>this.#r.size<t)}async onIdle(){this.#n===0&&this.#r.size===0||await this.#m("idle")}async onPendingZero(){this.#n!==0&&await this.#m("pendingZero")}async onRateLimit(){this.#S(),!this.isRateLimited&&await this.#m("rateLimit")}async onRateLimitCleared(){this.#S(),this.isRateLimited&&await this.#m("rateLimitCleared")}onError(){return new Promise((t,r)=>{this.addEventListener("error",n=>{r(n.detail)},{once:!0})})}get size(){return this.#r.size}sizeBy(t){return this.#r.filter(t).length}get pending(){return this.#n}get isPaused(){return this.#l}get isRateLimited(){return this.#D}get isSaturated(){return this.#r.size>0&&(this.#n>=this.#E||this.isRateLimited)}get runningTasks(){return Array.from(this.#B,t=>({...t,timeoutRemaining:t.timeout===void 0?void 0:Math.max(0,t.startTime+t.timeout-Date.now())}))}},hi=class extends DOMException{constructor(t){super(t,"TimeoutError")}};var hn=class{entries;validityMs;lastPruneTime=0;constructor(t){this.entries=new Map,this.validityMs=t.validityMs}put(t,r){this.entries.set(t,{value:r,validUntilMs:Date.now()+this.validityMs}),this.prune()}prune(){let t=Date.now();if(!(t-this.lastPruneTime<200)){this.lastPruneTime=t;for(let[r,n]of this.entries.entries())if(n.validUntilMs<t)this.entries.delete(r);else break}}has(t){return this.entries.has(t)}get(t){let r=this.entries.get(t);return r!=null&&r.validUntilMs>=Date.now()?r.value:void 0}clear(){this.entries=new Map,this.lastPruneTime=0}};var Ia={maxSubscriptions:5e3,maxMessages:5e3};function Ta(e){return{subscriptions:e.maxSubscriptions,messages:e.maxMessages}}var Se;(function(e){let t;(function(a){let c;a.codec=()=>(c==null&&(c=ie((l,h,b={})=>{b.lengthDelimited!==!1&&h.fork(),l.subscribe!=null&&(h.uint32(8),h.bool(l.subscribe)),l.topic!=null&&(h.uint32(18),h.string(l.topic)),b.lengthDelimited!==!1&&h.ldelim()},(l,h,b={})=>{let g={},E=h==null?l.len:l.pos+h;for(;l.pos<E;){let w=l.uint32();switch(w>>>3){case 1:{g.subscribe=l.bool();break}case 2:{g.topic=l.string();break}default:{l.skipType(w&7);break}}}return g},function*(l,h,b,g={}){let E=h==null?l.len:l.pos+h;for(;l.pos<E;){let w=l.uint32();switch(w>>>3){case 1:{yield{field:`${b}.subscribe`,value:l.bool()};break}case 2:{yield{field:`${b}.topic`,value:l.string()};break}default:{l.skipType(w&7);break}}}})),c);function u(l){return ne(l,a.codec())}a.encode=u;function f(l,h){return re(l,a.codec(),h)}a.decode=f;function d(l,h){return se(l,a.codec(),h)}a.stream=d})(t=e.SubOpts||(e.SubOpts={}));let r;(function(a){let c;a.codec=()=>(c==null&&(c=ie((l,h,b={})=>{b.lengthDelimited!==!1&&h.fork(),l.from!=null&&(h.uint32(10),h.bytes(l.from)),l.data!=null&&(h.uint32(18),h.bytes(l.data)),l.sequenceNumber!=null&&(h.uint32(26),h.bytes(l.sequenceNumber)),l.topic!=null&&(h.uint32(34),h.string(l.topic)),l.signature!=null&&(h.uint32(42),h.bytes(l.signature)),l.key!=null&&(h.uint32(50),h.bytes(l.key)),b.lengthDelimited!==!1&&h.ldelim()},(l,h,b={})=>{let g={},E=h==null?l.len:l.pos+h;for(;l.pos<E;){let w=l.uint32();switch(w>>>3){case 1:{g.from=l.bytes();break}case 2:{g.data=l.bytes();break}case 3:{g.sequenceNumber=l.bytes();break}case 4:{g.topic=l.string();break}case 5:{g.signature=l.bytes();break}case 6:{g.key=l.bytes();break}default:{l.skipType(w&7);break}}}return g},function*(l,h,b,g={}){let E=h==null?l.len:l.pos+h;for(;l.pos<E;){let w=l.uint32();switch(w>>>3){case 1:{yield{field:`${b}.from`,value:l.bytes()};break}case 2:{yield{field:`${b}.data`,value:l.bytes()};break}case 3:{yield{field:`${b}.sequenceNumber`,value:l.bytes()};break}case 4:{yield{field:`${b}.topic`,value:l.string()};break}case 5:{yield{field:`${b}.signature`,value:l.bytes()};break}case 6:{yield{field:`${b}.key`,value:l.bytes()};break}default:{l.skipType(w&7);break}}}})),c);function u(l){return ne(l,a.codec())}a.encode=u;function f(l,h){return re(l,a.codec(),h)}a.decode=f;function d(l,h){return se(l,a.codec(),h)}a.stream=d})(r=e.Message||(e.Message={}));let n;e.codec=()=>(n==null&&(n=ie((a,c,u={})=>{if(u.lengthDelimited!==!1&&c.fork(),a.subscriptions!=null&&a.subscriptions.length>0)for(let f of a.subscriptions)c.uint32(10),e.SubOpts.codec().encode(f,c);if(a.messages!=null&&a.messages.length>0)for(let f of a.messages)c.uint32(18),e.Message.codec().encode(f,c);u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={subscriptions:[],messages:[]},d=c==null?a.len:a.pos+c;for(;a.pos<d;){let l=a.uint32();switch(l>>>3){case 1:{if(u.limits?.subscriptions!=null&&f.subscriptions.length===u.limits.subscriptions)throw new ge('Decode error - repeated field "subscriptions" had too many elements');f.subscriptions.push(e.SubOpts.codec().decode(a,a.uint32(),{limits:u.limits?.subscriptions$}));break}case 2:{if(u.limits?.messages!=null&&f.messages.length===u.limits.messages)throw new ge('Decode error - repeated field "messages" had too many elements');f.messages.push(e.Message.codec().decode(a,a.uint32(),{limits:u.limits?.messages$}));break}default:{a.skipType(l&7);break}}}return f},function*(a,c,u,f={}){let d={subscriptions:0,messages:0},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let h=a.uint32();switch(h>>>3){case 1:{if(f.limits?.subscriptions!=null&&d.subscriptions===f.limits.subscriptions)throw new ge('Streaming decode error - repeated field "subscriptions" had too many elements');for(let b of e.SubOpts.codec().stream(a,a.uint32(),`${u}.subscriptions[]`,{limits:f.limits?.subscriptions$}))yield{...b,index:d.subscriptions};d.subscriptions++;break}case 2:{if(f.limits?.messages!=null&&d.messages===f.limits.messages)throw new ge('Streaming decode error - repeated field "messages" had too many elements');for(let b of e.Message.codec().stream(a,a.uint32(),`${u}.messages[]`,{limits:f.limits?.messages$}))yield{...b,index:d.messages};d.messages++;break}default:{a.skipType(h&7);break}}}})),n);function s(a){return ne(a,e.codec())}e.encode=s;function i(a,c){return re(a,e.codec(),c)}e.decode=i;function o(a,c){return se(a,e.codec(),c)}e.stream=o})(Se||(Se={}));var dn=class extends Ae{peerId;shutDownController;inboundPb;outboundPb;constructor(t){super(),this.peerId=t,this.shutDownController=new AbortController}attachInboundStream(t,r,n){this.inboundPb=fi(t,r).pb(Se),Promise.resolve().then(async()=>{for(;;){if(this.inboundPb==null)return;let s=await this.inboundPb.read({signal:this.shutDownController.signal,limits:n});this.safeDispatchEvent("message",{detail:s})}}).catch(s=>{this.inboundPb?.unwrap().unwrap().abort(s),this.close()})}attachOutboundStream(t,r){this.outboundPb=fi(t,r).pb(Se)}write(t){this.outboundPb!=null&&this.outboundPb.write(t,{signal:this.shutDownController.signal}).catch(r=>{this.outboundPb?.unwrap().unwrap().abort(r)})}close(){this.shutDownController.abort(),Promise.all([this.inboundPb?.unwrap().unwrap().close().catch(t=>{this.inboundPb?.unwrap().unwrap().abort(t)}),this.outboundPb?.unwrap().unwrap().close().catch(t=>{this.inboundPb?.unwrap().unwrap().abort(t)})]).finally(()=>{this.safeDispatchEvent("close")})}};function La(){return BigInt(`0x${Z(crypto.getRandomValues(new Uint8Array(8)),"base16")}`)}var Ra=(e,t)=>{let r=Y(t.toString(16).padStart(16,"0"),"base16"),n=Kt(e),s=new Uint8Array(n.byteLength+r.length);return s.set(n,0),s.set(r,n.byteLength),s},_a=e=>ue.encode(e);var Xf=async e=>{if(e.sequenceNumber==null||e.from==null||e.signature==null)return!1;let t=br(Vt(e.from));if(t.publicKey!=null)return!0;if(e.key!=null){let r=e.key;return ri(ei(r)).equals(t)}return!1},Da=async e=>{if(e.from==null)throw new ct("RPC message was missing from");if(!await Xf(e))return{type:"unsigned",topic:e.topic??"",data:e.data??new Uint8Array(0)};let t=br(Vt(e.from)),r=e.key??t.publicKey;if(r==null)throw new ct("RPC message was missing public key");return{type:"signed",from:t,topic:e.topic??"",sequenceNumber:Qf(e.sequenceNumber??new Uint8Array(0)),data:e.data??new Uint8Array(0),signature:e.signature??new Uint8Array(0),key:r instanceof Uint8Array?ei(r):r}},xr=e=>e.type==="signed"?{from:e.from.toMultihash().bytes,data:e.data,sequenceNumber:Jf(e.sequenceNumber),topic:e.topic,signature:e.signature,key:e.key?Kt(e.key):void 0}:{data:e.data,topic:e.topic},Jf=e=>{let t=e.toString(16);return t.length%2!==0&&(t=`0${t}`),Y(t,"base16")},Qf=e=>BigInt(`0x${Z(e,"base16")}`);var Ca=Y("libp2p-pubsub:");async function Pa(e,t,r){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:xa(e)},s=ce([Ca,r(xr(n)).subarray()]);return n.signature=await e.sign(s),n.key=e.publicKey,n}async function Oa(e,t){if(e.type!=="signed")throw new Error('Message type must be "signed" to be verified');if(e.signature==null)throw new Error("Message must contain a signature to be verified");if(e.from==null)throw new Error("Message must contain a from property to be verified");let r=ce([Ca,t({...xr(e),signature:void 0,key:void 0}).subarray()]);return tl(e).verify(r,e.signature)}function tl(e){if(e.type!=="signed")throw new Error('Message type must be "signed" to have a public key');if(e.from==null)throw new Error("Could not get the public key from the originator id");if(e.from.publicKey!=null)return e.from.publicKey;if(e.key!=null&&e.from.equals(e.key.toMultihash().bytes))return e.key;throw new Error("Could not get the public key from the originator id")}var pn=class extends Ae{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;protocol;components;_registrarTopologyId;maxInboundStreams;maxOutboundStreams;seenCache;decodeRpcLimits;constructor(t,r){super(),this.log=t.logger.forComponent("libp2p:floodsub"),this.components=t,this.protocol=r.protocol??di,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new yr,this.globalSignaturePolicy=r.globalSignaturePolicy==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=r.canRelayMessage??!0,this.emitSelf=r.emitSelf??!1,this.topicValidators=new Map,this.queue=new wr({concurrency:r.messageProcessingConcurrency??10}),this.maxInboundStreams=r.maxInboundStreams??1,this.maxOutboundStreams=r.maxOutboundStreams??1,this.seenCache=new hn({validityMs:r?.seenTTL??3e4}),this.decodeRpcLimits=Ta(r.decodeRpcLimits??Ia),this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}[Ve]=!0;[Symbol.toStringTag]="@libp2p/floodsub";[bi]=["@libp2p/pubsub"];[yi]=["@libp2p/identify"];async start(){this.started||(this.log("starting"),await this.components.registrar.handle(this.protocol,this._onIncomingStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this._registrarTopologyId=await this.components.registrar.register(this.protocol,{onConnect:this._onPeerConnected,onDisconnect:this._onPeerDisconnected}),this.log("started"),this.started=!0)}async stop(){if(!this.started)return;let t=this.components.registrar;this._registrarTopologyId!=null&&t.unregister(this._registrarTopologyId),await t.unhandle(this.protocol),this.log("stopping");for(let r of this.peers.values())r.close();this.peers.clear(),this.topics.clear(),this.subscriptions=new Set,this.started=!1,this.log("stopped")}isStarted(){return this.started}_onIncomingStream(t,r){this.addPeer(r.remotePeer,t).attachInboundStream(t,void 0,this.decodeRpcLimits)}async _onPeerConnected(t,r){if(this.log("connected %p",t),r.streams.find(i=>i.direction==="outbound"&&i.protocol===this.protocol)){this.log("outbound pubsub stream already present on connection from %p",t);return}let n=await r.newStream(this.protocol);this.addPeer(t,n).attachOutboundStream(n),this.send(t,{subscriptions:Array.from(this.subscriptions).map(i=>i.toString()),subscribe:!0})}_onPeerDisconnected(t,r){this.log("connection ended %p",t),this._removePeer(t)}addPeer(t,r){let n=this.peers.get(t);if(n!=null)return n;this.log("new peer %p",t);let s=new dn(t);return this.peers.set(t,s),s.addEventListener("message",i=>{let o=i.detail,a=[];for(let c of o.messages??[]){if(c.from==null||c.data==null||c.topic==null){this.log("message from %p was missing from, data or topic fields, dropping",t);continue}a.push({from:c.from,data:c.data,topic:c.topic,sequenceNumber:c.sequenceNumber??void 0,signature:c.signature??void 0,key:c.key??void 0})}this.processRpc(s,{subscriptions:(o.subscriptions??[]).map(c=>({subscribe:!!c.subscribe,topic:c.topic??""})),messages:a}).catch(c=>{this.log(c)})}),s.addEventListener("close",()=>this._removePeer(t),{once:!0}),s}_removePeer(t){let r=this.peers.get(t);if(r!=null){r.close(),this.log("delete peer %p",t),this.peers.delete(t);for(let[n,s]of this.topics)s.delete(t),s.size===0&&this.topics.delete(n)}}async processRpc(t,r){this.log("rpc from %p",t.peerId);let{subscriptions:n,messages:s}=r;return n!=null&&n.length>0&&(this.log("subscription update from %p",t.peerId),n.forEach(i=>{this.processRpcSubOpt(t.peerId,i)}),super.dispatchEvent(new CustomEvent("subscription-change",{detail:{peerId:t.peerId,subscriptions:n.map(({topic:i,subscribe:o})=>({topic:`${i??""}`,subscribe:!!o}))}}))),s!=null&&s.length>0&&(this.log("messages from %p",t.peerId),this.queue.addAll(s.map(i=>async()=>{if(i.topic==null||!this.subscriptions.has(i.topic)&&!this.canRelayMessage)return this.log("received message we didn't subscribe to. Dropping."),!1;try{let o=await Da(i);await this.processMessage(t.peerId,o)}catch(o){this.log.error("failed to queue messages from %p - %e",t.peerId,o)}})).catch(i=>{this.log(i)})),!0}processRpcSubOpt(t,r){let n=r.topic;if(n==null)return;let s=this.topics.get(n);r.subscribe===!0?(s==null&&(s=new gr,this.topics.set(n,s)),s.add(t)):s!=null&&(s.delete(t),s.size===0&&this.topics.delete(n))}async processMessage(t,r){if(this.components.peerId.equals(t)&&!this.emitSelf)return;let n=await this.getMsgId(r),s=Z(n,"base64");if(!this.seenCache.has(s)){this.seenCache.put(s,!0);try{await this.validate(t,r)}catch(i){this.log("Message is invalid, dropping it. %O",i);return}this.subscriptions.has(r.topic)&&(!this.components.peerId.equals(t)||this.emitSelf)&&super.dispatchEvent(new CustomEvent("message",{detail:r})),await this.publishMessage(t,r)}}getMsgId(t){switch(this.globalSignaturePolicy){case"StrictSign":if(t.type!=="signed")throw new ct('Message type should be "signed" when signature policy is StrictSign but it was not');if(t.sequenceNumber==null)throw new ct("Need sequence number when signature policy is StrictSign but it was missing");if(t.key==null)throw new ct("Need key when signature policy is StrictSign but it was missing");return Ra(t.key,t.sequenceNumber);case"StrictNoSign":return _a(t.data);default:throw new ct("Cannot get message id: unhandled signature policy")}}encodeMessage(t){return Se.Message.encode(t)}send(t,r){let{messages:n,subscriptions:s,subscribe:i}=r;this.sendRpc(t,{subscriptions:(s??[]).map(o=>({topic:o,subscribe:!!i})),messages:(n??[]).map(xr)})}sendRpc(t,r){let n=this.peers.get(t);if(n==null){this.log.error("cannot send RPC to %p as there are no streams to it available",t);return}n.write(r)}async validate(t,r){switch(this.globalSignaturePolicy){case"StrictNoSign":if(r.type!=="unsigned")throw new ct('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(r.signature!=null)throw new ct("StrictNoSigning: signature should not be present");if(r.key!=null)throw new ct("StrictNoSigning: key should not be present");if(r.sequenceNumber!=null)throw new ct("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(r.type!=="signed")throw new ct('Message type should be "signed" when signature policy is StrictSign but it was not');if(r.signature==null)throw new ct("StrictSigning: Signing required and no signature was present");if(r.sequenceNumber==null)throw new ct("StrictSigning: Signing required and no sequenceNumber was present");if(!await Oa(r,this.encodeMessage.bind(this)))throw new ct("StrictSigning: Invalid message signature");break;default:throw new ct("Cannot validate message: unhandled signature policy")}let s=this.topicValidators.get(r.topic);if(s!=null){let i=await s(t,r);if(i===ze.Reject||i===ze.Ignore)throw new ct("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return Pa(this.components.privateKey,t,this.encodeMessage.bind(this));case"StrictNoSign":return Promise.resolve({type:"unsigned",...t});default:throw new ct("Cannot build message: unhandled signature policy")}}getSubscribers(t){if(!this.started)throw new vr("not started yet");if(t==null)throw new et("Topic is required");let r=this.topics.get(t.toString());return r==null?[]:Array.from(r.values())}async publish(t,r){if(!this.started)throw new Error("Pubsub has not started");let n={from:this.components.peerId,topic:t,data:r??new Uint8Array(0),sequenceNumber:La()};this.log("publish topic: %s from: %p data: %m",t,n.from,n.data);let s=await this.buildMessage(n),i=!1;this.emitSelf&&this.subscriptions.has(t)&&(i=!0,super.dispatchEvent(new CustomEvent("message",{detail:s})));let o=await this.publishMessage(this.components.peerId,s);return i&&(o.recipients=[...o.recipients,this.components.peerId]),o}async publishMessage(t,r){let n=this.getSubscribers(r.topic),s=[];return n==null||n.length===0?(this.log("no peers are subscribed to topic %s",r.topic),{recipients:s}):(n.forEach(i=>{if(this.components.peerId.equals(i)){this.log("not sending message on topic %s to myself",r.topic);return}if(i.equals(t)){this.log("not sending message on topic %s to sender %p",r.topic,i);return}this.log("publish msgs on topics %s %p",r.topic,i),s.push(i),this.send(i,{messages:[r]})}),{recipients:s})}subscribe(t){if(!this.started)throw new Error("Pubsub has not started");if(!this.subscriptions.has(t)){this.log("subscribe to topic: %s",t),this.subscriptions.add(t);for(let r of this.peers.keys())this.send(r,{subscriptions:[t],subscribe:!0})}}unsubscribe(t){if(!this.started)throw new Error("Pubsub is not started");if(this.subscriptions.has(t)){this.log("unsubscribe from %s",t),this.subscriptions.delete(t);for(let r of this.peers.keys())this.send(r,{subscriptions:[t],subscribe:!1})}}getTopics(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.subscriptions)}getPeers(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.peers.keys())}};var di="/floodsub/1.0.0",el="StrictSign",rl="StrictNoSign",ze;(function(e){e.Accept="accept",e.Ignore="ignore",e.Reject="reject"})(ze||(ze={}));function nl(e){return!!e?.[Ve]}function sl(e={}){return t=>new pn(t,e)}return za(il);})();
|
|
2
|
+
"use strict";var Libp2PFloodsub=(()=>{var yn=Object.defineProperty;var Ua=Object.getOwnPropertyDescriptor;var qa=Object.getOwnPropertyNames;var za=Object.prototype.hasOwnProperty;var bt=(e,t)=>{for(var r in t)yn(e,r,{get:t[r],enumerable:!0})},Ha=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of qa(t))!za.call(e,s)&&s!==r&&yn(e,s,{get:()=>t[s],enumerable:!(n=Ua(t,s))||n.enumerable});return e};var $a=e=>Ha(yn({},"__esModule",{value:!0}),e);var hl={};bt(hl,{StrictNoSign:()=>ul,StrictSign:()=>cl,TopicValidatorResult:()=>ze,floodsub:()=>ll,isPubSub:()=>fl,protocol:()=>di,pubSubSymbol:()=>$e});var $e=Symbol.for("@libp2p/pubsub");var et=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Dt=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Er=class extends Error{static name="StreamBufferError";constructor(t="The stream buffer was full"){super(t),this.name="StreamBufferError"}};var Sr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var ct=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var vr=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var ae=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var gn=Symbol.for("@libp2p/peer-id");function Va(e){return typeof e?.handleEvent=="function"}function ja(e){return e===!0||e===!1}function Za(e){return ja(e)?e:e?.capture??!1}function wn(e){let t={capture:Za(e),once:!!e?.once};return e?.passive!=null&&(t.passive=e?.passive),e?.signal!=null&&(t.signal=e?.signal),t}function mi(e,t){return wn(e).capture===wn(t).capture}var Ae=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){let s=wn(n);if(s?.signal?.aborted===!0)return;let i=u=>{s.once&&this.removeEventListener(t,r,s),Va(r)?r.handleEvent(u):r(u)},o=this.#t.get(t);if(o==null&&(o=[],this.#t.set(t,o)),o.some(u=>u.callback!==r?!1:mi(u.options,s)))return;super.addEventListener(t,i,s);let c=()=>{this.removeEventListener(t,r,s)};s.signal?.addEventListener("abort",c),o.push({callback:r,wrapper:i,options:s,onAbort:c})}removeEventListener(t,r,n){let s=this.#t.get(t);if(s==null){super.removeEventListener(t,r??null,n);return}this.#t.set(t,s.filter(i=>i.callback===r&&mi(i.options,n)?(super.removeEventListener(t,i.wrapper,n),i.options?.signal?.removeEventListener("abort",i.onAbort),!1):!0))}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var bi=Symbol.for("@libp2p/service-capabilities"),yi=Symbol.for("@libp2p/service-dependencies");function ht(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}var An={};bt(An,{base58btc:()=>rt,base58flickr:()=>ec});var $l=new Uint8Array(0);function wi(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function vt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return ce(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return ce(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));throw new Error("Unknown type, must be binary type")}function xi(e){let t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}var gi=4096;function Ei(e){let t=e.length;if(t<=gi)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.subarray(n,n+=gi));return r}function Ya(e){return e?.buffer instanceof ArrayBuffer}function ce(e){return Ya(e)?e:e.slice()}function Ga(e,t,r){if(e.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),s=0;s<n.length;s++)n[s]=255;for(var i=0;i<e.length;i++){var o=e.charAt(i),a=o.charCodeAt(0);if(n[a]!==255)throw new TypeError(o+" is ambiguous");if(n[a]=i,r){var c=o.toLowerCase().charCodeAt(0),u=o.toUpperCase().charCodeAt(0);c!==a&&(n[c]=i),u!==a&&(n[u]=i)}}var f=e.length,h=e.charAt(0),l=Math.log(f)/Math.log(256),d=Math.log(256)/Math.log(f);function y(w){if(w instanceof Uint8Array||(ArrayBuffer.isView(w)?w=new Uint8Array(w.buffer,w.byteOffset,w.byteLength):Array.isArray(w)&&(w=Uint8Array.from(w))),!(w instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(w.length===0)return"";for(var v=0,m=0,S=0,B=w.length;S!==B&&w[S]===0;)S++,v++;for(var P=(B-S)*d+1>>>0,K=new Uint8Array(P);S!==B;){for(var k=w[S],_=0,C=P-1;(k!==0||_<m)&&C!==-1;C--,_++)k+=256*K[C]>>>0,K[C]=k%f>>>0,k=k/f>>>0;if(k!==0)throw new Error("Non-zero carry");m=_,S++}for(var q=P-m;q!==P&&K[q]===0;)q++;for(var U=h.repeat(v);q<P;++q)U+=e.charAt(K[q]);return U}function g(w){if(typeof w!="string")throw new TypeError("Expected String");if(w.length===0)return new Uint8Array;var v=0;if(w[v]!==" "){for(var m=0,S=0;w[v]===h;)m++,v++;for(var B=(w.length-v)*l+1>>>0,P=new Uint8Array(B);w[v];){var K=n[w.charCodeAt(v)];if(K===255)return;for(var k=0,_=B-1;(K!==0||k<S)&&_!==-1;_--,k++)K+=f*P[_]>>>0,P[_]=K%256>>>0,K=K/256>>>0;if(K!==0)throw new Error("Non-zero carry");S=k,v++}if(w[v]!==" "){for(var C=B-S;C!==B&&P[C]===0;)C++;for(var q=new Uint8Array(m+(B-C)),U=m;C!==B;)q[U++]=P[C++];return q}}}function E(w){var v=g(w);if(v)return v;throw new Error(`Non-${t} character`)}return{encode:y,decodeUnsafe:g,decode:E}}var Wa=Ga,Xa=Wa,vi=Xa;var xn=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")}},En=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let s=r.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Ai(this,t)}},Sn=class{decoders;constructor(t){this.decoders=t}or(t){return Ai(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ai(e,t){return new Sn({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var vn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,s){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=s,this.encoder=new xn(t,r,n),this.decoder=new En(t,r,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Be({name:e,prefix:t,encode:r,decode:n}){return new vn(e,t,r,n)}function $t({name:e,prefix:t,alphabet:r,caseInsensitive:n=!1}){let{encode:s,decode:i}=vi(r,e,n);return Be({prefix:t,name:e,encode:s,decode:o=>vt(i(o))})}function Ja(e,t,r,n){let s=e.length;for(;e[s-1]==="=";)--s;let i=new Uint8Array(s*r/8|0),o=0,a=0,c=0;for(let u=0;u<s;++u){let f=t[e[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,o+=r,o>=8&&(o-=8,i[c++]=255&a>>o)}if(o>=r||(255&a<<8-o)!==0)throw new SyntaxError("Unexpected end of data");return i}function Qa(e,t,r){let n=t[t.length-1]==="=",s=(1<<r)-1,i="",o=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],o+=8;o>r;)o-=r,i+=t[s&a>>o];if(o!==0&&(i+=t[s&a<<r-o]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function tc(e,t){let r={};for(let n=0;n<e.length;++n)if(r[e[n]]=n,t){let s=e[n].toLowerCase(),i=e[n].toUpperCase();s!==e[n]&&(r[s]=n),i!==e[n]&&(r[i]=n)}return r}function it({name:e,prefix:t,bitsPerChar:r,alphabet:n,caseInsensitive:s=!1}){let i=tc(n,s);return Be({prefix:t,name:e,encode(o){return Qa(o,n,r)},decode(o){return Ja(o,i,r,e)}})}var rt=$t({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ec=$t({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Bn={};bt(Bn,{base32:()=>Ie,base32hex:()=>ic,base32hexpad:()=>ac,base32hexpadupper:()=>cc,base32hexupper:()=>oc,base32pad:()=>nc,base32padupper:()=>sc,base32upper:()=>rc,base32z:()=>uc});var Ie=it({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),rc=it({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),nc=it({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),sc=it({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),ic=it({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),oc=it({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),ac=it({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),cc=it({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),uc=it({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var In={};bt(In,{base36:()=>Ve,base36upper:()=>fc});var Ve=$t({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),fc=$t({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var lc=Ti,Bi=128,hc=127,dc=~hc,pc=Math.pow(2,31);function Ti(e,t,r){t=t||[],r=r||0;for(var n=r;e>=pc;)t[r++]=e&255|Bi,e/=128;for(;e&dc;)t[r++]=e&255|Bi,e>>>=7;return t[r]=e|0,Ti.bytes=r-n+1,t}var mc=Tn,bc=128,Ii=127;function Tn(e,n){var r=0,n=n||0,s=0,i=n,o,a=e.length;do{if(i>=a)throw Tn.bytes=0,new RangeError("Could not decode varint");o=e[i++],r+=s<28?(o&Ii)<<s:(o&Ii)*Math.pow(2,s),s+=7}while(o>=bc);return Tn.bytes=i-n,r}var yc=Math.pow(2,7),gc=Math.pow(2,14),wc=Math.pow(2,21),xc=Math.pow(2,28),Ec=Math.pow(2,35),Sc=Math.pow(2,42),vc=Math.pow(2,49),Ac=Math.pow(2,56),Bc=Math.pow(2,63),Ic=function(e){return e<yc?1:e<gc?2:e<wc?3:e<xc?4:e<Ec?5:e<Sc?6:e<vc?7:e<Ac?8:e<Bc?9:10},Tc={encode:lc,decode:mc,encodingLength:Ic},Lc=Tc,je=Lc;function Ze(e,t=0){let r=je.decode(e,t),n=je.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&e[t+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function Te(e,t,r=0){return je.encode(e,t,r),t}function Le(e){return je.encodingLength(e)}function Ct(e,t){let r=t.byteLength,n=Le(e),s=n+Le(r),i=new Uint8Array(s+r);return Te(e,i,0),Te(r,i,n),i.set(t,s),new Re(e,r,t,i)}function Vt(e){let t=vt(e),[r,n]=Ze(t),[s,i]=Ze(t.subarray(n)),o=t.subarray(n+i);if(o.byteLength!==s)throw new Error("Incorrect length");return new Re(r,s,o,t)}function Li(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&wi(e.bytes,r.bytes)}}var Re=class{code;size;digest;bytes;constructor(t,r,n,s){this.code=t,this.size=r,this.digest=ce(n),this.bytes=ce(s)}};function Ri(e,t){let{bytes:r,version:n}=e;return n===0?_c(r,Ln(e),t??rt.encoder):Dc(r,Ln(e),t??Ie.encoder)}var _i=new WeakMap;function Ln(e){let t=_i.get(e);if(t==null){let r=new Map;return _i.set(e,r),r}return t}var dt=class e{code;version;multihash;bytes;"/";constructor(t,r,n,s){this.code=r,this.version=t,this.multihash=n,this.bytes=ce(s),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==Ye)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Cc)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=Ct(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&&Li(t.multihash,n.multihash)}toString(t){return Ri(this,t)}toJSON(){return{"/":Ri(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:s,multihash:i,bytes:o}=r;return new e(n,s,i,o??Di(n,s,i.bytes))}else if(r[Pc]===!0){let{version:n,multihash:s,code:i}=r,o=Vt(s);return e.create(n,i,o)}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!==Ye)throw new Error(`Version 0 CID must use dag-pb (code: ${Ye}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let s=Di(t,r,n.bytes);return new e(t,r,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Ye,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,s=vt(t.subarray(n,n+r.multihashSize));if(s.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=s.subarray(r.multihashSize-r.digestSize),o=new Re(r.multihashCode,r.digestSize,i,s);return[r.version===0?e.createV0(o):e.createV1(r.codec,o),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[h,l]=Ze(t.subarray(r));return r+=l,h},s=n(),i=Ye;if(s===18?(s=0,r=0):i=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let o=r,a=n(),c=n(),u=r+c,f=u-o;return{version:s,codec:i,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,r){let[n,s]=Rc(t,r),i=e.decode(s);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ln(i).set(n,t),i}};function Rc(e,t){switch(e[0]){case"Q":{let r=t??rt;return[rt.prefix,r.decode(`${rt.prefix}${e}`)]}case rt.prefix:{let r=t??rt;return[rt.prefix,r.decode(e)]}case Ie.prefix:{let r=t??Ie;return[Ie.prefix,r.decode(e)]}case Ve.prefix:{let r=t??Ve;return[Ve.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 _c(e,t,r){let{prefix:n}=r;if(n!==rt.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let s=t.get(n);if(s==null){let i=r.encode(e).slice(1);return t.set(n,i),i}else return s}function Dc(e,t,r){let{prefix:n}=r,s=t.get(n);if(s==null){let i=r.encode(e);return t.set(n,i),i}else return s}var Ye=112,Cc=18;function Di(e,t,r){let n=Le(e),s=n+Le(t),i=new Uint8Array(s+r.byteLength);return Te(e,i,0),Te(t,i,n),i.set(r,s),i}var Pc=Symbol.for("@ipld/js-cid/CID");var Rn={};bt(Rn,{identity:()=>Lt});var Ci=0,Oc="identity",Pi=vt;function kc(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 Ct(Ci,Pi(e))}var Lt={code:Ci,name:Oc,encode:Pi,digest:kc};function Nc(e){return e.buffer instanceof ArrayBuffer}function At(e){return Nc(e)?e:e.slice()}async function Oi(e,t,r,n){let s=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let i=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},s,At(t),At(r.subarray()));return n?.signal?.throwIfAborted(),i}function Nt(e=0){return new Uint8Array(e)}function yt(e=0){return new Uint8Array(e)}function Kc(e){return e?.buffer instanceof ArrayBuffer}function ki(e){if(Kc(e))return e;let t=e.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function ue(e,t){t==null&&(t=e.reduce((s,i)=>s+i.length,0));let r=yt(t),n=0;for(let s of e)r.set(s,n),n+=s.length;return ki(r)}var Ki=Symbol.for("@achingbrain/uint8arraylist");function Ni(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let s=r+n.byteLength;if(t<s)return{buf:n,index:t-r};r=s}throw new RangeError("index is out of bounds")}function Br(e){return!!e?.[Ki]}var lt=class e{bufs;length;[Ki]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Br(n)){r+=n.byteLength;for(let s of n.bufs)this.bufs.push(s)}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(Br(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=Ni(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Ni(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(Br(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:s}=this._subList(t,r);return ue(n,s)}subarray(t,r){let{bufs:n,length:s}=this._subList(t,r);return n.length===1?n[0]:ue(n,s)}sublist(t,r){let{bufs:n,length:s}=this._subList(t,r),i=new e;return i.length=s,i.bufs=n,i}_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=[],s=0;for(let i=0;i<this.bufs.length;i++){let o=this.bufs[i],a=s,c=a+o.byteLength;if(s=c,t>=c)continue;let u=t>=a&&t<c,f=r>a&&r<=c;if(u&&f){if(t===a&&r===c){n.push(o);break}let h=t-a;n.push(o.subarray(h,h+(r-t)));break}if(u){if(t===0){n.push(o);continue}n.push(o.subarray(t-a));continue}if(f){if(r===c){n.push(o);break}n.push(o.subarray(0,r-a));break}n.push(o)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Br(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 s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let i=256,o=new Int32Array(i);for(let h=0;h<i;h++)o[h]=-1;for(let h=0;h<s;h++)o[n[h]]=h;let a=o,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let h=r;h<=c;h+=f){f=0;for(let l=u;l>=0;l--){let d=this.get(h+l);if(n[l]!==d){f=Math.max(1,l-a[d]);break}}if(f===0)return h}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=yt(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 s=Nt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,r,n),this.write(s,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 s=Nt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,r,n),this.write(s,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 s=Nt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,r,n),this.write(s,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=yt(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 s=Nt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,r,n),this.write(s,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 s=Nt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,r,n),this.write(s,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 s=Nt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,r,n),this.write(s,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 s=Nt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,r,n),this.write(s,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 s=Nt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,r,n),this.write(s,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(!ht(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((s,i)=>s+i.byteLength,0)),n.length=r,n}};var _n={};bt(_n,{base10:()=>Fc});var Fc=$t({prefix:"9",name:"base10",alphabet:"0123456789"});var Dn={};bt(Dn,{base16:()=>Mc,base16upper:()=>Uc});var Mc=it({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Uc=it({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Cn={};bt(Cn,{base2:()=>qc});var qc=it({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Pn={};bt(Pn,{base256emoji:()=>jc});var Fi=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}"),zc=Fi.reduce((e,t,r)=>(e[r]=t,e),[]),Hc=Fi.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function $c(e){return e.reduce((t,r)=>(t+=zc[r],t),"")}function Vc(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let s=Hc[n];if(s==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(s)}return new Uint8Array(t)}var jc=Be({prefix:"\u{1F680}",name:"base256emoji",encode:$c,decode:Vc});var On={};bt(On,{base64:()=>Zc,base64pad:()=>Yc,base64url:()=>Gc,base64urlpad:()=>Wc});var Zc=it({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Yc=it({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Gc=it({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Wc=it({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var kn={};bt(kn,{base8:()=>Xc});var Xc=it({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Nn={};bt(Nn,{identity:()=>Jc});var Jc=Be({prefix:"\0",name:"identity",encode:e=>Ei(vt(e)),decode:e=>vt(xi(e))});var Lh=new TextEncoder,Rh=new TextDecoder;var Mn={};bt(Mn,{sha256:()=>fe,sha512:()=>ru});var eu=20;function Fn({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:s}){return new Kn(e,t,r,n,s)}var Kn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,s,i){this.name=t,this.code=r,this.encode=n,this.minDigestLength=s??eu,this.maxDigestLength=i}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?Mi(n,this.code,r?.truncate):n.then(s=>Mi(s,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Mi(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 Ct(t,e)}function qi(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var fe=Fn({name:"sha2-256",code:18,encode:qi("SHA-256")}),ru=Fn({name:"sha2-512",code:19,encode:qi("SHA-512")});var Un={...Nn,...Cn,...kn,..._n,...Dn,...Bn,...In,...An,...On,...Pn},qh={...Mn,...Rn};function Hi(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var zi=Hi("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),qn=Hi("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=yt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),nu={utf8:zi,"utf-8":zi,hex:Un.base16,latin1:qn,ascii:qn,binary:qn,...Un},Ir=nu;function Y(e,t="utf8"){let r=Ir[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function Z(e,t="utf8"){let r=Ir[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var su=parseInt("11111",2),zn=parseInt("10000000",2),iu=parseInt("01111111",2),$i={0:Ge,1:Ge,2:ou,3:uu,4:fu,5:cu,6:au,16:Ge,22:Ge,48:Ge};function Kt(e,t={offset:0}){let r=e[t.offset]&su;if(t.offset++,$i[r]!=null)return $i[r](e,t);throw new Error("No decoder for tag "+r)}function We(e,t){let r=0;if((e[t.offset]&zn)===zn){let n=e[t.offset]&iu,s="0x";t.offset++;for(let i=0;i<n;i++,t.offset++){if(t.offset>=e.byteLength)throw new Error("invalid DER element length");s+=e[t.offset].toString(16).padStart(2,"0")}r=parseInt(s,16)}else r=e[t.offset],t.offset++;if(!Number.isInteger(r)||r<0||r>e.byteLength-t.offset)throw new Error("invalid DER element length");return r}function Ge(e,t){We(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Kt(e,t);if(n===null)break;r.push(n)}return r}function ou(e,t){let r=We(e,t),n=t.offset,s=t.offset+r,i=[];for(let o=n;o<s;o++)o===n&&e[o]===0||i.push(e[o]);return t.offset+=r,Uint8Array.from(i)}function au(e,t){let r=We(e,t),n=t.offset+r,s=e[t.offset];t.offset++;let i=0,o=0;s<40?(i=0,o=s):s<80?(i=1,o=s-40):(i=2,o=s-80);let a=`${i}.${o}`,c=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let h=0;h<c.length;h++)f+=c[h]<<h*7;a+=`.${f}`,c=[]}}return a}function cu(e,t){return t.offset++,null}function uu(e,t){let r=We(e,t),n=e[t.offset];t.offset++;let s=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 s}function fu(e,t){let r=We(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function lu(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new lt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Hn(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=lu(e.byteLength);return new lt(Uint8Array.from([t.byteLength|zn]),t)}function gt(e){let t=new lt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new lt(Uint8Array.from([2]),Hn(t),t)}function Tr(e){let t=Uint8Array.from([0]),r=new lt(t,e);return new lt(Uint8Array.from([3]),Hn(r),r)}function Zt(e,t=48){let r=new lt;for(let n of e)r.append(n);return new lt(Uint8Array.from([t]),Hn(r),r)}var hu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),du=Uint8Array.from([6,5,43,129,4,0,34]),pu=Uint8Array.from([6,5,43,129,4,0,35]),mu={ext:!0,kty:"EC",crv:"P-256"},bu={ext:!0,kty:"EC",crv:"P-384"},yu={ext:!0,kty:"EC",crv:"P-521"},$n=32,Vn=48,jn=66;function Zn(e){let t=Kt(e);return Vi(t)}function Vi(e){let t=e[1][1][0],r=1,n,s;if(t.byteLength===$n*2+1)return n=Z(t.subarray(r,r+$n),"base64url"),s=Z(t.subarray(r+$n),"base64url"),new _e({...mu,key_ops:["verify"],x:n,y:s});if(t.byteLength===Vn*2+1)return n=Z(t.subarray(r,r+Vn),"base64url"),s=Z(t.subarray(r+Vn),"base64url"),new _e({...bu,key_ops:["verify"],x:n,y:s});if(t.byteLength===jn*2+1)return n=Z(t.subarray(r,r+jn),"base64url"),s=Z(t.subarray(r+jn),"base64url"),new _e({...yu,key_ops:["verify"],x:n,y:s});throw new et(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function ji(e){return Zt([gt(Uint8Array.from([1])),Zt([gu(e.crv)],160),Zt([Tr(new lt(Uint8Array.from([4]),Y(e.x??"","base64url"),Y(e.y??"","base64url")))],161)]).subarray()}function gu(e){if(e==="P-256")return hu;if(e==="P-384")return du;if(e==="P-521")return pu;throw new et(`Invalid curve ${e}`)}var _e=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=ji(this.jwk)),this._raw}toMultihash(){return Lt.digest(Ft(this))}toCID(){return dt.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ht(this.raw,t.raw)}async verify(t,r,n){return Oi(this.jwk,r,t,n)}};var Lr=BigInt(4294967295),Zi=BigInt(32);function wu(e,t=!1){return t?{h:Number(e&Lr),l:Number(e>>Zi&Lr)}:{h:Number(e>>Zi&Lr)|0,l:Number(e&Lr)|0}}function Yi(e,t=!1){let r=e.length,n=new Uint32Array(r),s=new Uint32Array(r);for(let i=0;i<r;i++){let{h:o,l:a}=wu(e[i],t);[n[i],s[i]]=[o,a]}return[n,s]}var xu=e=>e/2**32|0,Eu=e=>e>>>0;function Gi(e,t,r,n){let s=xu(r),i=Eu(r);e.setUint32(t,n?i:s,n),e.setUint32(t+4,n?s:i,n)}var Yn=(e,t,r)=>e>>>r,Gn=(e,t,r)=>e<<32-r|t>>>r,le=(e,t,r)=>e>>>r|t<<32-r,he=(e,t,r)=>e<<32-r|t>>>r,Xe=(e,t,r)=>e<<64-r|t>>>r-32,Je=(e,t,r)=>e>>>r-32|t<<64-r;function Pt(e,t,r,n){let s=(t>>>0)+(n>>>0);return{h:e+r+(s/2**32|0)|0,l:s|0}}var Wi=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Xi=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Ji=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Qi=(e,t,r,n,s)=>t+r+n+s+(e/2**32|0)|0,to=(e,t,r,n,s)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(s>>>0),eo=(e,t,r,n,s,i)=>t+r+n+s+i+(e/2**32|0)|0;function Rr(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}var Wn=e=>e?`"${e}" `:"";function Mt(e,t=""){if(typeof e!="number")throw new TypeError(Wn(t)+"expected number, got "+typeof e);if(!Number.isSafeInteger(e)||e<0)throw new RangeError(Wn(t)+"expected integer >= 0, got "+e);return e}function Bt(e,t,r=""){if(Rr(e)&&(t===void 0||e.length===t))return e;t!==void 0&&Mt(t,"length");let n=Rr(e),s=t!==void 0?` of length ${t}`:"",i=n?`length=${e.length}`:`type=${typeof e}`,o=Wn(r)+"expected Uint8Array"+s+", got "+i;throw n?new RangeError(o):new TypeError(o)}function _r(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(Mt(e.outputLen),Mt(e.blockLen),e.outputLen<1||e.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var vu=(e,t)=>{if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError((t==="object"?"":`"${t}" `)+"expected object, got type="+typeof e)},ro=(e,t)=>{vu(e,t);let r=Object.getPrototypeOf(e);if(r!==Object.prototype&&r!==null)throw new TypeError(`"${t}" expected plain object`);if(Object.hasOwn(e,"__proto__"))throw new TypeError(`"${t}.__proto__" is not allowed`)};function De(e,t=!0){if(e.destroyed)throw new Error("hash was destroyed");if(t&&e.finished)throw new Error("digest() was already called")}function Dr(e,t){Bt(e,void 0,"output");let r=t.outputLen;if(!(e.length>=r))throw new RangeError('"output" expected length >= '+r)}function de(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Cr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Rt(e,t){return e<<32-t|e>>>t}var so=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Au=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Pr(e){if(Bt(e),so)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Au[e[r]];return t}function no(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function Or(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(so)try{return Uint8Array.fromHex(e)}catch(s){throw s instanceof SyntaxError?new RangeError(s.message):s}let t=e.length,r=t/2;if(t%2)throw new RangeError("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let s=0,i=0;s<r;s++,i+=2){let o=no(e.charCodeAt(i)),a=no(e.charCodeAt(i+1));if(o===void 0||a===void 0){let c=e[i]+e[i+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+i)}n[s]=o*16+a}return n}function Xn(...e){let t=0;for(let n=0;n<e.length;n++){let s=e[n];Bt(s),t+=s.length}let r=new Uint8Array(t);for(let n=0,s=0;n<e.length;n++){let i=e[n];r.set(i,s),s+=i.length}return r}function Bu(e,t,r="opts"){return ro(e,"defaults"),t!==void 0&&ro(t,r),Object.assign(Object.create(null),e,t)}function Jn(e,t={}){if(typeof e!="function")throw new TypeError('"hashCons" expected function, got type='+typeof e);t=Bu({},t,"info");let r=(s,i)=>e(i).update(s).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=s=>e(s),Object.assign(r,t),Object.freeze(r)}function io(e=32){Mt(e,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(e>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}var Qn=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function oo(e,t,r){return e&t^~e&r}function ao(e,t,r){return e&t^e&r^t&r}var Qe=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,s){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(t),this.view=Cr(this.buffer)}update(t){De(this),Bt(t);let{view:r,buffer:n,blockLen:s}=this,i=t.length,o=!1;for(let a=0;a<i;){let c=Math.min(s-this.pos,i-a);if(c===s){let u=Cr(t);for(;s<=i-a;a+=s)this.process(u,a);o=!0;continue}n.set(a===0&&c===i?t:t.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===s&&(this.process(r,0),this.pos=0,o=!0)}return this.length+=t.length,o&&this.roundClean(),this}digestInto(t){De(this),Dr(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:s,isLE:i}=this,{pos:o}=this;r[o++]=128,r.fill(0,o),this.padOffset>s-o&&(this.process(n,0),r.fill(0)),Gi(n,s-8,this.length*8,i),this.process(n,0),this.roundClean();let a=t===r?n:Cr(t),c=this.outputLen,u=c/4,f=this.get();if(c%4||u>f.length)throw new Error("invalid outputLen");for(let h=0;h<u;h++)a.setUint32(4*h,f[h],i)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneIntoMeta(t){let{buffer:r,length:n,finished:s,destroyed:i,pos:o}=this;return t.destroyed=i,t.finished=s,t.length=n,t.pos=o,o&&t.buffer.set(r),t}clone(){return this._cloneInto()}},co=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var uo=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Iu=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]),Yt=new Uint32Array(64),ts=class extends Qe{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(t,r){super(64,t,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:t,B:r,C:n,D:s,E:i,F:o,G:a,H:c}=this;return[t,r,n,s,i,o,a,c]}set(t,r,n,s,i,o,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=s|0,this.E=i|0,this.F=o|0,this.G=a|0,this.H=c|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,r){for(let h=0;h<16;h++,r+=4)Yt[h]=t.getUint32(r,!1);for(let h=16;h<64;h++){let l=Yt[h-15],d=Yt[h-2],y=Rt(l,7)^Rt(l,18)^l>>>3,g=Rt(d,17)^Rt(d,19)^d>>>10;Yt[h]=g+Yt[h-7]+y+Yt[h-16]|0}let{A:n,B:s,C:i,D:o,E:a,F:c,G:u,H:f}=this;for(let h=0;h<64;h++){let l=Rt(a,6)^Rt(a,11)^Rt(a,25),d=f+l+oo(a,c,u)+Iu[h]+Yt[h]|0,g=(Rt(n,2)^Rt(n,13)^Rt(n,22))+ao(n,s,i)|0;f=u,u=c,c=a,a=o+d|0,o=i,i=s,s=n,n=d+g|0}n=n+this.A|0,s=s+this.B|0,i=i+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,s,i,o,a,c,u,f)}roundClean(){de(Yt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),de(this.buffer)}},es=class extends ts{constructor(){super(32,co)}};var fo=Yi(["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))),Tu=fo[0],Lu=fo[1],Gt=new Uint32Array(80),Wt=new Uint32Array(80),rs=class extends Qe{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(t,r){super(128,t,16,!1),this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:s,Ch:i,Cl:o,Dh:a,Dl:c,Eh:u,El:f,Fh:h,Fl:l,Gh:d,Gl:y,Hh:g,Hl:E}=this;return[t,r,n,s,i,o,a,c,u,f,h,l,d,y,g,E]}set(t,r,n,s,i,o,a,c,u,f,h,l,d,y,g,E){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=s|0,this.Ch=i|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=h|0,this.Fl=l|0,this.Gh=d|0,this.Gl=y|0,this.Hh=g|0,this.Hl=E|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,r){for(let m=0;m<16;m++,r+=4)Gt[m]=t.getUint32(r),Wt[m]=t.getUint32(r+=4);for(let m=16;m<80;m++){let S=Gt[m-15]|0,B=Wt[m-15]|0,P=le(S,B,1)^le(S,B,8)^Yn(S,B,7),K=he(S,B,1)^he(S,B,8)^Gn(S,B,7),k=Gt[m-2]|0,_=Wt[m-2]|0,C=le(k,_,19)^Xe(k,_,61)^Yn(k,_,6),q=he(k,_,19)^Je(k,_,61)^Gn(k,_,6),U=Ji(K,q,Wt[m-7],Wt[m-16]),G=Qi(U,P,C,Gt[m-7],Gt[m-16]);Gt[m]=G|0,Wt[m]=U|0}let{Ah:n,Al:s,Bh:i,Bl:o,Ch:a,Cl:c,Dh:u,Dl:f,Eh:h,El:l,Fh:d,Fl:y,Gh:g,Gl:E,Hh:w,Hl:v}=this;for(let m=0;m<80;m++){let S=le(h,l,14)^le(h,l,18)^Xe(h,l,41),B=he(h,l,14)^he(h,l,18)^Je(h,l,41),P=h&d^~h&g,K=l&y^~l&E,k=to(v,B,K,Lu[m],Wt[m]),_=eo(k,w,S,P,Tu[m],Gt[m]),C=k|0,q=le(n,s,28)^Xe(n,s,34)^Xe(n,s,39),U=he(n,s,28)^Je(n,s,34)^Je(n,s,39),G=n&i^n&a^i&a,T=s&o^s&c^o&c;w=g|0,v=E|0,g=d|0,E=y|0,d=h|0,y=l|0,{h,l}=Pt(u|0,f|0,_|0,C|0),u=a|0,f=c|0,a=i|0,c=o|0,i=n|0,o=s|0;let F=Wi(C,U,T);n=Xi(F,_,q,G),s=F|0}({h:n,l:s}=Pt(this.Ah|0,this.Al|0,n|0,s|0)),{h:i,l:o}=Pt(this.Bh|0,this.Bl|0,i|0,o|0),{h:a,l:c}=Pt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Pt(this.Dh|0,this.Dl|0,u|0,f|0),{h,l}=Pt(this.Eh|0,this.El|0,h|0,l|0),{h:d,l:y}=Pt(this.Fh|0,this.Fl|0,d|0,y|0),{h:g,l:E}=Pt(this.Gh|0,this.Gl|0,g|0,E|0),{h:w,l:v}=Pt(this.Hh|0,this.Hl|0,w|0,v|0),this.set(n,s,i,o,a,c,u,f,h,l,d,y,g,E,w,v)}roundClean(){de(Gt,Wt)}destroy(){this.destroyed=!0,de(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},ns=class extends rs{constructor(){super(64,uo)}};var Ce=Jn(()=>new es,Qn(1));var ss=Jn(()=>new ns,Qn(3));function Nr(e,t,r=()=>{}){if(!Array.isArray(e))throw new TypeError(`"${t}" expected array, got type=${typeof e}`);for(let n=0;n<e.length;n++)r(e[n],`${t}[${n}]`);return e}var $=(e,t,r)=>Bt(e,t,r),is=Mt;function ho(e,t=""){if(typeof e!="string"){let r=t&&`"${t}" `;throw new TypeError(r+"expected string, got type="+typeof e)}return e}function Xt(e,t="object"){if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError(t==="object"?"expected valid options object":`"${t}" expected object, got type=${typeof e}`);return e}function pe(e,t){if(typeof e!="function")throw new TypeError(`"${t}" is invalid: expected function, got ${typeof e}`);return e}var tr=Pr,It=(...e)=>Xn(...e),Pe=e=>Or(e),Qt=Rr,me=e=>io(e),kr=BigInt(0),lo=BigInt(1),Ru=e=>e?`"${e}" `:"";function wt(e,t=""){if(typeof e!="boolean")throw new TypeError(Ru(t)+"expected boolean, got type="+typeof e);return e}function Kr(e){if(typeof e=="bigint"){if(!Jt(e))throw new RangeError("positive bigint expected, got "+e)}else is(e);return e}function Ut(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(r+"expected number, got type="+typeof e)}if(!Number.isSafeInteger(e)){let r=t&&`"${t}" `;throw new RangeError(r+"expected safe integer, got "+e)}}function er(e){let t=Kr(e).toString(16);return t.length&1?"0"+t:t}function po(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?kr:BigInt("0x"+e)}function Ot(e){return po(Pr(e))}function be(e){return po(Pr(rr(Bt(e)).reverse()))}function Fr(e,t){if(Mt(t),t===0)throw new Error("zero output length is invalid");e=Kr(e);let r=t*2,n=e.toString(16);if(n.length>r)throw new RangeError("number is too large");return Or(n.padStart(r,"0"))}function os(e,t){return Fr(e,t).reverse()}function rr(e){return Uint8Array.from($(e))}function Jt(e){return typeof e=="bigint"&&kr<=e}function as(e,t,r){return Jt(e)&&Jt(t)&&Jt(r)&&t<=e&&e<r}function Oe(e,t,r,n){if(!as(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function ke(e){if(e<kr)throw new Error("expected non-negative bigint, got "+e);return e===kr?0:e.toString(2).length}var nr=e=>(Ut(e,"n"),(lo<<BigInt(e))-lo);function mo(e,t,r){if(Mt(e,"hashLen"),Mt(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=E=>new Uint8Array(E),s=Uint8Array.of(),i=Uint8Array.of(0),o=Uint8Array.of(1),a=1e3,c=n(e),u=n(e),f=0,h=()=>{c.fill(1),u.fill(0),f=0},l=(...E)=>r(u,It(c,...E)),d=(E=s)=>{u=l(i,E),c=l(),E.length!==0&&(u=l(o,E),c=l())},y=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let E=0,w=[];for(;E<t;){c=l();let v=c.slice();w.push(v),E+=c.length}return It(...w)};return(E,w)=>{h(),d(E);let v;for(;(v=w(y()))===void 0;)d();return h(),v}}function xt(e,t={},r={},n="object"){Xt(e,n),Xt(t,"fields"),Xt(r,"optFields");function s(o,a,c){let u=n==="object"?`param "${String(o)}"`:`"${n}.${String(o)}"`,f=e[o];if(!Object.hasOwn(e,o)&&(c?f!==void 0:a!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&f===void 0)return;let h=typeof f;if(h!==a||f===null)throw new TypeError(`${u} is invalid: expected ${a}, got ${h}`)}let i=(o,a)=>Object.entries(o).forEach(([c,u])=>s(c,u,a));i(t,!1),i(r,!0)}var ut=BigInt(0),V=BigInt(1),te=BigInt(2),go=BigInt(3),cs=BigInt(4),wo=BigInt(5),_u=BigInt(7),xo=BigInt(8),Du=BigInt(9),Cu=BigInt(15),Eo=BigInt(16),Pu=BigInt("0x10000000000000000");function nt(e,t){if(t<=ut)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=ut?r:t+r}function So(e,t,r){if(r<=V)throw new Error("pow: expected modulus > 1, got "+r);if(typeof t!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof t);if(t<ut)throw new Error("invalid exponent, negatives unsupported");if(t===ut)return V;if(t===V)return e;let n=e%r;if(n<ut&&(n+=r),t<Pu){let a=V;for(;t>ut;)t&V&&(a=a*n%r),n=n*n%r,t>>=V;return a}let s=[];for(;t>ut;)s.push(Number(t&Cu)),t>>=cs;let i=new Array(16);i[0]=V,i[1]=n;for(let a=2;a<16;a++)i[a]=i[a-1]*n%r;let o=i[s[s.length-1]];for(let a=s.length-2;a>=0;a--){o=o*o%r,o=o*o%r,o=o*o%r,o=o*o%r;let c=s[a];c!==0&&(o=o*i[c]%r)}return o}function Q(e,t,r){if(r<=V)throw new Error("pow2: expected modulus > 1, got "+r);if(t<ut)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >ut;)n*=n,n%=r;return n}function bo(e,t){if(e===ut)throw new Error("invert: expected non-zero number");if(t<=V)throw new Error("invert: expected modulus > 1, got "+t);let r=nt(e,t),n=t,s=ut,i=V;for(;r!==ut;){let a=n/r,c=n-r*a,u=s-i*a;n=r,r=c,s=i,i=u}if(n!==V)throw new Error("invert: does not exist");return nt(s,t)}function vo(e,t){if(t<=V)throw new Error("invertCt: expected prime modulus > 1, got "+t);let r=nt(e,t);if(r===ut)throw new Error("invertCt: expected non-zero number");let n=So(r,t-te,t);if(nt(r*n,t)!==V)throw new Error("invertCt: does not exist");return n}function us(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function fs(e,t){if((e&V)===ut)throw new Error(t+": expected odd modulus, got "+e)}function Ao(e,t){let r=e,n=(r.ORDER+V)/cs,s=r.pow(t,n);return us(r,s,t),s}function Ou(e,t){let r=e,n=(r.ORDER-wo)/xo,s=r.mul(t,te),i=r.pow(s,n),o=r.mul(t,i),a=r.mul(r.mul(o,te),i),c=r.mul(o,r.sub(a,r.ONE));return us(r,c,t),c}function ku(e){let t=Ke(e),r=Bo(e),n=r(t,t.neg(t.ONE)),s=r(t,n),i=r(t,t.neg(n)),o=(e+_u)/Eo;return((a,c)=>{let u=a,f=u.pow(c,o),h=u.mul(f,n),l=u.mul(f,s),d=u.mul(f,i),y=u.eql(u.sqr(h),c),g=u.eql(u.sqr(l),c);f=u.cmov(f,h,y),h=u.cmov(d,l,g);let E=u.eql(u.sqr(h),c),w=u.cmov(f,h,E);return us(u,w,c),w})}function Bo(e){if(e<go)throw new Error("sqrt is not defined for small field");fs(e,"tonelliShanks");let t=e-V,r=0;for(;t%te===ut;)t/=te,r++;let n=te,s=Ke(e);for(;sr(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Ao;let i=s.pow(n,t),o=(t+V)/te;return function(c,u){let f=c;if(f.is0(u))return u;if(sr(f,u)!==1)throw new Error("Cannot find square root");let h=r,l=f.mul(f.ONE,i),d=f.pow(u,t),y=f.pow(u,o);for(;!f.eql(d,f.ONE);){if(f.is0(d))throw new Error("Cannot find square root: probably non-prime P");let g=1,E=f.sqr(d);for(;!f.eql(E,f.ONE);)if(g++,E=f.sqr(E),g===h)throw new Error("Cannot find square root");let w=V<<BigInt(h-g-1),v=f.pow(l,w);h=g,l=f.sqr(v),d=f.mul(d,l),y=f.mul(y,v)}return y}}function Nu(e){return fs(e,"Fp.sqrt"),e%cs===go?Ao:e%xo===wo?Ou:e%Eo===Du?ku(e):Bo(e)}var Io=(e,t)=>(nt(e,t)&V)===V,Ku=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ne(e){if(Xt(e,"field"),typeof e.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof e.ORDER);Ut(e.BYTES,"BYTES"),Ut(e.BITS,"BITS");for(let t of Ku)pe(e[t],"field."+t);if(e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=V)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function Ur(e,t,r=!1){Ne(e),Nr(t,"nums"),wt(r,"passZero");let n=e,s=new Array(t.length).fill(r?n.ZERO:void 0),i=t.reduce((a,c,u)=>n.is0(c)?a:(s[u]=a,n.mul(a,c)),n.ONE),o=n.inv(i);return t.reduceRight((a,c,u)=>n.is0(c)?a:(s[u]=n.mul(a,s[u]),n.mul(a,c)),o),s}function sr(e,t){Ne(e);let r=e;fs(r.ORDER,"FpLegendre");let n=(r.ORDER-V)/te,s=r.pow(t,n),i=r.eql(s,r.ONE),o=r.eql(s,r.ZERO),a=r.eql(s,r.neg(r.ONE));if(!i&&!o&&!a)throw new Error("invalid Legendre symbol result");return i?1:o?0:-1}function Fu(e,t){if(t!==void 0&&is(t),e<=ut)throw new Error("invalid n length: expected positive n, got "+e);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let r=ke(e);if(t!==void 0&&t<r)throw new Error(`invalid n length: expected nBitLength (${t}) >= bitLen(n) (${r})`);let n=t!==void 0?t:r,s=Math.ceil(n/8);return{nBitLength:n,nByteLength:s}}var yo=new WeakMap,Mr=class{ORDER;BITS;BYTES;isLE;ZERO=ut;ONE=V;_lengths;_mod;constructor(t,r={}){if(t<=V)throw new Error("invalid field: expected ORDER > 1, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:s,nByteLength:i}=Fu(t,n);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=s,this.BYTES=i,Object.freeze(this)}create(t){return nt(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return ut<=t&&t<this.ORDER}is0(t){return t===ut}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&V)===V}neg(t){return nt(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return nt(t*t,this.ORDER)}add(t,r){return nt(t+r,this.ORDER)}sub(t,r){return nt(t-r,this.ORDER)}mul(t,r){return nt(t*r,this.ORDER)}pow(t,r){return So(t,r,this.ORDER)}div(t,r){return nt(t*bo(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 bo(t,this.ORDER)}sqrt(t){let r=yo.get(this);return r||yo.set(this,r=Nu(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?os(t,this.BYTES):Fr(t,this.BYTES)}fromBytes(t,r=!1){$(t);let{_lengths:n,BYTES:s,isLE:i,ORDER:o,_mod:a}=this;if(n){if(t.length<1||!n.includes(t.length)||t.length>s)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let u=new Uint8Array(s);u.set(t,i?0:u.length-t.length),t=u}if(t.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+t.length);let c=i?be(t):Ot(t);if(a&&(c=nt(c,o)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return Ur(this,t,!0)}cmov(t,r,n){return wt(n,"condition"),n?r:t}};function Ke(e,t={}){return Object.freeze(Mr.prototype),new Mr(e,t)}function To(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=V)throw new Error("field order must be greater than 1");let t=ke(e-V);return Math.ceil(t/8)}function qr(e){let t=To(e);return t+Math.ceil(t/2)}function zr(e,t,r=!1){$(e);let n=e.length,s=To(t),i=Math.max(qr(t),16);if(n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let o=r?be(e):Ot(e),a=nt(o,t-V)+V;return r?os(a,s):Fr(a,s)}var ds=BigInt(0),ir=BigInt(1),Mu=BigInt(4),ls=16,Lo=128,Uu=5,Ro=2**31;function ee(e){let t=e;if(typeof t!="function")throw new TypeError('"Point" expected constructor, got type='+typeof e);pe(t.fromAffine,"Point.fromAffine"),pe(t.fromBytes,"Point.fromBytes"),pe(t.fromHex,"Point.fromHex"),Xt(t.BASE,"Point.BASE"),Xt(t.ZERO,"Point.ZERO"),Ne(t.Fp),Ne(t.Fn)}function Hr(e,t){ee(e),Do(t,e);let r=Ur(e.Fp,t.map(n=>n.Z));return t.map((n,s)=>e.fromAffine(n.toAffine(r[s])))}function qu(e,t,r=1){if(!Number.isSafeInteger(e)||e<r||e>t)throw new Error("invalid window size, expected ["+r+".."+t+"], got W="+e)}function zu(e,t){let r=e*(4*t+128);if(r>Ro)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+Ro/2**20+" MiB")}function ps(e,t){if(e!==void 0){pe(e,"randomBytes");try{let r=e(t);if(!Qt(r)||r.length!==t)return}catch{return}return e}}function Do(e,t){Nr(e,"points"),e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Hu(e,t,r){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((n,s)=>{if(!(r===void 0?t.isValid(n):Jt(n)&&n<r))throw new Error("invalid scalar at index "+s)})}var Co=new WeakMap;function hs(e){return Co.get(e)||1}function $u(e,t){let r=e.double(),n=[e];for(let s=1;s<t;s++)n.push(n[s-1].add(r));return n}function Vu(e,t){let r=2**t,n=r/2,s=BigInt(r-1),i=[];for(;e>ds;){let o=0;e&ir&&(o=Number(e&s),o>=n&&(o-=r),e-=BigInt(o)),i.push(o),e>>=ir}return i}function ju(e,t,r){let n=2**t,s=n/2,i=BigInt(n-1),o=BigInt(t),a=[];for(let c=0;c<r;c++){let u=Number(e&i);e>>=o,u>s&&(u-=n,e+=ir),a.push(u)}if(e!==ds)throw new Error("invalid wnaf");return a}function Zu(e,t,r){let n=0;for(let i of r)n=Math.max(n,i.length);let s=e;for(let i=n-1;i>=0;i--){i!==n-1&&(s=s.double());for(let o=0;o<r.length;o++){let a=r[o][i];if(a){let c=t[o][Math.abs(a)-1>>1];s=s.add(a<0?c.negate():c)}}}return s}var Fe=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(t,r){ee(t),this.randomBytes=ps(r,ls),this.Point=t,this.BASE=t.BASE,this.ZERO=t.ZERO,this.bits=t.Fn.BITS}buildWnafTable(t,r,n){let s=Math.ceil(n/r)+1,i=2**(r-1),o=[],a=t;for(let c=0;c<s;c++){let u=a;for(let f=0;f<i;f++)o.push(u),u=u.add(a);a=o[o.length-1].double()}return{W:r,bits:n,windows:s,comp:o}}wnafCachedCT(t,r){let{W:n,windows:s,comp:i}=t,o=2**(n-1),a=ju(r,n,s),c=this.ZERO,u=this.BASE;for(let f=0;f<s;f++){let h=a[f],l=f*o,d=Math.abs(h)-1,y=i[l];for(let E=1;E<o;E++)y=E===d?i[l+E]:y;let g=y.negate();h===0?u=u.add(i[l]):c=c.add(h<0?g:y)}return{p:c,f:u}}getWnafPrecomputes(t,r,n,s){let i=this.wnafPrecomputes.get(r),o=i?.find(a=>a.W===t&&a.bits===n);return o||(o=this.buildWnafTable(r,t,n),typeof s=="function"&&(o={...o,comp:s(o.comp)}),i||(i=[],this.wnafPrecomputes.set(r,i)),i.push(o)),o}assertPoint(t){if(!(t instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof t)}validateMulInput(t,r){if(this.assertPoint(t),!as(r,ir,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(t,r,n,s){let i=hs(t);return i===1?this.fixedWindowCT(t,r,n):this.wnafCachedCT(this.getWnafPrecomputes(i,t,n,s),r)}mulCT(t,r,n){return this.validateMulInput(t,r),this.runCT(t,r,this.bits,n)}mulCTBlinded(t,r,n){if(this.validateMulInput(t,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let s=this.Point.Fn.BITS+Lo,i=this.randomBytes(ls);if(!Qt(i)||i.length!==ls)throw new Error("randomBytes returned invalid byte array");i[0]=i[0]&63|128;let o=r+Ot(i)*this.Point.Fn.ORDER;return this.runCT(t,o,s,n)}fixedWindowCT(t,r,n){let s=Uu,i=1<<s,o=nr(s),a=new Array(i);a[0]=this.ZERO;for(let f=1;f<i;f++)a[f]=a[f-1].add(t);let c=Math.ceil(n/s),u=this.ZERO;for(let f=c-1;f>=0;f--){if(f!==c-1)for(let d=0;d<s;d++)u=u.double();let h=Number(r>>BigInt(f*s)&o),l=a[0];for(let d=1;d<i;d++)l=d===h?a[d]:l;u=u.add(l)}return{p:u,f:u}}shouldBlind(t,r){return this.randomBytes===void 0?!1:r===ir?!0:t!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(t,r,n,s){return this.shouldBlind(t,n)?this.mulCTBlinded(t,r,s):this.mulCT(t,r,s)}mulUnsafe(t,r,n){if(this.assertPoint(t),!Jt(r))throw new Error("invalid scalar");let s=hs(t);if(s===1||r>=this.Point.Fn.ORDER)return $r(this.Point,[t],[r],!0);let i=this.getWnafPrecomputes(s,t,this.bits,n);return this.wnafCachedCT(i,r).p}setWindowSize(t,r){this.assertPoint(t),qu(r,this.bits);let n=Math.ceil((this.bits+Lo)/r)+1;zu(n*2**(r-1),this.Point.Fp.BYTES),Co.set(t,r),this.wnafPrecomputes.delete(t)}hasWindowSize(t){return hs(t)!==1}};function $r(e,t,r,n=!1){if(ee(e),Do(t,e),wt(n,"allowOversized"),Hu(r,e.Fn,n?e.Fn.ORDER**Mu:void 0),t.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let s=t.map(o=>$u(o,4)),i=r.map(o=>Vu(o,4));return Zu(e.ZERO,s,i)}function _o(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Ne(t),t}else return Ke(e,{isLE:r})}function Vr(e,t,r={},n){if(e!=="weierstrass"&&e!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);xt(r);for(let c of["p","n","h"]){let u=t[c];if(!(Jt(u)&&u!==ds))throw new Error(`CURVE.${c} must be positive bigint`)}let s=_o(t.p,r.Fp,n),i=_o(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of a)if(!s.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:s,Fn:i}}function jr(e,t){return function(n){let s=e(n);return{secretKey:s,publicKey:t(s)}}}var Zr=BigInt(0),Yr=BigInt(1),Gr=BigInt(2),Yu=BigInt(4),Po=BigInt(8);function Gu(e,t,r,n){let s=e.sqr(r),i=e.sqr(n),o=e.add(e.mul(t.a,s),i),a=e.add(e.ONE,e.mul(t.d,e.mul(s,i)));return e.eql(o,a)}function Oo(e,t={}){xt(t,{},{},"extraOpts");let r=t,n=Vr("edwards",e,r,r.FpFnLE),{Fp:s,Fn:i}=n,o=n.CURVE,{h:a}=o;if(sr(s,o.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(sr(s,o.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");xt(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?me:r.randomBytes,u=Gr<<BigInt(s.BYTES*8)-Yr;function f(v){if(!s.isOdd)throw new Error("Field does not have .isOdd()");return s.isOdd(v)}let h=r.uvRatio===void 0?(v,m)=>{try{return{isValid:!0,value:s.sqrt(s.div(v,m))}}catch{return{isValid:!1,value:Zr}}}:r.uvRatio;if(!Gu(s,o,o.Gx,o.Gy))throw new Error("bad curve params: generator point");let l=s.eql(o.a,s.neg(s.ONE))?v=>s.neg(v):s.eql(o.a,s.ONE)?v=>v:v=>s.mul(o.a,v);function d(v,m,S=!1){let B=S?Yr:Zr;return Oe("coordinate "+v,m,B,u),m}function y(v){if(!(v instanceof g))throw new Error("EdwardsPoint expected")}class g{static BASE=new g(o.Gx,o.Gy,s.ONE,s.mul(o.Gx,o.Gy));static ZERO=new g(s.ZERO,s.ONE,s.ONE,s.ZERO);static Fp=s;static Fn=i;X;Y;Z;T;constructor(m,S,B,P){this.X=d("x",m),this.Y=d("y",S),this.Z=d("z",B,!0),this.T=d("t",P),Object.freeze(this)}static CURVE(){return o}static fromAffine(m){if(m instanceof g)throw new Error("extended point not allowed");let{x:S,y:B}=m||{};return d("x",S),d("y",B),new g(S,B,s.ONE,s.mul(S,B))}static fromBytes(m,S=!1){let B=s.BYTES,{a:P,d:K}=o;m=rr($(m,B,"point")),wt(S,"zip215");let k=rr(m),_=m[B-1];k[B-1]=_&-129;let C=be(k),q=S?u:s.ORDER;Oe("point.y",C,Zr,q);let U=s.sqr(C),G=s.sub(U,s.ONE),T=s.sub(s.mulN(K,U),P),{isValid:F,value:M}=h(G,T);if(!F)throw new Error("bad point: invalid y coordinate");let D=f(M),W=(_&128)!==0;if(!S&&s.is0(M)&&W)throw new Error("bad point: x=0 and x_0=1");return W!==D&&(M=s.neg(M)),g.fromAffine({x:M,y:C})}static fromHex(m,S=!1){return g.fromBytes(Pe(m),S)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=6,S=!0){return w.setWindowSize(this,m),S||this.multiply(Gr),this}assertValidity(){let m=this,{a:S,d:B}=o;if(m.is0())throw new Error("bad point: ZERO");let{X:P,Y:K,Z:k,T:_}=m,C=s.sqr(P),q=s.sqr(K),U=s.sqr(k),G=s.sqr(U),T=s.mul(C,S),F=s.mul(s.add(T,q),U),M=s.add(G,s.mul(B,s.mul(C,q)));if(!s.eql(F,M))throw new Error("bad point: equation left != right (1)");let D=s.mul(P,K),W=s.mul(k,_);if(!s.eql(D,W))throw new Error("bad point: equation left != right (2)")}equals(m){y(m);let{X:S,Y:B,Z:P}=this,{X:K,Y:k,Z:_}=m,C=s.mul(S,_),q=s.mul(K,P),U=s.mul(B,_),G=s.mul(k,P);return s.eql(C,q)&&s.eql(U,G)}is0(){return this.equals(g.ZERO)}negate(){return new g(s.neg(this.X),this.Y,this.Z,s.neg(this.T))}double(){let{X:m,Y:S,Z:B}=this,P=s.sqr(m),K=s.sqr(S),k=s.mul(s.sqr(B),Gr),_=l(P),C=s.addN(m,S),q=s.sub(s.subN(s.sqr(C),P),K),U=s.addN(_,K),G=s.subN(U,k),T=s.subN(_,K),F=s.mul(q,G),M=s.mul(U,T),D=s.mul(q,T),W=s.mul(G,U);return new g(F,M,W,D)}add(m){y(m);let{d:S}=o,{X:B,Y:P,Z:K,T:k}=this,{X:_,Y:C,Z:q,T:U}=m,G=s.mul(B,_),T=s.mul(P,C),F=s.mul(s.mulN(k,S),U),M=s.mul(K,q),D=s.sub(s.subN(s.mulN(s.addN(B,P),s.addN(_,C)),G),T),W=s.subN(M,F),tt=s.addN(M,F),A=s.sub(T,l(G)),p=s.mul(D,W),b=s.mul(tt,A),x=s.mul(D,A),I=s.mul(W,tt);return new g(p,b,I,x)}subtract(m){return y(m),this.add(m.negate())}multiply(m){if(!i.isValidNot0(m))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:S,f:B}=w.mulSecret(this,m,a,E);return E([S,B])[0]}multiplyUnsafe(m){if(!i.isValid(m))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return m===Zr?g.ZERO:this.is0()||m===Yr?this:w.mulUnsafe(this,m,E)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return w.mulUnsafe(this,o.n).is0()}toAffine(m){let S=this,B=m;if(B!=null&&typeof B!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof B);let{X:P,Y:K,Z:k}=S,_=S.is0();B==null&&(B=_?s.create(Po):s.inv(k));let C=s.mul(P,B),q=s.mul(K,B),U=s.mul(k,B);if(_)return{x:s.ZERO,y:s.ONE};if(!s.eql(U,s.ONE))throw new Error("invZ was invalid");return{x:C,y:q}}clearCofactor(){return a===Yr?this:a===Gr?this.double():a===Yu?this.double().double():a===Po?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:m,y:S}=this.toAffine(),B=s.toBytes(S);return B[B.length-1]|=f(m)?128:0,B}toHex(){return tr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let E=v=>Hr(g,v),w=new Fe(g,c);return w.bits>=6&&g.BASE.precompute(6),Object.freeze(g.prototype),Object.freeze(g),g}function ko(e,t,r={}){if(ee(e),typeof t!="function")throw new Error('"hash" function param is required');let n=t,s=r;xt(s,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:i}=s,{BASE:o,Fp:a,Fn:c}=e,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(Ut(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let h=s.randomBytes===void 0?me:s.randomBytes,l=s.toMontgomery,d=s.toMontgomerySecret,y=s.adjustScalarBytes===void 0?T=>T:s.adjustScalarBytes,g=s.domain===void 0?(T,F,M)=>{if(wt(M,"phflag"),F.length||M)throw new Error("Contexts/pre-hash are not supported");return T}:s.domain;function E(T){return c.create(be(T))}function w(T){let F=_.secretKey;$(T,_.secretKey,"secretKey");let M=$(n(T),2*F,"hashedSecretKey"),D=y(M.slice(0,F)),W=M.slice(F,2*F),tt=E(D);return{head:D,prefix:W,scalar:tt}}function v(T){let{head:F,prefix:M,scalar:D}=w(T),W=o.multiply(D),tt=W.toBytes();return{head:F,prefix:M,scalar:D,point:W,pointBytes:tt}}function m(T){return v(T).pointBytes}function S(T=Uint8Array.of(),...F){let M=It(...F);return E(n(g(M,$(T,void 0,"context"),!!i)))}function B(T,F,M={}){xt(M,{},{},"options"),T=rr($(T,void 0,"message")),i&&(T=i(T));let{prefix:D,scalar:W,pointBytes:tt}=v(F),A=S(M.context,D,T),p=o.multiply(A).toBytes(),b=S(M.context,p,tt,T),x=c.create(A+b*W);if(!c.isValid(x))throw new Error("sign failed: invalid s");let I=It(p,c.toBytes(x));return $(I,_.signature,"result")}let P={zip215:s.zip215};function K(T,F,M,D=P){xt(D);let{context:W}=D,tt=D.zip215===void 0?!!P.zip215:D.zip215,A=_.signature;T=$(T,A,"signature"),F=$(F,void 0,"message"),M=$(M,_.publicKey,"publicKey"),tt!==void 0&&wt(tt,"zip215"),i&&(F=i(F));let p=A/2,b=T.subarray(0,p),x=be(T.subarray(p,A)),I,L,R;try{I=e.fromBytes(M,tt),L=e.fromBytes(b,tt),R=o.multiplyUnsafe(x)}catch{return!1}if(!tt&&I.isSmallOrder())return!1;let O=S(W,b,M,F);return L.add(I.multiplyUnsafe(O)).subtract(R).clearCofactor().is0()}let k=a.BYTES,_={secretKey:k,publicKey:k,signature:2*k,seed:k};function C(T){return T=T===void 0?h(_.seed):T,$(T,_.seed,"seed")}function q(T){return Qt(T)&&T.length===_.secretKey}function U(T,F){try{return!!e.fromBytes(T,F===void 0?P.zip215:F)}catch{return!1}}let G={getExtendedPublicKey:v,randomSecretKey:C,isValidSecretKey:q,isValidPublicKey:U,toMontgomery(T){if(l===void 0)throw new Error("Montgomery conversion is not supported for this curve");return l(e.fromBytes(T))},toMontgomerySecret(T){if(d===void 0)throw new Error("Montgomery conversion is not supported for this curve");return d(T)}};return Object.freeze(_),Object.freeze(G),Object.freeze({keygen:jr(C,m),getPublicKey:m,sign:B,verify:K,utils:G,Point:e,lengths:_})}var ms=BigInt(1),No=BigInt(2);var Wu=BigInt(5),Xu=BigInt(8),bs=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Ju={p:bs,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Xu,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Qu(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),s=BigInt(80),i=bs,a=e*e%i*e%i,c=Q(a,No,i)*a%i,u=Q(c,ms,i)*e%i,f=Q(u,Wu,i)*u%i,h=Q(f,t,i)*f%i,l=Q(h,r,i)*h%i,d=Q(l,n,i)*l%i,y=Q(d,s,i)*d%i,g=Q(y,s,i)*d%i,E=Q(g,t,i)*f%i;return{pow_p_5_8:Q(E,No,i)*e%i,b2:a}}function Mo(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Ko=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function tf(e,t){let r=bs,n=nt(t*t*t,r),s=nt(n*n*t,r),i=Qu(e*s).pow_p_5_8,o=nt(e*n*i,r),a=nt(t*o*o,r),c=o,u=nt(o*Ko,r),f=a===e,h=a===nt(-e,r),l=a===nt(-e*Ko,r);return f&&(o=c),(h||l)&&(o=u),Io(o,r)&&(o=nt(-o,r)),{isValid:f||h,value:o}}var ys=Oo(Ju,{uvRatio:tf}),Fo=ys.Fp;function ef(e){let{y:t}=e;return Fo.toBytes(Fo.div(ms+t,ms-t))}function rf(e){let t=ys.Fp.BYTES;return Bt(e,t),Mo(ss(e.subarray(0,t))).subarray(0,t)}function nf(e){return ko(ys,ss,Object.assign({adjustScalarBytes:Mo,toMontgomery:ef,toMontgomerySecret:rf,zip215:!0},e))}var Uo=nf({});var or=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Wr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Tt={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Wr("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 Xr=32;var gs,sf=(async()=>{try{return await Tt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function of(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Tt.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Tt.get().subtle.verify({name:"Ed25519"},n,At(t),At(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function af(e,t,r){return Uo.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function qo(e,t,r){return gs==null&&(gs=await sf),gs?of(e,t,r):af(e,t,r)}function Jr(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Qr=class{type="Ed25519";raw;constructor(t){this.raw=ws(t,Xr)}toMultihash(){return Lt.digest(Ft(this))}toCID(){return dt.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ht(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let s=qo(this.raw,r,t);return Jr(s)?s.then(i=>(n?.signal?.throwIfAborted(),i)):s}};function xs(e){return e=ws(e,Xr),new Qr(e)}function ws(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new et(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var uf=Math.pow(2,7),ff=Math.pow(2,14),lf=Math.pow(2,21),Es=Math.pow(2,28),Ss=Math.pow(2,35),vs=Math.pow(2,42),As=Math.pow(2,49),j=128,pt=127;function qt(e){if(e<uf)return 1;if(e<ff)return 2;if(e<lf)return 3;if(e<Es)return 4;if(e<Ss)return 5;if(e<vs)return 6;if(e<As)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Bs(e,t,r=0){switch(qt(e)){case 8:t[r++]=e&255|j,e/=128;case 7:t[r++]=e&255|j,e/=128;case 6:t[r++]=e&255|j,e/=128;case 5:t[r++]=e&255|j,e/=128;case 4:t[r++]=e&255|j,e>>>=7;case 3:t[r++]=e&255|j,e>>>=7;case 2:t[r++]=e&255|j,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function hf(e,t,r=0){switch(qt(e)){case 8:t.set(r++,e&255|j),e/=128;case 7:t.set(r++,e&255|j),e/=128;case 6:t.set(r++,e&255|j),e/=128;case 5:t.set(r++,e&255|j),e/=128;case 4:t.set(r++,e&255|j),e>>>=7;case 3:t.set(r++,e&255|j),e>>>=7;case 2:t.set(r++,e&255|j),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function Is(e,t){let r=e[t],n=0;if(n+=r&pt,r<j||(r=e[t+1],n+=(r&pt)<<7,r<j)||(r=e[t+2],n+=(r&pt)<<14,r<j)||(r=e[t+3],n+=(r&pt)<<21,r<j)||(r=e[t+4],n+=(r&pt)*Es,r<j)||(r=e[t+5],n+=(r&pt)*Ss,r<j)||(r=e[t+6],n+=(r&pt)*vs,r<j)||(r=e[t+7],n+=(r&pt)*As,r<j))return n;throw new RangeError("Could not decode varint")}function df(e,t){let r=e.get(t),n=0;if(n+=r&pt,r<j||(r=e.get(t+1),n+=(r&pt)<<7,r<j)||(r=e.get(t+2),n+=(r&pt)<<14,r<j)||(r=e.get(t+3),n+=(r&pt)<<21,r<j)||(r=e.get(t+4),n+=(r&pt)*Es,r<j)||(r=e.get(t+5),n+=(r&pt)*Ss,r<j)||(r=e.get(t+6),n+=(r&pt)*vs,r<j)||(r=e.get(t+7),n+=(r&pt)*As,r<j))return n;throw new RangeError("Could not decode varint")}function Ho(e,t,r=0){return t==null&&(t=yt(qt(e))),t instanceof Uint8Array?Bs(e,t,r):hf(e,t,r)}function $o(e,t=0){return e instanceof Uint8Array?Is(e,t):df(e,t)}var Ts=new Float32Array([-0]),re=new Uint8Array(Ts.buffer);function Vo(e,t,r){Ts[0]=e,t[r]=re[0],t[r+1]=re[1],t[r+2]=re[2],t[r+3]=re[3]}function jo(e,t){return re[0]=e[t],re[1]=e[t+1],re[2]=e[t+2],re[3]=e[t+3],Ts[0]}var Ls=new Float64Array([-0]),mt=new Uint8Array(Ls.buffer);function Zo(e,t,r){Ls[0]=e,t[r]=mt[0],t[r+1]=mt[1],t[r+2]=mt[2],t[r+3]=mt[3],t[r+4]=mt[4],t[r+5]=mt[5],t[r+6]=mt[6],t[r+7]=mt[7]}function Yo(e,t){return mt[0]=e[t],mt[1]=e[t+1],mt[2]=e[t+2],mt[3]=e[t+3],mt[4]=e[t+4],mt[5]=e[t+5],mt[6]=e[t+6],mt[7]=e[t+7],Ls[0]}var mf=BigInt(Number.MAX_SAFE_INTEGER),bf=BigInt(Number.MIN_SAFE_INTEGER),Et=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 ye;if(t<mf&&t>bf)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,s=t-(n<<32n);return r&&(n=~n|0n,s=~s|0n,++s>Go&&(s=0n,++n>Go&&(n=0n))),new e(Number(s),Number(n))}static fromNumber(t){if(t===0)return ye;let r=t<0;r&&(t=-t);let n=t>>>0,s=(t-n)/4294967296>>>0;return r&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new e(n,s)}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):ye}},ye=new Et(0,0);ye.toBigInt=function(){return 0n};ye.zzEncode=ye.zzDecode=function(){return this};ye.length=function(){return 1};var Go=4294967296n;function Wo(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 Xo(e,t,r){if(r-t<1)return"";let s,i=[],o=0,a;for(;t<r;)a=e[t++],a<128?i[o++]=a:a>191&&a<224?i[o++]=(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,i[o++]=55296+(a>>10),i[o++]=56320+(a&1023)):i[o++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,o>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,i)),o=0);return s!=null?(o>0&&s.push(String.fromCharCode.apply(String,i.slice(0,o))),s.join("")):String.fromCharCode.apply(String,i.slice(0,o))}function Rs(e,t,r){let n=r,s,i;for(let o=0;o<e.length;++o)s=e.charCodeAt(o),s<128?t[r++]=s:s<2048?(t[r++]=s>>6|192,t[r++]=s&63|128):(s&64512)===55296&&((i=e.charCodeAt(o+1))&64512)===56320?(s=65536+((s&1023)<<10)+(i&1023),++o,t[r++]=s>>18|240,t[r++]=s>>12&63|128,t[r++]=s>>6&63|128,t[r++]=s&63|128):(t[r++]=s>>12|224,t[r++]=s>>6&63|128,t[r++]=s&63|128);return r-n}function _t(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function tn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var _s=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=At(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,_t(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 _t(this,4);return tn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw _t(this,4);return tn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw _t(this,4);let t=jo(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw _t(this,4);let t=Yo(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 _t(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Xo(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw _t(this,t);this.pos+=t}else do if(this.pos>=this.len)throw _t(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 Et(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 _t(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 _t(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 _t(this,8);let t=tn(this.buf,this.pos+=4),r=tn(this.buf,this.pos+=4);return new Et(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=Is(this.buf,this.pos);return this.pos+=qt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function ar(e){return new _s(e instanceof Uint8Array?e:e.subarray())}function ne(e,t,r){let n=ar(e);return t.decode(n,void 0,r)}function Ds(e){let t=e??8192,r=t>>>1,n,s=t;return function(o){if(o<1||o>r)return yt(o);s+o>t&&(n=yt(t),s=0);let a=n.subarray(s,s+=o);return(s&7)!==0&&(s=(s|7)+1),a}}var ge=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Cs(){}var Os=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},yf=Ds();function gf(e){return globalThis.Buffer!=null?yt(e):yf(e)}var ur=class{len;head;tail;states;constructor(){this.len=0,this.head=new ge(Cs,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ge(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new ks((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(en,10,Et.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=Et.fromBigInt(t);return this._push(en,r.length(),r)}uint64Number(t){return this._push(Bs,qt(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=Et.fromBigInt(t).zzEncode();return this._push(en,r.length(),r)}sint64Number(t){let r=Et.fromNumber(t).zzEncode();return this._push(en,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Ps,1,t?1:0)}fixed32(t){return this._push(cr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=Et.fromBigInt(t);return this._push(cr,4,r.lo)._push(cr,4,r.hi)}fixed64Number(t){let r=Et.fromNumber(t);return this._push(cr,4,r.lo)._push(cr,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(Vo,4,t)}double(t){return this._push(Zo,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Ps,1,0):this.uint32(r)._push(xf,r,t)}string(t){let r=Wo(t);return r!==0?this.uint32(r)._push(Rs,r,t):this._push(Ps,1,0)}fork(){return this.states=new Os(this),this.head=this.tail=new ge(Cs,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 ge(Cs,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=gf(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Ps(e,t,r){t[r]=e&255}function wf(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var ks=class extends ge{next;constructor(t,r){super(wf,t,r),this.next=void 0}};function en(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function cr(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 xf(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(ur.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Ef,t,e),this},ur.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Sf,t,e),this});function Ef(e,t,r){t.set(e,r)}function Sf(e,t,r){e.length<40?Rs(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(Y(e),r)}function Ns(){return new ur}function se(e,t){let r=Ns();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*ie(e,t,r){let n=ar(e);yield*t.stream(n,void 0,".",r)}var rn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function nn(e,t,r,n,s){return{name:e,type:t,encode:r,decode:n,stream:s}}function Ks(e){function t(i){if(e[i.toString()]==null)throw new Error("Invalid enum value");return e[i]}let r=function(o,a){let c=t(o);a.int32(c)},n=function(o){let a=o.int32();return t(a)},s=function*(o,a){};return nn("enum",rn.VARINT,r,n,s)}function oe(e,t,r){return nn("message",rn.LENGTH_DELIMITED,e,t,r)}var we=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var st;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(st||(st={}));var Fs;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Fs||(Fs={}));(function(e){e.codec=()=>Ks(Fs)})(st||(st={}));var kt;(function(e){let t;e.codec=()=>(t==null&&(t=oe((i,o,a={})=>{a.lengthDelimited!==!1&&o.fork(),i.Type!=null&&(o.uint32(8),st.codec().encode(i.Type,o)),i.Data!=null&&(o.uint32(18),o.bytes(i.Data)),a.lengthDelimited!==!1&&o.ldelim()},(i,o,a={})=>{let c={},u=o==null?i.len:i.pos+o;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.Type=st.codec().decode(i);break}case 2:{c.Data=i.bytes();break}default:{i.skipType(f&7);break}}}return c},function*(i,o,a,c={}){let u=o==null?i.len:i.pos+o;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:st.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(f&7);break}}}})),t);function r(i){return se(i,e.codec())}e.encode=r;function n(i,o){return ne(i,e.codec(),o)}e.decode=n;function s(i,o){return ie(i,e.codec(),o)}e.stream=s})(kt||(kt={}));var Ms;(function(e){let t;e.codec=()=>(t==null&&(t=oe((i,o,a={})=>{a.lengthDelimited!==!1&&o.fork(),i.Type!=null&&(o.uint32(8),st.codec().encode(i.Type,o)),i.Data!=null&&(o.uint32(18),o.bytes(i.Data)),a.lengthDelimited!==!1&&o.ldelim()},(i,o,a={})=>{let c={},u=o==null?i.len:i.pos+o;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.Type=st.codec().decode(i);break}case 2:{c.Data=i.bytes();break}default:{i.skipType(f&7);break}}}return c},function*(i,o,a,c={}){let u=o==null?i.len:i.pos+o;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:st.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(f&7);break}}}})),t);function r(i){return se(i,e.codec())}e.encode=r;function n(i,o){return ne(i,e.codec(),o)}e.decode=n;function s(i,o){return ie(i,e.codec(),o)}e.stream=s})(Ms||(Ms={}));var lr={};bt(lr,{MAX_RSA_KEY_SIZE:()=>Us,generateRSAKeyPair:()=>na,jwkToJWKKeyPair:()=>sa,jwkToPkcs1:()=>If,jwkToPkix:()=>$s,jwkToRSAPrivateKey:()=>Ys,pkcs1MessageToJwk:()=>zs,pkcs1MessageToRSAPrivateKey:()=>Vs,pkcs1ToJwk:()=>Bf,pkcs1ToRSAPrivateKey:()=>ra,pkixMessageToJwk:()=>Hs,pkixMessageToRSAPublicKey:()=>Zs,pkixToJwk:()=>Tf,pkixToRSAPublicKey:()=>js});var Me=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=lr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return dt.createV1(114,this._multihash)}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ht(this.raw,t.raw)}verify(t,r,n){return ea(this.jwk,r,t,n)}},fr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=lr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ht(this.raw,t.raw)}sign(t,r){return ta(this.jwk,t,r)}};var Us=8192,qs=18,vf=1062,Af=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Bf(e){let t=Kt(e);return zs(t)}function zs(e){return{n:Z(e[1],"base64url"),e:Z(e[2],"base64url"),d:Z(e[3],"base64url"),p:Z(e[4],"base64url"),q:Z(e[5],"base64url"),dp:Z(e[6],"base64url"),dq:Z(e[7],"base64url"),qi:Z(e[8],"base64url"),kty:"RSA"}}function If(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new et("JWK was missing components");return Zt([gt(Uint8Array.from([0])),gt(Y(e.n,"base64url")),gt(Y(e.e,"base64url")),gt(Y(e.d,"base64url")),gt(Y(e.p,"base64url")),gt(Y(e.q,"base64url")),gt(Y(e.dp,"base64url")),gt(Y(e.dq,"base64url")),gt(Y(e.qi,"base64url"))]).subarray()}function Tf(e){let t=Kt(e,{offset:0});return Hs(t)}function Hs(e){let t=Kt(e[1],{offset:0});return{kty:"RSA",n:Z(t[0],"base64url"),e:Z(t[1],"base64url")}}function $s(e){if(e.n==null||e.e==null)throw new et("JWK was missing components");return Zt([Af,Tr(Zt([gt(Y(e.n,"base64url")),gt(Y(e.e,"base64url"))]))]).subarray()}function ra(e){let t=Kt(e);return Vs(t)}function Vs(e){let t=zs(e);return Ys(t)}function js(e,t){if(e.byteLength>=vf)throw new Dt("Key size is too large");let r=Kt(e,{offset:0});return Zs(r,e,t)}function Zs(e,t,r){let n=Hs(e);if(r==null){let s=Ce(kt.encode({Type:st.RSA,Data:t}));r=Ct(qs,s)}return new Me(n,r)}function Ys(e){if(oa(e)>Us)throw new et("Key size is too large");let t=sa(e),r=Ce(kt.encode({Type:st.RSA,Data:$s(t.publicKey)})),n=Ct(qs,r);return new fr(t.privateKey,new Me(t.publicKey,n))}async function na(e){if(e>Us)throw new et("Key size is too large");let t=await ia(e),r=Ce(kt.encode({Type:st.RSA,Data:$s(t.publicKey)})),n=Ct(qs,r);return new fr(t.privateKey,new Me(t.publicKey,n))}function sa(e){if(e==null)throw new et("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function ia(e,t){let r=await Tt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Lf(r,t);return{privateKey:n[0],publicKey:n[1]}}async function ta(e,t,r){let n=await Tt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let s=await Tt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,At(t instanceof Uint8Array?t:t.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(s,0,s.byteLength)}async function ea(e,t,r,n){let s=await Tt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await Tt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},s,At(t),At(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),i}async function Lf(e,t){if(e.privateKey==null||e.publicKey==null)throw new et("Private and public key are required");let r=await Promise.all([Tt.get().subtle.exportKey("jwk",e.privateKey),Tt.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function oa(e){if(e.kty!=="RSA")throw new et("invalid key type");if(e.n==null)throw new et("invalid key modulus");return Y(e.n,"base64url").length*8}var sn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(_r(t),Bt(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,s=new Uint8Array(n);s.set(r.length>n?t.create().update(r).digest():r);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),de(s)}update(t){return De(this),this.iHash.update(t),this}digestInto(t){De(this),Dr(t,this),this.finished=!0;let r=t.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:s,destroyed:i,blockLen:o,outputLen:a,canXOF:c}=this;return t=t,t.finished=s,t.destroyed=i,t.blockLen=o,t.outputLen=a,t.canXOF=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},aa=(()=>{let e=((t,r,n)=>new sn(t,r).update(n).digest());return e.create=(t,r)=>new sn(t,r),e})();var Rf=BigInt(0),Gs=class extends Error{constructor(t=""){super(t)}},zt={Err:Gs,_tlv:{encode:(e,t)=>{let{Err:r}=zt;if(Ut(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(ho(t,"data"),t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,s=er(n);if(s.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?er(s.length/2|128):"";return er(e)+i+s+t},decode(e,t){let{Err:r}=zt;t=$(t,void 0,"DER data");let n=0;if(e<0||e>255)throw new r("tlv.decode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let s=t[n++],i=!!(s&128),o=0;if(!i)o=s;else{let c=s&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)o=o<<8|f;if(n+=c,o<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+o);if(a.length!==o)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+o)}}},_int:{encode(e){let{Err:t}=zt;if(Kr(e),e<Rf)throw new t("integer: negative integers are not allowed");let r=er(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}=zt;if(e.length<1)throw new t("invalid signature integer: empty");if(e[0]&128)throw new t("invalid signature integer: negative");if(e.length>1&&e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Ot(e)}},toSig(e,t){let{Err:r,_int:n,_tlv:s}=zt;if(t!==void 0&&(Ut(t,"maxScalarBytes"),t<1))throw new r("invalid signature: maxScalarBytes must be positive");let i=$(e,void 0,"signature"),{v:o,l:a}=s.decode(48,i);if(a.length)throw new r("invalid signature: left bytes after parsing");let{v:c,l:u}=s.decode(2,o),{v:f,l:h}=s.decode(2,u);if(h.length)throw new r("invalid signature: left bytes after parsing");if(t!==void 0&&(c.length>t||f.length>t))throw new r("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(f)}},hexFromSig(e){let{_tlv:t,_int:r}=zt;xt(e,{r:"bigint",s:"bigint"},{},"sig");let n=t.encode(2,r.encode(e.r)),s=t.encode(2,r.encode(e.s)),i=n+s;return t.encode(48,i)}},on=(Object.freeze(zt._tlv),Object.freeze(zt._int),Object.freeze(zt));var ca=(e,t)=>(e+(e>=0?t:-t)/ua)/t;function _f(e,t,r){Oe("scalar",e,Ht,r);let[[n,s],[i,o]]=t,a=ca(o*e,r),c=ca(-s*e,r),u=e-a*n-c*i,f=-a*s-c*o,h=u<Ht,l=f<Ht;h&&(u=-u),l&&(f=-f);let d=nr(Math.ceil(ke(r)/2))+xe;if(u<Ht||u>=d||f<Ht||f>=d)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:h,k1:u,k2neg:l,k2:f}}function Js(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Ws(e,t){xt(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return wt(r.lowS,"lowS"),wt(r.prehash,"prehash"),r.format!==void 0&&Js(r.format),r}var Ht=BigInt(0),xe=BigInt(1),ua=BigInt(2),Xs=BigInt(3),Df=BigInt(4);function fa(e,t={}){let r=Vr("weierstrass",e,t),n=r.Fp,s=r.Fn,i=r.CURVE,{h:o,n:a}=i;xt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u,clearCofactor:f,isTorsionFree:h,fromBytes:l,toBytes:d}=t,y=t.randomBytes===void 0?me:t.randomBytes;if(c&&(!n.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let g=c?{beta:c.beta,basises:c.basises.map(A=>[...A])}:void 0,E=ha(n,s);function w(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function v(A,p,b){if(p.is0()){if(!u)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x,y:I}=p.toAffine(),L=n.toBytes(x);if(wt(b,"isCompressed"),b){w();let R=!n.isOdd(I);return It(la(R),L)}else return It(Uint8Array.of(4),L,n.toBytes(I))}function m(A){$(A,void 0,"Point");let{publicKey:p,publicKeyUncompressed:b}=E,x=A.length,I=A[0],L=A.subarray(1);if(u&&x===1&&I===0)return{x:n.ZERO,y:n.ZERO};if(x===p&&(I===2||I===3)){let R=n.fromBytes(L);if(!n.isValid(R))throw new Error("bad point: is not on curve, wrong x");let O=k(R),N;try{N=n.sqrt(O)}catch(ot){let X=ot instanceof Error?": "+ot.message:"";throw new Error("bad point: is not on curve, sqrt error"+X)}w();let H=n.isOdd(N);return(I&1)===1!==H&&(N=n.neg(N)),{x:R,y:N}}else if(x===b&&I===4){let R=n.BYTES,O=n.fromBytes(L.subarray(0,R)),N=n.fromBytes(L.subarray(R,R*2));if(!_(O,N))throw new Error("bad point: is not on curve");return{x:O,y:N}}else throw new Error(`bad point: got length ${x}, expected compressed=${p} or uncompressed=${b}`)}let S=d===void 0?v:d,B=l===void 0?m:l,P=n.mul(i.b,Xs),K=n.is0(i.a)?A=>n.ZERO:A=>n.mul(i.a,A);function k(A){let p=n.sqr(A),b=n.mul(p,A);return n.add(n.add(b,n.mul(A,i.a)),i.b)}function _(A,p){let b=n.sqr(p),x=k(A);return n.eql(b,x)}if(!_(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let C=n.mul(n.pow(i.a,Xs),Df),q=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(C,q)))throw new Error("bad curve params: a or b");function U(A,p,b=!1){if(!n.isValid(p)||b&&n.is0(p))throw new Error(`bad point coordinate ${A}`);return typeof p=="object"&&p!==null?n.create(p):p}function G(A){if(!(A instanceof D))throw new Error("Weierstrass Point expected")}function T(A){if(!g||!g.basises)throw new Error("no endo");return _f(A,g.basises,s.ORDER)}function F(A,p,b,x){if(!s.isValid(x))throw new RangeError("invalid scalar: out of range");if(g){let{k1neg:I,k1:L,k2neg:R,k2:O}=T(x),N=new D(n.mul(b.X,g.beta),b.Y,b.Z);A.push(I?b.negate():b,R?N.negate():N),p.push(L,O)}else A.push(b),p.push(x)}let M=new WeakSet;class D{static BASE=new D(i.Gx,i.Gy,n.ONE);static ZERO=new D(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=s;X;Y;Z;constructor(p,b,x){this.X=U("x",p),this.Y=U("y",b,!0),this.Z=U("z",x),Object.freeze(this)}static CURVE(){return i}static fromAffine(p){let{x:b,y:x}=p||{};if(!p||!n.isValid(b)||!n.isValid(x))throw new Error("invalid affine point");if(p instanceof D)throw new Error("projective point not allowed");return n.is0(b)&&n.is0(x)?D.ZERO:new D(b,x,n.ONE)}static fromBytes(p){let b=D.fromAffine(B($(p,void 0,"point")));return b.assertValidity(),b}static fromHex(p){return D.fromBytes(Pe(p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=6,b=!0){return tt.setWindowSize(this,p),b||this.multiply(Xs),this}assertValidity(){let p=this;if(p.is0()){if(u&&n.is0(p.X)&&n.eql(p.Y,n.ONE)&&n.is0(p.Z))return;throw new Error("bad point: ZERO")}if(M.has(p))return;let{x:b,y:x}=p.toAffine();if(!n.isValid(b)||!n.isValid(x))throw new Error("bad point: x or y not field elements");if(!_(b,x))throw new Error("bad point: equation left != right");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");M.add(p)}hasEvenY(){let{y:p}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(p)}equals(p){G(p);let{X:b,Y:x,Z:I}=this,{X:L,Y:R,Z:O}=p,N=n.eql(n.mul(b,O),n.mul(L,I)),H=n.eql(n.mul(x,O),n.mul(R,I));return N&&H}negate(){return new D(this.X,n.neg(this.Y),this.Z)}double(){let{X:p,Y:b,Z:x}=this,I=n.ZERO,L=n.ZERO,R=n.ZERO,O=n.mul(p,p),N=n.mul(b,b),H=n.mul(x,x),z=n.mul(p,b);return z=n.add(z,z),R=n.mul(p,x),R=n.add(R,R),I=K(R),L=n.mul(P,H),L=n.add(I,L),I=n.sub(N,L),L=n.add(N,L),L=n.mul(I,L),I=n.mul(z,I),R=n.mul(P,R),H=K(H),z=n.sub(O,H),z=K(z),z=n.add(z,R),R=n.add(O,O),O=n.add(R,O),O=n.add(O,H),O=n.mul(O,z),L=n.add(L,O),H=n.mul(b,x),H=n.add(H,H),O=n.mul(H,z),I=n.sub(I,O),R=n.mul(H,N),R=n.add(R,R),R=n.add(R,R),new D(I,L,R)}add(p){G(p);let{X:b,Y:x,Z:I}=this,{X:L,Y:R,Z:O}=p,N=n.ZERO,H=n.ZERO,z=n.ZERO,ot=n.mul(b,L),X=n.mul(x,R),ft=n.mul(I,O),St=n.add(b,x),J=n.add(L,R);St=n.mul(St,J),J=n.add(ot,X),St=n.sub(St,J),J=n.add(b,I);let at=n.add(L,O);return J=n.mul(J,at),at=n.add(ot,ft),J=n.sub(J,at),at=n.add(x,I),N=n.add(R,O),at=n.mul(at,N),N=n.add(X,ft),at=n.sub(at,N),z=K(J),N=n.mul(P,ft),z=n.add(N,z),N=n.sub(X,z),z=n.add(X,z),H=n.mul(N,z),X=n.add(ot,ot),X=n.add(X,ot),ft=K(ft),J=n.mul(P,J),X=n.add(X,ft),ft=n.sub(ot,ft),ft=K(ft),J=n.add(J,ft),ot=n.mul(X,J),H=n.add(H,ot),ot=n.mul(at,J),N=n.mul(St,N),N=n.sub(N,ot),ot=n.mul(St,X),z=n.mul(at,z),z=n.add(z,ot),new D(N,H,z)}subtract(p){return G(p),this.add(p.negate())}is0(){return this.equals(D.ZERO)}multiply(p){if(!s.isValidNot0(p))throw new RangeError("invalid scalar: out of range");let{p:b,f:x}=tt.mulSecret(this,p,o,W);return W([b,x])[0]}multiplyUnsafe(p){let b=this,x=p;if(!s.isValid(x))throw new RangeError("invalid scalar: out of range");if(x===Ht||b.is0())return D.ZERO;if(x===xe)return b;if(tt.hasWindowSize(this))return tt.mulUnsafe(b,x,W);let I=[],L=[];return F(I,L,b,x),$r(D,I,L)}mulAddUnsafe(p,b,x){G(b);let I=[],L=[];return F(I,L,this,p),F(I,L,b,x),$r(D,I,L)}toAffine(p){let b=this,x=p;if(x!=null&&!n.isValid(x))throw new RangeError('"invertedZ" expected valid field element');let{X:I,Y:L,Z:R}=b;if(n.eql(R,n.ONE))return{x:I,y:L};let O=b.is0();x==null&&(x=O?n.ONE:n.inv(R));let N=n.mul(I,x),H=n.mul(L,x),z=n.mul(R,x);if(O)return{x:n.ZERO,y:n.ZERO};if(!n.eql(z,n.ONE))throw new Error("invZ was invalid");return{x:N,y:H}}isTorsionFree(){return o===xe?!0:h?h(D,this):tt.mulUnsafe(this,a).is0()}clearCofactor(){return o===xe?this:f?f(D,this):this.multiplyUnsafe(o)}isSmallOrder(){return o===xe?this.is0():this.clearCofactor().is0()}toBytes(p=!0){return wt(p,"isCompressed"),this.assertValidity(),S(D,this,p)}toHex(p=!0){return tr(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let W=A=>Hr(D,A),tt=new Fe(D,y);return tt.bits>=6&&D.BASE.precompute(6),Object.freeze(D.prototype),Object.freeze(D),D}function la(e){return Uint8Array.of(e?2:3)}function ha(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Cf(e,t={}){ee(e);let{Fn:r}=e,n=t.randomBytes===void 0?me:t.randomBytes,s=Object.assign(ha(e.Fp,r),{seed:Math.max(qr(r.ORDER),16)});function i(d){try{let y=r.fromBytes(d);return r.isValidNot0(y)}catch{return!1}}function o(d,y){let{publicKey:g,publicKeyUncompressed:E}=s;try{let w=d.length;return y===!0&&w!==g||y===!1&&w!==E?!1:!e.fromBytes(d).is0()}catch{return!1}}function a(d){return d=d===void 0?n(s.seed):d,zr($(d,s.seed,"seed"),r.ORDER)}function c(d,y=!0){return e.BASE.multiply(r.fromBytes(d)).toBytes(y)}function u(d){let{secretKey:y,publicKey:g,publicKeyUncompressed:E}=s,w=r._lengths;if(!Qt(d))return;let v=$(d,void 0,"key").length,m=v===g||v===E,S=v===y||!!w?.includes(v);if(!(m&&S))return m}function f(d,y,g=!0){if(u(d)===!0)throw new Error("first arg must be private key");if(u(y)===!1)throw new Error("second arg must be public key");let E=r.fromBytes(d),w=e.fromBytes(y);if(w.is0())throw new Error("invalid public key: point at infinity");return w.multiply(E).toBytes(g)}let h={isValidSecretKey:i,isValidPublicKey:o,randomSecretKey:a},l=jr(a,c);return Object.freeze(h),Object.freeze(s),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:l,Point:e,utils:h,lengths:s})}function da(e,t,r={}){ee(e);let n=t;_r(n),xt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let s=Object.assign({},r),i=s.randomBytes===void 0?me:s.randomBytes,o=s.hmac===void 0?(A,p)=>aa(n,A,p):s.hmac,{Fp:a,Fn:c}=e,{ORDER:u,BITS:f}=c,h=qr(u),l=ps(i,h),{keygen:d,getPublicKey:y,getSharedSecret:g,utils:E,lengths:w}=Cf(e,s),v={prehash:!0,lowS:typeof s.lowS=="boolean"?s.lowS:!0,format:"compact",extraEntropy:!1},m=u*ua+xe<a.ORDER;function S(A){let p=u>>xe;return A>p}function B(A,p){if(!c.isValidNot0(p))throw new Error(`invalid signature ${A}: out of range 1..Point.Fn.ORDER`);return p}function P(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function K(A,p,b){return P(),(A===b?0:2)|Number(a.isOdd(p))}function k(){if(m)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function _(A,p){Js(p);let b=w.signature,x=p==="compact"?b:p==="recovered"?b+1:void 0;return $(A,x)}class C{r;s;recovery;constructor(p,b,x){if(this.r=B("r",p),this.s=B("s",b),x!=null){if(k(),![0,1,2,3].includes(x))throw new Error("invalid recovery id");this.recovery=x}Object.freeze(this)}static fromBytes(p,b=v.format){_(p,b);let x;if(b==="der"){if(p.length>2*c.BYTES+16)throw new on.Err("invalid signature: DER signature too long");let{r:O,s:N}=on.toSig($(p),c.BYTES+1);return new C(O,N)}b==="recovered"&&(x=p[0],b="compact",p=p.subarray(1));let I=w.signature/2,L=p.subarray(0,I),R=p.subarray(I,I*2);return new C(c.fromBytes(L),c.fromBytes(R),x)}static fromHex(p,b){return this.fromBytes(Pe(p),b)}assertRecovery(){let{recovery:p}=this;if(p==null)throw new Error("invalid recovery id: must be present");return p}addRecoveryBit(p){return new C(this.r,this.s,p)}recoverPublicKey(p){let{r:b,s:x}=this,I=this.assertRecovery(),L=I===2||I===3?b+u:b;if(!a.isValid(L))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let R=a.toBytes(L),O=e.fromBytes(It(la((I&1)===0),R)),N=c.inv(L),H=U($(p,void 0,"msgHash")),z=c.create(-H*N),ot=c.create(x*N),X=e.BASE.mulAddUnsafe(z,O,ot);if(X.is0())throw new Error("invalid recovery: point at infinify");return X.assertValidity(),X}hasHighS(){return S(this.s)}toBytes(p=v.format){if(Js(p),p==="der")return Pe(on.hexFromSig(this));let{r:b,s:x}=this,I=c.toBytes(b),L=c.toBytes(x);return p==="recovered"?(k(),It(Uint8Array.of(this.assertRecovery()),I,L)):It(I,L)}toHex(p){return tr(this.toBytes(p))}}Object.freeze(C.prototype),Object.freeze(C);let q=s.bits2int===void 0?function(p){if(p.length>8192)throw new Error("input is too large");let b=Ot(p),x=p.length*8-f;return x>0?b>>BigInt(x):b}:s.bits2int,U=s.bits2int_modN===void 0?function(p){return c.create(q(p))}:s.bits2int_modN,G=nr(f);function T(A){return Oe("num < 2^"+f,A,Ht,G),c.toBytes(A)}function F(A,p){return $(A,void 0,"message"),p?$(n(A),void 0,"prehashed message"):A}function M(A,p,b){let{lowS:x,prehash:I,extraEntropy:L}=Ws(b,v);A=F(A,I);let R=U(A),O=c.fromBytes(p);if(!c.isValidNot0(O))throw new Error("invalid private key");let N=[T(O),T(R)];if(L!=null&&L!==!1){let X=L===!0?i(w.secretKey):L;N.push($(X,void 0,"extraEntropy"))}let H=It(...N),z=R;function ot(X){let ft=q(X);if(!c.isValidNot0(ft))return;let St=e.BASE.multiply(ft).toAffine(),J=c.create(St.x);if(J===Ht)return;let at;if(l!==void 0){let He=Ot(zr(l(h),u)),Ka=c.inv(c.mul(He,ft)),Fa=c.mul(He,z),Ma=c.mul(He,O);at=c.create(Ka*c.create(Fa+Ma*J))}else{let He=vo(ft,u);at=c.create(He*c.create(z+J*O))}if(at===Ht)return;let bn=K(St.x,St.y,J),pi=at;return x&&S(at)&&(pi=c.neg(at),bn^=1),new C(J,pi,m?void 0:bn)}return{seed:H,k2sig:ot}}function D(A,p,b={}){let{seed:x,k2sig:I}=M(A,p,b);return mo(n.outputLen,c.BYTES,o)(x,I).toBytes(b.format)}function W(A,p,b,x={}){let{lowS:I,prehash:L,format:R}=Ws(x,v);if(b=$(b,void 0,"publicKey"),p=F(p,L),!Qt(A)){let O=A instanceof C?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+O)}_(A,R);try{let O=C.fromBytes(A,R),N=e.fromBytes(b);if(N.is0()||I&&O.hasHighS())return!1;let{r:H,s:z}=O,ot=U(p),X=c.inv(z),ft=c.create(ot*X),St=c.create(H*X),J=e.BASE.mulAddUnsafe(ft,N,St);if(J.is0())return!1;let at=J.toAffine();return!(c.create(at.x)!==H||R==="recovered"&&O.recovery!==K(at.x,at.y,H))}catch{return!1}}function tt(A,p,b={}){let{prehash:x}=Ws(b,v);return p=F(p,x),C.fromBytes(A,"recovered").recoverPublicKey(p).toBytes()}return Object.freeze({keygen:d,getPublicKey:y,getSharedSecret:g,utils:E,lengths:w,Point:e,sign:D,verify:W,recoverPublicKey:tt,Signature:C,hash:n})}var ti={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Pf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var pa=BigInt(2);function Of(e){let t=ti.p,r=BigInt(3),n=BigInt(6),s=BigInt(11),i=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,f=u*u*e%t,h=Q(f,r,t)*f%t,l=Q(h,r,t)*f%t,d=Q(l,pa,t)*u%t,y=Q(d,s,t)*d%t,g=Q(y,i,t)*y%t,E=Q(g,a,t)*g%t,w=Q(E,c,t)*E%t,v=Q(w,a,t)*g%t,m=Q(v,r,t)*f%t,S=Q(m,o,t)*y%t,B=Q(S,n,t)*u%t,P=Q(B,pa,t);if(!Qs.eql(Qs.sqr(P),e))throw new Error("Cannot find square root");return P}var Qs=Ke(ti.p,{sqrt:Of}),kf=fa(ti,{Fp:Qs,endo:Pf}),Ue=da(kf,Ce);function ma(e,t,r,n){let s=fe.digest(r instanceof Uint8Array?r:r.subarray());if(Jr(s))return s.then(({digest:i})=>(n?.signal?.throwIfAborted(),Ue.verify(t,i,e,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new or(String(i))});try{return n?.signal?.throwIfAborted(),Ue.verify(t,s.digest,e,{prehash:!1,format:"der"})}catch(i){throw new or(String(i))}}var an=class{type="secp256k1";raw;_key;constructor(t){this._key=ya(t),this.raw=ba(this._key)}toMultihash(){return Lt.digest(Ft(this))}toCID(){return dt.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ht(this.raw,t.raw)}verify(t,r,n){return ma(this._key,r,t,n)}};function ei(e){return new an(e)}function ba(e){return Ue.Point.fromBytes(e).toBytes()}function ya(e){try{return Ue.Point.fromBytes(e),e}catch(t){throw new Dt(String(t))}}function cn(e,t){let{Type:r,Data:n}=kt.decode(e),s=n??new Uint8Array;switch(r){case st.RSA:return js(s,t);case st.Ed25519:return xs(s);case st.secp256k1:return ei(s);case st.ECDSA:return Zn(s);default:throw new ae}}function ga(e){let{Type:t,Data:r}=kt.decode(e.digest),n=r??new Uint8Array;switch(t){case st.Ed25519:return xs(n);case st.secp256k1:return ei(n);case st.ECDSA:return Zn(n);default:throw new ae}}function Ft(e){return kt.encode({Type:st[e.type],Data:e.raw})}async function wa(e,t,r){if(r?.signal?.throwIfAborted(),t!=null){let n;try{n=t instanceof Uint8Array?cn(t):t}catch(s){throw new Dt(`Could not decode public key - ${s.message}`)}if(!ht(n.toMultihash().bytes,e.toMultihash().bytes))throw new Dt("Public key does not match peer id");return n}if(e.publicKey==null)throw new Dt("No public key available for peer id");return e.publicKey}var xa=Symbol.for("nodejs.util.inspect.custom"),Nf=114,hr=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()})`}[gn]=!0;toString(){return this.string==null&&(this.string=rt.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return dt.createV1(Nf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return ht(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return ht(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[xa](){return`PeerId(${this.toString()})`}},dr=class extends hr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},pr=class extends hr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},mr=class extends hr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Kf=2336,un=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Lt.digest(Y(this.url))}[xa](){return`PeerId(${this.url})`}[gn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return dt.createV1(Kf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=Z(t)),t.toString()===this.toString())}};function ri(e){if(e.type==="Ed25519")return new pr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new mr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new dr({multihash:e.toCID().multihash,publicKey:e});throw new ae}function Ea(e){return ri(e.publicKey)}function br(e){if(Mf(e))return new dr({multihash:e});if(Ff(e))try{let t=ga(e);if(t.type==="Ed25519")return new pr({multihash:e,publicKey:t});if(t.type==="secp256k1")return new mr({multihash:e,publicKey:t})}catch{let r=Z(e.digest);return new un(new URL(r))}throw new Sr("Supplied PeerID Multihash is invalid")}function Ff(e){return e.code===Lt.code}function Mf(e){return e.code===fe.code}function Ee(e,t){let r={[Symbol.iterator]:()=>r,next:()=>{let n=e.next(),s=n.value;return n.done===!0||s==null?{done:!0,value:void 0}:{done:!1,value:t(s)}}};return r}function fn(e){let t=Vt(rt.decode(`z${e}`));return br(t)}var yr=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[r,n]of t.entries())this.map.set(r.toString(),{key:r,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return Ee(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((r,n)=>{t(r.value,r.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,r){this.map.set(t.toString(),{key:t,value:r})}keys(){return Ee(this.map.values(),t=>t.key)}values(){return Ee(this.map.values(),t=>t.value)}get size(){return this.map.size}};var gr=class e{set;constructor(t){if(this.set=new Set,t!=null)for(let r of t)this.set.add(r.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return Ee(this.set.entries(),t=>{let r=fn(t[0]);return[r,r]})}forEach(t){this.set.forEach(r=>{let n=fn(r);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Ee(this.set.values(),t=>fn(t))}intersection(t){let r=new e;for(let n of t)this.has(n)&&r.add(n);return r}difference(t){let r=new e;for(let n of this)t.has(n)||r.add(n);return r}union(t){let r=new e;for(let n of t)r.add(n);for(let n of this)r.add(n);return r}};var ni=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},Sa=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function si(e,t){let{milliseconds:r,fallback:n,message:s,customTimers:i={setTimeout,clearTimeout},signal:o}=t,a,c,f=new Promise((h,l)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(o?.aborted){l(Sa(o)),e.then(h,l);return}if(o&&(c=()=>{l(Sa(o))},o.addEventListener("abort",c,{once:!0})),e.then(h,l),r===Number.POSITIVE_INFINITY)return;let d=new ni;a=i.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(y){l(y)}return}typeof e.cancel=="function"&&e.cancel(),s===!1?h():s instanceof Error?l(s):(d.message=s??`Promise timed out after ${r} milliseconds`,l(d))},r)}).finally(()=>{f.clear(),c&&o&&o.removeEventListener("abort",c)});return f.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},f}var va=e=>typeof e=="function"?{filter:e}:{...e},Uf=e=>e===1/0||Number.isSafeInteger(e)&&e>=0,qf=[["addEventListener","removeEventListener"],["on","off"],["addListener","removeListener"]],zf=e=>{for(let[t,r]of qf){let n=e?.[t],s=e?.[r];if(typeof n=="function"&&typeof s=="function")return{addListener:n.bind(e),removeListener:s.bind(e)}}throw new TypeError("Emitter is not compatible")},Hf=e=>{let t=new Map;for(let[r,n]of e)for(let s of Array.isArray(r)?r:[r])t.has(s)||t.set(s,n);return t},$f=({addListener:e,removeListener:t,handlers:r,signal:n,abortHandler:s,isDone:i})=>{n?.addEventListener("abort",s,{once:!0});for(let[o,a]of r)if(e(o,a),i()){t(o,a);return}},Vf=({removeListener:e,handlers:t,signal:r,abortHandler:n})=>{for(let[s,i]of t)e(s,i);r?.removeEventListener("abort",n)},jf=(e,t,r)=>{let n=Promise.resolve();return(s,i)=>{n=n.then(async()=>{if(t())return;let o;try{o=e?await e(s):!0}catch(a){t()||r(a);return}t()||i(o)})}};function Zf(e,t,r){let n=()=>{},s=!1,i,o=new Promise((a,c)=>{r=va(r);let{filter:u}=r;if(!Uf(r.count))throw new TypeError("The `count` option should be at least 0 or more");if(typeof r.timeout=="number"&&!(r.timeout>0))throw new TypeError(`Expected the \`timeout\` option to be a positive number, got \`${r.timeout}\``);r.signal?.throwIfAborted();let{addListener:f,removeListener:h}=zf(e);if(r.count===0){a([]);return}let l=[],d=S=>{n(),c(S)},y=jf(u,()=>s,d),g=S=>{l.push(S),r.count===l.length&&(n(),a(l))},E=(...S)=>{if(s)return;let B=r.multiArgs?S:S[0];if(!u){g(B);return}y(B,P=>{P&&g(B)})},w=(...S)=>{d(r.rejectionMultiArgs?S:S[0])},v=()=>{d(r.signal.reason)},m={addListener:f,removeListener:h,handlers:Hf([[t,E],[r.rejectionEvents??["error"],w]]),signal:r.signal,abortHandler:v,isDone:()=>s};n=()=>{s=!0,clearTimeout(i),Vf(m)},$f(m),!(s||!r.resolveImmediately)&&(Number.isFinite(r.timeout)&&(i=setTimeout(n,r.timeout)),a(l))});if(o.cancel=n,typeof r.timeout=="number"&&r.timeout>0&&!r.resolveImmediately){let a=si(o,{milliseconds:r.timeout});return a.cancel=()=>{n(),a.clear()},a}return o}function Aa(e,t,r){let n=Zf(e,t,{...va(r),count:1,resolveImmediately:!1}),s=n.then(i=>i[0]);return s.cancel=n.cancel,s}var Se=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Yf(e){return e.reason}function ii(e,t,r){if(t==null||e==null)return e;let n=r?.translateError??Yf;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let s;return Promise.race([e,new Promise((i,o)=>{s=()=>{o(n(t))},t.addEventListener("abort",s)})]).finally(()=>{s!=null&&t.removeEventListener("abort",s)})}var Wf=4194304,ln=class extends Error{static name="UnwrappedError";name="UnwrappedError"},ai=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ci=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},ui=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Xf(e){return typeof e?.closeRead=="function"}function Jf(e){return typeof e?.close=="function"}function oi(e){return Xf(e)?e.remoteWriteStatus!=="writable"&&e.readBufferLength===0:Jf(e)?e.status!=="open":!1}function Qf(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function tl(e,t){let r=t?.maxBufferSize??Wf,n=new lt,s,i=!1,o;if(!Qf(e))throw new et("Argument should be a Stream or a Multiaddr");let a=h=>{if(!i&&o==null){if(n.append(h.data),n.byteLength>r){let l=n.byteLength;n.consume(l);let d=new Er(`Read buffer overflow - ${l} > ${r}`);o=d,s?.reject(d),queueMicrotask(()=>{e.abort(d)});return}s?.resolve()}};e.addEventListener("message",a);let c=h=>{h.error!=null?s?.reject(h.error):s?.resolve()};e.addEventListener("close",c);let u=()=>{s?.resolve()};e.addEventListener("remoteCloseWrite",u);let f={readBuffer:n,async read(h){if(i===!0)throw new ln("Stream was unwrapped");if(o!=null)throw o;if(oi(e)){if(n.byteLength===0&&h?.bytes==null)return null;if(h?.bytes!=null&&n.byteLength<h.bytes)throw e.log.error("closed after reading %d/%d bytes",n.byteLength,h.bytes),new Se(`Unexpected EOF - stream closed after reading ${n.byteLength}/${h.bytes} bytes`)}let l=h?.bytes??1;for(s=Promise.withResolvers();;){if(n.byteLength>=l){s.resolve();break}if(await ii(s.promise,h?.signal),oi(e)){if(n.byteLength===0&&h?.bytes==null)return null;break}s=Promise.withResolvers()}let d=h?.bytes??n.byteLength;if(n.byteLength<d){if(oi(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,d),new Se(`Unexpected EOF - stream closed while reading ${n.byteLength}/${d} bytes`);return f.read(h)}let y=n.sublist(0,d);return n.consume(d),y},async write(h,l){if(i===!0)throw new ln("Stream was unwrapped");e.send(h)||await Aa(e,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return i||(i=!0,e.removeEventListener("message",a),e.removeEventListener("close",c),e.removeEventListener("remoteCloseWrite",u),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.unshift(n),n.consume(n.byteLength))),e}};return f}function el(e,t={}){let r=tl(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=qt(t.maxDataLength));let n=t?.lengthDecoder??$o,s=t?.lengthEncoder??Ho;return{async read(o){let a=-1,c=new lt;for(;;){let f=await r.read({...o,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(h){if(h instanceof RangeError)continue;throw h}if(a<0)throw new ai("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new ui(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new ci(`Message length too long - ${a} > ${t.maxDataLength}`);let u=await r.read({...o,bytes:a});if(u==null)throw e.log.error("tried to read %d bytes but the stream closed",a),new Se(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw e.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new Se(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(o,a){await r.write(new lt(s(o.byteLength),o),a)},async writeV(o,a){let c=new lt(...o.flatMap(u=>[s(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function fi(e,t){let r=el(e,t),n={read:async(s,i)=>{let o=await r.read(i);return s.decode(o,i)},write:async(s,i,o)=>{await r.write(i.encode(s),o)},writeV:async(s,i,o)=>{await r.writeV(s.map(a=>i.encode(a)),o)},pb:s=>({read:async i=>n.read(s,i),write:async(i,o)=>n.write(i,s,o),writeV:async(i,o)=>n.writeV(i,s,o),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}function li(e,t,r){let n=0,s=e.length;for(;s>0;){let i=Math.trunc(s/2),o=n+i;r(e[o],t)<=0?(n=++o,s-=i+1):s=i}return n}var rl=100,qe=class{#t=[];#e=0;#i(){this.#e!==0&&(this.#t.splice(0,this.#e),this.#e=0)}#u(t){for(let r=this.#e;r<this.#t.length;r++)if(t(this.#t[r]))return r;return-1}#b(){let t=this.#t[this.#e];return this.#t[this.#e]=void 0,this.#e++,this.#e===this.#t.length?(this.#t.length=0,this.#e=0):this.#e>rl&&this.#e>this.#t.length/2&&this.#i(),t.run}enqueue(t,r){let{priority:n=0,id:s}=r??{},{size:i}=this,o={priority:n,id:s,run:t};if(i===0){this.#t.length=0,this.#e=0,this.#t.push(o);return}if(this.#t.at(-1).priority>=n){this.#t.push(o);return}this.#i();let a=li(this.#t,o,(c,u)=>c.priority===u.priority?0:u.priority-c.priority);this.#t.splice(a,0,o)}setPriority(t,r){let n=this.#u(i=>i.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);if(this.#t[n].priority===r)return;let[s]=this.#t.splice(n,1);this.enqueue(s.run,{priority:r,id:t})}remove(t){let r=this.#u(n=>(typeof t=="string"?n.id:n.run)===t);r===this.#e?this.#b():r!==-1&&this.#t.splice(r,1)}dequeue(){return this.#e===this.#t.length?void 0:this.#b()}filter(t){let r=[];for(let n=this.#e;n<this.#t.length;n++){let s=this.#t[n];s.priority===t.priority&&r.push(s.run)}return r}get size(){return this.#t.length-this.#e}};var hn=2147483647,Ba=globalThis.process?.getBuiltinModule?.("node:async_hooks"),nl=e=>{if(Ba===void 0)return e;let t=new Ba.AsyncResource("PQueueTask");return()=>t.runInAsyncScope(e)},Ia=e=>{if(e!==void 0&&!(Number.isFinite(e)&&e>0&&e<=hn))throw new TypeError(`Expected \`timeout\` to be a positive finite number up to ${hn}, got \`${e}\` (${typeof e})`)},Ta=(e,t)=>{if(!(typeof t=="number"&&t>=1&&(t===1/0||Number.isInteger(t))))throw new TypeError(`Expected \`${e}\` to be an integer from 1 and up or \`Infinity\`, got \`${String(t)}\` (${typeof t})`)},sl=(e,t,r)=>{if(Ta("intervalCap",t),!(Number.isFinite(e)&&e>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${String(e)}\` (${typeof e})`);if(t!==1/0&&e>hn)throw new TypeError(`Expected \`interval\` to be at most ${hn} with an \`intervalCap\`, got \`${e}\``);if(r&&e===0)throw new TypeError("The `strict` option requires a non-zero `interval`");if(r&&t===1/0)throw new TypeError("The `strict` option requires a finite `intervalCap`")},wr=class extends EventTarget{#t;#e;#i=0;#u;#b=!1;#v=!1;#h;#x=0;#f;#d;#c;#o=[];#a=0;#r;#A;#n=0;#E;#l;#z=1n;#B=new Set;#y=new Map;#p=new Set;#I;constructor(t){super(),globalThis.process?.getBuiltinModule?.("node:events")?.setMaxListeners(1/0,this);let{carryoverIntervalCount:r=!1,intervalCap:n=1/0,interval:s=0,concurrency:i=1/0,autoStart:o=!0,queueClass:a=qe,strict:c=!1,timeout:u}=t??{};sl(s,n,c),this.#t=r,this.#e=n===1/0||s===0,this.#u=n,this.#h=s,this.#c=c,this.#A=a,this.#r=new this.#A,this.concurrency=i,this.timeout=u,this.#l=!o,this.#$()}#T(t,r){let n=this.#y.get(t);if(!n){let i=new Set,o=()=>{this.#y.delete(t);for(let a of i)a()};n={callbacks:i,dispatch:o},this.#y.set(t,n),t.addEventListener("abort",o,{once:!0})}let s=n;return s.callbacks.add(r),()=>{s.callbacks.delete(r),!(s.callbacks.size>0||this.#y.get(t)!==s)&&(this.#y.delete(t),t.removeEventListener("abort",s.dispatch))}}#s(t,r){this.dispatchEvent(new CustomEvent(t,{detail:r}))}async#m(t,r){let n=Array.isArray(t)?t:[t];return new Promise(s=>{let i=new AbortController,o=()=>{r&&!r()||(i.abort(),s())};for(let a of n)this.addEventListener(a,o,{signal:i.signal})})}get#D(){if(this.#e||this.#r.size===0)return!1;let t=Date.now();return this.#c?(this.#R(t),this.#_()>=this.#u):(this.#f===void 0&&this.#x<=t?this.#L:this.#i)>=this.#u}get#L(){return this.#t?this.#n:0}#S(){let t=this.#D;t!==this.#b&&(this.#b=t,this.#s(t?"rateLimit":"rateLimitCleared"))}#H(){this.#e||(this.#j(),this.#g())}#g(){this.#e||this.#v||(this.#v=!0,queueMicrotask(()=>{this.#v=!1,this.#S()}))}#$(){this.#e||(this.addEventListener("add",()=>{this.#r.size>0&&this.#g()}),this.addEventListener("next",()=>{this.#g()}))}#R(t){for(;this.#a<this.#o.length;){let n=this.#o[this.#a];if(n!==void 0&&t-n>=this.#h)this.#a++;else break}(this.#a>100&&this.#a>this.#o.length/2||this.#a===this.#o.length)&&(this.#o=this.#o.slice(this.#a),this.#a=0)}#V(t){this.#c?this.#o.push(t):this.#i++}#j(){if(this.#c){this.#o.length>this.#a&&this.#o.pop();return}this.#i>0&&this.#i--}#_(){return this.#o.length-this.#a}get#C(){return this.#e?!0:(this.#c?this.#_():this.#i)<this.#u}get#Z(){return this.#n<this.#E}#Y(){this.#n--,this.#n===0&&this.#s("pendingZero"),this.#w(),this.#s("next")}#G(){this.#d=void 0,this.#U(),this.#l||this.#M()}#P(t){if(this.#c){if(this.#R(t),this.#_()>=this.#u){let n=this.#o[this.#a],s=this.#h-(t-n);return this.#O(s),!0}return!1}if(this.#f===void 0){let r=this.#x-t;if(r<=0)this.#i=this.#L;else return this.#O(r),!0}return!1}#O(t){this.#d===void 0&&(this.#d=setTimeout(()=>{this.#G()},t))}#k(){this.#f!==void 0&&(clearInterval(this.#f),this.#f=void 0)}#N(){this.#d!==void 0&&(clearTimeout(this.#d),this.#d=void 0)}#K(){this.#k(),this.#s("empty"),!(this.#n>0||this.#r.size>0)&&(this.#N(),this.#c&&this.#R(Date.now()),this.#s("idle"))}#F(){let t;do t=this.#W();while(t===void 0);return t}#W(){if(this.#r.size===0)return this.#K(),!1;if(this.#l)return this.#C||this.#P(Date.now()),!1;let t=Date.now(),r=!this.#P(t);if(this.#C&&this.#Z){let n=this.#r.dequeue();this.#e||(this.#V(t),this.#g()),r&&this.#M();let s=this.#n;if(n(),this.#n===s){this.#s("next");return}return this.#s("active"),!0}return!1}#M(){this.#e||this.#f!==void 0||this.#c||(this.#N(),this.#f=setInterval(()=>{this.#U()},this.#h),this.#x=Date.now()+this.#h)}#U(){this.#c||(this.#f!==void 0&&(this.#i===0&&this.#n===0?this.#k():this.#x=Date.now()+this.#h),this.#i=this.#L),this.#w(),this.#g()}#w(){for(;this.#F(););}#q(){this.#r.size>0&&this.#w()}async#X(t,r,n){let s=r.id??(this.#z++).toString();if(r={timeout:this.#I,...r,id:s},Ia(r.timeout),r.priority!==void 0&&(typeof r.priority!="number"||Number.isNaN(r.priority)))throw new TypeError(`Expected \`priority\` to be a number, got \`${String(r.priority)}\` (${typeof r.priority})`);return n.id=s,n.priority=r.priority??0,new Promise((i,o)=>{if(r.signal?.aborted){o(r.signal.reason);return}let a=nl(async()=>{if(n.stopListeningForAbort?.(),this.#p.delete(n),r.signal?.aborted){this.#H(),o(r.signal.reason);return}this.#n++;let u={id:s,priority:n.priority,startTime:Date.now(),timeout:r.timeout};this.#B.add(u);let{signal:f}=r,h,l,d;try{if(r.timeout!==void 0){let{signal:E,timeout:w}=r,v=new AbortController;d=setTimeout(()=>{v.abort(new hi(`Task timed out after ${w}ms (queue has ${this.#n} running, ${this.#r.size} waiting)`))},w),E&&(l=this.#T(E,()=>{v.abort(E.reason)})),f=v.signal}let y;if(f){let E=f,w=new Promise((v,m)=>{h=this.#T(E,()=>{m(E.reason)})});y=Promise.race([w,(async()=>t({signal:f}))()])}else try{y=t({signal:f})}catch(E){y=Promise.reject(E)}let g=await y;i(g),this.#s("completed",g)}catch(y){o(y),this.#s("error",y)}finally{clearTimeout(d),h?.(),l?.(),this.#B.delete(u),queueMicrotask(()=>{this.#Y()})}}),c=this.#r.size>0;if(this.#r.enqueue(a,r),n.reject=o,this.#p.add(n),r.signal){let{signal:u}=r;n.stopListeningForAbort=this.#T(u,()=>{this.#p.delete(n),this.#r instanceof qe?this.#r.remove(a):this.#r.remove(s),o(u.reason),this.#w(),this.#s("next")})}this.#s("add"),c?this.#w():this.#F()})}get timeout(){return this.#I}set timeout(t){Ia(t),this.#I=t}get concurrency(){return this.#E}set concurrency(t){Ta("concurrency",t),this.#E=t,this.#q()}setPriority(t,r){if(typeof r!="number"||!Number.isFinite(r))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${r}\` (${typeof r})`);for(let n of this.#p)if(n.id===t){this.#r.setPriority(t,r),n.priority=r;return}throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`)}add(t,r={}){let n={},s=this.#X(t,r,n);return n.promise=s,n.isCleared&&s.catch(()=>{}),s}async addAll(t,r){return Promise.all(t.map(async n=>this.add(n,r)))}start(){return this.#l?(this.#l=!1,this.#q(),this):this}pause(){this.#l=!0}clear(){if(this.#r.size===0)return;this.#r=new this.#A;let t=new DOMException("The queue was cleared","AbortError");for(let r of this.#p)r.stopListeningForAbort?.(),r.isCleared=!0,r.promise?.catch(()=>{}),r.reject(t);this.#p.clear(),this.#K(),this.#S(),this.#s("next")}async onEmpty(){this.#r.size!==0&&await this.#m(["empty","active"],()=>this.#r.size===0)}async onSizeLessThan(t){this.#r.size<t||await this.#m(["next","active"],()=>this.#r.size<t)}async onIdle(){this.#n===0&&this.#r.size===0||await this.#m("idle")}async onPendingZero(){this.#n!==0&&await this.#m("pendingZero")}async onRateLimit(){this.#S(),!this.isRateLimited&&await this.#m("rateLimit")}async onRateLimitCleared(){this.#S(),this.isRateLimited&&await this.#m("rateLimitCleared")}onError(){return new Promise((t,r)=>{this.addEventListener("error",n=>{r(n.detail)},{once:!0})})}get size(){return this.#r.size}sizeBy(t){return this.#r.filter(t).length}get pending(){return this.#n}get isPaused(){return this.#l}get isRateLimited(){return this.#D}get isSaturated(){return this.#r.size>0&&(this.#n>=this.#E||this.isRateLimited)}get runningTasks(){return Array.from(this.#B,t=>({...t,timeoutRemaining:t.timeout===void 0?void 0:Math.max(0,t.startTime+t.timeout-Date.now())}))}},hi=class extends DOMException{constructor(t){super(t,"TimeoutError")}};var dn=class{entries;validityMs;lastPruneTime=0;constructor(t){this.entries=new Map,this.validityMs=t.validityMs}put(t,r){this.entries.set(t,{value:r,validUntilMs:Date.now()+this.validityMs}),this.prune()}prune(){let t=Date.now();if(!(t-this.lastPruneTime<200)){this.lastPruneTime=t;for(let[r,n]of this.entries.entries())if(n.validUntilMs<t)this.entries.delete(r);else break}}has(t){return this.entries.has(t)}get(t){let r=this.entries.get(t);return r!=null&&r.validUntilMs>=Date.now()?r.value:void 0}clear(){this.entries=new Map,this.lastPruneTime=0}};var La={maxSubscriptions:5e3,maxMessages:5e3};function Ra(e){return{subscriptions:e.maxSubscriptions,messages:e.maxMessages}}var ve;(function(e){let t;(function(a){let c;a.codec=()=>(c==null&&(c=oe((l,d,y={})=>{y.lengthDelimited!==!1&&d.fork(),l.subscribe!=null&&(d.uint32(8),d.bool(l.subscribe)),l.topic!=null&&(d.uint32(18),d.string(l.topic)),y.lengthDelimited!==!1&&d.ldelim()},(l,d,y={})=>{let g={},E=d==null?l.len:l.pos+d;for(;l.pos<E;){let w=l.uint32();switch(w>>>3){case 1:{g.subscribe=l.bool();break}case 2:{g.topic=l.string();break}default:{l.skipType(w&7);break}}}return g},function*(l,d,y,g={}){let E=d==null?l.len:l.pos+d;for(;l.pos<E;){let w=l.uint32();switch(w>>>3){case 1:{yield{field:`${y}.subscribe`,value:l.bool()};break}case 2:{yield{field:`${y}.topic`,value:l.string()};break}default:{l.skipType(w&7);break}}}})),c);function u(l){return se(l,a.codec())}a.encode=u;function f(l,d){return ne(l,a.codec(),d)}a.decode=f;function h(l,d){return ie(l,a.codec(),d)}a.stream=h})(t=e.SubOpts||(e.SubOpts={}));let r;(function(a){let c;a.codec=()=>(c==null&&(c=oe((l,d,y={})=>{y.lengthDelimited!==!1&&d.fork(),l.from!=null&&(d.uint32(10),d.bytes(l.from)),l.data!=null&&(d.uint32(18),d.bytes(l.data)),l.sequenceNumber!=null&&(d.uint32(26),d.bytes(l.sequenceNumber)),l.topic!=null&&(d.uint32(34),d.string(l.topic)),l.signature!=null&&(d.uint32(42),d.bytes(l.signature)),l.key!=null&&(d.uint32(50),d.bytes(l.key)),y.lengthDelimited!==!1&&d.ldelim()},(l,d,y={})=>{let g={},E=d==null?l.len:l.pos+d;for(;l.pos<E;){let w=l.uint32();switch(w>>>3){case 1:{g.from=l.bytes();break}case 2:{g.data=l.bytes();break}case 3:{g.sequenceNumber=l.bytes();break}case 4:{g.topic=l.string();break}case 5:{g.signature=l.bytes();break}case 6:{g.key=l.bytes();break}default:{l.skipType(w&7);break}}}return g},function*(l,d,y,g={}){let E=d==null?l.len:l.pos+d;for(;l.pos<E;){let w=l.uint32();switch(w>>>3){case 1:{yield{field:`${y}.from`,value:l.bytes()};break}case 2:{yield{field:`${y}.data`,value:l.bytes()};break}case 3:{yield{field:`${y}.sequenceNumber`,value:l.bytes()};break}case 4:{yield{field:`${y}.topic`,value:l.string()};break}case 5:{yield{field:`${y}.signature`,value:l.bytes()};break}case 6:{yield{field:`${y}.key`,value:l.bytes()};break}default:{l.skipType(w&7);break}}}})),c);function u(l){return se(l,a.codec())}a.encode=u;function f(l,d){return ne(l,a.codec(),d)}a.decode=f;function h(l,d){return ie(l,a.codec(),d)}a.stream=h})(r=e.Message||(e.Message={}));let n;e.codec=()=>(n==null&&(n=oe((a,c,u={})=>{if(u.lengthDelimited!==!1&&c.fork(),a.subscriptions!=null&&a.subscriptions.length>0)for(let f of a.subscriptions)c.uint32(10),e.SubOpts.codec().encode(f,c);if(a.messages!=null&&a.messages.length>0)for(let f of a.messages)c.uint32(18),e.Message.codec().encode(f,c);u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={subscriptions:[],messages:[]},h=c==null?a.len:a.pos+c;for(;a.pos<h;){let l=a.uint32();switch(l>>>3){case 1:{if(u.limits?.subscriptions!=null&&f.subscriptions.length===u.limits.subscriptions)throw new we('Decode error - repeated field "subscriptions" had too many elements');f.subscriptions.push(e.SubOpts.codec().decode(a,a.uint32(),{limits:u.limits?.subscriptions$}));break}case 2:{if(u.limits?.messages!=null&&f.messages.length===u.limits.messages)throw new we('Decode error - repeated field "messages" had too many elements');f.messages.push(e.Message.codec().decode(a,a.uint32(),{limits:u.limits?.messages$}));break}default:{a.skipType(l&7);break}}}return f},function*(a,c,u,f={}){let h={subscriptions:0,messages:0},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();switch(d>>>3){case 1:{if(f.limits?.subscriptions!=null&&h.subscriptions===f.limits.subscriptions)throw new we('Streaming decode error - repeated field "subscriptions" had too many elements');for(let y of e.SubOpts.codec().stream(a,a.uint32(),`${u}.subscriptions[]`,{limits:f.limits?.subscriptions$}))yield{...y,index:h.subscriptions};h.subscriptions++;break}case 2:{if(f.limits?.messages!=null&&h.messages===f.limits.messages)throw new we('Streaming decode error - repeated field "messages" had too many elements');for(let y of e.Message.codec().stream(a,a.uint32(),`${u}.messages[]`,{limits:f.limits?.messages$}))yield{...y,index:h.messages};h.messages++;break}default:{a.skipType(d&7);break}}}})),n);function s(a){return se(a,e.codec())}e.encode=s;function i(a,c){return ne(a,e.codec(),c)}e.decode=i;function o(a,c){return ie(a,e.codec(),c)}e.stream=o})(ve||(ve={}));var pn=class extends Ae{peerId;shutDownController;inboundPb;outboundPb;constructor(t){super(),this.peerId=t,this.shutDownController=new AbortController}attachInboundStream(t,r,n){this.inboundPb=fi(t,r).pb(ve),Promise.resolve().then(async()=>{for(;;){if(this.inboundPb==null)return;let s=await this.inboundPb.read({signal:this.shutDownController.signal,limits:n});this.safeDispatchEvent("message",{detail:s})}}).catch(s=>{this.inboundPb?.unwrap().unwrap().abort(s),this.close()})}attachOutboundStream(t,r){this.outboundPb=fi(t,r).pb(ve)}write(t){this.outboundPb!=null&&this.outboundPb.write(t,{signal:this.shutDownController.signal}).catch(r=>{this.outboundPb?.unwrap().unwrap().abort(r)})}close(){this.shutDownController.abort(),Promise.all([this.inboundPb?.unwrap().unwrap().close().catch(t=>{this.inboundPb?.unwrap().unwrap().abort(t)}),this.outboundPb?.unwrap().unwrap().close().catch(t=>{this.inboundPb?.unwrap().unwrap().abort(t)})]).finally(()=>{this.safeDispatchEvent("close")})}};function _a(){return BigInt(`0x${Z(crypto.getRandomValues(new Uint8Array(8)),"base16")}`)}var Da=(e,t)=>{let r=Y(t.toString(16).padStart(16,"0"),"base16"),n=Ft(e),s=new Uint8Array(n.byteLength+r.length);return s.set(n,0),s.set(r,n.byteLength),s},Ca=e=>fe.encode(e);var il=async e=>{if(e.sequenceNumber==null||e.from==null||e.signature==null)return!1;let t=br(Vt(e.from));if(t.publicKey!=null)return!0;if(e.key!=null){let r=e.key;return ri(cn(r)).equals(t)}return!1},Pa=async e=>{if(e.from==null)throw new ct("RPC message was missing from");if(!await il(e))return{type:"unsigned",topic:e.topic??"",data:e.data??new Uint8Array(0)};let t=br(Vt(e.from)),r=e.key??t.publicKey;if(r==null)throw new ct("RPC message was missing public key");return{type:"signed",from:t,topic:e.topic??"",sequenceNumber:al(e.sequenceNumber??new Uint8Array(0)),data:e.data??new Uint8Array(0),signature:e.signature??new Uint8Array(0),key:r instanceof Uint8Array?cn(r):r}},xr=e=>e.type==="signed"?{from:e.from.toMultihash().bytes,data:e.data,sequenceNumber:ol(e.sequenceNumber),topic:e.topic,signature:e.signature,key:e.key?Ft(e.key):void 0}:{data:e.data,topic:e.topic},ol=e=>{let t=e.toString(16);return t.length%2!==0&&(t=`0${t}`),Y(t,"base16")},al=e=>BigInt(`0x${Z(e,"base16")}`);var Oa=Y("libp2p-pubsub:");async function ka(e,t,r){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:Ea(e)},s=ue([Oa,r(xr(n)).subarray()]);return n.signature=await e.sign(s),n.key=e.publicKey,n}async function Na(e,t){if(e.type!=="signed")throw new Error('Message type must be "signed" to be verified');if(e.signature==null)throw new Error("Message must contain a signature to be verified");if(e.from==null)throw new Error("Message must contain a from property to be verified");let r=ue([Oa,t({...xr(e),signature:void 0,key:void 0}).subarray()]),n;try{n=await wa(e.from,e.key)}catch(s){if(s.name==="InvalidPublicKeyError")return!1;throw s}return n.verify(r,e.signature)}var mn=class extends Ae{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;protocol;components;_registrarTopologyId;maxInboundStreams;maxOutboundStreams;seenCache;decodeRpcLimits;constructor(t,r){super(),this.log=t.logger.forComponent("libp2p:floodsub"),this.components=t,this.protocol=r.protocol??di,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new yr,this.globalSignaturePolicy=r.globalSignaturePolicy==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=r.canRelayMessage??!0,this.emitSelf=r.emitSelf??!1,this.topicValidators=new Map,this.queue=new wr({concurrency:r.messageProcessingConcurrency??10}),this.maxInboundStreams=r.maxInboundStreams??1,this.maxOutboundStreams=r.maxOutboundStreams??1,this.seenCache=new dn({validityMs:r?.seenTTL??3e4}),this.decodeRpcLimits=Ra(r.decodeRpcLimits??La),this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}[$e]=!0;[Symbol.toStringTag]="@libp2p/floodsub";[bi]=["@libp2p/pubsub"];[yi]=["@libp2p/identify"];async start(){this.started||(this.log("starting"),await this.components.registrar.handle(this.protocol,this._onIncomingStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this._registrarTopologyId=await this.components.registrar.register(this.protocol,{onConnect:this._onPeerConnected,onDisconnect:this._onPeerDisconnected}),this.log("started"),this.started=!0)}async stop(){if(!this.started)return;let t=this.components.registrar;this._registrarTopologyId!=null&&t.unregister(this._registrarTopologyId),await t.unhandle(this.protocol),this.log("stopping");for(let r of this.peers.values())r.close();this.peers.clear(),this.topics.clear(),this.subscriptions=new Set,this.started=!1,this.log("stopped")}isStarted(){return this.started}_onIncomingStream(t,r){this.addPeer(r.remotePeer,t).attachInboundStream(t,void 0,this.decodeRpcLimits)}async _onPeerConnected(t,r){if(this.log("connected %p",t),r.streams.find(i=>i.direction==="outbound"&&i.protocol===this.protocol)){this.log("outbound pubsub stream already present on connection from %p",t);return}let n=await r.newStream(this.protocol);this.addPeer(t,n).attachOutboundStream(n),this.send(t,{subscriptions:Array.from(this.subscriptions).map(i=>i.toString()),subscribe:!0})}_onPeerDisconnected(t,r){this.log("connection ended %p",t),this._removePeer(t)}addPeer(t,r){let n=this.peers.get(t);if(n!=null)return n;this.log("new peer %p",t);let s=new pn(t);return this.peers.set(t,s),s.addEventListener("message",i=>{let o=i.detail,a=[];for(let c of o.messages??[]){if(c.from==null||c.data==null||c.topic==null){this.log("message from %p was missing from, data or topic fields, dropping",t);continue}a.push({from:c.from,data:c.data,topic:c.topic,sequenceNumber:c.sequenceNumber??void 0,signature:c.signature??void 0,key:c.key??void 0})}this.processRpc(s,{subscriptions:(o.subscriptions??[]).map(c=>({subscribe:!!c.subscribe,topic:c.topic??""})),messages:a}).catch(c=>{this.log(c)})}),s.addEventListener("close",()=>this._removePeer(t),{once:!0}),s}_removePeer(t){let r=this.peers.get(t);if(r!=null){r.close(),this.log("delete peer %p",t),this.peers.delete(t);for(let[n,s]of this.topics)s.delete(t),s.size===0&&this.topics.delete(n)}}async processRpc(t,r){this.log("rpc from %p",t.peerId);let{subscriptions:n,messages:s}=r;return n!=null&&n.length>0&&(this.log("subscription update from %p",t.peerId),n.forEach(i=>{this.processRpcSubOpt(t.peerId,i)}),super.dispatchEvent(new CustomEvent("subscription-change",{detail:{peerId:t.peerId,subscriptions:n.map(({topic:i,subscribe:o})=>({topic:`${i??""}`,subscribe:!!o}))}}))),s!=null&&s.length>0&&(this.log("messages from %p",t.peerId),this.queue.addAll(s.map(i=>async()=>{if(i.topic==null||!this.subscriptions.has(i.topic)&&!this.canRelayMessage)return this.log("received message we didn't subscribe to. Dropping."),!1;try{let o=await Pa(i);await this.processMessage(t.peerId,o)}catch(o){this.log.error("failed to queue messages from %p - %e",t.peerId,o)}})).catch(i=>{this.log(i)})),!0}processRpcSubOpt(t,r){let n=r.topic;if(n==null)return;let s=this.topics.get(n);r.subscribe===!0?(s==null&&(s=new gr,this.topics.set(n,s)),s.add(t)):s!=null&&(s.delete(t),s.size===0&&this.topics.delete(n))}async processMessage(t,r){if(this.components.peerId.equals(t)&&!this.emitSelf)return;let n=await this.getMsgId(r),s=Z(n,"base64");if(!this.seenCache.has(s)){this.seenCache.put(s,!0);try{await this.validate(t,r)}catch(i){this.log("Message is invalid, dropping it. %O",i);return}this.subscriptions.has(r.topic)&&(!this.components.peerId.equals(t)||this.emitSelf)&&super.dispatchEvent(new CustomEvent("message",{detail:r})),await this.publishMessage(t,r)}}getMsgId(t){switch(this.globalSignaturePolicy){case"StrictSign":if(t.type!=="signed")throw new ct('Message type should be "signed" when signature policy is StrictSign but it was not');if(t.sequenceNumber==null)throw new ct("Need sequence number when signature policy is StrictSign but it was missing");if(t.key==null)throw new ct("Need key when signature policy is StrictSign but it was missing");return Da(t.key,t.sequenceNumber);case"StrictNoSign":return Ca(t.data);default:throw new ct("Cannot get message id: unhandled signature policy")}}encodeMessage(t){return ve.Message.encode(t)}send(t,r){let{messages:n,subscriptions:s,subscribe:i}=r;this.sendRpc(t,{subscriptions:(s??[]).map(o=>({topic:o,subscribe:!!i})),messages:(n??[]).map(xr)})}sendRpc(t,r){let n=this.peers.get(t);if(n==null){this.log.error("cannot send RPC to %p as there are no streams to it available",t);return}n.write(r)}async validate(t,r){switch(this.globalSignaturePolicy){case"StrictNoSign":if(r.type!=="unsigned")throw new ct('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(r.signature!=null)throw new ct("StrictNoSigning: signature should not be present");if(r.key!=null)throw new ct("StrictNoSigning: key should not be present");if(r.sequenceNumber!=null)throw new ct("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(r.type!=="signed")throw new ct('Message type should be "signed" when signature policy is StrictSign but it was not');if(r.signature==null)throw new ct("StrictSigning: Signing required and no signature was present");if(r.sequenceNumber==null)throw new ct("StrictSigning: Signing required and no sequenceNumber was present");if(!await Na(r,this.encodeMessage.bind(this)))throw new ct("StrictSigning: Invalid message signature");break;default:throw new ct("Cannot validate message: unhandled signature policy")}let s=this.topicValidators.get(r.topic);if(s!=null){let i=await s(t,r);if(i===ze.Reject||i===ze.Ignore)throw new ct("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return ka(this.components.privateKey,t,this.encodeMessage.bind(this));case"StrictNoSign":return Promise.resolve({type:"unsigned",...t});default:throw new ct("Cannot build message: unhandled signature policy")}}getSubscribers(t){if(!this.started)throw new vr("not started yet");if(t==null)throw new et("Topic is required");let r=this.topics.get(t.toString());return r==null?[]:Array.from(r.values())}async publish(t,r){if(!this.started)throw new Error("Pubsub has not started");let n={from:this.components.peerId,topic:t,data:r??new Uint8Array(0),sequenceNumber:_a()};this.log("publish topic: %s from: %p data: %m",t,n.from,n.data);let s=await this.buildMessage(n),i=!1;this.emitSelf&&this.subscriptions.has(t)&&(i=!0,super.dispatchEvent(new CustomEvent("message",{detail:s})));let o=await this.publishMessage(this.components.peerId,s);return i&&(o.recipients=[...o.recipients,this.components.peerId]),o}async publishMessage(t,r){let n=this.getSubscribers(r.topic),s=[];return n==null||n.length===0?(this.log("no peers are subscribed to topic %s",r.topic),{recipients:s}):(n.forEach(i=>{if(this.components.peerId.equals(i)){this.log("not sending message on topic %s to myself",r.topic);return}if(i.equals(t)){this.log("not sending message on topic %s to sender %p",r.topic,i);return}this.log("publish msgs on topics %s %p",r.topic,i),s.push(i),this.send(i,{messages:[r]})}),{recipients:s})}subscribe(t){if(!this.started)throw new Error("Pubsub has not started");if(!this.subscriptions.has(t)){this.log("subscribe to topic: %s",t),this.subscriptions.add(t);for(let r of this.peers.keys())this.send(r,{subscriptions:[t],subscribe:!0})}}unsubscribe(t){if(!this.started)throw new Error("Pubsub is not started");if(this.subscriptions.has(t)){this.log("unsubscribe from %s",t),this.subscriptions.delete(t);for(let r of this.peers.keys())this.send(r,{subscriptions:[t],subscribe:!1})}}getTopics(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.subscriptions)}getPeers(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.peers.keys())}};var di="/floodsub/1.0.0",cl="StrictSign",ul="StrictNoSign",ze;(function(e){e.Accept="accept",e.Ignore="ignore",e.Reject="reject"})(ze||(ze={}));function fl(e){return!!e?.[$e]}function ll(e={}){return t=>new mn(t,e)}return $a(hl);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/curves/utils.js:
|