@libp2p/pubsub 10.1.18-a02cb0461 → 10.1.18-f5932c294
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/index.d.ts +3 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +22 -11
- package/dist/src/index.js.map +1 -1
- package/dist/src/peer-streams.d.ts.map +1 -1
- package/dist/src/peer-streams.js +5 -17
- package/dist/src/peer-streams.js.map +1 -1
- package/package.json +14 -16
- package/src/index.ts +23 -13
- package/src/peer-streams.ts +5 -18
package/dist/index.min.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PPubsub = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
2
|
-
"use strict";var Libp2PPubsub=(()=>{var Ka=Object.create;var Cr=Object.defineProperty;var Na=Object.getOwnPropertyDescriptor;var Ua=Object.getOwnPropertyNames;var Oa=Object.getPrototypeOf,Ma=Object.prototype.hasOwnProperty;var ka=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),yt=(e,t)=>{for(var r in t)Cr(e,r,{get:t[r],enumerable:!0})},Is=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ua(t))!Ma.call(e,o)&&o!==r&&Cr(e,o,{get:()=>t[o],enumerable:!(n=Na(t,o))||n.enumerable});return e};var qa=(e,t,r)=>(r=e!=null?Ka(Oa(e)):{},Is(t||!e||!e.__esModule?Cr(r,"default",{value:e,enumerable:!0}):r,e)),Ha=e=>Is(Cr({},"__esModule",{value:!0}),e);var Ia=ka((Qm,ws)=>{"use strict";var Ff=Object.prototype.hasOwnProperty,pt="~";function Ir(){}Object.create&&(Ir.prototype=Object.create(null),new Ir().__proto__||(pt=!1));function zf(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function Aa(e,t,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var s=new zf(r,n||e,o),i=pt?pt+t:t;return e._events[i]?e._events[i].fn?e._events[i]=[e._events[i],s]:e._events[i].push(s):(e._events[i]=s,e._eventsCount++),e}function Sn(e,t){--e._eventsCount===0?e._events=new Ir:delete e._events[t]}function lt(){this._events=new Ir,this._eventsCount=0}lt.prototype.eventNames=function(){var t=[],r,n;if(this._eventsCount===0)return t;for(n in r=this._events)Ff.call(r,n)&&t.push(pt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(r)):t};lt.prototype.listeners=function(t){var r=pt?pt+t:t,n=this._events[r];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};lt.prototype.listenerCount=function(t){var r=pt?pt+t:t,n=this._events[r];return n?n.fn?1:n.length:0};lt.prototype.emit=function(t,r,n,o,s,i){var c=pt?pt+t:t;if(!this._events[c])return!1;var a=this._events[c],f=arguments.length,d,l;if(a.fn){switch(a.once&&this.removeListener(t,a.fn,void 0,!0),f){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,r),!0;case 3:return a.fn.call(a.context,r,n),!0;case 4:return a.fn.call(a.context,r,n,o),!0;case 5:return a.fn.call(a.context,r,n,o,s),!0;case 6:return a.fn.call(a.context,r,n,o,s,i),!0}for(l=1,d=new Array(f-1);l<f;l++)d[l-1]=arguments[l];a.fn.apply(a.context,d)}else{var u=a.length,h;for(l=0;l<u;l++)switch(a[l].once&&this.removeListener(t,a[l].fn,void 0,!0),f){case 1:a[l].fn.call(a[l].context);break;case 2:a[l].fn.call(a[l].context,r);break;case 3:a[l].fn.call(a[l].context,r,n);break;case 4:a[l].fn.call(a[l].context,r,n,o);break;default:if(!d)for(h=1,d=new Array(f-1);h<f;h++)d[h-1]=arguments[h];a[l].fn.apply(a[l].context,d)}}return!0};lt.prototype.on=function(t,r,n){return Aa(this,t,r,n,!1)};lt.prototype.once=function(t,r,n){return Aa(this,t,r,n,!0)};lt.prototype.removeListener=function(t,r,n,o){var s=pt?pt+t:t;if(!this._events[s])return this;if(!r)return Sn(this,s),this;var i=this._events[s];if(i.fn)i.fn===r&&(!o||i.once)&&(!n||i.context===n)&&Sn(this,s);else{for(var c=0,a=[],f=i.length;c<f;c++)(i[c].fn!==r||o&&!i[c].once||n&&i[c].context!==n)&&a.push(i[c]);a.length?this._events[s]=a.length===1?a[0]:a:Sn(this,s)}return this};lt.prototype.removeAllListeners=function(t){var r;return t?(r=pt?pt+t:t,this._events[r]&&Sn(this,r)):(this._events=new Ir,this._eventsCount=0),this};lt.prototype.off=lt.prototype.removeListener;lt.prototype.addListener=lt.prototype.on;lt.prefixed=pt;lt.EventEmitter=lt;typeof ws<"u"&&(ws.exports=lt)});var Yf={};yt(Yf,{PubSubBaseProtocol:()=>Ss});var Pr=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var j=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Se=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Dr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Q=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var Rr=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var ue=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var An=Symbol.for("@libp2p/peer-id");var je;(function(e){e.Accept="accept",e.Ignore="ignore",e.Reject="reject"})(je||(je={}));var Qf=Symbol.for("@libp2p/pubsub");var ve=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){super.addEventListener(t,r,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,r,n){super.removeEventListener(t.toString(),r??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==r),this.#t.set(t,o))}dispatchEvent(t){let r=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),r}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var Tn={};yt(Tn,{base58btc:()=>Z,base58flickr:()=>$a});var rl=new Uint8Array(0);function Bs(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Dt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Ls(e){return new TextEncoder().encode(e)}function _s(e){return new TextDecoder().decode(e)}function Va(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var c=e.length,a=e.charAt(0),f=Math.log(c)/Math.log(256),d=Math.log(256)/Math.log(c);function l(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var E=0,S=0,b=0,A=p.length;b!==A&&p[b]===0;)b++,E++;for(var w=(A-b)*d+1>>>0,_=new Uint8Array(w);b!==A;){for(var D=p[b],M=0,O=w-1;(D!==0||M<S)&&O!==-1;O--,M++)D+=256*_[O]>>>0,_[O]=D%c>>>0,D=D/c>>>0;if(D!==0)throw new Error("Non-zero carry");S=M,b++}for(var K=w-S;K!==w&&_[K]===0;)K++;for(var x=a.repeat(E);K<w;++K)x+=e.charAt(_[K]);return x}function u(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var E=0;if(p[E]!==" "){for(var S=0,b=0;p[E]===a;)S++,E++;for(var A=(p.length-E)*f+1>>>0,w=new Uint8Array(A);p[E];){var _=r[p.charCodeAt(E)];if(_===255)return;for(var D=0,M=A-1;(_!==0||D<b)&&M!==-1;M--,D++)_+=c*w[M]>>>0,w[M]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");b=D,E++}if(p[E]!==" "){for(var O=A-b;O!==A&&w[O]===0;)O++;for(var K=new Uint8Array(S+(A-O)),x=S;O!==A;)K[x++]=w[O++];return K}}}function h(p){var E=u(p);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:u,decode:h}}var Fa=Va,za=Fa,Cs=za;var In=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Bn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Ps(this,t)}},Ln=class{decoders;constructor(t){this.decoders=t}or(t){return Ps(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ps(e,t){return new Ln({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var _n=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new In(t,r,n),this.decoder=new Bn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ae({name:e,prefix:t,encode:r,decode:n}){return new _n(e,t,r,n)}function Xt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Cs(r,e);return Ae({prefix:t,name:e,encode:n,decode:s=>Dt(o(s))})}function Ga(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,c=0,a=0;for(let f=0;f<o;++f){let d=t[e[f]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|d,i+=r,i>=8&&(i-=8,s[a++]=255&c>>i)}if(i>=r||(255&c<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function ja(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,c=0;for(let a=0;a<e.length;++a)for(c=c<<8|e[a],i+=8;i>r;)i-=r,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Za(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function W({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Za(n);return Ae({prefix:t,name:e,encode(s){return ja(s,n,r)},decode(s){return Ga(s,o,r,e)}})}var Z=Xt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),$a=Xt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Cn={};yt(Cn,{base32:()=>Ie,base32hex:()=>Ja,base32hexpad:()=>tc,base32hexpadupper:()=>ec,base32hexupper:()=>Qa,base32pad:()=>Xa,base32padupper:()=>Wa,base32upper:()=>Ya,base32z:()=>rc});var Ie=W({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ya=W({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Xa=W({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Wa=W({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ja=W({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Qa=W({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),tc=W({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ec=W({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),rc=W({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Pn={};yt(Pn,{base36:()=>Ze,base36upper:()=>nc});var Ze=Xt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),nc=Xt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var oc=Ks,Ds=128,sc=127,ic=~sc,ac=Math.pow(2,31);function Ks(e,t,r){t=t||[],r=r||0;for(var n=r;e>=ac;)t[r++]=e&255|Ds,e/=128;for(;e⁣)t[r++]=e&255|Ds,e>>>=7;return t[r]=e|0,Ks.bytes=r-n+1,t}var cc=Dn,uc=128,Rs=127;function Dn(e,n){var r=0,n=n||0,o=0,s=n,i,c=e.length;do{if(s>=c)throw Dn.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Rs)<<o:(i&Rs)*Math.pow(2,o),o+=7}while(i>=uc);return Dn.bytes=s-n,r}var fc=Math.pow(2,7),lc=Math.pow(2,14),hc=Math.pow(2,21),dc=Math.pow(2,28),pc=Math.pow(2,35),mc=Math.pow(2,42),yc=Math.pow(2,49),bc=Math.pow(2,56),gc=Math.pow(2,63),wc=function(e){return e<fc?1:e<lc?2:e<hc?3:e<dc?4:e<pc?5:e<mc?6:e<yc?7:e<bc?8:e<gc?9:10},xc={encode:oc,decode:cc,encodingLength:wc},Ec=xc,$e=Ec;function Ye(e,t=0){return[$e.decode(e,t),$e.decode.bytes]}function Be(e,t,r=0){return $e.encode(e,t,r),t}function Le(e){return $e.encodingLength(e)}function Tt(e,t){let r=t.byteLength,n=Le(e),o=n+Le(r),s=new Uint8Array(o+r);return Be(e,s,0),Be(r,s,n),s.set(t,o),new _e(e,r,t,s)}function Wt(e){let t=Dt(e),[r,n]=Ye(t),[o,s]=Ye(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new _e(r,o,i,t)}function Ns(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Bs(e.bytes,r.bytes)}}var _e=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Us(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return vc(r,Rn(e),t??Z.encoder);default:return Ac(r,Rn(e),t??Ie.encoder)}}var Os=new WeakMap;function Rn(e){let t=Os.get(e);if(t==null){let r=new Map;return Os.set(e,r),r}return t}var at=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==Xe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Ic)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=Tt(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&Ns(t.multihash,n.multihash)}toString(t){return Us(this,t)}toJSON(){return{"/":Us(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??Ms(n,o,s.bytes))}else if(r[Bc]===!0){let{version:n,multihash:o,code:s}=r,i=Wt(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==Xe)throw new Error(`Version 0 CID must use dag-pb (code: ${Xe}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Ms(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Xe,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Dt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new _e(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,u]=Ye(t.subarray(r));return r+=u,l},o=n(),s=Xe;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,c=n(),a=n(),f=r+a,d=f-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:d,size:f}}static parse(t,r){let[n,o]=Sc(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Rn(s).set(n,t),s}};function Sc(e,t){switch(e[0]){case"Q":{let r=t??Z;return[Z.prefix,r.decode(`${Z.prefix}${e}`)]}case Z.prefix:{let r=t??Z;return[Z.prefix,r.decode(e)]}case Ie.prefix:{let r=t??Ie;return[Ie.prefix,r.decode(e)]}case Ze.prefix:{let r=t??Ze;return[Ze.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function vc(e,t,r){let{prefix:n}=r;if(n!==Z.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function Ac(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var Xe=112,Ic=18;function Ms(e,t,r){let n=Le(e),o=n+Le(t),s=new Uint8Array(o+r.byteLength);return Be(e,s,0),Be(t,s,n),s.set(r,o),s}var Bc=Symbol.for("@ipld/js-cid/CID");var Kn={};yt(Kn,{identity:()=>Bt});var ks=0,Lc="identity",qs=Dt;function _c(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Tt(ks,qs(e))}var Bt={code:ks,name:Lc,encode:qs,digest:_c};function bt(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Rt(e=0){return new Uint8Array(e)}function ct(e=0){return new Uint8Array(e)}function fe(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=ct(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Vs=Symbol.for("@achingbrain/uint8arraylist");function Hs(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function Nr(e){return!!e?.[Vs]}var et=class e{bufs;length;[Vs]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Nr(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Nr(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=Hs(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Hs(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(Nr(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return fe(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:fe(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let f=t>=c&&t<a,d=r>c&&r<=a;if(f&&d){if(t===c&&r===a){n.push(i);break}let l=t-c;n.push(i.subarray(l,l+(r-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(d){if(r===a){n.push(i);break}n.push(i.subarray(0,r-c));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Nr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let 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 l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let c=i,a=this.byteLength-n.byteLength,f=n.byteLength-1,d;for(let l=r;l<=a;l+=d){d=0;for(let u=f;u>=0;u--){let h=this.get(l+u);if(n[u]!==h){d=Math.max(1,u-c[h]);break}}if(d===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=ct(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=Rt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=Rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=Rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=ct(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=Rt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=Rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=Rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=Rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=Rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!bt(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var Nn={};yt(Nn,{base10:()=>Tc});var Tc=Xt({prefix:"9",name:"base10",alphabet:"0123456789"});var Un={};yt(Un,{base16:()=>Cc,base16upper:()=>Pc});var Cc=W({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Pc=W({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var On={};yt(On,{base2:()=>Dc});var Dc=W({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Mn={};yt(Mn,{base256emoji:()=>Oc});var Fs=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}"),Rc=Fs.reduce((e,t,r)=>(e[r]=t,e),[]),Kc=Fs.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Nc(e){return e.reduce((t,r)=>(t+=Rc[r],t),"")}function Uc(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Kc[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Oc=Ae({prefix:"\u{1F680}",name:"base256emoji",encode:Nc,decode:Uc});var kn={};yt(kn,{base64:()=>Mc,base64pad:()=>kc,base64url:()=>qc,base64urlpad:()=>Hc});var Mc=W({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),kc=W({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),qc=W({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Hc=W({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var qn={};yt(qn,{base8:()=>Vc});var Vc=W({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Hn={};yt(Hn,{identity:()=>Fc});var Fc=Ae({prefix:"\0",name:"identity",encode:e=>_s(e),decode:e=>Ls(e)});var kl=new TextEncoder,ql=new TextDecoder;var zn={};yt(zn,{sha256:()=>le,sha512:()=>Zc});var jc=20;function Fn({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Vn(e,t,r,n,o)}var Vn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??jc,this.maxDigestLength=s}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?zs(n,this.code,r?.truncate):n.then(o=>zs(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function zs(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Tt(t,e)}function js(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var le=Fn({name:"sha2-256",code:18,encode:js("SHA-256")}),Zc=Fn({name:"sha2-512",code:19,encode:js("SHA-512")});var Gn={...Hn,...On,...qn,...Nn,...Un,...Cn,...Pn,...Tn,...kn,...Mn},Jl={...zn,...Kn};function $s(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Zs=$s("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),jn=$s("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=ct(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),$c={utf8:Zs,"utf-8":Zs,hex:Gn.base16,latin1:jn,ascii:jn,binary:jn,...Gn},Ur=$c;function F(e,t="utf8"){let r=Ur[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function z(e,t="utf8"){let r=Ur[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Yc=parseInt("11111",2),Zn=parseInt("10000000",2),Xc=parseInt("01111111",2),Ys={0:We,1:We,2:Wc,3:tu,4:eu,5:Qc,6:Jc,16:We,22:We,48:We};function Kt(e,t={offset:0}){let r=e[t.offset]&Yc;if(t.offset++,Ys[r]!=null)return Ys[r](e,t);throw new Error("No decoder for tag "+r)}function Je(e,t){let r=0;if((e[t.offset]&Zn)===Zn){let n=e[t.offset]&Xc,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function We(e,t){Je(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Kt(e,t);if(n===null)break;r.push(n)}return r}function Wc(e,t){let r=Je(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function Jc(e,t){let r=Je(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let c=`${s}.${i}`,a=[];for(;t.offset<n;){let f=e[t.offset];if(t.offset++,a.push(f&127),f<128){a.reverse();let d=0;for(let l=0;l<a.length;l++)d+=a[l]<<l*7;c+=`.${d}`,a=[]}}return c}function Qc(e,t){return t.offset++,null}function tu(e,t){let r=Je(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function eu(e,t){let r=Je(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function ru(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new et;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function $n(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=ru(e.byteLength);return new et(Uint8Array.from([t.byteLength|Zn]),t)}function gt(e){let t=new et,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new et(Uint8Array.from([2]),$n(t),t)}function Or(e){let t=Uint8Array.from([0]),r=new et(t,e);return new et(Uint8Array.from([3]),$n(r),r)}function Qt(e,t=48){let r=new et;for(let n of e)r.append(n);return new et(Uint8Array.from([t]),$n(r),r)}async function Xs(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),s}var nu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),ou=Uint8Array.from([6,5,43,129,4,0,34]),su=Uint8Array.from([6,5,43,129,4,0,35]),iu={ext:!0,kty:"EC",crv:"P-256"},au={ext:!0,kty:"EC",crv:"P-384"},cu={ext:!0,kty:"EC",crv:"P-521"},Yn=32,Xn=48,Wn=66;function Jn(e){let t=Kt(e);return Ws(t)}function Ws(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Yn*2+1)return n=z(t.subarray(r,r+Yn),"base64url"),o=z(t.subarray(r+Yn),"base64url"),new Te({...iu,key_ops:["verify"],x:n,y:o});if(t.byteLength===Xn*2+1)return n=z(t.subarray(r,r+Xn),"base64url"),o=z(t.subarray(r+Xn),"base64url"),new Te({...au,key_ops:["verify"],x:n,y:o});if(t.byteLength===Wn*2+1)return n=z(t.subarray(r,r+Wn),"base64url"),o=z(t.subarray(r+Wn),"base64url"),new Te({...cu,key_ops:["verify"],x:n,y:o});throw new j(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Js(e){return Qt([gt(Uint8Array.from([1])),Qt([uu(e.crv)],160),Qt([Or(new et(Uint8Array.from([4]),F(e.x??"","base64url"),F(e.y??"","base64url")))],161)]).subarray()}function uu(e){if(e==="P-256")return nu;if(e==="P-384")return ou;if(e==="P-521")return su;throw new j(`Invalid curve ${e}`)}var Te=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Js(this.jwk)),this._raw}toMultihash(){return Bt.digest(Nt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}async verify(t,r,n){return Xs(this.jwk,r,t,n)}};var he=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Ot(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Qe(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function wt(e,...t){if(!Ot(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Mr(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Qe(e.outputLen),Qe(e.blockLen)}function Pe(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function ti(e,t){wt(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Mt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function kr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Lt(e,t){return e<<32-t|e>>>t}var ei=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",fu=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function vt(e){if(wt(e),ei)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=fu[e[r]];return t}var Ut={_0:48,_9:57,A:65,F:70,a:97,f:102};function Qs(e){if(e>=Ut._0&&e<=Ut._9)return e-Ut._0;if(e>=Ut.A&&e<=Ut.F)return e-(Ut.A-10);if(e>=Ut.a&&e<=Ut.f)return e-(Ut.a-10)}function de(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(ei)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=Qs(e.charCodeAt(s)),c=Qs(e.charCodeAt(s+1));if(i===void 0||c===void 0){let a=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function Qn(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function tr(e){return typeof e=="string"&&(e=Qn(e)),wt(e),e}function ht(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];wt(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}var Ce=class{};function to(e){let t=n=>e().update(tr(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function te(e=32){if(he&&typeof he.getRandomValues=="function")return he.getRandomValues(new Uint8Array(e));if(he&&typeof he.randomBytes=="function")return Uint8Array.from(he.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function lu(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),c=Number(r&s),a=n?4:0,f=n?0:4;e.setUint32(t+a,i,n),e.setUint32(t+f,c,n)}function ri(e,t,r){return e&t^~e&r}function ni(e,t,r){return e&t^e&r^t&r}var er=class extends Ce{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=kr(this.buffer)}update(t){Pe(this),t=tr(t),wt(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=kr(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Pe(this),ti(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Mt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;lu(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=kr(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=a/4,d=this.get();if(f>d.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)c.setUint32(4*l,d[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},kt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var st=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var qr=BigInt(4294967295),oi=BigInt(32);function hu(e,t=!1){return t?{h:Number(e&qr),l:Number(e>>oi&qr)}:{h:Number(e>>oi&qr)|0,l:Number(e&qr)|0}}function si(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:c}=hu(e[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var eo=(e,t,r)=>e>>>r,ro=(e,t,r)=>e<<32-r|t>>>r,pe=(e,t,r)=>e>>>r|t<<32-r,me=(e,t,r)=>e<<32-r|t>>>r,rr=(e,t,r)=>e<<64-r|t>>>r-32,nr=(e,t,r)=>e>>>r-32|t<<64-r;function Ct(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var ii=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),ai=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ci=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),ui=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,fi=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),li=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var pu=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]),ee=new Uint32Array(64),Hr=class extends er{constructor(t=32){super(64,t,8,!1),this.A=kt[0]|0,this.B=kt[1]|0,this.C=kt[2]|0,this.D=kt[3]|0,this.E=kt[4]|0,this.F=kt[5]|0,this.G=kt[6]|0,this.H=kt[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,r,n,o,s,i,c,a]}set(t,r,n,o,s,i,c,a){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(t,r){for(let l=0;l<16;l++,r+=4)ee[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let u=ee[l-15],h=ee[l-2],p=Lt(u,7)^Lt(u,18)^u>>>3,E=Lt(h,17)^Lt(h,19)^h>>>10;ee[l]=E+ee[l-7]+p+ee[l-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:f,H:d}=this;for(let l=0;l<64;l++){let u=Lt(c,6)^Lt(c,11)^Lt(c,25),h=d+u+ri(c,a,f)+pu[l]+ee[l]|0,E=(Lt(n,2)^Lt(n,13)^Lt(n,22))+ni(n,o,s)|0;d=f,f=a,a=c,c=i+h|0,i=s,s=o,o=n,n=h+E|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,f=f+this.G|0,d=d+this.H|0,this.set(n,o,s,i,c,a,f,d)}roundClean(){Mt(ee)}destroy(){this.set(0,0,0,0,0,0,0,0),Mt(this.buffer)}};var hi=si(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),mu=hi[0],yu=hi[1],re=new Uint32Array(80),ne=new Uint32Array(80),no=class extends er{constructor(t=64){super(128,t,16,!1),this.Ah=st[0]|0,this.Al=st[1]|0,this.Bh=st[2]|0,this.Bl=st[3]|0,this.Ch=st[4]|0,this.Cl=st[5]|0,this.Dh=st[6]|0,this.Dl=st[7]|0,this.Eh=st[8]|0,this.El=st[9]|0,this.Fh=st[10]|0,this.Fl=st[11]|0,this.Gh=st[12]|0,this.Gl=st[13]|0,this.Hh=st[14]|0,this.Hl=st[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:f,El:d,Fh:l,Fl:u,Gh:h,Gl:p,Hh:E,Hl:S}=this;return[t,r,n,o,s,i,c,a,f,d,l,u,h,p,E,S]}set(t,r,n,o,s,i,c,a,f,d,l,u,h,p,E,S){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=f|0,this.El=d|0,this.Fh=l|0,this.Fl=u|0,this.Gh=h|0,this.Gl=p|0,this.Hh=E|0,this.Hl=S|0}process(t,r){for(let w=0;w<16;w++,r+=4)re[w]=t.getUint32(r),ne[w]=t.getUint32(r+=4);for(let w=16;w<80;w++){let _=re[w-15]|0,D=ne[w-15]|0,M=pe(_,D,1)^pe(_,D,8)^eo(_,D,7),O=me(_,D,1)^me(_,D,8)^ro(_,D,7),K=re[w-2]|0,x=ne[w-2]|0,T=pe(K,x,19)^rr(K,x,61)^eo(K,x,6),N=me(K,x,19)^nr(K,x,61)^ro(K,x,6),C=ci(O,N,ne[w-7],ne[w-16]),g=ui(C,M,T,re[w-7],re[w-16]);re[w]=g|0,ne[w]=C|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:f,Dl:d,Eh:l,El:u,Fh:h,Fl:p,Gh:E,Gl:S,Hh:b,Hl:A}=this;for(let w=0;w<80;w++){let _=pe(l,u,14)^pe(l,u,18)^rr(l,u,41),D=me(l,u,14)^me(l,u,18)^nr(l,u,41),M=l&h^~l&E,O=u&p^~u&S,K=fi(A,D,O,yu[w],ne[w]),x=li(K,b,_,M,mu[w],re[w]),T=K|0,N=pe(n,o,28)^rr(n,o,34)^rr(n,o,39),C=me(n,o,28)^nr(n,o,34)^nr(n,o,39),g=n&s^n&c^s&c,m=o&i^o&a^i&a;b=E|0,A=S|0,E=h|0,S=p|0,h=l|0,p=u|0,{h:l,l:u}=Ct(f|0,d|0,x|0,T|0),f=c|0,d=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let y=ii(T,C,m);n=ai(y,x,N,g),o=y|0}({h:n,l:o}=Ct(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ct(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=Ct(this.Ch|0,this.Cl|0,c|0,a|0),{h:f,l:d}=Ct(this.Dh|0,this.Dl|0,f|0,d|0),{h:l,l:u}=Ct(this.Eh|0,this.El|0,l|0,u|0),{h,l:p}=Ct(this.Fh|0,this.Fl|0,h|0,p|0),{h:E,l:S}=Ct(this.Gh|0,this.Gl|0,E|0,S|0),{h:b,l:A}=Ct(this.Hh|0,this.Hl|0,b|0,A|0),this.set(n,o,s,i,c,a,f,d,l,u,h,p,E,S,b,A)}roundClean(){Mt(re,ne)}destroy(){Mt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Vr=to(()=>new Hr);var di=to(()=>new no);var io=BigInt(0),so=BigInt(1);function qt(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function xt(e,t,r=""){let n=Ot(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,c=s?` of length ${t}`:"",a=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+c+", got "+a)}return e}function or(e){let t=e.toString(16);return t.length&1?"0"+t:t}function pi(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?io:BigInt("0x"+e)}function De(e){return pi(vt(e))}function Ht(e){return wt(e),pi(vt(Uint8Array.from(e).reverse()))}function Fr(e,t){return de(e.toString(16).padStart(t*2,"0"))}function ao(e,t){return Fr(e,t).reverse()}function H(e,t,r){let n;if(typeof t=="string")try{n=de(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(Ot(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}function mi(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function co(e){return Uint8Array.from(e)}var oo=e=>typeof e=="bigint"&&io<=e;function yi(e,t,r){return oo(e)&&oo(t)&&oo(r)&&t<=e&&e<r}function sr(e,t,r,n){if(!yi(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function zr(e){let t;for(t=0;e>io;e>>=so,t+=1);return t}var oe=e=>(so<<BigInt(e))-so;function bi(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=h=>new Uint8Array(h),o=h=>Uint8Array.of(h),s=n(e),i=n(e),c=0,a=()=>{s.fill(1),i.fill(0),c=0},f=(...h)=>r(i,s,...h),d=(h=n(0))=>{i=f(o(0),h),s=f(),h.length!==0&&(i=f(o(1),h),s=f())},l=()=>{if(c++>=1e3)throw new Error("drbg: tried 1000 values");let h=0,p=[];for(;h<t;){s=f();let E=s.slice();p.push(E),h+=s.length}return ht(...p)};return(h,p)=>{a(),d(h);let E;for(;!(E=p(l()));)d();return a(),E}}function se(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let c=e[o];if(i&&c===void 0)return;let a=typeof c;if(a!==s||c===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${a}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}var uo=()=>{throw new Error("not implemented")};function Re(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var dt=BigInt(0),nt=BigInt(1),ye=BigInt(2),xi=BigInt(3),Ei=BigInt(4),Si=BigInt(5),bu=BigInt(7),vi=BigInt(8),gu=BigInt(9),Ai=BigInt(16);function J(e,t){let r=e%t;return r>=dt?r:t+r}function G(e,t,r){let n=e;for(;t-- >dt;)n*=n,n%=r;return n}function gi(e,t){if(e===dt)throw new Error("invert: expected non-zero number");if(t<=dt)throw new Error("invert: expected positive modulus, got "+t);let r=J(e,t),n=t,o=dt,s=nt,i=nt,c=dt;for(;r!==dt;){let f=n/r,d=n%r,l=o-i*f,u=s-c*f;n=r,r=d,o=i,s=c,i=l,c=u}if(n!==nt)throw new Error("invert: does not exist");return J(o,t)}function fo(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function Ii(e,t){let r=(e.ORDER+nt)/Ei,n=e.pow(t,r);return fo(e,n,t),n}function wu(e,t){let r=(e.ORDER-Si)/vi,n=e.mul(t,ye),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,ye),o),c=e.mul(s,e.sub(i,e.ONE));return fo(e,c,t),c}function xu(e){let t=Et(e),r=Bi(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+bu)/Ai;return(c,a)=>{let f=c.pow(a,i),d=c.mul(f,n),l=c.mul(f,o),u=c.mul(f,s),h=c.eql(c.sqr(d),a),p=c.eql(c.sqr(l),a);f=c.cmov(f,d,h),d=c.cmov(u,l,p);let E=c.eql(c.sqr(d),a),S=c.cmov(f,d,E);return fo(c,S,a),S}}function Bi(e){if(e<xi)throw new Error("sqrt is not defined for small field");let t=e-nt,r=0;for(;t%ye===dt;)t/=ye,r++;let n=ye,o=Et(e);for(;wi(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Ii;let s=o.pow(n,t),i=(t+nt)/ye;return function(a,f){if(a.is0(f))return f;if(wi(a,f)!==1)throw new Error("Cannot find square root");let d=r,l=a.mul(a.ONE,s),u=a.pow(f,t),h=a.pow(f,i);for(;!a.eql(u,a.ONE);){if(a.is0(u))return a.ZERO;let p=1,E=a.sqr(u);for(;!a.eql(E,a.ONE);)if(p++,E=a.sqr(E),p===d)throw new Error("Cannot find square root");let S=nt<<BigInt(d-p-1),b=a.pow(l,S);d=p,l=a.sqr(b),u=a.mul(u,l),h=a.mul(h,b)}return h}}function Eu(e){return e%Ei===xi?Ii:e%vi===Si?wu:e%Ai===gu?xu(e):Bi(e)}var Vt=(e,t)=>(J(e,t)&nt)===nt,Su=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function lo(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=Su.reduce((n,o)=>(n[o]="function",n),t);return se(e,r),e}function vu(e,t,r){if(r<dt)throw new Error("invalid exponent, negatives unsupported");if(r===dt)return e.ONE;if(r===nt)return t;let n=e.ONE,o=t;for(;r>dt;)r&nt&&(n=e.mul(n,o)),o=e.sqr(o),r>>=nt;return n}function ir(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,c,a)=>e.is0(c)?i:(n[a]=i,e.mul(i,c)),e.ONE),s=e.inv(o);return t.reduceRight((i,c,a)=>e.is0(c)?i:(n[a]=e.mul(i,n[a]),e.mul(i,c)),s),n}function wi(e,t){let r=(e.ORDER-nt)/ye,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Gr(e,t){t!==void 0&&Qe(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function Et(e,t,r=!1,n={}){if(e<=dt)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s,i=!1,c;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let u=t;u.BITS&&(o=u.BITS),u.sqrt&&(s=u.sqrt),typeof u.isLE=="boolean"&&(r=u.isLE),typeof u.modFromBytes=="boolean"&&(i=u.modFromBytes),c=u.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:a,nByteLength:f}=Gr(e,o);if(f>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let d,l=Object.freeze({ORDER:e,isLE:r,BITS:a,BYTES:f,MASK:oe(a),ZERO:dt,ONE:nt,allowedLengths:c,create:u=>J(u,e),isValid:u=>{if(typeof u!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof u);return dt<=u&&u<e},is0:u=>u===dt,isValidNot0:u=>!l.is0(u)&&l.isValid(u),isOdd:u=>(u&nt)===nt,neg:u=>J(-u,e),eql:(u,h)=>u===h,sqr:u=>J(u*u,e),add:(u,h)=>J(u+h,e),sub:(u,h)=>J(u-h,e),mul:(u,h)=>J(u*h,e),pow:(u,h)=>vu(l,u,h),div:(u,h)=>J(u*gi(h,e),e),sqrN:u=>u*u,addN:(u,h)=>u+h,subN:(u,h)=>u-h,mulN:(u,h)=>u*h,inv:u=>gi(u,e),sqrt:s||(u=>(d||(d=Eu(e)),d(l,u))),toBytes:u=>r?ao(u,f):Fr(u,f),fromBytes:(u,h=!0)=>{if(c){if(!c.includes(u.length)||u.length>f)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+u.length);let E=new Uint8Array(f);E.set(u,r?0:E.length-u.length),u=E}if(u.length!==f)throw new Error("Field.fromBytes: expected "+f+" bytes, got "+u.length);let p=r?Ht(u):De(u);if(i&&(p=J(p,e)),!h&&!l.isValid(p))throw new Error("invalid field element: outside of range 0..ORDER");return p},invertBatch:u=>ir(l,u),cmov:(u,h,p)=>p?h:u});return Object.freeze(l)}function Li(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function ho(e){let t=Li(e);return t+Math.ceil(t/2)}function po(e,t,r=!1){let n=e.length,o=Li(t),s=ho(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Ht(e):De(e),c=J(i,t-nt)+nt;return r?ao(c,o):Fr(c,o)}var Ke=BigInt(0),be=BigInt(1);function ar(e,t){let r=t.negate();return e?r:t}function Ft(e,t){let r=ir(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Pi(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function mo(e,t){Pi(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=oe(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function _i(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,c=Number(e&o),a=e>>i;c>n&&(c-=s,a+=be);let f=t*n,d=f+Math.abs(c)-1,l=c===0,u=c<0,h=t%2!==0;return{nextN:a,offset:d,isZero:l,isNeg:u,isNegF:h,offsetF:f}}function Au(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Iu(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var yo=new WeakMap,Di=new WeakMap;function bo(e){return Di.get(e)||1}function Ti(e){if(e!==Ke)throw new Error("invalid wNAF")}var Ne=class{constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>Ke;)r&be&&(n=n.add(o)),o=o.double(),r>>=be;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=mo(r,this.bits),s=[],i=t,c=i;for(let a=0;a<n;a++){c=i,s.push(c);for(let f=1;f<o;f++)c=c.add(i),s.push(c);i=c.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=mo(t,this.bits);for(let c=0;c<i.windows;c++){let{nextN:a,offset:f,isZero:d,isNeg:l,isNegF:u,offsetF:h}=_i(n,c,i);n=a,d?s=s.add(ar(u,r[h])):o=o.add(ar(l,r[f]))}return Ti(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=mo(t,this.bits);for(let i=0;i<s.windows&&n!==Ke;i++){let{nextN:c,offset:a,isZero:f,isNeg:d}=_i(n,i,s);if(n=c,!f){let l=r[a];o=o.add(d?l.negate():l)}}return Ti(n),o}getPrecomputes(t,r,n){let o=yo.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),yo.set(r,o))),o}cached(t,r,n){let o=bo(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=bo(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){Pi(r,this.bits),Di.set(t,r),yo.delete(t)}hasCache(t){return bo(t)!==1}};function Ri(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Ke||n>Ke;)r&be&&(s=s.add(o)),n&be&&(i=i.add(o)),o=o.double(),r>>=be,n>>=be;return{p1:s,p2:i}}function Ue(e,t,r,n){Au(r,e),Iu(n,t);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,c=zr(BigInt(o)),a=1;c>12?a=c-3:c>4?a=c-2:c>0&&(a=2);let f=oe(a),d=new Array(Number(f)+1).fill(i),l=Math.floor((t.BITS-1)/a)*a,u=i;for(let h=l;h>=0;h-=a){d.fill(i);for(let E=0;E<s;E++){let S=n[E],b=Number(S>>BigInt(h)&f);d[b]=d[b].add(r[E])}let p=i;for(let E=d.length-1,S=i;E>0;E--)S=S.add(d[E]),p=p.add(S);if(u=u.add(p),h!==0)for(let E=0;E<a;E++)u=u.double()}return u}function Ci(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return lo(t),t}else return Et(e,{isLE:r})}function jr(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let a of["p","n","h"]){let f=t[a];if(!(typeof f=="bigint"&&f>Ke))throw new Error(`CURVE.${a} must be positive bigint`)}let o=Ci(t.p,r.Fp,n),s=Ci(t.n,r.Fn,n),c=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of c)if(!o.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}var ie=BigInt(0),ot=BigInt(1),go=BigInt(2),Bu=BigInt(8);function Lu(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),c=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,c)}function _u(e,t={}){let r=jr("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;se(t,{},{uvRatio:"function"});let c=go<<BigInt(o.BYTES*8)-ot,a=S=>n.create(S),f=t.uvRatio||((S,b)=>{try{return{isValid:!0,value:n.sqrt(n.div(S,b))}}catch{return{isValid:!1,value:ie}}});if(!Lu(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function d(S,b,A=!1){let w=A?ot:ie;return sr("coordinate "+S,b,w,c),b}function l(S){if(!(S instanceof p))throw new Error("ExtendedPoint expected")}let u=Re((S,b)=>{let{X:A,Y:w,Z:_}=S,D=S.is0();b==null&&(b=D?Bu:n.inv(_));let M=a(A*b),O=a(w*b),K=n.mul(_,b);if(D)return{x:ie,y:ot};if(K!==ot)throw new Error("invZ was invalid");return{x:M,y:O}}),h=Re(S=>{let{a:b,d:A}=s;if(S.is0())throw new Error("bad point: ZERO");let{X:w,Y:_,Z:D,T:M}=S,O=a(w*w),K=a(_*_),x=a(D*D),T=a(x*x),N=a(O*b),C=a(x*a(N+K)),g=a(T+a(A*a(O*K)));if(C!==g)throw new Error("bad point: equation left != right (1)");let m=a(w*_),y=a(D*M);if(m!==y)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(b,A,w,_){this.X=d("x",b),this.Y=d("y",A),this.Z=d("z",w,!0),this.T=d("t",_),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){if(b instanceof p)throw new Error("extended point not allowed");let{x:A,y:w}=b||{};return d("x",A),d("y",w),new p(A,w,ot,a(A*w))}static fromBytes(b,A=!1){let w=n.BYTES,{a:_,d:D}=s;b=co(xt(b,w,"point")),qt(A,"zip215");let M=co(b),O=b[w-1];M[w-1]=O&-129;let K=Ht(M),x=A?c:n.ORDER;sr("point.y",K,ie,x);let T=a(K*K),N=a(T-ot),C=a(D*T-_),{isValid:g,value:m}=f(N,C);if(!g)throw new Error("bad point: invalid y coordinate");let y=(m&ot)===ot,v=(O&128)!==0;if(!A&&m===ie&&v)throw new Error("bad point: x=0 and x_0=1");return v!==y&&(m=a(-m)),p.fromAffine({x:m,y:K})}static fromHex(b,A=!1){return p.fromBytes(H("point",b),A)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,A=!0){return E.createCache(this,b),A||this.multiply(go),this}assertValidity(){h(this)}equals(b){l(b);let{X:A,Y:w,Z:_}=this,{X:D,Y:M,Z:O}=b,K=a(A*O),x=a(D*_),T=a(w*O),N=a(M*_);return K===x&&T===N}is0(){return this.equals(p.ZERO)}negate(){return new p(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:b}=s,{X:A,Y:w,Z:_}=this,D=a(A*A),M=a(w*w),O=a(go*a(_*_)),K=a(b*D),x=A+w,T=a(a(x*x)-D-M),N=K+M,C=N-O,g=K-M,m=a(T*C),y=a(N*g),v=a(T*g),I=a(C*N);return new p(m,y,I,v)}add(b){l(b);let{a:A,d:w}=s,{X:_,Y:D,Z:M,T:O}=this,{X:K,Y:x,Z:T,T:N}=b,C=a(_*K),g=a(D*x),m=a(O*w*N),y=a(M*T),v=a((_+D)*(K+x)-C-g),I=y-m,P=y+m,B=a(g-A*C),L=a(v*I),R=a(P*B),U=a(v*B),$=a(I*P);return new p(L,R,$,U)}subtract(b){return this.add(b.negate())}multiply(b){if(!o.isValidNot0(b))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:A,f:w}=E.cached(this,b,_=>Ft(p,_));return Ft(p,[A,w])[0]}multiplyUnsafe(b,A=p.ZERO){if(!o.isValid(b))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return b===ie?p.ZERO:this.is0()||b===ot?this:E.unsafe(this,b,w=>Ft(p,w),A)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return E.unsafe(this,s.n).is0()}toAffine(b){return u(this,b)}clearCofactor(){return i===ot?this:this.multiplyUnsafe(i)}toBytes(){let{x:b,y:A}=this.toAffine(),w=n.toBytes(A);return w[w.length-1]|=b&ot?128:0,w}toHex(){return vt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(b){return Ft(p,b)}static msm(b,A){return Ue(p,o,b,A)}_setWindowSize(b){this.precompute(b)}toRawBytes(){return this.toBytes()}}p.BASE=new p(s.Gx,s.Gy,ot,a(s.Gx*s.Gy)),p.ZERO=new p(ie,ot,ot,ie),p.Fp=n,p.Fn=o;let E=new Ne(p,o.BITS);return p.BASE.precompute(8),p}var Zr=class{constructor(t){this.ep=t}static fromBytes(t){uo()}static fromHex(t){uo()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return vt(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.init(this.ep.precompute(t,r))}toRawBytes(){return this.toBytes()}};function Tu(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');se(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=e,c=r.randomBytes||te,a=r.adjustScalarBytes||(x=>x),f=r.domain||((x,T,N)=>{if(qt(N,"phflag"),T.length||N)throw new Error("Contexts/pre-hash are not supported");return x});function d(x){return i.create(Ht(x))}function l(x){let T=w.secretKey;x=H("private key",x,T);let N=H("hashed private key",t(x),2*T),C=a(N.slice(0,T)),g=N.slice(T,2*T),m=d(C);return{head:C,prefix:g,scalar:m}}function u(x){let{head:T,prefix:N,scalar:C}=l(x),g=o.multiply(C),m=g.toBytes();return{head:T,prefix:N,scalar:C,point:g,pointBytes:m}}function h(x){return u(x).pointBytes}function p(x=Uint8Array.of(),...T){let N=ht(...T);return d(t(f(N,H("context",x),!!n)))}function E(x,T,N={}){x=H("message",x),n&&(x=n(x));let{prefix:C,scalar:g,pointBytes:m}=u(T),y=p(N.context,C,x),v=o.multiply(y).toBytes(),I=p(N.context,v,m,x),P=i.create(y+I*g);if(!i.isValid(P))throw new Error("sign failed: invalid s");let B=ht(v,i.toBytes(P));return xt(B,w.signature,"result")}let S={zip215:!0};function b(x,T,N,C=S){let{context:g,zip215:m}=C,y=w.signature;x=H("signature",x,y),T=H("message",T),N=H("publicKey",N,w.publicKey),m!==void 0&&qt(m,"zip215"),n&&(T=n(T));let v=y/2,I=x.subarray(0,v),P=Ht(x.subarray(v,y)),B,L,R;try{B=e.fromBytes(N,m),L=e.fromBytes(I,m),R=o.multiplyUnsafe(P)}catch{return!1}if(!m&&B.isSmallOrder())return!1;let U=p(g,L.toBytes(),B.toBytes(),T);return L.add(B.multiplyUnsafe(U)).subtract(R).clearCofactor().is0()}let A=s.BYTES,w={secretKey:A,publicKey:A,signature:2*A,seed:A};function _(x=c(w.seed)){return xt(x,w.seed,"seed")}function D(x){let T=K.randomSecretKey(x);return{secretKey:T,publicKey:h(T)}}function M(x){return Ot(x)&&x.length===i.BYTES}function O(x,T){try{return!!e.fromBytes(x,T)}catch{return!1}}let K={getExtendedPublicKey:u,randomSecretKey:_,isValidSecretKey:M,isValidPublicKey:O,toMontgomery(x){let{y:T}=e.fromBytes(x),N=w.publicKey,C=N===32;if(!C&&N!==57)throw new Error("only defined for 25519 and 448");let g=C?s.div(ot+T,ot-T):s.div(T-ot,T+ot);return s.toBytes(g)},toMontgomerySecret(x){let T=w.secretKey;xt(x,T);let N=t(x.subarray(0,T));return a(N).subarray(0,T)},randomPrivateKey:_,precompute(x=8,T=e.BASE){return T.precompute(x,!1)}};return Object.freeze({keygen:D,getPublicKey:h,sign:E,verify:b,utils:K,Point:e,lengths:w})}function Cu(e){let t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=Et(t.n,e.nBitLength,!0),o={Fp:r,Fn:n,uvRatio:e.uvRatio},s={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:o,hash:e.hash,eddsaOpts:s}}function Pu(e,t){let r=t.Point;return Object.assign({},t,{ExtendedPoint:r,CURVE:e,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function Ki(e){let{CURVE:t,curveOpts:r,hash:n,eddsaOpts:o}=Cu(e),s=_u(t,r),i=Tu(s,n,o);return Pu(e,i)}var Du=BigInt(0),zt=BigInt(1),Ni=BigInt(2),id=BigInt(3),Ru=BigInt(5),Ku=BigInt(8),Oe=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),cr={p:Oe,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Ku,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Nu(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Oe,c=e*e%s*e%s,a=G(c,Ni,s)*c%s,f=G(a,zt,s)*e%s,d=G(f,Ru,s)*f%s,l=G(d,t,s)*d%s,u=G(l,r,s)*l%s,h=G(u,n,s)*u%s,p=G(h,o,s)*h%s,E=G(p,o,s)*h%s,S=G(E,t,s)*d%s;return{pow_p_5_8:G(S,Ni,s)*e%s,b2:c}}function Uu(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var wo=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function So(e,t){let r=Oe,n=J(t*t*t,r),o=J(n*n*t,r),s=Nu(e*o).pow_p_5_8,i=J(e*n*s,r),c=J(t*i*i,r),a=i,f=J(i*wo,r),d=c===e,l=c===J(-e,r),u=c===J(-e*wo,r);return d&&(i=a),(l||u)&&(i=f),Vt(i,r)&&(i=J(-i,r)),{isValid:d||l,value:i}}var ae=Et(cr.p,{isLE:!0}),Ou=Et(cr.n,{isLE:!0}),Mu={...cr,Fp:ae,hash:di,adjustScalarBytes:Uu,uvRatio:So},Gt=Ki(Mu);var xo=wo,ku=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),qu=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Hu=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Vu=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Ui=e=>So(zt,e),Fu=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Eo=e=>Gt.Point.Fp.create(Ht(e)&Fu);function Oi(e){let{d:t}=cr,r=Oe,n=b=>ae.create(b),o=n(xo*e*e),s=n((o+zt)*Hu),i=BigInt(-1),c=n((i-t*o)*n(o+t)),{isValid:a,value:f}=So(s,c),d=n(f*e);Vt(d,r)||(d=n(-d)),a||(f=d),a||(i=o);let l=n(i*(o-zt)*Vu-c),u=f*f,h=n((f+f)*c),p=n(l*ku),E=n(zt-u),S=n(zt+u);return new Gt.Point(n(h*S),n(E*p),n(p*S),n(h*E))}function zu(e){wt(e,64);let t=Eo(e.subarray(0,32)),r=Oi(t),n=Eo(e.subarray(32,64)),o=Oi(n);return new jt(r.add(o))}var jt=class e extends Zr{constructor(t){super(t)}static fromAffine(t){return new e(Gt.Point.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static hashToCurve(t){return zu(H("ristrettoHash",t,64))}static fromBytes(t){wt(t,32);let{a:r,d:n}=cr,o=Oe,s=_=>ae.create(_),i=Eo(t);if(!mi(ae.toBytes(i),t)||Vt(i,o))throw new Error("invalid ristretto255 encoding 1");let c=s(i*i),a=s(zt+r*c),f=s(zt-r*c),d=s(a*a),l=s(f*f),u=s(r*n*d-l),{isValid:h,value:p}=Ui(s(u*l)),E=s(p*f),S=s(p*E*u),b=s((i+i)*E);Vt(b,o)&&(b=s(-b));let A=s(a*S),w=s(b*A);if(!h||Vt(w,o)||A===Du)throw new Error("invalid ristretto255 encoding 2");return new e(new Gt.Point(b,A,zt,w))}static fromHex(t){return e.fromBytes(H("ristrettoHex",t,32))}static msm(t,r){return Ue(e,Gt.Point.Fn,t,r)}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=Oe,i=S=>ae.create(S),c=i(i(n+r)*i(n-r)),a=i(t*r),f=i(a*a),{value:d}=Ui(i(c*f)),l=i(d*c),u=i(d*a),h=i(l*u*o),p;if(Vt(o*h,s)){let S=i(r*xo),b=i(t*xo);t=S,r=b,p=i(l*qu)}else p=u;Vt(t*h,s)&&(r=i(-r));let E=i((n-r)*p);return Vt(E,s)&&(E=i(-E)),ae.toBytes(E)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=f=>ae.create(f),c=i(r*s)===i(n*o),a=i(n*s)===i(r*o);return c||a}is0(){return this.equals(e.ZERO)}};jt.BASE=new jt(Gt.Point.BASE);jt.ZERO=new jt(Gt.Point.ZERO);jt.Fp=ae;jt.Fn=Ou;var ur=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},$r=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Mi={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new $r("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var At=Mi;var Yr=32;var vo,Gu=(async()=>{try{return await At.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function ju(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await At.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await At.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Zu(e,t,r){return Gt.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function ki(e,t,r){return vo==null&&(vo=await Gu),vo?ju(e,t,r):Zu(e,t,r)}function Xr(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Wr=class{type="Ed25519";raw;constructor(t){this.raw=Ao(t,Yr)}toMultihash(){return Bt.digest(Nt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=ki(this.raw,r,t);return Xr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Io(e){return e=Ao(e,Yr),new Wr(e)}function Ao(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new j(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Yu=Math.pow(2,7),Xu=Math.pow(2,14),Wu=Math.pow(2,21),Bo=Math.pow(2,28),Lo=Math.pow(2,35),_o=Math.pow(2,42),To=Math.pow(2,49),q=128,ut=127;function It(e){if(e<Yu)return 1;if(e<Xu)return 2;if(e<Wu)return 3;if(e<Bo)return 4;if(e<Lo)return 5;if(e<_o)return 6;if(e<To)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Co(e,t,r=0){switch(It(e)){case 8:t[r++]=e&255|q,e/=128;case 7:t[r++]=e&255|q,e/=128;case 6:t[r++]=e&255|q,e/=128;case 5:t[r++]=e&255|q,e/=128;case 4:t[r++]=e&255|q,e>>>=7;case 3:t[r++]=e&255|q,e>>>=7;case 2:t[r++]=e&255|q,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Ju(e,t,r=0){switch(It(e)){case 8:t.set(r++,e&255|q),e/=128;case 7:t.set(r++,e&255|q),e/=128;case 6:t.set(r++,e&255|q),e/=128;case 5:t.set(r++,e&255|q),e/=128;case 4:t.set(r++,e&255|q),e>>>=7;case 3:t.set(r++,e&255|q),e>>>=7;case 2:t.set(r++,e&255|q),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function Po(e,t){let r=e[t],n=0;if(n+=r&ut,r<q||(r=e[t+1],n+=(r&ut)<<7,r<q)||(r=e[t+2],n+=(r&ut)<<14,r<q)||(r=e[t+3],n+=(r&ut)<<21,r<q)||(r=e[t+4],n+=(r&ut)*Bo,r<q)||(r=e[t+5],n+=(r&ut)*Lo,r<q)||(r=e[t+6],n+=(r&ut)*_o,r<q)||(r=e[t+7],n+=(r&ut)*To,r<q))return n;throw new RangeError("Could not decode varint")}function Qu(e,t){let r=e.get(t),n=0;if(n+=r&ut,r<q||(r=e.get(t+1),n+=(r&ut)<<7,r<q)||(r=e.get(t+2),n+=(r&ut)<<14,r<q)||(r=e.get(t+3),n+=(r&ut)<<21,r<q)||(r=e.get(t+4),n+=(r&ut)*Bo,r<q)||(r=e.get(t+5),n+=(r&ut)*Lo,r<q)||(r=e.get(t+6),n+=(r&ut)*_o,r<q)||(r=e.get(t+7),n+=(r&ut)*To,r<q))return n;throw new RangeError("Could not decode varint")}function Do(e,t,r=0){return t==null&&(t=ct(It(e))),t instanceof Uint8Array?Co(e,t,r):Ju(e,t,r)}function Ro(e,t=0){return e instanceof Uint8Array?Po(e,t):Qu(e,t)}var No=new Float32Array([-0]),ce=new Uint8Array(No.buffer);function Hi(e,t,r){No[0]=e,t[r]=ce[0],t[r+1]=ce[1],t[r+2]=ce[2],t[r+3]=ce[3]}function Vi(e,t){return ce[0]=e[t],ce[1]=e[t+1],ce[2]=e[t+2],ce[3]=e[t+3],No[0]}var Uo=new Float64Array([-0]),ft=new Uint8Array(Uo.buffer);function Fi(e,t,r){Uo[0]=e,t[r]=ft[0],t[r+1]=ft[1],t[r+2]=ft[2],t[r+3]=ft[3],t[r+4]=ft[4],t[r+5]=ft[5],t[r+6]=ft[6],t[r+7]=ft[7]}function zi(e,t){return ft[0]=e[t],ft[1]=e[t+1],ft[2]=e[t+2],ft[3]=e[t+3],ft[4]=e[t+4],ft[5]=e[t+5],ft[6]=e[t+6],ft[7]=e[t+7],Uo[0]}var tf=BigInt(Number.MAX_SAFE_INTEGER),ef=BigInt(Number.MIN_SAFE_INTEGER),St=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ge;if(t<tf&&t>ef)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Gi&&(o=0n,++n>Gi&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return ge;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):ge}},ge=new St(0,0);ge.toBigInt=function(){return 0n};ge.zzEncode=ge.zzDecode=function(){return this};ge.length=function(){return 1};var Gi=4294967296n;function ji(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Zi(e,t,r){if(r-t<1)return"";let o,s=[],i=0,c;for(;t<r;)c=e[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|e[t++]&63:c>239&&c<365?(c=((c&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Oo(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function _t(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Jr(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Mo=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,_t(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw _t(this,4);return Jr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw _t(this,4);return Jr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw _t(this,4);let t=Vi(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw _t(this,4);let t=zi(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw _t(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Zi(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw _t(this,t);this.pos+=t}else do if(this.pos>=this.len)throw _t(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new St(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw _t(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw _t(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw _t(this,8);let t=Jr(this.buf,this.pos+=4),r=Jr(this.buf,this.pos+=4);return new St(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Po(this.buf,this.pos);return this.pos+=It(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function ko(e){return new Mo(e instanceof Uint8Array?e:e.subarray())}function Qr(e,t,r){let n=ko(e);return t.decode(n,void 0,r)}function qo(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return ct(i);o+i>t&&(n=ct(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var we=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Ho(){}var Fo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},rf=qo();function nf(e){return globalThis.Buffer!=null?ct(e):rf(e)}var lr=class{len;head;tail;states;constructor(){this.len=0,this.head=new we(Ho,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new we(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new zo((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(tn,10,St.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=St.fromBigInt(t);return this._push(tn,r.length(),r)}uint64Number(t){return this._push(Co,It(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=St.fromBigInt(t).zzEncode();return this._push(tn,r.length(),r)}sint64Number(t){let r=St.fromNumber(t).zzEncode();return this._push(tn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Vo,1,t?1:0)}fixed32(t){return this._push(fr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=St.fromBigInt(t);return this._push(fr,4,r.lo)._push(fr,4,r.hi)}fixed64Number(t){let r=St.fromNumber(t);return this._push(fr,4,r.lo)._push(fr,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Hi,4,t)}double(t){return this._push(Fi,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Vo,1,0):this.uint32(r)._push(sf,r,t)}string(t){let r=ji(t);return r!==0?this.uint32(r)._push(Oo,r,t):this._push(Vo,1,0)}fork(){return this.states=new Fo(this),this.head=this.tail=new we(Ho,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 we(Ho,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=nf(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Vo(e,t,r){t[r]=e&255}function of(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var zo=class extends we{next;constructor(t,r){super(of,t,r),this.next=void 0}};function tn(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function fr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function sf(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(lr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(af,t,e),this},lr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(cf,t,e),this});function af(e,t,r){t.set(e,r)}function cf(e,t,r){e.length<40?Oo(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(F(e),r)}function Go(){return new lr}function en(e,t){let r=Go();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var Me;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(Me||(Me={}));function rn(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function jo(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(s,i){let c=t(s);i.int32(c)},n=function(s){let i=s.int32();return t(i)};return rn("enum",Me.VARINT,r,n)}function nn(e,t){return rn("message",Me.LENGTH_DELIMITED,e,t)}var tt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(tt||(tt={}));var Zo;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Zo||(Zo={}));(function(e){e.codec=()=>jo(Zo)})(tt||(tt={}));var Pt;(function(e){let t;e.codec=()=>(t==null&&(t=nn((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),tt.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=tt.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>en(r,e.codec()),e.decode=(r,n)=>Qr(r,e.codec(),n)})(Pt||(Pt={}));var $o;(function(e){let t;e.codec=()=>(t==null&&(t=nn((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),tt.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=tt.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>en(r,e.codec()),e.decode=(r,n)=>Qr(r,e.codec(),n)})($o||($o={}));function on(e){if(isNaN(e)||e<=0)throw new j("random bytes length must be a Number bigger than 0");return te(e)}var dr={};yt(dr,{MAX_RSA_KEY_SIZE:()=>Yo,generateRSAKeyPair:()=>Qi,jwkToJWKKeyPair:()=>ta,jwkToPkcs1:()=>hf,jwkToPkix:()=>Qo,jwkToRSAPrivateKey:()=>ns,pkcs1MessageToJwk:()=>Wo,pkcs1MessageToRSAPrivateKey:()=>ts,pkcs1ToJwk:()=>lf,pkcs1ToRSAPrivateKey:()=>Ji,pkixMessageToJwk:()=>Jo,pkixMessageToRSAPublicKey:()=>rs,pkixToJwk:()=>df,pkixToRSAPublicKey:()=>es});var sn=Vr;var ke=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=dr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return at.createV1(114,this._multihash)}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,r,n){return Wi(this.jwk,r,t,n)}},hr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=dr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}sign(t,r){return Xi(this.jwk,t,r)}};var Yo=8192,Xo=18,uf=1062,ff=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function lf(e){let t=Kt(e);return Wo(t)}function Wo(e){return{n:z(e[1],"base64url"),e:z(e[2],"base64url"),d:z(e[3],"base64url"),p:z(e[4],"base64url"),q:z(e[5],"base64url"),dp:z(e[6],"base64url"),dq:z(e[7],"base64url"),qi:z(e[8],"base64url"),kty:"RSA"}}function hf(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new j("JWK was missing components");return Qt([gt(Uint8Array.from([0])),gt(F(e.n,"base64url")),gt(F(e.e,"base64url")),gt(F(e.d,"base64url")),gt(F(e.p,"base64url")),gt(F(e.q,"base64url")),gt(F(e.dp,"base64url")),gt(F(e.dq,"base64url")),gt(F(e.qi,"base64url"))]).subarray()}function df(e){let t=Kt(e,{offset:0});return Jo(t)}function Jo(e){let t=Kt(e[1],{offset:0});return{kty:"RSA",n:z(t[0],"base64url"),e:z(t[1],"base64url")}}function Qo(e){if(e.n==null||e.e==null)throw new j("JWK was missing components");return Qt([ff,Or(Qt([gt(F(e.n,"base64url")),gt(F(e.e,"base64url"))]))]).subarray()}function Ji(e){let t=Kt(e);return ts(t)}function ts(e){let t=Wo(e);return ns(t)}function es(e,t){if(e.byteLength>=uf)throw new Se("Key size is too large");let r=Kt(e,{offset:0});return rs(r,e,t)}function rs(e,t,r){let n=Jo(e);if(r==null){let o=sn(Pt.encode({Type:tt.RSA,Data:t}));r=Tt(Xo,o)}return new ke(n,r)}function ns(e){if(ra(e)>Yo)throw new j("Key size is too large");let t=ta(e),r=sn(Pt.encode({Type:tt.RSA,Data:Qo(t.publicKey)})),n=Tt(Xo,r);return new hr(t.privateKey,new ke(t.publicKey,n))}async function Qi(e){if(e>Yo)throw new j("Key size is too large");let t=await ea(e),r=sn(Pt.encode({Type:tt.RSA,Data:Qo(t.publicKey)})),n=Tt(Xo,r);return new hr(t.privateKey,new ke(t.publicKey,n))}function ta(e){if(e==null)throw new j("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function ea(e,t){let r=await At.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await pf(r,t);return{privateKey:n[0],publicKey:n[1]}}async function Xi(e,t,r){let n=await At.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await At.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Wi(e,t,r,n){let o=await At.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await At.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function pf(e,t){if(e.privateKey==null||e.publicKey==null)throw new j("Private and public key are required");let r=await Promise.all([At.get().subtle.exportKey("jwk",e.privateKey),At.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function ra(e){if(e.kty!=="RSA")throw new j("invalid key type");if(e.n==null)throw new j("invalid key modulus");return F(e.n,"base64url").length*8}var an=class extends Ce{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,Mr(t);let n=tr(r);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),Mt(s)}update(t){return Pe(this),this.iHash.update(t),this}digestInto(t){Pe(this),wt(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},os=(e,t,r)=>new an(e,t).update(r).digest();os.create=(e,t)=>new an(e,t);var na=(e,t)=>(e+(e>=0?t:-t)/oa)/t;function mf(e,t,r){let[[n,o],[s,i]]=t,c=na(i*e,r),a=na(-o*e,r),f=e-c*n-a*s,d=-c*o-a*i,l=f<$t,u=d<$t;l&&(f=-f),u&&(d=-d);let h=oe(Math.ceil(zr(r)/2))+He;if(f<$t||f>=h||d<$t||d>=h)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:f,k2neg:u,k2:d}}function is(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function ss(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return qt(r.lowS,"lowS"),qt(r.prehash,"prehash"),r.format!==void 0&&is(r.format),r}var as=class extends Error{constructor(t=""){super(t)}},Zt={Err:as,_tlv:{encode:(e,t)=>{let{Err:r}=Zt;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=or(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?or(o.length/2|128):"";return or(e)+s+o+t},decode(e,t){let{Err:r}=Zt,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let a=o&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+a);if(f.length!==a)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let d of f)i=i<<8|d;if(n+=a,i<128)throw new r("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new r("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Zt;if(e<$t)throw new t("integer: negative integers are not allowed");let r=or(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=Zt;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return De(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Zt,o=H("signature",e),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,s),{v:f,l:d}=n.decode(2,a);if(d.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(f)}},hexFromSig(e){let{_tlv:t,_int:r}=Zt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},$t=BigInt(0),He=BigInt(1),oa=BigInt(2),cn=BigInt(3),yf=BigInt(4);function qe(e,t){let{BYTES:r}=e,n;if(typeof t=="bigint")n=t;else{let o=H("private key",t);try{n=e.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof t}`)}}if(!e.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function bf(e,t={}){let r=jr("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:c}=s;se(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:a}=t;if(a&&(!n.is0(s.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=ia(n,o);function d(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(C,g,m){let{x:y,y:v}=g.toAffine(),I=n.toBytes(y);if(qt(m,"isCompressed"),m){d();let P=!n.isOdd(v);return ht(sa(P),I)}else return ht(Uint8Array.of(4),I,n.toBytes(v))}function u(C){xt(C,void 0,"Point");let{publicKey:g,publicKeyUncompressed:m}=f,y=C.length,v=C[0],I=C.subarray(1);if(y===g&&(v===2||v===3)){let P=n.fromBytes(I);if(!n.isValid(P))throw new Error("bad point: is not on curve, wrong x");let B=E(P),L;try{L=n.sqrt(B)}catch($){let V=$ instanceof Error?": "+$.message:"";throw new Error("bad point: is not on curve, sqrt error"+V)}d();let R=n.isOdd(L);return(v&1)===1!==R&&(L=n.neg(L)),{x:P,y:L}}else if(y===m&&v===4){let P=n.BYTES,B=n.fromBytes(I.subarray(0,P)),L=n.fromBytes(I.subarray(P,P*2));if(!S(B,L))throw new Error("bad point: is not on curve");return{x:B,y:L}}else throw new Error(`bad point: got length ${y}, expected compressed=${g} or uncompressed=${m}`)}let h=t.toBytes||l,p=t.fromBytes||u;function E(C){let g=n.sqr(C),m=n.mul(g,C);return n.add(n.add(m,n.mul(C,s.a)),s.b)}function S(C,g){let m=n.sqr(g),y=E(C);return n.eql(m,y)}if(!S(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let b=n.mul(n.pow(s.a,cn),yf),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(b,A)))throw new Error("bad curve params: a or b");function w(C,g,m=!1){if(!n.isValid(g)||m&&n.is0(g))throw new Error(`bad point coordinate ${C}`);return g}function _(C){if(!(C instanceof x))throw new Error("ProjectivePoint expected")}function D(C){if(!a||!a.basises)throw new Error("no endo");return mf(C,a.basises,o.ORDER)}let M=Re((C,g)=>{let{X:m,Y:y,Z:v}=C;if(n.eql(v,n.ONE))return{x:m,y};let I=C.is0();g==null&&(g=I?n.ONE:n.inv(v));let P=n.mul(m,g),B=n.mul(y,g),L=n.mul(v,g);if(I)return{x:n.ZERO,y:n.ZERO};if(!n.eql(L,n.ONE))throw new Error("invZ was invalid");return{x:P,y:B}}),O=Re(C=>{if(C.is0()){if(t.allowInfinityPoint&&!n.is0(C.Y))return;throw new Error("bad point: ZERO")}let{x:g,y:m}=C.toAffine();if(!n.isValid(g)||!n.isValid(m))throw new Error("bad point: x or y not field elements");if(!S(g,m))throw new Error("bad point: equation left != right");if(!C.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function K(C,g,m,y,v){return m=new x(n.mul(m.X,C),m.Y,m.Z),g=ar(y,g),m=ar(v,m),g.add(m)}class x{constructor(g,m,y){this.X=w("x",g),this.Y=w("y",m,!0),this.Z=w("z",y),Object.freeze(this)}static CURVE(){return s}static fromAffine(g){let{x:m,y}=g||{};if(!g||!n.isValid(m)||!n.isValid(y))throw new Error("invalid affine point");if(g instanceof x)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(y)?x.ZERO:new x(m,y,n.ONE)}static fromBytes(g){let m=x.fromAffine(p(xt(g,void 0,"point")));return m.assertValidity(),m}static fromHex(g){return x.fromBytes(H("pointHex",g))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,m=!0){return N.createCache(this,g),m||this.multiply(cn),this}assertValidity(){O(this)}hasEvenY(){let{y:g}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(g)}equals(g){_(g);let{X:m,Y:y,Z:v}=this,{X:I,Y:P,Z:B}=g,L=n.eql(n.mul(m,B),n.mul(I,v)),R=n.eql(n.mul(y,B),n.mul(P,v));return L&&R}negate(){return new x(this.X,n.neg(this.Y),this.Z)}double(){let{a:g,b:m}=s,y=n.mul(m,cn),{X:v,Y:I,Z:P}=this,B=n.ZERO,L=n.ZERO,R=n.ZERO,U=n.mul(v,v),$=n.mul(I,I),V=n.mul(P,P),k=n.mul(v,I);return k=n.add(k,k),R=n.mul(v,P),R=n.add(R,R),B=n.mul(g,R),L=n.mul(y,V),L=n.add(B,L),B=n.sub($,L),L=n.add($,L),L=n.mul(B,L),B=n.mul(k,B),R=n.mul(y,R),V=n.mul(g,V),k=n.sub(U,V),k=n.mul(g,k),k=n.add(k,R),R=n.add(U,U),U=n.add(R,U),U=n.add(U,V),U=n.mul(U,k),L=n.add(L,U),V=n.mul(I,P),V=n.add(V,V),U=n.mul(V,k),B=n.sub(B,U),R=n.mul(V,$),R=n.add(R,R),R=n.add(R,R),new x(B,L,R)}add(g){_(g);let{X:m,Y:y,Z:v}=this,{X:I,Y:P,Z:B}=g,L=n.ZERO,R=n.ZERO,U=n.ZERO,$=s.a,V=n.mul(s.b,cn),k=n.mul(m,I),Y=n.mul(y,P),rt=n.mul(v,B),mt=n.add(m,y),X=n.add(I,P);mt=n.mul(mt,X),X=n.add(k,Y),mt=n.sub(mt,X),X=n.add(m,v);let it=n.add(I,B);return X=n.mul(X,it),it=n.add(k,rt),X=n.sub(X,it),it=n.add(y,v),L=n.add(P,B),it=n.mul(it,L),L=n.add(Y,rt),it=n.sub(it,L),U=n.mul($,X),L=n.mul(V,rt),U=n.add(L,U),L=n.sub(Y,U),U=n.add(Y,U),R=n.mul(L,U),Y=n.add(k,k),Y=n.add(Y,k),rt=n.mul($,rt),X=n.mul(V,X),Y=n.add(Y,rt),rt=n.sub(k,rt),rt=n.mul($,rt),X=n.add(X,rt),k=n.mul(Y,X),R=n.add(R,k),k=n.mul(it,X),L=n.mul(mt,L),L=n.sub(L,k),k=n.mul(mt,Y),U=n.mul(it,U),U=n.add(U,k),new x(L,R,U)}subtract(g){return this.add(g.negate())}is0(){return this.equals(x.ZERO)}multiply(g){let{endo:m}=t;if(!o.isValidNot0(g))throw new Error("invalid scalar: out of range");let y,v,I=P=>N.cached(this,P,B=>Ft(x,B));if(m){let{k1neg:P,k1:B,k2neg:L,k2:R}=D(g),{p:U,f:$}=I(B),{p:V,f:k}=I(R);v=$.add(k),y=K(m.beta,U,V,P,L)}else{let{p:P,f:B}=I(g);y=P,v=B}return Ft(x,[y,v])[0]}multiplyUnsafe(g){let{endo:m}=t,y=this;if(!o.isValid(g))throw new Error("invalid scalar: out of range");if(g===$t||y.is0())return x.ZERO;if(g===He)return y;if(N.hasCache(this))return this.multiply(g);if(m){let{k1neg:v,k1:I,k2neg:P,k2:B}=D(g),{p1:L,p2:R}=Ri(x,y,I,B);return K(m.beta,L,R,v,P)}else return N.unsafe(y,g)}multiplyAndAddUnsafe(g,m,y){let v=this.multiplyUnsafe(m).add(g.multiplyUnsafe(y));return v.is0()?void 0:v}toAffine(g){return M(this,g)}isTorsionFree(){let{isTorsionFree:g}=t;return i===He?!0:g?g(x,this):N.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:g}=t;return i===He?this:g?g(x,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(g=!0){return qt(g,"isCompressed"),this.assertValidity(),h(x,this,g)}toHex(g=!0){return vt(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(g=!0){return this.toBytes(g)}_setWindowSize(g){this.precompute(g)}static normalizeZ(g){return Ft(x,g)}static msm(g,m){return Ue(x,o,g,m)}static fromPrivateKey(g){return x.BASE.multiply(qe(o,g))}}x.BASE=new x(s.Gx,s.Gy,n.ONE),x.ZERO=new x(n.ZERO,n.ONE,n.ZERO),x.Fp=n,x.Fn=o;let T=o.BITS,N=new Ne(x,t.endo?Math.ceil(T/2):T);return x.BASE.precompute(8),x}function sa(e){return Uint8Array.of(e?2:3)}function ia(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function gf(e,t={}){let{Fn:r}=e,n=t.randomBytes||te,o=Object.assign(ia(e.Fp,r),{seed:ho(r.ORDER)});function s(h){try{return!!qe(r,h)}catch{return!1}}function i(h,p){let{publicKey:E,publicKeyUncompressed:S}=o;try{let b=h.length;return p===!0&&b!==E||p===!1&&b!==S?!1:!!e.fromBytes(h)}catch{return!1}}function c(h=n(o.seed)){return po(xt(h,o.seed,"seed"),r.ORDER)}function a(h,p=!0){return e.BASE.multiply(qe(r,h)).toBytes(p)}function f(h){let p=c(h);return{secretKey:p,publicKey:a(p)}}function d(h){if(typeof h=="bigint")return!1;if(h instanceof e)return!0;let{secretKey:p,publicKey:E,publicKeyUncompressed:S}=o;if(r.allowedLengths||p===E)return;let b=H("key",h).length;return b===E||b===S}function l(h,p,E=!0){if(d(h)===!0)throw new Error("first arg must be private key");if(d(p)===!1)throw new Error("second arg must be public key");let S=qe(r,h);return e.fromHex(p).multiply(S).toBytes(E)}return Object.freeze({getPublicKey:a,getSharedSecret:l,keygen:f,Point:e,utils:{isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c,isValidPrivateKey:s,randomPrivateKey:c,normPrivateKeyToScalar:h=>qe(r,h),precompute(h=8,p=e.BASE){return p.precompute(h,!1)}},lengths:o})}function wf(e,t,r={}){Mr(t),se(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||te,o=r.hmac||((m,...y)=>os(t,m,ht(...y))),{Fp:s,Fn:i}=e,{ORDER:c,BITS:a}=i,{keygen:f,getPublicKey:d,getSharedSecret:l,utils:u,lengths:h}=gf(e,r),p={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},E="compact";function S(m){let y=c>>He;return m>y}function b(m,y){if(!i.isValidNot0(y))throw new Error(`invalid signature ${m}: out of range 1..Point.Fn.ORDER`);return y}function A(m,y){is(y);let v=h.signature,I=y==="compact"?v:y==="recovered"?v+1:void 0;return xt(m,I,`${y} signature`)}class w{constructor(y,v,I){this.r=b("r",y),this.s=b("s",v),I!=null&&(this.recovery=I),Object.freeze(this)}static fromBytes(y,v=E){A(y,v);let I;if(v==="der"){let{r:R,s:U}=Zt.toSig(xt(y));return new w(R,U)}v==="recovered"&&(I=y[0],v="compact",y=y.subarray(1));let P=i.BYTES,B=y.subarray(0,P),L=y.subarray(P,P*2);return new w(i.fromBytes(B),i.fromBytes(L),I)}static fromHex(y,v){return this.fromBytes(de(y),v)}addRecoveryBit(y){return new w(this.r,this.s,y)}recoverPublicKey(y){let v=s.ORDER,{r:I,s:P,recovery:B}=this;if(B==null||![0,1,2,3].includes(B))throw new Error("recovery id invalid");if(c*oa<v&&B>1)throw new Error("recovery id is ambiguous for h>1 curve");let R=B===2||B===3?I+c:I;if(!s.isValid(R))throw new Error("recovery id 2 or 3 invalid");let U=s.toBytes(R),$=e.fromBytes(ht(sa((B&1)===0),U)),V=i.inv(R),k=D(H("msgHash",y)),Y=i.create(-k*V),rt=i.create(P*V),mt=e.BASE.multiplyUnsafe(Y).add($.multiplyUnsafe(rt));if(mt.is0())throw new Error("point at infinify");return mt.assertValidity(),mt}hasHighS(){return S(this.s)}toBytes(y=E){if(is(y),y==="der")return de(Zt.hexFromSig(this));let v=i.toBytes(this.r),I=i.toBytes(this.s);if(y==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return ht(Uint8Array.of(this.recovery),v,I)}return ht(v,I)}toHex(y){return vt(this.toBytes(y))}assertValidity(){}static fromCompact(y){return w.fromBytes(H("sig",y),"compact")}static fromDER(y){return w.fromBytes(H("sig",y),"der")}normalizeS(){return this.hasHighS()?new w(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return vt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return vt(this.toBytes("compact"))}}let _=r.bits2int||function(y){if(y.length>8192)throw new Error("input is too large");let v=De(y),I=y.length*8-a;return I>0?v>>BigInt(I):v},D=r.bits2int_modN||function(y){return i.create(_(y))},M=oe(a);function O(m){return sr("num < 2^"+a,m,$t,M),i.toBytes(m)}function K(m,y){return xt(m,void 0,"message"),y?xt(t(m),void 0,"prehashed message"):m}function x(m,y,v){if(["recovered","canonical"].some(Y=>Y in v))throw new Error("sign() legacy options not supported");let{lowS:I,prehash:P,extraEntropy:B}=ss(v,p);m=K(m,P);let L=D(m),R=qe(i,y),U=[O(R),O(L)];if(B!=null&&B!==!1){let Y=B===!0?n(h.secretKey):B;U.push(H("extraEntropy",Y))}let $=ht(...U),V=L;function k(Y){let rt=_(Y);if(!i.isValidNot0(rt))return;let mt=i.inv(rt),X=e.BASE.multiply(rt).toAffine(),it=i.create(X.x);if(it===$t)return;let Tr=i.create(mt*i.create(V+it*R));if(Tr===$t)return;let vs=(X.x===it?0:2)|Number(X.y&He),As=Tr;return I&&S(Tr)&&(As=i.neg(Tr),vs^=1),new w(it,As,vs)}return{seed:$,k2sig:k}}function T(m,y,v={}){m=H("message",m);let{seed:I,k2sig:P}=x(m,y,v);return bi(t.outputLen,i.BYTES,o)(I,P)}function N(m){let y,v=typeof m=="string"||Ot(m),I=!v&&m!==null&&typeof m=="object"&&typeof m.r=="bigint"&&typeof m.s=="bigint";if(!v&&!I)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(I)y=new w(m.r,m.s);else if(v){try{y=w.fromBytes(H("sig",m),"der")}catch(P){if(!(P instanceof Zt.Err))throw P}if(!y)try{y=w.fromBytes(H("sig",m),"compact")}catch{return!1}}return y||!1}function C(m,y,v,I={}){let{lowS:P,prehash:B,format:L}=ss(I,p);if(v=H("publicKey",v),y=K(H("message",y),B),"strict"in I)throw new Error("options.strict was renamed to lowS");let R=L===void 0?N(m):w.fromBytes(H("sig",m),L);if(R===!1)return!1;try{let U=e.fromBytes(v);if(P&&R.hasHighS())return!1;let{r:$,s:V}=R,k=D(y),Y=i.inv(V),rt=i.create(k*Y),mt=i.create($*Y),X=e.BASE.multiplyUnsafe(rt).add(U.multiplyUnsafe(mt));return X.is0()?!1:i.create(X.x)===$}catch{return!1}}function g(m,y,v={}){let{prehash:I}=ss(v,p);return y=K(y,I),w.fromBytes(m,"recovered").recoverPublicKey(y).toBytes()}return Object.freeze({keygen:f,getPublicKey:d,getSharedSecret:l,utils:u,lengths:h,Point:e,sign:T,verify:C,recoverPublicKey:g,Signature:w,hash:t})}function xf(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,o=Et(t.n,{BITS:e.nBitLength,allowedLengths:n,modFromBytes:e.wrapPrivateKey}),s={Fp:r,Fn:o,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:s}}function Ef(e){let{CURVE:t,curveOpts:r}=xf(e),n={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,hash:e.hash,ecdsaOpts:n}}function Sf(e,t){let r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,Gr(r.Fn.ORDER,r.Fn.BITS))})}function aa(e){let{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:o}=Ef(e),s=bf(t,r),i=wf(s,n,o);return Sf(e,i)}function ca(e,t){let r=n=>aa({...e,hash:n});return{...r(t),create:r}}var us={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},vf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var ua=BigInt(2);function Af(e){let t=us.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),f=e*e*e%t,d=f*f*e%t,l=G(d,r,t)*d%t,u=G(l,r,t)*d%t,h=G(u,ua,t)*f%t,p=G(h,o,t)*h%t,E=G(p,s,t)*p%t,S=G(E,c,t)*E%t,b=G(S,a,t)*S%t,A=G(b,c,t)*E%t,w=G(A,r,t)*d%t,_=G(w,i,t)*p%t,D=G(_,n,t)*f%t,M=G(D,ua,t);if(!cs.eql(cs.sqr(M),e))throw new Error("Cannot find square root");return M}var cs=Et(us.p,{sqrt:Af}),Ve=ca({...us,Fp:cs,lowS:!0,endo:vf},Vr);function fa(e,t,r,n){let o=le.digest(r instanceof Uint8Array?r:r.subarray());if(Xr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ve.verify(t,s,e))).catch(s=>{throw s.name==="AbortError"?s:new ur(String(s))});try{return n?.signal?.throwIfAborted(),Ve.verify(t,o.digest,e)}catch(s){throw new ur(String(s))}}var un=class{type="secp256k1";raw;_key;constructor(t){this._key=ha(t),this.raw=la(this._key)}toMultihash(){return Bt.digest(Nt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,r,n){return fa(this._key,r,t,n)}};function fs(e){return new un(e)}function la(e){return Ve.ProjectivePoint.fromHex(e).toRawBytes(!0)}function ha(e){try{return Ve.ProjectivePoint.fromHex(e),e}catch(t){throw new Se(String(t))}}function ls(e,t){let{Type:r,Data:n}=Pt.decode(e),o=n??new Uint8Array;switch(r){case tt.RSA:return es(o,t);case tt.Ed25519:return Io(o);case tt.secp256k1:return fs(o);case tt.ECDSA:return Jn(o);default:throw new ue}}function da(e){let{Type:t,Data:r}=Pt.decode(e.digest),n=r??new Uint8Array;switch(t){case tt.Ed25519:return Io(n);case tt.secp256k1:return fs(n);case tt.ECDSA:return Jn(n);default:throw new ue}}function Nt(e){return Pt.encode({Type:tt[e.type],Data:e.raw})}var pa=Symbol.for("nodejs.util.inspect.custom"),If=114,pr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[An]=!0;toString(){return this.string==null&&(this.string=Z.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return at.createV1(If,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return bt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return bt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[pa](){return`PeerId(${this.toString()})`}},mr=class extends pr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},yr=class extends pr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},br=class extends pr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Bf=2336,fn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Bt.digest(F(this.url))}[pa](){return`PeerId(${this.url})`}[An]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1(Bf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=z(t)),t.toString()===this.toString())}};function hs(e){if(e.type==="Ed25519")return new yr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new br({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new mr({multihash:e.toCID().multihash,publicKey:e});throw new ue}function ma(e){return hs(e.publicKey)}function gr(e){if(_f(e))return new mr({multihash:e});if(Lf(e))try{let t=da(e);if(t.type==="Ed25519")return new yr({multihash:e,publicKey:t});if(t.type==="secp256k1")return new br({multihash:e,publicKey:t})}catch{let r=z(e.digest);return new fn(new URL(r))}throw new Dr("Supplied PeerID Multihash is invalid")}function Lf(e){return e.code===Bt.code}function _f(e){return e.code===le.code}function xe(e,t){let r={[Symbol.iterator]:()=>r,next:()=>{let n=e.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return r}function ln(e){let t=Wt(Z.decode(`z${e}`));return gr(t)}var wr=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[r,n]of t.entries())this.map.set(r.toString(),{key:r,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return xe(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((r,n)=>{t(r.value,r.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,r){this.map.set(t.toString(),{key:t,value:r})}keys(){return xe(this.map.values(),t=>t.key)}values(){return xe(this.map.values(),t=>t.value)}get size(){return this.map.size}};var xr=class e{set;constructor(t){if(this.set=new Set,t!=null)for(let r of t)this.set.add(r.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return xe(this.set.entries(),t=>{let r=ln(t[0]);return[r,r]})}forEach(t){this.set.forEach(r=>{let n=ln(r);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return xe(this.set.values(),t=>ln(t))}intersection(t){let r=new e;for(let n of t)this.has(n)&&r.add(n);return r}difference(t){let r=new e;for(let n of this)t.has(n)||r.add(n);return r}union(t){let r=new e;for(let n of t)r.add(n);for(let n of this)r.add(n);return r}};function Yt(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var hn=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},Fe=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new hn(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let r=this.head;this.head=r.next=new hn(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var ds=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function ze(e={}){return Tf(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},e)}function Tf(e,t){t=t??{};let r=t.onEnd,n=new Fe,o,s,i,c=Yt(),a=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((S,b)=>{s=A=>{s=null,n.push(A);try{S(e(n))}catch(w){b(w)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=Yt()})}},f=S=>s!=null?s(S):(n.push(S),o),d=S=>(n=new Fe,s!=null?s({error:S}):(n.push({error:S}),o)),l=S=>{if(i)return o;if(t?.objectMode!==!0&&S?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:S})},u=S=>i?o:(i=!0,S!=null?d(S):f({done:!0})),h=()=>(n=new Fe,u(),{done:!0}),p=S=>(u(S),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:a,return:h,throw:p,push:l,end:u,get readableLength(){return n.size},onEmpty:async S=>{let b=S?.signal;if(b?.throwIfAborted(),n.isEmpty())return;let A,w;b!=null&&(A=new Promise((_,D)=>{w=()=>{D(new ds)},b.addEventListener("abort",w)}));try{await Promise.race([c.promise,A])}finally{w!=null&&b!=null&&b?.removeEventListener("abort",w)}}},r==null)return o;let E=o;return o={[Symbol.asyncIterator](){return this},next(){return E.next()},throw(S){return E.throw(S),r!=null&&(r(S),r=void 0),{done:!0}},return(){return E.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(S){return E.end(S),r!=null&&(r(S),r=void 0),o},get readableLength(){return E.readableLength},onEmpty:S=>E.onEmpty(S)},o}var Er=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},ps=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},ya=e=>globalThis.DOMException===void 0?new ps(e):new DOMException(e),ba=e=>{let t=e.reason===void 0?ya("This operation was aborted."):e.reason;return t instanceof Error?t:ya(t)};function Sr(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,c,f=new Promise((d,l)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(t.signal){let{signal:h}=t;h.aborted&&l(ba(h)),c=()=>{l(ba(h))},h.addEventListener("abort",c,{once:!0})}if(r===Number.POSITIVE_INFINITY){e.then(d,l);return}let u=new Er;i=s.setTimeout.call(void 0,()=>{if(n){try{d(n())}catch(h){l(h)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?d():o instanceof Error?l(o):(u.message=o??`Promise timed out after ${r} milliseconds`,l(u))},r),(async()=>{try{d(await e)}catch(h){l(h)}})()}).finally(()=>{f.clear(),c&&t.signal&&t.signal.removeEventListener("abort",c)});return f.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},f}var Cf=e=>{let t=e.addEventListener||e.on||e.addListener,r=e.removeEventListener||e.off||e.removeListener;if(!t||!r)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(e),removeListener:r.bind(e)}};function Pf(e,t,r){let n,o=new Promise((s,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let c=[t].flat(),a=[],{addListener:f,removeListener:d}=Cf(e),l=(...h)=>{let p=r.multiArgs?h:h[0];r.filter&&!r.filter(p)||(a.push(p),r.count===a.length&&(n(),s(a)))},u=h=>{n(),i(h)};n=()=>{for(let h of c)d(h,l);for(let h of r.rejectionEvents)d(h,u)};for(let h of c)f(h,l);for(let h of r.rejectionEvents)f(h,u);r.signal&&r.signal.addEventListener("abort",()=>{u(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(a)});if(o.cancel=n,typeof r.timeout=="number"){let s=Sr(o,{milliseconds:r.timeout});return s.cancel=n,s}return o}function dn(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Pf(e,t,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}var pn=class extends Error{type;code;constructor(t,r,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=r??"ABORT_ERR"}};async function ga(e,t,r){if(t==null)return e;if(t.aborted)return e.catch(()=>{}),Promise.reject(new pn(r?.errorMessage,r?.errorCode,r?.errorName));let n,o=new pn(r?.errorMessage,r?.errorCode,r?.errorName);try{return await Promise.race([e,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var ms=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Yt(),this.haveNext=Yt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Yt(),t}async throw(t){return this.ended=!0,this.error=t,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return this.ended=!0,this.nextResult=t,this.haveNext.resolve(),t}async push(t,r){await this._push(t,r)}async end(t,r){t!=null?await this.throw(t):await this._push(void 0,r)}async _push(t,r){if(t!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Yt(),await ga(this.readNext.promise,r?.signal,r)}};function wa(){return new ms}function Df(e){return e[Symbol.asyncIterator]!=null}async function Rf(e,t,r){try{await Promise.all(e.map(async n=>{for await(let o of n)await t.push(o,{signal:r}),r.throwIfAborted()})),await t.end(void 0,{signal:r})}catch(n){await t.end(n,{signal:r}).catch(()=>{})}}async function*Kf(e){let t=new AbortController,r=wa();Rf(e,r,t.signal).catch(()=>{});try{yield*r}finally{t.abort()}}function*Nf(e){for(let t of e)yield*t}function Uf(...e){let t=[];for(let r of e)Df(r)||t.push(r);return t.length===e.length?Nf(t):Kf(e)}var xa=Uf;function mn(e,...t){if(e==null)throw new Error("Empty pipeline");if(ys(e)){let n=e;e=()=>n.source}else if(Sa(e)||Ea(e)){let n=e;e=()=>n}let r=[e,...t];if(r.length>1&&ys(r[r.length-1])&&(r[r.length-1]=r[r.length-1].sink),r.length>2)for(let n=1;n<r.length-1;n++)ys(r[n])&&(r[n]=Mf(r[n]));return Of(...r)}var Of=(...e)=>{let t;for(;e.length>0;)t=e.shift()(t);return t},Ea=e=>e?.[Symbol.asyncIterator]!=null,Sa=e=>e?.[Symbol.iterator]!=null,ys=e=>e==null?!1:e.sink!=null&&e.source!=null,Mf=e=>t=>{let r=e.sink(t);if(r?.then!=null){let n=ze({objectMode:!0});r.then(()=>{n.end()},i=>{n.end(i)});let o,s=e.source;if(Ea(s))o=async function*(){yield*s,n.end()};else if(Sa(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return xa(n,o())}return e.source};function kf(e){return e?.addEventListener!=null}function qf(e){let t=ze(),r,n=i=>{t.push(i.data)},o=()=>{t.end(),e.removeEventListener("message",n),e.removeEventListener("close",s),e.removeEventListener("remoteCloseWrite",o)},s=i=>{t.end(i.error),i.error!=null&&r?.reject(i.error),e.removeEventListener("message",n),e.removeEventListener("close",s),e.removeEventListener("remoteCloseWrite",o)};return e.addEventListener("message",n),e.addEventListener("close",s,{once:!0}),e.addEventListener("remoteCloseWrite",o,{once:!0}),{source:t,async sink(i){async function*c(){yield*i}let a=c();for(;;){r=Promise.withResolvers();let{done:f,value:d}=await Promise.race([a.next(),r.promise]);if(e.writeStatus==="closing"||e.writeStatus==="closed"||(d!=null&&(e.send(d)||await Promise.race([dn(e,"drain",{rejectionEvents:["close"]})])),f===!0))break}await e.close()}}}function bs(...e){let t=e.map(r=>kf(r)?qf(r):r);return mn(...t)}var yn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ge=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},bn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},vr=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function gn(e){return e[Symbol.asyncIterator]!=null}function va(e,t){if(e.byteLength>t)throw new Ge("Message length too long")}var xn=e=>{let t=It(e),r=ct(t);return Do(e,r),xn.bytes=t,r};xn.bytes=0;function En(e,t){t=t??{};let r=t.lengthEncoder??xn,n=t?.maxDataLength??4194304;function*o(s){va(s,n);let i=r(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return gn(e)?(async function*(){for await(let s of e)yield*o(s)})():(function*(){for(let s of e)yield*o(s)})()}En.single=(e,t)=>{t=t??{};let r=t.lengthEncoder??xn,n=t?.maxDataLength??4194304;return va(e,n),new et(r(e.byteLength),e)};var Ee;(function(e){e[e.LENGTH=0]="LENGTH",e[e.DATA=1]="DATA"})(Ee||(Ee={}));var gs=e=>{let t=Ro(e);return gs.bytes=It(t),t};gs.bytes=0;function Ar(e,t){let r=new et,n=Ee.LENGTH,o=-1,s=t?.lengthDecoder??gs,i=t?.maxLengthLength??8,c=t?.maxDataLength??4194304;function*a(){for(;r.byteLength>0;){if(n===Ee.LENGTH)try{if(o=s(r),o<0)throw new yn("Invalid message length");if(o>c)throw new Ge("Message length too long");let f=s.bytes;r.consume(f),t?.onLength!=null&&t.onLength(o),n=Ee.DATA}catch(f){if(f instanceof RangeError){if(r.byteLength>i)throw new bn("Message length length too long");break}throw f}if(n===Ee.DATA){if(r.byteLength<o)break;let f=r.sublist(0,o);r.consume(o),t?.onData!=null&&t.onData(f),yield f,n=Ee.LENGTH}}}return gn(e)?(async function*(){for await(let f of e)r.append(f),yield*a();if(r.byteLength>0)throw new vr("Unexpected end of input")})():(function*(){for(let f of e)r.append(f),yield*a();if(r.byteLength>0)throw new vr("Unexpected end of input")})()}Ar.fromReader=(e,t)=>{let r=1,n=(async function*(){for(;;)try{let{done:s,value:i}=await e.next(r);if(s===!0)return;i!=null&&(yield i)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{r=1}})();return Ar(n,{...t??{},onLength:s=>{r=s}})};var xs=qa(Ia(),1);function Es(e,t,r){let n=0,o=e.length;for(;o>0;){let s=Math.trunc(o/2),i=n+s;r(e[i],t)<=0?(n=++i,o-=s+1):o=s}return n}var Br=class{#t=[];enqueue(t,r){r={priority:0,...r};let n={priority:r.priority,id:r.id,run:t};if(this.size===0||this.#t[this.size-1].priority>=r.priority){this.#t.push(n);return}let o=Es(this.#t,n,(s,i)=>i.priority-s.priority);this.#t.splice(o,0,n)}setPriority(t,r){let n=this.#t.findIndex(s=>s.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[o]=this.#t.splice(n,1);this.enqueue(o.run,{priority:r,id:t})}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(r=>r.priority===t.priority).map(r=>r.run)}get size(){return this.#t.length}};var Lr=class extends xs.default{#t;#i;#s=0;#d;#a;#p=0;#r;#c;#e;#m;#n=0;#u;#o;#y;#w=1n;timeout;constructor(t){if(super(),t={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Br,...t},!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString()??""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString()??""}\` (${typeof t.interval})`);this.#t=t.carryoverConcurrencyCount,this.#i=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#d=t.intervalCap,this.#a=t.interval,this.#e=new t.queueClass,this.#m=t.queueClass,this.concurrency=t.concurrency,this.timeout=t.timeout,this.#y=t.throwOnTimeout===!0,this.#o=t.autoStart===!1}get#x(){return this.#i||this.#s<this.#d}get#E(){return this.#n<this.#u}#S(){this.#n--,this.#f(),this.emit("next")}#v(){this.#g(),this.#b(),this.#c=void 0}get#A(){let t=Date.now();if(this.#r===void 0){let r=this.#p-t;if(r<0)this.#s=this.#t?this.#n:0;else return this.#c===void 0&&(this.#c=setTimeout(()=>{this.#v()},r)),!0}return!1}#f(){if(this.#e.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#o){let t=!this.#A;if(this.#x&&this.#E){let r=this.#e.dequeue();return r?(this.emit("active"),r(),t&&this.#b(),!0):!1}}return!1}#b(){this.#i||this.#r!==void 0||(this.#r=setInterval(()=>{this.#g()},this.#a),this.#p=Date.now()+this.#a)}#g(){this.#s===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#t?this.#n:0,this.#l()}#l(){for(;this.#f(););}get concurrency(){return this.#u}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#u=t,this.#l()}async#I(t){return new Promise((r,n)=>{t.addEventListener("abort",()=>{n(t.reason)},{once:!0})})}setPriority(t,r){this.#e.setPriority(t,r)}async add(t,r={}){return r.id??=(this.#w++).toString(),r={timeout:this.timeout,throwOnTimeout:this.#y,...r},new Promise((n,o)=>{this.#e.enqueue(async()=>{this.#n++,this.#s++;try{r.signal?.throwIfAborted();let s=t({signal:r.signal});r.timeout&&(s=Sr(Promise.resolve(s),{milliseconds:r.timeout})),r.signal&&(s=Promise.race([s,this.#I(r.signal)]));let i=await s;n(i),this.emit("completed",i)}catch(s){if(s instanceof Er&&!r.throwOnTimeout){n();return}o(s),this.emit("error",s)}finally{this.#S()}},r),this.emit("add"),this.#f()})}async addAll(t,r){return Promise.all(t.map(async n=>this.add(n,r)))}start(){return this.#o?(this.#o=!1,this.#l(),this):this}pause(){this.#o=!0}clear(){this.#e=new this.#m}async onEmpty(){this.#e.size!==0&&await this.#h("empty")}async onSizeLessThan(t){this.#e.size<t||await this.#h("next",()=>this.#e.size<t)}async onIdle(){this.#n===0&&this.#e.size===0||await this.#h("idle")}async#h(t,r){return new Promise(n=>{let o=()=>{r&&!r()||(this.off(t,o),n())};this.on(t,o)})}get size(){return this.#e.size}sizeBy(t){return this.#e.filter(t).length}get pending(){return this.#n}get isPaused(){return this.#o}};var vn=class extends ve{id;protocol;outboundStream;inboundStream;_rawOutboundStream;_rawInboundStream;_inboundAbortController;closed;log;constructor(t,r){super(),this.log=t.logger.forComponent("libp2p-pubsub:peer-streams"),this.id=r.id,this.protocol=r.protocol,this._inboundAbortController=new AbortController,this.closed=!1}get isReadable(){return!!this.inboundStream}get isWritable(){return!!this.outboundStream}write(t){if(this.outboundStream==null){let r=this.id.toString();throw new Error("No writable connection to "+r)}this.outboundStream.push(t instanceof Uint8Array?new et(t):t)}attachInboundStream(t,r){let n=()=>{t.abort(new Pr)};return this._inboundAbortController.signal.addEventListener("abort",n,{once:!0}),this._rawInboundStream=t,this.inboundStream=bs(this._rawInboundStream,o=>Ar(o,r)),this.dispatchEvent(new CustomEvent("stream:inbound")),this.inboundStream}async attachOutboundStream(t){let r=this.outboundStream;return this.outboundStream!=null&&this.outboundStream.end(),this._rawOutboundStream=t,this.outboundStream=ze({onEnd:n=>{this._rawOutboundStream?.close().catch(o=>{this.log("error closing outbound stream",o)}),this._rawOutboundStream=void 0,this.outboundStream=void 0,n!=null&&this.dispatchEvent(new CustomEvent("close"))}}),bs(this.outboundStream,n=>En(n),async n=>{for await(let o of n)t.send(o)===!1&&await dn(t,"drain",{rejectionEvents:["close"]})}).catch(n=>{this.log.error(n)}),r==null&&this.dispatchEvent(new CustomEvent("stream:outbound")),this.outboundStream}close(){this.closed||(this.closed=!0,this.outboundStream!=null&&this.outboundStream.end(),this.inboundStream!=null&&this._inboundAbortController.abort(),this._rawOutboundStream=void 0,this.outboundStream=void 0,this._rawInboundStream=void 0,this.inboundStream=void 0,this.dispatchEvent(new CustomEvent("close")))}};function Ba(){return BigInt(`0x${z(on(8),"base16")}`)}var La=(e,t)=>{let r=F(t.toString(16).padStart(16,"0"),"base16"),n=Nt(e),o=new Uint8Array(n.byteLength+r.length);return o.set(n,0),o.set(r,n.byteLength),o},_a=e=>le.encode(e);var Ta=function(e){return Array.isArray(e)?e:[e]},Gf=async e=>{if(e.sequenceNumber==null||e.from==null||e.signature==null)return!1;let t=gr(Wt(e.from));if(t.publicKey!=null)return!0;if(e.key!=null){let r=e.key;return hs(ls(r)).equals(t)}return!1},Ca=async e=>{if(e.from==null)throw new Q("RPC message was missing from");if(!await Gf(e))return{type:"unsigned",topic:e.topic??"",data:e.data??new Uint8Array(0)};let t=gr(Wt(e.from)),r=e.key??t.publicKey;if(r==null)throw new Q("RPC message was missing public key");return{type:"signed",from:t,topic:e.topic??"",sequenceNumber:Zf(e.sequenceNumber??new Uint8Array(0)),data:e.data??new Uint8Array(0),signature:e.signature??new Uint8Array(0),key:r instanceof Uint8Array?ls(r):r}},_r=e=>e.type==="signed"?{from:e.from.toMultihash().bytes,data:e.data,sequenceNumber:jf(e.sequenceNumber),topic:e.topic,signature:e.signature,key:e.key?Nt(e.key):void 0}:{data:e.data,topic:e.topic},jf=e=>{let t=e.toString(16);return t.length%2!==0&&(t=`0${t}`),F(t,"base16")},Zf=e=>BigInt(`0x${z(e,"base16")}`);var Pa=F("libp2p-pubsub:");async function Da(e,t,r){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:ma(e)},o=fe([Pa,r(_r(n)).subarray()]);return n.signature=await e.sign(o),n.key=e.publicKey,n}async function Ra(e,t){if(e.type!=="signed")throw new Error('Message type must be "signed" to be verified');if(e.signature==null)throw new Error("Message must contain a signature to be verified");if(e.from==null)throw new Error("Message must contain a from property to be verified");let r=fe([Pa,t({..._r(e),signature:void 0,key:void 0}).subarray()]);return $f(e).verify(r,e.signature)}function $f(e){if(e.type!=="signed")throw new Error('Message type must be "signed" to have a public key');if(e.from==null)throw new Error("Could not get the public key from the originator id");if(e.key!=null)return e.key;if(e.from.publicKey!=null)return e.from.publicKey;throw new Error("Could not get the public key from the originator id")}var Ss=class extends ve{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;multicodecs;components;_registrarTopologyIds;enabled;maxInboundStreams;maxOutboundStreams;constructor(t,r){super();let{multicodecs:n=[],globalSignaturePolicy:o="StrictSign",canRelayMessage:s=!1,emitSelf:i=!1,messageProcessingConcurrency:c=10,maxInboundStreams:a=1,maxOutboundStreams:f=1}=r;this.log=t.logger.forComponent("libp2p:pubsub"),this.components=t,this.multicodecs=Ta(n),this.enabled=r.enabled!==!1,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new wr,this.globalSignaturePolicy=o==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=s,this.emitSelf=i,this.topicValidators=new Map,this.queue=new Lr({concurrency:c}),this.maxInboundStreams=a,this.maxOutboundStreams=f,this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}async start(){if(this.started||!this.enabled)return;this.log("starting");let t=this.components.registrar;await Promise.all(this.multicodecs.map(async n=>{await t.handle(n,this._onIncomingStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams})}));let r={onConnect:this._onPeerConnected,onDisconnect:this._onPeerDisconnected};this._registrarTopologyIds=await Promise.all(this.multicodecs.map(async n=>t.register(n,r))),this.log("started"),this.started=!0}async stop(){if(!this.started||!this.enabled)return;let t=this.components.registrar;this._registrarTopologyIds!=null&&this._registrarTopologyIds?.forEach(r=>{t.unregister(r)}),await Promise.all(this.multicodecs.map(async r=>{await t.unhandle(r)})),this.log("stopping");for(let r of this.peers.values())r.close();this.peers.clear(),this.subscriptions=new Set,this.started=!1,this.log("stopped")}isStarted(){return this.started}_onIncomingStream(t,r){let n=r.remotePeer;if(t.protocol==null){t.abort(new Error("Stream was not multiplexed"));return}let o=this.addPeer(n,t.protocol),s=o.attachInboundStream(t);this.processMessages(n,s,o).catch(i=>{this.log(i)})}async _onPeerConnected(t,r){if(this.log("connected %p",t),r.streams.find(s=>s.direction==="outbound"&&s.protocol!=null&&this.multicodecs.includes(s.protocol))!=null){this.log("outbound pubsub streams already present on connection from %p",t);return}let n=await r.newStream(this.multicodecs);if(n.protocol==null){n.abort(new Error("Stream was not multiplexed"));return}await this.addPeer(t,n.protocol).attachOutboundStream(n),this.send(t,{subscriptions:Array.from(this.subscriptions).map(s=>s.toString()),subscribe:!0})}_onPeerDisconnected(t,r){this.log("connection ended %p",t),this._removePeer(t)}addPeer(t,r){let n=this.peers.get(t);if(n!=null)return n;this.log("new peer %p",t);let o=new vn(this.components,{id:t,protocol:r});return this.peers.set(t,o),o.addEventListener("close",()=>this._removePeer(t),{once:!0}),o}_removePeer(t){let r=this.peers.get(t);if(r!=null){r.close(),this.log("delete peer %p",t),this.peers.delete(t);for(let n of this.topics.values())n.delete(t);return r}}async processMessages(t,r,n){try{await mn(r,async o=>{for await(let s of o){let i=this.decodeRpc(s),c=[];for(let a of i.messages??[]){if(a.from==null||a.data==null||a.topic==null){this.log("message from %p was missing from, data or topic fields, dropping",t);continue}c.push({from:a.from,data:a.data,topic:a.topic,sequenceNumber:a.sequenceNumber??void 0,signature:a.signature??void 0,key:a.key??void 0})}this.processRpc(t,n,{subscriptions:(i.subscriptions??[]).map(a=>({subscribe:!!a.subscribe,topic:a.topic??""})),messages:c}).catch(a=>{this.log(a)})}})}catch(o){this._onPeerDisconnected(n.id,o)}}async processRpc(t,r,n){if(!this.acceptFrom(t))return this.log("received message from unacceptable peer %p",t),!1;this.log("rpc from %p",t);let{subscriptions:o,messages:s}=n;return o!=null&&o.length>0&&(this.log("subscription update from %p",t),o.forEach(i=>{this.processRpcSubOpt(t,i)}),super.dispatchEvent(new CustomEvent("subscription-change",{detail:{peerId:r.id,subscriptions:o.map(({topic:i,subscribe:c})=>({topic:`${i??""}`,subscribe:!!c}))}}))),s!=null&&s.length>0&&(this.log("messages from %p",t),this.queue.addAll(s.map(i=>async()=>{if(i.topic==null||!this.subscriptions.has(i.topic)&&!this.canRelayMessage)return this.log("received message we didn't subscribe to. Dropping."),!1;try{let c=await Ca(i);await this.processMessage(t,c)}catch(c){this.log.error(c)}})).catch(i=>{this.log(i)})),!0}processRpcSubOpt(t,r){let n=r.topic;if(n==null)return;let o=this.topics.get(n);o==null&&(o=new xr,this.topics.set(n,o)),r.subscribe===!0?o.add(t):o.delete(t)}async processMessage(t,r){if(!(this.components.peerId.equals(t)&&!this.emitSelf)){try{await this.validate(t,r)}catch(n){this.log("Message is invalid, dropping it. %O",n);return}this.subscriptions.has(r.topic)&&(!this.components.peerId.equals(t)||this.emitSelf)&&super.dispatchEvent(new CustomEvent("message",{detail:r})),await this.publishMessage(t,r)}}getMsgId(t){switch(this.globalSignaturePolicy){case"StrictSign":if(t.type!=="signed")throw new Q('Message type should be "signed" when signature policy is StrictSign but it was not');if(t.sequenceNumber==null)throw new Q("Need sequence number when signature policy is StrictSign but it was missing");if(t.key==null)throw new Q("Need key when signature policy is StrictSign but it was missing");return La(t.key,t.sequenceNumber);case"StrictNoSign":return _a(t.data);default:throw new Q("Cannot get message id: unhandled signature policy")}}acceptFrom(t){return!0}send(t,r){let{messages:n,subscriptions:o,subscribe:s}=r;this.sendRpc(t,{subscriptions:(o??[]).map(i=>({topic:i,subscribe:!!s})),messages:(n??[]).map(_r)})}sendRpc(t,r){let n=this.peers.get(t);if(n==null){this.log.error("Cannot send RPC to %p as there are no streams to it available",t);return}if(!n.isWritable){this.log.error("Cannot send RPC to %p as there is no outbound stream to it available",t);return}n.write(this.encodeRpc(r))}async validate(t,r){switch(this.globalSignaturePolicy){case"StrictNoSign":if(r.type!=="unsigned")throw new Q('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(r.signature!=null)throw new Q("StrictNoSigning: signature should not be present");if(r.key!=null)throw new Q("StrictNoSigning: key should not be present");if(r.sequenceNumber!=null)throw new Q("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(r.type!=="signed")throw new Q('Message type should be "signed" when signature policy is StrictSign but it was not');if(r.signature==null)throw new Q("StrictSigning: Signing required and no signature was present");if(r.sequenceNumber==null)throw new Q("StrictSigning: Signing required and no sequenceNumber was present");if(!await Ra(r,this.encodeMessage.bind(this)))throw new Q("StrictSigning: Invalid message signature");break;default:throw new Q("Cannot validate message: unhandled signature policy")}let o=this.topicValidators.get(r.topic);if(o!=null){let s=await o(t,r);if(s===je.Reject||s===je.Ignore)throw new Q("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return Da(this.components.privateKey,t,this.encodeMessage.bind(this));case"StrictNoSign":return Promise.resolve({type:"unsigned",...t});default:throw new Q("Cannot build message: unhandled signature policy")}}getSubscribers(t){if(!this.started)throw new Rr("not started yet");if(t==null)throw new j("Topic is required");let r=this.topics.get(t.toString());return r==null?[]:Array.from(r.values())}async publish(t,r){if(!this.started)throw new Error("Pubsub has not started");let n={from:this.components.peerId,topic:t,data:r??new Uint8Array(0),sequenceNumber:Ba()};this.log("publish topic: %s from: %p data: %m",t,n.from,n.data);let o=await this.buildMessage(n),s=!1;this.emitSelf&&this.subscriptions.has(t)&&(s=!0,super.dispatchEvent(new CustomEvent("message",{detail:o})));let i=await this.publishMessage(this.components.peerId,o);return s&&(i.recipients=[...i.recipients,this.components.peerId]),i}subscribe(t){if(!this.started)throw new Error("Pubsub has not started");if(this.log("subscribe to topic: %s",t),!this.subscriptions.has(t)){this.subscriptions.add(t);for(let r of this.peers.keys())this.send(r,{subscriptions:[t],subscribe:!0})}}unsubscribe(t){if(!this.started)throw new Error("Pubsub is not started");super.removeEventListener(t);let r=this.subscriptions.has(t);if(this.log("unsubscribe from %s - am subscribed %s",t,r),r){this.subscriptions.delete(t);for(let n of this.peers.keys())this.send(n,{subscriptions:[t],subscribe:!1})}}getTopics(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.subscriptions)}getPeers(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.peers.keys())}};return Ha(Yf);})();
|
2
|
+
"use strict";var Libp2PPubsub=(()=>{var Ra=Object.create;var Tr=Object.defineProperty;var Na=Object.getOwnPropertyDescriptor;var Ua=Object.getOwnPropertyNames;var ka=Object.getPrototypeOf,Ma=Object.prototype.hasOwnProperty;var Oa=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),yt=(e,t)=>{for(var r in t)Tr(e,r,{get:t[r],enumerable:!0})},ws=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ua(t))!Ma.call(e,o)&&o!==r&&Tr(e,o,{get:()=>t[o],enumerable:!(n=Na(t,o))||n.enumerable});return e};var qa=(e,t,r)=>(r=e!=null?Ra(ka(e)):{},ws(t||!e||!e.__esModule?Tr(r,"default",{value:e,enumerable:!0}):r,e)),Ha=e=>ws(Tr({},"__esModule",{value:!0}),e);var wa=Oa((Sm,fs)=>{"use strict";var kf=Object.prototype.hasOwnProperty,pt="~";function Er(){}Object.create&&(Er.prototype=Object.create(null),new Er().__proto__||(pt=!1));function Mf(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function ga(e,t,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var s=new Mf(r,n||e,o),i=pt?pt+t:t;return e._events[i]?e._events[i].fn?e._events[i]=[e._events[i],s]:e._events[i].push(s):(e._events[i]=s,e._eventsCount++),e}function dn(e,t){--e._eventsCount===0?e._events=new Er:delete e._events[t]}function lt(){this._events=new Er,this._eventsCount=0}lt.prototype.eventNames=function(){var t=[],r,n;if(this._eventsCount===0)return t;for(n in r=this._events)kf.call(r,n)&&t.push(pt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(r)):t};lt.prototype.listeners=function(t){var r=pt?pt+t:t,n=this._events[r];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};lt.prototype.listenerCount=function(t){var r=pt?pt+t:t,n=this._events[r];return n?n.fn?1:n.length:0};lt.prototype.emit=function(t,r,n,o,s,i){var c=pt?pt+t:t;if(!this._events[c])return!1;var a=this._events[c],f=arguments.length,p,l;if(a.fn){switch(a.once&&this.removeListener(t,a.fn,void 0,!0),f){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,r),!0;case 3:return a.fn.call(a.context,r,n),!0;case 4:return a.fn.call(a.context,r,n,o),!0;case 5:return a.fn.call(a.context,r,n,o,s),!0;case 6:return a.fn.call(a.context,r,n,o,s,i),!0}for(l=1,p=new Array(f-1);l<f;l++)p[l-1]=arguments[l];a.fn.apply(a.context,p)}else{var u=a.length,h;for(l=0;l<u;l++)switch(a[l].once&&this.removeListener(t,a[l].fn,void 0,!0),f){case 1:a[l].fn.call(a[l].context);break;case 2:a[l].fn.call(a[l].context,r);break;case 3:a[l].fn.call(a[l].context,r,n);break;case 4:a[l].fn.call(a[l].context,r,n,o);break;default:if(!p)for(h=1,p=new Array(f-1);h<f;h++)p[h-1]=arguments[h];a[l].fn.apply(a[l].context,p)}}return!0};lt.prototype.on=function(t,r,n){return ga(this,t,r,n,!1)};lt.prototype.once=function(t,r,n){return ga(this,t,r,n,!0)};lt.prototype.removeListener=function(t,r,n,o){var s=pt?pt+t:t;if(!this._events[s])return this;if(!r)return dn(this,s),this;var i=this._events[s];if(i.fn)i.fn===r&&(!o||i.once)&&(!n||i.context===n)&&dn(this,s);else{for(var c=0,a=[],f=i.length;c<f;c++)(i[c].fn!==r||o&&!i[c].once||n&&i[c].context!==n)&&a.push(i[c]);a.length?this._events[s]=a.length===1?a[0]:a:dn(this,s)}return this};lt.prototype.removeAllListeners=function(t){var r;return t?(r=pt?pt+t:t,this._events[r]&&dn(this,r)):(this._events=new Er,this._eventsCount=0),this};lt.prototype.off=lt.prototype.removeListener;lt.prototype.addListener=lt.prototype.on;lt.prefixed=pt;lt.EventEmitter=lt;typeof fs<"u"&&(fs.exports=lt)});var Gf={};yt(Gf,{PubSubBaseProtocol:()=>ys});var En=Symbol.for("@libp2p/peer-id");var Ge;(function(e){e.Accept="accept",e.Ignore="ignore",e.Reject="reject"})(Ge||(Ge={}));var Yf=Symbol.for("@libp2p/pubsub");var Z=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Se=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Cr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Q=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var Dr=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var ue=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var ve=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){super.addEventListener(t,r,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,r,n){super.removeEventListener(t.toString(),r??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==r),this.#t.set(t,o))}dispatchEvent(t){let r=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),r}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var In={};yt(In,{base58btc:()=>j,base58flickr:()=>Ya});var Jf=new Uint8Array(0);function xs(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Pt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Es(e){return new TextEncoder().encode(e)}function Ss(e){return new TextDecoder().decode(e)}function Va(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var c=e.length,a=e.charAt(0),f=Math.log(c)/Math.log(256),p=Math.log(256)/Math.log(c);function l(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var E=0,S=0,b=0,A=d.length;b!==A&&d[b]===0;)b++,E++;for(var w=(A-b)*p+1>>>0,L=new Uint8Array(w);b!==A;){for(var P=d[b],M=0,k=w-1;(P!==0||M<S)&&k!==-1;k--,M++)P+=256*L[k]>>>0,L[k]=P%c>>>0,P=P/c>>>0;if(P!==0)throw new Error("Non-zero carry");S=M,b++}for(var R=w-S;R!==w&&L[R]===0;)R++;for(var x=a.repeat(E);R<w;++R)x+=e.charAt(L[R]);return x}function u(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var E=0;if(d[E]!==" "){for(var S=0,b=0;d[E]===a;)S++,E++;for(var A=(d.length-E)*f+1>>>0,w=new Uint8Array(A);d[E];){var L=r[d.charCodeAt(E)];if(L===255)return;for(var P=0,M=A-1;(L!==0||P<b)&&M!==-1;M--,P++)L+=c*w[M]>>>0,w[M]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");b=P,E++}if(d[E]!==" "){for(var k=A-b;k!==A&&w[k]===0;)k++;for(var R=new Uint8Array(S+(A-k)),x=S;k!==A;)R[x++]=w[k++];return R}}}function h(d){var E=u(d);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:u,decode:h}}var Fa=Va,za=Fa,As=za;var Sn=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},vn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Bs(this,t)}},An=class{decoders;constructor(t){this.decoders=t}or(t){return Bs(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Bs(e,t){return new An({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Bn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Sn(t,r,n),this.decoder=new vn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ae({name:e,prefix:t,encode:r,decode:n}){return new Bn(e,t,r,n)}function Xt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=As(r,e);return Ae({prefix:t,name:e,encode:n,decode:s=>Pt(o(s))})}function Ga(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,c=0,a=0;for(let f=0;f<o;++f){let p=t[e[f]];if(p===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|p,i+=r,i>=8&&(i-=8,s[a++]=255&c>>i)}if(i>=r||(255&c<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Za(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,c=0;for(let a=0;a<e.length;++a)for(c=c<<8|e[a],i+=8;i>r;)i-=r,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function ja(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function W({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=ja(n);return Ae({prefix:t,name:e,encode(s){return Za(s,n,r)},decode(s){return Ga(s,o,r,e)}})}var j=Xt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ya=Xt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var _n={};yt(_n,{base32:()=>Be,base32hex:()=>Ja,base32hexpad:()=>tc,base32hexpadupper:()=>ec,base32hexupper:()=>Qa,base32pad:()=>Xa,base32padupper:()=>Wa,base32upper:()=>$a,base32z:()=>rc});var Be=W({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),$a=W({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Xa=W({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Wa=W({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ja=W({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Qa=W({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),tc=W({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ec=W({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),rc=W({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ln={};yt(Ln,{base36:()=>Ze,base36upper:()=>nc});var Ze=Xt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),nc=Xt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var oc=Ls,Is=128,sc=127,ic=~sc,ac=Math.pow(2,31);function Ls(e,t,r){t=t||[],r=r||0;for(var n=r;e>=ac;)t[r++]=e&255|Is,e/=128;for(;e⁣)t[r++]=e&255|Is,e>>>=7;return t[r]=e|0,Ls.bytes=r-n+1,t}var cc=Tn,uc=128,_s=127;function Tn(e,n){var r=0,n=n||0,o=0,s=n,i,c=e.length;do{if(s>=c)throw Tn.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&_s)<<o:(i&_s)*Math.pow(2,o),o+=7}while(i>=uc);return Tn.bytes=s-n,r}var fc=Math.pow(2,7),lc=Math.pow(2,14),hc=Math.pow(2,21),dc=Math.pow(2,28),pc=Math.pow(2,35),mc=Math.pow(2,42),yc=Math.pow(2,49),bc=Math.pow(2,56),gc=Math.pow(2,63),wc=function(e){return e<fc?1:e<lc?2:e<hc?3:e<dc?4:e<pc?5:e<mc?6:e<yc?7:e<bc?8:e<gc?9:10},xc={encode:oc,decode:cc,encodingLength:wc},Ec=xc,je=Ec;function Ye(e,t=0){return[je.decode(e,t),je.decode.bytes]}function Ie(e,t,r=0){return je.encode(e,t,r),t}function _e(e){return je.encodingLength(e)}function Tt(e,t){let r=t.byteLength,n=_e(e),o=n+_e(r),s=new Uint8Array(o+r);return Ie(e,s,0),Ie(r,s,n),s.set(t,o),new Le(e,r,t,s)}function Wt(e){let t=Pt(e),[r,n]=Ye(t),[o,s]=Ye(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Le(r,o,i,t)}function Ts(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&xs(e.bytes,r.bytes)}}var Le=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Cs(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return vc(r,Cn(e),t??j.encoder);default:return Ac(r,Cn(e),t??Be.encoder)}}var Ds=new WeakMap;function Cn(e){let t=Ds.get(e);if(t==null){let r=new Map;return Ds.set(e,r),r}return t}var at=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==$e)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Bc)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=Tt(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&Ts(t.multihash,n.multihash)}toString(t){return Cs(this,t)}toJSON(){return{"/":Cs(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??Ps(n,o,s.bytes))}else if(r[Ic]===!0){let{version:n,multihash:o,code:s}=r,i=Wt(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==$e)throw new Error(`Version 0 CID must use dag-pb (code: ${$e}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Ps(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,$e,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Pt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Le(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,u]=Ye(t.subarray(r));return r+=u,l},o=n(),s=$e;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,c=n(),a=n(),f=r+a,p=f-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:p,size:f}}static parse(t,r){let[n,o]=Sc(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Cn(s).set(n,t),s}};function Sc(e,t){switch(e[0]){case"Q":{let r=t??j;return[j.prefix,r.decode(`${j.prefix}${e}`)]}case j.prefix:{let r=t??j;return[j.prefix,r.decode(e)]}case Be.prefix:{let r=t??Be;return[Be.prefix,r.decode(e)]}case Ze.prefix:{let r=t??Ze;return[Ze.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function vc(e,t,r){let{prefix:n}=r;if(n!==j.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function Ac(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var $e=112,Bc=18;function Ps(e,t,r){let n=_e(e),o=n+_e(t),s=new Uint8Array(o+r.byteLength);return Ie(e,s,0),Ie(t,s,n),s.set(r,o),s}var Ic=Symbol.for("@ipld/js-cid/CID");var Dn={};yt(Dn,{identity:()=>Bt});var Ks=0,_c="identity",Rs=Pt;function Lc(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Tt(Ks,Rs(e))}var Bt={code:Ks,name:_c,encode:Rs,digest:Lc};function bt(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Kt(e=0){return new Uint8Array(e)}function ct(e=0){return new Uint8Array(e)}function fe(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=ct(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Us=Symbol.for("@achingbrain/uint8arraylist");function Ns(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function Kr(e){return!!e?.[Us]}var rt=class e{bufs;length;[Us]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Kr(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Kr(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=Ns(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Ns(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(Kr(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return fe(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:fe(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let f=t>=c&&t<a,p=r>c&&r<=a;if(f&&p){if(t===c&&r===a){n.push(i);break}let l=t-c;n.push(i.subarray(l,l+(r-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(p){if(r===a){n.push(i);break}n.push(i.subarray(0,r-c));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Kr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let 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 l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let c=i,a=this.byteLength-n.byteLength,f=n.byteLength-1,p;for(let l=r;l<=a;l+=p){p=0;for(let u=f;u>=0;u--){let h=this.get(l+u);if(n[u]!==h){p=Math.max(1,u-c[h]);break}}if(p===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=ct(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=Kt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=Kt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=Kt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=ct(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=Kt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=Kt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=Kt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=Kt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=Kt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!bt(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var Pn={};yt(Pn,{base10:()=>Tc});var Tc=Xt({prefix:"9",name:"base10",alphabet:"0123456789"});var Kn={};yt(Kn,{base16:()=>Cc,base16upper:()=>Dc});var Cc=W({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Dc=W({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Rn={};yt(Rn,{base2:()=>Pc});var Pc=W({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Nn={};yt(Nn,{base256emoji:()=>kc});var ks=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}"),Kc=ks.reduce((e,t,r)=>(e[r]=t,e),[]),Rc=ks.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Nc(e){return e.reduce((t,r)=>(t+=Kc[r],t),"")}function Uc(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Rc[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var kc=Ae({prefix:"\u{1F680}",name:"base256emoji",encode:Nc,decode:Uc});var Un={};yt(Un,{base64:()=>Mc,base64pad:()=>Oc,base64url:()=>qc,base64urlpad:()=>Hc});var Mc=W({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Oc=W({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),qc=W({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Hc=W({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var kn={};yt(kn,{base8:()=>Vc});var Vc=W({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Mn={};yt(Mn,{identity:()=>Fc});var Fc=Ae({prefix:"\0",name:"identity",encode:e=>Ss(e),decode:e=>Es(e)});var Nl=new TextEncoder,Ul=new TextDecoder;var Hn={};yt(Hn,{sha256:()=>le,sha512:()=>jc});var Zc=20;function qn({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new On(e,t,r,n,o)}var On=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Zc,this.maxDigestLength=s}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Ms(n,this.code,r?.truncate):n.then(o=>Ms(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ms(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Tt(t,e)}function qs(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var le=qn({name:"sha2-256",code:18,encode:qs("SHA-256")}),jc=qn({name:"sha2-512",code:19,encode:qs("SHA-512")});var Vn={...Mn,...Rn,...kn,...Pn,...Kn,..._n,...Ln,...In,...Un,...Nn},Yl={...Hn,...Dn};function Vs(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Hs=Vs("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Fn=Vs("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=ct(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Yc={utf8:Hs,"utf-8":Hs,hex:Vn.base16,latin1:Fn,ascii:Fn,binary:Fn,...Vn},Rr=Yc;function F(e,t="utf8"){let r=Rr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function z(e,t="utf8"){let r=Rr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var $c=parseInt("11111",2),zn=parseInt("10000000",2),Xc=parseInt("01111111",2),Fs={0:Xe,1:Xe,2:Wc,3:tu,4:eu,5:Qc,6:Jc,16:Xe,22:Xe,48:Xe};function Rt(e,t={offset:0}){let r=e[t.offset]&$c;if(t.offset++,Fs[r]!=null)return Fs[r](e,t);throw new Error("No decoder for tag "+r)}function We(e,t){let r=0;if((e[t.offset]&zn)===zn){let n=e[t.offset]&Xc,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function Xe(e,t){We(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Rt(e,t);if(n===null)break;r.push(n)}return r}function Wc(e,t){let r=We(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function Jc(e,t){let r=We(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let c=`${s}.${i}`,a=[];for(;t.offset<n;){let f=e[t.offset];if(t.offset++,a.push(f&127),f<128){a.reverse();let p=0;for(let l=0;l<a.length;l++)p+=a[l]<<l*7;c+=`.${p}`,a=[]}}return c}function Qc(e,t){return t.offset++,null}function tu(e,t){let r=We(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function eu(e,t){let r=We(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function ru(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new rt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Gn(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=ru(e.byteLength);return new rt(Uint8Array.from([t.byteLength|zn]),t)}function gt(e){let t=new rt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new rt(Uint8Array.from([2]),Gn(t),t)}function Nr(e){let t=Uint8Array.from([0]),r=new rt(t,e);return new rt(Uint8Array.from([3]),Gn(r),r)}function Qt(e,t=48){let r=new rt;for(let n of e)r.append(n);return new rt(Uint8Array.from([t]),Gn(r),r)}async function zs(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),s}var nu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),ou=Uint8Array.from([6,5,43,129,4,0,34]),su=Uint8Array.from([6,5,43,129,4,0,35]),iu={ext:!0,kty:"EC",crv:"P-256"},au={ext:!0,kty:"EC",crv:"P-384"},cu={ext:!0,kty:"EC",crv:"P-521"},Zn=32,jn=48,Yn=66;function $n(e){let t=Rt(e);return Gs(t)}function Gs(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Zn*2+1)return n=z(t.subarray(r,r+Zn),"base64url"),o=z(t.subarray(r+Zn),"base64url"),new Te({...iu,key_ops:["verify"],x:n,y:o});if(t.byteLength===jn*2+1)return n=z(t.subarray(r,r+jn),"base64url"),o=z(t.subarray(r+jn),"base64url"),new Te({...au,key_ops:["verify"],x:n,y:o});if(t.byteLength===Yn*2+1)return n=z(t.subarray(r,r+Yn),"base64url"),o=z(t.subarray(r+Yn),"base64url"),new Te({...cu,key_ops:["verify"],x:n,y:o});throw new Z(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Zs(e){return Qt([gt(Uint8Array.from([1])),Qt([uu(e.crv)],160),Qt([Nr(new rt(Uint8Array.from([4]),F(e.x??"","base64url"),F(e.y??"","base64url")))],161)]).subarray()}function uu(e){if(e==="P-256")return nu;if(e==="P-384")return ou;if(e==="P-521")return su;throw new Z(`Invalid curve ${e}`)}var Te=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Zs(this.jwk)),this._raw}toMultihash(){return Bt.digest(Nt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}async verify(t,r,n){return zs(this.jwk,r,t,n)}};var he=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function kt(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Je(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function wt(e,...t){if(!kt(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Ur(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Je(e.outputLen),Je(e.blockLen)}function De(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Ys(e,t){wt(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Mt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function kr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function It(e,t){return e<<32-t|e>>>t}var $s=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",fu=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function vt(e){if(wt(e),$s)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=fu[e[r]];return t}var Ut={_0:48,_9:57,A:65,F:70,a:97,f:102};function js(e){if(e>=Ut._0&&e<=Ut._9)return e-Ut._0;if(e>=Ut.A&&e<=Ut.F)return e-(Ut.A-10);if(e>=Ut.a&&e<=Ut.f)return e-(Ut.a-10)}function de(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if($s)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=js(e.charCodeAt(s)),c=js(e.charCodeAt(s+1));if(i===void 0||c===void 0){let a=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function Xn(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function Qe(e){return typeof e=="string"&&(e=Xn(e)),wt(e),e}function ht(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];wt(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}var Ce=class{};function Wn(e){let t=n=>e().update(Qe(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function te(e=32){if(he&&typeof he.getRandomValues=="function")return he.getRandomValues(new Uint8Array(e));if(he&&typeof he.randomBytes=="function")return Uint8Array.from(he.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function lu(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),c=Number(r&s),a=n?4:0,f=n?0:4;e.setUint32(t+a,i,n),e.setUint32(t+f,c,n)}function Xs(e,t,r){return e&t^~e&r}function Ws(e,t,r){return e&t^e&r^t&r}var tr=class extends Ce{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=kr(this.buffer)}update(t){De(this),t=Qe(t),wt(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=kr(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){De(this),Ys(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Mt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;lu(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=kr(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=a/4,p=this.get();if(f>p.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)c.setUint32(4*l,p[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Ot=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var st=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Mr=BigInt(4294967295),Js=BigInt(32);function hu(e,t=!1){return t?{h:Number(e&Mr),l:Number(e>>Js&Mr)}:{h:Number(e>>Js&Mr)|0,l:Number(e&Mr)|0}}function Qs(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:c}=hu(e[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var Jn=(e,t,r)=>e>>>r,Qn=(e,t,r)=>e<<32-r|t>>>r,pe=(e,t,r)=>e>>>r|t<<32-r,me=(e,t,r)=>e<<32-r|t>>>r,er=(e,t,r)=>e<<64-r|t>>>r-32,rr=(e,t,r)=>e>>>r-32|t<<64-r;function Ct(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var ti=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),ei=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ri=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),ni=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,oi=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),si=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var pu=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]),ee=new Uint32Array(64),Or=class extends tr{constructor(t=32){super(64,t,8,!1),this.A=Ot[0]|0,this.B=Ot[1]|0,this.C=Ot[2]|0,this.D=Ot[3]|0,this.E=Ot[4]|0,this.F=Ot[5]|0,this.G=Ot[6]|0,this.H=Ot[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,r,n,o,s,i,c,a]}set(t,r,n,o,s,i,c,a){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(t,r){for(let l=0;l<16;l++,r+=4)ee[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let u=ee[l-15],h=ee[l-2],d=It(u,7)^It(u,18)^u>>>3,E=It(h,17)^It(h,19)^h>>>10;ee[l]=E+ee[l-7]+d+ee[l-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:f,H:p}=this;for(let l=0;l<64;l++){let u=It(c,6)^It(c,11)^It(c,25),h=p+u+Xs(c,a,f)+pu[l]+ee[l]|0,E=(It(n,2)^It(n,13)^It(n,22))+Ws(n,o,s)|0;p=f,f=a,a=c,c=i+h|0,i=s,s=o,o=n,n=h+E|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,f=f+this.G|0,p=p+this.H|0,this.set(n,o,s,i,c,a,f,p)}roundClean(){Mt(ee)}destroy(){this.set(0,0,0,0,0,0,0,0),Mt(this.buffer)}};var ii=Qs(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),mu=ii[0],yu=ii[1],re=new Uint32Array(80),ne=new Uint32Array(80),to=class extends tr{constructor(t=64){super(128,t,16,!1),this.Ah=st[0]|0,this.Al=st[1]|0,this.Bh=st[2]|0,this.Bl=st[3]|0,this.Ch=st[4]|0,this.Cl=st[5]|0,this.Dh=st[6]|0,this.Dl=st[7]|0,this.Eh=st[8]|0,this.El=st[9]|0,this.Fh=st[10]|0,this.Fl=st[11]|0,this.Gh=st[12]|0,this.Gl=st[13]|0,this.Hh=st[14]|0,this.Hl=st[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:f,El:p,Fh:l,Fl:u,Gh:h,Gl:d,Hh:E,Hl:S}=this;return[t,r,n,o,s,i,c,a,f,p,l,u,h,d,E,S]}set(t,r,n,o,s,i,c,a,f,p,l,u,h,d,E,S){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=f|0,this.El=p|0,this.Fh=l|0,this.Fl=u|0,this.Gh=h|0,this.Gl=d|0,this.Hh=E|0,this.Hl=S|0}process(t,r){for(let w=0;w<16;w++,r+=4)re[w]=t.getUint32(r),ne[w]=t.getUint32(r+=4);for(let w=16;w<80;w++){let L=re[w-15]|0,P=ne[w-15]|0,M=pe(L,P,1)^pe(L,P,8)^Jn(L,P,7),k=me(L,P,1)^me(L,P,8)^Qn(L,P,7),R=re[w-2]|0,x=ne[w-2]|0,T=pe(R,x,19)^er(R,x,61)^Jn(R,x,6),N=me(R,x,19)^rr(R,x,61)^Qn(R,x,6),C=ri(k,N,ne[w-7],ne[w-16]),g=ni(C,M,T,re[w-7],re[w-16]);re[w]=g|0,ne[w]=C|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:f,Dl:p,Eh:l,El:u,Fh:h,Fl:d,Gh:E,Gl:S,Hh:b,Hl:A}=this;for(let w=0;w<80;w++){let L=pe(l,u,14)^pe(l,u,18)^er(l,u,41),P=me(l,u,14)^me(l,u,18)^rr(l,u,41),M=l&h^~l&E,k=u&d^~u&S,R=oi(A,P,k,yu[w],ne[w]),x=si(R,b,L,M,mu[w],re[w]),T=R|0,N=pe(n,o,28)^er(n,o,34)^er(n,o,39),C=me(n,o,28)^rr(n,o,34)^rr(n,o,39),g=n&s^n&c^s&c,m=o&i^o&a^i&a;b=E|0,A=S|0,E=h|0,S=d|0,h=l|0,d=u|0,{h:l,l:u}=Ct(f|0,p|0,x|0,T|0),f=c|0,p=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let y=ti(T,C,m);n=ei(y,x,N,g),o=y|0}({h:n,l:o}=Ct(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ct(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=Ct(this.Ch|0,this.Cl|0,c|0,a|0),{h:f,l:p}=Ct(this.Dh|0,this.Dl|0,f|0,p|0),{h:l,l:u}=Ct(this.Eh|0,this.El|0,l|0,u|0),{h,l:d}=Ct(this.Fh|0,this.Fl|0,h|0,d|0),{h:E,l:S}=Ct(this.Gh|0,this.Gl|0,E|0,S|0),{h:b,l:A}=Ct(this.Hh|0,this.Hl|0,b|0,A|0),this.set(n,o,s,i,c,a,f,p,l,u,h,d,E,S,b,A)}roundClean(){Mt(re,ne)}destroy(){Mt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var qr=Wn(()=>new Or);var ai=Wn(()=>new to);var no=BigInt(0),ro=BigInt(1);function qt(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function xt(e,t,r=""){let n=kt(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,c=s?` of length ${t}`:"",a=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+c+", got "+a)}return e}function nr(e){let t=e.toString(16);return t.length&1?"0"+t:t}function ci(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?no:BigInt("0x"+e)}function Pe(e){return ci(vt(e))}function Ht(e){return wt(e),ci(vt(Uint8Array.from(e).reverse()))}function Hr(e,t){return de(e.toString(16).padStart(t*2,"0"))}function oo(e,t){return Hr(e,t).reverse()}function H(e,t,r){let n;if(typeof t=="string")try{n=de(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(kt(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}function ui(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function so(e){return Uint8Array.from(e)}var eo=e=>typeof e=="bigint"&&no<=e;function fi(e,t,r){return eo(e)&&eo(t)&&eo(r)&&t<=e&&e<r}function or(e,t,r,n){if(!fi(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Vr(e){let t;for(t=0;e>no;e>>=ro,t+=1);return t}var oe=e=>(ro<<BigInt(e))-ro;function li(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=h=>new Uint8Array(h),o=h=>Uint8Array.of(h),s=n(e),i=n(e),c=0,a=()=>{s.fill(1),i.fill(0),c=0},f=(...h)=>r(i,s,...h),p=(h=n(0))=>{i=f(o(0),h),s=f(),h.length!==0&&(i=f(o(1),h),s=f())},l=()=>{if(c++>=1e3)throw new Error("drbg: tried 1000 values");let h=0,d=[];for(;h<t;){s=f();let E=s.slice();d.push(E),h+=s.length}return ht(...d)};return(h,d)=>{a(),p(h);let E;for(;!(E=d(l()));)p();return a(),E}}function se(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let c=e[o];if(i&&c===void 0)return;let a=typeof c;if(a!==s||c===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${a}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}var io=()=>{throw new Error("not implemented")};function Ke(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var dt=BigInt(0),nt=BigInt(1),ye=BigInt(2),pi=BigInt(3),mi=BigInt(4),yi=BigInt(5),bu=BigInt(7),bi=BigInt(8),gu=BigInt(9),gi=BigInt(16);function J(e,t){let r=e%t;return r>=dt?r:t+r}function G(e,t,r){let n=e;for(;t-- >dt;)n*=n,n%=r;return n}function hi(e,t){if(e===dt)throw new Error("invert: expected non-zero number");if(t<=dt)throw new Error("invert: expected positive modulus, got "+t);let r=J(e,t),n=t,o=dt,s=nt,i=nt,c=dt;for(;r!==dt;){let f=n/r,p=n%r,l=o-i*f,u=s-c*f;n=r,r=p,o=i,s=c,i=l,c=u}if(n!==nt)throw new Error("invert: does not exist");return J(o,t)}function ao(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function wi(e,t){let r=(e.ORDER+nt)/mi,n=e.pow(t,r);return ao(e,n,t),n}function wu(e,t){let r=(e.ORDER-yi)/bi,n=e.mul(t,ye),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,ye),o),c=e.mul(s,e.sub(i,e.ONE));return ao(e,c,t),c}function xu(e){let t=Et(e),r=xi(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+bu)/gi;return(c,a)=>{let f=c.pow(a,i),p=c.mul(f,n),l=c.mul(f,o),u=c.mul(f,s),h=c.eql(c.sqr(p),a),d=c.eql(c.sqr(l),a);f=c.cmov(f,p,h),p=c.cmov(u,l,d);let E=c.eql(c.sqr(p),a),S=c.cmov(f,p,E);return ao(c,S,a),S}}function xi(e){if(e<pi)throw new Error("sqrt is not defined for small field");let t=e-nt,r=0;for(;t%ye===dt;)t/=ye,r++;let n=ye,o=Et(e);for(;di(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return wi;let s=o.pow(n,t),i=(t+nt)/ye;return function(a,f){if(a.is0(f))return f;if(di(a,f)!==1)throw new Error("Cannot find square root");let p=r,l=a.mul(a.ONE,s),u=a.pow(f,t),h=a.pow(f,i);for(;!a.eql(u,a.ONE);){if(a.is0(u))return a.ZERO;let d=1,E=a.sqr(u);for(;!a.eql(E,a.ONE);)if(d++,E=a.sqr(E),d===p)throw new Error("Cannot find square root");let S=nt<<BigInt(p-d-1),b=a.pow(l,S);p=d,l=a.sqr(b),u=a.mul(u,l),h=a.mul(h,b)}return h}}function Eu(e){return e%mi===pi?wi:e%bi===yi?wu:e%gi===gu?xu(e):xi(e)}var Vt=(e,t)=>(J(e,t)&nt)===nt,Su=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function co(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=Su.reduce((n,o)=>(n[o]="function",n),t);return se(e,r),e}function vu(e,t,r){if(r<dt)throw new Error("invalid exponent, negatives unsupported");if(r===dt)return e.ONE;if(r===nt)return t;let n=e.ONE,o=t;for(;r>dt;)r&nt&&(n=e.mul(n,o)),o=e.sqr(o),r>>=nt;return n}function sr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,c,a)=>e.is0(c)?i:(n[a]=i,e.mul(i,c)),e.ONE),s=e.inv(o);return t.reduceRight((i,c,a)=>e.is0(c)?i:(n[a]=e.mul(i,n[a]),e.mul(i,c)),s),n}function di(e,t){let r=(e.ORDER-nt)/ye,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Fr(e,t){t!==void 0&&Je(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function Et(e,t,r=!1,n={}){if(e<=dt)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s,i=!1,c;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let u=t;u.BITS&&(o=u.BITS),u.sqrt&&(s=u.sqrt),typeof u.isLE=="boolean"&&(r=u.isLE),typeof u.modFromBytes=="boolean"&&(i=u.modFromBytes),c=u.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:a,nByteLength:f}=Fr(e,o);if(f>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let p,l=Object.freeze({ORDER:e,isLE:r,BITS:a,BYTES:f,MASK:oe(a),ZERO:dt,ONE:nt,allowedLengths:c,create:u=>J(u,e),isValid:u=>{if(typeof u!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof u);return dt<=u&&u<e},is0:u=>u===dt,isValidNot0:u=>!l.is0(u)&&l.isValid(u),isOdd:u=>(u&nt)===nt,neg:u=>J(-u,e),eql:(u,h)=>u===h,sqr:u=>J(u*u,e),add:(u,h)=>J(u+h,e),sub:(u,h)=>J(u-h,e),mul:(u,h)=>J(u*h,e),pow:(u,h)=>vu(l,u,h),div:(u,h)=>J(u*hi(h,e),e),sqrN:u=>u*u,addN:(u,h)=>u+h,subN:(u,h)=>u-h,mulN:(u,h)=>u*h,inv:u=>hi(u,e),sqrt:s||(u=>(p||(p=Eu(e)),p(l,u))),toBytes:u=>r?oo(u,f):Hr(u,f),fromBytes:(u,h=!0)=>{if(c){if(!c.includes(u.length)||u.length>f)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+u.length);let E=new Uint8Array(f);E.set(u,r?0:E.length-u.length),u=E}if(u.length!==f)throw new Error("Field.fromBytes: expected "+f+" bytes, got "+u.length);let d=r?Ht(u):Pe(u);if(i&&(d=J(d,e)),!h&&!l.isValid(d))throw new Error("invalid field element: outside of range 0..ORDER");return d},invertBatch:u=>sr(l,u),cmov:(u,h,d)=>d?h:u});return Object.freeze(l)}function Ei(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function uo(e){let t=Ei(e);return t+Math.ceil(t/2)}function fo(e,t,r=!1){let n=e.length,o=Ei(t),s=uo(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Ht(e):Pe(e),c=J(i,t-nt)+nt;return r?oo(c,o):Hr(c,o)}var Re=BigInt(0),be=BigInt(1);function ir(e,t){let r=t.negate();return e?r:t}function Ft(e,t){let r=sr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Bi(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function lo(e,t){Bi(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=oe(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Si(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,c=Number(e&o),a=e>>i;c>n&&(c-=s,a+=be);let f=t*n,p=f+Math.abs(c)-1,l=c===0,u=c<0,h=t%2!==0;return{nextN:a,offset:p,isZero:l,isNeg:u,isNegF:h,offsetF:f}}function Au(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Bu(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var ho=new WeakMap,Ii=new WeakMap;function po(e){return Ii.get(e)||1}function vi(e){if(e!==Re)throw new Error("invalid wNAF")}var Ne=class{constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>Re;)r&be&&(n=n.add(o)),o=o.double(),r>>=be;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=lo(r,this.bits),s=[],i=t,c=i;for(let a=0;a<n;a++){c=i,s.push(c);for(let f=1;f<o;f++)c=c.add(i),s.push(c);i=c.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=lo(t,this.bits);for(let c=0;c<i.windows;c++){let{nextN:a,offset:f,isZero:p,isNeg:l,isNegF:u,offsetF:h}=Si(n,c,i);n=a,p?s=s.add(ir(u,r[h])):o=o.add(ir(l,r[f]))}return vi(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=lo(t,this.bits);for(let i=0;i<s.windows&&n!==Re;i++){let{nextN:c,offset:a,isZero:f,isNeg:p}=Si(n,i,s);if(n=c,!f){let l=r[a];o=o.add(p?l.negate():l)}}return vi(n),o}getPrecomputes(t,r,n){let o=ho.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),ho.set(r,o))),o}cached(t,r,n){let o=po(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=po(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){Bi(r,this.bits),Ii.set(t,r),ho.delete(t)}hasCache(t){return po(t)!==1}};function _i(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Re||n>Re;)r&be&&(s=s.add(o)),n&be&&(i=i.add(o)),o=o.double(),r>>=be,n>>=be;return{p1:s,p2:i}}function Ue(e,t,r,n){Au(r,e),Bu(n,t);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,c=Vr(BigInt(o)),a=1;c>12?a=c-3:c>4?a=c-2:c>0&&(a=2);let f=oe(a),p=new Array(Number(f)+1).fill(i),l=Math.floor((t.BITS-1)/a)*a,u=i;for(let h=l;h>=0;h-=a){p.fill(i);for(let E=0;E<s;E++){let S=n[E],b=Number(S>>BigInt(h)&f);p[b]=p[b].add(r[E])}let d=i;for(let E=p.length-1,S=i;E>0;E--)S=S.add(p[E]),d=d.add(S);if(u=u.add(d),h!==0)for(let E=0;E<a;E++)u=u.double()}return u}function Ai(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return co(t),t}else return Et(e,{isLE:r})}function zr(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let a of["p","n","h"]){let f=t[a];if(!(typeof f=="bigint"&&f>Re))throw new Error(`CURVE.${a} must be positive bigint`)}let o=Ai(t.p,r.Fp,n),s=Ai(t.n,r.Fn,n),c=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of c)if(!o.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}var ie=BigInt(0),ot=BigInt(1),mo=BigInt(2),Iu=BigInt(8);function _u(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),c=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,c)}function Lu(e,t={}){let r=zr("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;se(t,{},{uvRatio:"function"});let c=mo<<BigInt(o.BYTES*8)-ot,a=S=>n.create(S),f=t.uvRatio||((S,b)=>{try{return{isValid:!0,value:n.sqrt(n.div(S,b))}}catch{return{isValid:!1,value:ie}}});if(!_u(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function p(S,b,A=!1){let w=A?ot:ie;return or("coordinate "+S,b,w,c),b}function l(S){if(!(S instanceof d))throw new Error("ExtendedPoint expected")}let u=Ke((S,b)=>{let{X:A,Y:w,Z:L}=S,P=S.is0();b==null&&(b=P?Iu:n.inv(L));let M=a(A*b),k=a(w*b),R=n.mul(L,b);if(P)return{x:ie,y:ot};if(R!==ot)throw new Error("invZ was invalid");return{x:M,y:k}}),h=Ke(S=>{let{a:b,d:A}=s;if(S.is0())throw new Error("bad point: ZERO");let{X:w,Y:L,Z:P,T:M}=S,k=a(w*w),R=a(L*L),x=a(P*P),T=a(x*x),N=a(k*b),C=a(x*a(N+R)),g=a(T+a(A*a(k*R)));if(C!==g)throw new Error("bad point: equation left != right (1)");let m=a(w*L),y=a(P*M);if(m!==y)throw new Error("bad point: equation left != right (2)");return!0});class d{constructor(b,A,w,L){this.X=p("x",b),this.Y=p("y",A),this.Z=p("z",w,!0),this.T=p("t",L),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){if(b instanceof d)throw new Error("extended point not allowed");let{x:A,y:w}=b||{};return p("x",A),p("y",w),new d(A,w,ot,a(A*w))}static fromBytes(b,A=!1){let w=n.BYTES,{a:L,d:P}=s;b=so(xt(b,w,"point")),qt(A,"zip215");let M=so(b),k=b[w-1];M[w-1]=k&-129;let R=Ht(M),x=A?c:n.ORDER;or("point.y",R,ie,x);let T=a(R*R),N=a(T-ot),C=a(P*T-L),{isValid:g,value:m}=f(N,C);if(!g)throw new Error("bad point: invalid y coordinate");let y=(m&ot)===ot,v=(k&128)!==0;if(!A&&m===ie&&v)throw new Error("bad point: x=0 and x_0=1");return v!==y&&(m=a(-m)),d.fromAffine({x:m,y:R})}static fromHex(b,A=!1){return d.fromBytes(H("point",b),A)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,A=!0){return E.createCache(this,b),A||this.multiply(mo),this}assertValidity(){h(this)}equals(b){l(b);let{X:A,Y:w,Z:L}=this,{X:P,Y:M,Z:k}=b,R=a(A*k),x=a(P*L),T=a(w*k),N=a(M*L);return R===x&&T===N}is0(){return this.equals(d.ZERO)}negate(){return new d(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:b}=s,{X:A,Y:w,Z:L}=this,P=a(A*A),M=a(w*w),k=a(mo*a(L*L)),R=a(b*P),x=A+w,T=a(a(x*x)-P-M),N=R+M,C=N-k,g=R-M,m=a(T*C),y=a(N*g),v=a(T*g),B=a(C*N);return new d(m,y,B,v)}add(b){l(b);let{a:A,d:w}=s,{X:L,Y:P,Z:M,T:k}=this,{X:R,Y:x,Z:T,T:N}=b,C=a(L*R),g=a(P*x),m=a(k*w*N),y=a(M*T),v=a((L+P)*(R+x)-C-g),B=y-m,D=y+m,I=a(g-A*C),_=a(v*B),K=a(D*I),U=a(v*I),Y=a(B*D);return new d(_,K,Y,U)}subtract(b){return this.add(b.negate())}multiply(b){if(!o.isValidNot0(b))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:A,f:w}=E.cached(this,b,L=>Ft(d,L));return Ft(d,[A,w])[0]}multiplyUnsafe(b,A=d.ZERO){if(!o.isValid(b))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return b===ie?d.ZERO:this.is0()||b===ot?this:E.unsafe(this,b,w=>Ft(d,w),A)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return E.unsafe(this,s.n).is0()}toAffine(b){return u(this,b)}clearCofactor(){return i===ot?this:this.multiplyUnsafe(i)}toBytes(){let{x:b,y:A}=this.toAffine(),w=n.toBytes(A);return w[w.length-1]|=b&ot?128:0,w}toHex(){return vt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(b){return Ft(d,b)}static msm(b,A){return Ue(d,o,b,A)}_setWindowSize(b){this.precompute(b)}toRawBytes(){return this.toBytes()}}d.BASE=new d(s.Gx,s.Gy,ot,a(s.Gx*s.Gy)),d.ZERO=new d(ie,ot,ot,ie),d.Fp=n,d.Fn=o;let E=new Ne(d,o.BITS);return d.BASE.precompute(8),d}var Gr=class{constructor(t){this.ep=t}static fromBytes(t){io()}static fromHex(t){io()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return vt(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.init(this.ep.precompute(t,r))}toRawBytes(){return this.toBytes()}};function Tu(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');se(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=e,c=r.randomBytes||te,a=r.adjustScalarBytes||(x=>x),f=r.domain||((x,T,N)=>{if(qt(N,"phflag"),T.length||N)throw new Error("Contexts/pre-hash are not supported");return x});function p(x){return i.create(Ht(x))}function l(x){let T=w.secretKey;x=H("private key",x,T);let N=H("hashed private key",t(x),2*T),C=a(N.slice(0,T)),g=N.slice(T,2*T),m=p(C);return{head:C,prefix:g,scalar:m}}function u(x){let{head:T,prefix:N,scalar:C}=l(x),g=o.multiply(C),m=g.toBytes();return{head:T,prefix:N,scalar:C,point:g,pointBytes:m}}function h(x){return u(x).pointBytes}function d(x=Uint8Array.of(),...T){let N=ht(...T);return p(t(f(N,H("context",x),!!n)))}function E(x,T,N={}){x=H("message",x),n&&(x=n(x));let{prefix:C,scalar:g,pointBytes:m}=u(T),y=d(N.context,C,x),v=o.multiply(y).toBytes(),B=d(N.context,v,m,x),D=i.create(y+B*g);if(!i.isValid(D))throw new Error("sign failed: invalid s");let I=ht(v,i.toBytes(D));return xt(I,w.signature,"result")}let S={zip215:!0};function b(x,T,N,C=S){let{context:g,zip215:m}=C,y=w.signature;x=H("signature",x,y),T=H("message",T),N=H("publicKey",N,w.publicKey),m!==void 0&&qt(m,"zip215"),n&&(T=n(T));let v=y/2,B=x.subarray(0,v),D=Ht(x.subarray(v,y)),I,_,K;try{I=e.fromBytes(N,m),_=e.fromBytes(B,m),K=o.multiplyUnsafe(D)}catch{return!1}if(!m&&I.isSmallOrder())return!1;let U=d(g,_.toBytes(),I.toBytes(),T);return _.add(I.multiplyUnsafe(U)).subtract(K).clearCofactor().is0()}let A=s.BYTES,w={secretKey:A,publicKey:A,signature:2*A,seed:A};function L(x=c(w.seed)){return xt(x,w.seed,"seed")}function P(x){let T=R.randomSecretKey(x);return{secretKey:T,publicKey:h(T)}}function M(x){return kt(x)&&x.length===i.BYTES}function k(x,T){try{return!!e.fromBytes(x,T)}catch{return!1}}let R={getExtendedPublicKey:u,randomSecretKey:L,isValidSecretKey:M,isValidPublicKey:k,toMontgomery(x){let{y:T}=e.fromBytes(x),N=w.publicKey,C=N===32;if(!C&&N!==57)throw new Error("only defined for 25519 and 448");let g=C?s.div(ot+T,ot-T):s.div(T-ot,T+ot);return s.toBytes(g)},toMontgomerySecret(x){let T=w.secretKey;xt(x,T);let N=t(x.subarray(0,T));return a(N).subarray(0,T)},randomPrivateKey:L,precompute(x=8,T=e.BASE){return T.precompute(x,!1)}};return Object.freeze({keygen:P,getPublicKey:h,sign:E,verify:b,utils:R,Point:e,lengths:w})}function Cu(e){let t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=Et(t.n,e.nBitLength,!0),o={Fp:r,Fn:n,uvRatio:e.uvRatio},s={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:o,hash:e.hash,eddsaOpts:s}}function Du(e,t){let r=t.Point;return Object.assign({},t,{ExtendedPoint:r,CURVE:e,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function Li(e){let{CURVE:t,curveOpts:r,hash:n,eddsaOpts:o}=Cu(e),s=Lu(t,r),i=Tu(s,n,o);return Du(e,i)}var Pu=BigInt(0),zt=BigInt(1),Ti=BigInt(2),rd=BigInt(3),Ku=BigInt(5),Ru=BigInt(8),ke=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),ar={p:ke,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Ru,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Nu(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=ke,c=e*e%s*e%s,a=G(c,Ti,s)*c%s,f=G(a,zt,s)*e%s,p=G(f,Ku,s)*f%s,l=G(p,t,s)*p%s,u=G(l,r,s)*l%s,h=G(u,n,s)*u%s,d=G(h,o,s)*h%s,E=G(d,o,s)*h%s,S=G(E,t,s)*p%s;return{pow_p_5_8:G(S,Ti,s)*e%s,b2:c}}function Uu(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var yo=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function wo(e,t){let r=ke,n=J(t*t*t,r),o=J(n*n*t,r),s=Nu(e*o).pow_p_5_8,i=J(e*n*s,r),c=J(t*i*i,r),a=i,f=J(i*yo,r),p=c===e,l=c===J(-e,r),u=c===J(-e*yo,r);return p&&(i=a),(l||u)&&(i=f),Vt(i,r)&&(i=J(-i,r)),{isValid:p||l,value:i}}var ae=Et(ar.p,{isLE:!0}),ku=Et(ar.n,{isLE:!0}),Mu={...ar,Fp:ae,hash:ai,adjustScalarBytes:Uu,uvRatio:wo},Gt=Li(Mu);var bo=yo,Ou=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),qu=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Hu=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Vu=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Ci=e=>wo(zt,e),Fu=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),go=e=>Gt.Point.Fp.create(Ht(e)&Fu);function Di(e){let{d:t}=ar,r=ke,n=b=>ae.create(b),o=n(bo*e*e),s=n((o+zt)*Hu),i=BigInt(-1),c=n((i-t*o)*n(o+t)),{isValid:a,value:f}=wo(s,c),p=n(f*e);Vt(p,r)||(p=n(-p)),a||(f=p),a||(i=o);let l=n(i*(o-zt)*Vu-c),u=f*f,h=n((f+f)*c),d=n(l*Ou),E=n(zt-u),S=n(zt+u);return new Gt.Point(n(h*S),n(E*d),n(d*S),n(h*E))}function zu(e){wt(e,64);let t=go(e.subarray(0,32)),r=Di(t),n=go(e.subarray(32,64)),o=Di(n);return new Zt(r.add(o))}var Zt=class e extends Gr{constructor(t){super(t)}static fromAffine(t){return new e(Gt.Point.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static hashToCurve(t){return zu(H("ristrettoHash",t,64))}static fromBytes(t){wt(t,32);let{a:r,d:n}=ar,o=ke,s=L=>ae.create(L),i=go(t);if(!ui(ae.toBytes(i),t)||Vt(i,o))throw new Error("invalid ristretto255 encoding 1");let c=s(i*i),a=s(zt+r*c),f=s(zt-r*c),p=s(a*a),l=s(f*f),u=s(r*n*p-l),{isValid:h,value:d}=Ci(s(u*l)),E=s(d*f),S=s(d*E*u),b=s((i+i)*E);Vt(b,o)&&(b=s(-b));let A=s(a*S),w=s(b*A);if(!h||Vt(w,o)||A===Pu)throw new Error("invalid ristretto255 encoding 2");return new e(new Gt.Point(b,A,zt,w))}static fromHex(t){return e.fromBytes(H("ristrettoHex",t,32))}static msm(t,r){return Ue(e,Gt.Point.Fn,t,r)}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=ke,i=S=>ae.create(S),c=i(i(n+r)*i(n-r)),a=i(t*r),f=i(a*a),{value:p}=Ci(i(c*f)),l=i(p*c),u=i(p*a),h=i(l*u*o),d;if(Vt(o*h,s)){let S=i(r*bo),b=i(t*bo);t=S,r=b,d=i(l*qu)}else d=u;Vt(t*h,s)&&(r=i(-r));let E=i((n-r)*d);return Vt(E,s)&&(E=i(-E)),ae.toBytes(E)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=f=>ae.create(f),c=i(r*s)===i(n*o),a=i(n*s)===i(r*o);return c||a}is0(){return this.equals(e.ZERO)}};Zt.BASE=new Zt(Gt.Point.BASE);Zt.ZERO=new Zt(Gt.Point.ZERO);Zt.Fp=ae;Zt.Fn=ku;var cr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Zr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Pi={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Zr("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var At=Pi;var jr=32;var xo,Gu=(async()=>{try{return await At.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Zu(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await At.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await At.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function ju(e,t,r){return Gt.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Ki(e,t,r){return xo==null&&(xo=await Gu),xo?Zu(e,t,r):ju(e,t,r)}function Yr(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var $r=class{type="Ed25519";raw;constructor(t){this.raw=Eo(t,jr)}toMultihash(){return Bt.digest(Nt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Ki(this.raw,r,t);return Yr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function So(e){return e=Eo(e,jr),new $r(e)}function Eo(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new Z(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var $u=Math.pow(2,7),Xu=Math.pow(2,14),Wu=Math.pow(2,21),vo=Math.pow(2,28),Ao=Math.pow(2,35),Bo=Math.pow(2,42),Io=Math.pow(2,49),q=128,ut=127;function _t(e){if(e<$u)return 1;if(e<Xu)return 2;if(e<Wu)return 3;if(e<vo)return 4;if(e<Ao)return 5;if(e<Bo)return 6;if(e<Io)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function _o(e,t,r=0){switch(_t(e)){case 8:t[r++]=e&255|q,e/=128;case 7:t[r++]=e&255|q,e/=128;case 6:t[r++]=e&255|q,e/=128;case 5:t[r++]=e&255|q,e/=128;case 4:t[r++]=e&255|q,e>>>=7;case 3:t[r++]=e&255|q,e>>>=7;case 2:t[r++]=e&255|q,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Ju(e,t,r=0){switch(_t(e)){case 8:t.set(r++,e&255|q),e/=128;case 7:t.set(r++,e&255|q),e/=128;case 6:t.set(r++,e&255|q),e/=128;case 5:t.set(r++,e&255|q),e/=128;case 4:t.set(r++,e&255|q),e>>>=7;case 3:t.set(r++,e&255|q),e>>>=7;case 2:t.set(r++,e&255|q),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function Lo(e,t){let r=e[t],n=0;if(n+=r&ut,r<q||(r=e[t+1],n+=(r&ut)<<7,r<q)||(r=e[t+2],n+=(r&ut)<<14,r<q)||(r=e[t+3],n+=(r&ut)<<21,r<q)||(r=e[t+4],n+=(r&ut)*vo,r<q)||(r=e[t+5],n+=(r&ut)*Ao,r<q)||(r=e[t+6],n+=(r&ut)*Bo,r<q)||(r=e[t+7],n+=(r&ut)*Io,r<q))return n;throw new RangeError("Could not decode varint")}function Qu(e,t){let r=e.get(t),n=0;if(n+=r&ut,r<q||(r=e.get(t+1),n+=(r&ut)<<7,r<q)||(r=e.get(t+2),n+=(r&ut)<<14,r<q)||(r=e.get(t+3),n+=(r&ut)<<21,r<q)||(r=e.get(t+4),n+=(r&ut)*vo,r<q)||(r=e.get(t+5),n+=(r&ut)*Ao,r<q)||(r=e.get(t+6),n+=(r&ut)*Bo,r<q)||(r=e.get(t+7),n+=(r&ut)*Io,r<q))return n;throw new RangeError("Could not decode varint")}function Ni(e,t,r=0){return t==null&&(t=ct(_t(e))),t instanceof Uint8Array?_o(e,t,r):Ju(e,t,r)}function Ui(e,t=0){return e instanceof Uint8Array?Lo(e,t):Qu(e,t)}var To=new Float32Array([-0]),ce=new Uint8Array(To.buffer);function Mi(e,t,r){To[0]=e,t[r]=ce[0],t[r+1]=ce[1],t[r+2]=ce[2],t[r+3]=ce[3]}function Oi(e,t){return ce[0]=e[t],ce[1]=e[t+1],ce[2]=e[t+2],ce[3]=e[t+3],To[0]}var Co=new Float64Array([-0]),ft=new Uint8Array(Co.buffer);function qi(e,t,r){Co[0]=e,t[r]=ft[0],t[r+1]=ft[1],t[r+2]=ft[2],t[r+3]=ft[3],t[r+4]=ft[4],t[r+5]=ft[5],t[r+6]=ft[6],t[r+7]=ft[7]}function Hi(e,t){return ft[0]=e[t],ft[1]=e[t+1],ft[2]=e[t+2],ft[3]=e[t+3],ft[4]=e[t+4],ft[5]=e[t+5],ft[6]=e[t+6],ft[7]=e[t+7],Co[0]}var tf=BigInt(Number.MAX_SAFE_INTEGER),ef=BigInt(Number.MIN_SAFE_INTEGER),St=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ge;if(t<tf&&t>ef)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Vi&&(o=0n,++n>Vi&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return ge;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):ge}},ge=new St(0,0);ge.toBigInt=function(){return 0n};ge.zzEncode=ge.zzDecode=function(){return this};ge.length=function(){return 1};var Vi=4294967296n;function Fi(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function zi(e,t,r){if(r-t<1)return"";let o,s=[],i=0,c;for(;t<r;)c=e[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|e[t++]&63:c>239&&c<365?(c=((c&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Do(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Lt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Xr(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Po=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Lt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Lt(this,4);return Xr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Lt(this,4);return Xr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Lt(this,4);let t=Oi(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Lt(this,4);let t=Hi(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Lt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return zi(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Lt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Lt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new St(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Lt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Lt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Lt(this,8);let t=Xr(this.buf,this.pos+=4),r=Xr(this.buf,this.pos+=4);return new St(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Lo(this.buf,this.pos);return this.pos+=_t(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Ko(e){return new Po(e instanceof Uint8Array?e:e.subarray())}function Wr(e,t,r){let n=Ko(e);return t.decode(n,void 0,r)}function Ro(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return ct(i);o+i>t&&(n=ct(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var we=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function No(){}var ko=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},rf=Ro();function nf(e){return globalThis.Buffer!=null?ct(e):rf(e)}var fr=class{len;head;tail;states;constructor(){this.len=0,this.head=new we(No,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new we(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Mo((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Jr,10,St.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=St.fromBigInt(t);return this._push(Jr,r.length(),r)}uint64Number(t){return this._push(_o,_t(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=St.fromBigInt(t).zzEncode();return this._push(Jr,r.length(),r)}sint64Number(t){let r=St.fromNumber(t).zzEncode();return this._push(Jr,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Uo,1,t?1:0)}fixed32(t){return this._push(ur,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=St.fromBigInt(t);return this._push(ur,4,r.lo)._push(ur,4,r.hi)}fixed64Number(t){let r=St.fromNumber(t);return this._push(ur,4,r.lo)._push(ur,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Mi,4,t)}double(t){return this._push(qi,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Uo,1,0):this.uint32(r)._push(sf,r,t)}string(t){let r=Fi(t);return r!==0?this.uint32(r)._push(Do,r,t):this._push(Uo,1,0)}fork(){return this.states=new ko(this),this.head=this.tail=new we(No,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 we(No,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=nf(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Uo(e,t,r){t[r]=e&255}function of(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Mo=class extends we{next;constructor(t,r){super(of,t,r),this.next=void 0}};function Jr(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function ur(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function sf(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(fr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(af,t,e),this},fr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(cf,t,e),this});function af(e,t,r){t.set(e,r)}function cf(e,t,r){e.length<40?Do(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(F(e),r)}function Oo(){return new fr}function Qr(e,t){let r=Oo();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var Me;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(Me||(Me={}));function tn(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function qo(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(s,i){let c=t(s);i.int32(c)},n=function(s){let i=s.int32();return t(i)};return tn("enum",Me.VARINT,r,n)}function en(e,t){return tn("message",Me.LENGTH_DELIMITED,e,t)}var tt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(tt||(tt={}));var Ho;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Ho||(Ho={}));(function(e){e.codec=()=>qo(Ho)})(tt||(tt={}));var Dt;(function(e){let t;e.codec=()=>(t==null&&(t=en((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),tt.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=tt.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>Qr(r,e.codec()),e.decode=(r,n)=>Wr(r,e.codec(),n)})(Dt||(Dt={}));var Vo;(function(e){let t;e.codec=()=>(t==null&&(t=en((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),tt.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=tt.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>Qr(r,e.codec()),e.decode=(r,n)=>Wr(r,e.codec(),n)})(Vo||(Vo={}));function rn(e){if(isNaN(e)||e<=0)throw new Z("random bytes length must be a Number bigger than 0");return te(e)}var hr={};yt(hr,{MAX_RSA_KEY_SIZE:()=>Fo,generateRSAKeyPair:()=>Xi,jwkToJWKKeyPair:()=>Wi,jwkToPkcs1:()=>hf,jwkToPkix:()=>jo,jwkToRSAPrivateKey:()=>Wo,pkcs1MessageToJwk:()=>Go,pkcs1MessageToRSAPrivateKey:()=>Yo,pkcs1ToJwk:()=>lf,pkcs1ToRSAPrivateKey:()=>$i,pkixMessageToJwk:()=>Zo,pkixMessageToRSAPublicKey:()=>Xo,pkixToJwk:()=>df,pkixToRSAPublicKey:()=>$o});var nn=qr;var Oe=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=hr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return at.createV1(114,this._multihash)}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,r,n){return Yi(this.jwk,r,t,n)}},lr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=hr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}sign(t,r){return ji(this.jwk,t,r)}};var Fo=8192,zo=18,uf=1062,ff=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function lf(e){let t=Rt(e);return Go(t)}function Go(e){return{n:z(e[1],"base64url"),e:z(e[2],"base64url"),d:z(e[3],"base64url"),p:z(e[4],"base64url"),q:z(e[5],"base64url"),dp:z(e[6],"base64url"),dq:z(e[7],"base64url"),qi:z(e[8],"base64url"),kty:"RSA"}}function hf(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new Z("JWK was missing components");return Qt([gt(Uint8Array.from([0])),gt(F(e.n,"base64url")),gt(F(e.e,"base64url")),gt(F(e.d,"base64url")),gt(F(e.p,"base64url")),gt(F(e.q,"base64url")),gt(F(e.dp,"base64url")),gt(F(e.dq,"base64url")),gt(F(e.qi,"base64url"))]).subarray()}function df(e){let t=Rt(e,{offset:0});return Zo(t)}function Zo(e){let t=Rt(e[1],{offset:0});return{kty:"RSA",n:z(t[0],"base64url"),e:z(t[1],"base64url")}}function jo(e){if(e.n==null||e.e==null)throw new Z("JWK was missing components");return Qt([ff,Nr(Qt([gt(F(e.n,"base64url")),gt(F(e.e,"base64url"))]))]).subarray()}function $i(e){let t=Rt(e);return Yo(t)}function Yo(e){let t=Go(e);return Wo(t)}function $o(e,t){if(e.byteLength>=uf)throw new Se("Key size is too large");let r=Rt(e,{offset:0});return Xo(r,e,t)}function Xo(e,t,r){let n=Zo(e);if(r==null){let o=nn(Dt.encode({Type:tt.RSA,Data:t}));r=Tt(zo,o)}return new Oe(n,r)}function Wo(e){if(Qi(e)>Fo)throw new Z("Key size is too large");let t=Wi(e),r=nn(Dt.encode({Type:tt.RSA,Data:jo(t.publicKey)})),n=Tt(zo,r);return new lr(t.privateKey,new Oe(t.publicKey,n))}async function Xi(e){if(e>Fo)throw new Z("Key size is too large");let t=await Ji(e),r=nn(Dt.encode({Type:tt.RSA,Data:jo(t.publicKey)})),n=Tt(zo,r);return new lr(t.privateKey,new Oe(t.publicKey,n))}function Wi(e){if(e==null)throw new Z("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function Ji(e,t){let r=await At.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await pf(r,t);return{privateKey:n[0],publicKey:n[1]}}async function ji(e,t,r){let n=await At.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await At.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Yi(e,t,r,n){let o=await At.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await At.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function pf(e,t){if(e.privateKey==null||e.publicKey==null)throw new Z("Private and public key are required");let r=await Promise.all([At.get().subtle.exportKey("jwk",e.privateKey),At.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function Qi(e){if(e.kty!=="RSA")throw new Z("invalid key type");if(e.n==null)throw new Z("invalid key modulus");return F(e.n,"base64url").length*8}var on=class extends Ce{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,Ur(t);let n=Qe(r);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),Mt(s)}update(t){return De(this),this.iHash.update(t),this}digestInto(t){De(this),wt(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Jo=(e,t,r)=>new on(e,t).update(r).digest();Jo.create=(e,t)=>new on(e,t);var ta=(e,t)=>(e+(e>=0?t:-t)/ea)/t;function mf(e,t,r){let[[n,o],[s,i]]=t,c=ta(i*e,r),a=ta(-o*e,r),f=e-c*n-a*s,p=-c*o-a*i,l=f<Yt,u=p<Yt;l&&(f=-f),u&&(p=-p);let h=oe(Math.ceil(Vr(r)/2))+He;if(f<Yt||f>=h||p<Yt||p>=h)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:f,k2neg:u,k2:p}}function ts(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Qo(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return qt(r.lowS,"lowS"),qt(r.prehash,"prehash"),r.format!==void 0&&ts(r.format),r}var es=class extends Error{constructor(t=""){super(t)}},jt={Err:es,_tlv:{encode:(e,t)=>{let{Err:r}=jt;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=nr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?nr(o.length/2|128):"";return nr(e)+s+o+t},decode(e,t){let{Err:r}=jt,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let a=o&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+a);if(f.length!==a)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let p of f)i=i<<8|p;if(n+=a,i<128)throw new r("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new r("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=jt;if(e<Yt)throw new t("integer: negative integers are not allowed");let r=nr(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=jt;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Pe(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=jt,o=H("signature",e),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,s),{v:f,l:p}=n.decode(2,a);if(p.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(f)}},hexFromSig(e){let{_tlv:t,_int:r}=jt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},Yt=BigInt(0),He=BigInt(1),ea=BigInt(2),sn=BigInt(3),yf=BigInt(4);function qe(e,t){let{BYTES:r}=e,n;if(typeof t=="bigint")n=t;else{let o=H("private key",t);try{n=e.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof t}`)}}if(!e.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function bf(e,t={}){let r=zr("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:c}=s;se(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:a}=t;if(a&&(!n.is0(s.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=na(n,o);function p(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(C,g,m){let{x:y,y:v}=g.toAffine(),B=n.toBytes(y);if(qt(m,"isCompressed"),m){p();let D=!n.isOdd(v);return ht(ra(D),B)}else return ht(Uint8Array.of(4),B,n.toBytes(v))}function u(C){xt(C,void 0,"Point");let{publicKey:g,publicKeyUncompressed:m}=f,y=C.length,v=C[0],B=C.subarray(1);if(y===g&&(v===2||v===3)){let D=n.fromBytes(B);if(!n.isValid(D))throw new Error("bad point: is not on curve, wrong x");let I=E(D),_;try{_=n.sqrt(I)}catch(Y){let V=Y instanceof Error?": "+Y.message:"";throw new Error("bad point: is not on curve, sqrt error"+V)}p();let K=n.isOdd(_);return(v&1)===1!==K&&(_=n.neg(_)),{x:D,y:_}}else if(y===m&&v===4){let D=n.BYTES,I=n.fromBytes(B.subarray(0,D)),_=n.fromBytes(B.subarray(D,D*2));if(!S(I,_))throw new Error("bad point: is not on curve");return{x:I,y:_}}else throw new Error(`bad point: got length ${y}, expected compressed=${g} or uncompressed=${m}`)}let h=t.toBytes||l,d=t.fromBytes||u;function E(C){let g=n.sqr(C),m=n.mul(g,C);return n.add(n.add(m,n.mul(C,s.a)),s.b)}function S(C,g){let m=n.sqr(g),y=E(C);return n.eql(m,y)}if(!S(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let b=n.mul(n.pow(s.a,sn),yf),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(b,A)))throw new Error("bad curve params: a or b");function w(C,g,m=!1){if(!n.isValid(g)||m&&n.is0(g))throw new Error(`bad point coordinate ${C}`);return g}function L(C){if(!(C instanceof x))throw new Error("ProjectivePoint expected")}function P(C){if(!a||!a.basises)throw new Error("no endo");return mf(C,a.basises,o.ORDER)}let M=Ke((C,g)=>{let{X:m,Y:y,Z:v}=C;if(n.eql(v,n.ONE))return{x:m,y};let B=C.is0();g==null&&(g=B?n.ONE:n.inv(v));let D=n.mul(m,g),I=n.mul(y,g),_=n.mul(v,g);if(B)return{x:n.ZERO,y:n.ZERO};if(!n.eql(_,n.ONE))throw new Error("invZ was invalid");return{x:D,y:I}}),k=Ke(C=>{if(C.is0()){if(t.allowInfinityPoint&&!n.is0(C.Y))return;throw new Error("bad point: ZERO")}let{x:g,y:m}=C.toAffine();if(!n.isValid(g)||!n.isValid(m))throw new Error("bad point: x or y not field elements");if(!S(g,m))throw new Error("bad point: equation left != right");if(!C.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function R(C,g,m,y,v){return m=new x(n.mul(m.X,C),m.Y,m.Z),g=ir(y,g),m=ir(v,m),g.add(m)}class x{constructor(g,m,y){this.X=w("x",g),this.Y=w("y",m,!0),this.Z=w("z",y),Object.freeze(this)}static CURVE(){return s}static fromAffine(g){let{x:m,y}=g||{};if(!g||!n.isValid(m)||!n.isValid(y))throw new Error("invalid affine point");if(g instanceof x)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(y)?x.ZERO:new x(m,y,n.ONE)}static fromBytes(g){let m=x.fromAffine(d(xt(g,void 0,"point")));return m.assertValidity(),m}static fromHex(g){return x.fromBytes(H("pointHex",g))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,m=!0){return N.createCache(this,g),m||this.multiply(sn),this}assertValidity(){k(this)}hasEvenY(){let{y:g}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(g)}equals(g){L(g);let{X:m,Y:y,Z:v}=this,{X:B,Y:D,Z:I}=g,_=n.eql(n.mul(m,I),n.mul(B,v)),K=n.eql(n.mul(y,I),n.mul(D,v));return _&&K}negate(){return new x(this.X,n.neg(this.Y),this.Z)}double(){let{a:g,b:m}=s,y=n.mul(m,sn),{X:v,Y:B,Z:D}=this,I=n.ZERO,_=n.ZERO,K=n.ZERO,U=n.mul(v,v),Y=n.mul(B,B),V=n.mul(D,D),O=n.mul(v,B);return O=n.add(O,O),K=n.mul(v,D),K=n.add(K,K),I=n.mul(g,K),_=n.mul(y,V),_=n.add(I,_),I=n.sub(Y,_),_=n.add(Y,_),_=n.mul(I,_),I=n.mul(O,I),K=n.mul(y,K),V=n.mul(g,V),O=n.sub(U,V),O=n.mul(g,O),O=n.add(O,K),K=n.add(U,U),U=n.add(K,U),U=n.add(U,V),U=n.mul(U,O),_=n.add(_,U),V=n.mul(B,D),V=n.add(V,V),U=n.mul(V,O),I=n.sub(I,U),K=n.mul(V,Y),K=n.add(K,K),K=n.add(K,K),new x(I,_,K)}add(g){L(g);let{X:m,Y:y,Z:v}=this,{X:B,Y:D,Z:I}=g,_=n.ZERO,K=n.ZERO,U=n.ZERO,Y=s.a,V=n.mul(s.b,sn),O=n.mul(m,B),$=n.mul(y,D),et=n.mul(v,I),mt=n.add(m,y),X=n.add(B,D);mt=n.mul(mt,X),X=n.add(O,$),mt=n.sub(mt,X),X=n.add(m,v);let it=n.add(B,I);return X=n.mul(X,it),it=n.add(O,et),X=n.sub(X,it),it=n.add(y,v),_=n.add(D,I),it=n.mul(it,_),_=n.add($,et),it=n.sub(it,_),U=n.mul(Y,X),_=n.mul(V,et),U=n.add(_,U),_=n.sub($,U),U=n.add($,U),K=n.mul(_,U),$=n.add(O,O),$=n.add($,O),et=n.mul(Y,et),X=n.mul(V,X),$=n.add($,et),et=n.sub(O,et),et=n.mul(Y,et),X=n.add(X,et),O=n.mul($,X),K=n.add(K,O),O=n.mul(it,X),_=n.mul(mt,_),_=n.sub(_,O),O=n.mul(mt,$),U=n.mul(it,U),U=n.add(U,O),new x(_,K,U)}subtract(g){return this.add(g.negate())}is0(){return this.equals(x.ZERO)}multiply(g){let{endo:m}=t;if(!o.isValidNot0(g))throw new Error("invalid scalar: out of range");let y,v,B=D=>N.cached(this,D,I=>Ft(x,I));if(m){let{k1neg:D,k1:I,k2neg:_,k2:K}=P(g),{p:U,f:Y}=B(I),{p:V,f:O}=B(K);v=Y.add(O),y=R(m.beta,U,V,D,_)}else{let{p:D,f:I}=B(g);y=D,v=I}return Ft(x,[y,v])[0]}multiplyUnsafe(g){let{endo:m}=t,y=this;if(!o.isValid(g))throw new Error("invalid scalar: out of range");if(g===Yt||y.is0())return x.ZERO;if(g===He)return y;if(N.hasCache(this))return this.multiply(g);if(m){let{k1neg:v,k1:B,k2neg:D,k2:I}=P(g),{p1:_,p2:K}=_i(x,y,B,I);return R(m.beta,_,K,v,D)}else return N.unsafe(y,g)}multiplyAndAddUnsafe(g,m,y){let v=this.multiplyUnsafe(m).add(g.multiplyUnsafe(y));return v.is0()?void 0:v}toAffine(g){return M(this,g)}isTorsionFree(){let{isTorsionFree:g}=t;return i===He?!0:g?g(x,this):N.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:g}=t;return i===He?this:g?g(x,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(g=!0){return qt(g,"isCompressed"),this.assertValidity(),h(x,this,g)}toHex(g=!0){return vt(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(g=!0){return this.toBytes(g)}_setWindowSize(g){this.precompute(g)}static normalizeZ(g){return Ft(x,g)}static msm(g,m){return Ue(x,o,g,m)}static fromPrivateKey(g){return x.BASE.multiply(qe(o,g))}}x.BASE=new x(s.Gx,s.Gy,n.ONE),x.ZERO=new x(n.ZERO,n.ONE,n.ZERO),x.Fp=n,x.Fn=o;let T=o.BITS,N=new Ne(x,t.endo?Math.ceil(T/2):T);return x.BASE.precompute(8),x}function ra(e){return Uint8Array.of(e?2:3)}function na(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function gf(e,t={}){let{Fn:r}=e,n=t.randomBytes||te,o=Object.assign(na(e.Fp,r),{seed:uo(r.ORDER)});function s(h){try{return!!qe(r,h)}catch{return!1}}function i(h,d){let{publicKey:E,publicKeyUncompressed:S}=o;try{let b=h.length;return d===!0&&b!==E||d===!1&&b!==S?!1:!!e.fromBytes(h)}catch{return!1}}function c(h=n(o.seed)){return fo(xt(h,o.seed,"seed"),r.ORDER)}function a(h,d=!0){return e.BASE.multiply(qe(r,h)).toBytes(d)}function f(h){let d=c(h);return{secretKey:d,publicKey:a(d)}}function p(h){if(typeof h=="bigint")return!1;if(h instanceof e)return!0;let{secretKey:d,publicKey:E,publicKeyUncompressed:S}=o;if(r.allowedLengths||d===E)return;let b=H("key",h).length;return b===E||b===S}function l(h,d,E=!0){if(p(h)===!0)throw new Error("first arg must be private key");if(p(d)===!1)throw new Error("second arg must be public key");let S=qe(r,h);return e.fromHex(d).multiply(S).toBytes(E)}return Object.freeze({getPublicKey:a,getSharedSecret:l,keygen:f,Point:e,utils:{isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c,isValidPrivateKey:s,randomPrivateKey:c,normPrivateKeyToScalar:h=>qe(r,h),precompute(h=8,d=e.BASE){return d.precompute(h,!1)}},lengths:o})}function wf(e,t,r={}){Ur(t),se(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||te,o=r.hmac||((m,...y)=>Jo(t,m,ht(...y))),{Fp:s,Fn:i}=e,{ORDER:c,BITS:a}=i,{keygen:f,getPublicKey:p,getSharedSecret:l,utils:u,lengths:h}=gf(e,r),d={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},E="compact";function S(m){let y=c>>He;return m>y}function b(m,y){if(!i.isValidNot0(y))throw new Error(`invalid signature ${m}: out of range 1..Point.Fn.ORDER`);return y}function A(m,y){ts(y);let v=h.signature,B=y==="compact"?v:y==="recovered"?v+1:void 0;return xt(m,B,`${y} signature`)}class w{constructor(y,v,B){this.r=b("r",y),this.s=b("s",v),B!=null&&(this.recovery=B),Object.freeze(this)}static fromBytes(y,v=E){A(y,v);let B;if(v==="der"){let{r:K,s:U}=jt.toSig(xt(y));return new w(K,U)}v==="recovered"&&(B=y[0],v="compact",y=y.subarray(1));let D=i.BYTES,I=y.subarray(0,D),_=y.subarray(D,D*2);return new w(i.fromBytes(I),i.fromBytes(_),B)}static fromHex(y,v){return this.fromBytes(de(y),v)}addRecoveryBit(y){return new w(this.r,this.s,y)}recoverPublicKey(y){let v=s.ORDER,{r:B,s:D,recovery:I}=this;if(I==null||![0,1,2,3].includes(I))throw new Error("recovery id invalid");if(c*ea<v&&I>1)throw new Error("recovery id is ambiguous for h>1 curve");let K=I===2||I===3?B+c:B;if(!s.isValid(K))throw new Error("recovery id 2 or 3 invalid");let U=s.toBytes(K),Y=e.fromBytes(ht(ra((I&1)===0),U)),V=i.inv(K),O=P(H("msgHash",y)),$=i.create(-O*V),et=i.create(D*V),mt=e.BASE.multiplyUnsafe($).add(Y.multiplyUnsafe(et));if(mt.is0())throw new Error("point at infinify");return mt.assertValidity(),mt}hasHighS(){return S(this.s)}toBytes(y=E){if(ts(y),y==="der")return de(jt.hexFromSig(this));let v=i.toBytes(this.r),B=i.toBytes(this.s);if(y==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return ht(Uint8Array.of(this.recovery),v,B)}return ht(v,B)}toHex(y){return vt(this.toBytes(y))}assertValidity(){}static fromCompact(y){return w.fromBytes(H("sig",y),"compact")}static fromDER(y){return w.fromBytes(H("sig",y),"der")}normalizeS(){return this.hasHighS()?new w(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return vt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return vt(this.toBytes("compact"))}}let L=r.bits2int||function(y){if(y.length>8192)throw new Error("input is too large");let v=Pe(y),B=y.length*8-a;return B>0?v>>BigInt(B):v},P=r.bits2int_modN||function(y){return i.create(L(y))},M=oe(a);function k(m){return or("num < 2^"+a,m,Yt,M),i.toBytes(m)}function R(m,y){return xt(m,void 0,"message"),y?xt(t(m),void 0,"prehashed message"):m}function x(m,y,v){if(["recovered","canonical"].some($=>$ in v))throw new Error("sign() legacy options not supported");let{lowS:B,prehash:D,extraEntropy:I}=Qo(v,d);m=R(m,D);let _=P(m),K=qe(i,y),U=[k(K),k(_)];if(I!=null&&I!==!1){let $=I===!0?n(h.secretKey):I;U.push(H("extraEntropy",$))}let Y=ht(...U),V=_;function O($){let et=L($);if(!i.isValidNot0(et))return;let mt=i.inv(et),X=e.BASE.multiply(et).toAffine(),it=i.create(X.x);if(it===Yt)return;let Lr=i.create(mt*i.create(V+it*K));if(Lr===Yt)return;let bs=(X.x===it?0:2)|Number(X.y&He),gs=Lr;return B&&S(Lr)&&(gs=i.neg(Lr),bs^=1),new w(it,gs,bs)}return{seed:Y,k2sig:O}}function T(m,y,v={}){m=H("message",m);let{seed:B,k2sig:D}=x(m,y,v);return li(t.outputLen,i.BYTES,o)(B,D)}function N(m){let y,v=typeof m=="string"||kt(m),B=!v&&m!==null&&typeof m=="object"&&typeof m.r=="bigint"&&typeof m.s=="bigint";if(!v&&!B)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(B)y=new w(m.r,m.s);else if(v){try{y=w.fromBytes(H("sig",m),"der")}catch(D){if(!(D instanceof jt.Err))throw D}if(!y)try{y=w.fromBytes(H("sig",m),"compact")}catch{return!1}}return y||!1}function C(m,y,v,B={}){let{lowS:D,prehash:I,format:_}=Qo(B,d);if(v=H("publicKey",v),y=R(H("message",y),I),"strict"in B)throw new Error("options.strict was renamed to lowS");let K=_===void 0?N(m):w.fromBytes(H("sig",m),_);if(K===!1)return!1;try{let U=e.fromBytes(v);if(D&&K.hasHighS())return!1;let{r:Y,s:V}=K,O=P(y),$=i.inv(V),et=i.create(O*$),mt=i.create(Y*$),X=e.BASE.multiplyUnsafe(et).add(U.multiplyUnsafe(mt));return X.is0()?!1:i.create(X.x)===Y}catch{return!1}}function g(m,y,v={}){let{prehash:B}=Qo(v,d);return y=R(y,B),w.fromBytes(m,"recovered").recoverPublicKey(y).toBytes()}return Object.freeze({keygen:f,getPublicKey:p,getSharedSecret:l,utils:u,lengths:h,Point:e,sign:T,verify:C,recoverPublicKey:g,Signature:w,hash:t})}function xf(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,o=Et(t.n,{BITS:e.nBitLength,allowedLengths:n,modFromBytes:e.wrapPrivateKey}),s={Fp:r,Fn:o,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:s}}function Ef(e){let{CURVE:t,curveOpts:r}=xf(e),n={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,hash:e.hash,ecdsaOpts:n}}function Sf(e,t){let r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,Fr(r.Fn.ORDER,r.Fn.BITS))})}function oa(e){let{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:o}=Ef(e),s=bf(t,r),i=wf(s,n,o);return Sf(e,i)}function sa(e,t){let r=n=>oa({...e,hash:n});return{...r(t),create:r}}var ns={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},vf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var ia=BigInt(2);function Af(e){let t=ns.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),f=e*e*e%t,p=f*f*e%t,l=G(p,r,t)*p%t,u=G(l,r,t)*p%t,h=G(u,ia,t)*f%t,d=G(h,o,t)*h%t,E=G(d,s,t)*d%t,S=G(E,c,t)*E%t,b=G(S,a,t)*S%t,A=G(b,c,t)*E%t,w=G(A,r,t)*p%t,L=G(w,i,t)*d%t,P=G(L,n,t)*f%t,M=G(P,ia,t);if(!rs.eql(rs.sqr(M),e))throw new Error("Cannot find square root");return M}var rs=Et(ns.p,{sqrt:Af}),Ve=sa({...ns,Fp:rs,lowS:!0,endo:vf},qr);function aa(e,t,r,n){let o=le.digest(r instanceof Uint8Array?r:r.subarray());if(Yr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ve.verify(t,s,e))).catch(s=>{throw s.name==="AbortError"?s:new cr(String(s))});try{return n?.signal?.throwIfAborted(),Ve.verify(t,o.digest,e)}catch(s){throw new cr(String(s))}}var an=class{type="secp256k1";raw;_key;constructor(t){this._key=ua(t),this.raw=ca(this._key)}toMultihash(){return Bt.digest(Nt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,r,n){return aa(this._key,r,t,n)}};function os(e){return new an(e)}function ca(e){return Ve.ProjectivePoint.fromHex(e).toRawBytes(!0)}function ua(e){try{return Ve.ProjectivePoint.fromHex(e),e}catch(t){throw new Se(String(t))}}function ss(e,t){let{Type:r,Data:n}=Dt.decode(e),o=n??new Uint8Array;switch(r){case tt.RSA:return $o(o,t);case tt.Ed25519:return So(o);case tt.secp256k1:return os(o);case tt.ECDSA:return $n(o);default:throw new ue}}function fa(e){let{Type:t,Data:r}=Dt.decode(e.digest),n=r??new Uint8Array;switch(t){case tt.Ed25519:return So(n);case tt.secp256k1:return os(n);case tt.ECDSA:return $n(n);default:throw new ue}}function Nt(e){return Dt.encode({Type:tt[e.type],Data:e.raw})}var la=Symbol.for("nodejs.util.inspect.custom"),Bf=114,dr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[En]=!0;toString(){return this.string==null&&(this.string=j.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return at.createV1(Bf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return bt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return bt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[la](){return`PeerId(${this.toString()})`}},pr=class extends dr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},mr=class extends dr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},yr=class extends dr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},If=2336,cn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Bt.digest(F(this.url))}[la](){return`PeerId(${this.url})`}[En]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1(If,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=z(t)),t.toString()===this.toString())}};function is(e){if(e.type==="Ed25519")return new mr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new yr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new pr({multihash:e.toCID().multihash,publicKey:e});throw new ue}function ha(e){return is(e.publicKey)}function br(e){if(Lf(e))return new pr({multihash:e});if(_f(e))try{let t=fa(e);if(t.type==="Ed25519")return new mr({multihash:e,publicKey:t});if(t.type==="secp256k1")return new yr({multihash:e,publicKey:t})}catch{let r=z(e.digest);return new cn(new URL(r))}throw new Cr("Supplied PeerID Multihash is invalid")}function _f(e){return e.code===Bt.code}function Lf(e){return e.code===le.code}function xe(e,t){let r={[Symbol.iterator]:()=>r,next:()=>{let n=e.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return r}function un(e){let t=Wt(j.decode(`z${e}`));return br(t)}var gr=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[r,n]of t.entries())this.map.set(r.toString(),{key:r,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return xe(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((r,n)=>{t(r.value,r.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,r){this.map.set(t.toString(),{key:t,value:r})}keys(){return xe(this.map.values(),t=>t.key)}values(){return xe(this.map.values(),t=>t.value)}get size(){return this.map.size}};var wr=class e{set;constructor(t){if(this.set=new Set,t!=null)for(let r of t)this.set.add(r.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return xe(this.set.entries(),t=>{let r=un(t[0]);return[r,r]})}forEach(t){this.set.forEach(r=>{let n=un(r);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return xe(this.set.values(),t=>un(t))}intersection(t){let r=new e;for(let n of t)this.has(n)&&r.add(n);return r}difference(t){let r=new e;for(let n of this)t.has(n)||r.add(n);return r}union(t){let r=new e;for(let n of t)r.add(n);for(let n of this)r.add(n);return r}};function $t(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var fn=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},Fe=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new fn(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let r=this.head;this.head=r.next=new fn(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var as=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function ln(e={}){return Tf(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},e)}function Tf(e,t){t=t??{};let r=t.onEnd,n=new Fe,o,s,i,c=$t(),a=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((S,b)=>{s=A=>{s=null,n.push(A);try{S(e(n))}catch(w){b(w)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=$t()})}},f=S=>s!=null?s(S):(n.push(S),o),p=S=>(n=new Fe,s!=null?s({error:S}):(n.push({error:S}),o)),l=S=>{if(i)return o;if(t?.objectMode!==!0&&S?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return f({done:!1,value:S})},u=S=>i?o:(i=!0,S!=null?p(S):f({done:!0})),h=()=>(n=new Fe,u(),{done:!0}),d=S=>(u(S),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:a,return:h,throw:d,push:l,end:u,get readableLength(){return n.size},onEmpty:async S=>{let b=S?.signal;if(b?.throwIfAborted(),n.isEmpty())return;let A,w;b!=null&&(A=new Promise((L,P)=>{w=()=>{P(new as)},b.addEventListener("abort",w)}));try{await Promise.race([c.promise,A])}finally{w!=null&&b!=null&&b?.removeEventListener("abort",w)}}},r==null)return o;let E=o;return o={[Symbol.asyncIterator](){return this},next(){return E.next()},throw(S){return E.throw(S),r!=null&&(r(S),r=void 0),{done:!0}},return(){return E.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(S){return E.end(S),r!=null&&(r(S),r=void 0),o},get readableLength(){return E.readableLength},onEmpty:S=>E.onEmpty(S)},o}var hn=class extends Error{type;code;constructor(t,r,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=r??"ABORT_ERR"}};async function da(e,t,r){if(t==null)return e;if(t.aborted)return e.catch(()=>{}),Promise.reject(new hn(r?.errorMessage,r?.errorCode,r?.errorName));let n,o=new hn(r?.errorMessage,r?.errorCode,r?.errorName);try{return await Promise.race([e,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var cs=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=$t(),this.haveNext=$t()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=$t(),t}async throw(t){return this.ended=!0,this.error=t,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return this.ended=!0,this.nextResult=t,this.haveNext.resolve(),t}async push(t,r){await this._push(t,r)}async end(t,r){t!=null?await this.throw(t):await this._push(void 0,r)}async _push(t,r){if(t!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=$t(),await da(this.readNext.promise,r?.signal,r)}};function pa(){return new cs}function Cf(e){return e[Symbol.asyncIterator]!=null}async function Df(e,t,r){try{await Promise.all(e.map(async n=>{for await(let o of n)await t.push(o,{signal:r}),r.throwIfAborted()})),await t.end(void 0,{signal:r})}catch(n){await t.end(n,{signal:r}).catch(()=>{})}}async function*Pf(e){let t=new AbortController,r=pa();Df(e,r,t.signal).catch(()=>{});try{yield*r}finally{t.abort()}}function*Kf(e){for(let t of e)yield*t}function Rf(...e){let t=[];for(let r of e)Cf(r)||t.push(r);return t.length===e.length?Kf(t):Pf(e)}var ma=Rf;function xr(e,...t){if(e==null)throw new Error("Empty pipeline");if(us(e)){let n=e;e=()=>n.source}else if(ba(e)||ya(e)){let n=e;e=()=>n}let r=[e,...t];if(r.length>1&&us(r[r.length-1])&&(r[r.length-1]=r[r.length-1].sink),r.length>2)for(let n=1;n<r.length-1;n++)us(r[n])&&(r[n]=Uf(r[n]));return Nf(...r)}var Nf=(...e)=>{let t;for(;e.length>0;)t=e.shift()(t);return t},ya=e=>e?.[Symbol.asyncIterator]!=null,ba=e=>e?.[Symbol.iterator]!=null,us=e=>e==null?!1:e.sink!=null&&e.source!=null,Uf=e=>t=>{let r=e.sink(t);if(r?.then!=null){let n=ln({objectMode:!0});r.then(()=>{n.end()},i=>{n.end(i)});let o,s=e.source;if(ya(s))o=async function*(){yield*s,n.end()};else if(ba(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return ma(n,o())}return e.source};var ls=qa(wa(),1);var Sr=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},hs=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},xa=e=>globalThis.DOMException===void 0?new hs(e):new DOMException(e),Ea=e=>{let t=e.reason===void 0?xa("This operation was aborted."):e.reason;return t instanceof Error?t:xa(t)};function ds(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,c,f=new Promise((p,l)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(t.signal){let{signal:h}=t;h.aborted&&l(Ea(h)),c=()=>{l(Ea(h))},h.addEventListener("abort",c,{once:!0})}if(r===Number.POSITIVE_INFINITY){e.then(p,l);return}let u=new Sr;i=s.setTimeout.call(void 0,()=>{if(n){try{p(n())}catch(h){l(h)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?p():o instanceof Error?l(o):(u.message=o??`Promise timed out after ${r} milliseconds`,l(u))},r),(async()=>{try{p(await e)}catch(h){l(h)}})()}).finally(()=>{f.clear(),c&&t.signal&&t.signal.removeEventListener("abort",c)});return f.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},f}function ps(e,t,r){let n=0,o=e.length;for(;o>0;){let s=Math.trunc(o/2),i=n+s;r(e[i],t)<=0?(n=++i,o-=s+1):o=s}return n}var vr=class{#t=[];enqueue(t,r){r={priority:0,...r};let n={priority:r.priority,id:r.id,run:t};if(this.size===0||this.#t[this.size-1].priority>=r.priority){this.#t.push(n);return}let o=ps(this.#t,n,(s,i)=>i.priority-s.priority);this.#t.splice(o,0,n)}setPriority(t,r){let n=this.#t.findIndex(s=>s.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[o]=this.#t.splice(n,1);this.enqueue(o.run,{priority:r,id:t})}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(r=>r.priority===t.priority).map(r=>r.run)}get size(){return this.#t.length}};var Ar=class extends ls.default{#t;#i;#s=0;#d;#a;#p=0;#r;#c;#e;#m;#n=0;#u;#o;#y;#w=1n;timeout;constructor(t){if(super(),t={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:vr,...t},!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString()??""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString()??""}\` (${typeof t.interval})`);this.#t=t.carryoverConcurrencyCount,this.#i=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#d=t.intervalCap,this.#a=t.interval,this.#e=new t.queueClass,this.#m=t.queueClass,this.concurrency=t.concurrency,this.timeout=t.timeout,this.#y=t.throwOnTimeout===!0,this.#o=t.autoStart===!1}get#x(){return this.#i||this.#s<this.#d}get#E(){return this.#n<this.#u}#S(){this.#n--,this.#f(),this.emit("next")}#v(){this.#g(),this.#b(),this.#c=void 0}get#A(){let t=Date.now();if(this.#r===void 0){let r=this.#p-t;if(r<0)this.#s=this.#t?this.#n:0;else return this.#c===void 0&&(this.#c=setTimeout(()=>{this.#v()},r)),!0}return!1}#f(){if(this.#e.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#o){let t=!this.#A;if(this.#x&&this.#E){let r=this.#e.dequeue();return r?(this.emit("active"),r(),t&&this.#b(),!0):!1}}return!1}#b(){this.#i||this.#r!==void 0||(this.#r=setInterval(()=>{this.#g()},this.#a),this.#p=Date.now()+this.#a)}#g(){this.#s===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#t?this.#n:0,this.#l()}#l(){for(;this.#f(););}get concurrency(){return this.#u}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#u=t,this.#l()}async#B(t){return new Promise((r,n)=>{t.addEventListener("abort",()=>{n(t.reason)},{once:!0})})}setPriority(t,r){this.#e.setPriority(t,r)}async add(t,r={}){return r.id??=(this.#w++).toString(),r={timeout:this.timeout,throwOnTimeout:this.#y,...r},new Promise((n,o)=>{this.#e.enqueue(async()=>{this.#n++,this.#s++;try{r.signal?.throwIfAborted();let s=t({signal:r.signal});r.timeout&&(s=ds(Promise.resolve(s),{milliseconds:r.timeout})),r.signal&&(s=Promise.race([s,this.#B(r.signal)]));let i=await s;n(i),this.emit("completed",i)}catch(s){if(s instanceof Sr&&!r.throwOnTimeout){n();return}o(s),this.emit("error",s)}finally{this.#S()}},r),this.emit("add"),this.#f()})}async addAll(t,r){return Promise.all(t.map(async n=>this.add(n,r)))}start(){return this.#o?(this.#o=!1,this.#l(),this):this}pause(){this.#o=!0}clear(){this.#e=new this.#m}async onEmpty(){this.#e.size!==0&&await this.#h("empty")}async onSizeLessThan(t){this.#e.size<t||await this.#h("next",()=>this.#e.size<t)}async onIdle(){this.#n===0&&this.#e.size===0||await this.#h("idle")}async#h(t,r){return new Promise(n=>{let o=()=>{r&&!r()||(this.off(t,o),n())};this.on(t,o)})}get size(){return this.#e.size}sizeBy(t){return this.#e.filter(t).length}get pending(){return this.#n}get isPaused(){return this.#o}};function Sa(e){if(e!=null){if(typeof e[Symbol.iterator]=="function")return e[Symbol.iterator]();if(typeof e[Symbol.asyncIterator]=="function")return e[Symbol.asyncIterator]();if(typeof e.next=="function")return e}throw new Error("argument is not an iterator or iterable")}function va(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}function Aa(e,t){let r=Sa(e).return?.();va(r)&&r.catch(n=>{t.error("could not cause iterator to return",n)})}var pn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ze=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},mn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},Br=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function yn(e){return e[Symbol.asyncIterator]!=null}function Ba(e,t){if(e.byteLength>t)throw new ze("Message length too long")}var gn=e=>{let t=_t(e),r=ct(t);return Ni(e,r),gn.bytes=t,r};gn.bytes=0;function wn(e,t){t=t??{};let r=t.lengthEncoder??gn,n=t?.maxDataLength??4194304;function*o(s){Ba(s,n);let i=r(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return yn(e)?(async function*(){for await(let s of e)yield*o(s)})():(function*(){for(let s of e)yield*o(s)})()}wn.single=(e,t)=>{t=t??{};let r=t.lengthEncoder??gn,n=t?.maxDataLength??4194304;return Ba(e,n),new rt(r(e.byteLength),e)};var Ee;(function(e){e[e.LENGTH=0]="LENGTH",e[e.DATA=1]="DATA"})(Ee||(Ee={}));var ms=e=>{let t=Ui(e);return ms.bytes=_t(t),t};ms.bytes=0;function Ir(e,t){let r=new rt,n=Ee.LENGTH,o=-1,s=t?.lengthDecoder??ms,i=t?.maxLengthLength??8,c=t?.maxDataLength??4194304;function*a(){for(;r.byteLength>0;){if(n===Ee.LENGTH)try{if(o=s(r),o<0)throw new pn("Invalid message length");if(o>c)throw new ze("Message length too long");let f=s.bytes;r.consume(f),t?.onLength!=null&&t.onLength(o),n=Ee.DATA}catch(f){if(f instanceof RangeError){if(r.byteLength>i)throw new mn("Message length length too long");break}throw f}if(n===Ee.DATA){if(r.byteLength<o)break;let f=r.sublist(0,o);r.consume(o),t?.onData!=null&&t.onData(f),yield f,n=Ee.LENGTH}}}return yn(e)?(async function*(){for await(let f of e)r.append(f),yield*a();if(r.byteLength>0)throw new Br("Unexpected end of input")})():(function*(){for(let f of e)r.append(f),yield*a();if(r.byteLength>0)throw new Br("Unexpected end of input")})()}Ir.fromReader=(e,t)=>{let r=1,n=(async function*(){for(;;)try{let{done:s,value:i}=await e.next(r);if(s===!0)return;i!=null&&(yield i)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{r=1}})();return Ir(n,{...t??{},onLength:s=>{r=s}})};var xn=class extends ve{id;protocol;outboundStream;inboundStream;_rawOutboundStream;_rawInboundStream;_inboundAbortController;closed;log;constructor(t,r){super(),this.log=t.logger.forComponent("libp2p-pubsub:peer-streams"),this.id=r.id,this.protocol=r.protocol,this._inboundAbortController=new AbortController,this.closed=!1}get isReadable(){return!!this.inboundStream}get isWritable(){return!!this.outboundStream}write(t){if(this.outboundStream==null){let r=this.id.toString();throw new Error("No writable connection to "+r)}this.outboundStream.push(t instanceof Uint8Array?new rt(t):t)}attachInboundStream(t,r){let n=()=>{Aa(t.source,this.log)};return this._inboundAbortController.signal.addEventListener("abort",n,{once:!0}),this._rawInboundStream=t,this.inboundStream=xr(this._rawInboundStream,o=>Ir(o,r)),this.dispatchEvent(new CustomEvent("stream:inbound")),this.inboundStream}async attachOutboundStream(t){let r=this.outboundStream;return this.outboundStream!=null&&this.outboundStream.end(),this._rawOutboundStream=t,this.outboundStream=ln({onEnd:n=>{this._rawOutboundStream?.closeWrite().catch(o=>{this.log("error closing outbound stream",o)}),this._rawOutboundStream=void 0,this.outboundStream=void 0,n!=null&&this.dispatchEvent(new CustomEvent("close"))}}),xr(this.outboundStream,n=>wn(n),this._rawOutboundStream).catch(n=>{this.log.error(n)}),r==null&&this.dispatchEvent(new CustomEvent("stream:outbound")),this.outboundStream}close(){this.closed||(this.closed=!0,this.outboundStream!=null&&this.outboundStream.end(),this.inboundStream!=null&&this._inboundAbortController.abort(),this._rawOutboundStream=void 0,this.outboundStream=void 0,this._rawInboundStream=void 0,this.inboundStream=void 0,this.dispatchEvent(new CustomEvent("close")))}};function Ia(){return BigInt(`0x${z(rn(8),"base16")}`)}var _a=(e,t)=>{let r=F(t.toString(16).padStart(16,"0"),"base16"),n=Nt(e),o=new Uint8Array(n.byteLength+r.length);return o.set(n,0),o.set(r,n.byteLength),o},La=e=>le.encode(e);var Ta=function(e){return Array.isArray(e)?e:[e]},Hf=async e=>{if(e.sequenceNumber==null||e.from==null||e.signature==null)return!1;let t=br(Wt(e.from));if(t.publicKey!=null)return!0;if(e.key!=null){let r=e.key;return is(ss(r)).equals(t)}return!1},Ca=async e=>{if(e.from==null)throw new Q("RPC message was missing from");if(!await Hf(e))return{type:"unsigned",topic:e.topic??"",data:e.data??new Uint8Array(0)};let t=br(Wt(e.from)),r=e.key??t.publicKey;if(r==null)throw new Q("RPC message was missing public key");return{type:"signed",from:t,topic:e.topic??"",sequenceNumber:Ff(e.sequenceNumber??new Uint8Array(0)),data:e.data??new Uint8Array(0),signature:e.signature??new Uint8Array(0),key:r instanceof Uint8Array?ss(r):r}},_r=e=>e.type==="signed"?{from:e.from.toMultihash().bytes,data:e.data,sequenceNumber:Vf(e.sequenceNumber),topic:e.topic,signature:e.signature,key:e.key?Nt(e.key):void 0}:{data:e.data,topic:e.topic},Vf=e=>{let t=e.toString(16);return t.length%2!==0&&(t=`0${t}`),F(t,"base16")},Ff=e=>BigInt(`0x${z(e,"base16")}`);var Da=F("libp2p-pubsub:");async function Pa(e,t,r){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:ha(e)},o=fe([Da,r(_r(n)).subarray()]);return n.signature=await e.sign(o),n.key=e.publicKey,n}async function Ka(e,t){if(e.type!=="signed")throw new Error('Message type must be "signed" to be verified');if(e.signature==null)throw new Error("Message must contain a signature to be verified");if(e.from==null)throw new Error("Message must contain a from property to be verified");let r=fe([Da,t({..._r(e),signature:void 0,key:void 0}).subarray()]);return zf(e).verify(r,e.signature)}function zf(e){if(e.type!=="signed")throw new Error('Message type must be "signed" to have a public key');if(e.from==null)throw new Error("Could not get the public key from the originator id");if(e.key!=null)return e.key;if(e.from.publicKey!=null)return e.from.publicKey;throw new Error("Could not get the public key from the originator id")}var ys=class extends ve{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;multicodecs;components;_registrarTopologyIds;enabled;maxInboundStreams;maxOutboundStreams;constructor(t,r){super();let{multicodecs:n=[],globalSignaturePolicy:o="StrictSign",canRelayMessage:s=!1,emitSelf:i=!1,messageProcessingConcurrency:c=10,maxInboundStreams:a=1,maxOutboundStreams:f=1}=r;this.log=t.logger.forComponent("libp2p:pubsub"),this.components=t,this.multicodecs=Ta(n),this.enabled=r.enabled!==!1,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new gr,this.globalSignaturePolicy=o==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=s,this.emitSelf=i,this.topicValidators=new Map,this.queue=new Ar({concurrency:c}),this.maxInboundStreams=a,this.maxOutboundStreams=f,this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}async start(){if(this.started||!this.enabled)return;this.log("starting");let t=this.components.registrar;await Promise.all(this.multicodecs.map(async n=>{await t.handle(n,this._onIncomingStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams})}));let r={onConnect:this._onPeerConnected,onDisconnect:this._onPeerDisconnected};this._registrarTopologyIds=await Promise.all(this.multicodecs.map(async n=>t.register(n,r))),this.log("started"),this.started=!0}async stop(){if(!this.started||!this.enabled)return;let t=this.components.registrar;this._registrarTopologyIds!=null&&this._registrarTopologyIds?.forEach(r=>{t.unregister(r)}),await Promise.all(this.multicodecs.map(async r=>{await t.unhandle(r)})),this.log("stopping");for(let r of this.peers.values())r.close();this.peers.clear(),this.subscriptions=new Set,this.started=!1,this.log("stopped")}isStarted(){return this.started}_onIncomingStream(t){let{stream:r,connection:n}=t,o=n.remotePeer;if(r.protocol==null){r.abort(new Error("Stream was not multiplexed"));return}let s=this.addPeer(o,r.protocol),i=s.attachInboundStream(r);this.processMessages(o,i,s).catch(c=>{this.log(c)})}_onPeerConnected(t,r){if(this.log("connected %p",t),r.streams.find(n=>n.direction==="outbound"&&n.protocol!=null&&this.multicodecs.includes(n.protocol))!=null){this.log("outbound pubsub streams already present on connection from %p",t);return}Promise.resolve().then(async()=>{try{let n=await r.newStream(this.multicodecs);if(n.protocol==null){n.abort(new Error("Stream was not multiplexed"));return}await this.addPeer(t,n.protocol).attachOutboundStream(n)}catch(n){this.log.error(n)}this.send(t,{subscriptions:Array.from(this.subscriptions).map(n=>n.toString()),subscribe:!0})}).catch(n=>{this.log.error(n)})}_onPeerDisconnected(t,r){this.log("connection ended %p",t),this._removePeer(t)}addPeer(t,r){let n=this.peers.get(t);if(n!=null)return n;this.log("new peer %p",t);let o=new xn(this.components,{id:t,protocol:r});return this.peers.set(t,o),o.addEventListener("close",()=>this._removePeer(t),{once:!0}),o}_removePeer(t){let r=this.peers.get(t);if(r!=null){r.close(),this.log("delete peer %p",t),this.peers.delete(t);for(let n of this.topics.values())n.delete(t);return r}}async processMessages(t,r,n){try{await xr(r,async o=>{for await(let s of o){let i=this.decodeRpc(s),c=[];for(let a of i.messages??[]){if(a.from==null||a.data==null||a.topic==null){this.log("message from %p was missing from, data or topic fields, dropping",t);continue}c.push({from:a.from,data:a.data,topic:a.topic,sequenceNumber:a.sequenceNumber??void 0,signature:a.signature??void 0,key:a.key??void 0})}this.processRpc(t,n,{subscriptions:(i.subscriptions??[]).map(a=>({subscribe:!!a.subscribe,topic:a.topic??""})),messages:c}).catch(a=>{this.log(a)})}})}catch(o){this._onPeerDisconnected(n.id,o)}}async processRpc(t,r,n){if(!this.acceptFrom(t))return this.log("received message from unacceptable peer %p",t),!1;this.log("rpc from %p",t);let{subscriptions:o,messages:s}=n;return o!=null&&o.length>0&&(this.log("subscription update from %p",t),o.forEach(i=>{this.processRpcSubOpt(t,i)}),super.dispatchEvent(new CustomEvent("subscription-change",{detail:{peerId:r.id,subscriptions:o.map(({topic:i,subscribe:c})=>({topic:`${i??""}`,subscribe:!!c}))}}))),s!=null&&s.length>0&&(this.log("messages from %p",t),this.queue.addAll(s.map(i=>async()=>{if(i.topic==null||!this.subscriptions.has(i.topic)&&!this.canRelayMessage)return this.log("received message we didn't subscribe to. Dropping."),!1;try{let c=await Ca(i);await this.processMessage(t,c)}catch(c){this.log.error(c)}})).catch(i=>{this.log(i)})),!0}processRpcSubOpt(t,r){let n=r.topic;if(n==null)return;let o=this.topics.get(n);o==null&&(o=new wr,this.topics.set(n,o)),r.subscribe===!0?o.add(t):o.delete(t)}async processMessage(t,r){if(!(this.components.peerId.equals(t)&&!this.emitSelf)){try{await this.validate(t,r)}catch(n){this.log("Message is invalid, dropping it. %O",n);return}this.subscriptions.has(r.topic)&&(!this.components.peerId.equals(t)||this.emitSelf)&&super.dispatchEvent(new CustomEvent("message",{detail:r})),await this.publishMessage(t,r)}}getMsgId(t){switch(this.globalSignaturePolicy){case"StrictSign":if(t.type!=="signed")throw new Q('Message type should be "signed" when signature policy is StrictSign but it was not');if(t.sequenceNumber==null)throw new Q("Need sequence number when signature policy is StrictSign but it was missing");if(t.key==null)throw new Q("Need key when signature policy is StrictSign but it was missing");return _a(t.key,t.sequenceNumber);case"StrictNoSign":return La(t.data);default:throw new Q("Cannot get message id: unhandled signature policy")}}acceptFrom(t){return!0}send(t,r){let{messages:n,subscriptions:o,subscribe:s}=r;this.sendRpc(t,{subscriptions:(o??[]).map(i=>({topic:i,subscribe:!!s})),messages:(n??[]).map(_r)})}sendRpc(t,r){let n=this.peers.get(t);if(n==null){this.log.error("Cannot send RPC to %p as there are no streams to it available",t);return}if(!n.isWritable){this.log.error("Cannot send RPC to %p as there is no outbound stream to it available",t);return}n.write(this.encodeRpc(r))}async validate(t,r){switch(this.globalSignaturePolicy){case"StrictNoSign":if(r.type!=="unsigned")throw new Q('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(r.signature!=null)throw new Q("StrictNoSigning: signature should not be present");if(r.key!=null)throw new Q("StrictNoSigning: key should not be present");if(r.sequenceNumber!=null)throw new Q("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(r.type!=="signed")throw new Q('Message type should be "signed" when signature policy is StrictSign but it was not');if(r.signature==null)throw new Q("StrictSigning: Signing required and no signature was present");if(r.sequenceNumber==null)throw new Q("StrictSigning: Signing required and no sequenceNumber was present");if(!await Ka(r,this.encodeMessage.bind(this)))throw new Q("StrictSigning: Invalid message signature");break;default:throw new Q("Cannot validate message: unhandled signature policy")}let o=this.topicValidators.get(r.topic);if(o!=null){let s=await o(t,r);if(s===Ge.Reject||s===Ge.Ignore)throw new Q("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return Pa(this.components.privateKey,t,this.encodeMessage.bind(this));case"StrictNoSign":return Promise.resolve({type:"unsigned",...t});default:throw new Q("Cannot build message: unhandled signature policy")}}getSubscribers(t){if(!this.started)throw new Dr("not started yet");if(t==null)throw new Z("Topic is required");let r=this.topics.get(t.toString());return r==null?[]:Array.from(r.values())}async publish(t,r){if(!this.started)throw new Error("Pubsub has not started");let n={from:this.components.peerId,topic:t,data:r??new Uint8Array(0),sequenceNumber:Ia()};this.log("publish topic: %s from: %p data: %m",t,n.from,n.data);let o=await this.buildMessage(n),s=!1;this.emitSelf&&this.subscriptions.has(t)&&(s=!0,super.dispatchEvent(new CustomEvent("message",{detail:o})));let i=await this.publishMessage(this.components.peerId,o);return s&&(i.recipients=[...i.recipients,this.components.peerId]),i}subscribe(t){if(!this.started)throw new Error("Pubsub has not started");if(this.log("subscribe to topic: %s",t),!this.subscriptions.has(t)){this.subscriptions.add(t);for(let r of this.peers.keys())this.send(r,{subscriptions:[t],subscribe:!0})}}unsubscribe(t){if(!this.started)throw new Error("Pubsub is not started");super.removeEventListener(t);let r=this.subscriptions.has(t);if(this.log("unsubscribe from %s - am subscribed %s",t,r),r){this.subscriptions.delete(t);for(let n of this.peers.keys())this.send(n,{subscriptions:[t],subscribe:!1})}}getTopics(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.subscriptions)}getPeers(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.peers.keys())}};return Ha(Gf);})();
|
3
3
|
/*! Bundled license information:
|
4
4
|
|
5
5
|
@noble/hashes/esm/utils.js:
|