@libp2p/pubsub 10.1.8-fc5122110 → 10.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/typedoc-urls.json +32 -0
- package/package.json +8 -8
package/dist/index.min.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PPubsub = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
2
|
-
"use strict";var Libp2PPubsub=(()=>{var ca=Object.create;var yr=Object.defineProperty;var ua=Object.getOwnPropertyDescriptor;var fa=Object.getOwnPropertyNames;var la=Object.getPrototypeOf,ha=Object.prototype.hasOwnProperty;var da=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),mt=(r,t)=>{for(var e in t)yr(r,e,{get:t[e],enumerable:!0})},es=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of fa(t))!ha.call(r,o)&&o!==e&&yr(r,o,{get:()=>t[o],enumerable:!(n=ua(t,o))||n.enumerable});return r};var pa=(r,t,e)=>(e=r!=null?ca(la(r)):{},es(t||!r||!r.__esModule?yr(e,"default",{value:r,enumerable:!0}):e,r)),ma=r=>es(yr({},"__esModule",{value:!0}),r);var ki=da((hm,Ho)=>{"use strict";var Lf=Object.prototype.hasOwnProperty,yt="~";function ur(){}Object.create&&(ur.prototype=Object.create(null),new ur().__proto__||(yt=!1));function _f(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function Mi(r,t,e,n,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var s=new _f(e,n||r,o),i=yt?yt+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 Xr(r,t){--r._eventsCount===0?r._events=new ur:delete r._events[t]}function dt(){this._events=new ur,this._eventsCount=0}dt.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)Lf.call(e,n)&&t.push(yt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};dt.prototype.listeners=function(t){var e=yt?yt+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};dt.prototype.listenerCount=function(t){var e=yt?yt+t:t,n=this._events[e];return n?n.fn?1:n.length:0};dt.prototype.emit=function(t,e,n,o,s,i){var c=yt?yt+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 p=a.length,x;for(f=0;f<p;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(x=1,u=new Array(l-1);x<l;x++)u[x-1]=arguments[x];a[f].fn.apply(a[f].context,u)}}return!0};dt.prototype.on=function(t,e,n){return Mi(this,t,e,n,!1)};dt.prototype.once=function(t,e,n){return Mi(this,t,e,n,!0)};dt.prototype.removeListener=function(t,e,n,o){var s=yt?yt+t:t;if(!this._events[s])return this;if(!e)return Xr(this,s),this;var i=this._events[s];if(i.fn)i.fn===e&&(!o||i.once)&&(!n||i.context===n)&&Xr(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:Xr(this,s)}return this};dt.prototype.removeAllListeners=function(t){var e;return t?(e=yt?yt+t:t,this._events[e]&&Xr(this,e)):(this._events=new ur,this._eventsCount=0),this};dt.prototype.off=dt.prototype.removeListener;dt.prototype.addListener=dt.prototype.on;dt.prefixed=yt;dt.EventEmitter=dt;typeof Ho<"u"&&(Ho.exports=dt)});var Uf={};mt(Uf,{PubSubBaseProtocol:()=>Yo});var an=Symbol.for("@libp2p/peer-id");var ke;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(ke||(ke={}));var Mf=Symbol.for("@libp2p/pubsub");var j=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 br=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 gr=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 we=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))}};async function rs(r,t,e){let n=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);return crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},n,t,e.subarray())}function Nt(r=0){return new Uint8Array(r)}function ut(r=0){return new Uint8Array(r)}function ie(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=ut(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}function gt(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}var os=Symbol.for("@achingbrain/uint8arraylist");function ns(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 xr(r){return!!r?.[os]}var rt=class r{bufs;length;[os]=!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(xr(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(xr(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=ns(this.bufs,t);return e.buf[e.index]}set(t,e){let n=ns(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(xr(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(!xr(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 p=l;p>=0;p--){let x=this.get(f+p);if(n[p]!==x){u=Math.max(1,p-c[x]);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=ut(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=Nt(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=Nt(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=Nt(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=ut(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=Nt(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=Nt(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=Nt(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=Nt(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=Nt(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(!gt(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 hn={};mt(hn,{base10:()=>Ea});var tl=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 Ut(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function is(r){return new TextEncoder().encode(r)}function as(r){return new TextDecoder().decode(r)}function ya(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(E){if(E instanceof Uint8Array||(ArrayBuffer.isView(E)?E=new Uint8Array(E.buffer,E.byteOffset,E.byteLength):Array.isArray(E)&&(E=Uint8Array.from(E))),!(E instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(E.length===0)return"";for(var b=0,h=0,g=0,S=E.length;g!==S&&E[g]===0;)g++,b++;for(var m=(S-g)*u+1>>>0,B=new Uint8Array(m);g!==S;){for(var P=E[g],C=0,I=m-1;(P!==0||C<h)&&I!==-1;I--,C++)P+=256*B[I]>>>0,B[I]=P%c>>>0,P=P/c>>>0;if(P!==0)throw new Error("Non-zero carry");h=C,g++}for(var T=m-h;T!==m&&B[T]===0;)T++;for(var L=a.repeat(b);T<m;++T)L+=r.charAt(B[T]);return L}function p(E){if(typeof E!="string")throw new TypeError("Expected String");if(E.length===0)return new Uint8Array;var b=0;if(E[b]!==" "){for(var h=0,g=0;E[b]===a;)h++,b++;for(var S=(E.length-b)*l+1>>>0,m=new Uint8Array(S);E[b];){var B=e[E.charCodeAt(b)];if(B===255)return;for(var P=0,C=S-1;(B!==0||P<g)&&C!==-1;C--,P++)B+=c*m[C]>>>0,m[C]=B%256>>>0,B=B/256>>>0;if(B!==0)throw new Error("Non-zero carry");g=P,b++}if(E[b]!==" "){for(var I=S-g;I!==S&&m[I]===0;)I++;for(var T=new Uint8Array(h+(S-I)),L=h;I!==S;)T[L++]=m[I++];return T}}}function x(E){var b=p(E);if(b)return b;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:p,decode:x}}var ba=ya,ga=ba,us=ga;var cn=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")}},un=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)}},fn=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 fn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var ln=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 cn(t,e,n),this.decoder=new un(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ee({name:r,prefix:t,encode:e,decode:n}){return new ln(r,t,e,n)}function Gt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=us(e,r);return Ee({prefix:t,name:r,encode:n,decode:s=>Ut(o(s))})}function xa(r,t,e,n){let o={};for(let u=0;u<t.length;++u)o[t[u]]=u;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*e/8|0),c=0,a=0,l=0;for(let u=0;u<s;++u){let f=o[r[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|f,c+=e,c>=8&&(c-=8,i[l++]=255&a>>c)}if(c>=e||(255&a<<8-c)!==0)throw new SyntaxError("Unexpected end of data");return i}function wa(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 J({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return Ee({prefix:t,name:r,encode(o){return wa(o,n,e)},decode(o){return xa(o,n,e,r)}})}var Ea=Gt({prefix:"9",name:"base10",alphabet:"0123456789"});var dn={};mt(dn,{base16:()=>Sa,base16upper:()=>va});var Sa=J({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),va=J({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var pn={};mt(pn,{base2:()=>Aa});var Aa=J({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var mn={};mt(mn,{base256emoji:()=>Ta});var ls=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}"),Ba=ls.reduce((r,t,e)=>(r[e]=t,r),[]),Ia=ls.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function La(r){return r.reduce((t,e)=>(t+=Ba[e],t),"")}function _a(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Ia[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Ta=Ee({prefix:"\u{1F680}",name:"base256emoji",encode:La,decode:_a});var yn={};mt(yn,{base32:()=>Se,base32hex:()=>Da,base32hexpad:()=>Ua,base32hexpadupper:()=>Ka,base32hexupper:()=>Na,base32pad:()=>Ca,base32padupper:()=>Ra,base32upper:()=>Pa,base32z:()=>Oa});var Se=J({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Pa=J({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ca=J({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ra=J({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Da=J({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Na=J({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ua=J({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ka=J({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Oa=J({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var bn={};mt(bn,{base36:()=>qe,base36upper:()=>Ma});var qe=Gt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ma=Gt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var gn={};mt(gn,{base58btc:()=>$,base58flickr:()=>ka});var $=Gt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ka=Gt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var xn={};mt(xn,{base64:()=>qa,base64pad:()=>Ha,base64url:()=>Va,base64urlpad:()=>za});var qa=J({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ha=J({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Va=J({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),za=J({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var wn={};mt(wn,{base8:()=>Fa});var Fa=J({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var En={};mt(En,{identity:()=>Ga});var Ga=Ee({prefix:"\0",name:"identity",encode:r=>as(r),decode:r=>is(r)});var yl=new TextEncoder,bl=new TextDecoder;var vn={};mt(vn,{identity:()=>At});var Wa=ps,hs=128,ja=127,$a=~ja,Xa=Math.pow(2,31);function ps(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Xa;)t[e++]=r&255|hs,r/=128;for(;r&$a;)t[e++]=r&255|hs,r>>>=7;return t[e]=r|0,ps.bytes=e-n+1,t}var Ja=Sn,Qa=128,ds=127;function Sn(r,n){var e=0,n=n||0,o=0,s=n,i,c=r.length;do{if(s>=c)throw Sn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&ds)<<o:(i&ds)*Math.pow(2,o),o+=7}while(i>=Qa);return Sn.bytes=s-n,e}var tc=Math.pow(2,7),ec=Math.pow(2,14),rc=Math.pow(2,21),nc=Math.pow(2,28),oc=Math.pow(2,35),sc=Math.pow(2,42),ic=Math.pow(2,49),ac=Math.pow(2,56),cc=Math.pow(2,63),uc=function(r){return r<tc?1:r<ec?2:r<rc?3:r<nc?4:r<oc?5:r<sc?6:r<ic?7:r<ac?8:r<cc?9:10},fc={encode:Wa,decode:Ja,encodingLength:uc},lc=fc,He=lc;function Ve(r,t=0){return[He.decode(r,t),He.decode.bytes]}function ve(r,t,e=0){return He.encode(r,t,e),t}function Ae(r){return He.encodingLength(r)}function vt(r,t){let e=t.byteLength,n=Ae(r),o=n+Ae(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 Zt(r){let t=Ut(r),[e,n]=Ve(t),[o,s]=Ve(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 ms(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}};var ys=0,hc="identity",bs=Ut;function dc(r){return vt(ys,bs(r))}var At={code:ys,name:hc,encode:bs,digest:dc};var In={};mt(In,{sha256:()=>ae,sha512:()=>pc});function Bn({name:r,code:t,encode:e}){return new An(r,t,e)}var An=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?vt(this.code,e):e.then(n=>vt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function xs(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var ae=Bn({name:"sha2-256",code:18,encode:xs("SHA-256")}),pc=Bn({name:"sha2-512",code:19,encode:xs("SHA-512")});function ws(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return yc(e,Ln(r),t??$.encoder);default:return bc(e,Ln(r),t??Se.encoder)}}var Es=new WeakMap;function Ln(r){let t=Es.get(r);if(t==null){let e=new Map;return Es.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!==ze)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==gc)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=vt(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&&ms(t.multihash,n.multihash)}toString(t){return ws(this,t)}toJSON(){return{"/":ws(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let 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??Ss(n,o,s.bytes))}else if(e[xc]===!0){let{version:n,multihash:o,code:s}=e,i=Zt(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!==ze)throw new Error(`Version 0 CID must use dag-pb (code: ${ze}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Ss(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,ze,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Ut(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new Be(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[f,p]=Ve(t.subarray(e));return e+=p,f},o=n(),s=ze;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]=mc(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 Ln(s).set(n,t),s}};function mc(r,t){switch(r[0]){case"Q":{let e=t??$;return[$.prefix,e.decode(`${$.prefix}${r}`)]}case $.prefix:{let e=t??$;return[$.prefix,e.decode(r)]}case Se.prefix:{let e=t??Se;return[Se.prefix,e.decode(r)]}case qe.prefix:{let e=t??qe;return[qe.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 yc(r,t,e){let{prefix:n}=e;if(n!==$.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 bc(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 ze=112,gc=18;function Ss(r,t,e){let n=Ae(r),o=n+Ae(t),s=new Uint8Array(o+e.byteLength);return ve(r,s,0),ve(t,s,n),s.set(e,o),s}var xc=Symbol.for("@ipld/js-cid/CID");var _n={...En,...pn,...wn,...hn,...dn,...yn,...bn,...gn,...xn,...mn},kl={...In,...vn};function As(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var vs=As("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Tn=As("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=ut(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),wc={utf8:vs,"utf-8":vs,hex:_n.base16,latin1:Tn,ascii:Tn,binary:Tn,..._n},Er=wc;function F(r,t="utf8"){let e=Er[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function G(r,t="utf8"){let e=Er[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Ec=parseInt("11111",2),Pn=parseInt("10000000",2),Sc=parseInt("01111111",2),Bs={0:Fe,1:Fe,2:vc,3:Ic,4:Lc,5:Bc,6:Ac,16:Fe,22:Fe,48:Fe};function Kt(r,t={offset:0}){let e=r[t.offset]&Ec;if(t.offset++,Bs[e]!=null)return Bs[e](r,t);throw new Error("No decoder for tag "+e)}function Ge(r,t){let e=0;if((r[t.offset]&Pn)===Pn){let n=r[t.offset]&Sc,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 Fe(r,t){Ge(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Kt(r,t);if(n===null)break;e.push(n)}return e}function vc(r,t){let e=Ge(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 Ac(r,t){let e=Ge(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 Bc(r,t){return t.offset++,null}function Ic(r,t){let e=Ge(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 Lc(r,t){let e=Ge(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function _c(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new rt;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Cn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=_c(r.byteLength);return new rt(Uint8Array.from([t.byteLength|Pn]),t)}function xt(r){let t=new rt,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new rt(Uint8Array.from([2]),Cn(t),t)}function Sr(r){let t=Uint8Array.from([0]),e=new rt(t,r);return new rt(Uint8Array.from([3]),Cn(e),e)}function Wt(r,t=48){let e=new rt;for(let n of r)e.append(n);return new rt(Uint8Array.from([t]),Cn(e),e)}var Ie=class{type="ECDSA";raw;_key;constructor(t){this._key=t,this.raw=Is(t)}toMultihash(){return At.digest(Ot(this))}toCID(){return ft.createV1(114,this.toMultihash())}toString(){return $.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:gt(this.raw,t.raw)}async verify(t,e){return rs(this._key,e,t)}};var Tc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Pc=Uint8Array.from([6,5,43,129,4,0,34]),Cc=Uint8Array.from([6,5,43,129,4,0,35]),Rc={ext:!0,kty:"EC",crv:"P-256"},Dc={ext:!0,kty:"EC",crv:"P-384"},Nc={ext:!0,kty:"EC",crv:"P-521"},Rn=32,Dn=48,Nn=66;function Un(r){let t=Kt(r);return Ls(t)}function Ls(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===Rn*2+1)return n=G(t.subarray(e,e+Rn),"base64url"),o=G(t.subarray(e+Rn),"base64url"),new Ie({...Rc,key_ops:["verify"],x:n,y:o});if(t.byteLength===Dn*2+1)return n=G(t.subarray(e,e+Dn),"base64url"),o=G(t.subarray(e+Dn),"base64url"),new Ie({...Dc,key_ops:["verify"],x:n,y:o});if(t.byteLength===Nn*2+1)return n=G(t.subarray(e,e+Nn),"base64url"),o=G(t.subarray(e+Nn),"base64url"),new Ie({...Nc,key_ops:["verify"],x:n,y:o});throw new j(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Is(r){return Wt([xt(Uint8Array.from([1])),Wt([Uc(r.crv)],160),Wt([Sr(new rt(Uint8Array.from([4]),F(r.x??"","base64url"),F(r.y??"","base64url")))],161)]).subarray()}function Uc(r){if(r==="P-256")return Tc;if(r==="P-384")return Pc;if(r==="P-521")return Cc;throw new j(`Invalid curve ${r}`)}function _s(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function Kc(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Le(r,...t){if(!Kc(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error("Uint8Array expected of length "+t+", got length="+r.length)}function Ts(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");_s(r.outputLen),_s(r.blockLen)}function _e(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function Ps(r,t){Le(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}var ce=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function vr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Bt(r,t){return r<<32-t|r>>>t}function Cs(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function Ze(r){return typeof r=="string"&&(r=Cs(r)),Le(r),r}function Kn(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Le(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 Te=class{clone(){return this._cloneInto()}};function Ar(r){let t=n=>r().update(Ze(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 ce.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function Oc(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 Rs(r,t,e){return r&t^~r&e}function Ds(r,t,e){return r&t^r&e^t&e}var Ce=class extends Te{constructor(t,e,n,o){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=vr(this.buffer)}update(t){_e(this);let{view:e,buffer:n,blockLen:o}=this;t=Ze(t);let s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=vr(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){_e(this),Ps(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)e[f]=0;Oc(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=vr(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.length=o,t.pos=c,t.finished=s,t.destroyed=i,o%e&&t.buffer.set(n),t}};var Br=BigInt(4294967295),On=BigInt(32);function Ns(r,t=!1){return t?{h:Number(r&Br),l:Number(r>>On&Br)}:{h:Number(r>>On&Br)|0,l:Number(r&Br)|0}}function Mc(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:s,l:i}=Ns(r[o],t);[e[o],n[o]]=[s,i]}return[e,n]}var kc=(r,t)=>BigInt(r>>>0)<<On|BigInt(t>>>0),qc=(r,t,e)=>r>>>e,Hc=(r,t,e)=>r<<32-e|t>>>e,Vc=(r,t,e)=>r>>>e|t<<32-e,zc=(r,t,e)=>r<<32-e|t>>>e,Fc=(r,t,e)=>r<<64-e|t>>>e-32,Gc=(r,t,e)=>r>>>e-32|t<<64-e,Zc=(r,t)=>t,Yc=(r,t)=>r,Wc=(r,t,e)=>r<<e|t>>>32-e,jc=(r,t,e)=>t<<e|r>>>32-e,$c=(r,t,e)=>t<<e-32|r>>>64-e,Xc=(r,t,e)=>r<<e-32|t>>>64-e;function Jc(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Qc=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),tu=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,eu=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),ru=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,nu=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),ou=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var su={fromBig:Ns,split:Mc,toBig:kc,shrSH:qc,shrSL:Hc,rotrSH:Vc,rotrSL:zc,rotrBH:Fc,rotrBL:Gc,rotr32H:Zc,rotr32L:Yc,rotlSH:Wc,rotlSL:jc,rotlBH:$c,rotlBL:Xc,add:Jc,add3L:Qc,add3H:tu,add4L:eu,add4H:ru,add5H:ou,add5L:nu},U=su;var[iu,au]=U.split(["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))),jt=new Uint32Array(80),$t=new Uint32Array(80),Mn=class extends Ce{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}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:p,Gh:x,Gl:E,Hh:b,Hl:h}=this;return[t,e,n,o,s,i,c,a,l,u,f,p,x,E,b,h]}set(t,e,n,o,s,i,c,a,l,u,f,p,x,E,b,h){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=p|0,this.Gh=x|0,this.Gl=E|0,this.Hh=b|0,this.Hl=h|0}process(t,e){for(let m=0;m<16;m++,e+=4)jt[m]=t.getUint32(e),$t[m]=t.getUint32(e+=4);for(let m=16;m<80;m++){let B=jt[m-15]|0,P=$t[m-15]|0,C=U.rotrSH(B,P,1)^U.rotrSH(B,P,8)^U.shrSH(B,P,7),I=U.rotrSL(B,P,1)^U.rotrSL(B,P,8)^U.shrSL(B,P,7),T=jt[m-2]|0,L=$t[m-2]|0,Z=U.rotrSH(T,L,19)^U.rotrBH(T,L,61)^U.shrSH(T,L,6),k=U.rotrSL(T,L,19)^U.rotrBL(T,L,61)^U.shrSL(T,L,6),O=U.add4L(I,k,$t[m-7],$t[m-16]),et=U.add4H(O,C,Z,jt[m-7],jt[m-16]);jt[m]=et|0,$t[m]=O|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:l,Dl:u,Eh:f,El:p,Fh:x,Fl:E,Gh:b,Gl:h,Hh:g,Hl:S}=this;for(let m=0;m<80;m++){let B=U.rotrSH(f,p,14)^U.rotrSH(f,p,18)^U.rotrBH(f,p,41),P=U.rotrSL(f,p,14)^U.rotrSL(f,p,18)^U.rotrBL(f,p,41),C=f&x^~f&b,I=p&E^~p&h,T=U.add5L(S,P,I,au[m],$t[m]),L=U.add5H(T,g,B,C,iu[m],jt[m]),Z=T|0,k=U.rotrSH(n,o,28)^U.rotrBH(n,o,34)^U.rotrBH(n,o,39),O=U.rotrSL(n,o,28)^U.rotrBL(n,o,34)^U.rotrBL(n,o,39),et=n&s^n&c^s&c,v=o&i^o&a^i&a;g=b|0,S=h|0,b=x|0,h=E|0,x=f|0,E=p|0,{h:f,l:p}=U.add(l|0,u|0,L|0,Z|0),l=c|0,u=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let _=U.add3L(Z,O,v);n=U.add3H(_,L,k,et),o=_|0}({h:n,l:o}=U.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=U.add(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=U.add(this.Ch|0,this.Cl|0,c|0,a|0),{h:l,l:u}=U.add(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:p}=U.add(this.Eh|0,this.El|0,f|0,p|0),{h:x,l:E}=U.add(this.Fh|0,this.Fl|0,x|0,E|0),{h:b,l:h}=U.add(this.Gh|0,this.Gl|0,b|0,h|0),{h:g,l:S}=U.add(this.Hh|0,this.Hl|0,g|0,S|0),this.set(n,o,s,i,c,a,l,u,f,p,x,E,b,h,g,S)}roundClean(){jt.fill(0),$t.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Us=Ar(()=>new Mn);var _r={};mt(_r,{aInRange:()=>wt,abool:()=>It,abytes:()=>Re,bitGet:()=>du,bitLen:()=>Vn,bitMask:()=>We,bitSet:()=>pu,bytesToHex:()=>kt,bytesToNumberBE:()=>qt,bytesToNumberLE:()=>Jt,concatBytes:()=>Ht,createHmacDrbg:()=>zn,ensureBytes:()=>X,equalBytes:()=>lu,hexToBytes:()=>fe,hexToNumber:()=>Hn,inRange:()=>Ye,isBytes:()=>Xt,memoized:()=>he,notImplemented:()=>yu,numberToBytesBE:()=>Qt,numberToBytesLE:()=>le,numberToHexUnpadded:()=>ue,numberToVarBytesBE:()=>fu,utf8ToBytes:()=>hu,validateObject:()=>Ct});var Ir=BigInt(0),Lr=BigInt(1),cu=BigInt(2);function Xt(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Re(r){if(!Xt(r))throw new Error("Uint8Array expected")}function It(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}var uu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function kt(r){Re(r);let t="";for(let e=0;e<r.length;e++)t+=uu[r[e]];return t}function ue(r){let t=r.toString(16);return t.length&1?"0"+t:t}function Hn(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Ir:BigInt("0x"+r)}var Mt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ks(r){if(r>=Mt._0&&r<=Mt._9)return r-Mt._0;if(r>=Mt.A&&r<=Mt.F)return r-(Mt.A-10);if(r>=Mt.a&&r<=Mt.f)return r-(Mt.a-10)}function fe(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof 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=Ks(r.charCodeAt(s)),c=Ks(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 qt(r){return Hn(kt(r))}function Jt(r){return Re(r),Hn(kt(Uint8Array.from(r).reverse()))}function Qt(r,t){return fe(r.toString(16).padStart(t*2,"0"))}function le(r,t){return Qt(r,t).reverse()}function fu(r){return fe(ue(r))}function X(r,t,e){let n;if(typeof t=="string")try{n=fe(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Xt(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 Ht(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Re(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}function lu(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function hu(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}var kn=r=>typeof r=="bigint"&&Ir<=r;function Ye(r,t,e){return kn(r)&&kn(t)&&kn(e)&&t<=r&&r<e}function wt(r,t,e,n){if(!Ye(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Vn(r){let t;for(t=0;r>Ir;r>>=Lr,t+=1);return t}function du(r,t){return r>>BigInt(t)&Lr}function pu(r,t,e){return r|(e?Lr:Ir)<<BigInt(t)}var We=r=>(cu<<BigInt(r-1))-Lr,qn=r=>new Uint8Array(r),Os=r=>Uint8Array.from(r);function zn(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=qn(r),o=qn(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},c=(...f)=>e(o,n,...f),a=(f=qn())=>{o=c(Os([0]),f),n=c(),f.length!==0&&(o=c(Os([1]),f),n=c())},l=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,p=[];for(;f<t;){n=c();let x=n.slice();p.push(x),f+=n.length}return Ht(...p)};return(f,p)=>{i(),a(f);let x;for(;!(x=p(l()));)a();return i(),x}}var mu={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"||Xt(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 Ct(r,t,e={}){let n=(o,s,i)=>{let c=mu[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}var yu=()=>{throw new Error("not implemented")};function he(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 nt=BigInt(0),Y=BigInt(1),de=BigInt(2),bu=BigInt(3),Fn=BigInt(4),Ms=BigInt(5),ks=BigInt(8),gu=BigInt(9),xu=BigInt(16);function V(r,t){let e=r%t;return e>=nt?e:t+e}function wu(r,t,e){if(t<nt)throw new Error("invalid exponent, negatives unsupported");if(e<=nt)throw new Error("invalid modulus");if(e===Y)return nt;let n=Y;for(;t>nt;)t&Y&&(n=n*r%e),r=r*r%e,t>>=Y;return n}function W(r,t,e){let n=r;for(;t-- >nt;)n*=n,n%=e;return n}function Tr(r,t){if(r===nt)throw new Error("invert: expected non-zero number");if(t<=nt)throw new Error("invert: expected positive modulus, got "+t);let e=V(r,t),n=t,o=nt,s=Y,i=Y,c=nt;for(;e!==nt;){let l=n/e,u=n%e,f=o-i*l,p=s-c*l;n=e,e=u,o=i,s=c,i=f,c=p}if(n!==Y)throw new Error("invert: does not exist");return V(o,t)}function Eu(r){let t=(r-Y)/de,e,n,o;for(e=r-Y,n=0;e%de===nt;e/=de,n++);for(o=de;o<r&&wu(o,t,r)!==r-Y;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let i=(r+Y)/Fn;return function(a,l){let u=a.pow(l,i);if(!a.eql(a.sqr(u),l))throw new Error("Cannot find square root");return u}}let s=(e+Y)/de;return function(c,a){if(c.pow(a,t)===c.neg(c.ONE))throw new Error("Cannot find square root");let l=n,u=c.pow(c.mul(c.ONE,o),e),f=c.pow(a,s),p=c.pow(a,e);for(;!c.eql(p,c.ONE);){if(c.eql(p,c.ZERO))return c.ZERO;let x=1;for(let b=c.sqr(p);x<l&&!c.eql(b,c.ONE);x++)b=c.sqr(b);let E=c.pow(u,Y<<BigInt(l-x-1));u=c.sqr(E),f=c.mul(f,E),p=c.mul(p,u),l=x}return f}}function Su(r){if(r%Fn===bu){let t=(r+Y)/Fn;return function(n,o){let s=n.pow(o,t);if(!n.eql(n.sqr(s),o))throw new Error("Cannot find square root");return s}}if(r%ks===Ms){let t=(r-Ms)/ks;return function(n,o){let s=n.mul(o,de),i=n.pow(s,t),c=n.mul(o,i),a=n.mul(n.mul(c,de),i),l=n.mul(c,n.sub(a,n.ONE));if(!n.eql(n.sqr(l),o))throw new Error("Cannot find square root");return l}}return r%xu,Eu(r)}var qs=(r,t)=>(V(r,t)&Y)===Y,vu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Gn(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=vu.reduce((n,o)=>(n[o]="function",n),t);return Ct(r,e)}function Au(r,t,e){if(e<nt)throw new Error("invalid exponent, negatives unsupported");if(e===nt)return r.ONE;if(e===Y)return t;let n=r.ONE,o=t;for(;e>nt;)e&Y&&(n=r.mul(n,o)),o=r.sqr(o),e>>=Y;return n}function Bu(r,t){let e=new Array(t.length),n=t.reduce((s,i,c)=>r.is0(i)?s:(e[c]=s,r.mul(s,i)),r.ONE),o=r.inv(n);return t.reduceRight((s,i,c)=>r.is0(i)?s:(e[c]=r.mul(s,e[c]),r.mul(s,i)),o),e}function Zn(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function te(r,t,e=!1,n={}){if(r<=nt)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=Zn(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:We(o),ZERO:nt,ONE:Y,create:a=>V(a,r),isValid:a=>{if(typeof a!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof a);return nt<=a&&a<r},is0:a=>a===nt,isOdd:a=>(a&Y)===Y,neg:a=>V(-a,r),eql:(a,l)=>a===l,sqr:a=>V(a*a,r),add:(a,l)=>V(a+l,r),sub:(a,l)=>V(a-l,r),mul:(a,l)=>V(a*l,r),pow:(a,l)=>Au(c,a,l),div:(a,l)=>V(a*Tr(l,r),r),sqrN:a=>a*a,addN:(a,l)=>a+l,subN:(a,l)=>a-l,mulN:(a,l)=>a*l,inv:a=>Tr(a,r),sqrt:n.sqrt||(a=>(i||(i=Su(r)),i(c,a))),invertBatch:a=>Bu(c,a),cmov:(a,l,u)=>u?l:a,toBytes:a=>e?le(a,s):Qt(a,s),fromBytes:a=>{if(a.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+a.length);return e?Jt(a):qt(a)}});return Object.freeze(c)}function Hs(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 Yn(r){let t=Hs(r);return t+Math.ceil(t/2)}function Vs(r,t,e=!1){let n=r.length,o=Hs(t),s=Yn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Jt(r):qt(r),c=V(i,t-Y)+Y;return e?le(c,o):Qt(c,o)}var zs=BigInt(0),Pr=BigInt(1);function Wn(r,t){let e=t.negate();return r?e:t}function Fs(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function jn(r,t){Fs(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1);return{windows:e,windowSize:n}}function Iu(r,t){if(!Array.isArray(r))throw new Error("array expected");r.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}function Lu(r,t){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}var $n=new WeakMap,Gs=new WeakMap;function Xn(r){return Gs.get(r)||1}function Cr(r,t){return{constTimeNegate:Wn,hasPrecomputes(e){return Xn(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>zs;)n&Pr&&(o=o.add(s)),s=s.double(),n>>=Pr;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=jn(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{windows:s,windowSize:i}=jn(e,t),c=r.ZERO,a=r.BASE,l=BigInt(2**e-1),u=2**e,f=BigInt(e);for(let p=0;p<s;p++){let x=p*i,E=Number(o&l);o>>=f,E>i&&(E-=u,o+=Pr);let b=x,h=x+Math.abs(E)-1,g=p%2!==0,S=E<0;E===0?a=a.add(Wn(g,n[b])):c=c.add(Wn(S,n[h]))}return{p:c,f:a}},wNAFUnsafe(e,n,o,s=r.ZERO){let{windows:i,windowSize:c}=jn(e,t),a=BigInt(2**e-1),l=2**e,u=BigInt(e);for(let f=0;f<i;f++){let p=f*c;if(o===zs)break;let x=Number(o&a);if(o>>=u,x>c&&(x-=l,o+=Pr),x===0)continue;let E=n[p+Math.abs(x)-1];x<0&&(E=E.negate()),s=s.add(E)}return s},getPrecomputes(e,n,o){let s=$n.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&$n.set(n,o(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){Fs(n,t),Gs.set(e,n),$n.delete(e)}}}function Rr(r,t,e,n){if(Iu(e,r),Lu(n,t),e.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=r.ZERO,s=Vn(BigInt(e.length)),i=s>12?s-3:s>4?s-2:s?2:1,c=(1<<i)-1,a=new Array(c+1).fill(o),l=Math.floor((t.BITS-1)/i)*i,u=o;for(let f=l;f>=0;f-=i){a.fill(o);for(let x=0;x<n.length;x++){let E=n[x],b=Number(E>>BigInt(f)&BigInt(c));a[b]=a[b].add(e[x])}let p=o;for(let x=a.length-1,E=o;x>0;x--)E=E.add(a[x]),p=p.add(E);if(u=u.add(p),f!==0)for(let x=0;x<i;x++)u=u.double()}return u}function je(r){return Gn(r.Fp),Ct(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Zn(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Lt=BigInt(0),Et=BigInt(1),Dr=BigInt(2),_u=BigInt(8),Tu={zip215:!0};function Pu(r){let t=je(r);return Ct(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Zs(r){let t=Pu(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:c,h:a}=t,l=Dr<<BigInt(c*8)-Et,u=e.create,f=te(t.n,t.nBitLength),p=t.uvRatio||((y,d)=>{try{return{isValid:!0,value:e.sqrt(y*e.inv(d))}}catch{return{isValid:!1,value:Lt}}}),x=t.adjustScalarBytes||(y=>y),E=t.domain||((y,d,w)=>{if(It("phflag",w),d.length||w)throw new Error("Contexts/pre-hash are not supported");return y});function b(y,d){wt("coordinate "+y,d,Lt,l)}function h(y){if(!(y instanceof m))throw new Error("ExtendedPoint expected")}let g=he((y,d)=>{let{ex:w,ey:A,ez:R}=y,D=y.is0();d==null&&(d=D?_u:e.inv(R));let K=u(w*d),M=u(A*d),N=u(R*d);if(D)return{x:Lt,y:Et};if(N!==Et)throw new Error("invZ was invalid");return{x:K,y:M}}),S=he(y=>{let{a:d,d:w}=t;if(y.is0())throw new Error("bad point: ZERO");let{ex:A,ey:R,ez:D,et:K}=y,M=u(A*A),N=u(R*R),H=u(D*D),z=u(H*H),ot=u(M*d),st=u(H*u(ot+N)),at=u(z+u(w*u(M*N)));if(st!==at)throw new Error("bad point: equation left != right (1)");let ct=u(A*R),bt=u(D*K);if(ct!==bt)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(d,w,A,R){this.ex=d,this.ey=w,this.ez=A,this.et=R,b("x",d),b("y",w),b("z",A),b("t",R),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(d){if(d instanceof m)throw new Error("extended point not allowed");let{x:w,y:A}=d||{};return b("x",w),b("y",A),new m(w,A,Et,u(w*A))}static normalizeZ(d){let w=e.invertBatch(d.map(A=>A.ez));return d.map((A,R)=>A.toAffine(w[R])).map(m.fromAffine)}static msm(d,w){return Rr(m,f,d,w)}_setWindowSize(d){C.setWindowSize(this,d)}assertValidity(){S(this)}equals(d){h(d);let{ex:w,ey:A,ez:R}=this,{ex:D,ey:K,ez:M}=d,N=u(w*M),H=u(D*R),z=u(A*M),ot=u(K*R);return N===H&&z===ot}is0(){return this.equals(m.ZERO)}negate(){return new m(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:d}=t,{ex:w,ey:A,ez:R}=this,D=u(w*w),K=u(A*A),M=u(Dr*u(R*R)),N=u(d*D),H=w+A,z=u(u(H*H)-D-K),ot=N+K,st=ot-M,at=N-K,ct=u(z*st),bt=u(ot*at),pt=u(z*at),Pt=u(st*ot);return new m(ct,bt,Pt,pt)}add(d){h(d);let{a:w,d:A}=t,{ex:R,ey:D,ez:K,et:M}=this,{ex:N,ey:H,ez:z,et:ot}=d;if(w===BigInt(-1)){let Wo=u((D-R)*(H+N)),jo=u((D+R)*(H-N)),sn=u(jo-Wo);if(sn===Lt)return this.double();let $o=u(K*Dr*ot),Xo=u(M*Dr*z),Jo=Xo+$o,Qo=jo+Wo,ts=Xo-$o,oa=u(Jo*sn),sa=u(Qo*ts),ia=u(Jo*ts),aa=u(sn*Qo);return new m(oa,sa,aa,ia)}let st=u(R*N),at=u(D*H),ct=u(M*A*ot),bt=u(K*z),pt=u((R+D)*(N+H)-st-at),Pt=bt-ct,Dt=bt+ct,Me=u(at-w*st),ta=u(pt*Pt),ea=u(Dt*Me),ra=u(pt*Me),na=u(Pt*Dt);return new m(ta,ea,na,ra)}subtract(d){return this.add(d.negate())}wNAF(d){return C.wNAFCached(this,d,m.normalizeZ)}multiply(d){let w=d;wt("scalar",w,Et,n);let{p:A,f:R}=this.wNAF(w);return m.normalizeZ([A,R])[0]}multiplyUnsafe(d,w=m.ZERO){let A=d;return wt("scalar",A,Lt,n),A===Lt?P:this.is0()||A===Et?this:C.wNAFCachedUnsafe(this,A,m.normalizeZ,w)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}isTorsionFree(){return C.unsafeLadder(this,n).is0()}toAffine(d){return g(this,d)}clearCofactor(){let{h:d}=t;return d===Et?this:this.multiplyUnsafe(d)}static fromHex(d,w=!1){let{d:A,a:R}=t,D=e.BYTES;d=X("pointHex",d,D),It("zip215",w);let K=d.slice(),M=d[D-1];K[D-1]=M&-129;let N=Jt(K),H=w?l:e.ORDER;wt("pointHex.y",N,Lt,H);let z=u(N*N),ot=u(z-Et),st=u(A*z-R),{isValid:at,value:ct}=p(ot,st);if(!at)throw new Error("Point.fromHex: invalid y coordinate");let bt=(ct&Et)===Et,pt=(M&128)!==0;if(!w&&ct===Lt&&pt)throw new Error("Point.fromHex: x=0 and x_0=1");return pt!==bt&&(ct=u(-ct)),m.fromAffine({x:ct,y:N})}static fromPrivateKey(d){return L(d).point}toRawBytes(){let{x:d,y:w}=this.toAffine(),A=le(w,e.BYTES);return A[A.length-1]|=d&Et?128:0,A}toHex(){return kt(this.toRawBytes())}}m.BASE=new m(t.Gx,t.Gy,Et,u(t.Gx*t.Gy)),m.ZERO=new m(Lt,Et,Et,Lt);let{BASE:B,ZERO:P}=m,C=Cr(m,c*8);function I(y){return V(y,n)}function T(y){return I(Jt(y))}function L(y){let d=e.BYTES;y=X("private key",y,d);let w=X("hashed private key",s(y),2*d),A=x(w.slice(0,d)),R=w.slice(d,2*d),D=T(A),K=B.multiply(D),M=K.toRawBytes();return{head:A,prefix:R,scalar:D,point:K,pointBytes:M}}function Z(y){return L(y).pointBytes}function k(y=new Uint8Array,...d){let w=Ht(...d);return T(s(E(w,X("context",y),!!o)))}function O(y,d,w={}){y=X("message",y),o&&(y=o(y));let{prefix:A,scalar:R,pointBytes:D}=L(d),K=k(w.context,A,y),M=B.multiply(K).toRawBytes(),N=k(w.context,M,D,y),H=I(K+N*R);wt("signature.s",H,Lt,n);let z=Ht(M,le(H,e.BYTES));return X("result",z,e.BYTES*2)}let et=Tu;function v(y,d,w,A=et){let{context:R,zip215:D}=A,K=e.BYTES;y=X("signature",y,2*K),d=X("message",d),w=X("publicKey",w,K),D!==void 0&&It("zip215",D),o&&(d=o(d));let M=Jt(y.slice(K,2*K)),N,H,z;try{N=m.fromHex(w,D),H=m.fromHex(y.slice(0,K),D),z=B.multiplyUnsafe(M)}catch{return!1}if(!D&&N.isSmallOrder())return!1;let ot=k(R,H.toRawBytes(),N.toRawBytes(),d);return H.add(N.multiplyUnsafe(ot)).subtract(z).clearCofactor().equals(m.ZERO)}return B._setWindowSize(8),{CURVE:t,getPublicKey:Z,sign:O,verify:v,ExtendedPoint:m,utils:{getExtendedPublicKey:L,randomPrivateKey:()=>i(e.BYTES),precompute(y=8,d=m.BASE){return d._setWindowSize(y),d.multiply(BigInt(3)),d}}}}var Jn=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Ys=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Vh=BigInt(0),Cu=BigInt(1),Ws=BigInt(2),zh=BigInt(3),Ru=BigInt(5),Du=BigInt(8);function Nu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=Jn,c=r*r%s*r%s,a=W(c,Ws,s)*c%s,l=W(a,Cu,s)*r%s,u=W(l,Ru,s)*l%s,f=W(u,t,s)*u%s,p=W(f,e,s)*f%s,x=W(p,n,s)*p%s,E=W(x,o,s)*x%s,b=W(E,o,s)*x%s,h=W(b,t,s)*u%s;return{pow_p_5_8:W(h,Ws,s)*r%s,b2:c}}function Uu(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Ku(r,t){let e=Jn,n=V(t*t*t,e),o=V(n*n*t,e),s=Nu(r*o).pow_p_5_8,i=V(r*n*s,e),c=V(t*i*i,e),a=i,l=V(i*Ys,e),u=c===r,f=c===V(-r,e),p=c===V(-r*Ys,e);return u&&(i=a),(f||p)&&(i=l),qs(i,e)&&(i=V(-i,e)),{isValid:u||f,value:i}}var Ou=te(Jn,void 0,!0),Mu={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Ou,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Du,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Us,randomBytes:Pe,adjustScalarBytes:Uu,uvRatio:Ku},js=Zs(Mu);var Nr=32;function $s(r,t,e){return js.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var Ur=class{type="Ed25519";raw;constructor(t){this.raw=Qn(t,Nr)}toMultihash(){return At.digest(Ot(this))}toCID(){return ft.createV1(114,this.toMultihash())}toString(){return $.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:gt(this.raw,t.raw)}verify(t,e){return $s(this.raw,e,t)}};function to(r){return r=Qn(r,Nr),new Ur(r)}function Qn(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new j(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var qu=Math.pow(2,7),Hu=Math.pow(2,14),Vu=Math.pow(2,21),eo=Math.pow(2,28),ro=Math.pow(2,35),no=Math.pow(2,42),oo=Math.pow(2,49),q=128,lt=127;function _t(r){if(r<qu)return 1;if(r<Hu)return 2;if(r<Vu)return 3;if(r<eo)return 4;if(r<ro)return 5;if(r<no)return 6;if(r<oo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function so(r,t,e=0){switch(_t(r)){case 8:t[e++]=r&255|q,r/=128;case 7:t[e++]=r&255|q,r/=128;case 6:t[e++]=r&255|q,r/=128;case 5:t[e++]=r&255|q,r/=128;case 4:t[e++]=r&255|q,r>>>=7;case 3:t[e++]=r&255|q,r>>>=7;case 2:t[e++]=r&255|q,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function zu(r,t,e=0){switch(_t(r)){case 8:t.set(e++,r&255|q),r/=128;case 7:t.set(e++,r&255|q),r/=128;case 6:t.set(e++,r&255|q),r/=128;case 5:t.set(e++,r&255|q),r/=128;case 4:t.set(e++,r&255|q),r>>>=7;case 3:t.set(e++,r&255|q),r>>>=7;case 2:t.set(e++,r&255|q),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function io(r,t){let e=r[t],n=0;if(n+=e<,e<q||(e=r[t+1],n+=(e<)<<7,e<q)||(e=r[t+2],n+=(e<)<<14,e<q)||(e=r[t+3],n+=(e<)<<21,e<q)||(e=r[t+4],n+=(e<)*eo,e<q)||(e=r[t+5],n+=(e<)*ro,e<q)||(e=r[t+6],n+=(e<)*no,e<q)||(e=r[t+7],n+=(e<)*oo,e<q))return n;throw new RangeError("Could not decode varint")}function Fu(r,t){let e=r.get(t),n=0;if(n+=e<,e<q||(e=r.get(t+1),n+=(e<)<<7,e<q)||(e=r.get(t+2),n+=(e<)<<14,e<q)||(e=r.get(t+3),n+=(e<)<<21,e<q)||(e=r.get(t+4),n+=(e<)*eo,e<q)||(e=r.get(t+5),n+=(e<)*ro,e<q)||(e=r.get(t+6),n+=(e<)*no,e<q)||(e=r.get(t+7),n+=(e<)*oo,e<q))return n;throw new RangeError("Could not decode varint")}function Js(r,t,e=0){return t==null&&(t=ut(_t(r))),t instanceof Uint8Array?so(r,t,e):zu(r,t,e)}function Qs(r,t=0){return r instanceof Uint8Array?io(r,t):Fu(r,t)}var ao=new Float32Array([-0]),ee=new Uint8Array(ao.buffer);function ei(r,t,e){ao[0]=r,t[e]=ee[0],t[e+1]=ee[1],t[e+2]=ee[2],t[e+3]=ee[3]}function ri(r,t){return ee[0]=r[t],ee[1]=r[t+1],ee[2]=r[t+2],ee[3]=r[t+3],ao[0]}var co=new Float64Array([-0]),ht=new Uint8Array(co.buffer);function ni(r,t,e){co[0]=r,t[e]=ht[0],t[e+1]=ht[1],t[e+2]=ht[2],t[e+3]=ht[3],t[e+4]=ht[4],t[e+5]=ht[5],t[e+6]=ht[6],t[e+7]=ht[7]}function oi(r,t){return ht[0]=r[t],ht[1]=r[t+1],ht[2]=r[t+2],ht[3]=r[t+3],ht[4]=r[t+4],ht[5]=r[t+5],ht[6]=r[t+6],ht[7]=r[t+7],co[0]}var Gu=BigInt(Number.MAX_SAFE_INTEGER),Zu=BigInt(Number.MIN_SAFE_INTEGER),St=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 pe;if(t<Gu&&t>Zu)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>si&&(o=0n,++n>si&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return pe;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):pe}},pe=new St(0,0);pe.toBigInt=function(){return 0n};pe.zzEncode=pe.zzDecode=function(){return this};pe.length=function(){return 1};var si=4294967296n;function ii(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 ai(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 uo(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 Tt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Kr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var fo=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,Tt(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 Tt(this,4);return Kr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Tt(this,4);return Kr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Tt(this,4);let t=ri(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Tt(this,4);let t=oi(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 Tt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return ai(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Tt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Tt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new St(0,0),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 Tt(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 Tt(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 Tt(this,8);let t=Kr(this.buf,this.pos+=4),e=Kr(this.buf,this.pos+=4);return new St(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=io(this.buf,this.pos);return this.pos+=_t(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 lo(r){return new fo(r instanceof Uint8Array?r:r.subarray())}function Or(r,t,e){let n=lo(r);return t.decode(n,void 0,e)}function ho(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return ut(i);o+i>t&&(n=ut(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var me=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function po(){}var yo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Yu=ho();function Wu(r){return globalThis.Buffer!=null?ut(r):Yu(r)}var Xe=class{len;head;tail;states;constructor(){this.len=0,this.head=new me(po,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new me(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new bo((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(Mr,10,St.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=St.fromBigInt(t);return this._push(Mr,e.length(),e)}uint64Number(t){return this._push(so,_t(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=St.fromBigInt(t).zzEncode();return this._push(Mr,e.length(),e)}sint64Number(t){let e=St.fromNumber(t).zzEncode();return this._push(Mr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(mo,1,t?1:0)}fixed32(t){return this._push($e,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=St.fromBigInt(t);return this._push($e,4,e.lo)._push($e,4,e.hi)}fixed64Number(t){let e=St.fromNumber(t);return this._push($e,4,e.lo)._push($e,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(ei,4,t)}double(t){return this._push(ni,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(mo,1,0):this.uint32(e)._push($u,e,t)}string(t){let e=ii(t);return e!==0?this.uint32(e)._push(uo,e,t):this._push(mo,1,0)}fork(){return this.states=new yo(this),this.head=this.tail=new me(po,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 me(po,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=Wu(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function mo(r,t,e){t[e]=r&255}function ju(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var bo=class extends me{next;constructor(t,e){super(ju,t,e),this.next=void 0}};function Mr(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 $e(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 $u(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(Xu,t,r),this},Xe.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Ju,t,r),this});function Xu(r,t,e){t.set(r,e)}function Ju(r,t,e){r.length<40?uo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(F(r),e)}function go(){return new Xe}function kr(r,t){let e=go();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var De;(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"})(De||(De={}));function qr(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 c=t(s);i.int32(c)},n=function(s){let i=s.int32();return t(i)};return qr("enum",De.VARINT,e,n)}function Hr(r,t){return qr("message",De.LENGTH_DELIMITED,r,t)}var tt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(tt||(tt={}));var wo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(wo||(wo={}));(function(r){r.codec=()=>xo(wo)})(tt||(tt={}));var Rt;(function(r){let t;r.codec=()=>(t==null&&(t=Hr((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=>kr(e,r.codec()),r.decode=(e,n)=>Or(e,r.codec(),n)})(Rt||(Rt={}));var Eo;(function(r){let t;r.codec=()=>(t==null&&(t=Hr((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=>kr(e,r.codec()),r.decode=(e,n)=>Or(e,r.codec(),n)})(Eo||(Eo={}));function Vr(r){if(isNaN(r)||r<=0)throw new j("random bytes length must be a Number bigger than 0");return Pe(r)}var Je=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},zr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var fi={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new zr("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 re=fi;var tr={};mt(tr,{MAX_RSA_KEY_SIZE:()=>vo,generateRSAKeyPair:()=>mi,jwkToJWKKeyPair:()=>yi,jwkToPkcs1:()=>nf,jwkToPkix:()=>Lo,jwkToRSAPrivateKey:()=>pi,pkcs1MessageToJwk:()=>Bo,pkcs1MessageToRSAPrivateKey:()=>_o,pkcs1ToJwk:()=>rf,pkcs1ToRSAPrivateKey:()=>di,pkixMessageToJwk:()=>Io,pkixMessageToRSAPublicKey:()=>Po,pkixToJwk:()=>of,pkixToRSAPublicKey:()=>To});var Qu=new Uint32Array([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]),ne=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),oe=new Uint32Array(64),So=class extends Ce{constructor(){super(64,32,8,!1),this.A=ne[0]|0,this.B=ne[1]|0,this.C=ne[2]|0,this.D=ne[3]|0,this.E=ne[4]|0,this.F=ne[5]|0,this.G=ne[6]|0,this.H=ne[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)oe[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let p=oe[f-15],x=oe[f-2],E=Bt(p,7)^Bt(p,18)^p>>>3,b=Bt(x,17)^Bt(x,19)^x>>>10;oe[f]=b+oe[f-7]+E+oe[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 p=Bt(c,6)^Bt(c,11)^Bt(c,25),x=u+p+Rs(c,a,l)+Qu[f]+oe[f]|0,b=(Bt(n,2)^Bt(n,13)^Bt(n,22))+Ds(n,o,s)|0;u=l,l=a,a=c,c=i+x|0,i=s,s=o,o=n,n=x+b|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(){oe.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Ne=Ar(()=>new So);var Ue=class{type="RSA";_key;_raw;_multihash;constructor(t,e){this._key=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=tr.jwkToPkix(this._key)),this._raw}toMultihash(){return this._multihash}toCID(){return ft.createV1(114,this._multihash)}toString(){return $.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:gt(this.raw,t.raw)}verify(t,e){return hi(this._key,e,t)}},Qe=class{type="RSA";_key;_raw;publicKey;constructor(t,e){this._key=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=tr.jwkToPkcs1(this._key)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:gt(this.raw,t.raw)}sign(t){return li(this._key,t)}};var vo=8192,Ao=18,tf=1062,ef=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function rf(r){let t=Kt(r);return Bo(t)}function Bo(r){return{n:G(r[1],"base64url"),e:G(r[2],"base64url"),d:G(r[3],"base64url"),p:G(r[4],"base64url"),q:G(r[5],"base64url"),dp:G(r[6],"base64url"),dq:G(r[7],"base64url"),qi:G(r[8],"base64url"),kty:"RSA"}}function nf(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 j("JWK was missing components");return Wt([xt(Uint8Array.from([0])),xt(F(r.n,"base64url")),xt(F(r.e,"base64url")),xt(F(r.d,"base64url")),xt(F(r.p,"base64url")),xt(F(r.q,"base64url")),xt(F(r.dp,"base64url")),xt(F(r.dq,"base64url")),xt(F(r.qi,"base64url"))]).subarray()}function of(r){let t=Kt(r,{offset:0});return Io(t)}function Io(r){let t=Kt(r[1],{offset:0});return{kty:"RSA",n:G(t[0],"base64url"),e:G(t[1],"base64url")}}function Lo(r){if(r.n==null||r.e==null)throw new j("JWK was missing components");return Wt([ef,Sr(Wt([xt(F(r.n,"base64url")),xt(F(r.e,"base64url"))]))]).subarray()}function di(r){let t=Kt(r);return _o(t)}function _o(r){let t=Bo(r);return pi(t)}function To(r,t){if(r.byteLength>=tf)throw new xe("Key size is too large");let e=Kt(r,{offset:0});return Po(e,r,t)}function Po(r,t,e){let n=Io(r);if(e==null){let o=Ne(Rt.encode({Type:tt.RSA,Data:t}));e=vt(Ao,o)}return new Ue(n,e)}function pi(r){if(gi(r)>vo)throw new j("Key size is too large");let t=yi(r),e=Ne(Rt.encode({Type:tt.RSA,Data:Lo(t.publicKey)})),n=vt(Ao,e);return new Qe(t.privateKey,new Ue(t.publicKey,n))}async function mi(r){if(r>vo)throw new j("Key size is too large");let t=await bi(r),e=Ne(Rt.encode({Type:tt.RSA,Data:Lo(t.publicKey)})),n=vt(Ao,e);return new Qe(t.privateKey,new Ue(t.publicKey,n))}function yi(r){if(r==null)throw new j("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function bi(r){let t=await re.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),e=await sf(t);return{privateKey:e[0],publicKey:e[1]}}async function li(r,t){let e=await re.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await re.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function hi(r,t,e){let n=await re.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return re.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function sf(r){if(r.privateKey==null||r.publicKey==null)throw new j("Private and public key are required");return Promise.all([re.get().subtle.exportKey("jwk",r.privateKey),re.get().subtle.exportKey("jwk",r.publicKey)])}function gi(r){if(r.kty!=="RSA")throw new j("invalid key type");if(r.n==null)throw new j("invalid key modulus");return F(r.n,"base64url").length*8}var Fr=class extends Te{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Ts(t);let n=Ze(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),s.fill(0)}update(t){return _e(this),this.iHash.update(t),this}digestInto(t){_e(this),Le(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}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Co=(r,t,e)=>new Fr(r,t).update(e).digest();Co.create=(r,t)=>new Fr(r,t);function xi(r){r.lowS!==void 0&&It("lowS",r.lowS),r.prehash!==void 0&&It("prehash",r.prehash)}function af(r){let t=je(r);Ct(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:o}=t;if(e){if(!n.eql(o,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:cf,hexToBytes:uf}=_r,Ro=class extends Error{constructor(t=""){super(t)}},Vt={Err:Ro,_tlv:{encode:(r,t)=>{let{Err:e}=Vt;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=ue(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?ue(o.length/2|128):"";return ue(r)+s+o+t},decode(r,t){let{Err:e}=Vt,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}=Vt;if(r<zt)throw new t("integer: negative integers are not allowed");let e=ue(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}=Vt;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 cf(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Vt,o=typeof r=="string"?uf(r):r;Re(o);let{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}=Vt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},zt=BigInt(0),it=BigInt(1),Ep=BigInt(2),wi=BigInt(3),Sp=BigInt(4);function ff(r){let t=af(r),{Fp:e}=t,n=te(t.n,t.nBitLength),o=t.toBytes||((b,h,g)=>{let S=h.toAffine();return Ht(Uint8Array.from([4]),e.toBytes(S.x),e.toBytes(S.y))}),s=t.fromBytes||(b=>{let h=b.subarray(1),g=e.fromBytes(h.subarray(0,e.BYTES)),S=e.fromBytes(h.subarray(e.BYTES,2*e.BYTES));return{x:g,y:S}});function i(b){let{a:h,b:g}=t,S=e.sqr(b),m=e.mul(S,b);return e.add(e.add(m,e.mul(b,h)),g)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function c(b){return Ye(b,it,t.n)}function a(b){let{allowedPrivateKeyLengths:h,nByteLength:g,wrapPrivateKey:S,n:m}=t;if(h&&typeof b!="bigint"){if(Xt(b)&&(b=kt(b)),typeof b!="string"||!h.includes(b.length))throw new Error("invalid private key");b=b.padStart(g*2,"0")}let B;try{B=typeof b=="bigint"?b:qt(X("private key",b,g))}catch{throw new Error("invalid private key, expected hex or "+g+" bytes, got "+typeof b)}return S&&(B=V(B,m)),wt("private key",B,it,m),B}function l(b){if(!(b instanceof p))throw new Error("ProjectivePoint expected")}let u=he((b,h)=>{let{px:g,py:S,pz:m}=b;if(e.eql(m,e.ONE))return{x:g,y:S};let B=b.is0();h==null&&(h=B?e.ONE:e.inv(m));let P=e.mul(g,h),C=e.mul(S,h),I=e.mul(m,h);if(B)return{x:e.ZERO,y:e.ZERO};if(!e.eql(I,e.ONE))throw new Error("invZ was invalid");return{x:P,y:C}}),f=he(b=>{if(b.is0()){if(t.allowInfinityPoint&&!e.is0(b.py))return;throw new Error("bad point: ZERO")}let{x:h,y:g}=b.toAffine();if(!e.isValid(h)||!e.isValid(g))throw new Error("bad point: x or y not FE");let S=e.sqr(g),m=i(h);if(!e.eql(S,m))throw new Error("bad point: equation left != right");if(!b.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class p{constructor(h,g,S){if(this.px=h,this.py=g,this.pz=S,h==null||!e.isValid(h))throw new Error("x required");if(g==null||!e.isValid(g))throw new Error("y required");if(S==null||!e.isValid(S))throw new Error("z required");Object.freeze(this)}static fromAffine(h){let{x:g,y:S}=h||{};if(!h||!e.isValid(g)||!e.isValid(S))throw new Error("invalid affine point");if(h instanceof p)throw new Error("projective point not allowed");let m=B=>e.eql(B,e.ZERO);return m(g)&&m(S)?p.ZERO:new p(g,S,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let g=e.invertBatch(h.map(S=>S.pz));return h.map((S,m)=>S.toAffine(g[m])).map(p.fromAffine)}static fromHex(h){let g=p.fromAffine(s(X("pointHex",h)));return g.assertValidity(),g}static fromPrivateKey(h){return p.BASE.multiply(a(h))}static msm(h,g){return Rr(p,n,h,g)}_setWindowSize(h){E.setWindowSize(this,h)}assertValidity(){f(this)}hasEvenY(){let{y:h}=this.toAffine();if(e.isOdd)return!e.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){l(h);let{px:g,py:S,pz:m}=this,{px:B,py:P,pz:C}=h,I=e.eql(e.mul(g,C),e.mul(B,m)),T=e.eql(e.mul(S,C),e.mul(P,m));return I&&T}negate(){return new p(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b:g}=t,S=e.mul(g,wi),{px:m,py:B,pz:P}=this,C=e.ZERO,I=e.ZERO,T=e.ZERO,L=e.mul(m,m),Z=e.mul(B,B),k=e.mul(P,P),O=e.mul(m,B);return O=e.add(O,O),T=e.mul(m,P),T=e.add(T,T),C=e.mul(h,T),I=e.mul(S,k),I=e.add(C,I),C=e.sub(Z,I),I=e.add(Z,I),I=e.mul(C,I),C=e.mul(O,C),T=e.mul(S,T),k=e.mul(h,k),O=e.sub(L,k),O=e.mul(h,O),O=e.add(O,T),T=e.add(L,L),L=e.add(T,L),L=e.add(L,k),L=e.mul(L,O),I=e.add(I,L),k=e.mul(B,P),k=e.add(k,k),L=e.mul(k,O),C=e.sub(C,L),T=e.mul(k,Z),T=e.add(T,T),T=e.add(T,T),new p(C,I,T)}add(h){l(h);let{px:g,py:S,pz:m}=this,{px:B,py:P,pz:C}=h,I=e.ZERO,T=e.ZERO,L=e.ZERO,Z=t.a,k=e.mul(t.b,wi),O=e.mul(g,B),et=e.mul(S,P),v=e.mul(m,C),_=e.add(g,S),y=e.add(B,P);_=e.mul(_,y),y=e.add(O,et),_=e.sub(_,y),y=e.add(g,m);let d=e.add(B,C);return y=e.mul(y,d),d=e.add(O,v),y=e.sub(y,d),d=e.add(S,m),I=e.add(P,C),d=e.mul(d,I),I=e.add(et,v),d=e.sub(d,I),L=e.mul(Z,y),I=e.mul(k,v),L=e.add(I,L),I=e.sub(et,L),L=e.add(et,L),T=e.mul(I,L),et=e.add(O,O),et=e.add(et,O),v=e.mul(Z,v),y=e.mul(k,y),et=e.add(et,v),v=e.sub(O,v),v=e.mul(Z,v),y=e.add(y,v),O=e.mul(et,y),T=e.add(T,O),O=e.mul(d,y),I=e.mul(_,I),I=e.sub(I,O),O=e.mul(_,et),L=e.mul(d,L),L=e.add(L,O),new p(I,T,L)}subtract(h){return this.add(h.negate())}is0(){return this.equals(p.ZERO)}wNAF(h){return E.wNAFCached(this,h,p.normalizeZ)}multiplyUnsafe(h){let{endo:g,n:S}=t;wt("scalar",h,zt,S);let m=p.ZERO;if(h===zt)return m;if(this.is0()||h===it)return this;if(!g||E.hasPrecomputes(this))return E.wNAFCachedUnsafe(this,h,p.normalizeZ);let{k1neg:B,k1:P,k2neg:C,k2:I}=g.splitScalar(h),T=m,L=m,Z=this;for(;P>zt||I>zt;)P&it&&(T=T.add(Z)),I&it&&(L=L.add(Z)),Z=Z.double(),P>>=it,I>>=it;return B&&(T=T.negate()),C&&(L=L.negate()),L=new p(e.mul(L.px,g.beta),L.py,L.pz),T.add(L)}multiply(h){let{endo:g,n:S}=t;wt("scalar",h,it,S);let m,B;if(g){let{k1neg:P,k1:C,k2neg:I,k2:T}=g.splitScalar(h),{p:L,f:Z}=this.wNAF(C),{p:k,f:O}=this.wNAF(T);L=E.constTimeNegate(P,L),k=E.constTimeNegate(I,k),k=new p(e.mul(k.px,g.beta),k.py,k.pz),m=L.add(k),B=Z.add(O)}else{let{p:P,f:C}=this.wNAF(h);m=P,B=C}return p.normalizeZ([m,B])[0]}multiplyAndAddUnsafe(h,g,S){let m=p.BASE,B=(C,I)=>I===zt||I===it||!C.equals(m)?C.multiplyUnsafe(I):C.multiply(I),P=B(this,g).add(B(h,S));return P.is0()?void 0:P}toAffine(h){return u(this,h)}isTorsionFree(){let{h,isTorsionFree:g}=t;if(h===it)return!0;if(g)return g(p,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:g}=t;return h===it?this:g?g(p,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return It("isCompressed",h),this.assertValidity(),o(p,this,h)}toHex(h=!0){return It("isCompressed",h),kt(this.toRawBytes(h))}}p.BASE=new p(t.Gx,t.Gy,e.ONE),p.ZERO=new p(e.ZERO,e.ONE,e.ZERO);let x=t.nBitLength,E=Cr(p,t.endo?Math.ceil(x/2):x);return{CURVE:t,ProjectivePoint:p,normPrivateKeyToScalar:a,weierstrassEquation:i,isWithinCurveOrder:c}}function lf(r){let t=je(r);return Ct(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Ei(r){let t=lf(r),{Fp:e,n}=t,o=e.BYTES+1,s=2*e.BYTES+1;function i(v){return V(v,n)}function c(v){return Tr(v,n)}let{ProjectivePoint:a,normPrivateKeyToScalar:l,weierstrassEquation:u,isWithinCurveOrder:f}=ff({...t,toBytes(v,_,y){let d=_.toAffine(),w=e.toBytes(d.x),A=Ht;return It("isCompressed",y),y?A(Uint8Array.from([_.hasEvenY()?2:3]),w):A(Uint8Array.from([4]),w,e.toBytes(d.y))},fromBytes(v){let _=v.length,y=v[0],d=v.subarray(1);if(_===o&&(y===2||y===3)){let w=qt(d);if(!Ye(w,it,e.ORDER))throw new Error("Point is not on curve");let A=u(w),R;try{R=e.sqrt(A)}catch(M){let N=M instanceof Error?": "+M.message:"";throw new Error("Point is not on curve"+N)}let D=(R&it)===it;return(y&1)===1!==D&&(R=e.neg(R)),{x:w,y:R}}else if(_===s&&y===4){let w=e.fromBytes(d.subarray(0,e.BYTES)),A=e.fromBytes(d.subarray(e.BYTES,2*e.BYTES));return{x:w,y:A}}else{let w=o,A=s;throw new Error("invalid Point, expected length of "+w+", or uncompressed "+A+", got "+_)}}}),p=v=>kt(Qt(v,t.nByteLength));function x(v){let _=n>>it;return v>_}function E(v){return x(v)?i(-v):v}let b=(v,_,y)=>qt(v.slice(_,y));class h{constructor(_,y,d){this.r=_,this.s=y,this.recovery=d,this.assertValidity()}static fromCompact(_){let y=t.nByteLength;return _=X("compactSignature",_,y*2),new h(b(_,0,y),b(_,y,2*y))}static fromDER(_){let{r:y,s:d}=Vt.toSig(X("DER",_));return new h(y,d)}assertValidity(){wt("r",this.r,it,n),wt("s",this.s,it,n)}addRecoveryBit(_){return new h(this.r,this.s,_)}recoverPublicKey(_){let{r:y,s:d,recovery:w}=this,A=C(X("msgHash",_));if(w==null||![0,1,2,3].includes(w))throw new Error("recovery id invalid");let R=w===2||w===3?y+t.n:y;if(R>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let D=(w&1)===0?"02":"03",K=a.fromHex(D+p(R)),M=c(R),N=i(-A*M),H=i(d*M),z=a.BASE.multiplyAndAddUnsafe(K,N,H);if(!z)throw new Error("point at infinify");return z.assertValidity(),z}hasHighS(){return x(this.s)}normalizeS(){return this.hasHighS()?new h(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return fe(this.toDERHex())}toDERHex(){return Vt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return fe(this.toCompactHex())}toCompactHex(){return p(this.r)+p(this.s)}}let g={isValidPrivateKey(v){try{return l(v),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let v=Yn(t.n);return Vs(t.randomBytes(v),t.n)},precompute(v=8,_=a.BASE){return _._setWindowSize(v),_.multiply(BigInt(3)),_}};function S(v,_=!0){return a.fromPrivateKey(v).toRawBytes(_)}function m(v){let _=Xt(v),y=typeof v=="string",d=(_||y)&&v.length;return _?d===o||d===s:y?d===2*o||d===2*s:v instanceof a}function B(v,_,y=!0){if(m(v))throw new Error("first arg must be private key");if(!m(_))throw new Error("second arg must be public key");return a.fromHex(_).multiply(l(v)).toRawBytes(y)}let P=t.bits2int||function(v){if(v.length>8192)throw new Error("input is too large");let _=qt(v),y=v.length*8-t.nBitLength;return y>0?_>>BigInt(y):_},C=t.bits2int_modN||function(v){return i(P(v))},I=We(t.nBitLength);function T(v){return wt("num < 2^"+t.nBitLength,v,zt,I),Qt(v,t.nByteLength)}function L(v,_,y=Z){if(["recovered","canonical"].some(st=>st in y))throw new Error("sign() legacy options not supported");let{hash:d,randomBytes:w}=t,{lowS:A,prehash:R,extraEntropy:D}=y;A==null&&(A=!0),v=X("msgHash",v),xi(y),R&&(v=X("prehashed msgHash",d(v)));let K=C(v),M=l(_),N=[T(M),T(K)];if(D!=null&&D!==!1){let st=D===!0?w(e.BYTES):D;N.push(X("extraEntropy",st))}let H=Ht(...N),z=K;function ot(st){let at=P(st);if(!f(at))return;let ct=c(at),bt=a.BASE.multiply(at).toAffine(),pt=i(bt.x);if(pt===zt)return;let Pt=i(ct*i(z+pt*M));if(Pt===zt)return;let Dt=(bt.x===pt?0:2)|Number(bt.y&it),Me=Pt;return A&&x(Pt)&&(Me=E(Pt),Dt^=1),new h(pt,Me,Dt)}return{seed:H,k2sig:ot}}let Z={lowS:t.lowS,prehash:!1},k={lowS:t.lowS,prehash:!1};function O(v,_,y=Z){let{seed:d,k2sig:w}=L(v,_,y),A=t;return zn(A.hash.outputLen,A.nByteLength,A.hmac)(d,w)}a.BASE._setWindowSize(8);function et(v,_,y,d=k){let w=v;_=X("msgHash",_),y=X("publicKey",y);let{lowS:A,prehash:R,format:D}=d;if(xi(d),"strict"in d)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 w=="string"||Xt(w),M=!K&&!D&&typeof w=="object"&&w!==null&&typeof w.r=="bigint"&&typeof w.s=="bigint";if(!K&&!M)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let N,H;try{if(M&&(N=new h(w.r,w.s)),K){try{D!=="compact"&&(N=h.fromDER(w))}catch(Dt){if(!(Dt instanceof Vt.Err))throw Dt}!N&&D!=="der"&&(N=h.fromCompact(w))}H=a.fromHex(y)}catch{return!1}if(!N||A&&N.hasHighS())return!1;R&&(_=t.hash(_));let{r:z,s:ot}=N,st=C(_),at=c(ot),ct=i(st*at),bt=i(z*at),pt=a.BASE.multiplyAndAddUnsafe(H,ct,bt)?.toAffine();return pt?i(pt.x)===z:!1}return{CURVE:t,getPublicKey:S,getSharedSecret:B,sign:O,verify:et,ProjectivePoint:a,Signature:h,utils:g}}function hf(r){return{hash:r,hmac:(t,...e)=>Co(r,t,Kn(...e)),randomBytes:Pe}}function Si(r,t){let e=n=>Ei({...r,...hf(n)});return{...e(t),create:e}}var Bi=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),vi=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),df=BigInt(1),Do=BigInt(2),Ai=(r,t)=>(r+t/Do)/t;function pf(r){let t=Bi,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=W(u,e,t)*u%t,p=W(f,e,t)*u%t,x=W(p,Do,t)*l%t,E=W(x,o,t)*x%t,b=W(E,s,t)*E%t,h=W(b,c,t)*b%t,g=W(h,a,t)*h%t,S=W(g,c,t)*b%t,m=W(S,e,t)*u%t,B=W(m,i,t)*E%t,P=W(B,n,t)*l%t,C=W(P,Do,t);if(!No.eql(No.sqr(C),r))throw new Error("Cannot find square root");return C}var No=te(Bi,void 0,void 0,{sqrt:pf}),ye=Si({a:BigInt(0),b:BigInt(7),Fp:No,n:vi,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=vi,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-df*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),c=Ai(s*r,t),a=Ai(-n*r,t),l=V(r-c*e-a*o,t),u=V(-c*n-a*s,t),f=l>i,p=u>i;if(f&&(l=t-l),p&&(u=t-u),l>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:l,k2neg:p,k2:u}}}},Ne),Cp=BigInt(0);var Rp=ye.ProjectivePoint;function Ii(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Li(r,t,e){let n=ae.digest(e instanceof Uint8Array?e:e.subarray());if(Ii(n))return n.then(({digest:o})=>ye.verify(t,o,r)).catch(o=>{throw new Je(String(o))});try{return ye.verify(t,n.digest,r)}catch(o){throw new Je(String(o))}}var Gr=class{type="secp256k1";raw;_key;constructor(t){this._key=Ti(t),this.raw=_i(this._key)}toMultihash(){return At.digest(Ot(this))}toCID(){return ft.createV1(114,this.toMultihash())}toString(){return $.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:gt(this.raw,t.raw)}verify(t,e){return Li(this._key,e,t)}};function Uo(r){return new Gr(r)}function _i(r){return ye.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Ti(r){try{return ye.ProjectivePoint.fromHex(r),r}catch(t){throw new xe(String(t))}}function Ko(r,t){let{Type:e,Data:n}=Rt.decode(r),o=n??new Uint8Array;switch(e){case tt.RSA:return To(o,t);case tt.Ed25519:return to(o);case tt.secp256k1:return Uo(o);case tt.ECDSA:return Un(o);default:throw new se}}function Pi(r){let{Type:t,Data:e}=Rt.decode(r.digest),n=e??new Uint8Array;switch(t){case tt.Ed25519:return to(n);case tt.secp256k1:return Uo(n);case tt.ECDSA:return Un(n);default:throw new se}}function Ot(r){return Rt.encode({Type:tt[r.type],Data:r.raw})}var Ci=Symbol.for("nodejs.util.inspect.custom"),mf=114,er=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()})`}[an]=!0;toString(){return this.string==null&&(this.string=$.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ft.createV1(mf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return gt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return gt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ci](){return`PeerId(${this.toString()})`}},rr=class extends er{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},nr=class extends er{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},or=class extends er{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},yf=2336,Zr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=At.digest(F(this.url))}[Ci](){return`PeerId(${this.url})`}[an]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ft.createV1(yf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=G(t)),t.toString()===this.toString())}};function Oo(r){if(r.type==="Ed25519")return new nr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new or({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new rr({multihash:r.toCID().multihash,publicKey:r});throw new se}function Ri(r){return Oo(r.publicKey)}function sr(r){if(gf(r))return new rr({multihash:r});if(bf(r))try{let t=Pi(r);if(t.type==="Ed25519")return new nr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new or({multihash:r,publicKey:t})}catch{let e=G(r.digest);return new Zr(new URL(e))}throw new br("Supplied PeerID Multihash is invalid")}function bf(r){return r.code===At.code}function gf(r){return r.code===ae.code}function be(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 Yr(r){let t=Zt($.decode(`z${r}`));return sr(t)}var ir=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 be(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 be(this.map.values(),t=>t.key)}values(){return be(this.map.values(),t=>t.value)}get size(){return this.map.size}};var ar=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 be(this.set.entries(),t=>{let e=Yr(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Yr(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return be(this.set.values(),t=>Yr(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 Ft(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Wr=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}},Ke=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Wr(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 Wr(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 Mo=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function jr(r={}){return xf(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 xf(r,t){t=t??{};let e=t.onEnd,n=new Ke,o,s,i,c=Ft(),a=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((h,g)=>{s=S=>{s=null,n.push(S);try{h(r(n))}catch(m){g(m)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=Ft()})}},l=h=>s!=null?s(h):(n.push(h),o),u=h=>(n=new Ke,s!=null?s({error:h}):(n.push({error:h}),o)),f=h=>{if(i)return o;if(t?.objectMode!==!0&&h?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:h})},p=h=>i?o:(i=!0,h!=null?u(h):l({done:!0})),x=()=>(n=new Ke,p(),{done:!0}),E=h=>(p(h),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:a,return:x,throw:E,push:f,end:p,get readableLength(){return n.size},onEmpty:async h=>{let g=h?.signal;if(g?.throwIfAborted(),n.isEmpty())return;let S,m;g!=null&&(S=new Promise((B,P)=>{m=()=>{P(new Mo)},g.addEventListener("abort",m)}));try{await Promise.race([c.promise,S])}finally{m!=null&&g!=null&&g?.removeEventListener("abort",m)}}},e==null)return o;let b=o;return o={[Symbol.asyncIterator](){return this},next(){return b.next()},throw(h){return b.throw(h),e!=null&&(e(h),e=void 0),{done:!0}},return(){return b.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(h){return b.end(h),e!=null&&(e(h),e=void 0),o},get readableLength(){return b.readableLength},onEmpty:h=>b.onEmpty(h)},o}var $r=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 Di(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new $r(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new $r(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 ko=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Ft(),this.haveNext=Ft()}[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=Ft(),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=Ft(),await Di(this.readNext.promise,e?.signal,e)}};function Ni(){return new ko}function wf(r){return r[Symbol.asyncIterator]!=null}async function Ef(r,t){try{await Promise.all(r.map(async e=>{for await(let n of e)await t.push(n)})),await t.end()}catch(e){await t.end(e).catch(()=>{})}}async function*Sf(r){let t=Ni();Ef(r,t).catch(()=>{}),yield*t}function*vf(r){for(let t of r)yield*t}function Af(...r){let t=[];for(let e of r)wf(e)||t.push(e);return t.length===r.length?vf(t):Sf(r)}var Ui=Af;function cr(r,...t){if(r==null)throw new Error("Empty pipeline");if(qo(r)){let n=r;r=()=>n.source}else if(Oi(r)||Ki(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]=If(e[n]));return Bf(...e)}var Bf=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},Ki=r=>r?.[Symbol.asyncIterator]!=null,Oi=r=>r?.[Symbol.iterator]!=null,qo=r=>r==null?!1:r.sink!=null&&r.source!=null,If=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=jr({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let o,s=r.source;if(Ki(s))o=async function*(){yield*s,n.end()};else if(Oi(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Ui(n,o())}return r.source};var Vo=pa(ki(),1);var fr=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},zo=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},qi=r=>globalThis.DOMException===void 0?new zo(r):new DOMException(r),Hi=r=>{let t=r.reason===void 0?qi("This operation was aborted."):r.reason;return t instanceof Error?t:qi(t)};function Fo(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:x}=t;x.aborted&&f(Hi(x)),c=()=>{f(Hi(x))},x.addEventListener("abort",c,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(u,f);return}let p=new fr;i=s.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(x){f(x)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?u():o instanceof Error?f(o):(p.message=o??`Promise timed out after ${e} milliseconds`,f(p))},e),(async()=>{try{u(await r)}catch(x){f(x)}})()}).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 Go(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 lr=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=Go(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 hr=class extends Vo.default{#t;#i;#s=0;#d;#a;#p=0;#r;#c;#e;#m;#n=0;#u;#o;#y;#x=1n;timeout;constructor(t){if(super(),t={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:lr,...t},!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString()??""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString()??""}\` (${typeof t.interval})`);this.#t=t.carryoverConcurrencyCount,this.#i=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#d=t.intervalCap,this.#a=t.interval,this.#e=new t.queueClass,this.#m=t.queueClass,this.concurrency=t.concurrency,this.timeout=t.timeout,this.#y=t.throwOnTimeout===!0,this.#o=t.autoStart===!1}get#w(){return this.#i||this.#s<this.#d}get#E(){return this.#n<this.#u}#S(){this.#n--,this.#f(),this.emit("next")}#v(){this.#g(),this.#b(),this.#c=void 0}get#A(){let t=Date.now();if(this.#r===void 0){let e=this.#p-t;if(e<0)this.#s=this.#t?this.#n:0;else return this.#c===void 0&&(this.#c=setTimeout(()=>{this.#v()},e)),!0}return!1}#f(){if(this.#e.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#o){let t=!this.#A;if(this.#w&&this.#E){let e=this.#e.dequeue();return e?(this.emit("active"),e(),t&&this.#b(),!0):!1}}return!1}#b(){this.#i||this.#r!==void 0||(this.#r=setInterval(()=>{this.#g()},this.#a),this.#p=Date.now()+this.#a)}#g(){this.#s===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#t?this.#n:0,this.#l()}#l(){for(;this.#f(););}get concurrency(){return this.#u}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#u=t,this.#l()}async#B(t){return new Promise((e,n)=>{t.addEventListener("abort",()=>{n(t.reason)},{once:!0})})}setPriority(t,e){this.#e.setPriority(t,e)}async add(t,e={}){return e.id??=(this.#x++).toString(),e={timeout:this.timeout,throwOnTimeout:this.#y,...e},new Promise((n,o)=>{this.#e.enqueue(async()=>{this.#n++,this.#s++;try{e.signal?.throwIfAborted();let s=t({signal:e.signal});e.timeout&&(s=Fo(Promise.resolve(s),{milliseconds:e.timeout})),e.signal&&(s=Promise.race([s,this.#B(e.signal)]));let i=await s;n(i),this.emit("completed",i)}catch(s){if(s instanceof fr&&!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 Vi(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 zi(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Fi(r,t){let e=Vi(r).return?.();zi(e)&&e.catch(n=>{t.error("could not cause iterator to return",n)})}var Jr=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Oe=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Qr=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},dr=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function tn(r){return r[Symbol.asyncIterator]!=null}function Gi(r,t){if(r.byteLength>t)throw new Oe("Message length too long")}var rn=r=>{let t=_t(r),e=ut(t);return Js(r,e),rn.bytes=t,e};rn.bytes=0;function nn(r,t){t=t??{};let e=t.lengthEncoder??rn,n=t?.maxDataLength??4194304;function*o(s){Gi(s,n);let i=e(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return tn(r)?async function*(){for await(let s of r)yield*o(s)}():function*(){for(let s of r)yield*o(s)}()}nn.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??rn,n=t?.maxDataLength??4194304;return Gi(r,n),new rt(e(r.byteLength),r)};var ge;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(ge||(ge={}));var Zo=r=>{let t=Qs(r);return Zo.bytes=_t(t),t};Zo.bytes=0;function pr(r,t){let e=new rt,n=ge.LENGTH,o=-1,s=t?.lengthDecoder??Zo,i=t?.maxLengthLength??8,c=t?.maxDataLength??4194304;function*a(){for(;e.byteLength>0;){if(n===ge.LENGTH)try{if(o=s(e),o<0)throw new Jr("Invalid message length");if(o>c)throw new Oe("Message length too long");let l=s.bytes;e.consume(l),t?.onLength!=null&&t.onLength(o),n=ge.DATA}catch(l){if(l instanceof RangeError){if(e.byteLength>i)throw new Qr("Message length length too long");break}throw l}if(n===ge.DATA){if(e.byteLength<o)break;let l=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(l),yield l,n=ge.LENGTH}}}return tn(r)?async function*(){for await(let l of r)e.append(l),yield*a();if(e.byteLength>0)throw new dr("Unexpected end of input")}():function*(){for(let l of r)e.append(l),yield*a();if(e.byteLength>0)throw new dr("Unexpected end of input")}()}pr.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 pr(n,{...t??{},onLength:s=>{e=s}})};var on=class extends we{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 rt(t):t)}attachInboundStream(t,e){let n=()=>{Fi(t.source,this.log)};return this._inboundAbortController.signal.addEventListener("abort",n,{once:!0}),this._rawInboundStream=t,this.inboundStream=cr(this._rawInboundStream,o=>pr(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=jr({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"))}}),cr(this.outboundStream,n=>nn(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 Zi(){return BigInt(`0x${G(Vr(8),"base16")}`)}var Yi=(r,t)=>{let e=F(t.toString(16).padStart(16,"0"),"base16"),n=Ot(r),o=new Uint8Array(n.byteLength+e.length);return o.set(n,0),o.set(e,n.byteLength),o},Wi=r=>ae.encode(r);var ji=function(r){return Array.isArray(r)?r:[r]},Cf=async r=>{if(r.sequenceNumber==null||r.from==null||r.signature==null)return!1;let t=sr(Zt(r.from));if(t.publicKey!=null)return!0;if(r.key!=null){let e=r.key;return Oo(Ko(e)).equals(t)}return!1},$i=async r=>{if(r.from==null)throw new Q("RPC message was missing from");if(!await Cf(r))return{type:"unsigned",topic:r.topic??"",data:r.data??new Uint8Array(0)};let t=sr(Zt(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: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}},mr=r=>r.type==="signed"?{from:r.from.toMultihash().bytes,data:r.data,sequenceNumber:Rf(r.sequenceNumber),topic:r.topic,signature:r.signature,key:r.key?Ot(r.key):void 0}:{data:r.data,topic:r.topic},Rf=r=>{let t=r.toString(16);return t.length%2!==0&&(t=`0${t}`),F(t,"base16")},Df=r=>BigInt(`0x${G(r,"base16")}`);var Xi=F("libp2p-pubsub:");async function Ji(r,t,e){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:Ri(r)},o=ie([Xi,e(mr(n)).subarray()]);return n.signature=await r.sign(o),n.key=r.publicKey,n}async function Qi(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([Xi,t({...mr(r),signature:void 0,key:void 0}).subarray()]);return Nf(r).verify(e,r.signature)}function Nf(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 Yo=class extends we{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=ji(n),this.enabled=e.enabled!==!1,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new ir,this.globalSignaturePolicy=o==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=s,this.emitSelf=i,this.topicValidators=new Map,this.queue=new hr({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 on(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 cr(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 $i(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 ar,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 Yi(t.key,t.sequenceNumber);case"StrictNoSign":return Wi(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(mr)})}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 Qi(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===ke.Reject||s===ke.Ignore)throw new Q("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return Ji(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 gr("not started yet");if(t==null)throw new j("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:Zi()};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 ma(Uf);})();
|
2
|
+
"use strict";var Libp2PPubsub=(()=>{var ca=Object.create;var yr=Object.defineProperty;var ua=Object.getOwnPropertyDescriptor;var fa=Object.getOwnPropertyNames;var la=Object.getPrototypeOf,ha=Object.prototype.hasOwnProperty;var da=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),mt=(r,t)=>{for(var e in t)yr(r,e,{get:t[e],enumerable:!0})},rs=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of fa(t))!ha.call(r,o)&&o!==e&&yr(r,o,{get:()=>t[o],enumerable:!(n=ua(t,o))||n.enumerable});return r};var pa=(r,t,e)=>(e=r!=null?ca(la(r)):{},rs(t||!r||!r.__esModule?yr(e,"default",{value:r,enumerable:!0}):e,r)),ma=r=>rs(yr({},"__esModule",{value:!0}),r);var Mi=da((hm,Vo)=>{"use strict";var Lf=Object.prototype.hasOwnProperty,yt="~";function ur(){}Object.create&&(ur.prototype=Object.create(null),new ur().__proto__||(yt=!1));function _f(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function Oi(r,t,e,n,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var s=new _f(e,n||r,o),i=yt?yt+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 Xr(r,t){--r._eventsCount===0?r._events=new ur:delete r._events[t]}function dt(){this._events=new ur,this._eventsCount=0}dt.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)Lf.call(e,n)&&t.push(yt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};dt.prototype.listeners=function(t){var e=yt?yt+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};dt.prototype.listenerCount=function(t){var e=yt?yt+t:t,n=this._events[e];return n?n.fn?1:n.length:0};dt.prototype.emit=function(t,e,n,o,s,i){var c=yt?yt+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 p=a.length,w;for(f=0;f<p;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(w=1,u=new Array(l-1);w<l;w++)u[w-1]=arguments[w];a[f].fn.apply(a[f].context,u)}}return!0};dt.prototype.on=function(t,e,n){return Oi(this,t,e,n,!1)};dt.prototype.once=function(t,e,n){return Oi(this,t,e,n,!0)};dt.prototype.removeListener=function(t,e,n,o){var s=yt?yt+t:t;if(!this._events[s])return this;if(!e)return Xr(this,s),this;var i=this._events[s];if(i.fn)i.fn===e&&(!o||i.once)&&(!n||i.context===n)&&Xr(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:Xr(this,s)}return this};dt.prototype.removeAllListeners=function(t){var e;return t?(e=yt?yt+t:t,this._events[e]&&Xr(this,e)):(this._events=new ur,this._eventsCount=0),this};dt.prototype.off=dt.prototype.removeListener;dt.prototype.addListener=dt.prototype.on;dt.prefixed=yt;dt.EventEmitter=dt;typeof Vo<"u"&&(Vo.exports=dt)});var Kf={};mt(Kf,{PubSubBaseProtocol:()=>Yo});var an=Symbol.for("@libp2p/peer-id");var Me;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(Me||(Me={}));var Of=Symbol.for("@libp2p/pubsub");var W=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},we=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var br=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 gr=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 xe=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 hn={};mt(hn,{base58btc:()=>$,base58flickr:()=>Ea});var Vf=new Uint8Array(0);function ns(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Nt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function os(r){return new TextEncoder().encode(r)}function ss(r){return new TextDecoder().decode(r)}function ya(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(E){if(E instanceof Uint8Array||(ArrayBuffer.isView(E)?E=new Uint8Array(E.buffer,E.byteOffset,E.byteLength):Array.isArray(E)&&(E=Uint8Array.from(E))),!(E instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(E.length===0)return"";for(var b=0,h=0,g=0,S=E.length;g!==S&&E[g]===0;)g++,b++;for(var m=(S-g)*u+1>>>0,B=new Uint8Array(m);g!==S;){for(var P=E[g],C=0,I=m-1;(P!==0||C<h)&&I!==-1;I--,C++)P+=256*B[I]>>>0,B[I]=P%c>>>0,P=P/c>>>0;if(P!==0)throw new Error("Non-zero carry");h=C,g++}for(var T=m-h;T!==m&&B[T]===0;)T++;for(var L=a.repeat(b);T<m;++T)L+=r.charAt(B[T]);return L}function p(E){if(typeof E!="string")throw new TypeError("Expected String");if(E.length===0)return new Uint8Array;var b=0;if(E[b]!==" "){for(var h=0,g=0;E[b]===a;)h++,b++;for(var S=(E.length-b)*l+1>>>0,m=new Uint8Array(S);E[b];){var B=e[E.charCodeAt(b)];if(B===255)return;for(var P=0,C=S-1;(B!==0||P<g)&&C!==-1;C--,P++)B+=c*m[C]>>>0,m[C]=B%256>>>0,B=B/256>>>0;if(B!==0)throw new Error("Non-zero carry");g=P,b++}if(E[b]!==" "){for(var I=S-g;I!==S&&m[I]===0;)I++;for(var T=new Uint8Array(h+(S-I)),L=h;I!==S;)T[L++]=m[I++];return T}}}function w(E){var b=p(E);if(b)return b;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:p,decode:w}}var ba=ya,ga=ba,as=ga;var cn=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")}},un=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return cs(this,t)}},fn=class{decoders;constructor(t){this.decoders=t}or(t){return cs(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function cs(r,t){return new fn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var ln=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 cn(t,e,n),this.decoder=new un(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ee({name:r,prefix:t,encode:e,decode:n}){return new ln(r,t,e,n)}function Gt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=as(e,r);return Ee({prefix:t,name:r,encode:n,decode:s=>Nt(o(s))})}function wa(r,t,e,n){let o={};for(let u=0;u<t.length;++u)o[t[u]]=u;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*e/8|0),c=0,a=0,l=0;for(let u=0;u<s;++u){let f=o[r[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|f,c+=e,c>=8&&(c-=8,i[l++]=255&a>>c)}if(c>=e||(255&a<<8-c)!==0)throw new SyntaxError("Unexpected end of data");return i}function xa(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 J({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return Ee({prefix:t,name:r,encode(o){return xa(o,n,e)},decode(o){return wa(o,n,e,r)}})}var $=Gt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ea=Gt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var dn={};mt(dn,{base32:()=>Se,base32hex:()=>Ba,base32hexpad:()=>La,base32hexpadupper:()=>_a,base32hexupper:()=>Ia,base32pad:()=>va,base32padupper:()=>Aa,base32upper:()=>Sa,base32z:()=>Ta});var Se=J({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Sa=J({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),va=J({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Aa=J({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ba=J({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ia=J({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),La=J({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),_a=J({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ta=J({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var pn={};mt(pn,{base36:()=>qe,base36upper:()=>Pa});var qe=Gt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Pa=Gt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ca=ls,us=128,Ra=127,Da=~Ra,Na=Math.pow(2,31);function ls(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Na;)t[e++]=r&255|us,r/=128;for(;r&Da;)t[e++]=r&255|us,r>>>=7;return t[e]=r|0,ls.bytes=e-n+1,t}var Ka=mn,Ua=128,fs=127;function mn(r,n){var e=0,n=n||0,o=0,s=n,i,c=r.length;do{if(s>=c)throw mn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&fs)<<o:(i&fs)*Math.pow(2,o),o+=7}while(i>=Ua);return mn.bytes=s-n,e}var ka=Math.pow(2,7),Oa=Math.pow(2,14),Ma=Math.pow(2,21),qa=Math.pow(2,28),Ha=Math.pow(2,35),Va=Math.pow(2,42),za=Math.pow(2,49),Fa=Math.pow(2,56),Ga=Math.pow(2,63),ja=function(r){return r<ka?1:r<Oa?2:r<Ma?3:r<qa?4:r<Ha?5:r<Va?6:r<za?7:r<Fa?8:r<Ga?9:10},Za={encode:Ca,decode:Ka,encodingLength:ja},Ya=Za,He=Ya;function Ve(r,t=0){return[He.decode(r,t),He.decode.bytes]}function ve(r,t,e=0){return He.encode(r,t,e),t}function Ae(r){return He.encodingLength(r)}function vt(r,t){let e=t.byteLength,n=Ae(r),o=n+Ae(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 jt(r){let t=Nt(r),[e,n]=Ve(t),[o,s]=Ve(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Be(e,o,i,t)}function hs(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ns(r.bytes,e.bytes)}}var Be=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function ds(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return $a(e,yn(r),t??$.encoder);default:return Xa(e,yn(r),t??Se.encoder)}}var ps=new WeakMap;function yn(r){let t=ps.get(r);if(t==null){let e=new Map;return ps.set(r,e),e}return t}var ut=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!==ze)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Ja)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=vt(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&hs(t.multihash,n.multihash)}toString(t){return ds(this,t)}toJSON(){return{"/":ds(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??ms(n,o,s.bytes))}else if(e[Qa]===!0){let{version:n,multihash:o,code:s}=e,i=jt(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!==ze)throw new Error(`Version 0 CID must use dag-pb (code: ${ze}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=ms(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,ze,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=Nt(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,p]=Ve(t.subarray(e));return e+=p,f},o=n(),s=ze;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]=Wa(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 yn(s).set(n,t),s}};function Wa(r,t){switch(r[0]){case"Q":{let e=t??$;return[$.prefix,e.decode(`${$.prefix}${r}`)]}case $.prefix:{let e=t??$;return[$.prefix,e.decode(r)]}case Se.prefix:{let e=t??Se;return[Se.prefix,e.decode(r)]}case qe.prefix:{let e=t??qe;return[qe.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 $a(r,t,e){let{prefix:n}=e;if(n!==$.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 Xa(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 ze=112,Ja=18;function ms(r,t,e){let n=Ae(r),o=n+Ae(t),s=new Uint8Array(o+e.byteLength);return ve(r,s,0),ve(t,s,n),s.set(e,o),s}var Qa=Symbol.for("@ipld/js-cid/CID");var bn={};mt(bn,{identity:()=>At});var ys=0,tc="identity",bs=Nt;function ec(r){return vt(ys,bs(r))}var At={code:ys,name:tc,encode:bs,digest:ec};function gt(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 ft(r=0){return new Uint8Array(r)}function ie(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=ft(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var ws=Symbol.for("@achingbrain/uint8arraylist");function gs(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function xr(r){return!!r?.[ws]}var rt=class r{bufs;length;[ws]=!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(xr(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(xr(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=gs(this.bufs,t);return e.buf[e.index]}set(t,e){let n=gs(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(xr(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(!xr(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 p=l;p>=0;p--){let w=this.get(f+p);if(n[p]!==w){u=Math.max(1,p-c[w]);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=ft(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=ft(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(!gt(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 gn={};mt(gn,{base10:()=>rc});var rc=Gt({prefix:"9",name:"base10",alphabet:"0123456789"});var wn={};mt(wn,{base16:()=>nc,base16upper:()=>oc});var nc=J({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),oc=J({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var xn={};mt(xn,{base2:()=>sc});var sc=J({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var En={};mt(En,{base256emoji:()=>fc});var xs=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}"),ic=xs.reduce((r,t,e)=>(r[e]=t,r),[]),ac=xs.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function cc(r){return r.reduce((t,e)=>(t+=ic[e],t),"")}function uc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=ac[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var fc=Ee({prefix:"\u{1F680}",name:"base256emoji",encode:cc,decode:uc});var Sn={};mt(Sn,{base64:()=>lc,base64pad:()=>hc,base64url:()=>dc,base64urlpad:()=>pc});var lc=J({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),hc=J({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),dc=J({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),pc=J({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var vn={};mt(vn,{base8:()=>mc});var mc=J({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var An={};mt(An,{identity:()=>yc});var yc=Ee({prefix:"\0",name:"identity",encode:r=>ss(r),decode:r=>os(r)});var Bl=new TextEncoder,Il=new TextDecoder;var Ln={};mt(Ln,{sha256:()=>ae,sha512:()=>wc});function In({name:r,code:t,encode:e}){return new Bn(r,t,e)}var Bn=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?vt(this.code,e):e.then(n=>vt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Ss(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var ae=In({name:"sha2-256",code:18,encode:Ss("SHA-256")}),wc=In({name:"sha2-512",code:19,encode:Ss("SHA-512")});var _n={...An,...xn,...vn,...gn,...wn,...dn,...pn,...hn,...Sn,...En},Ol={...Ln,...bn};function As(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var vs=As("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Tn=As("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=ft(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),xc={utf8:vs,"utf-8":vs,hex:_n.base16,latin1:Tn,ascii:Tn,binary:Tn,..._n},Er=xc;function F(r,t="utf8"){let e=Er[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function G(r,t="utf8"){let e=Er[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Ec=parseInt("11111",2),Pn=parseInt("10000000",2),Sc=parseInt("01111111",2),Bs={0:Fe,1:Fe,2:vc,3:Ic,4:Lc,5:Bc,6:Ac,16:Fe,22:Fe,48:Fe};function Ut(r,t={offset:0}){let e=r[t.offset]&Ec;if(t.offset++,Bs[e]!=null)return Bs[e](r,t);throw new Error("No decoder for tag "+e)}function Ge(r,t){let e=0;if((r[t.offset]&Pn)===Pn){let n=r[t.offset]&Sc,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 Fe(r,t){Ge(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Ut(r,t);if(n===null)break;e.push(n)}return e}function vc(r,t){let e=Ge(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 Ac(r,t){let e=Ge(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 Bc(r,t){return t.offset++,null}function Ic(r,t){let e=Ge(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 Lc(r,t){let e=Ge(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function _c(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new rt;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Cn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=_c(r.byteLength);return new rt(Uint8Array.from([t.byteLength|Pn]),t)}function wt(r){let t=new rt,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new rt(Uint8Array.from([2]),Cn(t),t)}function Sr(r){let t=Uint8Array.from([0]),e=new rt(t,r);return new rt(Uint8Array.from([3]),Cn(e),e)}function Yt(r,t=48){let e=new rt;for(let n of r)e.append(n);return new rt(Uint8Array.from([t]),Cn(e),e)}async function Is(r,t,e){let n=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);return crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},n,t,e.subarray())}var Tc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Pc=Uint8Array.from([6,5,43,129,4,0,34]),Cc=Uint8Array.from([6,5,43,129,4,0,35]),Rc={ext:!0,kty:"EC",crv:"P-256"},Dc={ext:!0,kty:"EC",crv:"P-384"},Nc={ext:!0,kty:"EC",crv:"P-521"},Rn=32,Dn=48,Nn=66;function Kn(r){let t=Ut(r);return Ls(t)}function Ls(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===Rn*2+1)return n=G(t.subarray(e,e+Rn),"base64url"),o=G(t.subarray(e+Rn),"base64url"),new Ie({...Rc,key_ops:["verify"],x:n,y:o});if(t.byteLength===Dn*2+1)return n=G(t.subarray(e,e+Dn),"base64url"),o=G(t.subarray(e+Dn),"base64url"),new Ie({...Dc,key_ops:["verify"],x:n,y:o});if(t.byteLength===Nn*2+1)return n=G(t.subarray(e,e+Nn),"base64url"),o=G(t.subarray(e+Nn),"base64url"),new Ie({...Nc,key_ops:["verify"],x:n,y:o});throw new W(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function _s(r){return Yt([wt(Uint8Array.from([1])),Yt([Kc(r.crv)],160),Yt([Sr(new rt(Uint8Array.from([4]),F(r.x??"","base64url"),F(r.y??"","base64url")))],161)]).subarray()}function Kc(r){if(r==="P-256")return Tc;if(r==="P-384")return Pc;if(r==="P-521")return Cc;throw new W(`Invalid curve ${r}`)}var Ie=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=_s(this.jwk)),this._raw}toMultihash(){return At.digest(kt(this))}toCID(){return ut.createV1(114,this.toMultihash())}toString(){return $.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:gt(this.raw,t.raw)}async verify(t,e){return Is(this.jwk,e,t)}};function Ts(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function Uc(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Le(r,...t){if(!Uc(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 Ps(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Ts(r.outputLen),Ts(r.blockLen)}function _e(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 Cs(r,t){Le(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}var ce=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function vr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Bt(r,t){return r<<32-t|r>>>t}function Rs(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function je(r){return typeof r=="string"&&(r=Rs(r)),Le(r),r}function Un(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Le(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 Te=class{clone(){return this._cloneInto()}};function Ar(r){let t=n=>r().update(je(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 ce.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function kc(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(e>>o&s),c=Number(e&s),a=n?4:0,l=n?0:4;r.setUint32(t+a,i,n),r.setUint32(t+l,c,n)}function Ds(r,t,e){return r&t^~r&e}function Ns(r,t,e){return r&t^r&e^t&e}var Ce=class extends Te{constructor(t,e,n,o){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=vr(this.buffer)}update(t){_e(this);let{view:e,buffer:n,blockLen:o}=this;t=je(t);let s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=vr(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){_e(this),Cs(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)e[f]=0;kc(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=vr(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.length=o,t.pos=c,t.finished=s,t.destroyed=i,o%e&&t.buffer.set(n),t}};var Br=BigInt(4294967295),kn=BigInt(32);function Ks(r,t=!1){return t?{h:Number(r&Br),l:Number(r>>kn&Br)}:{h:Number(r>>kn&Br)|0,l:Number(r&Br)|0}}function Oc(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:s,l:i}=Ks(r[o],t);[e[o],n[o]]=[s,i]}return[e,n]}var Mc=(r,t)=>BigInt(r>>>0)<<kn|BigInt(t>>>0),qc=(r,t,e)=>r>>>e,Hc=(r,t,e)=>r<<32-e|t>>>e,Vc=(r,t,e)=>r>>>e|t<<32-e,zc=(r,t,e)=>r<<32-e|t>>>e,Fc=(r,t,e)=>r<<64-e|t>>>e-32,Gc=(r,t,e)=>r>>>e-32|t<<64-e,jc=(r,t)=>t,Zc=(r,t)=>r,Yc=(r,t,e)=>r<<e|t>>>32-e,Wc=(r,t,e)=>t<<e|r>>>32-e,$c=(r,t,e)=>t<<e-32|r>>>64-e,Xc=(r,t,e)=>r<<e-32|t>>>64-e;function Jc(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Qc=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),tu=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,eu=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),ru=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,nu=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),ou=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var su={fromBig:Ks,split:Oc,toBig:Mc,shrSH:qc,shrSL:Hc,rotrSH:Vc,rotrSL:zc,rotrBH:Fc,rotrBL:Gc,rotr32H:jc,rotr32L:Zc,rotlSH:Yc,rotlSL:Wc,rotlBH:$c,rotlBL:Xc,add:Jc,add3L:Qc,add3H:tu,add4L:eu,add4H:ru,add5H:ou,add5L:nu},K=su;var[iu,au]=K.split(["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))),Wt=new Uint32Array(80),$t=new Uint32Array(80),On=class extends Ce{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}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:p,Gh:w,Gl:E,Hh:b,Hl:h}=this;return[t,e,n,o,s,i,c,a,l,u,f,p,w,E,b,h]}set(t,e,n,o,s,i,c,a,l,u,f,p,w,E,b,h){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=p|0,this.Gh=w|0,this.Gl=E|0,this.Hh=b|0,this.Hl=h|0}process(t,e){for(let m=0;m<16;m++,e+=4)Wt[m]=t.getUint32(e),$t[m]=t.getUint32(e+=4);for(let m=16;m<80;m++){let B=Wt[m-15]|0,P=$t[m-15]|0,C=K.rotrSH(B,P,1)^K.rotrSH(B,P,8)^K.shrSH(B,P,7),I=K.rotrSL(B,P,1)^K.rotrSL(B,P,8)^K.shrSL(B,P,7),T=Wt[m-2]|0,L=$t[m-2]|0,j=K.rotrSH(T,L,19)^K.rotrBH(T,L,61)^K.shrSH(T,L,6),M=K.rotrSL(T,L,19)^K.rotrBL(T,L,61)^K.shrSL(T,L,6),k=K.add4L(I,M,$t[m-7],$t[m-16]),et=K.add4H(k,C,j,Wt[m-7],Wt[m-16]);Wt[m]=et|0,$t[m]=k|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:l,Dl:u,Eh:f,El:p,Fh:w,Fl:E,Gh:b,Gl:h,Hh:g,Hl:S}=this;for(let m=0;m<80;m++){let B=K.rotrSH(f,p,14)^K.rotrSH(f,p,18)^K.rotrBH(f,p,41),P=K.rotrSL(f,p,14)^K.rotrSL(f,p,18)^K.rotrBL(f,p,41),C=f&w^~f&b,I=p&E^~p&h,T=K.add5L(S,P,I,au[m],$t[m]),L=K.add5H(T,g,B,C,iu[m],Wt[m]),j=T|0,M=K.rotrSH(n,o,28)^K.rotrBH(n,o,34)^K.rotrBH(n,o,39),k=K.rotrSL(n,o,28)^K.rotrBL(n,o,34)^K.rotrBL(n,o,39),et=n&s^n&c^s&c,v=o&i^o&a^i&a;g=b|0,S=h|0,b=w|0,h=E|0,w=f|0,E=p|0,{h:f,l:p}=K.add(l|0,u|0,L|0,j|0),l=c|0,u=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let _=K.add3L(j,k,v);n=K.add3H(_,L,M,et),o=_|0}({h:n,l:o}=K.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=K.add(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=K.add(this.Ch|0,this.Cl|0,c|0,a|0),{h:l,l:u}=K.add(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:p}=K.add(this.Eh|0,this.El|0,f|0,p|0),{h:w,l:E}=K.add(this.Fh|0,this.Fl|0,w|0,E|0),{h:b,l:h}=K.add(this.Gh|0,this.Gl|0,b|0,h|0),{h:g,l:S}=K.add(this.Hh|0,this.Hl|0,g|0,S|0),this.set(n,o,s,i,c,a,l,u,f,p,w,E,b,h,g,S)}roundClean(){Wt.fill(0),$t.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Us=Ar(()=>new On);var _r={};mt(_r,{aInRange:()=>xt,abool:()=>It,abytes:()=>Re,bitGet:()=>du,bitLen:()=>Vn,bitMask:()=>Ye,bitSet:()=>pu,bytesToHex:()=>Mt,bytesToNumberBE:()=>qt,bytesToNumberLE:()=>Jt,concatBytes:()=>Ht,createHmacDrbg:()=>zn,ensureBytes:()=>X,equalBytes:()=>lu,hexToBytes:()=>fe,hexToNumber:()=>Hn,inRange:()=>Ze,isBytes:()=>Xt,memoized:()=>he,notImplemented:()=>yu,numberToBytesBE:()=>Qt,numberToBytesLE:()=>le,numberToHexUnpadded:()=>ue,numberToVarBytesBE:()=>fu,utf8ToBytes:()=>hu,validateObject:()=>Ct});var Ir=BigInt(0),Lr=BigInt(1),cu=BigInt(2);function Xt(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Re(r){if(!Xt(r))throw new Error("Uint8Array expected")}function It(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}var uu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Mt(r){Re(r);let t="";for(let e=0;e<r.length;e++)t+=uu[r[e]];return t}function ue(r){let t=r.toString(16);return t.length&1?"0"+t:t}function Hn(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Ir:BigInt("0x"+r)}var Ot={_0:48,_9:57,A:65,F:70,a:97,f:102};function ks(r){if(r>=Ot._0&&r<=Ot._9)return r-Ot._0;if(r>=Ot.A&&r<=Ot.F)return r-(Ot.A-10);if(r>=Ot.a&&r<=Ot.f)return r-(Ot.a-10)}function fe(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof 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=ks(r.charCodeAt(s)),c=ks(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 qt(r){return Hn(Mt(r))}function Jt(r){return Re(r),Hn(Mt(Uint8Array.from(r).reverse()))}function Qt(r,t){return fe(r.toString(16).padStart(t*2,"0"))}function le(r,t){return Qt(r,t).reverse()}function fu(r){return fe(ue(r))}function X(r,t,e){let n;if(typeof t=="string")try{n=fe(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Xt(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 Ht(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Re(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}function lu(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function hu(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}var Mn=r=>typeof r=="bigint"&&Ir<=r;function Ze(r,t,e){return Mn(r)&&Mn(t)&&Mn(e)&&t<=r&&r<e}function xt(r,t,e,n){if(!Ze(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Vn(r){let t;for(t=0;r>Ir;r>>=Lr,t+=1);return t}function du(r,t){return r>>BigInt(t)&Lr}function pu(r,t,e){return r|(e?Lr:Ir)<<BigInt(t)}var Ye=r=>(cu<<BigInt(r-1))-Lr,qn=r=>new Uint8Array(r),Os=r=>Uint8Array.from(r);function zn(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=qn(r),o=qn(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},c=(...f)=>e(o,n,...f),a=(f=qn())=>{o=c(Os([0]),f),n=c(),f.length!==0&&(o=c(Os([1]),f),n=c())},l=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,p=[];for(;f<t;){n=c();let w=n.slice();p.push(w),f+=n.length}return Ht(...p)};return(f,p)=>{i(),a(f);let w;for(;!(w=p(l()));)a();return i(),w}}var mu={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"||Xt(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 Ct(r,t,e={}){let n=(o,s,i)=>{let c=mu[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}var yu=()=>{throw new Error("not implemented")};function he(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 nt=BigInt(0),Z=BigInt(1),de=BigInt(2),bu=BigInt(3),Fn=BigInt(4),Ms=BigInt(5),qs=BigInt(8),gu=BigInt(9),wu=BigInt(16);function V(r,t){let e=r%t;return e>=nt?e:t+e}function xu(r,t,e){if(t<nt)throw new Error("invalid exponent, negatives unsupported");if(e<=nt)throw new Error("invalid modulus");if(e===Z)return nt;let n=Z;for(;t>nt;)t&Z&&(n=n*r%e),r=r*r%e,t>>=Z;return n}function Y(r,t,e){let n=r;for(;t-- >nt;)n*=n,n%=e;return n}function Tr(r,t){if(r===nt)throw new Error("invert: expected non-zero number");if(t<=nt)throw new Error("invert: expected positive modulus, got "+t);let e=V(r,t),n=t,o=nt,s=Z,i=Z,c=nt;for(;e!==nt;){let l=n/e,u=n%e,f=o-i*l,p=s-c*l;n=e,e=u,o=i,s=c,i=f,c=p}if(n!==Z)throw new Error("invert: does not exist");return V(o,t)}function Eu(r){let t=(r-Z)/de,e,n,o;for(e=r-Z,n=0;e%de===nt;e/=de,n++);for(o=de;o<r&&xu(o,t,r)!==r-Z;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let i=(r+Z)/Fn;return function(a,l){let u=a.pow(l,i);if(!a.eql(a.sqr(u),l))throw new Error("Cannot find square root");return u}}let s=(e+Z)/de;return function(c,a){if(c.pow(a,t)===c.neg(c.ONE))throw new Error("Cannot find square root");let l=n,u=c.pow(c.mul(c.ONE,o),e),f=c.pow(a,s),p=c.pow(a,e);for(;!c.eql(p,c.ONE);){if(c.eql(p,c.ZERO))return c.ZERO;let w=1;for(let b=c.sqr(p);w<l&&!c.eql(b,c.ONE);w++)b=c.sqr(b);let E=c.pow(u,Z<<BigInt(l-w-1));u=c.sqr(E),f=c.mul(f,E),p=c.mul(p,u),l=w}return f}}function Su(r){if(r%Fn===bu){let t=(r+Z)/Fn;return function(n,o){let s=n.pow(o,t);if(!n.eql(n.sqr(s),o))throw new Error("Cannot find square root");return s}}if(r%qs===Ms){let t=(r-Ms)/qs;return function(n,o){let s=n.mul(o,de),i=n.pow(s,t),c=n.mul(o,i),a=n.mul(n.mul(c,de),i),l=n.mul(c,n.sub(a,n.ONE));if(!n.eql(n.sqr(l),o))throw new Error("Cannot find square root");return l}}return r%wu,Eu(r)}var Hs=(r,t)=>(V(r,t)&Z)===Z,vu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Gn(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=vu.reduce((n,o)=>(n[o]="function",n),t);return Ct(r,e)}function Au(r,t,e){if(e<nt)throw new Error("invalid exponent, negatives unsupported");if(e===nt)return r.ONE;if(e===Z)return t;let n=r.ONE,o=t;for(;e>nt;)e&Z&&(n=r.mul(n,o)),o=r.sqr(o),e>>=Z;return n}function Bu(r,t){let e=new Array(t.length),n=t.reduce((s,i,c)=>r.is0(i)?s:(e[c]=s,r.mul(s,i)),r.ONE),o=r.inv(n);return t.reduceRight((s,i,c)=>r.is0(i)?s:(e[c]=r.mul(s,e[c]),r.mul(s,i)),o),e}function jn(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function te(r,t,e=!1,n={}){if(r<=nt)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=jn(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:Ye(o),ZERO:nt,ONE:Z,create:a=>V(a,r),isValid:a=>{if(typeof a!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof a);return nt<=a&&a<r},is0:a=>a===nt,isOdd:a=>(a&Z)===Z,neg:a=>V(-a,r),eql:(a,l)=>a===l,sqr:a=>V(a*a,r),add:(a,l)=>V(a+l,r),sub:(a,l)=>V(a-l,r),mul:(a,l)=>V(a*l,r),pow:(a,l)=>Au(c,a,l),div:(a,l)=>V(a*Tr(l,r),r),sqrN:a=>a*a,addN:(a,l)=>a+l,subN:(a,l)=>a-l,mulN:(a,l)=>a*l,inv:a=>Tr(a,r),sqrt:n.sqrt||(a=>(i||(i=Su(r)),i(c,a))),invertBatch:a=>Bu(c,a),cmov:(a,l,u)=>u?l:a,toBytes:a=>e?le(a,s):Qt(a,s),fromBytes:a=>{if(a.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+a.length);return e?Jt(a):qt(a)}});return Object.freeze(c)}function Vs(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 Zn(r){let t=Vs(r);return t+Math.ceil(t/2)}function zs(r,t,e=!1){let n=r.length,o=Vs(t),s=Zn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Jt(r):qt(r),c=V(i,t-Z)+Z;return e?le(c,o):Qt(c,o)}var Fs=BigInt(0),Pr=BigInt(1);function Yn(r,t){let e=t.negate();return r?e:t}function Gs(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Wn(r,t){Gs(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1);return{windows:e,windowSize:n}}function Iu(r,t){if(!Array.isArray(r))throw new Error("array expected");r.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}function Lu(r,t){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}var $n=new WeakMap,js=new WeakMap;function Xn(r){return js.get(r)||1}function Cr(r,t){return{constTimeNegate:Yn,hasPrecomputes(e){return Xn(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>Fs;)n&Pr&&(o=o.add(s)),s=s.double(),n>>=Pr;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=Wn(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{windows:s,windowSize:i}=Wn(e,t),c=r.ZERO,a=r.BASE,l=BigInt(2**e-1),u=2**e,f=BigInt(e);for(let p=0;p<s;p++){let w=p*i,E=Number(o&l);o>>=f,E>i&&(E-=u,o+=Pr);let b=w,h=w+Math.abs(E)-1,g=p%2!==0,S=E<0;E===0?a=a.add(Yn(g,n[b])):c=c.add(Yn(S,n[h]))}return{p:c,f:a}},wNAFUnsafe(e,n,o,s=r.ZERO){let{windows:i,windowSize:c}=Wn(e,t),a=BigInt(2**e-1),l=2**e,u=BigInt(e);for(let f=0;f<i;f++){let p=f*c;if(o===Fs)break;let w=Number(o&a);if(o>>=u,w>c&&(w-=l,o+=Pr),w===0)continue;let E=n[p+Math.abs(w)-1];w<0&&(E=E.negate()),s=s.add(E)}return s},getPrecomputes(e,n,o){let s=$n.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&$n.set(n,o(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){Gs(n,t),js.set(e,n),$n.delete(e)}}}function Rr(r,t,e,n){if(Iu(e,r),Lu(n,t),e.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=r.ZERO,s=Vn(BigInt(e.length)),i=s>12?s-3:s>4?s-2:s?2:1,c=(1<<i)-1,a=new Array(c+1).fill(o),l=Math.floor((t.BITS-1)/i)*i,u=o;for(let f=l;f>=0;f-=i){a.fill(o);for(let w=0;w<n.length;w++){let E=n[w],b=Number(E>>BigInt(f)&BigInt(c));a[b]=a[b].add(e[w])}let p=o;for(let w=a.length-1,E=o;w>0;w--)E=E.add(a[w]),p=p.add(E);if(u=u.add(p),f!==0)for(let w=0;w<i;w++)u=u.double()}return u}function We(r){return Gn(r.Fp),Ct(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...jn(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Lt=BigInt(0),Et=BigInt(1),Dr=BigInt(2),_u=BigInt(8),Tu={zip215:!0};function Pu(r){let t=We(r);return Ct(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Zs(r){let t=Pu(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:c,h:a}=t,l=Dr<<BigInt(c*8)-Et,u=e.create,f=te(t.n,t.nBitLength),p=t.uvRatio||((y,d)=>{try{return{isValid:!0,value:e.sqrt(y*e.inv(d))}}catch{return{isValid:!1,value:Lt}}}),w=t.adjustScalarBytes||(y=>y),E=t.domain||((y,d,x)=>{if(It("phflag",x),d.length||x)throw new Error("Contexts/pre-hash are not supported");return y});function b(y,d){xt("coordinate "+y,d,Lt,l)}function h(y){if(!(y instanceof m))throw new Error("ExtendedPoint expected")}let g=he((y,d)=>{let{ex:x,ey:A,ez:R}=y,D=y.is0();d==null&&(d=D?_u:e.inv(R));let U=u(x*d),O=u(A*d),N=u(R*d);if(D)return{x:Lt,y:Et};if(N!==Et)throw new Error("invZ was invalid");return{x:U,y:O}}),S=he(y=>{let{a:d,d:x}=t;if(y.is0())throw new Error("bad point: ZERO");let{ex:A,ey:R,ez:D,et:U}=y,O=u(A*A),N=u(R*R),H=u(D*D),z=u(H*H),ot=u(O*d),st=u(H*u(ot+N)),at=u(z+u(x*u(O*N)));if(st!==at)throw new Error("bad point: equation left != right (1)");let ct=u(A*R),bt=u(D*U);if(ct!==bt)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(d,x,A,R){this.ex=d,this.ey=x,this.ez=A,this.et=R,b("x",d),b("y",x),b("z",A),b("t",R),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(d){if(d instanceof m)throw new Error("extended point not allowed");let{x,y:A}=d||{};return b("x",x),b("y",A),new m(x,A,Et,u(x*A))}static normalizeZ(d){let x=e.invertBatch(d.map(A=>A.ez));return d.map((A,R)=>A.toAffine(x[R])).map(m.fromAffine)}static msm(d,x){return Rr(m,f,d,x)}_setWindowSize(d){C.setWindowSize(this,d)}assertValidity(){S(this)}equals(d){h(d);let{ex:x,ey:A,ez:R}=this,{ex:D,ey:U,ez:O}=d,N=u(x*O),H=u(D*R),z=u(A*O),ot=u(U*R);return N===H&&z===ot}is0(){return this.equals(m.ZERO)}negate(){return new m(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:d}=t,{ex:x,ey:A,ez:R}=this,D=u(x*x),U=u(A*A),O=u(Dr*u(R*R)),N=u(d*D),H=x+A,z=u(u(H*H)-D-U),ot=N+U,st=ot-O,at=N-U,ct=u(z*st),bt=u(ot*at),pt=u(z*at),Pt=u(st*ot);return new m(ct,bt,Pt,pt)}add(d){h(d);let{a:x,d:A}=t,{ex:R,ey:D,ez:U,et:O}=this,{ex:N,ey:H,ez:z,et:ot}=d;if(x===BigInt(-1)){let Wo=u((D-R)*(H+N)),$o=u((D+R)*(H-N)),sn=u($o-Wo);if(sn===Lt)return this.double();let Xo=u(U*Dr*ot),Jo=u(O*Dr*z),Qo=Jo+Xo,ts=$o+Wo,es=Jo-Xo,oa=u(Qo*sn),sa=u(ts*es),ia=u(Qo*es),aa=u(sn*ts);return new m(oa,sa,aa,ia)}let st=u(R*N),at=u(D*H),ct=u(O*A*ot),bt=u(U*z),pt=u((R+D)*(N+H)-st-at),Pt=bt-ct,Dt=bt+ct,Oe=u(at-x*st),ta=u(pt*Pt),ea=u(Dt*Oe),ra=u(pt*Oe),na=u(Pt*Dt);return new m(ta,ea,na,ra)}subtract(d){return this.add(d.negate())}wNAF(d){return C.wNAFCached(this,d,m.normalizeZ)}multiply(d){let x=d;xt("scalar",x,Et,n);let{p:A,f:R}=this.wNAF(x);return m.normalizeZ([A,R])[0]}multiplyUnsafe(d,x=m.ZERO){let A=d;return xt("scalar",A,Lt,n),A===Lt?P:this.is0()||A===Et?this:C.wNAFCachedUnsafe(this,A,m.normalizeZ,x)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}isTorsionFree(){return C.unsafeLadder(this,n).is0()}toAffine(d){return g(this,d)}clearCofactor(){let{h:d}=t;return d===Et?this:this.multiplyUnsafe(d)}static fromHex(d,x=!1){let{d:A,a:R}=t,D=e.BYTES;d=X("pointHex",d,D),It("zip215",x);let U=d.slice(),O=d[D-1];U[D-1]=O&-129;let N=Jt(U),H=x?l:e.ORDER;xt("pointHex.y",N,Lt,H);let z=u(N*N),ot=u(z-Et),st=u(A*z-R),{isValid:at,value:ct}=p(ot,st);if(!at)throw new Error("Point.fromHex: invalid y coordinate");let bt=(ct&Et)===Et,pt=(O&128)!==0;if(!x&&ct===Lt&&pt)throw new Error("Point.fromHex: x=0 and x_0=1");return pt!==bt&&(ct=u(-ct)),m.fromAffine({x:ct,y:N})}static fromPrivateKey(d){return L(d).point}toRawBytes(){let{x:d,y:x}=this.toAffine(),A=le(x,e.BYTES);return A[A.length-1]|=d&Et?128:0,A}toHex(){return Mt(this.toRawBytes())}}m.BASE=new m(t.Gx,t.Gy,Et,u(t.Gx*t.Gy)),m.ZERO=new m(Lt,Et,Et,Lt);let{BASE:B,ZERO:P}=m,C=Cr(m,c*8);function I(y){return V(y,n)}function T(y){return I(Jt(y))}function L(y){let d=e.BYTES;y=X("private key",y,d);let x=X("hashed private key",s(y),2*d),A=w(x.slice(0,d)),R=x.slice(d,2*d),D=T(A),U=B.multiply(D),O=U.toRawBytes();return{head:A,prefix:R,scalar:D,point:U,pointBytes:O}}function j(y){return L(y).pointBytes}function M(y=new Uint8Array,...d){let x=Ht(...d);return T(s(E(x,X("context",y),!!o)))}function k(y,d,x={}){y=X("message",y),o&&(y=o(y));let{prefix:A,scalar:R,pointBytes:D}=L(d),U=M(x.context,A,y),O=B.multiply(U).toRawBytes(),N=M(x.context,O,D,y),H=I(U+N*R);xt("signature.s",H,Lt,n);let z=Ht(O,le(H,e.BYTES));return X("result",z,e.BYTES*2)}let et=Tu;function v(y,d,x,A=et){let{context:R,zip215:D}=A,U=e.BYTES;y=X("signature",y,2*U),d=X("message",d),x=X("publicKey",x,U),D!==void 0&&It("zip215",D),o&&(d=o(d));let O=Jt(y.slice(U,2*U)),N,H,z;try{N=m.fromHex(x,D),H=m.fromHex(y.slice(0,U),D),z=B.multiplyUnsafe(O)}catch{return!1}if(!D&&N.isSmallOrder())return!1;let ot=M(R,H.toRawBytes(),N.toRawBytes(),d);return H.add(N.multiplyUnsafe(ot)).subtract(z).clearCofactor().equals(m.ZERO)}return B._setWindowSize(8),{CURVE:t,getPublicKey:j,sign:k,verify:v,ExtendedPoint:m,utils:{getExtendedPublicKey:L,randomPrivateKey:()=>i(e.BYTES),precompute(y=8,d=m.BASE){return d._setWindowSize(y),d.multiply(BigInt(3)),d}}}}var Jn=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Ys=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Vh=BigInt(0),Cu=BigInt(1),Ws=BigInt(2),zh=BigInt(3),Ru=BigInt(5),Du=BigInt(8);function Nu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=Jn,c=r*r%s*r%s,a=Y(c,Ws,s)*c%s,l=Y(a,Cu,s)*r%s,u=Y(l,Ru,s)*l%s,f=Y(u,t,s)*u%s,p=Y(f,e,s)*f%s,w=Y(p,n,s)*p%s,E=Y(w,o,s)*w%s,b=Y(E,o,s)*w%s,h=Y(b,t,s)*u%s;return{pow_p_5_8:Y(h,Ws,s)*r%s,b2:c}}function Ku(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Uu(r,t){let e=Jn,n=V(t*t*t,e),o=V(n*n*t,e),s=Nu(r*o).pow_p_5_8,i=V(r*n*s,e),c=V(t*i*i,e),a=i,l=V(i*Ys,e),u=c===r,f=c===V(-r,e),p=c===V(-r*Ys,e);return u&&(i=a),(f||p)&&(i=l),Hs(i,e)&&(i=V(-i,e)),{isValid:u||f,value:i}}var ku=te(Jn,void 0,!0),Ou={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:ku,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Du,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Us,randomBytes:Pe,adjustScalarBytes:Ku,uvRatio:Uu},$s=Zs(Ou);var Nr=32;function Xs(r,t,e){return $s.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var Kr=class{type="Ed25519";raw;constructor(t){this.raw=Qn(t,Nr)}toMultihash(){return At.digest(kt(this))}toCID(){return ut.createV1(114,this.toMultihash())}toString(){return $.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:gt(this.raw,t.raw)}verify(t,e){return Xs(this.raw,e,t)}};function to(r){return r=Qn(r,Nr),new Kr(r)}function Qn(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 qu=Math.pow(2,7),Hu=Math.pow(2,14),Vu=Math.pow(2,21),eo=Math.pow(2,28),ro=Math.pow(2,35),no=Math.pow(2,42),oo=Math.pow(2,49),q=128,lt=127;function _t(r){if(r<qu)return 1;if(r<Hu)return 2;if(r<Vu)return 3;if(r<eo)return 4;if(r<ro)return 5;if(r<no)return 6;if(r<oo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function so(r,t,e=0){switch(_t(r)){case 8:t[e++]=r&255|q,r/=128;case 7:t[e++]=r&255|q,r/=128;case 6:t[e++]=r&255|q,r/=128;case 5:t[e++]=r&255|q,r/=128;case 4:t[e++]=r&255|q,r>>>=7;case 3:t[e++]=r&255|q,r>>>=7;case 2:t[e++]=r&255|q,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function zu(r,t,e=0){switch(_t(r)){case 8:t.set(e++,r&255|q),r/=128;case 7:t.set(e++,r&255|q),r/=128;case 6:t.set(e++,r&255|q),r/=128;case 5:t.set(e++,r&255|q),r/=128;case 4:t.set(e++,r&255|q),r>>>=7;case 3:t.set(e++,r&255|q),r>>>=7;case 2:t.set(e++,r&255|q),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function io(r,t){let e=r[t],n=0;if(n+=e<,e<q||(e=r[t+1],n+=(e<)<<7,e<q)||(e=r[t+2],n+=(e<)<<14,e<q)||(e=r[t+3],n+=(e<)<<21,e<q)||(e=r[t+4],n+=(e<)*eo,e<q)||(e=r[t+5],n+=(e<)*ro,e<q)||(e=r[t+6],n+=(e<)*no,e<q)||(e=r[t+7],n+=(e<)*oo,e<q))return n;throw new RangeError("Could not decode varint")}function Fu(r,t){let e=r.get(t),n=0;if(n+=e<,e<q||(e=r.get(t+1),n+=(e<)<<7,e<q)||(e=r.get(t+2),n+=(e<)<<14,e<q)||(e=r.get(t+3),n+=(e<)<<21,e<q)||(e=r.get(t+4),n+=(e<)*eo,e<q)||(e=r.get(t+5),n+=(e<)*ro,e<q)||(e=r.get(t+6),n+=(e<)*no,e<q)||(e=r.get(t+7),n+=(e<)*oo,e<q))return n;throw new RangeError("Could not decode varint")}function Qs(r,t,e=0){return t==null&&(t=ft(_t(r))),t instanceof Uint8Array?so(r,t,e):zu(r,t,e)}function ti(r,t=0){return r instanceof Uint8Array?io(r,t):Fu(r,t)}var ao=new Float32Array([-0]),ee=new Uint8Array(ao.buffer);function ri(r,t,e){ao[0]=r,t[e]=ee[0],t[e+1]=ee[1],t[e+2]=ee[2],t[e+3]=ee[3]}function ni(r,t){return ee[0]=r[t],ee[1]=r[t+1],ee[2]=r[t+2],ee[3]=r[t+3],ao[0]}var co=new Float64Array([-0]),ht=new Uint8Array(co.buffer);function oi(r,t,e){co[0]=r,t[e]=ht[0],t[e+1]=ht[1],t[e+2]=ht[2],t[e+3]=ht[3],t[e+4]=ht[4],t[e+5]=ht[5],t[e+6]=ht[6],t[e+7]=ht[7]}function si(r,t){return ht[0]=r[t],ht[1]=r[t+1],ht[2]=r[t+2],ht[3]=r[t+3],ht[4]=r[t+4],ht[5]=r[t+5],ht[6]=r[t+6],ht[7]=r[t+7],co[0]}var Gu=BigInt(Number.MAX_SAFE_INTEGER),ju=BigInt(Number.MIN_SAFE_INTEGER),St=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 pe;if(t<Gu&&t>ju)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>ii&&(o=0n,++n>ii&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return pe;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):pe}},pe=new St(0,0);pe.toBigInt=function(){return 0n};pe.zzEncode=pe.zzDecode=function(){return this};pe.length=function(){return 1};var ii=4294967296n;function ai(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function ci(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 uo(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 Tt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Ur(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var fo=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,Tt(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 Tt(this,4);return Ur(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Tt(this,4);return Ur(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Tt(this,4);let t=ni(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Tt(this,4);let t=si(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw Tt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return ci(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Tt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Tt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new St(0,0),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 Tt(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 Tt(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 Tt(this,8);let t=Ur(this.buf,this.pos+=4),e=Ur(this.buf,this.pos+=4);return new St(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=io(this.buf,this.pos);return this.pos+=_t(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 lo(r){return new fo(r instanceof Uint8Array?r:r.subarray())}function kr(r,t,e){let n=lo(r);return t.decode(n,void 0,e)}function ho(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return ft(i);o+i>t&&(n=ft(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var me=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function po(){}var yo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Zu=ho();function Yu(r){return globalThis.Buffer!=null?ft(r):Zu(r)}var Xe=class{len;head;tail;states;constructor(){this.len=0,this.head=new me(po,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new me(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new bo((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(Or,10,St.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=St.fromBigInt(t);return this._push(Or,e.length(),e)}uint64Number(t){return this._push(so,_t(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=St.fromBigInt(t).zzEncode();return this._push(Or,e.length(),e)}sint64Number(t){let e=St.fromNumber(t).zzEncode();return this._push(Or,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(mo,1,t?1:0)}fixed32(t){return this._push($e,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=St.fromBigInt(t);return this._push($e,4,e.lo)._push($e,4,e.hi)}fixed64Number(t){let e=St.fromNumber(t);return this._push($e,4,e.lo)._push($e,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(ri,4,t)}double(t){return this._push(oi,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(mo,1,0):this.uint32(e)._push($u,e,t)}string(t){let e=ai(t);return e!==0?this.uint32(e)._push(uo,e,t):this._push(mo,1,0)}fork(){return this.states=new yo(this),this.head=this.tail=new me(po,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 me(po,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=Yu(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function mo(r,t,e){t[e]=r&255}function Wu(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var bo=class extends me{next;constructor(t,e){super(Wu,t,e),this.next=void 0}};function Or(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 $e(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 $u(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(Xu,t,r),this},Xe.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Ju,t,r),this});function Xu(r,t,e){t.set(r,e)}function Ju(r,t,e){r.length<40?uo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(F(r),e)}function go(){return new Xe}function Mr(r,t){let e=go();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var De;(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"})(De||(De={}));function qr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function wo(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 qr("enum",De.VARINT,e,n)}function Hr(r,t){return qr("message",De.LENGTH_DELIMITED,r,t)}var tt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(tt||(tt={}));var xo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(xo||(xo={}));(function(r){r.codec=()=>wo(xo)})(tt||(tt={}));var Rt;(function(r){let t;r.codec=()=>(t==null&&(t=Hr((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=>Mr(e,r.codec()),r.decode=(e,n)=>kr(e,r.codec(),n)})(Rt||(Rt={}));var Eo;(function(r){let t;r.codec=()=>(t==null&&(t=Hr((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=>Mr(e,r.codec()),r.decode=(e,n)=>kr(e,r.codec(),n)})(Eo||(Eo={}));function Vr(r){if(isNaN(r)||r<=0)throw new W("random bytes length must be a Number bigger than 0");return Pe(r)}var Je=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},zr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var li={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new zr("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 re=li;var tr={};mt(tr,{MAX_RSA_KEY_SIZE:()=>vo,generateRSAKeyPair:()=>mi,jwkToJWKKeyPair:()=>yi,jwkToPkcs1:()=>nf,jwkToPkix:()=>Lo,jwkToRSAPrivateKey:()=>Co,pkcs1MessageToJwk:()=>Bo,pkcs1MessageToRSAPrivateKey:()=>_o,pkcs1ToJwk:()=>rf,pkcs1ToRSAPrivateKey:()=>pi,pkixMessageToJwk:()=>Io,pkixMessageToRSAPublicKey:()=>Po,pkixToJwk:()=>of,pkixToRSAPublicKey:()=>To});var Qu=new Uint32Array([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]),ne=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),oe=new Uint32Array(64),So=class extends Ce{constructor(){super(64,32,8,!1),this.A=ne[0]|0,this.B=ne[1]|0,this.C=ne[2]|0,this.D=ne[3]|0,this.E=ne[4]|0,this.F=ne[5]|0,this.G=ne[6]|0,this.H=ne[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)oe[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let p=oe[f-15],w=oe[f-2],E=Bt(p,7)^Bt(p,18)^p>>>3,b=Bt(w,17)^Bt(w,19)^w>>>10;oe[f]=b+oe[f-7]+E+oe[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 p=Bt(c,6)^Bt(c,11)^Bt(c,25),w=u+p+Ds(c,a,l)+Qu[f]+oe[f]|0,b=(Bt(n,2)^Bt(n,13)^Bt(n,22))+Ns(n,o,s)|0;u=l,l=a,a=c,c=i+w|0,i=s,s=o,o=n,n=w+b|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(){oe.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Ne=Ar(()=>new So);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=tr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ut.createV1(114,this._multihash)}toString(){return $.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:gt(this.raw,t.raw)}verify(t,e){return di(this.jwk,e,t)}},Qe=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=tr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:gt(this.raw,t.raw)}sign(t){return hi(this.jwk,t)}};var vo=8192,Ao=18,tf=1062,ef=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function rf(r){let t=Ut(r);return Bo(t)}function Bo(r){return{n:G(r[1],"base64url"),e:G(r[2],"base64url"),d:G(r[3],"base64url"),p:G(r[4],"base64url"),q:G(r[5],"base64url"),dp:G(r[6],"base64url"),dq:G(r[7],"base64url"),qi:G(r[8],"base64url"),kty:"RSA"}}function nf(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 Yt([wt(Uint8Array.from([0])),wt(F(r.n,"base64url")),wt(F(r.e,"base64url")),wt(F(r.d,"base64url")),wt(F(r.p,"base64url")),wt(F(r.q,"base64url")),wt(F(r.dp,"base64url")),wt(F(r.dq,"base64url")),wt(F(r.qi,"base64url"))]).subarray()}function of(r){let t=Ut(r,{offset:0});return Io(t)}function Io(r){let t=Ut(r[1],{offset:0});return{kty:"RSA",n:G(t[0],"base64url"),e:G(t[1],"base64url")}}function Lo(r){if(r.n==null||r.e==null)throw new W("JWK was missing components");return Yt([ef,Sr(Yt([wt(F(r.n,"base64url")),wt(F(r.e,"base64url"))]))]).subarray()}function pi(r){let t=Ut(r);return _o(t)}function _o(r){let t=Bo(r);return Co(t)}function To(r,t){if(r.byteLength>=tf)throw new we("Key size is too large");let e=Ut(r,{offset:0});return Po(e,r,t)}function Po(r,t,e){let n=Io(r);if(e==null){let o=Ne(Rt.encode({Type:tt.RSA,Data:t}));e=vt(Ao,o)}return new Ke(n,e)}function Co(r){if(gi(r)>vo)throw new W("Key size is too large");let t=yi(r),e=Ne(Rt.encode({Type:tt.RSA,Data:Lo(t.publicKey)})),n=vt(Ao,e);return new Qe(t.privateKey,new Ke(t.publicKey,n))}async function mi(r){if(r>vo)throw new W("Key size is too large");let t=await bi(r),e=Ne(Rt.encode({Type:tt.RSA,Data:Lo(t.publicKey)})),n=vt(Ao,e);return new Qe(t.privateKey,new Ke(t.publicKey,n))}function yi(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 bi(r){let t=await re.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),e=await sf(t);return{privateKey:e[0],publicKey:e[1]}}async function hi(r,t){let e=await re.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await re.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function di(r,t,e){let n=await re.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return re.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function sf(r){if(r.privateKey==null||r.publicKey==null)throw new W("Private and public key are required");return Promise.all([re.get().subtle.exportKey("jwk",r.privateKey),re.get().subtle.exportKey("jwk",r.publicKey)])}function gi(r){if(r.kty!=="RSA")throw new W("invalid key type");if(r.n==null)throw new W("invalid key modulus");return F(r.n,"base64url").length*8}var Fr=class extends Te{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Ps(t);let n=je(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),s.fill(0)}update(t){return _e(this),this.iHash.update(t),this}digestInto(t){_e(this),Le(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}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ro=(r,t,e)=>new Fr(r,t).update(e).digest();Ro.create=(r,t)=>new Fr(r,t);function wi(r){r.lowS!==void 0&&It("lowS",r.lowS),r.prehash!==void 0&&It("prehash",r.prehash)}function af(r){let t=We(r);Ct(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:o}=t;if(e){if(!n.eql(o,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:cf,hexToBytes:uf}=_r,Do=class extends Error{constructor(t=""){super(t)}},Vt={Err:Do,_tlv:{encode:(r,t)=>{let{Err:e}=Vt;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=ue(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?ue(o.length/2|128):"";return ue(r)+s+o+t},decode(r,t){let{Err:e}=Vt,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}=Vt;if(r<zt)throw new t("integer: negative integers are not allowed");let e=ue(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}=Vt;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 cf(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Vt,o=typeof r=="string"?uf(r):r;Re(o);let{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}=Vt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},zt=BigInt(0),it=BigInt(1),Ep=BigInt(2),xi=BigInt(3),Sp=BigInt(4);function ff(r){let t=af(r),{Fp:e}=t,n=te(t.n,t.nBitLength),o=t.toBytes||((b,h,g)=>{let S=h.toAffine();return Ht(Uint8Array.from([4]),e.toBytes(S.x),e.toBytes(S.y))}),s=t.fromBytes||(b=>{let h=b.subarray(1),g=e.fromBytes(h.subarray(0,e.BYTES)),S=e.fromBytes(h.subarray(e.BYTES,2*e.BYTES));return{x:g,y:S}});function i(b){let{a:h,b:g}=t,S=e.sqr(b),m=e.mul(S,b);return e.add(e.add(m,e.mul(b,h)),g)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function c(b){return Ze(b,it,t.n)}function a(b){let{allowedPrivateKeyLengths:h,nByteLength:g,wrapPrivateKey:S,n:m}=t;if(h&&typeof b!="bigint"){if(Xt(b)&&(b=Mt(b)),typeof b!="string"||!h.includes(b.length))throw new Error("invalid private key");b=b.padStart(g*2,"0")}let B;try{B=typeof b=="bigint"?b:qt(X("private key",b,g))}catch{throw new Error("invalid private key, expected hex or "+g+" bytes, got "+typeof b)}return S&&(B=V(B,m)),xt("private key",B,it,m),B}function l(b){if(!(b instanceof p))throw new Error("ProjectivePoint expected")}let u=he((b,h)=>{let{px:g,py:S,pz:m}=b;if(e.eql(m,e.ONE))return{x:g,y:S};let B=b.is0();h==null&&(h=B?e.ONE:e.inv(m));let P=e.mul(g,h),C=e.mul(S,h),I=e.mul(m,h);if(B)return{x:e.ZERO,y:e.ZERO};if(!e.eql(I,e.ONE))throw new Error("invZ was invalid");return{x:P,y:C}}),f=he(b=>{if(b.is0()){if(t.allowInfinityPoint&&!e.is0(b.py))return;throw new Error("bad point: ZERO")}let{x:h,y:g}=b.toAffine();if(!e.isValid(h)||!e.isValid(g))throw new Error("bad point: x or y not FE");let S=e.sqr(g),m=i(h);if(!e.eql(S,m))throw new Error("bad point: equation left != right");if(!b.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class p{constructor(h,g,S){if(this.px=h,this.py=g,this.pz=S,h==null||!e.isValid(h))throw new Error("x required");if(g==null||!e.isValid(g))throw new Error("y required");if(S==null||!e.isValid(S))throw new Error("z required");Object.freeze(this)}static fromAffine(h){let{x:g,y:S}=h||{};if(!h||!e.isValid(g)||!e.isValid(S))throw new Error("invalid affine point");if(h instanceof p)throw new Error("projective point not allowed");let m=B=>e.eql(B,e.ZERO);return m(g)&&m(S)?p.ZERO:new p(g,S,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let g=e.invertBatch(h.map(S=>S.pz));return h.map((S,m)=>S.toAffine(g[m])).map(p.fromAffine)}static fromHex(h){let g=p.fromAffine(s(X("pointHex",h)));return g.assertValidity(),g}static fromPrivateKey(h){return p.BASE.multiply(a(h))}static msm(h,g){return Rr(p,n,h,g)}_setWindowSize(h){E.setWindowSize(this,h)}assertValidity(){f(this)}hasEvenY(){let{y:h}=this.toAffine();if(e.isOdd)return!e.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){l(h);let{px:g,py:S,pz:m}=this,{px:B,py:P,pz:C}=h,I=e.eql(e.mul(g,C),e.mul(B,m)),T=e.eql(e.mul(S,C),e.mul(P,m));return I&&T}negate(){return new p(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b:g}=t,S=e.mul(g,xi),{px:m,py:B,pz:P}=this,C=e.ZERO,I=e.ZERO,T=e.ZERO,L=e.mul(m,m),j=e.mul(B,B),M=e.mul(P,P),k=e.mul(m,B);return k=e.add(k,k),T=e.mul(m,P),T=e.add(T,T),C=e.mul(h,T),I=e.mul(S,M),I=e.add(C,I),C=e.sub(j,I),I=e.add(j,I),I=e.mul(C,I),C=e.mul(k,C),T=e.mul(S,T),M=e.mul(h,M),k=e.sub(L,M),k=e.mul(h,k),k=e.add(k,T),T=e.add(L,L),L=e.add(T,L),L=e.add(L,M),L=e.mul(L,k),I=e.add(I,L),M=e.mul(B,P),M=e.add(M,M),L=e.mul(M,k),C=e.sub(C,L),T=e.mul(M,j),T=e.add(T,T),T=e.add(T,T),new p(C,I,T)}add(h){l(h);let{px:g,py:S,pz:m}=this,{px:B,py:P,pz:C}=h,I=e.ZERO,T=e.ZERO,L=e.ZERO,j=t.a,M=e.mul(t.b,xi),k=e.mul(g,B),et=e.mul(S,P),v=e.mul(m,C),_=e.add(g,S),y=e.add(B,P);_=e.mul(_,y),y=e.add(k,et),_=e.sub(_,y),y=e.add(g,m);let d=e.add(B,C);return y=e.mul(y,d),d=e.add(k,v),y=e.sub(y,d),d=e.add(S,m),I=e.add(P,C),d=e.mul(d,I),I=e.add(et,v),d=e.sub(d,I),L=e.mul(j,y),I=e.mul(M,v),L=e.add(I,L),I=e.sub(et,L),L=e.add(et,L),T=e.mul(I,L),et=e.add(k,k),et=e.add(et,k),v=e.mul(j,v),y=e.mul(M,y),et=e.add(et,v),v=e.sub(k,v),v=e.mul(j,v),y=e.add(y,v),k=e.mul(et,y),T=e.add(T,k),k=e.mul(d,y),I=e.mul(_,I),I=e.sub(I,k),k=e.mul(_,et),L=e.mul(d,L),L=e.add(L,k),new p(I,T,L)}subtract(h){return this.add(h.negate())}is0(){return this.equals(p.ZERO)}wNAF(h){return E.wNAFCached(this,h,p.normalizeZ)}multiplyUnsafe(h){let{endo:g,n:S}=t;xt("scalar",h,zt,S);let m=p.ZERO;if(h===zt)return m;if(this.is0()||h===it)return this;if(!g||E.hasPrecomputes(this))return E.wNAFCachedUnsafe(this,h,p.normalizeZ);let{k1neg:B,k1:P,k2neg:C,k2:I}=g.splitScalar(h),T=m,L=m,j=this;for(;P>zt||I>zt;)P&it&&(T=T.add(j)),I&it&&(L=L.add(j)),j=j.double(),P>>=it,I>>=it;return B&&(T=T.negate()),C&&(L=L.negate()),L=new p(e.mul(L.px,g.beta),L.py,L.pz),T.add(L)}multiply(h){let{endo:g,n:S}=t;xt("scalar",h,it,S);let m,B;if(g){let{k1neg:P,k1:C,k2neg:I,k2:T}=g.splitScalar(h),{p:L,f:j}=this.wNAF(C),{p:M,f:k}=this.wNAF(T);L=E.constTimeNegate(P,L),M=E.constTimeNegate(I,M),M=new p(e.mul(M.px,g.beta),M.py,M.pz),m=L.add(M),B=j.add(k)}else{let{p:P,f:C}=this.wNAF(h);m=P,B=C}return p.normalizeZ([m,B])[0]}multiplyAndAddUnsafe(h,g,S){let m=p.BASE,B=(C,I)=>I===zt||I===it||!C.equals(m)?C.multiplyUnsafe(I):C.multiply(I),P=B(this,g).add(B(h,S));return P.is0()?void 0:P}toAffine(h){return u(this,h)}isTorsionFree(){let{h,isTorsionFree:g}=t;if(h===it)return!0;if(g)return g(p,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:g}=t;return h===it?this:g?g(p,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return It("isCompressed",h),this.assertValidity(),o(p,this,h)}toHex(h=!0){return It("isCompressed",h),Mt(this.toRawBytes(h))}}p.BASE=new p(t.Gx,t.Gy,e.ONE),p.ZERO=new p(e.ZERO,e.ONE,e.ZERO);let w=t.nBitLength,E=Cr(p,t.endo?Math.ceil(w/2):w);return{CURVE:t,ProjectivePoint:p,normPrivateKeyToScalar:a,weierstrassEquation:i,isWithinCurveOrder:c}}function lf(r){let t=We(r);return Ct(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Ei(r){let t=lf(r),{Fp:e,n}=t,o=e.BYTES+1,s=2*e.BYTES+1;function i(v){return V(v,n)}function c(v){return Tr(v,n)}let{ProjectivePoint:a,normPrivateKeyToScalar:l,weierstrassEquation:u,isWithinCurveOrder:f}=ff({...t,toBytes(v,_,y){let d=_.toAffine(),x=e.toBytes(d.x),A=Ht;return It("isCompressed",y),y?A(Uint8Array.from([_.hasEvenY()?2:3]),x):A(Uint8Array.from([4]),x,e.toBytes(d.y))},fromBytes(v){let _=v.length,y=v[0],d=v.subarray(1);if(_===o&&(y===2||y===3)){let x=qt(d);if(!Ze(x,it,e.ORDER))throw new Error("Point is not on curve");let A=u(x),R;try{R=e.sqrt(A)}catch(O){let N=O instanceof Error?": "+O.message:"";throw new Error("Point is not on curve"+N)}let D=(R&it)===it;return(y&1)===1!==D&&(R=e.neg(R)),{x,y:R}}else if(_===s&&y===4){let x=e.fromBytes(d.subarray(0,e.BYTES)),A=e.fromBytes(d.subarray(e.BYTES,2*e.BYTES));return{x,y:A}}else{let x=o,A=s;throw new Error("invalid Point, expected length of "+x+", or uncompressed "+A+", got "+_)}}}),p=v=>Mt(Qt(v,t.nByteLength));function w(v){let _=n>>it;return v>_}function E(v){return w(v)?i(-v):v}let b=(v,_,y)=>qt(v.slice(_,y));class h{constructor(_,y,d){this.r=_,this.s=y,this.recovery=d,this.assertValidity()}static fromCompact(_){let y=t.nByteLength;return _=X("compactSignature",_,y*2),new h(b(_,0,y),b(_,y,2*y))}static fromDER(_){let{r:y,s:d}=Vt.toSig(X("DER",_));return new h(y,d)}assertValidity(){xt("r",this.r,it,n),xt("s",this.s,it,n)}addRecoveryBit(_){return new h(this.r,this.s,_)}recoverPublicKey(_){let{r:y,s:d,recovery:x}=this,A=C(X("msgHash",_));if(x==null||![0,1,2,3].includes(x))throw new Error("recovery id invalid");let R=x===2||x===3?y+t.n:y;if(R>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let D=(x&1)===0?"02":"03",U=a.fromHex(D+p(R)),O=c(R),N=i(-A*O),H=i(d*O),z=a.BASE.multiplyAndAddUnsafe(U,N,H);if(!z)throw new Error("point at infinify");return z.assertValidity(),z}hasHighS(){return w(this.s)}normalizeS(){return this.hasHighS()?new h(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return fe(this.toDERHex())}toDERHex(){return Vt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return fe(this.toCompactHex())}toCompactHex(){return p(this.r)+p(this.s)}}let g={isValidPrivateKey(v){try{return l(v),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let v=Zn(t.n);return zs(t.randomBytes(v),t.n)},precompute(v=8,_=a.BASE){return _._setWindowSize(v),_.multiply(BigInt(3)),_}};function S(v,_=!0){return a.fromPrivateKey(v).toRawBytes(_)}function m(v){let _=Xt(v),y=typeof v=="string",d=(_||y)&&v.length;return _?d===o||d===s:y?d===2*o||d===2*s:v instanceof a}function B(v,_,y=!0){if(m(v))throw new Error("first arg must be private key");if(!m(_))throw new Error("second arg must be public key");return a.fromHex(_).multiply(l(v)).toRawBytes(y)}let P=t.bits2int||function(v){if(v.length>8192)throw new Error("input is too large");let _=qt(v),y=v.length*8-t.nBitLength;return y>0?_>>BigInt(y):_},C=t.bits2int_modN||function(v){return i(P(v))},I=Ye(t.nBitLength);function T(v){return xt("num < 2^"+t.nBitLength,v,zt,I),Qt(v,t.nByteLength)}function L(v,_,y=j){if(["recovered","canonical"].some(st=>st in y))throw new Error("sign() legacy options not supported");let{hash:d,randomBytes:x}=t,{lowS:A,prehash:R,extraEntropy:D}=y;A==null&&(A=!0),v=X("msgHash",v),wi(y),R&&(v=X("prehashed msgHash",d(v)));let U=C(v),O=l(_),N=[T(O),T(U)];if(D!=null&&D!==!1){let st=D===!0?x(e.BYTES):D;N.push(X("extraEntropy",st))}let H=Ht(...N),z=U;function ot(st){let at=P(st);if(!f(at))return;let ct=c(at),bt=a.BASE.multiply(at).toAffine(),pt=i(bt.x);if(pt===zt)return;let Pt=i(ct*i(z+pt*O));if(Pt===zt)return;let Dt=(bt.x===pt?0:2)|Number(bt.y&it),Oe=Pt;return A&&w(Pt)&&(Oe=E(Pt),Dt^=1),new h(pt,Oe,Dt)}return{seed:H,k2sig:ot}}let j={lowS:t.lowS,prehash:!1},M={lowS:t.lowS,prehash:!1};function k(v,_,y=j){let{seed:d,k2sig:x}=L(v,_,y),A=t;return zn(A.hash.outputLen,A.nByteLength,A.hmac)(d,x)}a.BASE._setWindowSize(8);function et(v,_,y,d=M){let x=v;_=X("msgHash",_),y=X("publicKey",y);let{lowS:A,prehash:R,format:D}=d;if(wi(d),"strict"in d)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 U=typeof x=="string"||Xt(x),O=!U&&!D&&typeof x=="object"&&x!==null&&typeof x.r=="bigint"&&typeof x.s=="bigint";if(!U&&!O)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let N,H;try{if(O&&(N=new h(x.r,x.s)),U){try{D!=="compact"&&(N=h.fromDER(x))}catch(Dt){if(!(Dt instanceof Vt.Err))throw Dt}!N&&D!=="der"&&(N=h.fromCompact(x))}H=a.fromHex(y)}catch{return!1}if(!N||A&&N.hasHighS())return!1;R&&(_=t.hash(_));let{r:z,s:ot}=N,st=C(_),at=c(ot),ct=i(st*at),bt=i(z*at),pt=a.BASE.multiplyAndAddUnsafe(H,ct,bt)?.toAffine();return pt?i(pt.x)===z:!1}return{CURVE:t,getPublicKey:S,getSharedSecret:B,sign:k,verify:et,ProjectivePoint:a,Signature:h,utils:g}}function hf(r){return{hash:r,hmac:(t,...e)=>Ro(r,t,Un(...e)),randomBytes:Pe}}function Si(r,t){let e=n=>Ei({...r,...hf(n)});return{...e(t),create:e}}var Bi=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),vi=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),df=BigInt(1),No=BigInt(2),Ai=(r,t)=>(r+t/No)/t;function pf(r){let t=Bi,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,p=Y(f,e,t)*u%t,w=Y(p,No,t)*l%t,E=Y(w,o,t)*w%t,b=Y(E,s,t)*E%t,h=Y(b,c,t)*b%t,g=Y(h,a,t)*h%t,S=Y(g,c,t)*b%t,m=Y(S,e,t)*u%t,B=Y(m,i,t)*E%t,P=Y(B,n,t)*l%t,C=Y(P,No,t);if(!Ko.eql(Ko.sqr(C),r))throw new Error("Cannot find square root");return C}var Ko=te(Bi,void 0,void 0,{sqrt:pf}),ye=Si({a:BigInt(0),b:BigInt(7),Fp:Ko,n:vi,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=vi,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-df*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),c=Ai(s*r,t),a=Ai(-n*r,t),l=V(r-c*e-a*o,t),u=V(-c*n-a*s,t),f=l>i,p=u>i;if(f&&(l=t-l),p&&(u=t-u),l>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:l,k2neg:p,k2:u}}}},Ne),Cp=BigInt(0);var Rp=ye.ProjectivePoint;function Ii(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Li(r,t,e){let n=ae.digest(e instanceof Uint8Array?e:e.subarray());if(Ii(n))return n.then(({digest:o})=>ye.verify(t,o,r)).catch(o=>{throw new Je(String(o))});try{return ye.verify(t,n.digest,r)}catch(o){throw new Je(String(o))}}var Gr=class{type="secp256k1";raw;_key;constructor(t){this._key=Ti(t),this.raw=_i(this._key)}toMultihash(){return At.digest(kt(this))}toCID(){return ut.createV1(114,this.toMultihash())}toString(){return $.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:gt(this.raw,t.raw)}verify(t,e){return Li(this._key,e,t)}};function Uo(r){return new Gr(r)}function _i(r){return ye.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Ti(r){try{return ye.ProjectivePoint.fromHex(r),r}catch(t){throw new we(String(t))}}function ko(r,t){let{Type:e,Data:n}=Rt.decode(r),o=n??new Uint8Array;switch(e){case tt.RSA:return To(o,t);case tt.Ed25519:return to(o);case tt.secp256k1:return Uo(o);case tt.ECDSA:return Kn(o);default:throw new se}}function Pi(r){let{Type:t,Data:e}=Rt.decode(r.digest),n=e??new Uint8Array;switch(t){case tt.Ed25519:return to(n);case tt.secp256k1:return Uo(n);case tt.ECDSA:return Kn(n);default:throw new se}}function kt(r){return Rt.encode({Type:tt[r.type],Data:r.raw})}var Ci=Symbol.for("nodejs.util.inspect.custom"),mf=114,er=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()})`}[an]=!0;toString(){return this.string==null&&(this.string=$.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ut.createV1(mf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return gt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return gt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ci](){return`PeerId(${this.toString()})`}},rr=class extends er{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},nr=class extends er{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},or=class extends er{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},yf=2336,jr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=At.digest(F(this.url))}[Ci](){return`PeerId(${this.url})`}[an]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ut.createV1(yf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=G(t)),t.toString()===this.toString())}};function Oo(r){if(r.type==="Ed25519")return new nr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new or({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new rr({multihash:r.toCID().multihash,publicKey:r});throw new se}function Ri(r){return Oo(r.publicKey)}function sr(r){if(gf(r))return new rr({multihash:r});if(bf(r))try{let t=Pi(r);if(t.type==="Ed25519")return new nr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new or({multihash:r,publicKey:t})}catch{let e=G(r.digest);return new jr(new URL(e))}throw new br("Supplied PeerID Multihash is invalid")}function bf(r){return r.code===At.code}function gf(r){return r.code===ae.code}function be(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 Zr(r){let t=jt($.decode(`z${r}`));return sr(t)}var ir=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 be(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 be(this.map.values(),t=>t.key)}values(){return be(this.map.values(),t=>t.value)}get size(){return this.map.size}};var ar=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 be(this.set.entries(),t=>{let e=Zr(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Zr(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return be(this.set.values(),t=>Zr(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 Ft(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Yr=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}},Ue=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Yr(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 Yr(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 Mo=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Wr(r={}){return wf(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 wf(r,t){t=t??{};let e=t.onEnd,n=new Ue,o,s,i,c=Ft(),a=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((h,g)=>{s=S=>{s=null,n.push(S);try{h(r(n))}catch(m){g(m)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=Ft()})}},l=h=>s!=null?s(h):(n.push(h),o),u=h=>(n=new Ue,s!=null?s({error:h}):(n.push({error:h}),o)),f=h=>{if(i)return o;if(t?.objectMode!==!0&&h?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:h})},p=h=>i?o:(i=!0,h!=null?u(h):l({done:!0})),w=()=>(n=new Ue,p(),{done:!0}),E=h=>(p(h),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:a,return:w,throw:E,push:f,end:p,get readableLength(){return n.size},onEmpty:async h=>{let g=h?.signal;if(g?.throwIfAborted(),n.isEmpty())return;let S,m;g!=null&&(S=new Promise((B,P)=>{m=()=>{P(new Mo)},g.addEventListener("abort",m)}));try{await Promise.race([c.promise,S])}finally{m!=null&&g!=null&&g?.removeEventListener("abort",m)}}},e==null)return o;let b=o;return o={[Symbol.asyncIterator](){return this},next(){return b.next()},throw(h){return b.throw(h),e!=null&&(e(h),e=void 0),{done:!0}},return(){return b.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(h){return b.end(h),e!=null&&(e(h),e=void 0),o},get readableLength(){return b.readableLength},onEmpty:h=>b.onEmpty(h)},o}var $r=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 Di(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new $r(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new $r(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 qo=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Ft(),this.haveNext=Ft()}[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=Ft(),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=Ft(),await Di(this.readNext.promise,e?.signal,e)}};function Ni(){return new qo}function xf(r){return r[Symbol.asyncIterator]!=null}async function Ef(r,t){try{await Promise.all(r.map(async e=>{for await(let n of e)await t.push(n)})),await t.end()}catch(e){await t.end(e).catch(()=>{})}}async function*Sf(r){let t=Ni();Ef(r,t).catch(()=>{}),yield*t}function*vf(r){for(let t of r)yield*t}function Af(...r){let t=[];for(let e of r)xf(e)||t.push(e);return t.length===r.length?vf(t):Sf(r)}var Ki=Af;function cr(r,...t){if(r==null)throw new Error("Empty pipeline");if(Ho(r)){let n=r;r=()=>n.source}else if(ki(r)||Ui(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&Ho(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++)Ho(e[n])&&(e[n]=If(e[n]));return Bf(...e)}var Bf=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},Ui=r=>r?.[Symbol.asyncIterator]!=null,ki=r=>r?.[Symbol.iterator]!=null,Ho=r=>r==null?!1:r.sink!=null&&r.source!=null,If=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=Wr({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let o,s=r.source;if(Ui(s))o=async function*(){yield*s,n.end()};else if(ki(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Ki(n,o())}return r.source};var zo=pa(Mi(),1);var fr=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},Fo=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},qi=r=>globalThis.DOMException===void 0?new Fo(r):new DOMException(r),Hi=r=>{let t=r.reason===void 0?qi("This operation was aborted."):r.reason;return t instanceof Error?t:qi(t)};function Go(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:w}=t;w.aborted&&f(Hi(w)),c=()=>{f(Hi(w))},w.addEventListener("abort",c,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(u,f);return}let p=new fr;i=s.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(w){f(w)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?u():o instanceof Error?f(o):(p.message=o??`Promise timed out after ${e} milliseconds`,f(p))},e),(async()=>{try{u(await r)}catch(w){f(w)}})()}).finally(()=>{l.clear(),c&&t.signal&&t.signal.removeEventListener("abort",c)});return l.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},l}function jo(r,t,e){let n=0,o=r.length;for(;o>0;){let s=Math.trunc(o/2),i=n+s;e(r[i],t)<=0?(n=++i,o-=s+1):o=s}return n}var lr=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 hr=class extends zo.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:lr,...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#B(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.#B(e.signal)]));let i=await s;n(i),this.emit("completed",i)}catch(s){if(s instanceof fr&&!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 Vi(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 zi(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Fi(r,t){let e=Vi(r).return?.();zi(e)&&e.catch(n=>{t.error("could not cause iterator to return",n)})}var Jr=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ke=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Qr=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},dr=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function tn(r){return r[Symbol.asyncIterator]!=null}function Gi(r,t){if(r.byteLength>t)throw new ke("Message length too long")}var rn=r=>{let t=_t(r),e=ft(t);return Qs(r,e),rn.bytes=t,e};rn.bytes=0;function nn(r,t){t=t??{};let e=t.lengthEncoder??rn,n=t?.maxDataLength??4194304;function*o(s){Gi(s,n);let i=e(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return tn(r)?async function*(){for await(let s of r)yield*o(s)}():function*(){for(let s of r)yield*o(s)}()}nn.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??rn,n=t?.maxDataLength??4194304;return Gi(r,n),new rt(e(r.byteLength),r)};var ge;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(ge||(ge={}));var Zo=r=>{let t=ti(r);return Zo.bytes=_t(t),t};Zo.bytes=0;function pr(r,t){let e=new rt,n=ge.LENGTH,o=-1,s=t?.lengthDecoder??Zo,i=t?.maxLengthLength??8,c=t?.maxDataLength??4194304;function*a(){for(;e.byteLength>0;){if(n===ge.LENGTH)try{if(o=s(e),o<0)throw new Jr("Invalid message length");if(o>c)throw new ke("Message length too long");let l=s.bytes;e.consume(l),t?.onLength!=null&&t.onLength(o),n=ge.DATA}catch(l){if(l instanceof RangeError){if(e.byteLength>i)throw new Qr("Message length length too long");break}throw l}if(n===ge.DATA){if(e.byteLength<o)break;let l=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(l),yield l,n=ge.LENGTH}}}return tn(r)?async function*(){for await(let l of r)e.append(l),yield*a();if(e.byteLength>0)throw new dr("Unexpected end of input")}():function*(){for(let l of r)e.append(l),yield*a();if(e.byteLength>0)throw new dr("Unexpected end of input")}()}pr.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 pr(n,{...t??{},onLength:s=>{e=s}})};var on=class extends xe{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 rt(t):t)}attachInboundStream(t,e){let n=()=>{Fi(t.source,this.log)};return this._inboundAbortController.signal.addEventListener("abort",n,{once:!0}),this._rawInboundStream=t,this.inboundStream=cr(this._rawInboundStream,o=>pr(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=Wr({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"))}}),cr(this.outboundStream,n=>nn(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 ji(){return BigInt(`0x${G(Vr(8),"base16")}`)}var Zi=(r,t)=>{let e=F(t.toString(16).padStart(16,"0"),"base16"),n=kt(r),o=new Uint8Array(n.byteLength+e.length);return o.set(n,0),o.set(e,n.byteLength),o},Yi=r=>ae.encode(r);var Wi=function(r){return Array.isArray(r)?r:[r]},Cf=async r=>{if(r.sequenceNumber==null||r.from==null||r.signature==null)return!1;let t=sr(jt(r.from));if(t.publicKey!=null)return!0;if(r.key!=null){let e=r.key;return Oo(ko(e)).equals(t)}return!1},$i=async r=>{if(r.from==null)throw new Q("RPC message was missing from");if(!await Cf(r))return{type:"unsigned",topic:r.topic??"",data:r.data??new Uint8Array(0)};let t=sr(jt(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: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}},mr=r=>r.type==="signed"?{from:r.from.toMultihash().bytes,data:r.data,sequenceNumber:Rf(r.sequenceNumber),topic:r.topic,signature:r.signature,key:r.key?kt(r.key):void 0}:{data:r.data,topic:r.topic},Rf=r=>{let t=r.toString(16);return t.length%2!==0&&(t=`0${t}`),F(t,"base16")},Df=r=>BigInt(`0x${G(r,"base16")}`);var Xi=F("libp2p-pubsub:");async function Ji(r,t,e){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:Ri(r)},o=ie([Xi,e(mr(n)).subarray()]);return n.signature=await r.sign(o),n.key=r.publicKey,n}async function Qi(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([Xi,t({...mr(r),signature:void 0,key:void 0}).subarray()]);return Nf(r).verify(e,r.signature)}function Nf(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 Yo=class extends xe{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=Wi(n),this.enabled=e.enabled!==!1,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new ir,this.globalSignaturePolicy=o==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=s,this.emitSelf=i,this.topicValidators=new Map,this.queue=new hr({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 on(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 cr(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 $i(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 ar,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 Zi(t.key,t.sequenceNumber);case"StrictNoSign":return Yi(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(mr)})}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 Qi(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===Me.Reject||s===Me.Ignore)throw new Q("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return Ji(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 gr("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:ji()};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 ma(Kf);})();
|
3
3
|
/*! Bundled license information:
|
4
4
|
|
5
5
|
@noble/hashes/esm/utils.js:
|
@@ -0,0 +1,32 @@
|
|
1
|
+
{
|
2
|
+
"PubSubBaseProtocol": "https://libp2p.github.io/js-libp2p/classes/_libp2p_pubsub.index.PubSubBaseProtocol.html",
|
3
|
+
".:PubSubBaseProtocol": "https://libp2p.github.io/js-libp2p/classes/_libp2p_pubsub.index.PubSubBaseProtocol.html",
|
4
|
+
"PubSubComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_pubsub.index.PubSubComponents.html",
|
5
|
+
".:PubSubComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_pubsub.index.PubSubComponents.html",
|
6
|
+
"PeerStreams": "https://libp2p.github.io/js-libp2p/classes/_libp2p_pubsub.peer_streams.PeerStreams.html",
|
7
|
+
"./peer-streams:PeerStreams": "https://libp2p.github.io/js-libp2p/classes/_libp2p_pubsub.peer_streams.PeerStreams.html",
|
8
|
+
"DecoderOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_pubsub.peer_streams.DecoderOptions.html",
|
9
|
+
"./peer-streams:DecoderOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_pubsub.peer_streams.DecoderOptions.html",
|
10
|
+
"PeerStreamsComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_pubsub.peer_streams.PeerStreamsComponents.html",
|
11
|
+
"./peer-streams:PeerStreamsComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_pubsub.peer_streams.PeerStreamsComponents.html",
|
12
|
+
"PeerStreamsInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_pubsub.peer_streams.PeerStreamsInit.html",
|
13
|
+
"./peer-streams:PeerStreamsInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_pubsub.peer_streams.PeerStreamsInit.html",
|
14
|
+
"anyMatch": "https://libp2p.github.io/js-libp2p/functions/_libp2p_pubsub.utils.anyMatch.html",
|
15
|
+
"./utils:anyMatch": "https://libp2p.github.io/js-libp2p/functions/_libp2p_pubsub.utils.anyMatch.html",
|
16
|
+
"bigIntFromBytes": "https://libp2p.github.io/js-libp2p/functions/_libp2p_pubsub.utils.bigIntFromBytes.html",
|
17
|
+
"./utils:bigIntFromBytes": "https://libp2p.github.io/js-libp2p/functions/_libp2p_pubsub.utils.bigIntFromBytes.html",
|
18
|
+
"bigIntToBytes": "https://libp2p.github.io/js-libp2p/functions/_libp2p_pubsub.utils.bigIntToBytes.html",
|
19
|
+
"./utils:bigIntToBytes": "https://libp2p.github.io/js-libp2p/functions/_libp2p_pubsub.utils.bigIntToBytes.html",
|
20
|
+
"ensureArray": "https://libp2p.github.io/js-libp2p/functions/_libp2p_pubsub.utils.ensureArray.html",
|
21
|
+
"./utils:ensureArray": "https://libp2p.github.io/js-libp2p/functions/_libp2p_pubsub.utils.ensureArray.html",
|
22
|
+
"msgId": "https://libp2p.github.io/js-libp2p/functions/_libp2p_pubsub.utils.msgId.html",
|
23
|
+
"./utils:msgId": "https://libp2p.github.io/js-libp2p/functions/_libp2p_pubsub.utils.msgId.html",
|
24
|
+
"noSignMsgId": "https://libp2p.github.io/js-libp2p/functions/_libp2p_pubsub.utils.noSignMsgId.html",
|
25
|
+
"./utils:noSignMsgId": "https://libp2p.github.io/js-libp2p/functions/_libp2p_pubsub.utils.noSignMsgId.html",
|
26
|
+
"randomSeqno": "https://libp2p.github.io/js-libp2p/functions/_libp2p_pubsub.utils.randomSeqno.html",
|
27
|
+
"./utils:randomSeqno": "https://libp2p.github.io/js-libp2p/functions/_libp2p_pubsub.utils.randomSeqno.html",
|
28
|
+
"toMessage": "https://libp2p.github.io/js-libp2p/functions/_libp2p_pubsub.utils.toMessage.html",
|
29
|
+
"./utils:toMessage": "https://libp2p.github.io/js-libp2p/functions/_libp2p_pubsub.utils.toMessage.html",
|
30
|
+
"toRpcMessage": "https://libp2p.github.io/js-libp2p/functions/_libp2p_pubsub.utils.toRpcMessage.html",
|
31
|
+
"./utils:toRpcMessage": "https://libp2p.github.io/js-libp2p/functions/_libp2p_pubsub.utils.toRpcMessage.html"
|
32
|
+
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@libp2p/pubsub",
|
3
|
-
"version": "10.1.
|
3
|
+
"version": "10.1.9",
|
4
4
|
"description": "libp2p pubsub base class",
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/pubsub#readme",
|
@@ -84,12 +84,12 @@
|
|
84
84
|
"test:electron-main": "aegir test -t electron-main"
|
85
85
|
},
|
86
86
|
"dependencies": {
|
87
|
-
"@libp2p/crypto": "5.0
|
88
|
-
"@libp2p/interface": "2.
|
89
|
-
"@libp2p/interface-internal": "2.3.
|
90
|
-
"@libp2p/peer-collections": "6.0.
|
91
|
-
"@libp2p/peer-id": "5.1.
|
92
|
-
"@libp2p/utils": "6.6.
|
87
|
+
"@libp2p/crypto": "^5.1.0",
|
88
|
+
"@libp2p/interface": "^2.8.0",
|
89
|
+
"@libp2p/interface-internal": "^2.3.10",
|
90
|
+
"@libp2p/peer-collections": "^6.0.26",
|
91
|
+
"@libp2p/peer-id": "^5.1.1",
|
92
|
+
"@libp2p/utils": "^6.6.1",
|
93
93
|
"it-length-prefixed": "^10.0.1",
|
94
94
|
"it-pipe": "^3.0.1",
|
95
95
|
"it-pushable": "^3.2.3",
|
@@ -99,7 +99,7 @@
|
|
99
99
|
"uint8arrays": "^5.1.0"
|
100
100
|
},
|
101
101
|
"devDependencies": {
|
102
|
-
"@libp2p/logger": "5.1.
|
102
|
+
"@libp2p/logger": "^5.1.14",
|
103
103
|
"@types/sinon": "^17.0.3",
|
104
104
|
"aegir": "^45.1.1",
|
105
105
|
"delay": "^6.0.0",
|