@libp2p/pubsub 10.1.14 → 10.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +2 -2
- package/dist/index.min.js.map +4 -4
- package/package.json +8 -8
package/dist/index.min.js
CHANGED
@@ -1,11 +1,11 @@
|
|
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 Ea=Object.create;var Er=Object.defineProperty;var Sa=Object.getOwnPropertyDescriptor;var Aa=Object.getOwnPropertyNames;var va=Object.getPrototypeOf,Ia=Object.prototype.hasOwnProperty;var Ba=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),wt=(r,t)=>{for(var e in t)Er(r,e,{get:t[e],enumerable:!0})},os=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Aa(t))!Ia.call(r,o)&&o!==e&&Er(r,o,{get:()=>t[o],enumerable:!(n=Sa(t,o))||n.enumerable});return r};var _a=(r,t,e)=>(e=r!=null?Ea(va(r)):{},os(t||!r||!r.__esModule?Er(e,"default",{value:r,enumerable:!0}):e,r)),La=r=>os(Er({},"__esModule",{value:!0}),r);var ra=Ba((W0,Xo)=>{"use strict";var df=Object.prototype.hasOwnProperty,bt="~";function pr(){}Object.create&&(pr.prototype=Object.create(null),new pr().__proto__||(bt=!1));function pf(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function ea(r,t,e,n,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var s=new pf(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 rn(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)df.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,A;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(A=1,u=new Array(l-1);A<l;A++)u[A-1]=arguments[A];a[f].fn.apply(a[f].context,u)}}return!0};pt.prototype.on=function(t,e,n){return ea(this,t,e,n,!1)};pt.prototype.once=function(t,e,n){return ea(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 rn(this,s),this;var i=this._events[s];if(i.fn)i.fn===e&&(!o||i.once)&&(!n||i.context===n)&&rn(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:rn(this,s)}return this};pt.prototype.removeAllListeners=function(t){var e;return t?(e=bt?bt+t:t,this._events[e]&&rn(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 Xo<"u"&&(Xo.exports=pt)});var Ef={};wt(Ef,{PubSubBaseProtocol:()=>rs});var ln=Symbol.for("@libp2p/peer-id");var He;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(He||(He={}));var vf=Symbol.for("@libp2p/pubsub");var W=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},xe=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 Ar=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 yn={};wt(yn,{base58btc:()=>X,base58flickr:()=>Ua});var Lf=new Uint8Array(0);function ss(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){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 is(r){return new TextEncoder().encode(r)}function as(r){return new TextDecoder().decode(r)}function Ta(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,v=0,P=0,M=I.length;P!==M&&I[P]===0;)P++,m++;for(var w=(M-P)*u+1>>>0,h=new Uint8Array(w);P!==M;){for(var y=I[P],B=0,_=w-1;(y!==0||B<v)&&_!==-1;_--,B++)y+=256*h[_]>>>0,h[_]=y%c>>>0,y=y/c>>>0;if(y!==0)throw new Error("Non-zero carry");v=B,P++}for(var L=w-v;L!==w&&h[L]===0;)L++;for(var N=a.repeat(m);L<w;++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 v=0,P=0;I[m]===a;)v++,m++;for(var M=(I.length-m)*l+1>>>0,w=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*w[B]>>>0,w[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&&w[_]===0;)_++;for(var L=new Uint8Array(v+(M-_)),N=v;_!==M;)L[N++]=w[_++];return L}}}function A(I){var m=b(I);if(m)return m;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:b,decode:A}}var Pa=Ta,Ca=Pa,us=Ca;var hn=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")}},dn=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 fs(this,t)}},pn=class{decoders;constructor(t){this.decoders=t}or(t){return fs(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 fs(r,t){return new pn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var mn=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 hn(t,e,n),this.decoder=new dn(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 mn(r,t,e,n)}function Wt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=us(e,r);return Se({prefix:t,name:r,encode:n,decode:s=>Kt(o(s))})}function Da(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 Ra(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 Na(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=Na(n);return Se({prefix:t,name:r,encode(s){return Ra(s,n,e)},decode(s){return Da(s,o,e,r)}})}var X=Wt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ua=Wt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var bn={};wt(bn,{base32:()=>Ae,base32hex:()=>Ma,base32hexpad:()=>Ha,base32hexpadupper:()=>Va,base32hexupper:()=>qa,base32pad:()=>ka,base32padupper:()=>Oa,base32upper:()=>Ka,base32z:()=>za});var Ae=$({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ka=$({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ka=$({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Oa=$({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ma=$({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),qa=$({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ha=$({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Va=$({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),za=$({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var gn={};wt(gn,{base36:()=>Ve,base36upper:()=>Fa});var Ve=Wt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Fa=Wt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ga=ds,ls=128,ja=127,Za=~ja,Ya=Math.pow(2,31);function ds(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Ya;)t[e++]=r&255|ls,r/=128;for(;r&Za;)t[e++]=r&255|ls,r>>>=7;return t[e]=r|0,ds.bytes=e-n+1,t}var Wa=wn,Xa=128,hs=127;function wn(r,n){var e=0,n=n||0,o=0,s=n,i,c=r.length;do{if(s>=c)throw wn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&hs)<<o:(i&hs)*Math.pow(2,o),o+=7}while(i>=Xa);return wn.bytes=s-n,e}var $a=Math.pow(2,7),Ja=Math.pow(2,14),Qa=Math.pow(2,21),tc=Math.pow(2,28),ec=Math.pow(2,35),rc=Math.pow(2,42),nc=Math.pow(2,49),oc=Math.pow(2,56),sc=Math.pow(2,63),ic=function(r){return r<$a?1:r<Ja?2:r<Qa?3:r<tc?4:r<ec?5:r<rc?6:r<nc?7:r<oc?8:r<sc?9:10},ac={encode:Ga,decode:Wa,encodingLength:ic},cc=ac,ze=cc;function Fe(r,t=0){return[ze.decode(r,t),ze.decode.bytes]}function ve(r,t,e=0){return ze.encode(r,t,e),t}function Ie(r){return ze.encodingLength(r)}function _t(r,t){let e=t.byteLength,n=Ie(r),o=n+Ie(e),s=new Uint8Array(o+e);return ve(r,s,0),ve(e,s,n),s.set(t,o),new Be(r,e,t,s)}function Xt(r){let t=Kt(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 ps(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ss(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 ms(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return fc(e,xn(r),t??X.encoder);default:return lc(e,xn(r),t??Ae.encoder)}}var ys=new WeakMap;function xn(r){let t=ys.get(r);if(t==null){let e=new Map;return ys.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!==hc)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=_t(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&&ps(t.multihash,n.multihash)}toString(t){return ms(this,t)}toJSON(){return{"/":ms(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??bs(n,o,s.bytes))}else if(e[dc]===!0){let{version:n,multihash:o,code:s}=e,i=Xt(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=bs(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=Kt(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]=uc(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 uc(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 Ae.prefix:{let e=t??Ae;return[Ae.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 fc(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 lc(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,hc=18;function bs(r,t,e){let n=Ie(r),o=n+Ie(t),s=new Uint8Array(o+e.byteLength);return ve(r,s,0),ve(t,s,n),s.set(e,o),s}var dc=Symbol.for("@ipld/js-cid/CID");var En={};wt(En,{identity:()=>Lt});var gs=0,pc="identity",ws=Kt;function mc(r){return _t(gs,ws(r))}var Lt={code:gs,name:pc,encode:ws,digest:mc};function xt(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 Es=Symbol.for("@achingbrain/uint8arraylist");function xs(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?.[Es]}var nt=class r{bufs;length;[Es]=!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=xs(this.bufs,t);return e.buf[e.index]}set(t,e){let n=xs(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 A=this.get(f+b);if(n[b]!==A){u=Math.max(1,b-c[A]);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(!xt(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 Sn={};wt(Sn,{base10:()=>yc});var yc=Wt({prefix:"9",name:"base10",alphabet:"0123456789"});var An={};wt(An,{base16:()=>bc,base16upper:()=>gc});var bc=$({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),gc=$({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var vn={};wt(vn,{base2:()=>wc});var wc=$({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var In={};wt(In,{base256emoji:()=>vc});var Ss=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=Ss.reduce((r,t,e)=>(r[e]=t,r),[]),Ec=Ss.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Sc(r){return r.reduce((t,e)=>(t+=xc[e],t),"")}function Ac(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Ec[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:Sc,decode:Ac});var Bn={};wt(Bn,{base64:()=>Ic,base64pad:()=>Bc,base64url:()=>_c,base64urlpad:()=>Lc});var Ic=$({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Bc=$({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),_c=$({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Lc=$({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var _n={};wt(_n,{base8:()=>Tc});var Tc=$({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ln={};wt(Ln,{identity:()=>Pc});var Pc=Se({prefix:"\0",name:"identity",encode:r=>as(r),decode:r=>is(r)});var ll=new TextEncoder,hl=new TextDecoder;var Cn={};wt(Cn,{sha256:()=>ae,sha512:()=>Rc});function Pn({name:r,code:t,encode:e}){return new Tn(r,t,e)}var Tn=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?_t(this.code,e):e.then(n=>_t(this.code,n))}else throw Error("Unknown type, must be binary type")}};function vs(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var ae=Pn({name:"sha2-256",code:18,encode:vs("SHA-256")}),Rc=Pn({name:"sha2-512",code:19,encode:vs("SHA-512")});var Dn={...Ln,...vn,..._n,...Sn,...An,...bn,...gn,...yn,...Bn,...In},vl={...Cn,...En};function Bs(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Is=Bs("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Rn=Bs("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}),Nc={utf8:Is,"utf-8":Is,hex:Dn.base16,latin1:Rn,ascii:Rn,binary:Rn,...Dn},Br=Nc;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 Uc=parseInt("11111",2),Nn=parseInt("10000000",2),Kc=parseInt("01111111",2),_s={0:je,1:je,2:kc,3:qc,4:Hc,5:Mc,6:Oc,16:je,22:je,48:je};function Ot(r,t={offset:0}){let e=r[t.offset]&Uc;if(t.offset++,_s[e]!=null)return _s[e](r,t);throw new Error("No decoder for tag "+e)}function Ze(r,t){let e=0;if((r[t.offset]&Nn)===Nn){let n=r[t.offset]&Kc,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=Ot(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 Oc(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 Mc(r,t){return t.offset++,null}function qc(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 Hc(r,t){let e=Ze(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Vc(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 Un(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Vc(r.byteLength);return new nt(Uint8Array.from([t.byteLength|Nn]),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]),Un(t),t)}function _r(r){let t=Uint8Array.from([0]),e=new nt(t,r);return new nt(Uint8Array.from([3]),Un(e),e)}function Jt(r,t=48){let e=new nt;for(let n of r)e.append(n);return new nt(Uint8Array.from([t]),Un(e),e)}async function Ls(r,t,e,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,e.subarray());return n?.signal?.throwIfAborted(),s}var zc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Fc=Uint8Array.from([6,5,43,129,4,0,34]),Gc=Uint8Array.from([6,5,43,129,4,0,35]),jc={ext:!0,kty:"EC",crv:"P-256"},Zc={ext:!0,kty:"EC",crv:"P-384"},Yc={ext:!0,kty:"EC",crv:"P-521"},Kn=32,kn=48,On=66;function Mn(r){let t=Ot(r);return Ts(t)}function Ts(r){let t=r[1][1][0],e=1,n,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});if(t.byteLength===On*2+1)return n=j(t.subarray(e,e+On),"base64url"),o=j(t.subarray(e+On),"base64url"),new _e({...Yc,key_ops:["verify"],x:n,y:o});throw new W(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Ps(r){return Jt([Et(Uint8Array.from([1])),Jt([Wc(r.crv)],160),Jt([_r(new nt(Uint8Array.from([4]),G(r.x??"","base64url"),G(r.y??"","base64url")))],161)]).subarray()}function Wc(r){if(r==="P-256")return zc;if(r==="P-384")return Fc;if(r==="P-521")return Gc;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=Ps(this.jwk)),this._raw}toMultihash(){return Lt.digest(Mt(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:xt(this.raw,t.raw)}async verify(t,e,n){return Ls(this.jwk,e,t,n)}};var ce=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Xc(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(!Xc(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 Cs(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 Ds(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 qt(...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 Tt(r,t){return r<<32-t|r>>>t}function Rs(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=Rs(r)),ue(r),r}function qn(...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 Hn(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 $c(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 Ns(r,t,e){return r&t^~r&e}function Us(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),Ds(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,qt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)e[f]=0;$c(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()}},Ht=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),Ks=BigInt(32);function Jc(r,t=!1){return t?{h:Number(r&Pr),l:Number(r>>Ks&Pr)}:{h:Number(r>>Ks&Pr)|0,l:Number(r&Pr)|0}}function ks(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}=Jc(r[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var Vn=(r,t,e)=>r>>>e,zn=(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 Dt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Os=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Ms=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,qs=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Hs=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Vs=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),zs=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var tu=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]),Qt=new Uint32Array(64),Cr=class extends We{constructor(t=32){super(64,t,8,!1),this.A=Ht[0]|0,this.B=Ht[1]|0,this.C=Ht[2]|0,this.D=Ht[3]|0,this.E=Ht[4]|0,this.F=Ht[5]|0,this.G=Ht[6]|0,this.H=Ht[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)Qt[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let b=Qt[f-15],A=Qt[f-2],I=Tt(b,7)^Tt(b,18)^b>>>3,m=Tt(A,17)^Tt(A,19)^A>>>10;Qt[f]=m+Qt[f-7]+I+Qt[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=Tt(c,6)^Tt(c,11)^Tt(c,25),A=u+b+Ns(c,a,l)+tu[f]+Qt[f]|0,m=(Tt(n,2)^Tt(n,13)^Tt(n,22))+Us(n,o,s)|0;u=l,l=a,a=c,c=i+A|0,i=s,s=o,o=n,n=A+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(){qt(Qt)}destroy(){this.set(0,0,0,0,0,0,0,0),qt(this.buffer)}};var Fs=ks(["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))),eu=Fs[0],ru=Fs[1],te=new Uint32Array(80),ee=new Uint32Array(80),Fn=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:A,Gl:I,Hh:m,Hl:v}=this;return[t,e,n,o,s,i,c,a,l,u,f,b,A,I,m,v]}set(t,e,n,o,s,i,c,a,l,u,f,b,A,I,m,v){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=A|0,this.Gl=I|0,this.Hh=m|0,this.Hl=v|0}process(t,e){for(let w=0;w<16;w++,e+=4)te[w]=t.getUint32(e),ee[w]=t.getUint32(e+=4);for(let w=16;w<80;w++){let h=te[w-15]|0,y=ee[w-15]|0,B=fe(h,y,1)^fe(h,y,8)^Vn(h,y,7),_=le(h,y,1)^le(h,y,8)^zn(h,y,7),L=te[w-2]|0,N=ee[w-2]|0,k=fe(L,N,19)^Xe(L,N,61)^Vn(L,N,6),C=le(L,N,19)^$e(L,N,61)^zn(L,N,6),U=qs(_,C,ee[w-7],ee[w-16]),R=Hs(U,B,k,te[w-7],te[w-16]);te[w]=R|0,ee[w]=U|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:l,Dl:u,Eh:f,El:b,Fh:A,Fl:I,Gh:m,Gl:v,Hh:P,Hl:M}=this;for(let w=0;w<80;w++){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&A^~f&m,_=b&I^~b&v,L=Vs(M,y,_,ru[w],ee[w]),N=zs(L,P,h,B,eu[w],te[w]),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=v|0,m=A|0,v=I|0,A=f|0,I=b|0,{h:f,l:b}=Dt(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=Os(k,U,et);n=Ms(E,N,C,R),o=E|0}({h:n,l:o}=Dt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Dt(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=Dt(this.Ch|0,this.Cl|0,c|0,a|0),{h:l,l:u}=Dt(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:b}=Dt(this.Eh|0,this.El|0,f|0,b|0),{h:A,l:I}=Dt(this.Fh|0,this.Fl|0,A|0,I|0),{h:m,l:v}=Dt(this.Gh|0,this.Gl|0,m|0,v|0),{h:P,l:M}=Dt(this.Hh|0,this.Hl|0,P|0,M|0),this.set(n,o,s,i,c,a,l,u,f,b,A,I,m,v,P,M)}roundClean(){qt(te,ee)}destroy(){qt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Dr=Hn(()=>new Cr);var Gs=Hn(()=>new Fn);var Yn=BigInt(0),Zn=BigInt(1);function Ce(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Wn(r){if(!Ce(r))throw new Error("Uint8Array expected")}function Rt(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 Ys(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Yn:BigInt("0x"+r)}var Ws=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",nu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function re(r){if(Wn(r),Ws)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=nu[r[e]];return t}var Vt={_0:48,_9:57,A:65,F:70,a:97,f:102};function js(r){if(r>=Vt._0&&r<=Vt._9)return r-Vt._0;if(r>=Vt.A&&r<=Vt.F)return r-(Vt.A-10);if(r>=Vt.a&&r<=Vt.f)return r-(Vt.a-10)}function Qe(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Ws)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=js(r.charCodeAt(s)),c=js(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 zt(r){return Ys(re(r))}function he(r){return Wn(r),Ys(re(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 ne(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Wn(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 Gn=r=>typeof r=="bigint"&&Yn<=r;function Rr(r,t,e){return Gn(r)&&Gn(t)&&Gn(e)&&t<=r&&r<e}function At(r,t,e,n){if(!Rr(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Xs(r){let t;for(t=0;r>Yn;r>>=Zn,t+=1);return t}var pe=r=>(Zn<<BigInt(r))-Zn,jn=r=>new Uint8Array(r),Zs=r=>Uint8Array.from(r);function $s(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=jn(r),o=jn(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},c=(...f)=>e(o,n,...f),a=(f=jn(0))=>{o=c(Zs([0]),f),n=c(),f.length!==0&&(o=c(Zs([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 A=n.slice();b.push(A),f+=n.length}return ne(...b)};return(f,b)=>{i(),a(f);let A;for(;!(A=b(l()));)a();return i(),A}}var ou={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 Ft(r,t,e={}){let n=(o,s,i)=>{let c=ou[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),su=BigInt(3),Qs=BigInt(4),ti=BigInt(5),ei=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 ri(r,t){let e=(r.ORDER+st)/Qs,n=r.pow(t,e);if(!r.eql(r.sqr(n),t))throw new Error("Cannot find square root");return n}function iu(r,t){let e=(r.ORDER-ti)/ei,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 au(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=Gt(r);for(;Js(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return ri;let s=o.pow(n,t),i=(t+st)/me;return function(a,l){if(a.is0(l))return l;if(Js(a,l)!==1)throw new Error("Cannot find square root");let u=e,f=a.mul(a.ONE,s),b=a.pow(l,t),A=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 v=st<<BigInt(u-I-1),P=a.pow(f,v);u=I,f=a.sqr(P),b=a.mul(b,f),A=a.mul(A,P)}return A}}function cu(r){return r%Qs===su?ri:r%ei===ti?iu:au(r)}var ni=(r,t)=>(F(r,t)&st)===st,uu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Xn(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=uu.reduce((n,o)=>(n[o]="function",n),t);return Ft(r,e)}function fu(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 Js(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 $n(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 Gt(r,t,e=!1,n={}){if(r<=mt)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=$n(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)=>fu(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=cu(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):zt(a)},invertBatch:a=>Ne(c,a),cmov:(a,l,u)=>u?l:a});return Object.freeze(c)}function oi(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 Jn(r){let t=oi(r);return t+Math.ceil(t/2)}function si(r,t,e=!1){let n=r.length,o=oi(t),s=Jn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?he(r):zt(r),c=F(i,t-st)+st;return e?De(c,o):de(c,o)}var ii=BigInt(0),no=BigInt(1);function Qn(r,t){let e=t.negate();return r?e:t}function ci(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function to(r,t){ci(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 ai(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+=no);let l=t*n,u=l+Math.abs(c)-1,f=c===0,b=c<0,A=t%2!==0;return{nextN:a,offset:u,isZero:f,isNeg:b,isNegF:A,offsetF:l}}function lu(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 hu(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 eo=new WeakMap,ui=new WeakMap;function ro(r){return ui.get(r)||1}function Ur(r,t){return{constTimeNegate:Qn,hasPrecomputes(e){return ro(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>ii;)n&no&&(o=o.add(s)),s=s.double(),n>>=no;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=to(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=to(e,t);for(let a=0;a<c.windows;a++){let{nextN:l,offset:u,isZero:f,isNeg:b,isNegF:A,offsetF:I}=ai(o,a,c);o=l,f?i=i.add(Qn(A,n[I])):s=s.add(Qn(b,n[u]))}return{p:s,f:i}},wNAFUnsafe(e,n,o,s=r.ZERO){let i=to(e,t);for(let c=0;c<i.windows&&o!==ii;c++){let{nextN:a,offset:l,isZero:u,isNeg:f}=ai(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=eo.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&eo.set(n,o(s))),s},wNAFCached(e,n,o){let s=ro(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=ro(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){ci(n,t),ui.set(e,n),eo.delete(e)}}}function Kr(r,t,e,n){lu(e,r),hu(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=Xs(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 A=f;A>=0;A-=a){u.fill(i);for(let m=0;m<s;m++){let v=n[m],P=Number(v>>BigInt(A)&l);u[P]=u[P].add(e[m])}let I=i;for(let m=u.length-1,v=i;m>0;m--)v=v.add(u[m]),I=I.add(v);if(b=b.add(I),A!==0)for(let m=0;m<a;m++)b=b.double()}return b}function tr(r){return Xn(r.Fp),Ft(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...$n(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Nt=BigInt(0),yt=BigInt(1),fi=BigInt(2),du=BigInt(8),pu={zip215:!0};function mu(r){let t=tr(r);return Ft(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function li(r){let t=mu(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:c,h:a}=t,l=fi<<BigInt(c*8)-yt,u=e.create,f=Gt(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 A=t.uvRatio||((g,d)=>{try{return{isValid:!0,value:e.sqrt(g*e.inv(d))}}catch{return{isValid:!1,value:Nt}}}),I=t.adjustScalarBytes||(g=>g),m=t.domain||((g,d,p)=>{if(Rt("phflag",p),d.length||p)throw new Error("Contexts/pre-hash are not supported");return g});function v(g,d,p=!1){let S=p?yt:Nt;At("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?du:e.inv(D));let O=u(p*d),q=u(S*d),H=u(D*d);if(K)return{x:Nt,y:yt};if(H!==yt)throw new Error("invZ was invalid");return{x:O,y:q}}),w=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){v("x",d),v("y",p),v("z",S,!0),v("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 v("x",p),v("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(){w(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(fi*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),Bt=u(at*J);return new h(ot,ut,Bt,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),Bt=ut-ot,qe=ut+ot,ns=u(gt-p*at),ba=u(St*Bt),ga=u(qe*ns),wa=u(St*ns),xa=u(Bt*qe);return new h(ba,ga,xa,wa)}subtract(d){return this.add(d.negate())}wNAF(d){return _.wNAFCached(this,d,h.normalizeZ)}multiply(d){let p=d;At("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 At("scalar",S,Nt,n),S===Nt?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),Rt("zip215",p);let O=d.slice(),q=d[K-1];O[K-1]=q&-129;let H=he(O),z=p?l:e.ORDER;At("pointHex.y",H,Nt,z);let rt=u(H*H),J=u(rt-yt),at=u(S*rt-D),{isValid:gt,value:ot}=A(J,at);if(!gt)throw new Error("Point.fromHex: invalid y coordinate");let ut=(ot&yt)===yt,St=(q&128)!==0;if(!p&&ot===Nt&&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 re(this.toRawBytes())}}h.BASE=new h(t.Gx,t.Gy,yt,u(t.Gx*t.Gy)),h.ZERO=new h(Nt,yt,yt,Nt);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=ne(...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);At("signature.s",z,Nt,n);let rt=ne(q,De(z,e.BYTES));return Z("result",rt,e.BYTES*2)}let E=pu;function x(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&&Rt("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:x,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 oo=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),hi=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),_h=BigInt(0),yu=BigInt(1),di=BigInt(2),Lh=BigInt(3),bu=BigInt(5),gu=BigInt(8);function wu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=oo,c=r*r%s*r%s,a=Y(c,di,s)*c%s,l=Y(a,yu,s)*r%s,u=Y(l,bu,s)*l%s,f=Y(u,t,s)*u%s,b=Y(f,e,s)*f%s,A=Y(b,n,s)*b%s,I=Y(A,o,s)*A%s,m=Y(I,o,s)*A%s,v=Y(m,t,s)*u%s;return{pow_p_5_8:Y(v,di,s)*r%s,b2:c}}function xu(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Eu(r,t){let e=oo,n=F(t*t*t,e),o=F(n*n*t,e),s=wu(r*o).pow_p_5_8,i=F(r*n*s,e),c=F(t*i*i,e),a=i,l=F(i*hi,e),u=c===r,f=c===F(-r,e),b=c===F(-r*hi,e);return u&&(i=a),(f||b)&&(i=l),ni(i,e)&&(i=F(-i,e)),{isValid:u||f,value:i}}var pi=Gt(oo,void 0,!0),Su={a:pi.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:pi,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:gu,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Gs,randomBytes:Pe,adjustScalarBytes:xu,uvRatio:Eu},mi=li(Su);var er=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},kr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var yi={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new kr("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 It=yi;var Or=32;var so,Au=(async()=>{try{return await It.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function vu(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await It.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await It.get().subtle.verify({name:"Ed25519"},n,t,e instanceof Uint8Array?e:e.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Iu(r,t,e){return mi.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function bi(r,t,e){return so==null&&(so=await Au),so?vu(r,t,e):Iu(r,t,e)}function Mr(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var qr=class{type="Ed25519";raw;constructor(t){this.raw=io(t,Or)}toMultihash(){return Lt.digest(Mt(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:xt(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=bi(this.raw,e,t);return Mr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function ao(r){return r=io(r,Or),new qr(r)}function io(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 _u=Math.pow(2,7),Lu=Math.pow(2,14),Tu=Math.pow(2,21),co=Math.pow(2,28),uo=Math.pow(2,35),fo=Math.pow(2,42),lo=Math.pow(2,49),V=128,ht=127;function Pt(r){if(r<_u)return 1;if(r<Lu)return 2;if(r<Tu)return 3;if(r<co)return 4;if(r<uo)return 5;if(r<fo)return 6;if(r<lo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ho(r,t,e=0){switch(Pt(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 Pu(r,t,e=0){switch(Pt(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 po(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)*co,e<V)||(e=r[t+5],n+=(e&ht)*uo,e<V)||(e=r[t+6],n+=(e&ht)*fo,e<V)||(e=r[t+7],n+=(e&ht)*lo,e<V))return n;throw new RangeError("Could not decode varint")}function Cu(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)*co,e<V)||(e=r.get(t+5),n+=(e&ht)*uo,e<V)||(e=r.get(t+6),n+=(e&ht)*fo,e<V)||(e=r.get(t+7),n+=(e&ht)*lo,e<V))return n;throw new RangeError("Could not decode varint")}function wi(r,t,e=0){return t==null&&(t=lt(Pt(r))),t instanceof Uint8Array?ho(r,t,e):Pu(r,t,e)}function xi(r,t=0){return r instanceof Uint8Array?po(r,t):Cu(r,t)}var mo=new Float32Array([-0]),oe=new Uint8Array(mo.buffer);function Si(r,t,e){mo[0]=r,t[e]=oe[0],t[e+1]=oe[1],t[e+2]=oe[2],t[e+3]=oe[3]}function Ai(r,t){return oe[0]=r[t],oe[1]=r[t+1],oe[2]=r[t+2],oe[3]=r[t+3],mo[0]}var yo=new Float64Array([-0]),dt=new Uint8Array(yo.buffer);function vi(r,t,e){yo[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 Ii(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],yo[0]}var Du=BigInt(Number.MAX_SAFE_INTEGER),Ru=BigInt(Number.MIN_SAFE_INTEGER),vt=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<Du&&t>Ru)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>Bi&&(o=0n,++n>Bi&&(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 vt(0,0);ye.toBigInt=function(){return 0n};ye.zzEncode=ye.zzDecode=function(){return this};ye.length=function(){return 1};var Bi=4294967296n;function _i(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 Li(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 bo(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 Ct(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Hr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var go=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,Ct(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 Ct(this,4);return Hr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ct(this,4);return Hr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ct(this,4);let t=Ai(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Ct(this,4);let t=Ii(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 Ct(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Li(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Ct(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Ct(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 vt(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 Ct(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 Ct(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 Ct(this,8);let t=Hr(this.buf,this.pos+=4),e=Hr(this.buf,this.pos+=4);return new vt(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=po(this.buf,this.pos);return this.pos+=Pt(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 wo(r){return new go(r instanceof Uint8Array?r:r.subarray())}function Vr(r,t,e){let n=wo(r);return t.decode(n,void 0,e)}function xo(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 Eo(){}var Ao=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Nu=xo();function Uu(r){return globalThis.Buffer!=null?lt(r):Nu(r)}var nr=class{len;head;tail;states;constructor(){this.len=0,this.head=new be(Eo,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 vo((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(zr,10,vt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=vt.fromBigInt(t);return this._push(zr,e.length(),e)}uint64Number(t){return this._push(ho,Pt(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=vt.fromBigInt(t).zzEncode();return this._push(zr,e.length(),e)}sint64Number(t){let e=vt.fromNumber(t).zzEncode();return this._push(zr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(So,1,t?1:0)}fixed32(t){return this._push(rr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=vt.fromBigInt(t);return this._push(rr,4,e.lo)._push(rr,4,e.hi)}fixed64Number(t){let e=vt.fromNumber(t);return this._push(rr,4,e.lo)._push(rr,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(Si,4,t)}double(t){return this._push(vi,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(So,1,0):this.uint32(e)._push(ku,e,t)}string(t){let e=_i(t);return e!==0?this.uint32(e)._push(bo,e,t):this._push(So,1,0)}fork(){return this.states=new Ao(this),this.head=this.tail=new be(Eo,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(Eo,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=Uu(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function So(r,t,e){t[e]=r&255}function Ku(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var vo=class extends be{next;constructor(t,e){super(Ku,t,e),this.next=void 0}};function zr(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 rr(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 ku(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(nr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Ou,t,r),this},nr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Mu,t,r),this});function Ou(r,t,e){t.set(r,e)}function Mu(r,t,e){r.length<40?bo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(G(r),e)}function Io(){return new nr}function Fr(r,t){let e=Io();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 Gr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Bo(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 Gr("enum",Ue.VARINT,e,n)}function jr(r,t){return Gr("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 _o;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(_o||(_o={}));(function(r){r.codec=()=>Bo(_o)})(tt||(tt={}));var Ut;(function(r){let t;r.codec=()=>(t==null&&(t=jr((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=>Fr(e,r.codec()),r.decode=(e,n)=>Vr(e,r.codec(),n)})(Ut||(Ut={}));var Lo;(function(r){let t;r.codec=()=>(t==null&&(t=jr((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=>Fr(e,r.codec()),r.decode=(e,n)=>Vr(e,r.codec(),n)})(Lo||(Lo={}));function Zr(r){if(isNaN(r)||r<=0)throw new W("random bytes length must be a Number bigger than 0");return Pe(r)}var sr={};wt(sr,{MAX_RSA_KEY_SIZE:()=>To,generateRSAKeyPair:()=>Ni,jwkToJWKKeyPair:()=>Ui,jwkToPkcs1:()=>zu,jwkToPkix:()=>Ro,jwkToRSAPrivateKey:()=>ko,pkcs1MessageToJwk:()=>Co,pkcs1MessageToRSAPrivateKey:()=>No,pkcs1ToJwk:()=>Vu,pkcs1ToRSAPrivateKey:()=>Ri,pkixMessageToJwk:()=>Do,pkixMessageToRSAPublicKey:()=>Ko,pkixToJwk:()=>Fu,pkixToRSAPublicKey:()=>Uo});var Yr=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:xt(this.raw,t.raw)}verify(t,e,n){return Di(this.jwk,e,t,n)}},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:xt(this.raw,t.raw)}sign(t,e){return Ci(this.jwk,t,e)}};var To=8192,Po=18,qu=1062,Hu=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Vu(r){let t=Ot(r);return Co(t)}function Co(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 zu(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 Jt([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 Fu(r){let t=Ot(r,{offset:0});return Do(t)}function Do(r){let t=Ot(r[1],{offset:0});return{kty:"RSA",n:j(t[0],"base64url"),e:j(t[1],"base64url")}}function Ro(r){if(r.n==null||r.e==null)throw new W("JWK was missing components");return Jt([Hu,_r(Jt([Et(G(r.n,"base64url")),Et(G(r.e,"base64url"))]))]).subarray()}function Ri(r){let t=Ot(r);return No(t)}function No(r){let t=Co(r);return ko(t)}function Uo(r,t){if(r.byteLength>=qu)throw new xe("Key size is too large");let e=Ot(r,{offset:0});return Ko(e,r,t)}function Ko(r,t,e){let n=Do(r);if(e==null){let o=Yr(Ut.encode({Type:tt.RSA,Data:t}));e=_t(Po,o)}return new Ke(n,e)}function ko(r){if(ki(r)>To)throw new W("Key size is too large");let t=Ui(r),e=Yr(Ut.encode({Type:tt.RSA,Data:Ro(t.publicKey)})),n=_t(Po,e);return new or(t.privateKey,new Ke(t.publicKey,n))}async function Ni(r){if(r>To)throw new W("Key size is too large");let t=await Ki(r),e=Yr(Ut.encode({Type:tt.RSA,Data:Ro(t.publicKey)})),n=_t(Po,e);return new or(t.privateKey,new Ke(t.publicKey,n))}function Ui(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 Ki(r,t){let e=await It.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Gu(e,t);return{privateKey:n[0],publicKey:n[1]}}async function Ci(r,t,e){let n=await It.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);e?.signal?.throwIfAborted();let o=await It.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return e?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Di(r,t,e,n){let o=await It.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await It.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,e instanceof Uint8Array?e:e.subarray());return n?.signal?.throwIfAborted(),s}async function Gu(r,t){if(r.privateKey==null||r.publicKey==null)throw new W("Private and public key are required");let e=await Promise.all([It.get().subtle.exportKey("jwk",r.privateKey),It.get().subtle.exportKey("jwk",r.publicKey)]);return t?.signal?.throwIfAborted(),e}function ki(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 Wr=class extends Le{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Cs(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),qt(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()}},Oo=(r,t,e)=>new Wr(r,t).update(e).digest();Oo.create=(r,t)=>new Wr(r,t);function Oi(r){r.lowS!==void 0&&Rt("lowS",r.lowS),r.prehash!==void 0&&Rt("prehash",r.prehash)}function ju(r){let t=tr(r);Ft(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 Ho=class extends Error{constructor(t=""){super(t)}},jt={Err:Ho,_tlv:{encode:(r,t)=>{let{Err:e}=jt;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}=jt,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}=jt;if(r<Zt)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}=jt;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 zt(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=jt,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}=jt,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 Mo(r,t){return re(de(r,t))}var Zt=BigInt(0),it=BigInt(1),fp=BigInt(2),qo=BigInt(3),Zu=BigInt(4);function Yu(r){let t=ju(r),{Fp:e}=t,n=Gt(t.n,t.nBitLength),o=t.toBytes||((w,h,y)=>{let B=h.toAffine();return ne(Uint8Array.from([4]),e.toBytes(B.x),e.toBytes(B.y))}),s=t.fromBytes||(w=>{let h=w.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(w){let{a:h,b:y}=t,B=e.sqr(w),_=e.mul(B,w);return e.add(e.add(_,e.mul(w,h)),y)}function c(w,h){let y=e.sqr(h),B=i(w);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,qo),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(w){return Rr(w,it,t.n)}function f(w){let{allowedPrivateKeyLengths:h,nByteLength:y,wrapPrivateKey:B,n:_}=t;if(h&&typeof w!="bigint"){if(Ce(w)&&(w=re(w)),typeof w!="string"||!h.includes(w.length))throw new Error("invalid private key");w=w.padStart(y*2,"0")}let L;try{L=typeof w=="bigint"?w:zt(Z("private key",w,y))}catch{throw new Error("invalid private key, expected hex or "+y+" bytes, got "+typeof w)}return B&&(L=F(L,_)),At("private key",L,it,_),L}function b(w){if(!(w instanceof m))throw new Error("ProjectivePoint expected")}let A=Re((w,h)=>{let{px:y,py:B,pz:_}=w;if(e.eql(_,e.ONE))return{x:y,y:B};let L=w.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(w=>{if(w.is0()){if(t.allowInfinityPoint&&!e.is0(w.py))return;throw new Error("bad point: ZERO")}let{x:h,y}=w.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(!w.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,qo),{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),x=e.mul(_,L);return x=e.add(x,x),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(x,k),U=e.mul(B,U),E=e.mul(h,E),x=e.sub(R,E),x=e.mul(h,x),x=e.add(x,U),U=e.add(R,R),R=e.add(U,R),R=e.add(R,E),R=e.mul(R,x),C=e.add(C,R),E=e.mul(L,N),E=e.add(E,E),R=e.mul(E,x),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,qo),x=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(x,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(x,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(x,x),T=e.add(T,x),g=e.mul(et,g),p=e.mul(E,p),T=e.add(T,g),g=e.sub(x,g),g=e.mul(et,g),p=e.add(p,g),x=e.mul(T,p),U=e.add(U,x),x=e.mul(S,p),C=e.mul(d,C),C=e.sub(C,x),x=e.mul(d,T),R=e.mul(S,R),R=e.add(R,x),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;At("scalar",h,Zt,B);let _=m.ZERO;if(h===Zt)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>Zt||C>Zt;)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;At("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:x}=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(x)}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===Zt||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 A(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 Rt("isCompressed",h),this.assertValidity(),o(m,this,h)}toHex(h=!0){return Rt("isCompressed",h),re(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:v,nBitLength:P}=t,M=Ur(m,v?Math.ceil(P/2):P);return{CURVE:t,ProjectivePoint:m,normPrivateKeyToScalar:f,weierstrassEquation:i,isWithinCurveOrder:u}}function Wu(r){let t=tr(r);return Ft(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Mi(r){let t=Wu(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:A}=Yu({...t,toBytes(E,x,T){let g=x.toAffine(),d=e.toBytes(g.x),p=ne;return Rt("isCompressed",T),T?p(Uint8Array.from([x.hasEvenY()?2:3]),d):p(Uint8Array.from([4]),d,e.toBytes(g.y))},fromBytes(E){let x=E.length,T=E[0],g=E.subarray(1);if(x===i&&(T===2||T===3)){let d=zt(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(x===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 "+x)}}});function I(E){let x=n>>it;return E>x}function m(E){return I(E)?a(-E):E}let v=(E,x,T)=>zt(E.slice(x,T));class P{constructor(x,T,g){At("r",x,it,n),At("s",T,it,n),this.r=x,this.s=T,g!=null&&(this.recovery=g),Object.freeze(this)}static fromCompact(x){let T=o;return x=Z("compactSignature",x,T*2),new P(v(x,0,T),v(x,T,2*T))}static fromDER(x){let{r:T,s:g}=jt.toSig(Z("DER",x));return new P(T,g)}assertValidity(){}addRecoveryBit(x){return new P(this.r,this.s,x)}recoverPublicKey(x){let{r:T,s:g,recovery:d}=this,p=_(Z("msgHash",x));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+Mo(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 jt.hexFromSig(this)}toCompactRawBytes(){return Qe(this.toCompactHex())}toCompactHex(){let x=o;return Mo(this.r,x)+Mo(this.s,x)}}let M={isValidPrivateKey(E){try{return f(E),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let E=Jn(t.n);return si(t.randomBytes(E),t.n)},precompute(E=8,x=u.BASE){return x._setWindowSize(E),x.multiply(BigInt(3)),x}};function w(E,x=!0){return u.fromPrivateKey(E).toRawBytes(x)}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,x,T=!0){if(h(E)===!0)throw new Error("first arg must be private key");if(h(x)===!1)throw new Error("second arg must be public key");return u.fromHex(x).multiply(f(E)).toRawBytes(T)}let B=t.bits2int||function(E){if(E.length>8192)throw new Error("input is too large");let x=zt(E),T=E.length*8-s;return T>0?x>>BigInt(T):x},_=t.bits2int_modN||function(E){return a(B(E))},L=pe(s);function N(E){return At("num < 2^"+s,E,Zt,L),de(E,o)}function k(E,x,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),Oi(T),S&&(E=Z("prehashed msgHash",g(E)));let K=_(E),O=f(x),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=ne(...q),z=K;function rt(J){let at=B(J);if(!A(at))return;let gt=l(at),ot=u.BASE.multiply(at).toAffine(),ut=a(ot.x);if(ut===Zt)return;let St=a(gt*a(z+ut*O));if(St===Zt)return;let Bt=(ot.x===ut?0:2)|Number(ot.y&it),qe=St;return p&&I(St)&&(qe=m(St),Bt^=1),new P(ut,qe,Bt)}return{seed:H,k2sig:rt}}let C={lowS:t.lowS,prehash:!1},U={lowS:t.lowS,prehash:!1};function R(E,x,T=C){let{seed:g,k2sig:d}=k(E,x,T),p=t;return $s(p.hash.outputLen,p.nByteLength,p.hmac)(g,d)}u.BASE._setWindowSize(8);function et(E,x,T,g=U){let d=E;x=Z("msgHash",x),T=Z("publicKey",T);let{lowS:p,prehash:S,format:D}=g;if(Oi(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(Bt){if(!(Bt instanceof jt.Err))throw Bt}!q&&D!=="der"&&(q=P.fromCompact(d))}H=u.fromHex(T)}catch{return!1}if(!q||p&&q.hasHighS())return!1;S&&(x=t.hash(x));let{r:z,s:rt}=q,J=_(x),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:w,getSharedSecret:y,sign:R,verify:et,ProjectivePoint:u,Signature:P,utils:M}}function Xu(r){return{hash:r,hmac:(t,...e)=>Oo(r,t,qn(...e)),randomBytes:Pe}}function qi(r,t){let e=n=>Mi({...r,...Xu(n)});return{...e(t),create:e}}var zi=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Hi=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),$u=BigInt(0),Ju=BigInt(1),Vo=BigInt(2),Vi=(r,t)=>(r+t/Vo)/t;function Qu(r){let t=zi,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,A=Y(b,Vo,t)*l%t,I=Y(A,o,t)*A%t,m=Y(I,s,t)*I%t,v=Y(m,c,t)*m%t,P=Y(v,a,t)*v%t,M=Y(P,c,t)*m%t,w=Y(M,e,t)*u%t,h=Y(w,i,t)*I%t,y=Y(h,n,t)*l%t,B=Y(y,Vo,t);if(!zo.eql(zo.sqr(B),r))throw new Error("Cannot find square root");return B}var zo=Gt(zi,void 0,void 0,{sqrt:Qu}),ke=qi({a:$u,b:BigInt(7),Fp:zo,n:Hi,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Hi,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Ju*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),c=Vi(s*r,t),a=Vi(-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 Fi(r,t,e,n){let o=ae.digest(e instanceof Uint8Array?e:e.subarray());if(Mr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),ke.verify(t,s,r))).catch(s=>{throw s.name==="AbortError"?s:new er(String(s))});try{return n?.signal?.throwIfAborted(),ke.verify(t,o.digest,r)}catch(s){throw new er(String(s))}}var Xr=class{type="secp256k1";raw;_key;constructor(t){this._key=ji(t),this.raw=Gi(this._key)}toMultihash(){return Lt.digest(Mt(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:xt(this.raw,t.raw)}verify(t,e,n){return Fi(this._key,e,t,n)}};function Fo(r){return new Xr(r)}function Gi(r){return ke.ProjectivePoint.fromHex(r).toRawBytes(!0)}function ji(r){try{return ke.ProjectivePoint.fromHex(r),r}catch(t){throw new xe(String(t))}}function Go(r,t){let{Type:e,Data:n}=Ut.decode(r),o=n??new Uint8Array;switch(e){case tt.RSA:return Uo(o,t);case tt.Ed25519:return ao(o);case tt.secp256k1:return Fo(o);case tt.ECDSA:return Mn(o);default:throw new se}}function Zi(r){let{Type:t,Data:e}=Ut.decode(r.digest),n=e??new Uint8Array;switch(t){case tt.Ed25519:return ao(n);case tt.secp256k1:return Fo(n);case tt.ECDSA:return Mn(n);default:throw new se}}function Mt(r){return Ut.encode({Type:tt[r.type],Data:r.raw})}var Yi=Symbol.for("nodejs.util.inspect.custom"),tf=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()})`}[ln]=!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(tf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return xt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return xt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Yi](){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}},ef=2336,$r=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Lt.digest(G(this.url))}[Yi](){return`PeerId(${this.url})`}[ln]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ft.createV1(ef,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=j(t)),t.toString()===this.toString())}};function jo(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 Wi(r){return jo(r.publicKey)}function fr(r){if(nf(r))return new ar({multihash:r});if(rf(r))try{let t=Zi(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 $r(new URL(e))}throw new Sr("Supplied PeerID Multihash is invalid")}function rf(r){return r.code===Lt.code}function nf(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 Jr(r){let t=Xt(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=Jr(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Jr(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return ge(this.set.values(),t=>Jr(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 Yt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Qr=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 Qr(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 Qr(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 Zo=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function tn(r={}){return of(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 of(r,t){t=t??{};let e=t.onEnd,n=new Oe,o,s,i,c=Yt(),a=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((v,P)=>{s=M=>{s=null,n.push(M);try{v(r(n))}catch(w){P(w)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=Yt()})}},l=v=>s!=null?s(v):(n.push(v),o),u=v=>(n=new Oe,s!=null?s({error:v}):(n.push({error:v}),o)),f=v=>{if(i)return o;if(t?.objectMode!==!0&&v?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:v})},b=v=>i?o:(i=!0,v!=null?u(v):l({done:!0})),A=()=>(n=new Oe,b(),{done:!0}),I=v=>(b(v),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:a,return:A,throw:I,push:f,end:b,get readableLength(){return n.size},onEmpty:async v=>{let P=v?.signal;if(P?.throwIfAborted(),n.isEmpty())return;let M,w;P!=null&&(M=new Promise((h,y)=>{w=()=>{y(new Zo)},P.addEventListener("abort",w)}));try{await Promise.race([c.promise,M])}finally{w!=null&&P!=null&&P?.removeEventListener("abort",w)}}},e==null)return o;let m=o;return o={[Symbol.asyncIterator](){return this},next(){return m.next()},throw(v){return m.throw(v),e!=null&&(e(v),e=void 0),{done:!0}},return(){return m.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(v){return m.end(v),e!=null&&(e(v),e=void 0),o},get readableLength(){return m.readableLength},onEmpty:v=>m.onEmpty(v)},o}var en=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 Xi(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new en(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new en(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 Yo=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Yt(),this.haveNext=Yt()}[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=Yt(),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=Yt(),await Xi(this.readNext.promise,e?.signal,e)}};function $i(){return new Yo}function sf(r){return r[Symbol.asyncIterator]!=null}async function af(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*cf(r){let t=new AbortController,e=$i();af(r,e,t.signal).catch(()=>{});try{yield*e}finally{t.abort()}}function*uf(r){for(let t of r)yield*t}function ff(...r){let t=[];for(let e of r)sf(e)||t.push(e);return t.length===r.length?uf(t):cf(r)}var Ji=ff;function dr(r,...t){if(r==null)throw new Error("Empty pipeline");if(Wo(r)){let n=r;r=()=>n.source}else if(ta(r)||Qi(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&Wo(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++)Wo(e[n])&&(e[n]=hf(e[n]));return lf(...e)}var lf=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},Qi=r=>r?.[Symbol.asyncIterator]!=null,ta=r=>r?.[Symbol.iterator]!=null,Wo=r=>r==null?!1:r.sink!=null&&r.source!=null,hf=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=tn({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let o,s=r.source;if(Qi(s))o=async function*(){yield*s,n.end()};else if(ta(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Ji(n,o())}return r.source};var $o=_a(ra(),1);var mr=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},Jo=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},na=r=>globalThis.DOMException===void 0?new Jo(r):new DOMException(r),oa=r=>{let t=r.reason===void 0?na("This operation was aborted."):r.reason;return t instanceof Error?t:na(t)};function Qo(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:A}=t;A.aborted&&f(oa(A)),c=()=>{f(oa(A))},A.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(A){f(A)}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(A){f(A)}})()}).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 ts(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=ts(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 $o.default{#t;#i;#s=0;#d;#a;#p=0;#r;#c;#e;#m;#n=0;#u;#o;#y;#w=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#x(){return this.#i||this.#s<this.#d}get#E(){return this.#n<this.#u}#S(){this.#n--,this.#f(),this.emit("next")}#A(){this.#g(),this.#b(),this.#c=void 0}get#v(){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.#A()},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.#v;if(this.#x&&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.#w++).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=Qo(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 sa(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 ia(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function aa(r,t){let e=sa(r).return?.();ia(e)&&e.catch(n=>{t.error("could not cause iterator to return",n)})}var nn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Me=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},on=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},gr=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function sn(r){return r[Symbol.asyncIterator]!=null}function ca(r,t){if(r.byteLength>t)throw new Me("Message length too long")}var cn=r=>{let t=Pt(r),e=lt(t);return wi(r,e),cn.bytes=t,e};cn.bytes=0;function un(r,t){t=t??{};let e=t.lengthEncoder??cn,n=t?.maxDataLength??4194304;function*o(s){ca(s,n);let i=e(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return sn(r)?async function*(){for await(let s of r)yield*o(s)}():function*(){for(let s of r)yield*o(s)}()}un.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??cn,n=t?.maxDataLength??4194304;return ca(r,n),new nt(e(r.byteLength),r)};var we;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(we||(we={}));var es=r=>{let t=xi(r);return es.bytes=Pt(t),t};es.bytes=0;function wr(r,t){let e=new nt,n=we.LENGTH,o=-1,s=t?.lengthDecoder??es,i=t?.maxLengthLength??8,c=t?.maxDataLength??4194304;function*a(){for(;e.byteLength>0;){if(n===we.LENGTH)try{if(o=s(e),o<0)throw new nn("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=we.DATA}catch(l){if(l instanceof RangeError){if(e.byteLength>i)throw new on("Message length length too long");break}throw l}if(n===we.DATA){if(e.byteLength<o)break;let l=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(l),yield l,n=we.LENGTH}}}return sn(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")}()}wr.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 wr(n,{...t??{},onLength:s=>{e=s}})};var fn=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=()=>{aa(t.source,this.log)};return this._inboundAbortController.signal.addEventListener("abort",n,{once:!0}),this._rawInboundStream=t,this.inboundStream=dr(this._rawInboundStream,o=>wr(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=tn({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=>un(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 ua(){return BigInt(`0x${j(Zr(8),"base16")}`)}var fa=(r,t)=>{let e=G(t.toString(16).padStart(16,"0"),"base16"),n=Mt(r),o=new Uint8Array(n.byteLength+e.length);return o.set(n,0),o.set(e,n.byteLength),o},la=r=>ae.encode(r);var ha=function(r){return Array.isArray(r)?r:[r]},bf=async r=>{if(r.sequenceNumber==null||r.from==null||r.signature==null)return!1;let t=fr(Xt(r.from));if(t.publicKey!=null)return!0;if(r.key!=null){let e=r.key;return jo(Go(e)).equals(t)}return!1},da=async r=>{if(r.from==null)throw new Q("RPC message was missing from");if(!await bf(r))return{type:"unsigned",topic:r.topic??"",data:r.data??new Uint8Array(0)};let t=fr(Xt(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:wf(r.sequenceNumber??new Uint8Array(0)),data:r.data??new Uint8Array(0),signature:r.signature??new Uint8Array(0),key:e instanceof Uint8Array?Go(e):e}},xr=r=>r.type==="signed"?{from:r.from.toMultihash().bytes,data:r.data,sequenceNumber:gf(r.sequenceNumber),topic:r.topic,signature:r.signature,key:r.key?Mt(r.key):void 0}:{data:r.data,topic:r.topic},gf=r=>{let t=r.toString(16);return t.length%2!==0&&(t=`0${t}`),G(t,"base16")},wf=r=>BigInt(`0x${j(r,"base16")}`);var pa=G("libp2p-pubsub:");async function ma(r,t,e){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:Wi(r)},o=ie([pa,e(xr(n)).subarray()]);return n.signature=await r.sign(o),n.key=r.publicKey,n}async function ya(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([pa,t({...xr(r),signature:void 0,key:void 0}).subarray()]);return xf(r).verify(e,r.signature)}function xf(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 rs=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=ha(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 fn(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 da(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 fa(t.key,t.sequenceNumber);case"StrictNoSign":return la(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(xr)})}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 ya(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 ma(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 Ar("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:ua()};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 La(Ef);})();
|
2
|
+
"use strict";var Libp2PPubsub=(()=>{var fa=Object.create;var br=Object.defineProperty;var la=Object.getOwnPropertyDescriptor;var ha=Object.getOwnPropertyNames;var da=Object.getPrototypeOf,pa=Object.prototype.hasOwnProperty;var ma=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),ht=(r,t)=>{for(var e in t)br(r,e,{get:t[e],enumerable:!0})},Yo=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ha(t))!pa.call(r,o)&&o!==e&&br(r,o,{get:()=>t[o],enumerable:!(n=la(t,o))||n.enumerable});return r};var ya=(r,t,e)=>(e=r!=null?fa(da(r)):{},Yo(t||!r||!r.__esModule?br(e,"default",{value:r,enumerable:!0}):e,r)),ba=r=>Yo(br({},"__esModule",{value:!0}),r);var Yi=ma((F0,zo)=>{"use strict";var af=Object.prototype.hasOwnProperty,lt="~";function fr(){}Object.create&&(fr.prototype=Object.create(null),new fr().__proto__||(lt=!1));function cf(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function $i(r,t,e,n,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var s=new cf(e,n||r,o),i=lt?lt+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 fr:delete r._events[t]}function at(){this._events=new fr,this._eventsCount=0}at.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)af.call(e,n)&&t.push(lt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};at.prototype.listeners=function(t){var e=lt?lt+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};at.prototype.listenerCount=function(t){var e=lt?lt+t:t,n=this._events[e];return n?n.fn?1:n.length:0};at.prototype.emit=function(t,e,n,o,s,i){var a=lt?lt+t:t;if(!this._events[a])return!1;var c=this._events[a],l=arguments.length,u,f;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),l){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,e),!0;case 3:return c.fn.call(c.context,e,n),!0;case 4:return c.fn.call(c.context,e,n,o),!0;case 5:return c.fn.call(c.context,e,n,o,s),!0;case 6:return c.fn.call(c.context,e,n,o,s,i),!0}for(f=1,u=new Array(l-1);f<l;f++)u[f-1]=arguments[f];c.fn.apply(c.context,u)}else{var b=c.length,p;for(f=0;f<b;f++)switch(c[f].once&&this.removeListener(t,c[f].fn,void 0,!0),l){case 1:c[f].fn.call(c[f].context);break;case 2:c[f].fn.call(c[f].context,e);break;case 3:c[f].fn.call(c[f].context,e,n);break;case 4:c[f].fn.call(c[f].context,e,n,o);break;default:if(!u)for(p=1,u=new Array(l-1);p<l;p++)u[p-1]=arguments[p];c[f].fn.apply(c[f].context,u)}}return!0};at.prototype.on=function(t,e,n){return $i(this,t,e,n,!1)};at.prototype.once=function(t,e,n){return $i(this,t,e,n,!0)};at.prototype.removeListener=function(t,e,n,o){var s=lt?lt+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 a=0,c=[],l=i.length;a<l;a++)(i[a].fn!==e||o&&!i[a].once||n&&i[a].context!==n)&&c.push(i[a]);c.length?this._events[s]=c.length===1?c[0]:c:en(this,s)}return this};at.prototype.removeAllListeners=function(t){var e;return t?(e=lt?lt+t:t,this._events[e]&&en(this,e)):(this._events=new fr,this._eventsCount=0),this};at.prototype.off=at.prototype.removeListener;at.prototype.addListener=at.prototype.on;at.prefixed=lt;at.EventEmitter=at;typeof zo<"u"&&(zo.exports=at)});var mf={};ht(mf,{PubSubBaseProtocol:()=>$o});var ln=Symbol.for("@libp2p/peer-id");var Ke;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(Ke||(Ke={}));var gf=Symbol.for("@libp2p/pubsub");var V=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},he=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var gr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var $=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var wr=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var Yt=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var de=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 yn={};ht(yn,{base58btc:()=>F,base58flickr:()=>Aa});var Sf=new Uint8Array(0);function Wo(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 Lt(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 Xo(r){return new TextEncoder().encode(r)}function Jo(r){return new TextDecoder().decode(r)}function ga(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 a=r.length,c=r.charAt(0),l=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function f(v){if(v instanceof Uint8Array||(ArrayBuffer.isView(v)?v=new Uint8Array(v.buffer,v.byteOffset,v.byteLength):Array.isArray(v)&&(v=Uint8Array.from(v))),!(v instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(v.length===0)return"";for(var x=0,d=0,S=0,L=v.length;S!==L&&v[S]===0;)S++,x++;for(var A=(L-S)*u+1>>>0,D=new Uint8Array(A);S!==L;){for(var y=v[S],C=0,P=A-1;(y!==0||C<d)&&P!==-1;P--,C++)y+=256*D[P]>>>0,D[P]=y%a>>>0,y=y/a>>>0;if(y!==0)throw new Error("Non-zero carry");d=C,S++}for(var B=A-d;B!==A&&D[B]===0;)B++;for(var h=c.repeat(x);B<A;++B)h+=r.charAt(D[B]);return h}function b(v){if(typeof v!="string")throw new TypeError("Expected String");if(v.length===0)return new Uint8Array;var x=0;if(v[x]!==" "){for(var d=0,S=0;v[x]===c;)d++,x++;for(var L=(v.length-x)*l+1>>>0,A=new Uint8Array(L);v[x];){var D=e[v.charCodeAt(x)];if(D===255)return;for(var y=0,C=L-1;(D!==0||y<S)&&C!==-1;C--,y++)D+=a*A[C]>>>0,A[C]=D%256>>>0,D=D/256>>>0;if(D!==0)throw new Error("Non-zero carry");S=y,x++}if(v[x]!==" "){for(var P=L-S;P!==L&&A[P]===0;)P++;for(var B=new Uint8Array(d+(L-P)),h=d;P!==L;)B[h++]=A[P++];return B}}}function p(v){var x=b(v);if(x)return x;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:b,decode:p}}var wa=ga,xa=wa,ts=xa;var hn=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")}},dn=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 es(this,t)}},pn=class{decoders;constructor(t){this.decoders=t}or(t){return es(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 es(r,t){return new pn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var mn=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 hn(t,e,n),this.decoder=new dn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function pe({name:r,prefix:t,encode:e,decode:n}){return new mn(r,t,e,n)}function Mt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=ts(e,r);return pe({prefix:t,name:r,encode:n,decode:s=>Lt(o(s))})}function Ea(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let l=0;l<o;++l){let u=t[r[l]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|u,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Sa(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function va(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function j({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=va(n);return pe({prefix:t,name:r,encode(s){return Sa(s,n,e)},decode(s){return Ea(s,o,e,r)}})}var F=Mt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Aa=Mt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var bn={};ht(bn,{base32:()=>me,base32hex:()=>La,base32hexpad:()=>Pa,base32hexpadupper:()=>Ca,base32hexupper:()=>Ta,base32pad:()=>Ba,base32padupper:()=>_a,base32upper:()=>Ia,base32z:()=>Da});var me=j({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ia=j({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ba=j({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),_a=j({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),La=j({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ta=j({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Pa=j({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ca=j({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Da=j({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var gn={};ht(gn,{base36:()=>Ue,base36upper:()=>Na});var Ue=Mt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Na=Mt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ra=os,rs=128,Ka=127,Ua=~Ka,ka=Math.pow(2,31);function os(r,t,e){t=t||[],e=e||0;for(var n=e;r>=ka;)t[e++]=r&255|rs,r/=128;for(;r&Ua;)t[e++]=r&255|rs,r>>>=7;return t[e]=r|0,os.bytes=e-n+1,t}var Ma=wn,Oa=128,ns=127;function wn(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw wn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&ns)<<o:(i&ns)*Math.pow(2,o),o+=7}while(i>=Oa);return wn.bytes=s-n,e}var Ha=Math.pow(2,7),qa=Math.pow(2,14),za=Math.pow(2,21),Va=Math.pow(2,28),Fa=Math.pow(2,35),Ga=Math.pow(2,42),ja=Math.pow(2,49),Za=Math.pow(2,56),$a=Math.pow(2,63),Ya=function(r){return r<Ha?1:r<qa?2:r<za?3:r<Va?4:r<Fa?5:r<Ga?6:r<ja?7:r<Za?8:r<$a?9:10},Wa={encode:Ra,decode:Ma,encodingLength:Ya},Xa=Wa,ke=Xa;function Me(r,t=0){return[ke.decode(r,t),ke.decode.bytes]}function ye(r,t,e=0){return ke.encode(r,t,e),t}function be(r){return ke.encodingLength(r)}function gt(r,t){let e=t.byteLength,n=be(r),o=n+be(e),s=new Uint8Array(o+e);return ye(r,s,0),ye(e,s,n),s.set(t,o),new ge(r,e,t,s)}function Ot(r){let t=Lt(r),[e,n]=Me(t),[o,s]=Me(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ge(e,o,i,t)}function ss(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Wo(r.bytes,e.bytes)}}var ge=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function is(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Qa(e,xn(r),t??F.encoder);default:return tc(e,xn(r),t??me.encoder)}}var as=new WeakMap;function xn(r){let t=as.get(r);if(t==null){let e=new Map;return as.set(r,e),e}return t}var rt=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!==Oe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==ec)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=gt(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&&ss(t.multihash,n.multihash)}toString(t){return is(this,t)}toJSON(){return{"/":is(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??cs(n,o,s.bytes))}else if(e[rc]===!0){let{version:n,multihash:o,code:s}=e,i=Ot(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!==Oe)throw new Error(`Version 0 CID must use dag-pb (code: ${Oe}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=cs(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Oe,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=Lt(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 ge(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]=Me(t.subarray(e));return e+=b,f},o=n(),s=Oe;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),l=e+c,u=l-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:l}}static parse(t,e){let[n,o]=Ja(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 Ja(r,t){switch(r[0]){case"Q":{let e=t??F;return[F.prefix,e.decode(`${F.prefix}${r}`)]}case F.prefix:{let e=t??F;return[F.prefix,e.decode(r)]}case me.prefix:{let e=t??me;return[me.prefix,e.decode(r)]}case Ue.prefix:{let e=t??Ue;return[Ue.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 Qa(r,t,e){let{prefix:n}=e;if(n!==F.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 tc(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 Oe=112,ec=18;function cs(r,t,e){let n=be(r),o=n+be(t),s=new Uint8Array(o+e.byteLength);return ye(r,s,0),ye(t,s,n),s.set(e,o),s}var rc=Symbol.for("@ipld/js-cid/CID");var En={};ht(En,{identity:()=>wt});var us=0,nc="identity",fs=Lt;function oc(r){return gt(us,fs(r))}var wt={code:us,name:nc,encode:fs,digest:oc};function dt(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 Tt(r=0){return new Uint8Array(r)}function nt(r=0){return new Uint8Array(r)}function Wt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=nt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var hs=Symbol.for("@achingbrain/uint8arraylist");function ls(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 Er(r){return!!r?.[hs]}var X=class r{bufs;length;[hs]=!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(Er(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(Er(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=ls(this.bufs,t);return e.buf[e.index]}set(t,e){let n=ls(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(Er(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 Wt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Wt(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],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let l=t>=a&&t<c,u=e>a&&e<=c;if(l&&u){if(t===a&&e===c){n.push(i);break}let f=t-a;n.push(i.subarray(f,f+(e-t)));break}if(l){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Er(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 a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let f=e;f<=c;f+=u){u=0;for(let b=l;b>=0;b--){let p=this.get(f+b);if(n[b]!==p){u=Math.max(1,b-a[p]);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=nt(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=Tt(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=Tt(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=Tt(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=nt(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=Tt(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=Tt(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=Tt(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=Tt(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=Tt(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(!dt(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 Sn={};ht(Sn,{base10:()=>sc});var sc=Mt({prefix:"9",name:"base10",alphabet:"0123456789"});var vn={};ht(vn,{base16:()=>ic,base16upper:()=>ac});var ic=j({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),ac=j({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var An={};ht(An,{base2:()=>cc});var cc=j({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var In={};ht(In,{base256emoji:()=>dc});var ds=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),uc=ds.reduce((r,t,e)=>(r[e]=t,r),[]),fc=ds.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function lc(r){return r.reduce((t,e)=>(t+=uc[e],t),"")}function hc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=fc[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var dc=pe({prefix:"\u{1F680}",name:"base256emoji",encode:lc,decode:hc});var Bn={};ht(Bn,{base64:()=>pc,base64pad:()=>mc,base64url:()=>yc,base64urlpad:()=>bc});var pc=j({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),mc=j({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),yc=j({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),bc=j({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var _n={};ht(_n,{base8:()=>gc});var gc=j({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ln={};ht(Ln,{identity:()=>wc});var wc=pe({prefix:"\0",name:"identity",encode:r=>Jo(r),decode:r=>Xo(r)});var sl=new TextEncoder,il=new TextDecoder;var Cn={};ht(Cn,{sha256:()=>Xt,sha512:()=>Sc});function Pn({name:r,code:t,encode:e}){return new Tn(r,t,e)}var Tn=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?gt(this.code,e):e.then(n=>gt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function ms(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Xt=Pn({name:"sha2-256",code:18,encode:ms("SHA-256")}),Sc=Pn({name:"sha2-512",code:19,encode:ms("SHA-512")});var Dn={...Ln,...An,..._n,...Sn,...vn,...bn,...gn,...yn,...Bn,...In},gl={...Cn,...En};function bs(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var ys=bs("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Nn=bs("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=nt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),vc={utf8:ys,"utf-8":ys,hex:Dn.base16,latin1:Nn,ascii:Nn,binary:Nn,...Dn},Sr=vc;function M(r,t="utf8"){let e=Sr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function O(r,t="utf8"){let e=Sr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Ac=parseInt("11111",2),Rn=parseInt("10000000",2),Ic=parseInt("01111111",2),gs={0:He,1:He,2:Bc,3:Tc,4:Pc,5:Lc,6:_c,16:He,22:He,48:He};function Pt(r,t={offset:0}){let e=r[t.offset]&Ac;if(t.offset++,gs[e]!=null)return gs[e](r,t);throw new Error("No decoder for tag "+e)}function qe(r,t){let e=0;if((r[t.offset]&Rn)===Rn){let n=r[t.offset]&Ic,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 He(r,t){qe(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Pt(r,t);if(n===null)break;e.push(n)}return e}function Bc(r,t){let e=qe(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 _c(r,t){let e=qe(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 a=`${s}.${i}`,c=[];for(;t.offset<n;){let l=r[t.offset];if(t.offset++,c.push(l&127),l<128){c.reverse();let u=0;for(let f=0;f<c.length;f++)u+=c[f]<<f*7;a+=`.${u}`,c=[]}}return a}function Lc(r,t){return t.offset++,null}function Tc(r,t){let e=qe(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 Pc(r,t){let e=qe(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Cc(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new X;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Kn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Cc(r.byteLength);return new X(Uint8Array.from([t.byteLength|Rn]),t)}function pt(r){let t=new X,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new X(Uint8Array.from([2]),Kn(t),t)}function vr(r){let t=Uint8Array.from([0]),e=new X(t,r);return new X(Uint8Array.from([3]),Kn(e),e)}function qt(r,t=48){let e=new X;for(let n of r)e.append(n);return new X(Uint8Array.from([t]),Kn(e),e)}async function ws(r,t,e,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,e.subarray());return n?.signal?.throwIfAborted(),s}var Dc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Nc=Uint8Array.from([6,5,43,129,4,0,34]),Rc=Uint8Array.from([6,5,43,129,4,0,35]),Kc={ext:!0,kty:"EC",crv:"P-256"},Uc={ext:!0,kty:"EC",crv:"P-384"},kc={ext:!0,kty:"EC",crv:"P-521"},Un=32,kn=48,Mn=66;function On(r){let t=Pt(r);return xs(t)}function xs(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===Un*2+1)return n=O(t.subarray(e,e+Un),"base64url"),o=O(t.subarray(e+Un),"base64url"),new we({...Kc,key_ops:["verify"],x:n,y:o});if(t.byteLength===kn*2+1)return n=O(t.subarray(e,e+kn),"base64url"),o=O(t.subarray(e+kn),"base64url"),new we({...Uc,key_ops:["verify"],x:n,y:o});if(t.byteLength===Mn*2+1)return n=O(t.subarray(e,e+Mn),"base64url"),o=O(t.subarray(e+Mn),"base64url"),new we({...kc,key_ops:["verify"],x:n,y:o});throw new V(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Es(r){return qt([pt(Uint8Array.from([1])),qt([Mc(r.crv)],160),qt([vr(new X(Uint8Array.from([4]),M(r.x??"","base64url"),M(r.y??"","base64url")))],161)]).subarray()}function Mc(r){if(r==="P-256")return Dc;if(r==="P-384")return Nc;if(r==="P-521")return Rc;throw new V(`Invalid curve ${r}`)}var we=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Es(this.jwk)),this._raw}toMultihash(){return wt.digest(Ct(this))}toCID(){return rt.createV1(114,this.toMultihash())}toString(){return F.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}async verify(t,e,n){return ws(this.jwk,e,t,n)}};var Jt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Ee(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function ze(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function ot(r,...t){if(!Ee(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 vs(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");ze(r.outputLen),ze(r.blockLen)}function Se(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 As(r,t){ot(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}function Nt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Ar(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function xt(r,t){return r<<32-t|r>>>t}var Is=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Oc=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function At(r){if(ot(r),Is)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Oc[r[e]];return t}var Dt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ss(r){if(r>=Dt._0&&r<=Dt._9)return r-Dt._0;if(r>=Dt.A&&r<=Dt.F)return r-(Dt.A-10);if(r>=Dt.a&&r<=Dt.f)return r-(Dt.a-10)}function ve(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Is)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=Ss(r.charCodeAt(s)),a=Ss(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Bs(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function Ve(r){return typeof r=="string"&&(r=Bs(r)),ot(r),r}function mt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];ot(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 xe=class{};function Hn(r){let t=n=>r().update(Ve(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Qt(r=32){if(Jt&&typeof Jt.getRandomValues=="function")return Jt.getRandomValues(new Uint8Array(r));if(Jt&&typeof Jt.randomBytes=="function")return Uint8Array.from(Jt.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function Hc(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),a=Number(e&s),c=n?4:0,l=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+l,a,n)}function _s(r,t,e){return r&t^~r&e}function Ls(r,t,e){return r&t^r&e^t&e}var Fe=class extends xe{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=Ar(this.buffer)}update(t){Se(this),t=Ve(t),ot(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Ar(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Se(this),As(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Nt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)e[f]=0;Hc(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Ar(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=c/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)a.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:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Rt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var tt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Ir=BigInt(4294967295),Ts=BigInt(32);function qc(r,t=!1){return t?{h:Number(r&Ir),l:Number(r>>Ts&Ir)}:{h:Number(r>>Ts&Ir)|0,l:Number(r&Ir)|0}}function Ps(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:a}=qc(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var qn=(r,t,e)=>r>>>e,zn=(r,t,e)=>r<<32-e|t>>>e,te=(r,t,e)=>r>>>e|t<<32-e,ee=(r,t,e)=>r<<32-e|t>>>e,Ge=(r,t,e)=>r<<64-e|t>>>e-32,je=(r,t,e)=>r>>>e-32|t<<64-e;function It(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Cs=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Ds=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Ns=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Rs=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Ks=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Us=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Vc=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),zt=new Uint32Array(64),Br=class extends Fe{constructor(t=32){super(64,t,8,!1),this.A=Rt[0]|0,this.B=Rt[1]|0,this.C=Rt[2]|0,this.D=Rt[3]|0,this.E=Rt[4]|0,this.F=Rt[5]|0,this.G=Rt[6]|0,this.H=Rt[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){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=a|0,this.H=c|0}process(t,e){for(let f=0;f<16;f++,e+=4)zt[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let b=zt[f-15],p=zt[f-2],v=xt(b,7)^xt(b,18)^b>>>3,x=xt(p,17)^xt(p,19)^p>>>10;zt[f]=x+zt[f-7]+v+zt[f-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:l,H:u}=this;for(let f=0;f<64;f++){let b=xt(a,6)^xt(a,11)^xt(a,25),p=u+b+_s(a,c,l)+Vc[f]+zt[f]|0,x=(xt(n,2)^xt(n,13)^xt(n,22))+Ls(n,o,s)|0;u=l,l=c,c=a,a=i+p|0,i=s,s=o,o=n,n=p+x|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,c,l,u)}roundClean(){Nt(zt)}destroy(){this.set(0,0,0,0,0,0,0,0),Nt(this.buffer)}};var ks=Ps(["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))),Fc=ks[0],Gc=ks[1],Vt=new Uint32Array(80),Ft=new Uint32Array(80),Vn=class extends Fe{constructor(t=64){super(128,t,16,!1),this.Ah=tt[0]|0,this.Al=tt[1]|0,this.Bh=tt[2]|0,this.Bl=tt[3]|0,this.Ch=tt[4]|0,this.Cl=tt[5]|0,this.Dh=tt[6]|0,this.Dl=tt[7]|0,this.Eh=tt[8]|0,this.El=tt[9]|0,this.Fh=tt[10]|0,this.Fl=tt[11]|0,this.Gh=tt[12]|0,this.Gl=tt[13]|0,this.Hh=tt[14]|0,this.Hl=tt[15]|0}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:l,El:u,Fh:f,Fl:b,Gh:p,Gl:v,Hh:x,Hl:d}=this;return[t,e,n,o,s,i,a,c,l,u,f,b,p,v,x,d]}set(t,e,n,o,s,i,a,c,l,u,f,b,p,v,x,d){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=a|0,this.Dl=c|0,this.Eh=l|0,this.El=u|0,this.Fh=f|0,this.Fl=b|0,this.Gh=p|0,this.Gl=v|0,this.Hh=x|0,this.Hl=d|0}process(t,e){for(let A=0;A<16;A++,e+=4)Vt[A]=t.getUint32(e),Ft[A]=t.getUint32(e+=4);for(let A=16;A<80;A++){let D=Vt[A-15]|0,y=Ft[A-15]|0,C=te(D,y,1)^te(D,y,8)^qn(D,y,7),P=ee(D,y,1)^ee(D,y,8)^zn(D,y,7),B=Vt[A-2]|0,h=Ft[A-2]|0,w=te(B,h,19)^Ge(B,h,61)^qn(B,h,6),m=ee(B,h,19)^je(B,h,61)^zn(B,h,6),g=Ns(P,m,Ft[A-7],Ft[A-16]),E=Rs(g,C,w,Vt[A-7],Vt[A-16]);Vt[A]=E|0,Ft[A]=g|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:l,Dl:u,Eh:f,El:b,Fh:p,Fl:v,Gh:x,Gl:d,Hh:S,Hl:L}=this;for(let A=0;A<80;A++){let D=te(f,b,14)^te(f,b,18)^Ge(f,b,41),y=ee(f,b,14)^ee(f,b,18)^je(f,b,41),C=f&p^~f&x,P=b&v^~b&d,B=Ks(L,y,P,Gc[A],Ft[A]),h=Us(B,S,D,C,Fc[A],Vt[A]),w=B|0,m=te(n,o,28)^Ge(n,o,34)^Ge(n,o,39),g=ee(n,o,28)^je(n,o,34)^je(n,o,39),E=n&s^n&a^s&a,_=o&i^o&c^i&c;S=x|0,L=d|0,x=p|0,d=v|0,p=f|0,v=b|0,{h:f,l:b}=It(l|0,u|0,h|0,w|0),l=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let I=Cs(w,g,_);n=Ds(I,h,m,E),o=I|0}({h:n,l:o}=It(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=It(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=It(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:u}=It(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:b}=It(this.Eh|0,this.El|0,f|0,b|0),{h:p,l:v}=It(this.Fh|0,this.Fl|0,p|0,v|0),{h:x,l:d}=It(this.Gh|0,this.Gl|0,x|0,d|0),{h:S,l:L}=It(this.Hh|0,this.Hl|0,S|0,L|0),this.set(n,o,s,i,a,c,l,u,f,b,p,v,x,d,S,L)}roundClean(){Nt(Vt,Ft)}destroy(){Nt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var _r=Hn(()=>new Br);var Ms=Hn(()=>new Vn);var jn=BigInt(0),Gn=BigInt(1);function Kt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function Ze(r){let t=r.toString(16);return t.length&1?"0"+t:t}function Os(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?jn:BigInt("0x"+r)}function Ae(r){return Os(At(r))}function re(r){return ot(r),Os(At(Uint8Array.from(r).reverse()))}function Lr(r,t){return ve(r.toString(16).padStart(t*2,"0"))}function Ie(r,t){return Lr(r,t).reverse()}function q(r,t,e){let n;if(typeof t=="string")try{n=ve(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Ee(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}var Fn=r=>typeof r=="bigint"&&jn<=r;function Hs(r,t,e){return Fn(r)&&Fn(t)&&Fn(e)&&t<=r&&r<e}function Gt(r,t,e,n){if(!Hs(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function qs(r){let t;for(t=0;r>jn;r>>=Gn,t+=1);return t}var ne=r=>(Gn<<BigInt(r))-Gn;function zs(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=p=>new Uint8Array(p),o=p=>Uint8Array.of(p),s=n(r),i=n(r),a=0,c=()=>{s.fill(1),i.fill(0),a=0},l=(...p)=>e(i,s,...p),u=(p=n(0))=>{i=l(o(0),p),s=l(),p.length!==0&&(i=l(o(1),p),s=l())},f=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let p=0,v=[];for(;p<t;){s=l();let x=s.slice();v.push(x),p+=s.length}return mt(...v)};return(p,v)=>{c(),u(p);let x;for(;!(x=v(f()));)u();return c(),x}}function jt(r,t,e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(o,s,i){let a=r[o];if(i&&a===void 0)return;let c=typeof a;if(c!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${c}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(e).forEach(([o,s])=>n(o,s,!0))}function Be(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 ut=BigInt(0),Q=BigInt(1),oe=BigInt(2),jc=BigInt(3),Gs=BigInt(4),js=BigInt(5),Zs=BigInt(8);function G(r,t){let e=r%t;return e>=ut?e:t+e}function z(r,t,e){let n=r;for(;t-- >ut;)n*=n,n%=e;return n}function Vs(r,t){if(r===ut)throw new Error("invert: expected non-zero number");if(t<=ut)throw new Error("invert: expected positive modulus, got "+t);let e=G(r,t),n=t,o=ut,s=Q,i=Q,a=ut;for(;e!==ut;){let l=n/e,u=n%e,f=o-i*l,b=s-a*l;n=e,e=u,o=i,s=a,i=f,a=b}if(n!==Q)throw new Error("invert: does not exist");return G(o,t)}function $s(r,t){let e=(r.ORDER+Q)/Gs,n=r.pow(t,e);if(!r.eql(r.sqr(n),t))throw new Error("Cannot find square root");return n}function Zc(r,t){let e=(r.ORDER-js)/Zs,n=r.mul(t,oe),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,oe),o),a=r.mul(s,r.sub(i,r.ONE));if(!r.eql(r.sqr(a),t))throw new Error("Cannot find square root");return a}function $c(r){if(r<BigInt(3))throw new Error("sqrt is not defined for small field");let t=r-Q,e=0;for(;t%oe===ut;)t/=oe,e++;let n=oe,o=Et(r);for(;Fs(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return $s;let s=o.pow(n,t),i=(t+Q)/oe;return function(c,l){if(c.is0(l))return l;if(Fs(c,l)!==1)throw new Error("Cannot find square root");let u=e,f=c.mul(c.ONE,s),b=c.pow(l,t),p=c.pow(l,i);for(;!c.eql(b,c.ONE);){if(c.is0(b))return c.ZERO;let v=1,x=c.sqr(b);for(;!c.eql(x,c.ONE);)if(v++,x=c.sqr(x),v===u)throw new Error("Cannot find square root");let d=Q<<BigInt(u-v-1),S=c.pow(f,d);u=v,f=c.sqr(S),b=c.mul(b,f),p=c.mul(p,S)}return p}}function Yc(r){return r%Gs===jc?$s:r%Zs===js?Zc:$c(r)}var Ys=(r,t)=>(G(r,t)&Q)===Q,Wc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Zn(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},e=Wc.reduce((n,o)=>(n[o]="function",n),t);return jt(r,e),r}function Xc(r,t,e){if(e<ut)throw new Error("invalid exponent, negatives unsupported");if(e===ut)return r.ONE;if(e===Q)return t;let n=r.ONE,o=t;for(;e>ut;)e&Q&&(n=r.mul(n,o)),o=r.sqr(o),e>>=Q;return n}function $e(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,a,c)=>r.is0(a)?i:(n[c]=i,r.mul(i,a)),r.ONE),s=r.inv(o);return t.reduceRight((i,a,c)=>r.is0(a)?i:(n[c]=r.mul(i,n[c]),r.mul(i,a)),s),n}function Fs(r,t){let e=(r.ORDER-Q)/oe,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 Ws(r,t){t!==void 0&&ze(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Et(r,t,e=!1,n={}){if(r<=ut)throw new Error("invalid field: expected ORDER > 0, got "+r);let o,s;if(typeof t=="object"&&t!=null){if(n.sqrt||e)throw new Error("cannot specify opts in two arguments");let u=t;u.BITS&&(o=u.BITS),u.sqrt&&(s=u.sqrt),typeof u.isLE=="boolean"&&(e=u.isLE)}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:i,nByteLength:a}=Ws(r,o);if(a>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let c,l=Object.freeze({ORDER:r,isLE:e,BITS:i,BYTES:a,MASK:ne(i),ZERO:ut,ONE:Q,create:u=>G(u,r),isValid:u=>{if(typeof u!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof u);return ut<=u&&u<r},is0:u=>u===ut,isValidNot0:u=>!l.is0(u)&&l.isValid(u),isOdd:u=>(u&Q)===Q,neg:u=>G(-u,r),eql:(u,f)=>u===f,sqr:u=>G(u*u,r),add:(u,f)=>G(u+f,r),sub:(u,f)=>G(u-f,r),mul:(u,f)=>G(u*f,r),pow:(u,f)=>Xc(l,u,f),div:(u,f)=>G(u*Vs(f,r),r),sqrN:u=>u*u,addN:(u,f)=>u+f,subN:(u,f)=>u-f,mulN:(u,f)=>u*f,inv:u=>Vs(u,r),sqrt:s||(u=>(c||(c=Yc(r)),c(l,u))),toBytes:u=>e?Ie(u,a):Lr(u,a),fromBytes:u=>{if(u.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+u.length);return e?re(u):Ae(u)},invertBatch:u=>$e(l,u),cmov:(u,f,b)=>b?f:u});return Object.freeze(l)}function Xs(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=Xs(r);return t+Math.ceil(t/2)}function Js(r,t,e=!1){let n=r.length,o=Xs(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?re(r):Ae(r),a=G(i,t-Q)+Q;return e?Ie(a,o):Lr(a,o)}var Le=BigInt(0),se=BigInt(1);function _e(r,t){let e=t.negate();return r?e:t}function Tr(r,t,e){let n=t==="pz"?i=>i.pz:i=>i.ez,o=$e(r.Fp,e.map(n));return e.map((i,a)=>i.toAffine(o[a])).map(r.fromAffine)}function ri(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Yn(r,t){ri(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=ne(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Qs(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=se);let l=t*n,u=l+Math.abs(a)-1,f=a===0,b=a<0,p=t%2!==0;return{nextN:c,offset:u,isZero:f,isNeg:b,isNegF:p,offsetF:l}}function Jc(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 Qc(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 Wn=new WeakMap,ni=new WeakMap;function Xn(r){return ni.get(r)||1}function ti(r){if(r!==Le)throw new Error("invalid wNAF")}function Pr(r,t){return{constTimeNegate:_e,hasPrecomputes(e){return Xn(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>Le;)n&se&&(o=o.add(s)),s=s.double(),n>>=se;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=Yn(n,t),i=[],a=e,c=a;for(let l=0;l<o;l++){c=a,i.push(c);for(let u=1;u<s;u++)c=c.add(a),i.push(c);a=c.double()}return i},wNAF(e,n,o){let s=r.ZERO,i=r.BASE,a=Yn(e,t);for(let c=0;c<a.windows;c++){let{nextN:l,offset:u,isZero:f,isNeg:b,isNegF:p,offsetF:v}=Qs(o,c,a);o=l,f?i=i.add(_e(p,n[v])):s=s.add(_e(b,n[u]))}return ti(o),{p:s,f:i}},wNAFUnsafe(e,n,o,s=r.ZERO){let i=Yn(e,t);for(let a=0;a<i.windows&&o!==Le;a++){let{nextN:c,offset:l,isZero:u,isNeg:f}=Qs(o,a,i);if(o=c,!u){let b=n[l];s=s.add(f?b.negate():b)}}return ti(o),s},getPrecomputes(e,n,o){let s=Wn.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&(typeof o=="function"&&(s=o(s)),Wn.set(n,s))),s},wNAFCached(e,n,o){let s=Xn(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=Xn(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){ri(n,t),ni.set(e,n),Wn.delete(e)}}}function oi(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>Le||n>Le;)e&se&&(s=s.add(o)),n&se&&(i=i.add(o)),o=o.double(),e>>=se,n>>=se;return{p1:s,p2:i}}function Cr(r,t,e,n){Jc(e,r),Qc(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,a=qs(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let l=ne(c),u=new Array(Number(l)+1).fill(i),f=Math.floor((t.BITS-1)/c)*c,b=i;for(let p=f;p>=0;p-=c){u.fill(i);for(let x=0;x<s;x++){let d=n[x],S=Number(d>>BigInt(p)&l);u[S]=u[S].add(e[x])}let v=i;for(let x=u.length-1,d=i;x>0;x--)d=d.add(u[x]),v=v.add(d);if(b=b.add(v),p!==0)for(let x=0;x<c;x++)b=b.double()}return b}function ei(r,t){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Zn(t),t}else return Et(r)}function Dr(r,t,e={}){if(!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let a of["p","n","h"]){let c=t[a];if(!(typeof c=="bigint"&&c>Le))throw new Error(`CURVE.${a} must be positive bigint`)}let n=ei(t.p,e.Fp),o=ei(t.n,e.Fn),i=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let a of i)if(!n.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return{Fp:n,Fn:o}}var Bt=BigInt(0),ft=BigInt(1),Jn=BigInt(2),tu=BigInt(8),eu={zip215:!0};function ru(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),a=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,a)}function nu(r,t={}){let{Fp:e,Fn:n}=Dr("edwards",r,t),{h:o,n:s}=r;jt(t,{},{uvRatio:"function"});let i=Jn<<BigInt(n.BYTES*8)-ft,a=x=>e.create(x),c=t.uvRatio||((x,d)=>{try{return{isValid:!0,value:e.sqrt(e.div(x,d))}}catch{return{isValid:!1,value:Bt}}});if(!ru(e,r,r.Gx,r.Gy))throw new Error("bad curve params: generator point");function l(x,d,S=!1){let L=S?ft:Bt;return Gt("coordinate "+x,d,L,i),d}function u(x){if(!(x instanceof p))throw new Error("ExtendedPoint expected")}let f=Be((x,d)=>{let{ex:S,ey:L,ez:A}=x,D=x.is0();d==null&&(d=D?tu:e.inv(A));let y=a(S*d),C=a(L*d),P=a(A*d);if(D)return{x:Bt,y:ft};if(P!==ft)throw new Error("invZ was invalid");return{x:y,y:C}}),b=Be(x=>{let{a:d,d:S}=r;if(x.is0())throw new Error("bad point: ZERO");let{ex:L,ey:A,ez:D,et:y}=x,C=a(L*L),P=a(A*A),B=a(D*D),h=a(B*B),w=a(C*d),m=a(B*a(w+P)),g=a(h+a(S*a(C*P)));if(m!==g)throw new Error("bad point: equation left != right (1)");let E=a(L*A),_=a(D*y);if(E!==_)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(d,S,L,A){this.ex=l("x",d),this.ey=l("y",S),this.ez=l("z",L,!0),this.et=l("t",A),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(d){if(d instanceof p)throw new Error("extended point not allowed");let{x:S,y:L}=d||{};return l("x",S),l("y",L),new p(S,L,ft,a(S*L))}static normalizeZ(d){return Tr(p,"ez",d)}static msm(d,S){return Cr(p,n,d,S)}_setWindowSize(d){this.precompute(d)}precompute(d=8,S=!0){return v.setWindowSize(this,d),S||this.multiply(Jn),this}assertValidity(){b(this)}equals(d){u(d);let{ex:S,ey:L,ez:A}=this,{ex:D,ey:y,ez:C}=d,P=a(S*C),B=a(D*A),h=a(L*C),w=a(y*A);return P===B&&h===w}is0(){return this.equals(p.ZERO)}negate(){return new p(a(-this.ex),this.ey,this.ez,a(-this.et))}double(){let{a:d}=r,{ex:S,ey:L,ez:A}=this,D=a(S*S),y=a(L*L),C=a(Jn*a(A*A)),P=a(d*D),B=S+L,h=a(a(B*B)-D-y),w=P+y,m=w-C,g=P-y,E=a(h*m),_=a(w*g),I=a(h*g),T=a(m*w);return new p(E,_,T,I)}add(d){u(d);let{a:S,d:L}=r,{ex:A,ey:D,ez:y,et:C}=this,{ex:P,ey:B,ez:h,et:w}=d,m=a(A*P),g=a(D*B),E=a(C*L*w),_=a(y*h),I=a((A+D)*(P+B)-m-g),T=_-E,R=_+E,N=a(g-S*m),Z=a(I*T),k=a(R*N),K=a(I*N),W=a(T*R);return new p(Z,k,W,K)}subtract(d){return this.add(d.negate())}multiply(d){let S=d;Gt("scalar",S,ft,s);let{p:L,f:A}=v.wNAFCached(this,S,p.normalizeZ);return p.normalizeZ([L,A])[0]}multiplyUnsafe(d,S=p.ZERO){let L=d;return Gt("scalar",L,Bt,s),L===Bt?p.ZERO:this.is0()||L===ft?this:v.wNAFCachedUnsafe(this,L,p.normalizeZ,S)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return v.wNAFCachedUnsafe(this,s).is0()}toAffine(d){return f(this,d)}clearCofactor(){return o===ft?this:this.multiplyUnsafe(o)}static fromBytes(d,S=!1){return ot(d),this.fromHex(d,S)}static fromHex(d,S=!1){let{d:L,a:A}=r,D=e.BYTES;d=q("pointHex",d,D),Kt("zip215",S);let y=d.slice(),C=d[D-1];y[D-1]=C&-129;let P=re(y),B=S?i:e.ORDER;Gt("pointHex.y",P,Bt,B);let h=a(P*P),w=a(h-ft),m=a(L*h-A),{isValid:g,value:E}=c(w,m);if(!g)throw new Error("Point.fromHex: invalid y coordinate");let _=(E&ft)===ft,I=(C&128)!==0;if(!S&&E===Bt&&I)throw new Error("Point.fromHex: x=0 and x_0=1");return I!==_&&(E=a(-E)),p.fromAffine({x:E,y:P})}static fromPrivateScalar(d){return p.BASE.multiply(d)}toBytes(){let{x:d,y:S}=this.toAffine(),L=Ie(S,e.BYTES);return L[L.length-1]|=d&ft?128:0,L}toRawBytes(){return this.toBytes()}toHex(){return At(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}p.BASE=new p(r.Gx,r.Gy,ft,a(r.Gx*r.Gy)),p.ZERO=new p(Bt,ft,ft,Bt),p.Fp=e,p.Fn=n;let v=Pr(p,n.BYTES*8);return p}function ou(r,t){jt(t,{hash:"function"},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:e,hash:n}=t,{BASE:o,Fp:s,Fn:i}=r,a=i.ORDER,c=t.randomBytes||Qt,l=t.adjustScalarBytes||(y=>y),u=t.domain||((y,C,P)=>{if(Kt("phflag",P),C.length||P)throw new Error("Contexts/pre-hash are not supported");return y});function f(y){return i.create(y)}function b(y){return f(re(y))}function p(y){let C=s.BYTES;y=q("private key",y,C);let P=q("hashed private key",n(y),2*C),B=l(P.slice(0,C)),h=P.slice(C,2*C),w=b(B);return{head:B,prefix:h,scalar:w}}function v(y){let{head:C,prefix:P,scalar:B}=p(y),h=o.multiply(B),w=h.toBytes();return{head:C,prefix:P,scalar:B,point:h,pointBytes:w}}function x(y){return v(y).pointBytes}function d(y=Uint8Array.of(),...C){let P=mt(...C);return b(n(u(P,q("context",y),!!e)))}function S(y,C,P={}){y=q("message",y),e&&(y=e(y));let{prefix:B,scalar:h,pointBytes:w}=v(C),m=d(P.context,B,y),g=o.multiply(m).toBytes(),E=d(P.context,g,w,y),_=f(m+E*h);Gt("signature.s",_,Bt,a);let I=s.BYTES,T=mt(g,Ie(_,I));return q("result",T,I*2)}let L=eu;function A(y,C,P,B=L){let{context:h,zip215:w}=B,m=s.BYTES;y=q("signature",y,2*m),C=q("message",C),P=q("publicKey",P,m),w!==void 0&&Kt("zip215",w),e&&(C=e(C));let g=re(y.slice(m,2*m)),E,_,I;try{E=r.fromHex(P,w),_=r.fromHex(y.slice(0,m),w),I=o.multiplyUnsafe(g)}catch{return!1}if(!w&&E.isSmallOrder())return!1;let T=d(h,_.toBytes(),E.toBytes(),C);return _.add(E.multiplyUnsafe(T)).subtract(I).clearCofactor().is0()}return o.precompute(8),{getPublicKey:x,sign:S,verify:A,utils:{getExtendedPublicKey:v,randomPrivateKey:()=>c(s.BYTES),precompute(y=8,C=r.BASE){return C.precompute(y,!1)}},Point:r}}function su(r){let t={a:r.a,d:r.d,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=Et(t.n,r.nBitLength,!0),o={Fp:e,Fn:n,uvRatio:r.uvRatio},s={hash:r.hash,randomBytes:r.randomBytes,adjustScalarBytes:r.adjustScalarBytes,domain:r.domain,prehash:r.prehash,mapToCurve:r.mapToCurve};return{CURVE:t,curveOpts:o,eddsaOpts:s}}function iu(r,t){return Object.assign({},t,{ExtendedPoint:t.Point,CURVE:r})}function si(r){let{CURVE:t,curveOpts:e,eddsaOpts:n}=su(r),o=nu(t,e),s=ou(o,n);return iu(r,s)}var vh=BigInt(0),au=BigInt(1),ii=BigInt(2),Ah=BigInt(3),cu=BigInt(5),uu=BigInt(8),Nr={p:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:uu,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function fu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=Nr.p,a=r*r%s*r%s,c=z(a,ii,s)*a%s,l=z(c,au,s)*r%s,u=z(l,cu,s)*l%s,f=z(u,t,s)*u%s,b=z(f,e,s)*f%s,p=z(b,n,s)*b%s,v=z(p,o,s)*p%s,x=z(v,o,s)*p%s,d=z(x,t,s)*u%s;return{pow_p_5_8:z(d,ii,s)*r%s,b2:a}}function lu(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var ai=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function hu(r,t){let e=Nr.p,n=G(t*t*t,e),o=G(n*n*t,e),s=fu(r*o).pow_p_5_8,i=G(r*n*s,e),a=G(t*i*i,e),c=i,l=G(i*ai,e),u=a===r,f=a===G(-r,e),b=a===G(-r*ai,e);return u&&(i=c),(f||b)&&(i=l),Ys(i,e)&&(i=G(-i,e)),{isValid:u||f,value:i}}var du=Et(Nr.p,void 0,!0),pu={...Nr,Fp:du,hash:Ms,adjustScalarBytes:lu,uvRatio:hu},ci=si(pu);var Ye=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Rr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var ui={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Rr("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 bt=ui;var Kr=32;var Qn,mu=(async()=>{try{return await bt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function yu(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await bt.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await bt.get().subtle.verify({name:"Ed25519"},n,t,e instanceof Uint8Array?e:e.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function bu(r,t,e){return ci.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function fi(r,t,e){return Qn==null&&(Qn=await mu),Qn?yu(r,t,e):bu(r,t,e)}function Ur(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var kr=class{type="Ed25519";raw;constructor(t){this.raw=to(t,Kr)}toMultihash(){return wt.digest(Ct(this))}toCID(){return rt.createV1(114,this.toMultihash())}toString(){return F.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=fi(this.raw,e,t);return Ur(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function eo(r){return r=to(r,Kr),new kr(r)}function to(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new V(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var wu=Math.pow(2,7),xu=Math.pow(2,14),Eu=Math.pow(2,21),ro=Math.pow(2,28),no=Math.pow(2,35),oo=Math.pow(2,42),so=Math.pow(2,49),U=128,st=127;function St(r){if(r<wu)return 1;if(r<xu)return 2;if(r<Eu)return 3;if(r<ro)return 4;if(r<no)return 5;if(r<oo)return 6;if(r<so)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function io(r,t,e=0){switch(St(r)){case 8:t[e++]=r&255|U,r/=128;case 7:t[e++]=r&255|U,r/=128;case 6:t[e++]=r&255|U,r/=128;case 5:t[e++]=r&255|U,r/=128;case 4:t[e++]=r&255|U,r>>>=7;case 3:t[e++]=r&255|U,r>>>=7;case 2:t[e++]=r&255|U,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Su(r,t,e=0){switch(St(r)){case 8:t.set(e++,r&255|U),r/=128;case 7:t.set(e++,r&255|U),r/=128;case 6:t.set(e++,r&255|U),r/=128;case 5:t.set(e++,r&255|U),r/=128;case 4:t.set(e++,r&255|U),r>>>=7;case 3:t.set(e++,r&255|U),r>>>=7;case 2:t.set(e++,r&255|U),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function ao(r,t){let e=r[t],n=0;if(n+=e&st,e<U||(e=r[t+1],n+=(e&st)<<7,e<U)||(e=r[t+2],n+=(e&st)<<14,e<U)||(e=r[t+3],n+=(e&st)<<21,e<U)||(e=r[t+4],n+=(e&st)*ro,e<U)||(e=r[t+5],n+=(e&st)*no,e<U)||(e=r[t+6],n+=(e&st)*oo,e<U)||(e=r[t+7],n+=(e&st)*so,e<U))return n;throw new RangeError("Could not decode varint")}function vu(r,t){let e=r.get(t),n=0;if(n+=e&st,e<U||(e=r.get(t+1),n+=(e&st)<<7,e<U)||(e=r.get(t+2),n+=(e&st)<<14,e<U)||(e=r.get(t+3),n+=(e&st)<<21,e<U)||(e=r.get(t+4),n+=(e&st)*ro,e<U)||(e=r.get(t+5),n+=(e&st)*no,e<U)||(e=r.get(t+6),n+=(e&st)*oo,e<U)||(e=r.get(t+7),n+=(e&st)*so,e<U))return n;throw new RangeError("Could not decode varint")}function hi(r,t,e=0){return t==null&&(t=nt(St(r))),t instanceof Uint8Array?io(r,t,e):Su(r,t,e)}function di(r,t=0){return r instanceof Uint8Array?ao(r,t):vu(r,t)}var co=new Float32Array([-0]),Zt=new Uint8Array(co.buffer);function mi(r,t,e){co[0]=r,t[e]=Zt[0],t[e+1]=Zt[1],t[e+2]=Zt[2],t[e+3]=Zt[3]}function yi(r,t){return Zt[0]=r[t],Zt[1]=r[t+1],Zt[2]=r[t+2],Zt[3]=r[t+3],co[0]}var uo=new Float64Array([-0]),it=new Uint8Array(uo.buffer);function bi(r,t,e){uo[0]=r,t[e]=it[0],t[e+1]=it[1],t[e+2]=it[2],t[e+3]=it[3],t[e+4]=it[4],t[e+5]=it[5],t[e+6]=it[6],t[e+7]=it[7]}function gi(r,t){return it[0]=r[t],it[1]=r[t+1],it[2]=r[t+2],it[3]=r[t+3],it[4]=r[t+4],it[5]=r[t+5],it[6]=r[t+6],it[7]=r[t+7],uo[0]}var Au=BigInt(Number.MAX_SAFE_INTEGER),Iu=BigInt(Number.MIN_SAFE_INTEGER),yt=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 ie;if(t<Au&&t>Iu)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>wi&&(o=0n,++n>wi&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ie;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):ie}},ie=new yt(0,0);ie.toBigInt=function(){return 0n};ie.zzEncode=ie.zzDecode=function(){return this};ie.length=function(){return 1};var wi=4294967296n;function xi(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 Ei(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&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 fo(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 vt(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 lo=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,vt(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 vt(this,4);return Mr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw vt(this,4);return Mr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw vt(this,4);let t=yi(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw vt(this,4);let t=gi(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 vt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Ei(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw vt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw vt(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 yt(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 vt(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 vt(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 vt(this,8);let t=Mr(this.buf,this.pos+=4),e=Mr(this.buf,this.pos+=4);return new yt(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=ao(this.buf,this.pos);return this.pos+=St(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 ho(r){return new lo(r instanceof Uint8Array?r:r.subarray())}function Or(r,t,e){let n=ho(r);return t.decode(n,void 0,e)}function po(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return nt(i);o+i>t&&(n=nt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var ae=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function mo(){}var bo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Bu=po();function _u(r){return globalThis.Buffer!=null?nt(r):Bu(r)}var Xe=class{len;head;tail;states;constructor(){this.len=0,this.head=new ae(mo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new ae(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new go((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Hr,10,yt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=yt.fromBigInt(t);return this._push(Hr,e.length(),e)}uint64Number(t){return this._push(io,St(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=yt.fromBigInt(t).zzEncode();return this._push(Hr,e.length(),e)}sint64Number(t){let e=yt.fromNumber(t).zzEncode();return this._push(Hr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(yo,1,t?1:0)}fixed32(t){return this._push(We,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=yt.fromBigInt(t);return this._push(We,4,e.lo)._push(We,4,e.hi)}fixed64Number(t){let e=yt.fromNumber(t);return this._push(We,4,e.lo)._push(We,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(mi,4,t)}double(t){return this._push(bi,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(yo,1,0):this.uint32(e)._push(Tu,e,t)}string(t){let e=xi(t);return e!==0?this.uint32(e)._push(fo,e,t):this._push(yo,1,0)}fork(){return this.states=new bo(this),this.head=this.tail=new ae(mo,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new ae(mo,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=_u(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function yo(r,t,e){t[e]=r&255}function Lu(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var go=class extends ae{next;constructor(t,e){super(Lu,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 We(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 Tu(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Xe.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Pu,t,r),this},Xe.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Cu,t,r),this});function Pu(r,t,e){t.set(r,e)}function Cu(r,t,e){r.length<40?fo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(M(r),e)}function wo(){return new Xe}function qr(r,t){let e=wo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Te;(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"})(Te||(Te={}));function zr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function xo(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return zr("enum",Te.VARINT,e,n)}function Vr(r,t){return zr("message",Te.LENGTH_DELIMITED,r,t)}var Y;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(Y||(Y={}));var Eo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Eo||(Eo={}));(function(r){r.codec=()=>xo(Eo)})(Y||(Y={}));var _t;(function(r){let t;r.codec=()=>(t==null&&(t=Vr((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),Y.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 a=e.uint32();switch(a>>>3){case 1:{s.Type=Y.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>qr(e,r.codec()),r.decode=(e,n)=>Or(e,r.codec(),n)})(_t||(_t={}));var So;(function(r){let t;r.codec=()=>(t==null&&(t=Vr((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),Y.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 a=e.uint32();switch(a>>>3){case 1:{s.Type=Y.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>qr(e,r.codec()),r.decode=(e,n)=>Or(e,r.codec(),n)})(So||(So={}));function Fr(r){if(isNaN(r)||r<=0)throw new V("random bytes length must be a Number bigger than 0");return Qt(r)}var Qe={};ht(Qe,{MAX_RSA_KEY_SIZE:()=>vo,generateRSAKeyPair:()=>_i,jwkToJWKKeyPair:()=>Li,jwkToPkcs1:()=>Ku,jwkToPkix:()=>_o,jwkToRSAPrivateKey:()=>Co,pkcs1MessageToJwk:()=>Io,pkcs1MessageToRSAPrivateKey:()=>Lo,pkcs1ToJwk:()=>Ru,pkcs1ToRSAPrivateKey:()=>Bi,pkixMessageToJwk:()=>Bo,pkixMessageToRSAPublicKey:()=>Po,pkixToJwk:()=>Uu,pkixToRSAPublicKey:()=>To});var Gr=_r;var Pe=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=Qe.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return rt.createV1(114,this._multihash)}toString(){return F.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}verify(t,e,n){return Ii(this.jwk,e,t,n)}},Je=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=Qe.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}sign(t,e){return Ai(this.jwk,t,e)}};var vo=8192,Ao=18,Du=1062,Nu=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Ru(r){let t=Pt(r);return Io(t)}function Io(r){return{n:O(r[1],"base64url"),e:O(r[2],"base64url"),d:O(r[3],"base64url"),p:O(r[4],"base64url"),q:O(r[5],"base64url"),dp:O(r[6],"base64url"),dq:O(r[7],"base64url"),qi:O(r[8],"base64url"),kty:"RSA"}}function Ku(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 V("JWK was missing components");return qt([pt(Uint8Array.from([0])),pt(M(r.n,"base64url")),pt(M(r.e,"base64url")),pt(M(r.d,"base64url")),pt(M(r.p,"base64url")),pt(M(r.q,"base64url")),pt(M(r.dp,"base64url")),pt(M(r.dq,"base64url")),pt(M(r.qi,"base64url"))]).subarray()}function Uu(r){let t=Pt(r,{offset:0});return Bo(t)}function Bo(r){let t=Pt(r[1],{offset:0});return{kty:"RSA",n:O(t[0],"base64url"),e:O(t[1],"base64url")}}function _o(r){if(r.n==null||r.e==null)throw new V("JWK was missing components");return qt([Nu,vr(qt([pt(M(r.n,"base64url")),pt(M(r.e,"base64url"))]))]).subarray()}function Bi(r){let t=Pt(r);return Lo(t)}function Lo(r){let t=Io(r);return Co(t)}function To(r,t){if(r.byteLength>=Du)throw new he("Key size is too large");let e=Pt(r,{offset:0});return Po(e,r,t)}function Po(r,t,e){let n=Bo(r);if(e==null){let o=Gr(_t.encode({Type:Y.RSA,Data:t}));e=gt(Ao,o)}return new Pe(n,e)}function Co(r){if(Pi(r)>vo)throw new V("Key size is too large");let t=Li(r),e=Gr(_t.encode({Type:Y.RSA,Data:_o(t.publicKey)})),n=gt(Ao,e);return new Je(t.privateKey,new Pe(t.publicKey,n))}async function _i(r){if(r>vo)throw new V("Key size is too large");let t=await Ti(r),e=Gr(_t.encode({Type:Y.RSA,Data:_o(t.publicKey)})),n=gt(Ao,e);return new Je(t.privateKey,new Pe(t.publicKey,n))}function Li(r){if(r==null)throw new V("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function Ti(r,t){let e=await bt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await ku(e,t);return{privateKey:n[0],publicKey:n[1]}}async function Ai(r,t,e){let n=await bt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);e?.signal?.throwIfAborted();let o=await bt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return e?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Ii(r,t,e,n){let o=await bt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await bt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,e instanceof Uint8Array?e:e.subarray());return n?.signal?.throwIfAborted(),s}async function ku(r,t){if(r.privateKey==null||r.publicKey==null)throw new V("Private and public key are required");let e=await Promise.all([bt.get().subtle.exportKey("jwk",r.privateKey),bt.get().subtle.exportKey("jwk",r.publicKey)]);return t?.signal?.throwIfAborted(),e}function Pi(r){if(r.kty!=="RSA")throw new V("invalid key type");if(r.n==null)throw new V("invalid key modulus");return M(r.n,"base64url").length*8}var jr=class extends xe{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,vs(t);let n=Ve(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),Nt(s)}update(t){return Se(this),this.iHash.update(t),this}digestInto(t){Se(this),ot(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:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,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()}},Do=(r,t,e)=>new jr(r,t).update(e).digest();Do.create=(r,t)=>new jr(r,t);function Ci(r){r.lowS!==void 0&&Kt("lowS",r.lowS),r.prehash!==void 0&&Kt("prehash",r.prehash)}var No=class extends Error{constructor(t=""){super(t)}},Ut={Err:No,_tlv:{encode:(r,t)=>{let{Err:e}=Ut;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=Ze(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?Ze(o.length/2|128):"";return Ze(r)+s+o+t},decode(r,t){let{Err:e}=Ut,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 c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let l=t.subarray(n,n+c);if(l.length!==c)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+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Ut;if(r<tr)throw new t("integer: negative integers are not allowed");let e=Ze(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}=Ut;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 Ae(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Ut,o=q("signature",r),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:l,l:u}=n.decode(2,c);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(l)}},hexFromSig(r){let{_tlv:t,_int:e}=Ut,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},tr=BigInt(0),er=BigInt(1),Mu=BigInt(2),Zr=BigInt(3),Ou=BigInt(4);function Hu(r,t,e){function n(o){let s=r.sqr(o),i=r.mul(s,o);return r.add(r.add(i,r.mul(o,t)),e)}return n}function Di(r,t,e){let{BYTES:n}=r;function o(s){let i;if(typeof s=="bigint")i=s;else{let a=q("private key",s);if(t){if(!t.includes(a.length*2))throw new Error("invalid private key");let c=new Uint8Array(n);c.set(a,c.length-a.length),a=c}try{i=r.fromBytes(a)}catch{throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof s}`)}}if(e&&(i=r.create(i)),!r.isValidNot0(i))throw new Error("invalid private key: out of range [1..N-1]");return i}return o}function qu(r,t={}){let{Fp:e,Fn:n}=Dr("weierstrass",r,t),{h:o,n:s}=r;jt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:i}=t;if(i&&(!e.is0(r.a)||typeof i.beta!="bigint"||typeof i.splitScalar!="function"))throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');function a(){if(!e.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function c(B,h,w){let{x:m,y:g}=h.toAffine(),E=e.toBytes(m);if(Kt("isCompressed",w),w){a();let _=!e.isOdd(g);return mt(Ni(_),E)}else return mt(Uint8Array.of(4),E,e.toBytes(g))}function l(B){ot(B);let h=e.BYTES,w=h+1,m=2*h+1,g=B.length,E=B[0],_=B.subarray(1);if(g===w&&(E===2||E===3)){let I=e.fromBytes(_);if(!e.isValid(I))throw new Error("bad point: is not on curve, wrong x");let T=b(I),R;try{R=e.sqrt(T)}catch(k){let K=k instanceof Error?": "+k.message:"";throw new Error("bad point: is not on curve, sqrt error"+K)}a();let N=e.isOdd(R);return(E&1)===1!==N&&(R=e.neg(R)),{x:I,y:R}}else if(g===m&&E===4){let I=e.fromBytes(_.subarray(h*0,h*1)),T=e.fromBytes(_.subarray(h*1,h*2));if(!p(I,T))throw new Error("bad point: is not on curve");return{x:I,y:T}}else throw new Error(`bad point: got length ${g}, expected compressed=${w} or uncompressed=${m}`)}let u=t.toBytes||c,f=t.fromBytes||l,b=Hu(e,r.a,r.b);function p(B,h){let w=e.sqr(h),m=b(B);return e.eql(w,m)}if(!p(r.Gx,r.Gy))throw new Error("bad curve params: generator point");let v=e.mul(e.pow(r.a,Zr),Ou),x=e.mul(e.sqr(r.b),BigInt(27));if(e.is0(e.add(v,x)))throw new Error("bad curve params: a or b");function d(B,h,w=!1){if(!e.isValid(h)||w&&e.is0(h))throw new Error(`bad point coordinate ${B}`);return h}function S(B){if(!(B instanceof y))throw new Error("ProjectivePoint expected")}let L=Be((B,h)=>{let{px:w,py:m,pz:g}=B;if(e.eql(g,e.ONE))return{x:w,y:m};let E=B.is0();h==null&&(h=E?e.ONE:e.inv(g));let _=e.mul(w,h),I=e.mul(m,h),T=e.mul(g,h);if(E)return{x:e.ZERO,y:e.ZERO};if(!e.eql(T,e.ONE))throw new Error("invZ was invalid");return{x:_,y:I}}),A=Be(B=>{if(B.is0()){if(t.allowInfinityPoint&&!e.is0(B.py))return;throw new Error("bad point: ZERO")}let{x:h,y:w}=B.toAffine();if(!e.isValid(h)||!e.isValid(w))throw new Error("bad point: x or y not field elements");if(!p(h,w))throw new Error("bad point: equation left != right");if(!B.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function D(B,h,w,m,g){return w=new y(e.mul(w.px,B),w.py,w.pz),h=_e(m,h),w=_e(g,w),h.add(w)}class y{constructor(h,w,m){this.px=d("x",h),this.py=d("y",w,!0),this.pz=d("z",m),Object.freeze(this)}static fromAffine(h){let{x:w,y:m}=h||{};if(!h||!e.isValid(w)||!e.isValid(m))throw new Error("invalid affine point");if(h instanceof y)throw new Error("projective point not allowed");return e.is0(w)&&e.is0(m)?y.ZERO:new y(w,m,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){return Tr(y,"pz",h)}static fromBytes(h){return ot(h),y.fromHex(h)}static fromHex(h){let w=y.fromAffine(f(q("pointHex",h)));return w.assertValidity(),w}static fromPrivateKey(h){let w=Di(n,t.allowedPrivateKeyLengths,t.wrapPrivateKey);return y.BASE.multiply(w(h))}static msm(h,w){return Cr(y,n,h,w)}precompute(h=8,w=!0){return P.setWindowSize(this,h),w||this.multiply(Zr),this}_setWindowSize(h){this.precompute(h)}assertValidity(){A(this)}hasEvenY(){let{y:h}=this.toAffine();if(!e.isOdd)throw new Error("Field doesn't support isOdd");return!e.isOdd(h)}equals(h){S(h);let{px:w,py:m,pz:g}=this,{px:E,py:_,pz:I}=h,T=e.eql(e.mul(w,I),e.mul(E,g)),R=e.eql(e.mul(m,I),e.mul(_,g));return T&&R}negate(){return new y(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b:w}=r,m=e.mul(w,Zr),{px:g,py:E,pz:_}=this,I=e.ZERO,T=e.ZERO,R=e.ZERO,N=e.mul(g,g),Z=e.mul(E,E),k=e.mul(_,_),K=e.mul(g,E);return K=e.add(K,K),R=e.mul(g,_),R=e.add(R,R),I=e.mul(h,R),T=e.mul(m,k),T=e.add(I,T),I=e.sub(Z,T),T=e.add(Z,T),T=e.mul(I,T),I=e.mul(K,I),R=e.mul(m,R),k=e.mul(h,k),K=e.sub(N,k),K=e.mul(h,K),K=e.add(K,R),R=e.add(N,N),N=e.add(R,N),N=e.add(N,k),N=e.mul(N,K),T=e.add(T,N),k=e.mul(E,_),k=e.add(k,k),N=e.mul(k,K),I=e.sub(I,N),R=e.mul(k,Z),R=e.add(R,R),R=e.add(R,R),new y(I,T,R)}add(h){S(h);let{px:w,py:m,pz:g}=this,{px:E,py:_,pz:I}=h,T=e.ZERO,R=e.ZERO,N=e.ZERO,Z=r.a,k=e.mul(r.b,Zr),K=e.mul(w,E),W=e.mul(m,_),J=e.mul(g,I),et=e.add(w,m),H=e.add(E,_);et=e.mul(et,H),H=e.add(K,W),et=e.sub(et,H),H=e.add(w,g);let ct=e.add(E,I);return H=e.mul(H,ct),ct=e.add(K,J),H=e.sub(H,ct),ct=e.add(m,g),T=e.add(_,I),ct=e.mul(ct,T),T=e.add(W,J),ct=e.sub(ct,T),N=e.mul(Z,H),T=e.mul(k,J),N=e.add(T,N),T=e.sub(W,N),N=e.add(W,N),R=e.mul(T,N),W=e.add(K,K),W=e.add(W,K),J=e.mul(Z,J),H=e.mul(k,H),W=e.add(W,J),J=e.sub(K,J),J=e.mul(Z,J),H=e.add(H,J),K=e.mul(W,H),R=e.add(R,K),K=e.mul(ct,H),T=e.mul(et,T),T=e.sub(T,K),K=e.mul(et,W),N=e.mul(ct,N),N=e.add(N,K),new y(T,R,N)}subtract(h){return this.add(h.negate())}is0(){return this.equals(y.ZERO)}multiply(h){let{endo:w}=t;if(!n.isValidNot0(h))throw new Error("invalid scalar: out of range");let m,g,E=_=>P.wNAFCached(this,_,y.normalizeZ);if(w){let{k1neg:_,k1:I,k2neg:T,k2:R}=w.splitScalar(h),{p:N,f:Z}=E(I),{p:k,f:K}=E(R);g=Z.add(K),m=D(w.beta,N,k,_,T)}else{let{p:_,f:I}=E(h);m=_,g=I}return y.normalizeZ([m,g])[0]}multiplyUnsafe(h){let{endo:w}=t,m=this;if(!n.isValid(h))throw new Error("invalid scalar: out of range");if(h===tr||m.is0())return y.ZERO;if(h===er)return m;if(P.hasPrecomputes(this))return this.multiply(h);if(w){let{k1neg:g,k1:E,k2neg:_,k2:I}=w.splitScalar(h),{p1:T,p2:R}=oi(y,m,E,I);return D(w.beta,T,R,g,_)}else return P.wNAFCachedUnsafe(m,h)}multiplyAndAddUnsafe(h,w,m){let g=this.multiplyUnsafe(w).add(h.multiplyUnsafe(m));return g.is0()?void 0:g}toAffine(h){return L(this,h)}isTorsionFree(){let{isTorsionFree:h}=t;return o===er?!0:h?h(y,this):P.wNAFCachedUnsafe(this,s).is0()}clearCofactor(){let{clearCofactor:h}=t;return o===er?this:h?h(y,this):this.multiplyUnsafe(o)}toBytes(h=!0){return Kt("isCompressed",h),this.assertValidity(),u(y,this,h)}toRawBytes(h=!0){return this.toBytes(h)}toHex(h=!0){return At(this.toBytes(h))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}y.BASE=new y(r.Gx,r.Gy,e.ONE),y.ZERO=new y(e.ZERO,e.ONE,e.ZERO),y.Fp=e,y.Fn=n;let C=n.BITS,P=Pr(y,t.endo?Math.ceil(C/2):C);return y}function Ni(r){return Uint8Array.of(r?2:3)}function zu(r,t,e={}){jt(t,{hash:"function"},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=t.randomBytes||Qt,o=t.hmac||((m,...g)=>Do(t.hash,m,mt(...g))),{Fp:s,Fn:i}=r,{ORDER:a,BITS:c}=i;function l(m){let g=a>>er;return m>g}function u(m){return l(m)?i.neg(m):m}function f(m,g){if(!i.isValidNot0(g))throw new Error(`invalid signature ${m}: out of range 1..CURVE.n`)}class b{constructor(g,E,_){f("r",g),f("s",E),this.r=g,this.s=E,_!=null&&(this.recovery=_),Object.freeze(this)}static fromCompact(g){let E=i.BYTES,_=q("compactSignature",g,E*2);return new b(i.fromBytes(_.subarray(0,E)),i.fromBytes(_.subarray(E,E*2)))}static fromDER(g){let{r:E,s:_}=Ut.toSig(q("DER",g));return new b(E,_)}assertValidity(){}addRecoveryBit(g){return new b(this.r,this.s,g)}recoverPublicKey(g){let E=s.ORDER,{r:_,s:I,recovery:T}=this;if(T==null||![0,1,2,3].includes(T))throw new Error("recovery id invalid");if(a*Mu<E&&T>1)throw new Error("recovery id is ambiguous for h>1 curve");let N=T===2||T===3?_+a:_;if(!s.isValid(N))throw new Error("recovery id 2 or 3 invalid");let Z=s.toBytes(N),k=r.fromHex(mt(Ni((T&1)===0),Z)),K=i.inv(N),W=A(q("msgHash",g)),J=i.create(-W*K),et=i.create(I*K),H=r.BASE.multiplyUnsafe(J).add(k.multiplyUnsafe(et));if(H.is0())throw new Error("point at infinify");return H.assertValidity(),H}hasHighS(){return l(this.s)}normalizeS(){return this.hasHighS()?new b(this.r,i.neg(this.s),this.recovery):this}toBytes(g){if(g==="compact")return mt(i.toBytes(this.r),i.toBytes(this.s));if(g==="der")return ve(Ut.hexFromSig(this));throw new Error("invalid format")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return At(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return At(this.toBytes("compact"))}}let p=Di(i,e.allowedPrivateKeyLengths,e.wrapPrivateKey),v={isValidPrivateKey(m){try{return p(m),!0}catch{return!1}},normPrivateKeyToScalar:p,randomPrivateKey:()=>{let m=a;return Js(n($n(m)),m)},precompute(m=8,g=r.BASE){return g.precompute(m,!1)}};function x(m,g=!0){return r.fromPrivateKey(m).toBytes(g)}function d(m){if(typeof m=="bigint")return!1;if(m instanceof r)return!0;let E=q("key",m).length,_=s.BYTES,I=_+1,T=2*_+1;if(!(e.allowedPrivateKeyLengths||i.BYTES===I))return E===I||E===T}function S(m,g,E=!0){if(d(m)===!0)throw new Error("first arg must be private key");if(d(g)===!1)throw new Error("second arg must be public key");return r.fromHex(g).multiply(p(m)).toBytes(E)}let L=t.bits2int||function(m){if(m.length>8192)throw new Error("input is too large");let g=Ae(m),E=m.length*8-c;return E>0?g>>BigInt(E):g},A=t.bits2int_modN||function(m){return i.create(L(m))},D=ne(c);function y(m){return Gt("num < 2^"+c,m,tr,D),i.toBytes(m)}function C(m,g,E=P){if(["recovered","canonical"].some(et=>et in E))throw new Error("sign() legacy options not supported");let{hash:_}=t,{lowS:I,prehash:T,extraEntropy:R}=E;I==null&&(I=!0),m=q("msgHash",m),Ci(E),T&&(m=q("prehashed msgHash",_(m)));let N=A(m),Z=p(g),k=[y(Z),y(N)];if(R!=null&&R!==!1){let et=R===!0?n(s.BYTES):R;k.push(q("extraEntropy",et))}let K=mt(...k),W=N;function J(et){let H=L(et);if(!i.isValidNot0(H))return;let ct=i.inv(H),Re=r.BASE.multiply(H).toAffine(),fe=i.create(Re.x);if(fe===tr)return;let $t=i.create(ct*i.create(W+fe*Z));if($t===tr)return;let fn=(Re.x===fe?0:2)|Number(Re.y&er),le=$t;return I&&l($t)&&(le=u($t),fn^=1),new b(fe,le,fn)}return{seed:K,k2sig:J}}let P={lowS:t.lowS,prehash:!1},B={lowS:t.lowS,prehash:!1};function h(m,g,E=P){let{seed:_,k2sig:I}=C(m,g,E);return zs(t.hash.outputLen,i.BYTES,o)(_,I)}r.BASE.precompute(8);function w(m,g,E,_=B){let I=m;g=q("msgHash",g),E=q("publicKey",E),Ci(_);let{lowS:T,prehash:R,format:N}=_;if("strict"in _)throw new Error("options.strict was renamed to lowS");if(N!==void 0&&!["compact","der","js"].includes(N))throw new Error('format must be "compact", "der" or "js"');let Z=typeof I=="string"||Ee(I),k=!Z&&!N&&typeof I=="object"&&I!==null&&typeof I.r=="bigint"&&typeof I.s=="bigint";if(!Z&&!k)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let K,W;try{if(k)if(N===void 0||N==="js")K=new b(I.r,I.s);else throw new Error("invalid format");if(Z){try{N!=="compact"&&(K=b.fromDER(I))}catch(le){if(!(le instanceof Ut.Err))throw le}!K&&N!=="der"&&(K=b.fromCompact(I))}W=r.fromHex(E)}catch{return!1}if(!K||T&&K.hasHighS())return!1;R&&(g=t.hash(g));let{r:J,s:et}=K,H=A(g),ct=i.inv(et),Re=i.create(H*ct),fe=i.create(J*ct),$t=r.BASE.multiplyUnsafe(Re).add(W.multiplyUnsafe(fe));return $t.is0()?!1:i.create($t.x)===J}return Object.freeze({getPublicKey:x,getSharedSecret:S,sign:h,verify:w,utils:v,Point:r,Signature:b})}function Vu(r){let t={a:r.a,b:r.b,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=Et(t.n,r.nBitLength),o={Fp:e,Fn:n,allowedPrivateKeyLengths:r.allowedPrivateKeyLengths,allowInfinityPoint:r.allowInfinityPoint,endo:r.endo,wrapPrivateKey:r.wrapPrivateKey,isTorsionFree:r.isTorsionFree,clearCofactor:r.clearCofactor,fromBytes:r.fromBytes,toBytes:r.toBytes};return{CURVE:t,curveOpts:o}}function Fu(r){let{CURVE:t,curveOpts:e}=Vu(r),n={hash:r.hash,hmac:r.hmac,randomBytes:r.randomBytes,lowS:r.lowS,bits2int:r.bits2int,bits2int_modN:r.bits2int_modN};return{CURVE:t,curveOpts:e,ecdsaOpts:n}}function Gu(r,t){return Object.assign({},t,{ProjectivePoint:t.Point,CURVE:r})}function Ri(r){let{CURVE:t,curveOpts:e,ecdsaOpts:n}=Fu(r),o=qu(t,e),s=zu(o,n,e);return Gu(r,s)}function Ki(r,t){let e=n=>Ri({...r,hash:n});return{...e(t),create:e}}var $r={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},dp=BigInt(0),ju=BigInt(1),Ro=BigInt(2),Ui=(r,t)=>(r+t/Ro)/t;function Zu(r){let t=$r.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),l=r*r*r%t,u=l*l*r%t,f=z(u,e,t)*u%t,b=z(f,e,t)*u%t,p=z(b,Ro,t)*l%t,v=z(p,o,t)*p%t,x=z(v,s,t)*v%t,d=z(x,a,t)*x%t,S=z(d,c,t)*d%t,L=z(S,a,t)*x%t,A=z(L,e,t)*u%t,D=z(A,i,t)*v%t,y=z(D,n,t)*l%t,C=z(y,Ro,t);if(!Ko.eql(Ko.sqr(C),r))throw new Error("Cannot find square root");return C}var Ko=Et($r.p,void 0,void 0,{sqrt:Zu}),Ce=Ki({...$r,Fp:Ko,lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=$r.n,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-ju*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),a=Ui(s*r,t),c=Ui(-n*r,t),l=G(r-a*e-c*o,t),u=G(-a*n-c*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}}}},_r);function ki(r,t,e,n){let o=Xt.digest(e instanceof Uint8Array?e:e.subarray());if(Ur(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ce.verify(t,s,r))).catch(s=>{throw s.name==="AbortError"?s:new Ye(String(s))});try{return n?.signal?.throwIfAborted(),Ce.verify(t,o.digest,r)}catch(s){throw new Ye(String(s))}}var Yr=class{type="secp256k1";raw;_key;constructor(t){this._key=Oi(t),this.raw=Mi(this._key)}toMultihash(){return wt.digest(Ct(this))}toCID(){return rt.createV1(114,this.toMultihash())}toString(){return F.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}verify(t,e,n){return ki(this._key,e,t,n)}};function Uo(r){return new Yr(r)}function Mi(r){return Ce.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Oi(r){try{return Ce.ProjectivePoint.fromHex(r),r}catch(t){throw new he(String(t))}}function ko(r,t){let{Type:e,Data:n}=_t.decode(r),o=n??new Uint8Array;switch(e){case Y.RSA:return To(o,t);case Y.Ed25519:return eo(o);case Y.secp256k1:return Uo(o);case Y.ECDSA:return On(o);default:throw new Yt}}function Hi(r){let{Type:t,Data:e}=_t.decode(r.digest),n=e??new Uint8Array;switch(t){case Y.Ed25519:return eo(n);case Y.secp256k1:return Uo(n);case Y.ECDSA:return On(n);default:throw new Yt}}function Ct(r){return _t.encode({Type:Y[r.type],Data:r.raw})}var qi=Symbol.for("nodejs.util.inspect.custom"),$u=114,rr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[ln]=!0;toString(){return this.string==null&&(this.string=F.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return rt.createV1($u,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return dt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return dt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[qi](){return`PeerId(${this.toString()})`}},nr=class extends rr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},or=class extends rr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},sr=class extends rr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Yu=2336,Wr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=wt.digest(M(this.url))}[qi](){return`PeerId(${this.url})`}[ln]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return rt.createV1(Yu,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=O(t)),t.toString()===this.toString())}};function Mo(r){if(r.type==="Ed25519")return new or({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new sr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new nr({multihash:r.toCID().multihash,publicKey:r});throw new Yt}function zi(r){return Mo(r.publicKey)}function ir(r){if(Xu(r))return new nr({multihash:r});if(Wu(r))try{let t=Hi(r);if(t.type==="Ed25519")return new or({multihash:r,publicKey:t});if(t.type==="secp256k1")return new sr({multihash:r,publicKey:t})}catch{let e=O(r.digest);return new Wr(new URL(e))}throw new gr("Supplied PeerID Multihash is invalid")}function Wu(r){return r.code===wt.code}function Xu(r){return r.code===Xt.code}function ce(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 Xr(r){let t=Ot(F.decode(`z${r}`));return ir(t)}var ar=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 ce(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 ce(this.map.values(),t=>t.key)}values(){return ce(this.map.values(),t=>t.value)}get size(){return this.map.size}};var cr=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 ce(this.set.entries(),t=>{let e=Xr(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Xr(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return ce(this.set.values(),t=>Xr(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 kt(){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}},De=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 Oo=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 Ju(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 Ju(r,t){t=t??{};let e=t.onEnd,n=new De,o,s,i,a=kt(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((d,S)=>{s=L=>{s=null,n.push(L);try{d(r(n))}catch(A){S(A)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=kt()})}},l=d=>s!=null?s(d):(n.push(d),o),u=d=>(n=new De,s!=null?s({error:d}):(n.push({error:d}),o)),f=d=>{if(i)return o;if(t?.objectMode!==!0&&d?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:d})},b=d=>i?o:(i=!0,d!=null?u(d):l({done:!0})),p=()=>(n=new De,b(),{done:!0}),v=d=>(b(d),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:p,throw:v,push:f,end:b,get readableLength(){return n.size},onEmpty:async d=>{let S=d?.signal;if(S?.throwIfAborted(),n.isEmpty())return;let L,A;S!=null&&(L=new Promise((D,y)=>{A=()=>{y(new Oo)},S.addEventListener("abort",A)}));try{await Promise.race([a.promise,L])}finally{A!=null&&S!=null&&S?.removeEventListener("abort",A)}}},e==null)return o;let x=o;return o={[Symbol.asyncIterator](){return this},next(){return x.next()},throw(d){return x.throw(d),e!=null&&(e(d),e=void 0),{done:!0}},return(){return x.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(d){return x.end(d),e!=null&&(e(d),e=void 0),o},get readableLength(){return x.readableLength},onEmpty:d=>x.onEmpty(d)},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 Vi(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 Ho=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=kt(),this.haveNext=kt()}[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=kt(),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=kt(),await Vi(this.readNext.promise,e?.signal,e)}};function Fi(){return new Ho}function Qu(r){return r[Symbol.asyncIterator]!=null}async function tf(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*ef(r){let t=new AbortController,e=Fi();tf(r,e,t.signal).catch(()=>{});try{yield*e}finally{t.abort()}}function*rf(r){for(let t of r)yield*t}function nf(...r){let t=[];for(let e of r)Qu(e)||t.push(e);return t.length===r.length?rf(t):ef(r)}var Gi=nf;function ur(r,...t){if(r==null)throw new Error("Empty pipeline");if(qo(r)){let n=r;r=()=>n.source}else if(Zi(r)||ji(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&qo(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++)qo(e[n])&&(e[n]=sf(e[n]));return of(...e)}var of=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},ji=r=>r?.[Symbol.asyncIterator]!=null,Zi=r=>r?.[Symbol.iterator]!=null,qo=r=>r==null?!1:r.sink!=null&&r.source!=null,sf=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(Zi(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Gi(n,o())}return r.source};var Vo=ya(Yi(),1);var lr=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},Fo=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},Wi=r=>globalThis.DOMException===void 0?new Fo(r):new DOMException(r),Xi=r=>{let t=r.reason===void 0?Wi("This operation was aborted."):r.reason;return t instanceof Error?t:Wi(t)};function Go(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,a,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:p}=t;p.aborted&&f(Xi(p)),a=()=>{f(Xi(p))},p.addEventListener("abort",a,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(u,f);return}let b=new lr;i=s.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(p){f(p)}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(p){f(p)}})()}).finally(()=>{l.clear(),a&&t.signal&&t.signal.removeEventListener("abort",a)});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 hr=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 dr=class extends Vo.default{#t;#i;#s=0;#d;#a;#p=0;#r;#c;#e;#m;#n=0;#u;#o;#y;#w=1n;timeout;constructor(t){if(super(),t={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:hr,...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#x(){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.#x&&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.#w++).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=Go(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 lr&&!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 Ji(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 Qi(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function ta(r,t){let e=Ji(r).return?.();Qi(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"},Ne=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},nn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},pr=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function on(r){return r[Symbol.asyncIterator]!=null}function ea(r,t){if(r.byteLength>t)throw new Ne("Message length too long")}var an=r=>{let t=St(r),e=nt(t);return hi(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){ea(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 ea(r,n),new X(e(r.byteLength),r)};var ue;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(ue||(ue={}));var Zo=r=>{let t=di(r);return Zo.bytes=St(t),t};Zo.bytes=0;function mr(r,t){let e=new X,n=ue.LENGTH,o=-1,s=t?.lengthDecoder??Zo,i=t?.maxLengthLength??8,a=t?.maxDataLength??4194304;function*c(){for(;e.byteLength>0;){if(n===ue.LENGTH)try{if(o=s(e),o<0)throw new rn("Invalid message length");if(o>a)throw new Ne("Message length too long");let l=s.bytes;e.consume(l),t?.onLength!=null&&t.onLength(o),n=ue.DATA}catch(l){if(l instanceof RangeError){if(e.byteLength>i)throw new nn("Message length length too long");break}throw l}if(n===ue.DATA){if(e.byteLength<o)break;let l=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(l),yield l,n=ue.LENGTH}}}return on(r)?async function*(){for await(let l of r)e.append(l),yield*c();if(e.byteLength>0)throw new pr("Unexpected end of input")}():function*(){for(let l of r)e.append(l),yield*c();if(e.byteLength>0)throw new pr("Unexpected end of input")}()}mr.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 mr(n,{...t??{},onLength:s=>{e=s}})};var un=class extends de{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 X(t):t)}attachInboundStream(t,e){let n=()=>{ta(t.source,this.log)};return this._inboundAbortController.signal.addEventListener("abort",n,{once:!0}),this._rawInboundStream=t,this.inboundStream=ur(this._rawInboundStream,o=>mr(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"))}}),ur(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 ra(){return BigInt(`0x${O(Fr(8),"base16")}`)}var na=(r,t)=>{let e=M(t.toString(16).padStart(16,"0"),"base16"),n=Ct(r),o=new Uint8Array(n.byteLength+e.length);return o.set(n,0),o.set(e,n.byteLength),o},oa=r=>Xt.encode(r);var sa=function(r){return Array.isArray(r)?r:[r]},lf=async r=>{if(r.sequenceNumber==null||r.from==null||r.signature==null)return!1;let t=ir(Ot(r.from));if(t.publicKey!=null)return!0;if(r.key!=null){let e=r.key;return Mo(ko(e)).equals(t)}return!1},ia=async r=>{if(r.from==null)throw new $("RPC message was missing from");if(!await lf(r))return{type:"unsigned",topic:r.topic??"",data:r.data??new Uint8Array(0)};let t=ir(Ot(r.from)),e=r.key??t.publicKey;if(e==null)throw new $("RPC message was missing public key");return{type:"signed",from:t,topic:r.topic??"",sequenceNumber:df(r.sequenceNumber??new Uint8Array(0)),data:r.data??new Uint8Array(0),signature:r.signature??new Uint8Array(0),key:e instanceof Uint8Array?ko(e):e}},yr=r=>r.type==="signed"?{from:r.from.toMultihash().bytes,data:r.data,sequenceNumber:hf(r.sequenceNumber),topic:r.topic,signature:r.signature,key:r.key?Ct(r.key):void 0}:{data:r.data,topic:r.topic},hf=r=>{let t=r.toString(16);return t.length%2!==0&&(t=`0${t}`),M(t,"base16")},df=r=>BigInt(`0x${O(r,"base16")}`);var aa=M("libp2p-pubsub:");async function ca(r,t,e){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:zi(r)},o=Wt([aa,e(yr(n)).subarray()]);return n.signature=await r.sign(o),n.key=r.publicKey,n}async function ua(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=Wt([aa,t({...yr(r),signature:void 0,key:void 0}).subarray()]);return pf(r).verify(e,r.signature)}function pf(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 $o=class extends de{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:a=10,maxInboundStreams:c=1,maxOutboundStreams:l=1}=e;this.log=t.logger.forComponent("libp2p:pubsub"),this.components=t,this.multicodecs=sa(n),this.enabled=e.enabled!==!1,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new ar,this.globalSignaturePolicy=o==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=s,this.emitSelf=i,this.topicValidators=new Map,this.queue=new dr({concurrency:a}),this.maxInboundStreams=c,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(a=>{this.log(a)})}_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 ur(e,async o=>{for await(let s of o){let i=this.decodeRpc(s),a=[];for(let c of i.messages??[]){if(c.from==null||c.data==null||c.topic==null){this.log("message from %p was missing from, data or topic fields, dropping",t);continue}a.push({from:c.from,data:c.data,topic:c.topic,sequenceNumber:c.sequenceNumber??void 0,signature:c.signature??void 0,key:c.key??void 0})}this.processRpc(t,n,{subscriptions:(i.subscriptions??[]).map(c=>({subscribe:!!c.subscribe,topic:c.topic??""})),messages:a}).catch(c=>{this.log(c)})}})}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:a})=>({topic:`${i??""}`,subscribe:!!a}))}}))),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 a=await ia(i);await this.processMessage(t,a)}catch(a){this.log.error(a)}})).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 cr,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 $('Message type should be "signed" when signature policy is StrictSign but it was not');if(t.sequenceNumber==null)throw new $("Need sequence number when signature policy is StrictSign but it was missing");if(t.key==null)throw new $("Need key when signature policy is StrictSign but it was missing");return na(t.key,t.sequenceNumber);case"StrictNoSign":return oa(t.data);default:throw new $("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(yr)})}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 $('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(e.signature!=null)throw new $("StrictNoSigning: signature should not be present");if(e.key!=null)throw new $("StrictNoSigning: key should not be present");if(e.sequenceNumber!=null)throw new $("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(e.type!=="signed")throw new $('Message type should be "signed" when signature policy is StrictSign but it was not');if(e.signature==null)throw new $("StrictSigning: Signing required and no signature was present");if(e.sequenceNumber==null)throw new $("StrictSigning: Signing required and no sequenceNumber was present");if(!await ua(e,this.encodeMessage.bind(this)))throw new $("StrictSigning: Invalid message signature");break;default:throw new $("Cannot validate message: unhandled signature policy")}let o=this.topicValidators.get(e.topic);if(o!=null){let s=await o(t,e);if(s===Ke.Reject||s===Ke.Ignore)throw new $("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return ca(this.components.privateKey,t,this.encodeMessage.bind(this));case"StrictNoSign":return Promise.resolve({type:"unsigned",...t});default:throw new $("Cannot build message: unhandled signature policy")}}getSubscribers(t){if(!this.started)throw new wr("not started yet");if(t==null)throw new V("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:ra()};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 ba(mf);})();
|
3
3
|
/*! Bundled license information:
|
4
4
|
|
5
5
|
@noble/hashes/esm/utils.js:
|
6
6
|
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
7
7
|
|
8
|
-
@noble/curves/esm/
|
8
|
+
@noble/curves/esm/utils.js:
|
9
9
|
@noble/curves/esm/abstract/modular.js:
|
10
10
|
@noble/curves/esm/abstract/curve.js:
|
11
11
|
@noble/curves/esm/abstract/edwards.js:
|