libp2p 3.5.1-ff95dc546 → 3.5.2-67732803f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +2 -2
- package/dist/index.min.js.map +2 -2
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +10 -10
- package/src/version.ts +1 -1
package/dist/index.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2P = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2P=(()=>{var Pm=Object.create;var Uo=Object.defineProperty;var Dm=Object.getOwnPropertyDescriptor;var Rm=Object.getOwnPropertyNames;var Om=Object.getPrototypeOf,km=Object.prototype.hasOwnProperty;var pf=(r,e)=>()=>{try{return e||r((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}},$e=(r,e)=>{for(var t in e)Uo(r,t,{get:e[t],enumerable:!0})},mf=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Rm(e))!km.call(r,o)&&o!==t&&Uo(r,o,{get:()=>e[o],enumerable:!(n=Dm(e,o))||n.enumerable});return r};var gf=(r,e,t)=>(t=r!=null?Pm(Om(r)):{},mf(e||!r||!r.__esModule?Uo(t,"default",{value:r,enumerable:!0}):t,r)),Nm=r=>mf(Uo({},"__esModule",{value:!0}),r);var lm=pf((vP,ql)=>{"use strict";var Uw=Object.prototype.hasOwnProperty,qe="~";function No(){}Object.create&&(No.prototype=Object.create(null),new No().__proto__||(qe=!1));function Kw(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function um(r,e,t,n,o){if(typeof t!="function")throw new TypeError("The listener must be a function");var s=new Kw(t,n||r,o),i=qe?qe+e:e;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 ga(r,e){--r._eventsCount===0?r._events=new No:delete r._events[e]}function ke(){this._events=new No,this._eventsCount=0}ke.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)Uw.call(t,n)&&e.push(qe?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};ke.prototype.listeners=function(e){var t=qe?qe+e:e,n=this._events[t];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};ke.prototype.listenerCount=function(e){var t=qe?qe+e:e,n=this._events[t];return n?n.fn?1:n.length:0};ke.prototype.emit=function(e,t,n,o,s,i){var a=qe?qe+e:e;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,l,f;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,o),!0;case 5:return c.fn.call(c.context,t,n,o,s),!0;case 6:return c.fn.call(c.context,t,n,o,s,i),!0}for(f=1,l=new Array(u-1);f<u;f++)l[f-1]=arguments[f];c.fn.apply(c.context,l)}else{var d=c.length,h;for(f=0;f<d;f++)switch(c[f].once&&this.removeListener(e,c[f].fn,void 0,!0),u){case 1:c[f].fn.call(c[f].context);break;case 2:c[f].fn.call(c[f].context,t);break;case 3:c[f].fn.call(c[f].context,t,n);break;case 4:c[f].fn.call(c[f].context,t,n,o);break;default:if(!l)for(h=1,l=new Array(u-1);h<u;h++)l[h-1]=arguments[h];c[f].fn.apply(c[f].context,l)}}return!0};ke.prototype.on=function(e,t,n){return um(this,e,t,n,!1)};ke.prototype.once=function(e,t,n){return um(this,e,t,n,!0)};ke.prototype.removeListener=function(e,t,n,o){var s=qe?qe+e:e;if(!this._events[s])return this;if(!t)return ga(this,s),this;var i=this._events[s];if(i.fn)i.fn===t&&(!o||i.once)&&(!n||i.context===n)&&ga(this,s);else{for(var a=0,c=[],u=i.length;a<u;a++)(i[a].fn!==t||o&&!i[a].once||n&&i[a].context!==n)&&c.push(i[a]);c.length?this._events[s]=c.length===1?c[0]:c:ga(this,s)}return this};ke.prototype.removeAllListeners=function(e){var t;return e?(t=qe?qe+e:e,this._events[t]&&ga(this,t)):(this._events=new No,this._eventsCount=0),this};ke.prototype.off=ke.prototype.removeListener;ke.prototype.addListener=ke.prototype.on;ke.prefixed=qe;ke.EventEmitter=ke;typeof ql<"u"&&(ql.exports=ke)});var pm=pf((HP,hm)=>{hm.exports=function(r){if(!r)throw Error("hashlru must have a max value, of type number, greater than 0");var e=0,t=Object.create(null),n=Object.create(null);function o(s,i){t[s]=i,e++,e>=r&&(e=0,n=t,t=Object.create(null))}return{has:function(s){return t[s]!==void 0||n[s]!==void 0},remove:function(s){t[s]!==void 0&&(t[s]=void 0),n[s]!==void 0&&(n[s]=void 0)},get:function(s){var i=t[s];if(i!==void 0)return i;if((i=n[s])!==void 0)return o(s,i),i},set:function(s,i){t[s]!==void 0?t[s]=i:o(s,i)},clear:function(){t=Object.create(null),n=Object.create(null)}}}});var px={};$e(px,{createLibp2p:()=>fx,dnsaddrResolver:()=>kr,isLibp2p:()=>hx});var yf=Symbol.for("@libp2p/connection");var Ma=Symbol.for("@libp2p/content-routing");var Qe=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}},Ko=class extends Error{static name="UnexpectedPeerError";constructor(e="Unexpected Peer"){super(e),this.name="UnexpectedPeerError"}};var T=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},mt=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}},_n=class extends Error{static name="InvalidPrivateKeyError";constructor(e="Invalid private key"){super(e),this.name="InvalidPrivateKeyError"}};var rr=class extends Error{static name="ConnectionClosedError";constructor(e="The connection is closed"){super(e),this.name="ConnectionClosedError"}};var qo=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}},nr=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}},Nr=class extends Error{static name="InvalidPeerIdError";constructor(e="Invalid PeerID"){super(e),this.name="InvalidPeerIdError"}},Mt=class extends Error{static name="InvalidMultiaddrError";constructor(e="Invalid multiaddr"){super(e),this.name="InvalidMultiaddrError"}},$o=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},zo=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}},Vo=class extends Error{static name="UnsupportedProtocolError";constructor(e="Unsupported protocol error"){super(e),this.name="UnsupportedProtocolError"}},Ho=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var Wo=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},St=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}};var Mr=class extends Error{static name="DialError";constructor(e="Dial error"){super(e),this.name="DialError"}};var Cn=class extends Error{static name="LimitedConnectionError";constructor(e="Limited connection"){super(e),this.name="LimitedConnectionError"}},Go=class extends Error{static name="TooManyInboundProtocolStreamsError";constructor(e="Too many inbound protocol streams"){super(e),this.name="TooManyInboundProtocolStreamsError"}},jo=class extends Error{static name="TooManyOutboundProtocolStreamsError";constructor(e="Too many outbound protocol streams"){super(e),this.name="TooManyOutboundProtocolStreamsError"}},Bt=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Yo=class extends Event{error;local;constructor(e,t,n){super("close",n),this.error=t,this.local=e}};var Ba=Symbol.for("@libp2p/peer-discovery");var Xo=Symbol.for("@libp2p/peer-id");function Ft(r){return!!r?.[Xo]}var Fa=Symbol.for("@libp2p/peer-routing");var Ua="keep-alive";function Zo(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function bf(...r){let e=[];for(let t of r)Zo(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStart!=null&&await t.beforeStart()})),await Promise.all(e.map(async t=>{await t.start()})),await Promise.all(e.map(async t=>{t.afterStart!=null&&await t.afterStart()}))}async function wf(...r){let e=[];for(let t of r)Zo(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStop!=null&&await t.beforeStop()})),await Promise.all(e.map(async t=>{await t.stop()})),await Promise.all(e.map(async t=>{t.afterStop!=null&&await t.afterStop()}))}var Tn;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Tn||(Tn={}));function Mm(r){return typeof r?.handleEvent=="function"}function Bm(r){return r===!0||r===!1}function Fm(r){return Bm(r)?r:r?.capture??!1}function Ka(r){let e={capture:Fm(r),once:!!r?.once};return r?.passive!=null&&(e.passive=r?.passive),r?.signal!=null&&(e.signal=r?.signal),e}function xf(r,e){return Ka(r).capture===Ka(e).capture}var Ne=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){let o=Ka(n);if(o?.signal?.aborted===!0)return;let s=u=>{o.once&&this.removeEventListener(e,t,o),Mm(t)?t.handleEvent(u):t(u)},i=this.#e.get(e);if(i==null&&(i=[],this.#e.set(e,i)),i.some(u=>u.callback!==t?!1:xf(u.options,o)))return;super.addEventListener(e,s,o);let c=()=>{this.removeEventListener(e,t,o)};o.signal?.addEventListener("abort",c),i.push({callback:t,wrapper:s,options:o,onAbort:c})}removeEventListener(e,t,n){let o=this.#e.get(e);if(o==null){super.removeEventListener(e,t??null,n);return}this.#e.set(e,o.filter(s=>s.callback===t&&xf(s.options,n)?(super.removeEventListener(e,s.wrapper,n),s.options?.signal?.removeEventListener("abort",s.onAbort),!1):!0))}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var In=Symbol.for("@libp2p/service-capabilities"),qa=Symbol.for("@libp2p/service-dependencies");function Q(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}var Wa={};$e(Wa,{base58btc:()=>ie,base58flickr:()=>Wm});var Jx=new Uint8Array(0);function vf(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function Je(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return or(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return or(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function Sf(r){let e=new Uint8Array(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}var Ef=4096;function Af(r){let e=r.length;if(e<=Ef)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.subarray(n,n+=Ef));return t}function Um(r){return r?.buffer instanceof ArrayBuffer}function or(r){return Um(r)?r:r.slice()}function Km(r,e,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var s=0;s<r.length;s++){var i=r.charAt(s),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=s,t){var c=i.toLowerCase().charCodeAt(0),u=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=s),u!==a&&(n[u]=s)}}var l=r.length,f=r.charAt(0),d=Math.log(l)/Math.log(256),h=Math.log(256)/Math.log(l);function y(b){if(b instanceof Uint8Array||(ArrayBuffer.isView(b)?b=new Uint8Array(b.buffer,b.byteOffset,b.byteLength):Array.isArray(b)&&(b=Uint8Array.from(b))),!(b instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(b.length===0)return"";for(var S=0,w=0,v=0,A=b.length;v!==A&&b[v]===0;)v++,S++;for(var M=(A-v)*h+1>>>0,$=new Uint8Array(M);v!==A;){for(var k=b[v],D=0,B=M-1;(k!==0||D<w)&&B!==-1;B--,D++)k+=256*$[B]>>>0,$[B]=k%l>>>0,k=k/l>>>0;if(k!==0)throw new Error("Non-zero carry");w=D,v++}for(var V=M-w;V!==M&&$[V]===0;)V++;for(var W=f.repeat(S);V<M;++V)W+=r.charAt($[V]);return W}function p(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var S=0;if(b[S]!==" "){for(var w=0,v=0;b[S]===f;)w++,S++;for(var A=(b.length-S)*d+1>>>0,M=new Uint8Array(A);b[S];){var $=b.charCodeAt(S);if($>255)return;var k=n[$];if(k===255)return;for(var D=0,B=A-1;(k!==0||D<v)&&B!==-1;B--,D++)k+=l*M[B]>>>0,M[B]=k%256>>>0,k=k/256>>>0;if(k!==0)throw new Error("Non-zero carry");v=D,S++}if(b[S]!==" "){for(var V=A-v;V!==A&&M[V]===0;)V++;for(var W=new Uint8Array(w+(A-V)),oe=w;V!==A;)W[oe++]=M[V++];return W}}}function g(b){var S=p(b);if(S)return S;throw new Error(`Non-${e} character`)}return{encode:y,decodeUnsafe:p,decode:g}}var qm=Km,$m=qm,Cf=$m;var $a=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},za=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Tf(this,e)}},Va=class{decoders;constructor(e){this.decoders=e}or(e){return Tf(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Tf(r,e){return new Va({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Ha=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new $a(e,t,n),this.decoder=new za(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Br({name:r,prefix:e,encode:t,decode:n}){return new Ha(r,e,t,n)}function Ut({name:r,prefix:e,alphabet:t,caseInsensitive:n=!1}){let{encode:o,decode:s}=Cf(t,r,n);return Br({prefix:e,name:r,encode:o,decode:i=>Je(s(i))})}function zm(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*t/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let l=e[r[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|l,i+=t,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=t||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Vm(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<t-i]),n)for(;(s.length*t&7)!==0;)s+="=";return s}function Hm(r,e){let t={};for(let n=0;n<r.length;++n)if(t[r[n]]=n,e){let o=r[n].toLowerCase(),s=r[n].toUpperCase();o!==r[n]&&(t[o]=n),s!==r[n]&&(t[s]=n)}return t}function ye({name:r,prefix:e,bitsPerChar:t,alphabet:n,caseInsensitive:o=!1}){let s=Hm(n,o);return Br({prefix:e,name:r,encode(i){return Vm(i,n,t)},decode(i){return zm(i,s,t,r)}})}var ie=Ut({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Wm=Ut({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ga={};$e(Ga,{base32:()=>et,base32hex:()=>Xm,base32hexpad:()=>Qm,base32hexpadupper:()=>Jm,base32hexupper:()=>Zm,base32pad:()=>jm,base32padupper:()=>Ym,base32upper:()=>Gm,base32z:()=>eg});var et=ye({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Gm=ye({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),jm=ye({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Ym=ye({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Xm=ye({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Zm=ye({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),Qm=ye({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),Jm=ye({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),eg=ye({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ja={};$e(ja,{base36:()=>Ln,base36upper:()=>tg});var Ln=Ut({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),tg=Ut({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var rg=Pf,If=128,ng=127,og=~ng,sg=Math.pow(2,31);function Pf(r,e,t){e=e||[],t=t||0;for(var n=t;r>=sg;)e[t++]=r&255|If,r/=128;for(;r&og;)e[t++]=r&255|If,r>>>=7;return e[t]=r|0,Pf.bytes=t-n+1,e}var ig=Ya,ag=128,Lf=127;function Ya(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Ya.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Lf)<<o:(i&Lf)*Math.pow(2,o),o+=7}while(i>=ag);return Ya.bytes=s-n,t}var cg=Math.pow(2,7),ug=Math.pow(2,14),lg=Math.pow(2,21),fg=Math.pow(2,28),dg=Math.pow(2,35),hg=Math.pow(2,42),pg=Math.pow(2,49),mg=Math.pow(2,56),gg=Math.pow(2,63),yg=function(r){return r<cg?1:r<ug?2:r<lg?3:r<fg?4:r<dg?5:r<hg?6:r<pg?7:r<mg?8:r<gg?9:10},bg={encode:rg,decode:ig,encodingLength:yg},wg=bg,Pn=wg;function Dn(r,e=0){let t=Pn.decode(r,e),n=Pn.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&r[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[t,n]}function Fr(r,e,t=0){return Pn.encode(r,e,t),e}function Ur(r){return Pn.encodingLength(r)}function gt(r,e){let t=e.byteLength,n=Ur(r),o=n+Ur(t),s=new Uint8Array(o+t);return Fr(r,s,0),Fr(t,s,n),s.set(e,o),new Kr(r,t,e,s)}function At(r){let e=Je(r),[t,n]=Dn(e),[o,s]=Dn(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Kr(t,o,i,e)}function Df(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&vf(r.bytes,t.bytes)}}var Kr=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=or(n),this.bytes=or(o)}};function Rf(r,e){let{bytes:t,version:n}=r;return n===0?Eg(t,Xa(r),e??ie.encoder):vg(t,Xa(r),e??et.encoder)}var Of=new WeakMap;function Xa(r){let e=Of.get(r);if(e==null){let t=new Map;return Of.set(r,t),t}return e}var xe=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=or(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==Rn)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Sg)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}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:e,digest:t}=this.multihash,n=gt(e,t);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(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&Df(e.multihash,n.multihash)}toString(e){return Rf(this,e)}toJSON(){return{"/":Rf(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:s,bytes:i}=t;return new r(n,o,s,i??kf(n,o,s.bytes))}else if(t[Ag]===!0){let{version:n,multihash:o,code:s}=t,i=At(o);return r.create(n,s,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==Rn)throw new Error(`Version 0 CID must use dag-pb (code: ${Rn}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=kf(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Rn,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=Je(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new Kr(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,d]=Dn(e.subarray(t));return t+=d,f},o=n(),s=Rn;if(o===18)o=0,t=0;else if(o===1)s=n();else throw o===0?new RangeError("Invalid CID version, v0 is always implicit"):new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),c=n(),u=t+c,l=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,t){let[n,o]=xg(e,t),s=r.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Xa(s).set(n,e),s}};function xg(r,e){switch(r[0]){case"Q":{let t=e??ie;return[ie.prefix,t.decode(`${ie.prefix}${r}`)]}case ie.prefix:{let t=e??ie;return[ie.prefix,t.decode(r)]}case et.prefix:{let t=e??et;return[et.prefix,t.decode(r)]}case Ln.prefix:{let t=e??Ln;return[Ln.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Eg(r,e,t){let{prefix:n}=t;if(n!==ie.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function vg(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o}var Rn=112,Sg=18;function kf(r,e,t){let n=Ur(r),o=n+Ur(e),s=new Uint8Array(o+t.byteLength);return Fr(r,s,0),Fr(e,s,n),s.set(t,o),s}var Ag=Symbol.for("@ipld/js-cid/CID");var Za={};$e(Za,{identity:()=>at});var Nf=0,_g="identity",Mf=Je;function Cg(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return gt(Nf,Mf(r))}var at={code:Nf,name:_g,encode:Mf,digest:Cg};function Tg(r){return r.buffer instanceof ArrayBuffer}function Te(r){return Tg(r)?r:r.slice()}async function Bf(r="P-256"){let e=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:r},!0,["sign","verify"]);return{publicKey:await crypto.subtle.exportKey("jwk",e.publicKey),privateKey:await crypto.subtle.exportKey("jwk",e.privateKey)}}async function Ff(r,e,t){let n=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["sign"]);t?.signal?.throwIfAborted();let o=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},n,Te(e.subarray()));return t?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Uf(r,e,t,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,Te(e),Te(t.subarray()));return n?.signal?.throwIfAborted(),s}function pe(r=0){return new Uint8Array(r)}function Se(r=0){return new Uint8Array(r)}function Ig(r){return r?.buffer instanceof ArrayBuffer}function Qa(r){if(Ig(r))return r;let e=r.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function tt(r,e){e==null&&(e=r.reduce((o,s)=>o+s.length,0));let t=Se(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return Qa(t)}var qf=Symbol.for("@achingbrain/uint8arraylist");function Kf(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let o=t+n.byteLength;if(e<o)return{buf:n,index:e-t};t=o}throw new RangeError("index is out of bounds")}function Jo(r){return!!r?.[qf]}var ne=class r{bufs;length;[qf]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(Jo(n)){t+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(Jo(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=Kf(this.bufs,e);return t.buf[t.index]}set(e,t){let n=Kf(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(Jo(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:o}=this._subList(e,t);return tt(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:tt(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),s=new r;return s.length=o,s.bufs=n,s}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,e>=c)continue;let u=e>=a&&e<c,l=t>a&&t<=c;if(u&&l){if(e===a&&t===c){n.push(i);break}let f=e-a;n.push(i.subarray(f,f+(t-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(l){if(t===c){n.push(i);break}n.push(i.subarray(0,t-a));break}n.push(i)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!Jo(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let f=t;f<=c;f+=l){l=0;for(let d=u;d>=0;d--){let h=this.get(f+d);if(n[d]!==h){l=Math.max(1,d-a[h]);break}}if(l===0)return f}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=Se(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let o=pe(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,t,n),this.write(o,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let o=pe(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,t,n),this.write(o,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let o=pe(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,t,n),this.write(o,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=Se(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let o=pe(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,t,n),this.write(o,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let o=pe(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,t,n),this.write(o,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let o=pe(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,t,n),this.write(o,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let o=pe(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,t,n),this.write(o,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let o=pe(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,t,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!Q(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((o,s)=>o+s.byteLength,0)),n.length=t,n}};var Ja={};$e(Ja,{base10:()=>Lg});var Lg=Ut({prefix:"9",name:"base10",alphabet:"0123456789"});var ec={};$e(ec,{base16:()=>Pg,base16upper:()=>Dg});var Pg=ye({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Dg=ye({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var tc={};$e(tc,{base2:()=>Rg});var Rg=ye({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var rc={};$e(rc,{base256emoji:()=>Bg});var $f=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}"),Og=$f.reduce((r,e,t)=>(r[t]=e,r),[]),kg=$f.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Ng(r){return r.reduce((e,t)=>(e+=Og[t],e),"")}function Mg(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=kg[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var Bg=Br({prefix:"\u{1F680}",name:"base256emoji",encode:Ng,decode:Mg});var sc={};$e(sc,{base64:()=>nc,base64pad:()=>Fg,base64url:()=>oc,base64urlpad:()=>Ug});var nc=ye({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Fg=ye({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),oc=ye({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ug=ye({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ic={};$e(ic,{base8:()=>Kg});var Kg=ye({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ac={};$e(ac,{identity:()=>qg});var qg=Br({prefix:"\0",name:"identity",encode:r=>Af(Je(r)),decode:r=>Je(Sf(r))});var BE=new TextEncoder,FE=new TextDecoder;var lc={};$e(lc,{sha256:()=>qr,sha512:()=>Hg});var Vg=20;function uc({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new cc(r,e,t,n,o)}var cc=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,s){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??Vg,this.maxDigestLength=s}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?zf(n,this.code,t?.truncate):n.then(o=>zf(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function zf(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return gt(e,r)}function Hf(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var qr=uc({name:"sha2-256",code:18,encode:Hf("SHA-256")}),Hg=uc({name:"sha2-512",code:19,encode:Hf("SHA-512")});var On={...ac,...tc,...ic,...Ja,...ec,...Ga,...ja,...Wa,...sc,...rc},XE={...lc,...Za};function Gf(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Wf=Gf("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),fc=Gf("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=Se(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Wg={utf8:Wf,"utf-8":Wf,hex:On.base16,latin1:fc,ascii:fc,binary:fc,...On},es=Wg;function I(r,e="utf8"){let t=es[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function F(r,e="utf8"){let t=es[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var Gg=parseInt("11111",2),dc=parseInt("10000000",2),jg=parseInt("01111111",2),jf={0:kn,1:kn,2:Yg,3:Qg,4:Jg,5:Zg,6:Xg,16:kn,22:kn,48:kn};function _t(r,e={offset:0}){let t=r[e.offset]⋙if(e.offset++,jf[t]!=null)return jf[t](r,e);throw new Error("No decoder for tag "+t)}function Nn(r,e){let t=0;if((r[e.offset]&dc)===dc){let n=r[e.offset]&jg,o="0x";e.offset++;for(let s=0;s<n;s++,e.offset++){if(e.offset>=r.byteLength)throw new Error("invalid DER element length");o+=r[e.offset].toString(16).padStart(2,"0")}t=parseInt(o,16)}else t=r[e.offset],e.offset++;if(!Number.isInteger(t)||t<0||t>r.byteLength-e.offset)throw new Error("invalid DER element length");return t}function kn(r,e){Nn(r,e);let t=[];for(;!(e.offset>=r.byteLength);){let n=_t(r,e);if(n===null)break;t.push(n)}return t}function Yg(r,e){let t=Nn(r,e),n=e.offset,o=e.offset+t,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return e.offset+=t,Uint8Array.from(s)}function Xg(r,e){let t=Nn(r,e),n=e.offset+t,o=r[e.offset];e.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;e.offset<n;){let u=r[e.offset];if(e.offset++,c.push(u&127),u<128){c.reverse();let l=0;for(let f=0;f<c.length;f++)l+=c[f]<<f*7;a+=`.${l}`,c=[]}}return a}function Zg(r,e){return e.offset++,null}function Qg(r,e){let t=Nn(r,e),n=r[e.offset];e.offset++;let o=r.subarray(e.offset,e.offset+t-1);if(e.offset+=t,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Jg(r,e){let t=Nn(r,e),n=r.subarray(e.offset,e.offset+t);return e.offset+=t,n}function ey(r){let e=r.toString(16);e.length%2===1&&(e="0"+e);let t=new ne;for(let n=0;n<e.length;n+=2)t.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return t}function ts(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let e=ey(r.byteLength);return new ne(Uint8Array.from([e.byteLength|dc]),e)}function Me(r){let e=new ne,t=128;return(r.subarray()[0]&t)===t&&e.append(Uint8Array.from([0])),e.append(r),new ne(Uint8Array.from([2]),ts(e),e)}function Mn(r){let e=Uint8Array.from([0]),t=new ne(e,r);return new ne(Uint8Array.from([3]),ts(t),t)}function Yf(r){return new ne(Uint8Array.from([4]),ts(r),r)}function ct(r,e=48){let t=new ne;for(let n of r)t.append(n);return new ne(Uint8Array.from([e]),ts(t),t)}var ty=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),ry=Uint8Array.from([6,5,43,129,4,0,34]),ny=Uint8Array.from([6,5,43,129,4,0,35]),oy={ext:!0,kty:"EC",crv:"P-256"},sy={ext:!0,kty:"EC",crv:"P-384"},iy={ext:!0,kty:"EC",crv:"P-521"},hc=32,pc=48,mc=66;function gc(r){let e=_t(r);return Xf(e)}function Xf(r){let e=r[1][1][0],t=1,n,o;if(e.byteLength===hc*2+1)return n=F(e.subarray(t,t+hc),"base64url"),o=F(e.subarray(t+hc),"base64url"),new sr({...oy,key_ops:["verify"],x:n,y:o});if(e.byteLength===pc*2+1)return n=F(e.subarray(t,t+pc),"base64url"),o=F(e.subarray(t+pc),"base64url"),new sr({...sy,key_ops:["verify"],x:n,y:o});if(e.byteLength===mc*2+1)return n=F(e.subarray(t,t+mc),"base64url"),o=F(e.subarray(t+mc),"base64url"),new sr({...iy,key_ops:["verify"],x:n,y:o});throw new T(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Zf(r){return ct([Me(Uint8Array.from([1])),Yf(I(r.d??"","base64url")),ct([Jf(r.crv)],160),ct([Mn(new ne(Uint8Array.from([4]),I(r.x??"","base64url"),I(r.y??"","base64url")))],161)]).subarray()}function Qf(r){return ct([Me(Uint8Array.from([1])),ct([Jf(r.crv)],160),ct([Mn(new ne(Uint8Array.from([4]),I(r.x??"","base64url"),I(r.y??"","base64url")))],161)]).subarray()}function Jf(r){if(r==="P-256")return ty;if(r==="P-384")return ry;if(r==="P-521")return ny;throw new T(`Invalid curve ${r}`)}async function ed(r="P-256"){let e=await Bf(r);return new rs(e.privateKey)}var sr=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Qf(this.jwk)),this._raw}toMultihash(){return at.digest(rt(this))}toCID(){return xe.createV1(114,this.toMultihash())}toString(){return ie.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Q(this.raw,e.raw)}async verify(e,t,n){return Uf(this.jwk,t,e,n)}},rs=class{type="ECDSA";jwk;publicKey;_raw;constructor(e){this.jwk=e,this.publicKey=new sr({crv:e.crv,ext:e.ext,key_ops:["verify"],kty:"EC",x:e.x,y:e.y})}get raw(){return this._raw==null&&(this._raw=Zf(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Q(this.raw,e.raw)}async sign(e,t){return Ff(this.jwk,e,t)}};var ns=BigInt(4294967295),td=BigInt(32);function ay(r,e=!1){return e?{h:Number(r&ns),l:Number(r>>td&ns)}:{h:Number(r>>td&ns)|0,l:Number(r&ns)|0}}function rd(r,e=!1){let t=r.length,n=new Uint32Array(t),o=new Uint32Array(t);for(let s=0;s<t;s++){let{h:i,l:a}=ay(r[s],e);[n[s],o[s]]=[i,a]}return[n,o]}var cy=r=>r/2**32|0,uy=r=>r>>>0;function nd(r,e,t,n){let o=cy(t),s=uy(t);r.setUint32(e,n?s:o,n),r.setUint32(e+4,n?o:s,n)}var yc=(r,e,t)=>r>>>t,bc=(r,e,t)=>r<<32-t|e>>>t,ir=(r,e,t)=>r>>>t|e<<32-t,ar=(r,e,t)=>r<<32-t|e>>>t,Bn=(r,e,t)=>r<<64-t|e>>>t-32,Fn=(r,e,t)=>r>>>t-32|e<<64-t;function yt(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var od=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),sd=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,id=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),ad=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,cd=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),ud=(r,e,t,n,o,s)=>e+t+n+o+s+(r/2**32|0)|0;function os(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in r&&r.BYTES_PER_ELEMENT===1}var wc=r=>r?`"${r}" `:"";function Ct(r,e=""){if(typeof r!="number")throw new TypeError(wc(e)+"expected number, got "+typeof r);if(!Number.isSafeInteger(r)||r<0)throw new RangeError(wc(e)+"expected integer >= 0, got "+r);return r}function nt(r,e,t=""){if(os(r)&&(e===void 0||r.length===e))return r;e!==void 0&&Ct(e,"length");let n=os(r),o=e!==void 0?` of length ${e}`:"",s=n?`length=${r.length}`:`type=${typeof r}`,i=wc(t)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function ss(r){if(typeof r!="function"||typeof r.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(Ct(r.outputLen),Ct(r.blockLen),r.outputLen<1||r.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var fy=(r,e)=>{if(r===null||typeof r!="object"||Array.isArray(r))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof r)},ld=(r,e)=>{fy(r,e);let t=Object.getPrototypeOf(r);if(t!==Object.prototype&&t!==null)throw new TypeError(`"${e}" expected plain object`);if(Object.hasOwn(r,"__proto__"))throw new TypeError(`"${e}.__proto__" is not allowed`)};function $r(r,e=!0){if(r.destroyed)throw new Error("hash was destroyed");if(e&&r.finished)throw new Error("digest() was already called")}function is(r,e){nt(r,void 0,"output");let t=e.outputLen;if(!(r.length>=t))throw new RangeError('"output" expected length >= '+t)}function cr(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function as(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function ut(r,e){return r<<32-e|r>>>e}var dd=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",dy=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function cs(r){if(nt(r),dd)return r.toHex();let e="";for(let t=0;t<r.length;t++)e+=dy[r[t]];return e}function fd(r){return r>=48&&r<=57?r-48:r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:void 0}function us(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);if(dd)try{return Uint8Array.fromHex(r)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let e=r.length,t=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let o=0,s=0;o<t;o++,s+=2){let i=fd(r.charCodeAt(s)),a=fd(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function xc(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];nt(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let s=r[n];t.set(s,o),o+=s.length}return t}function hy(r,e,t="opts"){return ld(r,"defaults"),e!==void 0&&ld(e,t),Object.assign(Object.create(null),r,e)}function Ec(r,e={}){if(typeof r!="function")throw new TypeError('"hashCons" expected function, got type='+typeof r);e=hy({},e,"info");let t=(o,s)=>r(s).update(o).digest(),n=r(void 0);return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.canXOF=n.canXOF,t.create=o=>r(o),Object.assign(t,e),Object.freeze(t)}function hd(r=32){Ct(r,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(r>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${r}`);return e.getRandomValues(new Uint8Array(r))}var vc=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function pd(r,e,t){return r&e^~r&t}function md(r,e,t){return r&e^r&t^e&t}var Un=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,n,o){this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=as(this.buffer)}update(e){$r(this),nt(e);let{view:t,buffer:n,blockLen:o}=this,s=e.length,i=!1;for(let a=0;a<s;){let c=Math.min(o-this.pos,s-a);if(c===o){let u=as(e);for(;o<=s-a;a+=o)this.process(u,a);i=!0;continue}n.set(a===0&&c===s?e:e.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===o&&(this.process(t,0),this.pos=0,i=!0)}return this.length+=e.length,i&&this.roundClean(),this}digestInto(e){$r(this),is(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;t[i++]=128,t.fill(0,i),this.padOffset>o-i&&(this.process(n,0),t.fill(0)),nd(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let a=e===t?n:as(e),c=this.outputLen,u=c/4,l=this.get();if(c%4||u>l.length)throw new Error("invalid outputLen");for(let f=0;f<u;f++)a.setUint32(4*f,l[f],s)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:t,length:n,finished:o,destroyed:s,pos:i}=this;return e.destroyed=s,e.finished=o,e.length=n,e.pos=i,i&&e.buffer.set(t),e}clone(){return this._cloneInto()}},gd=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var yd=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var py=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),qt=new Uint32Array(64),Sc=class extends Un{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,t){super(64,e,8,!1),this.A=t[0]|0,this.B=t[1]|0,this.C=t[2]|0,this.D=t[3]|0,this.E=t[4]|0,this.F=t[5]|0,this.G=t[6]|0,this.H=t[7]|0}get(){let{A:e,B:t,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[e,t,n,o,s,i,a,c]}set(e,t,n,o,s,i,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,t){for(let f=0;f<16;f++,t+=4)qt[f]=e.getUint32(t,!1);for(let f=16;f<64;f++){let d=qt[f-15],h=qt[f-2],y=ut(d,7)^ut(d,18)^d>>>3,p=ut(h,17)^ut(h,19)^h>>>10;qt[f]=p+qt[f-7]+y+qt[f-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){let d=ut(a,6)^ut(a,11)^ut(a,25),h=l+d+pd(a,c,u)+py[f]+qt[f]|0,p=(ut(n,2)^ut(n,13)^ut(n,22))+md(n,o,s)|0;l=u,u=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+p|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,o,s,i,a,c,u,l)}roundClean(){cr(qt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),cr(this.buffer)}},Ac=class extends Sc{constructor(){super(32,gd)}};var bd=rd(["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))),my=bd[0],gy=bd[1],$t=new Uint32Array(80),zt=new Uint32Array(80),_c=class extends Un{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(e,t){super(128,e,16,!1),this.Ah=t[0]|0,this.Al=t[1]|0,this.Bh=t[2]|0,this.Bl=t[3]|0,this.Ch=t[4]|0,this.Cl=t[5]|0,this.Dh=t[6]|0,this.Dl=t[7]|0,this.Eh=t[8]|0,this.El=t[9]|0,this.Fh=t[10]|0,this.Fl=t[11]|0,this.Gh=t[12]|0,this.Gl=t[13]|0,this.Hh=t[14]|0,this.Hl=t[15]|0}get(){let{Ah:e,Al:t,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:l,Fh:f,Fl:d,Gh:h,Gl:y,Hh:p,Hl:g}=this;return[e,t,n,o,s,i,a,c,u,l,f,d,h,y,p,g]}set(e,t,n,o,s,i,a,c,u,l,f,d,h,y,p,g){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=l|0,this.Fh=f|0,this.Fl=d|0,this.Gh=h|0,this.Gl=y|0,this.Hh=p|0,this.Hl=g|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,t){for(let w=0;w<16;w++,t+=4)$t[w]=e.getUint32(t),zt[w]=e.getUint32(t+=4);for(let w=16;w<80;w++){let v=$t[w-15]|0,A=zt[w-15]|0,M=ir(v,A,1)^ir(v,A,8)^yc(v,A,7),$=ar(v,A,1)^ar(v,A,8)^bc(v,A,7),k=$t[w-2]|0,D=zt[w-2]|0,B=ir(k,D,19)^Bn(k,D,61)^yc(k,D,6),V=ar(k,D,19)^Fn(k,D,61)^bc(k,D,6),W=id($,V,zt[w-7],zt[w-16]),oe=ad(W,M,B,$t[w-7],$t[w-16]);$t[w]=oe|0,zt[w]=W|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:d,Fh:h,Fl:y,Gh:p,Gl:g,Hh:b,Hl:S}=this;for(let w=0;w<80;w++){let v=ir(f,d,14)^ir(f,d,18)^Bn(f,d,41),A=ar(f,d,14)^ar(f,d,18)^Fn(f,d,41),M=f&h^~f&p,$=d&y^~d&g,k=cd(S,A,$,gy[w],zt[w]),D=ud(k,b,v,M,my[w],$t[w]),B=k|0,V=ir(n,o,28)^Bn(n,o,34)^Bn(n,o,39),W=ar(n,o,28)^Fn(n,o,34)^Fn(n,o,39),oe=n&s^n&a^s&a,L=o&i^o&c^i&c;b=p|0,S=g|0,p=h|0,g=y|0,h=f|0,y=d|0,{h:f,l:d}=yt(u|0,l|0,D|0,B|0),u=a|0,l=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let z=od(B,W,L);n=sd(z,D,V,oe),o=z|0}({h:n,l:o}=yt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=yt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=yt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=yt(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:d}=yt(this.Eh|0,this.El|0,f|0,d|0),{h,l:y}=yt(this.Fh|0,this.Fl|0,h|0,y|0),{h:p,l:g}=yt(this.Gh|0,this.Gl|0,p|0,g|0),{h:b,l:S}=yt(this.Hh|0,this.Hl|0,b|0,S|0),this.set(n,o,s,i,a,c,u,l,f,d,h,y,p,g,b,S)}roundClean(){cr($t,zt)}destroy(){this.destroyed=!0,cr(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Cc=class extends _c{constructor(){super(64,yd)}};var zr=Ec(()=>new Ac,vc(1));var Tc=Ec(()=>new Cc,vc(3));function fs(r,e,t=()=>{}){if(!Array.isArray(r))throw new TypeError(`"${e}" expected array, got type=${typeof r}`);for(let n=0;n<r.length;n++)t(r[n],`${e}[${n}]`);return r}var J=(r,e,t)=>nt(r,e,t),Ic=Ct;function xd(r,e=""){if(typeof r!="string"){let t=e&&`"${e}" `;throw new TypeError(t+"expected string, got type="+typeof r)}return r}function Vt(r,e="object"){if(r===null||typeof r!="object"||Array.isArray(r))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof r}`);return r}function ur(r,e){if(typeof r!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof r}`);return r}var Kn=cs,ot=(...r)=>xc(...r),Vr=r=>us(r),Wt=os,lr=r=>hd(r),ls=BigInt(0),wd=BigInt(1),yy=r=>r?`"${r}" `:"";function ze(r,e=""){if(typeof r!="boolean")throw new TypeError(yy(e)+"expected boolean, got type="+typeof r);return r}function ds(r){if(typeof r=="bigint"){if(!Ht(r))throw new RangeError("positive bigint expected, got "+r)}else Ic(r);return r}function Tt(r,e=""){if(typeof r!="number"){let t=e&&`"${e}" `;throw new TypeError(t+"expected number, got type="+typeof r)}if(!Number.isSafeInteger(r)){let t=e&&`"${e}" `;throw new RangeError(t+"expected safe integer, got "+r)}}function qn(r){let e=ds(r).toString(16);return e.length&1?"0"+e:e}function Ed(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);return r===""?ls:BigInt("0x"+r)}function bt(r){return Ed(cs(r))}function fr(r){return Ed(cs($n(nt(r)).reverse()))}function hs(r,e){if(Ct(e),e===0)throw new Error("zero output length is invalid");r=ds(r);let t=e*2,n=r.toString(16);if(n.length>t)throw new RangeError("number is too large");return us(n.padStart(t,"0"))}function Lc(r,e){return hs(r,e).reverse()}function $n(r){return Uint8Array.from(J(r))}function Ht(r){return typeof r=="bigint"&&ls<=r}function Pc(r,e,t){return Ht(r)&&Ht(e)&&Ht(t)&&e<=r&&r<t}function Hr(r,e,t,n){if(!Pc(e,t,n))throw new RangeError("expected valid "+r+": "+t+" <= n < "+n+", got "+e)}function Wr(r){if(r<ls)throw new Error("expected non-negative bigint, got "+r);return r===ls?0:r.toString(2).length}var zn=r=>(Tt(r,"n"),(wd<<BigInt(r))-wd);function vd(r,e,t){if(Ct(r,"hashLen"),Ct(e,"qByteLen"),typeof t!="function")throw new TypeError("hmacFn must be a function");let n=g=>new Uint8Array(g),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(r),u=n(r),l=0,f=()=>{c.fill(1),u.fill(0),l=0},d=(...g)=>t(u,ot(c,...g)),h=(g=o)=>{u=d(s,g),c=d(),g.length!==0&&(u=d(i,g),c=d())},y=()=>{if(l++>=a)throw new Error("drbg: tried max amount of iterations");let g=0,b=[];for(;g<e;){c=d();let S=c.slice();b.push(S),g+=c.length}return ot(...b)};return(g,b)=>{f(),h(g);let S;for(;(S=b(y()))===void 0;)h();return f(),S}}function Ve(r,e={},t={},n="object"){Vt(r,n),Vt(e,"fields"),Vt(t,"optFields");function o(i,a,c){let u=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,l=r[i];if(!Object.hasOwn(r,i)&&(c?l!==void 0:a!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&l===void 0)return;let f=typeof l;if(f!==a||l===null)throw new TypeError(`${u} is invalid: expected ${a}, got ${f}`)}let s=(i,a)=>Object.entries(i).forEach(([c,u])=>o(c,u,a));s(e,!1),s(t,!0)}var Ee=BigInt(0),ee=BigInt(1),Gt=BigInt(2),_d=BigInt(3),Dc=BigInt(4),Cd=BigInt(5),by=BigInt(7),Td=BigInt(8),wy=BigInt(9),xy=BigInt(15),Id=BigInt(16),Ey=BigInt("0x10000000000000000");function me(r,e){if(e<=Ee)throw new Error("mod: expected positive modulus, got "+e);let t=r%e;return t>=Ee?t:e+t}function Ld(r,e,t){if(t<=ee)throw new Error("pow: expected modulus > 1, got "+t);if(typeof e!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof e);if(e<Ee)throw new Error("invalid exponent, negatives unsupported");if(e===Ee)return ee;if(e===ee)return r;let n=r%t;if(n<Ee&&(n+=t),e<Ey){let a=ee;for(;e>Ee;)e&ee&&(a=a*n%t),n=n*n%t,e>>=ee;return a}let o=[];for(;e>Ee;)o.push(Number(e&xy)),e>>=Dc;let s=new Array(16);s[0]=ee,s[1]=n;for(let a=2;a<16;a++)s[a]=s[a-1]*n%t;let i=s[o[o.length-1]];for(let a=o.length-2;a>=0;a--){i=i*i%t,i=i*i%t,i=i*i%t,i=i*i%t;let c=o[a];c!==0&&(i=i*s[c]%t)}return i}function de(r,e,t){if(t<=ee)throw new Error("pow2: expected modulus > 1, got "+t);if(e<Ee)throw new Error("pow2: expected non-negative exponent, got "+e);let n=r;for(;e-- >Ee;)n*=n,n%=t;return n}function Sd(r,e){if(r===Ee)throw new Error("invert: expected non-zero number");if(e<=ee)throw new Error("invert: expected modulus > 1, got "+e);let t=me(r,e),n=e,o=Ee,s=ee;for(;t!==Ee;){let a=n/t,c=n-t*a,u=o-s*a;n=t,t=c,o=s,s=u}if(n!==ee)throw new Error("invert: does not exist");return me(o,e)}function Pd(r,e){if(e<=ee)throw new Error("invertCt: expected prime modulus > 1, got "+e);let t=me(r,e);if(t===Ee)throw new Error("invertCt: expected non-zero number");let n=Ld(t,e-Gt,e);if(me(t*n,e)!==ee)throw new Error("invertCt: does not exist");return n}function Rc(r,e,t){let n=r;if(!n.eql(n.sqr(e),t))throw new Error("Cannot find square root")}function Oc(r,e){if((r&ee)===Ee)throw new Error(e+": expected odd modulus, got "+r)}function Dd(r,e){let t=r,n=(t.ORDER+ee)/Dc,o=t.pow(e,n);return Rc(t,o,e),o}function vy(r,e){let t=r,n=(t.ORDER-Cd)/Td,o=t.mul(e,Gt),s=t.pow(o,n),i=t.mul(e,s),a=t.mul(t.mul(i,Gt),s),c=t.mul(i,t.sub(a,t.ONE));return Rc(t,c,e),c}function Sy(r){let e=jr(r),t=Rd(r),n=t(e,e.neg(e.ONE)),o=t(e,n),s=t(e,e.neg(n)),i=(r+by)/Id;return((a,c)=>{let u=a,l=u.pow(c,i),f=u.mul(l,n),d=u.mul(l,o),h=u.mul(l,s),y=u.eql(u.sqr(f),c),p=u.eql(u.sqr(d),c);l=u.cmov(l,f,y),f=u.cmov(h,d,p);let g=u.eql(u.sqr(f),c),b=u.cmov(l,f,g);return Rc(u,b,c),b})}function Rd(r){if(r<_d)throw new Error("sqrt is not defined for small field");Oc(r,"tonelliShanks");let e=r-ee,t=0;for(;e%Gt===Ee;)e/=Gt,t++;let n=Gt,o=jr(r);for(;Vn(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(t===1)return Dd;let s=o.pow(n,e),i=(e+ee)/Gt;return function(c,u){let l=c;if(l.is0(u))return u;if(Vn(l,u)!==1)throw new Error("Cannot find square root");let f=t,d=l.mul(l.ONE,s),h=l.pow(u,e),y=l.pow(u,i);for(;!l.eql(h,l.ONE);){if(l.is0(h))throw new Error("Cannot find square root: probably non-prime P");let p=1,g=l.sqr(h);for(;!l.eql(g,l.ONE);)if(p++,g=l.sqr(g),p===f)throw new Error("Cannot find square root");let b=ee<<BigInt(f-p-1),S=l.pow(d,b);f=p,d=l.sqr(S),h=l.mul(h,d),y=l.mul(y,S)}return y}}function Ay(r){return Oc(r,"Fp.sqrt"),r%Dc===_d?Dd:r%Td===Cd?vy:r%Id===wy?Sy(r):Rd(r)}var Od=(r,e)=>(me(r,e)&ee)===ee,_y=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Gr(r){if(Vt(r,"field"),typeof r.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof r.ORDER);Tt(r.BYTES,"BYTES"),Tt(r.BITS,"BITS");for(let e of _y)ur(r[e],"field."+e);if(r.BYTES<1||r.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(r.ORDER<=ee)throw new Error("invalid field: expected ORDER > 1, got "+r.ORDER);return r}function ms(r,e,t=!1){Gr(r),fs(e,"nums"),ze(t,"passZero");let n=r,o=new Array(e.length).fill(t?n.ZERO:void 0),s=e.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return e.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),i),o}function Vn(r,e){Gr(r);let t=r;Oc(t.ORDER,"FpLegendre");let n=(t.ORDER-ee)/Gt,o=t.pow(e,n),s=t.eql(o,t.ONE),i=t.eql(o,t.ZERO),a=t.eql(o,t.neg(t.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function Cy(r,e){if(e!==void 0&&Ic(e),r<=Ee)throw new Error("invalid n length: expected positive n, got "+r);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let t=Wr(r);if(e!==void 0&&e<t)throw new Error(`invalid n length: expected nBitLength (${e}) >= bitLen(n) (${t})`);let n=e!==void 0?e:t,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var Ad=new WeakMap,ps=class{ORDER;BITS;BYTES;isLE;ZERO=Ee;ONE=ee;_lengths;_mod;constructor(e,t={}){if(e<=ee)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,t!=null&&typeof t=="object"&&(typeof t.BITS=="number"&&(n=t.BITS),typeof t.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:t.sqrt,enumerable:!0}),typeof t.isLE=="boolean"&&(this.isLE=t.isLE),t.allowedLengths&&(this._lengths=Object.freeze(t.allowedLengths.slice())),typeof t.modFromBytes=="boolean"&&(this._mod=t.modFromBytes));let{nBitLength:o,nByteLength:s}=Cy(e,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(e){return me(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return Ee<=e&&e<this.ORDER}is0(e){return e===Ee}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&ee)===ee}neg(e){return me(-e,this.ORDER)}eql(e,t){return e===t}sqr(e){return me(e*e,this.ORDER)}add(e,t){return me(e+t,this.ORDER)}sub(e,t){return me(e-t,this.ORDER)}mul(e,t){return me(e*t,this.ORDER)}pow(e,t){return Ld(e,t,this.ORDER)}div(e,t){return me(e*Sd(t,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,t){return e+t}subN(e,t){return e-t}mulN(e,t){return e*t}inv(e){return Sd(e,this.ORDER)}sqrt(e){let t=Ad.get(this);return t||Ad.set(this,t=Ay(this.ORDER)),t(this,e)}toBytes(e){return this.isLE?Lc(e,this.BYTES):hs(e,this.BYTES)}fromBytes(e,t=!1){J(e);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(o);u.set(e,s?0:u.length-e.length),e=u}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=s?fr(e):bt(e);if(a&&(c=me(c,i)),!t&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return ms(this,e,!0)}cmov(e,t,n){return ze(n,"condition"),n?t:e}};function jr(r,e={}){return Object.freeze(ps.prototype),new ps(r,e)}function kd(r){if(typeof r!="bigint")throw new Error("field order must be bigint");if(r<=ee)throw new Error("field order must be greater than 1");let e=Wr(r-ee);return Math.ceil(e/8)}function gs(r){let e=kd(r);return e+Math.ceil(e/2)}function ys(r,e,t=!1){J(r);let n=r.length,o=kd(e),s=Math.max(gs(e),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=t?fr(r):bt(r),a=me(i,e-ee)+ee;return t?Lc(a,o):hs(a,o)}var Mc=BigInt(0),Hn=BigInt(1),Ty=BigInt(4),kc=16,Nd=128,Iy=5,Md=2**31;function jt(r){let e=r;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof r);ur(e.fromAffine,"Point.fromAffine"),ur(e.fromBytes,"Point.fromBytes"),ur(e.fromHex,"Point.fromHex"),Vt(e.BASE,"Point.BASE"),Vt(e.ZERO,"Point.ZERO"),Gr(e.Fp),Gr(e.Fn)}function bs(r,e){jt(r),Fd(e,r);let t=ms(r.Fp,e.map(n=>n.Z));return e.map((n,o)=>r.fromAffine(n.toAffine(t[o])))}function Ly(r,e,t=1){if(!Number.isSafeInteger(r)||r<t||r>e)throw new Error("invalid window size, expected ["+t+".."+e+"], got W="+r)}function Py(r,e){let t=r*(4*e+128);if(t>Md)throw new Error("invalid window size: table would need ~"+Math.ceil(t/2**20)+" MiB, max "+Md/2**20+" MiB")}function Bc(r,e){if(r!==void 0){ur(r,"randomBytes");try{let t=r(e);if(!Wt(t)||t.length!==e)return}catch{return}return r}}function Fd(r,e){fs(r,"points"),r.forEach((t,n)=>{if(!(t instanceof e))throw new Error("invalid point at index "+n)})}function Dy(r,e,t){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((n,o)=>{if(!(t===void 0?e.isValid(n):Ht(n)&&n<t))throw new Error("invalid scalar at index "+o)})}var Ud=new WeakMap;function Nc(r){return Ud.get(r)||1}function Ry(r,e){let t=r.double(),n=[r];for(let o=1;o<e;o++)n.push(n[o-1].add(t));return n}function Oy(r,e){let t=2**e,n=t/2,o=BigInt(t-1),s=[];for(;r>Mc;){let i=0;r&Hn&&(i=Number(r&o),i>=n&&(i-=t),r-=BigInt(i)),s.push(i),r>>=Hn}return s}function ky(r,e,t){let n=2**e,o=n/2,s=BigInt(n-1),i=BigInt(e),a=[];for(let c=0;c<t;c++){let u=Number(r&s);r>>=i,u>o&&(u-=n,r+=Hn),a.push(u)}if(r!==Mc)throw new Error("invalid wnaf");return a}function Ny(r,e,t){let n=0;for(let s of t)n=Math.max(n,s.length);let o=r;for(let s=n-1;s>=0;s--){s!==n-1&&(o=o.double());for(let i=0;i<t.length;i++){let a=t[i][s];if(a){let c=e[i][Math.abs(a)-1>>1];o=o.add(a<0?c.negate():c)}}}return o}var Yr=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,t){jt(e),this.randomBytes=Bc(t,kc),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,t,n){let o=Math.ceil(n/t)+1,s=2**(t-1),i=[],a=e;for(let c=0;c<o;c++){let u=a;for(let l=0;l<s;l++)i.push(u),u=u.add(a);a=i[i.length-1].double()}return{W:t,bits:n,windows:o,comp:i}}wnafCachedCT(e,t){let{W:n,windows:o,comp:s}=e,i=2**(n-1),a=ky(t,n,o),c=this.ZERO,u=this.BASE;for(let l=0;l<o;l++){let f=a[l],d=l*i,h=Math.abs(f)-1,y=s[d];for(let g=1;g<i;g++)y=g===h?s[d+g]:y;let p=y.negate();f===0?u=u.add(s[d]):c=c.add(f<0?p:y)}return{p:c,f:u}}getWnafPrecomputes(e,t,n,o){let s=this.wnafPrecomputes.get(t),i=s?.find(a=>a.W===e&&a.bits===n);return i||(i=this.buildWnafTable(t,e,n),typeof o=="function"&&(i={...i,comp:o(i.comp)}),s||(s=[],this.wnafPrecomputes.set(t,s)),s.push(i)),i}assertPoint(e){if(!(e instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof e)}validateMulInput(e,t){if(this.assertPoint(e),!Pc(t,Hn,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,t,n,o){let s=Nc(e);return s===1?this.fixedWindowCT(e,t,n):this.wnafCachedCT(this.getWnafPrecomputes(s,e,n,o),t)}mulCT(e,t,n){return this.validateMulInput(e,t),this.runCT(e,t,this.bits,n)}mulCTBlinded(e,t,n){if(this.validateMulInput(e,t),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let o=this.Point.Fn.BITS+Nd,s=this.randomBytes(kc);if(!Wt(s)||s.length!==kc)throw new Error("randomBytes returned invalid byte array");s[0]=s[0]&63|128;let i=t+bt(s)*this.Point.Fn.ORDER;return this.runCT(e,i,o,n)}fixedWindowCT(e,t,n){let o=Iy,s=1<<o,i=zn(o),a=new Array(s);a[0]=this.ZERO;for(let l=1;l<s;l++)a[l]=a[l-1].add(e);let c=Math.ceil(n/o),u=this.ZERO;for(let l=c-1;l>=0;l--){if(l!==c-1)for(let h=0;h<o;h++)u=u.double();let f=Number(t>>BigInt(l*o)&i),d=a[0];for(let h=1;h<s;h++)d=h===f?a[h]:d;u=u.add(d)}return{p:u,f:u}}shouldBlind(e,t){return this.randomBytes===void 0?!1:t===Hn?!0:e!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(e,t,n,o){return this.shouldBlind(e,n)?this.mulCTBlinded(e,t,o):this.mulCT(e,t,o)}mulUnsafe(e,t,n){if(this.assertPoint(e),!Ht(t))throw new Error("invalid scalar");let o=Nc(e);if(o===1||t>=this.Point.Fn.ORDER)return ws(this.Point,[e],[t],!0);let s=this.getWnafPrecomputes(o,e,this.bits,n);return this.wnafCachedCT(s,t).p}setWindowSize(e,t){this.assertPoint(e),Ly(t,this.bits);let n=Math.ceil((this.bits+Nd)/t)+1;Py(n*2**(t-1),this.Point.Fp.BYTES),Ud.set(e,t),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return Nc(e)!==1}};function ws(r,e,t,n=!1){if(jt(r),Fd(e,r),ze(n,"allowOversized"),Dy(t,r.Fn,n?r.Fn.ORDER**Ty:void 0),e.length!==t.length)throw new Error("arrays of points and scalars must have equal length");let o=e.map(i=>Ry(i,4)),s=t.map(i=>Oy(i,4));return Ny(r.ZERO,o,s)}function Bd(r,e,t){if(e){if(e.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Gr(e),e}else return jr(r,{isLE:t})}function xs(r,e,t={},n){if(r!=="weierstrass"&&r!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=r==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${r} CURVE object`);Ve(t);for(let c of["p","n","h"]){let u=e[c];if(!(Ht(u)&&u!==Mc))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Bd(e.p,t.Fp,n),s=Bd(e.n,t.Fn,n),a=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:s}}function Es(r,e){return function(n){let o=r(n);return{secretKey:o,publicKey:e(o)}}}var vs=BigInt(0),Ss=BigInt(1),As=BigInt(2),My=BigInt(4),Kd=BigInt(8);function By(r,e,t,n){let o=r.sqr(t),s=r.sqr(n),i=r.add(r.mul(e.a,o),s),a=r.add(r.ONE,r.mul(e.d,r.mul(o,s)));return r.eql(i,a)}function qd(r,e={}){Ve(e,{},{},"extraOpts");let t=e,n=xs("edwards",r,t,t.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;if(Vn(o,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(Vn(o,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");Ve(t,{},{uvRatio:"function",randomBytes:"function"});let c=t.randomBytes===void 0?lr:t.randomBytes,u=As<<BigInt(o.BYTES*8)-Ss;function l(S){if(!o.isOdd)throw new Error("Field does not have .isOdd()");return o.isOdd(S)}let f=t.uvRatio===void 0?(S,w)=>{try{return{isValid:!0,value:o.sqrt(o.div(S,w))}}catch{return{isValid:!1,value:vs}}}:t.uvRatio;if(!By(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let d=o.eql(i.a,o.neg(o.ONE))?S=>o.neg(S):o.eql(i.a,o.ONE)?S=>S:S=>o.mul(i.a,S);function h(S,w,v=!1){let A=v?Ss:vs;return Hr("coordinate "+S,w,A,u),w}function y(S){if(!(S instanceof p))throw new Error("EdwardsPoint expected")}class p{static BASE=new p(i.Gx,i.Gy,o.ONE,o.mul(i.Gx,i.Gy));static ZERO=new p(o.ZERO,o.ONE,o.ONE,o.ZERO);static Fp=o;static Fn=s;X;Y;Z;T;constructor(w,v,A,M){this.X=h("x",w),this.Y=h("y",v),this.Z=h("z",A,!0),this.T=h("t",M),Object.freeze(this)}static CURVE(){return i}static fromAffine(w){if(w instanceof p)throw new Error("extended point not allowed");let{x:v,y:A}=w||{};return h("x",v),h("y",A),new p(v,A,o.ONE,o.mul(v,A))}static fromBytes(w,v=!1){let A=o.BYTES,{a:M,d:$}=i;w=$n(J(w,A,"point")),ze(v,"zip215");let k=$n(w),D=w[A-1];k[A-1]=D&-129;let B=fr(k),V=v?u:o.ORDER;Hr("point.y",B,vs,V);let W=o.sqr(B),oe=o.sub(W,o.ONE),L=o.sub(o.mulN($,W),M),{isValid:z,value:H}=f(oe,L);if(!z)throw new Error("bad point: invalid y coordinate");let N=l(H),ue=(D&128)!==0;if(!v&&o.is0(H)&&ue)throw new Error("bad point: x=0 and x_0=1");return ue!==N&&(H=o.neg(H)),p.fromAffine({x:H,y:B})}static fromHex(w,v=!1){return p.fromBytes(Vr(w),v)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(w=6,v=!0){return b.setWindowSize(this,w),v||this.multiply(As),this}assertValidity(){let w=this,{a:v,d:A}=i;if(w.is0())throw new Error("bad point: ZERO");let{X:M,Y:$,Z:k,T:D}=w,B=o.sqr(M),V=o.sqr($),W=o.sqr(k),oe=o.sqr(W),L=o.mul(B,v),z=o.mul(o.add(L,V),W),H=o.add(oe,o.mul(A,o.mul(B,V)));if(!o.eql(z,H))throw new Error("bad point: equation left != right (1)");let N=o.mul(M,$),ue=o.mul(k,D);if(!o.eql(N,ue))throw new Error("bad point: equation left != right (2)")}equals(w){y(w);let{X:v,Y:A,Z:M}=this,{X:$,Y:k,Z:D}=w,B=o.mul(v,D),V=o.mul($,M),W=o.mul(A,D),oe=o.mul(k,M);return o.eql(B,V)&&o.eql(W,oe)}is0(){return this.equals(p.ZERO)}negate(){return new p(o.neg(this.X),this.Y,this.Z,o.neg(this.T))}double(){let{X:w,Y:v,Z:A}=this,M=o.sqr(w),$=o.sqr(v),k=o.mul(o.sqr(A),As),D=d(M),B=o.addN(w,v),V=o.sub(o.subN(o.sqr(B),M),$),W=o.addN(D,$),oe=o.subN(W,k),L=o.subN(D,$),z=o.mul(V,oe),H=o.mul(W,L),N=o.mul(V,L),ue=o.mul(oe,W);return new p(z,H,ue,N)}add(w){y(w);let{d:v}=i,{X:A,Y:M,Z:$,T:k}=this,{X:D,Y:B,Z:V,T:W}=w,oe=o.mul(A,D),L=o.mul(M,B),z=o.mul(o.mulN(k,v),W),H=o.mul($,V),N=o.sub(o.subN(o.mulN(o.addN(A,M),o.addN(D,B)),oe),L),ue=o.subN(H,z),he=o.addN(H,z),_=o.sub(L,d(oe)),m=o.mul(N,ue),x=o.mul(he,_),E=o.mul(N,_),C=o.mul(ue,he);return new p(m,x,C,E)}subtract(w){return y(w),this.add(w.negate())}multiply(w){if(!s.isValidNot0(w))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:v,f:A}=b.mulSecret(this,w,a,g);return g([v,A])[0]}multiplyUnsafe(w){if(!s.isValid(w))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return w===vs?p.ZERO:this.is0()||w===Ss?this:b.mulUnsafe(this,w,g)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return b.mulUnsafe(this,i.n).is0()}toAffine(w){let v=this,A=w;if(A!=null&&typeof A!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof A);let{X:M,Y:$,Z:k}=v,D=v.is0();A==null&&(A=D?o.create(Kd):o.inv(k));let B=o.mul(M,A),V=o.mul($,A),W=o.mul(k,A);if(D)return{x:o.ZERO,y:o.ONE};if(!o.eql(W,o.ONE))throw new Error("invZ was invalid");return{x:B,y:V}}clearCofactor(){return a===Ss?this:a===As?this.double():a===My?this.double().double():a===Kd?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:w,y:v}=this.toAffine(),A=o.toBytes(v);return A[A.length-1]|=l(w)?128:0,A}toHex(){return Kn(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let g=S=>bs(p,S),b=new Yr(p,c);return b.bits>=6&&p.BASE.precompute(6),Object.freeze(p.prototype),Object.freeze(p),p}function $d(r,e,t={}){if(jt(r),typeof e!="function")throw new Error('"hash" function param is required');let n=e,o=t;Ve(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=r,u=n.outputLen,l=2*a.BYTES;if(u!==void 0&&(Tt(u,"hash.outputLen"),u!==l))throw new Error(`hash.outputLen must be ${l}, got ${u}`);let f=o.randomBytes===void 0?lr:o.randomBytes,d=o.toMontgomery,h=o.toMontgomerySecret,y=o.adjustScalarBytes===void 0?L=>L:o.adjustScalarBytes,p=o.domain===void 0?(L,z,H)=>{if(ze(H,"phflag"),z.length||H)throw new Error("Contexts/pre-hash are not supported");return L}:o.domain;function g(L){return c.create(fr(L))}function b(L){let z=D.secretKey;J(L,D.secretKey,"secretKey");let H=J(n(L),2*z,"hashedSecretKey"),N=y(H.slice(0,z)),ue=H.slice(z,2*z),he=g(N);return{head:N,prefix:ue,scalar:he}}function S(L){let{head:z,prefix:H,scalar:N}=b(L),ue=i.multiply(N),he=ue.toBytes();return{head:z,prefix:H,scalar:N,point:ue,pointBytes:he}}function w(L){return S(L).pointBytes}function v(L=Uint8Array.of(),...z){let H=ot(...z);return g(n(p(H,J(L,void 0,"context"),!!s)))}function A(L,z,H={}){Ve(H,{},{},"options"),L=$n(J(L,void 0,"message")),s&&(L=s(L));let{prefix:N,scalar:ue,pointBytes:he}=S(z),_=v(H.context,N,L),m=i.multiply(_).toBytes(),x=v(H.context,m,he,L),E=c.create(_+x*ue);if(!c.isValid(E))throw new Error("sign failed: invalid s");let C=ot(m,c.toBytes(E));return J(C,D.signature,"result")}let M={zip215:o.zip215};function $(L,z,H,N=M){Ve(N);let{context:ue}=N,he=N.zip215===void 0?!!M.zip215:N.zip215,_=D.signature;L=J(L,_,"signature"),z=J(z,void 0,"message"),H=J(H,D.publicKey,"publicKey"),he!==void 0&&ze(he,"zip215"),s&&(z=s(z));let m=_/2,x=L.subarray(0,m),E=fr(L.subarray(m,_)),C,P,R;try{C=r.fromBytes(H,he),P=r.fromBytes(x,he),R=i.multiplyUnsafe(E)}catch{return!1}if(!he&&C.isSmallOrder())return!1;let U=v(ue,x,H,z);return P.add(C.multiplyUnsafe(U)).subtract(R).clearCofactor().is0()}let k=a.BYTES,D={secretKey:k,publicKey:k,signature:2*k,seed:k};function B(L){return L=L===void 0?f(D.seed):L,J(L,D.seed,"seed")}function V(L){return Wt(L)&&L.length===D.secretKey}function W(L,z){try{return!!r.fromBytes(L,z===void 0?M.zip215:z)}catch{return!1}}let oe={getExtendedPublicKey:S,randomSecretKey:B,isValidSecretKey:V,isValidPublicKey:W,toMontgomery(L){if(d===void 0)throw new Error("Montgomery conversion is not supported for this curve");return d(r.fromBytes(L))},toMontgomerySecret(L){if(h===void 0)throw new Error("Montgomery conversion is not supported for this curve");return h(L)}};return Object.freeze(D),Object.freeze(oe),Object.freeze({keygen:Es(B,w),getPublicKey:w,sign:A,verify:$,utils:oe,Point:r,lengths:D})}var Fc=BigInt(1),zd=BigInt(2);var Fy=BigInt(5),Uy=BigInt(8),Uc=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Ky={p:Uc,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Uy,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function qy(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),o=BigInt(80),s=Uc,a=r*r%s*r%s,c=de(a,zd,s)*a%s,u=de(c,Fc,s)*r%s,l=de(u,Fy,s)*u%s,f=de(l,e,s)*l%s,d=de(f,t,s)*f%s,h=de(d,n,s)*d%s,y=de(h,o,s)*h%s,p=de(y,o,s)*h%s,g=de(p,e,s)*l%s;return{pow_p_5_8:de(g,zd,s)*r%s,b2:a}}function Wd(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var Vd=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function $y(r,e){let t=Uc,n=me(e*e*e,t),o=me(n*n*e,t),s=qy(r*o).pow_p_5_8,i=me(r*n*s,t),a=me(e*i*i,t),c=i,u=me(i*Vd,t),l=a===r,f=a===me(-r,t),d=a===me(-r*Vd,t);return l&&(i=c),(f||d)&&(i=u),Od(i,t)&&(i=me(-i,t)),{isValid:l||f,value:i}}var Kc=qd(Ky,{uvRatio:$y}),Hd=Kc.Fp;function zy(r){let{y:e}=r;return Hd.toBytes(Hd.div(Fc+e,Fc-e))}function Vy(r){let e=Kc.Fp.BYTES;return nt(r,e),Wd(Tc(r.subarray(0,e))).subarray(0,e)}function Hy(r){return $d(Kc,Tc,Object.assign({adjustScalarBytes:Wd,toMontgomery:zy,toMontgomerySecret:Vy,zip215:!0},r))}var Wn=Hy({});var Gn=class extends Error{constructor(e="An error occurred while signing a message"){super(e),this.name="SigningError"}},jn=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},_s=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var He={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw new _s("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 e}};var Cs=32,Yn=64,qc=32;var Xr,Gd=(async()=>{try{return await He.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function jd(){let r=Wn.utils.randomSecretKey(),e=Wn.getPublicKey(r);return{privateKey:Xy(r,e),publicKey:e}}async function Wy(r,e){let t;r.length===Yn?t=r.subarray(0,32):t=r;let n={crv:"Ed25519",kty:"OKP",x:F(r.subarray(32),"base64url"),d:F(t,"base64url"),ext:!0,key_ops:["sign"]},o=await He.get().subtle.importKey("jwk",n,{name:"Ed25519"},!0,["sign"]),s=await He.get().subtle.sign({name:"Ed25519"},o,Te(e instanceof Uint8Array?e:e.subarray()));return new Uint8Array(s,0,s.byteLength)}function Gy(r,e){let t=r.subarray(0,qc);return Wn.sign(e instanceof Uint8Array?e:e.subarray(),t)}async function Yd(r,e){return Xr==null&&(Xr=await Gd),Xr?Wy(r,e):Gy(r,e)}async function jy(r,e,t){if(r.buffer instanceof ArrayBuffer){let n=await He.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await He.get().subtle.verify({name:"Ed25519"},n,Te(e),Te(t instanceof Uint8Array?t:t.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Yy(r,e,t){return Wn.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}async function Xd(r,e,t){return Xr==null&&(Xr=await Gd),Xr?jy(r,e,t):Yy(r,e,t)}function Xy(r,e){let t=new Uint8Array(Yn);for(let n=0;n<qc;n++)t[n]=r[n],t[qc+n]=e[n];return t}function Zr(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Xn=class{type="Ed25519";raw;constructor(e){this.raw=Is(e,Cs)}toMultihash(){return at.digest(rt(this))}toCID(){return xe.createV1(114,this.toMultihash())}toString(){return ie.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Q(this.raw,e.raw)}verify(e,t,n){n?.signal?.throwIfAborted();let o=Xd(this.raw,t,e);return Zr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}},Ts=class{type="Ed25519";raw;publicKey;constructor(e,t){this.raw=Is(e,Yn),this.publicKey=new Xn(t)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Q(this.raw,e.raw)}sign(e,t){t?.signal?.throwIfAborted();let n=Yd(this.raw,e);return Zr(n)?n.then(o=>(t?.signal?.throwIfAborted(),o)):(t?.signal?.throwIfAborted(),n)}};function $c(r){return r=Is(r,Cs),new Xn(r)}async function Qd(){let{privateKey:r,publicKey:e}=jd();return new Ts(r,e)}function Is(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new T(`Key must be a Uint8Array of length ${e}, got ${r.length}`);return r}var Zy=Math.pow(2,7),Qy=Math.pow(2,14),Jy=Math.pow(2,21),zc=Math.pow(2,28),Vc=Math.pow(2,35),Hc=Math.pow(2,42),Wc=Math.pow(2,49),te=128,Pe=127;function Ae(r){if(r<Zy)return 1;if(r<Qy)return 2;if(r<Jy)return 3;if(r<zc)return 4;if(r<Vc)return 5;if(r<Hc)return 6;if(r<Wc)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Qr(r,e,t=0){switch(Ae(r)){case 8:e[t++]=r&255|te,r/=128;case 7:e[t++]=r&255|te,r/=128;case 6:e[t++]=r&255|te,r/=128;case 5:e[t++]=r&255|te,r/=128;case 4:e[t++]=r&255|te,r>>>=7;case 3:e[t++]=r&255|te,r>>>=7;case 2:e[t++]=r&255|te,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function e0(r,e,t=0){switch(Ae(r)){case 8:e.set(t++,r&255|te),r/=128;case 7:e.set(t++,r&255|te),r/=128;case 6:e.set(t++,r&255|te),r/=128;case 5:e.set(t++,r&255|te),r/=128;case 4:e.set(t++,r&255|te),r>>>=7;case 3:e.set(t++,r&255|te),r>>>=7;case 2:e.set(t++,r&255|te),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Gc(r,e){let t=r[e],n=0;if(n+=t&Pe,t<te||(t=r[e+1],n+=(t&Pe)<<7,t<te)||(t=r[e+2],n+=(t&Pe)<<14,t<te)||(t=r[e+3],n+=(t&Pe)<<21,t<te)||(t=r[e+4],n+=(t&Pe)*zc,t<te)||(t=r[e+5],n+=(t&Pe)*Vc,t<te)||(t=r[e+6],n+=(t&Pe)*Hc,t<te)||(t=r[e+7],n+=(t&Pe)*Wc,t<te))return n;throw new RangeError("Could not decode varint")}function t0(r,e){let t=r.get(e),n=0;if(n+=t&Pe,t<te||(t=r.get(e+1),n+=(t&Pe)<<7,t<te)||(t=r.get(e+2),n+=(t&Pe)<<14,t<te)||(t=r.get(e+3),n+=(t&Pe)<<21,t<te)||(t=r.get(e+4),n+=(t&Pe)*zc,t<te)||(t=r.get(e+5),n+=(t&Pe)*Vc,t<te)||(t=r.get(e+6),n+=(t&Pe)*Hc,t<te)||(t=r.get(e+7),n+=(t&Pe)*Wc,t<te))return n;throw new RangeError("Could not decode varint")}function Yt(r,e,t=0){return e==null&&(e=Se(Ae(r))),e instanceof Uint8Array?Qr(r,e,t):e0(r,e,t)}function dr(r,e=0){return r instanceof Uint8Array?Gc(r,e):t0(r,e)}var jc=new Float32Array([-0]),Xt=new Uint8Array(jc.buffer);function Jd(r,e,t){jc[0]=r,e[t]=Xt[0],e[t+1]=Xt[1],e[t+2]=Xt[2],e[t+3]=Xt[3]}function eh(r,e){return Xt[0]=r[e],Xt[1]=r[e+1],Xt[2]=r[e+2],Xt[3]=r[e+3],jc[0]}var Yc=new Float64Array([-0]),De=new Uint8Array(Yc.buffer);function th(r,e,t){Yc[0]=r,e[t]=De[0],e[t+1]=De[1],e[t+2]=De[2],e[t+3]=De[3],e[t+4]=De[4],e[t+5]=De[5],e[t+6]=De[6],e[t+7]=De[7]}function rh(r,e){return De[0]=r[e],De[1]=r[e+1],De[2]=r[e+2],De[3]=r[e+3],De[4]=r[e+4],De[5]=r[e+5],De[6]=r[e+6],De[7]=r[e+7],Yc[0]}var r0=BigInt(Number.MAX_SAFE_INTEGER),n0=BigInt(Number.MIN_SAFE_INTEGER),Ge=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return hr;if(e<r0&&e>n0)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,o=e-(n<<32n);return t&&(n=~n|0n,o=~o|0n,++o>nh&&(o=0n,++n>nh&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return hr;let t=e<0;t&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return t&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):hr}},hr=new Ge(0,0);hr.toBigInt=function(){return 0n};hr.zzEncode=hr.zzDecode=function(){return this};hr.length=function(){return 1};var nh=4294967296n;function oh(r){let e=0,t=0;for(let n=0;n<r.length;++n)t=r.charCodeAt(n),t<128?e+=1:t<2048?e+=2:(t&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function sh(r,e,t){if(t-e<1)return"";let o,s=[],i=0,a;for(;e<t;)a=r[e++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&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 Xc(r,e,t){let n=t,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128);return t-n}function lt(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function Ls(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Zc=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=Te(e),this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,lt(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw lt(this,4);return Ls(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw lt(this,4);return Ls(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw lt(this,4);let e=eh(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw lt(this,4);let e=rh(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),t=this.pos,n=this.pos+e;if(n>this.len)throw lt(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return sh(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw lt(this,e);this.pos+=e}else do if(this.pos>=this.len)throw lt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Ge(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw lt(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<t*7)>>>0,e}if(this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw lt(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw lt(this,8);let e=Ls(this.buf,this.pos+=4),t=Ls(this.buf,this.pos+=4);return new Ge(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Gc(this.buf,this.pos);return this.pos+=Ae(e),e}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 Qn(r){return new Zc(r instanceof Uint8Array?r:r.subarray())}function Be(r,e,t){let n=Qn(r);return e.decode(n,void 0,t)}function Qc(r){let e=r??8192,t=e>>>1,n,o=e;return function(i){if(i<1||i>t)return Se(i);o+i>e&&(n=Se(e),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var pr=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function Jc(){}var tu=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},o0=Qc();function s0(r){return globalThis.Buffer!=null?Se(r):o0(r)}var eo=class{len;head;tail;states;constructor(){this.len=0,this.head=new pr(Jc,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new pr(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new ru((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(Ps,10,Ge.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=Ge.fromBigInt(e);return this._push(Ps,t.length(),t)}uint64Number(e){return this._push(Qr,Ae(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=Ge.fromBigInt(e).zzEncode();return this._push(Ps,t.length(),t)}sint64Number(e){let t=Ge.fromNumber(e).zzEncode();return this._push(Ps,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(eu,1,e?1:0)}fixed32(e){return this._push(Jn,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=Ge.fromBigInt(e);return this._push(Jn,4,t.lo)._push(Jn,4,t.hi)}fixed64Number(e){let t=Ge.fromNumber(e);return this._push(Jn,4,t.lo)._push(Jn,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(Jd,4,e)}double(e){return this._push(th,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(eu,1,0):this.uint32(t)._push(a0,t,e)}string(e){let t=oh(e);return t!==0?this.uint32(t)._push(Xc,t,e):this._push(eu,1,0)}fork(){return this.states=new tu(this),this.head=this.tail=new pr(Jc,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 pr(Jc,0,0),this.len=0),this}ldelim(){let e=this.head,t=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=t,this.len+=n),this}finish(){let e=this.head.next,t=s0(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function eu(r,e,t){e[t]=r&255}function i0(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var ru=class extends pr{next;constructor(e,t){super(i0,e,t),this.next=void 0}};function Ps(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function Jn(r,e,t){e[t]=r&255,e[t+1]=r>>>8&255,e[t+2]=r>>>16&255,e[t+3]=r>>>24}function a0(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(eo.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(c0,e,r),this},eo.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(u0,e,r),this});function c0(r,e,t){e.set(r,t)}function u0(r,e,t){r.length<40?Xc(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(I(r),t)}function nu(){return new eo}function Fe(r,e){let t=nu();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}function*Ue(r,e,t){let n=Qn(r);yield*e.stream(n,void 0,".",t)}var Ds={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Rs(r,e,t,n,o){return{name:r,type:e,encode:t,decode:n,stream:o}}function ou(r){function e(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let t=function(i,a){let c=e(i);a.int32(c)},n=function(i){let a=i.int32();return e(a)},o=function*(i,a){};return Rs("enum",Ds.VARINT,t,n,o)}function Ke(r,e,t){return Rs("message",Ds.LENGTH_DELIMITED,r,e,t)}var st=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},to=class extends Error{code="ERR_MAX_SIZE";name="MaxSizeError"};var ge;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(ge||(ge={}));var su;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(su||(su={}));(function(r){r.codec=()=>ou(su)})(ge||(ge={}));var wt;(function(r){let e;r.codec=()=>(e==null&&(e=Ke((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ge.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let l=s.uint32();switch(l>>>3){case 1:{c.Type=ge.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(l&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let l=s.uint32();switch(l>>>3){case 1:{yield{field:`${a}.Type`,value:ge.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(l&7);break}}}})),e);function t(s){return Fe(s,r.codec())}r.encode=t;function n(s,i){return Be(s,r.codec(),i)}r.decode=n;function o(s,i){return Ue(s,r.codec(),i)}r.stream=o})(wt||(wt={}));var iu;(function(r){let e;r.codec=()=>(e==null&&(e=Ke((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ge.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let l=s.uint32();switch(l>>>3){case 1:{c.Type=ge.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(l&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let l=s.uint32();switch(l>>>3){case 1:{yield{field:`${a}.Type`,value:ge.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(l&7);break}}}})),e);function t(s){return Fe(s,r.codec())}r.encode=t;function n(s,i){return Be(s,r.codec(),i)}r.decode=n;function o(s,i){return Ue(s,r.codec(),i)}r.stream=o})(iu||(iu={}));var no={};$e(no,{MAX_RSA_KEY_SIZE:()=>au,generateRSAKeyPair:()=>gu,jwkToJWKKeyPair:()=>fh,jwkToPkcs1:()=>h0,jwkToPkix:()=>fu,jwkToRSAPrivateKey:()=>mu,pkcs1MessageToJwk:()=>uu,pkcs1MessageToRSAPrivateKey:()=>du,pkcs1ToJwk:()=>d0,pkcs1ToRSAPrivateKey:()=>lh,pkixMessageToJwk:()=>lu,pkixMessageToRSAPublicKey:()=>pu,pkixToJwk:()=>p0,pkixToRSAPublicKey:()=>hu});var Jr=class{type="RSA";jwk;_raw;_multihash;constructor(e,t){this.jwk=e,this._multihash=t}get raw(){return this._raw==null&&(this._raw=no.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return xe.createV1(114,this._multihash)}toString(){return ie.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Q(this.raw,e.raw)}verify(e,t,n){return uh(this.jwk,t,e,n)}},ro=class{type="RSA";jwk;_raw;publicKey;constructor(e,t){this.jwk=e,this.publicKey=t}get raw(){return this._raw==null&&(this._raw=no.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Q(this.raw,e.raw)}sign(e,t){return ch(this.jwk,e,t)}};var au=8192,cu=18,l0=1062,f0=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function d0(r){let e=_t(r);return uu(e)}function uu(r){return{n:F(r[1],"base64url"),e:F(r[2],"base64url"),d:F(r[3],"base64url"),p:F(r[4],"base64url"),q:F(r[5],"base64url"),dp:F(r[6],"base64url"),dq:F(r[7],"base64url"),qi:F(r[8],"base64url"),kty:"RSA"}}function h0(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 T("JWK was missing components");return ct([Me(Uint8Array.from([0])),Me(I(r.n,"base64url")),Me(I(r.e,"base64url")),Me(I(r.d,"base64url")),Me(I(r.p,"base64url")),Me(I(r.q,"base64url")),Me(I(r.dp,"base64url")),Me(I(r.dq,"base64url")),Me(I(r.qi,"base64url"))]).subarray()}function p0(r){let e=_t(r,{offset:0});return lu(e)}function lu(r){let e=_t(r[1],{offset:0});return{kty:"RSA",n:F(e[0],"base64url"),e:F(e[1],"base64url")}}function fu(r){if(r.n==null||r.e==null)throw new T("JWK was missing components");return ct([f0,Mn(ct([Me(I(r.n,"base64url")),Me(I(r.e,"base64url"))]))]).subarray()}function lh(r){let e=_t(r);return du(e)}function du(r){let e=uu(r);return mu(e)}function hu(r,e){if(r.byteLength>=l0)throw new mt("Key size is too large");let t=_t(r,{offset:0});return pu(t,r,e)}function pu(r,e,t){let n=lu(r);if(t==null){let o=zr(wt.encode({Type:ge.RSA,Data:e}));t=gt(cu,o)}return new Jr(n,t)}function mu(r){if(hh(r)>au)throw new T("Key size is too large");let e=fh(r),t=zr(wt.encode({Type:ge.RSA,Data:fu(e.publicKey)})),n=gt(cu,t);return new ro(e.privateKey,new Jr(e.publicKey,n))}async function gu(r){if(r>au)throw new T("Key size is too large");let e=await dh(r),t=zr(wt.encode({Type:ge.RSA,Data:fu(e.publicKey)})),n=gt(cu,t);return new ro(e.privateKey,new Jr(e.publicKey,n))}function fh(r){if(r==null)throw new T("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function dh(r,e){let t=await He.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await m0(t,e);return{privateKey:n[0],publicKey:n[1]}}async function ch(r,e,t){let n=await He.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);t?.signal?.throwIfAborted();let o=await He.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,Te(e instanceof Uint8Array?e:e.subarray()));return t?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function uh(r,e,t,n){let o=await He.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await He.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,Te(e),Te(t instanceof Uint8Array?t:t.subarray()));return n?.signal?.throwIfAborted(),s}async function m0(r,e){if(r.privateKey==null||r.publicKey==null)throw new T("Private and public key are required");let t=await Promise.all([He.get().subtle.exportKey("jwk",r.privateKey),He.get().subtle.exportKey("jwk",r.publicKey)]);return e?.signal?.throwIfAborted(),t}function hh(r){if(r.kty!=="RSA")throw new T("invalid key type");if(r.n==null)throw new T("invalid key modulus");return I(r.n,"base64url").length*8}var Os=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,t){if(ss(e),nt(t,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(t.length>n?e.create().update(t).digest():t);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),cr(o)}update(e){return $r(this),this.iHash.update(e),this}digestInto(e){$r(this),is(e,this),this.finished=!0;let t=e.subarray(0,this.outputLen);this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:t,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a,canXOF:c}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.canXOF=c,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ph=(()=>{let r=((e,t,n)=>new Os(e,t).update(n).digest());return r.create=(e,t)=>new Os(e,t),r})();var g0=BigInt(0),yu=class extends Error{constructor(e=""){super(e)}},It={Err:yu,_tlv:{encode:(r,e)=>{let{Err:t}=It;if(Tt(r,"tag"),r<0||r>255)throw new t("tlv.encode: wrong tag");if(xd(e,"data"),e.length&1)throw new t("tlv.encode: unpadded data");let n=e.length/2,o=qn(n);if(o.length/2&128)throw new t("tlv.encode: long form length too big");let s=n>127?qn(o.length/2|128):"";return qn(r)+s+o+e},decode(r,e){let{Err:t}=It;e=J(e,void 0,"DER data");let n=0;if(r<0||r>255)throw new t("tlv.decode: wrong tag");if(e.length<2||e[n++]!==r)throw new t("tlv.decode: wrong tlv");let o=e[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new t("tlv.decode(long): indefinite length not supported");if(c>4)throw new t("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+c);if(u.length!==c)throw new t("tlv.decode: length bytes not complete");if(u[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(let l of u)i=i<<8|l;if(n+=c,i<128)throw new t("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+i);if(a.length!==i)throw new t("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(r){let{Err:e}=It;if(ds(r),r<g0)throw new e("integer: negative integers are not allowed");let t=qn(r);if(Number.parseInt(t[0],16)&8&&(t="00"+t),t.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return t},decode(r){let{Err:e}=It;if(r.length<1)throw new e("invalid signature integer: empty");if(r[0]&128)throw new e("invalid signature integer: negative");if(r.length>1&&r[0]===0&&!(r[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return bt(r)}},toSig(r,e){let{Err:t,_int:n,_tlv:o}=It;if(e!==void 0&&(Tt(e,"maxScalarBytes"),e<1))throw new t("invalid signature: maxScalarBytes must be positive");let s=J(r,void 0,"signature"),{v:i,l:a}=o.decode(48,s);if(a.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:u}=o.decode(2,i),{v:l,l:f}=o.decode(2,u);if(f.length)throw new t("invalid signature: left bytes after parsing");if(e!==void 0&&(c.length>e||l.length>e))throw new t("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(l)}},hexFromSig(r){let{_tlv:e,_int:t}=It;Ve(r,{r:"bigint",s:"bigint"},{},"sig");let n=e.encode(2,t.encode(r.r)),o=e.encode(2,t.encode(r.s)),s=n+o;return e.encode(48,s)}},ks=(Object.freeze(It._tlv),Object.freeze(It._int),Object.freeze(It));var mh=(r,e)=>(r+(r>=0?e:-e)/gh)/e;function y0(r,e,t){Hr("scalar",r,Lt,t);let[[n,o],[s,i]]=e,a=mh(i*r,t),c=mh(-o*r,t),u=r-a*n-c*s,l=-a*o-c*i,f=u<Lt,d=l<Lt;f&&(u=-u),d&&(l=-l);let h=zn(Math.ceil(Wr(t)/2))+mr;if(u<Lt||u>=h||l<Lt||l>=h)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:f,k1:u,k2neg:d,k2:l}}function xu(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function bu(r,e){Ve(r);let t={};for(let n of Object.keys(e))t[n]=r[n]===void 0?e[n]:r[n];return ze(t.lowS,"lowS"),ze(t.prehash,"prehash"),t.format!==void 0&&xu(t.format),t}var Lt=BigInt(0),mr=BigInt(1),gh=BigInt(2),wu=BigInt(3),b0=BigInt(4);function yh(r,e={}){let t=xs("weierstrass",r,e),n=t.Fp,o=t.Fn,s=t.CURVE,{h:i,n:a}=s;Ve(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u,clearCofactor:l,isTorsionFree:f,fromBytes:d,toBytes:h}=e,y=e.randomBytes===void 0?lr:e.randomBytes;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let p=c?{beta:c.beta,basises:c.basises.map(_=>[..._])}:void 0,g=wh(n,o);function b(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function S(_,m,x){if(m.is0()){if(!u)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:E,y:C}=m.toAffine(),P=n.toBytes(E);if(ze(x,"isCompressed"),x){b();let R=!n.isOdd(C);return ot(bh(R),P)}else return ot(Uint8Array.of(4),P,n.toBytes(C))}function w(_){J(_,void 0,"Point");let{publicKey:m,publicKeyUncompressed:x}=g,E=_.length,C=_[0],P=_.subarray(1);if(u&&E===1&&C===0)return{x:n.ZERO,y:n.ZERO};if(E===m&&(C===2||C===3)){let R=n.fromBytes(P);if(!n.isValid(R))throw new Error("bad point: is not on curve, wrong x");let U=k(R),K;try{K=n.sqrt(U)}catch(be){let le=be instanceof Error?": "+be.message:"";throw new Error("bad point: is not on curve, sqrt error"+le)}b();let Z=n.isOdd(K);return(C&1)===1!==Z&&(K=n.neg(K)),{x:R,y:K}}else if(E===x&&C===4){let R=n.BYTES,U=n.fromBytes(P.subarray(0,R)),K=n.fromBytes(P.subarray(R,R*2));if(!D(U,K))throw new Error("bad point: is not on curve");return{x:U,y:K}}else throw new Error(`bad point: got length ${E}, expected compressed=${m} or uncompressed=${x}`)}let v=h===void 0?S:h,A=d===void 0?w:d,M=n.mul(s.b,wu),$=n.is0(s.a)?_=>n.ZERO:_=>n.mul(s.a,_);function k(_){let m=n.sqr(_),x=n.mul(m,_);return n.add(n.add(x,n.mul(_,s.a)),s.b)}function D(_,m){let x=n.sqr(m),E=k(_);return n.eql(x,E)}if(!D(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let B=n.mul(n.pow(s.a,wu),b0),V=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(B,V)))throw new Error("bad curve params: a or b");function W(_,m,x=!1){if(!n.isValid(m)||x&&n.is0(m))throw new Error(`bad point coordinate ${_}`);return typeof m=="object"&&m!==null?n.create(m):m}function oe(_){if(!(_ instanceof N))throw new Error("Weierstrass Point expected")}function L(_){if(!p||!p.basises)throw new Error("no endo");return y0(_,p.basises,o.ORDER)}function z(_,m,x,E){if(!o.isValid(E))throw new RangeError("invalid scalar: out of range");if(p){let{k1neg:C,k1:P,k2neg:R,k2:U}=L(E),K=new N(n.mul(x.X,p.beta),x.Y,x.Z);_.push(C?x.negate():x,R?K.negate():K),m.push(P,U)}else _.push(x),m.push(E)}let H=new WeakSet;class N{static BASE=new N(s.Gx,s.Gy,n.ONE);static ZERO=new N(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(m,x,E){this.X=W("x",m),this.Y=W("y",x,!0),this.Z=W("z",E),Object.freeze(this)}static CURVE(){return s}static fromAffine(m){let{x,y:E}=m||{};if(!m||!n.isValid(x)||!n.isValid(E))throw new Error("invalid affine point");if(m instanceof N)throw new Error("projective point not allowed");return n.is0(x)&&n.is0(E)?N.ZERO:new N(x,E,n.ONE)}static fromBytes(m){let x=N.fromAffine(A(J(m,void 0,"point")));return x.assertValidity(),x}static fromHex(m){return N.fromBytes(Vr(m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=6,x=!0){return he.setWindowSize(this,m),x||this.multiply(wu),this}assertValidity(){let m=this;if(m.is0()){if(u&&n.is0(m.X)&&n.eql(m.Y,n.ONE)&&n.is0(m.Z))return;throw new Error("bad point: ZERO")}if(H.has(m))return;let{x,y:E}=m.toAffine();if(!n.isValid(x)||!n.isValid(E))throw new Error("bad point: x or y not field elements");if(!D(x,E))throw new Error("bad point: equation left != right");if(!m.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");H.add(m)}hasEvenY(){let{y:m}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(m)}equals(m){oe(m);let{X:x,Y:E,Z:C}=this,{X:P,Y:R,Z:U}=m,K=n.eql(n.mul(x,U),n.mul(P,C)),Z=n.eql(n.mul(E,U),n.mul(R,C));return K&&Z}negate(){return new N(this.X,n.neg(this.Y),this.Z)}double(){let{X:m,Y:x,Z:E}=this,C=n.ZERO,P=n.ZERO,R=n.ZERO,U=n.mul(m,m),K=n.mul(x,x),Z=n.mul(E,E),j=n.mul(m,x);return j=n.add(j,j),R=n.mul(m,E),R=n.add(R,R),C=$(R),P=n.mul(M,Z),P=n.add(C,P),C=n.sub(K,P),P=n.add(K,P),P=n.mul(C,P),C=n.mul(j,C),R=n.mul(M,R),Z=$(Z),j=n.sub(U,Z),j=$(j),j=n.add(j,R),R=n.add(U,U),U=n.add(R,U),U=n.add(U,Z),U=n.mul(U,j),P=n.add(P,U),Z=n.mul(x,E),Z=n.add(Z,Z),U=n.mul(Z,j),C=n.sub(C,U),R=n.mul(Z,K),R=n.add(R,R),R=n.add(R,R),new N(C,P,R)}add(m){oe(m);let{X:x,Y:E,Z:C}=this,{X:P,Y:R,Z:U}=m,K=n.ZERO,Z=n.ZERO,j=n.ZERO,be=n.mul(x,P),le=n.mul(E,R),ve=n.mul(C,U),Ze=n.add(x,E),fe=n.add(P,R);Ze=n.mul(Ze,fe),fe=n.add(be,le),Ze=n.sub(Ze,fe),fe=n.add(x,C);let we=n.add(P,U);return fe=n.mul(fe,we),we=n.add(be,ve),fe=n.sub(fe,we),we=n.add(E,C),K=n.add(R,U),we=n.mul(we,K),K=n.add(le,ve),we=n.sub(we,K),j=$(fe),K=n.mul(M,ve),j=n.add(K,j),K=n.sub(le,j),j=n.add(le,j),Z=n.mul(K,j),le=n.add(be,be),le=n.add(le,be),ve=$(ve),fe=n.mul(M,fe),le=n.add(le,ve),ve=n.sub(be,ve),ve=$(ve),fe=n.add(fe,ve),be=n.mul(le,fe),Z=n.add(Z,be),be=n.mul(we,fe),K=n.mul(Ze,K),K=n.sub(K,be),be=n.mul(Ze,le),j=n.mul(we,j),j=n.add(j,be),new N(K,Z,j)}subtract(m){return oe(m),this.add(m.negate())}is0(){return this.equals(N.ZERO)}multiply(m){if(!o.isValidNot0(m))throw new RangeError("invalid scalar: out of range");let{p:x,f:E}=he.mulSecret(this,m,i,ue);return ue([x,E])[0]}multiplyUnsafe(m){let x=this,E=m;if(!o.isValid(E))throw new RangeError("invalid scalar: out of range");if(E===Lt||x.is0())return N.ZERO;if(E===mr)return x;if(he.hasWindowSize(this))return he.mulUnsafe(x,E,ue);let C=[],P=[];return z(C,P,x,E),ws(N,C,P)}mulAddUnsafe(m,x,E){oe(x);let C=[],P=[];return z(C,P,this,m),z(C,P,x,E),ws(N,C,P)}toAffine(m){let x=this,E=m;if(E!=null&&!n.isValid(E))throw new RangeError('"invertedZ" expected valid field element');let{X:C,Y:P,Z:R}=x;if(n.eql(R,n.ONE))return{x:C,y:P};let U=x.is0();E==null&&(E=U?n.ONE:n.inv(R));let K=n.mul(C,E),Z=n.mul(P,E),j=n.mul(R,E);if(U)return{x:n.ZERO,y:n.ZERO};if(!n.eql(j,n.ONE))throw new Error("invZ was invalid");return{x:K,y:Z}}isTorsionFree(){return i===mr?!0:f?f(N,this):he.mulUnsafe(this,a).is0()}clearCofactor(){return i===mr?this:l?l(N,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===mr?this.is0():this.clearCofactor().is0()}toBytes(m=!0){return ze(m,"isCompressed"),this.assertValidity(),v(N,this,m)}toHex(m=!0){return Kn(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let ue=_=>bs(N,_),he=new Yr(N,y);return he.bits>=6&&N.BASE.precompute(6),Object.freeze(N.prototype),Object.freeze(N),N}function bh(r){return Uint8Array.of(r?2:3)}function wh(r,e){return{secretKey:e.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function w0(r,e={}){jt(r);let{Fn:t}=r,n=e.randomBytes===void 0?lr:e.randomBytes,o=Object.assign(wh(r.Fp,t),{seed:Math.max(gs(t.ORDER),16)});function s(h){try{let y=t.fromBytes(h);return t.isValidNot0(y)}catch{return!1}}function i(h,y){let{publicKey:p,publicKeyUncompressed:g}=o;try{let b=h.length;return y===!0&&b!==p||y===!1&&b!==g?!1:!r.fromBytes(h).is0()}catch{return!1}}function a(h){return h=h===void 0?n(o.seed):h,ys(J(h,o.seed,"seed"),t.ORDER)}function c(h,y=!0){return r.BASE.multiply(t.fromBytes(h)).toBytes(y)}function u(h){let{secretKey:y,publicKey:p,publicKeyUncompressed:g}=o,b=t._lengths;if(!Wt(h))return;let S=J(h,void 0,"key").length,w=S===p||S===g,v=S===y||!!b?.includes(S);if(!(w&&v))return w}function l(h,y,p=!0){if(u(h)===!0)throw new Error("first arg must be private key");if(u(y)===!1)throw new Error("second arg must be public key");let g=t.fromBytes(h),b=r.fromBytes(y);if(b.is0())throw new Error("invalid public key: point at infinity");return b.multiply(g).toBytes(p)}let f={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},d=Es(a,c);return Object.freeze(f),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:l,keygen:d,Point:r,utils:f,lengths:o})}function xh(r,e,t={}){jt(r);let n=e;ss(n),Ve(t,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},t),s=o.randomBytes===void 0?lr:o.randomBytes,i=o.hmac===void 0?(_,m)=>ph(n,_,m):o.hmac,{Fp:a,Fn:c}=r,{ORDER:u,BITS:l}=c,f=gs(u),d=Bc(s,f),{keygen:h,getPublicKey:y,getSharedSecret:p,utils:g,lengths:b}=w0(r,o),S={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},w=u*gh+mr<a.ORDER;function v(_){let m=u>>mr;return _>m}function A(_,m){if(!c.isValidNot0(m))throw new Error(`invalid signature ${_}: out of range 1..Point.Fn.ORDER`);return m}function M(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function $(_,m,x){return M(),(_===x?0:2)|Number(a.isOdd(m))}function k(){if(w)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function D(_,m){xu(m);let x=b.signature,E=m==="compact"?x:m==="recovered"?x+1:void 0;return J(_,E)}class B{r;s;recovery;constructor(m,x,E){if(this.r=A("r",m),this.s=A("s",x),E!=null){if(k(),![0,1,2,3].includes(E))throw new Error("invalid recovery id");this.recovery=E}Object.freeze(this)}static fromBytes(m,x=S.format){D(m,x);let E;if(x==="der"){if(m.length>2*c.BYTES+16)throw new ks.Err("invalid signature: DER signature too long");let{r:U,s:K}=ks.toSig(J(m),c.BYTES+1);return new B(U,K)}x==="recovered"&&(E=m[0],x="compact",m=m.subarray(1));let C=b.signature/2,P=m.subarray(0,C),R=m.subarray(C,C*2);return new B(c.fromBytes(P),c.fromBytes(R),E)}static fromHex(m,x){return this.fromBytes(Vr(m),x)}assertRecovery(){let{recovery:m}=this;if(m==null)throw new Error("invalid recovery id: must be present");return m}addRecoveryBit(m){return new B(this.r,this.s,m)}recoverPublicKey(m){let{r:x,s:E}=this,C=this.assertRecovery(),P=C===2||C===3?x+u:x;if(!a.isValid(P))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let R=a.toBytes(P),U=r.fromBytes(ot(bh((C&1)===0),R)),K=c.inv(P),Z=W(J(m,void 0,"msgHash")),j=c.create(-Z*K),be=c.create(E*K),le=r.BASE.mulAddUnsafe(j,U,be);if(le.is0())throw new Error("invalid recovery: point at infinify");return le.assertValidity(),le}hasHighS(){return v(this.s)}toBytes(m=S.format){if(xu(m),m==="der")return Vr(ks.hexFromSig(this));let{r:x,s:E}=this,C=c.toBytes(x),P=c.toBytes(E);return m==="recovered"?(k(),ot(Uint8Array.of(this.assertRecovery()),C,P)):ot(C,P)}toHex(m){return Kn(this.toBytes(m))}}Object.freeze(B.prototype),Object.freeze(B);let V=o.bits2int===void 0?function(m){if(m.length>8192)throw new Error("input is too large");let x=bt(m),E=m.length*8-l;return E>0?x>>BigInt(E):x}:o.bits2int,W=o.bits2int_modN===void 0?function(m){return c.create(V(m))}:o.bits2int_modN,oe=zn(l);function L(_){return Hr("num < 2^"+l,_,Lt,oe),c.toBytes(_)}function z(_,m){return J(_,void 0,"message"),m?J(n(_),void 0,"prehashed message"):_}function H(_,m,x){let{lowS:E,prehash:C,extraEntropy:P}=bu(x,S);_=z(_,C);let R=W(_),U=c.fromBytes(m);if(!c.isValidNot0(U))throw new Error("invalid private key");let K=[L(U),L(R)];if(P!=null&&P!==!1){let le=P===!0?s(b.secretKey):P;K.push(J(le,void 0,"extraEntropy"))}let Z=ot(...K),j=R;function be(le){let ve=V(le);if(!c.isValidNot0(ve))return;let Ze=r.BASE.multiply(ve).toAffine(),fe=c.create(Ze.x);if(fe===Lt)return;let we;if(d!==void 0){let An=bt(ys(d(f),u)),Tm=c.inv(c.mul(An,ve)),Im=c.mul(An,j),Lm=c.mul(An,U);we=c.create(Tm*c.create(Im+Lm*fe))}else{let An=Pd(ve,u);we=c.create(An*c.create(j+fe*U))}if(we===Lt)return;let Na=$(Ze.x,Ze.y,fe),hf=we;return E&&v(we)&&(hf=c.neg(we),Na^=1),new B(fe,hf,w?void 0:Na)}return{seed:Z,k2sig:be}}function N(_,m,x={}){let{seed:E,k2sig:C}=H(_,m,x);return vd(n.outputLen,c.BYTES,i)(E,C).toBytes(x.format)}function ue(_,m,x,E={}){let{lowS:C,prehash:P,format:R}=bu(E,S);if(x=J(x,void 0,"publicKey"),m=z(m,P),!Wt(_)){let U=_ instanceof B?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+U)}D(_,R);try{let U=B.fromBytes(_,R),K=r.fromBytes(x);if(K.is0()||C&&U.hasHighS())return!1;let{r:Z,s:j}=U,be=W(m),le=c.inv(j),ve=c.create(be*le),Ze=c.create(Z*le),fe=r.BASE.mulAddUnsafe(ve,K,Ze);if(fe.is0())return!1;let we=fe.toAffine();return!(c.create(we.x)!==Z||R==="recovered"&&U.recovery!==$(we.x,we.y,Z))}catch{return!1}}function he(_,m,x={}){let{prehash:E}=bu(x,S);return m=z(m,E),B.fromBytes(_,"recovered").recoverPublicKey(m).toBytes()}return Object.freeze({keygen:h,getPublicKey:y,getSharedSecret:p,utils:g,lengths:b,Point:r,sign:N,verify:ue,recoverPublicKey:he,Signature:B,hash:n})}var vu={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},x0={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Eh=BigInt(2);function E0(r){let e=vu.p,t=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%e,l=u*u*r%e,f=de(l,t,e)*l%e,d=de(f,t,e)*l%e,h=de(d,Eh,e)*u%e,y=de(h,o,e)*h%e,p=de(y,s,e)*y%e,g=de(p,a,e)*p%e,b=de(g,c,e)*g%e,S=de(b,a,e)*p%e,w=de(S,t,e)*l%e,v=de(w,i,e)*y%e,A=de(v,n,e)*u%e,M=de(A,Eh,e);if(!Eu.eql(Eu.sqr(M),r))throw new Error("Cannot find square root");return M}var Eu=jr(vu.p,{sqrt:E0}),v0=yh(vu,{Fp:Eu,endo:x0}),ft=xh(v0,zr);function vh(r,e,t){let n=qr.digest(e instanceof Uint8Array?e:e.subarray());if(Zr(n))return n.then(({digest:o})=>(t?.signal?.throwIfAborted(),ft.sign(o,r,{prehash:!1,format:"der"}))).catch(o=>{throw o.name==="AbortError"?o:new Gn(String(o))});try{return ft.sign(n.digest,r,{prehash:!1,format:"der"})}catch(o){throw new Gn(String(o))}}function Sh(r,e,t,n){let o=qr.digest(t instanceof Uint8Array?t:t.subarray());if(Zr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),ft.verify(e,s,r,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new jn(String(s))});try{return n?.signal?.throwIfAborted(),ft.verify(e,o.digest,r,{prehash:!1,format:"der"})}catch(s){throw new jn(String(s))}}var oo=class{type="secp256k1";raw;_key;constructor(e){this._key=Ch(e),this.raw=Ah(this._key)}toMultihash(){return at.digest(rt(this))}toCID(){return xe.createV1(114,this.toMultihash())}toString(){return ie.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Q(this.raw,e.raw)}verify(e,t,n){return Sh(this._key,t,e,n)}},Ns=class{type="secp256k1";raw;publicKey;constructor(e,t){this.raw=_h(e),this.publicKey=new oo(t??Th(e))}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Q(this.raw,e.raw)}sign(e,t){return vh(this.raw,e,t)}};function Su(r){return new oo(r)}async function Ih(){let r=S0();return new Ns(r)}function Ah(r){return ft.Point.fromBytes(r).toBytes()}function _h(r){try{return ft.getPublicKey(r,!0),r}catch(e){throw new _n(String(e))}}function Ch(r){try{return ft.Point.fromBytes(r),r}catch(e){throw new mt(String(e))}}function Th(r){try{return ft.getPublicKey(r,!0)}catch(e){throw new _n(String(e))}}function S0(){return ft.utils.randomSecretKey()}async function Lh(r,e){if(r==="Ed25519")return Qd();if(r==="secp256k1")return Ih();if(r==="RSA")return gu(A0(e));if(r==="ECDSA")return ed(_0(e));throw new Bt}function so(r,e){let{Type:t,Data:n}=wt.decode(r),o=n??new Uint8Array;switch(t){case ge.RSA:return hu(o,e);case ge.Ed25519:return $c(o);case ge.secp256k1:return Su(o);case ge.ECDSA:return gc(o);default:throw new Bt}}function Ph(r){let{Type:e,Data:t}=wt.decode(r.digest),n=t??new Uint8Array;switch(e){case ge.Ed25519:return $c(n);case ge.secp256k1:return Su(n);case ge.ECDSA:return gc(n);default:throw new Bt}}function rt(r){return wt.encode({Type:ge[r.type],Data:r.raw})}async function Dh(r,e,t){if(t?.signal?.throwIfAborted(),e!=null){let n;try{n=e instanceof Uint8Array?so(e):e}catch(o){throw new mt(`Could not decode public key - ${o.message}`)}if(!Q(n.toMultihash().bytes,r.toMultihash().bytes))throw new mt("Public key does not match peer id");return n}if(r.publicKey==null)throw new mt("No public key available for peer id");return r.publicKey}function A0(r){return r==null?2048:parseInt(r,10)}function _0(r){if(r==="P-256"||r==null)return"P-256";if(r==="P-384")return"P-384";if(r==="P-521")return"P-521";throw new T("Unsupported curve, should be P-256, P-384 or P-521")}var Rh=Symbol.for("nodejs.util.inspect.custom"),C0=114,io=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Xo]=!0;toString(){return this.string==null&&(this.string=ie.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return xe.createV1(C0,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return Q(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return Q(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[Rh](){return`PeerId(${this.toString()})`}},ao=class extends io{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},co=class extends io{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},uo=class extends io{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},T0=2336,lo=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=at.digest(I(this.url))}[Rh](){return`PeerId(${this.url})`}[Xo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return xe.createV1(T0,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=F(e)),e.toString()===this.toString())}};var I0=114,Oh=2336;function xt(r,e){let t;if(r.charAt(0)==="1"||r.charAt(0)==="Q")t=At(ie.decode(`z${r}`));else{if(r.startsWith("k51qzi5uqu5")||r.startsWith("kzwfwjn5ji4")||r.startsWith("k2k4r8")||r.startsWith("bafz"))return Au(xe.parse(r));if(e==null)throw new T('Please pass a multibase decoder for strings that do not start with "1" or "Q"');t=At(e.decode(r))}return en(t)}function fo(r){if(r.type==="Ed25519")return new co({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new uo({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new ao({multihash:r.toCID().multihash,publicKey:r});throw new Bt}function kh(r){return fo(r.publicKey)}function en(r){if(P0(r))return new ao({multihash:r});if(L0(r))try{let e=Ph(r);if(e.type==="Ed25519")return new co({multihash:r,publicKey:e});if(e.type==="secp256k1")return new uo({multihash:r,publicKey:e})}catch{let t=F(r.digest);return new lo(new URL(t))}throw new zo("Supplied PeerID Multihash is invalid")}function Au(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==I0&&r.code!==Oh)throw new $o("Supplied PeerID CID is invalid");if(r.code===Oh){let e=F(r.multihash.digest);return new lo(new URL(e))}return en(r.multihash)}function L0(r){return r.code===at.code}function P0(r){return r.code===qr.code}async function Nh(r){if(r.connectionProtector===null&&globalThis.process?.env?.LIBP2P_FORCE_PNET!=null)throw new T("Private network is enforced, but no protector was provided");return r}function Ms(r,e){if(typeof r=="string")return D0(r);if(typeof r=="number")return k0(r,e);throw new Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(r)}`)}function D0(r){if(typeof r!="string"||r.length===0||r.length>100)throw new Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(r)}`);let e=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(r);if(!e?.groups)return NaN;let{value:t,unit:n="ms"}=e.groups,o=parseFloat(t),s=n.toLowerCase();switch(s){case"years":case"year":case"yrs":case"yr":case"y":return o*315576e5;case"months":case"month":case"mo":return o*26298e5;case"weeks":case"week":case"w":return o*6048e5;case"days":case"day":case"d":return o*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return o*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return o*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return o*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return o;default:throw new Error(`Unknown unit "${s}" provided to ms.parse(). value=${JSON.stringify(r)}`)}}function R0(r){let e=Math.abs(r);return e>=315576e5?`${Math.round(r/315576e5)}y`:e>=26298e5?`${Math.round(r/26298e5)}mo`:e>=6048e5?`${Math.round(r/6048e5)}w`:e>=864e5?`${Math.round(r/864e5)}d`:e>=36e5?`${Math.round(r/36e5)}h`:e>=6e4?`${Math.round(r/6e4)}m`:e>=1e3?`${Math.round(r/1e3)}s`:`${r}ms`}function O0(r){let e=Math.abs(r);return e>=315576e5?gr(r,e,315576e5,"year"):e>=26298e5?gr(r,e,26298e5,"month"):e>=6048e5?gr(r,e,6048e5,"week"):e>=864e5?gr(r,e,864e5,"day"):e>=36e5?gr(r,e,36e5,"hour"):e>=6e4?gr(r,e,6e4,"minute"):e>=1e3?gr(r,e,1e3,"second"):`${r} ms`}function k0(r,e){if(typeof r!="number"||!Number.isFinite(r))throw new Error("Value provided to ms.format() must be of type number.");return e?.long?O0(r):R0(r)}function gr(r,e,t,n){let o=e>=t*1.5;return`${Math.round(r/t)} ${n}${o?"s":""}`}function _u(r){t.debug=t,t.default=t,t.coerce=c,t.disable=s,t.enable=o,t.enabled=i,t.humanize=Ms,t.destroy=u,Object.keys(r).forEach(l=>{t[l]=r[l]}),t.names=[],t.skips=[],t.formatters={};function e(l){let f=0;for(let d=0;d<l.length;d++)f=(f<<5)-f+l.charCodeAt(d),f|=0;return t.colors[Math.abs(f)%t.colors.length]}t.selectColor=e;function t(l,f){let d,h=null,y,p;function g(...b){if(!g.enabled)return;let S=g,w=Number(new Date),v=w-(d||w);S.diff=v,S.prev=d,S.curr=w,d=w,b[0]=t.coerce(b[0]),typeof b[0]!="string"&&b.unshift("%O");let A=0;b[0]=b[0].replace(/%([a-zA-Z%])/g,($,k)=>{if($==="%%")return"%";A++;let D=t.formatters[k];if(typeof D=="function"){let B=b[A];$=D.call(S,B),b.splice(A,1),A--}return $}),t.formatArgs.call(S,b),f?.onLog!=null&&f.onLog(...b),(S.log||t.log).apply(S,b)}return g.namespace=l,g.useColors=t.useColors(),g.color=t.selectColor(l),g.extend=n,g.destroy=t.destroy,Object.defineProperty(g,"enabled",{enumerable:!0,configurable:!1,get:()=>h!==null?h:(y!==t.namespaces&&(y=t.namespaces,p=t.enabled(l)),p),set:b=>{h=b}}),typeof t.init=="function"&&t.init(g),g}function n(l,f){let d=t(this.namespace+(typeof f>"u"?":":f)+l);return d.log=this.log,d}function o(l){t.save(l),t.namespaces=l,t.names=[],t.skips=[];let f,d=(typeof l=="string"?l:"").split(/[\s,]+/),h=d.length;for(f=0;f<h;f++)d[f]&&(l=d[f].replace(/\*/g,".*?"),l[0]==="-"?t.skips.push(new RegExp("^"+l.substr(1)+"$")):t.names.push(new RegExp("^"+l+"$")))}function s(){let l=[...t.names.map(a),...t.skips.map(a).map(f=>"-"+f)].join(",");return t.enable(""),l}function i(l){if(l[l.length-1]==="*")return!0;let f,d;for(f=0,d=t.skips.length;f<d;f++)if(t.skips[f].test(l))return!1;for(f=0,d=t.names.length;f<d;f++)if(t.names[f].test(l))return!0;return!1}function a(l){return l.toString().substring(2,l.toString().length-2).replace(/\.\*\?$/,"*")}function c(l){return l instanceof Error?l.stack??l.message:l}function u(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return t.setupFormatters(t.formatters),t.enable(t.load()),t}var Bs=q0(),N0=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function M0(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/(edge|trident)\/(\d+)/)!=null?!1:typeof document<"u"&&document.documentElement?.style?.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/firefox\/(\d+)/)!=null&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/applewebkit\/(\d+)/)}function B0(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+Ms(this.diff),!this.useColors)return;let e="color: "+this.color;r.splice(1,0,e,"color: inherit");let t=0,n=0;r[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(t++,o==="%c"&&(n=t))}),r.splice(n,0,e)}var F0=console.debug??console.log??(()=>{});function U0(r){try{r?Bs?.setItem("debug",r):Bs?.removeItem("debug")}catch{}}function K0(){let r;try{r=Bs?.getItem("debug")}catch{}return!r&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(r=globalThis.process.env.DEBUG),r}function q0(){try{return localStorage}catch{}}function $0(r){r.j=function(e){try{return JSON.stringify(e)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}}var Mh=_u({formatArgs:B0,save:U0,load:K0,useColors:M0,setupFormatters:$0,colors:N0,storage:Bs,log:F0});var We=Mh;We.formatters.b=r=>r==null?"undefined":ie.baseEncode(r);We.formatters.t=r=>r==null?"undefined":et.baseEncode(r);We.formatters.m=r=>r==null?"undefined":nc.baseEncode(r);We.formatters.p=r=>r==null?"undefined":r.toString();We.formatters.c=r=>r==null?"undefined":r.toString();We.formatters.k=r=>r==null?"undefined":r.toString();We.formatters.a=r=>r==null?"undefined":r.toString();function Bh(r,e=""){let t=Fh(r.message),n=Fh(r.stack);return t!=null&&n!=null?n.includes(t)?`${n.split(`
|
|
2
|
+
"use strict";var Libp2P=(()=>{var Pm=Object.create;var Uo=Object.defineProperty;var Dm=Object.getOwnPropertyDescriptor;var Rm=Object.getOwnPropertyNames;var Om=Object.getPrototypeOf,km=Object.prototype.hasOwnProperty;var pf=(r,e)=>()=>{try{return e||r((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}},$e=(r,e)=>{for(var t in e)Uo(r,t,{get:e[t],enumerable:!0})},mf=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Rm(e))!km.call(r,o)&&o!==t&&Uo(r,o,{get:()=>e[o],enumerable:!(n=Dm(e,o))||n.enumerable});return r};var gf=(r,e,t)=>(t=r!=null?Pm(Om(r)):{},mf(e||!r||!r.__esModule?Uo(t,"default",{value:r,enumerable:!0}):t,r)),Nm=r=>mf(Uo({},"__esModule",{value:!0}),r);var lm=pf((vP,ql)=>{"use strict";var Uw=Object.prototype.hasOwnProperty,qe="~";function No(){}Object.create&&(No.prototype=Object.create(null),new No().__proto__||(qe=!1));function Kw(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function um(r,e,t,n,o){if(typeof t!="function")throw new TypeError("The listener must be a function");var s=new Kw(t,n||r,o),i=qe?qe+e:e;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 ga(r,e){--r._eventsCount===0?r._events=new No:delete r._events[e]}function ke(){this._events=new No,this._eventsCount=0}ke.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)Uw.call(t,n)&&e.push(qe?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};ke.prototype.listeners=function(e){var t=qe?qe+e:e,n=this._events[t];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};ke.prototype.listenerCount=function(e){var t=qe?qe+e:e,n=this._events[t];return n?n.fn?1:n.length:0};ke.prototype.emit=function(e,t,n,o,s,i){var a=qe?qe+e:e;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,l,f;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,o),!0;case 5:return c.fn.call(c.context,t,n,o,s),!0;case 6:return c.fn.call(c.context,t,n,o,s,i),!0}for(f=1,l=new Array(u-1);f<u;f++)l[f-1]=arguments[f];c.fn.apply(c.context,l)}else{var d=c.length,h;for(f=0;f<d;f++)switch(c[f].once&&this.removeListener(e,c[f].fn,void 0,!0),u){case 1:c[f].fn.call(c[f].context);break;case 2:c[f].fn.call(c[f].context,t);break;case 3:c[f].fn.call(c[f].context,t,n);break;case 4:c[f].fn.call(c[f].context,t,n,o);break;default:if(!l)for(h=1,l=new Array(u-1);h<u;h++)l[h-1]=arguments[h];c[f].fn.apply(c[f].context,l)}}return!0};ke.prototype.on=function(e,t,n){return um(this,e,t,n,!1)};ke.prototype.once=function(e,t,n){return um(this,e,t,n,!0)};ke.prototype.removeListener=function(e,t,n,o){var s=qe?qe+e:e;if(!this._events[s])return this;if(!t)return ga(this,s),this;var i=this._events[s];if(i.fn)i.fn===t&&(!o||i.once)&&(!n||i.context===n)&&ga(this,s);else{for(var a=0,c=[],u=i.length;a<u;a++)(i[a].fn!==t||o&&!i[a].once||n&&i[a].context!==n)&&c.push(i[a]);c.length?this._events[s]=c.length===1?c[0]:c:ga(this,s)}return this};ke.prototype.removeAllListeners=function(e){var t;return e?(t=qe?qe+e:e,this._events[t]&&ga(this,t)):(this._events=new No,this._eventsCount=0),this};ke.prototype.off=ke.prototype.removeListener;ke.prototype.addListener=ke.prototype.on;ke.prefixed=qe;ke.EventEmitter=ke;typeof ql<"u"&&(ql.exports=ke)});var pm=pf((HP,hm)=>{hm.exports=function(r){if(!r)throw Error("hashlru must have a max value, of type number, greater than 0");var e=0,t=Object.create(null),n=Object.create(null);function o(s,i){t[s]=i,e++,e>=r&&(e=0,n=t,t=Object.create(null))}return{has:function(s){return t[s]!==void 0||n[s]!==void 0},remove:function(s){t[s]!==void 0&&(t[s]=void 0),n[s]!==void 0&&(n[s]=void 0)},get:function(s){var i=t[s];if(i!==void 0)return i;if((i=n[s])!==void 0)return o(s,i),i},set:function(s,i){t[s]!==void 0?t[s]=i:o(s,i)},clear:function(){t=Object.create(null),n=Object.create(null)}}}});var px={};$e(px,{createLibp2p:()=>fx,dnsaddrResolver:()=>kr,isLibp2p:()=>hx});var yf=Symbol.for("@libp2p/connection");var Ma=Symbol.for("@libp2p/content-routing");var Qe=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}},Ko=class extends Error{static name="UnexpectedPeerError";constructor(e="Unexpected Peer"){super(e),this.name="UnexpectedPeerError"}};var T=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},mt=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}},_n=class extends Error{static name="InvalidPrivateKeyError";constructor(e="Invalid private key"){super(e),this.name="InvalidPrivateKeyError"}};var rr=class extends Error{static name="ConnectionClosedError";constructor(e="The connection is closed"){super(e),this.name="ConnectionClosedError"}};var qo=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}},nr=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}},Nr=class extends Error{static name="InvalidPeerIdError";constructor(e="Invalid PeerID"){super(e),this.name="InvalidPeerIdError"}},Mt=class extends Error{static name="InvalidMultiaddrError";constructor(e="Invalid multiaddr"){super(e),this.name="InvalidMultiaddrError"}},$o=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},zo=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}},Vo=class extends Error{static name="UnsupportedProtocolError";constructor(e="Unsupported protocol error"){super(e),this.name="UnsupportedProtocolError"}},Ho=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var Wo=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},St=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}};var Mr=class extends Error{static name="DialError";constructor(e="Dial error"){super(e),this.name="DialError"}};var Cn=class extends Error{static name="LimitedConnectionError";constructor(e="Limited connection"){super(e),this.name="LimitedConnectionError"}},Go=class extends Error{static name="TooManyInboundProtocolStreamsError";constructor(e="Too many inbound protocol streams"){super(e),this.name="TooManyInboundProtocolStreamsError"}},jo=class extends Error{static name="TooManyOutboundProtocolStreamsError";constructor(e="Too many outbound protocol streams"){super(e),this.name="TooManyOutboundProtocolStreamsError"}},Bt=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Yo=class extends Event{error;local;constructor(e,t,n){super("close",n),this.error=t,this.local=e}};var Ba=Symbol.for("@libp2p/peer-discovery");var Xo=Symbol.for("@libp2p/peer-id");function Ft(r){return!!r?.[Xo]}var Fa=Symbol.for("@libp2p/peer-routing");var Ua="keep-alive";function Zo(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function bf(...r){let e=[];for(let t of r)Zo(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStart!=null&&await t.beforeStart()})),await Promise.all(e.map(async t=>{await t.start()})),await Promise.all(e.map(async t=>{t.afterStart!=null&&await t.afterStart()}))}async function wf(...r){let e=[];for(let t of r)Zo(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStop!=null&&await t.beforeStop()})),await Promise.all(e.map(async t=>{await t.stop()})),await Promise.all(e.map(async t=>{t.afterStop!=null&&await t.afterStop()}))}var Tn;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Tn||(Tn={}));function Mm(r){return typeof r?.handleEvent=="function"}function Bm(r){return r===!0||r===!1}function Fm(r){return Bm(r)?r:r?.capture??!1}function Ka(r){let e={capture:Fm(r),once:!!r?.once};return r?.passive!=null&&(e.passive=r?.passive),r?.signal!=null&&(e.signal=r?.signal),e}function xf(r,e){return Ka(r).capture===Ka(e).capture}var Ne=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){let o=Ka(n);if(o?.signal?.aborted===!0)return;let s=u=>{o.once&&this.removeEventListener(e,t,o),Mm(t)?t.handleEvent(u):t(u)},i=this.#e.get(e);if(i==null&&(i=[],this.#e.set(e,i)),i.some(u=>u.callback!==t?!1:xf(u.options,o)))return;super.addEventListener(e,s,o);let c=()=>{this.removeEventListener(e,t,o)};o.signal?.addEventListener("abort",c),i.push({callback:t,wrapper:s,options:o,onAbort:c})}removeEventListener(e,t,n){let o=this.#e.get(e);if(o==null){super.removeEventListener(e,t??null,n);return}this.#e.set(e,o.filter(s=>s.callback===t&&xf(s.options,n)?(super.removeEventListener(e,s.wrapper,n),s.options?.signal?.removeEventListener("abort",s.onAbort),!1):!0))}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var In=Symbol.for("@libp2p/service-capabilities"),qa=Symbol.for("@libp2p/service-dependencies");function Q(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}var Wa={};$e(Wa,{base58btc:()=>ie,base58flickr:()=>Wm});var Jx=new Uint8Array(0);function vf(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function Je(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return or(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return or(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function Sf(r){let e=new Uint8Array(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}var Ef=4096;function Af(r){let e=r.length;if(e<=Ef)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.subarray(n,n+=Ef));return t}function Um(r){return r?.buffer instanceof ArrayBuffer}function or(r){return Um(r)?r:r.slice()}function Km(r,e,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var s=0;s<r.length;s++){var i=r.charAt(s),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=s,t){var c=i.toLowerCase().charCodeAt(0),u=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=s),u!==a&&(n[u]=s)}}var l=r.length,f=r.charAt(0),d=Math.log(l)/Math.log(256),h=Math.log(256)/Math.log(l);function y(b){if(b instanceof Uint8Array||(ArrayBuffer.isView(b)?b=new Uint8Array(b.buffer,b.byteOffset,b.byteLength):Array.isArray(b)&&(b=Uint8Array.from(b))),!(b instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(b.length===0)return"";for(var S=0,w=0,v=0,A=b.length;v!==A&&b[v]===0;)v++,S++;for(var M=(A-v)*h+1>>>0,$=new Uint8Array(M);v!==A;){for(var k=b[v],D=0,B=M-1;(k!==0||D<w)&&B!==-1;B--,D++)k+=256*$[B]>>>0,$[B]=k%l>>>0,k=k/l>>>0;if(k!==0)throw new Error("Non-zero carry");w=D,v++}for(var V=M-w;V!==M&&$[V]===0;)V++;for(var W=f.repeat(S);V<M;++V)W+=r.charAt($[V]);return W}function p(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var S=0;if(b[S]!==" "){for(var w=0,v=0;b[S]===f;)w++,S++;for(var A=(b.length-S)*d+1>>>0,M=new Uint8Array(A);b[S];){var $=b.charCodeAt(S);if($>255)return;var k=n[$];if(k===255)return;for(var D=0,B=A-1;(k!==0||D<v)&&B!==-1;B--,D++)k+=l*M[B]>>>0,M[B]=k%256>>>0,k=k/256>>>0;if(k!==0)throw new Error("Non-zero carry");v=D,S++}if(b[S]!==" "){for(var V=A-v;V!==A&&M[V]===0;)V++;for(var W=new Uint8Array(w+(A-V)),oe=w;V!==A;)W[oe++]=M[V++];return W}}}function g(b){var S=p(b);if(S)return S;throw new Error(`Non-${e} character`)}return{encode:y,decodeUnsafe:p,decode:g}}var qm=Km,$m=qm,Cf=$m;var $a=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},za=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Tf(this,e)}},Va=class{decoders;constructor(e){this.decoders=e}or(e){return Tf(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Tf(r,e){return new Va({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Ha=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new $a(e,t,n),this.decoder=new za(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Br({name:r,prefix:e,encode:t,decode:n}){return new Ha(r,e,t,n)}function Ut({name:r,prefix:e,alphabet:t,caseInsensitive:n=!1}){let{encode:o,decode:s}=Cf(t,r,n);return Br({prefix:e,name:r,encode:o,decode:i=>Je(s(i))})}function zm(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*t/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let l=e[r[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|l,i+=t,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=t||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Vm(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<t-i]),n)for(;(s.length*t&7)!==0;)s+="=";return s}function Hm(r,e){let t={};for(let n=0;n<r.length;++n)if(r[n]!=="="&&(t[r[n]]=n,e)){let o=r[n].toLowerCase(),s=r[n].toUpperCase();o!==r[n]&&(t[o]=n),s!==r[n]&&(t[s]=n)}return t}function ye({name:r,prefix:e,bitsPerChar:t,alphabet:n,caseInsensitive:o=!1}){let s=Hm(n,o);return Br({prefix:e,name:r,encode(i){return Vm(i,n,t)},decode(i){return zm(i,s,t,r)}})}var ie=Ut({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Wm=Ut({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ga={};$e(Ga,{base32:()=>et,base32hex:()=>Xm,base32hexpad:()=>Qm,base32hexpadupper:()=>Jm,base32hexupper:()=>Zm,base32pad:()=>jm,base32padupper:()=>Ym,base32upper:()=>Gm,base32z:()=>eg});var et=ye({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Gm=ye({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),jm=ye({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Ym=ye({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Xm=ye({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Zm=ye({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),Qm=ye({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),Jm=ye({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),eg=ye({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ja={};$e(ja,{base36:()=>Ln,base36upper:()=>tg});var Ln=Ut({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),tg=Ut({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var rg=Pf,If=128,ng=127,og=~ng,sg=Math.pow(2,31);function Pf(r,e,t){e=e||[],t=t||0;for(var n=t;r>=sg;)e[t++]=r&255|If,r/=128;for(;r&og;)e[t++]=r&255|If,r>>>=7;return e[t]=r|0,Pf.bytes=t-n+1,e}var ig=Ya,ag=128,Lf=127;function Ya(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Ya.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Lf)<<o:(i&Lf)*Math.pow(2,o),o+=7}while(i>=ag);return Ya.bytes=s-n,t}var cg=Math.pow(2,7),ug=Math.pow(2,14),lg=Math.pow(2,21),fg=Math.pow(2,28),dg=Math.pow(2,35),hg=Math.pow(2,42),pg=Math.pow(2,49),mg=Math.pow(2,56),gg=Math.pow(2,63),yg=function(r){return r<cg?1:r<ug?2:r<lg?3:r<fg?4:r<dg?5:r<hg?6:r<pg?7:r<mg?8:r<gg?9:10},bg={encode:rg,decode:ig,encodingLength:yg},wg=bg,Pn=wg;function Dn(r,e=0){let t=Pn.decode(r,e),n=Pn.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&r[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[t,n]}function Fr(r,e,t=0){return Pn.encode(r,e,t),e}function Ur(r){return Pn.encodingLength(r)}function gt(r,e){let t=e.byteLength,n=Ur(r),o=n+Ur(t),s=new Uint8Array(o+t);return Fr(r,s,0),Fr(t,s,n),s.set(e,o),new Kr(r,t,e,s)}function At(r){let e=Je(r),[t,n]=Dn(e),[o,s]=Dn(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Kr(t,o,i,e)}function Df(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&vf(r.bytes,t.bytes)}}var Kr=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=or(n),this.bytes=or(o)}};function Rf(r,e){let{bytes:t,version:n}=r;return n===0?Eg(t,Xa(r),e??ie.encoder):vg(t,Xa(r),e??et.encoder)}var Of=new WeakMap;function Xa(r){let e=Of.get(r);if(e==null){let t=new Map;return Of.set(r,t),t}return e}var xe=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=or(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==Rn)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Sg)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}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:e,digest:t}=this.multihash,n=gt(e,t);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(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&Df(e.multihash,n.multihash)}toString(e){return Rf(this,e)}toJSON(){return{"/":Rf(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:s,bytes:i}=t;return new r(n,o,s,i??kf(n,o,s.bytes))}else if(t[Ag]===!0){let{version:n,multihash:o,code:s}=t,i=At(o);return r.create(n,s,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==Rn)throw new Error(`Version 0 CID must use dag-pb (code: ${Rn}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=kf(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Rn,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=Je(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new Kr(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,d]=Dn(e.subarray(t));return t+=d,f},o=n(),s=Rn;if(o===18)o=0,t=0;else if(o===1)s=n();else throw o===0?new RangeError("Invalid CID version, v0 is always implicit"):new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),c=n(),u=t+c,l=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,t){let[n,o]=xg(e,t),s=r.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Xa(s).set(n,e),s}};function xg(r,e){switch(r[0]){case"Q":{let t=e??ie;return[ie.prefix,t.decode(`${ie.prefix}${r}`)]}case ie.prefix:{let t=e??ie;return[ie.prefix,t.decode(r)]}case et.prefix:{let t=e??et;return[et.prefix,t.decode(r)]}case Ln.prefix:{let t=e??Ln;return[Ln.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Eg(r,e,t){let{prefix:n}=t;if(n!==ie.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function vg(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o}var Rn=112,Sg=18;function kf(r,e,t){let n=Ur(r),o=n+Ur(e),s=new Uint8Array(o+t.byteLength);return Fr(r,s,0),Fr(e,s,n),s.set(t,o),s}var Ag=Symbol.for("@ipld/js-cid/CID");var Za={};$e(Za,{identity:()=>at});var Nf=0,_g="identity",Mf=Je;function Cg(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return gt(Nf,Mf(r))}var at={code:Nf,name:_g,encode:Mf,digest:Cg};function Tg(r){return r.buffer instanceof ArrayBuffer}function Te(r){return Tg(r)?r:r.slice()}async function Bf(r="P-256"){let e=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:r},!0,["sign","verify"]);return{publicKey:await crypto.subtle.exportKey("jwk",e.publicKey),privateKey:await crypto.subtle.exportKey("jwk",e.privateKey)}}async function Ff(r,e,t){let n=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["sign"]);t?.signal?.throwIfAborted();let o=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},n,Te(e.subarray()));return t?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Uf(r,e,t,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,Te(e),Te(t.subarray()));return n?.signal?.throwIfAborted(),s}function pe(r=0){return new Uint8Array(r)}function Se(r=0){return new Uint8Array(r)}function Ig(r){return r?.buffer instanceof ArrayBuffer}function Qa(r){if(Ig(r))return r;let e=r.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function tt(r,e){e==null&&(e=r.reduce((o,s)=>o+s.length,0));let t=Se(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return Qa(t)}var qf=Symbol.for("@achingbrain/uint8arraylist");function Kf(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let o=t+n.byteLength;if(e<o)return{buf:n,index:e-t};t=o}throw new RangeError("index is out of bounds")}function Jo(r){return!!r?.[qf]}var ne=class r{bufs;length;[qf]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(Jo(n)){t+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(Jo(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=Kf(this.bufs,e);return t.buf[t.index]}set(e,t){let n=Kf(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(Jo(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:o}=this._subList(e,t);return tt(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:tt(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),s=new r;return s.length=o,s.bufs=n,s}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,e>=c)continue;let u=e>=a&&e<c,l=t>a&&t<=c;if(u&&l){if(e===a&&t===c){n.push(i);break}let f=e-a;n.push(i.subarray(f,f+(t-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(l){if(t===c){n.push(i);break}n.push(i.subarray(0,t-a));break}n.push(i)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!Jo(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let f=t;f<=c;f+=l){l=0;for(let d=u;d>=0;d--){let h=this.get(f+d);if(n[d]!==h){l=Math.max(1,d-a[h]);break}}if(l===0)return f}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=Se(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let o=pe(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,t,n),this.write(o,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let o=pe(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,t,n),this.write(o,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let o=pe(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,t,n),this.write(o,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=Se(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let o=pe(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,t,n),this.write(o,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let o=pe(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,t,n),this.write(o,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let o=pe(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,t,n),this.write(o,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let o=pe(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,t,n),this.write(o,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let o=pe(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,t,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!Q(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((o,s)=>o+s.byteLength,0)),n.length=t,n}};var Ja={};$e(Ja,{base10:()=>Lg});var Lg=Ut({prefix:"9",name:"base10",alphabet:"0123456789"});var ec={};$e(ec,{base16:()=>Pg,base16upper:()=>Dg});var Pg=ye({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Dg=ye({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var tc={};$e(tc,{base2:()=>Rg});var Rg=ye({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var rc={};$e(rc,{base256emoji:()=>Bg});var $f=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}"),Og=$f.reduce((r,e,t)=>(r[t]=e,r),[]),kg=$f.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Ng(r){return r.reduce((e,t)=>(e+=Og[t],e),"")}function Mg(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=kg[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var Bg=Br({prefix:"\u{1F680}",name:"base256emoji",encode:Ng,decode:Mg});var sc={};$e(sc,{base64:()=>nc,base64pad:()=>Fg,base64url:()=>oc,base64urlpad:()=>Ug});var nc=ye({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Fg=ye({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),oc=ye({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ug=ye({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ic={};$e(ic,{base8:()=>Kg});var Kg=ye({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ac={};$e(ac,{identity:()=>qg});var qg=Br({prefix:"\0",name:"identity",encode:r=>Af(Je(r)),decode:r=>Je(Sf(r))});var BE=new TextEncoder,FE=new TextDecoder;var lc={};$e(lc,{sha256:()=>qr,sha512:()=>Hg});var Vg=20;function uc({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new cc(r,e,t,n,o)}var cc=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,s){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??Vg,this.maxDigestLength=s}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?zf(n,this.code,t?.truncate):n.then(o=>zf(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function zf(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return gt(e,r)}function Hf(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var qr=uc({name:"sha2-256",code:18,encode:Hf("SHA-256")}),Hg=uc({name:"sha2-512",code:19,encode:Hf("SHA-512")});var On={...ac,...tc,...ic,...Ja,...ec,...Ga,...ja,...Wa,...sc,...rc},XE={...lc,...Za};function Gf(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Wf=Gf("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),fc=Gf("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=Se(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Wg={utf8:Wf,"utf-8":Wf,hex:On.base16,latin1:fc,ascii:fc,binary:fc,...On},es=Wg;function I(r,e="utf8"){let t=es[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function F(r,e="utf8"){let t=es[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var Gg=parseInt("11111",2),dc=parseInt("10000000",2),jg=parseInt("01111111",2),jf={0:kn,1:kn,2:Yg,3:Qg,4:Jg,5:Zg,6:Xg,16:kn,22:kn,48:kn};function _t(r,e={offset:0}){let t=r[e.offset]⋙if(e.offset++,jf[t]!=null)return jf[t](r,e);throw new Error("No decoder for tag "+t)}function Nn(r,e){let t=0;if((r[e.offset]&dc)===dc){let n=r[e.offset]&jg,o="0x";e.offset++;for(let s=0;s<n;s++,e.offset++){if(e.offset>=r.byteLength)throw new Error("invalid DER element length");o+=r[e.offset].toString(16).padStart(2,"0")}t=parseInt(o,16)}else t=r[e.offset],e.offset++;if(!Number.isInteger(t)||t<0||t>r.byteLength-e.offset)throw new Error("invalid DER element length");return t}function kn(r,e){Nn(r,e);let t=[];for(;!(e.offset>=r.byteLength);){let n=_t(r,e);if(n===null)break;t.push(n)}return t}function Yg(r,e){let t=Nn(r,e),n=e.offset,o=e.offset+t,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return e.offset+=t,Uint8Array.from(s)}function Xg(r,e){let t=Nn(r,e),n=e.offset+t,o=r[e.offset];e.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;e.offset<n;){let u=r[e.offset];if(e.offset++,c.push(u&127),u<128){c.reverse();let l=0;for(let f=0;f<c.length;f++)l+=c[f]<<f*7;a+=`.${l}`,c=[]}}return a}function Zg(r,e){return e.offset++,null}function Qg(r,e){let t=Nn(r,e),n=r[e.offset];e.offset++;let o=r.subarray(e.offset,e.offset+t-1);if(e.offset+=t,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Jg(r,e){let t=Nn(r,e),n=r.subarray(e.offset,e.offset+t);return e.offset+=t,n}function ey(r){let e=r.toString(16);e.length%2===1&&(e="0"+e);let t=new ne;for(let n=0;n<e.length;n+=2)t.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return t}function ts(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let e=ey(r.byteLength);return new ne(Uint8Array.from([e.byteLength|dc]),e)}function Me(r){let e=new ne,t=128;return(r.subarray()[0]&t)===t&&e.append(Uint8Array.from([0])),e.append(r),new ne(Uint8Array.from([2]),ts(e),e)}function Mn(r){let e=Uint8Array.from([0]),t=new ne(e,r);return new ne(Uint8Array.from([3]),ts(t),t)}function Yf(r){return new ne(Uint8Array.from([4]),ts(r),r)}function ct(r,e=48){let t=new ne;for(let n of r)t.append(n);return new ne(Uint8Array.from([e]),ts(t),t)}var ty=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),ry=Uint8Array.from([6,5,43,129,4,0,34]),ny=Uint8Array.from([6,5,43,129,4,0,35]),oy={ext:!0,kty:"EC",crv:"P-256"},sy={ext:!0,kty:"EC",crv:"P-384"},iy={ext:!0,kty:"EC",crv:"P-521"},hc=32,pc=48,mc=66;function gc(r){let e=_t(r);return Xf(e)}function Xf(r){let e=r[1][1][0],t=1,n,o;if(e.byteLength===hc*2+1)return n=F(e.subarray(t,t+hc),"base64url"),o=F(e.subarray(t+hc),"base64url"),new sr({...oy,key_ops:["verify"],x:n,y:o});if(e.byteLength===pc*2+1)return n=F(e.subarray(t,t+pc),"base64url"),o=F(e.subarray(t+pc),"base64url"),new sr({...sy,key_ops:["verify"],x:n,y:o});if(e.byteLength===mc*2+1)return n=F(e.subarray(t,t+mc),"base64url"),o=F(e.subarray(t+mc),"base64url"),new sr({...iy,key_ops:["verify"],x:n,y:o});throw new T(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Zf(r){return ct([Me(Uint8Array.from([1])),Yf(I(r.d??"","base64url")),ct([Jf(r.crv)],160),ct([Mn(new ne(Uint8Array.from([4]),I(r.x??"","base64url"),I(r.y??"","base64url")))],161)]).subarray()}function Qf(r){return ct([Me(Uint8Array.from([1])),ct([Jf(r.crv)],160),ct([Mn(new ne(Uint8Array.from([4]),I(r.x??"","base64url"),I(r.y??"","base64url")))],161)]).subarray()}function Jf(r){if(r==="P-256")return ty;if(r==="P-384")return ry;if(r==="P-521")return ny;throw new T(`Invalid curve ${r}`)}async function ed(r="P-256"){let e=await Bf(r);return new rs(e.privateKey)}var sr=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Qf(this.jwk)),this._raw}toMultihash(){return at.digest(rt(this))}toCID(){return xe.createV1(114,this.toMultihash())}toString(){return ie.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Q(this.raw,e.raw)}async verify(e,t,n){return Uf(this.jwk,t,e,n)}},rs=class{type="ECDSA";jwk;publicKey;_raw;constructor(e){this.jwk=e,this.publicKey=new sr({crv:e.crv,ext:e.ext,key_ops:["verify"],kty:"EC",x:e.x,y:e.y})}get raw(){return this._raw==null&&(this._raw=Zf(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Q(this.raw,e.raw)}async sign(e,t){return Ff(this.jwk,e,t)}};var ns=BigInt(4294967295),td=BigInt(32);function ay(r,e=!1){return e?{h:Number(r&ns),l:Number(r>>td&ns)}:{h:Number(r>>td&ns)|0,l:Number(r&ns)|0}}function rd(r,e=!1){let t=r.length,n=new Uint32Array(t),o=new Uint32Array(t);for(let s=0;s<t;s++){let{h:i,l:a}=ay(r[s],e);[n[s],o[s]]=[i,a]}return[n,o]}var cy=r=>r/2**32|0,uy=r=>r>>>0;function nd(r,e,t,n){let o=cy(t),s=uy(t);r.setUint32(e,n?s:o,n),r.setUint32(e+4,n?o:s,n)}var yc=(r,e,t)=>r>>>t,bc=(r,e,t)=>r<<32-t|e>>>t,ir=(r,e,t)=>r>>>t|e<<32-t,ar=(r,e,t)=>r<<32-t|e>>>t,Bn=(r,e,t)=>r<<64-t|e>>>t-32,Fn=(r,e,t)=>r>>>t-32|e<<64-t;function yt(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var od=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),sd=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,id=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),ad=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,cd=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),ud=(r,e,t,n,o,s)=>e+t+n+o+s+(r/2**32|0)|0;function os(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in r&&r.BYTES_PER_ELEMENT===1}var wc=r=>r?`"${r}" `:"";function Ct(r,e=""){if(typeof r!="number")throw new TypeError(wc(e)+"expected number, got "+typeof r);if(!Number.isSafeInteger(r)||r<0)throw new RangeError(wc(e)+"expected integer >= 0, got "+r);return r}function nt(r,e,t=""){if(os(r)&&(e===void 0||r.length===e))return r;e!==void 0&&Ct(e,"length");let n=os(r),o=e!==void 0?` of length ${e}`:"",s=n?`length=${r.length}`:`type=${typeof r}`,i=wc(t)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function ss(r){if(typeof r!="function"||typeof r.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(Ct(r.outputLen),Ct(r.blockLen),r.outputLen<1||r.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var fy=(r,e)=>{if(r===null||typeof r!="object"||Array.isArray(r))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof r)},ld=(r,e)=>{fy(r,e);let t=Object.getPrototypeOf(r);if(t!==Object.prototype&&t!==null)throw new TypeError(`"${e}" expected plain object`);if(Object.hasOwn(r,"__proto__"))throw new TypeError(`"${e}.__proto__" is not allowed`)};function $r(r,e=!0){if(r.destroyed)throw new Error("hash was destroyed");if(e&&r.finished)throw new Error("digest() was already called")}function is(r,e){nt(r,void 0,"output");let t=e.outputLen;if(!(r.length>=t))throw new RangeError('"output" expected length >= '+t)}function cr(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function as(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function ut(r,e){return r<<32-e|r>>>e}var dd=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",dy=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function cs(r){if(nt(r),dd)return r.toHex();let e="";for(let t=0;t<r.length;t++)e+=dy[r[t]];return e}function fd(r){return r>=48&&r<=57?r-48:r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:void 0}function us(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);if(dd)try{return Uint8Array.fromHex(r)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let e=r.length,t=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let o=0,s=0;o<t;o++,s+=2){let i=fd(r.charCodeAt(s)),a=fd(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function xc(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];nt(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let s=r[n];t.set(s,o),o+=s.length}return t}function hy(r,e,t="opts"){return ld(r,"defaults"),e!==void 0&&ld(e,t),Object.assign(Object.create(null),r,e)}function Ec(r,e={}){if(typeof r!="function")throw new TypeError('"hashCons" expected function, got type='+typeof r);e=hy({},e,"info");let t=(o,s)=>r(s).update(o).digest(),n=r(void 0);return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.canXOF=n.canXOF,t.create=o=>r(o),Object.assign(t,e),Object.freeze(t)}function hd(r=32){Ct(r,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(r>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${r}`);return e.getRandomValues(new Uint8Array(r))}var vc=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function pd(r,e,t){return r&e^~r&t}function md(r,e,t){return r&e^r&t^e&t}var Un=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,n,o){this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=as(this.buffer)}update(e){$r(this),nt(e);let{view:t,buffer:n,blockLen:o}=this,s=e.length,i=!1;for(let a=0;a<s;){let c=Math.min(o-this.pos,s-a);if(c===o){let u=as(e);for(;o<=s-a;a+=o)this.process(u,a);i=!0;continue}n.set(a===0&&c===s?e:e.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===o&&(this.process(t,0),this.pos=0,i=!0)}return this.length+=e.length,i&&this.roundClean(),this}digestInto(e){$r(this),is(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;t[i++]=128,t.fill(0,i),this.padOffset>o-i&&(this.process(n,0),t.fill(0)),nd(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let a=e===t?n:as(e),c=this.outputLen,u=c/4,l=this.get();if(c%4||u>l.length)throw new Error("invalid outputLen");for(let f=0;f<u;f++)a.setUint32(4*f,l[f],s)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:t,length:n,finished:o,destroyed:s,pos:i}=this;return e.destroyed=s,e.finished=o,e.length=n,e.pos=i,i&&e.buffer.set(t),e}clone(){return this._cloneInto()}},gd=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var yd=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var py=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),qt=new Uint32Array(64),Sc=class extends Un{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,t){super(64,e,8,!1),this.A=t[0]|0,this.B=t[1]|0,this.C=t[2]|0,this.D=t[3]|0,this.E=t[4]|0,this.F=t[5]|0,this.G=t[6]|0,this.H=t[7]|0}get(){let{A:e,B:t,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[e,t,n,o,s,i,a,c]}set(e,t,n,o,s,i,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,t){for(let f=0;f<16;f++,t+=4)qt[f]=e.getUint32(t,!1);for(let f=16;f<64;f++){let d=qt[f-15],h=qt[f-2],y=ut(d,7)^ut(d,18)^d>>>3,p=ut(h,17)^ut(h,19)^h>>>10;qt[f]=p+qt[f-7]+y+qt[f-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){let d=ut(a,6)^ut(a,11)^ut(a,25),h=l+d+pd(a,c,u)+py[f]+qt[f]|0,p=(ut(n,2)^ut(n,13)^ut(n,22))+md(n,o,s)|0;l=u,u=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+p|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,o,s,i,a,c,u,l)}roundClean(){cr(qt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),cr(this.buffer)}},Ac=class extends Sc{constructor(){super(32,gd)}};var bd=rd(["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))),my=bd[0],gy=bd[1],$t=new Uint32Array(80),zt=new Uint32Array(80),_c=class extends Un{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(e,t){super(128,e,16,!1),this.Ah=t[0]|0,this.Al=t[1]|0,this.Bh=t[2]|0,this.Bl=t[3]|0,this.Ch=t[4]|0,this.Cl=t[5]|0,this.Dh=t[6]|0,this.Dl=t[7]|0,this.Eh=t[8]|0,this.El=t[9]|0,this.Fh=t[10]|0,this.Fl=t[11]|0,this.Gh=t[12]|0,this.Gl=t[13]|0,this.Hh=t[14]|0,this.Hl=t[15]|0}get(){let{Ah:e,Al:t,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:l,Fh:f,Fl:d,Gh:h,Gl:y,Hh:p,Hl:g}=this;return[e,t,n,o,s,i,a,c,u,l,f,d,h,y,p,g]}set(e,t,n,o,s,i,a,c,u,l,f,d,h,y,p,g){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=l|0,this.Fh=f|0,this.Fl=d|0,this.Gh=h|0,this.Gl=y|0,this.Hh=p|0,this.Hl=g|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,t){for(let w=0;w<16;w++,t+=4)$t[w]=e.getUint32(t),zt[w]=e.getUint32(t+=4);for(let w=16;w<80;w++){let v=$t[w-15]|0,A=zt[w-15]|0,M=ir(v,A,1)^ir(v,A,8)^yc(v,A,7),$=ar(v,A,1)^ar(v,A,8)^bc(v,A,7),k=$t[w-2]|0,D=zt[w-2]|0,B=ir(k,D,19)^Bn(k,D,61)^yc(k,D,6),V=ar(k,D,19)^Fn(k,D,61)^bc(k,D,6),W=id($,V,zt[w-7],zt[w-16]),oe=ad(W,M,B,$t[w-7],$t[w-16]);$t[w]=oe|0,zt[w]=W|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:d,Fh:h,Fl:y,Gh:p,Gl:g,Hh:b,Hl:S}=this;for(let w=0;w<80;w++){let v=ir(f,d,14)^ir(f,d,18)^Bn(f,d,41),A=ar(f,d,14)^ar(f,d,18)^Fn(f,d,41),M=f&h^~f&p,$=d&y^~d&g,k=cd(S,A,$,gy[w],zt[w]),D=ud(k,b,v,M,my[w],$t[w]),B=k|0,V=ir(n,o,28)^Bn(n,o,34)^Bn(n,o,39),W=ar(n,o,28)^Fn(n,o,34)^Fn(n,o,39),oe=n&s^n&a^s&a,L=o&i^o&c^i&c;b=p|0,S=g|0,p=h|0,g=y|0,h=f|0,y=d|0,{h:f,l:d}=yt(u|0,l|0,D|0,B|0),u=a|0,l=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let z=od(B,W,L);n=sd(z,D,V,oe),o=z|0}({h:n,l:o}=yt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=yt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=yt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=yt(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:d}=yt(this.Eh|0,this.El|0,f|0,d|0),{h,l:y}=yt(this.Fh|0,this.Fl|0,h|0,y|0),{h:p,l:g}=yt(this.Gh|0,this.Gl|0,p|0,g|0),{h:b,l:S}=yt(this.Hh|0,this.Hl|0,b|0,S|0),this.set(n,o,s,i,a,c,u,l,f,d,h,y,p,g,b,S)}roundClean(){cr($t,zt)}destroy(){this.destroyed=!0,cr(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Cc=class extends _c{constructor(){super(64,yd)}};var zr=Ec(()=>new Ac,vc(1));var Tc=Ec(()=>new Cc,vc(3));function fs(r,e,t=()=>{}){if(!Array.isArray(r))throw new TypeError(`"${e}" expected array, got type=${typeof r}`);for(let n=0;n<r.length;n++)t(r[n],`${e}[${n}]`);return r}var J=(r,e,t)=>nt(r,e,t),Ic=Ct;function xd(r,e=""){if(typeof r!="string"){let t=e&&`"${e}" `;throw new TypeError(t+"expected string, got type="+typeof r)}return r}function Vt(r,e="object"){if(r===null||typeof r!="object"||Array.isArray(r))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof r}`);return r}function ur(r,e){if(typeof r!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof r}`);return r}var Kn=cs,ot=(...r)=>xc(...r),Vr=r=>us(r),Wt=os,lr=r=>hd(r),ls=BigInt(0),wd=BigInt(1),yy=r=>r?`"${r}" `:"";function ze(r,e=""){if(typeof r!="boolean")throw new TypeError(yy(e)+"expected boolean, got type="+typeof r);return r}function ds(r){if(typeof r=="bigint"){if(!Ht(r))throw new RangeError("positive bigint expected, got "+r)}else Ic(r);return r}function Tt(r,e=""){if(typeof r!="number"){let t=e&&`"${e}" `;throw new TypeError(t+"expected number, got type="+typeof r)}if(!Number.isSafeInteger(r)){let t=e&&`"${e}" `;throw new RangeError(t+"expected safe integer, got "+r)}}function qn(r){let e=ds(r).toString(16);return e.length&1?"0"+e:e}function Ed(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);return r===""?ls:BigInt("0x"+r)}function bt(r){return Ed(cs(r))}function fr(r){return Ed(cs($n(nt(r)).reverse()))}function hs(r,e){if(Ct(e),e===0)throw new Error("zero output length is invalid");r=ds(r);let t=e*2,n=r.toString(16);if(n.length>t)throw new RangeError("number is too large");return us(n.padStart(t,"0"))}function Lc(r,e){return hs(r,e).reverse()}function $n(r){return Uint8Array.from(J(r))}function Ht(r){return typeof r=="bigint"&&ls<=r}function Pc(r,e,t){return Ht(r)&&Ht(e)&&Ht(t)&&e<=r&&r<t}function Hr(r,e,t,n){if(!Pc(e,t,n))throw new RangeError("expected valid "+r+": "+t+" <= n < "+n+", got "+e)}function Wr(r){if(r<ls)throw new Error("expected non-negative bigint, got "+r);return r===ls?0:r.toString(2).length}var zn=r=>(Tt(r,"n"),(wd<<BigInt(r))-wd);function vd(r,e,t){if(Ct(r,"hashLen"),Ct(e,"qByteLen"),typeof t!="function")throw new TypeError("hmacFn must be a function");let n=g=>new Uint8Array(g),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(r),u=n(r),l=0,f=()=>{c.fill(1),u.fill(0),l=0},d=(...g)=>t(u,ot(c,...g)),h=(g=o)=>{u=d(s,g),c=d(),g.length!==0&&(u=d(i,g),c=d())},y=()=>{if(l++>=a)throw new Error("drbg: tried max amount of iterations");let g=0,b=[];for(;g<e;){c=d();let S=c.slice();b.push(S),g+=c.length}return ot(...b)};return(g,b)=>{f(),h(g);let S;for(;(S=b(y()))===void 0;)h();return f(),S}}function Ve(r,e={},t={},n="object"){Vt(r,n),Vt(e,"fields"),Vt(t,"optFields");function o(i,a,c){let u=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,l=r[i];if(!Object.hasOwn(r,i)&&(c?l!==void 0:a!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&l===void 0)return;let f=typeof l;if(f!==a||l===null)throw new TypeError(`${u} is invalid: expected ${a}, got ${f}`)}let s=(i,a)=>Object.entries(i).forEach(([c,u])=>o(c,u,a));s(e,!1),s(t,!0)}var Ee=BigInt(0),ee=BigInt(1),Gt=BigInt(2),_d=BigInt(3),Dc=BigInt(4),Cd=BigInt(5),by=BigInt(7),Td=BigInt(8),wy=BigInt(9),xy=BigInt(15),Id=BigInt(16),Ey=BigInt("0x10000000000000000");function me(r,e){if(e<=Ee)throw new Error("mod: expected positive modulus, got "+e);let t=r%e;return t>=Ee?t:e+t}function Ld(r,e,t){if(t<=ee)throw new Error("pow: expected modulus > 1, got "+t);if(typeof e!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof e);if(e<Ee)throw new Error("invalid exponent, negatives unsupported");if(e===Ee)return ee;if(e===ee)return r;let n=r%t;if(n<Ee&&(n+=t),e<Ey){let a=ee;for(;e>Ee;)e&ee&&(a=a*n%t),n=n*n%t,e>>=ee;return a}let o=[];for(;e>Ee;)o.push(Number(e&xy)),e>>=Dc;let s=new Array(16);s[0]=ee,s[1]=n;for(let a=2;a<16;a++)s[a]=s[a-1]*n%t;let i=s[o[o.length-1]];for(let a=o.length-2;a>=0;a--){i=i*i%t,i=i*i%t,i=i*i%t,i=i*i%t;let c=o[a];c!==0&&(i=i*s[c]%t)}return i}function de(r,e,t){if(t<=ee)throw new Error("pow2: expected modulus > 1, got "+t);if(e<Ee)throw new Error("pow2: expected non-negative exponent, got "+e);let n=r;for(;e-- >Ee;)n*=n,n%=t;return n}function Sd(r,e){if(r===Ee)throw new Error("invert: expected non-zero number");if(e<=ee)throw new Error("invert: expected modulus > 1, got "+e);let t=me(r,e),n=e,o=Ee,s=ee;for(;t!==Ee;){let a=n/t,c=n-t*a,u=o-s*a;n=t,t=c,o=s,s=u}if(n!==ee)throw new Error("invert: does not exist");return me(o,e)}function Pd(r,e){if(e<=ee)throw new Error("invertCt: expected prime modulus > 1, got "+e);let t=me(r,e);if(t===Ee)throw new Error("invertCt: expected non-zero number");let n=Ld(t,e-Gt,e);if(me(t*n,e)!==ee)throw new Error("invertCt: does not exist");return n}function Rc(r,e,t){let n=r;if(!n.eql(n.sqr(e),t))throw new Error("Cannot find square root")}function Oc(r,e){if((r&ee)===Ee)throw new Error(e+": expected odd modulus, got "+r)}function Dd(r,e){let t=r,n=(t.ORDER+ee)/Dc,o=t.pow(e,n);return Rc(t,o,e),o}function vy(r,e){let t=r,n=(t.ORDER-Cd)/Td,o=t.mul(e,Gt),s=t.pow(o,n),i=t.mul(e,s),a=t.mul(t.mul(i,Gt),s),c=t.mul(i,t.sub(a,t.ONE));return Rc(t,c,e),c}function Sy(r){let e=jr(r),t=Rd(r),n=t(e,e.neg(e.ONE)),o=t(e,n),s=t(e,e.neg(n)),i=(r+by)/Id;return((a,c)=>{let u=a,l=u.pow(c,i),f=u.mul(l,n),d=u.mul(l,o),h=u.mul(l,s),y=u.eql(u.sqr(f),c),p=u.eql(u.sqr(d),c);l=u.cmov(l,f,y),f=u.cmov(h,d,p);let g=u.eql(u.sqr(f),c),b=u.cmov(l,f,g);return Rc(u,b,c),b})}function Rd(r){if(r<_d)throw new Error("sqrt is not defined for small field");Oc(r,"tonelliShanks");let e=r-ee,t=0;for(;e%Gt===Ee;)e/=Gt,t++;let n=Gt,o=jr(r);for(;Vn(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(t===1)return Dd;let s=o.pow(n,e),i=(e+ee)/Gt;return function(c,u){let l=c;if(l.is0(u))return u;if(Vn(l,u)!==1)throw new Error("Cannot find square root");let f=t,d=l.mul(l.ONE,s),h=l.pow(u,e),y=l.pow(u,i);for(;!l.eql(h,l.ONE);){if(l.is0(h))throw new Error("Cannot find square root: probably non-prime P");let p=1,g=l.sqr(h);for(;!l.eql(g,l.ONE);)if(p++,g=l.sqr(g),p===f)throw new Error("Cannot find square root");let b=ee<<BigInt(f-p-1),S=l.pow(d,b);f=p,d=l.sqr(S),h=l.mul(h,d),y=l.mul(y,S)}return y}}function Ay(r){return Oc(r,"Fp.sqrt"),r%Dc===_d?Dd:r%Td===Cd?vy:r%Id===wy?Sy(r):Rd(r)}var Od=(r,e)=>(me(r,e)&ee)===ee,_y=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Gr(r){if(Vt(r,"field"),typeof r.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof r.ORDER);Tt(r.BYTES,"BYTES"),Tt(r.BITS,"BITS");for(let e of _y)ur(r[e],"field."+e);if(r.BYTES<1||r.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(r.ORDER<=ee)throw new Error("invalid field: expected ORDER > 1, got "+r.ORDER);return r}function ms(r,e,t=!1){Gr(r),fs(e,"nums"),ze(t,"passZero");let n=r,o=new Array(e.length).fill(t?n.ZERO:void 0),s=e.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return e.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),i),o}function Vn(r,e){Gr(r);let t=r;Oc(t.ORDER,"FpLegendre");let n=(t.ORDER-ee)/Gt,o=t.pow(e,n),s=t.eql(o,t.ONE),i=t.eql(o,t.ZERO),a=t.eql(o,t.neg(t.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function Cy(r,e){if(e!==void 0&&Ic(e),r<=Ee)throw new Error("invalid n length: expected positive n, got "+r);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let t=Wr(r);if(e!==void 0&&e<t)throw new Error(`invalid n length: expected nBitLength (${e}) >= bitLen(n) (${t})`);let n=e!==void 0?e:t,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var Ad=new WeakMap,ps=class{ORDER;BITS;BYTES;isLE;ZERO=Ee;ONE=ee;_lengths;_mod;constructor(e,t={}){if(e<=ee)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,t!=null&&typeof t=="object"&&(typeof t.BITS=="number"&&(n=t.BITS),typeof t.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:t.sqrt,enumerable:!0}),typeof t.isLE=="boolean"&&(this.isLE=t.isLE),t.allowedLengths&&(this._lengths=Object.freeze(t.allowedLengths.slice())),typeof t.modFromBytes=="boolean"&&(this._mod=t.modFromBytes));let{nBitLength:o,nByteLength:s}=Cy(e,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(e){return me(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return Ee<=e&&e<this.ORDER}is0(e){return e===Ee}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&ee)===ee}neg(e){return me(-e,this.ORDER)}eql(e,t){return e===t}sqr(e){return me(e*e,this.ORDER)}add(e,t){return me(e+t,this.ORDER)}sub(e,t){return me(e-t,this.ORDER)}mul(e,t){return me(e*t,this.ORDER)}pow(e,t){return Ld(e,t,this.ORDER)}div(e,t){return me(e*Sd(t,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,t){return e+t}subN(e,t){return e-t}mulN(e,t){return e*t}inv(e){return Sd(e,this.ORDER)}sqrt(e){let t=Ad.get(this);return t||Ad.set(this,t=Ay(this.ORDER)),t(this,e)}toBytes(e){return this.isLE?Lc(e,this.BYTES):hs(e,this.BYTES)}fromBytes(e,t=!1){J(e);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(o);u.set(e,s?0:u.length-e.length),e=u}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=s?fr(e):bt(e);if(a&&(c=me(c,i)),!t&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return ms(this,e,!0)}cmov(e,t,n){return ze(n,"condition"),n?t:e}};function jr(r,e={}){return Object.freeze(ps.prototype),new ps(r,e)}function kd(r){if(typeof r!="bigint")throw new Error("field order must be bigint");if(r<=ee)throw new Error("field order must be greater than 1");let e=Wr(r-ee);return Math.ceil(e/8)}function gs(r){let e=kd(r);return e+Math.ceil(e/2)}function ys(r,e,t=!1){J(r);let n=r.length,o=kd(e),s=Math.max(gs(e),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=t?fr(r):bt(r),a=me(i,e-ee)+ee;return t?Lc(a,o):hs(a,o)}var Mc=BigInt(0),Hn=BigInt(1),Ty=BigInt(4),kc=16,Nd=128,Iy=5,Md=2**31;function jt(r){let e=r;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof r);ur(e.fromAffine,"Point.fromAffine"),ur(e.fromBytes,"Point.fromBytes"),ur(e.fromHex,"Point.fromHex"),Vt(e.BASE,"Point.BASE"),Vt(e.ZERO,"Point.ZERO"),Gr(e.Fp),Gr(e.Fn)}function bs(r,e){jt(r),Fd(e,r);let t=ms(r.Fp,e.map(n=>n.Z));return e.map((n,o)=>r.fromAffine(n.toAffine(t[o])))}function Ly(r,e,t=1){if(!Number.isSafeInteger(r)||r<t||r>e)throw new Error("invalid window size, expected ["+t+".."+e+"], got W="+r)}function Py(r,e){let t=r*(4*e+128);if(t>Md)throw new Error("invalid window size: table would need ~"+Math.ceil(t/2**20)+" MiB, max "+Md/2**20+" MiB")}function Bc(r,e){if(r!==void 0){ur(r,"randomBytes");try{let t=r(e);if(!Wt(t)||t.length!==e)return}catch{return}return r}}function Fd(r,e){fs(r,"points"),r.forEach((t,n)=>{if(!(t instanceof e))throw new Error("invalid point at index "+n)})}function Dy(r,e,t){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((n,o)=>{if(!(t===void 0?e.isValid(n):Ht(n)&&n<t))throw new Error("invalid scalar at index "+o)})}var Ud=new WeakMap;function Nc(r){return Ud.get(r)||1}function Ry(r,e){let t=r.double(),n=[r];for(let o=1;o<e;o++)n.push(n[o-1].add(t));return n}function Oy(r,e){let t=2**e,n=t/2,o=BigInt(t-1),s=[];for(;r>Mc;){let i=0;r&Hn&&(i=Number(r&o),i>=n&&(i-=t),r-=BigInt(i)),s.push(i),r>>=Hn}return s}function ky(r,e,t){let n=2**e,o=n/2,s=BigInt(n-1),i=BigInt(e),a=[];for(let c=0;c<t;c++){let u=Number(r&s);r>>=i,u>o&&(u-=n,r+=Hn),a.push(u)}if(r!==Mc)throw new Error("invalid wnaf");return a}function Ny(r,e,t){let n=0;for(let s of t)n=Math.max(n,s.length);let o=r;for(let s=n-1;s>=0;s--){s!==n-1&&(o=o.double());for(let i=0;i<t.length;i++){let a=t[i][s];if(a){let c=e[i][Math.abs(a)-1>>1];o=o.add(a<0?c.negate():c)}}}return o}var Yr=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,t){jt(e),this.randomBytes=Bc(t,kc),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,t,n){let o=Math.ceil(n/t)+1,s=2**(t-1),i=[],a=e;for(let c=0;c<o;c++){let u=a;for(let l=0;l<s;l++)i.push(u),u=u.add(a);a=i[i.length-1].double()}return{W:t,bits:n,windows:o,comp:i}}wnafCachedCT(e,t){let{W:n,windows:o,comp:s}=e,i=2**(n-1),a=ky(t,n,o),c=this.ZERO,u=this.BASE;for(let l=0;l<o;l++){let f=a[l],d=l*i,h=Math.abs(f)-1,y=s[d];for(let g=1;g<i;g++)y=g===h?s[d+g]:y;let p=y.negate();f===0?u=u.add(s[d]):c=c.add(f<0?p:y)}return{p:c,f:u}}getWnafPrecomputes(e,t,n,o){let s=this.wnafPrecomputes.get(t),i=s?.find(a=>a.W===e&&a.bits===n);return i||(i=this.buildWnafTable(t,e,n),typeof o=="function"&&(i={...i,comp:o(i.comp)}),s||(s=[],this.wnafPrecomputes.set(t,s)),s.push(i)),i}assertPoint(e){if(!(e instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof e)}validateMulInput(e,t){if(this.assertPoint(e),!Pc(t,Hn,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,t,n,o){let s=Nc(e);return s===1?this.fixedWindowCT(e,t,n):this.wnafCachedCT(this.getWnafPrecomputes(s,e,n,o),t)}mulCT(e,t,n){return this.validateMulInput(e,t),this.runCT(e,t,this.bits,n)}mulCTBlinded(e,t,n){if(this.validateMulInput(e,t),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let o=this.Point.Fn.BITS+Nd,s=this.randomBytes(kc);if(!Wt(s)||s.length!==kc)throw new Error("randomBytes returned invalid byte array");s[0]=s[0]&63|128;let i=t+bt(s)*this.Point.Fn.ORDER;return this.runCT(e,i,o,n)}fixedWindowCT(e,t,n){let o=Iy,s=1<<o,i=zn(o),a=new Array(s);a[0]=this.ZERO;for(let l=1;l<s;l++)a[l]=a[l-1].add(e);let c=Math.ceil(n/o),u=this.ZERO;for(let l=c-1;l>=0;l--){if(l!==c-1)for(let h=0;h<o;h++)u=u.double();let f=Number(t>>BigInt(l*o)&i),d=a[0];for(let h=1;h<s;h++)d=h===f?a[h]:d;u=u.add(d)}return{p:u,f:u}}shouldBlind(e,t){return this.randomBytes===void 0?!1:t===Hn?!0:e!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(e,t,n,o){return this.shouldBlind(e,n)?this.mulCTBlinded(e,t,o):this.mulCT(e,t,o)}mulUnsafe(e,t,n){if(this.assertPoint(e),!Ht(t))throw new Error("invalid scalar");let o=Nc(e);if(o===1||t>=this.Point.Fn.ORDER)return ws(this.Point,[e],[t],!0);let s=this.getWnafPrecomputes(o,e,this.bits,n);return this.wnafCachedCT(s,t).p}setWindowSize(e,t){this.assertPoint(e),Ly(t,this.bits);let n=Math.ceil((this.bits+Nd)/t)+1;Py(n*2**(t-1),this.Point.Fp.BYTES),Ud.set(e,t),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return Nc(e)!==1}};function ws(r,e,t,n=!1){if(jt(r),Fd(e,r),ze(n,"allowOversized"),Dy(t,r.Fn,n?r.Fn.ORDER**Ty:void 0),e.length!==t.length)throw new Error("arrays of points and scalars must have equal length");let o=e.map(i=>Ry(i,4)),s=t.map(i=>Oy(i,4));return Ny(r.ZERO,o,s)}function Bd(r,e,t){if(e){if(e.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Gr(e),e}else return jr(r,{isLE:t})}function xs(r,e,t={},n){if(r!=="weierstrass"&&r!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=r==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${r} CURVE object`);Ve(t);for(let c of["p","n","h"]){let u=e[c];if(!(Ht(u)&&u!==Mc))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Bd(e.p,t.Fp,n),s=Bd(e.n,t.Fn,n),a=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:s}}function Es(r,e){return function(n){let o=r(n);return{secretKey:o,publicKey:e(o)}}}var vs=BigInt(0),Ss=BigInt(1),As=BigInt(2),My=BigInt(4),Kd=BigInt(8);function By(r,e,t,n){let o=r.sqr(t),s=r.sqr(n),i=r.add(r.mul(e.a,o),s),a=r.add(r.ONE,r.mul(e.d,r.mul(o,s)));return r.eql(i,a)}function qd(r,e={}){Ve(e,{},{},"extraOpts");let t=e,n=xs("edwards",r,t,t.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;if(Vn(o,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(Vn(o,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");Ve(t,{},{uvRatio:"function",randomBytes:"function"});let c=t.randomBytes===void 0?lr:t.randomBytes,u=As<<BigInt(o.BYTES*8)-Ss;function l(S){if(!o.isOdd)throw new Error("Field does not have .isOdd()");return o.isOdd(S)}let f=t.uvRatio===void 0?(S,w)=>{try{return{isValid:!0,value:o.sqrt(o.div(S,w))}}catch{return{isValid:!1,value:vs}}}:t.uvRatio;if(!By(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let d=o.eql(i.a,o.neg(o.ONE))?S=>o.neg(S):o.eql(i.a,o.ONE)?S=>S:S=>o.mul(i.a,S);function h(S,w,v=!1){let A=v?Ss:vs;return Hr("coordinate "+S,w,A,u),w}function y(S){if(!(S instanceof p))throw new Error("EdwardsPoint expected")}class p{static BASE=new p(i.Gx,i.Gy,o.ONE,o.mul(i.Gx,i.Gy));static ZERO=new p(o.ZERO,o.ONE,o.ONE,o.ZERO);static Fp=o;static Fn=s;X;Y;Z;T;constructor(w,v,A,M){this.X=h("x",w),this.Y=h("y",v),this.Z=h("z",A,!0),this.T=h("t",M),Object.freeze(this)}static CURVE(){return i}static fromAffine(w){if(w instanceof p)throw new Error("extended point not allowed");let{x:v,y:A}=w||{};return h("x",v),h("y",A),new p(v,A,o.ONE,o.mul(v,A))}static fromBytes(w,v=!1){let A=o.BYTES,{a:M,d:$}=i;w=$n(J(w,A,"point")),ze(v,"zip215");let k=$n(w),D=w[A-1];k[A-1]=D&-129;let B=fr(k),V=v?u:o.ORDER;Hr("point.y",B,vs,V);let W=o.sqr(B),oe=o.sub(W,o.ONE),L=o.sub(o.mulN($,W),M),{isValid:z,value:H}=f(oe,L);if(!z)throw new Error("bad point: invalid y coordinate");let N=l(H),ue=(D&128)!==0;if(!v&&o.is0(H)&&ue)throw new Error("bad point: x=0 and x_0=1");return ue!==N&&(H=o.neg(H)),p.fromAffine({x:H,y:B})}static fromHex(w,v=!1){return p.fromBytes(Vr(w),v)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(w=6,v=!0){return b.setWindowSize(this,w),v||this.multiply(As),this}assertValidity(){let w=this,{a:v,d:A}=i;if(w.is0())throw new Error("bad point: ZERO");let{X:M,Y:$,Z:k,T:D}=w,B=o.sqr(M),V=o.sqr($),W=o.sqr(k),oe=o.sqr(W),L=o.mul(B,v),z=o.mul(o.add(L,V),W),H=o.add(oe,o.mul(A,o.mul(B,V)));if(!o.eql(z,H))throw new Error("bad point: equation left != right (1)");let N=o.mul(M,$),ue=o.mul(k,D);if(!o.eql(N,ue))throw new Error("bad point: equation left != right (2)")}equals(w){y(w);let{X:v,Y:A,Z:M}=this,{X:$,Y:k,Z:D}=w,B=o.mul(v,D),V=o.mul($,M),W=o.mul(A,D),oe=o.mul(k,M);return o.eql(B,V)&&o.eql(W,oe)}is0(){return this.equals(p.ZERO)}negate(){return new p(o.neg(this.X),this.Y,this.Z,o.neg(this.T))}double(){let{X:w,Y:v,Z:A}=this,M=o.sqr(w),$=o.sqr(v),k=o.mul(o.sqr(A),As),D=d(M),B=o.addN(w,v),V=o.sub(o.subN(o.sqr(B),M),$),W=o.addN(D,$),oe=o.subN(W,k),L=o.subN(D,$),z=o.mul(V,oe),H=o.mul(W,L),N=o.mul(V,L),ue=o.mul(oe,W);return new p(z,H,ue,N)}add(w){y(w);let{d:v}=i,{X:A,Y:M,Z:$,T:k}=this,{X:D,Y:B,Z:V,T:W}=w,oe=o.mul(A,D),L=o.mul(M,B),z=o.mul(o.mulN(k,v),W),H=o.mul($,V),N=o.sub(o.subN(o.mulN(o.addN(A,M),o.addN(D,B)),oe),L),ue=o.subN(H,z),he=o.addN(H,z),_=o.sub(L,d(oe)),m=o.mul(N,ue),x=o.mul(he,_),E=o.mul(N,_),C=o.mul(ue,he);return new p(m,x,C,E)}subtract(w){return y(w),this.add(w.negate())}multiply(w){if(!s.isValidNot0(w))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:v,f:A}=b.mulSecret(this,w,a,g);return g([v,A])[0]}multiplyUnsafe(w){if(!s.isValid(w))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return w===vs?p.ZERO:this.is0()||w===Ss?this:b.mulUnsafe(this,w,g)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return b.mulUnsafe(this,i.n).is0()}toAffine(w){let v=this,A=w;if(A!=null&&typeof A!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof A);let{X:M,Y:$,Z:k}=v,D=v.is0();A==null&&(A=D?o.create(Kd):o.inv(k));let B=o.mul(M,A),V=o.mul($,A),W=o.mul(k,A);if(D)return{x:o.ZERO,y:o.ONE};if(!o.eql(W,o.ONE))throw new Error("invZ was invalid");return{x:B,y:V}}clearCofactor(){return a===Ss?this:a===As?this.double():a===My?this.double().double():a===Kd?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:w,y:v}=this.toAffine(),A=o.toBytes(v);return A[A.length-1]|=l(w)?128:0,A}toHex(){return Kn(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let g=S=>bs(p,S),b=new Yr(p,c);return b.bits>=6&&p.BASE.precompute(6),Object.freeze(p.prototype),Object.freeze(p),p}function $d(r,e,t={}){if(jt(r),typeof e!="function")throw new Error('"hash" function param is required');let n=e,o=t;Ve(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=r,u=n.outputLen,l=2*a.BYTES;if(u!==void 0&&(Tt(u,"hash.outputLen"),u!==l))throw new Error(`hash.outputLen must be ${l}, got ${u}`);let f=o.randomBytes===void 0?lr:o.randomBytes,d=o.toMontgomery,h=o.toMontgomerySecret,y=o.adjustScalarBytes===void 0?L=>L:o.adjustScalarBytes,p=o.domain===void 0?(L,z,H)=>{if(ze(H,"phflag"),z.length||H)throw new Error("Contexts/pre-hash are not supported");return L}:o.domain;function g(L){return c.create(fr(L))}function b(L){let z=D.secretKey;J(L,D.secretKey,"secretKey");let H=J(n(L),2*z,"hashedSecretKey"),N=y(H.slice(0,z)),ue=H.slice(z,2*z),he=g(N);return{head:N,prefix:ue,scalar:he}}function S(L){let{head:z,prefix:H,scalar:N}=b(L),ue=i.multiply(N),he=ue.toBytes();return{head:z,prefix:H,scalar:N,point:ue,pointBytes:he}}function w(L){return S(L).pointBytes}function v(L=Uint8Array.of(),...z){let H=ot(...z);return g(n(p(H,J(L,void 0,"context"),!!s)))}function A(L,z,H={}){Ve(H,{},{},"options"),L=$n(J(L,void 0,"message")),s&&(L=s(L));let{prefix:N,scalar:ue,pointBytes:he}=S(z),_=v(H.context,N,L),m=i.multiply(_).toBytes(),x=v(H.context,m,he,L),E=c.create(_+x*ue);if(!c.isValid(E))throw new Error("sign failed: invalid s");let C=ot(m,c.toBytes(E));return J(C,D.signature,"result")}let M={zip215:o.zip215};function $(L,z,H,N=M){Ve(N);let{context:ue}=N,he=N.zip215===void 0?!!M.zip215:N.zip215,_=D.signature;L=J(L,_,"signature"),z=J(z,void 0,"message"),H=J(H,D.publicKey,"publicKey"),he!==void 0&&ze(he,"zip215"),s&&(z=s(z));let m=_/2,x=L.subarray(0,m),E=fr(L.subarray(m,_)),C,P,R;try{C=r.fromBytes(H,he),P=r.fromBytes(x,he),R=i.multiplyUnsafe(E)}catch{return!1}if(!he&&C.isSmallOrder())return!1;let U=v(ue,x,H,z);return P.add(C.multiplyUnsafe(U)).subtract(R).clearCofactor().is0()}let k=a.BYTES,D={secretKey:k,publicKey:k,signature:2*k,seed:k};function B(L){return L=L===void 0?f(D.seed):L,J(L,D.seed,"seed")}function V(L){return Wt(L)&&L.length===D.secretKey}function W(L,z){try{return!!r.fromBytes(L,z===void 0?M.zip215:z)}catch{return!1}}let oe={getExtendedPublicKey:S,randomSecretKey:B,isValidSecretKey:V,isValidPublicKey:W,toMontgomery(L){if(d===void 0)throw new Error("Montgomery conversion is not supported for this curve");return d(r.fromBytes(L))},toMontgomerySecret(L){if(h===void 0)throw new Error("Montgomery conversion is not supported for this curve");return h(L)}};return Object.freeze(D),Object.freeze(oe),Object.freeze({keygen:Es(B,w),getPublicKey:w,sign:A,verify:$,utils:oe,Point:r,lengths:D})}var Fc=BigInt(1),zd=BigInt(2);var Fy=BigInt(5),Uy=BigInt(8),Uc=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Ky={p:Uc,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Uy,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function qy(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),o=BigInt(80),s=Uc,a=r*r%s*r%s,c=de(a,zd,s)*a%s,u=de(c,Fc,s)*r%s,l=de(u,Fy,s)*u%s,f=de(l,e,s)*l%s,d=de(f,t,s)*f%s,h=de(d,n,s)*d%s,y=de(h,o,s)*h%s,p=de(y,o,s)*h%s,g=de(p,e,s)*l%s;return{pow_p_5_8:de(g,zd,s)*r%s,b2:a}}function Wd(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var Vd=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function $y(r,e){let t=Uc,n=me(e*e*e,t),o=me(n*n*e,t),s=qy(r*o).pow_p_5_8,i=me(r*n*s,t),a=me(e*i*i,t),c=i,u=me(i*Vd,t),l=a===r,f=a===me(-r,t),d=a===me(-r*Vd,t);return l&&(i=c),(f||d)&&(i=u),Od(i,t)&&(i=me(-i,t)),{isValid:l||f,value:i}}var Kc=qd(Ky,{uvRatio:$y}),Hd=Kc.Fp;function zy(r){let{y:e}=r;return Hd.toBytes(Hd.div(Fc+e,Fc-e))}function Vy(r){let e=Kc.Fp.BYTES;return nt(r,e),Wd(Tc(r.subarray(0,e))).subarray(0,e)}function Hy(r){return $d(Kc,Tc,Object.assign({adjustScalarBytes:Wd,toMontgomery:zy,toMontgomerySecret:Vy,zip215:!0},r))}var Wn=Hy({});var Gn=class extends Error{constructor(e="An error occurred while signing a message"){super(e),this.name="SigningError"}},jn=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},_s=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var He={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw new _s("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 e}};var Cs=32,Yn=64,qc=32;var Xr,Gd=(async()=>{try{return await He.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function jd(){let r=Wn.utils.randomSecretKey(),e=Wn.getPublicKey(r);return{privateKey:Xy(r,e),publicKey:e}}async function Wy(r,e){let t;r.length===Yn?t=r.subarray(0,32):t=r;let n={crv:"Ed25519",kty:"OKP",x:F(r.subarray(32),"base64url"),d:F(t,"base64url"),ext:!0,key_ops:["sign"]},o=await He.get().subtle.importKey("jwk",n,{name:"Ed25519"},!0,["sign"]),s=await He.get().subtle.sign({name:"Ed25519"},o,Te(e instanceof Uint8Array?e:e.subarray()));return new Uint8Array(s,0,s.byteLength)}function Gy(r,e){let t=r.subarray(0,qc);return Wn.sign(e instanceof Uint8Array?e:e.subarray(),t)}async function Yd(r,e){return Xr==null&&(Xr=await Gd),Xr?Wy(r,e):Gy(r,e)}async function jy(r,e,t){if(r.buffer instanceof ArrayBuffer){let n=await He.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await He.get().subtle.verify({name:"Ed25519"},n,Te(e),Te(t instanceof Uint8Array?t:t.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Yy(r,e,t){return Wn.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}async function Xd(r,e,t){return Xr==null&&(Xr=await Gd),Xr?jy(r,e,t):Yy(r,e,t)}function Xy(r,e){let t=new Uint8Array(Yn);for(let n=0;n<qc;n++)t[n]=r[n],t[qc+n]=e[n];return t}function Zr(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Xn=class{type="Ed25519";raw;constructor(e){this.raw=Is(e,Cs)}toMultihash(){return at.digest(rt(this))}toCID(){return xe.createV1(114,this.toMultihash())}toString(){return ie.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Q(this.raw,e.raw)}verify(e,t,n){n?.signal?.throwIfAborted();let o=Xd(this.raw,t,e);return Zr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}},Ts=class{type="Ed25519";raw;publicKey;constructor(e,t){this.raw=Is(e,Yn),this.publicKey=new Xn(t)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Q(this.raw,e.raw)}sign(e,t){t?.signal?.throwIfAborted();let n=Yd(this.raw,e);return Zr(n)?n.then(o=>(t?.signal?.throwIfAborted(),o)):(t?.signal?.throwIfAborted(),n)}};function $c(r){return r=Is(r,Cs),new Xn(r)}async function Qd(){let{privateKey:r,publicKey:e}=jd();return new Ts(r,e)}function Is(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new T(`Key must be a Uint8Array of length ${e}, got ${r.length}`);return r}var Zy=Math.pow(2,7),Qy=Math.pow(2,14),Jy=Math.pow(2,21),zc=Math.pow(2,28),Vc=Math.pow(2,35),Hc=Math.pow(2,42),Wc=Math.pow(2,49),te=128,Pe=127;function Ae(r){if(r<Zy)return 1;if(r<Qy)return 2;if(r<Jy)return 3;if(r<zc)return 4;if(r<Vc)return 5;if(r<Hc)return 6;if(r<Wc)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Qr(r,e,t=0){switch(Ae(r)){case 8:e[t++]=r&255|te,r/=128;case 7:e[t++]=r&255|te,r/=128;case 6:e[t++]=r&255|te,r/=128;case 5:e[t++]=r&255|te,r/=128;case 4:e[t++]=r&255|te,r>>>=7;case 3:e[t++]=r&255|te,r>>>=7;case 2:e[t++]=r&255|te,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function e0(r,e,t=0){switch(Ae(r)){case 8:e.set(t++,r&255|te),r/=128;case 7:e.set(t++,r&255|te),r/=128;case 6:e.set(t++,r&255|te),r/=128;case 5:e.set(t++,r&255|te),r/=128;case 4:e.set(t++,r&255|te),r>>>=7;case 3:e.set(t++,r&255|te),r>>>=7;case 2:e.set(t++,r&255|te),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Gc(r,e){let t=r[e],n=0;if(n+=t&Pe,t<te||(t=r[e+1],n+=(t&Pe)<<7,t<te)||(t=r[e+2],n+=(t&Pe)<<14,t<te)||(t=r[e+3],n+=(t&Pe)<<21,t<te)||(t=r[e+4],n+=(t&Pe)*zc,t<te)||(t=r[e+5],n+=(t&Pe)*Vc,t<te)||(t=r[e+6],n+=(t&Pe)*Hc,t<te)||(t=r[e+7],n+=(t&Pe)*Wc,t<te))return n;throw new RangeError("Could not decode varint")}function t0(r,e){let t=r.get(e),n=0;if(n+=t&Pe,t<te||(t=r.get(e+1),n+=(t&Pe)<<7,t<te)||(t=r.get(e+2),n+=(t&Pe)<<14,t<te)||(t=r.get(e+3),n+=(t&Pe)<<21,t<te)||(t=r.get(e+4),n+=(t&Pe)*zc,t<te)||(t=r.get(e+5),n+=(t&Pe)*Vc,t<te)||(t=r.get(e+6),n+=(t&Pe)*Hc,t<te)||(t=r.get(e+7),n+=(t&Pe)*Wc,t<te))return n;throw new RangeError("Could not decode varint")}function Yt(r,e,t=0){return e==null&&(e=Se(Ae(r))),e instanceof Uint8Array?Qr(r,e,t):e0(r,e,t)}function dr(r,e=0){return r instanceof Uint8Array?Gc(r,e):t0(r,e)}var jc=new Float32Array([-0]),Xt=new Uint8Array(jc.buffer);function Jd(r,e,t){jc[0]=r,e[t]=Xt[0],e[t+1]=Xt[1],e[t+2]=Xt[2],e[t+3]=Xt[3]}function eh(r,e){return Xt[0]=r[e],Xt[1]=r[e+1],Xt[2]=r[e+2],Xt[3]=r[e+3],jc[0]}var Yc=new Float64Array([-0]),De=new Uint8Array(Yc.buffer);function th(r,e,t){Yc[0]=r,e[t]=De[0],e[t+1]=De[1],e[t+2]=De[2],e[t+3]=De[3],e[t+4]=De[4],e[t+5]=De[5],e[t+6]=De[6],e[t+7]=De[7]}function rh(r,e){return De[0]=r[e],De[1]=r[e+1],De[2]=r[e+2],De[3]=r[e+3],De[4]=r[e+4],De[5]=r[e+5],De[6]=r[e+6],De[7]=r[e+7],Yc[0]}var r0=BigInt(Number.MAX_SAFE_INTEGER),n0=BigInt(Number.MIN_SAFE_INTEGER),Ge=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return hr;if(e<r0&&e>n0)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,o=e-(n<<32n);return t&&(n=~n|0n,o=~o|0n,++o>nh&&(o=0n,++n>nh&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return hr;let t=e<0;t&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return t&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):hr}},hr=new Ge(0,0);hr.toBigInt=function(){return 0n};hr.zzEncode=hr.zzDecode=function(){return this};hr.length=function(){return 1};var nh=4294967296n;function oh(r){let e=0,t=0;for(let n=0;n<r.length;++n)t=r.charCodeAt(n),t<128?e+=1:t<2048?e+=2:(t&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function sh(r,e,t){if(t-e<1)return"";let o,s=[],i=0,a;for(;e<t;)a=r[e++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&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 Xc(r,e,t){let n=t,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128);return t-n}function lt(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function Ls(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var Zc=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=Te(e),this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,lt(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw lt(this,4);return Ls(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw lt(this,4);return Ls(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw lt(this,4);let e=eh(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw lt(this,4);let e=rh(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),t=this.pos,n=this.pos+e;if(n>this.len)throw lt(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return sh(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw lt(this,e);this.pos+=e}else do if(this.pos>=this.len)throw lt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Ge(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw lt(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<t*7)>>>0,e}if(this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw lt(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw lt(this,8);let e=Ls(this.buf,this.pos+=4),t=Ls(this.buf,this.pos+=4);return new Ge(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Gc(this.buf,this.pos);return this.pos+=Ae(e),e}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 Qn(r){return new Zc(r instanceof Uint8Array?r:r.subarray())}function Be(r,e,t){let n=Qn(r);return e.decode(n,void 0,t)}function Qc(r){let e=r??8192,t=e>>>1,n,o=e;return function(i){if(i<1||i>t)return Se(i);o+i>e&&(n=Se(e),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var pr=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function Jc(){}var tu=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},o0=Qc();function s0(r){return globalThis.Buffer!=null?Se(r):o0(r)}var eo=class{len;head;tail;states;constructor(){this.len=0,this.head=new pr(Jc,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new pr(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new ru((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(Ps,10,Ge.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=Ge.fromBigInt(e);return this._push(Ps,t.length(),t)}uint64Number(e){return this._push(Qr,Ae(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=Ge.fromBigInt(e).zzEncode();return this._push(Ps,t.length(),t)}sint64Number(e){let t=Ge.fromNumber(e).zzEncode();return this._push(Ps,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(eu,1,e?1:0)}fixed32(e){return this._push(Jn,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=Ge.fromBigInt(e);return this._push(Jn,4,t.lo)._push(Jn,4,t.hi)}fixed64Number(e){let t=Ge.fromNumber(e);return this._push(Jn,4,t.lo)._push(Jn,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(Jd,4,e)}double(e){return this._push(th,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(eu,1,0):this.uint32(t)._push(a0,t,e)}string(e){let t=oh(e);return t!==0?this.uint32(t)._push(Xc,t,e):this._push(eu,1,0)}fork(){return this.states=new tu(this),this.head=this.tail=new pr(Jc,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 pr(Jc,0,0),this.len=0),this}ldelim(){let e=this.head,t=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=t,this.len+=n),this}finish(){let e=this.head.next,t=s0(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function eu(r,e,t){e[t]=r&255}function i0(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var ru=class extends pr{next;constructor(e,t){super(i0,e,t),this.next=void 0}};function Ps(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function Jn(r,e,t){e[t]=r&255,e[t+1]=r>>>8&255,e[t+2]=r>>>16&255,e[t+3]=r>>>24}function a0(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(eo.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(c0,e,r),this},eo.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(u0,e,r),this});function c0(r,e,t){e.set(r,t)}function u0(r,e,t){r.length<40?Xc(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(I(r),t)}function nu(){return new eo}function Fe(r,e){let t=nu();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}function*Ue(r,e,t){let n=Qn(r);yield*e.stream(n,void 0,".",t)}var Ds={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Rs(r,e,t,n,o){return{name:r,type:e,encode:t,decode:n,stream:o}}function ou(r){function e(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let t=function(i,a){let c=e(i);a.int32(c)},n=function(i){let a=i.int32();return e(a)},o=function*(i,a){};return Rs("enum",Ds.VARINT,t,n,o)}function Ke(r,e,t){return Rs("message",Ds.LENGTH_DELIMITED,r,e,t)}var st=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},to=class extends Error{code="ERR_MAX_SIZE";name="MaxSizeError"};var ge;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(ge||(ge={}));var su;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(su||(su={}));(function(r){r.codec=()=>ou(su)})(ge||(ge={}));var wt;(function(r){let e;r.codec=()=>(e==null&&(e=Ke((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ge.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let l=s.uint32();switch(l>>>3){case 1:{c.Type=ge.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(l&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let l=s.uint32();switch(l>>>3){case 1:{yield{field:`${a}.Type`,value:ge.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(l&7);break}}}})),e);function t(s){return Fe(s,r.codec())}r.encode=t;function n(s,i){return Be(s,r.codec(),i)}r.decode=n;function o(s,i){return Ue(s,r.codec(),i)}r.stream=o})(wt||(wt={}));var iu;(function(r){let e;r.codec=()=>(e==null&&(e=Ke((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ge.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let l=s.uint32();switch(l>>>3){case 1:{c.Type=ge.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(l&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let l=s.uint32();switch(l>>>3){case 1:{yield{field:`${a}.Type`,value:ge.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(l&7);break}}}})),e);function t(s){return Fe(s,r.codec())}r.encode=t;function n(s,i){return Be(s,r.codec(),i)}r.decode=n;function o(s,i){return Ue(s,r.codec(),i)}r.stream=o})(iu||(iu={}));var no={};$e(no,{MAX_RSA_KEY_SIZE:()=>au,generateRSAKeyPair:()=>gu,jwkToJWKKeyPair:()=>fh,jwkToPkcs1:()=>h0,jwkToPkix:()=>fu,jwkToRSAPrivateKey:()=>mu,pkcs1MessageToJwk:()=>uu,pkcs1MessageToRSAPrivateKey:()=>du,pkcs1ToJwk:()=>d0,pkcs1ToRSAPrivateKey:()=>lh,pkixMessageToJwk:()=>lu,pkixMessageToRSAPublicKey:()=>pu,pkixToJwk:()=>p0,pkixToRSAPublicKey:()=>hu});var Jr=class{type="RSA";jwk;_raw;_multihash;constructor(e,t){this.jwk=e,this._multihash=t}get raw(){return this._raw==null&&(this._raw=no.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return xe.createV1(114,this._multihash)}toString(){return ie.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Q(this.raw,e.raw)}verify(e,t,n){return uh(this.jwk,t,e,n)}},ro=class{type="RSA";jwk;_raw;publicKey;constructor(e,t){this.jwk=e,this.publicKey=t}get raw(){return this._raw==null&&(this._raw=no.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Q(this.raw,e.raw)}sign(e,t){return ch(this.jwk,e,t)}};var au=8192,cu=18,l0=1062,f0=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function d0(r){let e=_t(r);return uu(e)}function uu(r){return{n:F(r[1],"base64url"),e:F(r[2],"base64url"),d:F(r[3],"base64url"),p:F(r[4],"base64url"),q:F(r[5],"base64url"),dp:F(r[6],"base64url"),dq:F(r[7],"base64url"),qi:F(r[8],"base64url"),kty:"RSA"}}function h0(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 T("JWK was missing components");return ct([Me(Uint8Array.from([0])),Me(I(r.n,"base64url")),Me(I(r.e,"base64url")),Me(I(r.d,"base64url")),Me(I(r.p,"base64url")),Me(I(r.q,"base64url")),Me(I(r.dp,"base64url")),Me(I(r.dq,"base64url")),Me(I(r.qi,"base64url"))]).subarray()}function p0(r){let e=_t(r,{offset:0});return lu(e)}function lu(r){let e=_t(r[1],{offset:0});return{kty:"RSA",n:F(e[0],"base64url"),e:F(e[1],"base64url")}}function fu(r){if(r.n==null||r.e==null)throw new T("JWK was missing components");return ct([f0,Mn(ct([Me(I(r.n,"base64url")),Me(I(r.e,"base64url"))]))]).subarray()}function lh(r){let e=_t(r);return du(e)}function du(r){let e=uu(r);return mu(e)}function hu(r,e){if(r.byteLength>=l0)throw new mt("Key size is too large");let t=_t(r,{offset:0});return pu(t,r,e)}function pu(r,e,t){let n=lu(r);if(t==null){let o=zr(wt.encode({Type:ge.RSA,Data:e}));t=gt(cu,o)}return new Jr(n,t)}function mu(r){if(hh(r)>au)throw new T("Key size is too large");let e=fh(r),t=zr(wt.encode({Type:ge.RSA,Data:fu(e.publicKey)})),n=gt(cu,t);return new ro(e.privateKey,new Jr(e.publicKey,n))}async function gu(r){if(r>au)throw new T("Key size is too large");let e=await dh(r),t=zr(wt.encode({Type:ge.RSA,Data:fu(e.publicKey)})),n=gt(cu,t);return new ro(e.privateKey,new Jr(e.publicKey,n))}function fh(r){if(r==null)throw new T("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function dh(r,e){let t=await He.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await m0(t,e);return{privateKey:n[0],publicKey:n[1]}}async function ch(r,e,t){let n=await He.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);t?.signal?.throwIfAborted();let o=await He.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,Te(e instanceof Uint8Array?e:e.subarray()));return t?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function uh(r,e,t,n){let o=await He.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await He.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,Te(e),Te(t instanceof Uint8Array?t:t.subarray()));return n?.signal?.throwIfAborted(),s}async function m0(r,e){if(r.privateKey==null||r.publicKey==null)throw new T("Private and public key are required");let t=await Promise.all([He.get().subtle.exportKey("jwk",r.privateKey),He.get().subtle.exportKey("jwk",r.publicKey)]);return e?.signal?.throwIfAborted(),t}function hh(r){if(r.kty!=="RSA")throw new T("invalid key type");if(r.n==null)throw new T("invalid key modulus");return I(r.n,"base64url").length*8}var Os=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,t){if(ss(e),nt(t,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(t.length>n?e.create().update(t).digest():t);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),cr(o)}update(e){return $r(this),this.iHash.update(e),this}digestInto(e){$r(this),is(e,this),this.finished=!0;let t=e.subarray(0,this.outputLen);this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:t,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a,canXOF:c}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.canXOF=c,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ph=(()=>{let r=((e,t,n)=>new Os(e,t).update(n).digest());return r.create=(e,t)=>new Os(e,t),r})();var g0=BigInt(0),yu=class extends Error{constructor(e=""){super(e)}},It={Err:yu,_tlv:{encode:(r,e)=>{let{Err:t}=It;if(Tt(r,"tag"),r<0||r>255)throw new t("tlv.encode: wrong tag");if(xd(e,"data"),e.length&1)throw new t("tlv.encode: unpadded data");let n=e.length/2,o=qn(n);if(o.length/2&128)throw new t("tlv.encode: long form length too big");let s=n>127?qn(o.length/2|128):"";return qn(r)+s+o+e},decode(r,e){let{Err:t}=It;e=J(e,void 0,"DER data");let n=0;if(r<0||r>255)throw new t("tlv.decode: wrong tag");if(e.length<2||e[n++]!==r)throw new t("tlv.decode: wrong tlv");let o=e[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new t("tlv.decode(long): indefinite length not supported");if(c>4)throw new t("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+c);if(u.length!==c)throw new t("tlv.decode: length bytes not complete");if(u[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(let l of u)i=i<<8|l;if(n+=c,i<128)throw new t("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+i);if(a.length!==i)throw new t("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(r){let{Err:e}=It;if(ds(r),r<g0)throw new e("integer: negative integers are not allowed");let t=qn(r);if(Number.parseInt(t[0],16)&8&&(t="00"+t),t.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return t},decode(r){let{Err:e}=It;if(r.length<1)throw new e("invalid signature integer: empty");if(r[0]&128)throw new e("invalid signature integer: negative");if(r.length>1&&r[0]===0&&!(r[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return bt(r)}},toSig(r,e){let{Err:t,_int:n,_tlv:o}=It;if(e!==void 0&&(Tt(e,"maxScalarBytes"),e<1))throw new t("invalid signature: maxScalarBytes must be positive");let s=J(r,void 0,"signature"),{v:i,l:a}=o.decode(48,s);if(a.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:u}=o.decode(2,i),{v:l,l:f}=o.decode(2,u);if(f.length)throw new t("invalid signature: left bytes after parsing");if(e!==void 0&&(c.length>e||l.length>e))throw new t("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(l)}},hexFromSig(r){let{_tlv:e,_int:t}=It;Ve(r,{r:"bigint",s:"bigint"},{},"sig");let n=e.encode(2,t.encode(r.r)),o=e.encode(2,t.encode(r.s)),s=n+o;return e.encode(48,s)}},ks=(Object.freeze(It._tlv),Object.freeze(It._int),Object.freeze(It));var mh=(r,e)=>(r+(r>=0?e:-e)/gh)/e;function y0(r,e,t){Hr("scalar",r,Lt,t);let[[n,o],[s,i]]=e,a=mh(i*r,t),c=mh(-o*r,t),u=r-a*n-c*s,l=-a*o-c*i,f=u<Lt,d=l<Lt;f&&(u=-u),d&&(l=-l);let h=zn(Math.ceil(Wr(t)/2))+mr;if(u<Lt||u>=h||l<Lt||l>=h)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:f,k1:u,k2neg:d,k2:l}}function xu(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function bu(r,e){Ve(r);let t={};for(let n of Object.keys(e))t[n]=r[n]===void 0?e[n]:r[n];return ze(t.lowS,"lowS"),ze(t.prehash,"prehash"),t.format!==void 0&&xu(t.format),t}var Lt=BigInt(0),mr=BigInt(1),gh=BigInt(2),wu=BigInt(3),b0=BigInt(4);function yh(r,e={}){let t=xs("weierstrass",r,e),n=t.Fp,o=t.Fn,s=t.CURVE,{h:i,n:a}=s;Ve(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u,clearCofactor:l,isTorsionFree:f,fromBytes:d,toBytes:h}=e,y=e.randomBytes===void 0?lr:e.randomBytes;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let p=c?{beta:c.beta,basises:c.basises.map(_=>[..._])}:void 0,g=wh(n,o);function b(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function S(_,m,x){if(m.is0()){if(!u)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:E,y:C}=m.toAffine(),P=n.toBytes(E);if(ze(x,"isCompressed"),x){b();let R=!n.isOdd(C);return ot(bh(R),P)}else return ot(Uint8Array.of(4),P,n.toBytes(C))}function w(_){J(_,void 0,"Point");let{publicKey:m,publicKeyUncompressed:x}=g,E=_.length,C=_[0],P=_.subarray(1);if(u&&E===1&&C===0)return{x:n.ZERO,y:n.ZERO};if(E===m&&(C===2||C===3)){let R=n.fromBytes(P);if(!n.isValid(R))throw new Error("bad point: is not on curve, wrong x");let U=k(R),K;try{K=n.sqrt(U)}catch(be){let le=be instanceof Error?": "+be.message:"";throw new Error("bad point: is not on curve, sqrt error"+le)}b();let Z=n.isOdd(K);return(C&1)===1!==Z&&(K=n.neg(K)),{x:R,y:K}}else if(E===x&&C===4){let R=n.BYTES,U=n.fromBytes(P.subarray(0,R)),K=n.fromBytes(P.subarray(R,R*2));if(!D(U,K))throw new Error("bad point: is not on curve");return{x:U,y:K}}else throw new Error(`bad point: got length ${E}, expected compressed=${m} or uncompressed=${x}`)}let v=h===void 0?S:h,A=d===void 0?w:d,M=n.mul(s.b,wu),$=n.is0(s.a)?_=>n.ZERO:_=>n.mul(s.a,_);function k(_){let m=n.sqr(_),x=n.mul(m,_);return n.add(n.add(x,n.mul(_,s.a)),s.b)}function D(_,m){let x=n.sqr(m),E=k(_);return n.eql(x,E)}if(!D(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let B=n.mul(n.pow(s.a,wu),b0),V=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(B,V)))throw new Error("bad curve params: a or b");function W(_,m,x=!1){if(!n.isValid(m)||x&&n.is0(m))throw new Error(`bad point coordinate ${_}`);return typeof m=="object"&&m!==null?n.create(m):m}function oe(_){if(!(_ instanceof N))throw new Error("Weierstrass Point expected")}function L(_){if(!p||!p.basises)throw new Error("no endo");return y0(_,p.basises,o.ORDER)}function z(_,m,x,E){if(!o.isValid(E))throw new RangeError("invalid scalar: out of range");if(p){let{k1neg:C,k1:P,k2neg:R,k2:U}=L(E),K=new N(n.mul(x.X,p.beta),x.Y,x.Z);_.push(C?x.negate():x,R?K.negate():K),m.push(P,U)}else _.push(x),m.push(E)}let H=new WeakSet;class N{static BASE=new N(s.Gx,s.Gy,n.ONE);static ZERO=new N(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(m,x,E){this.X=W("x",m),this.Y=W("y",x,!0),this.Z=W("z",E),Object.freeze(this)}static CURVE(){return s}static fromAffine(m){let{x,y:E}=m||{};if(!m||!n.isValid(x)||!n.isValid(E))throw new Error("invalid affine point");if(m instanceof N)throw new Error("projective point not allowed");return n.is0(x)&&n.is0(E)?N.ZERO:new N(x,E,n.ONE)}static fromBytes(m){let x=N.fromAffine(A(J(m,void 0,"point")));return x.assertValidity(),x}static fromHex(m){return N.fromBytes(Vr(m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=6,x=!0){return he.setWindowSize(this,m),x||this.multiply(wu),this}assertValidity(){let m=this;if(m.is0()){if(u&&n.is0(m.X)&&n.eql(m.Y,n.ONE)&&n.is0(m.Z))return;throw new Error("bad point: ZERO")}if(H.has(m))return;let{x,y:E}=m.toAffine();if(!n.isValid(x)||!n.isValid(E))throw new Error("bad point: x or y not field elements");if(!D(x,E))throw new Error("bad point: equation left != right");if(!m.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");H.add(m)}hasEvenY(){let{y:m}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(m)}equals(m){oe(m);let{X:x,Y:E,Z:C}=this,{X:P,Y:R,Z:U}=m,K=n.eql(n.mul(x,U),n.mul(P,C)),Z=n.eql(n.mul(E,U),n.mul(R,C));return K&&Z}negate(){return new N(this.X,n.neg(this.Y),this.Z)}double(){let{X:m,Y:x,Z:E}=this,C=n.ZERO,P=n.ZERO,R=n.ZERO,U=n.mul(m,m),K=n.mul(x,x),Z=n.mul(E,E),j=n.mul(m,x);return j=n.add(j,j),R=n.mul(m,E),R=n.add(R,R),C=$(R),P=n.mul(M,Z),P=n.add(C,P),C=n.sub(K,P),P=n.add(K,P),P=n.mul(C,P),C=n.mul(j,C),R=n.mul(M,R),Z=$(Z),j=n.sub(U,Z),j=$(j),j=n.add(j,R),R=n.add(U,U),U=n.add(R,U),U=n.add(U,Z),U=n.mul(U,j),P=n.add(P,U),Z=n.mul(x,E),Z=n.add(Z,Z),U=n.mul(Z,j),C=n.sub(C,U),R=n.mul(Z,K),R=n.add(R,R),R=n.add(R,R),new N(C,P,R)}add(m){oe(m);let{X:x,Y:E,Z:C}=this,{X:P,Y:R,Z:U}=m,K=n.ZERO,Z=n.ZERO,j=n.ZERO,be=n.mul(x,P),le=n.mul(E,R),ve=n.mul(C,U),Ze=n.add(x,E),fe=n.add(P,R);Ze=n.mul(Ze,fe),fe=n.add(be,le),Ze=n.sub(Ze,fe),fe=n.add(x,C);let we=n.add(P,U);return fe=n.mul(fe,we),we=n.add(be,ve),fe=n.sub(fe,we),we=n.add(E,C),K=n.add(R,U),we=n.mul(we,K),K=n.add(le,ve),we=n.sub(we,K),j=$(fe),K=n.mul(M,ve),j=n.add(K,j),K=n.sub(le,j),j=n.add(le,j),Z=n.mul(K,j),le=n.add(be,be),le=n.add(le,be),ve=$(ve),fe=n.mul(M,fe),le=n.add(le,ve),ve=n.sub(be,ve),ve=$(ve),fe=n.add(fe,ve),be=n.mul(le,fe),Z=n.add(Z,be),be=n.mul(we,fe),K=n.mul(Ze,K),K=n.sub(K,be),be=n.mul(Ze,le),j=n.mul(we,j),j=n.add(j,be),new N(K,Z,j)}subtract(m){return oe(m),this.add(m.negate())}is0(){return this.equals(N.ZERO)}multiply(m){if(!o.isValidNot0(m))throw new RangeError("invalid scalar: out of range");let{p:x,f:E}=he.mulSecret(this,m,i,ue);return ue([x,E])[0]}multiplyUnsafe(m){let x=this,E=m;if(!o.isValid(E))throw new RangeError("invalid scalar: out of range");if(E===Lt||x.is0())return N.ZERO;if(E===mr)return x;if(he.hasWindowSize(this))return he.mulUnsafe(x,E,ue);let C=[],P=[];return z(C,P,x,E),ws(N,C,P)}mulAddUnsafe(m,x,E){oe(x);let C=[],P=[];return z(C,P,this,m),z(C,P,x,E),ws(N,C,P)}toAffine(m){let x=this,E=m;if(E!=null&&!n.isValid(E))throw new RangeError('"invertedZ" expected valid field element');let{X:C,Y:P,Z:R}=x;if(n.eql(R,n.ONE))return{x:C,y:P};let U=x.is0();E==null&&(E=U?n.ONE:n.inv(R));let K=n.mul(C,E),Z=n.mul(P,E),j=n.mul(R,E);if(U)return{x:n.ZERO,y:n.ZERO};if(!n.eql(j,n.ONE))throw new Error("invZ was invalid");return{x:K,y:Z}}isTorsionFree(){return i===mr?!0:f?f(N,this):he.mulUnsafe(this,a).is0()}clearCofactor(){return i===mr?this:l?l(N,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===mr?this.is0():this.clearCofactor().is0()}toBytes(m=!0){return ze(m,"isCompressed"),this.assertValidity(),v(N,this,m)}toHex(m=!0){return Kn(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let ue=_=>bs(N,_),he=new Yr(N,y);return he.bits>=6&&N.BASE.precompute(6),Object.freeze(N.prototype),Object.freeze(N),N}function bh(r){return Uint8Array.of(r?2:3)}function wh(r,e){return{secretKey:e.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function w0(r,e={}){jt(r);let{Fn:t}=r,n=e.randomBytes===void 0?lr:e.randomBytes,o=Object.assign(wh(r.Fp,t),{seed:Math.max(gs(t.ORDER),16)});function s(h){try{let y=t.fromBytes(h);return t.isValidNot0(y)}catch{return!1}}function i(h,y){let{publicKey:p,publicKeyUncompressed:g}=o;try{let b=h.length;return y===!0&&b!==p||y===!1&&b!==g?!1:!r.fromBytes(h).is0()}catch{return!1}}function a(h){return h=h===void 0?n(o.seed):h,ys(J(h,o.seed,"seed"),t.ORDER)}function c(h,y=!0){return r.BASE.multiply(t.fromBytes(h)).toBytes(y)}function u(h){let{secretKey:y,publicKey:p,publicKeyUncompressed:g}=o,b=t._lengths;if(!Wt(h))return;let S=J(h,void 0,"key").length,w=S===p||S===g,v=S===y||!!b?.includes(S);if(!(w&&v))return w}function l(h,y,p=!0){if(u(h)===!0)throw new Error("first arg must be private key");if(u(y)===!1)throw new Error("second arg must be public key");let g=t.fromBytes(h),b=r.fromBytes(y);if(b.is0())throw new Error("invalid public key: point at infinity");return b.multiply(g).toBytes(p)}let f={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},d=Es(a,c);return Object.freeze(f),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:l,keygen:d,Point:r,utils:f,lengths:o})}function xh(r,e,t={}){jt(r);let n=e;ss(n),Ve(t,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},t),s=o.randomBytes===void 0?lr:o.randomBytes,i=o.hmac===void 0?(_,m)=>ph(n,_,m):o.hmac,{Fp:a,Fn:c}=r,{ORDER:u,BITS:l}=c,f=gs(u),d=Bc(s,f),{keygen:h,getPublicKey:y,getSharedSecret:p,utils:g,lengths:b}=w0(r,o),S={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},w=u*gh+mr<a.ORDER;function v(_){let m=u>>mr;return _>m}function A(_,m){if(!c.isValidNot0(m))throw new Error(`invalid signature ${_}: out of range 1..Point.Fn.ORDER`);return m}function M(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function $(_,m,x){return M(),(_===x?0:2)|Number(a.isOdd(m))}function k(){if(w)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function D(_,m){xu(m);let x=b.signature,E=m==="compact"?x:m==="recovered"?x+1:void 0;return J(_,E)}class B{r;s;recovery;constructor(m,x,E){if(this.r=A("r",m),this.s=A("s",x),E!=null){if(k(),![0,1,2,3].includes(E))throw new Error("invalid recovery id");this.recovery=E}Object.freeze(this)}static fromBytes(m,x=S.format){D(m,x);let E;if(x==="der"){if(m.length>2*c.BYTES+16)throw new ks.Err("invalid signature: DER signature too long");let{r:U,s:K}=ks.toSig(J(m),c.BYTES+1);return new B(U,K)}x==="recovered"&&(E=m[0],x="compact",m=m.subarray(1));let C=b.signature/2,P=m.subarray(0,C),R=m.subarray(C,C*2);return new B(c.fromBytes(P),c.fromBytes(R),E)}static fromHex(m,x){return this.fromBytes(Vr(m),x)}assertRecovery(){let{recovery:m}=this;if(m==null)throw new Error("invalid recovery id: must be present");return m}addRecoveryBit(m){return new B(this.r,this.s,m)}recoverPublicKey(m){let{r:x,s:E}=this,C=this.assertRecovery(),P=C===2||C===3?x+u:x;if(!a.isValid(P))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let R=a.toBytes(P),U=r.fromBytes(ot(bh((C&1)===0),R)),K=c.inv(P),Z=W(J(m,void 0,"msgHash")),j=c.create(-Z*K),be=c.create(E*K),le=r.BASE.mulAddUnsafe(j,U,be);if(le.is0())throw new Error("invalid recovery: point at infinify");return le.assertValidity(),le}hasHighS(){return v(this.s)}toBytes(m=S.format){if(xu(m),m==="der")return Vr(ks.hexFromSig(this));let{r:x,s:E}=this,C=c.toBytes(x),P=c.toBytes(E);return m==="recovered"?(k(),ot(Uint8Array.of(this.assertRecovery()),C,P)):ot(C,P)}toHex(m){return Kn(this.toBytes(m))}}Object.freeze(B.prototype),Object.freeze(B);let V=o.bits2int===void 0?function(m){if(m.length>8192)throw new Error("input is too large");let x=bt(m),E=m.length*8-l;return E>0?x>>BigInt(E):x}:o.bits2int,W=o.bits2int_modN===void 0?function(m){return c.create(V(m))}:o.bits2int_modN,oe=zn(l);function L(_){return Hr("num < 2^"+l,_,Lt,oe),c.toBytes(_)}function z(_,m){return J(_,void 0,"message"),m?J(n(_),void 0,"prehashed message"):_}function H(_,m,x){let{lowS:E,prehash:C,extraEntropy:P}=bu(x,S);_=z(_,C);let R=W(_),U=c.fromBytes(m);if(!c.isValidNot0(U))throw new Error("invalid private key");let K=[L(U),L(R)];if(P!=null&&P!==!1){let le=P===!0?s(b.secretKey):P;K.push(J(le,void 0,"extraEntropy"))}let Z=ot(...K),j=R;function be(le){let ve=V(le);if(!c.isValidNot0(ve))return;let Ze=r.BASE.multiply(ve).toAffine(),fe=c.create(Ze.x);if(fe===Lt)return;let we;if(d!==void 0){let An=bt(ys(d(f),u)),Tm=c.inv(c.mul(An,ve)),Im=c.mul(An,j),Lm=c.mul(An,U);we=c.create(Tm*c.create(Im+Lm*fe))}else{let An=Pd(ve,u);we=c.create(An*c.create(j+fe*U))}if(we===Lt)return;let Na=$(Ze.x,Ze.y,fe),hf=we;return E&&v(we)&&(hf=c.neg(we),Na^=1),new B(fe,hf,w?void 0:Na)}return{seed:Z,k2sig:be}}function N(_,m,x={}){let{seed:E,k2sig:C}=H(_,m,x);return vd(n.outputLen,c.BYTES,i)(E,C).toBytes(x.format)}function ue(_,m,x,E={}){let{lowS:C,prehash:P,format:R}=bu(E,S);if(x=J(x,void 0,"publicKey"),m=z(m,P),!Wt(_)){let U=_ instanceof B?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+U)}D(_,R);try{let U=B.fromBytes(_,R),K=r.fromBytes(x);if(K.is0()||C&&U.hasHighS())return!1;let{r:Z,s:j}=U,be=W(m),le=c.inv(j),ve=c.create(be*le),Ze=c.create(Z*le),fe=r.BASE.mulAddUnsafe(ve,K,Ze);if(fe.is0())return!1;let we=fe.toAffine();return!(c.create(we.x)!==Z||R==="recovered"&&U.recovery!==$(we.x,we.y,Z))}catch{return!1}}function he(_,m,x={}){let{prehash:E}=bu(x,S);return m=z(m,E),B.fromBytes(_,"recovered").recoverPublicKey(m).toBytes()}return Object.freeze({keygen:h,getPublicKey:y,getSharedSecret:p,utils:g,lengths:b,Point:r,sign:N,verify:ue,recoverPublicKey:he,Signature:B,hash:n})}var vu={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},x0={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Eh=BigInt(2);function E0(r){let e=vu.p,t=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%e,l=u*u*r%e,f=de(l,t,e)*l%e,d=de(f,t,e)*l%e,h=de(d,Eh,e)*u%e,y=de(h,o,e)*h%e,p=de(y,s,e)*y%e,g=de(p,a,e)*p%e,b=de(g,c,e)*g%e,S=de(b,a,e)*p%e,w=de(S,t,e)*l%e,v=de(w,i,e)*y%e,A=de(v,n,e)*u%e,M=de(A,Eh,e);if(!Eu.eql(Eu.sqr(M),r))throw new Error("Cannot find square root");return M}var Eu=jr(vu.p,{sqrt:E0}),v0=yh(vu,{Fp:Eu,endo:x0}),ft=xh(v0,zr);function vh(r,e,t){let n=qr.digest(e instanceof Uint8Array?e:e.subarray());if(Zr(n))return n.then(({digest:o})=>(t?.signal?.throwIfAborted(),ft.sign(o,r,{prehash:!1,format:"der"}))).catch(o=>{throw o.name==="AbortError"?o:new Gn(String(o))});try{return ft.sign(n.digest,r,{prehash:!1,format:"der"})}catch(o){throw new Gn(String(o))}}function Sh(r,e,t,n){let o=qr.digest(t instanceof Uint8Array?t:t.subarray());if(Zr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),ft.verify(e,s,r,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new jn(String(s))});try{return n?.signal?.throwIfAborted(),ft.verify(e,o.digest,r,{prehash:!1,format:"der"})}catch(s){throw new jn(String(s))}}var oo=class{type="secp256k1";raw;_key;constructor(e){this._key=Ch(e),this.raw=Ah(this._key)}toMultihash(){return at.digest(rt(this))}toCID(){return xe.createV1(114,this.toMultihash())}toString(){return ie.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Q(this.raw,e.raw)}verify(e,t,n){return Sh(this._key,t,e,n)}},Ns=class{type="secp256k1";raw;publicKey;constructor(e,t){this.raw=_h(e),this.publicKey=new oo(t??Th(e))}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Q(this.raw,e.raw)}sign(e,t){return vh(this.raw,e,t)}};function Su(r){return new oo(r)}async function Ih(){let r=S0();return new Ns(r)}function Ah(r){return ft.Point.fromBytes(r).toBytes()}function _h(r){try{return ft.getPublicKey(r,!0),r}catch(e){throw new _n(String(e))}}function Ch(r){try{return ft.Point.fromBytes(r),r}catch(e){throw new mt(String(e))}}function Th(r){try{return ft.getPublicKey(r,!0)}catch(e){throw new _n(String(e))}}function S0(){return ft.utils.randomSecretKey()}async function Lh(r,e){if(r==="Ed25519")return Qd();if(r==="secp256k1")return Ih();if(r==="RSA")return gu(A0(e));if(r==="ECDSA")return ed(_0(e));throw new Bt}function so(r,e){let{Type:t,Data:n}=wt.decode(r),o=n??new Uint8Array;switch(t){case ge.RSA:return hu(o,e);case ge.Ed25519:return $c(o);case ge.secp256k1:return Su(o);case ge.ECDSA:return gc(o);default:throw new Bt}}function Ph(r){let{Type:e,Data:t}=wt.decode(r.digest),n=t??new Uint8Array;switch(e){case ge.Ed25519:return $c(n);case ge.secp256k1:return Su(n);case ge.ECDSA:return gc(n);default:throw new Bt}}function rt(r){return wt.encode({Type:ge[r.type],Data:r.raw})}async function Dh(r,e,t){if(t?.signal?.throwIfAborted(),e!=null){let n;try{n=e instanceof Uint8Array?so(e):e}catch(o){throw new mt(`Could not decode public key - ${o.message}`)}if(!Q(n.toMultihash().bytes,r.toMultihash().bytes))throw new mt("Public key does not match peer id");return n}if(r.publicKey==null)throw new mt("No public key available for peer id");return r.publicKey}function A0(r){return r==null?2048:parseInt(r,10)}function _0(r){if(r==="P-256"||r==null)return"P-256";if(r==="P-384")return"P-384";if(r==="P-521")return"P-521";throw new T("Unsupported curve, should be P-256, P-384 or P-521")}var Rh=Symbol.for("nodejs.util.inspect.custom"),C0=114,io=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Xo]=!0;toString(){return this.string==null&&(this.string=ie.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return xe.createV1(C0,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return Q(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return Q(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[Rh](){return`PeerId(${this.toString()})`}},ao=class extends io{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},co=class extends io{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},uo=class extends io{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},T0=2336,lo=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=at.digest(I(this.url))}[Rh](){return`PeerId(${this.url})`}[Xo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return xe.createV1(T0,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=F(e)),e.toString()===this.toString())}};var I0=114,Oh=2336;function xt(r,e){let t;if(r.charAt(0)==="1"||r.charAt(0)==="Q")t=At(ie.decode(`z${r}`));else{if(r.startsWith("k51qzi5uqu5")||r.startsWith("kzwfwjn5ji4")||r.startsWith("k2k4r8")||r.startsWith("bafz"))return Au(xe.parse(r));if(e==null)throw new T('Please pass a multibase decoder for strings that do not start with "1" or "Q"');t=At(e.decode(r))}return en(t)}function fo(r){if(r.type==="Ed25519")return new co({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new uo({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new ao({multihash:r.toCID().multihash,publicKey:r});throw new Bt}function kh(r){return fo(r.publicKey)}function en(r){if(P0(r))return new ao({multihash:r});if(L0(r))try{let e=Ph(r);if(e.type==="Ed25519")return new co({multihash:r,publicKey:e});if(e.type==="secp256k1")return new uo({multihash:r,publicKey:e})}catch{let t=F(r.digest);return new lo(new URL(t))}throw new zo("Supplied PeerID Multihash is invalid")}function Au(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==I0&&r.code!==Oh)throw new $o("Supplied PeerID CID is invalid");if(r.code===Oh){let e=F(r.multihash.digest);return new lo(new URL(e))}return en(r.multihash)}function L0(r){return r.code===at.code}function P0(r){return r.code===qr.code}async function Nh(r){if(r.connectionProtector===null&&globalThis.process?.env?.LIBP2P_FORCE_PNET!=null)throw new T("Private network is enforced, but no protector was provided");return r}function Ms(r,e){if(typeof r=="string")return D0(r);if(typeof r=="number")return k0(r,e);throw new Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(r)}`)}function D0(r){if(typeof r!="string"||r.length===0||r.length>100)throw new Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(r)}`);let e=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(r);if(!e?.groups)return NaN;let{value:t,unit:n="ms"}=e.groups,o=parseFloat(t),s=n.toLowerCase();switch(s){case"years":case"year":case"yrs":case"yr":case"y":return o*315576e5;case"months":case"month":case"mo":return o*26298e5;case"weeks":case"week":case"w":return o*6048e5;case"days":case"day":case"d":return o*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return o*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return o*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return o*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return o;default:throw new Error(`Unknown unit "${s}" provided to ms.parse(). value=${JSON.stringify(r)}`)}}function R0(r){let e=Math.abs(r);return e>=315576e5?`${Math.round(r/315576e5)}y`:e>=26298e5?`${Math.round(r/26298e5)}mo`:e>=6048e5?`${Math.round(r/6048e5)}w`:e>=864e5?`${Math.round(r/864e5)}d`:e>=36e5?`${Math.round(r/36e5)}h`:e>=6e4?`${Math.round(r/6e4)}m`:e>=1e3?`${Math.round(r/1e3)}s`:`${r}ms`}function O0(r){let e=Math.abs(r);return e>=315576e5?gr(r,e,315576e5,"year"):e>=26298e5?gr(r,e,26298e5,"month"):e>=6048e5?gr(r,e,6048e5,"week"):e>=864e5?gr(r,e,864e5,"day"):e>=36e5?gr(r,e,36e5,"hour"):e>=6e4?gr(r,e,6e4,"minute"):e>=1e3?gr(r,e,1e3,"second"):`${r} ms`}function k0(r,e){if(typeof r!="number"||!Number.isFinite(r))throw new Error("Value provided to ms.format() must be of type number.");return e?.long?O0(r):R0(r)}function gr(r,e,t,n){let o=e>=t*1.5;return`${Math.round(r/t)} ${n}${o?"s":""}`}function _u(r){t.debug=t,t.default=t,t.coerce=c,t.disable=s,t.enable=o,t.enabled=i,t.humanize=Ms,t.destroy=u,Object.keys(r).forEach(l=>{t[l]=r[l]}),t.names=[],t.skips=[],t.formatters={};function e(l){let f=0;for(let d=0;d<l.length;d++)f=(f<<5)-f+l.charCodeAt(d),f|=0;return t.colors[Math.abs(f)%t.colors.length]}t.selectColor=e;function t(l,f){let d,h=null,y,p;function g(...b){if(!g.enabled)return;let S=g,w=Number(new Date),v=w-(d||w);S.diff=v,S.prev=d,S.curr=w,d=w,b[0]=t.coerce(b[0]),typeof b[0]!="string"&&b.unshift("%O");let A=0;b[0]=b[0].replace(/%([a-zA-Z%])/g,($,k)=>{if($==="%%")return"%";A++;let D=t.formatters[k];if(typeof D=="function"){let B=b[A];$=D.call(S,B),b.splice(A,1),A--}return $}),t.formatArgs.call(S,b),f?.onLog!=null&&f.onLog(...b),(S.log||t.log).apply(S,b)}return g.namespace=l,g.useColors=t.useColors(),g.color=t.selectColor(l),g.extend=n,g.destroy=t.destroy,Object.defineProperty(g,"enabled",{enumerable:!0,configurable:!1,get:()=>h!==null?h:(y!==t.namespaces&&(y=t.namespaces,p=t.enabled(l)),p),set:b=>{h=b}}),typeof t.init=="function"&&t.init(g),g}function n(l,f){let d=t(this.namespace+(typeof f>"u"?":":f)+l);return d.log=this.log,d}function o(l){t.save(l),t.namespaces=l,t.names=[],t.skips=[];let f,d=(typeof l=="string"?l:"").split(/[\s,]+/),h=d.length;for(f=0;f<h;f++)d[f]&&(l=d[f].replace(/\*/g,".*?"),l[0]==="-"?t.skips.push(new RegExp("^"+l.substr(1)+"$")):t.names.push(new RegExp("^"+l+"$")))}function s(){let l=[...t.names.map(a),...t.skips.map(a).map(f=>"-"+f)].join(",");return t.enable(""),l}function i(l){if(l[l.length-1]==="*")return!0;let f,d;for(f=0,d=t.skips.length;f<d;f++)if(t.skips[f].test(l))return!1;for(f=0,d=t.names.length;f<d;f++)if(t.names[f].test(l))return!0;return!1}function a(l){return l.toString().substring(2,l.toString().length-2).replace(/\.\*\?$/,"*")}function c(l){return l instanceof Error?l.stack??l.message:l}function u(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return t.setupFormatters(t.formatters),t.enable(t.load()),t}var Bs=q0(),N0=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function M0(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/(edge|trident)\/(\d+)/)!=null?!1:typeof document<"u"&&document.documentElement?.style?.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/firefox\/(\d+)/)!=null&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/applewebkit\/(\d+)/)}function B0(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+Ms(this.diff),!this.useColors)return;let e="color: "+this.color;r.splice(1,0,e,"color: inherit");let t=0,n=0;r[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(t++,o==="%c"&&(n=t))}),r.splice(n,0,e)}var F0=console.debug??console.log??(()=>{});function U0(r){try{r?Bs?.setItem("debug",r):Bs?.removeItem("debug")}catch{}}function K0(){let r;try{r=Bs?.getItem("debug")}catch{}return!r&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(r=globalThis.process.env.DEBUG),r}function q0(){try{return localStorage}catch{}}function $0(r){r.j=function(e){try{return JSON.stringify(e)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}}var Mh=_u({formatArgs:B0,save:U0,load:K0,useColors:M0,setupFormatters:$0,colors:N0,storage:Bs,log:F0});var We=Mh;We.formatters.b=r=>r==null?"undefined":ie.baseEncode(r);We.formatters.t=r=>r==null?"undefined":et.baseEncode(r);We.formatters.m=r=>r==null?"undefined":nc.baseEncode(r);We.formatters.p=r=>r==null?"undefined":r.toString();We.formatters.c=r=>r==null?"undefined":r.toString();We.formatters.k=r=>r==null?"undefined":r.toString();We.formatters.a=r=>r==null?"undefined":r.toString();function Bh(r,e=""){let t=Fh(r.message),n=Fh(r.stack);return t!=null&&n!=null?n.includes(t)?`${n.split(`
|
|
3
3
|
`).join(`
|
|
4
4
|
${e}`)}`:`${t}
|
|
5
5
|
${e}${n.split(`
|
|
@@ -23,7 +23,7 @@ ${[...t.errors.entries()].map(([s,i])=>`
|
|
|
23
23
|
`),t),n.trace('responded with "%s" for "%s"',s,s),o.unwrap(),s;if(s==="ls"){let i=new ne(...e.map(a=>bi.single(I(`${a}
|
|
24
24
|
`))),I(`
|
|
25
25
|
`));n.trace('respond with "%s" for %s',e,s),await o.write(i,t),n.trace('responded with "%s" for %s',e,s);continue}n.trace('respond with "na" for "%s"',s),await o.write(I(`na
|
|
26
|
-
`),t),n('responded with "na" for "%s"',s)}}var df=class extends Ne{id;remoteAddr;remotePeer;direction;timeline;direct;multiplexer;encryption;limits;log;maConn;muxer;components;outboundStreamProtocolNegotiationTimeout;inboundStreamProtocolNegotiationTimeout;closeTimeout;constructor(e,t){super(),this.components=e,this.id=t.id,this.remoteAddr=t.maConn.remoteAddr,this.remotePeer=t.remotePeer,this.direction=t.direction??"outbound",this.timeline=t.maConn.timeline,this.encryption=t.cryptoProtocol,this.limits=t.limits,this.maConn=t.maConn,this.log=t.maConn.log,this.outboundStreamProtocolNegotiationTimeout=t.outboundStreamProtocolNegotiationTimeout??1e4,this.inboundStreamProtocolNegotiationTimeout=t.inboundStreamProtocolNegotiationTimeout??1e4,this.closeTimeout=t.closeTimeout??1e3,this.direct=Kl(t.maConn.remoteAddr),this.onIncomingStream=this.onIncomingStream.bind(this),this.remoteAddr.getComponents().find(n=>n.code===421)==null&&(this.remoteAddr=this.remoteAddr.encapsulate(`/p2p/${this.remotePeer}`)),t.muxer!=null&&(this.multiplexer=t.muxer.protocol,this.muxer=t.muxer,this.muxer.addEventListener("stream",this.onIncomingStream)),this.maConn.addEventListener("close",n=>{this.dispatchEvent(new Yo(n.local,n.error))})}[Symbol.toStringTag]="Connection";[yf]=!0;get streams(){return this.muxer?.streams??[]}get status(){return this.maConn.status}newStream=async(e,t={})=>{if(this.muxer==null)throw new tr("Connection is not multiplexed");if(this.muxer.status!=="open")throw new rr(`The connection muxer is "${this.muxer.status}" and not "open"`);if(this.maConn.status!=="open")throw new rr(`The connection is "${this.status}" and not "open"`);if(this.limits!=null&&t?.runOnLimitedConnection!==!0)throw new Cn("Cannot open protocol stream on limited connection");Array.isArray(e)||(e=[e]),t.onProgress?.(new se("connection:open-stream",{connection:this,protocols:e})),this.log.trace("starting new stream for protocols %s",e);let n=await this.muxer.createStream({...t,protocol:e.length===1?e[0]:void 0});this.log.trace("started new stream %s for protocols %s",n.id,e);try{if(t.signal==null){n.log("no abort signal was passed while trying to negotiate protocols %s falling back to default timeout",e);let c=AbortSignal.timeout(this.outboundStreamProtocolNegotiationTimeout);t={...t,signal:c}}n.protocol===""?(n.log.trace("selecting protocol from protocols %s",e),n.protocol=await vn(n,e,t),n.log("negotiated protocol %s",n.protocol)):n.log("pre-negotiated protocol %s",n.protocol);let o=ux(n.protocol,this.components.registrar,t),s=Sm(n.protocol,"outbound",this);if(s>o){let c=new jo(`Too many outbound protocol streams for protocol "${n.protocol}" - ${s}/${o}`);throw n.abort(c),c}await this.components.peerStore.merge(this.remotePeer,{protocols:[n.protocol]}),this.components.metrics?.trackProtocolStream(n);let i=this.components.registrar.getMiddleware(n.protocol),a=await this.runMiddlewareChain(n,this,i);return t.onProgress?.(new se("connection:opened-stream",{connection:this,stream:a})),a}catch(o){throw n.status==="open"?n.abort(o):this.log.error("could not create new outbound stream on connection %s %a for protocols %s - %e",this.direction==="inbound"?"from":"to",this.remoteAddr,e,o),o}};async onIncomingStream(e){let t=e.detail,n=AbortSignal.timeout(this.inboundStreamProtocolNegotiationTimeout);t.log("start protocol negotiation, timing out after %dms",this.inboundStreamProtocolNegotiationTimeout);try{if(t.protocol===""){let u=this.components.registrar.getProtocols();t.log.trace("selecting protocol from protocols %s",u),t.protocol=await Sn(t,u,{signal:n}),t.log("negotiated protocol %s",t.protocol)}else t.log("pre-negotiated protocol %s",t.protocol);let o=cx(t.protocol,this.components.registrar);if(Sm(t.protocol,"inbound",this)>o)throw new Go(`Too many inbound protocol streams for protocol "${t.protocol}" - limit ${o}`);await this.components.peerStore.merge(this.remotePeer,{protocols:[t.protocol]},{signal:n}),this.components.metrics?.trackProtocolStream(t);let{handler:i,options:a}=this.components.registrar.getHandler(t.protocol);if(this.limits!=null&&a.runOnLimitedConnection!==!0)throw new Cn("Cannot open protocol stream on limited connection");let c=this.components.registrar.getMiddleware(t.protocol);c.push(async(u,l,f)=>{await i(u,l),f(u,l)}),await this.runMiddlewareChain(t,this,c)}catch(o){t.abort(o)}}async runMiddlewareChain(e,t,n){for(let o=0;o<n.length;o++){let s=n[o];e.log.trace("running middleware",o,s),await new Promise((i,a)=>{try{let c=s(e,t,(u,l)=>{e=u,t=l,i()});c instanceof Promise&&c.catch(a)}catch(c){a(c)}}),e.log.trace("ran middleware",o,s)}return e}async close(e={}){if(this.log("closing connection to %a",this.remoteAddr),e.signal==null){let t=AbortSignal.timeout(this.closeTimeout);e={...e,signal:t}}await this.muxer?.close(e),await this.maConn.close(e)}abort(e){this.muxer?.abort(e),this.maConn.abort(e)}};function Am(r,e){return new df(r,e)}function cx(r,e){try{let{options:t}=e.getHandler(r);if(t.maxInboundStreams!=null)return t.maxInboundStreams}catch(t){if(t.name!=="UnhandledProtocolError")throw t}return uf}function ux(r,e,t={}){try{let{options:n}=e.getHandler(r);if(n.maxOutboundStreams!=null)return n.maxOutboundStreams}catch(n){if(n.name!=="UnhandledProtocolError")throw n}return t.maxOutboundStreams??lf}function Sm(r,e,t){let n=0;return t.streams.forEach(o=>{o.direction===e&&o.protocol===r&&n++}),n}var Ra=class{components;connectionEncrypters;streamMuxers;inboundUpgradeTimeout;inboundStreamProtocolNegotiationTimeout;outboundStreamProtocolNegotiationTimeout;events;metrics;connectionCloseTimeout;constructor(e,t){this.components=e,this.connectionEncrypters=Oe({name:"libp2p_upgrader_connection_encrypters",metrics:this.components.metrics}),t.connectionEncrypters.forEach(n=>{this.connectionEncrypters.set(n.protocol,n)}),this.streamMuxers=Oe({name:"libp2p_upgrader_stream_multiplexers",metrics:this.components.metrics}),t.streamMuxers.forEach(n=>{this.streamMuxers.set(n.protocol,n)}),this.inboundUpgradeTimeout=t.inboundUpgradeTimeout??1e4,this.inboundStreamProtocolNegotiationTimeout=t.inboundStreamProtocolNegotiationTimeout??1e4,this.outboundStreamProtocolNegotiationTimeout=t.outboundStreamProtocolNegotiationTimeout??1e4,this.connectionCloseTimeout=t.connectionCloseTimeout??1e3,this.events=e.events,this.metrics={dials:e.metrics?.registerCounterGroup("libp2p_connection_manager_dials_total"),errors:e.metrics?.registerCounterGroup("libp2p_connection_manager_dial_errors_total"),inboundErrors:e.metrics?.registerCounterGroup("libp2p_connection_manager_dials_inbound_errors_total"),outboundErrors:e.metrics?.registerCounterGroup("libp2p_connection_manager_dials_outbound_errors_total")}}[Symbol.toStringTag]="@libp2p/upgrader";async shouldBlockConnection(e,...t){let n=this.components.connectionGater[e];if(n==null)return;if(await n.apply(this.components.connectionGater,t)===!0)throw new ia(`The multiaddr connection is blocked by gater.${e}`)}createInboundAbortSignal(e){let t=Et([AbortSignal.timeout(this.inboundUpgradeTimeout),e]);return t}async upgradeInbound(e,t){let n=!1,o=this.createInboundAbortSignal(t.signal);try{if(this.metrics.dials?.increment({inbound:!0}),n=this.components.connectionManager.acceptIncomingConnection(e),!n)throw new aa("Connection denied");await je(this.shouldBlockConnection("denyInboundConnection",e),o),await this._performUpgrade(e,"inbound",{...t,signal:o})}catch(s){throw this.metrics.errors?.increment({inbound:!0}),this.metrics.inboundErrors?.increment({[s.name??"Error"]:!0}),s}finally{o.clear(),n&&this.components.connectionManager.afterUpgradeInbound()}}async upgradeOutbound(e,t){try{this.metrics.dials?.increment({outbound:!0});let n=e.remoteAddr.getComponents().findLast(i=>i.code===421)?.value,o;n!=null&&(o=xt(n),await je(this.shouldBlockConnection("denyOutboundConnection",o,e),t.signal));let s="outbound";return t.initiator===!1&&(s="inbound"),await this._performUpgrade(e,s,t)}catch(n){throw this.metrics.errors?.increment({outbound:!0}),this.metrics.outboundErrors?.increment({[n.name??"Error"]:!0}),n}}async _performUpgrade(e,t,n){let o=e,s,i,a,c,u=`${parseInt(String(Math.random()*1e9)).toString(36)}${Date.now()}`;if(e.log=e.log.newScope(`${t}:${u}`),this.components.metrics?.trackMultiaddrConnection(e),e.log.trace("starting the %s connection upgrade",t),n?.skipProtection!==!0){let f=this.components.connectionProtector;f!=null&&(e.log("protecting the %s connection",t),o=await f.protect(o,n))}try{if(lx(n)){if(n.remotePeer==null)throw new Mt(`${t} connection that skipped encryption must have a peer id`);c="native",s=n.remotePeer}else{let f=e.remoteAddr.getComponents().findLast(h=>h.code===421)?.value,d;if(f!=null&&(d=xt(f)),n?.onProgress?.(new se(`upgrader:encrypt-${t}-connection`)),{connection:o,remotePeer:s,protocol:c,streamMuxer:i}=await(t==="inbound"?this._encryptInbound(o,{...n,remotePeer:d}):this._encryptOutbound(o,{...n,remotePeer:d})),d!=null&&!d.equals(s)){let h=new Ko(`Expected remote peer ${d} but connected to ${s}`);throw e.abort(h),h}}if(s.equals(this.components.peerId)){let f=new Nr("Can not dial self");throw e.abort(f),f}await this.shouldBlockConnection(t==="inbound"?"denyInboundEncryptedConnection":"denyOutboundEncryptedConnection",s,e),n?.muxerFactory!=null?i=n.muxerFactory:i==null&&this.streamMuxers.size>0&&(n?.onProgress?.(new se(`upgrader:multiplex-${t}-connection`)),i=await(t==="inbound"?this._multiplexInbound(o,this.streamMuxers,n):this._multiplexOutbound(o,this.streamMuxers,n)))}catch(f){throw e.log.error("failed to upgrade %s connection %s %a - %e",t,t==="inbound"?"from":"to",e.remoteAddr,f),f}i!=null&&(e.log("create muxer %s",i.protocol),a=i.createStreamMuxer(o)),await this.shouldBlockConnection(t==="inbound"?"denyInboundUpgradedConnection":"denyOutboundUpgradedConnection",s,e);let l=this._createConnection({id:u,cryptoProtocol:c,direction:t,maConn:e,stream:o,muxer:a,remotePeer:s,limits:n?.limits,closeTimeout:this.connectionCloseTimeout});return l.log("successfully upgraded connection"),l}_createConnection(e){let t=Am(this.components,{...e,outboundStreamProtocolNegotiationTimeout:this.outboundStreamProtocolNegotiationTimeout,inboundStreamProtocolNegotiationTimeout:this.inboundStreamProtocolNegotiationTimeout});return t.addEventListener("close",()=>{this.events.safeDispatchEvent("connection:close",{detail:t})}),this.events.safeDispatchEvent("connection:open",{detail:t}),t}async _encryptInbound(e,t){let n=Array.from(this.connectionEncrypters.keys());try{let o=await Sn(e,n,t),s=this.connectionEncrypters.get(o);if(s==null)throw new Or(`no crypto module found for ${o}`);return e.log("encrypting inbound connection using %s",o),{...await s.secureInbound(e,t),protocol:o}}catch(o){throw new Or(o.message)}}async _encryptOutbound(e,t){let n=Array.from(this.connectionEncrypters.keys());try{e.log.trace("selecting encrypter from %s",n);let o=await vn(e,n,t),s=this.connectionEncrypters.get(o);if(s==null)throw new Or(`no crypto module found for ${o}`);return e.log("encrypting outbound connection using %s",o),{...await s.secureOutbound(e,t),protocol:o}}catch(o){throw new Or(o.message)}}async _multiplexOutbound(e,t,n){let o=Array.from(t.keys());e.log("outbound selecting muxer %s",o);try{e.log.trace("selecting stream muxer from %s",o);let s=await vn(e,o,n),i=t.get(s);if(i==null)throw new tr(`No muxer configured for protocol "${s}"`);return e.log("selected %s as muxer protocol",s),i}catch(s){throw e.log.error("error multiplexing outbound connection - %e",s),new tr(String(s))}}async _multiplexInbound(e,t,n){let o=Array.from(t.keys());e.log("inbound handling muxers %s",o);try{e.log.trace("selecting stream muxer from %s",o);let s=await Sn(e,o,n),i=t.get(s);if(i==null)throw new tr(`No muxer configured for protocol "${s}"`);return e.log("selected %s as muxer protocol",s),i}catch(s){throw e.log.error("error multiplexing inbound connection - %e",s),s}}getConnectionEncrypters(){return this.connectionEncrypters}getStreamMuxers(){return this.streamMuxers}};function lx(r){return r.skipEncryption===!0}var Oa="3.5.1-ff95dc546",ka="js-libp2p";function Cm(r,e){return`${r??ka}/${e??Oa} browser/${globalThis.navigator.userAgent}`}var Fo=class extends Ne{peerId;peerStore;contentRouting;peerRouting;metrics;services;logger;status;components;log;constructor(e){super(),this.status="stopped";let t=new Ne,n=t.dispatchEvent.bind(t);t.dispatchEvent=u=>{let l=n(u),f=this.dispatchEvent(new CustomEvent(u.type,{detail:u.detail}));return l||f},this.peerId=e.peerId,this.logger=e.logger??Fs(),this.log=this.logger.forComponent("libp2p"),this.services={};let o=e.nodeInfo?.name??ka,s=e.nodeInfo?.version??Oa,i=this.components=tm({peerId:e.peerId,privateKey:e.privateKey,nodeInfo:{name:o,version:s,userAgent:e.nodeInfo?.userAgent??Cm(o,s)},logger:this.logger,events:t,datastore:e.datastore??new Wi,connectionGater:nm(e.connectionGater),dns:e.dns});e.metrics!=null&&(this.metrics=this.configureComponent("metrics",e.metrics(this.components))),this.peerStore=this.configureComponent("peerStore",Yp(i,{addressFilter:this.components.connectionGater.filterMultiaddrForPeer,...e.peerStore})),i.events.addEventListener("peer:update",u=>{if(u.detail.previous==null){let l={id:u.detail.peer.id,multiaddrs:u.detail.peer.addresses.map(f=>f.multiaddr)};i.events.safeDispatchEvent("peer:discovery",{detail:l})}}),e.connectionProtector!=null&&this.configureComponent("connectionProtector",e.connectionProtector(i)),this.components.upgrader=new Ra(this.components,{connectionEncrypters:(e.connectionEncrypters??[]).map((u,l)=>this.configureComponent(`connection-encryption-${l}`,u(this.components))),streamMuxers:(e.streamMuxers??[]).map((u,l)=>this.configureComponent(`stream-muxers-${l}`,u(this.components))),inboundUpgradeTimeout:e.connectionManager?.inboundUpgradeTimeout,inboundStreamProtocolNegotiationTimeout:e.connectionManager?.inboundStreamProtocolNegotiationTimeout,outboundStreamProtocolNegotiationTimeout:e.connectionManager?.outboundStreamProtocolNegotiationTimeout,connectionCloseTimeout:e.connectionManager?.connectionCloseTimeout}),this.configureComponent("transportManager",new Da(this.components,e.transportManager)),this.configureComponent("connectionManager",new Aa(this.components,e.connectionManager)),e.connectionMonitor?.enabled!==!1&&this.configureComponent("connectionMonitor",new _a(this.components,e.connectionMonitor)),this.configureComponent("registrar",new Pa(this.components)),this.configureComponent("addressManager",new Zi(this.components,e.addresses));let a=(e.peerRouters??[]).map((u,l)=>this.configureComponent(`peer-router-${l}`,u(this.components)));this.peerRouting=this.components.peerRouting=this.configureComponent("peerRouting",new Ia(this.components,{routers:a}));let c=(e.contentRouters??[]).map((u,l)=>this.configureComponent(`content-router-${l}`,u(this.components)));if(this.contentRouting=this.components.contentRouting=this.configureComponent("contentRouting",new Ca(this.components,{routers:c})),this.configureComponent("randomWalk",new La(this.components)),(e.peerDiscovery??[]).forEach((u,l)=>{this.configureComponent(`peer-discovery-${l}`,u(this.components)).addEventListener("peer",d=>{this.#e(d)})}),e.transports?.forEach((u,l)=>{this.components.transportManager.add(this.configureComponent(`transport-${l}`,u(this.components)))}),e.services!=null)for(let u of Object.keys(e.services)){let l=e.services[u],f=l(this.components);if(f==null){this.log.error("service factory %s returned null or undefined instance",u);continue}this.services[u]=f,this.configureComponent(u,f),f[Ma]!=null&&(this.log("registering service %s for content routing",u),c.push(f[Ma])),f[Fa]!=null&&(this.log("registering service %s for peer routing",u),a.push(f[Fa])),f[Ba]!=null&&(this.log("registering service %s for peer discovery",u),f[Ba].addEventListener?.("peer",d=>{this.#e(d)}))}rm(i)}configureComponent(e,t){return t==null&&this.log.error("component %s was null or undefined",e),this.components[e]=t,t}async start(){if(this.status==="stopped"){this.status="starting",this.log("libp2p is starting");try{await this.components.beforeStart?.(),await this.components.start(),await this.components.afterStart?.(),this.status="started",this.safeDispatchEvent("start",{detail:this}),this.log("libp2p has started with peer id %p",this.peerId)}catch(e){throw this.log.error("an error occurred starting libp2p - %e",e),this.status="started",await this.stop(),e}}}async stop(){this.status==="started"&&(this.log("libp2p is stopping"),this.status="stopping",await this.components.beforeStop?.(),await this.components.stop(),await this.components.afterStop?.(),this.status="stopped",this.safeDispatchEvent("stop",{detail:this}),this.log("libp2p has stopped"))}getConnections(e){return this.components.connectionManager.getConnections(e)}getDialQueue(){return this.components.connectionManager.getDialQueue()}getPeers(){let e=new br;for(let t of this.components.connectionManager.getConnections())e.add(t.remotePeer);return Array.from(e)}async dial(e,t={}){return this.components.connectionManager.openConnection(e,{priority:75,...t})}async dialProtocol(e,t,n={}){if(t==null)throw new T("no protocols were provided to open a stream");if(t=Array.isArray(t)?t:[t],t.length===0)throw new T("no protocols were provided to open a stream");return this.components.connectionManager.openStream(e,t,n)}getMultiaddrs(){return this.components.addressManager.getAddresses()}getProtocols(){return this.components.registrar.getProtocols()}async hangUp(e,t={}){er(e)&&(e=xt(e.getComponents().findLast(n=>n.code===421)?.value??"")),await this.components.connectionManager.closeConnections(e,t)}async getPublicKey(e,t={}){if(this.log("getPublicKey %p",e),e.publicKey!=null)return e.publicKey;try{let i=await this.peerStore.get(e,t);if(i.id.publicKey!=null)return i.id.publicKey}catch(i){if(i.name!=="NotFoundError")throw i}let n=tt([I("/pk/"),e.toMultihash().bytes]),o=await this.contentRouting.get(n,t),s=await Dh(e,o,t);return await this.peerStore.patch(e,{publicKey:s},t),s}async handle(e,t,n){Array.isArray(e)||(e=[e]),await Promise.all(e.map(async o=>{await this.components.registrar.handle(o,t,n)}))}async unhandle(e,t){Array.isArray(e)||(e=[e]),await Promise.all(e.map(async n=>{await this.components.registrar.unhandle(n,t)}))}async register(e,t,n){return this.components.registrar.register(e,t,n)}unregister(e){this.components.registrar.unregister(e)}use(e,t){if(typeof e=="function"){this.components.registrar.use(e);return}if(t==null)throw new T("Protocol middleware is required");this.components.registrar.use(e,Array.isArray(t)?t:[t])}unuse(e){if(typeof e=="function"){this.components.registrar.unuse(e);return}this.components.registrar.unuse(e)}async isDialable(e,t={}){return this.components.connectionManager.isDialable(e,t)}#e(e){let{detail:t}=e;if(t.id.toString()===this.peerId.toString()){this.log.error("peer discovery mechanism discovered self");return}this.components.peerStore.merge(t.id,{multiaddrs:t.multiaddrs}).catch(n=>{this.log.error("could not update multiaddrs of discovered peer - %e",n)})}};async function fx(r={}){r.privateKey??=await Lh("Ed25519");let e=new Fo({...await Nh(r),peerId:kh(r.privateKey)});return r.start!==!1&&await e.start(),e}var dx=["dial","dialProtocol","hangUp","handle","unhandle","getMultiaddrs","getProtocols"];function hx(r){return r==null?!1:r instanceof Fo?!0:dx.every(e=>typeof r[e]=="function")}return Nm(px);})();
|
|
26
|
+
`),t),n('responded with "na" for "%s"',s)}}var df=class extends Ne{id;remoteAddr;remotePeer;direction;timeline;direct;multiplexer;encryption;limits;log;maConn;muxer;components;outboundStreamProtocolNegotiationTimeout;inboundStreamProtocolNegotiationTimeout;closeTimeout;constructor(e,t){super(),this.components=e,this.id=t.id,this.remoteAddr=t.maConn.remoteAddr,this.remotePeer=t.remotePeer,this.direction=t.direction??"outbound",this.timeline=t.maConn.timeline,this.encryption=t.cryptoProtocol,this.limits=t.limits,this.maConn=t.maConn,this.log=t.maConn.log,this.outboundStreamProtocolNegotiationTimeout=t.outboundStreamProtocolNegotiationTimeout??1e4,this.inboundStreamProtocolNegotiationTimeout=t.inboundStreamProtocolNegotiationTimeout??1e4,this.closeTimeout=t.closeTimeout??1e3,this.direct=Kl(t.maConn.remoteAddr),this.onIncomingStream=this.onIncomingStream.bind(this),this.remoteAddr.getComponents().find(n=>n.code===421)==null&&(this.remoteAddr=this.remoteAddr.encapsulate(`/p2p/${this.remotePeer}`)),t.muxer!=null&&(this.multiplexer=t.muxer.protocol,this.muxer=t.muxer,this.muxer.addEventListener("stream",this.onIncomingStream)),this.maConn.addEventListener("close",n=>{this.dispatchEvent(new Yo(n.local,n.error))})}[Symbol.toStringTag]="Connection";[yf]=!0;get streams(){return this.muxer?.streams??[]}get status(){return this.maConn.status}newStream=async(e,t={})=>{if(this.muxer==null)throw new tr("Connection is not multiplexed");if(this.muxer.status!=="open")throw new rr(`The connection muxer is "${this.muxer.status}" and not "open"`);if(this.maConn.status!=="open")throw new rr(`The connection is "${this.status}" and not "open"`);if(this.limits!=null&&t?.runOnLimitedConnection!==!0)throw new Cn("Cannot open protocol stream on limited connection");Array.isArray(e)||(e=[e]),t.onProgress?.(new se("connection:open-stream",{connection:this,protocols:e})),this.log.trace("starting new stream for protocols %s",e);let n=await this.muxer.createStream({...t,protocol:e.length===1?e[0]:void 0});this.log.trace("started new stream %s for protocols %s",n.id,e);try{if(t.signal==null){n.log("no abort signal was passed while trying to negotiate protocols %s falling back to default timeout",e);let c=AbortSignal.timeout(this.outboundStreamProtocolNegotiationTimeout);t={...t,signal:c}}n.protocol===""?(n.log.trace("selecting protocol from protocols %s",e),n.protocol=await vn(n,e,t),n.log("negotiated protocol %s",n.protocol)):n.log("pre-negotiated protocol %s",n.protocol);let o=ux(n.protocol,this.components.registrar,t),s=Sm(n.protocol,"outbound",this);if(s>o){let c=new jo(`Too many outbound protocol streams for protocol "${n.protocol}" - ${s}/${o}`);throw n.abort(c),c}await this.components.peerStore.merge(this.remotePeer,{protocols:[n.protocol]}),this.components.metrics?.trackProtocolStream(n);let i=this.components.registrar.getMiddleware(n.protocol),a=await this.runMiddlewareChain(n,this,i);return t.onProgress?.(new se("connection:opened-stream",{connection:this,stream:a})),a}catch(o){throw n.status==="open"?n.abort(o):this.log.error("could not create new outbound stream on connection %s %a for protocols %s - %e",this.direction==="inbound"?"from":"to",this.remoteAddr,e,o),o}};async onIncomingStream(e){let t=e.detail,n=AbortSignal.timeout(this.inboundStreamProtocolNegotiationTimeout);t.log("start protocol negotiation, timing out after %dms",this.inboundStreamProtocolNegotiationTimeout);try{if(t.protocol===""){let u=this.components.registrar.getProtocols();t.log.trace("selecting protocol from protocols %s",u),t.protocol=await Sn(t,u,{signal:n}),t.log("negotiated protocol %s",t.protocol)}else t.log("pre-negotiated protocol %s",t.protocol);let o=cx(t.protocol,this.components.registrar);if(Sm(t.protocol,"inbound",this)>o)throw new Go(`Too many inbound protocol streams for protocol "${t.protocol}" - limit ${o}`);await this.components.peerStore.merge(this.remotePeer,{protocols:[t.protocol]},{signal:n}),this.components.metrics?.trackProtocolStream(t);let{handler:i,options:a}=this.components.registrar.getHandler(t.protocol);if(this.limits!=null&&a.runOnLimitedConnection!==!0)throw new Cn("Cannot open protocol stream on limited connection");let c=this.components.registrar.getMiddleware(t.protocol);c.push(async(u,l,f)=>{await i(u,l),f(u,l)}),await this.runMiddlewareChain(t,this,c)}catch(o){t.abort(o)}}async runMiddlewareChain(e,t,n){for(let o=0;o<n.length;o++){let s=n[o];e.log.trace("running middleware",o,s),await new Promise((i,a)=>{try{let c=s(e,t,(u,l)=>{e=u,t=l,i()});c instanceof Promise&&c.catch(a)}catch(c){a(c)}}),e.log.trace("ran middleware",o,s)}return e}async close(e={}){if(this.log("closing connection to %a",this.remoteAddr),e.signal==null){let t=AbortSignal.timeout(this.closeTimeout);e={...e,signal:t}}await this.muxer?.close(e),await this.maConn.close(e)}abort(e){this.muxer?.abort(e),this.maConn.abort(e)}};function Am(r,e){return new df(r,e)}function cx(r,e){try{let{options:t}=e.getHandler(r);if(t.maxInboundStreams!=null)return t.maxInboundStreams}catch(t){if(t.name!=="UnhandledProtocolError")throw t}return uf}function ux(r,e,t={}){try{let{options:n}=e.getHandler(r);if(n.maxOutboundStreams!=null)return n.maxOutboundStreams}catch(n){if(n.name!=="UnhandledProtocolError")throw n}return t.maxOutboundStreams??lf}function Sm(r,e,t){let n=0;return t.streams.forEach(o=>{o.direction===e&&o.protocol===r&&n++}),n}var Ra=class{components;connectionEncrypters;streamMuxers;inboundUpgradeTimeout;inboundStreamProtocolNegotiationTimeout;outboundStreamProtocolNegotiationTimeout;events;metrics;connectionCloseTimeout;constructor(e,t){this.components=e,this.connectionEncrypters=Oe({name:"libp2p_upgrader_connection_encrypters",metrics:this.components.metrics}),t.connectionEncrypters.forEach(n=>{this.connectionEncrypters.set(n.protocol,n)}),this.streamMuxers=Oe({name:"libp2p_upgrader_stream_multiplexers",metrics:this.components.metrics}),t.streamMuxers.forEach(n=>{this.streamMuxers.set(n.protocol,n)}),this.inboundUpgradeTimeout=t.inboundUpgradeTimeout??1e4,this.inboundStreamProtocolNegotiationTimeout=t.inboundStreamProtocolNegotiationTimeout??1e4,this.outboundStreamProtocolNegotiationTimeout=t.outboundStreamProtocolNegotiationTimeout??1e4,this.connectionCloseTimeout=t.connectionCloseTimeout??1e3,this.events=e.events,this.metrics={dials:e.metrics?.registerCounterGroup("libp2p_connection_manager_dials_total"),errors:e.metrics?.registerCounterGroup("libp2p_connection_manager_dial_errors_total"),inboundErrors:e.metrics?.registerCounterGroup("libp2p_connection_manager_dials_inbound_errors_total"),outboundErrors:e.metrics?.registerCounterGroup("libp2p_connection_manager_dials_outbound_errors_total")}}[Symbol.toStringTag]="@libp2p/upgrader";async shouldBlockConnection(e,...t){let n=this.components.connectionGater[e];if(n==null)return;if(await n.apply(this.components.connectionGater,t)===!0)throw new ia(`The multiaddr connection is blocked by gater.${e}`)}createInboundAbortSignal(e){let t=Et([AbortSignal.timeout(this.inboundUpgradeTimeout),e]);return t}async upgradeInbound(e,t){let n=!1,o=this.createInboundAbortSignal(t.signal);try{if(this.metrics.dials?.increment({inbound:!0}),n=this.components.connectionManager.acceptIncomingConnection(e),!n)throw new aa("Connection denied");await je(this.shouldBlockConnection("denyInboundConnection",e),o),await this._performUpgrade(e,"inbound",{...t,signal:o})}catch(s){throw this.metrics.errors?.increment({inbound:!0}),this.metrics.inboundErrors?.increment({[s.name??"Error"]:!0}),s}finally{o.clear(),n&&this.components.connectionManager.afterUpgradeInbound()}}async upgradeOutbound(e,t){try{this.metrics.dials?.increment({outbound:!0});let n=e.remoteAddr.getComponents().findLast(i=>i.code===421)?.value,o;n!=null&&(o=xt(n),await je(this.shouldBlockConnection("denyOutboundConnection",o,e),t.signal));let s="outbound";return t.initiator===!1&&(s="inbound"),await this._performUpgrade(e,s,t)}catch(n){throw this.metrics.errors?.increment({outbound:!0}),this.metrics.outboundErrors?.increment({[n.name??"Error"]:!0}),n}}async _performUpgrade(e,t,n){let o=e,s,i,a,c,u=`${parseInt(String(Math.random()*1e9)).toString(36)}${Date.now()}`;if(e.log=e.log.newScope(`${t}:${u}`),this.components.metrics?.trackMultiaddrConnection(e),e.log.trace("starting the %s connection upgrade",t),n?.skipProtection!==!0){let f=this.components.connectionProtector;f!=null&&(e.log("protecting the %s connection",t),o=await f.protect(o,n))}try{if(lx(n)){if(n.remotePeer==null)throw new Mt(`${t} connection that skipped encryption must have a peer id`);c="native",s=n.remotePeer}else{let f=e.remoteAddr.getComponents().findLast(h=>h.code===421)?.value,d;if(f!=null&&(d=xt(f)),n?.onProgress?.(new se(`upgrader:encrypt-${t}-connection`)),{connection:o,remotePeer:s,protocol:c,streamMuxer:i}=await(t==="inbound"?this._encryptInbound(o,{...n,remotePeer:d}):this._encryptOutbound(o,{...n,remotePeer:d})),d!=null&&!d.equals(s)){let h=new Ko(`Expected remote peer ${d} but connected to ${s}`);throw e.abort(h),h}}if(s.equals(this.components.peerId)){let f=new Nr("Can not dial self");throw e.abort(f),f}await this.shouldBlockConnection(t==="inbound"?"denyInboundEncryptedConnection":"denyOutboundEncryptedConnection",s,e),n?.muxerFactory!=null?i=n.muxerFactory:i==null&&this.streamMuxers.size>0&&(n?.onProgress?.(new se(`upgrader:multiplex-${t}-connection`)),i=await(t==="inbound"?this._multiplexInbound(o,this.streamMuxers,n):this._multiplexOutbound(o,this.streamMuxers,n)))}catch(f){throw e.log.error("failed to upgrade %s connection %s %a - %e",t,t==="inbound"?"from":"to",e.remoteAddr,f),f}i!=null&&(e.log("create muxer %s",i.protocol),a=i.createStreamMuxer(o)),await this.shouldBlockConnection(t==="inbound"?"denyInboundUpgradedConnection":"denyOutboundUpgradedConnection",s,e);let l=this._createConnection({id:u,cryptoProtocol:c,direction:t,maConn:e,stream:o,muxer:a,remotePeer:s,limits:n?.limits,closeTimeout:this.connectionCloseTimeout});return l.log("successfully upgraded connection"),l}_createConnection(e){let t=Am(this.components,{...e,outboundStreamProtocolNegotiationTimeout:this.outboundStreamProtocolNegotiationTimeout,inboundStreamProtocolNegotiationTimeout:this.inboundStreamProtocolNegotiationTimeout});return t.addEventListener("close",()=>{this.events.safeDispatchEvent("connection:close",{detail:t})}),this.events.safeDispatchEvent("connection:open",{detail:t}),t}async _encryptInbound(e,t){let n=Array.from(this.connectionEncrypters.keys());try{let o=await Sn(e,n,t),s=this.connectionEncrypters.get(o);if(s==null)throw new Or(`no crypto module found for ${o}`);return e.log("encrypting inbound connection using %s",o),{...await s.secureInbound(e,t),protocol:o}}catch(o){throw new Or(o.message)}}async _encryptOutbound(e,t){let n=Array.from(this.connectionEncrypters.keys());try{e.log.trace("selecting encrypter from %s",n);let o=await vn(e,n,t),s=this.connectionEncrypters.get(o);if(s==null)throw new Or(`no crypto module found for ${o}`);return e.log("encrypting outbound connection using %s",o),{...await s.secureOutbound(e,t),protocol:o}}catch(o){throw new Or(o.message)}}async _multiplexOutbound(e,t,n){let o=Array.from(t.keys());e.log("outbound selecting muxer %s",o);try{e.log.trace("selecting stream muxer from %s",o);let s=await vn(e,o,n),i=t.get(s);if(i==null)throw new tr(`No muxer configured for protocol "${s}"`);return e.log("selected %s as muxer protocol",s),i}catch(s){throw e.log.error("error multiplexing outbound connection - %e",s),new tr(String(s))}}async _multiplexInbound(e,t,n){let o=Array.from(t.keys());e.log("inbound handling muxers %s",o);try{e.log.trace("selecting stream muxer from %s",o);let s=await Sn(e,o,n),i=t.get(s);if(i==null)throw new tr(`No muxer configured for protocol "${s}"`);return e.log("selected %s as muxer protocol",s),i}catch(s){throw e.log.error("error multiplexing inbound connection - %e",s),s}}getConnectionEncrypters(){return this.connectionEncrypters}getStreamMuxers(){return this.streamMuxers}};function lx(r){return r.skipEncryption===!0}var Oa="3.5.2-67732803f",ka="js-libp2p";function Cm(r,e){return`${r??ka}/${e??Oa} browser/${globalThis.navigator.userAgent}`}var Fo=class extends Ne{peerId;peerStore;contentRouting;peerRouting;metrics;services;logger;status;components;log;constructor(e){super(),this.status="stopped";let t=new Ne,n=t.dispatchEvent.bind(t);t.dispatchEvent=u=>{let l=n(u),f=this.dispatchEvent(new CustomEvent(u.type,{detail:u.detail}));return l||f},this.peerId=e.peerId,this.logger=e.logger??Fs(),this.log=this.logger.forComponent("libp2p"),this.services={};let o=e.nodeInfo?.name??ka,s=e.nodeInfo?.version??Oa,i=this.components=tm({peerId:e.peerId,privateKey:e.privateKey,nodeInfo:{name:o,version:s,userAgent:e.nodeInfo?.userAgent??Cm(o,s)},logger:this.logger,events:t,datastore:e.datastore??new Wi,connectionGater:nm(e.connectionGater),dns:e.dns});e.metrics!=null&&(this.metrics=this.configureComponent("metrics",e.metrics(this.components))),this.peerStore=this.configureComponent("peerStore",Yp(i,{addressFilter:this.components.connectionGater.filterMultiaddrForPeer,...e.peerStore})),i.events.addEventListener("peer:update",u=>{if(u.detail.previous==null){let l={id:u.detail.peer.id,multiaddrs:u.detail.peer.addresses.map(f=>f.multiaddr)};i.events.safeDispatchEvent("peer:discovery",{detail:l})}}),e.connectionProtector!=null&&this.configureComponent("connectionProtector",e.connectionProtector(i)),this.components.upgrader=new Ra(this.components,{connectionEncrypters:(e.connectionEncrypters??[]).map((u,l)=>this.configureComponent(`connection-encryption-${l}`,u(this.components))),streamMuxers:(e.streamMuxers??[]).map((u,l)=>this.configureComponent(`stream-muxers-${l}`,u(this.components))),inboundUpgradeTimeout:e.connectionManager?.inboundUpgradeTimeout,inboundStreamProtocolNegotiationTimeout:e.connectionManager?.inboundStreamProtocolNegotiationTimeout,outboundStreamProtocolNegotiationTimeout:e.connectionManager?.outboundStreamProtocolNegotiationTimeout,connectionCloseTimeout:e.connectionManager?.connectionCloseTimeout}),this.configureComponent("transportManager",new Da(this.components,e.transportManager)),this.configureComponent("connectionManager",new Aa(this.components,e.connectionManager)),e.connectionMonitor?.enabled!==!1&&this.configureComponent("connectionMonitor",new _a(this.components,e.connectionMonitor)),this.configureComponent("registrar",new Pa(this.components)),this.configureComponent("addressManager",new Zi(this.components,e.addresses));let a=(e.peerRouters??[]).map((u,l)=>this.configureComponent(`peer-router-${l}`,u(this.components)));this.peerRouting=this.components.peerRouting=this.configureComponent("peerRouting",new Ia(this.components,{routers:a}));let c=(e.contentRouters??[]).map((u,l)=>this.configureComponent(`content-router-${l}`,u(this.components)));if(this.contentRouting=this.components.contentRouting=this.configureComponent("contentRouting",new Ca(this.components,{routers:c})),this.configureComponent("randomWalk",new La(this.components)),(e.peerDiscovery??[]).forEach((u,l)=>{this.configureComponent(`peer-discovery-${l}`,u(this.components)).addEventListener("peer",d=>{this.#e(d)})}),e.transports?.forEach((u,l)=>{this.components.transportManager.add(this.configureComponent(`transport-${l}`,u(this.components)))}),e.services!=null)for(let u of Object.keys(e.services)){let l=e.services[u],f=l(this.components);if(f==null){this.log.error("service factory %s returned null or undefined instance",u);continue}this.services[u]=f,this.configureComponent(u,f),f[Ma]!=null&&(this.log("registering service %s for content routing",u),c.push(f[Ma])),f[Fa]!=null&&(this.log("registering service %s for peer routing",u),a.push(f[Fa])),f[Ba]!=null&&(this.log("registering service %s for peer discovery",u),f[Ba].addEventListener?.("peer",d=>{this.#e(d)}))}rm(i)}configureComponent(e,t){return t==null&&this.log.error("component %s was null or undefined",e),this.components[e]=t,t}async start(){if(this.status==="stopped"){this.status="starting",this.log("libp2p is starting");try{await this.components.beforeStart?.(),await this.components.start(),await this.components.afterStart?.(),this.status="started",this.safeDispatchEvent("start",{detail:this}),this.log("libp2p has started with peer id %p",this.peerId)}catch(e){throw this.log.error("an error occurred starting libp2p - %e",e),this.status="started",await this.stop(),e}}}async stop(){this.status==="started"&&(this.log("libp2p is stopping"),this.status="stopping",await this.components.beforeStop?.(),await this.components.stop(),await this.components.afterStop?.(),this.status="stopped",this.safeDispatchEvent("stop",{detail:this}),this.log("libp2p has stopped"))}getConnections(e){return this.components.connectionManager.getConnections(e)}getDialQueue(){return this.components.connectionManager.getDialQueue()}getPeers(){let e=new br;for(let t of this.components.connectionManager.getConnections())e.add(t.remotePeer);return Array.from(e)}async dial(e,t={}){return this.components.connectionManager.openConnection(e,{priority:75,...t})}async dialProtocol(e,t,n={}){if(t==null)throw new T("no protocols were provided to open a stream");if(t=Array.isArray(t)?t:[t],t.length===0)throw new T("no protocols were provided to open a stream");return this.components.connectionManager.openStream(e,t,n)}getMultiaddrs(){return this.components.addressManager.getAddresses()}getProtocols(){return this.components.registrar.getProtocols()}async hangUp(e,t={}){er(e)&&(e=xt(e.getComponents().findLast(n=>n.code===421)?.value??"")),await this.components.connectionManager.closeConnections(e,t)}async getPublicKey(e,t={}){if(this.log("getPublicKey %p",e),e.publicKey!=null)return e.publicKey;try{let i=await this.peerStore.get(e,t);if(i.id.publicKey!=null)return i.id.publicKey}catch(i){if(i.name!=="NotFoundError")throw i}let n=tt([I("/pk/"),e.toMultihash().bytes]),o=await this.contentRouting.get(n,t),s=await Dh(e,o,t);return await this.peerStore.patch(e,{publicKey:s},t),s}async handle(e,t,n){Array.isArray(e)||(e=[e]),await Promise.all(e.map(async o=>{await this.components.registrar.handle(o,t,n)}))}async unhandle(e,t){Array.isArray(e)||(e=[e]),await Promise.all(e.map(async n=>{await this.components.registrar.unhandle(n,t)}))}async register(e,t,n){return this.components.registrar.register(e,t,n)}unregister(e){this.components.registrar.unregister(e)}use(e,t){if(typeof e=="function"){this.components.registrar.use(e);return}if(t==null)throw new T("Protocol middleware is required");this.components.registrar.use(e,Array.isArray(t)?t:[t])}unuse(e){if(typeof e=="function"){this.components.registrar.unuse(e);return}this.components.registrar.unuse(e)}async isDialable(e,t={}){return this.components.connectionManager.isDialable(e,t)}#e(e){let{detail:t}=e;if(t.id.toString()===this.peerId.toString()){this.log.error("peer discovery mechanism discovered self");return}this.components.peerStore.merge(t.id,{multiaddrs:t.multiaddrs}).catch(n=>{this.log.error("could not update multiaddrs of discovered peer - %e",n)})}};async function fx(r={}){r.privateKey??=await Lh("Ed25519");let e=new Fo({...await Nh(r),peerId:kh(r.privateKey)});return r.start!==!1&&await e.start(),e}var dx=["dial","dialProtocol","hangUp","handle","unhandle","getMultiaddrs","getProtocols"];function hx(r){return r==null?!1:r instanceof Fo?!0:dx.every(e=>typeof r[e]=="function")}return Nm(px);})();
|
|
27
27
|
/*! Bundled license information:
|
|
28
28
|
|
|
29
29
|
@noble/curves/utils.js:
|