@libp2p/pubsub 10.1.11 → 10.1.12
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 +1 -1
- package/dist/src/sign.d.ts.map +1 -1
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +0 -1
- package/dist/src/utils.js.map +1 -1
- package/dist/typedoc-urls.json +8 -8
- package/package.json +13 -20
- package/src/index.ts +1 -1
- package/src/utils.ts +1 -1
package/dist/index.min.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PPubsub = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
2
|
-
"use strict";var Libp2PPubsub=(()=>{var wa=Object.create;var Er=Object.defineProperty;var Ea=Object.getOwnPropertyDescriptor;var Sa=Object.getOwnPropertyNames;var va=Object.getPrototypeOf,Aa=Object.prototype.hasOwnProperty;var Ia=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),xt=(r,t)=>{for(var e in t)Er(r,e,{get:t[e],enumerable:!0})},rs=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Sa(t))!Aa.call(r,o)&&o!==e&&Er(r,o,{get:()=>t[o],enumerable:!(n=Ea(t,o))||n.enumerable});return r};var Ba=(r,t,e)=>(e=r!=null?wa(va(r)):{},rs(t||!r||!r.__esModule?Er(e,"default",{value:r,enumerable:!0}):e,r)),_a=r=>rs(Er({},"__esModule",{value:!0}),r);var ea=Ia((z0,Yo)=>{"use strict";var cf=Object.prototype.hasOwnProperty,bt="~";function pr(){}Object.create&&(pr.prototype=Object.create(null),new pr().__proto__||(bt=!1));function uf(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function ta(r,t,e,n,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var s=new uf(e,n||r,o),i=bt?bt+t:t;return r._events[i]?r._events[i].fn?r._events[i]=[r._events[i],s]:r._events[i].push(s):(r._events[i]=s,r._eventsCount++),r}function en(r,t){--r._eventsCount===0?r._events=new pr:delete r._events[t]}function pt(){this._events=new pr,this._eventsCount=0}pt.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)cf.call(e,n)&&t.push(bt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};pt.prototype.listeners=function(t){var e=bt?bt+t:t,n=this._events[e];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,s=n.length,i=new Array(s);o<s;o++)i[o]=n[o].fn;return i};pt.prototype.listenerCount=function(t){var e=bt?bt+t:t,n=this._events[e];return n?n.fn?1:n.length:0};pt.prototype.emit=function(t,e,n,o,s,i){var c=bt?bt+t:t;if(!this._events[c])return!1;var a=this._events[c],l=arguments.length,u,f;if(a.fn){switch(a.once&&this.removeListener(t,a.fn,void 0,!0),l){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,e),!0;case 3:return a.fn.call(a.context,e,n),!0;case 4:return a.fn.call(a.context,e,n,o),!0;case 5:return a.fn.call(a.context,e,n,o,s),!0;case 6:return a.fn.call(a.context,e,n,o,s,i),!0}for(f=1,u=new Array(l-1);f<l;f++)u[f-1]=arguments[f];a.fn.apply(a.context,u)}else{var b=a.length,v;for(f=0;f<b;f++)switch(a[f].once&&this.removeListener(t,a[f].fn,void 0,!0),l){case 1:a[f].fn.call(a[f].context);break;case 2:a[f].fn.call(a[f].context,e);break;case 3:a[f].fn.call(a[f].context,e,n);break;case 4:a[f].fn.call(a[f].context,e,n,o);break;default:if(!u)for(v=1,u=new Array(l-1);v<l;v++)u[v-1]=arguments[v];a[f].fn.apply(a[f].context,u)}}return!0};pt.prototype.on=function(t,e,n){return ta(this,t,e,n,!1)};pt.prototype.once=function(t,e,n){return ta(this,t,e,n,!0)};pt.prototype.removeListener=function(t,e,n,o){var s=bt?bt+t:t;if(!this._events[s])return this;if(!e)return en(this,s),this;var i=this._events[s];if(i.fn)i.fn===e&&(!o||i.once)&&(!n||i.context===n)&&en(this,s);else{for(var c=0,a=[],l=i.length;c<l;c++)(i[c].fn!==e||o&&!i[c].once||n&&i[c].context!==n)&&a.push(i[c]);a.length?this._events[s]=a.length===1?a[0]:a:en(this,s)}return this};pt.prototype.removeAllListeners=function(t){var e;return t?(e=bt?bt+t:t,this._events[e]&&en(this,e)):(this._events=new pr,this._eventsCount=0),this};pt.prototype.off=pt.prototype.removeListener;pt.prototype.addListener=pt.prototype.on;pt.prefixed=bt;pt.EventEmitter=pt;typeof Yo<"u"&&(Yo.exports=pt)});var yf={};xt(yf,{PubSubBaseProtocol:()=>ts});var fn=Symbol.for("@libp2p/peer-id");var He;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(He||(He={}));var xf=Symbol.for("@libp2p/pubsub");var W=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},we=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Sr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Q=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 se=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Ee=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==e),this.#t.set(t,o))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var mn={};xt(mn,{base58btc:()=>X,base58flickr:()=>Ra});var vf=new Uint8Array(0);function ns(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Ut(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function os(r){return new TextEncoder().encode(r)}function ss(r){return new TextDecoder().decode(r)}function La(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var c=r.length,a=r.charAt(0),l=Math.log(c)/Math.log(256),u=Math.log(256)/Math.log(c);function f(I){if(I instanceof Uint8Array||(ArrayBuffer.isView(I)?I=new Uint8Array(I.buffer,I.byteOffset,I.byteLength):Array.isArray(I)&&(I=Uint8Array.from(I))),!(I instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(I.length===0)return"";for(var m=0,A=0,P=0,M=I.length;P!==M&&I[P]===0;)P++,m++;for(var x=(M-P)*u+1>>>0,h=new Uint8Array(x);P!==M;){for(var y=I[P],B=0,_=x-1;(y!==0||B<A)&&_!==-1;_--,B++)y+=256*h[_]>>>0,h[_]=y%c>>>0,y=y/c>>>0;if(y!==0)throw new Error("Non-zero carry");A=B,P++}for(var L=x-A;L!==x&&h[L]===0;)L++;for(var N=a.repeat(m);L<x;++L)N+=r.charAt(h[L]);return N}function b(I){if(typeof I!="string")throw new TypeError("Expected String");if(I.length===0)return new Uint8Array;var m=0;if(I[m]!==" "){for(var A=0,P=0;I[m]===a;)A++,m++;for(var M=(I.length-m)*l+1>>>0,x=new Uint8Array(M);I[m];){var h=e[I.charCodeAt(m)];if(h===255)return;for(var y=0,B=M-1;(h!==0||y<P)&&B!==-1;B--,y++)h+=c*x[B]>>>0,x[B]=h%256>>>0,h=h/256>>>0;if(h!==0)throw new Error("Non-zero carry");P=y,m++}if(I[m]!==" "){for(var _=M-P;_!==M&&x[_]===0;)_++;for(var L=new Uint8Array(A+(M-_)),N=A;_!==M;)L[N++]=x[_++];return L}}}function v(I){var m=b(I);if(m)return m;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:b,decode:v}}var Ta=La,Pa=Ta,as=Pa;var ln=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},hn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return cs(this,t)}},dn=class{decoders;constructor(t){this.decoders=t}or(t){return cs(this,t)}decode(t){let e=t[0],n=this.decoders[e];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 cs(r,t){return new dn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var pn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new ln(t,e,n),this.decoder=new hn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Se({name:r,prefix:t,encode:e,decode:n}){return new pn(r,t,e,n)}function Yt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=as(e,r);return Se({prefix:t,name:r,encode:n,decode:s=>Ut(o(s))})}function Ca(r,t,e,n){let o={};for(let u=0;u<t.length;++u)o[t[u]]=u;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*e/8|0),c=0,a=0,l=0;for(let u=0;u<s;++u){let f=o[r[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|f,c+=e,c>=8&&(c-=8,i[l++]=255&a>>c)}if(c>=e||(255&a<<8-c)!==0)throw new SyntaxError("Unexpected end of data");return i}function Da(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,c=0;for(let a=0;a<r.length;++a)for(c=c<<8|r[a],i+=8;i>e;)i-=e,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function $({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return Se({prefix:t,name:r,encode(o){return Da(o,n,e)},decode(o){return Ca(o,n,e,r)}})}var X=Yt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ra=Yt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var yn={};xt(yn,{base32:()=>ve,base32hex:()=>ka,base32hexpad:()=>Ma,base32hexpadupper:()=>qa,base32hexupper:()=>Oa,base32pad:()=>Ua,base32padupper:()=>Ka,base32upper:()=>Na,base32z:()=>Ha});var ve=$({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Na=$({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ua=$({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ka=$({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ka=$({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Oa=$({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ma=$({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),qa=$({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ha=$({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var bn={};xt(bn,{base36:()=>Ve,base36upper:()=>Va});var Ve=Yt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Va=Yt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var za=ls,us=128,Fa=127,Ga=~Fa,ja=Math.pow(2,31);function ls(r,t,e){t=t||[],e=e||0;for(var n=e;r>=ja;)t[e++]=r&255|us,r/=128;for(;r&Ga;)t[e++]=r&255|us,r>>>=7;return t[e]=r|0,ls.bytes=e-n+1,t}var Za=gn,Ya=128,fs=127;function gn(r,n){var e=0,n=n||0,o=0,s=n,i,c=r.length;do{if(s>=c)throw gn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&fs)<<o:(i&fs)*Math.pow(2,o),o+=7}while(i>=Ya);return gn.bytes=s-n,e}var Wa=Math.pow(2,7),Xa=Math.pow(2,14),$a=Math.pow(2,21),Ja=Math.pow(2,28),Qa=Math.pow(2,35),tc=Math.pow(2,42),ec=Math.pow(2,49),rc=Math.pow(2,56),nc=Math.pow(2,63),oc=function(r){return r<Wa?1:r<Xa?2:r<$a?3:r<Ja?4:r<Qa?5:r<tc?6:r<ec?7:r<rc?8:r<nc?9:10},sc={encode:za,decode:Za,encodingLength:oc},ic=sc,ze=ic;function Fe(r,t=0){return[ze.decode(r,t),ze.decode.bytes]}function Ae(r,t,e=0){return ze.encode(r,t,e),t}function Ie(r){return ze.encodingLength(r)}function Bt(r,t){let e=t.byteLength,n=Ie(r),o=n+Ie(e),s=new Uint8Array(o+e);return Ae(r,s,0),Ae(e,s,n),s.set(t,o),new Be(r,e,t,s)}function Wt(r){let t=Ut(r),[e,n]=Fe(t),[o,s]=Fe(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Be(e,o,i,t)}function hs(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ns(r.bytes,e.bytes)}}var Be=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function ds(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return cc(e,xn(r),t??X.encoder);default:return uc(e,xn(r),t??ve.encoder)}}var ps=new WeakMap;function xn(r){let t=ps.get(r);if(t==null){let e=new Map;return ps.set(r,e),e}return t}var ft=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==Ge)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==fc)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}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:e}=this.multihash,n=Bt(t,e);return r.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 r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&hs(t.multihash,n.multihash)}toString(t){return ds(this,t)}toJSON(){return{"/":ds(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 e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??ms(n,o,s.bytes))}else if(e[lc]===!0){let{version:n,multihash:o,code:s}=e,i=Wt(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="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(e!==Ge)throw new Error(`Version 0 CID must use dag-pb (code: ${Ge}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=ms(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Ge,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Ut(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new Be(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[f,b]=Fe(t.subarray(e));return e+=b,f},o=n(),s=Ge;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,c=n(),a=n(),l=e+a,u=l-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:u,size:l}}static parse(t,e){let[n,o]=ac(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return xn(s).set(n,t),s}};function ac(r,t){switch(r[0]){case"Q":{let e=t??X;return[X.prefix,e.decode(`${X.prefix}${r}`)]}case X.prefix:{let e=t??X;return[X.prefix,e.decode(r)]}case ve.prefix:{let e=t??ve;return[ve.prefix,e.decode(r)]}case Ve.prefix:{let e=t??Ve;return[Ve.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function cc(r,t,e){let{prefix:n}=e;if(n!==X.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function uc(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var Ge=112,fc=18;function ms(r,t,e){let n=Ie(r),o=n+Ie(t),s=new Uint8Array(o+e.byteLength);return Ae(r,s,0),Ae(t,s,n),s.set(e,o),s}var lc=Symbol.for("@ipld/js-cid/CID");var wn={};xt(wn,{identity:()=>_t});var ys=0,hc="identity",bs=Ut;function dc(r){return Bt(ys,bs(r))}var _t={code:ys,name:hc,encode:bs,digest:dc};function wt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Kt(r=0){return new Uint8Array(r)}function lt(r=0){return new Uint8Array(r)}function ie(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=lt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var xs=Symbol.for("@achingbrain/uint8arraylist");function gs(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function Ir(r){return!!r?.[xs]}var nt=class r{bufs;length;[xs]=!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 e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Ir(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Ir(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=gs(this.bufs,t);return e.buf[e.index]}set(t,e){let n=gs(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Ir(t))for(let n=0;n<t.length;n++)this.set(e+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,e){let{bufs:n,length:o}=this._subList(t,e);return ie(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:ie(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let l=t>=c&&t<a,u=e>c&&e<=a;if(l&&u){if(t===c&&e===a){n.push(i);break}let f=t-c;n.push(i.subarray(f,f+(e-t)));break}if(l){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(u){if(e===a){n.push(i);break}n.push(i.subarray(0,e-c));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Ir(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(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let c=i,a=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let f=e;f<=a;f+=u){u=0;for(let b=l;b>=0;b--){let v=this.get(f+b);if(n[b]!==v){u=Math.max(1,b-c[v]);break}}if(u===0)return f}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=lt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=Kt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=Kt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=Kt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=lt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=Kt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=Kt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=Kt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=Kt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=Kt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!wt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var En={};xt(En,{base10:()=>pc});var pc=Yt({prefix:"9",name:"base10",alphabet:"0123456789"});var Sn={};xt(Sn,{base16:()=>mc,base16upper:()=>yc});var mc=$({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),yc=$({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var vn={};xt(vn,{base2:()=>bc});var bc=$({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var An={};xt(An,{base256emoji:()=>Sc});var ws=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}"),gc=ws.reduce((r,t,e)=>(r[e]=t,r),[]),xc=ws.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function wc(r){return r.reduce((t,e)=>(t+=gc[e],t),"")}function Ec(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=xc[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Sc=Se({prefix:"\u{1F680}",name:"base256emoji",encode:wc,decode:Ec});var In={};xt(In,{base64:()=>vc,base64pad:()=>Ac,base64url:()=>Ic,base64urlpad:()=>Bc});var vc=$({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ac=$({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ic=$({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Bc=$({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Bn={};xt(Bn,{base8:()=>_c});var _c=$({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var _n={};xt(_n,{identity:()=>Lc});var Lc=Se({prefix:"\0",name:"identity",encode:r=>ss(r),decode:r=>os(r)});var il=new TextEncoder,al=new TextDecoder;var Pn={};xt(Pn,{sha256:()=>ae,sha512:()=>Cc});function Tn({name:r,code:t,encode:e}){return new Ln(r,t,e)}var Ln=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?Bt(this.code,e):e.then(n=>Bt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Ss(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var ae=Tn({name:"sha2-256",code:18,encode:Ss("SHA-256")}),Cc=Tn({name:"sha2-512",code:19,encode:Ss("SHA-512")});var Cn={..._n,...vn,...Bn,...En,...Sn,...yn,...bn,...mn,...In,...An},xl={...Pn,...wn};function As(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var vs=As("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Dn=As("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=lt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Dc={utf8:vs,"utf-8":vs,hex:Cn.base16,latin1:Dn,ascii:Dn,binary:Dn,...Cn},Br=Dc;function G(r,t="utf8"){let e=Br[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function j(r,t="utf8"){let e=Br[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Rc=parseInt("11111",2),Rn=parseInt("10000000",2),Nc=parseInt("01111111",2),Is={0:je,1:je,2:Uc,3:Oc,4:Mc,5:kc,6:Kc,16:je,22:je,48:je};function kt(r,t={offset:0}){let e=r[t.offset]&Rc;if(t.offset++,Is[e]!=null)return Is[e](r,t);throw new Error("No decoder for tag "+e)}function Ze(r,t){let e=0;if((r[t.offset]&Rn)===Rn){let n=r[t.offset]&Nc,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function je(r,t){Ze(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=kt(r,t);if(n===null)break;e.push(n)}return e}function Uc(r,t){let e=Ze(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function Kc(r,t){let e=Ze(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let c=`${s}.${i}`,a=[];for(;t.offset<n;){let l=r[t.offset];if(t.offset++,a.push(l&127),l<128){a.reverse();let u=0;for(let f=0;f<a.length;f++)u+=a[f]<<f*7;c+=`.${u}`,a=[]}}return c}function kc(r,t){return t.offset++,null}function Oc(r,t){let e=Ze(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Mc(r,t){let e=Ze(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function qc(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new nt;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Nn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=qc(r.byteLength);return new nt(Uint8Array.from([t.byteLength|Rn]),t)}function Et(r){let t=new nt,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new nt(Uint8Array.from([2]),Nn(t),t)}function _r(r){let t=Uint8Array.from([0]),e=new nt(t,r);return new nt(Uint8Array.from([3]),Nn(e),e)}function $t(r,t=48){let e=new nt;for(let n of r)e.append(n);return new nt(Uint8Array.from([t]),Nn(e),e)}async function Bs(r,t,e){let n=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);return crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},n,t,e.subarray())}var Hc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Vc=Uint8Array.from([6,5,43,129,4,0,34]),zc=Uint8Array.from([6,5,43,129,4,0,35]),Fc={ext:!0,kty:"EC",crv:"P-256"},Gc={ext:!0,kty:"EC",crv:"P-384"},jc={ext:!0,kty:"EC",crv:"P-521"},Un=32,Kn=48,kn=66;function On(r){let t=kt(r);return _s(t)}function _s(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===Un*2+1)return n=j(t.subarray(e,e+Un),"base64url"),o=j(t.subarray(e+Un),"base64url"),new _e({...Fc,key_ops:["verify"],x:n,y:o});if(t.byteLength===Kn*2+1)return n=j(t.subarray(e,e+Kn),"base64url"),o=j(t.subarray(e+Kn),"base64url"),new _e({...Gc,key_ops:["verify"],x:n,y:o});if(t.byteLength===kn*2+1)return n=j(t.subarray(e,e+kn),"base64url"),o=j(t.subarray(e+kn),"base64url"),new _e({...jc,key_ops:["verify"],x:n,y:o});throw new W(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Ls(r){return $t([Et(Uint8Array.from([1])),$t([Zc(r.crv)],160),$t([_r(new nt(Uint8Array.from([4]),G(r.x??"","base64url"),G(r.y??"","base64url")))],161)]).subarray()}function Zc(r){if(r==="P-256")return Hc;if(r==="P-384")return Vc;if(r==="P-521")return zc;throw new W(`Invalid curve ${r}`)}var _e=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Ls(this.jwk)),this._raw}toMultihash(){return _t.digest(Ot(this))}toCID(){return ft.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:wt(this.raw,t.raw)}async verify(t,e){return Bs(this.jwk,e,t)}};var ce=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Yc(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Lr(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function ue(r,...t){if(!Yc(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error("Uint8Array expected of length "+t+", got length="+r.length)}function Ts(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Lr(r.outputLen),Lr(r.blockLen)}function Te(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function Ps(r,t){ue(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}function Mt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Tr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Lt(r,t){return r<<32-t|r>>>t}function Cs(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function Ye(r){return typeof r=="string"&&(r=Cs(r)),ue(r),r}function Mn(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];ue(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}var Le=class{};function qn(r){let t=n=>r().update(Ye(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Pe(r=32){if(ce&&typeof ce.getRandomValues=="function")return ce.getRandomValues(new Uint8Array(r));if(ce&&typeof ce.randomBytes=="function")return Uint8Array.from(ce.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function Wc(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(e>>o&s),c=Number(e&s),a=n?4:0,l=n?0:4;r.setUint32(t+a,i,n),r.setUint32(t+l,c,n)}function Ds(r,t,e){return r&t^~r&e}function Rs(r,t,e){return r&t^r&e^t&e}var We=class extends Le{constructor(t,e,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Tr(this.buffer)}update(t){Te(this),t=Ye(t),ue(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=Tr(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Te(this),Ps(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Mt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)e[f]=0;Wc(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=Tr(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=a/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)c.setUint32(4*f,u[f],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},qt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ct=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Pr=BigInt(4294967295),Ns=BigInt(32);function Xc(r,t=!1){return t?{h:Number(r&Pr),l:Number(r>>Ns&Pr)}:{h:Number(r>>Ns&Pr)|0,l:Number(r&Pr)|0}}function Us(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:c}=Xc(r[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var Hn=(r,t,e)=>r>>>e,Vn=(r,t,e)=>r<<32-e|t>>>e,fe=(r,t,e)=>r>>>e|t<<32-e,le=(r,t,e)=>r<<32-e|t>>>e,Xe=(r,t,e)=>r<<64-e|t>>>e-32,$e=(r,t,e)=>r>>>e-32|t<<64-e;function Ct(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Ks=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),ks=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Os=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Ms=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,qs=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Hs=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Jc=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]),Jt=new Uint32Array(64),Cr=class extends We{constructor(t=32){super(64,t,8,!1),this.A=qt[0]|0,this.B=qt[1]|0,this.C=qt[2]|0,this.D=qt[3]|0,this.E=qt[4]|0,this.F=qt[5]|0,this.G=qt[6]|0,this.H=qt[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,e,n,o,s,i,c,a]}set(t,e,n,o,s,i,c,a){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(t,e){for(let f=0;f<16;f++,e+=4)Jt[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let b=Jt[f-15],v=Jt[f-2],I=Lt(b,7)^Lt(b,18)^b>>>3,m=Lt(v,17)^Lt(v,19)^v>>>10;Jt[f]=m+Jt[f-7]+I+Jt[f-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:l,H:u}=this;for(let f=0;f<64;f++){let b=Lt(c,6)^Lt(c,11)^Lt(c,25),v=u+b+Ds(c,a,l)+Jc[f]+Jt[f]|0,m=(Lt(n,2)^Lt(n,13)^Lt(n,22))+Rs(n,o,s)|0;u=l,l=a,a=c,c=i+v|0,i=s,s=o,o=n,n=v+m|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(n,o,s,i,c,a,l,u)}roundClean(){Mt(Jt)}destroy(){this.set(0,0,0,0,0,0,0,0),Mt(this.buffer)}};var Vs=Us(["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(r=>BigInt(r))),Qc=Vs[0],tu=Vs[1],Qt=new Uint32Array(80),te=new Uint32Array(80),zn=class extends We{constructor(t=64){super(128,t,16,!1),this.Ah=ct[0]|0,this.Al=ct[1]|0,this.Bh=ct[2]|0,this.Bl=ct[3]|0,this.Ch=ct[4]|0,this.Cl=ct[5]|0,this.Dh=ct[6]|0,this.Dl=ct[7]|0,this.Eh=ct[8]|0,this.El=ct[9]|0,this.Fh=ct[10]|0,this.Fl=ct[11]|0,this.Gh=ct[12]|0,this.Gl=ct[13]|0,this.Hh=ct[14]|0,this.Hl=ct[15]|0}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:l,El:u,Fh:f,Fl:b,Gh:v,Gl:I,Hh:m,Hl:A}=this;return[t,e,n,o,s,i,c,a,l,u,f,b,v,I,m,A]}set(t,e,n,o,s,i,c,a,l,u,f,b,v,I,m,A){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=l|0,this.El=u|0,this.Fh=f|0,this.Fl=b|0,this.Gh=v|0,this.Gl=I|0,this.Hh=m|0,this.Hl=A|0}process(t,e){for(let x=0;x<16;x++,e+=4)Qt[x]=t.getUint32(e),te[x]=t.getUint32(e+=4);for(let x=16;x<80;x++){let h=Qt[x-15]|0,y=te[x-15]|0,B=fe(h,y,1)^fe(h,y,8)^Hn(h,y,7),_=le(h,y,1)^le(h,y,8)^Vn(h,y,7),L=Qt[x-2]|0,N=te[x-2]|0,k=fe(L,N,19)^Xe(L,N,61)^Hn(L,N,6),C=le(L,N,19)^$e(L,N,61)^Vn(L,N,6),U=Os(_,C,te[x-7],te[x-16]),R=Ms(U,B,k,Qt[x-7],Qt[x-16]);Qt[x]=R|0,te[x]=U|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:l,Dl:u,Eh:f,El:b,Fh:v,Fl:I,Gh:m,Gl:A,Hh:P,Hl:M}=this;for(let x=0;x<80;x++){let h=fe(f,b,14)^fe(f,b,18)^Xe(f,b,41),y=le(f,b,14)^le(f,b,18)^$e(f,b,41),B=f&v^~f&m,_=b&I^~b&A,L=qs(M,y,_,tu[x],te[x]),N=Hs(L,P,h,B,Qc[x],Qt[x]),k=L|0,C=fe(n,o,28)^Xe(n,o,34)^Xe(n,o,39),U=le(n,o,28)^$e(n,o,34)^$e(n,o,39),R=n&s^n&c^s&c,et=o&i^o&a^i&a;P=m|0,M=A|0,m=v|0,A=I|0,v=f|0,I=b|0,{h:f,l:b}=Ct(l|0,u|0,N|0,k|0),l=c|0,u=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let E=Ks(k,U,et);n=ks(E,N,C,R),o=E|0}({h:n,l:o}=Ct(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ct(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=Ct(this.Ch|0,this.Cl|0,c|0,a|0),{h:l,l:u}=Ct(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:b}=Ct(this.Eh|0,this.El|0,f|0,b|0),{h:v,l:I}=Ct(this.Fh|0,this.Fl|0,v|0,I|0),{h:m,l:A}=Ct(this.Gh|0,this.Gl|0,m|0,A|0),{h:P,l:M}=Ct(this.Hh|0,this.Hl|0,P|0,M|0),this.set(n,o,s,i,c,a,l,u,f,b,v,I,m,A,P,M)}roundClean(){Mt(Qt,te)}destroy(){Mt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Dr=qn(()=>new Cr);var zs=qn(()=>new zn);var Zn=BigInt(0),jn=BigInt(1);function Ce(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Yn(r){if(!Ce(r))throw new Error("Uint8Array expected")}function Dt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function Je(r){let t=r.toString(16);return t.length&1?"0"+t:t}function js(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Zn:BigInt("0x"+r)}var Zs=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",eu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function ee(r){if(Yn(r),Zs)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=eu[r[e]];return t}var Ht={_0:48,_9:57,A:65,F:70,a:97,f:102};function Fs(r){if(r>=Ht._0&&r<=Ht._9)return r-Ht._0;if(r>=Ht.A&&r<=Ht.F)return r-(Ht.A-10);if(r>=Ht.a&&r<=Ht.f)return r-(Ht.a-10)}function Qe(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Zs)return Uint8Array.fromHex(r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=Fs(r.charCodeAt(s)),c=Fs(r.charCodeAt(s+1));if(i===void 0||c===void 0){let a=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function Vt(r){return js(ee(r))}function he(r){return Yn(r),js(ee(Uint8Array.from(r).reverse()))}function de(r,t){return Qe(r.toString(16).padStart(t*2,"0"))}function De(r,t){return de(r,t).reverse()}function Z(r,t,e){let n;if(typeof t=="string")try{n=Qe(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Ce(t))n=Uint8Array.from(t);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(r+" of length "+e+" expected, got "+o);return n}function re(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Yn(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}var Fn=r=>typeof r=="bigint"&&Zn<=r;function Rr(r,t,e){return Fn(r)&&Fn(t)&&Fn(e)&&t<=r&&r<e}function vt(r,t,e,n){if(!Rr(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Ys(r){let t;for(t=0;r>Zn;r>>=jn,t+=1);return t}var pe=r=>(jn<<BigInt(r))-jn,Gn=r=>new Uint8Array(r),Gs=r=>Uint8Array.from(r);function Ws(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=Gn(r),o=Gn(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},c=(...f)=>e(o,n,...f),a=(f=Gn(0))=>{o=c(Gs([0]),f),n=c(),f.length!==0&&(o=c(Gs([1]),f),n=c())},l=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,b=[];for(;f<t;){n=c();let v=n.slice();b.push(v),f+=n.length}return re(...b)};return(f,b)=>{i(),a(f);let v;for(;!(v=b(l()));)a();return i(),v}}var ru={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||Ce(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function zt(r,t,e={}){let n=(o,s,i)=>{let c=ru[s];if(typeof c!="function")throw new Error("invalid validator function");let a=r[o];if(!(i&&a===void 0)&&!c(a,r))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+a)};for(let[o,s]of Object.entries(t))n(o,s,!1);for(let[o,s]of Object.entries(e))n(o,s,!0);return r}function Re(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var mt=BigInt(0),st=BigInt(1),me=BigInt(2),nu=BigInt(3),$s=BigInt(4),Js=BigInt(5),Qs=BigInt(8);function F(r,t){let e=r%t;return e>=mt?e:t+e}function Y(r,t,e){let n=r;for(;t-- >mt;)n*=n,n%=e;return n}function Nr(r,t){if(r===mt)throw new Error("invert: expected non-zero number");if(t<=mt)throw new Error("invert: expected positive modulus, got "+t);let e=F(r,t),n=t,o=mt,s=st,i=st,c=mt;for(;e!==mt;){let l=n/e,u=n%e,f=o-i*l,b=s-c*l;n=e,e=u,o=i,s=c,i=f,c=b}if(n!==st)throw new Error("invert: does not exist");return F(o,t)}function ti(r,t){let e=(r.ORDER+st)/$s,n=r.pow(t,e);if(!r.eql(r.sqr(n),t))throw new Error("Cannot find square root");return n}function ou(r,t){let e=(r.ORDER-Js)/Qs,n=r.mul(t,me),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,me),o),c=r.mul(s,r.sub(i,r.ONE));if(!r.eql(r.sqr(c),t))throw new Error("Cannot find square root");return c}function su(r){if(r<BigInt(3))throw new Error("sqrt is not defined for small field");let t=r-st,e=0;for(;t%me===mt;)t/=me,e++;let n=me,o=Ft(r);for(;Xs(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return ti;let s=o.pow(n,t),i=(t+st)/me;return function(a,l){if(a.is0(l))return l;if(Xs(a,l)!==1)throw new Error("Cannot find square root");let u=e,f=a.mul(a.ONE,s),b=a.pow(l,t),v=a.pow(l,i);for(;!a.eql(b,a.ONE);){if(a.is0(b))return a.ZERO;let I=1,m=a.sqr(b);for(;!a.eql(m,a.ONE);)if(I++,m=a.sqr(m),I===u)throw new Error("Cannot find square root");let A=st<<BigInt(u-I-1),P=a.pow(f,A);u=I,f=a.sqr(P),b=a.mul(b,f),v=a.mul(v,P)}return v}}function iu(r){return r%$s===nu?ti:r%Qs===Js?ou:su(r)}var ei=(r,t)=>(F(r,t)&st)===st,au=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Wn(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=au.reduce((n,o)=>(n[o]="function",n),t);return zt(r,e)}function cu(r,t,e){if(e<mt)throw new Error("invalid exponent, negatives unsupported");if(e===mt)return r.ONE;if(e===st)return t;let n=r.ONE,o=t;for(;e>mt;)e&st&&(n=r.mul(n,o)),o=r.sqr(o),e>>=st;return n}function Ne(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,c,a)=>r.is0(c)?i:(n[a]=i,r.mul(i,c)),r.ONE),s=r.inv(o);return t.reduceRight((i,c,a)=>r.is0(c)?i:(n[a]=r.mul(i,n[a]),r.mul(i,c)),s),n}function Xs(r,t){let e=(r.ORDER-st)/me,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Xn(r,t){t!==void 0&&Lr(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Ft(r,t,e=!1,n={}){if(r<=mt)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=Xn(r,t);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let i,c=Object.freeze({ORDER:r,isLE:e,BITS:o,BYTES:s,MASK:pe(o),ZERO:mt,ONE:st,create:a=>F(a,r),isValid:a=>{if(typeof a!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof a);return mt<=a&&a<r},is0:a=>a===mt,isOdd:a=>(a&st)===st,neg:a=>F(-a,r),eql:(a,l)=>a===l,sqr:a=>F(a*a,r),add:(a,l)=>F(a+l,r),sub:(a,l)=>F(a-l,r),mul:(a,l)=>F(a*l,r),pow:(a,l)=>cu(c,a,l),div:(a,l)=>F(a*Nr(l,r),r),sqrN:a=>a*a,addN:(a,l)=>a+l,subN:(a,l)=>a-l,mulN:(a,l)=>a*l,inv:a=>Nr(a,r),sqrt:n.sqrt||(a=>(i||(i=iu(r)),i(c,a))),toBytes:a=>e?De(a,s):de(a,s),fromBytes:a=>{if(a.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+a.length);return e?he(a):Vt(a)},invertBatch:a=>Ne(c,a),cmov:(a,l,u)=>u?l:a});return Object.freeze(c)}function ri(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function $n(r){let t=ri(r);return t+Math.ceil(t/2)}function ni(r,t,e=!1){let n=r.length,o=ri(t),s=$n(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?he(r):Vt(r),c=F(i,t-st)+st;return e?De(c,o):de(c,o)}var oi=BigInt(0),ro=BigInt(1);function Jn(r,t){let e=t.negate();return r?e:t}function ii(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Qn(r,t){ii(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=pe(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function si(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,c=Number(r&o),a=r>>i;c>n&&(c-=s,a+=ro);let l=t*n,u=l+Math.abs(c)-1,f=c===0,b=c<0,v=t%2!==0;return{nextN:a,offset:u,isZero:f,isNeg:b,isNegF:v,offsetF:l}}function uu(r,t){if(!Array.isArray(r))throw new Error("array expected");r.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}function fu(r,t){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}var to=new WeakMap,ai=new WeakMap;function eo(r){return ai.get(r)||1}function Ur(r,t){return{constTimeNegate:Jn,hasPrecomputes(e){return eo(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>oi;)n&ro&&(o=o.add(s)),s=s.double(),n>>=ro;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=Qn(n,t),i=[],c=e,a=c;for(let l=0;l<o;l++){a=c,i.push(a);for(let u=1;u<s;u++)a=a.add(c),i.push(a);c=a.double()}return i},wNAF(e,n,o){let s=r.ZERO,i=r.BASE,c=Qn(e,t);for(let a=0;a<c.windows;a++){let{nextN:l,offset:u,isZero:f,isNeg:b,isNegF:v,offsetF:I}=si(o,a,c);o=l,f?i=i.add(Jn(v,n[I])):s=s.add(Jn(b,n[u]))}return{p:s,f:i}},wNAFUnsafe(e,n,o,s=r.ZERO){let i=Qn(e,t);for(let c=0;c<i.windows&&o!==oi;c++){let{nextN:a,offset:l,isZero:u,isNeg:f}=si(o,c,i);if(o=a,!u){let b=n[l];s=s.add(f?b.negate():b)}}return s},getPrecomputes(e,n,o){let s=to.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&to.set(n,o(s))),s},wNAFCached(e,n,o){let s=eo(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=eo(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){ii(n,t),ai.set(e,n),to.delete(e)}}}function Kr(r,t,e,n){uu(e,r),fu(n,t);let o=e.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=r.ZERO,c=Ys(BigInt(o)),a=1;c>12?a=c-3:c>4?a=c-2:c>0&&(a=2);let l=pe(a),u=new Array(Number(l)+1).fill(i),f=Math.floor((t.BITS-1)/a)*a,b=i;for(let v=f;v>=0;v-=a){u.fill(i);for(let m=0;m<s;m++){let A=n[m],P=Number(A>>BigInt(v)&l);u[P]=u[P].add(e[m])}let I=i;for(let m=u.length-1,A=i;m>0;m--)A=A.add(u[m]),I=I.add(A);if(b=b.add(I),v!==0)for(let m=0;m<a;m++)b=b.double()}return b}function tr(r){return Wn(r.Fp),zt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Xn(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Rt=BigInt(0),yt=BigInt(1),ci=BigInt(2),lu=BigInt(8),hu={zip215:!0};function du(r){let t=tr(r);return zt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function ui(r){let t=du(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:c,h:a}=t,l=ci<<BigInt(c*8)-yt,u=e.create,f=Ft(t.n,t.nBitLength);function b(g,d){let p=e.sqr(g),S=e.sqr(d),D=e.add(e.mul(t.a,p),S),K=e.add(e.ONE,e.mul(t.d,e.mul(p,S)));return e.eql(D,K)}if(!b(t.Gx,t.Gy))throw new Error("bad curve params: generator point");let v=t.uvRatio||((g,d)=>{try{return{isValid:!0,value:e.sqrt(g*e.inv(d))}}catch{return{isValid:!1,value:Rt}}}),I=t.adjustScalarBytes||(g=>g),m=t.domain||((g,d,p)=>{if(Dt("phflag",p),d.length||p)throw new Error("Contexts/pre-hash are not supported");return g});function A(g,d,p=!1){let S=p?yt:Rt;vt("coordinate "+g,d,S,l)}function P(g){if(!(g instanceof h))throw new Error("ExtendedPoint expected")}let M=Re((g,d)=>{let{ex:p,ey:S,ez:D}=g,K=g.is0();d==null&&(d=K?lu:e.inv(D));let O=u(p*d),q=u(S*d),H=u(D*d);if(K)return{x:Rt,y:yt};if(H!==yt)throw new Error("invZ was invalid");return{x:O,y:q}}),x=Re(g=>{let{a:d,d:p}=t;if(g.is0())throw new Error("bad point: ZERO");let{ex:S,ey:D,ez:K,et:O}=g,q=u(S*S),H=u(D*D),z=u(K*K),rt=u(z*z),J=u(q*d),at=u(z*u(J+H)),gt=u(rt+u(p*u(q*H)));if(at!==gt)throw new Error("bad point: equation left != right (1)");let ot=u(S*D),ut=u(K*O);if(ot!==ut)throw new Error("bad point: equation left != right (2)");return!0});class h{constructor(d,p,S,D){A("x",d),A("y",p),A("z",S,!0),A("t",D),this.ex=d,this.ey=p,this.ez=S,this.et=D,Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(d){if(d instanceof h)throw new Error("extended point not allowed");let{x:p,y:S}=d||{};return A("x",p),A("y",S),new h(p,S,yt,u(p*S))}static normalizeZ(d){let p=Ne(e,d.map(S=>S.ez));return d.map((S,D)=>S.toAffine(p[D])).map(h.fromAffine)}static msm(d,p){return Kr(h,f,d,p)}_setWindowSize(d){_.setWindowSize(this,d)}assertValidity(){x(this)}equals(d){P(d);let{ex:p,ey:S,ez:D}=this,{ex:K,ey:O,ez:q}=d,H=u(p*q),z=u(K*D),rt=u(S*q),J=u(O*D);return H===z&&rt===J}is0(){return this.equals(h.ZERO)}negate(){return new h(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:d}=t,{ex:p,ey:S,ez:D}=this,K=u(p*p),O=u(S*S),q=u(ci*u(D*D)),H=u(d*K),z=p+S,rt=u(u(z*z)-K-O),J=H+O,at=J-q,gt=H-O,ot=u(rt*at),ut=u(J*gt),St=u(rt*gt),It=u(at*J);return new h(ot,ut,It,St)}add(d){P(d);let{a:p,d:S}=t,{ex:D,ey:K,ez:O,et:q}=this,{ex:H,ey:z,ez:rt,et:J}=d,at=u(D*H),gt=u(K*z),ot=u(q*S*J),ut=u(O*rt),St=u((D+K)*(H+z)-at-gt),It=ut-ot,qe=ut+ot,es=u(gt-p*at),ya=u(St*It),ba=u(qe*es),ga=u(St*es),xa=u(It*qe);return new h(ya,ba,xa,ga)}subtract(d){return this.add(d.negate())}wNAF(d){return _.wNAFCached(this,d,h.normalizeZ)}multiply(d){let p=d;vt("scalar",p,yt,n);let{p:S,f:D}=this.wNAF(p);return h.normalizeZ([S,D])[0]}multiplyUnsafe(d,p=h.ZERO){let S=d;return vt("scalar",S,Rt,n),S===Rt?B:this.is0()||S===yt?this:_.wNAFCachedUnsafe(this,S,h.normalizeZ,p)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}isTorsionFree(){return _.unsafeLadder(this,n).is0()}toAffine(d){return M(this,d)}clearCofactor(){let{h:d}=t;return d===yt?this:this.multiplyUnsafe(d)}static fromHex(d,p=!1){let{d:S,a:D}=t,K=e.BYTES;d=Z("pointHex",d,K),Dt("zip215",p);let O=d.slice(),q=d[K-1];O[K-1]=q&-129;let H=he(O),z=p?l:e.ORDER;vt("pointHex.y",H,Rt,z);let rt=u(H*H),J=u(rt-yt),at=u(S*rt-D),{isValid:gt,value:ot}=v(J,at);if(!gt)throw new Error("Point.fromHex: invalid y coordinate");let ut=(ot&yt)===yt,St=(q&128)!==0;if(!p&&ot===Rt&&St)throw new Error("Point.fromHex: x=0 and x_0=1");return St!==ut&&(ot=u(-ot)),h.fromAffine({x:ot,y:H})}static fromPrivateKey(d){let{scalar:p}=k(d);return y.multiply(p)}toRawBytes(){let{x:d,y:p}=this.toAffine(),S=De(p,e.BYTES);return S[S.length-1]|=d&yt?128:0,S}toHex(){return ee(this.toRawBytes())}}h.BASE=new h(t.Gx,t.Gy,yt,u(t.Gx*t.Gy)),h.ZERO=new h(Rt,yt,yt,Rt);let{BASE:y,ZERO:B}=h,_=Ur(h,c*8);function L(g){return F(g,n)}function N(g){return L(he(g))}function k(g){let d=e.BYTES;g=Z("private key",g,d);let p=Z("hashed private key",s(g),2*d),S=I(p.slice(0,d)),D=p.slice(d,2*d),K=N(S);return{head:S,prefix:D,scalar:K}}function C(g){let{head:d,prefix:p,scalar:S}=k(g),D=y.multiply(S),K=D.toRawBytes();return{head:d,prefix:p,scalar:S,point:D,pointBytes:K}}function U(g){return C(g).pointBytes}function R(g=Uint8Array.of(),...d){let p=re(...d);return N(s(m(p,Z("context",g),!!o)))}function et(g,d,p={}){g=Z("message",g),o&&(g=o(g));let{prefix:S,scalar:D,pointBytes:K}=C(d),O=R(p.context,S,g),q=y.multiply(O).toRawBytes(),H=R(p.context,q,K,g),z=L(O+H*D);vt("signature.s",z,Rt,n);let rt=re(q,De(z,e.BYTES));return Z("result",rt,e.BYTES*2)}let E=hu;function w(g,d,p,S=E){let{context:D,zip215:K}=S,O=e.BYTES;g=Z("signature",g,2*O),d=Z("message",d),p=Z("publicKey",p,O),K!==void 0&&Dt("zip215",K),o&&(d=o(d));let q=he(g.slice(O,2*O)),H,z,rt;try{H=h.fromHex(p,K),z=h.fromHex(g.slice(0,O),K),rt=y.multiplyUnsafe(q)}catch{return!1}if(!K&&H.isSmallOrder())return!1;let J=R(D,z.toRawBytes(),H.toRawBytes(),d);return z.add(H.multiplyUnsafe(J)).subtract(rt).clearCofactor().equals(h.ZERO)}return y._setWindowSize(8),{CURVE:t,getPublicKey:U,sign:et,verify:w,ExtendedPoint:h,utils:{getExtendedPublicKey:C,randomPrivateKey:()=>i(e.BYTES),precompute(g=8,d=h.BASE){return d._setWindowSize(g),d.multiply(BigInt(3)),d}}}}var no=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),fi=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Sh=BigInt(0),pu=BigInt(1),li=BigInt(2),vh=BigInt(3),mu=BigInt(5),yu=BigInt(8);function bu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=no,c=r*r%s*r%s,a=Y(c,li,s)*c%s,l=Y(a,pu,s)*r%s,u=Y(l,mu,s)*l%s,f=Y(u,t,s)*u%s,b=Y(f,e,s)*f%s,v=Y(b,n,s)*b%s,I=Y(v,o,s)*v%s,m=Y(I,o,s)*v%s,A=Y(m,t,s)*u%s;return{pow_p_5_8:Y(A,li,s)*r%s,b2:c}}function gu(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function xu(r,t){let e=no,n=F(t*t*t,e),o=F(n*n*t,e),s=bu(r*o).pow_p_5_8,i=F(r*n*s,e),c=F(t*i*i,e),a=i,l=F(i*fi,e),u=c===r,f=c===F(-r,e),b=c===F(-r*fi,e);return u&&(i=a),(f||b)&&(i=l),ei(i,e)&&(i=F(-i,e)),{isValid:u||f,value:i}}var hi=Ft(no,void 0,!0),wu={a:hi.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:hi,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:yu,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:zs,randomBytes:Pe,adjustScalarBytes:gu,uvRatio:xu},di=ui(wu);var kr=32;function pi(r,t,e){return di.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var Or=class{type="Ed25519";raw;constructor(t){this.raw=oo(t,kr)}toMultihash(){return _t.digest(Ot(this))}toCID(){return ft.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:wt(this.raw,t.raw)}verify(t,e){return pi(this.raw,e,t)}};function so(r){return r=oo(r,kr),new Or(r)}function oo(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new W(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var Su=Math.pow(2,7),vu=Math.pow(2,14),Au=Math.pow(2,21),io=Math.pow(2,28),ao=Math.pow(2,35),co=Math.pow(2,42),uo=Math.pow(2,49),V=128,ht=127;function Tt(r){if(r<Su)return 1;if(r<vu)return 2;if(r<Au)return 3;if(r<io)return 4;if(r<ao)return 5;if(r<co)return 6;if(r<uo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function fo(r,t,e=0){switch(Tt(r)){case 8:t[e++]=r&255|V,r/=128;case 7:t[e++]=r&255|V,r/=128;case 6:t[e++]=r&255|V,r/=128;case 5:t[e++]=r&255|V,r/=128;case 4:t[e++]=r&255|V,r>>>=7;case 3:t[e++]=r&255|V,r>>>=7;case 2:t[e++]=r&255|V,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Iu(r,t,e=0){switch(Tt(r)){case 8:t.set(e++,r&255|V),r/=128;case 7:t.set(e++,r&255|V),r/=128;case 6:t.set(e++,r&255|V),r/=128;case 5:t.set(e++,r&255|V),r/=128;case 4:t.set(e++,r&255|V),r>>>=7;case 3:t.set(e++,r&255|V),r>>>=7;case 2:t.set(e++,r&255|V),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function lo(r,t){let e=r[t],n=0;if(n+=e&ht,e<V||(e=r[t+1],n+=(e&ht)<<7,e<V)||(e=r[t+2],n+=(e&ht)<<14,e<V)||(e=r[t+3],n+=(e&ht)<<21,e<V)||(e=r[t+4],n+=(e&ht)*io,e<V)||(e=r[t+5],n+=(e&ht)*ao,e<V)||(e=r[t+6],n+=(e&ht)*co,e<V)||(e=r[t+7],n+=(e&ht)*uo,e<V))return n;throw new RangeError("Could not decode varint")}function Bu(r,t){let e=r.get(t),n=0;if(n+=e&ht,e<V||(e=r.get(t+1),n+=(e&ht)<<7,e<V)||(e=r.get(t+2),n+=(e&ht)<<14,e<V)||(e=r.get(t+3),n+=(e&ht)<<21,e<V)||(e=r.get(t+4),n+=(e&ht)*io,e<V)||(e=r.get(t+5),n+=(e&ht)*ao,e<V)||(e=r.get(t+6),n+=(e&ht)*co,e<V)||(e=r.get(t+7),n+=(e&ht)*uo,e<V))return n;throw new RangeError("Could not decode varint")}function yi(r,t,e=0){return t==null&&(t=lt(Tt(r))),t instanceof Uint8Array?fo(r,t,e):Iu(r,t,e)}function bi(r,t=0){return r instanceof Uint8Array?lo(r,t):Bu(r,t)}var ho=new Float32Array([-0]),ne=new Uint8Array(ho.buffer);function xi(r,t,e){ho[0]=r,t[e]=ne[0],t[e+1]=ne[1],t[e+2]=ne[2],t[e+3]=ne[3]}function wi(r,t){return ne[0]=r[t],ne[1]=r[t+1],ne[2]=r[t+2],ne[3]=r[t+3],ho[0]}var po=new Float64Array([-0]),dt=new Uint8Array(po.buffer);function Ei(r,t,e){po[0]=r,t[e]=dt[0],t[e+1]=dt[1],t[e+2]=dt[2],t[e+3]=dt[3],t[e+4]=dt[4],t[e+5]=dt[5],t[e+6]=dt[6],t[e+7]=dt[7]}function Si(r,t){return dt[0]=r[t],dt[1]=r[t+1],dt[2]=r[t+2],dt[3]=r[t+3],dt[4]=r[t+4],dt[5]=r[t+5],dt[6]=r[t+6],dt[7]=r[t+7],po[0]}var _u=BigInt(Number.MAX_SAFE_INTEGER),Lu=BigInt(Number.MIN_SAFE_INTEGER),At=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+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 e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(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,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ye;if(t<_u&&t>Lu)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>vi&&(o=0n,++n>vi&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ye;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):ye}},ye=new At(0,0);ye.toBigInt=function(){return 0n};ye.zzEncode=ye.zzDecode=function(){return this};ye.length=function(){return 1};var vi=4294967296n;function Ai(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Ii(r,t,e){if(e-t<1)return"";let o,s=[],i=0,c;for(;t<e;)c=r[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|r[t++]&63:c>239&&c<365?(c=((c&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function mo(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function Pt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Mr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var yo=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Pt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Pt(this,4);return Mr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Pt(this,4);return Mr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Pt(this,4);let t=wi(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Pt(this,4);let t=Si(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw Pt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Ii(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Pt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Pt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new At(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*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;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw Pt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw Pt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Pt(this,8);let t=Mr(this.buf,this.pos+=4),e=Mr(this.buf,this.pos+=4);return new At(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=lo(this.buf,this.pos);return this.pos+=Tt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function bo(r){return new yo(r instanceof Uint8Array?r:r.subarray())}function qr(r,t,e){let n=bo(r);return t.decode(n,void 0,e)}function go(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return lt(i);o+i>t&&(n=lt(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var be=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function xo(){}var Eo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Tu=go();function Pu(r){return globalThis.Buffer!=null?lt(r):Tu(r)}var rr=class{len;head;tail;states;constructor(){this.len=0,this.head=new be(xo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new be(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new So((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(Hr,10,At.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=At.fromBigInt(t);return this._push(Hr,e.length(),e)}uint64Number(t){return this._push(fo,Tt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=At.fromBigInt(t).zzEncode();return this._push(Hr,e.length(),e)}sint64Number(t){let e=At.fromNumber(t).zzEncode();return this._push(Hr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(wo,1,t?1:0)}fixed32(t){return this._push(er,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=At.fromBigInt(t);return this._push(er,4,e.lo)._push(er,4,e.hi)}fixed64Number(t){let e=At.fromNumber(t);return this._push(er,4,e.lo)._push(er,4,e.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(xi,4,t)}double(t){return this._push(Ei,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(wo,1,0):this.uint32(e)._push(Du,e,t)}string(t){let e=Ai(t);return e!==0?this.uint32(e)._push(mo,e,t):this._push(wo,1,0)}fork(){return this.states=new Eo(this),this.head=this.tail=new be(xo,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 be(xo,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Pu(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function wo(r,t,e){t[e]=r&255}function Cu(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var So=class extends be{next;constructor(t,e){super(Cu,t,e),this.next=void 0}};function Hr(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function er(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Du(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(rr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Ru,t,r),this},rr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Nu,t,r),this});function Ru(r,t,e){t.set(r,e)}function Nu(r,t,e){r.length<40?mo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(G(r),e)}function vo(){return new rr}function Vr(r,t){let e=vo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Ue;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(Ue||(Ue={}));function zr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Ao(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let c=t(s);i.int32(c)},n=function(s){let i=s.int32();return t(i)};return zr("enum",Ue.VARINT,e,n)}function Fr(r,t){return zr("message",Ue.LENGTH_DELIMITED,r,t)}var tt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(tt||(tt={}));var Io;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Io||(Io={}));(function(r){r.codec=()=>Ao(Io)})(tt||(tt={}));var Nt;(function(r){let t;r.codec=()=>(t==null&&(t=Fr((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),tt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let c=e.uint32();switch(c>>>3){case 1:{s.Type=tt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Vr(e,r.codec()),r.decode=(e,n)=>qr(e,r.codec(),n)})(Nt||(Nt={}));var Bo;(function(r){let t;r.codec=()=>(t==null&&(t=Fr((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),tt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let c=e.uint32();switch(c>>>3){case 1:{s.Type=tt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Vr(e,r.codec()),r.decode=(e,n)=>qr(e,r.codec(),n)})(Bo||(Bo={}));function Gr(r){if(isNaN(r)||r<=0)throw new W("random bytes length must be a Number bigger than 0");return Pe(r)}var nr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},jr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Li={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new jr("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 oe=Li;var sr={};xt(sr,{MAX_RSA_KEY_SIZE:()=>_o,generateRSAKeyPair:()=>Di,jwkToJWKKeyPair:()=>Ri,jwkToPkcs1:()=>Ou,jwkToPkix:()=>Co,jwkToRSAPrivateKey:()=>Uo,pkcs1MessageToJwk:()=>To,pkcs1MessageToRSAPrivateKey:()=>Do,pkcs1ToJwk:()=>ku,pkcs1ToRSAPrivateKey:()=>Ci,pkixMessageToJwk:()=>Po,pkixMessageToRSAPublicKey:()=>No,pkixToJwk:()=>Mu,pkixToRSAPublicKey:()=>Ro});var Zr=Dr;var Ke=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=sr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ft.createV1(114,this._multihash)}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:wt(this.raw,t.raw)}verify(t,e){return Pi(this.jwk,e,t)}},or=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=sr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:wt(this.raw,t.raw)}sign(t){return Ti(this.jwk,t)}};var _o=8192,Lo=18,Uu=1062,Ku=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function ku(r){let t=kt(r);return To(t)}function To(r){return{n:j(r[1],"base64url"),e:j(r[2],"base64url"),d:j(r[3],"base64url"),p:j(r[4],"base64url"),q:j(r[5],"base64url"),dp:j(r[6],"base64url"),dq:j(r[7],"base64url"),qi:j(r[8],"base64url"),kty:"RSA"}}function Ou(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new W("JWK was missing components");return $t([Et(Uint8Array.from([0])),Et(G(r.n,"base64url")),Et(G(r.e,"base64url")),Et(G(r.d,"base64url")),Et(G(r.p,"base64url")),Et(G(r.q,"base64url")),Et(G(r.dp,"base64url")),Et(G(r.dq,"base64url")),Et(G(r.qi,"base64url"))]).subarray()}function Mu(r){let t=kt(r,{offset:0});return Po(t)}function Po(r){let t=kt(r[1],{offset:0});return{kty:"RSA",n:j(t[0],"base64url"),e:j(t[1],"base64url")}}function Co(r){if(r.n==null||r.e==null)throw new W("JWK was missing components");return $t([Ku,_r($t([Et(G(r.n,"base64url")),Et(G(r.e,"base64url"))]))]).subarray()}function Ci(r){let t=kt(r);return Do(t)}function Do(r){let t=To(r);return Uo(t)}function Ro(r,t){if(r.byteLength>=Uu)throw new we("Key size is too large");let e=kt(r,{offset:0});return No(e,r,t)}function No(r,t,e){let n=Po(r);if(e==null){let o=Zr(Nt.encode({Type:tt.RSA,Data:t}));e=Bt(Lo,o)}return new Ke(n,e)}function Uo(r){if(Ui(r)>_o)throw new W("Key size is too large");let t=Ri(r),e=Zr(Nt.encode({Type:tt.RSA,Data:Co(t.publicKey)})),n=Bt(Lo,e);return new or(t.privateKey,new Ke(t.publicKey,n))}async function Di(r){if(r>_o)throw new W("Key size is too large");let t=await Ni(r),e=Zr(Nt.encode({Type:tt.RSA,Data:Co(t.publicKey)})),n=Bt(Lo,e);return new or(t.privateKey,new Ke(t.publicKey,n))}function Ri(r){if(r==null)throw new W("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function Ni(r){let t=await oe.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),e=await qu(t);return{privateKey:e[0],publicKey:e[1]}}async function Ti(r,t){let e=await oe.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await oe.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function Pi(r,t,e){let n=await oe.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return oe.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function qu(r){if(r.privateKey==null||r.publicKey==null)throw new W("Private and public key are required");return Promise.all([oe.get().subtle.exportKey("jwk",r.privateKey),oe.get().subtle.exportKey("jwk",r.publicKey)])}function Ui(r){if(r.kty!=="RSA")throw new W("invalid key type");if(r.n==null)throw new W("invalid key modulus");return G(r.n,"base64url").length*8}var Yr=class extends Le{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Ts(t);let n=Ye(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);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),Mt(s)}update(t){return Te(this),this.iHash.update(t),this}digestInto(t){Te(this),ue(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ko=(r,t,e)=>new Yr(r,t).update(e).digest();Ko.create=(r,t)=>new Yr(r,t);function Ki(r){r.lowS!==void 0&&Dt("lowS",r.lowS),r.prehash!==void 0&&Dt("prehash",r.prehash)}function Hu(r){let t=tr(r);zt(t,{a:"field",b:"field"},{allowInfinityPoint:"boolean",allowedPrivateKeyLengths:"array",clearCofactor:"function",fromBytes:"function",isTorsionFree:"function",toBytes:"function",wrapPrivateKey:"boolean"});let{endo:e,Fp:n,a:o}=t;if(e){if(!n.eql(o,n.ZERO))throw new Error("invalid endo: CURVE.a must be 0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function')}return Object.freeze({...t})}var Mo=class extends Error{constructor(t=""){super(t)}},Gt={Err:Mo,_tlv:{encode:(r,t)=>{let{Err:e}=Gt;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=Je(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?Je(o.length/2|128):"";return Je(r)+s+o+t},decode(r,t){let{Err:e}=Gt,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let a=o&127;if(!a)throw new e("tlv.decode(long): indefinite length not supported");if(a>4)throw new e("tlv.decode(long): byte length is too big");let l=t.subarray(n,n+a);if(l.length!==a)throw new e("tlv.decode: length bytes not complete");if(l[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let u of l)i=i<<8|u;if(n+=a,i<128)throw new e("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new e("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Gt;if(r<jt)throw new t("integer: negative integers are not allowed");let e=Je(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=Gt;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Vt(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Gt,o=Z("signature",r),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,s),{v:l,l:u}=n.decode(2,a);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(c),s:e.decode(l)}},hexFromSig(r){let{_tlv:t,_int:e}=Gt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}};function ko(r,t){return ee(de(r,t))}var jt=BigInt(0),it=BigInt(1),ep=BigInt(2),Oo=BigInt(3),Vu=BigInt(4);function zu(r){let t=Hu(r),{Fp:e}=t,n=Ft(t.n,t.nBitLength),o=t.toBytes||((x,h,y)=>{let B=h.toAffine();return re(Uint8Array.from([4]),e.toBytes(B.x),e.toBytes(B.y))}),s=t.fromBytes||(x=>{let h=x.subarray(1),y=e.fromBytes(h.subarray(0,e.BYTES)),B=e.fromBytes(h.subarray(e.BYTES,2*e.BYTES));return{x:y,y:B}});function i(x){let{a:h,b:y}=t,B=e.sqr(x),_=e.mul(B,x);return e.add(e.add(_,e.mul(x,h)),y)}function c(x,h){let y=e.sqr(h),B=i(x);return e.eql(y,B)}if(!c(t.Gx,t.Gy))throw new Error("bad curve params: generator point");let a=e.mul(e.pow(t.a,Oo),Vu),l=e.mul(e.sqr(t.b),BigInt(27));if(e.is0(e.add(a,l)))throw new Error("bad curve params: a or b");function u(x){return Rr(x,it,t.n)}function f(x){let{allowedPrivateKeyLengths:h,nByteLength:y,wrapPrivateKey:B,n:_}=t;if(h&&typeof x!="bigint"){if(Ce(x)&&(x=ee(x)),typeof x!="string"||!h.includes(x.length))throw new Error("invalid private key");x=x.padStart(y*2,"0")}let L;try{L=typeof x=="bigint"?x:Vt(Z("private key",x,y))}catch{throw new Error("invalid private key, expected hex or "+y+" bytes, got "+typeof x)}return B&&(L=F(L,_)),vt("private key",L,it,_),L}function b(x){if(!(x instanceof m))throw new Error("ProjectivePoint expected")}let v=Re((x,h)=>{let{px:y,py:B,pz:_}=x;if(e.eql(_,e.ONE))return{x:y,y:B};let L=x.is0();h==null&&(h=L?e.ONE:e.inv(_));let N=e.mul(y,h),k=e.mul(B,h),C=e.mul(_,h);if(L)return{x:e.ZERO,y:e.ZERO};if(!e.eql(C,e.ONE))throw new Error("invZ was invalid");return{x:N,y:k}}),I=Re(x=>{if(x.is0()){if(t.allowInfinityPoint&&!e.is0(x.py))return;throw new Error("bad point: ZERO")}let{x:h,y}=x.toAffine();if(!e.isValid(h)||!e.isValid(y))throw new Error("bad point: x or y not FE");if(!c(h,y))throw new Error("bad point: equation left != right");if(!x.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class m{constructor(h,y,B){if(h==null||!e.isValid(h))throw new Error("x required");if(y==null||!e.isValid(y)||e.is0(y))throw new Error("y required");if(B==null||!e.isValid(B))throw new Error("z required");this.px=h,this.py=y,this.pz=B,Object.freeze(this)}static fromAffine(h){let{x:y,y:B}=h||{};if(!h||!e.isValid(y)||!e.isValid(B))throw new Error("invalid affine point");if(h instanceof m)throw new Error("projective point not allowed");let _=L=>e.eql(L,e.ZERO);return _(y)&&_(B)?m.ZERO:new m(y,B,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let y=Ne(e,h.map(B=>B.pz));return h.map((B,_)=>B.toAffine(y[_])).map(m.fromAffine)}static fromHex(h){let y=m.fromAffine(s(Z("pointHex",h)));return y.assertValidity(),y}static fromPrivateKey(h){return m.BASE.multiply(f(h))}static msm(h,y){return Kr(m,n,h,y)}_setWindowSize(h){M.setWindowSize(this,h)}assertValidity(){I(this)}hasEvenY(){let{y:h}=this.toAffine();if(e.isOdd)return!e.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){b(h);let{px:y,py:B,pz:_}=this,{px:L,py:N,pz:k}=h,C=e.eql(e.mul(y,k),e.mul(L,_)),U=e.eql(e.mul(B,k),e.mul(N,_));return C&&U}negate(){return new m(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b:y}=t,B=e.mul(y,Oo),{px:_,py:L,pz:N}=this,k=e.ZERO,C=e.ZERO,U=e.ZERO,R=e.mul(_,_),et=e.mul(L,L),E=e.mul(N,N),w=e.mul(_,L);return w=e.add(w,w),U=e.mul(_,N),U=e.add(U,U),k=e.mul(h,U),C=e.mul(B,E),C=e.add(k,C),k=e.sub(et,C),C=e.add(et,C),C=e.mul(k,C),k=e.mul(w,k),U=e.mul(B,U),E=e.mul(h,E),w=e.sub(R,E),w=e.mul(h,w),w=e.add(w,U),U=e.add(R,R),R=e.add(U,R),R=e.add(R,E),R=e.mul(R,w),C=e.add(C,R),E=e.mul(L,N),E=e.add(E,E),R=e.mul(E,w),k=e.sub(k,R),U=e.mul(E,et),U=e.add(U,U),U=e.add(U,U),new m(k,C,U)}add(h){b(h);let{px:y,py:B,pz:_}=this,{px:L,py:N,pz:k}=h,C=e.ZERO,U=e.ZERO,R=e.ZERO,et=t.a,E=e.mul(t.b,Oo),w=e.mul(y,L),T=e.mul(B,N),g=e.mul(_,k),d=e.add(y,B),p=e.add(L,N);d=e.mul(d,p),p=e.add(w,T),d=e.sub(d,p),p=e.add(y,_);let S=e.add(L,k);return p=e.mul(p,S),S=e.add(w,g),p=e.sub(p,S),S=e.add(B,_),C=e.add(N,k),S=e.mul(S,C),C=e.add(T,g),S=e.sub(S,C),R=e.mul(et,p),C=e.mul(E,g),R=e.add(C,R),C=e.sub(T,R),R=e.add(T,R),U=e.mul(C,R),T=e.add(w,w),T=e.add(T,w),g=e.mul(et,g),p=e.mul(E,p),T=e.add(T,g),g=e.sub(w,g),g=e.mul(et,g),p=e.add(p,g),w=e.mul(T,p),U=e.add(U,w),w=e.mul(S,p),C=e.mul(d,C),C=e.sub(C,w),w=e.mul(d,T),R=e.mul(S,R),R=e.add(R,w),new m(C,U,R)}subtract(h){return this.add(h.negate())}is0(){return this.equals(m.ZERO)}wNAF(h){return M.wNAFCached(this,h,m.normalizeZ)}multiplyUnsafe(h){let{endo:y,n:B}=t;vt("scalar",h,jt,B);let _=m.ZERO;if(h===jt)return _;if(this.is0()||h===it)return this;if(!y||M.hasPrecomputes(this))return M.wNAFCachedUnsafe(this,h,m.normalizeZ);let{k1neg:L,k1:N,k2neg:k,k2:C}=y.splitScalar(h),U=_,R=_,et=this;for(;N>jt||C>jt;)N&it&&(U=U.add(et)),C&it&&(R=R.add(et)),et=et.double(),N>>=it,C>>=it;return L&&(U=U.negate()),k&&(R=R.negate()),R=new m(e.mul(R.px,y.beta),R.py,R.pz),U.add(R)}multiply(h){let{endo:y,n:B}=t;vt("scalar",h,it,B);let _,L;if(y){let{k1neg:N,k1:k,k2neg:C,k2:U}=y.splitScalar(h),{p:R,f:et}=this.wNAF(k),{p:E,f:w}=this.wNAF(U);R=M.constTimeNegate(N,R),E=M.constTimeNegate(C,E),E=new m(e.mul(E.px,y.beta),E.py,E.pz),_=R.add(E),L=et.add(w)}else{let{p:N,f:k}=this.wNAF(h);_=N,L=k}return m.normalizeZ([_,L])[0]}multiplyAndAddUnsafe(h,y,B){let _=m.BASE,L=(k,C)=>C===jt||C===it||!k.equals(_)?k.multiplyUnsafe(C):k.multiply(C),N=L(this,y).add(L(h,B));return N.is0()?void 0:N}toAffine(h){return v(this,h)}isTorsionFree(){let{h,isTorsionFree:y}=t;if(h===it)return!0;if(y)return y(m,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:y}=t;return h===it?this:y?y(m,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return Dt("isCompressed",h),this.assertValidity(),o(m,this,h)}toHex(h=!0){return Dt("isCompressed",h),ee(this.toRawBytes(h))}}m.BASE=new m(t.Gx,t.Gy,e.ONE),m.ZERO=new m(e.ZERO,e.ONE,e.ZERO);let{endo:A,nBitLength:P}=t,M=Ur(m,A?Math.ceil(P/2):P);return{CURVE:t,ProjectivePoint:m,normPrivateKeyToScalar:f,weierstrassEquation:i,isWithinCurveOrder:u}}function Fu(r){let t=tr(r);return zt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function ki(r){let t=Fu(r),{Fp:e,n,nByteLength:o,nBitLength:s}=t,i=e.BYTES+1,c=2*e.BYTES+1;function a(E){return F(E,n)}function l(E){return Nr(E,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:f,weierstrassEquation:b,isWithinCurveOrder:v}=zu({...t,toBytes(E,w,T){let g=w.toAffine(),d=e.toBytes(g.x),p=re;return Dt("isCompressed",T),T?p(Uint8Array.from([w.hasEvenY()?2:3]),d):p(Uint8Array.from([4]),d,e.toBytes(g.y))},fromBytes(E){let w=E.length,T=E[0],g=E.subarray(1);if(w===i&&(T===2||T===3)){let d=Vt(g);if(!Rr(d,it,e.ORDER))throw new Error("Point is not on curve");let p=b(d),S;try{S=e.sqrt(p)}catch(O){let q=O instanceof Error?": "+O.message:"";throw new Error("Point is not on curve"+q)}let D=(S&it)===it;return(T&1)===1!==D&&(S=e.neg(S)),{x:d,y:S}}else if(w===c&&T===4){let d=e.fromBytes(g.subarray(0,e.BYTES)),p=e.fromBytes(g.subarray(e.BYTES,2*e.BYTES));return{x:d,y:p}}else{let d=i,p=c;throw new Error("invalid Point, expected length of "+d+", or uncompressed "+p+", got "+w)}}});function I(E){let w=n>>it;return E>w}function m(E){return I(E)?a(-E):E}let A=(E,w,T)=>Vt(E.slice(w,T));class P{constructor(w,T,g){vt("r",w,it,n),vt("s",T,it,n),this.r=w,this.s=T,g!=null&&(this.recovery=g),Object.freeze(this)}static fromCompact(w){let T=o;return w=Z("compactSignature",w,T*2),new P(A(w,0,T),A(w,T,2*T))}static fromDER(w){let{r:T,s:g}=Gt.toSig(Z("DER",w));return new P(T,g)}assertValidity(){}addRecoveryBit(w){return new P(this.r,this.s,w)}recoverPublicKey(w){let{r:T,s:g,recovery:d}=this,p=_(Z("msgHash",w));if(d==null||![0,1,2,3].includes(d))throw new Error("recovery id invalid");let S=d===2||d===3?T+t.n:T;if(S>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let D=(d&1)===0?"02":"03",K=u.fromHex(D+ko(S,e.BYTES)),O=l(S),q=a(-p*O),H=a(g*O),z=u.BASE.multiplyAndAddUnsafe(K,q,H);if(!z)throw new Error("point at infinify");return z.assertValidity(),z}hasHighS(){return I(this.s)}normalizeS(){return this.hasHighS()?new P(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return Qe(this.toDERHex())}toDERHex(){return Gt.hexFromSig(this)}toCompactRawBytes(){return Qe(this.toCompactHex())}toCompactHex(){let w=o;return ko(this.r,w)+ko(this.s,w)}}let M={isValidPrivateKey(E){try{return f(E),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let E=$n(t.n);return ni(t.randomBytes(E),t.n)},precompute(E=8,w=u.BASE){return w._setWindowSize(E),w.multiply(BigInt(3)),w}};function x(E,w=!0){return u.fromPrivateKey(E).toRawBytes(w)}function h(E){if(typeof E=="bigint")return!1;if(E instanceof u)return!0;let T=Z("key",E).length,g=e.BYTES,d=g+1,p=2*g+1;if(!(t.allowedPrivateKeyLengths||o===d))return T===d||T===p}function y(E,w,T=!0){if(h(E)===!0)throw new Error("first arg must be private key");if(h(w)===!1)throw new Error("second arg must be public key");return u.fromHex(w).multiply(f(E)).toRawBytes(T)}let B=t.bits2int||function(E){if(E.length>8192)throw new Error("input is too large");let w=Vt(E),T=E.length*8-s;return T>0?w>>BigInt(T):w},_=t.bits2int_modN||function(E){return a(B(E))},L=pe(s);function N(E){return vt("num < 2^"+s,E,jt,L),de(E,o)}function k(E,w,T=C){if(["recovered","canonical"].some(J=>J in T))throw new Error("sign() legacy options not supported");let{hash:g,randomBytes:d}=t,{lowS:p,prehash:S,extraEntropy:D}=T;p==null&&(p=!0),E=Z("msgHash",E),Ki(T),S&&(E=Z("prehashed msgHash",g(E)));let K=_(E),O=f(w),q=[N(O),N(K)];if(D!=null&&D!==!1){let J=D===!0?d(e.BYTES):D;q.push(Z("extraEntropy",J))}let H=re(...q),z=K;function rt(J){let at=B(J);if(!v(at))return;let gt=l(at),ot=u.BASE.multiply(at).toAffine(),ut=a(ot.x);if(ut===jt)return;let St=a(gt*a(z+ut*O));if(St===jt)return;let It=(ot.x===ut?0:2)|Number(ot.y&it),qe=St;return p&&I(St)&&(qe=m(St),It^=1),new P(ut,qe,It)}return{seed:H,k2sig:rt}}let C={lowS:t.lowS,prehash:!1},U={lowS:t.lowS,prehash:!1};function R(E,w,T=C){let{seed:g,k2sig:d}=k(E,w,T),p=t;return Ws(p.hash.outputLen,p.nByteLength,p.hmac)(g,d)}u.BASE._setWindowSize(8);function et(E,w,T,g=U){let d=E;w=Z("msgHash",w),T=Z("publicKey",T);let{lowS:p,prehash:S,format:D}=g;if(Ki(g),"strict"in g)throw new Error("options.strict was renamed to lowS");if(D!==void 0&&D!=="compact"&&D!=="der")throw new Error("format must be compact or der");let K=typeof d=="string"||Ce(d),O=!K&&!D&&typeof d=="object"&&d!==null&&typeof d.r=="bigint"&&typeof d.s=="bigint";if(!K&&!O)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let q,H;try{if(O&&(q=new P(d.r,d.s)),K){try{D!=="compact"&&(q=P.fromDER(d))}catch(It){if(!(It instanceof Gt.Err))throw It}!q&&D!=="der"&&(q=P.fromCompact(d))}H=u.fromHex(T)}catch{return!1}if(!q||p&&q.hasHighS())return!1;S&&(w=t.hash(w));let{r:z,s:rt}=q,J=_(w),at=l(rt),gt=a(J*at),ot=a(z*at),ut=u.BASE.multiplyAndAddUnsafe(H,gt,ot)?.toAffine();return ut?a(ut.x)===z:!1}return{CURVE:t,getPublicKey:x,getSharedSecret:y,sign:R,verify:et,ProjectivePoint:u,Signature:P,utils:M}}function Gu(r){return{hash:r,hmac:(t,...e)=>Ko(r,t,Mn(...e)),randomBytes:Pe}}function Oi(r,t){let e=n=>ki({...r,...Gu(n)});return{...e(t),create:e}}var Hi=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Mi=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),ju=BigInt(0),Zu=BigInt(1),qo=BigInt(2),qi=(r,t)=>(r+t/qo)/t;function Yu(r){let t=Hi,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),l=r*r*r%t,u=l*l*r%t,f=Y(u,e,t)*u%t,b=Y(f,e,t)*u%t,v=Y(b,qo,t)*l%t,I=Y(v,o,t)*v%t,m=Y(I,s,t)*I%t,A=Y(m,c,t)*m%t,P=Y(A,a,t)*A%t,M=Y(P,c,t)*m%t,x=Y(M,e,t)*u%t,h=Y(x,i,t)*I%t,y=Y(h,n,t)*l%t,B=Y(y,qo,t);if(!Ho.eql(Ho.sqr(B),r))throw new Error("Cannot find square root");return B}var Ho=Ft(Hi,void 0,void 0,{sqrt:Yu}),ke=Oi({a:ju,b:BigInt(7),Fp:Ho,n:Mi,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Mi,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Zu*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),c=qi(s*r,t),a=qi(-n*r,t),l=F(r-c*e-a*o,t),u=F(-c*n-a*s,t),f=l>i,b=u>i;if(f&&(l=t-l),b&&(u=t-u),l>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:l,k2neg:b,k2:u}}}},Dr);function Vi(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function zi(r,t,e){let n=ae.digest(e instanceof Uint8Array?e:e.subarray());if(Vi(n))return n.then(({digest:o})=>ke.verify(t,o,r)).catch(o=>{throw new nr(String(o))});try{return ke.verify(t,n.digest,r)}catch(o){throw new nr(String(o))}}var Wr=class{type="secp256k1";raw;_key;constructor(t){this._key=Gi(t),this.raw=Fi(this._key)}toMultihash(){return _t.digest(Ot(this))}toCID(){return ft.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:wt(this.raw,t.raw)}verify(t,e){return zi(this._key,e,t)}};function Vo(r){return new Wr(r)}function Fi(r){return ke.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Gi(r){try{return ke.ProjectivePoint.fromHex(r),r}catch(t){throw new we(String(t))}}function zo(r,t){let{Type:e,Data:n}=Nt.decode(r),o=n??new Uint8Array;switch(e){case tt.RSA:return Ro(o,t);case tt.Ed25519:return so(o);case tt.secp256k1:return Vo(o);case tt.ECDSA:return On(o);default:throw new se}}function ji(r){let{Type:t,Data:e}=Nt.decode(r.digest),n=e??new Uint8Array;switch(t){case tt.Ed25519:return so(n);case tt.secp256k1:return Vo(n);case tt.ECDSA:return On(n);default:throw new se}}function Ot(r){return Nt.encode({Type:tt[r.type],Data:r.raw})}var Zi=Symbol.for("nodejs.util.inspect.custom"),Wu=114,ir=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()})`}[fn]=!0;toString(){return this.string==null&&(this.string=X.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ft.createV1(Wu,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return wt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return wt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Zi](){return`PeerId(${this.toString()})`}},ar=class extends ir{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},cr=class extends ir{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},ur=class extends ir{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Xu=2336,Xr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=_t.digest(G(this.url))}[Zi](){return`PeerId(${this.url})`}[fn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ft.createV1(Xu,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=j(t)),t.toString()===this.toString())}};function Fo(r){if(r.type==="Ed25519")return new cr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new ur({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new ar({multihash:r.toCID().multihash,publicKey:r});throw new se}function Yi(r){return Fo(r.publicKey)}function fr(r){if(Ju(r))return new ar({multihash:r});if($u(r))try{let t=ji(r);if(t.type==="Ed25519")return new cr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new ur({multihash:r,publicKey:t})}catch{let e=j(r.digest);return new Xr(new URL(e))}throw new Sr("Supplied PeerID Multihash is invalid")}function $u(r){return r.code===_t.code}function Ju(r){return r.code===ae.code}function ge(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return e}function $r(r){let t=Wt(X.decode(`z${r}`));return fr(t)}var lr=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[e,n]of t.entries())this.map.set(e.toString(),{key:e,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return ge(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((e,n)=>{t(e.value,e.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,e){this.map.set(t.toString(),{key:t,value:e})}keys(){return ge(this.map.values(),t=>t.key)}values(){return ge(this.map.values(),t=>t.value)}get size(){return this.map.size}};var hr=class r{set;constructor(t){if(this.set=new Set,t!=null)for(let e of t)this.set.add(e.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 ge(this.set.entries(),t=>{let e=$r(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=$r(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return ge(this.set.values(),t=>$r(t))}intersection(t){let e=new r;for(let n of t)this.has(n)&&e.add(n);return e}difference(t){let e=new r;for(let n of this)t.has(n)||e.add(n);return e}union(t){let e=new r;for(let n of t)e.add(n);for(let n of this)e.add(n);return e}};function Zt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Jr=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},Oe=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Jr(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new Jr(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Go=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Qr(r={}){return Qu(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function Qu(r,t){t=t??{};let e=t.onEnd,n=new Oe,o,s,i,c=Zt(),a=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((A,P)=>{s=M=>{s=null,n.push(M);try{A(r(n))}catch(x){P(x)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=Zt()})}},l=A=>s!=null?s(A):(n.push(A),o),u=A=>(n=new Oe,s!=null?s({error:A}):(n.push({error:A}),o)),f=A=>{if(i)return o;if(t?.objectMode!==!0&&A?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:A})},b=A=>i?o:(i=!0,A!=null?u(A):l({done:!0})),v=()=>(n=new Oe,b(),{done:!0}),I=A=>(b(A),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:a,return:v,throw:I,push:f,end:b,get readableLength(){return n.size},onEmpty:async A=>{let P=A?.signal;if(P?.throwIfAborted(),n.isEmpty())return;let M,x;P!=null&&(M=new Promise((h,y)=>{x=()=>{y(new Go)},P.addEventListener("abort",x)}));try{await Promise.race([c.promise,M])}finally{x!=null&&P!=null&&P?.removeEventListener("abort",x)}}},e==null)return o;let m=o;return o={[Symbol.asyncIterator](){return this},next(){return m.next()},throw(A){return m.throw(A),e!=null&&(e(A),e=void 0),{done:!0}},return(){return m.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(A){return m.end(A),e!=null&&(e(A),e=void 0),o},get readableLength(){return m.readableLength},onEmpty:A=>m.onEmpty(A)},o}var tn=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function Wi(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new tn(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new tn(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var jo=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Zt(),this.haveNext=Zt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Zt(),t}async throw(t){return this.ended=!0,this.error=t,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return this.ended=!0,this.nextResult=t,this.haveNext.resolve(),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Zt(),await Wi(this.readNext.promise,e?.signal,e)}};function Xi(){return new jo}function tf(r){return r[Symbol.asyncIterator]!=null}async function ef(r,t,e){try{await Promise.all(r.map(async n=>{for await(let o of n)await t.push(o,{signal:e}),e.throwIfAborted()})),await t.end(void 0,{signal:e})}catch(n){await t.end(n,{signal:e}).catch(()=>{})}}async function*rf(r){let t=new AbortController,e=Xi();ef(r,e,t.signal).catch(()=>{});try{yield*e}finally{t.abort()}}function*nf(r){for(let t of r)yield*t}function of(...r){let t=[];for(let e of r)tf(e)||t.push(e);return t.length===r.length?nf(t):rf(r)}var $i=of;function dr(r,...t){if(r==null)throw new Error("Empty pipeline");if(Zo(r)){let n=r;r=()=>n.source}else if(Qi(r)||Ji(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&Zo(e[e.length-1])&&(e[e.length-1]=e[e.length-1].sink),e.length>2)for(let n=1;n<e.length-1;n++)Zo(e[n])&&(e[n]=af(e[n]));return sf(...e)}var sf=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},Ji=r=>r?.[Symbol.asyncIterator]!=null,Qi=r=>r?.[Symbol.iterator]!=null,Zo=r=>r==null?!1:r.sink!=null&&r.source!=null,af=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=Qr({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let o,s=r.source;if(Ji(s))o=async function*(){yield*s,n.end()};else if(Qi(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return $i(n,o())}return r.source};var Wo=Ba(ea(),1);var mr=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},Xo=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},ra=r=>globalThis.DOMException===void 0?new Xo(r):new DOMException(r),na=r=>{let t=r.reason===void 0?ra("This operation was aborted."):r.reason;return t instanceof Error?t:ra(t)};function $o(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,c,l=new Promise((u,f)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(t.signal){let{signal:v}=t;v.aborted&&f(na(v)),c=()=>{f(na(v))},v.addEventListener("abort",c,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(u,f);return}let b=new mr;i=s.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(v){f(v)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?u():o instanceof Error?f(o):(b.message=o??`Promise timed out after ${e} milliseconds`,f(b))},e),(async()=>{try{u(await r)}catch(v){f(v)}})()}).finally(()=>{l.clear(),c&&t.signal&&t.signal.removeEventListener("abort",c)});return l.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},l}function Jo(r,t,e){let n=0,o=r.length;for(;o>0;){let s=Math.trunc(o/2),i=n+s;e(r[i],t)<=0?(n=++i,o-=s+1):o=s}return n}var yr=class{#t=[];enqueue(t,e){e={priority:0,...e};let n={priority:e.priority,id:e.id,run:t};if(this.size===0||this.#t[this.size-1].priority>=e.priority){this.#t.push(n);return}let o=Jo(this.#t,n,(s,i)=>i.priority-s.priority);this.#t.splice(o,0,n)}setPriority(t,e){let n=this.#t.findIndex(s=>s.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[o]=this.#t.splice(n,1);this.enqueue(o.run,{priority:e,id:t})}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(e=>e.priority===t.priority).map(e=>e.run)}get size(){return this.#t.length}};var br=class extends Wo.default{#t;#i;#s=0;#d;#a;#p=0;#r;#c;#e;#m;#n=0;#u;#o;#y;#x=1n;timeout;constructor(t){if(super(),t={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:yr,...t},!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString()??""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString()??""}\` (${typeof t.interval})`);this.#t=t.carryoverConcurrencyCount,this.#i=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#d=t.intervalCap,this.#a=t.interval,this.#e=new t.queueClass,this.#m=t.queueClass,this.concurrency=t.concurrency,this.timeout=t.timeout,this.#y=t.throwOnTimeout===!0,this.#o=t.autoStart===!1}get#w(){return this.#i||this.#s<this.#d}get#E(){return this.#n<this.#u}#S(){this.#n--,this.#f(),this.emit("next")}#v(){this.#g(),this.#b(),this.#c=void 0}get#A(){let t=Date.now();if(this.#r===void 0){let e=this.#p-t;if(e<0)this.#s=this.#t?this.#n:0;else return this.#c===void 0&&(this.#c=setTimeout(()=>{this.#v()},e)),!0}return!1}#f(){if(this.#e.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#o){let t=!this.#A;if(this.#w&&this.#E){let e=this.#e.dequeue();return e?(this.emit("active"),e(),t&&this.#b(),!0):!1}}return!1}#b(){this.#i||this.#r!==void 0||(this.#r=setInterval(()=>{this.#g()},this.#a),this.#p=Date.now()+this.#a)}#g(){this.#s===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#t?this.#n:0,this.#l()}#l(){for(;this.#f(););}get concurrency(){return this.#u}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#u=t,this.#l()}async#I(t){return new Promise((e,n)=>{t.addEventListener("abort",()=>{n(t.reason)},{once:!0})})}setPriority(t,e){this.#e.setPriority(t,e)}async add(t,e={}){return e.id??=(this.#x++).toString(),e={timeout:this.timeout,throwOnTimeout:this.#y,...e},new Promise((n,o)=>{this.#e.enqueue(async()=>{this.#n++,this.#s++;try{e.signal?.throwIfAborted();let s=t({signal:e.signal});e.timeout&&(s=$o(Promise.resolve(s),{milliseconds:e.timeout})),e.signal&&(s=Promise.race([s,this.#I(e.signal)]));let i=await s;n(i),this.emit("completed",i)}catch(s){if(s instanceof mr&&!e.throwOnTimeout){n();return}o(s),this.emit("error",s)}finally{this.#S()}},e),this.emit("add"),this.#f()})}async addAll(t,e){return Promise.all(t.map(async n=>this.add(n,e)))}start(){return this.#o?(this.#o=!1,this.#l(),this):this}pause(){this.#o=!0}clear(){this.#e=new this.#m}async onEmpty(){this.#e.size!==0&&await this.#h("empty")}async onSizeLessThan(t){this.#e.size<t||await this.#h("next",()=>this.#e.size<t)}async onIdle(){this.#n===0&&this.#e.size===0||await this.#h("idle")}async#h(t,e){return new Promise(n=>{let o=()=>{e&&!e()||(this.off(t,o),n())};this.on(t,o)})}get size(){return this.#e.size}sizeBy(t){return this.#e.filter(t).length}get pending(){return this.#n}get isPaused(){return this.#o}};function oa(r){if(r!=null){if(typeof r[Symbol.iterator]=="function")return r[Symbol.iterator]();if(typeof r[Symbol.asyncIterator]=="function")return r[Symbol.asyncIterator]();if(typeof r.next=="function")return r}throw new Error("argument is not an iterator or iterable")}function sa(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function ia(r,t){let e=oa(r).return?.();sa(e)&&e.catch(n=>{t.error("could not cause iterator to return",n)})}var rn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Me=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},nn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},gr=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function on(r){return r[Symbol.asyncIterator]!=null}function aa(r,t){if(r.byteLength>t)throw new Me("Message length too long")}var an=r=>{let t=Tt(r),e=lt(t);return yi(r,e),an.bytes=t,e};an.bytes=0;function cn(r,t){t=t??{};let e=t.lengthEncoder??an,n=t?.maxDataLength??4194304;function*o(s){aa(s,n);let i=e(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return on(r)?async function*(){for await(let s of r)yield*o(s)}():function*(){for(let s of r)yield*o(s)}()}cn.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??an,n=t?.maxDataLength??4194304;return aa(r,n),new nt(e(r.byteLength),r)};var xe;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(xe||(xe={}));var Qo=r=>{let t=bi(r);return Qo.bytes=Tt(t),t};Qo.bytes=0;function xr(r,t){let e=new nt,n=xe.LENGTH,o=-1,s=t?.lengthDecoder??Qo,i=t?.maxLengthLength??8,c=t?.maxDataLength??4194304;function*a(){for(;e.byteLength>0;){if(n===xe.LENGTH)try{if(o=s(e),o<0)throw new rn("Invalid message length");if(o>c)throw new Me("Message length too long");let l=s.bytes;e.consume(l),t?.onLength!=null&&t.onLength(o),n=xe.DATA}catch(l){if(l instanceof RangeError){if(e.byteLength>i)throw new nn("Message length length too long");break}throw l}if(n===xe.DATA){if(e.byteLength<o)break;let l=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(l),yield l,n=xe.LENGTH}}}return on(r)?async function*(){for await(let l of r)e.append(l),yield*a();if(e.byteLength>0)throw new gr("Unexpected end of input")}():function*(){for(let l of r)e.append(l),yield*a();if(e.byteLength>0)throw new gr("Unexpected end of input")}()}xr.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:s,value:i}=await r.next(e);if(s===!0)return;i!=null&&(yield i)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{e=1}}();return xr(n,{...t??{},onLength:s=>{e=s}})};var un=class extends Ee{id;protocol;outboundStream;inboundStream;_rawOutboundStream;_rawInboundStream;_inboundAbortController;closed;log;constructor(t,e){super(),this.log=t.logger.forComponent("libp2p-pubsub:peer-streams"),this.id=e.id,this.protocol=e.protocol,this._inboundAbortController=new AbortController,this.closed=!1}get isReadable(){return!!this.inboundStream}get isWritable(){return!!this.outboundStream}write(t){if(this.outboundStream==null){let e=this.id.toString();throw new Error("No writable connection to "+e)}this.outboundStream.push(t instanceof Uint8Array?new nt(t):t)}attachInboundStream(t,e){let n=()=>{ia(t.source,this.log)};return this._inboundAbortController.signal.addEventListener("abort",n,{once:!0}),this._rawInboundStream=t,this.inboundStream=dr(this._rawInboundStream,o=>xr(o,e)),this.dispatchEvent(new CustomEvent("stream:inbound")),this.inboundStream}async attachOutboundStream(t){let e=this.outboundStream;return this.outboundStream!=null&&this.outboundStream.end(),this._rawOutboundStream=t,this.outboundStream=Qr({onEnd:n=>{this._rawOutboundStream?.closeWrite().catch(o=>{this.log("error closing outbound stream",o)}),this._rawOutboundStream=void 0,this.outboundStream=void 0,n!=null&&this.dispatchEvent(new CustomEvent("close"))}}),dr(this.outboundStream,n=>cn(n),this._rawOutboundStream).catch(n=>{this.log.error(n)}),e==null&&this.dispatchEvent(new CustomEvent("stream:outbound")),this.outboundStream}close(){this.closed||(this.closed=!0,this.outboundStream!=null&&this.outboundStream.end(),this.inboundStream!=null&&this._inboundAbortController.abort(),this._rawOutboundStream=void 0,this.outboundStream=void 0,this._rawInboundStream=void 0,this.inboundStream=void 0,this.dispatchEvent(new CustomEvent("close")))}};function ca(){return BigInt(`0x${j(Gr(8),"base16")}`)}var ua=(r,t)=>{let e=G(t.toString(16).padStart(16,"0"),"base16"),n=Ot(r),o=new Uint8Array(n.byteLength+e.length);return o.set(n,0),o.set(e,n.byteLength),o},fa=r=>ae.encode(r);var la=function(r){return Array.isArray(r)?r:[r]},hf=async r=>{if(r.sequenceNumber==null||r.from==null||r.signature==null)return!1;let t=fr(Wt(r.from));if(t.publicKey!=null)return!0;if(r.key!=null){let e=r.key;return Fo(zo(e)).equals(t)}return!1},ha=async r=>{if(r.from==null)throw new Q("RPC message was missing from");if(!await hf(r))return{type:"unsigned",topic:r.topic??"",data:r.data??new Uint8Array(0)};let t=fr(Wt(r.from)),e=r.key??t.publicKey;if(e==null)throw new Q("RPC message was missing public key");return{type:"signed",from:t,topic:r.topic??"",sequenceNumber:pf(r.sequenceNumber??new Uint8Array(0)),data:r.data??new Uint8Array(0),signature:r.signature??new Uint8Array(0),key:e instanceof Uint8Array?zo(e):e}},wr=r=>r.type==="signed"?{from:r.from.toMultihash().bytes,data:r.data,sequenceNumber:df(r.sequenceNumber),topic:r.topic,signature:r.signature,key:r.key?Ot(r.key):void 0}:{data:r.data,topic:r.topic},df=r=>{let t=r.toString(16);return t.length%2!==0&&(t=`0${t}`),G(t,"base16")},pf=r=>BigInt(`0x${j(r,"base16")}`);var da=G("libp2p-pubsub:");async function pa(r,t,e){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:Yi(r)},o=ie([da,e(wr(n)).subarray()]);return n.signature=await r.sign(o),n.key=r.publicKey,n}async function ma(r,t){if(r.type!=="signed")throw new Error('Message type must be "signed" to be verified');if(r.signature==null)throw new Error("Message must contain a signature to be verified");if(r.from==null)throw new Error("Message must contain a from property to be verified");let e=ie([da,t({...wr(r),signature:void 0,key:void 0}).subarray()]);return mf(r).verify(e,r.signature)}function mf(r){if(r.type!=="signed")throw new Error('Message type must be "signed" to have a public key');if(r.from==null)throw new Error("Could not get the public key from the originator id");if(r.key!=null)return r.key;if(r.from.publicKey!=null)return r.from.publicKey;throw new Error("Could not get the public key from the originator id")}var ts=class extends Ee{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;multicodecs;components;_registrarTopologyIds;enabled;maxInboundStreams;maxOutboundStreams;constructor(t,e){super();let{multicodecs:n=[],globalSignaturePolicy:o="StrictSign",canRelayMessage:s=!1,emitSelf:i=!1,messageProcessingConcurrency:c=10,maxInboundStreams:a=1,maxOutboundStreams:l=1}=e;this.log=t.logger.forComponent("libp2p:pubsub"),this.components=t,this.multicodecs=la(n),this.enabled=e.enabled!==!1,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new lr,this.globalSignaturePolicy=o==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=s,this.emitSelf=i,this.topicValidators=new Map,this.queue=new br({concurrency:c}),this.maxInboundStreams=a,this.maxOutboundStreams=l,this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}async start(){if(this.started||!this.enabled)return;this.log("starting");let t=this.components.registrar;await Promise.all(this.multicodecs.map(async n=>{await t.handle(n,this._onIncomingStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams})}));let e={onConnect:this._onPeerConnected,onDisconnect:this._onPeerDisconnected};this._registrarTopologyIds=await Promise.all(this.multicodecs.map(async n=>t.register(n,e))),this.log("started"),this.started=!0}async stop(){if(!this.started||!this.enabled)return;let t=this.components.registrar;this._registrarTopologyIds!=null&&this._registrarTopologyIds?.forEach(e=>{t.unregister(e)}),await Promise.all(this.multicodecs.map(async e=>{await t.unhandle(e)})),this.log("stopping");for(let e of this.peers.values())e.close();this.peers.clear(),this.subscriptions=new Set,this.started=!1,this.log("stopped")}isStarted(){return this.started}_onIncomingStream(t){let{stream:e,connection:n}=t,o=n.remotePeer;if(e.protocol==null){e.abort(new Error("Stream was not multiplexed"));return}let s=this.addPeer(o,e.protocol),i=s.attachInboundStream(e);this.processMessages(o,i,s).catch(c=>{this.log(c)})}_onPeerConnected(t,e){if(this.log("connected %p",t),e.streams.find(n=>n.direction==="outbound"&&n.protocol!=null&&this.multicodecs.includes(n.protocol))!=null){this.log("outbound pubsub streams already present on connection from %p",t);return}Promise.resolve().then(async()=>{try{let n=await e.newStream(this.multicodecs);if(n.protocol==null){n.abort(new Error("Stream was not multiplexed"));return}await this.addPeer(t,n.protocol).attachOutboundStream(n)}catch(n){this.log.error(n)}this.send(t,{subscriptions:Array.from(this.subscriptions).map(n=>n.toString()),subscribe:!0})}).catch(n=>{this.log.error(n)})}_onPeerDisconnected(t,e){this.log("connection ended %p",t),this._removePeer(t)}addPeer(t,e){let n=this.peers.get(t);if(n!=null)return n;this.log("new peer %p",t);let o=new un(this.components,{id:t,protocol:e});return this.peers.set(t,o),o.addEventListener("close",()=>this._removePeer(t),{once:!0}),o}_removePeer(t){let e=this.peers.get(t);if(e!=null){e.close(),this.log("delete peer %p",t),this.peers.delete(t);for(let n of this.topics.values())n.delete(t);return e}}async processMessages(t,e,n){try{await dr(e,async o=>{for await(let s of o){let i=this.decodeRpc(s),c=[];for(let a of i.messages??[]){if(a.from==null||a.data==null||a.topic==null){this.log("message from %p was missing from, data or topic fields, dropping",t);continue}c.push({from:a.from,data:a.data,topic:a.topic,sequenceNumber:a.sequenceNumber??void 0,signature:a.signature??void 0,key:a.key??void 0})}this.processRpc(t,n,{subscriptions:(i.subscriptions??[]).map(a=>({subscribe:!!a.subscribe,topic:a.topic??""})),messages:c}).catch(a=>{this.log(a)})}})}catch(o){this._onPeerDisconnected(n.id,o)}}async processRpc(t,e,n){if(!this.acceptFrom(t))return this.log("received message from unacceptable peer %p",t),!1;this.log("rpc from %p",t);let{subscriptions:o,messages:s}=n;return o!=null&&o.length>0&&(this.log("subscription update from %p",t),o.forEach(i=>{this.processRpcSubOpt(t,i)}),super.dispatchEvent(new CustomEvent("subscription-change",{detail:{peerId:e.id,subscriptions:o.map(({topic:i,subscribe:c})=>({topic:`${i??""}`,subscribe:!!c}))}}))),s!=null&&s.length>0&&(this.log("messages from %p",t),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 c=await ha(i);await this.processMessage(t,c)}catch(c){this.log.error(c)}})).catch(i=>{this.log(i)})),!0}processRpcSubOpt(t,e){let n=e.topic;if(n==null)return;let o=this.topics.get(n);o==null&&(o=new hr,this.topics.set(n,o)),e.subscribe===!0?o.add(t):o.delete(t)}async processMessage(t,e){if(!(this.components.peerId.equals(t)&&!this.emitSelf)){try{await this.validate(t,e)}catch(n){this.log("Message is invalid, dropping it. %O",n);return}this.subscriptions.has(e.topic)&&(!this.components.peerId.equals(t)||this.emitSelf)&&super.dispatchEvent(new CustomEvent("message",{detail:e})),await this.publishMessage(t,e)}}getMsgId(t){switch(this.globalSignaturePolicy){case"StrictSign":if(t.type!=="signed")throw new Q('Message type should be "signed" when signature policy is StrictSign but it was not');if(t.sequenceNumber==null)throw new Q("Need sequence number when signature policy is StrictSign but it was missing");if(t.key==null)throw new Q("Need key when signature policy is StrictSign but it was missing");return ua(t.key,t.sequenceNumber);case"StrictNoSign":return fa(t.data);default:throw new Q("Cannot get message id: unhandled signature policy")}}acceptFrom(t){return!0}send(t,e){let{messages:n,subscriptions:o,subscribe:s}=e;this.sendRpc(t,{subscriptions:(o??[]).map(i=>({topic:i,subscribe:!!s})),messages:(n??[]).map(wr)})}sendRpc(t,e){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}if(!n.isWritable){this.log.error("Cannot send RPC to %p as there is no outbound stream to it available",t);return}n.write(this.encodeRpc(e))}async validate(t,e){switch(this.globalSignaturePolicy){case"StrictNoSign":if(e.type!=="unsigned")throw new Q('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(e.signature!=null)throw new Q("StrictNoSigning: signature should not be present");if(e.key!=null)throw new Q("StrictNoSigning: key should not be present");if(e.sequenceNumber!=null)throw new Q("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(e.type!=="signed")throw new Q('Message type should be "signed" when signature policy is StrictSign but it was not');if(e.signature==null)throw new Q("StrictSigning: Signing required and no signature was present");if(e.sequenceNumber==null)throw new Q("StrictSigning: Signing required and no sequenceNumber was present");if(!await ma(e,this.encodeMessage.bind(this)))throw new Q("StrictSigning: Invalid message signature");break;default:throw new Q("Cannot validate message: unhandled signature policy")}let o=this.topicValidators.get(e.topic);if(o!=null){let s=await o(t,e);if(s===He.Reject||s===He.Ignore)throw new Q("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 Q("Cannot build message: unhandled signature policy")}}getSubscribers(t){if(!this.started)throw new vr("not started yet");if(t==null)throw new W("Topic is required");let e=this.topics.get(t.toString());return e==null?[]:Array.from(e.values())}async publish(t,e){if(!this.started)throw new Error("Pubsub has not started");let n={from:this.components.peerId,topic:t,data:e??new Uint8Array(0),sequenceNumber:ca()};this.log("publish topic: %s from: %p data: %m",t,n.from,n.data);let o=await this.buildMessage(n),s=!1;this.emitSelf&&this.subscriptions.has(t)&&(s=!0,super.dispatchEvent(new CustomEvent("message",{detail:o})));let i=await this.publishMessage(this.components.peerId,o);return s&&(i.recipients=[...i.recipients,this.components.peerId]),i}subscribe(t){if(!this.started)throw new Error("Pubsub has not started");if(this.log("subscribe to topic: %s",t),!this.subscriptions.has(t)){this.subscriptions.add(t);for(let e of this.peers.keys())this.send(e,{subscriptions:[t],subscribe:!0})}}unsubscribe(t){if(!this.started)throw new Error("Pubsub is not started");super.removeEventListener(t);let e=this.subscriptions.has(t);if(this.log("unsubscribe from %s - am subscribed %s",t,e),e){this.subscriptions.delete(t);for(let n of this.peers.keys())this.send(n,{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())}};return _a(yf);})();
|
2
|
+
"use strict";var Libp2PPubsub=(()=>{var wa=Object.create;var Er=Object.defineProperty;var Ea=Object.getOwnPropertyDescriptor;var Sa=Object.getOwnPropertyNames;var va=Object.getPrototypeOf,Aa=Object.prototype.hasOwnProperty;var Ia=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),xt=(r,t)=>{for(var e in t)Er(r,e,{get:t[e],enumerable:!0})},rs=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Sa(t))!Aa.call(r,o)&&o!==e&&Er(r,o,{get:()=>t[o],enumerable:!(n=Ea(t,o))||n.enumerable});return r};var Ba=(r,t,e)=>(e=r!=null?wa(va(r)):{},rs(t||!r||!r.__esModule?Er(e,"default",{value:r,enumerable:!0}):e,r)),_a=r=>rs(Er({},"__esModule",{value:!0}),r);var ea=Ia((V0,Yo)=>{"use strict";var uf=Object.prototype.hasOwnProperty,bt="~";function pr(){}Object.create&&(pr.prototype=Object.create(null),new pr().__proto__||(bt=!1));function ff(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function ta(r,t,e,n,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var s=new ff(e,n||r,o),i=bt?bt+t:t;return r._events[i]?r._events[i].fn?r._events[i]=[r._events[i],s]:r._events[i].push(s):(r._events[i]=s,r._eventsCount++),r}function en(r,t){--r._eventsCount===0?r._events=new pr:delete r._events[t]}function pt(){this._events=new pr,this._eventsCount=0}pt.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)uf.call(e,n)&&t.push(bt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};pt.prototype.listeners=function(t){var e=bt?bt+t:t,n=this._events[e];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,s=n.length,i=new Array(s);o<s;o++)i[o]=n[o].fn;return i};pt.prototype.listenerCount=function(t){var e=bt?bt+t:t,n=this._events[e];return n?n.fn?1:n.length:0};pt.prototype.emit=function(t,e,n,o,s,i){var c=bt?bt+t:t;if(!this._events[c])return!1;var a=this._events[c],l=arguments.length,u,f;if(a.fn){switch(a.once&&this.removeListener(t,a.fn,void 0,!0),l){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,e),!0;case 3:return a.fn.call(a.context,e,n),!0;case 4:return a.fn.call(a.context,e,n,o),!0;case 5:return a.fn.call(a.context,e,n,o,s),!0;case 6:return a.fn.call(a.context,e,n,o,s,i),!0}for(f=1,u=new Array(l-1);f<l;f++)u[f-1]=arguments[f];a.fn.apply(a.context,u)}else{var b=a.length,v;for(f=0;f<b;f++)switch(a[f].once&&this.removeListener(t,a[f].fn,void 0,!0),l){case 1:a[f].fn.call(a[f].context);break;case 2:a[f].fn.call(a[f].context,e);break;case 3:a[f].fn.call(a[f].context,e,n);break;case 4:a[f].fn.call(a[f].context,e,n,o);break;default:if(!u)for(v=1,u=new Array(l-1);v<l;v++)u[v-1]=arguments[v];a[f].fn.apply(a[f].context,u)}}return!0};pt.prototype.on=function(t,e,n){return ta(this,t,e,n,!1)};pt.prototype.once=function(t,e,n){return ta(this,t,e,n,!0)};pt.prototype.removeListener=function(t,e,n,o){var s=bt?bt+t:t;if(!this._events[s])return this;if(!e)return en(this,s),this;var i=this._events[s];if(i.fn)i.fn===e&&(!o||i.once)&&(!n||i.context===n)&&en(this,s);else{for(var c=0,a=[],l=i.length;c<l;c++)(i[c].fn!==e||o&&!i[c].once||n&&i[c].context!==n)&&a.push(i[c]);a.length?this._events[s]=a.length===1?a[0]:a:en(this,s)}return this};pt.prototype.removeAllListeners=function(t){var e;return t?(e=bt?bt+t:t,this._events[e]&&en(this,e)):(this._events=new pr,this._eventsCount=0),this};pt.prototype.off=pt.prototype.removeListener;pt.prototype.addListener=pt.prototype.on;pt.prefixed=bt;pt.EventEmitter=pt;typeof Yo<"u"&&(Yo.exports=pt)});var bf={};xt(bf,{PubSubBaseProtocol:()=>ts});var fn=Symbol.for("@libp2p/peer-id");var He;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(He||(He={}));var wf=Symbol.for("@libp2p/pubsub");var W=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},we=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Sr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Q=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 se=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Ee=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==e),this.#t.set(t,o))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var mn={};xt(mn,{base58btc:()=>X,base58flickr:()=>Na});var Af=new Uint8Array(0);function ns(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Ut(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function os(r){return new TextEncoder().encode(r)}function ss(r){return new TextDecoder().decode(r)}function La(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var c=r.length,a=r.charAt(0),l=Math.log(c)/Math.log(256),u=Math.log(256)/Math.log(c);function f(I){if(I instanceof Uint8Array||(ArrayBuffer.isView(I)?I=new Uint8Array(I.buffer,I.byteOffset,I.byteLength):Array.isArray(I)&&(I=Uint8Array.from(I))),!(I instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(I.length===0)return"";for(var m=0,A=0,P=0,M=I.length;P!==M&&I[P]===0;)P++,m++;for(var x=(M-P)*u+1>>>0,h=new Uint8Array(x);P!==M;){for(var y=I[P],B=0,_=x-1;(y!==0||B<A)&&_!==-1;_--,B++)y+=256*h[_]>>>0,h[_]=y%c>>>0,y=y/c>>>0;if(y!==0)throw new Error("Non-zero carry");A=B,P++}for(var L=x-A;L!==x&&h[L]===0;)L++;for(var N=a.repeat(m);L<x;++L)N+=r.charAt(h[L]);return N}function b(I){if(typeof I!="string")throw new TypeError("Expected String");if(I.length===0)return new Uint8Array;var m=0;if(I[m]!==" "){for(var A=0,P=0;I[m]===a;)A++,m++;for(var M=(I.length-m)*l+1>>>0,x=new Uint8Array(M);I[m];){var h=e[I.charCodeAt(m)];if(h===255)return;for(var y=0,B=M-1;(h!==0||y<P)&&B!==-1;B--,y++)h+=c*x[B]>>>0,x[B]=h%256>>>0,h=h/256>>>0;if(h!==0)throw new Error("Non-zero carry");P=y,m++}if(I[m]!==" "){for(var _=M-P;_!==M&&x[_]===0;)_++;for(var L=new Uint8Array(A+(M-_)),N=A;_!==M;)L[N++]=x[_++];return L}}}function v(I){var m=b(I);if(m)return m;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:b,decode:v}}var Ta=La,Pa=Ta,as=Pa;var ln=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},hn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return cs(this,t)}},dn=class{decoders;constructor(t){this.decoders=t}or(t){return cs(this,t)}decode(t){let e=t[0],n=this.decoders[e];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 cs(r,t){return new dn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var pn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new ln(t,e,n),this.decoder=new hn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Se({name:r,prefix:t,encode:e,decode:n}){return new pn(r,t,e,n)}function Yt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=as(e,r);return Se({prefix:t,name:r,encode:n,decode:s=>Ut(o(s))})}function Ca(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,c=0,a=0;for(let l=0;l<o;++l){let u=t[r[l]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|u,i+=e,i>=8&&(i-=8,s[a++]=255&c>>i)}if(i>=e||(255&c<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Da(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,c=0;for(let a=0;a<r.length;++a)for(c=c<<8|r[a],i+=8;i>e;)i-=e,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Ra(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function $({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=Ra(n);return Se({prefix:t,name:r,encode(s){return Da(s,n,e)},decode(s){return Ca(s,o,e,r)}})}var X=Yt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Na=Yt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var yn={};xt(yn,{base32:()=>ve,base32hex:()=>Oa,base32hexpad:()=>qa,base32hexpadupper:()=>Ha,base32hexupper:()=>Ma,base32pad:()=>Ka,base32padupper:()=>ka,base32upper:()=>Ua,base32z:()=>Va});var ve=$({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ua=$({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ka=$({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ka=$({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Oa=$({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ma=$({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),qa=$({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ha=$({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Va=$({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var bn={};xt(bn,{base36:()=>Ve,base36upper:()=>za});var Ve=Yt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),za=Yt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Fa=ls,us=128,Ga=127,ja=~Ga,Za=Math.pow(2,31);function ls(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Za;)t[e++]=r&255|us,r/=128;for(;r&ja;)t[e++]=r&255|us,r>>>=7;return t[e]=r|0,ls.bytes=e-n+1,t}var Ya=gn,Wa=128,fs=127;function gn(r,n){var e=0,n=n||0,o=0,s=n,i,c=r.length;do{if(s>=c)throw gn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&fs)<<o:(i&fs)*Math.pow(2,o),o+=7}while(i>=Wa);return gn.bytes=s-n,e}var Xa=Math.pow(2,7),$a=Math.pow(2,14),Ja=Math.pow(2,21),Qa=Math.pow(2,28),tc=Math.pow(2,35),ec=Math.pow(2,42),rc=Math.pow(2,49),nc=Math.pow(2,56),oc=Math.pow(2,63),sc=function(r){return r<Xa?1:r<$a?2:r<Ja?3:r<Qa?4:r<tc?5:r<ec?6:r<rc?7:r<nc?8:r<oc?9:10},ic={encode:Fa,decode:Ya,encodingLength:sc},ac=ic,ze=ac;function Fe(r,t=0){return[ze.decode(r,t),ze.decode.bytes]}function Ae(r,t,e=0){return ze.encode(r,t,e),t}function Ie(r){return ze.encodingLength(r)}function Bt(r,t){let e=t.byteLength,n=Ie(r),o=n+Ie(e),s=new Uint8Array(o+e);return Ae(r,s,0),Ae(e,s,n),s.set(t,o),new Be(r,e,t,s)}function Wt(r){let t=Ut(r),[e,n]=Fe(t),[o,s]=Fe(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Be(e,o,i,t)}function hs(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ns(r.bytes,e.bytes)}}var Be=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function ds(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return uc(e,xn(r),t??X.encoder);default:return fc(e,xn(r),t??ve.encoder)}}var ps=new WeakMap;function xn(r){let t=ps.get(r);if(t==null){let e=new Map;return ps.set(r,e),e}return t}var ft=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==Ge)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==lc)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}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:e}=this.multihash,n=Bt(t,e);return r.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 r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&hs(t.multihash,n.multihash)}toString(t){return ds(this,t)}toJSON(){return{"/":ds(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 e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??ms(n,o,s.bytes))}else if(e[hc]===!0){let{version:n,multihash:o,code:s}=e,i=Wt(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="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(e!==Ge)throw new Error(`Version 0 CID must use dag-pb (code: ${Ge}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=ms(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Ge,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Ut(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new Be(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[f,b]=Fe(t.subarray(e));return e+=b,f},o=n(),s=Ge;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,c=n(),a=n(),l=e+a,u=l-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:u,size:l}}static parse(t,e){let[n,o]=cc(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return xn(s).set(n,t),s}};function cc(r,t){switch(r[0]){case"Q":{let e=t??X;return[X.prefix,e.decode(`${X.prefix}${r}`)]}case X.prefix:{let e=t??X;return[X.prefix,e.decode(r)]}case ve.prefix:{let e=t??ve;return[ve.prefix,e.decode(r)]}case Ve.prefix:{let e=t??Ve;return[Ve.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function uc(r,t,e){let{prefix:n}=e;if(n!==X.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function fc(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var Ge=112,lc=18;function ms(r,t,e){let n=Ie(r),o=n+Ie(t),s=new Uint8Array(o+e.byteLength);return Ae(r,s,0),Ae(t,s,n),s.set(e,o),s}var hc=Symbol.for("@ipld/js-cid/CID");var wn={};xt(wn,{identity:()=>_t});var ys=0,dc="identity",bs=Ut;function pc(r){return Bt(ys,bs(r))}var _t={code:ys,name:dc,encode:bs,digest:pc};function wt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Kt(r=0){return new Uint8Array(r)}function lt(r=0){return new Uint8Array(r)}function ie(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=lt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var xs=Symbol.for("@achingbrain/uint8arraylist");function gs(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function Ir(r){return!!r?.[xs]}var nt=class r{bufs;length;[xs]=!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 e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Ir(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Ir(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=gs(this.bufs,t);return e.buf[e.index]}set(t,e){let n=gs(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Ir(t))for(let n=0;n<t.length;n++)this.set(e+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,e){let{bufs:n,length:o}=this._subList(t,e);return ie(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:ie(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let l=t>=c&&t<a,u=e>c&&e<=a;if(l&&u){if(t===c&&e===a){n.push(i);break}let f=t-c;n.push(i.subarray(f,f+(e-t)));break}if(l){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(u){if(e===a){n.push(i);break}n.push(i.subarray(0,e-c));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Ir(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(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let c=i,a=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let f=e;f<=a;f+=u){u=0;for(let b=l;b>=0;b--){let v=this.get(f+b);if(n[b]!==v){u=Math.max(1,b-c[v]);break}}if(u===0)return f}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=lt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=Kt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=Kt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=Kt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=lt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=Kt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=Kt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=Kt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=Kt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=Kt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!wt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var En={};xt(En,{base10:()=>mc});var mc=Yt({prefix:"9",name:"base10",alphabet:"0123456789"});var Sn={};xt(Sn,{base16:()=>yc,base16upper:()=>bc});var yc=$({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),bc=$({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var vn={};xt(vn,{base2:()=>gc});var gc=$({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var An={};xt(An,{base256emoji:()=>vc});var ws=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}"),xc=ws.reduce((r,t,e)=>(r[e]=t,r),[]),wc=ws.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Ec(r){return r.reduce((t,e)=>(t+=xc[e],t),"")}function Sc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=wc[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var vc=Se({prefix:"\u{1F680}",name:"base256emoji",encode:Ec,decode:Sc});var In={};xt(In,{base64:()=>Ac,base64pad:()=>Ic,base64url:()=>Bc,base64urlpad:()=>_c});var Ac=$({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ic=$({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Bc=$({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),_c=$({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Bn={};xt(Bn,{base8:()=>Lc});var Lc=$({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var _n={};xt(_n,{identity:()=>Tc});var Tc=Se({prefix:"\0",name:"identity",encode:r=>ss(r),decode:r=>os(r)});var al=new TextEncoder,cl=new TextDecoder;var Pn={};xt(Pn,{sha256:()=>ae,sha512:()=>Dc});function Tn({name:r,code:t,encode:e}){return new Ln(r,t,e)}var Ln=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?Bt(this.code,e):e.then(n=>Bt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Ss(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var ae=Tn({name:"sha2-256",code:18,encode:Ss("SHA-256")}),Dc=Tn({name:"sha2-512",code:19,encode:Ss("SHA-512")});var Cn={..._n,...vn,...Bn,...En,...Sn,...yn,...bn,...mn,...In,...An},wl={...Pn,...wn};function As(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var vs=As("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Dn=As("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=lt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Rc={utf8:vs,"utf-8":vs,hex:Cn.base16,latin1:Dn,ascii:Dn,binary:Dn,...Cn},Br=Rc;function G(r,t="utf8"){let e=Br[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function j(r,t="utf8"){let e=Br[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Nc=parseInt("11111",2),Rn=parseInt("10000000",2),Uc=parseInt("01111111",2),Is={0:je,1:je,2:Kc,3:Mc,4:qc,5:Oc,6:kc,16:je,22:je,48:je};function kt(r,t={offset:0}){let e=r[t.offset]&Nc;if(t.offset++,Is[e]!=null)return Is[e](r,t);throw new Error("No decoder for tag "+e)}function Ze(r,t){let e=0;if((r[t.offset]&Rn)===Rn){let n=r[t.offset]&Uc,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function je(r,t){Ze(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=kt(r,t);if(n===null)break;e.push(n)}return e}function Kc(r,t){let e=Ze(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function kc(r,t){let e=Ze(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let c=`${s}.${i}`,a=[];for(;t.offset<n;){let l=r[t.offset];if(t.offset++,a.push(l&127),l<128){a.reverse();let u=0;for(let f=0;f<a.length;f++)u+=a[f]<<f*7;c+=`.${u}`,a=[]}}return c}function Oc(r,t){return t.offset++,null}function Mc(r,t){let e=Ze(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function qc(r,t){let e=Ze(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Hc(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new nt;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Nn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Hc(r.byteLength);return new nt(Uint8Array.from([t.byteLength|Rn]),t)}function Et(r){let t=new nt,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new nt(Uint8Array.from([2]),Nn(t),t)}function _r(r){let t=Uint8Array.from([0]),e=new nt(t,r);return new nt(Uint8Array.from([3]),Nn(e),e)}function $t(r,t=48){let e=new nt;for(let n of r)e.append(n);return new nt(Uint8Array.from([t]),Nn(e),e)}async function Bs(r,t,e){let n=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);return crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},n,t,e.subarray())}var Vc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),zc=Uint8Array.from([6,5,43,129,4,0,34]),Fc=Uint8Array.from([6,5,43,129,4,0,35]),Gc={ext:!0,kty:"EC",crv:"P-256"},jc={ext:!0,kty:"EC",crv:"P-384"},Zc={ext:!0,kty:"EC",crv:"P-521"},Un=32,Kn=48,kn=66;function On(r){let t=kt(r);return _s(t)}function _s(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===Un*2+1)return n=j(t.subarray(e,e+Un),"base64url"),o=j(t.subarray(e+Un),"base64url"),new _e({...Gc,key_ops:["verify"],x:n,y:o});if(t.byteLength===Kn*2+1)return n=j(t.subarray(e,e+Kn),"base64url"),o=j(t.subarray(e+Kn),"base64url"),new _e({...jc,key_ops:["verify"],x:n,y:o});if(t.byteLength===kn*2+1)return n=j(t.subarray(e,e+kn),"base64url"),o=j(t.subarray(e+kn),"base64url"),new _e({...Zc,key_ops:["verify"],x:n,y:o});throw new W(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Ls(r){return $t([Et(Uint8Array.from([1])),$t([Yc(r.crv)],160),$t([_r(new nt(Uint8Array.from([4]),G(r.x??"","base64url"),G(r.y??"","base64url")))],161)]).subarray()}function Yc(r){if(r==="P-256")return Vc;if(r==="P-384")return zc;if(r==="P-521")return Fc;throw new W(`Invalid curve ${r}`)}var _e=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Ls(this.jwk)),this._raw}toMultihash(){return _t.digest(Ot(this))}toCID(){return ft.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:wt(this.raw,t.raw)}async verify(t,e){return Bs(this.jwk,e,t)}};var ce=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Wc(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Lr(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function ue(r,...t){if(!Wc(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error("Uint8Array expected of length "+t+", got length="+r.length)}function Ts(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Lr(r.outputLen),Lr(r.blockLen)}function Te(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function Ps(r,t){ue(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}function Mt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Tr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Lt(r,t){return r<<32-t|r>>>t}function Cs(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function Ye(r){return typeof r=="string"&&(r=Cs(r)),ue(r),r}function Mn(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];ue(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}var Le=class{};function qn(r){let t=n=>r().update(Ye(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Pe(r=32){if(ce&&typeof ce.getRandomValues=="function")return ce.getRandomValues(new Uint8Array(r));if(ce&&typeof ce.randomBytes=="function")return Uint8Array.from(ce.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function Xc(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(e>>o&s),c=Number(e&s),a=n?4:0,l=n?0:4;r.setUint32(t+a,i,n),r.setUint32(t+l,c,n)}function Ds(r,t,e){return r&t^~r&e}function Rs(r,t,e){return r&t^r&e^t&e}var We=class extends Le{constructor(t,e,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Tr(this.buffer)}update(t){Te(this),t=Ye(t),ue(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=Tr(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Te(this),Ps(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Mt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)e[f]=0;Xc(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=Tr(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=a/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)c.setUint32(4*f,u[f],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},qt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ct=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Pr=BigInt(4294967295),Ns=BigInt(32);function $c(r,t=!1){return t?{h:Number(r&Pr),l:Number(r>>Ns&Pr)}:{h:Number(r>>Ns&Pr)|0,l:Number(r&Pr)|0}}function Us(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:c}=$c(r[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var Hn=(r,t,e)=>r>>>e,Vn=(r,t,e)=>r<<32-e|t>>>e,fe=(r,t,e)=>r>>>e|t<<32-e,le=(r,t,e)=>r<<32-e|t>>>e,Xe=(r,t,e)=>r<<64-e|t>>>e-32,$e=(r,t,e)=>r>>>e-32|t<<64-e;function Ct(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Ks=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),ks=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Os=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Ms=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,qs=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Hs=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Qc=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]),Jt=new Uint32Array(64),Cr=class extends We{constructor(t=32){super(64,t,8,!1),this.A=qt[0]|0,this.B=qt[1]|0,this.C=qt[2]|0,this.D=qt[3]|0,this.E=qt[4]|0,this.F=qt[5]|0,this.G=qt[6]|0,this.H=qt[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,e,n,o,s,i,c,a]}set(t,e,n,o,s,i,c,a){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(t,e){for(let f=0;f<16;f++,e+=4)Jt[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let b=Jt[f-15],v=Jt[f-2],I=Lt(b,7)^Lt(b,18)^b>>>3,m=Lt(v,17)^Lt(v,19)^v>>>10;Jt[f]=m+Jt[f-7]+I+Jt[f-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:l,H:u}=this;for(let f=0;f<64;f++){let b=Lt(c,6)^Lt(c,11)^Lt(c,25),v=u+b+Ds(c,a,l)+Qc[f]+Jt[f]|0,m=(Lt(n,2)^Lt(n,13)^Lt(n,22))+Rs(n,o,s)|0;u=l,l=a,a=c,c=i+v|0,i=s,s=o,o=n,n=v+m|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(n,o,s,i,c,a,l,u)}roundClean(){Mt(Jt)}destroy(){this.set(0,0,0,0,0,0,0,0),Mt(this.buffer)}};var Vs=Us(["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(r=>BigInt(r))),tu=Vs[0],eu=Vs[1],Qt=new Uint32Array(80),te=new Uint32Array(80),zn=class extends We{constructor(t=64){super(128,t,16,!1),this.Ah=ct[0]|0,this.Al=ct[1]|0,this.Bh=ct[2]|0,this.Bl=ct[3]|0,this.Ch=ct[4]|0,this.Cl=ct[5]|0,this.Dh=ct[6]|0,this.Dl=ct[7]|0,this.Eh=ct[8]|0,this.El=ct[9]|0,this.Fh=ct[10]|0,this.Fl=ct[11]|0,this.Gh=ct[12]|0,this.Gl=ct[13]|0,this.Hh=ct[14]|0,this.Hl=ct[15]|0}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:l,El:u,Fh:f,Fl:b,Gh:v,Gl:I,Hh:m,Hl:A}=this;return[t,e,n,o,s,i,c,a,l,u,f,b,v,I,m,A]}set(t,e,n,o,s,i,c,a,l,u,f,b,v,I,m,A){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=l|0,this.El=u|0,this.Fh=f|0,this.Fl=b|0,this.Gh=v|0,this.Gl=I|0,this.Hh=m|0,this.Hl=A|0}process(t,e){for(let x=0;x<16;x++,e+=4)Qt[x]=t.getUint32(e),te[x]=t.getUint32(e+=4);for(let x=16;x<80;x++){let h=Qt[x-15]|0,y=te[x-15]|0,B=fe(h,y,1)^fe(h,y,8)^Hn(h,y,7),_=le(h,y,1)^le(h,y,8)^Vn(h,y,7),L=Qt[x-2]|0,N=te[x-2]|0,k=fe(L,N,19)^Xe(L,N,61)^Hn(L,N,6),C=le(L,N,19)^$e(L,N,61)^Vn(L,N,6),U=Os(_,C,te[x-7],te[x-16]),R=Ms(U,B,k,Qt[x-7],Qt[x-16]);Qt[x]=R|0,te[x]=U|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:l,Dl:u,Eh:f,El:b,Fh:v,Fl:I,Gh:m,Gl:A,Hh:P,Hl:M}=this;for(let x=0;x<80;x++){let h=fe(f,b,14)^fe(f,b,18)^Xe(f,b,41),y=le(f,b,14)^le(f,b,18)^$e(f,b,41),B=f&v^~f&m,_=b&I^~b&A,L=qs(M,y,_,eu[x],te[x]),N=Hs(L,P,h,B,tu[x],Qt[x]),k=L|0,C=fe(n,o,28)^Xe(n,o,34)^Xe(n,o,39),U=le(n,o,28)^$e(n,o,34)^$e(n,o,39),R=n&s^n&c^s&c,et=o&i^o&a^i&a;P=m|0,M=A|0,m=v|0,A=I|0,v=f|0,I=b|0,{h:f,l:b}=Ct(l|0,u|0,N|0,k|0),l=c|0,u=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let E=Ks(k,U,et);n=ks(E,N,C,R),o=E|0}({h:n,l:o}=Ct(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ct(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=Ct(this.Ch|0,this.Cl|0,c|0,a|0),{h:l,l:u}=Ct(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:b}=Ct(this.Eh|0,this.El|0,f|0,b|0),{h:v,l:I}=Ct(this.Fh|0,this.Fl|0,v|0,I|0),{h:m,l:A}=Ct(this.Gh|0,this.Gl|0,m|0,A|0),{h:P,l:M}=Ct(this.Hh|0,this.Hl|0,P|0,M|0),this.set(n,o,s,i,c,a,l,u,f,b,v,I,m,A,P,M)}roundClean(){Mt(Qt,te)}destroy(){Mt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Dr=qn(()=>new Cr);var zs=qn(()=>new zn);var Zn=BigInt(0),jn=BigInt(1);function Ce(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Yn(r){if(!Ce(r))throw new Error("Uint8Array expected")}function Dt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function Je(r){let t=r.toString(16);return t.length&1?"0"+t:t}function js(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Zn:BigInt("0x"+r)}var Zs=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",ru=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function ee(r){if(Yn(r),Zs)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=ru[r[e]];return t}var Ht={_0:48,_9:57,A:65,F:70,a:97,f:102};function Fs(r){if(r>=Ht._0&&r<=Ht._9)return r-Ht._0;if(r>=Ht.A&&r<=Ht.F)return r-(Ht.A-10);if(r>=Ht.a&&r<=Ht.f)return r-(Ht.a-10)}function Qe(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Zs)return Uint8Array.fromHex(r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=Fs(r.charCodeAt(s)),c=Fs(r.charCodeAt(s+1));if(i===void 0||c===void 0){let a=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function Vt(r){return js(ee(r))}function he(r){return Yn(r),js(ee(Uint8Array.from(r).reverse()))}function de(r,t){return Qe(r.toString(16).padStart(t*2,"0"))}function De(r,t){return de(r,t).reverse()}function Z(r,t,e){let n;if(typeof t=="string")try{n=Qe(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Ce(t))n=Uint8Array.from(t);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(r+" of length "+e+" expected, got "+o);return n}function re(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Yn(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}var Fn=r=>typeof r=="bigint"&&Zn<=r;function Rr(r,t,e){return Fn(r)&&Fn(t)&&Fn(e)&&t<=r&&r<e}function vt(r,t,e,n){if(!Rr(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Ys(r){let t;for(t=0;r>Zn;r>>=jn,t+=1);return t}var pe=r=>(jn<<BigInt(r))-jn,Gn=r=>new Uint8Array(r),Gs=r=>Uint8Array.from(r);function Ws(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=Gn(r),o=Gn(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},c=(...f)=>e(o,n,...f),a=(f=Gn(0))=>{o=c(Gs([0]),f),n=c(),f.length!==0&&(o=c(Gs([1]),f),n=c())},l=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,b=[];for(;f<t;){n=c();let v=n.slice();b.push(v),f+=n.length}return re(...b)};return(f,b)=>{i(),a(f);let v;for(;!(v=b(l()));)a();return i(),v}}var nu={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||Ce(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function zt(r,t,e={}){let n=(o,s,i)=>{let c=nu[s];if(typeof c!="function")throw new Error("invalid validator function");let a=r[o];if(!(i&&a===void 0)&&!c(a,r))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+a)};for(let[o,s]of Object.entries(t))n(o,s,!1);for(let[o,s]of Object.entries(e))n(o,s,!0);return r}function Re(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var mt=BigInt(0),st=BigInt(1),me=BigInt(2),ou=BigInt(3),$s=BigInt(4),Js=BigInt(5),Qs=BigInt(8);function F(r,t){let e=r%t;return e>=mt?e:t+e}function Y(r,t,e){let n=r;for(;t-- >mt;)n*=n,n%=e;return n}function Nr(r,t){if(r===mt)throw new Error("invert: expected non-zero number");if(t<=mt)throw new Error("invert: expected positive modulus, got "+t);let e=F(r,t),n=t,o=mt,s=st,i=st,c=mt;for(;e!==mt;){let l=n/e,u=n%e,f=o-i*l,b=s-c*l;n=e,e=u,o=i,s=c,i=f,c=b}if(n!==st)throw new Error("invert: does not exist");return F(o,t)}function ti(r,t){let e=(r.ORDER+st)/$s,n=r.pow(t,e);if(!r.eql(r.sqr(n),t))throw new Error("Cannot find square root");return n}function su(r,t){let e=(r.ORDER-Js)/Qs,n=r.mul(t,me),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,me),o),c=r.mul(s,r.sub(i,r.ONE));if(!r.eql(r.sqr(c),t))throw new Error("Cannot find square root");return c}function iu(r){if(r<BigInt(3))throw new Error("sqrt is not defined for small field");let t=r-st,e=0;for(;t%me===mt;)t/=me,e++;let n=me,o=Ft(r);for(;Xs(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return ti;let s=o.pow(n,t),i=(t+st)/me;return function(a,l){if(a.is0(l))return l;if(Xs(a,l)!==1)throw new Error("Cannot find square root");let u=e,f=a.mul(a.ONE,s),b=a.pow(l,t),v=a.pow(l,i);for(;!a.eql(b,a.ONE);){if(a.is0(b))return a.ZERO;let I=1,m=a.sqr(b);for(;!a.eql(m,a.ONE);)if(I++,m=a.sqr(m),I===u)throw new Error("Cannot find square root");let A=st<<BigInt(u-I-1),P=a.pow(f,A);u=I,f=a.sqr(P),b=a.mul(b,f),v=a.mul(v,P)}return v}}function au(r){return r%$s===ou?ti:r%Qs===Js?su:iu(r)}var ei=(r,t)=>(F(r,t)&st)===st,cu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Wn(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=cu.reduce((n,o)=>(n[o]="function",n),t);return zt(r,e)}function uu(r,t,e){if(e<mt)throw new Error("invalid exponent, negatives unsupported");if(e===mt)return r.ONE;if(e===st)return t;let n=r.ONE,o=t;for(;e>mt;)e&st&&(n=r.mul(n,o)),o=r.sqr(o),e>>=st;return n}function Ne(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,c,a)=>r.is0(c)?i:(n[a]=i,r.mul(i,c)),r.ONE),s=r.inv(o);return t.reduceRight((i,c,a)=>r.is0(c)?i:(n[a]=r.mul(i,n[a]),r.mul(i,c)),s),n}function Xs(r,t){let e=(r.ORDER-st)/me,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Xn(r,t){t!==void 0&&Lr(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Ft(r,t,e=!1,n={}){if(r<=mt)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=Xn(r,t);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let i,c=Object.freeze({ORDER:r,isLE:e,BITS:o,BYTES:s,MASK:pe(o),ZERO:mt,ONE:st,create:a=>F(a,r),isValid:a=>{if(typeof a!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof a);return mt<=a&&a<r},is0:a=>a===mt,isOdd:a=>(a&st)===st,neg:a=>F(-a,r),eql:(a,l)=>a===l,sqr:a=>F(a*a,r),add:(a,l)=>F(a+l,r),sub:(a,l)=>F(a-l,r),mul:(a,l)=>F(a*l,r),pow:(a,l)=>uu(c,a,l),div:(a,l)=>F(a*Nr(l,r),r),sqrN:a=>a*a,addN:(a,l)=>a+l,subN:(a,l)=>a-l,mulN:(a,l)=>a*l,inv:a=>Nr(a,r),sqrt:n.sqrt||(a=>(i||(i=au(r)),i(c,a))),toBytes:a=>e?De(a,s):de(a,s),fromBytes:a=>{if(a.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+a.length);return e?he(a):Vt(a)},invertBatch:a=>Ne(c,a),cmov:(a,l,u)=>u?l:a});return Object.freeze(c)}function ri(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function $n(r){let t=ri(r);return t+Math.ceil(t/2)}function ni(r,t,e=!1){let n=r.length,o=ri(t),s=$n(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?he(r):Vt(r),c=F(i,t-st)+st;return e?De(c,o):de(c,o)}var oi=BigInt(0),ro=BigInt(1);function Jn(r,t){let e=t.negate();return r?e:t}function ii(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Qn(r,t){ii(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=pe(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function si(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,c=Number(r&o),a=r>>i;c>n&&(c-=s,a+=ro);let l=t*n,u=l+Math.abs(c)-1,f=c===0,b=c<0,v=t%2!==0;return{nextN:a,offset:u,isZero:f,isNeg:b,isNegF:v,offsetF:l}}function fu(r,t){if(!Array.isArray(r))throw new Error("array expected");r.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}function lu(r,t){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}var to=new WeakMap,ai=new WeakMap;function eo(r){return ai.get(r)||1}function Ur(r,t){return{constTimeNegate:Jn,hasPrecomputes(e){return eo(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>oi;)n&ro&&(o=o.add(s)),s=s.double(),n>>=ro;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=Qn(n,t),i=[],c=e,a=c;for(let l=0;l<o;l++){a=c,i.push(a);for(let u=1;u<s;u++)a=a.add(c),i.push(a);c=a.double()}return i},wNAF(e,n,o){let s=r.ZERO,i=r.BASE,c=Qn(e,t);for(let a=0;a<c.windows;a++){let{nextN:l,offset:u,isZero:f,isNeg:b,isNegF:v,offsetF:I}=si(o,a,c);o=l,f?i=i.add(Jn(v,n[I])):s=s.add(Jn(b,n[u]))}return{p:s,f:i}},wNAFUnsafe(e,n,o,s=r.ZERO){let i=Qn(e,t);for(let c=0;c<i.windows&&o!==oi;c++){let{nextN:a,offset:l,isZero:u,isNeg:f}=si(o,c,i);if(o=a,!u){let b=n[l];s=s.add(f?b.negate():b)}}return s},getPrecomputes(e,n,o){let s=to.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&to.set(n,o(s))),s},wNAFCached(e,n,o){let s=eo(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=eo(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){ii(n,t),ai.set(e,n),to.delete(e)}}}function Kr(r,t,e,n){fu(e,r),lu(n,t);let o=e.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=r.ZERO,c=Ys(BigInt(o)),a=1;c>12?a=c-3:c>4?a=c-2:c>0&&(a=2);let l=pe(a),u=new Array(Number(l)+1).fill(i),f=Math.floor((t.BITS-1)/a)*a,b=i;for(let v=f;v>=0;v-=a){u.fill(i);for(let m=0;m<s;m++){let A=n[m],P=Number(A>>BigInt(v)&l);u[P]=u[P].add(e[m])}let I=i;for(let m=u.length-1,A=i;m>0;m--)A=A.add(u[m]),I=I.add(A);if(b=b.add(I),v!==0)for(let m=0;m<a;m++)b=b.double()}return b}function tr(r){return Wn(r.Fp),zt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Xn(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Rt=BigInt(0),yt=BigInt(1),ci=BigInt(2),hu=BigInt(8),du={zip215:!0};function pu(r){let t=tr(r);return zt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function ui(r){let t=pu(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:c,h:a}=t,l=ci<<BigInt(c*8)-yt,u=e.create,f=Ft(t.n,t.nBitLength);function b(g,d){let p=e.sqr(g),S=e.sqr(d),D=e.add(e.mul(t.a,p),S),K=e.add(e.ONE,e.mul(t.d,e.mul(p,S)));return e.eql(D,K)}if(!b(t.Gx,t.Gy))throw new Error("bad curve params: generator point");let v=t.uvRatio||((g,d)=>{try{return{isValid:!0,value:e.sqrt(g*e.inv(d))}}catch{return{isValid:!1,value:Rt}}}),I=t.adjustScalarBytes||(g=>g),m=t.domain||((g,d,p)=>{if(Dt("phflag",p),d.length||p)throw new Error("Contexts/pre-hash are not supported");return g});function A(g,d,p=!1){let S=p?yt:Rt;vt("coordinate "+g,d,S,l)}function P(g){if(!(g instanceof h))throw new Error("ExtendedPoint expected")}let M=Re((g,d)=>{let{ex:p,ey:S,ez:D}=g,K=g.is0();d==null&&(d=K?hu:e.inv(D));let O=u(p*d),q=u(S*d),H=u(D*d);if(K)return{x:Rt,y:yt};if(H!==yt)throw new Error("invZ was invalid");return{x:O,y:q}}),x=Re(g=>{let{a:d,d:p}=t;if(g.is0())throw new Error("bad point: ZERO");let{ex:S,ey:D,ez:K,et:O}=g,q=u(S*S),H=u(D*D),z=u(K*K),rt=u(z*z),J=u(q*d),at=u(z*u(J+H)),gt=u(rt+u(p*u(q*H)));if(at!==gt)throw new Error("bad point: equation left != right (1)");let ot=u(S*D),ut=u(K*O);if(ot!==ut)throw new Error("bad point: equation left != right (2)");return!0});class h{constructor(d,p,S,D){A("x",d),A("y",p),A("z",S,!0),A("t",D),this.ex=d,this.ey=p,this.ez=S,this.et=D,Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(d){if(d instanceof h)throw new Error("extended point not allowed");let{x:p,y:S}=d||{};return A("x",p),A("y",S),new h(p,S,yt,u(p*S))}static normalizeZ(d){let p=Ne(e,d.map(S=>S.ez));return d.map((S,D)=>S.toAffine(p[D])).map(h.fromAffine)}static msm(d,p){return Kr(h,f,d,p)}_setWindowSize(d){_.setWindowSize(this,d)}assertValidity(){x(this)}equals(d){P(d);let{ex:p,ey:S,ez:D}=this,{ex:K,ey:O,ez:q}=d,H=u(p*q),z=u(K*D),rt=u(S*q),J=u(O*D);return H===z&&rt===J}is0(){return this.equals(h.ZERO)}negate(){return new h(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:d}=t,{ex:p,ey:S,ez:D}=this,K=u(p*p),O=u(S*S),q=u(ci*u(D*D)),H=u(d*K),z=p+S,rt=u(u(z*z)-K-O),J=H+O,at=J-q,gt=H-O,ot=u(rt*at),ut=u(J*gt),St=u(rt*gt),It=u(at*J);return new h(ot,ut,It,St)}add(d){P(d);let{a:p,d:S}=t,{ex:D,ey:K,ez:O,et:q}=this,{ex:H,ey:z,ez:rt,et:J}=d,at=u(D*H),gt=u(K*z),ot=u(q*S*J),ut=u(O*rt),St=u((D+K)*(H+z)-at-gt),It=ut-ot,qe=ut+ot,es=u(gt-p*at),ya=u(St*It),ba=u(qe*es),ga=u(St*es),xa=u(It*qe);return new h(ya,ba,xa,ga)}subtract(d){return this.add(d.negate())}wNAF(d){return _.wNAFCached(this,d,h.normalizeZ)}multiply(d){let p=d;vt("scalar",p,yt,n);let{p:S,f:D}=this.wNAF(p);return h.normalizeZ([S,D])[0]}multiplyUnsafe(d,p=h.ZERO){let S=d;return vt("scalar",S,Rt,n),S===Rt?B:this.is0()||S===yt?this:_.wNAFCachedUnsafe(this,S,h.normalizeZ,p)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}isTorsionFree(){return _.unsafeLadder(this,n).is0()}toAffine(d){return M(this,d)}clearCofactor(){let{h:d}=t;return d===yt?this:this.multiplyUnsafe(d)}static fromHex(d,p=!1){let{d:S,a:D}=t,K=e.BYTES;d=Z("pointHex",d,K),Dt("zip215",p);let O=d.slice(),q=d[K-1];O[K-1]=q&-129;let H=he(O),z=p?l:e.ORDER;vt("pointHex.y",H,Rt,z);let rt=u(H*H),J=u(rt-yt),at=u(S*rt-D),{isValid:gt,value:ot}=v(J,at);if(!gt)throw new Error("Point.fromHex: invalid y coordinate");let ut=(ot&yt)===yt,St=(q&128)!==0;if(!p&&ot===Rt&&St)throw new Error("Point.fromHex: x=0 and x_0=1");return St!==ut&&(ot=u(-ot)),h.fromAffine({x:ot,y:H})}static fromPrivateKey(d){let{scalar:p}=k(d);return y.multiply(p)}toRawBytes(){let{x:d,y:p}=this.toAffine(),S=De(p,e.BYTES);return S[S.length-1]|=d&yt?128:0,S}toHex(){return ee(this.toRawBytes())}}h.BASE=new h(t.Gx,t.Gy,yt,u(t.Gx*t.Gy)),h.ZERO=new h(Rt,yt,yt,Rt);let{BASE:y,ZERO:B}=h,_=Ur(h,c*8);function L(g){return F(g,n)}function N(g){return L(he(g))}function k(g){let d=e.BYTES;g=Z("private key",g,d);let p=Z("hashed private key",s(g),2*d),S=I(p.slice(0,d)),D=p.slice(d,2*d),K=N(S);return{head:S,prefix:D,scalar:K}}function C(g){let{head:d,prefix:p,scalar:S}=k(g),D=y.multiply(S),K=D.toRawBytes();return{head:d,prefix:p,scalar:S,point:D,pointBytes:K}}function U(g){return C(g).pointBytes}function R(g=Uint8Array.of(),...d){let p=re(...d);return N(s(m(p,Z("context",g),!!o)))}function et(g,d,p={}){g=Z("message",g),o&&(g=o(g));let{prefix:S,scalar:D,pointBytes:K}=C(d),O=R(p.context,S,g),q=y.multiply(O).toRawBytes(),H=R(p.context,q,K,g),z=L(O+H*D);vt("signature.s",z,Rt,n);let rt=re(q,De(z,e.BYTES));return Z("result",rt,e.BYTES*2)}let E=du;function w(g,d,p,S=E){let{context:D,zip215:K}=S,O=e.BYTES;g=Z("signature",g,2*O),d=Z("message",d),p=Z("publicKey",p,O),K!==void 0&&Dt("zip215",K),o&&(d=o(d));let q=he(g.slice(O,2*O)),H,z,rt;try{H=h.fromHex(p,K),z=h.fromHex(g.slice(0,O),K),rt=y.multiplyUnsafe(q)}catch{return!1}if(!K&&H.isSmallOrder())return!1;let J=R(D,z.toRawBytes(),H.toRawBytes(),d);return z.add(H.multiplyUnsafe(J)).subtract(rt).clearCofactor().equals(h.ZERO)}return y._setWindowSize(8),{CURVE:t,getPublicKey:U,sign:et,verify:w,ExtendedPoint:h,utils:{getExtendedPublicKey:C,randomPrivateKey:()=>i(e.BYTES),precompute(g=8,d=h.BASE){return d._setWindowSize(g),d.multiply(BigInt(3)),d}}}}var no=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),fi=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),vh=BigInt(0),mu=BigInt(1),li=BigInt(2),Ah=BigInt(3),yu=BigInt(5),bu=BigInt(8);function gu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=no,c=r*r%s*r%s,a=Y(c,li,s)*c%s,l=Y(a,mu,s)*r%s,u=Y(l,yu,s)*l%s,f=Y(u,t,s)*u%s,b=Y(f,e,s)*f%s,v=Y(b,n,s)*b%s,I=Y(v,o,s)*v%s,m=Y(I,o,s)*v%s,A=Y(m,t,s)*u%s;return{pow_p_5_8:Y(A,li,s)*r%s,b2:c}}function xu(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function wu(r,t){let e=no,n=F(t*t*t,e),o=F(n*n*t,e),s=gu(r*o).pow_p_5_8,i=F(r*n*s,e),c=F(t*i*i,e),a=i,l=F(i*fi,e),u=c===r,f=c===F(-r,e),b=c===F(-r*fi,e);return u&&(i=a),(f||b)&&(i=l),ei(i,e)&&(i=F(-i,e)),{isValid:u||f,value:i}}var hi=Ft(no,void 0,!0),Eu={a:hi.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:hi,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:bu,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:zs,randomBytes:Pe,adjustScalarBytes:xu,uvRatio:wu},di=ui(Eu);var kr=32;function pi(r,t,e){return di.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var Or=class{type="Ed25519";raw;constructor(t){this.raw=oo(t,kr)}toMultihash(){return _t.digest(Ot(this))}toCID(){return ft.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:wt(this.raw,t.raw)}verify(t,e){return pi(this.raw,e,t)}};function so(r){return r=oo(r,kr),new Or(r)}function oo(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new W(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var vu=Math.pow(2,7),Au=Math.pow(2,14),Iu=Math.pow(2,21),io=Math.pow(2,28),ao=Math.pow(2,35),co=Math.pow(2,42),uo=Math.pow(2,49),V=128,ht=127;function Tt(r){if(r<vu)return 1;if(r<Au)return 2;if(r<Iu)return 3;if(r<io)return 4;if(r<ao)return 5;if(r<co)return 6;if(r<uo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function fo(r,t,e=0){switch(Tt(r)){case 8:t[e++]=r&255|V,r/=128;case 7:t[e++]=r&255|V,r/=128;case 6:t[e++]=r&255|V,r/=128;case 5:t[e++]=r&255|V,r/=128;case 4:t[e++]=r&255|V,r>>>=7;case 3:t[e++]=r&255|V,r>>>=7;case 2:t[e++]=r&255|V,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Bu(r,t,e=0){switch(Tt(r)){case 8:t.set(e++,r&255|V),r/=128;case 7:t.set(e++,r&255|V),r/=128;case 6:t.set(e++,r&255|V),r/=128;case 5:t.set(e++,r&255|V),r/=128;case 4:t.set(e++,r&255|V),r>>>=7;case 3:t.set(e++,r&255|V),r>>>=7;case 2:t.set(e++,r&255|V),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function lo(r,t){let e=r[t],n=0;if(n+=e&ht,e<V||(e=r[t+1],n+=(e&ht)<<7,e<V)||(e=r[t+2],n+=(e&ht)<<14,e<V)||(e=r[t+3],n+=(e&ht)<<21,e<V)||(e=r[t+4],n+=(e&ht)*io,e<V)||(e=r[t+5],n+=(e&ht)*ao,e<V)||(e=r[t+6],n+=(e&ht)*co,e<V)||(e=r[t+7],n+=(e&ht)*uo,e<V))return n;throw new RangeError("Could not decode varint")}function _u(r,t){let e=r.get(t),n=0;if(n+=e&ht,e<V||(e=r.get(t+1),n+=(e&ht)<<7,e<V)||(e=r.get(t+2),n+=(e&ht)<<14,e<V)||(e=r.get(t+3),n+=(e&ht)<<21,e<V)||(e=r.get(t+4),n+=(e&ht)*io,e<V)||(e=r.get(t+5),n+=(e&ht)*ao,e<V)||(e=r.get(t+6),n+=(e&ht)*co,e<V)||(e=r.get(t+7),n+=(e&ht)*uo,e<V))return n;throw new RangeError("Could not decode varint")}function yi(r,t,e=0){return t==null&&(t=lt(Tt(r))),t instanceof Uint8Array?fo(r,t,e):Bu(r,t,e)}function bi(r,t=0){return r instanceof Uint8Array?lo(r,t):_u(r,t)}var ho=new Float32Array([-0]),ne=new Uint8Array(ho.buffer);function xi(r,t,e){ho[0]=r,t[e]=ne[0],t[e+1]=ne[1],t[e+2]=ne[2],t[e+3]=ne[3]}function wi(r,t){return ne[0]=r[t],ne[1]=r[t+1],ne[2]=r[t+2],ne[3]=r[t+3],ho[0]}var po=new Float64Array([-0]),dt=new Uint8Array(po.buffer);function Ei(r,t,e){po[0]=r,t[e]=dt[0],t[e+1]=dt[1],t[e+2]=dt[2],t[e+3]=dt[3],t[e+4]=dt[4],t[e+5]=dt[5],t[e+6]=dt[6],t[e+7]=dt[7]}function Si(r,t){return dt[0]=r[t],dt[1]=r[t+1],dt[2]=r[t+2],dt[3]=r[t+3],dt[4]=r[t+4],dt[5]=r[t+5],dt[6]=r[t+6],dt[7]=r[t+7],po[0]}var Lu=BigInt(Number.MAX_SAFE_INTEGER),Tu=BigInt(Number.MIN_SAFE_INTEGER),At=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+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 e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(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,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ye;if(t<Lu&&t>Tu)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>vi&&(o=0n,++n>vi&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ye;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):ye}},ye=new At(0,0);ye.toBigInt=function(){return 0n};ye.zzEncode=ye.zzDecode=function(){return this};ye.length=function(){return 1};var vi=4294967296n;function Ai(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Ii(r,t,e){if(e-t<1)return"";let o,s=[],i=0,c;for(;t<e;)c=r[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|r[t++]&63:c>239&&c<365?(c=((c&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function mo(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function Pt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Mr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var yo=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Pt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Pt(this,4);return Mr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Pt(this,4);return Mr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Pt(this,4);let t=wi(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Pt(this,4);let t=Si(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw Pt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Ii(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Pt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Pt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new At(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*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;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw Pt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw Pt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Pt(this,8);let t=Mr(this.buf,this.pos+=4),e=Mr(this.buf,this.pos+=4);return new At(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=lo(this.buf,this.pos);return this.pos+=Tt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function bo(r){return new yo(r instanceof Uint8Array?r:r.subarray())}function qr(r,t,e){let n=bo(r);return t.decode(n,void 0,e)}function go(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return lt(i);o+i>t&&(n=lt(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var be=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function xo(){}var Eo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Pu=go();function Cu(r){return globalThis.Buffer!=null?lt(r):Pu(r)}var rr=class{len;head;tail;states;constructor(){this.len=0,this.head=new be(xo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new be(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new So((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(Hr,10,At.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=At.fromBigInt(t);return this._push(Hr,e.length(),e)}uint64Number(t){return this._push(fo,Tt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=At.fromBigInt(t).zzEncode();return this._push(Hr,e.length(),e)}sint64Number(t){let e=At.fromNumber(t).zzEncode();return this._push(Hr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(wo,1,t?1:0)}fixed32(t){return this._push(er,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=At.fromBigInt(t);return this._push(er,4,e.lo)._push(er,4,e.hi)}fixed64Number(t){let e=At.fromNumber(t);return this._push(er,4,e.lo)._push(er,4,e.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(xi,4,t)}double(t){return this._push(Ei,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(wo,1,0):this.uint32(e)._push(Ru,e,t)}string(t){let e=Ai(t);return e!==0?this.uint32(e)._push(mo,e,t):this._push(wo,1,0)}fork(){return this.states=new Eo(this),this.head=this.tail=new be(xo,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 be(xo,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Cu(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function wo(r,t,e){t[e]=r&255}function Du(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var So=class extends be{next;constructor(t,e){super(Du,t,e),this.next=void 0}};function Hr(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function er(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Ru(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(rr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Nu,t,r),this},rr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Uu,t,r),this});function Nu(r,t,e){t.set(r,e)}function Uu(r,t,e){r.length<40?mo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(G(r),e)}function vo(){return new rr}function Vr(r,t){let e=vo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Ue;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(Ue||(Ue={}));function zr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Ao(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let c=t(s);i.int32(c)},n=function(s){let i=s.int32();return t(i)};return zr("enum",Ue.VARINT,e,n)}function Fr(r,t){return zr("message",Ue.LENGTH_DELIMITED,r,t)}var tt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(tt||(tt={}));var Io;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Io||(Io={}));(function(r){r.codec=()=>Ao(Io)})(tt||(tt={}));var Nt;(function(r){let t;r.codec=()=>(t==null&&(t=Fr((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),tt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let c=e.uint32();switch(c>>>3){case 1:{s.Type=tt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Vr(e,r.codec()),r.decode=(e,n)=>qr(e,r.codec(),n)})(Nt||(Nt={}));var Bo;(function(r){let t;r.codec=()=>(t==null&&(t=Fr((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),tt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let c=e.uint32();switch(c>>>3){case 1:{s.Type=tt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Vr(e,r.codec()),r.decode=(e,n)=>qr(e,r.codec(),n)})(Bo||(Bo={}));function Gr(r){if(isNaN(r)||r<=0)throw new W("random bytes length must be a Number bigger than 0");return Pe(r)}var nr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},jr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Li={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new jr("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 oe=Li;var sr={};xt(sr,{MAX_RSA_KEY_SIZE:()=>_o,generateRSAKeyPair:()=>Di,jwkToJWKKeyPair:()=>Ri,jwkToPkcs1:()=>Mu,jwkToPkix:()=>Co,jwkToRSAPrivateKey:()=>Uo,pkcs1MessageToJwk:()=>To,pkcs1MessageToRSAPrivateKey:()=>Do,pkcs1ToJwk:()=>Ou,pkcs1ToRSAPrivateKey:()=>Ci,pkixMessageToJwk:()=>Po,pkixMessageToRSAPublicKey:()=>No,pkixToJwk:()=>qu,pkixToRSAPublicKey:()=>Ro});var Zr=Dr;var Ke=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=sr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ft.createV1(114,this._multihash)}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:wt(this.raw,t.raw)}verify(t,e){return Pi(this.jwk,e,t)}},or=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=sr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:wt(this.raw,t.raw)}sign(t){return Ti(this.jwk,t)}};var _o=8192,Lo=18,Ku=1062,ku=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Ou(r){let t=kt(r);return To(t)}function To(r){return{n:j(r[1],"base64url"),e:j(r[2],"base64url"),d:j(r[3],"base64url"),p:j(r[4],"base64url"),q:j(r[5],"base64url"),dp:j(r[6],"base64url"),dq:j(r[7],"base64url"),qi:j(r[8],"base64url"),kty:"RSA"}}function Mu(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new W("JWK was missing components");return $t([Et(Uint8Array.from([0])),Et(G(r.n,"base64url")),Et(G(r.e,"base64url")),Et(G(r.d,"base64url")),Et(G(r.p,"base64url")),Et(G(r.q,"base64url")),Et(G(r.dp,"base64url")),Et(G(r.dq,"base64url")),Et(G(r.qi,"base64url"))]).subarray()}function qu(r){let t=kt(r,{offset:0});return Po(t)}function Po(r){let t=kt(r[1],{offset:0});return{kty:"RSA",n:j(t[0],"base64url"),e:j(t[1],"base64url")}}function Co(r){if(r.n==null||r.e==null)throw new W("JWK was missing components");return $t([ku,_r($t([Et(G(r.n,"base64url")),Et(G(r.e,"base64url"))]))]).subarray()}function Ci(r){let t=kt(r);return Do(t)}function Do(r){let t=To(r);return Uo(t)}function Ro(r,t){if(r.byteLength>=Ku)throw new we("Key size is too large");let e=kt(r,{offset:0});return No(e,r,t)}function No(r,t,e){let n=Po(r);if(e==null){let o=Zr(Nt.encode({Type:tt.RSA,Data:t}));e=Bt(Lo,o)}return new Ke(n,e)}function Uo(r){if(Ui(r)>_o)throw new W("Key size is too large");let t=Ri(r),e=Zr(Nt.encode({Type:tt.RSA,Data:Co(t.publicKey)})),n=Bt(Lo,e);return new or(t.privateKey,new Ke(t.publicKey,n))}async function Di(r){if(r>_o)throw new W("Key size is too large");let t=await Ni(r),e=Zr(Nt.encode({Type:tt.RSA,Data:Co(t.publicKey)})),n=Bt(Lo,e);return new or(t.privateKey,new Ke(t.publicKey,n))}function Ri(r){if(r==null)throw new W("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function Ni(r){let t=await oe.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),e=await Hu(t);return{privateKey:e[0],publicKey:e[1]}}async function Ti(r,t){let e=await oe.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await oe.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function Pi(r,t,e){let n=await oe.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return oe.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function Hu(r){if(r.privateKey==null||r.publicKey==null)throw new W("Private and public key are required");return Promise.all([oe.get().subtle.exportKey("jwk",r.privateKey),oe.get().subtle.exportKey("jwk",r.publicKey)])}function Ui(r){if(r.kty!=="RSA")throw new W("invalid key type");if(r.n==null)throw new W("invalid key modulus");return G(r.n,"base64url").length*8}var Yr=class extends Le{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Ts(t);let n=Ye(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);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),Mt(s)}update(t){return Te(this),this.iHash.update(t),this}digestInto(t){Te(this),ue(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ko=(r,t,e)=>new Yr(r,t).update(e).digest();Ko.create=(r,t)=>new Yr(r,t);function Ki(r){r.lowS!==void 0&&Dt("lowS",r.lowS),r.prehash!==void 0&&Dt("prehash",r.prehash)}function Vu(r){let t=tr(r);zt(t,{a:"field",b:"field"},{allowInfinityPoint:"boolean",allowedPrivateKeyLengths:"array",clearCofactor:"function",fromBytes:"function",isTorsionFree:"function",toBytes:"function",wrapPrivateKey:"boolean"});let{endo:e,Fp:n,a:o}=t;if(e){if(!n.eql(o,n.ZERO))throw new Error("invalid endo: CURVE.a must be 0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function')}return Object.freeze({...t})}var Mo=class extends Error{constructor(t=""){super(t)}},Gt={Err:Mo,_tlv:{encode:(r,t)=>{let{Err:e}=Gt;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=Je(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?Je(o.length/2|128):"";return Je(r)+s+o+t},decode(r,t){let{Err:e}=Gt,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let a=o&127;if(!a)throw new e("tlv.decode(long): indefinite length not supported");if(a>4)throw new e("tlv.decode(long): byte length is too big");let l=t.subarray(n,n+a);if(l.length!==a)throw new e("tlv.decode: length bytes not complete");if(l[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let u of l)i=i<<8|u;if(n+=a,i<128)throw new e("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new e("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Gt;if(r<jt)throw new t("integer: negative integers are not allowed");let e=Je(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=Gt;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Vt(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Gt,o=Z("signature",r),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,s),{v:l,l:u}=n.decode(2,a);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(c),s:e.decode(l)}},hexFromSig(r){let{_tlv:t,_int:e}=Gt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}};function ko(r,t){return ee(de(r,t))}var jt=BigInt(0),it=BigInt(1),tp=BigInt(2),Oo=BigInt(3),zu=BigInt(4);function Fu(r){let t=Vu(r),{Fp:e}=t,n=Ft(t.n,t.nBitLength),o=t.toBytes||((x,h,y)=>{let B=h.toAffine();return re(Uint8Array.from([4]),e.toBytes(B.x),e.toBytes(B.y))}),s=t.fromBytes||(x=>{let h=x.subarray(1),y=e.fromBytes(h.subarray(0,e.BYTES)),B=e.fromBytes(h.subarray(e.BYTES,2*e.BYTES));return{x:y,y:B}});function i(x){let{a:h,b:y}=t,B=e.sqr(x),_=e.mul(B,x);return e.add(e.add(_,e.mul(x,h)),y)}function c(x,h){let y=e.sqr(h),B=i(x);return e.eql(y,B)}if(!c(t.Gx,t.Gy))throw new Error("bad curve params: generator point");let a=e.mul(e.pow(t.a,Oo),zu),l=e.mul(e.sqr(t.b),BigInt(27));if(e.is0(e.add(a,l)))throw new Error("bad curve params: a or b");function u(x){return Rr(x,it,t.n)}function f(x){let{allowedPrivateKeyLengths:h,nByteLength:y,wrapPrivateKey:B,n:_}=t;if(h&&typeof x!="bigint"){if(Ce(x)&&(x=ee(x)),typeof x!="string"||!h.includes(x.length))throw new Error("invalid private key");x=x.padStart(y*2,"0")}let L;try{L=typeof x=="bigint"?x:Vt(Z("private key",x,y))}catch{throw new Error("invalid private key, expected hex or "+y+" bytes, got "+typeof x)}return B&&(L=F(L,_)),vt("private key",L,it,_),L}function b(x){if(!(x instanceof m))throw new Error("ProjectivePoint expected")}let v=Re((x,h)=>{let{px:y,py:B,pz:_}=x;if(e.eql(_,e.ONE))return{x:y,y:B};let L=x.is0();h==null&&(h=L?e.ONE:e.inv(_));let N=e.mul(y,h),k=e.mul(B,h),C=e.mul(_,h);if(L)return{x:e.ZERO,y:e.ZERO};if(!e.eql(C,e.ONE))throw new Error("invZ was invalid");return{x:N,y:k}}),I=Re(x=>{if(x.is0()){if(t.allowInfinityPoint&&!e.is0(x.py))return;throw new Error("bad point: ZERO")}let{x:h,y}=x.toAffine();if(!e.isValid(h)||!e.isValid(y))throw new Error("bad point: x or y not FE");if(!c(h,y))throw new Error("bad point: equation left != right");if(!x.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class m{constructor(h,y,B){if(h==null||!e.isValid(h))throw new Error("x required");if(y==null||!e.isValid(y)||e.is0(y))throw new Error("y required");if(B==null||!e.isValid(B))throw new Error("z required");this.px=h,this.py=y,this.pz=B,Object.freeze(this)}static fromAffine(h){let{x:y,y:B}=h||{};if(!h||!e.isValid(y)||!e.isValid(B))throw new Error("invalid affine point");if(h instanceof m)throw new Error("projective point not allowed");let _=L=>e.eql(L,e.ZERO);return _(y)&&_(B)?m.ZERO:new m(y,B,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let y=Ne(e,h.map(B=>B.pz));return h.map((B,_)=>B.toAffine(y[_])).map(m.fromAffine)}static fromHex(h){let y=m.fromAffine(s(Z("pointHex",h)));return y.assertValidity(),y}static fromPrivateKey(h){return m.BASE.multiply(f(h))}static msm(h,y){return Kr(m,n,h,y)}_setWindowSize(h){M.setWindowSize(this,h)}assertValidity(){I(this)}hasEvenY(){let{y:h}=this.toAffine();if(e.isOdd)return!e.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){b(h);let{px:y,py:B,pz:_}=this,{px:L,py:N,pz:k}=h,C=e.eql(e.mul(y,k),e.mul(L,_)),U=e.eql(e.mul(B,k),e.mul(N,_));return C&&U}negate(){return new m(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b:y}=t,B=e.mul(y,Oo),{px:_,py:L,pz:N}=this,k=e.ZERO,C=e.ZERO,U=e.ZERO,R=e.mul(_,_),et=e.mul(L,L),E=e.mul(N,N),w=e.mul(_,L);return w=e.add(w,w),U=e.mul(_,N),U=e.add(U,U),k=e.mul(h,U),C=e.mul(B,E),C=e.add(k,C),k=e.sub(et,C),C=e.add(et,C),C=e.mul(k,C),k=e.mul(w,k),U=e.mul(B,U),E=e.mul(h,E),w=e.sub(R,E),w=e.mul(h,w),w=e.add(w,U),U=e.add(R,R),R=e.add(U,R),R=e.add(R,E),R=e.mul(R,w),C=e.add(C,R),E=e.mul(L,N),E=e.add(E,E),R=e.mul(E,w),k=e.sub(k,R),U=e.mul(E,et),U=e.add(U,U),U=e.add(U,U),new m(k,C,U)}add(h){b(h);let{px:y,py:B,pz:_}=this,{px:L,py:N,pz:k}=h,C=e.ZERO,U=e.ZERO,R=e.ZERO,et=t.a,E=e.mul(t.b,Oo),w=e.mul(y,L),T=e.mul(B,N),g=e.mul(_,k),d=e.add(y,B),p=e.add(L,N);d=e.mul(d,p),p=e.add(w,T),d=e.sub(d,p),p=e.add(y,_);let S=e.add(L,k);return p=e.mul(p,S),S=e.add(w,g),p=e.sub(p,S),S=e.add(B,_),C=e.add(N,k),S=e.mul(S,C),C=e.add(T,g),S=e.sub(S,C),R=e.mul(et,p),C=e.mul(E,g),R=e.add(C,R),C=e.sub(T,R),R=e.add(T,R),U=e.mul(C,R),T=e.add(w,w),T=e.add(T,w),g=e.mul(et,g),p=e.mul(E,p),T=e.add(T,g),g=e.sub(w,g),g=e.mul(et,g),p=e.add(p,g),w=e.mul(T,p),U=e.add(U,w),w=e.mul(S,p),C=e.mul(d,C),C=e.sub(C,w),w=e.mul(d,T),R=e.mul(S,R),R=e.add(R,w),new m(C,U,R)}subtract(h){return this.add(h.negate())}is0(){return this.equals(m.ZERO)}wNAF(h){return M.wNAFCached(this,h,m.normalizeZ)}multiplyUnsafe(h){let{endo:y,n:B}=t;vt("scalar",h,jt,B);let _=m.ZERO;if(h===jt)return _;if(this.is0()||h===it)return this;if(!y||M.hasPrecomputes(this))return M.wNAFCachedUnsafe(this,h,m.normalizeZ);let{k1neg:L,k1:N,k2neg:k,k2:C}=y.splitScalar(h),U=_,R=_,et=this;for(;N>jt||C>jt;)N&it&&(U=U.add(et)),C&it&&(R=R.add(et)),et=et.double(),N>>=it,C>>=it;return L&&(U=U.negate()),k&&(R=R.negate()),R=new m(e.mul(R.px,y.beta),R.py,R.pz),U.add(R)}multiply(h){let{endo:y,n:B}=t;vt("scalar",h,it,B);let _,L;if(y){let{k1neg:N,k1:k,k2neg:C,k2:U}=y.splitScalar(h),{p:R,f:et}=this.wNAF(k),{p:E,f:w}=this.wNAF(U);R=M.constTimeNegate(N,R),E=M.constTimeNegate(C,E),E=new m(e.mul(E.px,y.beta),E.py,E.pz),_=R.add(E),L=et.add(w)}else{let{p:N,f:k}=this.wNAF(h);_=N,L=k}return m.normalizeZ([_,L])[0]}multiplyAndAddUnsafe(h,y,B){let _=m.BASE,L=(k,C)=>C===jt||C===it||!k.equals(_)?k.multiplyUnsafe(C):k.multiply(C),N=L(this,y).add(L(h,B));return N.is0()?void 0:N}toAffine(h){return v(this,h)}isTorsionFree(){let{h,isTorsionFree:y}=t;if(h===it)return!0;if(y)return y(m,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:y}=t;return h===it?this:y?y(m,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return Dt("isCompressed",h),this.assertValidity(),o(m,this,h)}toHex(h=!0){return Dt("isCompressed",h),ee(this.toRawBytes(h))}}m.BASE=new m(t.Gx,t.Gy,e.ONE),m.ZERO=new m(e.ZERO,e.ONE,e.ZERO);let{endo:A,nBitLength:P}=t,M=Ur(m,A?Math.ceil(P/2):P);return{CURVE:t,ProjectivePoint:m,normPrivateKeyToScalar:f,weierstrassEquation:i,isWithinCurveOrder:u}}function Gu(r){let t=tr(r);return zt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function ki(r){let t=Gu(r),{Fp:e,n,nByteLength:o,nBitLength:s}=t,i=e.BYTES+1,c=2*e.BYTES+1;function a(E){return F(E,n)}function l(E){return Nr(E,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:f,weierstrassEquation:b,isWithinCurveOrder:v}=Fu({...t,toBytes(E,w,T){let g=w.toAffine(),d=e.toBytes(g.x),p=re;return Dt("isCompressed",T),T?p(Uint8Array.from([w.hasEvenY()?2:3]),d):p(Uint8Array.from([4]),d,e.toBytes(g.y))},fromBytes(E){let w=E.length,T=E[0],g=E.subarray(1);if(w===i&&(T===2||T===3)){let d=Vt(g);if(!Rr(d,it,e.ORDER))throw new Error("Point is not on curve");let p=b(d),S;try{S=e.sqrt(p)}catch(O){let q=O instanceof Error?": "+O.message:"";throw new Error("Point is not on curve"+q)}let D=(S&it)===it;return(T&1)===1!==D&&(S=e.neg(S)),{x:d,y:S}}else if(w===c&&T===4){let d=e.fromBytes(g.subarray(0,e.BYTES)),p=e.fromBytes(g.subarray(e.BYTES,2*e.BYTES));return{x:d,y:p}}else{let d=i,p=c;throw new Error("invalid Point, expected length of "+d+", or uncompressed "+p+", got "+w)}}});function I(E){let w=n>>it;return E>w}function m(E){return I(E)?a(-E):E}let A=(E,w,T)=>Vt(E.slice(w,T));class P{constructor(w,T,g){vt("r",w,it,n),vt("s",T,it,n),this.r=w,this.s=T,g!=null&&(this.recovery=g),Object.freeze(this)}static fromCompact(w){let T=o;return w=Z("compactSignature",w,T*2),new P(A(w,0,T),A(w,T,2*T))}static fromDER(w){let{r:T,s:g}=Gt.toSig(Z("DER",w));return new P(T,g)}assertValidity(){}addRecoveryBit(w){return new P(this.r,this.s,w)}recoverPublicKey(w){let{r:T,s:g,recovery:d}=this,p=_(Z("msgHash",w));if(d==null||![0,1,2,3].includes(d))throw new Error("recovery id invalid");let S=d===2||d===3?T+t.n:T;if(S>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let D=(d&1)===0?"02":"03",K=u.fromHex(D+ko(S,e.BYTES)),O=l(S),q=a(-p*O),H=a(g*O),z=u.BASE.multiplyAndAddUnsafe(K,q,H);if(!z)throw new Error("point at infinify");return z.assertValidity(),z}hasHighS(){return I(this.s)}normalizeS(){return this.hasHighS()?new P(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return Qe(this.toDERHex())}toDERHex(){return Gt.hexFromSig(this)}toCompactRawBytes(){return Qe(this.toCompactHex())}toCompactHex(){let w=o;return ko(this.r,w)+ko(this.s,w)}}let M={isValidPrivateKey(E){try{return f(E),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let E=$n(t.n);return ni(t.randomBytes(E),t.n)},precompute(E=8,w=u.BASE){return w._setWindowSize(E),w.multiply(BigInt(3)),w}};function x(E,w=!0){return u.fromPrivateKey(E).toRawBytes(w)}function h(E){if(typeof E=="bigint")return!1;if(E instanceof u)return!0;let T=Z("key",E).length,g=e.BYTES,d=g+1,p=2*g+1;if(!(t.allowedPrivateKeyLengths||o===d))return T===d||T===p}function y(E,w,T=!0){if(h(E)===!0)throw new Error("first arg must be private key");if(h(w)===!1)throw new Error("second arg must be public key");return u.fromHex(w).multiply(f(E)).toRawBytes(T)}let B=t.bits2int||function(E){if(E.length>8192)throw new Error("input is too large");let w=Vt(E),T=E.length*8-s;return T>0?w>>BigInt(T):w},_=t.bits2int_modN||function(E){return a(B(E))},L=pe(s);function N(E){return vt("num < 2^"+s,E,jt,L),de(E,o)}function k(E,w,T=C){if(["recovered","canonical"].some(J=>J in T))throw new Error("sign() legacy options not supported");let{hash:g,randomBytes:d}=t,{lowS:p,prehash:S,extraEntropy:D}=T;p==null&&(p=!0),E=Z("msgHash",E),Ki(T),S&&(E=Z("prehashed msgHash",g(E)));let K=_(E),O=f(w),q=[N(O),N(K)];if(D!=null&&D!==!1){let J=D===!0?d(e.BYTES):D;q.push(Z("extraEntropy",J))}let H=re(...q),z=K;function rt(J){let at=B(J);if(!v(at))return;let gt=l(at),ot=u.BASE.multiply(at).toAffine(),ut=a(ot.x);if(ut===jt)return;let St=a(gt*a(z+ut*O));if(St===jt)return;let It=(ot.x===ut?0:2)|Number(ot.y&it),qe=St;return p&&I(St)&&(qe=m(St),It^=1),new P(ut,qe,It)}return{seed:H,k2sig:rt}}let C={lowS:t.lowS,prehash:!1},U={lowS:t.lowS,prehash:!1};function R(E,w,T=C){let{seed:g,k2sig:d}=k(E,w,T),p=t;return Ws(p.hash.outputLen,p.nByteLength,p.hmac)(g,d)}u.BASE._setWindowSize(8);function et(E,w,T,g=U){let d=E;w=Z("msgHash",w),T=Z("publicKey",T);let{lowS:p,prehash:S,format:D}=g;if(Ki(g),"strict"in g)throw new Error("options.strict was renamed to lowS");if(D!==void 0&&D!=="compact"&&D!=="der")throw new Error("format must be compact or der");let K=typeof d=="string"||Ce(d),O=!K&&!D&&typeof d=="object"&&d!==null&&typeof d.r=="bigint"&&typeof d.s=="bigint";if(!K&&!O)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let q,H;try{if(O&&(q=new P(d.r,d.s)),K){try{D!=="compact"&&(q=P.fromDER(d))}catch(It){if(!(It instanceof Gt.Err))throw It}!q&&D!=="der"&&(q=P.fromCompact(d))}H=u.fromHex(T)}catch{return!1}if(!q||p&&q.hasHighS())return!1;S&&(w=t.hash(w));let{r:z,s:rt}=q,J=_(w),at=l(rt),gt=a(J*at),ot=a(z*at),ut=u.BASE.multiplyAndAddUnsafe(H,gt,ot)?.toAffine();return ut?a(ut.x)===z:!1}return{CURVE:t,getPublicKey:x,getSharedSecret:y,sign:R,verify:et,ProjectivePoint:u,Signature:P,utils:M}}function ju(r){return{hash:r,hmac:(t,...e)=>Ko(r,t,Mn(...e)),randomBytes:Pe}}function Oi(r,t){let e=n=>ki({...r,...ju(n)});return{...e(t),create:e}}var Hi=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Mi=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Zu=BigInt(0),Yu=BigInt(1),qo=BigInt(2),qi=(r,t)=>(r+t/qo)/t;function Wu(r){let t=Hi,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),l=r*r*r%t,u=l*l*r%t,f=Y(u,e,t)*u%t,b=Y(f,e,t)*u%t,v=Y(b,qo,t)*l%t,I=Y(v,o,t)*v%t,m=Y(I,s,t)*I%t,A=Y(m,c,t)*m%t,P=Y(A,a,t)*A%t,M=Y(P,c,t)*m%t,x=Y(M,e,t)*u%t,h=Y(x,i,t)*I%t,y=Y(h,n,t)*l%t,B=Y(y,qo,t);if(!Ho.eql(Ho.sqr(B),r))throw new Error("Cannot find square root");return B}var Ho=Ft(Hi,void 0,void 0,{sqrt:Wu}),ke=Oi({a:Zu,b:BigInt(7),Fp:Ho,n:Mi,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Mi,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Yu*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),c=qi(s*r,t),a=qi(-n*r,t),l=F(r-c*e-a*o,t),u=F(-c*n-a*s,t),f=l>i,b=u>i;if(f&&(l=t-l),b&&(u=t-u),l>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:l,k2neg:b,k2:u}}}},Dr);function Vi(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function zi(r,t,e){let n=ae.digest(e instanceof Uint8Array?e:e.subarray());if(Vi(n))return n.then(({digest:o})=>ke.verify(t,o,r)).catch(o=>{throw new nr(String(o))});try{return ke.verify(t,n.digest,r)}catch(o){throw new nr(String(o))}}var Wr=class{type="secp256k1";raw;_key;constructor(t){this._key=Gi(t),this.raw=Fi(this._key)}toMultihash(){return _t.digest(Ot(this))}toCID(){return ft.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:wt(this.raw,t.raw)}verify(t,e){return zi(this._key,e,t)}};function Vo(r){return new Wr(r)}function Fi(r){return ke.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Gi(r){try{return ke.ProjectivePoint.fromHex(r),r}catch(t){throw new we(String(t))}}function zo(r,t){let{Type:e,Data:n}=Nt.decode(r),o=n??new Uint8Array;switch(e){case tt.RSA:return Ro(o,t);case tt.Ed25519:return so(o);case tt.secp256k1:return Vo(o);case tt.ECDSA:return On(o);default:throw new se}}function ji(r){let{Type:t,Data:e}=Nt.decode(r.digest),n=e??new Uint8Array;switch(t){case tt.Ed25519:return so(n);case tt.secp256k1:return Vo(n);case tt.ECDSA:return On(n);default:throw new se}}function Ot(r){return Nt.encode({Type:tt[r.type],Data:r.raw})}var Zi=Symbol.for("nodejs.util.inspect.custom"),Xu=114,ir=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()})`}[fn]=!0;toString(){return this.string==null&&(this.string=X.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ft.createV1(Xu,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return wt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return wt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Zi](){return`PeerId(${this.toString()})`}},ar=class extends ir{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},cr=class extends ir{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},ur=class extends ir{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},$u=2336,Xr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=_t.digest(G(this.url))}[Zi](){return`PeerId(${this.url})`}[fn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ft.createV1($u,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=j(t)),t.toString()===this.toString())}};function Fo(r){if(r.type==="Ed25519")return new cr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new ur({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new ar({multihash:r.toCID().multihash,publicKey:r});throw new se}function Yi(r){return Fo(r.publicKey)}function fr(r){if(Qu(r))return new ar({multihash:r});if(Ju(r))try{let t=ji(r);if(t.type==="Ed25519")return new cr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new ur({multihash:r,publicKey:t})}catch{let e=j(r.digest);return new Xr(new URL(e))}throw new Sr("Supplied PeerID Multihash is invalid")}function Ju(r){return r.code===_t.code}function Qu(r){return r.code===ae.code}function ge(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return e}function $r(r){let t=Wt(X.decode(`z${r}`));return fr(t)}var lr=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[e,n]of t.entries())this.map.set(e.toString(),{key:e,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return ge(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((e,n)=>{t(e.value,e.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,e){this.map.set(t.toString(),{key:t,value:e})}keys(){return ge(this.map.values(),t=>t.key)}values(){return ge(this.map.values(),t=>t.value)}get size(){return this.map.size}};var hr=class r{set;constructor(t){if(this.set=new Set,t!=null)for(let e of t)this.set.add(e.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 ge(this.set.entries(),t=>{let e=$r(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=$r(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return ge(this.set.values(),t=>$r(t))}intersection(t){let e=new r;for(let n of t)this.has(n)&&e.add(n);return e}difference(t){let e=new r;for(let n of this)t.has(n)||e.add(n);return e}union(t){let e=new r;for(let n of t)e.add(n);for(let n of this)e.add(n);return e}};function Zt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Jr=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},Oe=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Jr(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new Jr(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Go=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Qr(r={}){return tf(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function tf(r,t){t=t??{};let e=t.onEnd,n=new Oe,o,s,i,c=Zt(),a=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((A,P)=>{s=M=>{s=null,n.push(M);try{A(r(n))}catch(x){P(x)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=Zt()})}},l=A=>s!=null?s(A):(n.push(A),o),u=A=>(n=new Oe,s!=null?s({error:A}):(n.push({error:A}),o)),f=A=>{if(i)return o;if(t?.objectMode!==!0&&A?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:A})},b=A=>i?o:(i=!0,A!=null?u(A):l({done:!0})),v=()=>(n=new Oe,b(),{done:!0}),I=A=>(b(A),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:a,return:v,throw:I,push:f,end:b,get readableLength(){return n.size},onEmpty:async A=>{let P=A?.signal;if(P?.throwIfAborted(),n.isEmpty())return;let M,x;P!=null&&(M=new Promise((h,y)=>{x=()=>{y(new Go)},P.addEventListener("abort",x)}));try{await Promise.race([c.promise,M])}finally{x!=null&&P!=null&&P?.removeEventListener("abort",x)}}},e==null)return o;let m=o;return o={[Symbol.asyncIterator](){return this},next(){return m.next()},throw(A){return m.throw(A),e!=null&&(e(A),e=void 0),{done:!0}},return(){return m.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(A){return m.end(A),e!=null&&(e(A),e=void 0),o},get readableLength(){return m.readableLength},onEmpty:A=>m.onEmpty(A)},o}var tn=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function Wi(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new tn(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new tn(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var jo=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Zt(),this.haveNext=Zt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Zt(),t}async throw(t){return this.ended=!0,this.error=t,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return this.ended=!0,this.nextResult=t,this.haveNext.resolve(),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Zt(),await Wi(this.readNext.promise,e?.signal,e)}};function Xi(){return new jo}function ef(r){return r[Symbol.asyncIterator]!=null}async function rf(r,t,e){try{await Promise.all(r.map(async n=>{for await(let o of n)await t.push(o,{signal:e}),e.throwIfAborted()})),await t.end(void 0,{signal:e})}catch(n){await t.end(n,{signal:e}).catch(()=>{})}}async function*nf(r){let t=new AbortController,e=Xi();rf(r,e,t.signal).catch(()=>{});try{yield*e}finally{t.abort()}}function*of(r){for(let t of r)yield*t}function sf(...r){let t=[];for(let e of r)ef(e)||t.push(e);return t.length===r.length?of(t):nf(r)}var $i=sf;function dr(r,...t){if(r==null)throw new Error("Empty pipeline");if(Zo(r)){let n=r;r=()=>n.source}else if(Qi(r)||Ji(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&Zo(e[e.length-1])&&(e[e.length-1]=e[e.length-1].sink),e.length>2)for(let n=1;n<e.length-1;n++)Zo(e[n])&&(e[n]=cf(e[n]));return af(...e)}var af=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},Ji=r=>r?.[Symbol.asyncIterator]!=null,Qi=r=>r?.[Symbol.iterator]!=null,Zo=r=>r==null?!1:r.sink!=null&&r.source!=null,cf=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=Qr({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let o,s=r.source;if(Ji(s))o=async function*(){yield*s,n.end()};else if(Qi(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return $i(n,o())}return r.source};var Wo=Ba(ea(),1);var mr=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},Xo=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},ra=r=>globalThis.DOMException===void 0?new Xo(r):new DOMException(r),na=r=>{let t=r.reason===void 0?ra("This operation was aborted."):r.reason;return t instanceof Error?t:ra(t)};function $o(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,c,l=new Promise((u,f)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(t.signal){let{signal:v}=t;v.aborted&&f(na(v)),c=()=>{f(na(v))},v.addEventListener("abort",c,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(u,f);return}let b=new mr;i=s.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(v){f(v)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?u():o instanceof Error?f(o):(b.message=o??`Promise timed out after ${e} milliseconds`,f(b))},e),(async()=>{try{u(await r)}catch(v){f(v)}})()}).finally(()=>{l.clear(),c&&t.signal&&t.signal.removeEventListener("abort",c)});return l.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},l}function Jo(r,t,e){let n=0,o=r.length;for(;o>0;){let s=Math.trunc(o/2),i=n+s;e(r[i],t)<=0?(n=++i,o-=s+1):o=s}return n}var yr=class{#t=[];enqueue(t,e){e={priority:0,...e};let n={priority:e.priority,id:e.id,run:t};if(this.size===0||this.#t[this.size-1].priority>=e.priority){this.#t.push(n);return}let o=Jo(this.#t,n,(s,i)=>i.priority-s.priority);this.#t.splice(o,0,n)}setPriority(t,e){let n=this.#t.findIndex(s=>s.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[o]=this.#t.splice(n,1);this.enqueue(o.run,{priority:e,id:t})}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(e=>e.priority===t.priority).map(e=>e.run)}get size(){return this.#t.length}};var br=class extends Wo.default{#t;#i;#s=0;#d;#a;#p=0;#r;#c;#e;#m;#n=0;#u;#o;#y;#x=1n;timeout;constructor(t){if(super(),t={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:yr,...t},!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString()??""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString()??""}\` (${typeof t.interval})`);this.#t=t.carryoverConcurrencyCount,this.#i=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#d=t.intervalCap,this.#a=t.interval,this.#e=new t.queueClass,this.#m=t.queueClass,this.concurrency=t.concurrency,this.timeout=t.timeout,this.#y=t.throwOnTimeout===!0,this.#o=t.autoStart===!1}get#w(){return this.#i||this.#s<this.#d}get#E(){return this.#n<this.#u}#S(){this.#n--,this.#f(),this.emit("next")}#v(){this.#g(),this.#b(),this.#c=void 0}get#A(){let t=Date.now();if(this.#r===void 0){let e=this.#p-t;if(e<0)this.#s=this.#t?this.#n:0;else return this.#c===void 0&&(this.#c=setTimeout(()=>{this.#v()},e)),!0}return!1}#f(){if(this.#e.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#o){let t=!this.#A;if(this.#w&&this.#E){let e=this.#e.dequeue();return e?(this.emit("active"),e(),t&&this.#b(),!0):!1}}return!1}#b(){this.#i||this.#r!==void 0||(this.#r=setInterval(()=>{this.#g()},this.#a),this.#p=Date.now()+this.#a)}#g(){this.#s===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#t?this.#n:0,this.#l()}#l(){for(;this.#f(););}get concurrency(){return this.#u}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#u=t,this.#l()}async#I(t){return new Promise((e,n)=>{t.addEventListener("abort",()=>{n(t.reason)},{once:!0})})}setPriority(t,e){this.#e.setPriority(t,e)}async add(t,e={}){return e.id??=(this.#x++).toString(),e={timeout:this.timeout,throwOnTimeout:this.#y,...e},new Promise((n,o)=>{this.#e.enqueue(async()=>{this.#n++,this.#s++;try{e.signal?.throwIfAborted();let s=t({signal:e.signal});e.timeout&&(s=$o(Promise.resolve(s),{milliseconds:e.timeout})),e.signal&&(s=Promise.race([s,this.#I(e.signal)]));let i=await s;n(i),this.emit("completed",i)}catch(s){if(s instanceof mr&&!e.throwOnTimeout){n();return}o(s),this.emit("error",s)}finally{this.#S()}},e),this.emit("add"),this.#f()})}async addAll(t,e){return Promise.all(t.map(async n=>this.add(n,e)))}start(){return this.#o?(this.#o=!1,this.#l(),this):this}pause(){this.#o=!0}clear(){this.#e=new this.#m}async onEmpty(){this.#e.size!==0&&await this.#h("empty")}async onSizeLessThan(t){this.#e.size<t||await this.#h("next",()=>this.#e.size<t)}async onIdle(){this.#n===0&&this.#e.size===0||await this.#h("idle")}async#h(t,e){return new Promise(n=>{let o=()=>{e&&!e()||(this.off(t,o),n())};this.on(t,o)})}get size(){return this.#e.size}sizeBy(t){return this.#e.filter(t).length}get pending(){return this.#n}get isPaused(){return this.#o}};function oa(r){if(r!=null){if(typeof r[Symbol.iterator]=="function")return r[Symbol.iterator]();if(typeof r[Symbol.asyncIterator]=="function")return r[Symbol.asyncIterator]();if(typeof r.next=="function")return r}throw new Error("argument is not an iterator or iterable")}function sa(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function ia(r,t){let e=oa(r).return?.();sa(e)&&e.catch(n=>{t.error("could not cause iterator to return",n)})}var rn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Me=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},nn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},gr=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function on(r){return r[Symbol.asyncIterator]!=null}function aa(r,t){if(r.byteLength>t)throw new Me("Message length too long")}var an=r=>{let t=Tt(r),e=lt(t);return yi(r,e),an.bytes=t,e};an.bytes=0;function cn(r,t){t=t??{};let e=t.lengthEncoder??an,n=t?.maxDataLength??4194304;function*o(s){aa(s,n);let i=e(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return on(r)?async function*(){for await(let s of r)yield*o(s)}():function*(){for(let s of r)yield*o(s)}()}cn.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??an,n=t?.maxDataLength??4194304;return aa(r,n),new nt(e(r.byteLength),r)};var xe;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(xe||(xe={}));var Qo=r=>{let t=bi(r);return Qo.bytes=Tt(t),t};Qo.bytes=0;function xr(r,t){let e=new nt,n=xe.LENGTH,o=-1,s=t?.lengthDecoder??Qo,i=t?.maxLengthLength??8,c=t?.maxDataLength??4194304;function*a(){for(;e.byteLength>0;){if(n===xe.LENGTH)try{if(o=s(e),o<0)throw new rn("Invalid message length");if(o>c)throw new Me("Message length too long");let l=s.bytes;e.consume(l),t?.onLength!=null&&t.onLength(o),n=xe.DATA}catch(l){if(l instanceof RangeError){if(e.byteLength>i)throw new nn("Message length length too long");break}throw l}if(n===xe.DATA){if(e.byteLength<o)break;let l=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(l),yield l,n=xe.LENGTH}}}return on(r)?async function*(){for await(let l of r)e.append(l),yield*a();if(e.byteLength>0)throw new gr("Unexpected end of input")}():function*(){for(let l of r)e.append(l),yield*a();if(e.byteLength>0)throw new gr("Unexpected end of input")}()}xr.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:s,value:i}=await r.next(e);if(s===!0)return;i!=null&&(yield i)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{e=1}}();return xr(n,{...t??{},onLength:s=>{e=s}})};var un=class extends Ee{id;protocol;outboundStream;inboundStream;_rawOutboundStream;_rawInboundStream;_inboundAbortController;closed;log;constructor(t,e){super(),this.log=t.logger.forComponent("libp2p-pubsub:peer-streams"),this.id=e.id,this.protocol=e.protocol,this._inboundAbortController=new AbortController,this.closed=!1}get isReadable(){return!!this.inboundStream}get isWritable(){return!!this.outboundStream}write(t){if(this.outboundStream==null){let e=this.id.toString();throw new Error("No writable connection to "+e)}this.outboundStream.push(t instanceof Uint8Array?new nt(t):t)}attachInboundStream(t,e){let n=()=>{ia(t.source,this.log)};return this._inboundAbortController.signal.addEventListener("abort",n,{once:!0}),this._rawInboundStream=t,this.inboundStream=dr(this._rawInboundStream,o=>xr(o,e)),this.dispatchEvent(new CustomEvent("stream:inbound")),this.inboundStream}async attachOutboundStream(t){let e=this.outboundStream;return this.outboundStream!=null&&this.outboundStream.end(),this._rawOutboundStream=t,this.outboundStream=Qr({onEnd:n=>{this._rawOutboundStream?.closeWrite().catch(o=>{this.log("error closing outbound stream",o)}),this._rawOutboundStream=void 0,this.outboundStream=void 0,n!=null&&this.dispatchEvent(new CustomEvent("close"))}}),dr(this.outboundStream,n=>cn(n),this._rawOutboundStream).catch(n=>{this.log.error(n)}),e==null&&this.dispatchEvent(new CustomEvent("stream:outbound")),this.outboundStream}close(){this.closed||(this.closed=!0,this.outboundStream!=null&&this.outboundStream.end(),this.inboundStream!=null&&this._inboundAbortController.abort(),this._rawOutboundStream=void 0,this.outboundStream=void 0,this._rawInboundStream=void 0,this.inboundStream=void 0,this.dispatchEvent(new CustomEvent("close")))}};function ca(){return BigInt(`0x${j(Gr(8),"base16")}`)}var ua=(r,t)=>{let e=G(t.toString(16).padStart(16,"0"),"base16"),n=Ot(r),o=new Uint8Array(n.byteLength+e.length);return o.set(n,0),o.set(e,n.byteLength),o},fa=r=>ae.encode(r);var la=function(r){return Array.isArray(r)?r:[r]},df=async r=>{if(r.sequenceNumber==null||r.from==null||r.signature==null)return!1;let t=fr(Wt(r.from));if(t.publicKey!=null)return!0;if(r.key!=null){let e=r.key;return Fo(zo(e)).equals(t)}return!1},ha=async r=>{if(r.from==null)throw new Q("RPC message was missing from");if(!await df(r))return{type:"unsigned",topic:r.topic??"",data:r.data??new Uint8Array(0)};let t=fr(Wt(r.from)),e=r.key??t.publicKey;if(e==null)throw new Q("RPC message was missing public key");return{type:"signed",from:t,topic:r.topic??"",sequenceNumber:mf(r.sequenceNumber??new Uint8Array(0)),data:r.data??new Uint8Array(0),signature:r.signature??new Uint8Array(0),key:e instanceof Uint8Array?zo(e):e}},wr=r=>r.type==="signed"?{from:r.from.toMultihash().bytes,data:r.data,sequenceNumber:pf(r.sequenceNumber),topic:r.topic,signature:r.signature,key:r.key?Ot(r.key):void 0}:{data:r.data,topic:r.topic},pf=r=>{let t=r.toString(16);return t.length%2!==0&&(t=`0${t}`),G(t,"base16")},mf=r=>BigInt(`0x${j(r,"base16")}`);var da=G("libp2p-pubsub:");async function pa(r,t,e){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:Yi(r)},o=ie([da,e(wr(n)).subarray()]);return n.signature=await r.sign(o),n.key=r.publicKey,n}async function ma(r,t){if(r.type!=="signed")throw new Error('Message type must be "signed" to be verified');if(r.signature==null)throw new Error("Message must contain a signature to be verified");if(r.from==null)throw new Error("Message must contain a from property to be verified");let e=ie([da,t({...wr(r),signature:void 0,key:void 0}).subarray()]);return yf(r).verify(e,r.signature)}function yf(r){if(r.type!=="signed")throw new Error('Message type must be "signed" to have a public key');if(r.from==null)throw new Error("Could not get the public key from the originator id");if(r.key!=null)return r.key;if(r.from.publicKey!=null)return r.from.publicKey;throw new Error("Could not get the public key from the originator id")}var ts=class extends Ee{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;multicodecs;components;_registrarTopologyIds;enabled;maxInboundStreams;maxOutboundStreams;constructor(t,e){super();let{multicodecs:n=[],globalSignaturePolicy:o="StrictSign",canRelayMessage:s=!1,emitSelf:i=!1,messageProcessingConcurrency:c=10,maxInboundStreams:a=1,maxOutboundStreams:l=1}=e;this.log=t.logger.forComponent("libp2p:pubsub"),this.components=t,this.multicodecs=la(n),this.enabled=e.enabled!==!1,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new lr,this.globalSignaturePolicy=o==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=s,this.emitSelf=i,this.topicValidators=new Map,this.queue=new br({concurrency:c}),this.maxInboundStreams=a,this.maxOutboundStreams=l,this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}async start(){if(this.started||!this.enabled)return;this.log("starting");let t=this.components.registrar;await Promise.all(this.multicodecs.map(async n=>{await t.handle(n,this._onIncomingStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams})}));let e={onConnect:this._onPeerConnected,onDisconnect:this._onPeerDisconnected};this._registrarTopologyIds=await Promise.all(this.multicodecs.map(async n=>t.register(n,e))),this.log("started"),this.started=!0}async stop(){if(!this.started||!this.enabled)return;let t=this.components.registrar;this._registrarTopologyIds!=null&&this._registrarTopologyIds?.forEach(e=>{t.unregister(e)}),await Promise.all(this.multicodecs.map(async e=>{await t.unhandle(e)})),this.log("stopping");for(let e of this.peers.values())e.close();this.peers.clear(),this.subscriptions=new Set,this.started=!1,this.log("stopped")}isStarted(){return this.started}_onIncomingStream(t){let{stream:e,connection:n}=t,o=n.remotePeer;if(e.protocol==null){e.abort(new Error("Stream was not multiplexed"));return}let s=this.addPeer(o,e.protocol),i=s.attachInboundStream(e);this.processMessages(o,i,s).catch(c=>{this.log(c)})}_onPeerConnected(t,e){if(this.log("connected %p",t),e.streams.find(n=>n.direction==="outbound"&&n.protocol!=null&&this.multicodecs.includes(n.protocol))!=null){this.log("outbound pubsub streams already present on connection from %p",t);return}Promise.resolve().then(async()=>{try{let n=await e.newStream(this.multicodecs);if(n.protocol==null){n.abort(new Error("Stream was not multiplexed"));return}await this.addPeer(t,n.protocol).attachOutboundStream(n)}catch(n){this.log.error(n)}this.send(t,{subscriptions:Array.from(this.subscriptions).map(n=>n.toString()),subscribe:!0})}).catch(n=>{this.log.error(n)})}_onPeerDisconnected(t,e){this.log("connection ended %p",t),this._removePeer(t)}addPeer(t,e){let n=this.peers.get(t);if(n!=null)return n;this.log("new peer %p",t);let o=new un(this.components,{id:t,protocol:e});return this.peers.set(t,o),o.addEventListener("close",()=>this._removePeer(t),{once:!0}),o}_removePeer(t){let e=this.peers.get(t);if(e!=null){e.close(),this.log("delete peer %p",t),this.peers.delete(t);for(let n of this.topics.values())n.delete(t);return e}}async processMessages(t,e,n){try{await dr(e,async o=>{for await(let s of o){let i=this.decodeRpc(s),c=[];for(let a of i.messages??[]){if(a.from==null||a.data==null||a.topic==null){this.log("message from %p was missing from, data or topic fields, dropping",t);continue}c.push({from:a.from,data:a.data,topic:a.topic,sequenceNumber:a.sequenceNumber??void 0,signature:a.signature??void 0,key:a.key??void 0})}this.processRpc(t,n,{subscriptions:(i.subscriptions??[]).map(a=>({subscribe:!!a.subscribe,topic:a.topic??""})),messages:c}).catch(a=>{this.log(a)})}})}catch(o){this._onPeerDisconnected(n.id,o)}}async processRpc(t,e,n){if(!this.acceptFrom(t))return this.log("received message from unacceptable peer %p",t),!1;this.log("rpc from %p",t);let{subscriptions:o,messages:s}=n;return o!=null&&o.length>0&&(this.log("subscription update from %p",t),o.forEach(i=>{this.processRpcSubOpt(t,i)}),super.dispatchEvent(new CustomEvent("subscription-change",{detail:{peerId:e.id,subscriptions:o.map(({topic:i,subscribe:c})=>({topic:`${i??""}`,subscribe:!!c}))}}))),s!=null&&s.length>0&&(this.log("messages from %p",t),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 c=await ha(i);await this.processMessage(t,c)}catch(c){this.log.error(c)}})).catch(i=>{this.log(i)})),!0}processRpcSubOpt(t,e){let n=e.topic;if(n==null)return;let o=this.topics.get(n);o==null&&(o=new hr,this.topics.set(n,o)),e.subscribe===!0?o.add(t):o.delete(t)}async processMessage(t,e){if(!(this.components.peerId.equals(t)&&!this.emitSelf)){try{await this.validate(t,e)}catch(n){this.log("Message is invalid, dropping it. %O",n);return}this.subscriptions.has(e.topic)&&(!this.components.peerId.equals(t)||this.emitSelf)&&super.dispatchEvent(new CustomEvent("message",{detail:e})),await this.publishMessage(t,e)}}getMsgId(t){switch(this.globalSignaturePolicy){case"StrictSign":if(t.type!=="signed")throw new Q('Message type should be "signed" when signature policy is StrictSign but it was not');if(t.sequenceNumber==null)throw new Q("Need sequence number when signature policy is StrictSign but it was missing");if(t.key==null)throw new Q("Need key when signature policy is StrictSign but it was missing");return ua(t.key,t.sequenceNumber);case"StrictNoSign":return fa(t.data);default:throw new Q("Cannot get message id: unhandled signature policy")}}acceptFrom(t){return!0}send(t,e){let{messages:n,subscriptions:o,subscribe:s}=e;this.sendRpc(t,{subscriptions:(o??[]).map(i=>({topic:i,subscribe:!!s})),messages:(n??[]).map(wr)})}sendRpc(t,e){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}if(!n.isWritable){this.log.error("Cannot send RPC to %p as there is no outbound stream to it available",t);return}n.write(this.encodeRpc(e))}async validate(t,e){switch(this.globalSignaturePolicy){case"StrictNoSign":if(e.type!=="unsigned")throw new Q('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(e.signature!=null)throw new Q("StrictNoSigning: signature should not be present");if(e.key!=null)throw new Q("StrictNoSigning: key should not be present");if(e.sequenceNumber!=null)throw new Q("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(e.type!=="signed")throw new Q('Message type should be "signed" when signature policy is StrictSign but it was not');if(e.signature==null)throw new Q("StrictSigning: Signing required and no signature was present");if(e.sequenceNumber==null)throw new Q("StrictSigning: Signing required and no sequenceNumber was present");if(!await ma(e,this.encodeMessage.bind(this)))throw new Q("StrictSigning: Invalid message signature");break;default:throw new Q("Cannot validate message: unhandled signature policy")}let o=this.topicValidators.get(e.topic);if(o!=null){let s=await o(t,e);if(s===He.Reject||s===He.Ignore)throw new Q("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 Q("Cannot build message: unhandled signature policy")}}getSubscribers(t){if(!this.started)throw new vr("not started yet");if(t==null)throw new W("Topic is required");let e=this.topics.get(t.toString());return e==null?[]:Array.from(e.values())}async publish(t,e){if(!this.started)throw new Error("Pubsub has not started");let n={from:this.components.peerId,topic:t,data:e??new Uint8Array(0),sequenceNumber:ca()};this.log("publish topic: %s from: %p data: %m",t,n.from,n.data);let o=await this.buildMessage(n),s=!1;this.emitSelf&&this.subscriptions.has(t)&&(s=!0,super.dispatchEvent(new CustomEvent("message",{detail:o})));let i=await this.publishMessage(this.components.peerId,o);return s&&(i.recipients=[...i.recipients,this.components.peerId]),i}subscribe(t){if(!this.started)throw new Error("Pubsub has not started");if(this.log("subscribe to topic: %s",t),!this.subscriptions.has(t)){this.subscriptions.add(t);for(let e of this.peers.keys())this.send(e,{subscriptions:[t],subscribe:!0})}}unsubscribe(t){if(!this.started)throw new Error("Pubsub is not started");super.removeEventListener(t);let e=this.subscriptions.has(t);if(this.log("unsubscribe from %s - am subscribed %s",t,e),e){this.subscriptions.delete(t);for(let n of this.peers.keys())this.send(n,{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())}};return _a(bf);})();
|
3
3
|
/*! Bundled license information:
|
4
4
|
|
5
5
|
@noble/hashes/esm/utils.js:
|